1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2012
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
26 #include "character.h"
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
43 #endif /* HAVE_X_WINDOWS */
54 Lisp_Object Qwindowp
, Qwindow_live_p
;
55 static Lisp_Object Qwindow_configuration_p
, Qrecord_window_buffer
;
56 static Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
57 static Lisp_Object Qreplace_buffer_in_windows
, Qget_mru_window
;
58 static Lisp_Object Qwindow_resize_root_window
, Qwindow_resize_root_window_vertically
;
59 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
60 static Lisp_Object Qsafe
, Qabove
, Qbelow
;
61 static Lisp_Object Qauto_buffer_name
, Qclone_of
;
63 static int displayed_window_lines (struct window
*);
64 static struct window
*decode_window (Lisp_Object
);
65 static int count_windows (struct window
*);
66 static int get_leaf_windows (struct window
*, struct window
**, int);
67 static void window_scroll (Lisp_Object
, EMACS_INT
, int, int);
68 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
69 static void window_scroll_line_based (Lisp_Object
, int, int, int);
70 static int freeze_window_start (struct window
*, void *);
71 static Lisp_Object
window_list (void);
72 static int add_window_to_list (struct window
*, void *);
73 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
75 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
77 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
79 static void foreach_window (struct frame
*,
80 int (* fn
) (struct window
*, void *),
82 static int foreach_window_1 (struct window
*,
83 int (* fn
) (struct window
*, void *),
85 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
86 static int window_resize_check (struct window
*, int);
87 static void window_resize_apply (struct window
*, int);
88 static Lisp_Object
select_window (Lisp_Object
, Lisp_Object
, int);
90 /* This is the window in which the terminal's cursor should
91 be left when nothing is being done with it. This must
92 always be a leaf window, and its buffer is selected by
93 the top level editing loop at the end of each command.
95 This value is always the same as
96 FRAME_SELECTED_WINDOW (selected_frame). */
97 Lisp_Object selected_window
;
99 /* A list of all windows for use by next_window and Fwindow_list.
100 Functions creating or deleting windows should invalidate this cache
101 by setting it to nil. */
102 Lisp_Object Vwindow_list
;
104 /* The mini-buffer window of the selected frame.
105 Note that you cannot test for mini-bufferness of an arbitrary window
106 by comparing against this; but you can test for mini-bufferness of
107 the selected window. */
108 Lisp_Object minibuf_window
;
110 /* Non-nil means it is the window whose mode line should be
111 shown as the selected window when the minibuffer is selected. */
112 Lisp_Object minibuf_selected_window
;
114 /* Hook run at end of temp_output_buffer_show. */
115 static Lisp_Object Qtemp_buffer_show_hook
;
117 /* Incremented for each window created. */
118 static int sequence_number
;
120 /* Nonzero after init_window_once has finished. */
121 static int window_initialized
;
123 /* Hook to run when window config changes. */
124 static Lisp_Object Qwindow_configuration_change_hook
;
126 /* Used by the function window_scroll_pixel_based */
127 static int window_scroll_pixel_based_preserve_x
;
128 static int window_scroll_pixel_based_preserve_y
;
130 /* Same for window_scroll_line_based. */
131 static EMACS_INT window_scroll_preserve_hpos
;
132 static EMACS_INT window_scroll_preserve_vpos
;
134 static struct window
*
135 decode_window (register Lisp_Object window
)
138 return XWINDOW (selected_window
);
140 CHECK_LIVE_WINDOW (window
);
141 return XWINDOW (window
);
144 static struct window
*
145 decode_any_window (register Lisp_Object window
)
150 return XWINDOW (selected_window
);
152 CHECK_WINDOW (window
);
153 w
= XWINDOW (window
);
154 /* The following test throws up every time a tooltip frame is displayed. */
155 /* CHECK_LIVE_FRAME (w->frame); */
159 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
160 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
163 return WINDOWP (object
) ? Qt
: Qnil
;
166 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
167 doc
: /* Return t if OBJECT is a live window and nil otherwise.
168 A live window is a window that displays a buffer.
169 Internal windows and deleted windows are not live. */)
172 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
175 /* Frames and windows. */
176 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
177 doc
: /* Return the frame that window WINDOW is on.
178 If WINDOW is omitted or nil, it defaults to the selected window. */)
181 return WGET (decode_any_window (window
), frame
);
184 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
185 doc
: /* Return the root window of FRAME-OR-WINDOW.
186 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
187 With a frame argument, return that frame's root window.
188 With a window argument, return the root window of that window's frame. */)
189 (Lisp_Object frame_or_window
)
193 if (NILP (frame_or_window
))
194 window
= SELECTED_FRAME ()->root_window
;
195 else if (WINDOWP (frame_or_window
))
196 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
199 CHECK_LIVE_FRAME (frame_or_window
);
200 window
= XFRAME (frame_or_window
)->root_window
;
206 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
207 doc
: /* Return the minibuffer window for frame FRAME.
208 If FRAME is omitted or nil, it defaults to the selected frame. */)
212 frame
= selected_frame
;
213 CHECK_LIVE_FRAME (frame
);
214 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
217 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
218 Swindow_minibuffer_p
, 0, 1, 0,
219 doc
: /* Return non-nil if WINDOW is a minibuffer window.
220 If WINDOW is omitted or nil, it defaults to the selected window. */)
223 return MINI_WINDOW_P (decode_any_window (window
)) ? Qt
: Qnil
;
226 /* Don't move this to window.el - this must be a safe routine. */
227 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
228 doc
: /* Return the topmost, leftmost live window on FRAME-OR-WINDOW.
229 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
230 Else if FRAME-OR-WINDOW denotes any window, return the first window of
231 that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
232 the first window of that frame. */)
233 (Lisp_Object frame_or_window
)
237 if (NILP (frame_or_window
))
238 window
= SELECTED_FRAME ()->root_window
;
239 else if (WINDOWP (frame_or_window
))
240 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
243 CHECK_LIVE_FRAME (frame_or_window
);
244 window
= XFRAME (frame_or_window
)->root_window
;
247 while (NILP (WGET (XWINDOW (window
), buffer
)))
249 if (! NILP (WGET (XWINDOW (window
), hchild
)))
250 window
= WGET (XWINDOW (window
), hchild
);
251 else if (! NILP (WGET (XWINDOW (window
), vchild
)))
252 window
= WGET (XWINDOW (window
), vchild
);
260 DEFUN ("frame-selected-window", Fframe_selected_window
,
261 Sframe_selected_window
, 0, 1, 0,
262 doc
: /* Return the selected window of FRAME-OR-WINDOW.
263 If omitted, FRAME-OR-WINDOW defaults to the currently selected frame.
264 Else if FRAME-OR-WINDOW denotes any window, return the selected window
265 of that window's frame. If FRAME-OR-WINDOW denotes a live frame, return
266 the selected window of that frame. */)
267 (Lisp_Object frame_or_window
)
271 if (NILP (frame_or_window
))
272 window
= SELECTED_FRAME ()->selected_window
;
273 else if (WINDOWP (frame_or_window
))
274 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
277 CHECK_LIVE_FRAME (frame_or_window
);
278 window
= XFRAME (frame_or_window
)->selected_window
;
284 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
285 Sset_frame_selected_window
, 2, 3, 0,
286 doc
: /* Set selected window of FRAME to WINDOW.
287 FRAME must be a live frame and defaults to the selected one. If FRAME
288 is the selected frame, this makes WINDOW the selected window. Optional
289 argument NORECORD non-nil means to neither change the order of recently
290 selected windows nor the buffer list. WINDOW must denote a live window.
292 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
295 frame
= selected_frame
;
297 CHECK_LIVE_FRAME (frame
);
298 CHECK_LIVE_WINDOW (window
);
300 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
301 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
303 if (EQ (frame
, selected_frame
))
304 return Fselect_window (window
, norecord
);
306 return FSET (XFRAME (frame
), selected_window
, window
);
309 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
310 doc
: /* Return the selected window.
311 The selected window is the window in which the standard cursor for
312 selected windows appears and to which many commands apply. */)
315 return selected_window
;
318 int window_select_count
;
320 /* If select_window is called with inhibit_point_swap non-zero it will
321 not store point of the old selected window's buffer back into that
322 window's pointm slot. This is needed by Fset_window_configuration to
323 avoid that the display routine is called with selected_window set to
324 Qnil causing a subsequent crash. */
326 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
328 register struct window
*w
;
329 register struct window
*ow
;
332 CHECK_LIVE_WINDOW (window
);
334 w
= XWINDOW (window
);
335 w
->frozen_window_start_p
= 0;
339 w
->use_time
= ++window_select_count
;
340 record_buffer (WGET (w
, buffer
));
343 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
346 sf
= SELECTED_FRAME ();
347 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
349 FSET (XFRAME (WINDOW_FRAME (w
)), selected_window
, window
);
350 /* Use this rather than Fhandle_switch_frame
351 so that FRAME_FOCUS_FRAME is moved appropriately as we
352 move around in the state where a minibuffer in a separate
354 Fselect_frame (WINDOW_FRAME (w
), norecord
);
355 /* Fselect_frame called us back so we've done all the work already. */
356 eassert (EQ (window
, selected_window
));
360 FSET (sf
, selected_window
, window
);
362 /* Store the current buffer's actual point into the
363 old selected window. It belongs to that window,
364 and when the window is not selected, must be in the window. */
365 if (!inhibit_point_swap
)
367 ow
= XWINDOW (selected_window
);
368 if (! NILP (WGET (ow
, buffer
)))
369 set_marker_both (WGET (ow
, pointm
), WGET (ow
, buffer
),
370 BUF_PT (XBUFFER (WGET (ow
, buffer
))),
371 BUF_PT_BYTE (XBUFFER (WGET (ow
, buffer
))));
374 selected_window
= window
;
376 Fset_buffer (WGET (w
, buffer
));
378 BVAR (XBUFFER (WGET (w
, buffer
)), last_selected_window
) = window
;
380 /* Go to the point recorded in the window.
381 This is important when the buffer is in more
382 than one window. It also matters when
383 redisplay_window has altered point after scrolling,
384 because it makes the change only in the window. */
386 register ptrdiff_t new_point
= marker_position (WGET (w
, pointm
));
387 if (new_point
< BEGV
)
389 else if (new_point
> ZV
)
395 windows_or_buffers_changed
++;
399 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
400 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
401 Also make WINDOW's buffer current and make WINDOW the frame's selected
402 window. Return WINDOW.
404 Optional second arg NORECORD non-nil means do not put this buffer at the
405 front of the buffer list and do not make this window the most recently
408 Note that the main editor command loop sets the current buffer to the
409 buffer of the selected window before each command. */)
410 (register Lisp_Object window
, Lisp_Object norecord
)
412 return select_window (window
, norecord
, 0);
415 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
416 doc
: /* Return the buffer displayed in window WINDOW.
417 If WINDOW is omitted or nil, it defaults to the selected window.
418 Return nil for an internal window or a deleted window. */)
421 return WGET (decode_any_window (window
), buffer
);
424 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
425 doc
: /* Return the parent window of window WINDOW.
426 If WINDOW is omitted or nil, it defaults to the selected window.
427 Return nil for a window with no parent (e.g. a root window). */)
430 return WGET (decode_any_window (window
), parent
);
433 DEFUN ("window-top-child", Fwindow_top_child
, Swindow_top_child
, 1, 1, 0,
434 doc
: /* Return the topmost child window of window WINDOW.
435 Return nil if WINDOW is a live window (live windows have no children).
436 Return nil if WINDOW is an internal window whose children form a
437 horizontal combination. */)
440 CHECK_WINDOW (window
);
441 return WGET (decode_any_window (window
), vchild
);
444 DEFUN ("window-left-child", Fwindow_left_child
, Swindow_left_child
, 1, 1, 0,
445 doc
: /* Return the leftmost child window of window WINDOW.
446 Return nil if WINDOW is a live window (live windows have no children).
447 Return nil if WINDOW is an internal window whose children form a
448 vertical combination. */)
451 CHECK_WINDOW (window
);
452 return WGET (decode_any_window (window
), hchild
);
455 DEFUN ("window-next-sibling", Fwindow_next_sibling
, Swindow_next_sibling
, 0, 1, 0,
456 doc
: /* Return the next sibling window of window WINDOW.
457 If WINDOW is omitted or nil, it defaults to the selected window.
458 Return nil if WINDOW has no next sibling. */)
461 return WGET (decode_any_window (window
), next
);
464 DEFUN ("window-prev-sibling", Fwindow_prev_sibling
, Swindow_prev_sibling
, 0, 1, 0,
465 doc
: /* Return the previous sibling window of window WINDOW.
466 If WINDOW is omitted or nil, it defaults to the selected window.
467 Return nil if WINDOW has no previous sibling. */)
470 return WGET (decode_any_window (window
), prev
);
473 DEFUN ("window-combination-limit", Fwindow_combination_limit
, Swindow_combination_limit
, 1, 1, 0,
474 doc
: /* Return combination limit of window WINDOW.
475 If the return value is nil, child windows of WINDOW can be recombined with
476 WINDOW's siblings. A return value of t means that child windows of
477 WINDOW are never \(re-)combined with WINDOW's siblings. */)
480 return WGET (decode_any_window (window
), combination_limit
);
483 DEFUN ("set-window-combination-limit", Fset_window_combination_limit
, Sset_window_combination_limit
, 2, 2, 0,
484 doc
: /* Set combination limit of window WINDOW to LIMIT; return LIMIT.
485 If LIMIT is nil, child windows of WINDOW can be recombined with
486 WINDOW's siblings. LIMIT t means that child windows of WINDOW are
487 never \(re-)combined with WINDOW's siblings. Other values are reserved
489 (Lisp_Object window
, Lisp_Object limit
)
491 return WSET (decode_any_window (window
), combination_limit
, limit
);
494 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
495 doc
: /* Return the use time of window WINDOW.
496 If WINDOW is omitted or nil, it defaults to the selected window.
497 The window with the highest use time is the most recently selected
498 one. The window with the lowest use time is the least recently
502 return make_number (decode_window (window
)->use_time
);
505 DEFUN ("window-total-height", Fwindow_total_height
, Swindow_total_height
, 0, 1, 0,
506 doc
: /* Return the total height, in lines, of window WINDOW.
507 If WINDOW is omitted or nil, it defaults to the selected window.
509 The return value includes the mode line and header line, if any.
510 If WINDOW is an internal window, the total height is the height
511 of the screen areas spanned by its children.
513 On a graphical display, this total height is reported as an
514 integer multiple of the default character height. */)
517 return WGET (decode_any_window (window
), total_lines
);
520 DEFUN ("window-total-width", Fwindow_total_width
, Swindow_total_width
, 0, 1, 0,
521 doc
: /* Return the total width, in columns, of window WINDOW.
522 If WINDOW is omitted or nil, it defaults to the selected window.
524 The return value includes any vertical dividers or scroll bars
525 belonging to WINDOW. If WINDOW is an internal window, the total width
526 is the width of the screen areas spanned by its children.
528 On a graphical display, this total width is reported as an
529 integer multiple of the default character width. */)
532 return WGET (decode_any_window (window
), total_cols
);
535 DEFUN ("window-new-total", Fwindow_new_total
, Swindow_new_total
, 0, 1, 0,
536 doc
: /* Return the new total size of window WINDOW.
537 If WINDOW is omitted or nil, it defaults to the selected window. */)
540 return WGET (decode_any_window (window
), new_total
);
543 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
544 doc
: /* Return the normal height of window WINDOW.
545 If WINDOW is omitted or nil, it defaults to the selected window.
546 If HORIZONTAL is non-nil, return the normal width of WINDOW. */)
547 (Lisp_Object window
, Lisp_Object horizontal
)
549 if (NILP (horizontal
))
550 return WGET (decode_any_window (window
), normal_lines
);
552 return WGET (decode_any_window (window
), normal_cols
);
555 DEFUN ("window-new-normal", Fwindow_new_normal
, Swindow_new_normal
, 0, 1, 0,
556 doc
: /* Return new normal size of window WINDOW.
557 If WINDOW is omitted or nil, it defaults to the selected window. */)
560 return WGET (decode_any_window (window
), new_normal
);
563 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
564 doc
: /* Return left column of window WINDOW.
565 This is the distance, in columns, between the left edge of WINDOW and
566 the left edge of the frame's window area. For instance, the return
567 value is 0 if there is no window to the left of WINDOW.
569 If WINDOW is omitted or nil, it defaults to the selected window. */)
572 return WGET (decode_any_window (window
), left_col
);
575 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
576 doc
: /* Return top line of window WINDOW.
577 This is the distance, in lines, between the top of WINDOW and the top
578 of the frame's window area. For instance, the return value is 0 if
579 there is no window above WINDOW.
581 If WINDOW is omitted or nil, it defaults to the selected window. */)
584 return WGET (decode_any_window (window
), top_line
);
587 /* Return the number of lines of W's body. Don't count any mode or
591 window_body_lines (struct window
*w
)
593 int height
= XFASTINT (WGET (w
, total_lines
));
595 if (!MINI_WINDOW_P (w
))
597 if (WINDOW_WANTS_MODELINE_P (w
))
599 if (WINDOW_WANTS_HEADER_LINE_P (w
))
606 /* Return the number of columns of W's body. Don't count columns
607 occupied by the scroll bar or the vertical bar separating W from its
608 right sibling. On window-systems don't count fringes or display
612 window_body_cols (struct window
*w
)
614 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
615 int width
= XINT (WGET (w
, total_cols
));
617 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
618 /* Scroll bars occupy a few columns. */
619 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
620 else if (!FRAME_WINDOW_P (f
)
621 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
622 /* The column of `|' characters separating side-by-side windows
623 occupies one column only. */
626 if (FRAME_WINDOW_P (f
))
627 /* On window-systems, fringes and display margins cannot be
628 used for normal text. */
629 width
-= (WINDOW_FRINGE_COLS (w
)
630 + WINDOW_LEFT_MARGIN_COLS (w
)
631 + WINDOW_RIGHT_MARGIN_COLS (w
));
636 DEFUN ("window-body-height", Fwindow_body_height
, Swindow_body_height
, 0, 1, 0,
637 doc
: /* Return the height, in lines, of WINDOW's text area.
638 If WINDOW is omitted or nil, it defaults to the selected window.
639 Signal an error if the window is not live.
641 The returned height does not include the mode line or header line.
642 On a graphical display, the height is expressed as an integer multiple
643 of the default character height. If a line at the bottom of the text
644 area is only partially visible, that counts as a whole line; to
645 exclude partially-visible lines, use `window-text-height'. */)
648 struct window
*w
= decode_window (window
);
649 return make_number (window_body_lines (w
));
652 DEFUN ("window-body-width", Fwindow_body_width
, Swindow_body_width
, 0, 1, 0,
653 doc
: /* Return the width, in columns, of WINDOW's text area.
654 If WINDOW is omitted or nil, it defaults to the selected window.
655 Signal an error if the window is not live.
657 The return value does not include any vertical dividers, fringe or
658 marginal areas, or scroll bars. On a graphical display, the width is
659 expressed as an integer multiple of the default character width. */)
662 struct window
*w
= decode_window (window
);
663 return make_number (window_body_cols (w
));
666 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
667 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
668 WINDOW must be a live window and defaults to the selected one. */)
671 return make_number (decode_window (window
)->hscroll
);
674 /* Set W's horizontal scroll amount to HSCROLL clipped to a reasonable
675 range, returning the new amount as a fixnum. */
677 set_window_hscroll (struct window
*w
, EMACS_INT hscroll
)
679 /* Horizontal scrolling has problems with large scroll amounts.
680 It's too slow with long lines, and even with small lines the
681 display can be messed up. For now, though, impose only the limits
682 required by the internal representation: horizontal scrolling must
683 fit in fixnum (since it's visible to Elisp) and into ptrdiff_t
684 (since it's stored in a ptrdiff_t). */
685 ptrdiff_t hscroll_max
= min (MOST_POSITIVE_FIXNUM
, PTRDIFF_MAX
);
686 ptrdiff_t new_hscroll
= clip_to_bounds (0, hscroll
, hscroll_max
);
688 /* Prevent redisplay shortcuts when changing the hscroll. */
689 if (w
->hscroll
!= new_hscroll
)
690 XBUFFER (WGET (w
, buffer
))->prevent_redisplay_optimizations_p
= 1;
692 w
->hscroll
= new_hscroll
;
693 return make_number (new_hscroll
);
696 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
697 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
698 If WINDOW is nil, the selected window is used.
699 Clip the number to a reasonable value if out of range.
700 Return the new number. NCOL should be zero or positive.
702 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
703 window so that the location of point moves off-window. */)
704 (Lisp_Object window
, Lisp_Object ncol
)
706 struct window
*w
= decode_window (window
);
709 return set_window_hscroll (w
, XINT (ncol
));
712 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
713 Swindow_redisplay_end_trigger
, 0, 1, 0,
714 doc
: /* Return WINDOW's redisplay end trigger value.
715 WINDOW defaults to the selected window.
716 See `set-window-redisplay-end-trigger' for more information. */)
719 return WGET (decode_window (window
), redisplay_end_trigger
);
722 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
723 Sset_window_redisplay_end_trigger
, 2, 2, 0,
724 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
725 VALUE should be a buffer position (typically a marker) or nil.
726 If it is a buffer position, then if redisplay in WINDOW reaches a position
727 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
728 with two arguments: WINDOW, and the end trigger value.
729 Afterwards the end-trigger value is reset to nil. */)
730 (register Lisp_Object window
, Lisp_Object value
)
732 return WSET (decode_window (window
), redisplay_end_trigger
, value
);
735 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
736 doc
: /* Return a list of the edge coordinates of WINDOW.
737 The list has the form (LEFT TOP RIGHT BOTTOM).
738 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
739 all relative to 0, 0 at top left corner of frame.
741 RIGHT is one more than the rightmost column occupied by WINDOW.
742 BOTTOM is one more than the bottommost row occupied by WINDOW.
743 The edges include the space used by WINDOW's scroll bar, display
744 margins, fringes, header line, and/or mode line. For the edges of
745 just the text area, use `window-inside-edges'. */)
748 register struct window
*w
= decode_any_window (window
);
750 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
751 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
752 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
753 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
757 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
758 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
759 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
760 the top left corner of the frame.
762 RIGHT is one more than the rightmost x position occupied by WINDOW.
763 BOTTOM is one more than the bottommost y position occupied by WINDOW.
764 The pixel edges include the space used by WINDOW's scroll bar, display
765 margins, fringes, header line, and/or mode line. For the pixel edges
766 of just the text area, use `window-inside-pixel-edges'. */)
769 register struct window
*w
= decode_any_window (window
);
771 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
772 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
773 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
774 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
779 calc_absolute_offset (struct window
*w
, int *add_x
, int *add_y
)
781 struct frame
*f
= XFRAME (WGET (w
, frame
));
783 #ifdef FRAME_MENUBAR_HEIGHT
784 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
786 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
787 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
788 #elif FRAME_TOOLBAR_HEIGHT
789 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
791 #ifdef FRAME_NS_TITLEBAR_HEIGHT
792 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
794 *add_x
= f
->left_pos
;
795 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
796 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
800 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
801 Swindow_absolute_pixel_edges
, 0, 1, 0,
802 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
803 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
804 the top left corner of the display.
806 RIGHT is one more than the rightmost x position occupied by WINDOW.
807 BOTTOM is one more than the bottommost y position occupied by WINDOW.
808 The pixel edges include the space used by WINDOW's scroll bar, display
809 margins, fringes, header line, and/or mode line. For the pixel edges
810 of just the text area, use `window-inside-absolute-pixel-edges'. */)
813 register struct window
*w
= decode_any_window (window
);
815 calc_absolute_offset (w
, &add_x
, &add_y
);
817 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
) + add_x
),
818 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
) + add_y
),
819 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
) + add_x
),
820 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
) + add_y
),
824 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
825 doc
: /* Return a list of the edge coordinates of WINDOW.
826 The list has the form (LEFT TOP RIGHT BOTTOM).
827 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
828 all relative to 0, 0 at top left corner of frame.
830 RIGHT is one more than the rightmost column of WINDOW's text area.
831 BOTTOM is one more than the bottommost row of WINDOW's text area.
832 The inside edges do not include the space used by the WINDOW's scroll
833 bar, display margins, fringes, header line, and/or mode line. */)
836 register struct window
*w
= decode_window (window
);
838 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
839 + WINDOW_LEFT_MARGIN_COLS (w
)
840 + WINDOW_LEFT_FRINGE_COLS (w
)),
841 make_number (WINDOW_TOP_EDGE_LINE (w
)
842 + WINDOW_HEADER_LINE_LINES (w
)),
843 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
844 - WINDOW_RIGHT_MARGIN_COLS (w
)
845 - WINDOW_RIGHT_FRINGE_COLS (w
)),
846 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
847 - WINDOW_MODE_LINE_LINES (w
)));
850 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
851 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
852 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
853 at the top left corner of the frame's window area.
855 RIGHT is one more than the rightmost x position of WINDOW's text area.
856 BOTTOM is one more than the bottommost y position of WINDOW's text area.
857 The inside edges do not include the space used by WINDOW's scroll bar,
858 display margins, fringes, header line, and/or mode line. */)
861 register struct window
*w
= decode_window (window
);
863 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
864 + WINDOW_LEFT_MARGIN_WIDTH (w
)
865 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
866 make_number (WINDOW_TOP_EDGE_Y (w
)
867 + WINDOW_HEADER_LINE_HEIGHT (w
)),
868 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
869 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
870 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
871 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
872 - WINDOW_MODE_LINE_HEIGHT (w
)));
875 DEFUN ("window-inside-absolute-pixel-edges",
876 Fwindow_inside_absolute_pixel_edges
,
877 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
878 doc
: /* Return a list of the edge pixel coordinates of WINDOW's text area.
879 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to (0,0)
880 at the top left corner of the frame's window area.
882 RIGHT is one more than the rightmost x position of WINDOW's text area.
883 BOTTOM is one more than the bottommost y position of WINDOW's text area.
884 The inside edges do not include the space used by WINDOW's scroll bar,
885 display margins, fringes, header line, and/or mode line. */)
888 register struct window
*w
= decode_window (window
);
890 calc_absolute_offset (w
, &add_x
, &add_y
);
892 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
893 + WINDOW_LEFT_MARGIN_WIDTH (w
)
894 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
895 make_number (WINDOW_TOP_EDGE_Y (w
)
896 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
897 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
898 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
899 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
900 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
901 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
904 /* Test if the character at column X, row Y is within window W.
905 If it is not, return ON_NOTHING;
906 if it is in the window's text area, return ON_TEXT;
907 if it is on the window's modeline, return ON_MODE_LINE;
908 if it is on the border between the window and its right sibling,
909 return ON_VERTICAL_BORDER.
910 if it is on a scroll bar, return ON_SCROLL_BAR.
911 if it is on the window's top line, return ON_HEADER_LINE;
912 if it is in left or right fringe of the window,
913 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
914 if it is in the marginal area to the left/right of the window,
915 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
917 X and Y are frame relative pixel coordinates. */
919 static enum window_part
920 coordinates_in_window (register struct window
*w
, int x
, int y
)
922 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
923 enum window_part part
;
924 int ux
= FRAME_COLUMN_WIDTH (f
);
925 int left_x
= WINDOW_LEFT_EDGE_X (w
);
926 int right_x
= WINDOW_RIGHT_EDGE_X (w
);
927 int top_y
= WINDOW_TOP_EDGE_Y (w
);
928 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
929 /* The width of the area where the vertical line can be dragged.
930 (Between mode lines for instance. */
931 int grabbable_width
= ux
;
932 int lmargin_width
, rmargin_width
, text_left
, text_right
;
934 /* Outside any interesting row or column? */
935 if (y
< top_y
|| y
>= bottom_y
|| x
< left_x
|| x
>= right_x
)
938 /* On the mode line or header line? */
939 if ((WINDOW_WANTS_MODELINE_P (w
)
940 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
)
941 && (part
= ON_MODE_LINE
))
942 || (WINDOW_WANTS_HEADER_LINE_P (w
)
943 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
)
944 && (part
= ON_HEADER_LINE
)))
946 /* If it's under/over the scroll bar portion of the mode/header
947 line, say it's on the vertical line. That's to be able to
948 resize windows horizontally in case we're using toolkit scroll
949 bars. Note: If scrollbars are on the left, the window that
950 must be eventually resized is that on the left of WINDOW. */
951 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
952 && !WINDOW_LEFTMOST_P (w
)
953 && eabs (x
- left_x
) < grabbable_width
)
954 || (!WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
955 && !WINDOW_RIGHTMOST_P (w
)
956 && eabs (x
- right_x
) < grabbable_width
))
957 return ON_VERTICAL_BORDER
;
962 /* In what's below, we subtract 1 when computing right_x because we
963 want the rightmost pixel, which is given by left_pixel+width-1. */
964 if (w
->pseudo_window_p
)
967 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
971 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
972 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
975 /* Outside any interesting column? */
976 if (x
< left_x
|| x
> right_x
)
977 return ON_SCROLL_BAR
;
979 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
980 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
982 text_left
= window_box_left (w
, TEXT_AREA
);
983 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
985 if (FRAME_WINDOW_P (f
))
987 if (!w
->pseudo_window_p
988 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
989 && !WINDOW_RIGHTMOST_P (w
)
990 && (eabs (x
- right_x
) < grabbable_width
))
991 return ON_VERTICAL_BORDER
;
993 /* Need to say "x > right_x" rather than >=, since on character
994 terminals, the vertical line's x coordinate is right_x. */
995 else if (!w
->pseudo_window_p
996 && !WINDOW_RIGHTMOST_P (w
)
998 return ON_VERTICAL_BORDER
;
1002 if (lmargin_width
> 0
1003 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1004 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1005 : (x
< left_x
+ lmargin_width
)))
1006 return ON_LEFT_MARGIN
;
1008 return ON_LEFT_FRINGE
;
1011 if (x
>= text_right
)
1013 if (rmargin_width
> 0
1014 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1015 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1016 : (x
>= right_x
- rmargin_width
)))
1017 return ON_RIGHT_MARGIN
;
1019 return ON_RIGHT_FRINGE
;
1022 /* Everything special ruled out - must be on text area */
1026 /* Take X is the frame-relative pixel x-coordinate, and return the
1027 x-coordinate relative to part PART of window W. */
1029 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1031 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1036 return x
- window_box_left (w
, TEXT_AREA
);
1038 case ON_LEFT_FRINGE
:
1041 case ON_RIGHT_FRINGE
:
1042 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1044 case ON_LEFT_MARGIN
:
1046 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1047 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1049 case ON_RIGHT_MARGIN
:
1051 - ((w
->pseudo_window_p
)
1052 ? WINDOW_TOTAL_WIDTH (w
)
1053 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1054 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1055 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1056 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1059 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1064 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1065 Scoordinates_in_window_p
, 2, 2, 0,
1066 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1067 WINDOW must be a live window.
1068 COORDINATES is a cons of the form (X . Y), X and Y being distances
1069 measured in characters from the upper-left corner of the frame.
1070 \(0 . 0) denotes the character in the upper left corner of the
1072 If COORDINATES are in the text portion of WINDOW,
1073 the coordinates relative to the window are returned.
1074 If they are in the mode line of WINDOW, `mode-line' is returned.
1075 If they are in the top mode line of WINDOW, `header-line' is returned.
1076 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1077 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1078 If they are on the border between WINDOW and its right sibling,
1079 `vertical-line' is returned.
1080 If they are in the windows's left or right marginal areas, `left-margin'\n\
1081 or `right-margin' is returned. */)
1082 (register Lisp_Object coordinates
, Lisp_Object window
)
1089 CHECK_LIVE_WINDOW (window
);
1090 w
= XWINDOW (window
);
1091 f
= XFRAME (WGET (w
, frame
));
1092 CHECK_CONS (coordinates
);
1093 lx
= Fcar (coordinates
);
1094 ly
= Fcdr (coordinates
);
1095 CHECK_NUMBER_OR_FLOAT (lx
);
1096 CHECK_NUMBER_OR_FLOAT (ly
);
1097 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1098 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1100 switch (coordinates_in_window (w
, x
, y
))
1106 /* Convert X and Y to window relative pixel coordinates, and
1107 return the canonical char units. */
1108 x
-= window_box_left (w
, TEXT_AREA
);
1109 y
-= WINDOW_TOP_EDGE_Y (w
);
1110 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1111 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1116 case ON_VERTICAL_BORDER
:
1117 return Qvertical_line
;
1119 case ON_HEADER_LINE
:
1120 return Qheader_line
;
1122 case ON_LEFT_FRINGE
:
1123 return Qleft_fringe
;
1125 case ON_RIGHT_FRINGE
:
1126 return Qright_fringe
;
1128 case ON_LEFT_MARGIN
:
1129 return Qleft_margin
;
1131 case ON_RIGHT_MARGIN
:
1132 return Qright_margin
;
1135 /* Historically we are supposed to return nil in this case. */
1144 /* Callback for foreach_window, used in window_from_coordinates.
1145 Check if window W contains coordinates specified by USER_DATA which
1146 is actually a pointer to a struct check_window_data CW.
1148 Check if window W contains coordinates *CW->x and *CW->y. If it
1149 does, return W in *CW->window, as Lisp_Object, and return in
1150 *CW->part the part of the window under coordinates *X,*Y. Return
1151 zero from this function to stop iterating over windows. */
1153 struct check_window_data
1155 Lisp_Object
*window
;
1157 enum window_part
*part
;
1161 check_window_containing (struct window
*w
, void *user_data
)
1163 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1164 enum window_part found
;
1167 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1168 if (found
!= ON_NOTHING
)
1171 XSETWINDOW (*cw
->window
, w
);
1179 /* Find the window containing frame-relative pixel position X/Y and
1180 return it as a Lisp_Object.
1182 If X, Y is on one of the window's special `window_part' elements,
1183 set *PART to the id of that element.
1185 If there is no window under X, Y return nil and leave *PART
1186 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1188 This function was previously implemented with a loop cycling over
1189 windows with Fnext_window, and starting with the frame's selected
1190 window. It turned out that this doesn't work with an
1191 implementation of next_window using Vwindow_list, because
1192 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1193 tree of F when this function is called asynchronously from
1194 note_mouse_highlight. The original loop didn't terminate in this
1198 window_from_coordinates (struct frame
*f
, int x
, int y
,
1199 enum window_part
*part
, int tool_bar_p
)
1202 struct check_window_data cw
;
1203 enum window_part dummy
;
1209 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1210 foreach_window (f
, check_window_containing
, &cw
);
1212 /* If not found above, see if it's in the tool bar window, if a tool
1216 && WINDOWP (f
->tool_bar_window
)
1217 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1218 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1222 window
= f
->tool_bar_window
;
1228 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1229 doc
: /* Return window containing coordinates X and Y on FRAME.
1230 FRAME must be a live frame and defaults to the selected one.
1231 The top left corner of the frame is considered to be row 0,
1233 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1238 frame
= selected_frame
;
1239 CHECK_LIVE_FRAME (frame
);
1242 /* Check that arguments are integers or floats. */
1243 CHECK_NUMBER_OR_FLOAT (x
);
1244 CHECK_NUMBER_OR_FLOAT (y
);
1246 return window_from_coordinates (f
,
1247 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1248 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1249 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1250 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1254 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1255 doc
: /* Return current value of point in WINDOW.
1256 WINDOW must be a live window and defaults to the selected one.
1258 For a nonselected window, this is the value point would have
1259 if that window were selected.
1261 Note that, when WINDOW is the selected window and its buffer
1262 is also currently selected, the value returned is the same as (point).
1263 It would be more strictly correct to return the `top-level' value
1264 of point, outside of any save-excursion forms.
1265 But that is hard to define. */)
1266 (Lisp_Object window
)
1268 register struct window
*w
= decode_window (window
);
1270 if (w
== XWINDOW (selected_window
)
1271 && current_buffer
== XBUFFER (WGET (w
, buffer
)))
1273 return Fmarker_position (WGET (w
, pointm
));
1276 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1277 doc
: /* Return position at which display currently starts in WINDOW.
1278 WINDOW must be a live window and defaults to the selected one.
1279 This is updated by redisplay or by calling `set-window-start'. */)
1280 (Lisp_Object window
)
1282 return Fmarker_position (WGET (decode_window (window
), start
));
1285 /* This is text temporarily removed from the doc string below.
1287 This function returns nil if the position is not currently known.
1288 That happens when redisplay is preempted and doesn't finish.
1289 If in that case you want to compute where the end of the window would
1290 have been if redisplay had finished, do this:
1292 (goto-char (window-start window))
1293 (vertical-motion (1- (window-height window)) window)
1296 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1297 doc
: /* Return position at which display currently ends in WINDOW.
1298 WINDOW must be a live window and defaults to the selected one.
1299 This is updated by redisplay, when it runs to completion.
1300 Simply changing the buffer text or setting `window-start'
1301 does not update this value.
1302 Return nil if there is no recorded value. (This can happen if the
1303 last redisplay of WINDOW was preempted, and did not finish.)
1304 If UPDATE is non-nil, compute the up-to-date position
1305 if it isn't already recorded. */)
1306 (Lisp_Object window
, Lisp_Object update
)
1309 struct window
*w
= decode_window (window
);
1313 buf
= WGET (w
, buffer
);
1317 #if 0 /* This change broke some things. We should make it later. */
1318 /* If we don't know the end position, return nil.
1319 The user can compute it with vertical-motion if he wants to.
1320 It would be nicer to do it automatically,
1321 but that's so slow that it would probably bother people. */
1322 if (NILP (WGET (w
, window_end_valid
)))
1327 && ! (! NILP (WGET (w
, window_end_valid
))
1328 && w
->last_modified
>= BUF_MODIFF (b
)
1329 && w
->last_overlay_modified
>= BUF_OVERLAY_MODIFF (b
))
1332 struct text_pos startp
;
1334 struct buffer
*old_buffer
= NULL
;
1335 void *itdata
= NULL
;
1337 /* Cannot use Fvertical_motion because that function doesn't
1338 cope with variable-height lines. */
1339 if (b
!= current_buffer
)
1341 old_buffer
= current_buffer
;
1342 set_buffer_internal (b
);
1345 /* In case W->start is out of the range, use something
1346 reasonable. This situation occurred when loading a file with
1347 `-l' containing a call to `rmail' with subsequent other
1348 commands. At the end, W->start happened to be BEG, while
1349 rmail had already narrowed the buffer. */
1350 if (XMARKER (WGET (w
, start
))->charpos
< BEGV
)
1351 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1352 else if (XMARKER (WGET (w
, start
))->charpos
> ZV
)
1353 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1355 SET_TEXT_POS_FROM_MARKER (startp
, WGET (w
, start
));
1357 itdata
= bidi_shelve_cache ();
1358 start_display (&it
, w
, startp
);
1359 move_it_vertically (&it
, window_box_height (w
));
1360 if (it
.current_y
< it
.last_visible_y
)
1361 move_it_past_eol (&it
);
1362 value
= make_number (IT_CHARPOS (it
));
1363 bidi_unshelve_cache (itdata
, 0);
1366 set_buffer_internal (old_buffer
);
1369 XSETINT (value
, BUF_Z (b
) - XFASTINT (WGET (w
, window_end_pos
)));
1374 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1375 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1377 (Lisp_Object window
, Lisp_Object pos
)
1379 register struct window
*w
= decode_window (window
);
1381 CHECK_NUMBER_COERCE_MARKER (pos
);
1382 if (w
== XWINDOW (selected_window
)
1383 && XBUFFER (WGET (w
, buffer
)) == current_buffer
)
1386 set_marker_restricted (WGET (w
, pointm
), pos
, WGET (w
, buffer
));
1388 /* We have to make sure that redisplay updates the window to show
1389 the new value of point. */
1390 if (!EQ (window
, selected_window
))
1391 ++windows_or_buffers_changed
;
1396 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1397 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1398 If WINDOW is nil, the selected window is used. Return POS.
1399 Optional third arg NOFORCE non-nil inhibits next redisplay from
1400 overriding motion of point in order to display at this exact start. */)
1401 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1403 register struct window
*w
= decode_window (window
);
1405 CHECK_NUMBER_COERCE_MARKER (pos
);
1406 set_marker_restricted (WGET (w
, start
), pos
, WGET (w
, buffer
));
1407 /* this is not right, but much easier than doing what is right. */
1408 w
->start_at_line_beg
= 0;
1411 w
->update_mode_line
= 1;
1412 w
->last_modified
= 0;
1413 w
->last_overlay_modified
= 0;
1414 if (!EQ (window
, selected_window
))
1415 windows_or_buffers_changed
++;
1420 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1421 Spos_visible_in_window_p
, 0, 3, 0,
1422 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
1423 Return nil if that position is scrolled vertically out of view.
1424 If a character is only partially visible, nil is returned, unless the
1425 optional argument PARTIALLY is non-nil.
1426 If POS is only out of view because of horizontal scrolling, return non-nil.
1427 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1428 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1430 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1431 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1432 where X and Y are the pixel coordinates relative to the top left corner
1433 of the window. The remaining elements are omitted if the character after
1434 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1435 off-window at the top and bottom of the row, ROWH is the height of the
1436 display row, and VPOS is the row number (0-based) containing POS. */)
1437 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1439 register struct window
*w
;
1440 register EMACS_INT posint
;
1441 register struct buffer
*buf
;
1442 struct text_pos top
;
1443 Lisp_Object in_window
= Qnil
;
1444 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1447 w
= decode_window (window
);
1448 buf
= XBUFFER (WGET (w
, buffer
));
1449 SET_TEXT_POS_FROM_MARKER (top
, WGET (w
, start
));
1453 else if (!NILP (pos
))
1455 CHECK_NUMBER_COERCE_MARKER (pos
);
1456 posint
= XINT (pos
);
1458 else if (w
== XWINDOW (selected_window
))
1461 posint
= XMARKER (WGET (w
, pointm
))->charpos
;
1463 /* If position is above window start or outside buffer boundaries,
1464 or if window start is out of range, position is not visible. */
1466 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1467 && CHARPOS (top
) >= BUF_BEGV (buf
)
1468 && CHARPOS (top
) <= BUF_ZV (buf
)
1469 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1470 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1473 if (!NILP (in_window
) && !NILP (partially
))
1475 Lisp_Object part
= Qnil
;
1477 part
= list4 (make_number (rtop
), make_number (rbot
),
1478 make_number (rowh
), make_number (vpos
));
1479 in_window
= Fcons (make_number (x
),
1480 Fcons (make_number (y
), part
));
1486 DEFUN ("window-line-height", Fwindow_line_height
,
1487 Swindow_line_height
, 0, 2, 0,
1488 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1489 WINDOW defaults to the selected window.
1491 Return height of current line if LINE is omitted or nil. Return height of
1492 header or mode line if LINE is `header-line' or `mode-line'.
1493 Otherwise, LINE is a text line number starting from 0. A negative number
1494 counts from the end of the window.
1496 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1497 in pixels of the visible part of the line, VPOS and YPOS are the
1498 vertical position in lines and pixels of the line, relative to the top
1499 of the first text line, and OFFBOT is the number of off-window pixels at
1500 the bottom of the text line. If there are off-window pixels at the top
1501 of the (first) text line, YPOS is negative.
1503 Return nil if window display is not up-to-date. In that case, use
1504 `pos-visible-in-window-p' to obtain the information. */)
1505 (Lisp_Object line
, Lisp_Object window
)
1507 register struct window
*w
;
1508 register struct buffer
*b
;
1509 struct glyph_row
*row
, *end_row
;
1513 w
= decode_window (window
);
1515 if (noninteractive
|| w
->pseudo_window_p
)
1518 CHECK_BUFFER (WGET (w
, buffer
));
1519 b
= XBUFFER (WGET (w
, buffer
));
1521 /* Fail if current matrix is not up-to-date. */
1522 if (NILP (WGET (w
, window_end_valid
))
1523 || current_buffer
->clip_changed
1524 || current_buffer
->prevent_redisplay_optimizations_p
1525 || w
->last_modified
< BUF_MODIFF (b
)
1526 || w
->last_overlay_modified
< BUF_OVERLAY_MODIFF (b
))
1532 if (i
< 0 || i
>= w
->current_matrix
->nrows
1533 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1535 max_y
= window_text_bottom_y (w
);
1539 if (EQ (line
, Qheader_line
))
1541 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1543 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1544 if (!row
->enabled_p
)
1546 return list4 (make_number (row
->height
),
1547 make_number (0), make_number (0),
1551 if (EQ (line
, Qmode_line
))
1553 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1554 if (!row
->enabled_p
)
1556 return list4 (make_number (row
->height
),
1557 make_number (0), /* not accurate */
1558 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
1559 + window_text_bottom_y (w
)),
1563 CHECK_NUMBER (line
);
1566 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1567 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1568 max_y
= window_text_bottom_y (w
);
1571 while ((n
< 0 || i
< n
)
1572 && row
<= end_row
&& row
->enabled_p
1573 && row
->y
+ row
->height
< max_y
)
1576 if (row
> end_row
|| !row
->enabled_p
)
1588 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1589 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
1591 make_number (row
->y
),
1592 make_number (crop
));
1595 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1597 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1598 More precisely, return the value assigned by the last call of
1599 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1600 never called with WINDOW as its argument, or the value set by that
1601 function was internally reset since its last call. WINDOW defaults to
1602 the selected window.
1604 When a window is dedicated to its buffer, `display-buffer' will refrain
1605 from displaying another buffer in it. `get-lru-window' and
1606 `get-largest-window' treat dedicated windows specially.
1607 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1608 `kill-buffer' can delete a dedicated window and the containing frame.
1610 Functions like `set-window-buffer' may change the buffer displayed by a
1611 window, unless that window is "strongly" dedicated to its buffer, that
1612 is the value returned by `window-dedicated-p' is t. */)
1613 (Lisp_Object window
)
1615 return WGET (decode_window (window
), dedicated
);
1618 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1619 Sset_window_dedicated_p
, 2, 2, 0,
1620 doc
: /* Mark WINDOW as dedicated according to FLAG.
1621 WINDOW must be a live window and defaults to the selected one. FLAG
1622 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1623 mark WINDOW as non-dedicated. Return FLAG.
1625 When a window is dedicated to its buffer, `display-buffer' will refrain
1626 from displaying another buffer in it. `get-lru-window' and
1627 `get-largest-window' treat dedicated windows specially.
1628 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1629 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1630 and the containing frame.
1632 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1633 its buffer. Functions like `set-window-buffer' may change the buffer
1634 displayed by a window, unless that window is strongly dedicated to its
1635 buffer. If and when `set-window-buffer' displays another buffer in a
1636 window, it also makes sure that the window is no more dedicated. */)
1637 (Lisp_Object window
, Lisp_Object flag
)
1639 return WSET (decode_window (window
), dedicated
, flag
);
1642 DEFUN ("window-prev-buffers", Fwindow_prev_buffers
, Swindow_prev_buffers
,
1644 doc
: /* Return buffers previously shown in WINDOW.
1645 WINDOW must be a live window and defaults to the selected one.
1647 The return value is a list of elements (BUFFER WINDOW-START POS),
1648 where BUFFER is a buffer, WINDOW-START is the start position of the
1649 window for that buffer, and POS is a window-specific point value. */)
1650 (Lisp_Object window
)
1652 return WGET (decode_window (window
), prev_buffers
);
1655 DEFUN ("set-window-prev-buffers", Fset_window_prev_buffers
,
1656 Sset_window_prev_buffers
, 2, 2, 0,
1657 doc
: /* Set WINDOW's previous buffers to PREV-BUFFERS.
1658 WINDOW must be a live window and defaults to the selected one.
1660 PREV-BUFFERS should be a list of elements (BUFFER WINDOW-START POS),
1661 where BUFFER is a buffer, WINDOW-START is the start position of the
1662 window for that buffer, and POS is a window-specific point value. */)
1663 (Lisp_Object window
, Lisp_Object prev_buffers
)
1665 return WSET (decode_window (window
), prev_buffers
, prev_buffers
);
1668 DEFUN ("window-next-buffers", Fwindow_next_buffers
, Swindow_next_buffers
,
1670 doc
: /* Return list of buffers recently re-shown in WINDOW.
1671 WINDOW must be a live window and defaults to the selected one. */)
1672 (Lisp_Object window
)
1674 return WGET (decode_window (window
), next_buffers
);
1677 DEFUN ("set-window-next-buffers", Fset_window_next_buffers
,
1678 Sset_window_next_buffers
, 2, 2, 0,
1679 doc
: /* Set WINDOW's next buffers to NEXT-BUFFERS.
1680 WINDOW must be a live window and defaults to the selected one.
1681 NEXT-BUFFERS should be a list of buffers. */)
1682 (Lisp_Object window
, Lisp_Object next_buffers
)
1684 return WSET (decode_window (window
), next_buffers
, next_buffers
);
1687 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1689 doc
: /* Return the parameters of WINDOW and their values.
1690 WINDOW defaults to the selected window. The return value is a list of
1691 elements of the form (PARAMETER . VALUE). */)
1692 (Lisp_Object window
)
1694 return Fcopy_alist (WGET (decode_any_window (window
), window_parameters
));
1697 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1699 doc
: /* Return WINDOW's value for PARAMETER.
1700 WINDOW defaults to the selected window. */)
1701 (Lisp_Object window
, Lisp_Object parameter
)
1705 result
= Fassq (parameter
, WGET (decode_any_window (window
),
1706 window_parameters
));
1707 return CDR_SAFE (result
);
1710 DEFUN ("set-window-parameter", Fset_window_parameter
,
1711 Sset_window_parameter
, 3, 3, 0,
1712 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1713 WINDOW defaults to the selected window. Return VALUE. */)
1714 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1716 register struct window
*w
= decode_any_window (window
);
1717 Lisp_Object old_alist_elt
;
1719 old_alist_elt
= Fassq (parameter
, WGET (w
, window_parameters
));
1720 if (NILP (old_alist_elt
))
1721 WSET (w
, window_parameters
,
1722 Fcons (Fcons (parameter
, value
), WGET (w
, window_parameters
)));
1724 Fsetcdr (old_alist_elt
, value
);
1728 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1730 doc
: /* Return the display-table that WINDOW is using.
1731 WINDOW defaults to the selected window. */)
1732 (Lisp_Object window
)
1734 return WGET (decode_window (window
), display_table
);
1737 /* Get the display table for use on window W. This is either W's
1738 display table or W's buffer's display table. Ignore the specified
1739 tables if they are not valid; if no valid table is specified,
1742 struct Lisp_Char_Table
*
1743 window_display_table (struct window
*w
)
1745 struct Lisp_Char_Table
*dp
= NULL
;
1747 if (DISP_TABLE_P (WGET (w
, display_table
)))
1748 dp
= XCHAR_TABLE (WGET (w
, display_table
));
1749 else if (BUFFERP (WGET (w
, buffer
)))
1751 struct buffer
*b
= XBUFFER (WGET (w
, buffer
));
1753 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1754 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1755 else if (DISP_TABLE_P (Vstandard_display_table
))
1756 dp
= XCHAR_TABLE (Vstandard_display_table
);
1762 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1763 doc
: /* Set WINDOW's display-table to TABLE. */)
1764 (register Lisp_Object window
, Lisp_Object table
)
1766 return WSET (decode_window (window
), display_table
, table
);
1769 /* Record info on buffer window W is displaying
1770 when it is about to cease to display that buffer. */
1772 unshow_buffer (register struct window
*w
)
1777 buf
= WGET (w
, buffer
);
1779 if (b
!= XMARKER (WGET (w
, pointm
))->buffer
)
1783 if (w
== XWINDOW (selected_window
)
1784 || ! EQ (buf
, WGET (XWINDOW (selected_window
), buffer
)))
1785 /* Do this except when the selected window's buffer
1786 is being removed from some other window. */
1788 /* last_window_start records the start position that this buffer
1789 had in the last window to be disconnected from it.
1790 Now that this statement is unconditional,
1791 it is possible for the buffer to be displayed in the
1792 selected window, while last_window_start reflects another
1793 window which was recently showing the same buffer.
1794 Some people might say that might be a good thing. Let's see. */
1795 b
->last_window_start
= marker_position (WGET (w
, start
));
1797 /* Point in the selected window's buffer
1798 is actually stored in that buffer, and the window's pointm isn't used.
1799 So don't clobber point in that buffer. */
1800 if (! EQ (buf
, WGET (XWINDOW (selected_window
), buffer
))
1801 /* This line helps to fix Horsley's testbug.el bug. */
1802 && !(WINDOWP (BVAR (b
, last_selected_window
))
1803 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1804 && EQ (buf
, WGET (XWINDOW (BVAR (b
, last_selected_window
)), buffer
))))
1805 temp_set_point_both (b
,
1806 clip_to_bounds (BUF_BEGV (b
),
1807 XMARKER (WGET (w
, pointm
))->charpos
,
1809 clip_to_bounds (BUF_BEGV_BYTE (b
),
1810 marker_byte_position (WGET (w
, pointm
)),
1813 if (WINDOWP (BVAR (b
, last_selected_window
))
1814 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1815 BVAR (b
, last_selected_window
) = Qnil
;
1818 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1819 means change window structure only. Otherwise store geometry and
1820 other settings as well. */
1822 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
1824 register Lisp_Object tem
;
1825 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
1827 /* If OLD is its frame's root window, then NEW is the new
1828 root window for that frame. */
1829 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (WGET (o
, frame
)))))
1830 FSET (XFRAME (WGET (o
, frame
)), root_window
, new);
1834 WSET (n
, left_col
, WGET (o
, left_col
));
1835 WSET (n
, top_line
, WGET (o
, top_line
));
1836 WSET (n
, total_cols
, WGET (o
, total_cols
));
1837 WSET (n
, total_lines
, WGET (o
, total_lines
));
1838 WSET (n
, normal_cols
, WGET (o
, normal_cols
));
1839 WSET (o
, normal_cols
, make_float (1.0));
1840 WSET (n
, normal_lines
, WGET (o
, normal_lines
));
1841 WSET (o
, normal_lines
, make_float (1.0));
1842 n
->desired_matrix
= n
->current_matrix
= 0;
1844 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
1845 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
1846 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
1847 n
->phys_cursor_type
= -1;
1848 n
->phys_cursor_width
= -1;
1849 n
->must_be_updated_p
= 0;
1850 n
->pseudo_window_p
= 0;
1851 WSET (n
, window_end_vpos
, make_number (0));
1852 WSET (n
, window_end_pos
, make_number (0));
1853 WSET (n
, window_end_valid
, Qnil
);
1854 n
->frozen_window_start_p
= 0;
1857 tem
= WGET (o
, next
);
1858 WSET (n
, next
, tem
);
1860 WSET (XWINDOW (tem
), prev
, new);
1862 tem
= WGET (o
, prev
);
1863 WSET (n
, prev
, tem
);
1865 WSET (XWINDOW (tem
), next
, new);
1867 tem
= WGET (o
, parent
);
1868 WSET (n
, parent
, tem
);
1871 if (EQ (WGET (XWINDOW (tem
), vchild
), old
))
1872 WSET (XWINDOW (tem
), vchild
, new);
1873 if (EQ (WGET (XWINDOW (tem
), hchild
), old
))
1874 WSET (XWINDOW (tem
), hchild
, new);
1878 /* If window WINDOW and its parent window are iso-combined, merge
1879 WINDOW's children into those of its parent window and mark WINDOW as
1883 recombine_windows (Lisp_Object window
)
1885 struct window
*w
, *p
, *c
;
1886 Lisp_Object parent
, child
;
1889 w
= XWINDOW (window
);
1890 parent
= WGET (w
, parent
);
1891 if (!NILP (parent
) && NILP (WGET (w
, combination_limit
)))
1893 p
= XWINDOW (parent
);
1894 if (((!NILP (WGET (p
, vchild
)) && !NILP (WGET (w
, vchild
)))
1895 || (!NILP (WGET (p
, hchild
)) && !NILP (WGET (w
, hchild
)))))
1896 /* WINDOW and PARENT are both either a vertical or a horizontal
1899 horflag
= NILP (WGET (w
, vchild
));
1900 child
= horflag
? WGET (w
, hchild
) : WGET (w
, vchild
);
1901 c
= XWINDOW (child
);
1903 /* Splice WINDOW's children into its parent's children and
1904 assign new normal sizes. */
1905 if (NILP (WGET (w
, prev
)))
1907 WSET (p
, hchild
, child
);
1909 WSET (p
, vchild
, child
);
1912 WSET (c
, prev
, WGET (w
, prev
));
1913 WSET (XWINDOW (WGET (w
, prev
)), next
, child
);
1918 WSET (c
, parent
, parent
);
1921 WSET (c
, normal_cols
,
1922 make_float (XFLOATINT (WGET (c
, total_cols
))
1923 / XFLOATINT (WGET (p
, total_cols
))));
1925 WSET (c
, normal_lines
,
1926 make_float (XFLOATINT (WGET (c
, total_lines
))
1927 / XFLOATINT (WGET (p
, total_lines
))));
1929 if (NILP (WGET (c
, next
)))
1931 if (!NILP (WGET (w
, next
)))
1933 WSET (c
, next
, WGET (w
, next
));
1934 WSET (XWINDOW (WGET (c
, next
)), prev
, child
);
1941 child
= WGET (c
, next
);
1942 c
= XWINDOW (child
);
1946 /* WINDOW can be deleted now. */
1947 WSET (w
, vchild
, Qnil
);
1948 WSET (w
, hchild
, Qnil
);
1953 /* If WINDOW can be deleted, delete it. */
1955 delete_deletable_window (Lisp_Object window
)
1957 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
1958 call1 (Qdelete_window
, window
);
1961 /***********************************************************************
1963 ***********************************************************************/
1965 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1966 pointer. This is a callback function for foreach_window, used in
1967 the window_list function. */
1970 add_window_to_list (struct window
*w
, void *user_data
)
1972 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1974 XSETWINDOW (window
, w
);
1975 *list
= Fcons (window
, *list
);
1980 /* Return a list of all windows, for use by next_window. If
1981 Vwindow_list is a list, return that list. Otherwise, build a new
1982 list, cache it in Vwindow_list, and return that. */
1987 if (!CONSP (Vwindow_list
))
1991 Vwindow_list
= Qnil
;
1992 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1994 Lisp_Object args
[2];
1996 /* We are visiting windows in canonical order, and add
1997 new windows at the front of args[1], which means we
1998 have to reverse this list at the end. */
2000 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
2001 args
[0] = Vwindow_list
;
2002 args
[1] = Fnreverse (args
[1]);
2003 Vwindow_list
= Fnconc (2, args
);
2007 return Vwindow_list
;
2011 /* Value is non-zero if WINDOW satisfies the constraints given by
2012 OWINDOW, MINIBUF and ALL_FRAMES.
2014 MINIBUF t means WINDOW may be minibuffer windows.
2015 `lambda' means WINDOW may not be a minibuffer window.
2016 a window means a specific minibuffer window
2018 ALL_FRAMES t means search all frames,
2019 nil means search just current frame,
2020 `visible' means search just visible frames on the
2022 0 means search visible and iconified frames on the
2024 a window means search the frame that window belongs to,
2025 a frame means consider windows on that frame, only. */
2028 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2030 struct window
*w
= XWINDOW (window
);
2031 struct frame
*f
= XFRAME (WGET (w
, frame
));
2032 int candidate_p
= 1;
2034 if (!BUFFERP (WGET (w
, buffer
)))
2036 else if (MINI_WINDOW_P (w
)
2037 && (EQ (minibuf
, Qlambda
)
2038 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2040 /* If MINIBUF is `lambda' don't consider any mini-windows.
2041 If it is a window, consider only that one. */
2044 else if (EQ (all_frames
, Qt
))
2046 else if (NILP (all_frames
))
2048 eassert (WINDOWP (owindow
));
2049 candidate_p
= EQ (WGET (w
, frame
), WGET (XWINDOW (owindow
), frame
));
2051 else if (EQ (all_frames
, Qvisible
))
2053 FRAME_SAMPLE_VISIBILITY (f
);
2054 candidate_p
= FRAME_VISIBLE_P (f
)
2055 && (FRAME_TERMINAL (XFRAME (WGET (w
, frame
)))
2056 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2059 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2061 FRAME_SAMPLE_VISIBILITY (f
);
2062 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2063 #ifdef HAVE_X_WINDOWS
2064 /* Yuck!! If we've just created the frame and the
2065 window-manager requested the user to place it
2066 manually, the window may still not be considered
2067 `visible'. I'd argue it should be at least
2068 something like `iconified', but don't know how to do
2070 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2071 && !f
->output_data
.x
->has_been_visible
)
2074 && (FRAME_TERMINAL (XFRAME (WGET (w
, frame
)))
2075 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2077 else if (WINDOWP (all_frames
))
2078 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2079 || EQ (WGET (XWINDOW (all_frames
), frame
), WGET (w
, frame
))
2080 || EQ (WGET (XWINDOW (all_frames
), frame
), FRAME_FOCUS_FRAME (f
)));
2081 else if (FRAMEP (all_frames
))
2082 candidate_p
= EQ (all_frames
, WGET (w
, frame
));
2088 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2089 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2090 MINIBUF, and ALL_FRAMES. */
2093 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2096 *window
= selected_window
;
2098 CHECK_LIVE_WINDOW (*window
);
2100 /* MINIBUF nil may or may not include minibuffers. Decide if it
2102 if (NILP (*minibuf
))
2103 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2104 else if (!EQ (*minibuf
, Qt
))
2107 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2108 => count none of them, or a specific minibuffer window (the
2109 active one) to count. */
2111 /* ALL_FRAMES nil doesn't specify which frames to include. */
2112 if (NILP (*all_frames
))
2114 = (!EQ (*minibuf
, Qlambda
)
2115 ? FRAME_MINIBUF_WINDOW (XFRAME (WGET (XWINDOW (*window
), frame
)))
2117 else if (EQ (*all_frames
, Qvisible
))
2119 else if (EQ (*all_frames
, make_number (0)))
2121 else if (FRAMEP (*all_frames
))
2123 else if (!EQ (*all_frames
, Qt
))
2128 /* Return the next or previous window of WINDOW in cyclic ordering
2129 of windows. NEXT_P non-zero means return the next window. See the
2130 documentation string of next-window for the meaning of MINIBUF and
2134 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2136 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2138 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2139 return the first window on the frame. */
2140 if (FRAMEP (all_frames
)
2141 && !EQ (all_frames
, WGET (XWINDOW (window
), frame
)))
2142 return Fframe_first_window (all_frames
);
2148 /* Find WINDOW in the list of all windows. */
2149 list
= Fmemq (window
, window_list ());
2151 /* Scan forward from WINDOW to the end of the window list. */
2153 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2154 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2157 /* Scan from the start of the window list up to WINDOW. */
2159 for (list
= Vwindow_list
;
2160 CONSP (list
) && !EQ (XCAR (list
), window
);
2162 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2166 window
= XCAR (list
);
2170 Lisp_Object candidate
, list
;
2172 /* Scan through the list of windows for candidates. If there are
2173 candidate windows in front of WINDOW, the last one of these
2174 is the one we want. If there are candidates following WINDOW
2175 in the list, again the last one of these is the one we want. */
2177 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2179 if (EQ (XCAR (list
), window
))
2181 if (WINDOWP (candidate
))
2184 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2186 candidate
= XCAR (list
);
2189 if (WINDOWP (candidate
))
2197 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2198 doc
: /* Return live window after WINDOW in the cyclic ordering of windows.
2199 WINDOW must be a live window and defaults to the selected one. The
2200 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2203 MINIBUF nil or omitted means consider the minibuffer window only if the
2204 minibuffer is active. MINIBUF t means consider the minibuffer window
2205 even if the minibuffer is not active. Any other value means do not
2206 consider the minibuffer window even if the minibuffer is active.
2208 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2209 plus the minibuffer window if specified by the MINIBUF argument. If the
2210 minibuffer counts, consider all windows on all frames that share that
2211 minibuffer too. The following non-nil values of ALL-FRAMES have special
2214 - t means consider all windows on all existing frames.
2216 - `visible' means consider all windows on all visible frames.
2218 - 0 (the number zero) means consider all windows on all visible and
2221 - A frame means consider all windows on that frame only.
2223 Anything else means consider all windows on WINDOW's frame and no
2226 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2227 `next-window' to iterate through the entire cycle of acceptable
2228 windows, eventually ending up back at the window you started with.
2229 `previous-window' traverses the same cycle, in the reverse order. */)
2230 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2232 return next_window (window
, minibuf
, all_frames
, 1);
2236 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2237 doc
: /* Return live window before WINDOW in the cyclic ordering of windows.
2238 WINDOW must be a live window and defaults to the selected one. The
2239 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2242 MINIBUF nil or omitted means consider the minibuffer window only if the
2243 minibuffer is active. MINIBUF t means consider the minibuffer window
2244 even if the minibuffer is not active. Any other value means do not
2245 consider the minibuffer window even if the minibuffer is active.
2247 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2248 plus the minibuffer window if specified by the MINIBUF argument. If the
2249 minibuffer counts, consider all windows on all frames that share that
2250 minibuffer too. The following non-nil values of ALL-FRAMES have special
2253 - t means consider all windows on all existing frames.
2255 - `visible' means consider all windows on all visible frames.
2257 - 0 (the number zero) means consider all windows on all visible and
2260 - A frame means consider all windows on that frame only.
2262 Anything else means consider all windows on WINDOW's frame and no
2265 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2266 use `previous-window' to iterate through the entire cycle of
2267 acceptable windows, eventually ending up back at the window you
2268 started with. `next-window' traverses the same cycle, in the
2270 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2272 return next_window (window
, minibuf
, all_frames
, 0);
2276 /* Return a list of windows in cyclic ordering. Arguments are like
2277 for `next-window'. */
2280 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2282 Lisp_Object tail
, list
, rest
;
2284 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2287 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2288 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2289 list
= Fcons (XCAR (tail
), list
);
2291 /* Rotate the list to start with WINDOW. */
2292 list
= Fnreverse (list
);
2293 rest
= Fmemq (window
, list
);
2294 if (!NILP (rest
) && !EQ (rest
, list
))
2296 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2298 XSETCDR (tail
, Qnil
);
2299 list
= nconc2 (rest
, list
);
2305 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2306 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2307 FRAME nil or omitted means use the selected frame.
2308 WINDOW nil or omitted means use the window selected within FRAME.
2309 MINIBUF t means include the minibuffer window, even if it isn't active.
2310 MINIBUF nil or omitted means include the minibuffer window only
2312 MINIBUF neither nil nor t means never include the minibuffer window. */)
2313 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2316 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2317 CHECK_WINDOW (window
);
2319 frame
= selected_frame
;
2321 if (!EQ (frame
, WGET (XWINDOW (window
), frame
)))
2322 error ("Window is on a different frame");
2324 return window_list_1 (window
, minibuf
, frame
);
2328 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2329 doc
: /* Return a list of all live windows.
2330 WINDOW specifies the first window to list and defaults to the selected
2333 Optional argument MINIBUF nil or omitted means consider the minibuffer
2334 window only if the minibuffer is active. MINIBUF t means consider the
2335 minibuffer window even if the minibuffer is not active. Any other value
2336 means do not consider the minibuffer window even if the minibuffer is
2339 Optional argument ALL-FRAMES nil or omitted means consider all windows
2340 on WINDOW's frame, plus the minibuffer window if specified by the
2341 MINIBUF argument. If the minibuffer counts, consider all windows on all
2342 frames that share that minibuffer too. The following non-nil values of
2343 ALL-FRAMES have special meanings:
2345 - t means consider all windows on all existing frames.
2347 - `visible' means consider all windows on all visible frames.
2349 - 0 (the number zero) means consider all windows on all visible and
2352 - A frame means consider all windows on that frame only.
2354 Anything else means consider all windows on WINDOW's frame and no
2357 If WINDOW is not on the list of windows returned, some other window will
2358 be listed first but no error is signaled. */)
2359 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2361 return window_list_1 (window
, minibuf
, all_frames
);
2364 /* Look at all windows, performing an operation specified by TYPE
2366 If FRAMES is Qt, look at all frames;
2367 Qnil, look at just the selected frame;
2368 Qvisible, look at visible frames;
2369 a frame, just look at windows on that frame.
2370 If MINI is non-zero, perform the operation on minibuffer windows too. */
2375 GET_BUFFER_WINDOW
, /* Arg is buffer */
2376 REPLACE_BUFFER_IN_WINDOWS_SAFELY
, /* Arg is buffer */
2377 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2382 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2384 Lisp_Object window
, windows
, best_window
, frame_arg
;
2385 int frame_best_window_flag
= 0;
2387 struct gcpro gcpro1
;
2389 /* If we're only looping through windows on a particular frame,
2390 frame points to that frame. If we're looping through windows
2391 on all frames, frame is 0. */
2392 if (FRAMEP (frames
))
2393 f
= XFRAME (frames
);
2394 else if (NILP (frames
))
2395 f
= SELECTED_FRAME ();
2400 frame_arg
= Qlambda
;
2401 else if (EQ (frames
, make_number (0)))
2403 else if (EQ (frames
, Qvisible
))
2408 /* frame_arg is Qlambda to stick to one frame,
2409 Qvisible to consider all visible frames,
2412 /* Pick a window to start with. */
2416 window
= FRAME_SELECTED_WINDOW (f
);
2418 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2420 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2424 for (; CONSP (windows
); windows
= XCDR (windows
))
2428 window
= XCAR (windows
);
2429 w
= XWINDOW (window
);
2431 /* Note that we do not pay attention here to whether the frame
2432 is visible, since Fwindow_list skips non-visible frames if
2433 that is desired, under the control of frame_arg. */
2434 if (!MINI_WINDOW_P (w
)
2435 /* For REPLACE_BUFFER_IN_WINDOWS_SAFELY, we must always
2436 consider all windows. */
2437 || type
== REPLACE_BUFFER_IN_WINDOWS_SAFELY
2438 || (mini
&& minibuf_level
> 0))
2441 case GET_BUFFER_WINDOW
:
2442 if (EQ (WGET (w
, buffer
), obj
)
2443 /* Don't find any minibuffer window except the one that
2444 is currently in use. */
2445 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2447 if (EQ (window
, selected_window
))
2448 /* Preferably return the selected window. */
2449 RETURN_UNGCPRO (window
);
2450 else if (EQ (WGET (XWINDOW (window
), frame
), selected_frame
)
2451 && !frame_best_window_flag
)
2452 /* Prefer windows on the current frame (but don't
2453 choose another one if we have one already). */
2455 best_window
= window
;
2456 frame_best_window_flag
= 1;
2458 else if (NILP (best_window
))
2459 best_window
= window
;
2463 case REPLACE_BUFFER_IN_WINDOWS_SAFELY
:
2464 /* We could simply check whether the buffer shown by window
2465 is live, and show another buffer in case it isn't. */
2466 if (EQ (WGET (w
, buffer
), obj
))
2468 /* Undedicate WINDOW. */
2469 WSET (w
, dedicated
, Qnil
);
2470 /* Make WINDOW show the buffer returned by
2471 other_buffer_safely, don't run any hooks. */
2473 (window
, other_buffer_safely (WGET (w
, buffer
)), 0, 0);
2474 /* If WINDOW is the selected window, make its buffer
2475 current. But do so only if the window shows the
2476 current buffer (Bug#6454). */
2477 if (EQ (window
, selected_window
)
2478 && XBUFFER (WGET (w
, buffer
)) == current_buffer
)
2479 Fset_buffer (WGET (w
, buffer
));
2483 case REDISPLAY_BUFFER_WINDOWS
:
2484 if (EQ (WGET (w
, buffer
), obj
))
2486 mark_window_display_accurate (window
, 0);
2487 w
->update_mode_line
= 1;
2488 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2489 ++update_mode_lines
;
2490 best_window
= window
;
2494 /* Check for a window that has a killed buffer. */
2495 case CHECK_ALL_WINDOWS
:
2496 if (! NILP (WGET (w
, buffer
))
2497 && NILP (BVAR (XBUFFER (WGET (w
, buffer
)), name
)))
2501 case WINDOW_LOOP_UNUSED
:
2510 /* Used for debugging. Abort if any window has a dead buffer. */
2512 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2514 check_all_windows (void)
2516 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2519 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2520 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2521 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2524 The optional argument ALL-FRAMES specifies the frames to consider:
2526 - t means consider all windows on all existing frames.
2528 - `visible' means consider all windows on all visible frames.
2530 - 0 (the number zero) means consider all windows on all visible
2531 and iconified frames.
2533 - A frame means consider all windows on that frame only.
2535 Any other value of ALL-FRAMES means consider all windows on the
2536 selected frame and no others. */)
2537 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2541 if (NILP (buffer_or_name
))
2542 buffer
= Fcurrent_buffer ();
2544 buffer
= Fget_buffer (buffer_or_name
);
2546 if (BUFFERP (buffer
))
2547 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2553 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2555 return call4 (Qwindow_resize_root_window
, window
, delta
, horizontal
, ignore
);
2559 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2560 Sdelete_other_windows_internal
, 0, 2, "",
2561 doc
: /* Make WINDOW fill its frame.
2562 Only the frame WINDOW is on is affected. WINDOW may be any window and
2563 defaults to the selected one.
2565 Optional argument ROOT, if non-nil, must specify an internal window such
2566 that WINDOW is in its window subtree. If this is the case, replace ROOT
2567 by WINDOW and leave alone any windows not part of ROOT's subtree.
2569 When WINDOW is live try to reduce display jumps by keeping the text
2570 previously visible in WINDOW in the same place on the frame. Doing this
2571 depends on the value of (window-start WINDOW), so if calling this
2572 function in a program gives strange scrolling, make sure the
2573 window-start value is reasonable when this function is called. */)
2574 (Lisp_Object window
, Lisp_Object root
)
2576 struct window
*w
, *r
, *s
;
2578 Lisp_Object sibling
, pwindow
, swindow
IF_LINT (= Qnil
), delta
;
2579 ptrdiff_t startpos
IF_LINT (= 0);
2580 int top
IF_LINT (= 0), new_top
, resize_failed
;
2582 w
= decode_any_window (window
);
2583 XSETWINDOW (window
, w
);
2584 f
= XFRAME (WGET (w
, frame
));
2587 /* ROOT is the frame's root window. */
2589 root
= FRAME_ROOT_WINDOW (f
);
2593 /* ROOT must be an ancestor of WINDOW. */
2595 r
= decode_any_window (root
);
2596 pwindow
= WGET (XWINDOW (window
), parent
);
2597 while (!NILP (pwindow
))
2598 if (EQ (pwindow
, root
))
2601 pwindow
= WGET (XWINDOW (pwindow
), parent
);
2602 if (!EQ (pwindow
, root
))
2603 error ("Specified root is not an ancestor of specified window");
2606 if (EQ (window
, root
))
2609 /* I don't understand the "top > 0" part below. If we deal with a
2610 standalone minibuffer it would have been caught by the preceding
2612 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2613 error ("Can't expand minibuffer to full frame");
2615 if (!NILP (WGET (w
, buffer
)))
2617 startpos
= marker_position (WGET (w
, start
));
2618 top
= WINDOW_TOP_EDGE_LINE (w
)
2619 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2620 /* Make sure WINDOW is the frame's selected window. */
2621 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2623 if (EQ (selected_frame
, WGET (w
, frame
)))
2624 Fselect_window (window
, Qnil
);
2626 FSET (f
, selected_window
, window
);
2631 /* See if the frame's selected window is a part of the window
2632 subtree rooted at WINDOW, by finding all the selected window's
2633 parents and comparing each one with WINDOW. If it isn't we
2634 need a new selected window for this frame. */
2635 swindow
= FRAME_SELECTED_WINDOW (f
);
2639 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2640 pwindow
= WGET (XWINDOW (pwindow
), parent
);
2642 if (EQ (window
, pwindow
))
2643 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2644 as the new selected window. */
2647 /* Else try the previous window of SWINDOW. */
2648 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2651 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2653 if (EQ (selected_frame
, WGET (w
, frame
)))
2654 Fselect_window (swindow
, Qnil
);
2656 FSET (f
, selected_window
, swindow
);
2661 if (!FRAME_INITIAL_P (f
))
2663 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
2665 /* We are going to free the glyph matrices of WINDOW, and with
2666 that we might lose any information about glyph rows that have
2667 some of their glyphs highlighted in mouse face. (These rows
2668 are marked with a non-zero mouse_face_p flag.) If WINDOW
2669 indeed has some glyphs highlighted in mouse face, signal to
2670 frame's up-to-date hook that mouse highlight was overwritten,
2671 so that it will arrange for redisplaying the highlight. */
2672 if (EQ (hlinfo
->mouse_face_window
, window
))
2674 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
2675 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
2676 hlinfo
->mouse_face_window
= Qnil
;
2679 free_window_matrices (r
);
2681 windows_or_buffers_changed
++;
2682 Vwindow_list
= Qnil
;
2683 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2686 if (NILP (WGET (w
, buffer
)))
2688 /* Resize child windows vertically. */
2689 XSETINT (delta
, XINT (WGET (r
, total_lines
))
2690 - XINT (WGET (w
, total_lines
)));
2691 WSET (w
, top_line
, WGET (r
, top_line
));
2692 resize_root_window (window
, delta
, Qnil
, Qnil
);
2693 if (window_resize_check (w
, 0))
2694 window_resize_apply (w
, 0);
2697 resize_root_window (window
, delta
, Qnil
, Qt
);
2698 if (window_resize_check (w
, 0))
2699 window_resize_apply (w
, 0);
2704 /* Resize child windows horizontally. */
2707 WSET (w
, left_col
, WGET (r
, left_col
));
2708 XSETINT (delta
, XINT (WGET (r
, total_cols
))
2709 - XINT (WGET (w
, total_cols
)));
2710 WSET (w
, left_col
, WGET (r
, left_col
));
2711 resize_root_window (window
, delta
, Qt
, Qnil
);
2712 if (window_resize_check (w
, 1))
2713 window_resize_apply (w
, 1);
2716 resize_root_window (window
, delta
, Qt
, Qt
);
2717 if (window_resize_check (w
, 1))
2718 window_resize_apply (w
, 1);
2725 /* Play safe, if we still can ... */
2728 w
= XWINDOW (window
);
2732 /* Cleanly unlink WINDOW from window-tree. */
2733 if (!NILP (WGET (w
, prev
)))
2734 /* Get SIBLING above (on the left of) WINDOW. */
2736 sibling
= WGET (w
, prev
);
2737 s
= XWINDOW (sibling
);
2738 WSET (s
, next
, WGET (w
, next
));
2739 if (!NILP (WGET (s
, next
)))
2740 WSET (XWINDOW (WGET (s
, next
)), prev
, sibling
);
2743 /* Get SIBLING below (on the right of) WINDOW. */
2745 sibling
= WGET (w
, next
);
2746 s
= XWINDOW (sibling
);
2747 WSET (s
, prev
, Qnil
);
2748 if (!NILP (WGET (XWINDOW (WGET (w
, parent
)), vchild
)))
2749 WSET (XWINDOW (WGET (w
, parent
)), vchild
, sibling
);
2751 WSET (XWINDOW (WGET (w
, parent
)), hchild
, sibling
);
2754 /* Delete ROOT and all child windows of ROOT. */
2755 if (!NILP (WGET (r
, vchild
)))
2757 delete_all_child_windows (WGET (r
, vchild
));
2758 WSET (r
, vchild
, Qnil
);
2760 else if (!NILP (WGET (r
, hchild
)))
2762 delete_all_child_windows (WGET (r
, hchild
));
2763 WSET (r
, hchild
, Qnil
);
2766 replace_window (root
, window
, 1);
2768 /* This must become SWINDOW anyway ....... */
2769 if (!NILP (WGET (w
, buffer
)) && !resize_failed
)
2771 /* Try to minimize scrolling, by setting the window start to the
2772 point will cause the text at the old window start to be at the
2773 same place on the frame. But don't try to do this if the
2774 window start is outside the visible portion (as might happen
2775 when the display is not current, due to typeahead). */
2776 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2778 && startpos
>= BUF_BEGV (XBUFFER (WGET (w
, buffer
)))
2779 && startpos
<= BUF_ZV (XBUFFER (WGET (w
, buffer
))))
2781 struct position pos
;
2782 struct buffer
*obuf
= current_buffer
;
2784 Fset_buffer (WGET (w
, buffer
));
2785 /* This computation used to temporarily move point, but that
2786 can have unwanted side effects due to text properties. */
2787 pos
= *vmotion (startpos
, -top
, w
);
2789 set_marker_both (WGET (w
, start
), WGET (w
, buffer
), pos
.bufpos
, pos
.bytepos
);
2790 WSET (w
, window_end_valid
, Qnil
);
2791 w
->start_at_line_beg
= (pos
.bytepos
== BEGV_BYTE
2792 || FETCH_BYTE (pos
.bytepos
- 1) == '\n');
2793 /* We need to do this, so that the window-scroll-functions
2795 w
->optional_new_start
= 1;
2797 set_buffer_internal (obuf
);
2804 run_window_configuration_change_hook (f
);
2811 replace_buffer_in_windows (Lisp_Object buffer
)
2813 call1 (Qreplace_buffer_in_windows
, buffer
);
2817 /* Safely replace BUFFER with some other buffer in all windows of all
2818 frames, even those on other keyboards. */
2821 replace_buffer_in_windows_safely (Lisp_Object buffer
)
2823 Lisp_Object tail
, frame
;
2825 /* A single call to window_loop won't do the job because it only
2826 considers frames on the current keyboard. So loop manually over
2827 frames, and handle each one. */
2828 FOR_EACH_FRAME (tail
, frame
)
2829 window_loop (REPLACE_BUFFER_IN_WINDOWS_SAFELY
, buffer
, 1, frame
);
2832 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2833 minimum allowable size. */
2836 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
2838 /* For height, we have to see:
2839 how many windows the frame has at minimum (one or two),
2840 and whether it has a menu bar or other special stuff at the top. */
2842 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2843 ? MIN_SAFE_WINDOW_HEIGHT
2844 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2846 if (FRAME_TOP_MARGIN (frame
) > 0)
2847 min_height
+= FRAME_TOP_MARGIN (frame
);
2849 if (*rows
< min_height
)
2851 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2852 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2855 /* Adjust the margins of window W if text area is too small.
2856 Return 1 if window width is ok after adjustment; 0 if window
2857 is still too narrow. */
2860 adjust_window_margins (struct window
*w
)
2862 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2863 - WINDOW_FRINGE_COLS (w
)
2864 - WINDOW_SCROLL_BAR_COLS (w
));
2865 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2866 + WINDOW_RIGHT_MARGIN_COLS (w
));
2868 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2871 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2874 /* Window's text area is too narrow, but reducing the window
2875 margins will fix that. */
2876 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2877 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2879 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2881 WSET (w
, left_margin_cols
, make_number (margin_cols
/ 2));
2882 WSET (w
, right_margin_cols
, make_number (margin_cols
/ 2));
2885 WSET (w
, right_margin_cols
, make_number (margin_cols
));
2888 WSET (w
, left_margin_cols
, make_number (margin_cols
));
2892 /* The following three routines are needed for running a window's
2893 configuration change hook. */
2895 run_funs (Lisp_Object funs
)
2897 for (; CONSP (funs
); funs
= XCDR (funs
))
2898 if (!EQ (XCAR (funs
), Qt
))
2899 call0 (XCAR (funs
));
2903 select_window_norecord (Lisp_Object window
)
2905 return WINDOW_LIVE_P (window
)
2906 ? Fselect_window (window
, Qt
) : selected_window
;
2910 select_frame_norecord (Lisp_Object frame
)
2912 return FRAME_LIVE_P (XFRAME (frame
))
2913 ? Fselect_frame (frame
, Qt
) : selected_frame
;
2917 run_window_configuration_change_hook (struct frame
*f
)
2919 ptrdiff_t count
= SPECPDL_INDEX ();
2920 Lisp_Object frame
, global_wcch
2921 = Fdefault_value (Qwindow_configuration_change_hook
);
2922 XSETFRAME (frame
, f
);
2924 if (NILP (Vrun_hooks
) || !NILP (inhibit_lisp_code
))
2927 /* Use the right buffer. Matters when running the local hooks. */
2928 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
2930 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
2931 Fset_buffer (Fwindow_buffer (Qnil
));
2934 if (SELECTED_FRAME () != f
)
2936 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
2937 select_frame_norecord (frame
);
2940 /* Look for buffer-local values. */
2942 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
2943 for (; CONSP (windows
); windows
= XCDR (windows
))
2945 Lisp_Object window
= XCAR (windows
);
2946 Lisp_Object buffer
= Fwindow_buffer (window
);
2947 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
2950 ptrdiff_t inner_count
= SPECPDL_INDEX ();
2951 record_unwind_protect (select_window_norecord
, Fselected_window ());
2952 select_window_norecord (window
);
2953 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
2955 unbind_to (inner_count
, Qnil
);
2960 run_funs (global_wcch
);
2961 unbind_to (count
, Qnil
);
2964 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
2965 Srun_window_configuration_change_hook
, 1, 1, 0,
2966 doc
: /* Run `window-configuration-change-hook' for FRAME. */)
2969 CHECK_LIVE_FRAME (frame
);
2970 run_window_configuration_change_hook (XFRAME (frame
));
2974 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2975 means it's allowed to run hooks. See make_frame for a case where
2976 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2977 margins, fringes, and scroll-bar settings of the window are not
2978 reset from the buffer's local settings. */
2981 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
2983 struct window
*w
= XWINDOW (window
);
2984 struct buffer
*b
= XBUFFER (buffer
);
2985 ptrdiff_t count
= SPECPDL_INDEX ();
2986 int samebuf
= EQ (buffer
, WGET (w
, buffer
));
2988 WSET (w
, buffer
, buffer
);
2990 if (EQ (window
, selected_window
))
2991 BVAR (b
, last_selected_window
) = window
;
2993 /* Let redisplay errors through. */
2994 b
->display_error_modiff
= 0;
2996 /* Update time stamps of buffer display. */
2997 if (INTEGERP (BVAR (b
, display_count
)))
2998 XSETINT (BVAR (b
, display_count
), XINT (BVAR (b
, display_count
)) + 1);
2999 BVAR (b
, display_time
) = Fcurrent_time ();
3001 WSET (w
, window_end_pos
, make_number (0));
3002 WSET (w
, window_end_vpos
, make_number (0));
3003 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3004 WSET (w
, window_end_valid
, Qnil
);
3005 if (!(keep_margins_p
&& samebuf
))
3006 { /* If we're not actually changing the buffer, don't reset hscroll and
3007 vscroll. This case happens for example when called from
3008 change_frame_size_1, where we use a dummy call to
3009 Fset_window_buffer on the frame's selected window (and no other)
3010 just in order to run window-configuration-change-hook.
3011 Resetting hscroll and vscroll here is problematic for things like
3012 image-mode and doc-view-mode since it resets the image's position
3013 whenever we resize the frame. */
3014 w
->hscroll
= w
->min_hscroll
= 0;
3016 set_marker_both (WGET (w
, pointm
), buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3017 set_marker_restricted (WGET (w
, start
),
3018 make_number (b
->last_window_start
),
3020 w
->start_at_line_beg
= 0;
3022 w
->last_modified
= 0;
3023 w
->last_overlay_modified
= 0;
3025 /* Maybe we could move this into the `if' but it's not obviously safe and
3026 I doubt it's worth the trouble. */
3027 windows_or_buffers_changed
++;
3029 /* We must select BUFFER for running the window-scroll-functions. */
3030 /* We can't check ! NILP (Vwindow_scroll_functions) here
3031 because that might itself be a local variable. */
3032 if (window_initialized
)
3034 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3035 Fset_buffer (buffer
);
3038 XMARKER (WGET (w
, pointm
))->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3040 if (!keep_margins_p
)
3042 /* Set left and right marginal area width etc. from buffer. */
3044 /* This may call adjust_window_margins three times, so
3045 temporarily disable window margins. */
3046 Lisp_Object save_left
= WGET (w
, left_margin_cols
);
3047 Lisp_Object save_right
= WGET (w
, right_margin_cols
);
3049 WSET (w
, left_margin_cols
, Qnil
);
3050 WSET (w
, right_margin_cols
, Qnil
);
3052 Fset_window_fringes (window
,
3053 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3054 BVAR (b
, fringes_outside_margins
));
3056 Fset_window_scroll_bars (window
,
3057 BVAR (b
, scroll_bar_width
),
3058 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3060 WSET (w
, left_margin_cols
, save_left
);
3061 WSET (w
, right_margin_cols
, save_right
);
3063 Fset_window_margins (window
,
3064 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3069 if (! NILP (Vwindow_scroll_functions
))
3070 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3071 Fmarker_position (WGET (w
, start
)));
3072 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3075 unbind_to (count
, Qnil
);
3078 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3079 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3080 WINDOW has to be a live window and defaults to the selected one.
3081 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3083 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3084 display margins, fringe widths, and scroll bar settings are preserved;
3085 the default is to reset these from the local settings for BUFFER-OR-NAME
3086 or the frame defaults. Return nil.
3088 This function throws an error when WINDOW is strongly dedicated to its
3089 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3090 already display BUFFER-OR-NAME.
3092 This function runs `window-scroll-functions' before running
3093 `window-configuration-change-hook'. */)
3094 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3096 register Lisp_Object tem
, buffer
;
3097 register struct window
*w
= decode_window (window
);
3099 XSETWINDOW (window
, w
);
3100 buffer
= Fget_buffer (buffer_or_name
);
3101 CHECK_BUFFER (buffer
);
3102 if (NILP (BVAR (XBUFFER (buffer
), name
)))
3103 error ("Attempt to display deleted buffer");
3105 tem
= WGET (w
, buffer
);
3107 error ("Window is deleted");
3108 else if (!EQ (tem
, Qt
))
3109 /* w->buffer is t when the window is first being set up. */
3111 if (!EQ (tem
, buffer
))
3113 if (EQ (WGET (w
, dedicated
), Qt
))
3114 /* WINDOW is strongly dedicated to its buffer, signal an
3116 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3118 /* WINDOW is weakly dedicated to its buffer, reset
3120 WSET (w
, dedicated
, Qnil
);
3122 call1 (Qrecord_window_buffer
, window
);
3128 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3134 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3136 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3139 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3141 doc
: /* Force all windows to be updated on next redisplay.
3142 If optional arg OBJECT is a window, force redisplay of that window only.
3143 If OBJECT is a buffer or buffer name, force redisplay of all windows
3144 displaying that buffer. */)
3145 (Lisp_Object object
)
3149 windows_or_buffers_changed
++;
3150 update_mode_lines
++;
3154 if (WINDOWP (object
))
3156 struct window
*w
= XWINDOW (object
);
3157 mark_window_display_accurate (object
, 0);
3158 w
->update_mode_line
= 1;
3159 if (BUFFERP (WGET (w
, buffer
)))
3160 XBUFFER (WGET (w
, buffer
))->prevent_redisplay_optimizations_p
= 1;
3161 ++update_mode_lines
;
3165 if (STRINGP (object
))
3166 object
= Fget_buffer (object
);
3167 if (BUFFERP (object
) && !NILP (BVAR (XBUFFER (object
), name
)))
3169 /* Walk all windows looking for buffer, and force update
3170 of each of those windows. */
3172 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3173 return NILP (object
) ? Qnil
: Qt
;
3176 /* If nothing suitable was found, just return.
3177 We could signal an error, but this feature will typically be used
3178 asynchronously in timers or process sentinels, so we don't. */
3184 temp_output_buffer_show (register Lisp_Object buf
)
3186 register struct buffer
*old
= current_buffer
;
3187 register Lisp_Object window
;
3188 register struct window
*w
;
3190 BVAR (XBUFFER (buf
), directory
) = BVAR (current_buffer
, directory
);
3193 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3197 set_buffer_internal (old
);
3199 if (!NILP (Vtemp_buffer_show_function
))
3200 call1 (Vtemp_buffer_show_function
, buf
);
3203 window
= display_buffer (buf
, Qnil
, Qnil
);
3205 if (!EQ (WGET (XWINDOW (window
), frame
), selected_frame
))
3206 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3207 Vminibuf_scroll_window
= window
;
3208 w
= XWINDOW (window
);
3211 set_marker_restricted_both (WGET (w
, start
), buf
, BEG
, BEG
);
3212 set_marker_restricted_both (WGET (w
, pointm
), buf
, BEG
, BEG
);
3214 /* Run temp-buffer-show-hook, with the chosen window selected
3215 and its buffer current. */
3217 ptrdiff_t count
= SPECPDL_INDEX ();
3218 Lisp_Object prev_window
, prev_buffer
;
3219 prev_window
= selected_window
;
3220 XSETBUFFER (prev_buffer
, old
);
3222 /* Select the window that was chosen, for running the hook.
3223 Note: Both Fselect_window and select_window_norecord may
3224 set-buffer to the buffer displayed in the window,
3225 so we need to save the current buffer. --stef */
3226 record_unwind_protect (Fset_buffer
, prev_buffer
);
3227 record_unwind_protect (select_window_norecord
, prev_window
);
3228 Fselect_window (window
, Qt
);
3229 Fset_buffer (WGET (w
, buffer
));
3230 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3231 unbind_to (count
, Qnil
);
3236 DEFUN ("internal-temp-output-buffer-show",
3237 Ftemp_output_buffer_show
, Stemp_output_buffer_show
,
3239 doc
: /* Internal function for `with-output-to-temp-buffer'. */)
3242 temp_output_buffer_show (buf
);
3246 /* Make new window, have it replace WINDOW in window-tree, and make
3247 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3248 horizontal child). */
3250 make_parent_window (Lisp_Object window
, int horflag
)
3253 register struct window
*o
, *p
;
3255 o
= XWINDOW (window
);
3256 p
= allocate_window ();
3257 memcpy ((char *) p
+ sizeof (struct vectorlike_header
),
3258 (char *) o
+ sizeof (struct vectorlike_header
),
3259 word_size
* VECSIZE (struct window
));
3260 XSETWINDOW (parent
, p
);
3262 p
->sequence_number
= ++sequence_number
;
3264 replace_window (window
, parent
, 1);
3266 WSET (o
, next
, Qnil
);
3267 WSET (o
, prev
, Qnil
);
3268 WSET (o
, parent
, parent
);
3270 WSET (p
, hchild
, horflag
? window
: Qnil
);
3271 WSET (p
, vchild
, horflag
? Qnil
: window
);
3272 WSET (p
, start
, Qnil
);
3273 WSET (p
, pointm
, Qnil
);
3274 WSET (p
, buffer
, Qnil
);
3275 WSET (p
, combination_limit
, Qnil
);
3276 WSET (p
, window_parameters
, Qnil
);
3279 /* Make new window from scratch. */
3284 register struct window
*w
;
3286 w
= allocate_window ();
3287 /* Initialize Lisp data. Note that allocate_window initializes all
3288 Lisp data to nil, so do it only for slots which should not be nil. */
3289 WSET (w
, left_col
, make_number (0));
3290 WSET (w
, top_line
, make_number (0));
3291 WSET (w
, total_lines
, make_number (0));
3292 WSET (w
, total_cols
, make_number (0));
3293 WSET (w
, normal_lines
, make_float (1.0));
3294 WSET (w
, normal_cols
, make_float (1.0));
3295 WSET (w
, new_total
, make_number (0));
3296 WSET (w
, new_normal
, make_number (0));
3297 WSET (w
, start
, Fmake_marker ());
3298 WSET (w
, pointm
, Fmake_marker ());
3299 WSET (w
, vertical_scroll_bar_type
, Qt
);
3300 WSET (w
, window_end_pos
, make_number (0));
3301 WSET (w
, window_end_vpos
, make_number (0));
3303 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3304 non-Lisp data, so do it only for slots which should not be zero. */
3305 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3306 w
->phys_cursor_type
= -1;
3307 w
->phys_cursor_width
= -1;
3308 w
->sequence_number
= ++sequence_number
;
3310 /* Reset window_list. */
3311 Vwindow_list
= Qnil
;
3312 /* Return window. */
3313 XSETWINDOW (window
, w
);
3317 DEFUN ("set-window-new-total", Fset_window_new_total
, Sset_window_new_total
, 2, 3, 0,
3318 doc
: /* Set new total size of WINDOW to SIZE.
3321 Optional argument ADD non-nil means add SIZE to the new total size of
3322 WINDOW and return the sum.
3324 Note: This function does not operate on any child windows of WINDOW. */)
3325 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3327 struct window
*w
= decode_any_window (window
);
3329 CHECK_NUMBER (size
);
3331 WSET (w
, new_total
, size
);
3333 WSET (w
, new_total
, make_number (XINT (WGET (w
, new_total
)) + XINT (size
)));
3335 return WGET (w
, new_total
);
3338 DEFUN ("set-window-new-normal", Fset_window_new_normal
, Sset_window_new_normal
, 1, 2, 0,
3339 doc
: /* Set new normal size of WINDOW to SIZE.
3342 Note: This function does not operate on any child windows of WINDOW. */)
3343 (Lisp_Object window
, Lisp_Object size
)
3345 return WSET (decode_any_window (window
), new_normal
, size
);
3348 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3349 non-zero) to w->new_total would result in correct heights (widths)
3350 for window W and recursively all child windows of W.
3352 Note: This function does not check any of `window-fixed-size-p',
3353 `window-min-height' or `window-min-width'. It does check that window
3354 sizes do not drop below one line (two columns). */
3356 window_resize_check (struct window
*w
, int horflag
)
3360 if (!NILP (WGET (w
, vchild
)))
3361 /* W is a vertical combination. */
3363 c
= XWINDOW (WGET (w
, vchild
));
3365 /* All child windows of W must have the same width as W. */
3369 if ((XINT (WGET (c
, new_total
)) != XINT (WGET (w
, new_total
)))
3370 || !window_resize_check (c
, horflag
))
3372 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3377 /* The sum of the heights of the child windows of W must equal
3380 int sum_of_sizes
= 0;
3383 if (!window_resize_check (c
, horflag
))
3385 sum_of_sizes
= sum_of_sizes
+ XINT (WGET (c
, new_total
));
3386 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3388 return (sum_of_sizes
== XINT (WGET (w
, new_total
)));
3391 else if (!NILP (WGET (w
, hchild
)))
3392 /* W is a horizontal combination. */
3394 c
= XWINDOW (WGET (w
, hchild
));
3396 /* The sum of the widths of the child windows of W must equal W's
3399 int sum_of_sizes
= 0;
3402 if (!window_resize_check (c
, horflag
))
3404 sum_of_sizes
= sum_of_sizes
+ XINT (WGET (c
, new_total
));
3405 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3407 return (sum_of_sizes
== XINT (WGET (w
, new_total
)));
3410 /* All child windows of W must have the same height as W. */
3414 if ((XINT (WGET (c
, new_total
)) != XINT (WGET (w
, new_total
)))
3415 || !window_resize_check (c
, horflag
))
3417 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3423 /* A leaf window. Make sure it's not too small. The following
3424 hardcodes the values of `window-safe-min-width' (2) and
3425 `window-safe-min-height' (1) which are defined in window.el. */
3426 return XINT (WGET (w
, new_total
)) >= (horflag
? 2 : 1);
3429 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3430 w->new_total for window W and recursively all child windows of W.
3431 Also calculate and assign the new vertical (horizontal) start
3432 positions of each of these windows.
3434 This function does not perform any error checks. Make sure you have
3435 run window_resize_check on W before applying this function. */
3437 window_resize_apply (struct window
*w
, int horflag
)
3442 /* Note: Assigning new_normal requires that the new total size of the
3443 parent window has been set *before*. */
3446 WSET (w
, total_cols
, WGET (w
, new_total
));
3447 if (NUMBERP (WGET (w
, new_normal
)))
3448 WSET (w
, normal_cols
, WGET (w
, new_normal
));
3450 pos
= XINT (WGET (w
, left_col
));
3454 WSET (w
, total_lines
, WGET (w
, new_total
));
3455 if (NUMBERP (WGET (w
, new_normal
)))
3456 WSET (w
, normal_lines
, WGET (w
, new_normal
));
3458 pos
= XINT (WGET (w
, top_line
));
3461 if (!NILP (WGET (w
, vchild
)))
3462 /* W is a vertical combination. */
3464 c
= XWINDOW (WGET (w
, vchild
));
3468 WSET (c
, left_col
, make_number (pos
));
3470 WSET (c
, top_line
, make_number (pos
));
3471 window_resize_apply (c
, horflag
);
3473 pos
= pos
+ XINT (WGET (c
, total_lines
));
3474 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3477 else if (!NILP (WGET (w
, hchild
)))
3478 /* W is a horizontal combination. */
3480 c
= XWINDOW (WGET (w
, hchild
));
3484 WSET (c
, left_col
, make_number (pos
));
3486 WSET (c
, top_line
, make_number (pos
));
3487 window_resize_apply (c
, horflag
);
3489 pos
= pos
+ XINT (WGET (c
, total_cols
));
3490 c
= NILP (WGET (c
, next
)) ? 0 : XWINDOW (WGET (c
, next
));
3494 /* Clear out some redisplay caches. */
3495 w
->last_modified
= 0;
3496 w
->last_overlay_modified
= 0;
3500 DEFUN ("window-resize-apply", Fwindow_resize_apply
, Swindow_resize_apply
, 1, 2, 0,
3501 doc
: /* Apply requested size values for window-tree of FRAME.
3502 Optional argument HORIZONTAL omitted or nil means apply requested height
3503 values. HORIZONTAL non-nil means apply requested width values.
3505 This function checks whether the requested values sum up to a valid
3506 window layout, recursively assigns the new sizes of all child windows
3507 and calculates and assigns the new start positions of these windows.
3509 Note: This function does not check any of `window-fixed-size-p',
3510 `window-min-height' or `window-min-width'. All these checks have to
3511 be applied on the Elisp level. */)
3512 (Lisp_Object frame
, Lisp_Object horizontal
)
3516 int horflag
= !NILP (horizontal
);
3519 frame
= selected_frame
;
3520 CHECK_LIVE_FRAME (frame
);
3523 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3525 if (!window_resize_check (r
, horflag
)
3526 || ! EQ (WGET (r
, new_total
),
3527 (horflag
? WGET (r
, total_cols
) : WGET (r
, total_lines
))))
3531 window_resize_apply (r
, horflag
);
3533 windows_or_buffers_changed
++;
3534 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3539 run_window_configuration_change_hook (f
);
3545 /* Resize frame F's windows when number of lines of F is set to SIZE.
3546 HORFLAG 1 means resize windows when number of columns of F is set to
3549 This function can delete all windows but the selected one in order to
3550 satisfy the request. The result will be meaningful if and only if
3551 F's windows have meaningful sizes when you call this. */
3553 resize_frame_windows (struct frame
*f
, int size
, int horflag
)
3555 Lisp_Object root
= f
->root_window
;
3556 struct window
*r
= XWINDOW (root
);
3557 Lisp_Object mini
= f
->minibuffer_window
;
3559 /* new_size is the new size of the frame's root window. */
3560 int new_size
= (horflag
3563 - FRAME_TOP_MARGIN (f
)
3564 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3567 WSET (r
, top_line
, make_number (FRAME_TOP_MARGIN (f
)));
3568 if (NILP (WGET (r
, vchild
)) && NILP (WGET (r
, hchild
)))
3569 /* For a leaf root window just set the size. */
3571 WSET (r
, total_cols
, make_number (new_size
));
3573 WSET (r
, total_lines
, make_number (new_size
));
3576 /* old_size is the old size of the frame's root window. */
3577 int old_size
= XFASTINT (horflag
? WGET (r
, total_cols
)
3578 : WGET (r
, total_lines
));
3581 XSETINT (delta
, new_size
- old_size
);
3582 /* Try a "normal" resize first. */
3583 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3584 if (window_resize_check (r
, horflag
)
3585 && new_size
== XINT (WGET (r
, new_total
)))
3586 window_resize_apply (r
, horflag
);
3589 /* Try with "reasonable" minimum sizes next. */
3590 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3591 if (window_resize_check (r
, horflag
)
3592 && new_size
== XINT (WGET (r
, new_total
)))
3593 window_resize_apply (r
, horflag
);
3596 /* Finally, try with "safe" minimum sizes. */
3597 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qsafe
);
3598 if (window_resize_check (r
, horflag
)
3599 && new_size
== XINT (WGET (r
, new_total
)))
3600 window_resize_apply (r
, horflag
);
3603 /* We lost. Delete all windows but the frame's
3605 root
= f
->selected_window
;
3606 Fdelete_other_windows_internal (root
, Qnil
);
3608 WSET (XWINDOW (root
), total_cols
, make_number (new_size
));
3610 WSET (XWINDOW (root
), total_lines
, make_number (new_size
));
3616 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3620 WSET (m
, total_cols
, make_number (size
));
3623 /* Are we sure we always want 1 line here? */
3624 WSET (m
, total_lines
, make_number (1));
3626 make_number (XINT (WGET (r
, top_line
)) + XINT (WGET (r
, total_lines
))));
3632 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 4, 4, 0,
3633 doc
: /* Split window OLD.
3634 Second argument TOTAL-SIZE specifies the number of lines or columns of the
3635 new window. In any case TOTAL-SIZE must be a positive integer.
3637 Third argument SIDE nil (or `below') specifies that the new window shall
3638 be located below WINDOW. SIDE `above' means the new window shall be
3639 located above WINDOW. In both cases TOTAL-SIZE specifies the number of
3640 lines of the new window including space reserved for the mode and/or
3643 SIDE t (or `right') specifies that the new window shall be located on
3644 the right side of WINDOW. SIDE `left' means the new window shall be
3645 located on the left of WINDOW. In both cases TOTAL-SIZE specifies the
3646 number of columns of the new window including space reserved for fringes
3647 and the scrollbar or a divider column.
3649 Fourth argument NORMAL-SIZE specifies the normal size of the new window
3650 according to the SIDE argument.
3652 The new total and normal sizes of all involved windows must have been
3653 set correctly. See the code of `split-window' for how this is done. */)
3654 (Lisp_Object old
, Lisp_Object total_size
, Lisp_Object side
, Lisp_Object normal_size
)
3656 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3657 parent window or an internal window we have to install as OLD's new
3658 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3659 provided OLD is a leaf window, or to the frame's selected window.
3660 NEW (*n) is the new window created with some parameters taken from
3662 register Lisp_Object
new, frame
, reference
;
3663 register struct window
*o
, *p
, *n
, *r
;
3666 /* HORFLAG is 1 when we split side-by-side, 0 otherwise. */
3667 = EQ (side
, Qt
) || EQ (side
, Qleft
) || EQ (side
, Qright
);
3668 int combination_limit
= 0;
3672 frame
= WINDOW_FRAME (o
);
3675 CHECK_NUMBER (total_size
);
3677 /* Set combination_limit to 1 if we have to make a new parent window.
3678 We do that if either `window-combination-limit' is t, or OLD has no
3679 parent, or OLD is ortho-combined. */
3681 !NILP (Vwindow_combination_limit
)
3682 || NILP (WGET (o
, parent
))
3684 ? (WGET (XWINDOW (WGET (o
, parent
)), hchild
))
3685 : (WGET (XWINDOW (WGET (o
, parent
)), vchild
)));
3687 /* We need a live reference window to initialize some parameters. */
3688 if (WINDOW_LIVE_P (old
))
3689 /* OLD is live, use it as reference window. */
3692 /* Use the frame's selected window as reference window. */
3693 reference
= FRAME_SELECTED_WINDOW (f
);
3694 r
= XWINDOW (reference
);
3696 /* The following bugs are caught by `split-window'. */
3697 if (MINI_WINDOW_P (o
))
3698 error ("Attempt to split minibuffer window");
3699 else if (XINT (total_size
) < (horflag
? 2 : 1))
3700 error ("Size of new window too small (after split)");
3701 else if (!combination_limit
&& !NILP (Vwindow_combination_resize
))
3702 /* `window-combination-resize' non-nil means try to resize OLD's siblings
3705 p
= XWINDOW (WGET (o
, parent
));
3706 /* Temporarily pretend we split the parent window. */
3708 make_number (XINT (horflag
? WGET (p
, total_cols
) : WGET (p
, total_lines
))
3709 - XINT (total_size
)));
3710 if (!window_resize_check (p
, horflag
))
3711 error ("Window sizes don't fit");
3713 /* Undo the temporary pretension. */
3715 horflag
? WGET (p
, total_cols
) : WGET (p
, total_lines
));
3719 if (!window_resize_check (o
, horflag
))
3720 error ("Resizing old window failed");
3721 else if (XINT (total_size
) + XINT (WGET (o
, new_total
))
3722 != XINT (horflag
? WGET (o
, total_cols
) : WGET (o
, total_lines
)))
3723 error ("Sum of sizes of old and new window don't fit");
3726 /* This is our point of no return. */
3727 if (combination_limit
)
3729 /* Save the old value of o->normal_cols/lines. It gets corrupted
3730 by make_parent_window and we need it below for assigning it to
3732 Lisp_Object new_normal
3733 = horflag
? WGET (o
, normal_cols
) : WGET (o
, normal_lines
);
3735 make_parent_window (old
, horflag
);
3736 p
= XWINDOW (WGET (o
, parent
));
3737 /* Store value of `window-combination-limit' in new parent's
3738 combination_limit slot. */
3739 WSET (p
, combination_limit
, Vwindow_combination_limit
);
3740 /* These get applied below. */
3742 horflag
? WGET (o
, total_cols
) : WGET (o
, total_lines
));
3743 WSET (p
, new_normal
, new_normal
);
3746 p
= XWINDOW (WGET (o
, parent
));
3748 windows_or_buffers_changed
++;
3749 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3750 new = make_window ();
3752 WSET (n
, frame
, frame
);
3753 WSET (n
, parent
, WGET (o
, parent
));
3754 WSET (n
, vchild
, Qnil
);
3755 WSET (n
, hchild
, Qnil
);
3757 if (EQ (side
, Qabove
) || EQ (side
, Qleft
))
3759 WSET (n
, prev
, WGET (o
, prev
));
3760 if (NILP (WGET (n
, prev
)))
3762 WSET (p
, hchild
, new);
3764 WSET (p
, vchild
, new);
3766 WSET (XWINDOW (WGET (n
, prev
)), next
, new);
3767 WSET (n
, next
, old
);
3768 WSET (o
, prev
, new);
3772 WSET (n
, next
, WGET (o
, next
));
3773 if (!NILP (WGET (n
, next
)))
3774 WSET (XWINDOW (WGET (n
, next
)), prev
, new);
3775 WSET (n
, prev
, old
);
3776 WSET (o
, next
, new);
3779 WSET (n
, buffer
, Qt
);
3780 WSET (n
, window_end_valid
, Qnil
);
3781 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3783 /* Get special geometry settings from reference window. */
3784 WSET (n
, left_margin_cols
, WGET (r
, left_margin_cols
));
3785 WSET (n
, right_margin_cols
, WGET (r
, right_margin_cols
));
3786 WSET (n
, left_fringe_width
, WGET (r
, left_fringe_width
));
3787 WSET (n
, right_fringe_width
, WGET (r
, right_fringe_width
));
3788 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3789 WSET (n
, scroll_bar_width
, WGET (r
, scroll_bar_width
));
3790 WSET (n
, vertical_scroll_bar_type
, WGET (r
, vertical_scroll_bar_type
));
3792 /* Directly assign orthogonal coordinates and sizes. */
3795 WSET (n
, top_line
, WGET (o
, top_line
));
3796 WSET (n
, total_lines
, WGET (o
, total_lines
));
3800 WSET (n
, left_col
, WGET (o
, left_col
));
3801 WSET (n
, total_cols
, WGET (o
, total_cols
));
3804 /* Iso-coordinates and sizes are assigned by window_resize_apply,
3805 get them ready here. */
3806 WSET (n
, new_total
, total_size
);
3807 WSET (n
, new_normal
, normal_size
);
3810 window_resize_apply (p
, horflag
);
3812 /* Set buffer of NEW to buffer of reference window. Don't run
3814 set_window_buffer (new, WGET (r
, buffer
), 0, 1);
3817 /* Maybe we should run the scroll functions in Elisp (which already
3818 runs the configuration change hook). */
3819 if (! NILP (Vwindow_scroll_functions
))
3820 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3821 Fmarker_position (WGET (n
, start
)));
3827 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
3828 doc
: /* Remove WINDOW from its frame.
3829 WINDOW defaults to the selected window. Return nil.
3830 Signal an error when WINDOW is the only window on its frame. */)
3831 (register Lisp_Object window
)
3833 register Lisp_Object parent
, sibling
, frame
, root
;
3834 struct window
*w
, *p
, *s
, *r
;
3837 int before_sibling
= 0;
3839 w
= decode_any_window (window
);
3840 XSETWINDOW (window
, w
);
3841 if (NILP (WGET (w
, buffer
))
3842 && NILP (WGET (w
, hchild
)) && NILP (WGET (w
, vchild
)))
3843 /* It's a no-op to delete an already deleted window. */
3846 parent
= WGET (w
, parent
);
3848 /* Never delete a minibuffer or frame root window. */
3849 error ("Attempt to delete minibuffer or sole ordinary window");
3850 else if (NILP (WGET (w
, prev
)) && NILP (WGET (w
, next
)))
3851 /* Rather bow out here, this case should be handled on the Elisp
3853 error ("Attempt to delete sole window of parent");
3855 p
= XWINDOW (parent
);
3856 horflag
= NILP (WGET (p
, vchild
));
3858 frame
= WINDOW_FRAME (w
);
3861 root
= FRAME_ROOT_WINDOW (f
);
3864 /* Unlink WINDOW from window tree. */
3865 if (NILP (WGET (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. */
3871 sibling
= WGET (w
, next
);
3872 s
= XWINDOW (sibling
);
3873 WSET (s
, prev
, Qnil
);
3875 WSET (p
, hchild
, sibling
);
3877 WSET (p
, vchild
, sibling
);
3880 /* Get SIBLING above (on the left of) WINDOW. */
3882 sibling
= WGET (w
, prev
);
3883 s
= XWINDOW (sibling
);
3884 WSET (s
, next
, WGET (w
, next
));
3885 if (!NILP (WGET (s
, next
)))
3886 WSET (XWINDOW (WGET (s
, next
)), prev
, sibling
);
3889 if (window_resize_check (r
, horflag
)
3890 && EQ (WGET (r
, new_total
),
3891 (horflag
? WGET (r
, total_cols
) : WGET (r
, total_lines
))))
3892 /* We can delete WINDOW now. */
3897 window_resize_apply (p
, horflag
);
3899 /* If this window is referred to by the dpyinfo's mouse
3900 highlight, invalidate that slot to be safe (Bug#9904). */
3901 if (!FRAME_INITIAL_P (f
))
3903 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
3905 if (EQ (hlinfo
->mouse_face_window
, window
))
3906 hlinfo
->mouse_face_window
= Qnil
;
3909 windows_or_buffers_changed
++;
3910 Vwindow_list
= Qnil
;
3911 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3913 WSET (w
, next
, Qnil
); /* Don't delete w->next too. */
3914 free_window_matrices (w
);
3916 if (!NILP (WGET (w
, vchild
)))
3918 delete_all_child_windows (WGET (w
, vchild
));
3919 WSET (w
, vchild
, Qnil
);
3921 else if (!NILP (WGET (w
, hchild
)))
3923 delete_all_child_windows (WGET (w
, hchild
));
3924 WSET (w
, hchild
, Qnil
);
3926 else if (!NILP (WGET (w
, buffer
)))
3929 unchain_marker (XMARKER (WGET (w
, pointm
)));
3930 unchain_marker (XMARKER (WGET (w
, start
)));
3931 WSET (w
, buffer
, Qnil
);
3934 if (NILP (WGET (s
, prev
)) && NILP (WGET (s
, next
)))
3935 /* A matrjoshka where SIBLING has become the only child of
3938 /* Put SIBLING into PARENT's place. */
3939 replace_window (parent
, sibling
, 0);
3940 /* Have SIBLING inherit the following three slot values from
3941 PARENT (the combination_limit slot is not inherited). */
3942 WSET (s
, normal_cols
, WGET (p
, normal_cols
));
3943 WSET (s
, normal_lines
, WGET (p
, normal_lines
));
3944 /* Mark PARENT as deleted. */
3945 WSET (p
, vchild
, Qnil
);
3946 WSET (p
, hchild
, Qnil
);
3947 /* Try to merge SIBLING into its new parent. */
3948 recombine_windows (sibling
);
3953 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
3954 /* We deleted the frame's selected window. */
3956 /* Use the frame's first window as fallback ... */
3957 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
3958 /* ... but preferably use its most recently used window. */
3959 Lisp_Object mru_window
;
3961 /* `get-mru-window' might fail for some reason so play it safe
3962 - promote the first window _without recording it_ first. */
3963 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
3964 Fselect_window (new_selected_window
, Qt
);
3966 FSET (f
, selected_window
, new_selected_window
);
3970 /* Now look whether `get-mru-window' gets us something. */
3971 mru_window
= call1 (Qget_mru_window
, frame
);
3972 if (WINDOW_LIVE_P (mru_window
)
3973 && EQ (WGET (XWINDOW (mru_window
), frame
), frame
))
3974 new_selected_window
= mru_window
;
3976 /* If all ended up well, we now promote the mru window. */
3977 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
3978 Fselect_window (new_selected_window
, Qnil
);
3980 FSET (f
, selected_window
, new_selected_window
);
3985 /* Must be run by the caller:
3986 run_window_configuration_change_hook (f); */
3989 /* We failed: Relink WINDOW into window tree. */
3993 WSET (s
, prev
, window
);
3995 WSET (p
, hchild
, window
);
3997 WSET (p
, vchild
, window
);
4001 WSET (s
, next
, window
);
4002 if (!NILP (WGET (w
, next
)))
4003 WSET (XWINDOW (WGET (w
, next
)), prev
, window
);
4005 error ("Deletion failed");
4011 /***********************************************************************
4012 Resizing Mini-Windows
4013 ***********************************************************************/
4015 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4018 grow_mini_window (struct window
*w
, int delta
)
4020 struct frame
*f
= XFRAME (WGET (w
, frame
));
4022 Lisp_Object root
, value
;
4024 eassert (MINI_WINDOW_P (w
));
4025 eassert (delta
>= 0);
4027 root
= FRAME_ROOT_WINDOW (f
);
4029 value
= call2 (Qwindow_resize_root_window_vertically
,
4030 root
, make_number (- delta
));
4031 if (INTEGERP (value
) && window_resize_check (r
, 0))
4034 window_resize_apply (r
, 0);
4036 /* Grow the mini-window. */
4038 make_number (XFASTINT (WGET (r
, top_line
)) + XFASTINT (WGET (r
, total_lines
))));
4039 WSET (w
, total_lines
,
4040 make_number (XFASTINT (WGET (w
, total_lines
)) - XINT (value
)));
4041 w
->last_modified
= 0;
4042 w
->last_overlay_modified
= 0;
4050 /* Shrink mini-window W. */
4052 shrink_mini_window (struct window
*w
)
4054 struct frame
*f
= XFRAME (WGET (w
, frame
));
4056 Lisp_Object root
, value
;
4059 eassert (MINI_WINDOW_P (w
));
4061 size
= XINT (WGET (w
, total_lines
));
4064 root
= FRAME_ROOT_WINDOW (f
);
4066 value
= call2 (Qwindow_resize_root_window_vertically
,
4067 root
, make_number (size
- 1));
4068 if (INTEGERP (value
) && window_resize_check (r
, 0))
4071 window_resize_apply (r
, 0);
4073 /* Shrink the mini-window. */
4075 make_number (XFASTINT (WGET (r
, top_line
)) + XFASTINT (WGET (r
, total_lines
))));
4076 WSET (w
, total_lines
, make_number (1));
4078 w
->last_modified
= 0;
4079 w
->last_overlay_modified
= 0;
4084 /* If the above failed for whatever strange reason we must make a
4085 one window frame here. The same routine will be needed when
4086 shrinking the frame (and probably when making the initial
4087 *scratch* window). For the moment leave things as they are. */
4091 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4092 doc
: /* Resize minibuffer window WINDOW. */)
4093 (Lisp_Object window
)
4095 struct window
*w
= XWINDOW (window
);
4100 CHECK_WINDOW (window
);
4101 f
= XFRAME (WGET (w
, frame
));
4103 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (WGET (w
, frame
))), window
))
4104 error ("Not a valid minibuffer window");
4105 else if (FRAME_MINIBUF_ONLY_P (f
))
4106 error ("Cannot resize a minibuffer-only frame");
4108 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4109 height
= XINT (WGET (r
, total_lines
)) + XINT (WGET (w
, total_lines
));
4110 if (window_resize_check (r
, 0)
4111 && XINT (WGET (w
, new_total
)) > 0
4112 && height
== XINT (WGET (r
, new_total
)) + XINT (WGET (w
, new_total
)))
4115 window_resize_apply (r
, 0);
4117 WSET (w
, total_lines
, WGET (w
, new_total
));
4119 make_number (XINT (WGET (r
, top_line
)) + XINT (WGET (r
, total_lines
))));
4121 windows_or_buffers_changed
++;
4122 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4126 run_window_configuration_change_hook (f
);
4129 else error ("Failed to resize minibuffer window");
4132 /* Mark window cursors off for all windows in the window tree rooted
4133 at W by setting their phys_cursor_on_p flag to zero. Called from
4134 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4135 the frame are cleared. */
4138 mark_window_cursors_off (struct window
*w
)
4142 if (!NILP (WGET (w
, hchild
)))
4143 mark_window_cursors_off (XWINDOW (WGET (w
, hchild
)));
4144 else if (!NILP (WGET (w
, vchild
)))
4145 mark_window_cursors_off (XWINDOW (WGET (w
, vchild
)));
4147 w
->phys_cursor_on_p
= 0;
4149 w
= NILP (WGET (w
, next
)) ? 0 : XWINDOW (WGET (w
, next
));
4154 /* Return number of lines of text (not counting mode lines) in W. */
4157 window_internal_height (struct window
*w
)
4159 int ht
= XFASTINT (WGET (w
, total_lines
));
4161 if (!MINI_WINDOW_P (w
))
4163 if (!NILP (WGET (w
, parent
))
4164 || !NILP (WGET (w
, vchild
))
4165 || !NILP (WGET (w
, hchild
))
4166 || !NILP (WGET (w
, next
))
4167 || !NILP (WGET (w
, prev
))
4168 || WINDOW_WANTS_MODELINE_P (w
))
4171 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4178 /************************************************************************
4180 ***********************************************************************/
4182 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4183 N screen-fulls, which is defined as the height of the window minus
4184 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4185 instead. Negative values of N mean scroll down. NOERROR non-zero
4186 means don't signal an error if we try to move over BEGV or ZV,
4190 window_scroll (Lisp_Object window
, EMACS_INT n
, int whole
, int noerror
)
4193 n
= clip_to_bounds (INT_MIN
, n
, INT_MAX
);
4195 /* If we must, use the pixel-based version which is much slower than
4196 the line-based one but can handle varying line heights. */
4197 if (FRAME_WINDOW_P (XFRAME (WGET (XWINDOW (window
), frame
))))
4198 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4200 window_scroll_line_based (window
, n
, whole
, noerror
);
4206 /* Implementation of window_scroll that works based on pixel line
4207 heights. See the comment of window_scroll for parameter
4211 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4214 struct window
*w
= XWINDOW (window
);
4215 struct text_pos start
;
4216 int this_scroll_margin
;
4217 /* True if we fiddled the window vscroll field without really scrolling. */
4219 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4220 void *itdata
= NULL
;
4222 SET_TEXT_POS_FROM_MARKER (start
, WGET (w
, start
));
4223 /* Scrolling a minibuffer window via scroll bar when the echo area
4224 shows long text sometimes resets the minibuffer contents behind
4226 if (CHARPOS (start
) > ZV
)
4227 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4229 /* If PT is not visible in WINDOW, move back one half of
4230 the screen. Allow PT to be partially visible, otherwise
4231 something like (scroll-down 1) with PT in the line before
4232 the partially visible one would recenter. */
4234 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4236 itdata
= bidi_shelve_cache ();
4237 /* Move backward half the height of the window. Performance note:
4238 vmotion used here is about 10% faster, but would give wrong
4239 results for variable height lines. */
4240 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4241 it
.current_y
= it
.last_visible_y
;
4242 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4244 /* The function move_iterator_vertically may move over more than
4245 the specified y-distance. If it->w is small, e.g. a
4246 mini-buffer window, we may end up in front of the window's
4247 display area. This is the case when Start displaying at the
4248 start of the line containing PT in this case. */
4249 if (it
.current_y
<= 0)
4251 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4252 move_it_vertically_backward (&it
, 0);
4256 start
= it
.current
.pos
;
4257 bidi_unshelve_cache (itdata
, 0);
4259 else if (auto_window_vscroll_p
)
4261 if (rtop
|| rbot
) /* partially visible */
4264 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4266 dy
= max ((window_box_height (w
)
4267 - next_screen_context_lines
* dy
),
4273 /* Only vscroll backwards if already vscrolled forwards. */
4274 if (w
->vscroll
< 0 && rtop
> 0)
4276 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4277 Fset_window_vscroll (window
, make_number (px
), Qt
);
4283 /* Do vscroll if already vscrolled or only display line. */
4284 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4286 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4287 Fset_window_vscroll (window
, make_number (px
), Qt
);
4291 /* Maybe modify window start instead of scrolling. */
4292 if (rbot
> 0 || w
->vscroll
< 0)
4296 Fset_window_vscroll (window
, make_number (0), Qt
);
4297 /* If there are other text lines above the current row,
4298 move window start to current row. Else to next row. */
4300 spos
= XINT (Fline_beginning_position (Qnil
));
4302 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4303 set_marker_restricted (WGET (w
, start
), make_number (spos
),
4305 w
->start_at_line_beg
= 1;
4306 w
->update_mode_line
= 1;
4307 w
->last_modified
= 0;
4308 w
->last_overlay_modified
= 0;
4309 /* Set force_start so that redisplay_window will run the
4310 window-scroll-functions. */
4316 /* Cancel previous vscroll. */
4317 Fset_window_vscroll (window
, make_number (0), Qt
);
4320 itdata
= bidi_shelve_cache ();
4321 /* If scroll_preserve_screen_position is non-nil, we try to set
4322 point in the same window line as it is now, so get that line. */
4323 if (!NILP (Vscroll_preserve_screen_position
))
4325 /* We preserve the goal pixel coordinate across consecutive
4326 calls to scroll-up, scroll-down and other commands that
4327 have the `scroll-command' property. This avoids the
4328 possibility of point becoming "stuck" on a tall line when
4329 scrolling by one line. */
4330 if (window_scroll_pixel_based_preserve_y
< 0
4331 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4332 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4334 start_display (&it
, w
, start
);
4335 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4336 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4337 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4341 window_scroll_pixel_based_preserve_y
4342 = window_scroll_pixel_based_preserve_x
= -1;
4344 /* Move iterator it from start the specified distance forward or
4345 backward. The result is the new window start. */
4346 start_display (&it
, w
, start
);
4349 ptrdiff_t start_pos
= IT_CHARPOS (it
);
4350 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4351 dy
= max ((window_box_height (w
)
4352 - next_screen_context_lines
* dy
),
4355 /* Note that move_it_vertically always moves the iterator to the
4356 start of a line. So, if the last line doesn't have a newline,
4357 we would end up at the start of the line ending at ZV. */
4360 move_it_vertically_backward (&it
, -dy
);
4361 /* Ensure we actually do move, e.g. in case we are currently
4362 looking at an image that is taller that the window height. */
4363 while (start_pos
== IT_CHARPOS (it
)
4364 && start_pos
> BEGV
)
4365 move_it_by_lines (&it
, -1);
4369 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4370 MOVE_TO_POS
| MOVE_TO_Y
);
4371 /* Ensure we actually do move, e.g. in case we are currently
4372 looking at an image that is taller that the window height. */
4373 while (start_pos
== IT_CHARPOS (it
)
4375 move_it_by_lines (&it
, 1);
4379 move_it_by_lines (&it
, n
);
4381 /* We failed if we find ZV is already on the screen (scrolling up,
4382 means there's nothing past the end), or if we can't start any
4383 earlier (scrolling down, means there's nothing past the top). */
4384 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4385 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4387 if (IT_CHARPOS (it
) == ZV
)
4389 if (it
.current_y
< it
.last_visible_y
4390 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4391 > it
.last_visible_y
))
4393 /* The last line was only partially visible, make it fully
4395 w
->vscroll
= (it
.last_visible_y
4396 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4397 adjust_glyphs (it
.f
);
4401 bidi_unshelve_cache (itdata
, 0);
4404 else if (n
< 0) /* could happen with empty buffers */
4405 xsignal0 (Qbeginning_of_buffer
);
4407 xsignal0 (Qend_of_buffer
);
4412 if (w
->vscroll
!= 0)
4413 /* The first line was only partially visible, make it fully
4418 bidi_unshelve_cache (itdata
, 0);
4422 xsignal0 (Qbeginning_of_buffer
);
4426 /* If control gets here, then we vscrolled. */
4428 XBUFFER (WGET (w
, buffer
))->prevent_redisplay_optimizations_p
= 1;
4430 /* Don't try to change the window start below. */
4436 ptrdiff_t pos
= IT_CHARPOS (it
);
4439 /* If in the middle of a multi-glyph character move forward to
4440 the next character. */
4441 if (in_display_vector_p (&it
))
4444 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4447 /* Set the window start, and set up the window for redisplay. */
4448 set_marker_restricted (WGET (w
, start
), make_number (pos
),
4450 bytepos
= XMARKER (WGET (w
, start
))->bytepos
;
4451 w
->start_at_line_beg
= (pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n');
4452 w
->update_mode_line
= 1;
4453 w
->last_modified
= 0;
4454 w
->last_overlay_modified
= 0;
4455 /* Set force_start so that redisplay_window will run the
4456 window-scroll-functions. */
4460 /* The rest of this function uses current_y in a nonstandard way,
4461 not including the height of the header line if any. */
4462 it
.current_y
= it
.vpos
= 0;
4464 /* Move PT out of scroll margins.
4465 This code wants current_y to be zero at the window start position
4466 even if there is a header line. */
4467 this_scroll_margin
= max (0, scroll_margin
);
4469 = min (this_scroll_margin
, XFASTINT (WGET (w
, total_lines
)) / 4);
4470 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4474 /* We moved the window start towards ZV, so PT may be now
4475 in the scroll margin at the top. */
4476 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4477 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4478 && (NILP (Vscroll_preserve_screen_position
)
4479 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4480 /* We found PT at a legitimate height. Leave it alone. */
4482 else if (window_scroll_pixel_based_preserve_y
>= 0)
4484 /* If we have a header line, take account of it.
4485 This is necessary because we set it.current_y to 0, above. */
4486 move_it_to (&it
, -1,
4487 window_scroll_pixel_based_preserve_x
,
4488 window_scroll_pixel_based_preserve_y
4489 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4490 -1, MOVE_TO_Y
| MOVE_TO_X
);
4491 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4495 while (it
.current_y
< this_scroll_margin
)
4497 int prev
= it
.current_y
;
4498 move_it_by_lines (&it
, 1);
4499 if (prev
== it
.current_y
)
4502 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4507 ptrdiff_t charpos
, bytepos
;
4510 /* Save our position, for the
4511 window_scroll_pixel_based_preserve_y case. */
4512 charpos
= IT_CHARPOS (it
);
4513 bytepos
= IT_BYTEPOS (it
);
4515 /* We moved the window start towards BEGV, so PT may be now
4516 in the scroll margin at the bottom. */
4517 move_it_to (&it
, PT
, -1,
4518 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4519 - this_scroll_margin
- 1),
4521 MOVE_TO_POS
| MOVE_TO_Y
);
4523 /* Save our position, in case it's correct. */
4524 charpos
= IT_CHARPOS (it
);
4525 bytepos
= IT_BYTEPOS (it
);
4527 /* See if point is on a partially visible line at the end. */
4528 if (it
.what
== IT_EOB
)
4529 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4532 move_it_by_lines (&it
, 1);
4533 partial_p
= it
.current_y
> it
.last_visible_y
;
4536 if (charpos
== PT
&& !partial_p
4537 && (NILP (Vscroll_preserve_screen_position
)
4538 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4539 /* We found PT before we found the display margin, so PT is ok. */
4541 else if (window_scroll_pixel_based_preserve_y
>= 0)
4543 SET_TEXT_POS_FROM_MARKER (start
, WGET (w
, start
));
4544 start_display (&it
, w
, start
);
4545 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4546 here because we called start_display again and did not
4547 alter it.current_y this time. */
4548 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4549 window_scroll_pixel_based_preserve_y
, -1,
4550 MOVE_TO_Y
| MOVE_TO_X
);
4551 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4556 /* The last line was only partially visible, so back up two
4557 lines to make sure we're on a fully visible line. */
4559 move_it_by_lines (&it
, -2);
4560 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4563 /* No, the position we saved is OK, so use it. */
4564 SET_PT_BOTH (charpos
, bytepos
);
4567 bidi_unshelve_cache (itdata
, 0);
4571 /* Implementation of window_scroll that works based on screen lines.
4572 See the comment of window_scroll for parameter descriptions. */
4575 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4577 register struct window
*w
= XWINDOW (window
);
4578 /* Fvertical_motion enters redisplay, which can trigger
4579 fontification, which in turn can modify buffer text (e.g., if the
4580 fontification functions replace escape sequences with faces, as
4581 in `grep-mode-font-lock-keywords'). So we use a marker to record
4582 the old point position, to prevent crashes in SET_PT_BOTH. */
4583 Lisp_Object opoint_marker
= Fpoint_marker ();
4584 register ptrdiff_t pos
, pos_byte
;
4585 register int ht
= window_internal_height (w
);
4586 register Lisp_Object tem
;
4590 Lisp_Object original_pos
= Qnil
;
4592 /* If scrolling screen-fulls, compute the number of lines to
4593 scroll from the window's height. */
4595 n
*= max (1, ht
- next_screen_context_lines
);
4597 startpos
= marker_position (WGET (w
, start
));
4599 if (!NILP (Vscroll_preserve_screen_position
))
4601 if (window_scroll_preserve_vpos
<= 0
4602 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4603 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4605 struct position posit
4606 = *compute_motion (startpos
, 0, 0, 0,
4610 window_scroll_preserve_vpos
= posit
.vpos
;
4611 window_scroll_preserve_hpos
= posit
.hpos
+ w
->hscroll
;
4614 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4615 make_number (window_scroll_preserve_vpos
));
4618 XSETFASTINT (tem
, PT
);
4619 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4623 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4628 lose
= n
< 0 && PT
== BEGV
;
4629 Fvertical_motion (make_number (n
), window
);
4633 SET_PT_BOTH (marker_position (opoint_marker
),
4634 marker_byte_position (opoint_marker
));
4641 xsignal0 (Qbeginning_of_buffer
);
4646 /* Don't use a scroll margin that is negative or too large. */
4647 int this_scroll_margin
=
4648 max (0, min (scroll_margin
, XINT (WGET (w
, total_lines
)) / 4));
4650 set_marker_restricted_both (WGET (w
, start
), WGET (w
, buffer
), pos
, pos_byte
);
4651 w
->start_at_line_beg
= !NILP (bolp
);
4652 w
->update_mode_line
= 1;
4653 w
->last_modified
= 0;
4654 w
->last_overlay_modified
= 0;
4655 /* Set force_start so that redisplay_window will run
4656 the window-scroll-functions. */
4659 if (!NILP (Vscroll_preserve_screen_position
)
4660 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4662 SET_PT_BOTH (pos
, pos_byte
);
4663 Fvertical_motion (original_pos
, window
);
4665 /* If we scrolled forward, put point enough lines down
4666 that it is outside the scroll margin. */
4671 if (this_scroll_margin
> 0)
4673 SET_PT_BOTH (pos
, pos_byte
);
4674 Fvertical_motion (make_number (this_scroll_margin
), window
);
4680 if (top_margin
<= marker_position (opoint_marker
))
4681 SET_PT_BOTH (marker_position (opoint_marker
),
4682 marker_byte_position (opoint_marker
));
4683 else if (!NILP (Vscroll_preserve_screen_position
))
4685 SET_PT_BOTH (pos
, pos_byte
);
4686 Fvertical_motion (original_pos
, window
);
4689 SET_PT (top_margin
);
4695 /* If we scrolled backward, put point near the end of the window
4696 but not within the scroll margin. */
4697 SET_PT_BOTH (pos
, pos_byte
);
4698 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4699 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4702 bottom_margin
= PT
+ 1;
4704 if (bottom_margin
> marker_position (opoint_marker
))
4705 SET_PT_BOTH (marker_position (opoint_marker
),
4706 marker_byte_position (opoint_marker
));
4709 if (!NILP (Vscroll_preserve_screen_position
))
4711 SET_PT_BOTH (pos
, pos_byte
);
4712 Fvertical_motion (original_pos
, window
);
4715 Fvertical_motion (make_number (-1), window
);
4724 xsignal0 (Qend_of_buffer
);
4729 /* Scroll selected_window up or down. If N is nil, scroll a
4730 screen-full which is defined as the height of the window minus
4731 next_screen_context_lines. If N is the symbol `-', scroll.
4732 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4733 up. This is the guts of Fscroll_up and Fscroll_down. */
4736 scroll_command (Lisp_Object n
, int direction
)
4738 ptrdiff_t count
= SPECPDL_INDEX ();
4740 eassert (eabs (direction
) == 1);
4742 /* If selected window's buffer isn't current, make it current for
4743 the moment. But don't screw up if window_scroll gets an error. */
4744 if (XBUFFER (WGET (XWINDOW (selected_window
), buffer
)) != current_buffer
)
4746 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4747 Fset_buffer (WGET (XWINDOW (selected_window
), buffer
));
4749 /* Make redisplay consider other windows than just selected_window. */
4750 ++windows_or_buffers_changed
;
4754 window_scroll (selected_window
, direction
, 1, 0);
4755 else if (EQ (n
, Qminus
))
4756 window_scroll (selected_window
, -direction
, 1, 0);
4759 n
= Fprefix_numeric_value (n
);
4760 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4763 unbind_to (count
, Qnil
);
4766 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4767 doc
: /* Scroll text of selected window upward ARG lines.
4768 If ARG is omitted or nil, scroll upward by a near full screen.
4769 A near full screen is `next-screen-context-lines' less than a full screen.
4770 Negative ARG means scroll downward.
4771 If ARG is the atom `-', scroll downward by nearly full screen.
4772 When calling from a program, supply as argument a number, nil, or `-'. */)
4775 scroll_command (arg
, 1);
4779 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4780 doc
: /* Scroll text of selected window down ARG lines.
4781 If ARG is omitted or nil, scroll down by a near full screen.
4782 A near full screen is `next-screen-context-lines' less than a full screen.
4783 Negative ARG means scroll upward.
4784 If ARG is the atom `-', scroll upward by nearly full screen.
4785 When calling from a program, supply as argument a number, nil, or `-'. */)
4788 scroll_command (arg
, -1);
4792 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4793 doc
: /* Return the other window for \"other window scroll\" commands.
4794 If `other-window-scroll-buffer' is non-nil, a window
4795 showing that buffer is used.
4796 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4797 specifies the window. This takes precedence over
4798 `other-window-scroll-buffer'. */)
4803 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4804 && !NILP (Vminibuf_scroll_window
))
4805 window
= Vminibuf_scroll_window
;
4806 /* If buffer is specified, scroll that buffer. */
4807 else if (!NILP (Vother_window_scroll_buffer
))
4809 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4811 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4815 /* Nothing specified; look for a neighboring window on the same
4817 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4819 if (EQ (window
, selected_window
))
4820 /* That didn't get us anywhere; look for a window on another
4823 window
= Fnext_window (window
, Qnil
, Qt
);
4824 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4825 && ! EQ (window
, selected_window
));
4828 CHECK_LIVE_WINDOW (window
);
4830 if (EQ (window
, selected_window
))
4831 error ("There is no other window");
4836 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4837 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4838 A near full screen is `next-screen-context-lines' less than a full screen.
4839 The next window is the one below the current one; or the one at the top
4840 if the current one is at the bottom. Negative ARG means scroll downward.
4841 If ARG is the atom `-', scroll downward by nearly full screen.
4842 When calling from a program, supply as argument a number, nil, or `-'.
4844 If `other-window-scroll-buffer' is non-nil, scroll the window
4845 showing that buffer, popping the buffer up if necessary.
4846 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4847 specifies the window to scroll. This takes precedence over
4848 `other-window-scroll-buffer'. */)
4853 ptrdiff_t count
= SPECPDL_INDEX ();
4855 window
= Fother_window_for_scrolling ();
4856 w
= XWINDOW (window
);
4858 /* Don't screw up if window_scroll gets an error. */
4859 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4860 ++windows_or_buffers_changed
;
4862 Fset_buffer (WGET (w
, buffer
));
4863 SET_PT (marker_position (WGET (w
, pointm
)));
4866 window_scroll (window
, 1, 1, 1);
4867 else if (EQ (arg
, Qminus
))
4868 window_scroll (window
, -1, 1, 1);
4874 window_scroll (window
, XINT (arg
), 0, 1);
4877 set_marker_both (WGET (w
, pointm
), Qnil
, PT
, PT_BYTE
);
4878 unbind_to (count
, Qnil
);
4883 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
4884 doc
: /* Scroll selected window display ARG columns left.
4885 Default for ARG is window width minus 2.
4886 Value is the total amount of leftward horizontal scrolling in
4887 effect after the change.
4888 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4889 lower bound for automatic scrolling, i.e. automatic scrolling
4890 will not scroll a window to a column less than the value returned
4891 by this function. This happens in an interactive call. */)
4892 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4894 struct window
*w
= XWINDOW (selected_window
);
4895 EMACS_INT requested_arg
= (NILP (arg
)
4896 ? window_body_cols (w
) - 2
4897 : XINT (Fprefix_numeric_value (arg
)));
4898 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
+ requested_arg
);
4900 if (!NILP (set_minimum
))
4901 w
->min_hscroll
= w
->hscroll
;
4906 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
4907 doc
: /* Scroll selected window display ARG columns right.
4908 Default for ARG is window width minus 2.
4909 Value is the total amount of leftward horizontal scrolling in
4910 effect after the change.
4911 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4912 lower bound for automatic scrolling, i.e. automatic scrolling
4913 will not scroll a window to a column less than the value returned
4914 by this function. This happens in an interactive call. */)
4915 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4917 struct window
*w
= XWINDOW (selected_window
);
4918 EMACS_INT requested_arg
= (NILP (arg
)
4919 ? window_body_cols (w
) - 2
4920 : XINT (Fprefix_numeric_value (arg
)));
4921 Lisp_Object result
= set_window_hscroll (w
, w
->hscroll
- requested_arg
);
4923 if (!NILP (set_minimum
))
4924 w
->min_hscroll
= w
->hscroll
;
4929 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
4930 doc
: /* Return the window which was selected when entering the minibuffer.
4931 Returns nil, if selected window is not a minibuffer window. */)
4934 if (minibuf_level
> 0
4935 && MINI_WINDOW_P (XWINDOW (selected_window
))
4936 && WINDOW_LIVE_P (minibuf_selected_window
))
4937 return minibuf_selected_window
;
4942 /* Value is the number of lines actually displayed in window W,
4943 as opposed to its height. */
4946 displayed_window_lines (struct window
*w
)
4949 struct text_pos start
;
4950 int height
= window_box_height (w
);
4951 struct buffer
*old_buffer
;
4953 void *itdata
= NULL
;
4955 if (XBUFFER (WGET (w
, buffer
)) != current_buffer
)
4957 old_buffer
= current_buffer
;
4958 set_buffer_internal (XBUFFER (WGET (w
, buffer
)));
4963 /* In case W->start is out of the accessible range, do something
4964 reasonable. This happens in Info mode when Info-scroll-down
4965 calls (recenter -1) while W->start is 1. */
4966 if (XMARKER (WGET (w
, start
))->charpos
< BEGV
)
4967 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4968 else if (XMARKER (WGET (w
, start
))->charpos
> ZV
)
4969 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4971 SET_TEXT_POS_FROM_MARKER (start
, WGET (w
, start
));
4973 itdata
= bidi_shelve_cache ();
4974 start_display (&it
, w
, start
);
4975 move_it_vertically (&it
, height
);
4976 bottom_y
= line_bottom_y (&it
);
4977 bidi_unshelve_cache (itdata
, 0);
4979 /* rms: On a non-window display,
4980 the value of it.vpos at the bottom of the screen
4981 seems to be 1 larger than window_box_height (w).
4982 This kludge fixes a bug whereby (move-to-window-line -1)
4983 when ZV is on the last screen line
4984 moves to the previous screen line instead of the last one. */
4985 if (! FRAME_WINDOW_P (XFRAME (WGET (w
, frame
))))
4988 /* Add in empty lines at the bottom of the window. */
4989 if (bottom_y
< height
)
4991 int uy
= FRAME_LINE_HEIGHT (it
.f
);
4992 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
4996 set_buffer_internal (old_buffer
);
5002 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5003 doc
: /* Center point in selected window and maybe redisplay frame.
5004 With prefix argument ARG, recenter putting point on screen line ARG
5005 relative to the selected window. If ARG is negative, it counts up from the
5006 bottom of the window. (ARG should be less than the height of the window.)
5008 If ARG is omitted or nil, then recenter with point on the middle line of
5009 the selected window; if the variable `recenter-redisplay' is non-nil,
5010 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5011 is set to `grow-only', this resets the tool-bar's height to the minimum
5012 height needed); if `recenter-redisplay' has the special value `tty',
5013 then only tty frames are redrawn.
5015 Just C-u as prefix means put point in the center of the window
5016 and redisplay normally--don't erase and redraw the frame. */)
5017 (register Lisp_Object arg
)
5019 struct window
*w
= XWINDOW (selected_window
);
5020 struct buffer
*buf
= XBUFFER (WGET (w
, buffer
));
5021 struct buffer
*obuf
= current_buffer
;
5023 ptrdiff_t charpos
, bytepos
;
5024 EMACS_INT iarg
IF_LINT (= 0);
5025 int this_scroll_margin
;
5027 /* If redisplay is suppressed due to an error, try again. */
5028 obuf
->display_error_modiff
= 0;
5032 if (!NILP (Vrecenter_redisplay
)
5033 && (!EQ (Vrecenter_redisplay
, Qtty
)
5034 || !NILP (Ftty_type (selected_frame
))))
5038 /* Invalidate pixel data calculated for all compositions. */
5039 for (i
= 0; i
< n_compositions
; i
++)
5040 composition_table
[i
]->font
= NULL
;
5042 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5044 Fredraw_frame (WINDOW_FRAME (w
));
5045 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5050 else if (CONSP (arg
)) /* Just C-u. */
5054 arg
= Fprefix_numeric_value (arg
);
5059 set_buffer_internal (buf
);
5061 /* Do this after making BUF current
5062 in case scroll_margin is buffer-local. */
5063 this_scroll_margin
=
5064 max (0, min (scroll_margin
, XFASTINT (WGET (w
, total_lines
)) / 4));
5066 /* Handle centering on a graphical frame specially. Such frames can
5067 have variable-height lines and centering point on the basis of
5068 line counts would lead to strange effects. */
5069 if (FRAME_WINDOW_P (XFRAME (WGET (w
, frame
))))
5075 void *itdata
= bidi_shelve_cache ();
5077 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5078 start_display (&it
, w
, pt
);
5079 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5080 charpos
= IT_CHARPOS (it
);
5081 bytepos
= IT_BYTEPOS (it
);
5082 bidi_unshelve_cache (itdata
, 0);
5088 ptrdiff_t nlines
= min (PTRDIFF_MAX
, -iarg
);
5089 int extra_line_spacing
;
5090 int h
= window_box_height (w
);
5091 void *itdata
= bidi_shelve_cache ();
5093 iarg
= - max (-iarg
, this_scroll_margin
);
5095 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5096 start_display (&it
, w
, pt
);
5098 /* Be sure we have the exact height of the full line containing PT. */
5099 move_it_by_lines (&it
, 0);
5101 /* The amount of pixels we have to move back is the window
5102 height minus what's displayed in the line containing PT,
5103 and the lines below. */
5106 move_it_by_lines (&it
, nlines
);
5108 if (it
.vpos
== nlines
)
5112 /* Last line has no newline */
5113 h
-= line_bottom_y (&it
);
5117 /* Don't reserve space for extra line spacing of last line. */
5118 extra_line_spacing
= it
.max_extra_line_spacing
;
5120 /* If we can't move down NLINES lines because we hit
5121 the end of the buffer, count in some empty lines. */
5122 if (it
.vpos
< nlines
)
5125 extra_line_spacing
= it
.extra_line_spacing
;
5126 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5130 bidi_unshelve_cache (itdata
, 0);
5134 /* Now find the new top line (starting position) of the window. */
5135 start_display (&it
, w
, pt
);
5137 move_it_vertically_backward (&it
, h
);
5139 /* If extra line spacing is present, we may move too far
5140 back. This causes the last line to be only partially
5141 visible (which triggers redisplay to recenter that line
5142 in the middle), so move forward.
5143 But ignore extra line spacing on last line, as it is not
5144 considered to be part of the visible height of the line.
5146 h
+= extra_line_spacing
;
5147 while (-it
.current_y
> h
)
5148 move_it_by_lines (&it
, 1);
5150 charpos
= IT_CHARPOS (it
);
5151 bytepos
= IT_BYTEPOS (it
);
5153 bidi_unshelve_cache (itdata
, 0);
5157 struct position pos
;
5159 iarg
= max (iarg
, this_scroll_margin
);
5161 pos
= *vmotion (PT
, -iarg
, w
);
5162 charpos
= pos
.bufpos
;
5163 bytepos
= pos
.bytepos
;
5168 struct position pos
;
5169 int ht
= window_internal_height (w
);
5176 /* Don't let it get into the margin at either top or bottom. */
5177 iarg
= max (iarg
, this_scroll_margin
);
5178 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5180 pos
= *vmotion (PT
, - iarg
, w
);
5181 charpos
= pos
.bufpos
;
5182 bytepos
= pos
.bytepos
;
5185 /* Set the new window start. */
5186 set_marker_both (WGET (w
, start
), WGET (w
, buffer
), charpos
, bytepos
);
5187 WSET (w
, window_end_valid
, Qnil
);
5189 w
->optional_new_start
= 1;
5191 w
->start_at_line_beg
= (bytepos
== BEGV_BYTE
||
5192 FETCH_BYTE (bytepos
- 1) == '\n');
5194 set_buffer_internal (obuf
);
5198 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5200 doc
: /* Return the height in lines of the text display area of WINDOW.
5201 If WINDOW is omitted or nil, it defaults to the selected window.
5203 The returned height does not include the mode line, any header line,
5204 nor any partial-height lines at the bottom of the text area. */)
5205 (Lisp_Object window
)
5207 struct window
*w
= decode_window (window
);
5208 int pixel_height
= window_box_height (w
);
5209 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (WGET (w
, frame
)));
5210 return make_number (line_height
);
5215 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5217 doc
: /* Position point relative to window.
5218 ARG nil means position point at center of window.
5219 Else, ARG specifies vertical position within the window;
5220 zero means top of window, negative means relative to bottom of window. */)
5223 struct window
*w
= XWINDOW (selected_window
);
5227 int this_scroll_margin
;
5230 if (!(BUFFERP (WGET (w
, buffer
))
5231 && XBUFFER (WGET (w
, buffer
)) == current_buffer
))
5232 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5233 when passed below to set_marker_both. */
5234 error ("move-to-window-line called from unrelated buffer");
5236 window
= selected_window
;
5237 start
= marker_position (WGET (w
, start
));
5238 if (start
< BEGV
|| start
> ZV
)
5240 int height
= window_internal_height (w
);
5241 Fvertical_motion (make_number (- (height
/ 2)), window
);
5242 set_marker_both (WGET (w
, start
), WGET (w
, buffer
), PT
, PT_BYTE
);
5243 w
->start_at_line_beg
= !NILP (Fbolp ());
5247 Fgoto_char (WGET (w
, start
));
5249 lines
= displayed_window_lines (w
);
5252 this_scroll_margin
= max (0, min (scroll_margin
, lines
/ 4));
5256 XSETFASTINT (arg
, lines
/ 2);
5259 EMACS_INT iarg
= XINT (Fprefix_numeric_value (arg
));
5262 iarg
= iarg
+ lines
;
5264 #if 0 /* This code would prevent move-to-window-line from moving point
5265 to a place inside the scroll margins (which would cause the
5266 next redisplay to scroll). I wrote this code, but then concluded
5267 it is probably better not to install it. However, it is here
5268 inside #if 0 so as not to lose it. -- rms. */
5270 /* Don't let it get into the margin at either top or bottom. */
5271 iarg
= max (iarg
, this_scroll_margin
);
5272 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5275 arg
= make_number (iarg
);
5278 /* Skip past a partially visible first line. */
5280 XSETINT (arg
, XINT (arg
) + 1);
5282 return Fvertical_motion (arg
, window
);
5287 /***********************************************************************
5288 Window Configuration
5289 ***********************************************************************/
5291 struct save_window_data
5293 struct vectorlike_header header
;
5294 Lisp_Object selected_frame
;
5295 Lisp_Object current_window
;
5296 Lisp_Object current_buffer
;
5297 Lisp_Object minibuf_scroll_window
;
5298 Lisp_Object minibuf_selected_window
;
5299 Lisp_Object root_window
;
5300 Lisp_Object focus_frame
;
5301 /* A vector, each of whose elements is a struct saved_window
5303 Lisp_Object saved_windows
;
5305 /* All fields above are traced by the GC.
5306 From `fame-cols' down, the fields are ignored by the GC. */
5308 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5309 int frame_tool_bar_lines
;
5312 /* This is saved as a Lisp_Vector */
5315 struct vectorlike_header header
;
5317 Lisp_Object window
, buffer
, start
, pointm
, mark
;
5318 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5319 Lisp_Object normal_cols
, normal_lines
;
5320 Lisp_Object hscroll
, min_hscroll
;
5321 Lisp_Object parent
, prev
;
5322 Lisp_Object start_at_line_beg
;
5323 Lisp_Object display_table
;
5324 Lisp_Object left_margin_cols
, right_margin_cols
;
5325 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5326 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5327 Lisp_Object combination_limit
, window_parameters
;
5330 #define SAVED_WINDOW_N(swv,n) \
5331 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5333 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5334 doc
: /* Return t if OBJECT is a window-configuration object. */)
5335 (Lisp_Object object
)
5337 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5340 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5341 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5342 (Lisp_Object config
)
5344 register struct save_window_data
*data
;
5345 struct Lisp_Vector
*saved_windows
;
5347 CHECK_WINDOW_CONFIGURATION (config
);
5349 data
= (struct save_window_data
*) XVECTOR (config
);
5350 saved_windows
= XVECTOR (data
->saved_windows
);
5351 return WGET (XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
), frame
);
5354 DEFUN ("set-window-configuration", Fset_window_configuration
,
5355 Sset_window_configuration
, 1, 1, 0,
5356 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5357 CONFIGURATION must be a value previously returned
5358 by `current-window-configuration' (which see).
5359 If CONFIGURATION was made from a frame that is now deleted,
5360 only frame-independent values can be restored. In this case,
5361 the return value is nil. Otherwise the value is t. */)
5362 (Lisp_Object configuration
)
5364 register struct save_window_data
*data
;
5365 struct Lisp_Vector
*saved_windows
;
5366 Lisp_Object new_current_buffer
;
5368 Lisp_Object auto_buffer_name
;
5370 ptrdiff_t old_point
= -1;
5372 CHECK_WINDOW_CONFIGURATION (configuration
);
5374 data
= (struct save_window_data
*) XVECTOR (configuration
);
5375 saved_windows
= XVECTOR (data
->saved_windows
);
5377 new_current_buffer
= data
->current_buffer
;
5378 if (NILP (BVAR (XBUFFER (new_current_buffer
), name
)))
5379 new_current_buffer
= Qnil
;
5382 if (XBUFFER (new_current_buffer
) == current_buffer
)
5383 /* The code further down "preserves point" by saving here PT in
5384 old_point and then setting it later back into PT. When the
5385 current-selected-window and the final-selected-window both show
5386 the current buffer, this suffers from the problem that the
5387 current PT is the window-point of the current-selected-window,
5388 while the final PT is the point of the final-selected-window, so
5389 this copy from one PT to the other would end up moving the
5390 window-point of the final-selected-window to the window-point of
5391 the current-selected-window. So we have to be careful which
5392 point of the current-buffer we copy into old_point. */
5393 if (EQ (WGET (XWINDOW (data
->current_window
), buffer
), new_current_buffer
)
5394 && WINDOWP (selected_window
)
5395 && EQ (WGET (XWINDOW (selected_window
), buffer
), new_current_buffer
)
5396 && !EQ (selected_window
, data
->current_window
))
5397 old_point
= XMARKER (WGET (XWINDOW (data
->current_window
), pointm
))->charpos
;
5401 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5402 point in new_current_buffer as of the last time this buffer was
5403 used. This can be non-deterministic since it can be changed by
5404 things like jit-lock by mere temporary selection of some random
5405 window that happens to show this buffer.
5406 So if possible we want this arbitrary choice of "which point" to
5407 be the one from the to-be-selected-window so as to prevent this
5408 window's cursor from being copied from another window. */
5409 if (EQ (WGET (XWINDOW (data
->current_window
), buffer
), new_current_buffer
)
5410 /* If current_window = selected_window, its point is in BUF_PT. */
5411 && !EQ (selected_window
, data
->current_window
))
5412 old_point
= XMARKER (WGET (XWINDOW (data
->current_window
), pointm
))->charpos
;
5414 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5417 frame
= WGET (XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
), frame
);
5420 /* If f is a dead frame, don't bother rebuilding its window tree.
5421 However, there is other stuff we should still try to do below. */
5422 if (FRAME_LIVE_P (f
))
5425 Lisp_Object dead_windows
= Qnil
;
5426 register Lisp_Object tem
, par
, pers
;
5427 register struct window
*w
;
5428 register struct saved_window
*p
;
5429 struct window
*root_window
;
5430 struct window
**leaf_windows
;
5435 /* If the frame has been resized since this window configuration was
5436 made, we change the frame to the size specified in the
5437 configuration, restore the configuration, and then resize it
5438 back. We keep track of the prevailing height in these variables. */
5439 int previous_frame_lines
= FRAME_LINES (f
);
5440 int previous_frame_cols
= FRAME_COLS (f
);
5441 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5442 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5444 /* The mouse highlighting code could get screwed up
5445 if it runs during this. */
5448 if (data
->frame_lines
!= previous_frame_lines
5449 || data
->frame_cols
!= previous_frame_cols
)
5450 change_frame_size (f
, data
->frame_lines
,
5451 data
->frame_cols
, 0, 0, 0);
5452 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5453 if (data
->frame_menu_bar_lines
5454 != previous_frame_menu_bar_lines
)
5455 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5457 #ifdef HAVE_WINDOW_SYSTEM
5458 if (data
->frame_tool_bar_lines
5459 != previous_frame_tool_bar_lines
)
5460 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5465 /* "Swap out" point from the selected window's buffer
5466 into the window itself. (Normally the pointm of the selected
5467 window holds garbage.) We do this now, before
5468 restoring the window contents, and prevent it from
5469 being done later on when we select a new window. */
5470 if (! NILP (WGET (XWINDOW (selected_window
), buffer
)))
5472 w
= XWINDOW (selected_window
);
5473 set_marker_both (WGET (w
, pointm
),
5475 BUF_PT (XBUFFER (WGET (w
, buffer
))),
5476 BUF_PT_BYTE (XBUFFER (WGET (w
, buffer
))));
5479 windows_or_buffers_changed
++;
5480 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5482 /* Problem: Freeing all matrices and later allocating them again
5483 is a serious redisplay flickering problem. What we would
5484 really like to do is to free only those matrices not reused
5486 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5487 leaf_windows
= alloca (count_windows (root_window
)
5488 * sizeof *leaf_windows
);
5489 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5492 Mark all windows now on frame as "deleted".
5493 Restoring the new configuration "undeletes" any that are in it.
5495 Save their current buffers in their height fields, since we may
5496 need it later, if a buffer saved in the configuration is now
5498 delete_all_child_windows (FRAME_ROOT_WINDOW (f
));
5500 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
5502 p
= SAVED_WINDOW_N (saved_windows
, k
);
5504 w
= XWINDOW (window
);
5505 WSET (w
, next
, Qnil
);
5507 if (!NILP (p
->parent
))
5508 WSET (w
, parent
, SAVED_WINDOW_N (saved_windows
,
5509 XFASTINT (p
->parent
))->window
);
5511 WSET (w
, parent
, Qnil
);
5513 if (!NILP (p
->prev
))
5515 WSET (w
, prev
, SAVED_WINDOW_N (saved_windows
,
5516 XFASTINT (p
->prev
))->window
);
5517 WSET (XWINDOW (WGET (w
, prev
)), next
, p
->window
);
5521 WSET (w
, prev
, Qnil
);
5522 if (!NILP (WGET (w
, parent
)))
5524 if (EQ (p
->total_cols
, WGET (XWINDOW (WGET (w
, parent
)), total_cols
)))
5526 WSET (XWINDOW (WGET (w
, parent
)), vchild
, p
->window
);
5527 WSET (XWINDOW (WGET (w
, parent
)), hchild
, Qnil
);
5531 WSET (XWINDOW (WGET (w
, parent
)), hchild
, p
->window
);
5532 WSET (XWINDOW (WGET (w
, parent
)), vchild
, Qnil
);
5537 /* If we squirreled away the buffer in the window's height,
5539 if (BUFFERP (WGET (w
, total_lines
)))
5540 WSET (w
, buffer
, WGET (w
, total_lines
));
5541 WSET (w
, left_col
, p
->left_col
);
5542 WSET (w
, top_line
, p
->top_line
);
5543 WSET (w
, total_cols
, p
->total_cols
);
5544 WSET (w
, total_lines
, p
->total_lines
);
5545 WSET (w
, normal_cols
, p
->normal_cols
);
5546 WSET (w
, normal_lines
, p
->normal_lines
);
5547 w
->hscroll
= XFASTINT (p
->hscroll
);
5548 w
->min_hscroll
= XFASTINT (p
->min_hscroll
);
5549 WSET (w
, display_table
, p
->display_table
);
5550 WSET (w
, left_margin_cols
, p
->left_margin_cols
);
5551 WSET (w
, right_margin_cols
, p
->right_margin_cols
);
5552 WSET (w
, left_fringe_width
, p
->left_fringe_width
);
5553 WSET (w
, right_fringe_width
, p
->right_fringe_width
);
5554 w
->fringes_outside_margins
= !NILP (p
->fringes_outside_margins
);
5555 WSET (w
, scroll_bar_width
, p
->scroll_bar_width
);
5556 WSET (w
, vertical_scroll_bar_type
, p
->vertical_scroll_bar_type
);
5557 WSET (w
, dedicated
, p
->dedicated
);
5558 WSET (w
, combination_limit
, p
->combination_limit
);
5559 /* Restore any window parameters that have been saved.
5560 Parameters that have not been saved are left alone. */
5561 for (tem
= p
->window_parameters
; CONSP (tem
); tem
= XCDR (tem
))
5566 if (NILP (XCDR (pers
)))
5568 par
= Fassq (XCAR (pers
), WGET (w
, window_parameters
));
5569 if (CONSP (par
) && !NILP (XCDR (par
)))
5570 /* Reset a parameter to nil if and only if it
5571 has a non-nil association. Don't make new
5573 Fsetcdr (par
, Qnil
);
5576 /* Always restore a non-nil value. */
5577 Fset_window_parameter (window
, XCAR (pers
), XCDR (pers
));
5581 w
->last_modified
= 0;
5582 w
->last_overlay_modified
= 0;
5584 /* Reinstall the saved buffer and pointers into it. */
5585 if (NILP (p
->buffer
))
5586 /* An internal window. */
5587 WSET (w
, buffer
, p
->buffer
);
5588 else if (!NILP (BVAR (XBUFFER (p
->buffer
), name
)))
5589 /* If saved buffer is alive, install it. */
5591 WSET (w
, buffer
, p
->buffer
);
5592 w
->start_at_line_beg
= !NILP (p
->start_at_line_beg
);
5593 set_marker_restricted (WGET (w
, start
), p
->start
, WGET (w
, buffer
));
5594 set_marker_restricted (WGET (w
, pointm
), p
->pointm
,
5596 Fset_marker (BVAR (XBUFFER (WGET (w
, buffer
)), mark
),
5597 p
->mark
, WGET (w
, buffer
));
5599 /* As documented in Fcurrent_window_configuration, don't
5600 restore the location of point in the buffer which was
5601 current when the window configuration was recorded. */
5602 if (!EQ (p
->buffer
, new_current_buffer
)
5603 && XBUFFER (p
->buffer
) == current_buffer
)
5604 Fgoto_char (WGET (w
, pointm
));
5606 else if (!NILP (WGET (w
, buffer
))
5607 && !NILP (BVAR (XBUFFER (WGET (w
, buffer
)), name
)))
5608 /* Keep window's old buffer; make sure the markers are
5611 /* Set window markers at start of visible range. */
5612 if (XMARKER (WGET (w
, start
))->buffer
== 0)
5613 set_marker_restricted (WGET (w
, start
), make_number (0),
5615 if (XMARKER (WGET (w
, pointm
))->buffer
== 0)
5616 set_marker_restricted_both
5617 (WGET (w
, pointm
), WGET (w
, buffer
),
5618 BUF_PT (XBUFFER (WGET (w
, buffer
))),
5619 BUF_PT_BYTE (XBUFFER (WGET (w
, buffer
))));
5620 w
->start_at_line_beg
= 1;
5622 else if (STRINGP (auto_buffer_name
=
5623 Fwindow_parameter (window
, Qauto_buffer_name
))
5624 && SCHARS (auto_buffer_name
) != 0
5625 && !NILP (WSET (w
, buffer
, Fget_buffer_create (auto_buffer_name
))))
5627 set_marker_restricted (WGET (w
, start
),
5628 make_number (0), WGET (w
, buffer
));
5629 set_marker_restricted (WGET (w
, pointm
),
5630 make_number (0), WGET (w
, buffer
));
5631 w
->start_at_line_beg
= 1;
5634 /* Window has no live buffer, get one. */
5636 /* Get the buffer via other_buffer_safely in order to
5637 avoid showing an unimportant buffer and, if necessary, to
5638 recreate *scratch* in the course (part of Juanma's bs-show
5639 scenario from March 2011). */
5640 WSET (w
, buffer
, other_buffer_safely (Fcurrent_buffer ()));
5641 /* This will set the markers to beginning of visible
5643 set_marker_restricted (WGET (w
, start
),
5644 make_number (0), WGET (w
, buffer
));
5645 set_marker_restricted (WGET (w
, pointm
),
5646 make_number (0), WGET (w
, buffer
));
5647 w
->start_at_line_beg
= 1;
5648 if (!NILP (WGET (w
, dedicated
)))
5649 /* Record this window as dead. */
5650 dead_windows
= Fcons (window
, dead_windows
);
5651 /* Make sure window is no more dedicated. */
5652 WSET (w
, dedicated
, Qnil
);
5656 FSET (f
, root_window
, data
->root_window
);
5657 /* Arrange *not* to restore point in the buffer that was
5658 current when the window configuration was saved. */
5659 if (EQ (WGET (XWINDOW (data
->current_window
), buffer
), new_current_buffer
))
5660 set_marker_restricted (WGET (XWINDOW (data
->current_window
), pointm
),
5661 make_number (old_point
),
5662 WGET (XWINDOW (data
->current_window
), buffer
));
5664 /* In the following call to `select-window', prevent "swapping out
5665 point" in the old selected window using the buffer that has
5666 been restored into it. We already swapped out that point from
5667 that window's old buffer. */
5668 select_window (data
->current_window
, Qnil
, 1);
5669 BVAR (XBUFFER (WGET (XWINDOW (selected_window
), buffer
)), last_selected_window
)
5672 if (NILP (data
->focus_frame
)
5673 || (FRAMEP (data
->focus_frame
)
5674 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5675 Fredirect_frame_focus (frame
, data
->focus_frame
);
5677 /* Set the screen height to the value it had before this function. */
5678 if (previous_frame_lines
!= FRAME_LINES (f
)
5679 || previous_frame_cols
!= FRAME_COLS (f
))
5680 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5682 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5683 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5684 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5686 #ifdef HAVE_WINDOW_SYSTEM
5687 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5688 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5693 /* Now, free glyph matrices in windows that were not reused. */
5694 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5696 if (NILP (WGET (leaf_windows
[i
], buffer
)))
5698 /* Assert it's not reused as a combination. */
5699 eassert (NILP (WGET (leaf_windows
[i
], hchild
))
5700 && NILP (WGET (leaf_windows
[i
], vchild
)));
5701 free_window_matrices (leaf_windows
[i
]);
5703 else if (EQ (WGET (leaf_windows
[i
], buffer
), new_current_buffer
))
5710 /* Scan dead buffer windows. */
5711 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5713 window
= XCAR (dead_windows
);
5714 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5715 delete_deletable_window (window
);
5718 /* Fselect_window will have made f the selected frame, so we
5719 reselect the proper frame here. Fhandle_switch_frame will change the
5720 selected window too, but that doesn't make the call to
5721 Fselect_window above totally superfluous; it still sets f's
5723 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5724 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5726 run_window_configuration_change_hook (f
);
5729 if (!NILP (new_current_buffer
))
5730 Fset_buffer (new_current_buffer
);
5732 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5733 minibuf_selected_window
= data
->minibuf_selected_window
;
5735 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5739 /* Recursively delete all child windows reachable via the next, vchild,
5740 and hchild slots of WINDOW. */
5742 delete_all_child_windows (Lisp_Object window
)
5744 register struct window
*w
;
5746 w
= XWINDOW (window
);
5748 if (!NILP (WGET (w
, next
)))
5749 /* Delete WINDOW's siblings (we traverse postorderly). */
5750 delete_all_child_windows (WGET (w
, next
));
5752 WSET (w
, total_lines
, WGET (w
, buffer
)); /* See Fset_window_configuration for excuse. */
5754 if (!NILP (WGET (w
, vchild
)))
5756 delete_all_child_windows (WGET (w
, vchild
));
5757 WSET (w
, vchild
, Qnil
);
5759 else if (!NILP (WGET (w
, hchild
)))
5761 delete_all_child_windows (WGET (w
, hchild
));
5762 WSET (w
, hchild
, Qnil
);
5764 else if (!NILP (WGET (w
, buffer
)))
5767 unchain_marker (XMARKER (WGET (w
, pointm
)));
5768 unchain_marker (XMARKER (WGET (w
, start
)));
5769 WSET (w
, buffer
, Qnil
);
5772 Vwindow_list
= Qnil
;
5776 count_windows (register struct window
*window
)
5778 register int count
= 1;
5779 if (!NILP (WGET (window
, next
)))
5780 count
+= count_windows (XWINDOW (WGET (window
, next
)));
5781 if (!NILP (WGET (window
, vchild
)))
5782 count
+= count_windows (XWINDOW (WGET (window
, vchild
)));
5783 if (!NILP (WGET (window
, hchild
)))
5784 count
+= count_windows (XWINDOW (WGET (window
, hchild
)));
5789 /* Fill vector FLAT with leaf windows under W, starting at index I.
5790 Value is last index + 1. */
5792 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5796 if (!NILP (WGET (w
, hchild
)))
5797 i
= get_leaf_windows (XWINDOW (WGET (w
, hchild
)), flat
, i
);
5798 else if (!NILP (WGET (w
, vchild
)))
5799 i
= get_leaf_windows (XWINDOW (WGET (w
, vchild
)), flat
, i
);
5803 w
= NILP (WGET (w
, next
)) ? 0 : XWINDOW (WGET (w
, next
));
5810 /* Return a pointer to the glyph W's physical cursor is on. Value is
5811 null if W's current matrix is invalid, so that no meaningful glyph
5814 get_phys_cursor_glyph (struct window
*w
)
5816 struct glyph_row
*row
;
5817 struct glyph
*glyph
;
5818 int hpos
= w
->phys_cursor
.hpos
;
5820 if (!(w
->phys_cursor
.vpos
>= 0
5821 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
))
5824 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
5825 if (!row
->enabled_p
)
5830 /* When the window is hscrolled, cursor hpos can legitimately be
5831 out of bounds, but we draw the cursor at the corresponding
5832 window margin in that case. */
5833 if (!row
->reversed_p
&& hpos
< 0)
5835 if (row
->reversed_p
&& hpos
>= row
->used
[TEXT_AREA
])
5836 hpos
= row
->used
[TEXT_AREA
] - 1;
5839 if (row
->used
[TEXT_AREA
] > hpos
5841 glyph
= row
->glyphs
[TEXT_AREA
] + hpos
;
5850 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
5852 register struct saved_window
*p
;
5853 register struct window
*w
;
5854 register Lisp_Object tem
, pers
, par
;
5856 for (;!NILP (window
); window
= WGET (w
, next
))
5858 p
= SAVED_WINDOW_N (vector
, i
);
5859 w
= XWINDOW (window
);
5861 WSET (w
, temslot
, make_number (i
)); i
++;
5863 p
->buffer
= WGET (w
, buffer
);
5864 p
->left_col
= WGET (w
, left_col
);
5865 p
->top_line
= WGET (w
, top_line
);
5866 p
->total_cols
= WGET (w
, total_cols
);
5867 p
->total_lines
= WGET (w
, total_lines
);
5868 p
->normal_cols
= WGET (w
, normal_cols
);
5869 p
->normal_lines
= WGET (w
, normal_lines
);
5870 XSETFASTINT (p
->hscroll
, w
->hscroll
);
5871 XSETFASTINT (p
->min_hscroll
, w
->min_hscroll
);
5872 p
->display_table
= WGET (w
, display_table
);
5873 p
->left_margin_cols
= WGET (w
, left_margin_cols
);
5874 p
->right_margin_cols
= WGET (w
, right_margin_cols
);
5875 p
->left_fringe_width
= WGET (w
, left_fringe_width
);
5876 p
->right_fringe_width
= WGET (w
, right_fringe_width
);
5877 p
->fringes_outside_margins
= w
->fringes_outside_margins
? Qt
: Qnil
;
5878 p
->scroll_bar_width
= WGET (w
, scroll_bar_width
);
5879 p
->vertical_scroll_bar_type
= WGET (w
, vertical_scroll_bar_type
);
5880 p
->dedicated
= WGET (w
, dedicated
);
5881 p
->combination_limit
= WGET (w
, combination_limit
);
5882 p
->window_parameters
= Qnil
;
5884 if (!NILP (Vwindow_persistent_parameters
))
5886 /* Run cycle detection on Vwindow_persistent_parameters. */
5887 Lisp_Object tortoise
, hare
;
5889 hare
= tortoise
= Vwindow_persistent_parameters
;
5890 while (CONSP (hare
))
5897 tortoise
= XCDR (tortoise
);
5899 if (EQ (hare
, tortoise
))
5900 /* Reset Vwindow_persistent_parameters to Qnil. */
5902 Vwindow_persistent_parameters
= Qnil
;
5907 for (tem
= Vwindow_persistent_parameters
; CONSP (tem
);
5911 /* Save values for persistent window parameters. */
5912 if (CONSP (pers
) && !NILP (XCDR (pers
)))
5914 par
= Fassq (XCAR (pers
), WGET (w
, window_parameters
));
5916 /* If the window has no value for the parameter,
5918 p
->window_parameters
= Fcons (Fcons (XCAR (pers
), Qnil
),
5919 p
->window_parameters
);
5921 /* If the window has a value for the parameter,
5923 p
->window_parameters
= Fcons (Fcons (XCAR (par
),
5925 p
->window_parameters
);
5930 if (!NILP (WGET (w
, buffer
)))
5932 /* Save w's value of point in the window configuration. If w
5933 is the selected window, then get the value of point from
5934 the buffer; pointm is garbage in the selected window. */
5935 if (EQ (window
, selected_window
))
5936 p
->pointm
= build_marker (XBUFFER (WGET (w
, buffer
)),
5937 BUF_PT (XBUFFER (WGET (w
, buffer
))),
5938 BUF_PT_BYTE (XBUFFER (WGET (w
, buffer
))));
5940 p
->pointm
= Fcopy_marker (WGET (w
, pointm
), Qnil
);
5941 XMARKER (p
->pointm
)->insertion_type
5942 = !NILP (Vwindow_point_insertion_type
);
5944 p
->start
= Fcopy_marker (WGET (w
, start
), Qnil
);
5945 p
->start_at_line_beg
= w
->start_at_line_beg
? Qt
: Qnil
;
5947 tem
= BVAR (XBUFFER (WGET (w
, buffer
)), mark
);
5948 p
->mark
= Fcopy_marker (tem
, Qnil
);
5955 p
->start_at_line_beg
= Qnil
;
5958 if (NILP (WGET (w
, parent
)))
5961 p
->parent
= WGET (XWINDOW (WGET (w
, parent
)), temslot
);
5963 if (NILP (WGET (w
, prev
)))
5966 p
->prev
= WGET (XWINDOW (WGET (w
, prev
)), temslot
);
5968 if (!NILP (WGET (w
, vchild
)))
5969 i
= save_window_save (WGET (w
, vchild
), vector
, i
);
5970 if (!NILP (WGET (w
, hchild
)))
5971 i
= save_window_save (WGET (w
, hchild
), vector
, i
);
5977 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5978 Scurrent_window_configuration
, 0, 1, 0,
5979 doc
: /* Return an object representing the current window configuration of FRAME.
5980 If FRAME is nil or omitted, use the selected frame.
5981 This describes the number of windows, their sizes and current buffers,
5982 and for each displayed buffer, where display starts, and the positions of
5983 point and mark. An exception is made for point in the current buffer:
5984 its value is -not- saved.
5985 This also records the currently selected frame, and FRAME's focus
5986 redirection (see `redirect-frame-focus'). The variable
5987 `window-persistent-parameters' specifies which window parameters are
5988 saved by this function. */)
5991 register Lisp_Object tem
;
5992 register int n_windows
;
5993 register struct save_window_data
*data
;
5998 frame
= selected_frame
;
5999 CHECK_LIVE_FRAME (frame
);
6002 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6003 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6004 PVEC_WINDOW_CONFIGURATION
);
6006 data
->frame_cols
= FRAME_COLS (f
);
6007 data
->frame_lines
= FRAME_LINES (f
);
6008 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6009 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6010 data
->selected_frame
= selected_frame
;
6011 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6012 XSETBUFFER (data
->current_buffer
, current_buffer
);
6013 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6014 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6015 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6016 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6017 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6018 data
->saved_windows
= tem
;
6019 for (i
= 0; i
< n_windows
; i
++)
6021 Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
));
6022 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6023 XSETWINDOW_CONFIGURATION (tem
, data
);
6027 /***********************************************************************
6029 ***********************************************************************/
6031 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6033 doc
: /* Set width of marginal areas of window WINDOW.
6034 If WINDOW is nil, set margins of the currently selected window.
6035 Second arg LEFT-WIDTH specifies the number of character cells to
6036 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6037 does the same for the right marginal area. A nil width parameter
6038 means no margin. */)
6039 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6041 struct window
*w
= decode_window (window
);
6043 /* Translate negative or zero widths to nil.
6044 Margins that are too wide have to be checked elsewhere. */
6046 if (!NILP (left_width
))
6048 CHECK_NUMBER (left_width
);
6049 if (XINT (left_width
) <= 0)
6053 if (!NILP (right_width
))
6055 CHECK_NUMBER (right_width
);
6056 if (XINT (right_width
) <= 0)
6060 if (!EQ (WGET (w
, left_margin_cols
), left_width
)
6061 || !EQ (WGET (w
, right_margin_cols
), right_width
))
6063 WSET (w
, left_margin_cols
, left_width
);
6064 WSET (w
, right_margin_cols
, right_width
);
6066 adjust_window_margins (w
);
6068 ++windows_or_buffers_changed
;
6069 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6076 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6078 doc
: /* Get width of marginal areas of window WINDOW.
6079 If WINDOW is omitted or nil, it defaults to the selected window.
6080 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6081 If a marginal area does not exist, its width will be returned
6083 (Lisp_Object window
)
6085 struct window
*w
= decode_window (window
);
6086 return Fcons (WGET (w
, left_margin_cols
), WGET (w
, right_margin_cols
));
6091 /***********************************************************************
6093 ***********************************************************************/
6095 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6097 doc
: /* Set the fringe widths of window WINDOW.
6098 If WINDOW is nil, set the fringe widths of the currently selected
6100 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6101 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6102 fringe width. If a fringe width arg is nil, that means to use the
6103 frame's default fringe width. Default fringe widths can be set with
6104 the command `set-fringe-style'.
6105 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6106 outside of the display margins. By default, fringes are drawn between
6107 display marginal areas and the text area. */)
6108 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6110 struct window
*w
= decode_window (window
);
6111 int outside
= !NILP (outside_margins
);
6113 if (!NILP (left_width
))
6114 CHECK_NATNUM (left_width
);
6115 if (!NILP (right_width
))
6116 CHECK_NATNUM (right_width
);
6118 /* Do nothing on a tty. */
6119 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6120 && (!EQ (WGET (w
, left_fringe_width
), left_width
)
6121 || !EQ (WGET (w
, right_fringe_width
), right_width
)
6122 || w
->fringes_outside_margins
!= outside
))
6124 WSET (w
, left_fringe_width
, left_width
);
6125 WSET (w
, right_fringe_width
, right_width
);
6126 w
->fringes_outside_margins
= outside
;
6128 adjust_window_margins (w
);
6130 clear_glyph_matrix (w
->current_matrix
);
6131 WSET (w
, window_end_valid
, Qnil
);
6133 ++windows_or_buffers_changed
;
6134 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6141 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6143 doc
: /* Get width of fringes of window WINDOW.
6144 If WINDOW is omitted or nil, it defaults to the selected window.
6145 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6146 (Lisp_Object window
)
6148 struct window
*w
= decode_window (window
);
6150 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6151 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6152 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6153 ? Qt
: Qnil
), Qnil
)));
6158 /***********************************************************************
6160 ***********************************************************************/
6162 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6163 Sset_window_scroll_bars
, 2, 4, 0,
6164 doc
: /* Set width and type of scroll bars of window WINDOW.
6165 If window is nil, set scroll bars of the currently selected window.
6166 Second parameter WIDTH specifies the pixel width for the scroll bar;
6167 this is automatically adjusted to a multiple of the frame column width.
6168 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6169 bar: left, right, or nil.
6170 If WIDTH is nil, use the frame's scroll-bar width.
6171 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6172 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6173 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6175 struct window
*w
= decode_window (window
);
6179 CHECK_RANGED_INTEGER (width
, 0, INT_MAX
);
6181 if (XINT (width
) == 0)
6182 vertical_type
= Qnil
;
6185 if (!(NILP (vertical_type
)
6186 || EQ (vertical_type
, Qleft
)
6187 || EQ (vertical_type
, Qright
)
6188 || EQ (vertical_type
, Qt
)))
6189 error ("Invalid type of vertical scroll bar");
6191 if (!EQ (WGET (w
, scroll_bar_width
), width
)
6192 || !EQ (WGET (w
, vertical_scroll_bar_type
), vertical_type
))
6194 WSET (w
, scroll_bar_width
, width
);
6195 WSET (w
, vertical_scroll_bar_type
, vertical_type
);
6197 adjust_window_margins (w
);
6199 clear_glyph_matrix (w
->current_matrix
);
6200 WSET (w
, window_end_valid
, Qnil
);
6202 ++windows_or_buffers_changed
;
6203 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6210 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6212 doc
: /* Get width and type of scroll bars of window WINDOW.
6213 If WINDOW is omitted or nil, it defaults to the selected window.
6214 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6215 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6217 (Lisp_Object window
)
6219 struct window
*w
= decode_window (window
);
6220 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6221 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6222 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6223 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6224 Fcons (WGET (w
, vertical_scroll_bar_type
),
6225 Fcons (Qnil
, Qnil
))));
6230 /***********************************************************************
6232 ***********************************************************************/
6234 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6235 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6236 If WINDOW is omitted or nil, it defaults to the selected window.
6237 Normally, value is a multiple of the canonical character height of WINDOW;
6238 optional second arg PIXELS-P means value is measured in pixels. */)
6239 (Lisp_Object window
, Lisp_Object pixels_p
)
6246 window
= selected_window
;
6248 CHECK_WINDOW (window
);
6249 w
= XWINDOW (window
);
6250 f
= XFRAME (WGET (w
, frame
));
6252 if (FRAME_WINDOW_P (f
))
6253 result
= (NILP (pixels_p
)
6254 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6255 : make_number (-w
->vscroll
));
6257 result
= make_number (0);
6262 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6264 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6265 WINDOW nil means use the selected window. Normally, VSCROLL is a
6266 non-negative multiple of the canonical character height of WINDOW;
6267 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6268 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6269 corresponds to an integral number of pixels. The return value is the
6270 result of this rounding.
6271 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6272 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6278 window
= selected_window
;
6280 CHECK_WINDOW (window
);
6281 CHECK_NUMBER_OR_FLOAT (vscroll
);
6283 w
= XWINDOW (window
);
6284 f
= XFRAME (WGET (w
, frame
));
6286 if (FRAME_WINDOW_P (f
))
6288 int old_dy
= w
->vscroll
;
6290 w
->vscroll
= - (NILP (pixels_p
)
6291 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6292 : XFLOATINT (vscroll
));
6293 w
->vscroll
= min (w
->vscroll
, 0);
6295 if (w
->vscroll
!= old_dy
)
6297 /* Adjust glyph matrix of the frame if the virtual display
6298 area becomes larger than before. */
6299 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6302 /* Prevent redisplay shortcuts. */
6303 XBUFFER (WGET (w
, buffer
))->prevent_redisplay_optimizations_p
= 1;
6307 return Fwindow_vscroll (window
, pixels_p
);
6311 /* Call FN for all leaf windows on frame F. FN is called with the
6312 first argument being a pointer to the leaf window, and with
6313 additional argument USER_DATA. Stops when FN returns 0. */
6316 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6319 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6320 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6321 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6325 /* Helper function for foreach_window. Call FN for all leaf windows
6326 reachable from W. FN is called with the first argument being a
6327 pointer to the leaf window, and with additional argument USER_DATA.
6328 Stop when FN returns 0. Value is 0 if stopped by FN. */
6331 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6335 for (cont
= 1; w
&& cont
;)
6337 if (!NILP (WGET (w
, hchild
)))
6338 cont
= foreach_window_1 (XWINDOW (WGET (w
, hchild
)), fn
, user_data
);
6339 else if (!NILP (WGET (w
, vchild
)))
6340 cont
= foreach_window_1 (XWINDOW (WGET (w
, vchild
)), fn
, user_data
);
6342 cont
= fn (w
, user_data
);
6344 w
= NILP (WGET (w
, next
)) ? 0 : XWINDOW (WGET (w
, next
));
6351 /* Freeze or unfreeze the window start of W unless it is a
6352 mini-window or the selected window. FREEZE_P non-null means freeze
6353 the window start. */
6356 freeze_window_start (struct window
*w
, void *freeze_p
)
6358 if (MINI_WINDOW_P (w
)
6359 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6360 && (w
== XWINDOW (selected_window
)
6361 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6362 && ! NILP (Vminibuf_scroll_window
)
6363 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6366 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6371 /* Freeze or unfreeze the window starts of all leaf windows on frame
6372 F, except the selected window and a mini-window. FREEZE_P non-zero
6373 means freeze the window start. */
6376 freeze_window_starts (struct frame
*f
, int freeze_p
)
6378 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6382 /***********************************************************************
6384 ***********************************************************************/
6386 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6387 describe the same state of affairs. This is used by Fequal.
6389 ignore_positions non-zero means ignore non-matching scroll positions
6392 This ignores a couple of things like the dedication status of
6393 window, combination_limit and the like. This might have to be
6397 compare_window_configurations (Lisp_Object configuration1
, Lisp_Object configuration2
, int ignore_positions
)
6399 register struct save_window_data
*d1
, *d2
;
6400 struct Lisp_Vector
*sws1
, *sws2
;
6403 CHECK_WINDOW_CONFIGURATION (configuration1
);
6404 CHECK_WINDOW_CONFIGURATION (configuration2
);
6406 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6407 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6408 sws1
= XVECTOR (d1
->saved_windows
);
6409 sws2
= XVECTOR (d2
->saved_windows
);
6411 /* Frame settings must match. */
6412 if (d1
->frame_cols
!= d2
->frame_cols
6413 || d1
->frame_lines
!= d2
->frame_lines
6414 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6415 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6416 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6417 || (!ignore_positions
6418 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6419 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6420 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6421 /* Verify that the two configurations have the same number of windows. */
6422 || sws1
->header
.size
!= sws2
->header
.size
)
6425 for (i
= 0; i
< sws1
->header
.size
; i
++)
6427 struct saved_window
*sw1
, *sw2
;
6429 sw1
= SAVED_WINDOW_N (sws1
, i
);
6430 sw2
= SAVED_WINDOW_N (sws2
, i
);
6433 /* The "current" windows in the two configurations must
6434 correspond to each other. */
6435 EQ (d1
->current_window
, sw1
->window
)
6436 != EQ (d2
->current_window
, sw2
->window
)
6437 /* Windows' buffers must match. */
6438 || !EQ (sw1
->buffer
, sw2
->buffer
)
6439 || !EQ (sw1
->left_col
, sw2
->left_col
)
6440 || !EQ (sw1
->top_line
, sw2
->top_line
)
6441 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6442 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6443 || !EQ (sw1
->display_table
, sw2
->display_table
)
6444 /* The next two disjuncts check the window structure for
6446 || !EQ (sw1
->parent
, sw2
->parent
)
6447 || !EQ (sw1
->prev
, sw2
->prev
)
6448 || (!ignore_positions
6449 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6450 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6451 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6452 || NILP (Fequal (sw1
->start
, sw2
->start
))
6453 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6454 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6455 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6456 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6457 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6458 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6459 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6460 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6461 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6468 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6469 Scompare_window_configurations
, 2, 2, 0,
6470 doc
: /* Compare two window configurations as regards the structure of windows.
6471 This function ignores details such as the values of point and mark
6472 and scrolling positions. */)
6473 (Lisp_Object x
, Lisp_Object y
)
6475 if (compare_window_configurations (x
, y
, 1))
6481 init_window_once (void)
6483 struct frame
*f
= make_initial_frame ();
6484 XSETFRAME (selected_frame
, f
);
6485 Vterminal_frame
= selected_frame
;
6486 minibuf_window
= f
->minibuffer_window
;
6487 selected_window
= f
->selected_window
;
6488 last_nonminibuf_frame
= f
;
6490 window_initialized
= 1;
6496 Vwindow_list
= Qnil
;
6500 syms_of_window (void)
6502 DEFSYM (Qscroll_up
, "scroll-up");
6503 DEFSYM (Qscroll_down
, "scroll-down");
6504 DEFSYM (Qscroll_command
, "scroll-command");
6506 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6507 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6509 DEFSYM (Qwindow_configuration_change_hook
, "window-configuration-change-hook");
6510 DEFSYM (Qwindowp
, "windowp");
6511 DEFSYM (Qwindow_configuration_p
, "window-configuration-p");
6512 DEFSYM (Qwindow_live_p
, "window-live-p");
6513 DEFSYM (Qwindow_deletable_p
, "window-deletable-p");
6514 DEFSYM (Qdelete_window
, "delete-window");
6515 DEFSYM (Qwindow_resize_root_window
, "window--resize-root-window");
6516 DEFSYM (Qwindow_resize_root_window_vertically
, "window--resize-root-window-vertically");
6517 DEFSYM (Qsafe
, "safe");
6518 DEFSYM (Qdisplay_buffer
, "display-buffer");
6519 DEFSYM (Qreplace_buffer_in_windows
, "replace-buffer-in-windows");
6520 DEFSYM (Qrecord_window_buffer
, "record-window-buffer");
6521 DEFSYM (Qget_mru_window
, "get-mru-window");
6522 DEFSYM (Qtemp_buffer_show_hook
, "temp-buffer-show-hook");
6523 DEFSYM (Qabove
, "above");
6524 DEFSYM (Qbelow
, "below");
6525 DEFSYM (Qauto_buffer_name
, "auto-buffer-name");
6526 DEFSYM (Qclone_of
, "clone-of");
6528 staticpro (&Vwindow_list
);
6530 minibuf_selected_window
= Qnil
;
6531 staticpro (&minibuf_selected_window
);
6533 window_scroll_pixel_based_preserve_x
= -1;
6534 window_scroll_pixel_based_preserve_y
= -1;
6535 window_scroll_preserve_hpos
= -1;
6536 window_scroll_preserve_vpos
= -1;
6538 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
6539 doc
: /* Non-nil means call as function to display a help buffer.
6540 The function is called with one argument, the buffer to be displayed.
6541 Used by `with-output-to-temp-buffer'.
6542 If this function is used, then it must do the entire job of showing
6543 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6544 Vtemp_buffer_show_function
= Qnil
;
6546 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
6547 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6548 Vminibuf_scroll_window
= Qnil
;
6550 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
6551 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6552 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6553 is displayed in the `mode-line' face. */);
6554 mode_line_in_non_selected_windows
= 1;
6556 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
6557 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6558 Vother_window_scroll_buffer
= Qnil
;
6560 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
6561 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6562 auto_window_vscroll_p
= 1;
6564 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
6565 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6566 next_screen_context_lines
= 2;
6568 DEFVAR_LISP ("scroll-preserve-screen-position",
6569 Vscroll_preserve_screen_position
,
6570 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6571 A value of nil means point does not keep its screen position except
6572 at the scroll margin or window boundary respectively.
6573 A value of t means point keeps its screen position if the scroll
6574 command moved it vertically out of the window, e.g. when scrolling
6576 Any other value means point always keeps its screen position.
6577 Scroll commands should have the `scroll-command' property
6578 on their symbols to be controlled by this variable. */);
6579 Vscroll_preserve_screen_position
= Qnil
;
6581 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
6582 doc
: /* Type of marker to use for `window-point'. */);
6583 Vwindow_point_insertion_type
= Qnil
;
6585 DEFVAR_LISP ("window-configuration-change-hook",
6586 Vwindow_configuration_change_hook
,
6587 doc
: /* Functions to call when window configuration changes.
6588 The buffer-local part is run once per window, with the relevant window
6589 selected; while the global part is run only once for the modified frame,
6590 with the relevant frame selected. */);
6591 Vwindow_configuration_change_hook
= Qnil
;
6593 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
6594 doc
: /* Non-nil means `recenter' redraws entire frame.
6595 If this option is non-nil, then the `recenter' command with a nil
6596 argument will redraw the entire frame; the special value `tty' causes
6597 the frame to be redrawn only if it is a tty frame. */);
6598 Vrecenter_redisplay
= Qtty
;
6600 DEFVAR_LISP ("window-combination-resize", Vwindow_combination_resize
,
6601 doc
: /* If t, resize window combinations proportionally.
6602 If this variable is nil, splitting a window gets the entire screen space
6603 for displaying the new window from the window to split. Deleting and
6604 resizing a window preferably resizes one adjacent window only.
6606 If this variable is t, splitting a window tries to get the space
6607 proportionally from all windows in the same combination. This also
6608 allows to split a window that is otherwise too small or of fixed size.
6609 Resizing and deleting a window proportionally resize all windows in the
6612 Other values are reserved for future use.
6614 This variable takes no effect if `window-combination-limit' is non-nil. */);
6615 Vwindow_combination_resize
= Qnil
;
6617 DEFVAR_LISP ("window-combination-limit", Vwindow_combination_limit
,
6618 doc
: /* If t, splitting a window makes a new parent window.
6619 If this variable is nil, splitting a window will create a new parent
6620 window only if the window has no parent window or the window shall
6621 become a combination orthogonal to the one it is part of.
6623 If this variable is t, splitting a window always creates a new parent
6624 window. If all splits behave this way, each frame's window tree is a
6625 binary tree and every window but the frame's root window has exactly one
6628 Other values are reserved for future use.
6630 The value of this variable is also assigned to the combination limit of
6631 the new parent window. The combination limit of a window can be
6632 retrieved via the function `window-combination-limit' and altered by the
6633 function `set-window-combination-limit'. */);
6634 Vwindow_combination_limit
= Qnil
;
6636 DEFVAR_LISP ("window-persistent-parameters", Vwindow_persistent_parameters
,
6637 doc
: /* Alist of persistent window parameters.
6638 This alist specifies which window parameters shall get saved by
6639 `current-window-configuration' and `window-state-get' and subsequently
6640 restored to their previous values by `set-window-configuration' and
6643 The car of each entry of this alist is the symbol specifying the
6644 parameter. The cdr is one of the following:
6646 nil means the parameter is neither saved by `window-state-get' nor by
6647 `current-window-configuration'.
6649 t means the parameter is saved by `current-window-configuration' and,
6650 provided its WRITABLE argument is nil, by `window-state-get'.
6652 The symbol `writable' means the parameter is saved unconditionally by
6653 both `current-window-configuration' and `window-state-get'. Do not use
6654 this value for parameters without read syntax (like windows or frames).
6656 Parameters not saved by `current-window-configuration' or
6657 `window-state-get' are left alone by `set-window-configuration'
6658 respectively are not installed by `window-state-put'. */);
6659 Vwindow_persistent_parameters
= list1 (Fcons (Qclone_of
, Qt
));
6661 defsubr (&Sselected_window
);
6662 defsubr (&Sminibuffer_window
);
6663 defsubr (&Swindow_minibuffer_p
);
6664 defsubr (&Swindowp
);
6665 defsubr (&Swindow_live_p
);
6666 defsubr (&Swindow_frame
);
6667 defsubr (&Sframe_root_window
);
6668 defsubr (&Sframe_first_window
);
6669 defsubr (&Sframe_selected_window
);
6670 defsubr (&Sset_frame_selected_window
);
6671 defsubr (&Spos_visible_in_window_p
);
6672 defsubr (&Swindow_line_height
);
6673 defsubr (&Swindow_buffer
);
6674 defsubr (&Swindow_parent
);
6675 defsubr (&Swindow_top_child
);
6676 defsubr (&Swindow_left_child
);
6677 defsubr (&Swindow_next_sibling
);
6678 defsubr (&Swindow_prev_sibling
);
6679 defsubr (&Swindow_combination_limit
);
6680 defsubr (&Sset_window_combination_limit
);
6681 defsubr (&Swindow_use_time
);
6682 defsubr (&Swindow_top_line
);
6683 defsubr (&Swindow_left_column
);
6684 defsubr (&Swindow_total_height
);
6685 defsubr (&Swindow_total_width
);
6686 defsubr (&Swindow_normal_size
);
6687 defsubr (&Swindow_new_total
);
6688 defsubr (&Swindow_new_normal
);
6689 defsubr (&Sset_window_new_total
);
6690 defsubr (&Sset_window_new_normal
);
6691 defsubr (&Swindow_resize_apply
);
6692 defsubr (&Swindow_body_height
);
6693 defsubr (&Swindow_body_width
);
6694 defsubr (&Swindow_hscroll
);
6695 defsubr (&Sset_window_hscroll
);
6696 defsubr (&Swindow_redisplay_end_trigger
);
6697 defsubr (&Sset_window_redisplay_end_trigger
);
6698 defsubr (&Swindow_edges
);
6699 defsubr (&Swindow_pixel_edges
);
6700 defsubr (&Swindow_absolute_pixel_edges
);
6701 defsubr (&Swindow_inside_edges
);
6702 defsubr (&Swindow_inside_pixel_edges
);
6703 defsubr (&Swindow_inside_absolute_pixel_edges
);
6704 defsubr (&Scoordinates_in_window_p
);
6705 defsubr (&Swindow_at
);
6706 defsubr (&Swindow_point
);
6707 defsubr (&Swindow_start
);
6708 defsubr (&Swindow_end
);
6709 defsubr (&Sset_window_point
);
6710 defsubr (&Sset_window_start
);
6711 defsubr (&Swindow_dedicated_p
);
6712 defsubr (&Sset_window_dedicated_p
);
6713 defsubr (&Swindow_display_table
);
6714 defsubr (&Sset_window_display_table
);
6715 defsubr (&Snext_window
);
6716 defsubr (&Sprevious_window
);
6717 defsubr (&Sget_buffer_window
);
6718 defsubr (&Sdelete_other_windows_internal
);
6719 defsubr (&Sdelete_window_internal
);
6720 defsubr (&Sresize_mini_window_internal
);
6721 defsubr (&Sset_window_buffer
);
6722 defsubr (&Srun_window_configuration_change_hook
);
6723 defsubr (&Sselect_window
);
6724 defsubr (&Sforce_window_update
);
6725 defsubr (&Stemp_output_buffer_show
);
6726 defsubr (&Ssplit_window_internal
);
6727 defsubr (&Sscroll_up
);
6728 defsubr (&Sscroll_down
);
6729 defsubr (&Sscroll_left
);
6730 defsubr (&Sscroll_right
);
6731 defsubr (&Sother_window_for_scrolling
);
6732 defsubr (&Sscroll_other_window
);
6733 defsubr (&Sminibuffer_selected_window
);
6734 defsubr (&Srecenter
);
6735 defsubr (&Swindow_text_height
);
6736 defsubr (&Smove_to_window_line
);
6737 defsubr (&Swindow_configuration_p
);
6738 defsubr (&Swindow_configuration_frame
);
6739 defsubr (&Sset_window_configuration
);
6740 defsubr (&Scurrent_window_configuration
);
6741 defsubr (&Sset_window_margins
);
6742 defsubr (&Swindow_margins
);
6743 defsubr (&Sset_window_fringes
);
6744 defsubr (&Swindow_fringes
);
6745 defsubr (&Sset_window_scroll_bars
);
6746 defsubr (&Swindow_scroll_bars
);
6747 defsubr (&Swindow_vscroll
);
6748 defsubr (&Sset_window_vscroll
);
6749 defsubr (&Scompare_window_configurations
);
6750 defsubr (&Swindow_list
);
6751 defsubr (&Swindow_list_1
);
6752 defsubr (&Swindow_prev_buffers
);
6753 defsubr (&Sset_window_prev_buffers
);
6754 defsubr (&Swindow_next_buffers
);
6755 defsubr (&Sset_window_next_buffers
);
6756 defsubr (&Swindow_parameters
);
6757 defsubr (&Swindow_parameter
);
6758 defsubr (&Sset_window_parameter
);
6762 keys_of_window (void)
6764 initial_define_key (control_x_map
, '<', "scroll-left");
6765 initial_define_key (control_x_map
, '>', "scroll-right");
6767 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6768 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6769 initial_define_key (meta_map
, 'v', "scroll-down-command");