1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985-1987, 1993-1998, 2000-2011
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
35 #include "dispextern.h"
36 #include "blockinput.h"
37 #include "intervals.h"
38 #include "termhooks.h" /* For FRAME_TERMINAL. */
42 #endif /* HAVE_X_WINDOWS */
53 Lisp_Object Qwindowp
, Qwindow_live_p
;
54 static Lisp_Object Qwindow_configuration_p
;
55 static Lisp_Object Qdisplay_buffer
;
56 static Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
57 static Lisp_Object Qwindow_size_fixed
;
59 static int displayed_window_lines (struct window
*);
60 static struct window
*decode_window (Lisp_Object
);
61 static int count_windows (struct window
*);
62 static int get_leaf_windows (struct window
*, struct window
**, int);
63 static void window_scroll (Lisp_Object
, int, int, int);
64 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
65 static void window_scroll_line_based (Lisp_Object
, int, int, int);
66 static int window_min_size_1 (struct window
*, int, int);
67 static int window_min_size_2 (struct window
*, int, int);
68 static int window_min_size (struct window
*, int, int, int, int *);
69 static void size_window (Lisp_Object
, int, int, int, int, int);
70 static int freeze_window_start (struct window
*, void *);
71 static int window_fixed_size_p (struct window
*, int, int);
72 static void enlarge_window (Lisp_Object
, int, int);
73 static Lisp_Object
window_list (void);
74 static int add_window_to_list (struct window
*, void *);
75 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
77 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
79 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
81 static void foreach_window (struct frame
*,
82 int (* fn
) (struct window
*, void *),
84 static int foreach_window_1 (struct window
*,
85 int (* fn
) (struct window
*, void *),
87 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
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 /* Incremented by 1 whenever a window is deleted. */
127 static int window_deletion_count
;
129 /* Used by the function window_scroll_pixel_based */
130 static int window_scroll_pixel_based_preserve_x
;
131 static int window_scroll_pixel_based_preserve_y
;
133 /* Same for window_scroll_line_based. */
134 static int window_scroll_preserve_hpos
;
135 static int window_scroll_preserve_vpos
;
137 static struct window
*
138 decode_window (register Lisp_Object window
)
141 return XWINDOW (selected_window
);
143 CHECK_LIVE_WINDOW (window
);
144 return XWINDOW (window
);
147 static struct window
*
148 decode_any_window (register Lisp_Object window
)
151 return XWINDOW (selected_window
);
153 CHECK_WINDOW (window
);
154 return XWINDOW (window
);
157 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
158 doc
: /* Return t if OBJECT is a window and nil otherwise. */)
161 return WINDOWP (object
) ? Qt
: Qnil
;
164 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
165 doc
: /* Return t if OBJECT is a live window and nil otherwise.
166 A live window is a window that displays a buffer. */)
169 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
172 /* Frames and windows. */
173 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
174 doc
: /* Return the frame that window WINDOW is on.
175 WINDOW can be any window and defaults to the selected one. */)
178 return decode_any_window (window
)->frame
;
181 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
182 doc
: /* Return the root window of FRAME_OR_WINDOW.
183 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
184 Else if FRAME_OR_WINDOW denotes any window, return the root window of
185 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
186 the root window of that frame. */)
187 (Lisp_Object frame_or_window
)
191 if (NILP (frame_or_window
))
192 window
= SELECTED_FRAME ()->root_window
;
193 else if (WINDOWP (frame_or_window
))
194 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
197 CHECK_LIVE_FRAME (frame_or_window
);
198 window
= XFRAME (frame_or_window
)->root_window
;
204 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
205 doc
: /* Return the window used now for minibuffers.
206 If the optional argument FRAME is specified, return the minibuffer window
207 used by that frame. */)
211 frame
= selected_frame
;
212 CHECK_LIVE_FRAME (frame
);
213 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
216 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
,
217 Swindow_minibuffer_p
, 0, 1, 0,
218 doc
: /* Return non-nil if WINDOW is a minibuffer window.
219 WINDOW can be any window and defaults to the selected one. */)
222 return MINI_WINDOW_P (decode_any_window (window
)) ? Qt
: Qnil
;
225 /* Don't move this to window.el - this must be a safe routine. */
226 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
227 doc
: /* Return the topmost, leftmost live window on FRAME_OR_WINDOW.
228 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
229 Else if FRAME_OR_WINDOW denotes any window, return the first window of
230 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
231 the first window of that frame. */)
232 (Lisp_Object frame_or_window
)
236 if (NILP (frame_or_window
))
237 window
= SELECTED_FRAME ()->root_window
;
238 else if (WINDOWP (frame_or_window
))
239 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
242 CHECK_LIVE_FRAME (frame_or_window
);
243 window
= XFRAME (frame_or_window
)->root_window
;
246 while (NILP (XWINDOW (window
)->buffer
))
248 if (! NILP (XWINDOW (window
)->hchild
))
249 window
= XWINDOW (window
)->hchild
;
250 else if (! NILP (XWINDOW (window
)->vchild
))
251 window
= XWINDOW (window
)->vchild
;
259 DEFUN ("frame-selected-window", Fframe_selected_window
,
260 Sframe_selected_window
, 0, 1, 0,
261 doc
: /* Return the selected window of FRAME_OR_WINDOW.
262 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
263 Else if FRAME_OR_WINDOW denotes any window, return the selected window
264 of that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
265 the selected window of that frame. */)
266 (Lisp_Object frame_or_window
)
270 if (NILP (frame_or_window
))
271 window
= SELECTED_FRAME ()->selected_window
;
272 else if (WINDOWP (frame_or_window
))
273 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
276 CHECK_LIVE_FRAME (frame_or_window
);
277 window
= XFRAME (frame_or_window
)->selected_window
;
283 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
284 Sset_frame_selected_window
, 2, 3, 0,
285 doc
: /* Set selected window of FRAME to WINDOW.
286 FRAME must be a live frame and defaults to the selected one. If FRAME
287 is the selected frame, this makes WINDOW the selected window. Optional
288 argument NORECORD non-nil means to neither change the order of recently
289 selected windows nor the buffer list. WINDOW must denote a live window.
291 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
294 frame
= selected_frame
;
296 CHECK_LIVE_FRAME (frame
);
297 CHECK_LIVE_WINDOW (window
);
299 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
300 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
302 if (EQ (frame
, selected_frame
))
303 return Fselect_window (window
, norecord
);
305 return XFRAME (frame
)->selected_window
= window
;
308 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
309 doc
: /* Return the selected window.
310 The selected window is the window in which the standard cursor for
311 selected windows appears and to which many commands apply. */)
314 return selected_window
;
317 /* If select_window is called with inhibit_point_swap non-zero it will
318 not store point of the old selected window's buffer back into that
319 window's pointm slot. This is needed by Fset_window_configuration to
320 avoid that the display routine is called with selected_window set to
321 Qnil causing a subsequent crash. */
323 select_window (Lisp_Object window
, Lisp_Object norecord
, int inhibit_point_swap
)
325 register struct window
*w
;
326 register struct window
*ow
;
329 CHECK_LIVE_WINDOW (window
);
331 w
= XWINDOW (window
);
332 w
->frozen_window_start_p
= 0;
336 ++window_select_count
;
337 XSETFASTINT (w
->use_time
, window_select_count
);
338 record_buffer (w
->buffer
);
341 if (EQ (window
, selected_window
) && !inhibit_point_swap
)
344 sf
= SELECTED_FRAME ();
345 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
347 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
348 /* Use this rather than Fhandle_switch_frame
349 so that FRAME_FOCUS_FRAME is moved appropriately as we
350 move around in the state where a minibuffer in a separate
352 Fselect_frame (WINDOW_FRAME (w
), norecord
);
353 /* Fselect_frame called us back so we've done all the work already. */
354 eassert (EQ (window
, selected_window
));
358 sf
->selected_window
= window
;
360 /* Store the current buffer's actual point into the
361 old selected window. It belongs to that window,
362 and when the window is not selected, must be in the window. */
363 if (!inhibit_point_swap
)
365 ow
= XWINDOW (selected_window
);
366 if (! NILP (ow
->buffer
))
367 set_marker_both (ow
->pointm
, ow
->buffer
,
368 BUF_PT (XBUFFER (ow
->buffer
)),
369 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
372 selected_window
= window
;
374 Fset_buffer (w
->buffer
);
376 BVAR (XBUFFER (w
->buffer
), last_selected_window
) = window
;
378 /* Go to the point recorded in the window.
379 This is important when the buffer is in more
380 than one window. It also matters when
381 redisplay_window has altered point after scrolling,
382 because it makes the change only in the window. */
384 register EMACS_INT new_point
= marker_position (w
->pointm
);
385 if (new_point
< BEGV
)
387 else if (new_point
> ZV
)
393 windows_or_buffers_changed
++;
397 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
398 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
399 Also make WINDOW's buffer current and make WINDOW the frame's selected
400 window. Return WINDOW.
402 Optional second arg NORECORD non-nil means do not put this buffer at the
403 front of the buffer list and do not make this window the most recently
406 Note that the main editor command loop sets the current buffer to the
407 buffer of the selected window before each command. */)
408 (register Lisp_Object window
, Lisp_Object norecord
)
410 return select_window (window
, norecord
, 0);
413 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
414 doc
: /* Return the buffer that WINDOW is displaying.
415 WINDOW can be any window and defaults to the selected one.
416 If WINDOW is an internal window return nil. */)
419 return decode_any_window (window
)->buffer
;
422 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
423 doc
: /* Return WINDOW's parent window.
424 WINDOW can be any window and defaults to the selected one.
425 Return nil if WINDOW has no parent. */)
428 return decode_any_window (window
)->parent
;
431 DEFUN ("window-vchild", Fwindow_vchild
, Swindow_vchild
, 0, 1, 0,
432 doc
: /* Return WINDOW's first vertical child window.
433 WINDOW can be any window and defaults to the selected one.
434 Return nil if WINDOW has no vertical child. */)
437 return decode_any_window (window
)->vchild
;
440 DEFUN ("window-hchild", Fwindow_hchild
, Swindow_hchild
, 0, 1, 0,
441 doc
: /* Return WINDOW's first horizontal child window.
442 WINDOW can be any window and defaults to the selected one.
443 Return nil if WINDOW has no horizontal child. */)
446 return decode_any_window (window
)->hchild
;
449 DEFUN ("window-next", Fwindow_next
, Swindow_next
, 0, 1, 0,
450 doc
: /* Return WINDOW's right sibling window.
451 WINDOW can be any window and defaults to the selected one.
452 Return nil if WINDOW has no right sibling. */)
455 return decode_any_window (window
)->next
;
458 DEFUN ("window-prev", Fwindow_prev
, Swindow_prev
, 0, 1, 0,
459 doc
: /* Return WINDOW's left sibling window.
460 WINDOW can be any window and defaults to the selected one.
461 Return nil if WINDOW has no left sibling. */)
464 return decode_any_window (window
)->prev
;
471 register struct window
*p
;
473 p
= allocate_window ();
475 XSETFASTINT (p
->sequence_number
, sequence_number
);
476 XSETFASTINT (p
->left_col
, 0);
477 XSETFASTINT (p
->top_line
, 0);
478 XSETFASTINT (p
->total_lines
, 0);
479 XSETFASTINT (p
->total_cols
, 0);
480 XSETFASTINT (p
->hscroll
, 0);
481 XSETFASTINT (p
->min_hscroll
, 0);
482 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
483 p
->start
= Fmake_marker ();
484 p
->pointm
= Fmake_marker ();
485 XSETFASTINT (p
->use_time
, 0);
487 p
->display_table
= Qnil
;
489 p
->window_parameters
= Qnil
;
490 p
->pseudo_window_p
= 0;
491 memset (&p
->cursor
, 0, sizeof (p
->cursor
));
492 memset (&p
->last_cursor
, 0, sizeof (p
->last_cursor
));
493 memset (&p
->phys_cursor
, 0, sizeof (p
->phys_cursor
));
494 p
->desired_matrix
= p
->current_matrix
= 0;
495 p
->nrows_scale_factor
= p
->ncols_scale_factor
= 1;
496 p
->phys_cursor_type
= -1;
497 p
->phys_cursor_width
= -1;
498 p
->must_be_updated_p
= 0;
499 XSETFASTINT (p
->window_end_vpos
, 0);
500 XSETFASTINT (p
->window_end_pos
, 0);
501 p
->window_end_valid
= Qnil
;
504 XSETFASTINT (p
->last_point
, 0);
505 p
->frozen_window_start_p
= 0;
506 p
->last_cursor_off_p
= p
->cursor_off_p
= 0;
507 p
->left_margin_cols
= Qnil
;
508 p
->right_margin_cols
= Qnil
;
509 p
->left_fringe_width
= Qnil
;
510 p
->right_fringe_width
= Qnil
;
511 p
->fringes_outside_margins
= Qnil
;
512 p
->scroll_bar_width
= Qnil
;
513 p
->vertical_scroll_bar_type
= Qt
;
514 p
->resize_proportionally
= Qnil
;
520 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
521 Spos_visible_in_window_p
, 0, 3, 0,
522 doc
: /* Return non-nil if position POS is currently on the frame in WINDOW.
523 Return nil if that position is scrolled vertically out of view.
524 If a character is only partially visible, nil is returned, unless the
525 optional argument PARTIALLY is non-nil.
526 If POS is only out of view because of horizontal scrolling, return non-nil.
527 If POS is t, it specifies the position of the last visible glyph in WINDOW.
528 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
530 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
531 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
532 where X and Y are the pixel coordinates relative to the top left corner
533 of the window. The remaining elements are omitted if the character after
534 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
535 off-window at the top and bottom of the row, ROWH is the height of the
536 display row, and VPOS is the row number (0-based) containing POS. */)
537 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
539 register struct window
*w
;
540 register EMACS_INT posint
;
541 register struct buffer
*buf
;
543 Lisp_Object in_window
= Qnil
;
544 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
547 w
= decode_window (window
);
548 buf
= XBUFFER (w
->buffer
);
549 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
553 else if (!NILP (pos
))
555 CHECK_NUMBER_COERCE_MARKER (pos
);
558 else if (w
== XWINDOW (selected_window
))
561 posint
= XMARKER (w
->pointm
)->charpos
;
563 /* If position is above window start or outside buffer boundaries,
564 or if window start is out of range, position is not visible. */
566 || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
567 && CHARPOS (top
) >= BUF_BEGV (buf
)
568 && CHARPOS (top
) <= BUF_ZV (buf
)
569 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
570 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
573 if (!NILP (in_window
) && !NILP (partially
))
575 Lisp_Object part
= Qnil
;
577 part
= list4 (make_number (rtop
), make_number (rbot
),
578 make_number (rowh
), make_number (vpos
));
579 in_window
= Fcons (make_number (x
),
580 Fcons (make_number (y
), part
));
586 DEFUN ("window-line-height", Fwindow_line_height
,
587 Swindow_line_height
, 0, 2, 0,
588 doc
: /* Return height in pixels of text line LINE in window WINDOW.
589 If WINDOW is nil or omitted, use selected window.
591 Return height of current line if LINE is omitted or nil. Return height of
592 header or mode line if LINE is `header-line' and `mode-line'.
593 Otherwise, LINE is a text line number starting from 0. A negative number
594 counts from the end of the window.
596 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
597 in pixels of the visible part of the line, VPOS and YPOS are the
598 vertical position in lines and pixels of the line, relative to the top
599 of the first text line, and OFFBOT is the number of off-window pixels at
600 the bottom of the text line. If there are off-window pixels at the top
601 of the (first) text line, YPOS is negative.
603 Return nil if window display is not up-to-date. In that case, use
604 `pos-visible-in-window-p' to obtain the information. */)
605 (Lisp_Object line
, Lisp_Object window
)
607 register struct window
*w
;
608 register struct buffer
*b
;
609 struct glyph_row
*row
, *end_row
;
610 int max_y
, crop
, i
, n
;
612 w
= decode_window (window
);
615 || w
->pseudo_window_p
)
618 CHECK_BUFFER (w
->buffer
);
619 b
= XBUFFER (w
->buffer
);
621 /* Fail if current matrix is not up-to-date. */
622 if (NILP (w
->window_end_valid
)
623 || current_buffer
->clip_changed
624 || current_buffer
->prevent_redisplay_optimizations_p
625 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
626 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
632 if (i
< 0 || i
>= w
->current_matrix
->nrows
633 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
635 max_y
= window_text_bottom_y (w
);
639 if (EQ (line
, Qheader_line
))
641 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
643 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
646 return list4 (make_number (row
->height
),
647 make_number (0), make_number (0),
651 if (EQ (line
, Qmode_line
))
653 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
656 return list4 (make_number (row
->height
),
657 make_number (0), /* not accurate */
658 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
659 + window_text_bottom_y (w
)),
666 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
667 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
668 max_y
= window_text_bottom_y (w
);
671 while ((n
< 0 || i
< n
)
672 && row
<= end_row
&& row
->enabled_p
673 && row
->y
+ row
->height
< max_y
)
676 if (row
> end_row
|| !row
->enabled_p
)
688 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
689 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
691 make_number (row
->y
),
697 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
698 doc
: /* Return the number of lines in WINDOW.
699 WINDOW defaults to the selected window.
701 The return value includes WINDOW's mode line and header line, if any.
703 Note: The function does not take into account the value of `line-spacing'
704 when calculating the number of lines in WINDOW. */)
707 return decode_any_window (window
)->total_lines
;
710 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
711 doc
: /* Return the number of display columns in WINDOW.
712 WINDOW defaults to the selected window.
714 Note: The return value is the number of columns available for text in
715 WINDOW. If you want to find out how many columns WINDOW takes up, use
716 (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
719 return make_number (window_box_text_cols (decode_any_window (window
)));
722 DEFUN ("window-full-width-p", Fwindow_full_width_p
, Swindow_full_width_p
, 0, 1, 0,
723 doc
: /* Return t if WINDOW is as wide as its frame.
724 WINDOW defaults to the selected window. */)
727 return WINDOW_FULL_WIDTH_P (decode_any_window (window
)) ? Qt
: Qnil
;
730 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
731 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
732 WINDOW defaults to the selected window. */)
735 return decode_window (window
)->hscroll
;
738 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
739 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
740 Return NCOL. NCOL should be zero or positive.
742 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
743 window so that the location of point moves off-window. */)
744 (Lisp_Object window
, Lisp_Object ncol
)
746 struct window
*w
= decode_window (window
);
750 hscroll
= max (0, XINT (ncol
));
752 /* Prevent redisplay shortcuts when changing the hscroll. */
753 if (XINT (w
->hscroll
) != hscroll
)
754 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
756 w
->hscroll
= make_number (hscroll
);
760 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
761 Swindow_redisplay_end_trigger
, 0, 1, 0,
762 doc
: /* Return WINDOW's redisplay end trigger value.
763 WINDOW defaults to the selected window.
764 See `set-window-redisplay-end-trigger' for more information. */)
767 return decode_window (window
)->redisplay_end_trigger
;
770 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
771 Sset_window_redisplay_end_trigger
, 2, 2, 0,
772 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
773 VALUE should be a buffer position (typically a marker) or nil.
774 If it is a buffer position, then if redisplay in WINDOW reaches a position
775 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
776 with two arguments: WINDOW, and the end trigger value.
777 Afterwards the end-trigger value is reset to nil. */)
778 (register Lisp_Object window
, Lisp_Object value
)
780 register struct window
*w
;
782 w
= decode_window (window
);
783 w
->redisplay_end_trigger
= value
;
787 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
788 doc
: /* Return a list of the edge coordinates of WINDOW.
789 The list has the form (LEFT TOP RIGHT BOTTOM).
790 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
791 all relative to 0, 0 at top left corner of frame.
793 RIGHT is one more than the rightmost column occupied by WINDOW.
794 BOTTOM is one more than the bottommost row occupied by WINDOW.
795 The edges include the space used by WINDOW's scroll bar, display
796 margins, fringes, header line, and/or mode line. For the edges of
797 just the text area, use `window-inside-edges'. */)
800 register struct window
*w
= decode_any_window (window
);
802 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
803 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
804 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
805 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
809 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
810 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
811 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
812 the top left corner of the frame.
814 RIGHT is one more than the rightmost x position occupied by WINDOW.
815 BOTTOM is one more than the bottommost y position occupied by WINDOW.
816 The pixel edges include the space used by WINDOW's scroll bar, display
817 margins, fringes, header line, and/or mode line. For the pixel edges
818 of just the text area, use `window-inside-pixel-edges'. */)
821 register struct window
*w
= decode_any_window (window
);
823 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
824 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
825 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
826 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
831 calc_absolute_offset(struct window
*w
, int *add_x
, int *add_y
)
833 struct frame
*f
= XFRAME (w
->frame
);
835 #ifdef FRAME_MENUBAR_HEIGHT
836 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
838 #ifdef FRAME_TOOLBAR_TOP_HEIGHT
839 *add_y
+= FRAME_TOOLBAR_TOP_HEIGHT (f
);
840 #elif FRAME_TOOLBAR_HEIGHT
841 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
843 #ifdef FRAME_NS_TITLEBAR_HEIGHT
844 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
846 *add_x
= f
->left_pos
;
847 #ifdef FRAME_TOOLBAR_LEFT_WIDTH
848 *add_x
+= FRAME_TOOLBAR_LEFT_WIDTH (f
);
852 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
853 Swindow_absolute_pixel_edges
, 0, 1, 0,
854 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
855 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
856 the top left corner of the display.
858 RIGHT is one more than the rightmost x position occupied by WINDOW.
859 BOTTOM is one more than the bottommost y position occupied by WINDOW.
860 The pixel edges include the space used by WINDOW's scroll bar, display
861 margins, fringes, header line, and/or mode line. For the pixel edges
862 of just the text area, use `window-inside-absolute-pixel-edges'. */)
865 register struct window
*w
= decode_any_window (window
);
867 calc_absolute_offset (w
, &add_x
, &add_y
);
869 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
) + add_x
),
870 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
) + add_y
),
871 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
) + add_x
),
872 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
) + add_y
),
876 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
877 doc
: /* Return a list of the edge coordinates of WINDOW.
878 The list has the form (LEFT TOP RIGHT BOTTOM).
879 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
880 all relative to 0, 0 at top left corner of frame.
882 RIGHT is one more than the rightmost column of WINDOW's text area.
883 BOTTOM is one more than the bottommost row of WINDOW's text area.
884 The inside edges do not include the space used by the WINDOW's scroll
885 bar, display margins, fringes, header line, and/or mode line. */)
888 register struct window
*w
= decode_any_window (window
);
890 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
891 + WINDOW_LEFT_MARGIN_COLS (w
)
892 + WINDOW_LEFT_FRINGE_COLS (w
)),
893 make_number (WINDOW_TOP_EDGE_LINE (w
)
894 + WINDOW_HEADER_LINE_LINES (w
)),
895 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
896 - WINDOW_RIGHT_MARGIN_COLS (w
)
897 - WINDOW_RIGHT_FRINGE_COLS (w
)),
898 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
899 - WINDOW_MODE_LINE_LINES (w
)));
902 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
903 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
904 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
905 the top left corner of the frame.
907 RIGHT is one more than the rightmost x position of WINDOW's text area.
908 BOTTOM is one more than the bottommost y position of WINDOW's text area.
909 The inside edges do not include the space used by WINDOW's scroll bar,
910 display margins, fringes, header line, and/or mode line. */)
913 register struct window
*w
= decode_any_window (window
);
915 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
916 + WINDOW_LEFT_MARGIN_WIDTH (w
)
917 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
918 make_number (WINDOW_TOP_EDGE_Y (w
)
919 + WINDOW_HEADER_LINE_HEIGHT (w
)),
920 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
921 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
922 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
923 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
924 - WINDOW_MODE_LINE_HEIGHT (w
)));
927 DEFUN ("window-inside-absolute-pixel-edges",
928 Fwindow_inside_absolute_pixel_edges
,
929 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
930 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
931 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
932 the top left corner of the display.
934 RIGHT is one more than the rightmost x position of WINDOW's text area.
935 BOTTOM is one more than the bottommost y position of WINDOW's text area.
936 The inside edges do not include the space used by WINDOW's scroll bar,
937 display margins, fringes, header line, and/or mode line. */)
940 register struct window
*w
= decode_any_window (window
);
942 calc_absolute_offset (w
, &add_x
, &add_y
);
944 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
945 + WINDOW_LEFT_MARGIN_WIDTH (w
)
946 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
947 make_number (WINDOW_TOP_EDGE_Y (w
)
948 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
949 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
950 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
951 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
952 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
953 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
956 /* Test if the character at column X, row Y is within window W.
957 If it is not, return ON_NOTHING;
958 if it is in the window's text area, return ON_TEXT;
959 if it is on the window's modeline, return ON_MODE_LINE;
960 if it is on the border between the window and its right sibling,
961 return ON_VERTICAL_BORDER.
962 if it is on a scroll bar, return ON_SCROLL_BAR.
963 if it is on the window's top line, return ON_HEADER_LINE;
964 if it is in left or right fringe of the window,
965 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE;
966 if it is in the marginal area to the left/right of the window,
967 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN.
969 X and Y are frame relative pixel coordinates. */
971 static enum window_part
972 coordinates_in_window (register struct window
*w
, int x
, int y
)
974 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
976 enum window_part part
;
977 int ux
= FRAME_COLUMN_WIDTH (f
);
978 int x0
= WINDOW_LEFT_EDGE_X (w
);
979 int x1
= WINDOW_RIGHT_EDGE_X (w
);
980 /* The width of the area where the vertical line can be dragged.
981 (Between mode lines for instance. */
982 int grabbable_width
= ux
;
983 int lmargin_width
, rmargin_width
, text_left
, text_right
;
984 int top_y
= WINDOW_TOP_EDGE_Y (w
);
985 int bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
987 /* Outside any interesting row? */
988 if (y
< top_y
|| y
>= bottom_y
)
991 /* In what's below, we subtract 1 when computing right_x because we
992 want the rightmost pixel, which is given by left_pixel+width-1. */
993 if (w
->pseudo_window_p
)
996 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
1000 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
1001 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
1004 /* On the mode line or header line? If it's near the start of
1005 the mode or header line of window that's has a horizontal
1006 sibling, say it's on the vertical line. That's to be able
1007 to resize windows horizontally in case we're using toolkit
1010 if (WINDOW_WANTS_MODELINE_P (w
)
1011 && y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
1013 part
= ON_MODE_LINE
;
1015 header_vertical_border_check
:
1016 /* We're somewhere on the mode line. We consider the place
1017 between mode lines of horizontally adjacent mode lines
1018 as the vertical border. If scroll bars on the left,
1019 return the right window. */
1020 if ((WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
1021 || WINDOW_RIGHTMOST_P (w
))
1022 && !WINDOW_LEFTMOST_P (w
)
1023 && eabs (x
- x0
) < grabbable_width
)
1024 return ON_VERTICAL_BORDER
;
1026 /* Make sure we're not at the rightmost position of a
1027 mode-/header-line and there's yet another window on the
1028 right. (Bug#1372) */
1029 else if ((WINDOW_RIGHTMOST_P (w
) || x
< x1
)
1030 && eabs (x
- x1
) < grabbable_width
)
1031 return ON_VERTICAL_BORDER
;
1033 if (x
< x0
|| x
>= x1
)
1039 if (WINDOW_WANTS_HEADER_LINE_P (w
)
1040 && y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
1042 part
= ON_HEADER_LINE
;
1043 goto header_vertical_border_check
;
1046 if (x
< x0
|| x
>= x1
) return ON_NOTHING
;
1048 /* Outside any interesting column? */
1049 if (x
< left_x
|| x
> right_x
)
1050 return ON_SCROLL_BAR
;
1052 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
1053 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
1055 text_left
= window_box_left (w
, TEXT_AREA
);
1056 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
1058 if (FRAME_WINDOW_P (f
))
1060 if (!w
->pseudo_window_p
1061 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1062 && !WINDOW_RIGHTMOST_P (w
)
1063 && (eabs (x
- right_x
) < grabbable_width
))
1064 return ON_VERTICAL_BORDER
;
1066 /* Need to say "x > right_x" rather than >=, since on character
1067 terminals, the vertical line's x coordinate is right_x. */
1068 else if (!w
->pseudo_window_p
1069 && !WINDOW_RIGHTMOST_P (w
)
1070 && x
> right_x
- ux
)
1071 return ON_VERTICAL_BORDER
;
1075 if (lmargin_width
> 0
1076 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1077 ? (x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1078 : (x
< left_x
+ lmargin_width
)))
1079 return ON_LEFT_MARGIN
;
1081 return ON_LEFT_FRINGE
;
1084 if (x
>= text_right
)
1086 if (rmargin_width
> 0
1087 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1088 ? (x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1089 : (x
>= right_x
- rmargin_width
)))
1090 return ON_RIGHT_MARGIN
;
1092 return ON_RIGHT_FRINGE
;
1095 /* Everything special ruled out - must be on text area */
1099 /* Take X is the frame-relative pixel x-coordinate, and return the
1100 x-coordinate relative to part PART of window W. */
1102 window_relative_x_coord (struct window
*w
, enum window_part part
, int x
)
1104 int left_x
= (w
->pseudo_window_p
) ? 0 : WINDOW_BOX_LEFT_EDGE_X (w
);
1109 return x
- window_box_left (w
, TEXT_AREA
);
1111 case ON_LEFT_FRINGE
:
1114 case ON_RIGHT_FRINGE
:
1115 return x
- left_x
- WINDOW_LEFT_FRINGE_WIDTH (w
);
1117 case ON_LEFT_MARGIN
:
1119 - ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1120 ? WINDOW_LEFT_FRINGE_WIDTH (w
) : 0));
1122 case ON_RIGHT_MARGIN
:
1124 - ((w
->pseudo_window_p
)
1125 ? WINDOW_TOTAL_WIDTH (w
)
1126 : WINDOW_BOX_RIGHT_EDGE_X (w
))
1127 + window_box_width (w
, RIGHT_MARGIN_AREA
)
1128 + ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1129 ? WINDOW_RIGHT_FRINGE_WIDTH (w
) : 0));
1132 /* ON_SCROLL_BAR, ON_NOTHING, and ON_VERTICAL_BORDER: */
1137 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1138 Scoordinates_in_window_p
, 2, 2, 0,
1139 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1140 COORDINATES is a cons of the form (X . Y), X and Y being distances
1141 measured in characters from the upper-left corner of the frame.
1142 \(0 . 0) denotes the character in the upper left corner of the
1144 If COORDINATES are in the text portion of WINDOW,
1145 the coordinates relative to the window are returned.
1146 If they are in the mode line of WINDOW, `mode-line' is returned.
1147 If they are in the top mode line of WINDOW, `header-line' is returned.
1148 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1149 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1150 If they are on the border between WINDOW and its right sibling,
1151 `vertical-line' is returned.
1152 If they are in the windows's left or right marginal areas, `left-margin'\n\
1153 or `right-margin' is returned. */)
1154 (register Lisp_Object coordinates
, Lisp_Object window
)
1161 CHECK_WINDOW (window
);
1162 w
= XWINDOW (window
);
1163 f
= XFRAME (w
->frame
);
1164 CHECK_CONS (coordinates
);
1165 lx
= Fcar (coordinates
);
1166 ly
= Fcdr (coordinates
);
1167 CHECK_NUMBER_OR_FLOAT (lx
);
1168 CHECK_NUMBER_OR_FLOAT (ly
);
1169 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1170 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1172 switch (coordinates_in_window (w
, x
, y
))
1178 /* Convert X and Y to window relative pixel coordinates, and
1179 return the canonical char units. */
1180 x
-= window_box_left (w
, TEXT_AREA
);
1181 y
-= WINDOW_TOP_EDGE_Y (w
);
1182 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1183 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1188 case ON_VERTICAL_BORDER
:
1189 return Qvertical_line
;
1191 case ON_HEADER_LINE
:
1192 return Qheader_line
;
1194 case ON_LEFT_FRINGE
:
1195 return Qleft_fringe
;
1197 case ON_RIGHT_FRINGE
:
1198 return Qright_fringe
;
1200 case ON_LEFT_MARGIN
:
1201 return Qleft_margin
;
1203 case ON_RIGHT_MARGIN
:
1204 return Qright_margin
;
1207 /* Historically we are supposed to return nil in this case. */
1216 /* Callback for foreach_window, used in window_from_coordinates.
1217 Check if window W contains coordinates specified by USER_DATA which
1218 is actually a pointer to a struct check_window_data CW.
1220 Check if window W contains coordinates *CW->x and *CW->y. If it
1221 does, return W in *CW->window, as Lisp_Object, and return in
1222 *CW->part the part of the window under coordinates *X,*Y. Return
1223 zero from this function to stop iterating over windows. */
1225 struct check_window_data
1227 Lisp_Object
*window
;
1229 enum window_part
*part
;
1233 check_window_containing (struct window
*w
, void *user_data
)
1235 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1236 enum window_part found
;
1239 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1240 if (found
!= ON_NOTHING
)
1243 XSETWINDOW (*cw
->window
, w
);
1251 /* Find the window containing frame-relative pixel position X/Y and
1252 return it as a Lisp_Object.
1254 If X, Y is on one of the window's special `window_part' elements,
1255 set *PART to the id of that element.
1257 If there is no window under X, Y return nil and leave *PART
1258 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1260 This function was previously implemented with a loop cycling over
1261 windows with Fnext_window, and starting with the frame's selected
1262 window. It turned out that this doesn't work with an
1263 implementation of next_window using Vwindow_list, because
1264 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1265 tree of F when this function is called asynchronously from
1266 note_mouse_highlight. The original loop didn't terminate in this
1270 window_from_coordinates (struct frame
*f
, int x
, int y
,
1271 enum window_part
*part
, int tool_bar_p
)
1274 struct check_window_data cw
;
1275 enum window_part dummy
;
1281 cw
.window
= &window
, cw
.x
= x
, cw
.y
= y
; cw
.part
= part
;
1282 foreach_window (f
, check_window_containing
, &cw
);
1284 /* If not found above, see if it's in the tool bar window, if a tool
1288 && WINDOWP (f
->tool_bar_window
)
1289 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1290 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), x
, y
)
1294 window
= f
->tool_bar_window
;
1300 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1301 doc
: /* Return window containing coordinates X and Y on FRAME.
1302 If omitted, FRAME defaults to the currently selected frame.
1303 The top left corner of the frame is considered to be row 0,
1305 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1310 frame
= selected_frame
;
1311 CHECK_LIVE_FRAME (frame
);
1314 /* Check that arguments are integers or floats. */
1315 CHECK_NUMBER_OR_FLOAT (x
);
1316 CHECK_NUMBER_OR_FLOAT (y
);
1318 return window_from_coordinates (f
,
1319 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1320 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1321 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1322 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1326 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1327 doc
: /* Return current value of point in WINDOW.
1328 WINDOW defaults to the selected window.
1330 For a nonselected window, this is the value point would have
1331 if that window were selected.
1333 Note that, when WINDOW is the selected window and its buffer
1334 is also currently selected, the value returned is the same as (point).
1335 It would be more strictly correct to return the `top-level' value
1336 of point, outside of any save-excursion forms.
1337 But that is hard to define. */)
1338 (Lisp_Object window
)
1340 register struct window
*w
= decode_window (window
);
1342 if (w
== XWINDOW (selected_window
)
1343 && current_buffer
== XBUFFER (w
->buffer
))
1345 return Fmarker_position (w
->pointm
);
1348 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1349 doc
: /* Return position at which display currently starts in WINDOW.
1350 WINDOW defaults to the selected window.
1351 This is updated by redisplay or by calling `set-window-start'. */)
1352 (Lisp_Object window
)
1354 return Fmarker_position (decode_window (window
)->start
);
1357 /* This is text temporarily removed from the doc string below.
1359 This function returns nil if the position is not currently known.
1360 That happens when redisplay is preempted and doesn't finish.
1361 If in that case you want to compute where the end of the window would
1362 have been if redisplay had finished, do this:
1364 (goto-char (window-start window))
1365 (vertical-motion (1- (window-height window)) window)
1368 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1369 doc
: /* Return position at which display currently ends in WINDOW.
1370 WINDOW defaults to the selected window.
1371 This is updated by redisplay, when it runs to completion.
1372 Simply changing the buffer text or setting `window-start'
1373 does not update this value.
1374 Return nil if there is no recorded value. \(This can happen if the
1375 last redisplay of WINDOW was preempted, and did not finish.)
1376 If UPDATE is non-nil, compute the up-to-date position
1377 if it isn't already recorded. */)
1378 (Lisp_Object window
, Lisp_Object update
)
1381 struct window
*w
= decode_window (window
);
1389 #if 0 /* This change broke some things. We should make it later. */
1390 /* If we don't know the end position, return nil.
1391 The user can compute it with vertical-motion if he wants to.
1392 It would be nicer to do it automatically,
1393 but that's so slow that it would probably bother people. */
1394 if (NILP (w
->window_end_valid
))
1399 && ! (! NILP (w
->window_end_valid
)
1400 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1401 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1404 struct text_pos startp
;
1406 struct buffer
*old_buffer
= NULL
;
1408 /* Cannot use Fvertical_motion because that function doesn't
1409 cope with variable-height lines. */
1410 if (b
!= current_buffer
)
1412 old_buffer
= current_buffer
;
1413 set_buffer_internal (b
);
1416 /* In case W->start is out of the range, use something
1417 reasonable. This situation occurred when loading a file with
1418 `-l' containing a call to `rmail' with subsequent other
1419 commands. At the end, W->start happened to be BEG, while
1420 rmail had already narrowed the buffer. */
1421 if (XMARKER (w
->start
)->charpos
< BEGV
)
1422 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1423 else if (XMARKER (w
->start
)->charpos
> ZV
)
1424 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1426 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1428 start_display (&it
, w
, startp
);
1429 move_it_vertically (&it
, window_box_height (w
));
1430 if (it
.current_y
< it
.last_visible_y
)
1431 move_it_past_eol (&it
);
1432 value
= make_number (IT_CHARPOS (it
));
1435 set_buffer_internal (old_buffer
);
1438 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1443 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1444 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1446 (Lisp_Object window
, Lisp_Object pos
)
1448 register struct window
*w
= decode_window (window
);
1450 CHECK_NUMBER_COERCE_MARKER (pos
);
1451 if (w
== XWINDOW (selected_window
)
1452 && XBUFFER (w
->buffer
) == current_buffer
)
1455 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1457 /* We have to make sure that redisplay updates the window to show
1458 the new value of point. */
1459 if (!EQ (window
, selected_window
))
1460 ++windows_or_buffers_changed
;
1465 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1466 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1467 WINDOW defaults to the selected window. Return POS.
1468 Optional third arg NOFORCE non-nil inhibits next redisplay from
1469 overriding motion of point in order to display at this exact start. */)
1470 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1472 register struct window
*w
= decode_window (window
);
1474 CHECK_NUMBER_COERCE_MARKER (pos
);
1475 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1476 /* this is not right, but much easier than doing what is right. */
1477 w
->start_at_line_beg
= Qnil
;
1479 w
->force_start
= Qt
;
1480 w
->update_mode_line
= Qt
;
1481 XSETFASTINT (w
->last_modified
, 0);
1482 XSETFASTINT (w
->last_overlay_modified
, 0);
1483 if (!EQ (window
, selected_window
))
1484 windows_or_buffers_changed
++;
1490 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1492 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1493 More precisely, return the value assigned by the last call of
1494 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1495 never called with WINDOW as its argument, or the value set by that
1496 function was internally reset since its last call. WINDOW defaults to
1497 the selected window.
1499 When a window is dedicated to its buffer, `display-buffer' will refrain
1500 from displaying another buffer in it. `get-lru-window' and
1501 `get-largest-window' treat dedicated windows specially.
1502 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1503 `kill-buffer' can delete a dedicated window and the containing frame.
1505 Functions like `set-window-buffer' may change the buffer displayed by a
1506 window, unless that window is "strongly" dedicated to its buffer, that
1507 is the value returned by `window-dedicated-p' is t. */)
1508 (Lisp_Object window
)
1510 return decode_window (window
)->dedicated
;
1513 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1514 Sset_window_dedicated_p
, 2, 2, 0,
1515 doc
: /* Mark WINDOW as dedicated according to FLAG.
1516 WINDOW defaults to the selected window. FLAG non-nil means mark WINDOW
1517 as dedicated to its buffer. FLAG nil means mark WINDOW as non-dedicated.
1520 When a window is dedicated to its buffer, `display-buffer' will refrain
1521 from displaying another buffer in it. `get-lru-window' and
1522 `get-largest-window' treat dedicated windows specially.
1523 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1524 `kill-buffer' can delete a dedicated window and the containing
1527 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1528 its buffer. Functions like `set-window-buffer' may change the buffer
1529 displayed by a window, unless that window is strongly dedicated to its
1530 buffer. If and when `set-window-buffer' displays another buffer in a
1531 window, it also makes sure that the window is not marked as dedicated. */)
1532 (Lisp_Object window
, Lisp_Object flag
)
1534 register struct window
*w
= decode_window (window
);
1536 w
->dedicated
= flag
;
1537 return w
->dedicated
;
1541 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1543 doc
: /* Return the parameters of WINDOW and their values.
1544 WINDOW defaults to the selected window. The return value is a list of
1545 elements of the form (PARAMETER . VALUE). */)
1546 (Lisp_Object window
)
1548 return Fcopy_alist (decode_window (window
)->window_parameters
);
1551 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1553 doc
: /* Return WINDOW's value for PARAMETER.
1554 WINDOW defaults to the selected window. */)
1555 (Lisp_Object window
, Lisp_Object parameter
)
1559 result
= Fassq (parameter
, decode_window (window
)->window_parameters
);
1560 return CDR_SAFE (result
);
1563 DEFUN ("set-window-parameter", Fset_window_parameter
,
1564 Sset_window_parameter
, 3, 3, 0,
1565 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1566 WINDOW defaults to the selected window. Return VALUE. */)
1567 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1569 register struct window
*w
= decode_window (window
);
1570 Lisp_Object old_alist_elt
;
1572 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1573 if (NILP (old_alist_elt
))
1574 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1576 Fsetcdr (old_alist_elt
, value
);
1581 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1583 doc
: /* Return the display-table that WINDOW is using.
1584 WINDOW defaults to the selected window. */)
1585 (Lisp_Object window
)
1587 return decode_window (window
)->display_table
;
1590 /* Get the display table for use on window W. This is either W's
1591 display table or W's buffer's display table. Ignore the specified
1592 tables if they are not valid; if no valid table is specified,
1595 struct Lisp_Char_Table
*
1596 window_display_table (struct window
*w
)
1598 struct Lisp_Char_Table
*dp
= NULL
;
1600 if (DISP_TABLE_P (w
->display_table
))
1601 dp
= XCHAR_TABLE (w
->display_table
);
1602 else if (BUFFERP (w
->buffer
))
1604 struct buffer
*b
= XBUFFER (w
->buffer
);
1606 if (DISP_TABLE_P (BVAR (b
, display_table
)))
1607 dp
= XCHAR_TABLE (BVAR (b
, display_table
));
1608 else if (DISP_TABLE_P (Vstandard_display_table
))
1609 dp
= XCHAR_TABLE (Vstandard_display_table
);
1615 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1616 doc
: /* Set WINDOW's display-table to TABLE. */)
1617 (register Lisp_Object window
, Lisp_Object table
)
1619 register struct window
*w
;
1621 w
= decode_window (window
);
1622 w
->display_table
= table
;
1626 static void delete_window (Lisp_Object
);
1628 /* Record info on buffer window w is displaying
1629 when it is about to cease to display that buffer. */
1631 unshow_buffer (register struct window
*w
)
1638 if (b
!= XMARKER (w
->pointm
)->buffer
)
1642 if (w
== XWINDOW (selected_window
)
1643 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1644 /* Do this except when the selected window's buffer
1645 is being removed from some other window. */
1647 /* last_window_start records the start position that this buffer
1648 had in the last window to be disconnected from it.
1649 Now that this statement is unconditional,
1650 it is possible for the buffer to be displayed in the
1651 selected window, while last_window_start reflects another
1652 window which was recently showing the same buffer.
1653 Some people might say that might be a good thing. Let's see. */
1654 b
->last_window_start
= marker_position (w
->start
);
1656 /* Point in the selected window's buffer
1657 is actually stored in that buffer, and the window's pointm isn't used.
1658 So don't clobber point in that buffer. */
1659 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1660 /* This line helps to fix Horsley's testbug.el bug. */
1661 && !(WINDOWP (BVAR (b
, last_selected_window
))
1662 && w
!= XWINDOW (BVAR (b
, last_selected_window
))
1663 && EQ (buf
, XWINDOW (BVAR (b
, last_selected_window
))->buffer
)))
1664 temp_set_point_both (b
,
1665 clip_to_bounds (BUF_BEGV (b
),
1666 XMARKER (w
->pointm
)->charpos
,
1668 clip_to_bounds (BUF_BEGV_BYTE (b
),
1669 marker_byte_position (w
->pointm
),
1672 if (WINDOWP (BVAR (b
, last_selected_window
))
1673 && w
== XWINDOW (BVAR (b
, last_selected_window
)))
1674 BVAR (b
, last_selected_window
) = Qnil
;
1677 /* Put replacement into the window structure in place of old. */
1679 replace_window (Lisp_Object old
, Lisp_Object replacement
)
1681 register Lisp_Object tem
;
1682 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
1684 /* If OLD is its frame's root_window, then replacement is the new
1685 root_window for that frame. */
1687 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1688 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
1690 p
->left_col
= o
->left_col
;
1691 p
->top_line
= o
->top_line
;
1692 p
->total_cols
= o
->total_cols
;
1693 p
->total_lines
= o
->total_lines
;
1694 p
->desired_matrix
= p
->current_matrix
= 0;
1696 memset (&p
->cursor
, 0, sizeof (p
->cursor
));
1697 memset (&p
->last_cursor
, 0, sizeof (p
->last_cursor
));
1698 memset (&p
->phys_cursor
, 0, sizeof (p
->phys_cursor
));
1699 p
->phys_cursor_type
= -1;
1700 p
->phys_cursor_width
= -1;
1701 p
->must_be_updated_p
= 0;
1702 p
->pseudo_window_p
= 0;
1703 XSETFASTINT (p
->window_end_vpos
, 0);
1704 XSETFASTINT (p
->window_end_pos
, 0);
1705 p
->window_end_valid
= Qnil
;
1706 p
->frozen_window_start_p
= 0;
1707 p
->orig_top_line
= p
->orig_total_lines
= Qnil
;
1709 p
->next
= tem
= o
->next
;
1711 XWINDOW (tem
)->prev
= replacement
;
1713 p
->prev
= tem
= o
->prev
;
1715 XWINDOW (tem
)->next
= replacement
;
1717 p
->parent
= tem
= o
->parent
;
1720 if (EQ (XWINDOW (tem
)->vchild
, old
))
1721 XWINDOW (tem
)->vchild
= replacement
;
1722 if (EQ (XWINDOW (tem
)->hchild
, old
))
1723 XWINDOW (tem
)->hchild
= replacement
;
1726 /*** Here, if replacement is a vertical combination
1727 and so is its new parent, we should make replacement's
1728 children be children of that parent instead. ***/
1731 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
1732 doc
: /* Remove WINDOW from its frame.
1733 WINDOW defaults to the selected window. Return nil.
1734 Signal an error when WINDOW is the only window on its frame. */)
1735 (register Lisp_Object window
)
1739 window
= selected_window
;
1741 CHECK_LIVE_WINDOW (window
);
1743 f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
1744 delete_window (window
);
1746 run_window_configuration_change_hook (f
);
1752 delete_window (register Lisp_Object window
)
1754 register Lisp_Object tem
, parent
, sib
;
1755 register struct window
*p
;
1756 register struct window
*par
;
1759 /* Because this function is called by other C code on non-leaf
1760 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1761 so we can't decode_window here. */
1762 CHECK_WINDOW (window
);
1763 p
= XWINDOW (window
);
1765 /* It's a no-op to delete an already-deleted window. */
1766 if (NILP (p
->buffer
)
1768 && NILP (p
->vchild
))
1773 error ("Attempt to delete minibuffer or sole ordinary window");
1774 par
= XWINDOW (parent
);
1776 windows_or_buffers_changed
++;
1777 Vwindow_list
= Qnil
;
1778 f
= XFRAME (WINDOW_FRAME (p
));
1779 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
1781 /* Are we trying to delete any frame's selected window? */
1783 Lisp_Object swindow
, pwindow
;
1785 /* See if the frame's selected window is either WINDOW
1786 or any subwindow of it, by finding all that window's parents
1787 and comparing each one with WINDOW. */
1788 swindow
= FRAME_SELECTED_WINDOW (f
);
1793 while (!NILP (pwindow
))
1795 if (EQ (window
, pwindow
))
1797 pwindow
= XWINDOW (pwindow
)->parent
;
1800 /* If the window being deleted is not a parent of SWINDOW,
1801 then SWINDOW is ok as the new selected window. */
1802 if (!EQ (window
, pwindow
))
1804 /* Otherwise, try another window for SWINDOW. */
1805 swindow
= Fnext_window (swindow
, Qlambda
, Qnil
);
1807 /* If we get back to the frame's selected window,
1808 it means there was no acceptable alternative,
1809 so we cannot delete. */
1810 if (EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1811 error ("Cannot delete window");
1814 /* If we need to change SWINDOW, do it. */
1815 if (! EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
1817 /* If we're about to delete the selected window on the
1818 selected frame, then we should use Fselect_window to select
1819 the new window. On the other hand, if we're about to
1820 delete the selected window on any other frame, we shouldn't do
1821 anything but set the frame's selected_window slot. */
1822 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
1823 Fselect_window (swindow
, Qnil
);
1825 FRAME_SELECTED_WINDOW (f
) = swindow
;
1829 /* Now we know we can delete this one. */
1830 window_deletion_count
++;
1833 /* tem is null for dummy parent windows
1834 (which have inferiors but not any contents themselves) */
1838 unchain_marker (XMARKER (p
->pointm
));
1839 unchain_marker (XMARKER (p
->start
));
1842 /* Free window glyph matrices. It is sure that they are allocated
1843 again when ADJUST_GLYPHS is called. Block input so that expose
1844 events and other events that access glyph matrices are not
1845 processed while we are changing them. */
1847 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f
)));
1851 XWINDOW (tem
)->prev
= p
->prev
;
1855 XWINDOW (tem
)->next
= p
->next
;
1857 if (EQ (window
, par
->hchild
))
1858 par
->hchild
= p
->next
;
1859 if (EQ (window
, par
->vchild
))
1860 par
->vchild
= p
->next
;
1862 /* Find one of our siblings to give our space to. */
1866 /* If p gives its space to its next sibling, that sibling needs
1867 to have its top/left side pulled back to where p's is.
1868 set_window_{height,width} will re-position the sibling's
1871 XWINDOW (sib
)->top_line
= p
->top_line
;
1872 XWINDOW (sib
)->left_col
= p
->left_col
;
1875 /* Stretch that sibling. */
1876 if (!NILP (par
->vchild
))
1877 set_window_height (sib
,
1878 XFASTINT (XWINDOW (sib
)->total_lines
) + XFASTINT (p
->total_lines
),
1880 if (!NILP (par
->hchild
))
1881 set_window_width (sib
,
1882 XFASTINT (XWINDOW (sib
)->total_cols
) + XFASTINT (p
->total_cols
),
1885 /* If parent now has only one child,
1886 put the child into the parent's place. */
1890 if (NILP (XWINDOW (tem
)->next
)) {
1891 replace_window (parent
, tem
);
1892 par
= XWINDOW (tem
);
1895 /* Since we may be deleting combination windows, we must make sure that
1896 not only p but all its children have been marked as deleted. */
1897 if (! NILP (p
->hchild
))
1898 delete_all_subwindows (XWINDOW (p
->hchild
));
1899 else if (! NILP (p
->vchild
))
1900 delete_all_subwindows (XWINDOW (p
->vchild
));
1902 /* Mark this window as deleted. */
1903 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1905 if (! NILP (par
->parent
))
1906 par
= XWINDOW (par
->parent
);
1908 /* Check if we have a v/hchild with a v/hchild. In that case remove
1911 if (! NILP (par
->vchild
) && ! NILP (XWINDOW (par
->vchild
)->vchild
))
1913 p
= XWINDOW (par
->vchild
);
1914 par
->vchild
= p
->vchild
;
1917 else if (! NILP (par
->hchild
) && ! NILP (XWINDOW (par
->hchild
)->hchild
))
1919 p
= XWINDOW (par
->hchild
);
1920 par
->hchild
= p
->hchild
;
1928 while (! NILP (tem
)) {
1929 XWINDOW (tem
)->parent
= p
->parent
;
1930 if (NILP (XWINDOW (tem
)->next
))
1932 tem
= XWINDOW (tem
)->next
;
1935 /* The next of the v/hchild we are removing is now the next of the
1936 last child for the v/hchild:
1937 Before v/hchild -> v/hchild -> next1 -> next2
1940 After: v/hchild -> next1 -> next2 -> next3
1942 XWINDOW (tem
)->next
= p
->next
;
1943 if (! NILP (p
->next
))
1944 XWINDOW (p
->next
)->prev
= tem
;
1946 p
->next
= p
->prev
= p
->vchild
= p
->hchild
= p
->buffer
= Qnil
;
1950 /* Adjust glyph matrices. */
1957 /***********************************************************************
1959 ***********************************************************************/
1961 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1962 pointer. This is a callback function for foreach_window, used in
1963 function window_list. */
1966 add_window_to_list (struct window
*w
, void *user_data
)
1968 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1970 XSETWINDOW (window
, w
);
1971 *list
= Fcons (window
, *list
);
1976 /* Return a list of all windows, for use by next_window. If
1977 Vwindow_list is a list, return that list. Otherwise, build a new
1978 list, cache it in Vwindow_list, and return that. */
1983 if (!CONSP (Vwindow_list
))
1987 Vwindow_list
= Qnil
;
1988 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1990 Lisp_Object args
[2];
1992 /* We are visiting windows in canonical order, and add
1993 new windows at the front of args[1], which means we
1994 have to reverse this list at the end. */
1996 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1997 args
[0] = Vwindow_list
;
1998 args
[1] = Fnreverse (args
[1]);
1999 Vwindow_list
= Fnconc (2, args
);
2003 return Vwindow_list
;
2007 /* Value is non-zero if WINDOW satisfies the constraints given by
2008 OWINDOW, MINIBUF and ALL_FRAMES.
2010 MINIBUF t means WINDOW may be minibuffer windows.
2011 `lambda' means WINDOW may not be a minibuffer window.
2012 a window means a specific minibuffer window
2014 ALL_FRAMES t means search all frames,
2015 nil means search just current frame,
2016 `visible' means search just visible frames on the
2018 0 means search visible and iconified frames on the
2020 a window means search the frame that window belongs to,
2021 a frame means consider windows on that frame, only. */
2024 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2026 struct window
*w
= XWINDOW (window
);
2027 struct frame
*f
= XFRAME (w
->frame
);
2028 int candidate_p
= 1;
2030 if (!BUFFERP (w
->buffer
))
2032 else if (MINI_WINDOW_P (w
)
2033 && (EQ (minibuf
, Qlambda
)
2034 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2036 /* If MINIBUF is `lambda' don't consider any mini-windows.
2037 If it is a window, consider only that one. */
2040 else if (EQ (all_frames
, Qt
))
2042 else if (NILP (all_frames
))
2044 xassert (WINDOWP (owindow
));
2045 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2047 else if (EQ (all_frames
, Qvisible
))
2049 FRAME_SAMPLE_VISIBILITY (f
);
2050 candidate_p
= FRAME_VISIBLE_P (f
)
2051 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2052 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2055 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2057 FRAME_SAMPLE_VISIBILITY (f
);
2058 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2059 #ifdef HAVE_X_WINDOWS
2060 /* Yuck!! If we've just created the frame and the
2061 window-manager requested the user to place it
2062 manually, the window may still not be considered
2063 `visible'. I'd argue it should be at least
2064 something like `iconified', but don't know how to do
2066 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2067 && !f
->output_data
.x
->has_been_visible
)
2070 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2071 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2073 else if (WINDOWP (all_frames
))
2074 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2075 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2076 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2077 else if (FRAMEP (all_frames
))
2078 candidate_p
= EQ (all_frames
, w
->frame
);
2084 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2085 Fwindow_list. See candidate_window_p for the meaning of WINDOW,
2086 MINIBUF, and ALL_FRAMES. */
2089 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2092 *window
= selected_window
;
2094 CHECK_LIVE_WINDOW (*window
);
2096 /* MINIBUF nil may or may not include minibuffers. Decide if it
2098 if (NILP (*minibuf
))
2099 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2100 else if (!EQ (*minibuf
, Qt
))
2103 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2104 => count none of them, or a specific minibuffer window (the
2105 active one) to count. */
2107 /* ALL_FRAMES nil doesn't specify which frames to include. */
2108 if (NILP (*all_frames
))
2109 *all_frames
= (!EQ (*minibuf
, Qlambda
)
2110 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
2112 else if (EQ (*all_frames
, Qvisible
))
2114 else if (EQ (*all_frames
, make_number (0)))
2116 else if (FRAMEP (*all_frames
))
2118 else if (!EQ (*all_frames
, Qt
))
2123 /* Return the next or previous window of WINDOW in cyclic ordering
2124 of windows. NEXT_P non-zero means return the next window. See the
2125 documentation string of next-window for the meaning of MINIBUF and
2129 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2131 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2133 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2134 return the first window on the frame. */
2135 if (FRAMEP (all_frames
)
2136 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2137 return Fframe_first_window (all_frames
);
2143 /* Find WINDOW in the list of all windows. */
2144 list
= Fmemq (window
, window_list ());
2146 /* Scan forward from WINDOW to the end of the window list. */
2148 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2149 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2152 /* Scan from the start of the window list up to WINDOW. */
2154 for (list
= Vwindow_list
;
2155 CONSP (list
) && !EQ (XCAR (list
), window
);
2157 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2161 window
= XCAR (list
);
2165 Lisp_Object candidate
, list
;
2167 /* Scan through the list of windows for candidates. If there are
2168 candidate windows in front of WINDOW, the last one of these
2169 is the one we want. If there are candidates following WINDOW
2170 in the list, again the last one of these is the one we want. */
2172 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2174 if (EQ (XCAR (list
), window
))
2176 if (WINDOWP (candidate
))
2179 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2181 candidate
= XCAR (list
);
2184 if (WINDOWP (candidate
))
2192 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2193 doc
: /* Return window following WINDOW in cyclic ordering of windows.
2194 WINDOW defaults to the selected window. The optional arguments
2195 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2197 MINIBUF t means consider the minibuffer window even if the
2198 minibuffer is not active. MINIBUF nil or omitted means consider
2199 the minibuffer window only if the minibuffer is active. Any
2200 other value means do not consider the minibuffer window even if
2201 the minibuffer is active.
2203 Several frames may share a single minibuffer; if the minibuffer
2204 is active, all windows on all frames that share that minibuffer
2205 are considered too. Therefore, if you are using a separate
2206 minibuffer frame and the minibuffer is active and MINIBUF says it
2207 counts, `next-window' considers the windows in the frame from
2208 which you entered the minibuffer, as well as the minibuffer
2211 ALL-FRAMES nil or omitted means consider all windows on WINDOW's
2212 frame, plus the minibuffer window if specified by the MINIBUF
2213 argument, see above. If the minibuffer counts, consider all
2214 windows on all frames that share that minibuffer too.
2215 ALL-FRAMES t means consider all windows on all existing frames.
2216 ALL-FRAMES `visible' means consider all windows on all visible
2217 frames on the current terminal.
2218 ALL-FRAMES 0 means consider all windows on all visible and
2219 iconified frames on the current terminal.
2220 ALL-FRAMES a frame means consider all windows on that frame only.
2221 Anything else means consider all windows on WINDOW's frame and no
2224 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2225 `next-window' to iterate through the entire cycle of acceptable
2226 windows, eventually ending up back at the window you started with.
2227 `previous-window' traverses the same cycle, in the reverse order. */)
2228 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2230 return next_window (window
, minibuf
, all_frames
, 1);
2234 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2235 doc
: /* Return window preceding WINDOW in cyclic ordering of windows.
2236 WINDOW defaults to the selected window. The optional arguments
2237 MINIBUF and ALL-FRAMES specify the set of windows to consider.
2238 For the precise meaning of these arguments see `next-window'.
2240 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2241 use `previous-window' to iterate through the entire cycle of
2242 acceptable windows, eventually ending up back at the window you
2243 started with. `next-window' traverses the same cycle, in the
2245 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2247 return next_window (window
, minibuf
, all_frames
, 0);
2251 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
2252 doc
: /* Select another window in cyclic ordering of windows.
2253 COUNT specifies the number of windows to skip, starting with the
2254 selected window, before making the selection. If COUNT is
2255 positive, skip COUNT windows forwards. If COUNT is negative,
2256 skip -COUNT windows backwards. COUNT zero means do not skip any
2257 window, so select the selected window. In an interactive call,
2258 COUNT is the numeric prefix argument. Return nil.
2260 This function uses `next-window' for finding the window to select.
2261 The argument ALL-FRAMES has the same meaning as in `next-window',
2262 but the MINIBUF argument of `next-window' is always effectively
2264 (Lisp_Object count
, Lisp_Object all_frames
)
2269 CHECK_NUMBER (count
);
2270 window
= selected_window
;
2272 for (i
= XINT (count
); i
> 0; --i
)
2273 window
= Fnext_window (window
, Qnil
, all_frames
);
2275 window
= Fprevious_window (window
, Qnil
, all_frames
);
2277 Fselect_window (window
, Qnil
);
2282 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2283 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2284 FRAME nil or omitted means use the selected frame.
2285 WINDOW nil or omitted means use the selected window.
2286 MINIBUF t means include the minibuffer window, even if it isn't active.
2287 MINIBUF nil or omitted means include the minibuffer window only
2289 MINIBUF neither nil nor t means never include the minibuffer window. */)
2290 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2293 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2294 CHECK_WINDOW (window
);
2296 frame
= selected_frame
;
2298 if (!EQ (frame
, XWINDOW (window
)->frame
))
2299 error ("Window is on a different frame");
2301 return window_list_1 (window
, minibuf
, frame
);
2305 /* Return a list of windows in cyclic ordering. Arguments are like
2306 for `next-window'. */
2309 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2311 Lisp_Object tail
, list
, rest
;
2313 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2316 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2317 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2318 list
= Fcons (XCAR (tail
), list
);
2320 /* Rotate the list to start with WINDOW. */
2321 list
= Fnreverse (list
);
2322 rest
= Fmemq (window
, list
);
2323 if (!NILP (rest
) && !EQ (rest
, list
))
2325 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2327 XSETCDR (tail
, Qnil
);
2328 list
= nconc2 (rest
, list
);
2335 /* Look at all windows, performing an operation specified by TYPE
2337 If FRAMES is Qt, look at all frames;
2338 Qnil, look at just the selected frame;
2339 Qvisible, look at visible frames;
2340 a frame, just look at windows on that frame.
2341 If MINI is non-zero, perform the operation on minibuffer windows too. */
2346 GET_BUFFER_WINDOW
, /* Arg is buffer */
2347 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
2348 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
2349 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
2351 UNSHOW_BUFFER
, /* Arg is buffer */
2352 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2357 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2359 Lisp_Object window
, windows
, best_window
, frame_arg
;
2361 struct gcpro gcpro1
;
2363 /* If we're only looping through windows on a particular frame,
2364 frame points to that frame. If we're looping through windows
2365 on all frames, frame is 0. */
2366 if (FRAMEP (frames
))
2367 f
= XFRAME (frames
);
2368 else if (NILP (frames
))
2369 f
= SELECTED_FRAME ();
2374 frame_arg
= Qlambda
;
2375 else if (EQ (frames
, make_number (0)))
2377 else if (EQ (frames
, Qvisible
))
2382 /* frame_arg is Qlambda to stick to one frame,
2383 Qvisible to consider all visible frames,
2386 /* Pick a window to start with. */
2390 window
= FRAME_SELECTED_WINDOW (f
);
2392 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2394 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2398 for (; CONSP (windows
); windows
= XCDR (windows
))
2402 window
= XCAR (windows
);
2403 w
= XWINDOW (window
);
2405 /* Note that we do not pay attention here to whether the frame
2406 is visible, since Fwindow_list skips non-visible frames if
2407 that is desired, under the control of frame_arg. */
2408 if (!MINI_WINDOW_P (w
)
2409 /* For UNSHOW_BUFFER, we must always consider all windows. */
2410 || type
== UNSHOW_BUFFER
2411 || (mini
&& minibuf_level
> 0))
2414 case GET_BUFFER_WINDOW
:
2415 if (EQ (w
->buffer
, obj
)
2416 /* Don't find any minibuffer window
2417 except the one that is currently in use. */
2418 && (MINI_WINDOW_P (w
)
2419 ? EQ (window
, minibuf_window
)
2422 if (NILP (best_window
))
2423 best_window
= window
;
2424 else if (EQ (window
, selected_window
))
2425 /* Prefer to return selected-window. */
2426 RETURN_UNGCPRO (window
);
2427 else if (EQ (Fwindow_frame (window
), selected_frame
))
2428 /* Prefer windows on the current frame. */
2429 best_window
= window
;
2433 case GET_LRU_WINDOW
:
2434 /* `obj' is an integer encoding a bitvector.
2435 `obj & 1' means consider only full-width windows.
2436 `obj & 2' means consider also dedicated windows. */
2437 if (((XINT (obj
) & 1) && !WINDOW_FULL_WIDTH_P (w
))
2438 || (!(XINT (obj
) & 2) && !NILP (w
->dedicated
))
2439 /* Minibuffer windows are always ignored. */
2440 || MINI_WINDOW_P (w
))
2442 if (NILP (best_window
)
2443 || (XFASTINT (XWINDOW (best_window
)->use_time
)
2444 > XFASTINT (w
->use_time
)))
2445 best_window
= window
;
2448 case DELETE_OTHER_WINDOWS
:
2449 if (!EQ (window
, obj
))
2450 Fdelete_window (window
);
2453 case DELETE_BUFFER_WINDOWS
:
2454 if (EQ (w
->buffer
, obj
))
2456 struct frame
*fr
= XFRAME (WINDOW_FRAME (w
));
2458 /* If this window is dedicated, and in a frame of its own,
2460 if (EQ (window
, FRAME_ROOT_WINDOW (fr
))
2461 && !NILP (w
->dedicated
)
2462 && other_visible_frames (fr
))
2464 /* Skip the other windows on this frame.
2465 There might be one, the minibuffer! */
2466 while (CONSP (XCDR (windows
))
2467 && EQ (XWINDOW (XCAR (windows
))->frame
,
2468 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2469 windows
= XCDR (windows
);
2471 /* Now we can safely delete the frame. */
2472 delete_frame (w
->frame
, Qnil
);
2474 else if (NILP (w
->parent
))
2476 /* If we're deleting the buffer displayed in the
2477 only window on the frame, find a new buffer to
2480 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2481 /* Reset dedicated state of window. */
2482 w
->dedicated
= Qnil
;
2483 Fset_window_buffer (window
, buffer
, Qnil
);
2484 if (EQ (window
, selected_window
))
2485 Fset_buffer (w
->buffer
);
2488 Fdelete_window (window
);
2492 case GET_LARGEST_WINDOW
:
2493 { /* nil `obj' means to ignore dedicated windows. */
2494 /* Ignore dedicated windows and minibuffers. */
2495 if (MINI_WINDOW_P (w
) || (NILP (obj
) && !NILP (w
->dedicated
)))
2498 if (NILP (best_window
))
2499 best_window
= window
;
2502 struct window
*b
= XWINDOW (best_window
);
2503 if (XFASTINT (w
->total_lines
) * XFASTINT (w
->total_cols
)
2504 > XFASTINT (b
->total_lines
) * XFASTINT (b
->total_cols
))
2505 best_window
= window
;
2511 if (EQ (w
->buffer
, obj
))
2514 struct frame
*fr
= XFRAME (w
->frame
);
2516 /* Find another buffer to show in this window. */
2517 buffer
= Fother_buffer (obj
, Qnil
, w
->frame
);
2519 /* If this window is dedicated, and in a frame of its own,
2521 if (EQ (window
, FRAME_ROOT_WINDOW (fr
))
2522 && !NILP (w
->dedicated
)
2523 && other_visible_frames (fr
))
2525 /* Skip the other windows on this frame.
2526 There might be one, the minibuffer! */
2527 while (CONSP (XCDR (windows
))
2528 && EQ (XWINDOW (XCAR (windows
))->frame
,
2529 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2530 windows
= XCDR (windows
);
2532 /* Now we can safely delete the frame. */
2533 delete_frame (w
->frame
, Qnil
);
2535 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2537 Lisp_Object window_to_delete
;
2538 XSETWINDOW (window_to_delete
, w
);
2539 /* If this window is dedicated and not the only window
2540 in its frame, then kill it. */
2541 Fdelete_window (window_to_delete
);
2545 /* Otherwise show a different buffer in the window. */
2546 w
->dedicated
= Qnil
;
2547 Fset_window_buffer (window
, buffer
, Qnil
);
2548 if (EQ (window
, selected_window
))
2549 Fset_buffer (w
->buffer
);
2554 case REDISPLAY_BUFFER_WINDOWS
:
2555 if (EQ (w
->buffer
, obj
))
2557 mark_window_display_accurate (window
, 0);
2558 w
->update_mode_line
= Qt
;
2559 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2560 ++update_mode_lines
;
2561 best_window
= window
;
2565 /* Check for a window that has a killed buffer. */
2566 case CHECK_ALL_WINDOWS
:
2567 if (! NILP (w
->buffer
)
2568 && NILP (BVAR (XBUFFER (w
->buffer
), name
)))
2572 case WINDOW_LOOP_UNUSED
:
2581 /* Used for debugging. Abort if any window has a dead buffer. */
2583 extern void check_all_windows (void) EXTERNALLY_VISIBLE
;
2585 check_all_windows (void)
2587 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2590 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
2591 doc
: /* Return WINDOW's use time.
2592 WINDOW defaults to the selected window. The window with the highest use
2593 time is the most recently selected one. The window with the lowest use
2594 time is the least recently selected one. */)
2595 (Lisp_Object window
)
2597 return decode_window (window
)->use_time
;
2600 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 2, 0,
2601 doc
: /* Return the window least recently selected or used for display.
2602 \(LRU means Least Recently Used.)
2604 Return a full-width window if possible.
2605 A minibuffer window is never a candidate.
2606 A dedicated window is never a candidate, unless DEDICATED is non-nil,
2607 so if all windows are dedicated, the value is nil.
2608 If optional argument FRAME is `visible', search all visible frames.
2609 If FRAME is 0, search all visible and iconified frames.
2610 If FRAME is t, search all frames.
2611 If FRAME is nil, search only the selected frame.
2612 If FRAME is a frame, search only that frame. */)
2613 (Lisp_Object frame
, Lisp_Object dedicated
)
2615 register Lisp_Object w
;
2616 /* First try for a window that is full-width */
2617 w
= window_loop (GET_LRU_WINDOW
,
2618 NILP (dedicated
) ? make_number (1) : make_number (3),
2620 if (!NILP (w
) && !EQ (w
, selected_window
))
2622 /* If none of them, try the rest */
2623 return window_loop (GET_LRU_WINDOW
,
2624 NILP (dedicated
) ? make_number (0) : make_number (2),
2628 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 2, 0,
2629 doc
: /* Return the largest window in area.
2630 A minibuffer window is never a candidate.
2631 A dedicated window is never a candidate unless DEDICATED is non-nil,
2632 so if all windows are dedicated, the value is nil.
2633 If optional argument FRAME is `visible', search all visible frames.
2634 If FRAME is 0, search all visible and iconified frames.
2635 If FRAME is t, search all frames.
2636 If FRAME is nil, search only the selected frame.
2637 If FRAME is a frame, search only that frame. */)
2638 (Lisp_Object frame
, Lisp_Object dedicated
)
2640 return window_loop (GET_LARGEST_WINDOW
, dedicated
, 0,
2644 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2645 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2646 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to the
2648 If optional argument FRAME is `visible', search all visible frames.
2649 If optional argument FRAME is 0, search all visible and iconified frames.
2650 If FRAME is t, search all frames.
2651 If FRAME is nil, search only the selected frame.
2652 If FRAME is a frame, search only that frame. */)
2653 (Lisp_Object buffer_or_name
, Lisp_Object frame
)
2657 if (NILP (buffer_or_name
))
2658 buffer
= Fcurrent_buffer ();
2660 buffer
= Fget_buffer (buffer_or_name
);
2662 if (BUFFERP (buffer
))
2663 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
2668 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
2670 doc
: /* Make WINDOW (or the selected window) fill its frame.
2671 Only the frame WINDOW is on is affected.
2672 This function tries to reduce display jumps by keeping the text
2673 previously visible in WINDOW in the same place on the frame. Doing this
2674 depends on the value of (window-start WINDOW), so if calling this
2675 function in a program gives strange scrolling, make sure the
2676 window-start value is reasonable when this function is called. */)
2677 (Lisp_Object window
)
2684 window
= selected_window
;
2686 CHECK_LIVE_WINDOW (window
);
2687 w
= XWINDOW (window
);
2689 startpos
= marker_position (w
->start
);
2690 top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2692 if (MINI_WINDOW_P (w
) && top
> 0)
2693 error ("Can't expand minibuffer to full frame");
2695 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
2697 /* Try to minimize scrolling, by setting the window start to the point
2698 will cause the text at the old window start to be at the same place
2699 on the frame. But don't try to do this if the window start is
2700 outside the visible portion (as might happen when the display is
2701 not current, due to typeahead). */
2702 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2704 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2705 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2707 struct position pos
;
2708 struct buffer
*obuf
= current_buffer
;
2710 Fset_buffer (w
->buffer
);
2711 /* This computation used to temporarily move point, but that can
2712 have unwanted side effects due to text properties. */
2713 pos
= *vmotion (startpos
, -top
, w
);
2715 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2716 w
->window_end_valid
= Qnil
;
2717 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2718 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2720 /* We need to do this, so that the window-scroll-functions
2722 w
->optional_new_start
= Qt
;
2724 set_buffer_internal (obuf
);
2730 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
2731 0, 2, "bDelete windows on (buffer): ",
2732 doc
: /* Delete all windows showing BUFFER-OR-NAME.
2733 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2734 defaults to the current buffer.
2736 Optional second argument FRAME controls which frames are affected.
2737 If optional argument FRAME is `visible', search all visible frames.
2738 If FRAME is 0, search all visible and iconified frames.
2739 If FRAME is nil, search all frames.
2740 If FRAME is t, search only the selected frame.
2741 If FRAME is a frame, search only that frame.
2742 When a window showing BUFFER-OR-NAME is dedicated and the only window of
2743 its frame, that frame is deleted when there are other frames left. */)
2744 (Lisp_Object buffer_or_name
, Lisp_Object frame
)
2748 /* FRAME uses t and nil to mean the opposite of what window_loop
2752 else if (EQ (frame
, Qt
))
2755 if (NILP (buffer_or_name
))
2756 buffer
= Fcurrent_buffer ();
2759 buffer
= Fget_buffer (buffer_or_name
);
2760 CHECK_BUFFER (buffer
);
2763 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
2768 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2769 Sreplace_buffer_in_windows
,
2770 0, 1, "bReplace buffer in windows: ",
2771 doc
: /* Replace BUFFER-OR-NAME with some other buffer in all windows showing it.
2772 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2773 defaults to the current buffer.
2775 When a window showing BUFFER-OR-NAME is dedicated that window is
2776 deleted. If that window is the only window on its frame, that frame is
2777 deleted too when there are other frames left. If there are no other
2778 frames left, some other buffer is displayed in that window. */)
2779 (Lisp_Object buffer_or_name
)
2783 if (NILP (buffer_or_name
))
2784 buffer
= Fcurrent_buffer ();
2787 buffer
= Fget_buffer (buffer_or_name
);
2788 CHECK_BUFFER (buffer
);
2791 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2796 /* Replace BUFFER with some other buffer in all windows
2797 of all frames, even those on other keyboards. */
2800 replace_buffer_in_all_windows (Lisp_Object buffer
)
2802 Lisp_Object tail
, frame
;
2804 /* A single call to window_loop won't do the job
2805 because it only considers frames on the current keyboard.
2806 So loop manually over frames, and handle each one. */
2807 FOR_EACH_FRAME (tail
, frame
)
2808 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2811 /* Set the height of WINDOW and all its inferiors. */
2813 /* The smallest acceptable dimensions for a window. Anything smaller
2814 might crash Emacs. */
2816 #define MIN_SAFE_WINDOW_WIDTH (2)
2817 #define MIN_SAFE_WINDOW_HEIGHT (1)
2819 /* For wp non-zero the total number of columns of window w. Otherwise
2820 the total number of lines of w. */
2822 #define WINDOW_TOTAL_SIZE(w, wp) \
2823 (wp ? WINDOW_TOTAL_COLS (w) : WINDOW_TOTAL_LINES (w))
2825 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2826 minimum allowable size. */
2829 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
2831 /* For height, we have to see:
2832 how many windows the frame has at minimum (one or two),
2833 and whether it has a menu bar or other special stuff at the top. */
2835 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2836 ? MIN_SAFE_WINDOW_HEIGHT
2837 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2839 if (FRAME_TOP_MARGIN (frame
) > 0)
2840 min_height
+= FRAME_TOP_MARGIN (frame
);
2842 if (*rows
< min_height
)
2844 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2845 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2848 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2849 check if W's width can be changed, otherwise check W's height.
2850 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2851 siblings, too. If none of the siblings is resizable, WINDOW isn't
2855 window_fixed_size_p (struct window
*w
, int width_p
, int check_siblings_p
)
2860 if (!NILP (w
->hchild
))
2862 c
= XWINDOW (w
->hchild
);
2866 /* A horizontal combination is fixed-width if all of if its
2868 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2869 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2870 fixed_p
= c
== NULL
;
2874 /* A horizontal combination is fixed-height if one of if its
2876 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2877 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2878 fixed_p
= c
!= NULL
;
2881 else if (!NILP (w
->vchild
))
2883 c
= XWINDOW (w
->vchild
);
2887 /* A vertical combination is fixed-width if one of if its
2889 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
2890 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2891 fixed_p
= c
!= NULL
;
2895 /* A vertical combination is fixed-height if all of if its
2897 while (c
&& window_fixed_size_p (c
, width_p
, 0))
2898 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2899 fixed_p
= c
== NULL
;
2902 else if (BUFFERP (w
->buffer
))
2904 struct buffer
*old
= current_buffer
;
2907 current_buffer
= XBUFFER (w
->buffer
);
2908 val
= find_symbol_value (Qwindow_size_fixed
);
2909 current_buffer
= old
;
2912 if (!EQ (val
, Qunbound
))
2914 fixed_p
= !NILP (val
);
2917 && ((EQ (val
, Qheight
) && width_p
)
2918 || (EQ (val
, Qwidth
) && !width_p
)))
2922 /* Can't tell if this one is resizable without looking at
2923 siblings. If all siblings are fixed-size this one is too. */
2924 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
2928 for (child
= w
->prev
; WINDOWP (child
); child
= XWINDOW (child
)->prev
)
2929 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2933 for (child
= w
->next
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
2934 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2947 /* Return minimum size of leaf window W. WIDTH_P non-zero means return
2948 the minimum width of W, WIDTH_P zero means return the minimum height
2949 of W. SAFE_P non-zero means ignore window-min-height|width but just
2950 return values that won't crash Emacs and don't hide components like
2951 fringes, scrollbars, or modelines. If WIDTH_P is zero and W is the
2952 minibuffer window, always return 1. */
2955 window_min_size_2 (struct window
*w
, int width_p
, int safe_p
)
2957 /* We should consider buffer-local values of window_min_height and
2958 window_min_width here. */
2961 int safe_size
= (MIN_SAFE_WINDOW_WIDTH
2962 + WINDOW_FRINGE_COLS (w
)
2963 + WINDOW_SCROLL_BAR_COLS (w
));
2965 return safe_p
? safe_size
: max (window_min_width
, safe_size
);
2967 else if (MINI_WINDOW_P (w
))
2971 int safe_size
= (MIN_SAFE_WINDOW_HEIGHT
2972 + ((BUFFERP (w
->buffer
)
2973 && !NILP (BVAR (XBUFFER (w
->buffer
), mode_line_format
)))
2976 return safe_p
? safe_size
: max (window_min_height
, safe_size
);
2980 /* Return minimum size of window W, not taking fixed-width windows into
2981 account. WIDTH_P non-zero means return the minimum width, otherwise
2982 return the minimum height. SAFE_P non-zero means ignore
2983 window-min-height|width but just return values that won't crash Emacs
2984 and don't hide components like fringes, scrollbars, or modelines. If
2985 W is a combination window, compute the minimum size from the minimum
2986 sizes of W's children. */
2989 window_min_size_1 (struct window
*w
, int width_p
, int safe_p
)
2994 if (!NILP (w
->hchild
))
2996 /* W is a horizontal combination. */
2997 c
= XWINDOW (w
->hchild
);
3002 /* The minimum width of a horizontal combination is the sum of
3003 the minimum widths of its children. */
3006 size
+= window_min_size_1 (c
, 1, safe_p
);
3007 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3012 /* The minimum height of a horizontal combination is the
3013 maximum of the minimum heights of its children. */
3016 size
= max (window_min_size_1 (c
, 0, safe_p
), size
);
3017 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3021 else if (!NILP (w
->vchild
))
3023 /* W is a vertical combination. */
3024 c
= XWINDOW (w
->vchild
);
3029 /* The minimum width of a vertical combination is the maximum
3030 of the minimum widths of its children. */
3033 size
= max (window_min_size_1 (c
, 1, safe_p
), size
);
3034 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3039 /* The minimum height of a vertical combination is the sum of
3040 the minimum height of its children. */
3043 size
+= window_min_size_1 (c
, 0, safe_p
);
3044 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
3049 /* W is a leaf window. */
3050 size
= window_min_size_2 (w
, width_p
, safe_p
);
3055 /* Return the minimum size of window W, taking fixed-size windows into
3056 account. WIDTH_P non-zero means return the minimum width, otherwise
3057 return the minimum height. SAFE_P non-zero means ignore
3058 window-min-height|width but just return values that won't crash Emacs
3059 and don't hide components like fringes, scrollbars, or modelines.
3060 IGNORE_FIXED_P non-zero means ignore if W is fixed-size. Set *FIXED
3061 to 1 if W is fixed-size unless FIXED is null. */
3064 window_min_size (struct window
*w
, int width_p
, int safe_p
, int ignore_fixed_p
, int *fixed
)
3071 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
3077 size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3079 size
= window_min_size_1 (w
, width_p
, safe_p
);
3085 /* Adjust the margins of window W if text area is too small.
3086 Return 1 if window width is ok after adjustment; 0 if window
3087 is still too narrow. */
3090 adjust_window_margins (struct window
*w
)
3092 int box_cols
= (WINDOW_TOTAL_COLS (w
)
3093 - WINDOW_FRINGE_COLS (w
)
3094 - WINDOW_SCROLL_BAR_COLS (w
));
3095 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
3096 + WINDOW_RIGHT_MARGIN_COLS (w
));
3098 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
3101 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
3104 /* Window's text area is too narrow, but reducing the window
3105 margins will fix that. */
3106 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
3107 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
3109 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
3110 w
->left_margin_cols
= w
->right_margin_cols
3111 = make_number (margin_cols
/2);
3113 w
->right_margin_cols
= make_number (margin_cols
);
3116 w
->left_margin_cols
= make_number (margin_cols
);
3120 /* Calculate new sizes for windows in the list FORWARD when their
3121 compound size goes from TOTAL to SIZE. TOTAL must be greater than
3122 SIZE. The number of windows in FORWARD is NCHILDREN, and the number
3123 that can shrink is SHRINKABLE. Fixed-size windows may be shrunk if
3124 and only if RESIZE_FIXED_P is non-zero. WIDTH_P non-zero means
3125 shrink columns, otherwise shrink lines.
3127 SAFE_P zero means windows may be sized down to window-min-height
3128 lines (window-min-window columns for WIDTH_P non-zero). SAFE_P
3129 non-zero means windows may be sized down to their minimum safe sizes
3130 taking into account the space needed to display modelines, fringes,
3133 This function returns an allocated array of new sizes that the caller
3134 must free. A size -1 means the window is fixed and RESIZE_FIXED_P is
3135 zero. A size zero means the window shall be deleted. Array index 0
3136 refers to the first window in FORWARD, 1 to the second, and so on.
3138 This function resizes windows proportionally to their size. It also
3139 tries to preserve smaller windows by resizing larger windows before
3140 resizing any window to zero. If resize_proportionally is non-nil for
3141 a specific window, it will attempt to strictly resize that window
3142 proportionally, even at the expense of deleting smaller windows. */
3144 shrink_windows (int total
, int size
, int nchildren
, int shrinkable
,
3145 int resize_fixed_p
, Lisp_Object forward
, int width_p
, int safe_p
)
3147 int available_resize
= 0;
3148 int *new_sizes
, *min_sizes
;
3151 int smallest
= total
;
3152 int total_removed
= 0;
3153 int total_shrink
= total
- size
;
3156 new_sizes
= xmalloc (sizeof (*new_sizes
) * nchildren
);
3157 min_sizes
= xmalloc (sizeof (*min_sizes
) * nchildren
);
3159 for (i
= 0, child
= forward
; !NILP (child
); child
= c
->next
, ++i
)
3163 c
= XWINDOW (child
);
3164 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3166 if (!resize_fixed_p
&& window_fixed_size_p (c
, width_p
, 0))
3170 new_sizes
[i
] = child_size
;
3171 min_sizes
[i
] = window_min_size_1 (c
, width_p
, safe_p
);
3172 if (child_size
> min_sizes
[i
]
3173 && NILP (c
->resize_proportionally
))
3174 available_resize
+= child_size
- min_sizes
[i
];
3177 /* We might need to shrink some windows to zero. Find the smallest
3178 windows and set them to 0 until we can fulfil the new size. */
3180 while (shrinkable
> 1 && size
+ available_resize
< total
)
3182 for (i
= 0; i
< nchildren
; ++i
)
3183 if (new_sizes
[i
] > 0 && smallest
> new_sizes
[i
])
3184 smallest
= new_sizes
[i
];
3186 for (i
= 0; i
< nchildren
; ++i
)
3187 if (new_sizes
[i
] == smallest
)
3189 /* Resize this window down to zero. */
3191 if (smallest
> min_sizes
[i
])
3192 available_resize
-= smallest
- min_sizes
[i
];
3193 available_resize
+= smallest
;
3195 total_removed
+= smallest
;
3197 /* We don't know what the smallest is now. */
3200 /* Out of for, just remove one window at the time and
3201 check again if we have enough space. */
3206 /* Now, calculate the new sizes. Try to shrink each window
3207 proportional to its size. */
3208 for (i
= 0; i
< nchildren
; ++i
)
3210 if (new_sizes
[i
] > min_sizes
[i
])
3212 int to_shrink
= total_shrink
* new_sizes
[i
] / total
;
3214 if (new_sizes
[i
] - to_shrink
< min_sizes
[i
])
3215 to_shrink
= new_sizes
[i
] - min_sizes
[i
];
3216 new_sizes
[i
] -= to_shrink
;
3217 total_removed
+= to_shrink
;
3221 /* Any reminder due to rounding, we just subtract from windows
3222 that are left and still can be shrunk. */
3223 while (total_shrink
> total_removed
)
3225 int nonzero_sizes
= 0;
3227 for (i
= 0; i
< nchildren
; ++i
)
3228 if (new_sizes
[i
] > 0)
3231 for (i
= 0; i
< nchildren
; ++i
)
3232 if (new_sizes
[i
] > min_sizes
[i
])
3237 /* Out of for, just shrink one window at the time and
3238 check again if we have enough space. */
3242 /* Special case, only one window left. */
3243 if (nonzero_sizes
== 1)
3247 /* Any surplus due to rounding, we add to windows that are left. */
3248 while (total_shrink
< total_removed
)
3250 for (i
= 0; i
< nchildren
; ++i
)
3252 if (new_sizes
[i
] != 0 && total_shrink
< total_removed
)
3266 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
3267 WINDOW's width. Resize WINDOW's children, if any, so that they keep
3268 their proportionate size relative to WINDOW.
3270 If FIRST_ONLY is 1, change only the first of WINDOW's children when
3271 they are in series. If LAST_ONLY is 1, change only the last of
3272 WINDOW's children when they are in series.
3274 Propagate WINDOW's top or left edge position to children. Delete
3275 windows that become too small unless NODELETE_P is 1. When
3276 NODELETE_P equals 2 do not honor settings for window-min-height and
3277 window-min-width when resizing windows but use safe defaults instead.
3278 This should give better behavior when resizing frames. */
3281 size_window (Lisp_Object window
, int size
, int width_p
, int nodelete_p
, int first_only
, int last_only
)
3283 struct window
*w
= XWINDOW (window
);
3285 Lisp_Object child
, *forward
, *sideward
;
3286 int old_size
= WINDOW_TOTAL_SIZE (w
, width_p
);
3288 size
= max (0, size
);
3290 /* Delete WINDOW if it's too small. */
3291 if (nodelete_p
!= 1 && !NILP (w
->parent
)
3292 && size
< window_min_size_1 (w
, width_p
, nodelete_p
== 2))
3294 delete_window (window
);
3298 /* Set redisplay hints. */
3299 w
->last_modified
= make_number (0);
3300 w
->last_overlay_modified
= make_number (0);
3301 windows_or_buffers_changed
++;
3302 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w
->frame
)) = 1;
3306 sideward
= &w
->vchild
;
3307 forward
= &w
->hchild
;
3308 w
->total_cols
= make_number (size
);
3309 adjust_window_margins (w
);
3313 sideward
= &w
->hchild
;
3314 forward
= &w
->vchild
;
3315 w
->total_lines
= make_number (size
);
3316 w
->orig_total_lines
= Qnil
;
3319 if (!NILP (*sideward
))
3321 /* We have a chain of parallel siblings whose size should all change. */
3322 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
3324 c
= XWINDOW (child
);
3326 c
->left_col
= w
->left_col
;
3328 c
->top_line
= w
->top_line
;
3329 size_window (child
, size
, width_p
, nodelete_p
,
3330 first_only
, last_only
);
3333 else if (!NILP (*forward
) && last_only
)
3335 /* Change the last in a series of siblings. */
3336 Lisp_Object last_child
;
3342 c
= XWINDOW (child
);
3346 while (!NILP (child
));
3348 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3349 size_window (last_child
, size
- old_size
+ child_size
,
3350 width_p
, nodelete_p
, first_only
, last_only
);
3352 else if (!NILP (*forward
) && first_only
)
3354 /* Change the first in a series of siblings. */
3358 c
= XWINDOW (child
);
3361 c
->left_col
= w
->left_col
;
3363 c
->top_line
= w
->top_line
;
3365 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3366 size_window (child
, size
- old_size
+ child_size
,
3367 width_p
, nodelete_p
, first_only
, last_only
);
3369 else if (!NILP (*forward
))
3371 int fixed_size
, each
IF_LINT (= 0), extra
IF_LINT (= 0), n
;
3372 int resize_fixed_p
, nfixed
;
3373 int last_pos
, first_pos
, nchildren
, total
;
3374 int *new_sizes
= NULL
;
3376 /* Determine the fixed-size portion of this window, and the
3377 number of child windows. */
3378 fixed_size
= nchildren
= nfixed
= total
= 0;
3379 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
3383 c
= XWINDOW (child
);
3384 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3385 total
+= child_size
;
3387 if (window_fixed_size_p (c
, width_p
, 0))
3389 fixed_size
+= child_size
;
3394 /* If the new size is smaller than fixed_size, or if there
3395 aren't any resizable windows, allow resizing fixed-size
3397 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
3399 /* Compute how many lines/columns to add/remove to each child. The
3400 value of extra takes care of rounding errors. */
3401 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
3402 if (size
< total
&& n
> 1)
3403 new_sizes
= shrink_windows (total
, size
, nchildren
, n
,
3404 resize_fixed_p
, *forward
, width_p
,
3408 each
= (size
- total
) / n
;
3409 extra
= (size
- total
) - n
* each
;
3412 /* Compute new children heights and edge positions. */
3413 first_pos
= width_p
? XINT (w
->left_col
) : XINT (w
->top_line
);
3414 last_pos
= first_pos
;
3415 for (n
= 0, child
= *forward
; !NILP (child
); child
= c
->next
, ++n
)
3417 int new_child_size
, old_child_size
;
3419 c
= XWINDOW (child
);
3420 old_child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3421 new_child_size
= old_child_size
;
3423 /* The top or left edge position of this child equals the
3424 bottom or right edge of its predecessor. */
3426 c
->left_col
= make_number (last_pos
);
3428 c
->top_line
= make_number (last_pos
);
3430 /* If this child can be resized, do it. */
3431 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
3434 new_sizes
? new_sizes
[n
] : old_child_size
+ each
+ extra
;
3438 /* Set new size. Note that size_window also propagates
3439 edge positions to children, so it's not a no-op if we
3440 didn't change the child's size. */
3441 size_window (child
, new_child_size
, width_p
, 1,
3442 first_only
, last_only
);
3444 /* Remember the bottom/right edge position of this child; it
3445 will be used to set the top/left edge of the next child. */
3446 last_pos
+= new_child_size
;
3451 /* We should have covered the parent exactly with child windows. */
3452 xassert (size
== last_pos
- first_pos
);
3454 /* Now delete any children that became too small. */
3455 if (nodelete_p
!= 1)
3456 for (child
= *forward
; !NILP (child
); child
= c
->next
)
3460 c
= XWINDOW (child
);
3461 child_size
= WINDOW_TOTAL_SIZE (c
, width_p
);
3462 size_window (child
, child_size
, width_p
, nodelete_p
,
3463 first_only
, last_only
);
3468 /* Set WINDOW's height to HEIGHT, and recursively change the height of
3469 WINDOW's children. NODELETE zero means windows that have become
3470 smaller than window-min-height in the process may be deleted.
3471 NODELETE 1 means never delete windows that become too small in the
3472 process. (The caller should check later and do so if appropriate.)
3473 NODELETE 2 means delete only windows that have become too small to be
3474 displayed correctly. */
3477 set_window_height (Lisp_Object window
, int height
, int nodelete
)
3479 size_window (window
, height
, 0, nodelete
, 0, 0);
3482 /* Set WINDOW's width to WIDTH, and recursively change the width of
3483 WINDOW's children. NODELETE zero means windows that have become
3484 smaller than window-min-width in the process may be deleted.
3485 NODELETE 1 means never delete windows that become too small in the
3486 process. (The caller should check later and do so if appropriate.)
3487 NODELETE 2 means delete only windows that have become too small to be
3488 displayed correctly. */
3491 set_window_width (Lisp_Object window
, int width
, int nodelete
)
3493 size_window (window
, width
, 1, nodelete
, 0, 0);
3496 /* Change window heights in windows rooted in WINDOW by N lines. */
3499 change_window_heights (Lisp_Object window
, int n
)
3501 struct window
*w
= XWINDOW (window
);
3503 XSETFASTINT (w
->top_line
, XFASTINT (w
->top_line
) + n
);
3504 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - n
);
3506 if (INTEGERP (w
->orig_top_line
))
3507 XSETFASTINT (w
->orig_top_line
, XFASTINT (w
->orig_top_line
) + n
);
3508 if (INTEGERP (w
->orig_total_lines
))
3509 XSETFASTINT (w
->orig_total_lines
, XFASTINT (w
->orig_total_lines
) - n
);
3511 /* Handle just the top child in a vertical split. */
3512 if (!NILP (w
->vchild
))
3513 change_window_heights (w
->vchild
, n
);
3515 /* Adjust all children in a horizontal split. */
3516 for (window
= w
->hchild
; !NILP (window
); window
= w
->next
)
3518 w
= XWINDOW (window
);
3519 change_window_heights (window
, n
);
3524 int window_select_count
;
3526 static Lisp_Object
Fset_window_margins (Lisp_Object
, Lisp_Object
, Lisp_Object
);
3527 static Lisp_Object
Fset_window_fringes (Lisp_Object
, Lisp_Object
, Lisp_Object
,
3529 static Lisp_Object
Fset_window_scroll_bars (Lisp_Object
, Lisp_Object
,
3530 Lisp_Object
, Lisp_Object
);
3531 static Lisp_Object
Fset_window_vscroll (Lisp_Object
, Lisp_Object
, Lisp_Object
);
3534 run_funs (Lisp_Object funs
)
3536 for (; CONSP (funs
); funs
= XCDR (funs
))
3537 if (!EQ (XCAR (funs
), Qt
))
3538 call0 (XCAR (funs
));
3541 static Lisp_Object
select_window_norecord (Lisp_Object window
);
3542 static Lisp_Object
select_frame_norecord (Lisp_Object frame
);
3545 run_window_configuration_change_hook (struct frame
*f
)
3547 int count
= SPECPDL_INDEX ();
3548 Lisp_Object frame
, global_wcch
3549 = Fdefault_value (Qwindow_configuration_change_hook
);
3550 XSETFRAME (frame
, f
);
3552 if (NILP (Vrun_hooks
))
3555 if (SELECTED_FRAME () != f
)
3557 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
3558 Fselect_frame (frame
, Qt
);
3561 /* Use the right buffer. Matters when running the local hooks. */
3562 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
3564 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3565 Fset_buffer (Fwindow_buffer (Qnil
));
3568 /* Look for buffer-local values. */
3570 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
3571 for (; CONSP (windows
); windows
= XCDR (windows
))
3573 Lisp_Object window
= XCAR (windows
);
3574 Lisp_Object buffer
= Fwindow_buffer (window
);
3575 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
3578 int count1
= SPECPDL_INDEX ();
3579 record_unwind_protect (select_window_norecord
, Fselected_window ());
3580 select_window_norecord (window
);
3581 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
3583 unbind_to (count1
, Qnil
);
3588 run_funs (global_wcch
);
3589 unbind_to (count
, Qnil
);
3592 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
3593 means it's allowed to run hooks. See make_frame for a case where
3594 it's not allowed. KEEP_MARGINS_P non-zero means that the current
3595 margins, fringes, and scroll-bar settings of the window are not
3596 reset from the buffer's local settings. */
3599 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
3601 struct window
*w
= XWINDOW (window
);
3602 struct buffer
*b
= XBUFFER (buffer
);
3603 int count
= SPECPDL_INDEX ();
3604 int samebuf
= EQ (buffer
, w
->buffer
);
3608 if (EQ (window
, selected_window
))
3609 BVAR (b
, last_selected_window
) = window
;
3611 /* Let redisplay errors through. */
3612 b
->display_error_modiff
= 0;
3614 /* Update time stamps of buffer display. */
3615 if (INTEGERP (BVAR (b
, display_count
)))
3616 XSETINT (BVAR (b
, display_count
), XINT (BVAR (b
, display_count
)) + 1);
3617 BVAR (b
, display_time
) = Fcurrent_time ();
3619 XSETFASTINT (w
->window_end_pos
, 0);
3620 XSETFASTINT (w
->window_end_vpos
, 0);
3621 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3622 w
->window_end_valid
= Qnil
;
3623 if (!(keep_margins_p
&& samebuf
))
3624 { /* If we're not actually changing the buffer, don't reset hscroll and
3625 vscroll. This case happens for example when called from
3626 change_frame_size_1, where we use a dummy call to
3627 Fset_window_buffer on the frame's selected window (and no other)
3628 just in order to run window-configuration-change-hook.
3629 Resetting hscroll and vscroll here is problematic for things like
3630 image-mode and doc-view-mode since it resets the image's position
3631 whenever we resize the frame. */
3632 w
->hscroll
= w
->min_hscroll
= make_number (0);
3634 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3635 set_marker_restricted (w
->start
,
3636 make_number (b
->last_window_start
),
3638 w
->start_at_line_beg
= Qnil
;
3639 w
->force_start
= Qnil
;
3640 XSETFASTINT (w
->last_modified
, 0);
3641 XSETFASTINT (w
->last_overlay_modified
, 0);
3643 /* Maybe we could move this into the `if' but it's not obviously safe and
3644 I doubt it's worth the trouble. */
3645 windows_or_buffers_changed
++;
3647 /* We must select BUFFER for running the window-scroll-functions. */
3648 /* We can't check ! NILP (Vwindow_scroll_functions) here
3649 because that might itself be a local variable. */
3650 if (window_initialized
)
3652 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3653 Fset_buffer (buffer
);
3656 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3658 if (!keep_margins_p
)
3660 /* Set left and right marginal area width etc. from buffer. */
3662 /* This may call adjust_window_margins three times, so
3663 temporarily disable window margins. */
3664 Lisp_Object save_left
= w
->left_margin_cols
;
3665 Lisp_Object save_right
= w
->right_margin_cols
;
3667 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3669 Fset_window_fringes (window
,
3670 BVAR (b
, left_fringe_width
), BVAR (b
, right_fringe_width
),
3671 BVAR (b
, fringes_outside_margins
));
3673 Fset_window_scroll_bars (window
,
3674 BVAR (b
, scroll_bar_width
),
3675 BVAR (b
, vertical_scroll_bar_type
), Qnil
);
3677 w
->left_margin_cols
= save_left
;
3678 w
->right_margin_cols
= save_right
;
3680 Fset_window_margins (window
,
3681 BVAR (b
, left_margin_cols
), BVAR (b
, right_margin_cols
));
3686 if (! NILP (Vwindow_scroll_functions
))
3687 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3688 Fmarker_position (w
->start
));
3689 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3692 unbind_to (count
, Qnil
);
3696 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3697 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3698 WINDOW defaults to the selected window. BUFFER-OR-NAME must be a buffer
3699 or the name of an existing buffer. Optional third argument KEEP-MARGINS
3700 non-nil means that WINDOW's current display margins, fringe widths, and
3701 scroll bar settings are preserved; the default is to reset these from
3702 the local settings for BUFFER-OR-NAME or the frame defaults. Return nil.
3704 This function throws an error when WINDOW is strongly dedicated to its
3705 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3706 already display BUFFER-OR-NAME.
3708 This function runs `window-scroll-functions' before running
3709 `window-configuration-change-hook'. */)
3710 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3712 register Lisp_Object tem
, buffer
;
3713 register struct window
*w
= decode_window (window
);
3715 XSETWINDOW (window
, w
);
3716 buffer
= Fget_buffer (buffer_or_name
);
3717 CHECK_BUFFER (buffer
);
3718 if (NILP (BVAR (XBUFFER (buffer
), name
)))
3719 error ("Attempt to display deleted buffer");
3723 error ("Window is deleted");
3724 else if (!EQ (tem
, Qt
))
3725 /* w->buffer is t when the window is first being set up. */
3727 if (EQ (tem
, buffer
))
3729 else if (EQ (w
->dedicated
, Qt
))
3730 error ("Window is dedicated to `%s'", SDATA (BVAR (XBUFFER (tem
), name
)));
3732 w
->dedicated
= Qnil
;
3737 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3742 select_window_norecord (Lisp_Object window
)
3744 return WINDOW_LIVE_P (window
)
3745 ? Fselect_window (window
, Qt
) : selected_window
;
3749 select_frame_norecord (Lisp_Object frame
)
3751 return FRAME_LIVE_P (XFRAME (frame
))
3752 ? Fselect_frame (frame
, Qt
) : selected_frame
;
3756 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3758 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3761 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3763 doc
: /* Force all windows to be updated on next redisplay.
3764 If optional arg OBJECT is a window, force redisplay of that window only.
3765 If OBJECT is a buffer or buffer name, force redisplay of all windows
3766 displaying that buffer. */)
3767 (Lisp_Object object
)
3771 windows_or_buffers_changed
++;
3772 update_mode_lines
++;
3776 if (WINDOWP (object
))
3778 struct window
*w
= XWINDOW (object
);
3779 mark_window_display_accurate (object
, 0);
3780 w
->update_mode_line
= Qt
;
3781 if (BUFFERP (w
->buffer
))
3782 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3783 ++update_mode_lines
;
3787 if (STRINGP (object
))
3788 object
= Fget_buffer (object
);
3789 if (BUFFERP (object
) && !NILP (BVAR (XBUFFER (object
), name
)))
3791 /* Walk all windows looking for buffer, and force update
3792 of each of those windows. */
3794 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3795 return NILP (object
) ? Qnil
: Qt
;
3798 /* If nothing suitable was found, just return.
3799 We could signal an error, but this feature will typically be used
3800 asynchronously in timers or process sentinels, so we don't. */
3806 temp_output_buffer_show (register Lisp_Object buf
)
3808 register struct buffer
*old
= current_buffer
;
3809 register Lisp_Object window
;
3810 register struct window
*w
;
3812 BVAR (XBUFFER (buf
), directory
) = BVAR (current_buffer
, directory
);
3815 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3819 set_buffer_internal (old
);
3821 if (!NILP (Vtemp_buffer_show_function
))
3822 call1 (Vtemp_buffer_show_function
, buf
);
3825 window
= display_buffer (buf
, Qnil
, Qnil
);
3827 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3828 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3829 Vminibuf_scroll_window
= window
;
3830 w
= XWINDOW (window
);
3831 XSETFASTINT (w
->hscroll
, 0);
3832 XSETFASTINT (w
->min_hscroll
, 0);
3833 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3834 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3836 /* Run temp-buffer-show-hook, with the chosen window selected
3837 and its buffer current. */
3839 int count
= SPECPDL_INDEX ();
3840 Lisp_Object prev_window
, prev_buffer
;
3841 prev_window
= selected_window
;
3842 XSETBUFFER (prev_buffer
, old
);
3844 /* Select the window that was chosen, for running the hook.
3845 Note: Both Fselect_window and select_window_norecord may
3846 set-buffer to the buffer displayed in the window,
3847 so we need to save the current buffer. --stef */
3848 record_unwind_protect (Fset_buffer
, prev_buffer
);
3849 record_unwind_protect (select_window_norecord
, prev_window
);
3850 Fselect_window (window
, Qt
);
3851 Fset_buffer (w
->buffer
);
3852 Frun_hooks (1, &Qtemp_buffer_show_hook
);
3853 unbind_to (count
, Qnil
);
3858 DEFUN ("internal-temp-output-buffer-show",
3859 Ftemp_output_buffer_show
, Stemp_output_buffer_show
,
3861 doc
: /* Internal function for `with-output-to-temp-buffer''. */)
3864 temp_output_buffer_show (buf
);
3869 make_dummy_parent (Lisp_Object window
)
3872 register struct window
*o
, *p
;
3875 o
= XWINDOW (window
);
3876 p
= allocate_window ();
3877 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3878 ((struct Lisp_Vector
*) p
)->contents
[i
]
3879 = ((struct Lisp_Vector
*)o
)->contents
[i
];
3880 XSETWINDOW (new, p
);
3883 XSETFASTINT (p
->sequence_number
, sequence_number
);
3885 /* Put new into window structure in place of window */
3886 replace_window (window
, new);
3899 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
3900 doc
: /* Split WINDOW, putting SIZE lines in the first of the pair.
3901 WINDOW defaults to selected one and SIZE to half its size.
3902 If optional third arg HORIZONTAL is non-nil, split side by side and put
3903 SIZE columns in the first of the pair. In that case, SIZE includes that
3904 window's scroll bar, or the divider column to its right.
3905 Interactively, all arguments are nil.
3906 Returns the newly created window (which is the lower or rightmost one).
3907 The upper or leftmost window is the original one, and remains selected
3908 if it was selected before.
3910 See Info node `(elisp)Splitting Windows' for more details and examples. */)
3911 (Lisp_Object window
, Lisp_Object size
, Lisp_Object horizontal
)
3913 register Lisp_Object
new;
3914 register struct window
*o
, *p
;
3916 register int size_int
;
3919 window
= selected_window
;
3921 CHECK_LIVE_WINDOW (window
);
3923 o
= XWINDOW (window
);
3924 fo
= XFRAME (WINDOW_FRAME (o
));
3928 if (!NILP (horizontal
))
3929 /* Calculate the size of the left-hand window, by dividing
3930 the usable space in columns by two.
3931 We round up, since the left-hand window may include
3932 a dividing line, while the right-hand may not. */
3933 size_int
= (XFASTINT (o
->total_cols
) + 1) >> 1;
3935 size_int
= XFASTINT (o
->total_lines
) >> 1;
3939 CHECK_NUMBER (size
);
3940 size_int
= XINT (size
);
3943 if (MINI_WINDOW_P (o
))
3944 error ("Attempt to split minibuffer window");
3945 else if (window_fixed_size_p (o
, !NILP (horizontal
), 0))
3946 error ("Attempt to split fixed-size window");
3948 if (NILP (horizontal
))
3950 int window_safe_height
= window_min_size_2 (o
, 0, 0);
3952 if (size_int
< window_safe_height
)
3953 error ("Window height %d too small (after splitting)", size_int
);
3954 if (size_int
+ window_safe_height
> XFASTINT (o
->total_lines
))
3955 error ("Window height %d too small (after splitting)",
3956 (int) (XFASTINT (o
->total_lines
) - size_int
));
3957 if (NILP (o
->parent
)
3958 || NILP (XWINDOW (o
->parent
)->vchild
))
3960 make_dummy_parent (window
);
3962 XWINDOW (new)->vchild
= window
;
3967 int window_safe_width
= window_min_size_2 (o
, 1, 0);
3969 if (size_int
< window_safe_width
)
3970 error ("Window width %d too small (after splitting)", size_int
);
3971 if (size_int
+ window_safe_width
> XFASTINT (o
->total_cols
))
3972 error ("Window width %d too small (after splitting)",
3973 (int) (XFASTINT (o
->total_cols
) - size_int
));
3974 if (NILP (o
->parent
)
3975 || NILP (XWINDOW (o
->parent
)->hchild
))
3977 make_dummy_parent (window
);
3979 XWINDOW (new)->hchild
= window
;
3983 /* Now we know that window's parent is a vertical combination
3984 if we are dividing vertically, or a horizontal combination
3985 if we are making side-by-side windows */
3987 windows_or_buffers_changed
++;
3988 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
3989 new = make_window ();
3992 p
->frame
= o
->frame
;
3994 if (!NILP (p
->next
))
3995 XWINDOW (p
->next
)->prev
= new;
3998 p
->parent
= o
->parent
;
4000 p
->window_end_valid
= Qnil
;
4001 memset (&p
->last_cursor
, 0, sizeof p
->last_cursor
);
4003 /* Duplicate special geometry settings. */
4005 p
->left_margin_cols
= o
->left_margin_cols
;
4006 p
->right_margin_cols
= o
->right_margin_cols
;
4007 p
->left_fringe_width
= o
->left_fringe_width
;
4008 p
->right_fringe_width
= o
->right_fringe_width
;
4009 p
->fringes_outside_margins
= o
->fringes_outside_margins
;
4010 p
->scroll_bar_width
= o
->scroll_bar_width
;
4011 p
->vertical_scroll_bar_type
= o
->vertical_scroll_bar_type
;
4013 /* Apportion the available frame space among the two new windows */
4015 if (!NILP (horizontal
))
4017 p
->total_lines
= o
->total_lines
;
4018 p
->top_line
= o
->top_line
;
4019 XSETFASTINT (p
->total_cols
, XFASTINT (o
->total_cols
) - size_int
);
4020 XSETFASTINT (o
->total_cols
, size_int
);
4021 XSETFASTINT (p
->left_col
, XFASTINT (o
->left_col
) + size_int
);
4022 adjust_window_margins (p
);
4023 adjust_window_margins (o
);
4027 p
->left_col
= o
->left_col
;
4028 p
->total_cols
= o
->total_cols
;
4029 XSETFASTINT (p
->total_lines
, XFASTINT (o
->total_lines
) - size_int
);
4030 XSETFASTINT (o
->total_lines
, size_int
);
4031 XSETFASTINT (p
->top_line
, XFASTINT (o
->top_line
) + size_int
);
4034 /* Adjust glyph matrices. */
4037 Fset_window_buffer (new, o
->buffer
, Qt
);
4041 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
4042 doc
: /* Make selected window SIZE lines taller.
4043 Interactively, if no argument is given, make the selected window one
4044 line taller. If optional argument HORIZONTAL is non-nil, make selected
4045 window wider by SIZE columns. If SIZE is negative, shrink the window by
4046 -SIZE lines or columns. Return nil.
4048 This function can delete windows if they get too small. The size of
4049 fixed size windows is not altered by this function. */)
4050 (Lisp_Object size
, Lisp_Object horizontal
)
4052 CHECK_NUMBER (size
);
4053 enlarge_window (selected_window
, XINT (size
), !NILP (horizontal
));
4055 run_window_configuration_change_hook (SELECTED_FRAME ());
4060 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
4061 doc
: /* Make selected window SIZE lines smaller.
4062 Interactively, if no argument is given, make the selected window one
4063 line smaller. If optional argument HORIZONTAL is non-nil, make the
4064 window narrower by SIZE columns. If SIZE is negative, enlarge selected
4065 window by -SIZE lines or columns. Return nil.
4067 This function can delete windows if they get too small. The size of
4068 fixed size windows is not altered by this function. */)
4069 (Lisp_Object size
, Lisp_Object horizontal
)
4071 CHECK_NUMBER (size
);
4072 enlarge_window (selected_window
, -XINT (size
), !NILP (horizontal
));
4074 run_window_configuration_change_hook (SELECTED_FRAME ());
4080 window_height (Lisp_Object window
)
4082 register struct window
*p
= XWINDOW (window
);
4083 return WINDOW_TOTAL_LINES (p
);
4087 window_width (Lisp_Object window
)
4089 register struct window
*p
= XWINDOW (window
);
4090 return WINDOW_TOTAL_COLS (p
);
4095 *(horiz_flag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
4097 #define CURSIZE(w) \
4098 *(horiz_flag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
4101 /* Enlarge WINDOW by DELTA. HORIZ_FLAG nonzero means enlarge it
4102 horizontally; zero means do it vertically.
4104 Siblings of the selected window are resized to fulfill the size
4105 request. If they become too small in the process, they may be
4109 enlarge_window (Lisp_Object window
, int delta
, int horiz_flag
)
4111 Lisp_Object parent
, next
, prev
;
4115 int (*sizefun
) (Lisp_Object
)
4116 = horiz_flag
? window_width
: window_height
;
4117 void (*setsizefun
) (Lisp_Object
, int, int)
4118 = (horiz_flag
? set_window_width
: set_window_height
);
4120 /* Give up if this window cannot be resized. */
4121 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4122 error ("Window is not resizable");
4124 /* Find the parent of the selected window. */
4127 p
= XWINDOW (window
);
4133 error ("No other window to side of this one");
4138 ? !NILP (XWINDOW (parent
)->hchild
)
4139 : !NILP (XWINDOW (parent
)->vchild
))
4145 sizep
= &CURSIZE (window
);
4148 register int maxdelta
;
4150 /* Compute the maximum size increment this window can have. */
4152 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - XINT (*sizep
)
4153 /* This is a main window followed by a minibuffer. */
4154 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
4155 - window_min_size (XWINDOW (p
->next
),
4156 horiz_flag
, 0, 0, 0))
4157 /* This is a minibuffer following a main window. */
4158 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
4159 - window_min_size (XWINDOW (p
->prev
),
4160 horiz_flag
, 0, 0, 0))
4161 /* This is a frame with only one window, a minibuffer-only
4162 or a minibufferless frame. */
4165 if (delta
> maxdelta
)
4166 /* This case traps trying to make the minibuffer
4167 the full frame, or make the only window aside from the
4168 minibuffer the full frame. */
4172 if (XINT (*sizep
) + delta
< window_min_size (XWINDOW (window
),
4173 horiz_flag
, 0, 0, 0))
4175 delete_window (window
);
4182 /* Find the total we can get from other siblings without deleting them. */
4184 for (next
= p
->next
; WINDOWP (next
); next
= XWINDOW (next
)->next
)
4185 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
4186 horiz_flag
, 0, 0, 0);
4187 for (prev
= p
->prev
; WINDOWP (prev
); prev
= XWINDOW (prev
)->prev
)
4188 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
4189 horiz_flag
, 0, 0, 0);
4191 /* If we can get it all from them without deleting them, do so. */
4192 if (delta
<= maximum
)
4194 Lisp_Object first_unaffected
;
4195 Lisp_Object first_affected
;
4200 first_affected
= window
;
4201 /* Look at one sibling at a time,
4202 moving away from this window in both directions alternately,
4203 and take as much as we can get without deleting that sibling. */
4205 && (!NILP (next
) || !NILP (prev
)))
4209 int this_one
= ((*sizefun
) (next
)
4210 - window_min_size (XWINDOW (next
), horiz_flag
,
4214 if (this_one
> delta
)
4217 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
4218 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4223 next
= XWINDOW (next
)->next
;
4231 int this_one
= ((*sizefun
) (prev
)
4232 - window_min_size (XWINDOW (prev
), horiz_flag
,
4236 if (this_one
> delta
)
4239 first_affected
= prev
;
4241 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
4242 (*setsizefun
) (window
, XINT (*sizep
) + this_one
, 0);
4247 prev
= XWINDOW (prev
)->prev
;
4251 xassert (delta
== 0);
4253 /* Now recalculate the edge positions of all the windows affected,
4254 based on the new sizes. */
4255 first_unaffected
= next
;
4256 prev
= first_affected
;
4257 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
4258 prev
= next
, next
= XWINDOW (next
)->next
)
4260 XSETINT (CURBEG (next
), XINT (CURBEG (prev
)) + (*sizefun
) (prev
));
4261 /* This does not change size of NEXT,
4262 but it propagates the new top edge to its children */
4263 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
4268 register int delta1
;
4269 register int opht
= (*sizefun
) (parent
);
4271 if (opht
<= XINT (*sizep
) + delta
)
4273 /* If trying to grow this window to or beyond size of the parent,
4274 just delete all the sibling windows. */
4275 Lisp_Object start
, tem
;
4277 start
= XWINDOW (parent
)->vchild
;
4279 start
= XWINDOW (parent
)->hchild
;
4281 /* Delete any siblings that come after WINDOW. */
4282 tem
= XWINDOW (window
)->next
;
4283 while (! NILP (tem
))
4285 Lisp_Object next1
= XWINDOW (tem
)->next
;
4286 delete_window (tem
);
4290 /* Delete any siblings that come after WINDOW.
4291 Note that if START is not WINDOW, then WINDOW still
4292 has siblings, so WINDOW has not yet replaced its parent. */
4294 while (! EQ (tem
, window
))
4296 Lisp_Object next1
= XWINDOW (tem
)->next
;
4297 delete_window (tem
);
4303 /* Otherwise, make delta1 just right so that if we add
4304 delta1 lines to this window and to the parent, and then
4305 shrink the parent back to its original size, the new
4306 proportional size of this window will increase by delta.
4308 The function size_window will compute the new height h'
4309 of the window from delta1 as:
4312 x = delta1 - delta1/n * n for the 1st resizable child
4315 where n is the number of children that can be resized.
4316 We can ignore x by choosing a delta1 that is a multiple of
4317 n. We want the height of this window to come out as
4327 The number of children n equals the number of resizable
4328 children of this window + 1 because we know window itself
4329 is resizable (otherwise we would have signaled an error).
4331 This reasoning is not correct when other windows become too
4332 small and shrink_windows refuses to delete them. Below we
4333 use resize_proportionally to work around this problem. */
4335 struct window
*w
= XWINDOW (window
);
4339 for (s
= w
->next
; WINDOWP (s
); s
= XWINDOW (s
)->next
)
4340 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4342 for (s
= w
->prev
; WINDOWP (s
); s
= XWINDOW (s
)->prev
)
4343 if (!window_fixed_size_p (XWINDOW (s
), horiz_flag
, 0))
4348 /* Add delta1 lines or columns to this window, and to the parent,
4349 keeping things consistent while not affecting siblings. */
4350 XSETINT (CURSIZE (parent
), opht
+ delta1
);
4351 (*setsizefun
) (window
, XINT (*sizep
) + delta1
, 0);
4353 /* Squeeze out delta1 lines or columns from our parent,
4354 shrinking this window and siblings proportionately. This
4355 brings parent back to correct size. Delta1 was calculated
4356 so this makes this window the desired size, taking it all
4357 out of the siblings.
4359 Temporarily set resize_proportionally to Qt to assure that,
4360 if necessary, shrink_windows deletes smaller windows rather
4361 than shrink this window. */
4362 w
->resize_proportionally
= Qt
;
4363 (*setsizefun
) (parent
, opht
, 0);
4364 w
->resize_proportionally
= Qnil
;
4368 XSETFASTINT (p
->last_modified
, 0);
4369 XSETFASTINT (p
->last_overlay_modified
, 0);
4371 /* Adjust glyph matrices. */
4372 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4376 /* Adjust the size of WINDOW by DELTA, moving only its trailing edge.
4377 HORIZ_FLAG nonzero means adjust the width, moving the right edge.
4378 zero means adjust the height, moving the bottom edge.
4380 Following siblings of the selected window are resized to fulfill
4381 the size request. If they become too small in the process, they
4382 are not deleted; instead, we signal an error. */
4385 adjust_window_trailing_edge (Lisp_Object window
, int delta
, int horiz_flag
)
4387 Lisp_Object parent
, child
;
4389 Lisp_Object old_config
= Fcurrent_window_configuration (Qnil
);
4390 int delcount
= window_deletion_count
;
4392 CHECK_WINDOW (window
);
4394 /* Give up if this window cannot be resized. */
4395 if (window_fixed_size_p (XWINDOW (window
), horiz_flag
, 1))
4396 error ("Window is not resizable");
4400 Lisp_Object first_parallel
= Qnil
;
4404 /* This happens if WINDOW on the previous iteration was
4405 at top level of the window tree. */
4406 Fset_window_configuration (old_config
);
4407 error ("Specified window edge is fixed");
4410 p
= XWINDOW (window
);
4413 /* See if this level has windows in parallel in the specified
4414 direction. If so, set FIRST_PARALLEL to the first one. */
4417 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->vchild
))
4418 first_parallel
= XWINDOW (parent
)->vchild
;
4419 else if (NILP (parent
) && !NILP (p
->next
))
4421 /* Handle the vertical chain of main window and minibuffer
4422 which has no parent. */
4423 first_parallel
= window
;
4424 while (! NILP (XWINDOW (first_parallel
)->prev
))
4425 first_parallel
= XWINDOW (first_parallel
)->prev
;
4430 if (! NILP (parent
) && !NILP (XWINDOW (parent
)->hchild
))
4431 first_parallel
= XWINDOW (parent
)->hchild
;
4434 /* If this level's succession is in the desired dimension,
4435 and this window is the last one, and there is no higher level,
4436 its trailing edge is fixed. */
4437 if (NILP (XWINDOW (window
)->next
) && NILP (first_parallel
)
4440 Fset_window_configuration (old_config
);
4441 error ("Specified window edge is fixed");
4444 /* Don't make this window too small. */
4445 if (XINT (CURSIZE (window
)) + delta
4446 < window_min_size_2 (XWINDOW (window
), horiz_flag
, 0))
4448 Fset_window_configuration (old_config
);
4449 error ("Cannot adjust window size as specified");
4452 /* Clear out some redisplay caches. */
4453 XSETFASTINT (p
->last_modified
, 0);
4454 XSETFASTINT (p
->last_overlay_modified
, 0);
4456 /* Adjust this window's edge. */
4457 XSETINT (CURSIZE (window
),
4458 XINT (CURSIZE (window
)) + delta
);
4460 /* If this window has following siblings in the desired dimension,
4461 make them smaller, and exit the loop.
4463 (If we reach the top of the tree and can never do this,
4464 we will fail and report an error, above.) */
4465 if (NILP (first_parallel
))
4467 if (!NILP (p
->next
))
4469 /* This may happen for the minibuffer. In that case
4470 the window_deletion_count check below does not work. */
4471 if (XINT (CURSIZE (p
->next
)) - delta
<= 0)
4473 Fset_window_configuration (old_config
);
4474 error ("Cannot adjust window size as specified");
4477 XSETINT (CURBEG (p
->next
),
4478 XINT (CURBEG (p
->next
)) + delta
);
4479 size_window (p
->next
, XINT (CURSIZE (p
->next
)) - delta
,
4480 horiz_flag
, 0, 1, 0);
4485 /* Here we have a chain of parallel siblings, in the other dimension.
4486 Change the size of the other siblings. */
4487 for (child
= first_parallel
;
4489 child
= XWINDOW (child
)->next
)
4490 if (! EQ (child
, window
))
4491 size_window (child
, XINT (CURSIZE (child
)) + delta
,
4492 horiz_flag
, 0, 0, 1);
4497 /* If we made a window so small it got deleted,
4498 we failed. Report failure. */
4499 if (delcount
!= window_deletion_count
)
4501 Fset_window_configuration (old_config
);
4502 error ("Cannot adjust window size as specified");
4505 /* Adjust glyph matrices. */
4506 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4512 DEFUN ("adjust-window-trailing-edge", Fadjust_window_trailing_edge
,
4513 Sadjust_window_trailing_edge
, 3, 3, 0,
4514 doc
: /* Adjust the bottom or right edge of WINDOW by DELTA.
4515 If HORIZONTAL is non-nil, that means adjust the width, moving the right edge.
4516 Otherwise, adjust the height, moving the bottom edge.
4518 Following siblings of the selected window are resized to fulfill
4519 the size request. If they become too small in the process, they
4520 are not deleted; instead, we signal an error. */)
4521 (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
)
4523 CHECK_NUMBER (delta
);
4525 window
= selected_window
;
4526 adjust_window_trailing_edge (window
, XINT (delta
), !NILP (horizontal
));
4528 run_window_configuration_change_hook
4529 (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
4536 /***********************************************************************
4537 Resizing Mini-Windows
4538 ***********************************************************************/
4540 static void shrink_window_lowest_first (struct window
*, int);
4542 enum save_restore_action
4549 static int save_restore_orig_size (struct window
*,
4550 enum save_restore_action
);
4552 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
4553 from lowest windows first. */
4556 shrink_window_lowest_first (struct window
*w
, int height
)
4562 xassert (!MINI_WINDOW_P (w
));
4564 /* Set redisplay hints. */
4565 XSETFASTINT (w
->last_modified
, 0);
4566 XSETFASTINT (w
->last_overlay_modified
, 0);
4567 windows_or_buffers_changed
++;
4568 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
4570 old_height
= XFASTINT (w
->total_lines
);
4571 XSETFASTINT (w
->total_lines
, height
);
4573 if (!NILP (w
->hchild
))
4575 for (child
= w
->hchild
; !NILP (child
); child
= c
->next
)
4577 c
= XWINDOW (child
);
4578 c
->top_line
= w
->top_line
;
4579 shrink_window_lowest_first (c
, height
);
4582 else if (!NILP (w
->vchild
))
4584 Lisp_Object last_child
;
4585 int delta
= old_height
- height
;
4590 /* Find the last child. We are taking space from lowest windows
4591 first, so we iterate over children from the last child
4593 for (child
= w
->vchild
; WINDOWP (child
); child
= XWINDOW (child
)->next
)
4596 /* Size children down to their safe heights. */
4597 for (child
= last_child
; delta
&& !NILP (child
); child
= c
->prev
)
4601 c
= XWINDOW (child
);
4602 this_one
= XFASTINT (c
->total_lines
) - window_min_size_1 (c
, 0, 1);
4604 if (this_one
> delta
)
4607 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
) - this_one
);
4611 /* Compute new positions. */
4612 last_top
= XINT (w
->top_line
);
4613 for (child
= w
->vchild
; !NILP (child
); child
= c
->next
)
4615 c
= XWINDOW (child
);
4616 c
->top_line
= make_number (last_top
);
4617 shrink_window_lowest_first (c
, XFASTINT (c
->total_lines
));
4618 last_top
+= XFASTINT (c
->total_lines
);
4624 /* Save, restore, or check positions and sizes in the window tree
4625 rooted at W. ACTION says what to do.
4627 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
4628 orig_total_lines members are valid for all windows in the window
4629 tree. Value is non-zero if they are valid.
4631 If ACTION is SAVE_ORIG_SIZES, save members top and height in
4632 orig_top_line and orig_total_lines for all windows in the tree.
4634 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
4635 stored in orig_top_line and orig_total_lines for all windows. */
4638 save_restore_orig_size (struct window
*w
, enum save_restore_action action
)
4644 if (!NILP (w
->hchild
))
4646 if (!save_restore_orig_size (XWINDOW (w
->hchild
), action
))
4649 else if (!NILP (w
->vchild
))
4651 if (!save_restore_orig_size (XWINDOW (w
->vchild
), action
))
4657 case CHECK_ORIG_SIZES
:
4658 if (!INTEGERP (w
->orig_top_line
) || !INTEGERP (w
->orig_total_lines
))
4662 case SAVE_ORIG_SIZES
:
4663 w
->orig_top_line
= w
->top_line
;
4664 w
->orig_total_lines
= w
->total_lines
;
4665 XSETFASTINT (w
->last_modified
, 0);
4666 XSETFASTINT (w
->last_overlay_modified
, 0);
4669 case RESTORE_ORIG_SIZES
:
4670 xassert (INTEGERP (w
->orig_top_line
) && INTEGERP (w
->orig_total_lines
));
4671 w
->top_line
= w
->orig_top_line
;
4672 w
->total_lines
= w
->orig_total_lines
;
4673 w
->orig_total_lines
= w
->orig_top_line
= Qnil
;
4674 XSETFASTINT (w
->last_modified
, 0);
4675 XSETFASTINT (w
->last_overlay_modified
, 0);
4682 w
= NILP (w
->next
) ? NULL
: XWINDOW (w
->next
);
4689 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4690 without deleting other windows. */
4693 grow_mini_window (struct window
*w
, int delta
)
4695 struct frame
*f
= XFRAME (w
->frame
);
4696 struct window
*root
;
4698 xassert (MINI_WINDOW_P (w
));
4699 /* Commenting out the following assertion goes against the stated interface
4700 of the function, but it currently does not seem to do anything useful.
4701 See discussion of this issue in the thread for bug#4534.
4702 xassert (delta >= 0); */
4704 /* Compute how much we can enlarge the mini-window without deleting
4706 root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4709 int min_height
= window_min_size (root
, 0, 0, 0, 0);
4710 if (XFASTINT (root
->total_lines
) - delta
< min_height
)
4711 /* Note that the root window may already be smaller than
4713 delta
= max (0, XFASTINT (root
->total_lines
) - min_height
);
4718 /* Save original window sizes and positions, if not already done. */
4719 if (!save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4720 save_restore_orig_size (root
, SAVE_ORIG_SIZES
);
4722 /* Shrink other windows. */
4723 shrink_window_lowest_first (root
, XFASTINT (root
->total_lines
) - delta
);
4725 /* Grow the mini-window. */
4726 w
->top_line
= make_number (XFASTINT (root
->top_line
) + XFASTINT (root
->total_lines
));
4727 w
->total_lines
= make_number (XFASTINT (w
->total_lines
) + delta
);
4728 XSETFASTINT (w
->last_modified
, 0);
4729 XSETFASTINT (w
->last_overlay_modified
, 0);
4736 /* Shrink mini-window W. If there is recorded info about window sizes
4737 before a call to grow_mini_window, restore recorded window sizes.
4738 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4742 shrink_mini_window (struct window
*w
)
4744 struct frame
*f
= XFRAME (w
->frame
);
4745 struct window
*root
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4747 if (save_restore_orig_size (root
, CHECK_ORIG_SIZES
))
4749 save_restore_orig_size (root
, RESTORE_ORIG_SIZES
);
4751 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4752 windows_or_buffers_changed
= 1;
4754 else if (XFASTINT (w
->total_lines
) > 1)
4756 /* Distribute the additional lines of the mini-window
4757 among the other windows. */
4759 XSETWINDOW (window
, w
);
4760 enlarge_window (window
, 1 - XFASTINT (w
->total_lines
), 0);
4766 /* Mark window cursors off for all windows in the window tree rooted
4767 at W by setting their phys_cursor_on_p flag to zero. Called from
4768 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4769 the frame are cleared. */
4772 mark_window_cursors_off (struct window
*w
)
4776 if (!NILP (w
->hchild
))
4777 mark_window_cursors_off (XWINDOW (w
->hchild
));
4778 else if (!NILP (w
->vchild
))
4779 mark_window_cursors_off (XWINDOW (w
->vchild
));
4781 w
->phys_cursor_on_p
= 0;
4783 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4788 /* Return number of lines of text (not counting mode lines) in W. */
4791 window_internal_height (struct window
*w
)
4793 int ht
= XFASTINT (w
->total_lines
);
4795 if (!MINI_WINDOW_P (w
))
4797 if (!NILP (w
->parent
)
4798 || !NILP (w
->vchild
)
4799 || !NILP (w
->hchild
)
4802 || WINDOW_WANTS_MODELINE_P (w
))
4805 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4813 /* Return the number of columns in W.
4814 Don't count columns occupied by scroll bars or the vertical bar
4815 separating W from the sibling to its right. */
4818 window_box_text_cols (struct window
*w
)
4820 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
4821 int width
= XINT (w
->total_cols
);
4823 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
4824 /* Scroll bars occupy a few columns. */
4825 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
4826 else if (!FRAME_WINDOW_P (f
)
4827 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
4828 /* The column of `|' characters separating side-by-side windows
4829 occupies one column only. */
4832 if (FRAME_WINDOW_P (f
))
4833 /* On window-systems, fringes and display margins cannot be
4834 used for normal text. */
4835 width
-= (WINDOW_FRINGE_COLS (w
)
4836 + WINDOW_LEFT_MARGIN_COLS (w
)
4837 + WINDOW_RIGHT_MARGIN_COLS (w
));
4843 /************************************************************************
4845 ***********************************************************************/
4847 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4848 N screen-fulls, which is defined as the height of the window minus
4849 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4850 instead. Negative values of N mean scroll down. NOERROR non-zero
4851 means don't signal an error if we try to move over BEGV or ZV,
4855 window_scroll (Lisp_Object window
, int n
, int whole
, int noerror
)
4859 /* If we must, use the pixel-based version which is much slower than
4860 the line-based one but can handle varying line heights. */
4861 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4862 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4864 window_scroll_line_based (window
, n
, whole
, noerror
);
4870 /* Implementation of window_scroll that works based on pixel line
4871 heights. See the comment of window_scroll for parameter
4875 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4878 struct window
*w
= XWINDOW (window
);
4879 struct text_pos start
;
4880 int this_scroll_margin
;
4881 /* True if we fiddled the window vscroll field without really scrolling. */
4883 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4885 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4887 /* If PT is not visible in WINDOW, move back one half of
4888 the screen. Allow PT to be partially visible, otherwise
4889 something like (scroll-down 1) with PT in the line before
4890 the partially visible one would recenter. */
4892 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4894 /* Move backward half the height of the window. Performance note:
4895 vmotion used here is about 10% faster, but would give wrong
4896 results for variable height lines. */
4897 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4898 it
.current_y
= it
.last_visible_y
;
4899 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4901 /* The function move_iterator_vertically may move over more than
4902 the specified y-distance. If it->w is small, e.g. a
4903 mini-buffer window, we may end up in front of the window's
4904 display area. This is the case when Start displaying at the
4905 start of the line containing PT in this case. */
4906 if (it
.current_y
<= 0)
4908 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4909 move_it_vertically_backward (&it
, 0);
4913 start
= it
.current
.pos
;
4915 else if (auto_window_vscroll_p
)
4917 if (rtop
|| rbot
) /* partially visible */
4920 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4922 dy
= max ((window_box_height (w
)
4923 - next_screen_context_lines
* dy
),
4929 /* Only vscroll backwards if already vscrolled forwards. */
4930 if (w
->vscroll
< 0 && rtop
> 0)
4932 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4933 Fset_window_vscroll (window
, make_number (px
), Qt
);
4939 /* Do vscroll if already vscrolled or only display line. */
4940 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4942 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4943 Fset_window_vscroll (window
, make_number (px
), Qt
);
4947 /* Maybe modify window start instead of scrolling. */
4948 if (rbot
> 0 || w
->vscroll
< 0)
4952 Fset_window_vscroll (window
, make_number (0), Qt
);
4953 /* If there are other text lines above the current row,
4954 move window start to current row. Else to next row. */
4956 spos
= XINT (Fline_beginning_position (Qnil
));
4958 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4959 set_marker_restricted (w
->start
, make_number (spos
),
4961 w
->start_at_line_beg
= Qt
;
4962 w
->update_mode_line
= Qt
;
4963 XSETFASTINT (w
->last_modified
, 0);
4964 XSETFASTINT (w
->last_overlay_modified
, 0);
4965 /* Set force_start so that redisplay_window will run the
4966 window-scroll-functions. */
4967 w
->force_start
= Qt
;
4972 /* Cancel previous vscroll. */
4973 Fset_window_vscroll (window
, make_number (0), Qt
);
4976 /* If scroll_preserve_screen_position is non-nil, we try to set
4977 point in the same window line as it is now, so get that line. */
4978 if (!NILP (Vscroll_preserve_screen_position
))
4980 /* We preserve the goal pixel coordinate across consecutive
4981 calls to scroll-up, scroll-down and other commands that
4982 have the `scroll-command' property. This avoids the
4983 possibility of point becoming "stuck" on a tall line when
4984 scrolling by one line. */
4985 if (window_scroll_pixel_based_preserve_y
< 0
4986 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
4987 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
4989 start_display (&it
, w
, start
);
4990 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4991 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4992 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4996 window_scroll_pixel_based_preserve_y
4997 = window_scroll_pixel_based_preserve_x
= -1;
4999 /* Move iterator it from start the specified distance forward or
5000 backward. The result is the new window start. */
5001 start_display (&it
, w
, start
);
5004 EMACS_INT start_pos
= IT_CHARPOS (it
);
5005 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
5006 dy
= max ((window_box_height (w
)
5007 - next_screen_context_lines
* dy
),
5010 /* Note that move_it_vertically always moves the iterator to the
5011 start of a line. So, if the last line doesn't have a newline,
5012 we would end up at the start of the line ending at ZV. */
5015 move_it_vertically_backward (&it
, -dy
);
5016 /* Ensure we actually do move, e.g. in case we are currently
5017 looking at an image that is taller that the window height. */
5018 while (start_pos
== IT_CHARPOS (it
)
5019 && start_pos
> BEGV
)
5020 move_it_by_lines (&it
, -1);
5024 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
5025 MOVE_TO_POS
| MOVE_TO_Y
);
5026 /* Ensure we actually do move, e.g. in case we are currently
5027 looking at an image that is taller that the window height. */
5028 while (start_pos
== IT_CHARPOS (it
)
5030 move_it_by_lines (&it
, 1);
5034 move_it_by_lines (&it
, n
);
5036 /* We failed if we find ZV is already on the screen (scrolling up,
5037 means there's nothing past the end), or if we can't start any
5038 earlier (scrolling down, means there's nothing past the top). */
5039 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
5040 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
5042 if (IT_CHARPOS (it
) == ZV
)
5044 if (it
.current_y
< it
.last_visible_y
5045 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
5046 > it
.last_visible_y
))
5048 /* The last line was only partially visible, make it fully
5050 w
->vscroll
= (it
.last_visible_y
5051 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
5052 adjust_glyphs (it
.f
);
5056 else if (n
< 0) /* could happen with empty buffers */
5057 xsignal0 (Qbeginning_of_buffer
);
5059 xsignal0 (Qend_of_buffer
);
5063 if (w
->vscroll
!= 0)
5064 /* The first line was only partially visible, make it fully
5070 xsignal0 (Qbeginning_of_buffer
);
5073 /* If control gets here, then we vscrolled. */
5075 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
5077 /* Don't try to change the window start below. */
5083 EMACS_INT pos
= IT_CHARPOS (it
);
5086 /* If in the middle of a multi-glyph character move forward to
5087 the next character. */
5088 if (in_display_vector_p (&it
))
5091 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
5094 /* Set the window start, and set up the window for redisplay. */
5095 set_marker_restricted (w
->start
, make_number (pos
),
5097 bytepos
= XMARKER (w
->start
)->bytepos
;
5098 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
5100 w
->update_mode_line
= Qt
;
5101 XSETFASTINT (w
->last_modified
, 0);
5102 XSETFASTINT (w
->last_overlay_modified
, 0);
5103 /* Set force_start so that redisplay_window will run the
5104 window-scroll-functions. */
5105 w
->force_start
= Qt
;
5108 /* The rest of this function uses current_y in a nonstandard way,
5109 not including the height of the header line if any. */
5110 it
.current_y
= it
.vpos
= 0;
5112 /* Move PT out of scroll margins.
5113 This code wants current_y to be zero at the window start position
5114 even if there is a header line. */
5115 this_scroll_margin
= max (0, scroll_margin
);
5116 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
5117 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
5121 /* We moved the window start towards ZV, so PT may be now
5122 in the scroll margin at the top. */
5123 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
5124 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
5125 && (NILP (Vscroll_preserve_screen_position
)
5126 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5127 /* We found PT at a legitimate height. Leave it alone. */
5129 else if (window_scroll_pixel_based_preserve_y
>= 0)
5131 /* If we have a header line, take account of it.
5132 This is necessary because we set it.current_y to 0, above. */
5133 move_it_to (&it
, -1,
5134 window_scroll_pixel_based_preserve_x
,
5135 window_scroll_pixel_based_preserve_y
5136 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
5137 -1, MOVE_TO_Y
| MOVE_TO_X
);
5138 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5142 while (it
.current_y
< this_scroll_margin
)
5144 int prev
= it
.current_y
;
5145 move_it_by_lines (&it
, 1);
5146 if (prev
== it
.current_y
)
5149 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5154 EMACS_INT charpos
, bytepos
;
5157 /* Save our position, for the
5158 window_scroll_pixel_based_preserve_y case. */
5159 charpos
= IT_CHARPOS (it
);
5160 bytepos
= IT_BYTEPOS (it
);
5162 /* We moved the window start towards BEGV, so PT may be now
5163 in the scroll margin at the bottom. */
5164 move_it_to (&it
, PT
, -1,
5165 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
5166 - this_scroll_margin
- 1),
5168 MOVE_TO_POS
| MOVE_TO_Y
);
5170 /* Save our position, in case it's correct. */
5171 charpos
= IT_CHARPOS (it
);
5172 bytepos
= IT_BYTEPOS (it
);
5174 /* See if point is on a partially visible line at the end. */
5175 if (it
.what
== IT_EOB
)
5176 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
5179 move_it_by_lines (&it
, 1);
5180 partial_p
= it
.current_y
> it
.last_visible_y
;
5183 if (charpos
== PT
&& !partial_p
5184 && (NILP (Vscroll_preserve_screen_position
)
5185 || EQ (Vscroll_preserve_screen_position
, Qt
)))
5186 /* We found PT before we found the display margin, so PT is ok. */
5188 else if (window_scroll_pixel_based_preserve_y
>= 0)
5190 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5191 start_display (&it
, w
, start
);
5192 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5193 here because we called start_display again and did not
5194 alter it.current_y this time. */
5195 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
5196 window_scroll_pixel_based_preserve_y
, -1,
5197 MOVE_TO_Y
| MOVE_TO_X
);
5198 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5203 /* The last line was only partially visible, so back up two
5204 lines to make sure we're on a fully visible line. */
5206 move_it_by_lines (&it
, -2);
5207 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
5210 /* No, the position we saved is OK, so use it. */
5211 SET_PT_BOTH (charpos
, bytepos
);
5217 /* Implementation of window_scroll that works based on screen lines.
5218 See the comment of window_scroll for parameter descriptions. */
5221 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
5223 register struct window
*w
= XWINDOW (window
);
5224 /* Fvertical_motion enters redisplay, which can trigger
5225 fontification, which in turn can modify buffer text (e.g., if the
5226 fontification functions replace escape sequences with faces, as
5227 in `grep-mode-font-lock-keywords'). So we use a marker to record
5228 the old point position, to prevent crashes in SET_PT_BOTH. */
5229 Lisp_Object opoint_marker
= Fpoint_marker ();
5230 register EMACS_INT pos
, pos_byte
;
5231 register int ht
= window_internal_height (w
);
5232 register Lisp_Object tem
;
5236 Lisp_Object original_pos
= Qnil
;
5238 /* If scrolling screen-fulls, compute the number of lines to
5239 scroll from the window's height. */
5241 n
*= max (1, ht
- next_screen_context_lines
);
5243 startpos
= marker_position (w
->start
);
5245 if (!NILP (Vscroll_preserve_screen_position
))
5247 if (window_scroll_preserve_vpos
<= 0
5248 || !SYMBOLP (KVAR (current_kboard
, Vlast_command
))
5249 || NILP (Fget (KVAR (current_kboard
, Vlast_command
), Qscroll_command
)))
5251 struct position posit
5252 = *compute_motion (startpos
, 0, 0, 0,
5254 -1, XINT (w
->hscroll
),
5256 window_scroll_preserve_vpos
= posit
.vpos
;
5257 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
5260 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
5261 make_number (window_scroll_preserve_vpos
));
5264 XSETFASTINT (tem
, PT
);
5265 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
5269 Fvertical_motion (make_number (- (ht
/ 2)), window
);
5274 lose
= n
< 0 && PT
== BEGV
;
5275 Fvertical_motion (make_number (n
), window
);
5279 SET_PT_BOTH (marker_position (opoint_marker
),
5280 marker_byte_position (opoint_marker
));
5287 xsignal0 (Qbeginning_of_buffer
);
5292 int this_scroll_margin
= scroll_margin
;
5294 /* Don't use a scroll margin that is negative or too large. */
5295 if (this_scroll_margin
< 0)
5296 this_scroll_margin
= 0;
5298 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
5299 this_scroll_margin
= XINT (w
->total_lines
) / 4;
5301 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
5302 w
->start_at_line_beg
= bolp
;
5303 w
->update_mode_line
= Qt
;
5304 XSETFASTINT (w
->last_modified
, 0);
5305 XSETFASTINT (w
->last_overlay_modified
, 0);
5306 /* Set force_start so that redisplay_window will run
5307 the window-scroll-functions. */
5308 w
->force_start
= Qt
;
5310 if (!NILP (Vscroll_preserve_screen_position
)
5311 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
5313 SET_PT_BOTH (pos
, pos_byte
);
5314 Fvertical_motion (original_pos
, window
);
5316 /* If we scrolled forward, put point enough lines down
5317 that it is outside the scroll margin. */
5322 if (this_scroll_margin
> 0)
5324 SET_PT_BOTH (pos
, pos_byte
);
5325 Fvertical_motion (make_number (this_scroll_margin
), window
);
5331 if (top_margin
<= marker_position (opoint_marker
))
5332 SET_PT_BOTH (marker_position (opoint_marker
),
5333 marker_byte_position (opoint_marker
));
5334 else if (!NILP (Vscroll_preserve_screen_position
))
5336 SET_PT_BOTH (pos
, pos_byte
);
5337 Fvertical_motion (original_pos
, window
);
5340 SET_PT (top_margin
);
5346 /* If we scrolled backward, put point near the end of the window
5347 but not within the scroll margin. */
5348 SET_PT_BOTH (pos
, pos_byte
);
5349 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
5350 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
5353 bottom_margin
= PT
+ 1;
5355 if (bottom_margin
> marker_position (opoint_marker
))
5356 SET_PT_BOTH (marker_position (opoint_marker
),
5357 marker_byte_position (opoint_marker
));
5360 if (!NILP (Vscroll_preserve_screen_position
))
5362 SET_PT_BOTH (pos
, pos_byte
);
5363 Fvertical_motion (original_pos
, window
);
5366 Fvertical_motion (make_number (-1), window
);
5375 xsignal0 (Qend_of_buffer
);
5380 /* Scroll selected_window up or down. If N is nil, scroll a
5381 screen-full which is defined as the height of the window minus
5382 next_screen_context_lines. If N is the symbol `-', scroll.
5383 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
5384 up. This is the guts of Fscroll_up and Fscroll_down. */
5387 scroll_command (Lisp_Object n
, int direction
)
5389 int count
= SPECPDL_INDEX ();
5391 xassert (eabs (direction
) == 1);
5393 /* If selected window's buffer isn't current, make it current for
5394 the moment. But don't screw up if window_scroll gets an error. */
5395 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
5397 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5398 Fset_buffer (XWINDOW (selected_window
)->buffer
);
5400 /* Make redisplay consider other windows than just selected_window. */
5401 ++windows_or_buffers_changed
;
5405 window_scroll (selected_window
, direction
, 1, 0);
5406 else if (EQ (n
, Qminus
))
5407 window_scroll (selected_window
, -direction
, 1, 0);
5410 n
= Fprefix_numeric_value (n
);
5411 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
5414 unbind_to (count
, Qnil
);
5417 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
5418 doc
: /* Scroll text of selected window upward ARG lines.
5419 If ARG is omitted or nil, scroll upward by a near full screen.
5420 A near full screen is `next-screen-context-lines' less than a full screen.
5421 Negative ARG means scroll downward.
5422 If ARG is the atom `-', scroll downward by nearly full screen.
5423 When calling from a program, supply as argument a number, nil, or `-'. */)
5426 scroll_command (arg
, 1);
5430 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
5431 doc
: /* Scroll text of selected window down ARG lines.
5432 If ARG is omitted or nil, scroll down by a near full screen.
5433 A near full screen is `next-screen-context-lines' less than a full screen.
5434 Negative ARG means scroll upward.
5435 If ARG is the atom `-', scroll upward by nearly full screen.
5436 When calling from a program, supply as argument a number, nil, or `-'. */)
5439 scroll_command (arg
, -1);
5443 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
5444 doc
: /* Return the other window for \"other window scroll\" commands.
5445 If `other-window-scroll-buffer' is non-nil, a window
5446 showing that buffer is used.
5447 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5448 specifies the window. This takes precedence over
5449 `other-window-scroll-buffer'. */)
5454 if (MINI_WINDOW_P (XWINDOW (selected_window
))
5455 && !NILP (Vminibuf_scroll_window
))
5456 window
= Vminibuf_scroll_window
;
5457 /* If buffer is specified, scroll that buffer. */
5458 else if (!NILP (Vother_window_scroll_buffer
))
5460 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
5462 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
5466 /* Nothing specified; look for a neighboring window on the same
5468 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
5470 if (EQ (window
, selected_window
))
5471 /* That didn't get us anywhere; look for a window on another
5474 window
= Fnext_window (window
, Qnil
, Qt
);
5475 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
5476 && ! EQ (window
, selected_window
));
5479 CHECK_LIVE_WINDOW (window
);
5481 if (EQ (window
, selected_window
))
5482 error ("There is no other window");
5487 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
5488 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
5489 A near full screen is `next-screen-context-lines' less than a full screen.
5490 The next window is the one below the current one; or the one at the top
5491 if the current one is at the bottom. Negative ARG means scroll downward.
5492 If ARG is the atom `-', scroll downward by nearly full screen.
5493 When calling from a program, supply as argument a number, nil, or `-'.
5495 If `other-window-scroll-buffer' is non-nil, scroll the window
5496 showing that buffer, popping the buffer up if necessary.
5497 If in the minibuffer, `minibuffer-scroll-window' if non-nil
5498 specifies the window to scroll. This takes precedence over
5499 `other-window-scroll-buffer'. */)
5504 int count
= SPECPDL_INDEX ();
5506 window
= Fother_window_for_scrolling ();
5507 w
= XWINDOW (window
);
5509 /* Don't screw up if window_scroll gets an error. */
5510 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
5511 ++windows_or_buffers_changed
;
5513 Fset_buffer (w
->buffer
);
5514 SET_PT (marker_position (w
->pointm
));
5517 window_scroll (window
, 1, 1, 1);
5518 else if (EQ (arg
, Qminus
))
5519 window_scroll (window
, -1, 1, 1);
5525 window_scroll (window
, XINT (arg
), 0, 1);
5528 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
5529 unbind_to (count
, Qnil
);
5534 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
5535 doc
: /* Scroll selected window display ARG columns left.
5536 Default for ARG is window width minus 2.
5537 Value is the total amount of leftward horizontal scrolling in
5538 effect after the change.
5539 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5540 lower bound for automatic scrolling, i.e. automatic scrolling
5541 will not scroll a window to a column less than the value returned
5542 by this function. This happens in an interactive call. */)
5543 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5547 struct window
*w
= XWINDOW (selected_window
);
5550 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5552 arg
= Fprefix_numeric_value (arg
);
5554 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
5555 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5557 if (!NILP (set_minimum
))
5558 w
->min_hscroll
= w
->hscroll
;
5563 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
5564 doc
: /* Scroll selected window display ARG columns right.
5565 Default for ARG is window width minus 2.
5566 Value is the total amount of leftward horizontal scrolling in
5567 effect after the change.
5568 If SET-MINIMUM is non-nil, the new scroll amount becomes the
5569 lower bound for automatic scrolling, i.e. automatic scrolling
5570 will not scroll a window to a column less than the value returned
5571 by this function. This happens in an interactive call. */)
5572 (register Lisp_Object arg
, Lisp_Object set_minimum
)
5576 struct window
*w
= XWINDOW (selected_window
);
5579 XSETFASTINT (arg
, window_box_text_cols (w
) - 2);
5581 arg
= Fprefix_numeric_value (arg
);
5583 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
5584 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
5586 if (!NILP (set_minimum
))
5587 w
->min_hscroll
= w
->hscroll
;
5592 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
5593 doc
: /* Return the window which was selected when entering the minibuffer.
5594 Returns nil, if selected window is not a minibuffer window. */)
5597 if (minibuf_level
> 0
5598 && MINI_WINDOW_P (XWINDOW (selected_window
))
5599 && WINDOW_LIVE_P (minibuf_selected_window
))
5600 return minibuf_selected_window
;
5605 /* Value is the number of lines actually displayed in window W,
5606 as opposed to its height. */
5609 displayed_window_lines (struct window
*w
)
5612 struct text_pos start
;
5613 int height
= window_box_height (w
);
5614 struct buffer
*old_buffer
;
5617 if (XBUFFER (w
->buffer
) != current_buffer
)
5619 old_buffer
= current_buffer
;
5620 set_buffer_internal (XBUFFER (w
->buffer
));
5625 /* In case W->start is out of the accessible range, do something
5626 reasonable. This happens in Info mode when Info-scroll-down
5627 calls (recenter -1) while W->start is 1. */
5628 if (XMARKER (w
->start
)->charpos
< BEGV
)
5629 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
5630 else if (XMARKER (w
->start
)->charpos
> ZV
)
5631 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
5633 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
5635 start_display (&it
, w
, start
);
5636 move_it_vertically (&it
, height
);
5637 bottom_y
= line_bottom_y (&it
);
5639 /* rms: On a non-window display,
5640 the value of it.vpos at the bottom of the screen
5641 seems to be 1 larger than window_box_height (w).
5642 This kludge fixes a bug whereby (move-to-window-line -1)
5643 when ZV is on the last screen line
5644 moves to the previous screen line instead of the last one. */
5645 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5648 /* Add in empty lines at the bottom of the window. */
5649 if (bottom_y
< height
)
5651 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5652 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5656 set_buffer_internal (old_buffer
);
5662 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5663 doc
: /* Center point in selected window and maybe redisplay frame.
5664 With prefix argument ARG, recenter putting point on screen line ARG
5665 relative to the selected window. If ARG is negative, it counts up from the
5666 bottom of the window. (ARG should be less than the height of the window.)
5668 If ARG is omitted or nil, then recenter with point on the middle line of
5669 the selected window; if the variable `recenter-redisplay' is non-nil,
5670 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5671 is set to `grow-only', this resets the tool-bar's height to the minimum
5672 height needed); if `recenter-redisplay' has the special value `tty',
5673 then only tty frame are redrawn.
5675 Just C-u as prefix means put point in the center of the window
5676 and redisplay normally--don't erase and redraw the frame. */)
5677 (register Lisp_Object arg
)
5679 struct window
*w
= XWINDOW (selected_window
);
5680 struct buffer
*buf
= XBUFFER (w
->buffer
);
5681 struct buffer
*obuf
= current_buffer
;
5683 EMACS_INT charpos
, bytepos
;
5684 int iarg
IF_LINT (= 0);
5685 int this_scroll_margin
;
5687 /* If redisplay is suppressed due to an error, try again. */
5688 obuf
->display_error_modiff
= 0;
5692 if (!NILP (Vrecenter_redisplay
)
5693 && (!EQ (Vrecenter_redisplay
, Qtty
)
5694 || !NILP (Ftty_type (selected_frame
))))
5698 /* Invalidate pixel data calculated for all compositions. */
5699 for (i
= 0; i
< n_compositions
; i
++)
5700 composition_table
[i
]->font
= NULL
;
5702 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5704 Fredraw_frame (WINDOW_FRAME (w
));
5705 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5710 else if (CONSP (arg
)) /* Just C-u. */
5714 arg
= Fprefix_numeric_value (arg
);
5719 set_buffer_internal (buf
);
5721 /* Do this after making BUF current
5722 in case scroll_margin is buffer-local. */
5723 this_scroll_margin
= max (0, scroll_margin
);
5724 this_scroll_margin
= min (this_scroll_margin
,
5725 XFASTINT (w
->total_lines
) / 4);
5727 /* Handle centering on a graphical frame specially. Such frames can
5728 have variable-height lines and centering point on the basis of
5729 line counts would lead to strange effects. */
5730 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5737 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5738 start_display (&it
, w
, pt
);
5739 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5740 charpos
= IT_CHARPOS (it
);
5741 bytepos
= IT_BYTEPOS (it
);
5748 int extra_line_spacing
;
5749 int h
= window_box_height (w
);
5751 iarg
= - max (-iarg
, this_scroll_margin
);
5753 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5754 start_display (&it
, w
, pt
);
5756 /* Be sure we have the exact height of the full line containing PT. */
5757 move_it_by_lines (&it
, 0);
5759 /* The amount of pixels we have to move back is the window
5760 height minus what's displayed in the line containing PT,
5761 and the lines below. */
5764 move_it_by_lines (&it
, nlines
);
5766 if (it
.vpos
== nlines
)
5770 /* Last line has no newline */
5771 h
-= line_bottom_y (&it
);
5775 /* Don't reserve space for extra line spacing of last line. */
5776 extra_line_spacing
= it
.max_extra_line_spacing
;
5778 /* If we can't move down NLINES lines because we hit
5779 the end of the buffer, count in some empty lines. */
5780 if (it
.vpos
< nlines
)
5783 extra_line_spacing
= it
.extra_line_spacing
;
5784 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5789 /* Now find the new top line (starting position) of the window. */
5790 start_display (&it
, w
, pt
);
5792 move_it_vertically_backward (&it
, h
);
5794 /* If extra line spacing is present, we may move too far
5795 back. This causes the last line to be only partially
5796 visible (which triggers redisplay to recenter that line
5797 in the middle), so move forward.
5798 But ignore extra line spacing on last line, as it is not
5799 considered to be part of the visible height of the line.
5801 h
+= extra_line_spacing
;
5802 while (-it
.current_y
> h
)
5803 move_it_by_lines (&it
, 1);
5805 charpos
= IT_CHARPOS (it
);
5806 bytepos
= IT_BYTEPOS (it
);
5810 struct position pos
;
5812 iarg
= max (iarg
, this_scroll_margin
);
5814 pos
= *vmotion (PT
, -iarg
, w
);
5815 charpos
= pos
.bufpos
;
5816 bytepos
= pos
.bytepos
;
5821 struct position pos
;
5822 int ht
= window_internal_height (w
);
5829 /* Don't let it get into the margin at either top or bottom. */
5830 iarg
= max (iarg
, this_scroll_margin
);
5831 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5833 pos
= *vmotion (PT
, - iarg
, w
);
5834 charpos
= pos
.bufpos
;
5835 bytepos
= pos
.bytepos
;
5838 /* Set the new window start. */
5839 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5840 w
->window_end_valid
= Qnil
;
5842 w
->optional_new_start
= Qt
;
5844 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5845 w
->start_at_line_beg
= Qt
;
5847 w
->start_at_line_beg
= Qnil
;
5849 set_buffer_internal (obuf
);
5854 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5856 doc
: /* Return the height in lines of the text display area of WINDOW.
5857 WINDOW defaults to the selected window.
5859 The return value does not include the mode line, any header line, nor
5860 any partial-height lines in the text display area. */)
5861 (Lisp_Object window
)
5863 struct window
*w
= decode_window (window
);
5864 int pixel_height
= window_box_height (w
);
5865 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5866 return make_number (line_height
);
5871 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5873 doc
: /* Position point relative to window.
5874 With no argument, position point at center of window.
5875 An argument specifies vertical position within the window;
5876 zero means top of window, negative means relative to bottom of window. */)
5879 struct window
*w
= XWINDOW (selected_window
);
5883 int this_scroll_margin
;
5886 if (!(BUFFERP (w
->buffer
)
5887 && XBUFFER (w
->buffer
) == current_buffer
))
5888 /* This test is needed to make sure PT/PT_BYTE make sense in w->buffer
5889 when passed below to set_marker_both. */
5890 error ("move-to-window-line called from unrelated buffer");
5892 window
= selected_window
;
5893 start
= marker_position (w
->start
);
5894 if (start
< BEGV
|| start
> ZV
)
5896 int height
= window_internal_height (w
);
5897 Fvertical_motion (make_number (- (height
/ 2)), window
);
5898 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5899 w
->start_at_line_beg
= Fbolp ();
5900 w
->force_start
= Qt
;
5903 Fgoto_char (w
->start
);
5905 lines
= displayed_window_lines (w
);
5908 this_scroll_margin
= max (0, scroll_margin
);
5909 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5913 XSETFASTINT (arg
, lines
/ 2);
5916 int iarg
= XINT (Fprefix_numeric_value (arg
));
5919 iarg
= iarg
+ lines
;
5921 #if 0 /* This code would prevent move-to-window-line from moving point
5922 to a place inside the scroll margins (which would cause the
5923 next redisplay to scroll). I wrote this code, but then concluded
5924 it is probably better not to install it. However, it is here
5925 inside #if 0 so as not to lose it. -- rms. */
5927 /* Don't let it get into the margin at either top or bottom. */
5928 iarg
= max (iarg
, this_scroll_margin
);
5929 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5932 arg
= make_number (iarg
);
5935 /* Skip past a partially visible first line. */
5937 XSETINT (arg
, XINT (arg
) + 1);
5939 return Fvertical_motion (arg
, window
);
5944 /***********************************************************************
5945 Window Configuration
5946 ***********************************************************************/
5948 struct save_window_data
5950 struct vectorlike_header header
;
5951 Lisp_Object selected_frame
;
5952 Lisp_Object current_window
;
5953 Lisp_Object current_buffer
;
5954 Lisp_Object minibuf_scroll_window
;
5955 Lisp_Object minibuf_selected_window
;
5956 Lisp_Object root_window
;
5957 Lisp_Object focus_frame
;
5958 /* A vector, each of whose elements is a struct saved_window
5960 Lisp_Object saved_windows
;
5962 /* All fields above are traced by the GC.
5963 From `fame-cols' down, the fields are ignored by the GC. */
5965 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5966 int frame_tool_bar_lines
;
5969 /* This is saved as a Lisp_Vector */
5972 struct vectorlike_header header
;
5974 Lisp_Object buffer
, start
, pointm
, mark
;
5975 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5976 Lisp_Object hscroll
, min_hscroll
;
5977 Lisp_Object parent
, prev
;
5978 Lisp_Object start_at_line_beg
;
5979 Lisp_Object display_table
;
5980 Lisp_Object orig_top_line
, orig_total_lines
;
5981 Lisp_Object left_margin_cols
, right_margin_cols
;
5982 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5983 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
;
5984 Lisp_Object dedicated
, resize_proportionally
;
5987 #define SAVED_WINDOW_N(swv,n) \
5988 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5990 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5991 doc
: /* Return t if OBJECT is a window-configuration object. */)
5992 (Lisp_Object object
)
5994 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5997 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5998 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5999 (Lisp_Object config
)
6001 register struct save_window_data
*data
;
6002 struct Lisp_Vector
*saved_windows
;
6004 CHECK_WINDOW_CONFIGURATION (config
);
6006 data
= (struct save_window_data
*) XVECTOR (config
);
6007 saved_windows
= XVECTOR (data
->saved_windows
);
6008 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6011 DEFUN ("set-window-configuration", Fset_window_configuration
,
6012 Sset_window_configuration
, 1, 1, 0,
6013 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
6014 CONFIGURATION must be a value previously returned
6015 by `current-window-configuration' (which see).
6016 If CONFIGURATION was made from a frame that is now deleted,
6017 only frame-independent values can be restored. In this case,
6018 the return value is nil. Otherwise the value is t. */)
6019 (Lisp_Object configuration
)
6021 register struct save_window_data
*data
;
6022 struct Lisp_Vector
*saved_windows
;
6023 Lisp_Object new_current_buffer
;
6026 EMACS_INT old_point
= -1;
6028 CHECK_WINDOW_CONFIGURATION (configuration
);
6030 data
= (struct save_window_data
*) XVECTOR (configuration
);
6031 saved_windows
= XVECTOR (data
->saved_windows
);
6033 new_current_buffer
= data
->current_buffer
;
6034 if (NILP (BVAR (XBUFFER (new_current_buffer
), name
)))
6035 new_current_buffer
= Qnil
;
6038 if (XBUFFER (new_current_buffer
) == current_buffer
)
6039 /* The code further down "preserves point" by saving here PT in
6040 old_point and then setting it later back into PT. When the
6041 current-selected-window and the final-selected-window both show
6042 the current buffer, this suffers from the problem that the
6043 current PT is the window-point of the current-selected-window,
6044 while the final PT is the point of the final-selected-window, so
6045 this copy from one PT to the other would end up moving the
6046 window-point of the final-selected-window to the window-point of
6047 the current-selected-window. So we have to be careful which
6048 point of the current-buffer we copy into old_point. */
6049 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6050 && WINDOWP (selected_window
)
6051 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
6052 && !EQ (selected_window
, data
->current_window
))
6053 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6057 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
6058 point in new_current_buffer as of the last time this buffer was
6059 used. This can be non-deterministic since it can be changed by
6060 things like jit-lock by mere temporary selection of some random
6061 window that happens to show this buffer.
6062 So if possible we want this arbitrary choice of "which point" to
6063 be the one from the to-be-selected-window so as to prevent this
6064 window's cursor from being copied from another window. */
6065 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
6066 /* If current_window = selected_window, its point is in BUF_PT. */
6067 && !EQ (selected_window
, data
->current_window
))
6068 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
6070 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
6073 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
6076 /* If f is a dead frame, don't bother rebuilding its window tree.
6077 However, there is other stuff we should still try to do below. */
6078 if (FRAME_LIVE_P (f
))
6080 register struct window
*w
;
6081 register struct saved_window
*p
;
6082 struct window
*root_window
;
6083 struct window
**leaf_windows
;
6087 /* If the frame has been resized since this window configuration was
6088 made, we change the frame to the size specified in the
6089 configuration, restore the configuration, and then resize it
6090 back. We keep track of the prevailing height in these variables. */
6091 int previous_frame_lines
= FRAME_LINES (f
);
6092 int previous_frame_cols
= FRAME_COLS (f
);
6093 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6094 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6096 /* The mouse highlighting code could get screwed up
6097 if it runs during this. */
6100 if (data
->frame_lines
!= previous_frame_lines
6101 || data
->frame_cols
!= previous_frame_cols
)
6102 change_frame_size (f
, data
->frame_lines
,
6103 data
->frame_cols
, 0, 0, 0);
6104 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6105 if (data
->frame_menu_bar_lines
6106 != previous_frame_menu_bar_lines
)
6107 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
6109 #ifdef HAVE_WINDOW_SYSTEM
6110 if (data
->frame_tool_bar_lines
6111 != previous_frame_tool_bar_lines
)
6112 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
6117 /* "Swap out" point from the selected window's buffer
6118 into the window itself. (Normally the pointm of the selected
6119 window holds garbage.) We do this now, before
6120 restoring the window contents, and prevent it from
6121 being done later on when we select a new window. */
6122 if (! NILP (XWINDOW (selected_window
)->buffer
))
6124 w
= XWINDOW (selected_window
);
6125 set_marker_both (w
->pointm
,
6127 BUF_PT (XBUFFER (w
->buffer
)),
6128 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6131 windows_or_buffers_changed
++;
6132 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
6134 /* Problem: Freeing all matrices and later allocating them again
6135 is a serious redisplay flickering problem. What we would
6136 really like to do is to free only those matrices not reused
6138 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
6140 = (struct window
**) alloca (count_windows (root_window
)
6141 * sizeof (struct window
*));
6142 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
6145 Mark all windows now on frame as "deleted".
6146 Restoring the new configuration "undeletes" any that are in it.
6148 Save their current buffers in their height fields, since we may
6149 need it later, if a buffer saved in the configuration is now
6151 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6153 for (k
= 0; k
< saved_windows
->header
.size
; k
++)
6155 p
= SAVED_WINDOW_N (saved_windows
, k
);
6156 w
= XWINDOW (p
->window
);
6159 if (!NILP (p
->parent
))
6160 w
->parent
= SAVED_WINDOW_N (saved_windows
,
6161 XFASTINT (p
->parent
))->window
;
6165 if (!NILP (p
->prev
))
6167 w
->prev
= SAVED_WINDOW_N (saved_windows
,
6168 XFASTINT (p
->prev
))->window
;
6169 XWINDOW (w
->prev
)->next
= p
->window
;
6174 if (!NILP (w
->parent
))
6176 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
6178 XWINDOW (w
->parent
)->vchild
= p
->window
;
6179 XWINDOW (w
->parent
)->hchild
= Qnil
;
6183 XWINDOW (w
->parent
)->hchild
= p
->window
;
6184 XWINDOW (w
->parent
)->vchild
= Qnil
;
6189 /* If we squirreled away the buffer in the window's height,
6191 if (BUFFERP (w
->total_lines
))
6192 w
->buffer
= w
->total_lines
;
6193 w
->left_col
= p
->left_col
;
6194 w
->top_line
= p
->top_line
;
6195 w
->total_cols
= p
->total_cols
;
6196 w
->total_lines
= p
->total_lines
;
6197 w
->hscroll
= p
->hscroll
;
6198 w
->min_hscroll
= p
->min_hscroll
;
6199 w
->display_table
= p
->display_table
;
6200 w
->orig_top_line
= p
->orig_top_line
;
6201 w
->orig_total_lines
= p
->orig_total_lines
;
6202 w
->left_margin_cols
= p
->left_margin_cols
;
6203 w
->right_margin_cols
= p
->right_margin_cols
;
6204 w
->left_fringe_width
= p
->left_fringe_width
;
6205 w
->right_fringe_width
= p
->right_fringe_width
;
6206 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
6207 w
->scroll_bar_width
= p
->scroll_bar_width
;
6208 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
6209 w
->dedicated
= p
->dedicated
;
6210 w
->resize_proportionally
= p
->resize_proportionally
;
6211 XSETFASTINT (w
->last_modified
, 0);
6212 XSETFASTINT (w
->last_overlay_modified
, 0);
6214 /* Reinstall the saved buffer and pointers into it. */
6215 if (NILP (p
->buffer
))
6216 w
->buffer
= p
->buffer
;
6219 if (!NILP (BVAR (XBUFFER (p
->buffer
), name
)))
6220 /* If saved buffer is alive, install it. */
6222 w
->buffer
= p
->buffer
;
6223 w
->start_at_line_beg
= p
->start_at_line_beg
;
6224 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
6225 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
6226 Fset_marker (BVAR (XBUFFER (w
->buffer
), mark
),
6227 p
->mark
, w
->buffer
);
6229 /* As documented in Fcurrent_window_configuration, don't
6230 restore the location of point in the buffer which was
6231 current when the window configuration was recorded. */
6232 if (!EQ (p
->buffer
, new_current_buffer
)
6233 && XBUFFER (p
->buffer
) == current_buffer
)
6234 Fgoto_char (w
->pointm
);
6236 else if (NILP (w
->buffer
) || NILP (BVAR (XBUFFER (w
->buffer
), name
)))
6237 /* Else unless window has a live buffer, get one. */
6239 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
6240 /* This will set the markers to beginning of visible
6242 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
6243 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
6244 w
->start_at_line_beg
= Qt
;
6247 /* Keeping window's old buffer; make sure the markers
6250 /* Set window markers at start of visible range. */
6251 if (XMARKER (w
->start
)->buffer
== 0)
6252 set_marker_restricted (w
->start
, make_number (0),
6254 if (XMARKER (w
->pointm
)->buffer
== 0)
6255 set_marker_restricted_both (w
->pointm
, w
->buffer
,
6256 BUF_PT (XBUFFER (w
->buffer
)),
6257 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6258 w
->start_at_line_beg
= Qt
;
6263 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
6265 /* Arrange *not* to restore point in the buffer that was
6266 current when the window configuration was saved. */
6267 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
6268 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
6269 make_number (old_point
),
6270 XWINDOW (data
->current_window
)->buffer
);
6272 /* In the following call to `select-window, prevent "swapping
6273 out point" in the old selected window using the buffer that
6274 has been restored into it. We already swapped out that point
6275 from that window's old buffer. */
6276 select_window (data
->current_window
, Qnil
, 1);
6277 BVAR (XBUFFER (XWINDOW (selected_window
)->buffer
), last_selected_window
)
6280 if (NILP (data
->focus_frame
)
6281 || (FRAMEP (data
->focus_frame
)
6282 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
6283 Fredirect_frame_focus (frame
, data
->focus_frame
);
6285 /* Set the screen height to the value it had before this function. */
6286 if (previous_frame_lines
!= FRAME_LINES (f
)
6287 || previous_frame_cols
!= FRAME_COLS (f
))
6288 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
6290 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
6291 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
6292 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
6294 #ifdef HAVE_WINDOW_SYSTEM
6295 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
6296 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
6301 /* Now, free glyph matrices in windows that were not reused. */
6302 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
6304 if (NILP (leaf_windows
[i
]->buffer
))
6306 /* Assert it's not reused as a combination. */
6307 xassert (NILP (leaf_windows
[i
]->hchild
)
6308 && NILP (leaf_windows
[i
]->vchild
));
6309 free_window_matrices (leaf_windows
[i
]);
6311 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
6319 /* Fselect_window will have made f the selected frame, so we
6320 reselect the proper frame here. Fhandle_switch_frame will change the
6321 selected window too, but that doesn't make the call to
6322 Fselect_window above totally superfluous; it still sets f's
6324 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
6325 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
6327 run_window_configuration_change_hook (f
);
6330 if (!NILP (new_current_buffer
))
6331 Fset_buffer (new_current_buffer
);
6333 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
6334 minibuf_selected_window
= data
->minibuf_selected_window
;
6336 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
6339 /* Mark all windows now on frame as deleted
6340 by setting their buffers to nil. */
6343 delete_all_subwindows (register struct window
*w
)
6345 if (!NILP (w
->next
))
6346 delete_all_subwindows (XWINDOW (w
->next
));
6347 if (!NILP (w
->vchild
))
6348 delete_all_subwindows (XWINDOW (w
->vchild
));
6349 if (!NILP (w
->hchild
))
6350 delete_all_subwindows (XWINDOW (w
->hchild
));
6352 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
6354 if (!NILP (w
->buffer
))
6357 /* We set all three of these fields to nil, to make sure that we can
6358 distinguish this dead window from any live window. Live leaf
6359 windows will have buffer set, and combination windows will have
6360 vchild or hchild set. */
6365 Vwindow_list
= Qnil
;
6369 count_windows (register struct window
*window
)
6371 register int count
= 1;
6372 if (!NILP (window
->next
))
6373 count
+= count_windows (XWINDOW (window
->next
));
6374 if (!NILP (window
->vchild
))
6375 count
+= count_windows (XWINDOW (window
->vchild
));
6376 if (!NILP (window
->hchild
))
6377 count
+= count_windows (XWINDOW (window
->hchild
));
6382 /* Fill vector FLAT with leaf windows under W, starting at index I.
6383 Value is last index + 1. */
6386 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
6390 if (!NILP (w
->hchild
))
6391 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
6392 else if (!NILP (w
->vchild
))
6393 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
6397 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6404 /* Return a pointer to the glyph W's physical cursor is on. Value is
6405 null if W's current matrix is invalid, so that no meaningfull glyph
6409 get_phys_cursor_glyph (struct window
*w
)
6411 struct glyph_row
*row
;
6412 struct glyph
*glyph
;
6414 if (w
->phys_cursor
.vpos
>= 0
6415 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
6416 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
6418 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
6419 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
6428 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
6430 register struct saved_window
*p
;
6431 register struct window
*w
;
6432 register Lisp_Object tem
;
6434 for (;!NILP (window
); window
= w
->next
)
6436 p
= SAVED_WINDOW_N (vector
, i
);
6437 w
= XWINDOW (window
);
6439 XSETFASTINT (w
->temslot
, i
); i
++;
6441 p
->buffer
= w
->buffer
;
6442 p
->left_col
= w
->left_col
;
6443 p
->top_line
= w
->top_line
;
6444 p
->total_cols
= w
->total_cols
;
6445 p
->total_lines
= w
->total_lines
;
6446 p
->hscroll
= w
->hscroll
;
6447 p
->min_hscroll
= w
->min_hscroll
;
6448 p
->display_table
= w
->display_table
;
6449 p
->orig_top_line
= w
->orig_top_line
;
6450 p
->orig_total_lines
= w
->orig_total_lines
;
6451 p
->left_margin_cols
= w
->left_margin_cols
;
6452 p
->right_margin_cols
= w
->right_margin_cols
;
6453 p
->left_fringe_width
= w
->left_fringe_width
;
6454 p
->right_fringe_width
= w
->right_fringe_width
;
6455 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
6456 p
->scroll_bar_width
= w
->scroll_bar_width
;
6457 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
6458 p
->dedicated
= w
->dedicated
;
6459 p
->resize_proportionally
= w
->resize_proportionally
;
6460 if (!NILP (w
->buffer
))
6462 /* Save w's value of point in the window configuration.
6463 If w is the selected window, then get the value of point
6464 from the buffer; pointm is garbage in the selected window. */
6465 if (EQ (window
, selected_window
))
6467 p
->pointm
= Fmake_marker ();
6468 set_marker_both (p
->pointm
, w
->buffer
,
6469 BUF_PT (XBUFFER (w
->buffer
)),
6470 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
6473 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
6475 p
->start
= Fcopy_marker (w
->start
, Qnil
);
6476 p
->start_at_line_beg
= w
->start_at_line_beg
;
6478 tem
= BVAR (XBUFFER (w
->buffer
), mark
);
6479 p
->mark
= Fcopy_marker (tem
, Qnil
);
6486 p
->start_at_line_beg
= Qnil
;
6489 if (NILP (w
->parent
))
6492 p
->parent
= XWINDOW (w
->parent
)->temslot
;
6497 p
->prev
= XWINDOW (w
->prev
)->temslot
;
6499 if (!NILP (w
->vchild
))
6500 i
= save_window_save (w
->vchild
, vector
, i
);
6501 if (!NILP (w
->hchild
))
6502 i
= save_window_save (w
->hchild
, vector
, i
);
6508 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
6509 Scurrent_window_configuration
, 0, 1, 0,
6510 doc
: /* Return an object representing the current window configuration of FRAME.
6511 If FRAME is nil or omitted, use the selected frame.
6512 This describes the number of windows, their sizes and current buffers,
6513 and for each displayed buffer, where display starts, and the positions of
6514 point and mark. An exception is made for point in the current buffer:
6515 its value is -not- saved.
6516 This also records the currently selected frame, and FRAME's focus
6517 redirection (see `redirect-frame-focus'). */)
6520 register Lisp_Object tem
;
6521 register int n_windows
;
6522 register struct save_window_data
*data
;
6527 frame
= selected_frame
;
6528 CHECK_LIVE_FRAME (frame
);
6531 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6532 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
6533 PVEC_WINDOW_CONFIGURATION
);
6535 data
->frame_cols
= FRAME_COLS (f
);
6536 data
->frame_lines
= FRAME_LINES (f
);
6537 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
6538 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
6539 data
->selected_frame
= selected_frame
;
6540 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
6541 XSETBUFFER (data
->current_buffer
, current_buffer
);
6542 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
6543 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
6544 data
->root_window
= FRAME_ROOT_WINDOW (f
);
6545 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
6546 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
6547 data
->saved_windows
= tem
;
6548 for (i
= 0; i
< n_windows
; i
++)
6549 XVECTOR (tem
)->contents
[i
]
6550 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
6551 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
6552 XSETWINDOW_CONFIGURATION (tem
, data
);
6557 /***********************************************************************
6559 ***********************************************************************/
6562 window_tree (struct window
*w
)
6564 Lisp_Object tail
= Qnil
;
6565 Lisp_Object result
= Qnil
;
6572 if (!NILP (w
->hchild
))
6573 wn
= Fcons (Qnil
, Fcons (Fwindow_edges (wn
),
6574 window_tree (XWINDOW (w
->hchild
))));
6575 else if (!NILP (w
->vchild
))
6576 wn
= Fcons (Qt
, Fcons (Fwindow_edges (wn
),
6577 window_tree (XWINDOW (w
->vchild
))));
6581 result
= tail
= Fcons (wn
, Qnil
);
6585 XSETCDR (tail
, Fcons (wn
, Qnil
));
6589 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6597 DEFUN ("window-tree", Fwindow_tree
, Swindow_tree
,
6599 doc
: /* Return the window tree for frame FRAME.
6601 The return value is a list of the form (ROOT MINI), where ROOT
6602 represents the window tree of the frame's root window, and MINI
6603 is the frame's minibuffer window.
6605 If the root window is not split, ROOT is the root window itself.
6606 Otherwise, ROOT is a list (DIR EDGES W1 W2 ...) where DIR is nil for a
6607 horizontal split, and t for a vertical split, EDGES gives the combined
6608 size and position of the subwindows in the split, and the rest of the
6609 elements are the subwindows in the split. Each of the subwindows may
6610 again be a window or a list representing a window split, and so on.
6611 EDGES is a list \(LEFT TOP RIGHT BOTTOM) as returned by `window-edges'.
6613 If FRAME is nil or omitted, return information on the currently
6620 frame
= selected_frame
;
6622 CHECK_FRAME (frame
);
6625 if (!FRAME_LIVE_P (f
))
6628 return window_tree (XWINDOW (FRAME_ROOT_WINDOW (f
)));
6632 /***********************************************************************
6634 ***********************************************************************/
6636 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
6638 doc
: /* Set width of marginal areas of window WINDOW.
6639 If WINDOW is nil, set margins of the currently selected window.
6640 Second arg LEFT-WIDTH specifies the number of character cells to
6641 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6642 does the same for the right marginal area. A nil width parameter
6643 means no margin. */)
6644 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
6646 struct window
*w
= decode_window (window
);
6648 /* Translate negative or zero widths to nil.
6649 Margins that are too wide have to be checked elsewhere. */
6651 if (!NILP (left_width
))
6653 CHECK_NUMBER (left_width
);
6654 if (XINT (left_width
) <= 0)
6658 if (!NILP (right_width
))
6660 CHECK_NUMBER (right_width
);
6661 if (XINT (right_width
) <= 0)
6665 if (!EQ (w
->left_margin_cols
, left_width
)
6666 || !EQ (w
->right_margin_cols
, right_width
))
6668 w
->left_margin_cols
= left_width
;
6669 w
->right_margin_cols
= right_width
;
6671 adjust_window_margins (w
);
6673 ++windows_or_buffers_changed
;
6674 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6681 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6683 doc
: /* Get width of marginal areas of window WINDOW.
6684 If WINDOW is omitted or nil, use the currently selected window.
6685 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6686 If a marginal area does not exist, its width will be returned
6688 (Lisp_Object window
)
6690 struct window
*w
= decode_window (window
);
6691 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6696 /***********************************************************************
6698 ***********************************************************************/
6700 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6702 doc
: /* Set the fringe widths of window WINDOW.
6703 If WINDOW is nil, set the fringe widths of the currently selected
6705 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6706 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6707 fringe width. If a fringe width arg is nil, that means to use the
6708 frame's default fringe width. Default fringe widths can be set with
6709 the command `set-fringe-style'.
6710 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6711 outside of the display margins. By default, fringes are drawn between
6712 display marginal areas and the text area. */)
6713 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6715 struct window
*w
= decode_window (window
);
6717 if (!NILP (left_width
))
6718 CHECK_NATNUM (left_width
);
6719 if (!NILP (right_width
))
6720 CHECK_NATNUM (right_width
);
6722 /* Do nothing on a tty. */
6723 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6724 && (!EQ (w
->left_fringe_width
, left_width
)
6725 || !EQ (w
->right_fringe_width
, right_width
)
6726 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6728 w
->left_fringe_width
= left_width
;
6729 w
->right_fringe_width
= right_width
;
6730 w
->fringes_outside_margins
= outside_margins
;
6732 adjust_window_margins (w
);
6734 clear_glyph_matrix (w
->current_matrix
);
6735 w
->window_end_valid
= Qnil
;
6737 ++windows_or_buffers_changed
;
6738 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6745 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6747 doc
: /* Get width of fringes of window WINDOW.
6748 If WINDOW is omitted or nil, use the currently selected window.
6749 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6750 (Lisp_Object window
)
6752 struct window
*w
= decode_window (window
);
6754 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6755 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6756 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6757 ? Qt
: Qnil
), Qnil
)));
6762 /***********************************************************************
6764 ***********************************************************************/
6766 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
,
6767 Sset_window_scroll_bars
, 2, 4, 0,
6768 doc
: /* Set width and type of scroll bars of window WINDOW.
6769 If window is nil, set scroll bars of the currently selected window.
6770 Second parameter WIDTH specifies the pixel width for the scroll bar;
6771 this is automatically adjusted to a multiple of the frame column width.
6772 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6773 bar: left, right, or nil.
6774 If WIDTH is nil, use the frame's scroll-bar width.
6775 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6776 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6777 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6779 struct window
*w
= decode_window (window
);
6783 CHECK_NATNUM (width
);
6785 if (XINT (width
) == 0)
6786 vertical_type
= Qnil
;
6789 if (!(NILP (vertical_type
)
6790 || EQ (vertical_type
, Qleft
)
6791 || EQ (vertical_type
, Qright
)
6792 || EQ (vertical_type
, Qt
)))
6793 error ("Invalid type of vertical scroll bar");
6795 if (!EQ (w
->scroll_bar_width
, width
)
6796 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6798 w
->scroll_bar_width
= width
;
6799 w
->vertical_scroll_bar_type
= vertical_type
;
6801 adjust_window_margins (w
);
6803 clear_glyph_matrix (w
->current_matrix
);
6804 w
->window_end_valid
= Qnil
;
6806 ++windows_or_buffers_changed
;
6807 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6814 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6816 doc
: /* Get width and type of scroll bars of window WINDOW.
6817 If WINDOW is omitted or nil, use the currently selected window.
6818 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6819 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6821 (Lisp_Object window
)
6823 struct window
*w
= decode_window (window
);
6824 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6825 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6826 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6827 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6828 Fcons (w
->vertical_scroll_bar_type
,
6829 Fcons (Qnil
, Qnil
))));
6834 /***********************************************************************
6836 ***********************************************************************/
6838 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6839 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6840 Use the selected window if WINDOW is nil or omitted.
6841 Normally, value is a multiple of the canonical character height of WINDOW;
6842 optional second arg PIXELS-P means value is measured in pixels. */)
6843 (Lisp_Object window
, Lisp_Object pixels_p
)
6850 window
= selected_window
;
6852 CHECK_WINDOW (window
);
6853 w
= XWINDOW (window
);
6854 f
= XFRAME (w
->frame
);
6856 if (FRAME_WINDOW_P (f
))
6857 result
= (NILP (pixels_p
)
6858 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6859 : make_number (-w
->vscroll
));
6861 result
= make_number (0);
6866 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6868 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6869 WINDOW nil means use the selected window. Normally, VSCROLL is a
6870 non-negative multiple of the canonical character height of WINDOW;
6871 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6872 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6873 corresponds to an integral number of pixels. The return value is the
6874 result of this rounding.
6875 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6876 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6882 window
= selected_window
;
6884 CHECK_WINDOW (window
);
6885 CHECK_NUMBER_OR_FLOAT (vscroll
);
6887 w
= XWINDOW (window
);
6888 f
= XFRAME (w
->frame
);
6890 if (FRAME_WINDOW_P (f
))
6892 int old_dy
= w
->vscroll
;
6894 w
->vscroll
= - (NILP (pixels_p
)
6895 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6896 : XFLOATINT (vscroll
));
6897 w
->vscroll
= min (w
->vscroll
, 0);
6899 if (w
->vscroll
!= old_dy
)
6901 /* Adjust glyph matrix of the frame if the virtual display
6902 area becomes larger than before. */
6903 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6906 /* Prevent redisplay shortcuts. */
6907 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6911 return Fwindow_vscroll (window
, pixels_p
);
6915 /* Call FN for all leaf windows on frame F. FN is called with the
6916 first argument being a pointer to the leaf window, and with
6917 additional argument USER_DATA. Stops when FN returns 0. */
6920 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *),
6923 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6924 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6925 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6929 /* Helper function for foreach_window. Call FN for all leaf windows
6930 reachable from W. FN is called with the first argument being a
6931 pointer to the leaf window, and with additional argument USER_DATA.
6932 Stop when FN returns 0. Value is 0 if stopped by FN. */
6935 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6939 for (cont
= 1; w
&& cont
;)
6941 if (!NILP (w
->hchild
))
6942 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6943 else if (!NILP (w
->vchild
))
6944 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6946 cont
= fn (w
, user_data
);
6948 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6955 /* Freeze or unfreeze the window start of W unless it is a
6956 mini-window or the selected window. FREEZE_P non-null means freeze
6957 the window start. */
6960 freeze_window_start (struct window
*w
, void *freeze_p
)
6962 if (MINI_WINDOW_P (w
)
6963 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6964 && (w
== XWINDOW (selected_window
)
6965 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6966 && ! NILP (Vminibuf_scroll_window
)
6967 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6970 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6975 /* Freeze or unfreeze the window starts of all leaf windows on frame
6976 F, except the selected window and a mini-window. FREEZE_P non-zero
6977 means freeze the window start. */
6980 freeze_window_starts (struct frame
*f
, int freeze_p
)
6982 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6986 /***********************************************************************
6988 ***********************************************************************/
6990 /* Return 1 if window configurations C1 and C2
6991 describe the same state of affairs. This is used by Fequal. */
6994 compare_window_configurations (Lisp_Object c1
, Lisp_Object c2
, int ignore_positions
)
6996 register struct save_window_data
*d1
, *d2
;
6997 struct Lisp_Vector
*sw1
, *sw2
;
7000 CHECK_WINDOW_CONFIGURATION (c1
);
7001 CHECK_WINDOW_CONFIGURATION (c2
);
7003 d1
= (struct save_window_data
*) XVECTOR (c1
);
7004 d2
= (struct save_window_data
*) XVECTOR (c2
);
7005 sw1
= XVECTOR (d1
->saved_windows
);
7006 sw2
= XVECTOR (d2
->saved_windows
);
7008 if (d1
->frame_cols
!= d2
->frame_cols
)
7010 if (d1
->frame_lines
!= d2
->frame_lines
)
7012 if (d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
)
7014 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
7016 /* Don't compare the current_window field directly.
7017 Instead see w1_is_current and w2_is_current, below. */
7018 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
7020 if (! ignore_positions
)
7022 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
7024 if (! EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
))
7027 /* Don't compare the root_window field.
7028 We don't require the two configurations
7029 to use the same window object,
7030 and the two root windows must be equivalent
7031 if everything else compares equal. */
7032 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
7035 /* Verify that the two confis have the same number of windows. */
7036 if (sw1
->header
.size
!= sw2
->header
.size
)
7039 for (i
= 0; i
< sw1
->header
.size
; i
++)
7041 struct saved_window
*p1
, *p2
;
7042 int w1_is_current
, w2_is_current
;
7044 p1
= SAVED_WINDOW_N (sw1
, i
);
7045 p2
= SAVED_WINDOW_N (sw2
, i
);
7047 /* Verify that the current windows in the two
7048 configurations correspond to each other. */
7049 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
7050 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
7052 if (w1_is_current
!= w2_is_current
)
7055 /* Verify that the corresponding windows do match. */
7056 if (! EQ (p1
->buffer
, p2
->buffer
))
7058 if (! EQ (p1
->left_col
, p2
->left_col
))
7060 if (! EQ (p1
->top_line
, p2
->top_line
))
7062 if (! EQ (p1
->total_cols
, p2
->total_cols
))
7064 if (! EQ (p1
->total_lines
, p2
->total_lines
))
7066 if (! EQ (p1
->display_table
, p2
->display_table
))
7068 if (! EQ (p1
->parent
, p2
->parent
))
7070 if (! EQ (p1
->prev
, p2
->prev
))
7072 if (! ignore_positions
)
7074 if (! EQ (p1
->hscroll
, p2
->hscroll
))
7076 if (!EQ (p1
->min_hscroll
, p2
->min_hscroll
))
7078 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
7080 if (NILP (Fequal (p1
->start
, p2
->start
)))
7082 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
7084 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
7087 if (! EQ (p1
->left_margin_cols
, p2
->left_margin_cols
))
7089 if (! EQ (p1
->right_margin_cols
, p2
->right_margin_cols
))
7091 if (! EQ (p1
->left_fringe_width
, p2
->left_fringe_width
))
7093 if (! EQ (p1
->right_fringe_width
, p2
->right_fringe_width
))
7095 if (! EQ (p1
->fringes_outside_margins
, p2
->fringes_outside_margins
))
7097 if (! EQ (p1
->scroll_bar_width
, p2
->scroll_bar_width
))
7099 if (! EQ (p1
->vertical_scroll_bar_type
, p2
->vertical_scroll_bar_type
))
7106 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
7107 Scompare_window_configurations
, 2, 2, 0,
7108 doc
: /* Compare two window configurations as regards the structure of windows.
7109 This function ignores details such as the values of point and mark
7110 and scrolling positions. */)
7111 (Lisp_Object x
, Lisp_Object y
)
7113 if (compare_window_configurations (x
, y
, 1))
7119 init_window_once (void)
7121 struct frame
*f
= make_initial_frame ();
7122 XSETFRAME (selected_frame
, f
);
7123 Vterminal_frame
= selected_frame
;
7124 minibuf_window
= f
->minibuffer_window
;
7125 selected_window
= f
->selected_window
;
7126 last_nonminibuf_frame
= f
;
7128 window_initialized
= 1;
7134 Vwindow_list
= Qnil
;
7138 syms_of_window (void)
7140 Qscroll_up
= intern_c_string ("scroll-up");
7141 staticpro (&Qscroll_up
);
7143 Qscroll_down
= intern_c_string ("scroll-down");
7144 staticpro (&Qscroll_down
);
7146 Qscroll_command
= intern_c_string ("scroll-command");
7147 staticpro (&Qscroll_command
);
7149 Fput (Qscroll_up
, Qscroll_command
, Qt
);
7150 Fput (Qscroll_down
, Qscroll_command
, Qt
);
7152 Qwindow_size_fixed
= intern_c_string ("window-size-fixed");
7153 staticpro (&Qwindow_size_fixed
);
7154 Fset (Qwindow_size_fixed
, Qnil
);
7156 staticpro (&Qwindow_configuration_change_hook
);
7157 Qwindow_configuration_change_hook
7158 = intern_c_string ("window-configuration-change-hook");
7160 Qwindowp
= intern_c_string ("windowp");
7161 staticpro (&Qwindowp
);
7163 Qwindow_configuration_p
= intern_c_string ("window-configuration-p");
7164 staticpro (&Qwindow_configuration_p
);
7166 Qwindow_live_p
= intern_c_string ("window-live-p");
7167 staticpro (&Qwindow_live_p
);
7169 Qdisplay_buffer
= intern_c_string ("display-buffer");
7170 staticpro (&Qdisplay_buffer
);
7172 Qtemp_buffer_show_hook
= intern_c_string ("temp-buffer-show-hook");
7173 staticpro (&Qtemp_buffer_show_hook
);
7175 staticpro (&Vwindow_list
);
7177 minibuf_selected_window
= Qnil
;
7178 staticpro (&minibuf_selected_window
);
7180 window_scroll_pixel_based_preserve_x
= -1;
7181 window_scroll_pixel_based_preserve_y
= -1;
7182 window_scroll_preserve_hpos
= -1;
7183 window_scroll_preserve_vpos
= -1;
7185 DEFVAR_LISP ("temp-buffer-show-function", Vtemp_buffer_show_function
,
7186 doc
: /* Non-nil means call as function to display a help buffer.
7187 The function is called with one argument, the buffer to be displayed.
7188 Used by `with-output-to-temp-buffer'.
7189 If this function is used, then it must do the entire job of showing
7190 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
7191 Vtemp_buffer_show_function
= Qnil
;
7193 DEFVAR_LISP ("minibuffer-scroll-window", Vminibuf_scroll_window
,
7194 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
7195 Vminibuf_scroll_window
= Qnil
;
7197 DEFVAR_BOOL ("mode-line-in-non-selected-windows", mode_line_in_non_selected_windows
,
7198 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
7199 If the minibuffer is active, the `minibuffer-scroll-window' mode line
7200 is displayed in the `mode-line' face. */);
7201 mode_line_in_non_selected_windows
= 1;
7203 DEFVAR_LISP ("other-window-scroll-buffer", Vother_window_scroll_buffer
,
7204 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
7205 Vother_window_scroll_buffer
= Qnil
;
7207 DEFVAR_BOOL ("auto-window-vscroll", auto_window_vscroll_p
,
7208 doc
: /* *Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
7209 auto_window_vscroll_p
= 1;
7211 DEFVAR_INT ("next-screen-context-lines", next_screen_context_lines
,
7212 doc
: /* *Number of lines of continuity when scrolling by screenfuls. */);
7213 next_screen_context_lines
= 2;
7215 DEFVAR_INT ("window-min-height", window_min_height
,
7216 doc
: /* Allow deleting windows less than this tall.
7217 The value is measured in line units. If a window wants a modeline it
7218 is counted as one line.
7220 Emacs honors settings of this variable when enlarging or shrinking
7221 windows vertically. A value less than 1 is invalid. */);
7222 window_min_height
= 4;
7224 DEFVAR_INT ("window-min-width", window_min_width
,
7225 doc
: /* Allow deleting windows less than this wide.
7226 The value is measured in characters and includes any fringes or
7229 Emacs honors settings of this variable when enlarging or shrinking
7230 windows horizontally. A value less than 2 is invalid. */);
7231 window_min_width
= 10;
7233 DEFVAR_LISP ("scroll-preserve-screen-position",
7234 Vscroll_preserve_screen_position
,
7235 doc
: /* *Controls if scroll commands move point to keep its screen position unchanged.
7236 A value of nil means point does not keep its screen position except
7237 at the scroll margin or window boundary respectively.
7238 A value of t means point keeps its screen position if the scroll
7239 command moved it vertically out of the window, e.g. when scrolling
7241 Any other value means point always keeps its screen position.
7242 Scroll commands should have the `scroll-command' property
7243 on their symbols to be controlled by this variable. */);
7244 Vscroll_preserve_screen_position
= Qnil
;
7246 DEFVAR_LISP ("window-point-insertion-type", Vwindow_point_insertion_type
,
7247 doc
: /* Type of marker to use for `window-point'. */);
7248 Vwindow_point_insertion_type
= Qnil
;
7250 DEFVAR_LISP ("window-configuration-change-hook",
7251 Vwindow_configuration_change_hook
,
7252 doc
: /* Functions to call when window configuration changes.
7253 The buffer-local part is run once per window, with the relevant window
7254 selected; while the global part is run only once for the modified frame,
7255 with the relevant frame selected. */);
7256 Vwindow_configuration_change_hook
= Qnil
;
7258 DEFVAR_LISP ("recenter-redisplay", Vrecenter_redisplay
,
7259 doc
: /* If non-nil, then the `recenter' command with a nil argument
7260 will redraw the entire frame; the special value `tty' causes the
7261 frame to be redrawn only if it is a tty frame. */);
7262 Vrecenter_redisplay
= Qtty
;
7265 defsubr (&Sselected_window
);
7266 defsubr (&Sminibuffer_window
);
7267 defsubr (&Swindow_minibuffer_p
);
7268 defsubr (&Swindowp
);
7269 defsubr (&Swindow_live_p
);
7270 defsubr (&Swindow_frame
);
7271 defsubr (&Sframe_root_window
);
7272 defsubr (&Sframe_first_window
);
7273 defsubr (&Sframe_selected_window
);
7274 defsubr (&Sset_frame_selected_window
);
7275 defsubr (&Spos_visible_in_window_p
);
7276 defsubr (&Swindow_line_height
);
7277 defsubr (&Swindow_buffer
);
7278 defsubr (&Swindow_parent
);
7279 defsubr (&Swindow_vchild
);
7280 defsubr (&Swindow_hchild
);
7281 defsubr (&Swindow_next
);
7282 defsubr (&Swindow_prev
);
7283 defsubr (&Swindow_height
);
7284 defsubr (&Swindow_width
);
7285 defsubr (&Swindow_full_width_p
);
7286 defsubr (&Swindow_hscroll
);
7287 defsubr (&Sset_window_hscroll
);
7288 defsubr (&Swindow_redisplay_end_trigger
);
7289 defsubr (&Sset_window_redisplay_end_trigger
);
7290 defsubr (&Swindow_edges
);
7291 defsubr (&Swindow_pixel_edges
);
7292 defsubr (&Swindow_absolute_pixel_edges
);
7293 defsubr (&Swindow_inside_edges
);
7294 defsubr (&Swindow_inside_pixel_edges
);
7295 defsubr (&Swindow_inside_absolute_pixel_edges
);
7296 defsubr (&Scoordinates_in_window_p
);
7297 defsubr (&Swindow_at
);
7298 defsubr (&Swindow_point
);
7299 defsubr (&Swindow_start
);
7300 defsubr (&Swindow_end
);
7301 defsubr (&Sset_window_point
);
7302 defsubr (&Sset_window_start
);
7303 defsubr (&Swindow_dedicated_p
);
7304 defsubr (&Sset_window_dedicated_p
);
7305 defsubr (&Swindow_display_table
);
7306 defsubr (&Sset_window_display_table
);
7307 defsubr (&Snext_window
);
7308 defsubr (&Sprevious_window
);
7309 defsubr (&Sother_window
);
7310 defsubr (&Sget_lru_window
);
7311 defsubr (&Swindow_use_time
);
7312 defsubr (&Sget_largest_window
);
7313 defsubr (&Sget_buffer_window
);
7314 defsubr (&Sdelete_other_windows
);
7315 defsubr (&Sdelete_windows_on
);
7316 defsubr (&Sreplace_buffer_in_windows
);
7317 defsubr (&Sdelete_window
);
7318 defsubr (&Sset_window_buffer
);
7319 defsubr (&Sselect_window
);
7320 defsubr (&Sforce_window_update
);
7321 defsubr (&Stemp_output_buffer_show
);
7322 defsubr (&Ssplit_window
);
7323 defsubr (&Senlarge_window
);
7324 defsubr (&Sshrink_window
);
7325 defsubr (&Sadjust_window_trailing_edge
);
7326 defsubr (&Sscroll_up
);
7327 defsubr (&Sscroll_down
);
7328 defsubr (&Sscroll_left
);
7329 defsubr (&Sscroll_right
);
7330 defsubr (&Sother_window_for_scrolling
);
7331 defsubr (&Sscroll_other_window
);
7332 defsubr (&Sminibuffer_selected_window
);
7333 defsubr (&Srecenter
);
7334 defsubr (&Swindow_text_height
);
7335 defsubr (&Smove_to_window_line
);
7336 defsubr (&Swindow_configuration_p
);
7337 defsubr (&Swindow_configuration_frame
);
7338 defsubr (&Sset_window_configuration
);
7339 defsubr (&Scurrent_window_configuration
);
7340 defsubr (&Swindow_tree
);
7341 defsubr (&Sset_window_margins
);
7342 defsubr (&Swindow_margins
);
7343 defsubr (&Sset_window_fringes
);
7344 defsubr (&Swindow_fringes
);
7345 defsubr (&Sset_window_scroll_bars
);
7346 defsubr (&Swindow_scroll_bars
);
7347 defsubr (&Swindow_vscroll
);
7348 defsubr (&Sset_window_vscroll
);
7349 defsubr (&Scompare_window_configurations
);
7350 defsubr (&Swindow_list
);
7351 defsubr (&Swindow_parameters
);
7352 defsubr (&Swindow_parameter
);
7353 defsubr (&Sset_window_parameter
);
7358 keys_of_window (void)
7360 initial_define_key (control_x_map
, '1', "delete-other-windows");
7361 initial_define_key (control_x_map
, '2', "split-window");
7362 initial_define_key (control_x_map
, '0', "delete-window");
7363 initial_define_key (control_x_map
, 'o', "other-window");
7364 initial_define_key (control_x_map
, '^', "enlarge-window");
7365 initial_define_key (control_x_map
, '<', "scroll-left");
7366 initial_define_key (control_x_map
, '>', "scroll-right");
7368 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
7369 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
7370 initial_define_key (meta_map
, 'v', "scroll-down-command");