1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1996, 1997, 1998, 2000,
4 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
5 Free Software Foundation, Inc.
7 This file is part of GNU Emacs.
9 GNU Emacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 GNU Emacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
36 #include "dispextern.h"
37 #include "blockinput.h"
38 #include "intervals.h"
39 #include "termhooks.h" /* For FRAME_TERMINAL. */
43 #endif /* HAVE_X_WINDOWS */
55 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
56 Lisp_Object Qwindow_deletable_p
, Qdelete_window
, Qdisplay_buffer
;
57 Lisp_Object Qget_mru_window
;
58 Lisp_Object Qresize_root_window
, Qresize_root_window_vertically
;
59 Lisp_Object Qscroll_up
, Qscroll_down
, Qscroll_command
;
60 Lisp_Object Qset
, Qabove
, Qbelow
, Qnest
, Qgroup
, Qresize
;
62 extern Lisp_Object Qleft_margin
, Qright_margin
;
64 static int displayed_window_lines (struct window
*);
65 static struct window
*decode_window (Lisp_Object
);
66 static int count_windows (struct window
*);
67 static int get_leaf_windows (struct window
*, struct window
**, int);
68 static void window_scroll (Lisp_Object
, int, int, int);
69 static void window_scroll_pixel_based (Lisp_Object
, int, int, int);
70 static void window_scroll_line_based (Lisp_Object
, int, int, int);
71 static int freeze_window_start (struct window
*, void *);
72 static Lisp_Object
window_list (void);
73 static int add_window_to_list (struct window
*, void *);
74 static int candidate_window_p (Lisp_Object
, Lisp_Object
, Lisp_Object
,
76 static Lisp_Object
next_window (Lisp_Object
, Lisp_Object
,
78 static void decode_next_window_args (Lisp_Object
*, Lisp_Object
*,
80 static int foreach_window_1 (struct window
*,
81 int (* fn
) (struct window
*, void *),
83 static Lisp_Object
window_list_1 (Lisp_Object
, Lisp_Object
, Lisp_Object
);
84 static void resize_window_apply (struct window
*, int);
86 /* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by
89 the top level editing loop at the end of each command.
91 This value is always the same as
92 FRAME_SELECTED_WINDOW (selected_frame). */
93 Lisp_Object selected_window
;
95 /* A list of all windows for use by next_window and Fwindow_list.
96 Functions creating or deleting windows should invalidate this cache
97 by setting it to nil. */
98 Lisp_Object Vwindow_list
;
100 /* The mini-buffer window of the selected frame.
101 Note that you cannot test for mini-bufferness of an arbitrary window
102 by comparing against this; but you can test for mini-bufferness of
103 the selected window. */
104 Lisp_Object minibuf_window
;
106 /* Non-nil means it is the window whose mode line should be
107 shown as the selected window when the minibuffer is selected. */
108 Lisp_Object minibuf_selected_window
;
110 /* Non-nil means it is the window for C-M-v to scroll
111 when the mini-buffer is selected. */
112 Lisp_Object Vminibuf_scroll_window
;
114 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
115 Lisp_Object Vother_window_scroll_buffer
;
117 /* Non-nil means it's function to call to display temp buffers. */
118 Lisp_Object Vtemp_buffer_show_function
;
120 /* Non-zero means line and page scrolling on tall lines (with images)
121 does partial scrolling by modifying window-vscroll. */
122 int auto_window_vscroll_p
;
124 /* Non-zero means to use mode-line-inactive face in all windows but the
125 selected-window and the minibuffer-scroll-window when the
126 minibuffer is active. */
127 int mode_line_in_non_selected_windows
;
129 /* Hook run at end of temp_output_buffer_show. */
130 Lisp_Object Qtemp_buffer_show_hook
;
132 /* Number of lines of continuity in scrolling by screenfuls. */
133 EMACS_INT next_screen_context_lines
;
135 /* Incremented for each window created. */
136 static int sequence_number
;
138 /* Nonzero after init_window_once has finished. */
139 static int window_initialized
;
141 /* Hook to run when window config changes. */
142 static Lisp_Object Qwindow_configuration_change_hook
;
143 static Lisp_Object Vwindow_configuration_change_hook
;
145 /* Non-nil means scroll commands try to put point
146 at the same screen height as previously. */
147 Lisp_Object Vscroll_preserve_screen_position
;
149 /* Non-nil means that text is inserted before window's markers. */
150 Lisp_Object Vwindow_point_insertion_type
;
152 /* Used by the function window_scroll_pixel_based */
153 static int window_scroll_pixel_based_preserve_x
;
154 static int window_scroll_pixel_based_preserve_y
;
156 /* Same for window_scroll_line_based. */
157 static int window_scroll_preserve_hpos
;
158 static int window_scroll_preserve_vpos
;
160 /* Whether splitting/deleting is handled specially. */
161 Lisp_Object Vwindow_splits
;
163 extern EMACS_INT scroll_margin
;
165 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
167 /* If non-nil, then the `recenter' command with a nil argument causes
168 the entire frame to be redrawn; the special value `tty' causes the
169 frame to be redrawn only if it is a tty frame. */
170 static Lisp_Object Vrecenter_redisplay
;
171 extern Lisp_Object Qtty
;
173 static struct window
*
174 decode_window (register Lisp_Object window
)
177 return XWINDOW (selected_window
);
179 CHECK_LIVE_WINDOW (window
);
180 return XWINDOW (window
);
183 static struct window
*
184 decode_any_window (register Lisp_Object window
)
187 return XWINDOW (selected_window
);
189 CHECK_WINDOW (window
);
190 return XWINDOW (window
);
193 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
194 doc
: /* Return t if OBJECT is a window. */)
197 return WINDOWP (object
) ? Qt
: Qnil
;
200 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
201 doc
: /* Return t if OBJECT is a live window and nil otherwise.
202 A live window is a window that is currently used to display a
206 return WINDOW_LIVE_P (object
) ? Qt
: Qnil
;
209 /* Frames and windows. */
210 DEFUN ("window-frame", Fwindow_frame
, Swindow_frame
, 1, 1, 0,
211 doc
: /* Return the frame that window WINDOW is on.
212 WINDOW can be any window and defaults to the selected one. */)
215 return decode_any_window (window
)->frame
;
218 DEFUN ("frame-root-window", Fframe_root_window
, Sframe_root_window
, 0, 1, 0,
219 doc
: /* Return the root window of FRAME_OR_WINDOW.
220 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
221 Else if FRAME_OR_WINDOW denotes any window, return the root window of
222 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
223 the root window of that frame. */)
224 (Lisp_Object frame_or_window
)
228 if (NILP (frame_or_window
))
229 window
= SELECTED_FRAME ()->root_window
;
230 else if (WINDOWP (frame_or_window
))
231 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
234 CHECK_LIVE_FRAME (frame_or_window
);
235 window
= XFRAME (frame_or_window
)->root_window
;
241 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
242 doc
: /* Return the window used now for minibuffers.
243 If the optional argument FRAME is specified, return the minibuffer window
244 used by that frame. */)
248 frame
= selected_frame
;
249 CHECK_LIVE_FRAME (frame
);
250 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
253 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
254 doc
: /* Return non-nil if WINDOW is a minibuffer window.
255 WINDOW can be any window and defaults to the selected one. */)
258 return MINI_WINDOW_P (decode_any_window (window
)) ? Qt
: Qnil
;
261 /* Don't move this to window.el - this must be a safe routine. */
262 DEFUN ("frame-first-window", Fframe_first_window
, Sframe_first_window
, 0, 1, 0,
263 doc
: /* Return the topmost, leftmost live window on FRAME_OR_WINDOW.
264 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
265 Else if FRAME_OR_WINDOW denotes any window, return the first window of
266 that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
267 the first window of that frame. */)
268 (Lisp_Object frame_or_window
)
272 if (NILP (frame_or_window
))
273 window
= SELECTED_FRAME ()->root_window
;
274 else if (WINDOWP (frame_or_window
))
275 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->root_window
;
278 CHECK_LIVE_FRAME (frame_or_window
);
279 window
= XFRAME (frame_or_window
)->root_window
;
282 while (NILP (XWINDOW (window
)->buffer
))
284 if (! NILP (XWINDOW (window
)->hchild
))
285 window
= XWINDOW (window
)->hchild
;
286 else if (! NILP (XWINDOW (window
)->vchild
))
287 window
= XWINDOW (window
)->vchild
;
295 DEFUN ("frame-selected-window", Fframe_selected_window
,
296 Sframe_selected_window
, 0, 1, 0,
297 doc
: /* Return the selected window of FRAME_OR_WINDOW.
298 If omitted, FRAME_OR_WINDOW defaults to the currently selected frame.
299 Else if FRAME_OR_WINDOW denotes any window, return the selected window
300 of that window's frame. If FRAME_OR_WINDOW denotes a live frame, return
301 the selected window of that frame. */)
302 (Lisp_Object frame_or_window
)
306 if (NILP (frame_or_window
))
307 window
= SELECTED_FRAME ()->selected_window
;
308 else if (WINDOWP (frame_or_window
))
309 window
= XFRAME (WINDOW_FRAME (XWINDOW (frame_or_window
)))->selected_window
;
312 CHECK_LIVE_FRAME (frame_or_window
);
313 window
= XFRAME (frame_or_window
)->selected_window
;
319 DEFUN ("set-frame-selected-window", Fset_frame_selected_window
,
320 Sset_frame_selected_window
, 2, 3, 0,
321 doc
: /* Set selected window of FRAME to WINDOW.
322 FRAME must be a live frame and defaults to the selected one. If FRAME
323 is the selected frame, this makes WINDOW the selected window. Optional
324 argument NORECORD non-nil means to neither change the order of recently
325 selected windows nor the buffer list. WINDOW must denote a live window.
327 (Lisp_Object frame
, Lisp_Object window
, Lisp_Object norecord
)
330 frame
= selected_frame
;
332 CHECK_LIVE_FRAME (frame
);
333 CHECK_LIVE_WINDOW (window
);
335 if (! EQ (frame
, WINDOW_FRAME (XWINDOW (window
))))
336 error ("In `set-frame-selected-window', WINDOW is not on FRAME");
338 if (EQ (frame
, selected_frame
))
339 return Fselect_window (window
, norecord
);
341 return XFRAME (frame
)->selected_window
= window
;
344 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
345 doc
: /* Return the selected window.
346 The selected window is the window in which the standard cursor for
347 selected windows appears and to which many commands apply. */)
350 return selected_window
;
353 int window_select_count
;
355 /* Note that selected_window can be nil when this is called from
356 Fset_window_configuration. */
357 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 2, 0,
358 doc
: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
359 Also make WINDOW's buffer current and make WINDOW the frame's selected
360 window. Return WINDOW.
362 Optional second arg NORECORD non-nil means do not put this buffer at the
363 front of the buffer list and do not make this window the most recently
366 Note that the main editor command loop sets the current buffer to the
367 buffer of the selected window before each command. */)
368 (register Lisp_Object window
, Lisp_Object norecord
)
370 register struct window
*w
;
371 register struct window
*ow
;
373 int not_selected_before
= !EQ (window
, selected_window
);
375 CHECK_LIVE_WINDOW (window
);
377 w
= XWINDOW (window
);
378 w
->frozen_window_start_p
= 0;
380 if (not_selected_before
)
382 sf
= SELECTED_FRAME ();
383 if (XFRAME (WINDOW_FRAME (w
)) != sf
)
385 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
386 /* Use this rather than Fhandle_switch_frame
387 so that FRAME_FOCUS_FRAME is moved appropriately as we
388 move around in the state where a minibuffer in a separate
390 Fselect_frame (WINDOW_FRAME (w
), norecord
);
391 /* Fselect_frame called us back so we've done all the work already. */
392 eassert (EQ (window
, selected_window
));
396 sf
->selected_window
= window
;
398 /* Store the current buffer's actual point into the
399 old selected window. It belongs to that window,
400 and when the window is not selected, must be in the window. */
401 if (!NILP (selected_window
))
403 ow
= XWINDOW (selected_window
);
404 if (! NILP (ow
->buffer
))
405 set_marker_both (ow
->pointm
, ow
->buffer
,
406 BUF_PT (XBUFFER (ow
->buffer
)),
407 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
410 selected_window
= window
;
413 Fset_buffer (w
->buffer
);
417 ++window_select_count
;
418 XSETFASTINT (w
->use_time
, window_select_count
);
419 record_buffer (w
->buffer
);
422 XBUFFER (w
->buffer
)->last_selected_window
= window
;
424 /* Go to the point recorded in the window.
425 This is important when the buffer is in more
426 than one window. It also matters when
427 redisplay_window has altered point after scrolling,
428 because it makes the change only in the window. */
429 if (not_selected_before
)
431 register int new_point
= marker_position (w
->pointm
);
432 if (new_point
< BEGV
)
434 else if (new_point
> ZV
)
439 windows_or_buffers_changed
++;
445 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
446 doc
: /* Return the buffer that WINDOW is displaying.
447 WINDOW can be any window and defaults to the selected one.
448 If WINDOW is an internal window return nil. */)
451 return decode_any_window (window
)->buffer
;
454 DEFUN ("window-parent", Fwindow_parent
, Swindow_parent
, 0, 1, 0,
455 doc
: /* Return WINDOW's parent window.
456 WINDOW can be any window and defaults to the selected one.
457 Return nil if WINDOW has no parent. */)
460 return decode_any_window (window
)->parent
;
463 DEFUN ("window-vchild", Fwindow_vchild
, Swindow_vchild
, 0, 1, 0,
464 doc
: /* Return WINDOW's first vertical child window.
465 WINDOW can be any window and defaults to the selected one.
466 Return nil if WINDOW has no vertical child. */)
469 return decode_any_window (window
)->vchild
;
472 DEFUN ("window-hchild", Fwindow_hchild
, Swindow_hchild
, 0, 1, 0,
473 doc
: /* Return WINDOW's first horizontal child window.
474 WINDOW can be any window and defaults to the selected one.
475 Return nil if WINDOW has no horizontal child. */)
478 return decode_any_window (window
)->hchild
;
481 DEFUN ("window-next", Fwindow_next
, Swindow_next
, 0, 1, 0,
482 doc
: /* Return WINDOW's right sibling window.
483 WINDOW can be any window and defaults to the selected one.
484 Return nil if WINDOW has no right sibling. */)
487 return decode_any_window (window
)->next
;
490 DEFUN ("window-prev", Fwindow_prev
, Swindow_prev
, 0, 1, 0,
491 doc
: /* Return WINDOW's left sibling window.
492 WINDOW can be any window and defaults to the selected one.
493 Return nil if WINDOW has no left sibling. */)
496 return decode_any_window (window
)->prev
;
499 DEFUN ("window-use-time", Fwindow_use_time
, Swindow_use_time
, 0, 1, 0,
500 doc
: /* Return WINDOW's use time.
501 WINDOW defaults to the selected window. The window with the highest use
502 time is the most recently selected one. The window with the lowest use
503 time is the least recently selected one. */)
506 return decode_window (window
)->use_time
;
509 DEFUN ("window-total-size", Fwindow_total_size
, Swindow_total_size
, 0, 2, 0,
510 doc
: /* Return the total number of lines of WINDOW.
511 WINDOW can be any window and defaults to the selected one. The return
512 value includes WINDOW's mode line and header line, if any. If WINDOW
513 is internal, the return value is the sum of the total number of lines
514 of WINDOW's child windows if these are vertically combined and the
515 height of WINDOW's first child otherwise.
517 Optional argument HORIZONTAL non-nil means return the total number of
518 columns of WINDOW. In this case the return value includes any vertical
519 dividers or scrollbars of WINDOW. If WINDOW is internal, the return
520 value is the sum of the total number of columns of WINDOW's child
521 windows if they are horizontally combined and the width of WINDOW's
522 first child otherwise. */)
523 (Lisp_Object window
, Lisp_Object horizontal
)
525 if (NILP (horizontal
))
526 return decode_any_window (window
)->total_lines
;
528 return decode_any_window (window
)->total_cols
;
531 DEFUN ("window-new-total-size", Fwindow_new_total_size
, Swindow_new_total_size
, 0, 1, 0,
532 doc
: /* Return new total size of WINDOW.
533 WINDOW defaults to the selected window. */)
536 return decode_any_window (window
)->new_total
;
539 DEFUN ("window-normal-size", Fwindow_normal_size
, Swindow_normal_size
, 0, 2, 0,
540 doc
: /* Return normal height of WINDOW.
541 WINDOW can be any window and defaults to the selected one. Optional
542 argument HORIZONTAL non-nil means return normal width of WINDOW. */)
543 (Lisp_Object window
, Lisp_Object horizontal
)
545 if (NILP (horizontal
))
546 return decode_any_window (window
)->normal_lines
;
548 return decode_any_window (window
)->normal_cols
;
551 DEFUN ("window-new-normal-size", Fwindow_new_normal_size
, Swindow_new_normal_size
, 0, 1, 0,
552 doc
: /* Return new normal size of WINDOW.
553 WINDOW can be any window and defaults to the selected one. */)
556 return decode_any_window (window
)->new_normal
;
559 DEFUN ("window-left-column", Fwindow_left_column
, Swindow_left_column
, 0, 1, 0,
560 doc
: /* Return left column of WINDOW.
561 WINDOW can be any window and defaults to the selected one. */)
564 return decode_any_window (window
)->left_col
;
567 DEFUN ("window-top-line", Fwindow_top_line
, Swindow_top_line
, 0, 1, 0,
568 doc
: /* Return top line of WINDOW.
569 WINDOW can be any window and defaults to the selected one. */)
572 return decode_any_window (window
)->top_line
;
575 /* Return the number of lines of W's body. Don't count any mode or
579 window_body_lines (struct window
*w
)
581 int height
= XFASTINT (w
->total_lines
);
583 if (!MINI_WINDOW_P (w
))
585 if (WINDOW_WANTS_MODELINE_P (w
))
587 if (WINDOW_WANTS_HEADER_LINE_P (w
))
594 /* Return the number of columns of W's body. Don't count columns
595 occupied by the scroll bar or the vertical bar separating W from its
596 right sibling. On window-systems don't count fringes or display
600 window_body_cols (struct window
*w
)
602 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
603 int width
= XINT (w
->total_cols
);
605 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
606 /* Scroll bars occupy a few columns. */
607 width
-= WINDOW_CONFIG_SCROLL_BAR_COLS (w
);
608 else if (!FRAME_WINDOW_P (f
)
609 && !WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
610 /* The column of `|' characters separating side-by-side windows
611 occupies one column only. */
614 if (FRAME_WINDOW_P (f
))
615 /* On window-systems, fringes and display margins cannot be
616 used for normal text. */
617 width
-= (WINDOW_FRINGE_COLS (w
)
618 + WINDOW_LEFT_MARGIN_COLS (w
)
619 + WINDOW_RIGHT_MARGIN_COLS (w
));
624 DEFUN ("window-body-size", Fwindow_body_size
, Swindow_body_size
, 0, 2, 0,
625 doc
: /* Return the number of lines of WINDOW's body.
626 WINDOW must be a live window and defaults to the selected one. The
627 return value does not include WINDOW's mode line and header line, if
630 Optional argument HORIZONTAL non-nil means return the number of columns
631 of WINDOW's body. In this case, the return value does not include any
632 vertical dividers or scroll bars owned by WINDOW. On a window-system
633 the return value does not include the number of columns used for
634 WINDOW's fringes or display margins either. */)
635 (Lisp_Object window
, Lisp_Object horizontal
)
637 struct window
*w
= decode_any_window (window
);
639 if (NILP (horizontal
))
640 return make_number (window_body_lines (w
));
642 return make_number (window_body_cols (w
));
645 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
646 doc
: /* Return the number of columns by which WINDOW is scrolled from left margin.
647 WINDOW must be a live window and defaults to the selected one. */)
650 return decode_window (window
)->hscroll
;
653 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
654 doc
: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
655 Return NCOL. NCOL should be zero or positive.
657 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
658 window so that the location of point moves off-window. */)
659 (Lisp_Object window
, Lisp_Object ncol
)
661 struct window
*w
= decode_window (window
);
665 hscroll
= max (0, XINT (ncol
));
667 /* Prevent redisplay shortcuts when changing the hscroll. */
668 if (XINT (w
->hscroll
) != hscroll
)
669 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
671 w
->hscroll
= make_number (hscroll
);
675 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
676 Swindow_redisplay_end_trigger
, 0, 1, 0,
677 doc
: /* Return WINDOW's redisplay end trigger value.
678 WINDOW defaults to the selected window.
679 See `set-window-redisplay-end-trigger' for more information. */)
682 return decode_window (window
)->redisplay_end_trigger
;
685 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
686 Sset_window_redisplay_end_trigger
, 2, 2, 0,
687 doc
: /* Set WINDOW's redisplay end trigger value to VALUE.
688 VALUE should be a buffer position (typically a marker) or nil.
689 If it is a buffer position, then if redisplay in WINDOW reaches a position
690 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
691 with two arguments: WINDOW, and the end trigger value.
692 Afterwards the end-trigger value is reset to nil. */)
693 (register Lisp_Object window
, Lisp_Object value
)
695 register struct window
*w
;
697 w
= decode_window (window
);
698 w
->redisplay_end_trigger
= value
;
702 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
703 doc
: /* Return a list of the edge coordinates of WINDOW.
704 The list has the form (LEFT TOP RIGHT BOTTOM).
705 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
706 all relative to 0, 0 at top left corner of frame.
708 RIGHT is one more than the rightmost column occupied by WINDOW.
709 BOTTOM is one more than the bottommost row occupied by WINDOW.
710 The edges include the space used by WINDOW's scroll bar, display
711 margins, fringes, header line, and/or mode line. For the edges of
712 just the text area, use `window-inside-edges'. */)
715 register struct window
*w
= decode_any_window (window
);
717 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w
)),
718 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w
)),
719 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w
)),
720 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w
)),
724 DEFUN ("window-pixel-edges", Fwindow_pixel_edges
, Swindow_pixel_edges
, 0, 1, 0,
725 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
726 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
727 the top left corner of the frame.
729 RIGHT is one more than the rightmost x position occupied by WINDOW.
730 BOTTOM is one more than the bottommost y position occupied by WINDOW.
731 The pixel edges include the space used by WINDOW's scroll bar, display
732 margins, fringes, header line, and/or mode line. For the pixel edges
733 of just the text area, use `window-inside-pixel-edges'. */)
736 register struct window
*w
= decode_any_window (window
);
738 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
)),
739 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
)),
740 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
)),
741 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
)),
746 calc_absolute_offset(struct window
*w
, int *add_x
, int *add_y
)
748 struct frame
*f
= XFRAME (w
->frame
);
750 #ifdef FRAME_MENUBAR_HEIGHT
751 *add_y
+= FRAME_MENUBAR_HEIGHT (f
);
753 #ifdef FRAME_TOOLBAR_HEIGHT
754 *add_y
+= FRAME_TOOLBAR_HEIGHT (f
);
756 #ifdef FRAME_NS_TITLEBAR_HEIGHT
757 *add_y
+= FRAME_NS_TITLEBAR_HEIGHT (f
);
759 *add_x
= f
->left_pos
;
762 DEFUN ("window-absolute-pixel-edges", Fwindow_absolute_pixel_edges
,
763 Swindow_absolute_pixel_edges
, 0, 1, 0,
764 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
765 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
766 the top left corner of the display.
768 RIGHT is one more than the rightmost x position occupied by WINDOW.
769 BOTTOM is one more than the bottommost y position occupied by WINDOW.
770 The pixel edges include the space used by WINDOW's scroll bar, display
771 margins, fringes, header line, and/or mode line. For the pixel edges
772 of just the text area, use `window-inside-absolute-pixel-edges'. */)
775 register struct window
*w
= decode_any_window (window
);
777 calc_absolute_offset (w
, &add_x
, &add_y
);
779 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w
) + add_x
),
780 Fcons (make_number (WINDOW_TOP_EDGE_Y (w
) + add_y
),
781 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w
) + add_x
),
782 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w
) + add_y
),
786 DEFUN ("window-inside-edges", Fwindow_inside_edges
, Swindow_inside_edges
, 0, 1, 0,
787 doc
: /* Return a list of the edge coordinates of WINDOW.
788 The list has the form (LEFT TOP RIGHT BOTTOM).
789 TOP and BOTTOM count by lines, and LEFT and RIGHT count by columns,
790 all relative to 0, 0 at top left corner of frame.
792 RIGHT is one more than the rightmost column of WINDOW's text area.
793 BOTTOM is one more than the bottommost row of WINDOW's text area.
794 The inside edges do not include the space used by the WINDOW's scroll
795 bar, display margins, fringes, header line, and/or mode line. */)
798 register struct window
*w
= decode_any_window (window
);
800 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w
)
801 + WINDOW_LEFT_MARGIN_COLS (w
)
802 + WINDOW_LEFT_FRINGE_COLS (w
)),
803 make_number (WINDOW_TOP_EDGE_LINE (w
)
804 + WINDOW_HEADER_LINE_LINES (w
)),
805 make_number (WINDOW_BOX_RIGHT_EDGE_COL (w
)
806 - WINDOW_RIGHT_MARGIN_COLS (w
)
807 - WINDOW_RIGHT_FRINGE_COLS (w
)),
808 make_number (WINDOW_BOTTOM_EDGE_LINE (w
)
809 - WINDOW_MODE_LINE_LINES (w
)));
812 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges
, Swindow_inside_pixel_edges
, 0, 1, 0,
813 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
814 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
815 the top left corner of the frame.
817 RIGHT is one more than the rightmost x position of WINDOW's text area.
818 BOTTOM is one more than the bottommost y position of WINDOW's text area.
819 The inside edges do not include the space used by WINDOW's scroll bar,
820 display margins, fringes, header line, and/or mode line. */)
823 register struct window
*w
= decode_any_window (window
);
825 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
826 + WINDOW_LEFT_MARGIN_WIDTH (w
)
827 + WINDOW_LEFT_FRINGE_WIDTH (w
)),
828 make_number (WINDOW_TOP_EDGE_Y (w
)
829 + WINDOW_HEADER_LINE_HEIGHT (w
)),
830 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
831 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
832 - WINDOW_RIGHT_FRINGE_WIDTH (w
)),
833 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
834 - WINDOW_MODE_LINE_HEIGHT (w
)));
837 DEFUN ("window-inside-absolute-pixel-edges",
838 Fwindow_inside_absolute_pixel_edges
,
839 Swindow_inside_absolute_pixel_edges
, 0, 1, 0,
840 doc
: /* Return a list of the edge pixel coordinates of WINDOW.
841 The list has the form (LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at
842 the top left corner of the display.
844 RIGHT is one more than the rightmost x position of WINDOW's text area.
845 BOTTOM is one more than the bottommost y position of WINDOW's text area.
846 The inside edges do not include the space used by WINDOW's scroll bar,
847 display margins, fringes, header line, and/or mode line. */)
850 register struct window
*w
= decode_any_window (window
);
852 calc_absolute_offset (w
, &add_x
, &add_y
);
854 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w
)
855 + WINDOW_LEFT_MARGIN_WIDTH (w
)
856 + WINDOW_LEFT_FRINGE_WIDTH (w
) + add_x
),
857 make_number (WINDOW_TOP_EDGE_Y (w
)
858 + WINDOW_HEADER_LINE_HEIGHT (w
) + add_y
),
859 make_number (WINDOW_BOX_RIGHT_EDGE_X (w
)
860 - WINDOW_RIGHT_MARGIN_WIDTH (w
)
861 - WINDOW_RIGHT_FRINGE_WIDTH (w
) + add_x
),
862 make_number (WINDOW_BOTTOM_EDGE_Y (w
)
863 - WINDOW_MODE_LINE_HEIGHT (w
) + add_y
));
866 /* Test if the character at column *X, row *Y is within window W.
867 If it is not, return ON_NOTHING;
868 if it is in the window's text area,
869 set *x and *y to its location relative to the upper left corner
872 if it is on the window's modeline, return ON_MODE_LINE;
873 if it is on the border between the window and its right sibling,
874 return ON_VERTICAL_BORDER.
875 if it is on a scroll bar,
876 return ON_SCROLL_BAR.
877 if it is on the window's top line, return ON_HEADER_LINE;
878 if it is in left or right fringe of the window,
879 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
880 to window-relative coordinates;
881 if it is in the marginal area to the left/right of the window,
882 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
883 to window-relative coordinates.
885 X and Y are frame relative pixel coordinates. */
887 static enum window_part
888 coordinates_in_window (register struct window
*w
, register int *x
, register int *y
)
890 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
891 int left_x
, right_x
, top_y
, bottom_y
;
892 enum window_part part
;
893 int ux
= FRAME_COLUMN_WIDTH (f
);
894 int x0
= WINDOW_LEFT_EDGE_X (w
);
895 int x1
= WINDOW_RIGHT_EDGE_X (w
);
896 /* The width of the area where the vertical line can be dragged.
897 (Between mode lines for instance. */
898 int grabbable_width
= ux
;
899 int lmargin_width
, rmargin_width
, text_left
, text_right
;
901 /* In what's below, we subtract 1 when computing right_x because we
902 want the rightmost pixel, which is given by left_pixel+width-1. */
903 if (w
->pseudo_window_p
)
906 right_x
= WINDOW_TOTAL_WIDTH (w
) - 1;
907 top_y
= WINDOW_TOP_EDGE_Y (w
);
908 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
912 left_x
= WINDOW_BOX_LEFT_EDGE_X (w
);
913 right_x
= WINDOW_BOX_RIGHT_EDGE_X (w
) - 1;
914 top_y
= WINDOW_TOP_EDGE_Y (w
);
915 bottom_y
= WINDOW_BOTTOM_EDGE_Y (w
);
918 /* Outside any interesting row? */
919 if (*y
< top_y
|| *y
>= bottom_y
)
922 /* On the mode line or header line? If it's near the start of
923 the mode or header line of window that's has a horizontal
924 sibling, say it's on the vertical line. That's to be able
925 to resize windows horizontally in case we're using toolkit
928 if (WINDOW_WANTS_MODELINE_P (w
)
929 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
933 header_vertical_border_check
:
934 /* We're somewhere on the mode line. We consider the place
935 between mode lines of horizontally adjacent mode lines
936 as the vertical border. If scroll bars on the left,
937 return the right window. */
938 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
)
939 || WINDOW_RIGHTMOST_P (w
))
941 if (!WINDOW_LEFTMOST_P (w
) && eabs (*x
- x0
) < grabbable_width
)
943 /* Convert X and Y to window relative coordinates.
944 Vertical border is at the left edge of window. */
945 *x
= max (0, *x
- x0
);
947 return ON_VERTICAL_BORDER
;
952 /* Make sure we're not at the rightmost position of a
953 mode-/header-line and there's yet another window on
954 the right. (Bug#1372) */
955 if ((WINDOW_RIGHTMOST_P (w
) || *x
< x1
)
956 && eabs (*x
- x1
) < grabbable_width
)
958 /* Convert X and Y to window relative coordinates.
959 Vertical border is at the right edge of window. */
960 *x
= min (x1
, *x
) - x0
;
962 return ON_VERTICAL_BORDER
;
966 if (*x
< x0
|| *x
>= x1
)
969 /* Convert X and Y to window relative coordinates.
970 Mode line starts at left edge of window. */
976 if (WINDOW_WANTS_HEADER_LINE_P (w
)
977 && *y
< top_y
+ CURRENT_HEADER_LINE_HEIGHT (w
))
979 part
= ON_HEADER_LINE
;
980 goto header_vertical_border_check
;
983 if (*x
< x0
|| *x
>= x1
)
986 /* Outside any interesting column? */
987 if (*x
< left_x
|| *x
> right_x
)
990 return ON_SCROLL_BAR
;
993 lmargin_width
= window_box_width (w
, LEFT_MARGIN_AREA
);
994 rmargin_width
= window_box_width (w
, RIGHT_MARGIN_AREA
);
996 text_left
= window_box_left (w
, TEXT_AREA
);
997 text_right
= text_left
+ window_box_width (w
, TEXT_AREA
);
999 if (FRAME_WINDOW_P (f
))
1001 if (!w
->pseudo_window_p
1002 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w
)
1003 && !WINDOW_RIGHTMOST_P (w
)
1004 && (eabs (*x
- right_x
) < grabbable_width
))
1006 /* Convert X and Y to window relative coordinates.
1007 Vertical border is at the right edge of window. */
1008 *x
= min (right_x
, *x
) - left_x
;
1010 return ON_VERTICAL_BORDER
;
1015 /* Need to say "*x > right_x" rather than >=, since on character
1016 terminals, the vertical line's x coordinate is right_x. */
1017 if (!w
->pseudo_window_p
1018 && !WINDOW_RIGHTMOST_P (w
)
1019 && *x
> right_x
- ux
)
1021 /* On the border on the right side of the window? Assume that
1022 this area begins at RIGHT_X minus a canonical char width. */
1023 *x
= min (right_x
, *x
) - left_x
;
1025 return ON_VERTICAL_BORDER
;
1031 if (lmargin_width
> 0
1032 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1033 ? (*x
>= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
))
1034 : (*x
< left_x
+ lmargin_width
)))
1037 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1038 *x
-= WINDOW_LEFT_FRINGE_WIDTH (w
);
1040 return ON_LEFT_MARGIN
;
1043 /* Convert X and Y to window-relative pixel coordinates. */
1046 return ON_LEFT_FRINGE
;
1049 if (*x
>= text_right
)
1051 if (rmargin_width
> 0
1052 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
1053 ? (*x
< right_x
- WINDOW_RIGHT_FRINGE_WIDTH (w
))
1054 : (*x
>= right_x
- rmargin_width
)))
1056 *x
-= right_x
- rmargin_width
;
1057 if (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
))
1058 *x
+= WINDOW_RIGHT_FRINGE_WIDTH (w
);
1060 return ON_RIGHT_MARGIN
;
1063 /* Convert X and Y to window-relative pixel coordinates. */
1064 *x
-= left_x
+ WINDOW_LEFT_FRINGE_WIDTH (w
);
1066 return ON_RIGHT_FRINGE
;
1069 /* Everything special ruled out - must be on text area */
1076 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
1077 Scoordinates_in_window_p
, 2, 2, 0,
1078 doc
: /* Return non-nil if COORDINATES are in WINDOW.
1079 COORDINATES is a cons of the form (X . Y), X and Y being distances
1080 measured in characters from the upper-left corner of the frame.
1081 \(0 . 0) denotes the character in the upper left corner of the
1083 If COORDINATES are in the text portion of WINDOW,
1084 the coordinates relative to the window are returned.
1085 If they are in the mode line of WINDOW, `mode-line' is returned.
1086 If they are in the top mode line of WINDOW, `header-line' is returned.
1087 If they are in the left fringe of WINDOW, `left-fringe' is returned.
1088 If they are in the right fringe of WINDOW, `right-fringe' is returned.
1089 If they are on the border between WINDOW and its right sibling,
1090 `vertical-line' is returned.
1091 If they are in the windows's left or right marginal areas, `left-margin'\n\
1092 or `right-margin' is returned. */)
1093 (register Lisp_Object coordinates
, Lisp_Object window
)
1100 CHECK_WINDOW (window
);
1101 w
= XWINDOW (window
);
1102 f
= XFRAME (w
->frame
);
1103 CHECK_CONS (coordinates
);
1104 lx
= Fcar (coordinates
);
1105 ly
= Fcdr (coordinates
);
1106 CHECK_NUMBER_OR_FLOAT (lx
);
1107 CHECK_NUMBER_OR_FLOAT (ly
);
1108 x
= FRAME_PIXEL_X_FROM_CANON_X (f
, lx
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1109 y
= FRAME_PIXEL_Y_FROM_CANON_Y (f
, ly
) + FRAME_INTERNAL_BORDER_WIDTH (f
);
1111 switch (coordinates_in_window (w
, &x
, &y
))
1117 /* X and Y are now window relative pixel coordinates. Convert
1118 them to canonical char units before returning them. */
1119 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f
, x
),
1120 FRAME_CANON_Y_FROM_PIXEL_Y (f
, y
));
1125 case ON_VERTICAL_BORDER
:
1126 return Qvertical_line
;
1128 case ON_HEADER_LINE
:
1129 return Qheader_line
;
1131 case ON_LEFT_FRINGE
:
1132 return Qleft_fringe
;
1134 case ON_RIGHT_FRINGE
:
1135 return Qright_fringe
;
1137 case ON_LEFT_MARGIN
:
1138 return Qleft_margin
;
1140 case ON_RIGHT_MARGIN
:
1141 return Qright_margin
;
1144 /* Historically we are supposed to return nil in this case. */
1153 /* Callback for foreach_window, used in window_from_coordinates.
1154 Check if window W contains coordinates specified by USER_DATA which
1155 is actually a pointer to a struct check_window_data CW.
1157 Check if window W contains coordinates *CW->x and *CW->y. If it
1158 does, return W in *CW->window, as Lisp_Object, and return in
1159 *CW->part the part of the window under coordinates *X,*Y. Return
1160 zero from this function to stop iterating over windows. */
1162 struct check_window_data
1164 Lisp_Object
*window
;
1166 enum window_part
*part
;
1170 check_window_containing (struct window
*w
, void *user_data
)
1172 struct check_window_data
*cw
= (struct check_window_data
*) user_data
;
1173 enum window_part found
;
1176 found
= coordinates_in_window (w
, cw
->x
, cw
->y
);
1177 if (found
!= ON_NOTHING
)
1180 XSETWINDOW (*cw
->window
, w
);
1188 /* Find the window containing frame-relative pixel position X/Y and
1189 return it as a Lisp_Object.
1191 If X, Y is on one of the window's special `window_part' elements,
1192 set *PART to the id of that element, and return X and Y converted
1193 to window relative coordinates in WX and WY.
1195 If there is no window under X, Y return nil and leave *PART
1196 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
1198 This function was previously implemented with a loop cycling over
1199 windows with Fnext_window, and starting with the frame's selected
1200 window. It turned out that this doesn't work with an
1201 implementation of next_window using Vwindow_list, because
1202 FRAME_SELECTED_WINDOW (F) is not always contained in the window
1203 tree of F when this function is called asynchronously from
1204 note_mouse_highlight. The original loop didn't terminate in this
1208 window_from_coordinates (struct frame
*f
, int x
, int y
, enum window_part
*part
, int *wx
, int *wy
, int tool_bar_p
)
1211 struct check_window_data cw
;
1212 enum window_part dummy
;
1218 cw
.window
= &window
, cw
.x
= &x
, cw
.y
= &y
; cw
.part
= part
;
1219 foreach_window (f
, check_window_containing
, &cw
);
1221 /* If not found above, see if it's in the tool bar window, if a tool
1225 && WINDOWP (f
->tool_bar_window
)
1226 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)) > 0
1227 && (coordinates_in_window (XWINDOW (f
->tool_bar_window
), &x
, &y
)
1231 window
= f
->tool_bar_window
;
1240 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
1241 doc
: /* Return window containing coordinates X and Y on FRAME.
1242 FRAME must be a live frame and defaults to the selected one.
1243 The top left corner of the frame is considered to be row 0,
1245 (Lisp_Object x
, Lisp_Object y
, Lisp_Object frame
)
1250 frame
= selected_frame
;
1251 CHECK_LIVE_FRAME (frame
);
1254 /* Check that arguments are integers or floats. */
1255 CHECK_NUMBER_OR_FLOAT (x
);
1256 CHECK_NUMBER_OR_FLOAT (y
);
1258 return window_from_coordinates (f
,
1259 (FRAME_PIXEL_X_FROM_CANON_X (f
, x
)
1260 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1261 (FRAME_PIXEL_Y_FROM_CANON_Y (f
, y
)
1262 + FRAME_INTERNAL_BORDER_WIDTH (f
)),
1266 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
1267 doc
: /* Return current value of point in WINDOW.
1268 WINDOW must be a live window and defaults to the selected one.
1270 For a nonselected window, this is the value point would have
1271 if that window were selected.
1273 Note that, when WINDOW is the selected window and its buffer
1274 is also currently selected, the value returned is the same as (point).
1275 It would be more strictly correct to return the `top-level' value
1276 of point, outside of any save-excursion forms.
1277 But that is hard to define. */)
1278 (Lisp_Object window
)
1280 register struct window
*w
= decode_window (window
);
1282 if (w
== XWINDOW (selected_window
)
1283 && current_buffer
== XBUFFER (w
->buffer
))
1285 return Fmarker_position (w
->pointm
);
1288 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
1289 doc
: /* Return position at which display currently starts in WINDOW.
1290 WINDOW must be a live window and defaults to the selected one.
1291 This is updated by redisplay or by calling `set-window-start'. */)
1292 (Lisp_Object window
)
1294 return Fmarker_position (decode_window (window
)->start
);
1297 /* This is text temporarily removed from the doc string below.
1299 This function returns nil if the position is not currently known.
1300 That happens when redisplay is preempted and doesn't finish.
1301 If in that case you want to compute where the end of the window would
1302 have been if redisplay had finished, do this:
1304 (goto-char (window-start window))
1305 (vertical-motion (1- (window-height window)) window)
1308 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
1309 doc
: /* Return position at which display currently ends in WINDOW.
1310 WINDOW must be a live window and defaults to the selected one.
1311 This is updated by redisplay, when it runs to completion.
1312 Simply changing the buffer text or setting `window-start'
1313 does not update this value.
1314 Return nil if there is no recorded value. \(This can happen if the
1315 last redisplay of WINDOW was preempted, and did not finish.)
1316 If UPDATE is non-nil, compute the up-to-date position
1317 if it isn't already recorded. */)
1318 (Lisp_Object window
, Lisp_Object update
)
1321 struct window
*w
= decode_window (window
);
1329 #if 0 /* This change broke some things. We should make it later. */
1330 /* If we don't know the end position, return nil.
1331 The user can compute it with vertical-motion if he wants to.
1332 It would be nicer to do it automatically,
1333 but that's so slow that it would probably bother people. */
1334 if (NILP (w
->window_end_valid
))
1339 && ! (! NILP (w
->window_end_valid
)
1340 && XFASTINT (w
->last_modified
) >= BUF_MODIFF (b
)
1341 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (b
))
1344 struct text_pos startp
;
1346 struct buffer
*old_buffer
= NULL
;
1348 /* Cannot use Fvertical_motion because that function doesn't
1349 cope with variable-height lines. */
1350 if (b
!= current_buffer
)
1352 old_buffer
= current_buffer
;
1353 set_buffer_internal (b
);
1356 /* In case W->start is out of the range, use something
1357 reasonable. This situation occurred when loading a file with
1358 `-l' containing a call to `rmail' with subsequent other
1359 commands. At the end, W->start happened to be BEG, while
1360 rmail had already narrowed the buffer. */
1361 if (XMARKER (w
->start
)->charpos
< BEGV
)
1362 SET_TEXT_POS (startp
, BEGV
, BEGV_BYTE
);
1363 else if (XMARKER (w
->start
)->charpos
> ZV
)
1364 SET_TEXT_POS (startp
, ZV
, ZV_BYTE
);
1366 SET_TEXT_POS_FROM_MARKER (startp
, w
->start
);
1368 start_display (&it
, w
, startp
);
1369 move_it_vertically (&it
, window_box_height (w
));
1370 if (it
.current_y
< it
.last_visible_y
)
1371 move_it_past_eol (&it
);
1372 value
= make_number (IT_CHARPOS (it
));
1375 set_buffer_internal (old_buffer
);
1378 XSETINT (value
, BUF_Z (b
) - XFASTINT (w
->window_end_pos
));
1383 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
1384 doc
: /* Make point value in WINDOW be at position POS in WINDOW's buffer.
1386 (Lisp_Object window
, Lisp_Object pos
)
1388 register struct window
*w
= decode_window (window
);
1390 CHECK_NUMBER_COERCE_MARKER (pos
);
1391 if (w
== XWINDOW (selected_window
)
1392 && XBUFFER (w
->buffer
) == current_buffer
)
1395 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
1397 /* We have to make sure that redisplay updates the window to show
1398 the new value of point. */
1399 if (!EQ (window
, selected_window
))
1400 ++windows_or_buffers_changed
;
1405 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
1406 doc
: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1407 WINDOW defaults to the selected window. Return POS.
1408 Optional third arg NOFORCE non-nil inhibits next redisplay from
1409 overriding motion of point in order to display at this exact start. */)
1410 (Lisp_Object window
, Lisp_Object pos
, Lisp_Object noforce
)
1412 register struct window
*w
= decode_window (window
);
1414 CHECK_NUMBER_COERCE_MARKER (pos
);
1415 set_marker_restricted (w
->start
, pos
, w
->buffer
);
1416 /* this is not right, but much easier than doing what is right. */
1417 w
->start_at_line_beg
= Qnil
;
1419 w
->force_start
= Qt
;
1420 w
->update_mode_line
= Qt
;
1421 XSETFASTINT (w
->last_modified
, 0);
1422 XSETFASTINT (w
->last_overlay_modified
, 0);
1423 if (!EQ (window
, selected_window
))
1424 windows_or_buffers_changed
++;
1429 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
1430 Spos_visible_in_window_p
, 0, 3, 0,
1431 doc
: /* Return non-nil if position POS is currently in WINDOW.
1432 Return nil if that position is scrolled vertically out of view.
1433 If a character is only partially visible, nil is returned, unless the
1434 optional argument PARTIALLY is non-nil.
1435 If POS is only out of view because of horizontal scrolling, return non-nil.
1436 If POS is t, it specifies the position of the last visible glyph in WINDOW.
1437 POS defaults to point in WINDOW; WINDOW defaults to the selected window.
1439 If POS is visible, return t if PARTIALLY is nil; if PARTIALLY is non-nil,
1440 return value is a list of 2 or 6 elements (X Y [RTOP RBOT ROWH VPOS]),
1441 where X and Y are the pixel coordinates relative to the top left corner
1442 of the window. The remaining elements are omitted if the character after
1443 POS is fully visible; otherwise, RTOP and RBOT are the number of pixels
1444 off-window at the top and bottom of the row, ROWH is the height of the
1445 display row, and VPOS is the row number (0-based) containing POS. */)
1446 (Lisp_Object pos
, Lisp_Object window
, Lisp_Object partially
)
1448 register struct window
*w
;
1449 register int posint
;
1450 register struct buffer
*buf
;
1451 struct text_pos top
;
1452 Lisp_Object in_window
= Qnil
;
1453 int rtop
, rbot
, rowh
, vpos
, fully_p
= 1;
1456 w
= decode_window (window
);
1457 buf
= XBUFFER (w
->buffer
);
1458 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
1462 else if (!NILP (pos
))
1464 CHECK_NUMBER_COERCE_MARKER (pos
);
1465 posint
= XINT (pos
);
1467 else if (w
== XWINDOW (selected_window
))
1470 posint
= XMARKER (w
->pointm
)->charpos
;
1472 /* If position is above window start or outside buffer boundaries,
1473 or if window start is out of range, position is not visible. */
1474 if ((EQ (pos
, Qt
) || (posint
>= CHARPOS (top
) && posint
<= BUF_ZV (buf
)))
1475 && CHARPOS (top
) >= BUF_BEGV (buf
)
1476 && CHARPOS (top
) <= BUF_ZV (buf
)
1477 && pos_visible_p (w
, posint
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
)
1478 && (fully_p
= !rtop
&& !rbot
, (!NILP (partially
) || fully_p
)))
1481 if (!NILP (in_window
) && !NILP (partially
))
1483 Lisp_Object part
= Qnil
;
1485 part
= list4 (make_number (rtop
), make_number (rbot
),
1486 make_number (rowh
), make_number (vpos
));
1487 in_window
= Fcons (make_number (x
),
1488 Fcons (make_number (y
), part
));
1494 DEFUN ("window-line-height", Fwindow_line_height
,
1495 Swindow_line_height
, 0, 2, 0,
1496 doc
: /* Return height in pixels of text line LINE in window WINDOW.
1497 WINDOW defaults to the selected window.
1499 Return height of current line if LINE is omitted or nil. Return height of
1500 header or mode line if LINE is `header-line' or `mode-line'.
1501 Otherwise, LINE is a text line number starting from 0. A negative number
1502 counts from the end of the window.
1504 Value is a list (HEIGHT VPOS YPOS OFFBOT), where HEIGHT is the height
1505 in pixels of the visible part of the line, VPOS and YPOS are the
1506 vertical position in lines and pixels of the line, relative to the top
1507 of the first text line, and OFFBOT is the number of off-window pixels at
1508 the bottom of the text line. If there are off-window pixels at the top
1509 of the (first) text line, YPOS is negative.
1511 Return nil if window display is not up-to-date. In that case, use
1512 `pos-visible-in-window-p' to obtain the information. */)
1513 (Lisp_Object line
, Lisp_Object window
)
1515 register struct window
*w
;
1516 register struct buffer
*b
;
1517 struct glyph_row
*row
, *end_row
;
1518 int max_y
, crop
, i
, n
;
1520 w
= decode_window (window
);
1522 if (noninteractive
|| w
->pseudo_window_p
)
1525 CHECK_BUFFER (w
->buffer
);
1526 b
= XBUFFER (w
->buffer
);
1528 /* Fail if current matrix is not up-to-date. */
1529 if (NILP (w
->window_end_valid
)
1530 || current_buffer
->clip_changed
1531 || current_buffer
->prevent_redisplay_optimizations_p
1532 || XFASTINT (w
->last_modified
) < BUF_MODIFF (b
)
1533 || XFASTINT (w
->last_overlay_modified
) < BUF_OVERLAY_MODIFF (b
))
1539 if (i
< 0 || i
>= w
->current_matrix
->nrows
1540 || (row
= MATRIX_ROW (w
->current_matrix
, i
), !row
->enabled_p
))
1542 max_y
= window_text_bottom_y (w
);
1546 if (EQ (line
, Qheader_line
))
1548 if (!WINDOW_WANTS_HEADER_LINE_P (w
))
1550 row
= MATRIX_HEADER_LINE_ROW (w
->current_matrix
);
1551 if (!row
->enabled_p
)
1553 return list4 (make_number (row
->height
),
1554 make_number (0), make_number (0),
1558 if (EQ (line
, Qmode_line
))
1560 row
= MATRIX_MODE_LINE_ROW (w
->current_matrix
);
1561 if (!row
->enabled_p
)
1563 return list4 (make_number (row
->height
),
1564 make_number (0), /* not accurate */
1565 make_number (WINDOW_HEADER_LINE_HEIGHT (w
)
1566 + window_text_bottom_y (w
)),
1570 CHECK_NUMBER (line
);
1573 row
= MATRIX_FIRST_TEXT_ROW (w
->current_matrix
);
1574 end_row
= MATRIX_BOTTOM_TEXT_ROW (w
->current_matrix
, w
);
1575 max_y
= window_text_bottom_y (w
);
1578 while ((n
< 0 || i
< n
)
1579 && row
<= end_row
&& row
->enabled_p
1580 && row
->y
+ row
->height
< max_y
)
1583 if (row
> end_row
|| !row
->enabled_p
)
1595 crop
= max (0, (row
->y
+ row
->height
) - max_y
);
1596 return list4 (make_number (row
->height
+ min (0, row
->y
) - crop
),
1598 make_number (row
->y
),
1599 make_number (crop
));
1602 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
1604 doc
: /* Return non-nil when WINDOW is dedicated to its buffer.
1605 More precisely, return the value assigned by the last call of
1606 `set-window-dedicated-p' for WINDOW. Return nil if that function was
1607 never called with WINDOW as its argument, or the value set by that
1608 function was internally reset since its last call. WINDOW defaults to
1609 the selected window.
1611 When a window is dedicated to its buffer, `display-buffer' will refrain
1612 from displaying another buffer in it. `get-lru-window' and
1613 `get-largest-window' treat dedicated windows specially.
1614 `delete-windows-on', `replace-buffer-in-windows', `quit-window' and
1615 `kill-buffer' can delete a dedicated window and the containing frame.
1617 Functions like `set-window-buffer' may change the buffer displayed by a
1618 window, unless that window is "strongly" dedicated to its buffer, that
1619 is the value returned by `window-dedicated-p' is t. */)
1620 (Lisp_Object window
)
1622 return decode_window (window
)->dedicated
;
1625 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
1626 Sset_window_dedicated_p
, 2, 2, 0,
1627 doc
: /* Mark WINDOW as dedicated according to FLAG.
1628 WINDOW must be a live window and defaults to the selected one. FLAG
1629 non-nil means mark WINDOW as dedicated to its buffer. FLAG nil means
1630 mark WINDOW as non-dedicated. Return FLAG.
1632 When a window is dedicated to its buffer, `display-buffer' will refrain
1633 from displaying another buffer in it. `get-lru-window' and
1634 `get-largest-window' treat dedicated windows specially.
1635 `delete-windows-on', `replace-buffer-in-windows', `quit-window',
1636 `quit-restore-window' and `kill-buffer' can delete a dedicated window
1637 and the containing frame.
1639 As a special case, if FLAG is t, mark WINDOW as "strongly" dedicated to
1640 its buffer. Functions like `set-window-buffer' may change the buffer
1641 displayed by a window, unless that window is strongly dedicated to its
1642 buffer. If and when `set-window-buffer' displays another buffer in a
1643 window, it also makes sure that the window is no more dedicated. */)
1644 (Lisp_Object window
, Lisp_Object flag
)
1646 register struct window
*w
= decode_window (window
);
1648 w
->dedicated
= flag
;
1649 return w
->dedicated
;
1652 DEFUN ("window-parameters", Fwindow_parameters
, Swindow_parameters
,
1654 doc
: /* Return the parameters of WINDOW and their values.
1655 WINDOW defaults to the selected window. The return value is a list of
1656 elements of the form (PARAMETER . VALUE). */)
1657 (Lisp_Object window
)
1659 return Fcopy_alist (decode_any_window (window
)->window_parameters
);
1662 DEFUN ("window-parameter", Fwindow_parameter
, Swindow_parameter
,
1664 doc
: /* Return WINDOW's value for PARAMETER.
1665 WINDOW defaults to the selected window. */)
1666 (Lisp_Object window
, Lisp_Object parameter
)
1670 result
= Fassq (parameter
, decode_any_window (window
)->window_parameters
);
1671 return CDR_SAFE (result
);
1674 DEFUN ("set-window-parameter", Fset_window_parameter
,
1675 Sset_window_parameter
, 3, 3, 0,
1676 doc
: /* Set WINDOW's value of PARAMETER to VALUE.
1677 WINDOW defaults to the selected window. Return VALUE. */)
1678 (Lisp_Object window
, Lisp_Object parameter
, Lisp_Object value
)
1680 register struct window
*w
= decode_any_window (window
);
1681 Lisp_Object old_alist_elt
;
1683 old_alist_elt
= Fassq (parameter
, w
->window_parameters
);
1684 if (NILP (old_alist_elt
))
1685 w
->window_parameters
= Fcons (Fcons (parameter
, value
), w
->window_parameters
);
1687 Fsetcdr (old_alist_elt
, value
);
1691 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
1693 doc
: /* Return the display-table that WINDOW is using.
1694 WINDOW defaults to the selected window. */)
1695 (Lisp_Object window
)
1697 return decode_window (window
)->display_table
;
1700 /* Get the display table for use on window W. This is either W's
1701 display table or W's buffer's display table. Ignore the specified
1702 tables if they are not valid; if no valid table is specified,
1705 struct Lisp_Char_Table
*
1706 window_display_table (struct window
*w
)
1708 struct Lisp_Char_Table
*dp
= NULL
;
1710 if (DISP_TABLE_P (w
->display_table
))
1711 dp
= XCHAR_TABLE (w
->display_table
);
1712 else if (BUFFERP (w
->buffer
))
1714 struct buffer
*b
= XBUFFER (w
->buffer
);
1716 if (DISP_TABLE_P (b
->display_table
))
1717 dp
= XCHAR_TABLE (b
->display_table
);
1718 else if (DISP_TABLE_P (Vstandard_display_table
))
1719 dp
= XCHAR_TABLE (Vstandard_display_table
);
1725 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
1726 doc
: /* Set WINDOW's display-table to TABLE. */)
1727 (register Lisp_Object window
, Lisp_Object table
)
1729 register struct window
*w
;
1731 w
= decode_window (window
);
1732 w
->display_table
= table
;
1736 /* Record info on buffer window W is displaying
1737 when it is about to cease to display that buffer. */
1739 unshow_buffer (register struct window
*w
)
1746 if (b
!= XMARKER (w
->pointm
)->buffer
)
1750 if (w
== XWINDOW (selected_window
)
1751 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
1752 /* Do this except when the selected window's buffer
1753 is being removed from some other window. */
1755 /* last_window_start records the start position that this buffer
1756 had in the last window to be disconnected from it.
1757 Now that this statement is unconditional,
1758 it is possible for the buffer to be displayed in the
1759 selected window, while last_window_start reflects another
1760 window which was recently showing the same buffer.
1761 Some people might say that might be a good thing. Let's see. */
1762 b
->last_window_start
= marker_position (w
->start
);
1764 /* Point in the selected window's buffer
1765 is actually stored in that buffer, and the window's pointm isn't used.
1766 So don't clobber point in that buffer. */
1767 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
)
1768 /* This line helps to fix Horsley's testbug.el bug. */
1769 && !(WINDOWP (b
->last_selected_window
)
1770 && w
!= XWINDOW (b
->last_selected_window
)
1771 && EQ (buf
, XWINDOW (b
->last_selected_window
)->buffer
)))
1772 temp_set_point_both (b
,
1773 clip_to_bounds (BUF_BEGV (b
),
1774 XMARKER (w
->pointm
)->charpos
,
1776 clip_to_bounds (BUF_BEGV_BYTE (b
),
1777 marker_byte_position (w
->pointm
),
1780 if (WINDOWP (b
->last_selected_window
)
1781 && w
== XWINDOW (b
->last_selected_window
))
1782 b
->last_selected_window
= Qnil
;
1785 /* Put NEW into the window structure in place of OLD. SETFLAG zero
1786 means change window structure only. Otherwise store geometry and
1787 other settings as well. */
1789 replace_window (Lisp_Object old
, Lisp_Object
new, int setflag
)
1791 register Lisp_Object tem
;
1792 register struct window
*o
= XWINDOW (old
), *n
= XWINDOW (new);
1794 /* If OLD is its frame's root window, then NEW is the new
1795 root window for that frame. */
1796 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
1797 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = new;
1801 n
->left_col
= o
->left_col
;
1802 n
->top_line
= o
->top_line
;
1803 n
->total_cols
= o
->total_cols
;
1804 n
->total_lines
= o
->total_lines
;
1805 n
->normal_cols
= o
->normal_cols
;
1806 XSETFASTINT (o
->normal_cols
, 1); /* !!! */
1807 n
->normal_lines
= o
->normal_lines
;
1808 XSETFASTINT (o
->normal_lines
, 1); /* !!! */
1809 n
->desired_matrix
= n
->current_matrix
= 0;
1811 memset (&n
->cursor
, 0, sizeof (n
->cursor
));
1812 memset (&n
->last_cursor
, 0, sizeof (n
->last_cursor
));
1813 memset (&n
->phys_cursor
, 0, sizeof (n
->phys_cursor
));
1814 n
->phys_cursor_type
= -1;
1815 n
->phys_cursor_width
= -1;
1816 n
->must_be_updated_p
= 0;
1817 n
->pseudo_window_p
= 0;
1818 XSETFASTINT (n
->window_end_vpos
, 0);
1819 XSETFASTINT (n
->window_end_pos
, 0);
1820 n
->window_end_valid
= Qnil
;
1821 n
->frozen_window_start_p
= 0;
1824 n
->next
= tem
= o
->next
;
1826 XWINDOW (tem
)->prev
= new;
1828 n
->prev
= tem
= o
->prev
;
1830 XWINDOW (tem
)->next
= new;
1832 n
->parent
= tem
= o
->parent
;
1835 if (EQ (XWINDOW (tem
)->vchild
, old
))
1836 XWINDOW (tem
)->vchild
= new;
1837 if (EQ (XWINDOW (tem
)->hchild
, old
))
1838 XWINDOW (tem
)->hchild
= new;
1842 /* If window WINDOW and its parent window are iso-combined, merge
1843 WINDOW's children into those of its parent window and mark WINDOW as
1847 recombine_windows (Lisp_Object window
)
1849 struct window
*w
, *p
, *c
;
1850 Lisp_Object parent
, child
;
1853 w
= XWINDOW (window
);
1855 if (NILP (w
->inhibit_recombine
) && !NILP (parent
))
1857 p
= XWINDOW (parent
);
1858 if (((!NILP (p
->vchild
) && !NILP (w
->vchild
))
1859 || (!NILP (p
->hchild
) && !NILP (w
->hchild
))))
1860 /* WINDOW and PARENT are both either a vertical or a horizontal
1863 horflag
= NILP (w
->vchild
);
1864 child
= horflag
? w
->hchild
: w
->vchild
;
1865 c
= XWINDOW (child
);
1867 /* Splice WINDOW's children into its parent's children and
1868 assign new normal sizes. */
1877 XWINDOW (w
->prev
)->next
= child
;
1886 = make_float (XFLOATINT (c
->total_cols
)
1887 / XFLOATINT (p
->total_cols
));
1890 = make_float (XFLOATINT (c
->total_lines
)
1891 / XFLOATINT (p
->total_lines
));
1895 if (!NILP (w
->next
))
1898 XWINDOW (c
->next
)->prev
= child
;
1906 c
= XWINDOW (child
);
1910 /* WINDOW can be deleted now. */
1911 w
->vchild
= w
->hchild
= Qnil
;
1917 /* If WINDOW can be deleted, delete it. */
1919 delete_deletable_window (Lisp_Object window
)
1921 if (!NILP (call1 (Qwindow_deletable_p
, window
)))
1922 call1 (Qdelete_window
, window
);
1925 /***********************************************************************
1927 ***********************************************************************/
1929 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1930 pointer. This is a callback function for foreach_window, used in
1931 the window_list function. */
1934 add_window_to_list (struct window
*w
, void *user_data
)
1936 Lisp_Object
*list
= (Lisp_Object
*) user_data
;
1938 XSETWINDOW (window
, w
);
1939 *list
= Fcons (window
, *list
);
1944 /* Return a list of all windows, for use by next_window. If
1945 Vwindow_list is a list, return that list. Otherwise, build a new
1946 list, cache it in Vwindow_list, and return that. */
1951 if (!CONSP (Vwindow_list
))
1955 Vwindow_list
= Qnil
;
1956 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1958 Lisp_Object args
[2];
1960 /* We are visiting windows in canonical order, and add
1961 new windows at the front of args[1], which means we
1962 have to reverse this list at the end. */
1964 foreach_window (XFRAME (XCAR (tail
)), add_window_to_list
, &args
[1]);
1965 args
[0] = Vwindow_list
;
1966 args
[1] = Fnreverse (args
[1]);
1967 Vwindow_list
= Fnconc (2, args
);
1971 return Vwindow_list
;
1975 /* Value is non-zero if WINDOW satisfies the constraints given by
1976 OWINDOW, MINIBUF and ALL_FRAMES.
1978 MINIBUF t means WINDOW may be minibuffer windows.
1979 `lambda' means WINDOW may not be a minibuffer window.
1980 a window means a specific minibuffer window
1982 ALL_FRAMES t means search all frames,
1983 nil means search just current frame,
1984 `visible' means search just visible frames,
1985 0 means search visible and iconified frames,
1986 a window means search the frame that window belongs to,
1987 a frame means consider windows on that frame, only. */
1990 candidate_window_p (Lisp_Object window
, Lisp_Object owindow
, Lisp_Object minibuf
, Lisp_Object all_frames
)
1992 struct window
*w
= XWINDOW (window
);
1993 struct frame
*f
= XFRAME (w
->frame
);
1994 int candidate_p
= 1;
1996 if (!BUFFERP (w
->buffer
))
1998 else if (MINI_WINDOW_P (w
)
1999 && (EQ (minibuf
, Qlambda
)
2000 || (WINDOWP (minibuf
) && !EQ (minibuf
, window
))))
2002 /* If MINIBUF is `lambda' don't consider any mini-windows.
2003 If it is a window, consider only that one. */
2006 else if (EQ (all_frames
, Qt
))
2008 else if (NILP (all_frames
))
2010 xassert (WINDOWP (owindow
));
2011 candidate_p
= EQ (w
->frame
, XWINDOW (owindow
)->frame
);
2013 else if (EQ (all_frames
, Qvisible
))
2015 FRAME_SAMPLE_VISIBILITY (f
);
2016 candidate_p
= FRAME_VISIBLE_P (f
)
2017 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2018 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2021 else if (INTEGERP (all_frames
) && XINT (all_frames
) == 0)
2023 FRAME_SAMPLE_VISIBILITY (f
);
2024 candidate_p
= (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
)
2025 #ifdef HAVE_X_WINDOWS
2026 /* Yuck!! If we've just created the frame and the
2027 window-manager requested the user to place it
2028 manually, the window may still not be considered
2029 `visible'. I'd argue it should be at least
2030 something like `iconified', but don't know how to do
2032 || (FRAME_X_P (f
) && f
->output_data
.x
->asked_for_visible
2033 && !f
->output_data
.x
->has_been_visible
)
2036 && (FRAME_TERMINAL (XFRAME (w
->frame
))
2037 == FRAME_TERMINAL (XFRAME (selected_frame
)));
2039 else if (WINDOWP (all_frames
))
2040 candidate_p
= (EQ (FRAME_MINIBUF_WINDOW (f
), all_frames
)
2041 || EQ (XWINDOW (all_frames
)->frame
, w
->frame
)
2042 || EQ (XWINDOW (all_frames
)->frame
, FRAME_FOCUS_FRAME (f
)));
2043 else if (FRAMEP (all_frames
))
2044 candidate_p
= EQ (all_frames
, w
->frame
);
2050 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
2051 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
2055 decode_next_window_args (Lisp_Object
*window
, Lisp_Object
*minibuf
, Lisp_Object
*all_frames
)
2058 *window
= selected_window
;
2060 CHECK_LIVE_WINDOW (*window
);
2062 /* MINIBUF nil may or may not include minibuffers. Decide if it
2064 if (NILP (*minibuf
))
2065 *minibuf
= minibuf_level
? minibuf_window
: Qlambda
;
2066 else if (!EQ (*minibuf
, Qt
))
2069 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
2070 => count none of them, or a specific minibuffer window (the
2071 active one) to count. */
2073 /* ALL_FRAMES nil doesn't specify which frames to include. */
2074 if (NILP (*all_frames
))
2075 *all_frames
= (!EQ (*minibuf
, Qlambda
)
2076 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window
)->frame
))
2078 else if (EQ (*all_frames
, Qvisible
))
2080 else if (EQ (*all_frames
, make_number (0)))
2082 else if (FRAMEP (*all_frames
))
2084 else if (!EQ (*all_frames
, Qt
))
2087 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
2088 search just current frame, `visible' meaning search just visible
2089 frames, 0 meaning search visible and iconified frames, or a
2090 window, meaning search the frame that window belongs to, or a
2091 frame, meaning consider windows on that frame, only. */
2095 /* Return the next or previous window of WINDOW in cyclic ordering
2096 of windows. NEXT_P non-zero means return the next window. See the
2097 documentation string of next-window for the meaning of MINIBUF and
2101 next_window (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
, int next_p
)
2103 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2105 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
2106 return the first window on the frame. */
2107 if (FRAMEP (all_frames
)
2108 && !EQ (all_frames
, XWINDOW (window
)->frame
))
2109 return Fframe_first_window (all_frames
);
2115 /* Find WINDOW in the list of all windows. */
2116 list
= Fmemq (window
, window_list ());
2118 /* Scan forward from WINDOW to the end of the window list. */
2120 for (list
= XCDR (list
); CONSP (list
); list
= XCDR (list
))
2121 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2124 /* Scan from the start of the window list up to WINDOW. */
2126 for (list
= Vwindow_list
;
2127 CONSP (list
) && !EQ (XCAR (list
), window
);
2129 if (candidate_window_p (XCAR (list
), window
, minibuf
, all_frames
))
2133 window
= XCAR (list
);
2137 Lisp_Object candidate
, list
;
2139 /* Scan through the list of windows for candidates. If there are
2140 candidate windows in front of WINDOW, the last one of these
2141 is the one we want. If there are candidates following WINDOW
2142 in the list, again the last one of these is the one we want. */
2144 for (list
= window_list (); CONSP (list
); list
= XCDR (list
))
2146 if (EQ (XCAR (list
), window
))
2148 if (WINDOWP (candidate
))
2151 else if (candidate_window_p (XCAR (list
), window
, minibuf
,
2153 candidate
= XCAR (list
);
2156 if (WINDOWP (candidate
))
2164 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
2165 doc
: /* Return window following WINDOW in cyclic ordering of windows.
2166 WINDOW must be a live window and defaults to the selected one. The
2167 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2170 MINIBUF nil or omitted means consider the minibuffer window only if the
2171 minibuffer is active. MINIBUF t means consider the minibuffer window
2172 even if the minibuffer is not active. Any other value means do not
2173 consider the minibuffer window even if the minibuffer is active.
2175 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2176 plus the minibuffer window if specified by the MINIBUF argument. If the
2177 minibuffer counts, consider all windows on all frames that share that
2178 minibuffer too. The following non-nil values of ALL-FRAMES have special
2181 - t means consider all windows on all existing frames.
2183 - `visible' means consider all windows on all visible frames.
2185 - 0 (the number zero) means consider all windows on all visible and
2188 - A frame means consider all windows on that frame only.
2190 Anything else means consider all windows on WINDOW's frame and no
2193 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
2194 `next-window' to iterate through the entire cycle of acceptable
2195 windows, eventually ending up back at the window you started with.
2196 `previous-window' traverses the same cycle, in the reverse order. */)
2197 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2199 return next_window (window
, minibuf
, all_frames
, 1);
2203 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
2204 doc
: /* Return window preceding WINDOW in cyclic ordering of windows.
2205 WINDOW must be a live window and defaults to the selected one. The
2206 optional arguments MINIBUF and ALL-FRAMES specify the set of windows to
2209 MINIBUF nil or omitted means consider the minibuffer window only if the
2210 minibuffer is active. MINIBUF t means consider the minibuffer window
2211 even if the minibuffer is not active. Any other value means do not
2212 consider the minibuffer window even if the minibuffer is active.
2214 ALL-FRAMES nil or omitted means consider all windows on WINDOW's frame,
2215 plus the minibuffer window if specified by the MINIBUF argument. If the
2216 minibuffer counts, consider all windows on all frames that share that
2217 minibuffer too. The following non-nil values of ALL-FRAMES have special
2220 - t means consider all windows on all existing frames.
2222 - `visible' means consider all windows on all visible frames.
2224 - 0 (the number zero) means consider all windows on all visible and
2227 - A frame means consider all windows on that frame only.
2229 Anything else means consider all windows on WINDOW's frame and no
2232 If you use consistent values for MINIBUF and ALL-FRAMES, you can
2233 use `previous-window' to iterate through the entire cycle of
2234 acceptable windows, eventually ending up back at the window you
2235 started with. `next-window' traverses the same cycle, in the
2237 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2239 return next_window (window
, minibuf
, all_frames
, 0);
2243 /* Return a list of windows in cyclic ordering. Arguments are like
2244 for `next-window'. */
2247 window_list_1 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2249 Lisp_Object tail
, list
, rest
;
2251 decode_next_window_args (&window
, &minibuf
, &all_frames
);
2254 for (tail
= window_list (); CONSP (tail
); tail
= XCDR (tail
))
2255 if (candidate_window_p (XCAR (tail
), window
, minibuf
, all_frames
))
2256 list
= Fcons (XCAR (tail
), list
);
2258 /* Rotate the list to start with WINDOW. */
2259 list
= Fnreverse (list
);
2260 rest
= Fmemq (window
, list
);
2261 if (!NILP (rest
) && !EQ (rest
, list
))
2263 for (tail
= list
; !EQ (XCDR (tail
), rest
); tail
= XCDR (tail
))
2265 XSETCDR (tail
, Qnil
);
2266 list
= nconc2 (rest
, list
);
2272 DEFUN ("window-list", Fwindow_list
, Swindow_list
, 0, 3, 0,
2273 doc
: /* Return a list of windows on FRAME, starting with WINDOW.
2274 FRAME nil or omitted means use the selected frame.
2275 WINDOW nil or omitted means use the selected window.
2276 MINIBUF t means include the minibuffer window, even if it isn't active.
2277 MINIBUF nil or omitted means include the minibuffer window only
2279 MINIBUF neither nil nor t means never include the minibuffer window. */)
2280 (Lisp_Object frame
, Lisp_Object minibuf
, Lisp_Object window
)
2283 window
= FRAMEP (frame
) ? XFRAME (frame
)->selected_window
: selected_window
;
2284 CHECK_WINDOW (window
);
2286 frame
= selected_frame
;
2288 if (!EQ (frame
, XWINDOW (window
)->frame
))
2289 error ("Window is on a different frame");
2291 return window_list_1 (window
, minibuf
, frame
);
2295 DEFUN ("window-list-1", Fwindow_list_1
, Swindow_list_1
, 0, 3, 0,
2296 doc
: /* Return a list of all live windows.
2297 WINDOW specifies the first window to list and defaults to the selected
2300 Optional argument MINIBUF nil or omitted means consider the minibuffer
2301 window only if the minibuffer is active. MINIBUF t means consider the
2302 minibuffer window even if the minibuffer is not active. Any other value
2303 means do not consider the minibuffer window even if the minibuffer is
2306 Optional argument ALL-FRAMES nil or omitted means consider all windows
2307 on WINDOW's frame, plus the minibuffer window if specified by the
2308 MINIBUF argument. If the minibuffer counts, consider all windows on all
2309 frames that share that minibuffer too. The following non-nil values of
2310 ALL-FRAMES have special meanings:
2312 - t means consider all windows on all existing frames.
2314 - `visible' means consider all windows on all visible frames.
2316 - 0 (the number zero) means consider all windows on all visible and
2319 - A frame means consider all windows on that frame only.
2321 Anything else means consider all windows on WINDOW's frame and no
2324 If WINDOW is not on the list of windows returned, some other window will
2325 be listed first but no error is signalled. */)
2326 (Lisp_Object window
, Lisp_Object minibuf
, Lisp_Object all_frames
)
2328 return window_list_1 (window
, minibuf
, all_frames
);
2331 /* Look at all windows, performing an operation specified by TYPE
2333 If FRAMES is Qt, look at all frames;
2334 Qnil, look at just the selected frame;
2335 Qvisible, look at visible frames;
2336 a frame, just look at windows on that frame.
2337 If MINI is non-zero, perform the operation on minibuffer windows too. */
2342 GET_BUFFER_WINDOW
, /* Arg is buffer */
2343 UNSHOW_BUFFER
, /* Arg is buffer */
2344 REDISPLAY_BUFFER_WINDOWS
, /* Arg is buffer */
2348 /* Make WINDOW show another buffer. */
2350 window_show_other_buffer (Lisp_Object window
)
2352 struct window
*w
= XWINDOW (window
);
2354 /* Undedicate WINDOW. */
2355 w
->dedicated
= Qnil
;
2356 /* Make WINDOW show the buffer returned by Fother_buffer. */
2358 (window
, Fother_buffer (w
->buffer
, Qnil
, w
->frame
), Qnil
);
2359 /* If WINDOW is the selected window, make its buffer current. But do
2360 so only if the window shows the current buffer (Bug#6454). */
2361 if (EQ (window
, selected_window
)
2362 && XBUFFER (w
->buffer
) == current_buffer
)
2363 Fset_buffer (w
->buffer
);
2369 window_loop (enum window_loop type
, Lisp_Object obj
, int mini
, Lisp_Object frames
)
2371 Lisp_Object window
, windows
, best_window
, frame_arg
;
2373 struct gcpro gcpro1
;
2375 /* If we're only looping through windows on a particular frame,
2376 frame points to that frame. If we're looping through windows
2377 on all frames, frame is 0. */
2378 if (FRAMEP (frames
))
2379 f
= XFRAME (frames
);
2380 else if (NILP (frames
))
2381 f
= SELECTED_FRAME ();
2386 frame_arg
= Qlambda
;
2387 else if (EQ (frames
, make_number (0)))
2389 else if (EQ (frames
, Qvisible
))
2394 /* frame_arg is Qlambda to stick to one frame,
2395 Qvisible to consider all visible frames,
2398 /* Pick a window to start with. */
2402 window
= FRAME_SELECTED_WINDOW (f
);
2404 window
= FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
2406 windows
= window_list_1 (window
, mini
? Qt
: Qnil
, frame_arg
);
2410 for (; CONSP (windows
); windows
= XCDR (windows
))
2414 window
= XCAR (windows
);
2415 w
= XWINDOW (window
);
2417 /* Note that we do not pay attention here to whether the frame
2418 is visible, since Fwindow_list skips non-visible frames if
2419 that is desired, under the control of frame_arg. */
2420 if (!MINI_WINDOW_P (w
)
2421 /* For UNSHOW_BUFFER, we must always consider all windows. */
2422 || type
== UNSHOW_BUFFER
2423 || (mini
&& minibuf_level
> 0))
2426 case GET_BUFFER_WINDOW
:
2427 if (EQ (w
->buffer
, obj
)
2428 /* Don't find any minibuffer window
2429 except the one that is currently in use. */
2430 && (MINI_WINDOW_P (w
) ? EQ (window
, minibuf_window
) : 1))
2432 if (NILP (best_window
))
2433 best_window
= window
;
2434 else if (EQ (window
, selected_window
))
2435 /* Preferably return the selected window. */
2436 RETURN_UNGCPRO (window
);
2437 else if (EQ (XWINDOW (window
)->frame
, selected_frame
))
2438 /* Prefer windows on the current frame. */
2439 best_window
= window
;
2444 if (EQ (w
->buffer
, obj
))
2446 struct frame
*f
= XFRAME (w
->frame
);
2448 /* If this window is dedicated, and in a frame of its own,
2450 if (EQ (window
, FRAME_ROOT_WINDOW (f
))
2451 && !NILP (w
->dedicated
)
2452 && other_visible_frames (f
))
2454 /* Skip the other windows on this frame.
2455 There might be one, the minibuffer! */
2456 while (CONSP (XCDR (windows
))
2457 && EQ (XWINDOW (XCAR (windows
))->frame
,
2458 XWINDOW (XCAR (XCDR (windows
)))->frame
))
2459 windows
= XCDR (windows
);
2461 /* Now we can safely delete the frame. */
2462 delete_frame (w
->frame
, Qnil
);
2463 if (WINDOW_LIVE_P (window
))
2464 /* If the window is still alive, deleting the
2465 frame failed, so show another buffer in it. */
2466 window_show_other_buffer (window
);
2468 else if (!NILP (w
->dedicated
) && !NILP (w
->parent
))
2471 XSETWINDOW (window
, w
);
2472 /* If this window is dedicated and not the only window
2473 in its frame, then kill it. */
2474 delete_deletable_window (window
);
2476 if (WINDOW_LIVE_P (window
))
2477 /* If the window is still alive, deleting the
2478 window failed, so show another buffer in
2480 window_show_other_buffer (window
);
2483 window_show_other_buffer (window
);
2487 case REDISPLAY_BUFFER_WINDOWS
:
2488 if (EQ (w
->buffer
, obj
))
2490 mark_window_display_accurate (window
, 0);
2491 w
->update_mode_line
= Qt
;
2492 XBUFFER (obj
)->prevent_redisplay_optimizations_p
= 1;
2493 ++update_mode_lines
;
2494 best_window
= window
;
2498 /* Check for a window that has a killed buffer. */
2499 case CHECK_ALL_WINDOWS
:
2500 if (! NILP (w
->buffer
)
2501 && NILP (XBUFFER (w
->buffer
)->name
))
2505 case WINDOW_LOOP_UNUSED
:
2514 /* Used for debugging. Abort if any window has a dead buffer. */
2517 check_all_windows (void)
2519 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
2522 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 0, 2, 0,
2523 doc
: /* Return a window currently displaying BUFFER-OR-NAME, or nil if none.
2524 BUFFER-OR-NAME may be a buffer or a buffer name and defaults to
2527 The optional argument ALL-FRAMES specifies the frames to consider:
2529 - t means consider all windows on all existing frames.
2531 - `visible' means consider all windows on all visible frames.
2533 - 0 (the number zero) means consider all windows on all visible
2534 and iconified frames.
2536 - A frame means consider all windows on that frame only.
2538 Any other value of ALL-FRAMES means consider all windows on the
2539 selected frame and no others. */)
2540 (Lisp_Object buffer_or_name
, Lisp_Object all_frames
)
2544 if (NILP (buffer_or_name
))
2545 buffer
= Fcurrent_buffer ();
2547 buffer
= Fget_buffer (buffer_or_name
);
2549 if (BUFFERP (buffer
))
2550 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, all_frames
);
2556 resize_root_window (Lisp_Object window
, Lisp_Object delta
, Lisp_Object horizontal
, Lisp_Object ignore
)
2558 return call4 (Qresize_root_window
, window
, delta
, horizontal
, ignore
);
2562 DEFUN ("delete-other-windows-internal", Fdelete_other_windows_internal
,
2563 Sdelete_other_windows_internal
, 0, 2, "",
2564 doc
: /* Make WINDOW fill its frame.
2565 Only the frame WINDOW is on is affected. WINDOW may be any window and
2566 defaults to the selected one.
2568 Optional argument ROOT, if non-nil, must specify an internal window
2569 containing WINDOW as a subwindow. If this is the case, replace ROOT by
2570 WINDOW and leave alone any windows not contained in ROOT.
2572 When WINDOW is live try to reduce display jumps by keeping the text
2573 previously visible in WINDOW in the same place on the frame. Doing this
2574 depends on the value of (window-start WINDOW), so if calling this
2575 function in a program gives strange scrolling, make sure the
2576 window-start value is reasonable when this function is called. */)
2577 (Lisp_Object window
, Lisp_Object root
)
2579 struct window
*w
, *r
, *s
;
2581 Lisp_Object sibling
, pwindow
, swindow
, delta
;
2582 int startpos
, top
, new_top
, resize_failed
;
2584 w
= decode_any_window (window
);
2585 XSETWINDOW (window
, w
);
2586 f
= XFRAME (w
->frame
);
2589 /* ROOT is the frame's root window. */
2591 root
= FRAME_ROOT_WINDOW (f
);
2595 /* ROOT must be an ancestor of WINDOW. */
2597 r
= decode_any_window (root
);
2598 pwindow
= XWINDOW (window
)->parent
;
2599 while (!NILP (pwindow
))
2600 if (EQ (pwindow
, root
))
2603 pwindow
= XWINDOW (pwindow
)->parent
;
2604 if (!EQ (pwindow
, root
))
2605 error ("Specified root is not an ancestor of specified window");
2608 if (EQ (window
, root
))
2611 /* I don't understand the "top > 0" part below. If we deal with a
2612 standalone minibuffer it would have been caught by the preceding
2614 else if (MINI_WINDOW_P (w
)) /* && top > 0) */
2615 error ("Can't expand minibuffer to full frame");
2617 if (!NILP (w
->buffer
))
2619 startpos
= marker_position (w
->start
);
2620 top
= WINDOW_TOP_EDGE_LINE (w
)
2621 - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2622 /* Make sure WINDOW is the frame's selected window. */
2623 if (!EQ (window
, FRAME_SELECTED_WINDOW (f
)))
2625 if (EQ (selected_frame
, w
->frame
))
2626 Fselect_window (window
, Qnil
);
2628 FRAME_SELECTED_WINDOW (f
) = window
;
2633 /* See if the frame's selected window is a subwindow of WINDOW, by
2634 finding all the selected window's parents and comparing each
2635 one with WINDOW. If it isn't we need a new selected window for
2637 swindow
= FRAME_SELECTED_WINDOW (f
);
2641 while (!NILP (pwindow
) && !EQ (window
, pwindow
))
2642 pwindow
= XWINDOW (pwindow
)->parent
;
2644 if (EQ (window
, pwindow
))
2645 /* If WINDOW is an ancestor of SWINDOW, then SWINDOW is ok
2646 as the new selected window. */
2649 /* Else try the previous window of SWINDOW. */
2650 swindow
= Fprevious_window (swindow
, Qlambda
, Qnil
);
2653 if (!EQ (swindow
, FRAME_SELECTED_WINDOW (f
)))
2655 if (EQ (selected_frame
, w
->frame
))
2656 Fselect_window (swindow
, Qnil
);
2658 FRAME_SELECTED_WINDOW (f
) = swindow
;
2663 free_window_matrices (r
);
2665 windows_or_buffers_changed
++;
2666 Vwindow_list
= Qnil
;
2667 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
2669 if (NILP (w
->buffer
))
2672 /* Resize subwindows vertically. */
2673 XSETINT (delta
, XINT (r
->total_lines
) - XINT (w
->total_lines
));
2674 w
->top_line
= r
->top_line
;
2675 resize_root_window (window
, delta
, Qnil
, Qnil
);
2676 if (resize_window_check (w
, 0))
2677 resize_window_apply (w
, 0);
2680 resize_root_window (window
, delta
, Qnil
, Qt
);
2681 if (resize_window_check (w
, 0))
2682 resize_window_apply (w
, 0);
2687 /* Resize subwindows horizontally. */
2690 w
->left_col
= r
->left_col
;
2691 XSETINT (delta
, XINT (r
->total_cols
) - XINT (w
->total_cols
));
2692 w
->left_col
= r
->left_col
;
2693 resize_root_window (window
, delta
, Qt
, Qnil
);
2694 if (resize_window_check (w
, 1))
2695 resize_window_apply (w
, 1);
2698 resize_root_window (window
, delta
, Qt
, Qt
);
2699 if (resize_window_check (w
, 1))
2700 resize_window_apply (w
, 1);
2707 /* Play safe, if we still can ... */
2710 w
= XWINDOW (window
);
2714 /* Cleanly unlink WINDOW from window-tree. */
2715 if (!NILP (w
->prev
))
2716 /* Get SIBLING above (on the left of) WINDOW. */
2719 s
= XWINDOW (sibling
);
2721 if (!NILP (s
->next
))
2722 XWINDOW (s
->next
)->prev
= sibling
;
2725 /* Get SIBLING below (on the right of) WINDOW. */
2728 s
= XWINDOW (sibling
);
2730 if (!NILP (XWINDOW (w
->parent
)->vchild
))
2731 XWINDOW (w
->parent
)->vchild
= sibling
;
2733 XWINDOW (w
->parent
)->hchild
= sibling
;
2736 /* Delete ROOT and all subwindows of ROOT. */
2737 if (!NILP (r
->vchild
))
2739 delete_all_subwindows (r
->vchild
);
2742 else if (!NILP (r
->hchild
))
2744 delete_all_subwindows (r
->hchild
);
2748 replace_window (root
, window
, 1);
2750 /* This must become SWINDOW anyway ....... */
2751 if (!NILP (w
->buffer
) && !resize_failed
)
2753 /* Try to minimize scrolling, by setting the window start to the
2754 point will cause the text at the old window start to be at the
2755 same place on the frame. But don't try to do this if the
2756 window start is outside the visible portion (as might happen
2757 when the display is not current, due to typeahead). */
2758 new_top
= WINDOW_TOP_EDGE_LINE (w
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
2760 && startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
2761 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
2763 struct position pos
;
2764 struct buffer
*obuf
= current_buffer
;
2766 Fset_buffer (w
->buffer
);
2767 /* This computation used to temporarily move point, but that
2768 can have unwanted side effects due to text properties. */
2769 pos
= *vmotion (startpos
, -top
, w
);
2771 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
2772 w
->window_end_valid
= Qnil
;
2773 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
2774 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
2776 /* We need to do this, so that the window-scroll-functions
2778 w
->optional_new_start
= Qt
;
2780 set_buffer_internal (obuf
);
2787 run_window_configuration_change_hook (f
);
2793 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
2794 Sreplace_buffer_in_windows
,
2795 0, 1, "bReplace buffer in windows: ",
2796 doc
: /* Replace BUFFER-OR-NAME with some other buffer in all windows showing it.
2797 BUFFER-OR-NAME may be a buffer or the name of an existing buffer and
2798 defaults to the current buffer.
2800 When a window showing BUFFER-OR-NAME is dedicated that window is
2801 deleted. If that window is the only window on its frame, that frame is
2802 deleted too when there are other frames left. If there are no other
2803 frames left, some other buffer is displayed in that window. */)
2804 (Lisp_Object buffer_or_name
)
2808 if (NILP (buffer_or_name
))
2809 buffer
= Fcurrent_buffer ();
2812 buffer
= Fget_buffer (buffer_or_name
);
2813 CHECK_BUFFER (buffer
);
2816 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
2821 /* Replace BUFFER with some other buffer in all windows
2822 of all frames, even those on other keyboards. */
2825 replace_buffer_in_all_windows (Lisp_Object buffer
)
2827 Lisp_Object tail
, frame
;
2829 /* A single call to window_loop won't do the job because it only
2830 considers frames on the current keyboard. So loop manually over
2831 frames, and handle each one. */
2832 FOR_EACH_FRAME (tail
, frame
)
2833 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
2836 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2837 minimum allowable size. */
2840 check_frame_size (FRAME_PTR frame
, int *rows
, int *cols
)
2842 /* For height, we have to see:
2843 how many windows the frame has at minimum (one or two),
2844 and whether it has a menu bar or other special stuff at the top. */
2846 = ((FRAME_MINIBUF_ONLY_P (frame
) || ! FRAME_HAS_MINIBUF_P (frame
))
2847 ? MIN_SAFE_WINDOW_HEIGHT
2848 : 2 * MIN_SAFE_WINDOW_HEIGHT
);
2850 if (FRAME_TOP_MARGIN (frame
) > 0)
2851 min_height
+= FRAME_TOP_MARGIN (frame
);
2853 if (*rows
< min_height
)
2855 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
2856 *cols
= MIN_SAFE_WINDOW_WIDTH
;
2859 /* Adjust the margins of window W if text area is too small.
2860 Return 1 if window width is ok after adjustment; 0 if window
2861 is still too narrow. */
2864 adjust_window_margins (struct window
*w
)
2866 int box_cols
= (WINDOW_TOTAL_COLS (w
)
2867 - WINDOW_FRINGE_COLS (w
)
2868 - WINDOW_SCROLL_BAR_COLS (w
));
2869 int margin_cols
= (WINDOW_LEFT_MARGIN_COLS (w
)
2870 + WINDOW_RIGHT_MARGIN_COLS (w
));
2872 if (box_cols
- margin_cols
>= MIN_SAFE_WINDOW_WIDTH
)
2875 if (margin_cols
< 0 || box_cols
< MIN_SAFE_WINDOW_WIDTH
)
2878 /* Window's text area is too narrow, but reducing the window
2879 margins will fix that. */
2880 margin_cols
= box_cols
- MIN_SAFE_WINDOW_WIDTH
;
2881 if (WINDOW_RIGHT_MARGIN_COLS (w
) > 0)
2883 if (WINDOW_LEFT_MARGIN_COLS (w
) > 0)
2884 w
->left_margin_cols
= w
->right_margin_cols
2885 = make_number (margin_cols
/2);
2887 w
->right_margin_cols
= make_number (margin_cols
);
2890 w
->left_margin_cols
= make_number (margin_cols
);
2894 EXFUN (Fset_window_fringes
, 4);
2895 EXFUN (Fset_window_scroll_bars
, 4);
2897 /* The following three routines are needed for running a window's
2898 configuration change hook. */
2900 run_funs (Lisp_Object funs
)
2902 for (; CONSP (funs
); funs
= XCDR (funs
))
2903 if (!EQ (XCAR (funs
), Qt
))
2904 call0 (XCAR (funs
));
2908 select_window_norecord (Lisp_Object window
)
2910 return WINDOW_LIVE_P (window
)
2911 ? Fselect_window (window
, Qt
) : selected_window
;
2915 select_frame_norecord (Lisp_Object frame
)
2917 return FRAME_LIVE_P (XFRAME (frame
))
2918 ? Fselect_frame (frame
, Qt
) : selected_frame
;
2922 run_window_configuration_change_hook (struct frame
*f
)
2924 int count
= SPECPDL_INDEX ();
2925 Lisp_Object frame
, global_wcch
2926 = Fdefault_value (Qwindow_configuration_change_hook
);
2927 XSETFRAME (frame
, f
);
2929 if (NILP (Vrun_hooks
))
2932 if (SELECTED_FRAME () != f
)
2934 record_unwind_protect (select_frame_norecord
, Fselected_frame ());
2935 Fselect_frame (frame
, Qt
);
2938 /* Use the right buffer. Matters when running the local hooks. */
2939 if (current_buffer
!= XBUFFER (Fwindow_buffer (Qnil
)))
2941 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
2942 Fset_buffer (Fwindow_buffer (Qnil
));
2945 /* Look for buffer-local values. */
2947 Lisp_Object windows
= Fwindow_list (frame
, Qlambda
, Qnil
);
2948 for (; CONSP (windows
); windows
= XCDR (windows
))
2950 Lisp_Object window
= XCAR (windows
);
2951 Lisp_Object buffer
= Fwindow_buffer (window
);
2952 if (!NILP (Flocal_variable_p (Qwindow_configuration_change_hook
,
2955 int count
= SPECPDL_INDEX ();
2956 record_unwind_protect (select_window_norecord
, Fselected_window ());
2957 select_window_norecord (window
);
2958 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook
,
2960 unbind_to (count
, Qnil
);
2965 run_funs (global_wcch
);
2966 unbind_to (count
, Qnil
);
2969 DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook
,
2970 Srun_window_configuration_change_hook
, 1, 1, 0,
2971 doc
: /* Run `window-configuration-change-hook' for FRAME. */)
2974 CHECK_LIVE_FRAME (frame
);
2975 run_window_configuration_change_hook (XFRAME (frame
));
2979 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2980 means it's allowed to run hooks. See make_frame for a case where
2981 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2982 margins, fringes, and scroll-bar settings of the window are not
2983 reset from the buffer's local settings. */
2986 set_window_buffer (Lisp_Object window
, Lisp_Object buffer
, int run_hooks_p
, int keep_margins_p
)
2988 struct window
*w
= XWINDOW (window
);
2989 struct buffer
*b
= XBUFFER (buffer
);
2990 int count
= SPECPDL_INDEX ();
2991 int samebuf
= EQ (buffer
, w
->buffer
);
2995 if (EQ (window
, selected_window
))
2996 b
->last_selected_window
= window
;
2998 /* Let redisplay errors through. */
2999 b
->display_error_modiff
= 0;
3001 /* Update time stamps of buffer display. */
3002 if (INTEGERP (b
->display_count
))
3003 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
3004 b
->display_time
= Fcurrent_time ();
3006 XSETFASTINT (w
->window_end_pos
, 0);
3007 XSETFASTINT (w
->window_end_vpos
, 0);
3008 memset (&w
->last_cursor
, 0, sizeof w
->last_cursor
);
3009 w
->window_end_valid
= Qnil
;
3010 if (!(keep_margins_p
&& samebuf
))
3011 { /* If we're not actually changing the buffer, don't reset hscroll and
3012 vscroll. This case happens for example when called from
3013 change_frame_size_1, where we use a dummy call to
3014 Fset_window_buffer on the frame's selected window (and no other)
3015 just in order to run window-configuration-change-hook.
3016 Resetting hscroll and vscroll here is problematic for things like
3017 image-mode and doc-view-mode since it resets the image's position
3018 whenever we resize the frame. */
3019 w
->hscroll
= w
->min_hscroll
= make_number (0);
3021 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
3022 set_marker_restricted (w
->start
,
3023 make_number (b
->last_window_start
),
3025 w
->start_at_line_beg
= Qnil
;
3026 w
->force_start
= Qnil
;
3027 XSETFASTINT (w
->last_modified
, 0);
3028 XSETFASTINT (w
->last_overlay_modified
, 0);
3030 /* Maybe we could move this into the `if' but it's not obviously safe and
3031 I doubt it's worth the trouble. */
3032 windows_or_buffers_changed
++;
3034 /* We must select BUFFER for running the window-scroll-functions. */
3035 /* We can't check ! NILP (Vwindow_scroll_functions) here
3036 because that might itself be a local variable. */
3037 if (window_initialized
)
3039 record_unwind_protect (Fset_buffer
, Fcurrent_buffer ());
3040 Fset_buffer (buffer
);
3043 XMARKER (w
->pointm
)->insertion_type
= !NILP (Vwindow_point_insertion_type
);
3045 if (!keep_margins_p
)
3047 /* Set left and right marginal area width etc. from buffer. */
3049 /* This may call adjust_window_margins three times, so
3050 temporarily disable window margins. */
3051 Lisp_Object save_left
= w
->left_margin_cols
;
3052 Lisp_Object save_right
= w
->right_margin_cols
;
3054 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3056 Fset_window_fringes (window
,
3057 b
->left_fringe_width
, b
->right_fringe_width
,
3058 b
->fringes_outside_margins
);
3060 Fset_window_scroll_bars (window
,
3061 b
->scroll_bar_width
,
3062 b
->vertical_scroll_bar_type
, Qnil
);
3064 w
->left_margin_cols
= save_left
;
3065 w
->right_margin_cols
= save_right
;
3067 Fset_window_margins (window
,
3068 b
->left_margin_cols
, b
->right_margin_cols
);
3073 if (! NILP (Vwindow_scroll_functions
))
3074 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
3075 Fmarker_position (w
->start
));
3076 run_window_configuration_change_hook (XFRAME (WINDOW_FRAME (w
)));
3079 unbind_to (count
, Qnil
);
3082 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 3, 0,
3083 doc
: /* Make WINDOW display BUFFER-OR-NAME as its contents.
3084 WINDOW has to be a live window and defaults to the selected one.
3085 BUFFER-OR-NAME must be a buffer or the name of an existing buffer.
3087 Optional third argument KEEP-MARGINS non-nil means that WINDOW's current
3088 display margins, fringe widths, and scroll bar settings are preserved;
3089 the default is to reset these from the local settings for BUFFER-OR-NAME
3090 or the frame defaults. Return nil.
3092 This function throws an error when WINDOW is strongly dedicated to its
3093 buffer (that is `window-dedicated-p' returns t for WINDOW) and does not
3094 already display BUFFER-OR-NAME.
3096 This function runs `window-scroll-functions' before running
3097 `window-configuration-change-hook'. */)
3098 (register Lisp_Object window
, Lisp_Object buffer_or_name
, Lisp_Object keep_margins
)
3100 register Lisp_Object tem
, buffer
;
3101 register struct window
*w
= decode_window (window
);
3103 XSETWINDOW (window
, w
);
3104 buffer
= Fget_buffer (buffer_or_name
);
3105 CHECK_BUFFER (buffer
);
3106 if (NILP (XBUFFER (buffer
)->name
))
3107 error ("Attempt to display deleted buffer");
3111 error ("Window is deleted");
3112 else if (!EQ (tem
, Qt
))
3113 /* w->buffer is t when the window is first being set up. */
3115 if (!EQ (tem
, buffer
))
3116 if (EQ (w
->dedicated
, Qt
))
3117 error ("Window is dedicated to `%s'", SDATA (XBUFFER (tem
)->name
));
3119 w
->dedicated
= Qnil
;
3124 set_window_buffer (window
, buffer
, 1, !NILP (keep_margins
));
3130 display_buffer (Lisp_Object buffer
, Lisp_Object not_this_window_p
, Lisp_Object override_frame
)
3132 return call3 (Qdisplay_buffer
, buffer
, not_this_window_p
, override_frame
);
3135 DEFUN ("force-window-update", Fforce_window_update
, Sforce_window_update
,
3137 doc
: /* Force all windows to be updated on next redisplay.
3138 If optional arg OBJECT is a window, force redisplay of that window only.
3139 If OBJECT is a buffer or buffer name, force redisplay of all windows
3140 displaying that buffer. */)
3141 (Lisp_Object object
)
3145 windows_or_buffers_changed
++;
3146 update_mode_lines
++;
3150 if (WINDOWP (object
))
3152 struct window
*w
= XWINDOW (object
);
3153 mark_window_display_accurate (object
, 0);
3154 w
->update_mode_line
= Qt
;
3155 if (BUFFERP (w
->buffer
))
3156 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
3157 ++update_mode_lines
;
3161 if (STRINGP (object
))
3162 object
= Fget_buffer (object
);
3163 if (BUFFERP (object
) && !NILP (XBUFFER (object
)->name
))
3165 /* Walk all windows looking for buffer, and force update
3166 of each of those windows. */
3168 object
= window_loop (REDISPLAY_BUFFER_WINDOWS
, object
, 0, Qvisible
);
3169 return NILP (object
) ? Qnil
: Qt
;
3172 /* If nothing suitable was found, just return.
3173 We could signal an error, but this feature will typically be used
3174 asynchronously in timers or process sentinels, so we don't. */
3180 temp_output_buffer_show (register Lisp_Object buf
)
3182 register struct buffer
*old
= current_buffer
;
3183 register Lisp_Object window
;
3184 register struct window
*w
;
3186 XBUFFER (buf
)->directory
= current_buffer
->directory
;
3189 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
3193 #if 0 /* rms: there should be no reason for this. */
3194 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
3196 set_buffer_internal (old
);
3198 if (!NILP (Vtemp_buffer_show_function
))
3199 call1 (Vtemp_buffer_show_function
, buf
);
3202 window
= display_buffer (buf
, Qnil
, Qnil
);
3204 if (!EQ (XWINDOW (window
)->frame
, selected_frame
))
3205 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
3206 Vminibuf_scroll_window
= window
;
3207 w
= XWINDOW (window
);
3208 XSETFASTINT (w
->hscroll
, 0);
3209 XSETFASTINT (w
->min_hscroll
, 0);
3210 set_marker_restricted_both (w
->start
, buf
, BEG
, BEG
);
3211 set_marker_restricted_both (w
->pointm
, buf
, BEG
, BEG
);
3213 /* Run temp-buffer-show-hook, with the chosen window selected
3214 and its buffer current. */
3216 if (!NILP (Vrun_hooks
)
3217 && !NILP (Fboundp (Qtemp_buffer_show_hook
))
3218 && !NILP (Fsymbol_value (Qtemp_buffer_show_hook
)))
3220 int count
= SPECPDL_INDEX ();
3221 Lisp_Object prev_window
, prev_buffer
;
3222 prev_window
= selected_window
;
3223 XSETBUFFER (prev_buffer
, old
);
3225 /* Select the window that was chosen, for running the hook.
3226 Note: Both Fselect_window and select_window_norecord may
3227 set-buffer to the buffer displayed in the window,
3228 so we need to save the current buffer. --stef */
3229 record_unwind_protect (Fset_buffer
, prev_buffer
);
3230 record_unwind_protect (select_window_norecord
, prev_window
);
3231 Fselect_window (window
, Qt
);
3232 Fset_buffer (w
->buffer
);
3233 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
3234 unbind_to (count
, Qnil
);
3239 /* Make new window, have it replace WINDOW in window-tree, and make
3240 WINDOW its only vertical child (HORFLAG 1 means make WINDOW its only
3241 horizontal child). */
3243 make_parent_window (Lisp_Object window
, int horflag
)
3246 register struct window
*o
, *p
;
3249 o
= XWINDOW (window
);
3250 p
= allocate_window ();
3251 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
3252 ((struct Lisp_Vector
*) p
)->contents
[i
]
3253 = ((struct Lisp_Vector
*) o
)->contents
[i
];
3254 XSETWINDOW (parent
, p
);
3257 XSETFASTINT (p
->sequence_number
, sequence_number
);
3259 replace_window (window
, parent
, 1);
3265 p
->hchild
= horflag
? window
: Qnil
;
3266 p
->vchild
= horflag
? Qnil
: window
;
3270 p
->window_parameters
= Qnil
;
3273 /* Make new window from scratch. */
3278 register struct window
*w
;
3280 w
= allocate_window ();
3281 /* Initialize all Lisp data. */
3282 w
->frame
= w
->mini_p
= Qnil
;
3283 w
->next
= w
->prev
= w
->hchild
= w
->vchild
= w
->parent
= Qnil
;
3284 XSETFASTINT (w
->left_col
, 0);
3285 XSETFASTINT (w
->top_line
, 0);
3286 XSETFASTINT (w
->total_lines
, 0);
3287 XSETFASTINT (w
->total_cols
, 0);
3288 XSETFASTINT (w
->normal_lines
, 1);
3289 XSETFASTINT (w
->normal_cols
, 1);
3290 XSETFASTINT (w
->new_total
, 0);
3291 XSETFASTINT (w
->new_normal
, 0);
3293 w
->start
= Fmake_marker ();
3294 w
->pointm
= Fmake_marker ();
3295 w
->force_start
= w
->optional_new_start
= Qnil
;
3296 XSETFASTINT (w
->hscroll
, 0);
3297 XSETFASTINT (w
->min_hscroll
, 0);
3298 XSETFASTINT (w
->use_time
, 0);
3300 XSETFASTINT (w
->sequence_number
, sequence_number
);
3301 w
->temslot
= w
->last_modified
= w
->last_overlay_modified
= Qnil
;
3302 XSETFASTINT (w
->last_point
, 0);
3303 w
->last_had_star
= w
->vertical_scroll_bar
= Qnil
;
3304 w
->left_margin_cols
= w
->right_margin_cols
= Qnil
;
3305 w
->left_fringe_width
= w
->right_fringe_width
= Qnil
;
3306 w
->fringes_outside_margins
= Qnil
;
3307 w
->scroll_bar_width
= Qnil
;
3308 w
->vertical_scroll_bar_type
= Qt
;
3309 w
->last_mark_x
= w
->last_mark_y
= Qnil
;
3310 XSETFASTINT (w
->window_end_pos
, 0);
3311 XSETFASTINT (w
->window_end_vpos
, 0);
3312 w
->window_end_valid
= w
->update_mode_line
= Qnil
;
3313 w
->start_at_line_beg
= w
->display_table
= w
->dedicated
= Qnil
;
3314 w
->base_line_number
= w
->base_line_pos
= w
->region_showing
= Qnil
;
3315 w
->column_number_displayed
= w
->redisplay_end_trigger
= Qnil
;
3316 /* Initialize non-Lisp data. */
3317 w
->desired_matrix
= w
->current_matrix
= 0;
3318 w
->nrows_scale_factor
= w
->ncols_scale_factor
= 1;
3319 memset (&w
->cursor
, 0, sizeof (w
->cursor
));
3320 memset (&w
->last_cursor
, 0, sizeof (w
->last_cursor
));
3321 memset (&w
->phys_cursor
, 0, sizeof (w
->phys_cursor
));
3322 w
->phys_cursor_type
= -1;
3323 w
->phys_cursor_width
= -1;
3324 w
->last_cursor_off_p
= w
->cursor_off_p
= 0;
3325 w
->must_be_updated_p
= 0;
3326 w
->pseudo_window_p
= 0;
3327 w
->frozen_window_start_p
= 0;
3329 /* Reset window_list. */
3330 Vwindow_list
= Qnil
;
3331 /* Return window. */
3332 XSETWINDOW (window
, w
);
3336 DEFUN ("resize-window-total", Fresize_window_total
, Sresize_window_total
, 2, 3, 0,
3337 doc
: /* Set new total size of WINDOW to SIZE.
3340 Optional argument ADD non-nil means add SIZE to the new total size of
3341 WINDOW and return the sum.
3343 Note: This function does not operate on any subwindows of WINDOW. */)
3344 (Lisp_Object window
, Lisp_Object size
, Lisp_Object add
)
3346 struct window
*w
= decode_any_window (window
);
3348 CHECK_NUMBER (size
);
3350 XSETINT (w
->new_total
, XINT (size
));
3352 XSETINT (w
->new_total
, XINT (w
->new_total
) + XINT (size
));
3354 return w
->new_total
;
3357 DEFUN ("resize-window-normal", Fresize_window_normal
, Sresize_window_normal
, 1, 2, 0,
3358 doc
: /* Set new normal size of WINDOW to SIZE.
3361 Note: This function does not operate on any subwindows of WINDOW. */)
3362 (Lisp_Object window
, Lisp_Object size
)
3364 struct window
*w
= decode_any_window (window
);
3366 w
->new_normal
= size
;
3367 return w
->new_normal
;
3370 /* Return 1 if setting w->total_lines (w->total_cols if HORFLAG is
3371 non-zero) to w->new_total would result in correct heights (widths)
3372 for window W and recursively all subwindows of W.
3374 Note: This function does not check any of `window-fixed-size-p',
3375 `window-min-height' or `window-min-width'. It does check that window
3376 sizes do not drop below one line (two columns). */
3378 resize_window_check (struct window
*w
, int horflag
)
3382 if (!NILP (w
->vchild
))
3383 /* W is a vertical combination. */
3385 c
= XWINDOW (w
->vchild
);
3387 /* All subwindows of W must have the same width as W. */
3391 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3392 || !resize_window_check (c
, horflag
))
3394 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3399 /* The sum of the heights of the subwindows of W must equal W's
3402 int sum_of_sizes
= 0;
3405 if (!resize_window_check (c
, horflag
))
3407 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3408 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3410 return (sum_of_sizes
== XINT (w
->new_total
));
3413 else if (!NILP (w
->hchild
))
3414 /* W is a horizontal combination. */
3416 c
= XWINDOW (w
->hchild
);
3418 /* The sum of the widths of the subwindows of W must equal W's
3421 int sum_of_sizes
= 0;
3424 if (!resize_window_check (c
, horflag
))
3426 sum_of_sizes
= sum_of_sizes
+ XINT (c
->new_total
);
3427 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3429 return (sum_of_sizes
== XINT (w
->new_total
));
3432 /* All subwindows of W must have the same height as W. */
3436 if ((XINT (c
->new_total
) != XINT (w
->new_total
))
3437 || !resize_window_check (c
, horflag
))
3439 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3445 /* A leaf window. Make sure it's not too small. The following
3446 hardcodes the values of `window-safe-min-width' (2) and
3447 `window-safe-min-height' (1) which are defined in window.el. */
3448 return XINT (w
->new_total
) >= (horflag
? 2 : 1);
3451 /* Set w->total_lines (w->total_cols if HORIZONTAL is non-zero) to
3452 w->new_total for window W and recursively all subwindows of W. Also
3453 calculate and assign the new vertical (horizontal) start positions of
3454 each of these windows.
3456 This function does not perform any error checks. Make sure you have
3457 run resize_window_check on W before applying this function. */
3459 resize_window_apply (struct window
*w
, int horflag
)
3461 struct window
*c
, *p
;
3464 /* Note: Assigning new_normal requires that the new total size of the
3465 parent window has been set *before*. */
3468 w
->total_cols
= w
->new_total
;
3469 if (EQ (w
->new_normal
, Qset
))
3471 if (NILP (w
->parent
))
3472 XSETFASTINT (w
->normal_cols
, 1);
3475 = make_float (XFLOATINT (w
->total_cols
)
3476 / XFLOATINT (XWINDOW (w
->parent
)->total_cols
));
3478 else if (NUMBERP (w
->new_normal
))
3479 w
->normal_cols
= w
->new_normal
;
3481 pos
= XINT (w
->left_col
);
3485 w
->total_lines
= w
->new_total
;
3486 if (EQ (w
->new_normal
, Qset
))
3488 if (NILP (w
->parent
))
3489 XSETFASTINT (w
->normal_lines
, 1);
3492 = make_float (XFLOATINT (w
->total_lines
)
3493 / XFLOATINT (XWINDOW (w
->parent
)->total_lines
));
3495 else if (NUMBERP (w
->new_normal
))
3496 w
->normal_lines
= w
->new_normal
;
3498 pos
= XINT (w
->top_line
);
3501 if (!NILP (w
->vchild
))
3502 /* W is a vertical combination. */
3504 c
= XWINDOW (w
->vchild
);
3508 XSETFASTINT (c
->left_col
, pos
);
3510 XSETFASTINT (c
->top_line
, pos
);
3511 resize_window_apply (c
, horflag
);
3513 pos
= pos
+ XINT (c
->total_lines
);
3514 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3517 else if (!NILP (w
->hchild
))
3518 /* W is a horizontal combination. */
3520 c
= XWINDOW (w
->hchild
);
3524 XSETFASTINT (c
->left_col
, pos
);
3526 XSETFASTINT (c
->top_line
, pos
);
3527 resize_window_apply (c
, horflag
);
3529 pos
= pos
+ XINT (c
->total_cols
);
3530 c
= NILP (c
->next
) ? 0 : XWINDOW (c
->next
);
3534 /* Clear out some redisplay caches. */
3535 XSETFASTINT (w
->last_modified
, 0);
3536 XSETFASTINT (w
->last_overlay_modified
, 0);
3540 DEFUN ("resize-window-apply", Fresize_window_apply
, Sresize_window_apply
, 1, 2, 0,
3541 doc
: /* Apply requested size values for window-tree of FRAME.
3542 Optional argument HORIZONTAL omitted or nil means apply requested height
3543 values. HORIZONTAL non-nil means apply requested width values.
3545 This function checks whether the requested values sum up to a valid
3546 window layout, recursively assigns the new sizes of all subwindows and
3547 calculates and assigns the new start positions of these windows.
3549 Note: This function does not check any of `window-fixed-size-p',
3550 `window-min-height' or `window-min-width'. All these checks have to
3551 be applied on the Elisp level. */)
3552 (Lisp_Object frame
, Lisp_Object horizontal
)
3556 int horflag
= !NILP (horizontal
);
3559 frame
= selected_frame
;
3560 CHECK_LIVE_FRAME (frame
);
3563 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
3565 if (!resize_window_check (r
, horflag
)
3566 || (r
->new_total
!= (horflag
? r
->total_cols
: r
->total_lines
)))
3570 resize_window_apply (r
, horflag
);
3572 windows_or_buffers_changed
++;
3573 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3578 run_window_configuration_change_hook (f
);
3584 /* Resize frame F's windows when number of lines of F is set to SIZE.
3585 HORFLAG 1 means resize windows when number of columns of F is set to
3588 This function can delete all windows but the selected one in order to
3589 satisfy the request. The result will be meaningful if and only if
3590 F's windows have meaningful sizes when you call this. */
3592 resize_frame_windows (struct frame
*f
, int size
, int horflag
)
3594 Lisp_Object root
= f
->root_window
;
3595 struct window
*r
= XWINDOW (root
);
3596 Lisp_Object mini
= f
->minibuffer_window
;
3599 XSETFASTINT (r
->top_line
, FRAME_TOP_MARGIN (f
));
3601 if (NILP (r
->vchild
) && NILP (r
->hchild
))
3602 /* For a leaf root window just set the size. */
3604 XSETFASTINT (r
->total_cols
, size
);
3606 XSETFASTINT (r
->total_lines
,
3607 /* Take menubar, toolbar, and minibuffer into account. */
3609 - FRAME_TOP_MARGIN (f
)
3610 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3617 XSETINT (delta
, size
- XINT (r
->total_cols
));
3620 /* Take menubar, toolbar, and minibuffer into account. */
3623 - FRAME_TOP_MARGIN (f
)
3624 - ((FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3626 - XINT (r
->total_lines
));
3631 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qnil
);
3632 if (resize_window_check (r
, horflag
))
3633 resize_window_apply (r
, horflag
);
3636 resize_root_window (root
, delta
, horflag
? Qt
: Qnil
, Qt
);
3637 if (resize_window_check (r
, horflag
))
3638 resize_window_apply (r
, horflag
);
3641 root
= f
->selected_window
;
3642 Fdelete_other_windows_internal (root
, Qnil
);
3644 XSETFASTINT (r
->total_cols
, size
);
3646 XSETFASTINT (r
->total_lines
, size
);
3651 if (FRAME_HAS_MINIBUF_P (f
) && !FRAME_MINIBUF_ONLY_P (f
))
3655 XSETFASTINT (m
->total_cols
, size
);
3658 /* Are we sure we always want 1 line here? */
3659 XSETFASTINT (m
->total_lines
, 1);
3660 XSETFASTINT (m
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
3666 DEFUN ("split-window-internal", Fsplit_window_internal
, Ssplit_window_internal
, 2, 3, 0,
3667 doc
: /* Split window OLD vertically giving the new window SIZE lines.
3668 Optional argument HORIZONTAL non-nil means split OLD giving the new
3669 window SIZE columns. In any case SIZE must be a positive integer.
3671 Optional third argument HORIZONTAL nil (or `below') specifies that the
3672 new window shall be located below WINDOW. HORIZONTAL `above' means the
3673 new window shall be located above WINDOW. In these cases SIZE specifies
3674 the new number of lines for WINDOW (or the new window provided SIZE is
3675 negative) including space reserved for the mode and/or header line.
3677 HORIZONTAL t (or `right') specifies that the new window shall be located
3678 on the right side of WINDOW. HORIZONTAL `left' means the new window
3679 shall be located on the left of WINDOW. In these cases SIZE specifies
3680 the new number of columns for WINDOW (or the new window provided SIZE is
3681 negative) including space reserved for fringes and the scrollbar or a
3683 (Lisp_Object old
, Lisp_Object size
, Lisp_Object horizontal
)
3685 /* OLD (*o) is the window we have to split. (*p) is either OLD's
3686 parent window or an internal window we have to install as OLD's new
3687 parent. REFERENCE (*r) must denote a live window, or is set to OLD
3688 provided OLD is a leaf window, or to the frame's selected window.
3689 NEW (*n) is the new window created with some parameters taken from
3691 register Lisp_Object
new, frame
, reference
;
3692 register struct window
*o
, *p
, *n
, *r
;
3695 /* HORFLAG is 1 when we split horizontally, 0 otherwise. */
3696 = EQ (horizontal
, Qt
) || EQ (horizontal
, Qleft
) || EQ (horizontal
, Qright
);
3701 frame
= WINDOW_FRAME (o
);
3704 CHECK_NUMBER (size
);
3706 /* Set do_resize to 1 iff we don't nest and OLD has an iso-combined
3709 EQ (Vwindow_splits
, Qresize
)
3710 && !NILP (o
->parent
)
3712 ? !NILP (XWINDOW (o
->parent
)->hchild
)
3713 : !NILP (XWINDOW (o
->parent
)->vchild
));
3715 /* We may need a live reference window to copy some parameters. */
3716 if (WINDOW_LIVE_P (old
))
3718 else /* Neither REFERENCE nor OLD are alive. Use the frame's
3719 selected window as reference window. */
3720 reference
= FRAME_SELECTED_WINDOW (f
);
3721 r
= XWINDOW (reference
);
3723 /* The following bugs are caught by `split-window'. */
3724 if (MINI_WINDOW_P (o
))
3725 error ("Attempt to split minibuffer window");
3726 else if (XINT (size
) < (horflag
? 2 : 1))
3727 error ("Size of new window too small (after split)");
3730 p
= XWINDOW (o
->parent
);
3731 /* Temporarily pretend we split the parent window. */
3732 XSETINT (p
->new_total
,
3733 XINT (horflag
? p
->total_cols
: p
->total_lines
) - XINT (size
));
3734 if (!resize_window_check (p
, horflag
))
3735 error ("Sum of window sizes won't fit");
3737 /* Undo the temporal pretension. */
3738 p
->new_total
= horflag
? p
->total_cols
: p
->total_lines
;
3742 if (!resize_window_check (o
, horflag
))
3743 error ("Resizing old window failed");
3744 else if (XINT (size
) + XINT (o
->new_total
)
3745 != XINT (horflag
? o
->total_cols
: o
->total_lines
))
3746 error ("Sum of sizes of old and new window don't fit");
3749 /* This is our point of no return. */
3750 if (NILP (o
->parent
)
3752 ? (XWINDOW (o
->parent
)->hchild
)
3753 : (XWINDOW (o
->parent
)->vchild
))
3754 || EQ (Vwindow_splits
, Qnest
))
3755 /* Make a new parent window in the following cases:
3757 - OLD doesn't have a parent window, or
3759 - OLD is in a vertical (horizontal) combination and shall be
3760 split horizontally (vertically), or
3762 - we want to nest the new parent window.
3764 Note that the new parent window is a matrjoshka window; so any
3765 matrjoshka window invariants are temporarily invalid now. */
3767 /* Save the old value of o->normal_cols/lines. It gets corrupted
3768 by make_parent_window and we need it below for assigning it to
3770 Lisp_Object new_normal
= horflag
? o
->normal_cols
: o
->normal_lines
;
3771 make_parent_window (old
, horflag
);
3772 p
= XWINDOW (o
->parent
);
3773 if (EQ (Vwindow_splits
, Qnest
))
3774 /* Make sure that parent is not recombined. */
3775 p
->inhibit_recombine
= Qt
;
3776 /* These get applied below. */
3777 p
->new_total
= horflag
? o
->total_cols
: o
->total_lines
;
3778 p
->new_normal
= new_normal
;
3781 p
= XWINDOW (o
->parent
);
3783 windows_or_buffers_changed
++;
3784 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3785 new = make_window ();
3788 n
->parent
= o
->parent
;
3789 n
->vchild
= n
->hchild
= Qnil
;
3791 if (EQ (horizontal
, Qabove
) || EQ (horizontal
, Qleft
))
3800 XWINDOW (n
->prev
)->next
= new;
3807 if (!NILP (n
->next
))
3808 XWINDOW (n
->next
)->prev
= new;
3814 n
->window_end_valid
= Qnil
;
3815 memset (&n
->last_cursor
, 0, sizeof n
->last_cursor
);
3817 /* Get special geometry settings from reference window. */
3818 n
->left_margin_cols
= r
->left_margin_cols
;
3819 n
->right_margin_cols
= r
->right_margin_cols
;
3820 n
->left_fringe_width
= r
->left_fringe_width
;
3821 n
->right_fringe_width
= r
->right_fringe_width
;
3822 n
->fringes_outside_margins
= r
->fringes_outside_margins
;
3823 n
->scroll_bar_width
= r
->scroll_bar_width
;
3824 n
->vertical_scroll_bar_type
= r
->vertical_scroll_bar_type
;
3828 n
->top_line
= o
->top_line
;
3829 n
->total_lines
= o
->total_lines
;
3833 n
->left_col
= o
->left_col
;
3834 n
->total_cols
= o
->total_cols
;
3836 n
->new_total
= size
;
3839 resize_window_apply (p
, horflag
);
3843 /* Assign normal sizes for OLD. */
3846 = make_float (XFLOATINT (o
->total_cols
) / XFLOATINT (p
->total_cols
));
3849 = make_float (XFLOATINT (o
->total_lines
) / XFLOATINT (p
->total_lines
));
3853 = make_float (XFLOATINT (n
->total_lines
) / XFLOATINT (p
->total_lines
));
3855 = make_float (XFLOATINT (n
->total_cols
) / XFLOATINT (p
->total_cols
));
3860 /* Use buffer of reference window. */
3861 set_window_buffer (new, r
->buffer
, 0, 1);
3862 /* Maybe we should run the scroll functions in Elisp (which already
3863 runs the configuration change hook). */
3864 if (! NILP (Vwindow_scroll_functions
))
3865 run_hook_with_args_2 (Qwindow_scroll_functions
, new,
3866 Fmarker_position (n
->start
));
3871 DEFUN ("delete-window-internal", Fdelete_window_internal
, Sdelete_window_internal
, 1, 1, 0,
3872 doc
: /* Remove WINDOW from its frame.
3873 WINDOW defaults to the selected window. Return nil. Signal an error
3874 when WINDOW is the only window on its frame. */)
3875 (register Lisp_Object window
)
3877 register Lisp_Object parent
, sibling
, frame
, root
;
3878 struct window
*w
, *p
, *s
, *r
;
3882 int before_sibling
= 0;
3884 w
= decode_any_window (window
);
3885 XSETWINDOW (window
, w
);
3886 if (NILP (w
->buffer
) && NILP (w
->hchild
) && NILP (w
->vchild
))
3887 /* It's a no-op to delete an already deleted window. */
3892 /* Never delete a minibuffer or frame root window. */
3893 error ("Attempt to delete minibuffer or sole ordinary window");
3894 else if (NILP (w
->prev
) && NILP (w
->next
))
3895 /* Rather bow out here, this case should be handled on the Elisp
3897 error ("Attempt to delete sole window of parent");
3899 p
= XWINDOW (parent
);
3900 horflag
= NILP (p
->vchild
);
3902 frame
= WINDOW_FRAME (w
);
3905 root
= FRAME_ROOT_WINDOW (f
);
3908 /* Unlink WINDOW from window tree. */
3910 /* Get SIBLING below (on the right of) WINDOW. */
3912 /* before_sibling 1 means WINDOW is the first child of its
3913 parent and thus before the sibling. */
3916 s
= XWINDOW (sibling
);
3919 p
->hchild
= sibling
;
3921 p
->vchild
= sibling
;
3924 /* Get SIBLING above (on the left of) WINDOW. */
3927 s
= XWINDOW (sibling
);
3929 if (!NILP (s
->next
))
3930 XWINDOW (s
->next
)->prev
= sibling
;
3933 if (resize_window_check (r
, horflag
)
3934 && r
->new_total
== (horflag
? r
->total_cols
: r
->total_lines
))
3935 /* We can delete WINDOW now. */
3939 resize_window_apply (p
, horflag
);
3941 windows_or_buffers_changed
++;
3942 Vwindow_list
= Qnil
;
3943 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
3945 w
->next
= Qnil
; /* Don't delete w->next too. */
3946 free_window_matrices (w
);
3948 if (!NILP (w
->vchild
))
3950 delete_all_subwindows (w
->vchild
);
3953 else if (!NILP (w
->hchild
))
3955 delete_all_subwindows (w
->hchild
);
3958 else if (!NILP (w
->buffer
))
3961 unchain_marker (XMARKER (w
->pointm
));
3962 unchain_marker (XMARKER (w
->start
));
3966 if (NILP (s
->prev
) && NILP (s
->next
))
3967 /* A matrjoshka where SIBLING has become the only child of
3970 /* Put SIBLING into PARENT's place. */
3971 replace_window (parent
, sibling
, 0);
3972 /* Inherit these two. */
3973 s
->normal_cols
= p
->normal_cols
;
3974 s
->normal_lines
= p
->normal_lines
;
3975 /* Mark PARENT as deleted. */
3976 p
->vchild
= p
->hchild
= Qnil
;
3977 /* Merge SIBLING's into its new parent unless we want binary
3979 if (!EQ (Vwindow_splits
, Qnest
))
3980 recombine_windows (sibling
);
3985 if (!WINDOW_LIVE_P (FRAME_SELECTED_WINDOW (f
)))
3986 /* We deleted the frame's selected window. */
3988 /* Use the frame's first window as fallback ... */
3989 Lisp_Object new_selected_window
= Fframe_first_window (frame
);
3990 /* ... but preferably use its most recently used window. */
3991 Lisp_Object mru_window
;
3993 /* `get-mru-window' might fail for some reason so play it safe
3994 - promote the first window _without recording it_ first. */
3995 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
3996 Fselect_window (new_selected_window
, Qt
);
3998 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
4002 /* Now look whether `get-mru-window' gets us something. */
4003 mru_window
= call1 (Qget_mru_window
, frame
);
4004 if (WINDOW_LIVE_P (mru_window
)
4005 && XWINDOW (mru_window
)->frame
== frame
)
4006 new_selected_window
= mru_window
;
4008 /* If all ended up well, we now promote the mru window. */
4009 if (EQ (FRAME_SELECTED_WINDOW (f
), selected_window
))
4010 Fselect_window (new_selected_window
, Qnil
);
4012 FRAME_SELECTED_WINDOW (f
) = new_selected_window
;
4017 /* Must be run by the caller:
4018 run_window_configuration_change_hook (f); */
4021 /* We failed: Relink WINDOW into window tree. */
4034 if (!NILP (w
->next
))
4035 XWINDOW (w
->next
)->prev
= window
;
4037 error ("Deletion failed");
4043 /***********************************************************************
4044 Resizing Mini-Windows
4045 ***********************************************************************/
4047 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we
4050 grow_mini_window (struct window
*w
, int delta
)
4052 struct frame
*f
= XFRAME (w
->frame
);
4054 Lisp_Object root
, value
;
4056 xassert (MINI_WINDOW_P (w
));
4057 xassert (delta
>= 0);
4059 root
= FRAME_ROOT_WINDOW (f
);
4061 value
= call2 (Qresize_root_window_vertically
, root
, make_number (- delta
));
4062 if (INTEGERP (value
) && resize_window_check (r
, 0))
4065 resize_window_apply (r
, 0);
4067 /* Grow the mini-window. */
4068 XSETFASTINT (w
->top_line
, XFASTINT (r
->top_line
) + XFASTINT (r
->total_lines
));
4069 XSETFASTINT (w
->total_lines
, XFASTINT (w
->total_lines
) - XINT (value
));
4070 XSETFASTINT (w
->last_modified
, 0);
4071 XSETFASTINT (w
->last_overlay_modified
, 0);
4079 /* Shrink mini-window W. */
4081 shrink_mini_window (struct window
*w
)
4083 struct frame
*f
= XFRAME (w
->frame
);
4085 Lisp_Object root
, value
, size
;
4087 xassert (MINI_WINDOW_P (w
));
4089 size
= XINT (w
->total_lines
);
4092 root
= FRAME_ROOT_WINDOW (f
);
4094 value
= call2 (Qresize_root_window_vertically
,
4095 root
, make_number (size
- 1));
4096 if (INTEGERP (value
) && resize_window_check (r
, 0))
4099 resize_window_apply (r
, 0);
4101 /* Shrink the mini-window. */
4102 XSETFASTINT (w
->top_line
, XFASTINT (r
->top_line
) + XFASTINT (r
->total_lines
));
4103 XSETFASTINT (w
->total_lines
, 1);
4105 XSETFASTINT (w
->last_modified
, 0);
4106 XSETFASTINT (w
->last_overlay_modified
, 0);
4111 /* If the above failed for whatever strange reason we must make a
4112 one window frame here. The same routine will be needed when
4113 shrinking the frame (and probably when making the initial
4114 *scratch* window). For the moment leave things as they are. */
4118 DEFUN ("resize-mini-window-internal", Fresize_mini_window_internal
, Sresize_mini_window_internal
, 1, 1, 0,
4119 doc
: /* Resize minibuffer window WINDOW. */)
4120 (Lisp_Object window
)
4122 struct window
*w
= XWINDOW (window
);
4127 CHECK_WINDOW (window
);
4128 f
= XFRAME (w
->frame
);
4130 if (!EQ (FRAME_MINIBUF_WINDOW (XFRAME (w
->frame
)), window
))
4131 error ("Not a valid minibuffer window");
4132 else if (FRAME_MINIBUF_ONLY_P (f
))
4133 error ("Cannot resize a minibuffer-only frame");
4135 r
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4136 height
= XINT (r
->total_lines
) + XINT (w
->total_lines
);
4137 if (resize_window_check (r
, 0)
4138 && XINT (w
->new_total
) > 0
4139 && height
== XINT (r
->new_total
) + XINT (w
->new_total
))
4142 resize_window_apply (r
, 0);
4144 w
->total_lines
= w
->new_total
;
4145 XSETFASTINT (w
->top_line
, XINT (r
->top_line
) + XINT (r
->total_lines
));
4147 windows_or_buffers_changed
++;
4148 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4152 run_window_configuration_change_hook (f
);
4155 else error ("Failed to resize minibuffer window");
4158 /* Mark window cursors off for all windows in the window tree rooted
4159 at W by setting their phys_cursor_on_p flag to zero. Called from
4160 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4161 the frame are cleared. */
4164 mark_window_cursors_off (struct window
*w
)
4168 if (!NILP (w
->hchild
))
4169 mark_window_cursors_off (XWINDOW (w
->hchild
));
4170 else if (!NILP (w
->vchild
))
4171 mark_window_cursors_off (XWINDOW (w
->vchild
));
4173 w
->phys_cursor_on_p
= 0;
4175 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4180 /* Return number of lines of text (not counting mode lines) in W. */
4183 window_internal_height (struct window
*w
)
4185 int ht
= XFASTINT (w
->total_lines
);
4187 if (!MINI_WINDOW_P (w
))
4189 if (!NILP (w
->parent
)
4190 || !NILP (w
->vchild
)
4191 || !NILP (w
->hchild
)
4194 || WINDOW_WANTS_MODELINE_P (w
))
4197 if (WINDOW_WANTS_HEADER_LINE_P (w
))
4204 /************************************************************************
4206 ***********************************************************************/
4208 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4209 N screen-fulls, which is defined as the height of the window minus
4210 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4211 instead. Negative values of N mean scroll down. NOERROR non-zero
4212 means don't signal an error if we try to move over BEGV or ZV,
4216 window_scroll (Lisp_Object window
, int n
, int whole
, int noerror
)
4220 /* If we must, use the pixel-based version which is much slower than
4221 the line-based one but can handle varying line heights. */
4222 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
4223 window_scroll_pixel_based (window
, n
, whole
, noerror
);
4225 window_scroll_line_based (window
, n
, whole
, noerror
);
4231 /* Implementation of window_scroll that works based on pixel line
4232 heights. See the comment of window_scroll for parameter
4236 window_scroll_pixel_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4239 struct window
*w
= XWINDOW (window
);
4240 struct text_pos start
;
4241 int this_scroll_margin
;
4242 /* True if we fiddled the window vscroll field without really scrolling. */
4244 int x
, y
, rtop
, rbot
, rowh
, vpos
;
4246 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4248 /* If PT is not visible in WINDOW, move back one half of
4249 the screen. Allow PT to be partially visible, otherwise
4250 something like (scroll-down 1) with PT in the line before
4251 the partially visible one would recenter. */
4253 if (!pos_visible_p (w
, PT
, &x
, &y
, &rtop
, &rbot
, &rowh
, &vpos
))
4255 /* Move backward half the height of the window. Performance note:
4256 vmotion used here is about 10% faster, but would give wrong
4257 results for variable height lines. */
4258 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4259 it
.current_y
= it
.last_visible_y
;
4260 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
4262 /* The function move_iterator_vertically may move over more than
4263 the specified y-distance. If it->w is small, e.g. a
4264 mini-buffer window, we may end up in front of the window's
4265 display area. This is the case when Start displaying at the
4266 start of the line containing PT in this case. */
4267 if (it
.current_y
<= 0)
4269 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
4270 move_it_vertically_backward (&it
, 0);
4274 start
= it
.current
.pos
;
4276 else if (auto_window_vscroll_p
)
4278 if (rtop
|| rbot
) /* partially visible */
4281 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4283 dy
= max ((window_box_height (w
)
4284 - next_screen_context_lines
* dy
),
4290 /* Only vscroll backwards if already vscrolled forwards. */
4291 if (w
->vscroll
< 0 && rtop
> 0)
4293 px
= max (0, -w
->vscroll
- min (rtop
, -dy
));
4294 Fset_window_vscroll (window
, make_number (px
), Qt
);
4300 /* Do vscroll if already vscrolled or only display line. */
4301 if (rbot
> 0 && (w
->vscroll
< 0 || vpos
== 0))
4303 px
= max (0, -w
->vscroll
+ min (rbot
, dy
));
4304 Fset_window_vscroll (window
, make_number (px
), Qt
);
4308 /* Maybe modify window start instead of scrolling. */
4309 if (rbot
> 0 || w
->vscroll
< 0)
4313 Fset_window_vscroll (window
, make_number (0), Qt
);
4314 /* If there are other text lines above the current row,
4315 move window start to current row. Else to next row. */
4317 spos
= XINT (Fline_beginning_position (Qnil
));
4319 spos
= min (XINT (Fline_end_position (Qnil
)) + 1, ZV
);
4320 set_marker_restricted (w
->start
, make_number (spos
),
4322 w
->start_at_line_beg
= Qt
;
4323 w
->update_mode_line
= Qt
;
4324 XSETFASTINT (w
->last_modified
, 0);
4325 XSETFASTINT (w
->last_overlay_modified
, 0);
4326 /* Set force_start so that redisplay_window will run the
4327 window-scroll-functions. */
4328 w
->force_start
= Qt
;
4333 /* Cancel previous vscroll. */
4334 Fset_window_vscroll (window
, make_number (0), Qt
);
4337 /* If scroll_preserve_screen_position is non-nil, we try to set
4338 point in the same window line as it is now, so get that line. */
4339 if (!NILP (Vscroll_preserve_screen_position
))
4341 /* We preserve the goal pixel coordinate across consecutive
4342 calls to scroll-up, scroll-down and other commands that
4343 have the `scroll-command' property. This avoids the
4344 possibility of point becoming "stuck" on a tall line when
4345 scrolling by one line. */
4346 if (window_scroll_pixel_based_preserve_y
< 0
4347 || !SYMBOLP (current_kboard
->Vlast_command
)
4348 || NILP (Fget (current_kboard
->Vlast_command
, Qscroll_command
)))
4350 start_display (&it
, w
, start
);
4351 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4352 window_scroll_pixel_based_preserve_y
= it
.current_y
;
4353 window_scroll_pixel_based_preserve_x
= it
.current_x
;
4357 window_scroll_pixel_based_preserve_y
4358 = window_scroll_pixel_based_preserve_x
= -1;
4360 /* Move iterator it from start the specified distance forward or
4361 backward. The result is the new window start. */
4362 start_display (&it
, w
, start
);
4365 int start_pos
= IT_CHARPOS (it
);
4366 int dy
= WINDOW_FRAME_LINE_HEIGHT (w
);
4367 dy
= max ((window_box_height (w
)
4368 - next_screen_context_lines
* dy
),
4371 /* Note that move_it_vertically always moves the iterator to the
4372 start of a line. So, if the last line doesn't have a newline,
4373 we would end up at the start of the line ending at ZV. */
4376 move_it_vertically_backward (&it
, -dy
);
4377 /* Ensure we actually do move, e.g. in case we are currently
4378 looking at an image that is taller that the window height. */
4379 while (start_pos
== IT_CHARPOS (it
)
4380 && start_pos
> BEGV
)
4381 move_it_by_lines (&it
, -1, 1);
4385 move_it_to (&it
, ZV
, -1, it
.current_y
+ dy
, -1,
4386 MOVE_TO_POS
| MOVE_TO_Y
);
4387 /* Ensure we actually do move, e.g. in case we are currently
4388 looking at an image that is taller that the window height. */
4389 while (start_pos
== IT_CHARPOS (it
)
4391 move_it_by_lines (&it
, 1, 1);
4395 move_it_by_lines (&it
, n
, 1);
4397 /* We failed if we find ZV is already on the screen (scrolling up,
4398 means there's nothing past the end), or if we can't start any
4399 earlier (scrolling down, means there's nothing past the top). */
4400 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
4401 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
4403 if (IT_CHARPOS (it
) == ZV
)
4405 if (it
.current_y
< it
.last_visible_y
4406 && (it
.current_y
+ it
.max_ascent
+ it
.max_descent
4407 > it
.last_visible_y
))
4409 /* The last line was only partially visible, make it fully
4411 w
->vscroll
= (it
.last_visible_y
4412 - it
.current_y
+ it
.max_ascent
+ it
.max_descent
);
4413 adjust_glyphs (it
.f
);
4417 else if (n
< 0) /* could happen with empty buffers */
4418 xsignal0 (Qbeginning_of_buffer
);
4420 xsignal0 (Qend_of_buffer
);
4424 if (w
->vscroll
!= 0)
4425 /* The first line was only partially visible, make it fully
4431 xsignal0 (Qbeginning_of_buffer
);
4434 /* If control gets here, then we vscrolled. */
4436 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4438 /* Don't try to change the window start below. */
4444 int pos
= IT_CHARPOS (it
);
4447 /* If in the middle of a multi-glyph character move forward to
4448 the next character. */
4449 if (in_display_vector_p (&it
))
4452 move_it_to (&it
, pos
, -1, -1, -1, MOVE_TO_POS
);
4455 /* Set the window start, and set up the window for redisplay. */
4456 set_marker_restricted (w
->start
, make_number (pos
),
4458 bytepos
= XMARKER (w
->start
)->bytepos
;
4459 w
->start_at_line_beg
= ((pos
== BEGV
|| FETCH_BYTE (bytepos
- 1) == '\n')
4461 w
->update_mode_line
= Qt
;
4462 XSETFASTINT (w
->last_modified
, 0);
4463 XSETFASTINT (w
->last_overlay_modified
, 0);
4464 /* Set force_start so that redisplay_window will run the
4465 window-scroll-functions. */
4466 w
->force_start
= Qt
;
4469 /* The rest of this function uses current_y in a nonstandard way,
4470 not including the height of the header line if any. */
4471 it
.current_y
= it
.vpos
= 0;
4473 /* Move PT out of scroll margins.
4474 This code wants current_y to be zero at the window start position
4475 even if there is a header line. */
4476 this_scroll_margin
= max (0, scroll_margin
);
4477 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->total_lines
) / 4);
4478 this_scroll_margin
*= FRAME_LINE_HEIGHT (it
.f
);
4482 /* We moved the window start towards ZV, so PT may be now
4483 in the scroll margin at the top. */
4484 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
4485 if (IT_CHARPOS (it
) == PT
&& it
.current_y
>= this_scroll_margin
4486 && (NILP (Vscroll_preserve_screen_position
)
4487 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4488 /* We found PT at a legitimate height. Leave it alone. */
4490 else if (window_scroll_pixel_based_preserve_y
>= 0)
4492 /* If we have a header line, take account of it.
4493 This is necessary because we set it.current_y to 0, above. */
4494 move_it_to (&it
, -1,
4495 window_scroll_pixel_based_preserve_x
,
4496 window_scroll_pixel_based_preserve_y
4497 - (WINDOW_WANTS_HEADER_LINE_P (w
) ? 1 : 0 ),
4498 -1, MOVE_TO_Y
| MOVE_TO_X
);
4499 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4503 while (it
.current_y
< this_scroll_margin
)
4505 int prev
= it
.current_y
;
4506 move_it_by_lines (&it
, 1, 1);
4507 if (prev
== it
.current_y
)
4510 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4515 int charpos
, bytepos
;
4518 /* Save our position, for the
4519 window_scroll_pixel_based_preserve_y case. */
4520 charpos
= IT_CHARPOS (it
);
4521 bytepos
= IT_BYTEPOS (it
);
4523 /* We moved the window start towards BEGV, so PT may be now
4524 in the scroll margin at the bottom. */
4525 move_it_to (&it
, PT
, -1,
4526 (it
.last_visible_y
- CURRENT_HEADER_LINE_HEIGHT (w
)
4527 - this_scroll_margin
- 1),
4529 MOVE_TO_POS
| MOVE_TO_Y
);
4531 /* Save our position, in case it's correct. */
4532 charpos
= IT_CHARPOS (it
);
4533 bytepos
= IT_BYTEPOS (it
);
4535 /* See if point is on a partially visible line at the end. */
4536 if (it
.what
== IT_EOB
)
4537 partial_p
= it
.current_y
+ it
.ascent
+ it
.descent
> it
.last_visible_y
;
4540 move_it_by_lines (&it
, 1, 1);
4541 partial_p
= it
.current_y
> it
.last_visible_y
;
4544 if (charpos
== PT
&& !partial_p
4545 && (NILP (Vscroll_preserve_screen_position
)
4546 || EQ (Vscroll_preserve_screen_position
, Qt
)))
4547 /* We found PT before we found the display margin, so PT is ok. */
4549 else if (window_scroll_pixel_based_preserve_y
>= 0)
4551 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4552 start_display (&it
, w
, start
);
4553 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
4554 here because we called start_display again and did not
4555 alter it.current_y this time. */
4556 move_it_to (&it
, -1, window_scroll_pixel_based_preserve_x
,
4557 window_scroll_pixel_based_preserve_y
, -1,
4558 MOVE_TO_Y
| MOVE_TO_X
);
4559 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4564 /* The last line was only partially visible, so back up two
4565 lines to make sure we're on a fully visible line. */
4567 move_it_by_lines (&it
, -2, 0);
4568 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
4571 /* No, the position we saved is OK, so use it. */
4572 SET_PT_BOTH (charpos
, bytepos
);
4578 /* Implementation of window_scroll that works based on screen lines.
4579 See the comment of window_scroll for parameter descriptions. */
4582 window_scroll_line_based (Lisp_Object window
, int n
, int whole
, int noerror
)
4584 register struct window
*w
= XWINDOW (window
);
4585 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
4586 register int pos
, pos_byte
;
4587 register int ht
= window_internal_height (w
);
4588 register Lisp_Object tem
;
4592 Lisp_Object original_pos
= Qnil
;
4594 /* If scrolling screen-fulls, compute the number of lines to
4595 scroll from the window's height. */
4597 n
*= max (1, ht
- next_screen_context_lines
);
4599 startpos
= marker_position (w
->start
);
4601 if (!NILP (Vscroll_preserve_screen_position
))
4603 if (window_scroll_preserve_vpos
<= 0
4604 || !SYMBOLP (current_kboard
->Vlast_command
)
4605 || NILP (Fget (current_kboard
->Vlast_command
, Qscroll_command
)))
4607 struct position posit
4608 = *compute_motion (startpos
, 0, 0, 0,
4610 -1, XINT (w
->hscroll
),
4612 window_scroll_preserve_vpos
= posit
.vpos
;
4613 window_scroll_preserve_hpos
= posit
.hpos
+ XINT (w
->hscroll
);
4616 original_pos
= Fcons (make_number (window_scroll_preserve_hpos
),
4617 make_number (window_scroll_preserve_vpos
));
4620 XSETFASTINT (tem
, PT
);
4621 tem
= Fpos_visible_in_window_p (tem
, window
, Qnil
);
4625 Fvertical_motion (make_number (- (ht
/ 2)), window
);
4630 lose
= n
< 0 && PT
== BEGV
;
4631 Fvertical_motion (make_number (n
), window
);
4635 SET_PT_BOTH (opoint
, opoint_byte
);
4642 xsignal0 (Qbeginning_of_buffer
);
4647 int this_scroll_margin
= scroll_margin
;
4649 /* Don't use a scroll margin that is negative or too large. */
4650 if (this_scroll_margin
< 0)
4651 this_scroll_margin
= 0;
4653 if (XINT (w
->total_lines
) < 4 * scroll_margin
)
4654 this_scroll_margin
= XINT (w
->total_lines
) / 4;
4656 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
4657 w
->start_at_line_beg
= bolp
;
4658 w
->update_mode_line
= Qt
;
4659 XSETFASTINT (w
->last_modified
, 0);
4660 XSETFASTINT (w
->last_overlay_modified
, 0);
4661 /* Set force_start so that redisplay_window will run
4662 the window-scroll-functions. */
4663 w
->force_start
= Qt
;
4665 if (!NILP (Vscroll_preserve_screen_position
)
4666 && (whole
|| !EQ (Vscroll_preserve_screen_position
, Qt
)))
4668 SET_PT_BOTH (pos
, pos_byte
);
4669 Fvertical_motion (original_pos
, window
);
4671 /* If we scrolled forward, put point enough lines down
4672 that it is outside the scroll margin. */
4677 if (this_scroll_margin
> 0)
4679 SET_PT_BOTH (pos
, pos_byte
);
4680 Fvertical_motion (make_number (this_scroll_margin
), window
);
4686 if (top_margin
<= opoint
)
4687 SET_PT_BOTH (opoint
, opoint_byte
);
4688 else if (!NILP (Vscroll_preserve_screen_position
))
4690 SET_PT_BOTH (pos
, pos_byte
);
4691 Fvertical_motion (original_pos
, window
);
4694 SET_PT (top_margin
);
4700 /* If we scrolled backward, put point near the end of the window
4701 but not within the scroll margin. */
4702 SET_PT_BOTH (pos
, pos_byte
);
4703 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
4704 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
4707 bottom_margin
= PT
+ 1;
4709 if (bottom_margin
> opoint
)
4710 SET_PT_BOTH (opoint
, opoint_byte
);
4713 if (!NILP (Vscroll_preserve_screen_position
))
4715 SET_PT_BOTH (pos
, pos_byte
);
4716 Fvertical_motion (original_pos
, window
);
4719 Fvertical_motion (make_number (-1), window
);
4728 xsignal0 (Qend_of_buffer
);
4733 /* Scroll selected_window up or down. If N is nil, scroll a
4734 screen-full which is defined as the height of the window minus
4735 next_screen_context_lines. If N is the symbol `-', scroll.
4736 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4737 up. This is the guts of Fscroll_up and Fscroll_down. */
4740 scroll_command (Lisp_Object n
, int direction
)
4742 int count
= SPECPDL_INDEX ();
4744 xassert (eabs (direction
) == 1);
4746 /* If selected window's buffer isn't current, make it current for
4747 the moment. But don't screw up if window_scroll gets an error. */
4748 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
4750 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4751 Fset_buffer (XWINDOW (selected_window
)->buffer
);
4753 /* Make redisplay consider other windows than just selected_window. */
4754 ++windows_or_buffers_changed
;
4758 window_scroll (selected_window
, direction
, 1, 0);
4759 else if (EQ (n
, Qminus
))
4760 window_scroll (selected_window
, -direction
, 1, 0);
4763 n
= Fprefix_numeric_value (n
);
4764 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
4767 unbind_to (count
, Qnil
);
4770 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "^P",
4771 doc
: /* Scroll text of selected window upward ARG lines.
4772 If ARG is omitted or nil, scroll upward by a near full screen.
4773 A near full screen is `next-screen-context-lines' less than a full screen.
4774 Negative ARG means scroll downward.
4775 If ARG is the atom `-', scroll downward by nearly full screen.
4776 When calling from a program, supply as argument a number, nil, or `-'. */)
4779 scroll_command (arg
, 1);
4783 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "^P",
4784 doc
: /* Scroll text of selected window down ARG lines.
4785 If ARG is omitted or nil, scroll down by a near full screen.
4786 A near full screen is `next-screen-context-lines' less than a full screen.
4787 Negative ARG means scroll upward.
4788 If ARG is the atom `-', scroll upward by nearly full screen.
4789 When calling from a program, supply as argument a number, nil, or `-'. */)
4792 scroll_command (arg
, -1);
4796 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
4797 doc
: /* Return the other window for \"other window scroll\" commands.
4798 If `other-window-scroll-buffer' is non-nil, a window
4799 showing that buffer is used.
4800 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4801 specifies the window. This takes precedence over
4802 `other-window-scroll-buffer'. */)
4807 if (MINI_WINDOW_P (XWINDOW (selected_window
))
4808 && !NILP (Vminibuf_scroll_window
))
4809 window
= Vminibuf_scroll_window
;
4810 /* If buffer is specified, scroll that buffer. */
4811 else if (!NILP (Vother_window_scroll_buffer
))
4813 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
4815 window
= display_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
4819 /* Nothing specified; look for a neighboring window on the same
4821 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
4823 if (EQ (window
, selected_window
))
4824 /* That didn't get us anywhere; look for a window on another
4827 window
= Fnext_window (window
, Qnil
, Qt
);
4828 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
4829 && ! EQ (window
, selected_window
));
4832 CHECK_LIVE_WINDOW (window
);
4834 if (EQ (window
, selected_window
))
4835 error ("There is no other window");
4840 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
4841 doc
: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4842 A near full screen is `next-screen-context-lines' less than a full screen.
4843 The next window is the one below the current one; or the one at the top
4844 if the current one is at the bottom. Negative ARG means scroll downward.
4845 If ARG is the atom `-', scroll downward by nearly full screen.
4846 When calling from a program, supply as argument a number, nil, or `-'.
4848 If `other-window-scroll-buffer' is non-nil, scroll the window
4849 showing that buffer, popping the buffer up if necessary.
4850 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4851 specifies the window to scroll. This takes precedence over
4852 `other-window-scroll-buffer'. */)
4857 int count
= SPECPDL_INDEX ();
4859 window
= Fother_window_for_scrolling ();
4860 w
= XWINDOW (window
);
4862 /* Don't screw up if window_scroll gets an error. */
4863 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
4864 ++windows_or_buffers_changed
;
4866 Fset_buffer (w
->buffer
);
4867 SET_PT (marker_position (w
->pointm
));
4870 window_scroll (window
, 1, 1, 1);
4871 else if (EQ (arg
, Qminus
))
4872 window_scroll (window
, -1, 1, 1);
4878 window_scroll (window
, XINT (arg
), 0, 1);
4881 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
4882 unbind_to (count
, Qnil
);
4887 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 2, "^P\np",
4888 doc
: /* Scroll selected window display ARG columns left.
4889 Default for ARG is window width minus 2.
4890 Value is the total amount of leftward horizontal scrolling in
4891 effect after the change.
4892 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4893 lower bound for automatic scrolling, i.e. automatic scrolling
4894 will not scroll a window to a column less than the value returned
4895 by this function. This happens in an interactive call. */)
4896 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4900 struct window
*w
= XWINDOW (selected_window
);
4903 XSETFASTINT (arg
, window_body_cols (w
) - 2);
4905 arg
= Fprefix_numeric_value (arg
);
4907 hscroll
= XINT (w
->hscroll
) + XINT (arg
);
4908 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4910 if (!NILP (set_minimum
))
4911 w
->min_hscroll
= w
->hscroll
;
4916 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 2, "^P\np",
4917 doc
: /* Scroll selected window display ARG columns right.
4918 Default for ARG is window width minus 2.
4919 Value is the total amount of leftward horizontal scrolling in
4920 effect after the change.
4921 If SET-MINIMUM is non-nil, the new scroll amount becomes the
4922 lower bound for automatic scrolling, i.e. automatic scrolling
4923 will not scroll a window to a column less than the value returned
4924 by this function. This happens in an interactive call. */)
4925 (register Lisp_Object arg
, Lisp_Object set_minimum
)
4929 struct window
*w
= XWINDOW (selected_window
);
4932 XSETFASTINT (arg
, window_body_cols (w
) - 2);
4934 arg
= Fprefix_numeric_value (arg
);
4936 hscroll
= XINT (w
->hscroll
) - XINT (arg
);
4937 result
= Fset_window_hscroll (selected_window
, make_number (hscroll
));
4939 if (!NILP (set_minimum
))
4940 w
->min_hscroll
= w
->hscroll
;
4945 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window
, Sminibuffer_selected_window
, 0, 0, 0,
4946 doc
: /* Return the window which was selected when entering the minibuffer.
4947 Returns nil, if selected window is not a minibuffer window. */)
4950 if (minibuf_level
> 0
4951 && MINI_WINDOW_P (XWINDOW (selected_window
))
4952 && WINDOW_LIVE_P (minibuf_selected_window
))
4953 return minibuf_selected_window
;
4958 /* Value is the number of lines actually displayed in window W,
4959 as opposed to its height. */
4962 displayed_window_lines (struct window
*w
)
4965 struct text_pos start
;
4966 int height
= window_box_height (w
);
4967 struct buffer
*old_buffer
;
4970 if (XBUFFER (w
->buffer
) != current_buffer
)
4972 old_buffer
= current_buffer
;
4973 set_buffer_internal (XBUFFER (w
->buffer
));
4978 /* In case W->start is out of the accessible range, do something
4979 reasonable. This happens in Info mode when Info-scroll-down
4980 calls (recenter -1) while W->start is 1. */
4981 if (XMARKER (w
->start
)->charpos
< BEGV
)
4982 SET_TEXT_POS (start
, BEGV
, BEGV_BYTE
);
4983 else if (XMARKER (w
->start
)->charpos
> ZV
)
4984 SET_TEXT_POS (start
, ZV
, ZV_BYTE
);
4986 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
4988 start_display (&it
, w
, start
);
4989 move_it_vertically (&it
, height
);
4990 bottom_y
= line_bottom_y (&it
);
4992 /* rms: On a non-window display,
4993 the value of it.vpos at the bottom of the screen
4994 seems to be 1 larger than window_box_height (w).
4995 This kludge fixes a bug whereby (move-to-window-line -1)
4996 when ZV is on the last screen line
4997 moves to the previous screen line instead of the last one. */
4998 if (! FRAME_WINDOW_P (XFRAME (w
->frame
)))
5001 /* Add in empty lines at the bottom of the window. */
5002 if (bottom_y
< height
)
5004 int uy
= FRAME_LINE_HEIGHT (it
.f
);
5005 it
.vpos
+= (height
- bottom_y
+ uy
- 1) / uy
;
5009 set_buffer_internal (old_buffer
);
5015 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
5016 doc
: /* Center point in selected window and maybe redisplay frame.
5017 With prefix argument ARG, recenter putting point on screen line ARG
5018 relative to the selected window. If ARG is negative, it counts up from the
5019 bottom of the window. (ARG should be less than the height of the window.)
5021 If ARG is omitted or nil, then recenter with point on the middle line of
5022 the selected window; if the variable `recenter-redisplay' is non-nil,
5023 also erase the entire frame and redraw it (when `auto-resize-tool-bars'
5024 is set to `grow-only', this resets the tool-bar's height to the minimum
5025 height needed); if `recenter-redisplay' has the special value `tty',
5026 then only tty frame are redrawn.
5028 Just C-u as prefix means put point in the center of the window
5029 and redisplay normally--don't erase and redraw the frame. */)
5030 (register Lisp_Object arg
)
5032 struct window
*w
= XWINDOW (selected_window
);
5033 struct buffer
*buf
= XBUFFER (w
->buffer
);
5034 struct buffer
*obuf
= current_buffer
;
5036 int charpos
, bytepos
;
5038 int this_scroll_margin
;
5040 /* If redisplay is suppressed due to an error, try again. */
5041 obuf
->display_error_modiff
= 0;
5045 if (!NILP (Vrecenter_redisplay
)
5046 && (!EQ (Vrecenter_redisplay
, Qtty
)
5047 || !NILP (Ftty_type (selected_frame
))))
5051 /* Invalidate pixel data calculated for all compositions. */
5052 for (i
= 0; i
< n_compositions
; i
++)
5053 composition_table
[i
]->font
= NULL
;
5055 WINDOW_XFRAME (w
)->minimize_tool_bar_window_p
= 1;
5057 Fredraw_frame (WINDOW_FRAME (w
));
5058 SET_FRAME_GARBAGED (WINDOW_XFRAME (w
));
5063 else if (CONSP (arg
)) /* Just C-u. */
5067 arg
= Fprefix_numeric_value (arg
);
5072 set_buffer_internal (buf
);
5074 /* Do this after making BUF current
5075 in case scroll_margin is buffer-local. */
5076 this_scroll_margin
= max (0, scroll_margin
);
5077 this_scroll_margin
= min (this_scroll_margin
,
5078 XFASTINT (w
->total_lines
) / 4);
5080 /* Handle centering on a graphical frame specially. Such frames can
5081 have variable-height lines and centering point on the basis of
5082 line counts would lead to strange effects. */
5083 if (FRAME_WINDOW_P (XFRAME (w
->frame
)))
5090 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5091 start_display (&it
, w
, pt
);
5092 move_it_vertically_backward (&it
, window_box_height (w
) / 2);
5093 charpos
= IT_CHARPOS (it
);
5094 bytepos
= IT_BYTEPOS (it
);
5101 int extra_line_spacing
;
5102 int h
= window_box_height (w
);
5104 iarg
= - max (-iarg
, this_scroll_margin
);
5106 SET_TEXT_POS (pt
, PT
, PT_BYTE
);
5107 start_display (&it
, w
, pt
);
5109 /* Be sure we have the exact height of the full line containing PT. */
5110 move_it_by_lines (&it
, 0, 1);
5112 /* The amount of pixels we have to move back is the window
5113 height minus what's displayed in the line containing PT,
5114 and the lines below. */
5117 move_it_by_lines (&it
, nlines
, 1);
5119 if (it
.vpos
== nlines
)
5123 /* Last line has no newline */
5124 h
-= line_bottom_y (&it
);
5128 /* Don't reserve space for extra line spacing of last line. */
5129 extra_line_spacing
= it
.max_extra_line_spacing
;
5131 /* If we can't move down NLINES lines because we hit
5132 the end of the buffer, count in some empty lines. */
5133 if (it
.vpos
< nlines
)
5136 extra_line_spacing
= it
.extra_line_spacing
;
5137 h
-= nlines
* (FRAME_LINE_HEIGHT (it
.f
) + extra_line_spacing
);
5142 /* Now find the new top line (starting position) of the window. */
5143 start_display (&it
, w
, pt
);
5145 move_it_vertically_backward (&it
, h
);
5147 /* If extra line spacing is present, we may move too far
5148 back. This causes the last line to be only partially
5149 visible (which triggers redisplay to recenter that line
5150 in the middle), so move forward.
5151 But ignore extra line spacing on last line, as it is not
5152 considered to be part of the visible height of the line.
5154 h
+= extra_line_spacing
;
5155 while (-it
.current_y
> h
)
5156 move_it_by_lines (&it
, 1, 1);
5158 charpos
= IT_CHARPOS (it
);
5159 bytepos
= IT_BYTEPOS (it
);
5163 struct position pos
;
5165 iarg
= max (iarg
, this_scroll_margin
);
5167 pos
= *vmotion (PT
, -iarg
, w
);
5168 charpos
= pos
.bufpos
;
5169 bytepos
= pos
.bytepos
;
5174 struct position pos
;
5175 int ht
= window_internal_height (w
);
5182 /* Don't let it get into the margin at either top or bottom. */
5183 iarg
= max (iarg
, this_scroll_margin
);
5184 iarg
= min (iarg
, ht
- this_scroll_margin
- 1);
5186 pos
= *vmotion (PT
, - iarg
, w
);
5187 charpos
= pos
.bufpos
;
5188 bytepos
= pos
.bytepos
;
5191 /* Set the new window start. */
5192 set_marker_both (w
->start
, w
->buffer
, charpos
, bytepos
);
5193 w
->window_end_valid
= Qnil
;
5195 w
->optional_new_start
= Qt
;
5197 if (bytepos
== BEGV_BYTE
|| FETCH_BYTE (bytepos
- 1) == '\n')
5198 w
->start_at_line_beg
= Qt
;
5200 w
->start_at_line_beg
= Qnil
;
5202 set_buffer_internal (obuf
);
5206 DEFUN ("window-text-height", Fwindow_text_height
, Swindow_text_height
,
5208 doc
: /* Return the height in lines of the text display area of WINDOW.
5209 WINDOW defaults to the selected window.
5211 The return value does not include the mode line, any header line, nor
5212 any partial-height lines in the text display area. */)
5213 (Lisp_Object window
)
5215 struct window
*w
= decode_window (window
);
5216 int pixel_height
= window_box_height (w
);
5217 int line_height
= pixel_height
/ FRAME_LINE_HEIGHT (XFRAME (w
->frame
));
5218 return make_number (line_height
);
5223 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
5225 doc
: /* Position point relative to window.
5226 With no argument, position point at center of window.
5227 An argument specifies vertical position within the window;
5228 zero means top of window, negative means relative to bottom of window. */)
5231 struct window
*w
= XWINDOW (selected_window
);
5235 int this_scroll_margin
;
5238 window
= selected_window
;
5239 start
= marker_position (w
->start
);
5240 if (start
< BEGV
|| start
> ZV
)
5242 int height
= window_internal_height (w
);
5243 Fvertical_motion (make_number (- (height
/ 2)), window
);
5244 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
5245 w
->start_at_line_beg
= Fbolp ();
5246 w
->force_start
= Qt
;
5249 Fgoto_char (w
->start
);
5251 lines
= displayed_window_lines (w
);
5254 this_scroll_margin
= max (0, scroll_margin
);
5255 this_scroll_margin
= min (this_scroll_margin
, lines
/ 4);
5259 XSETFASTINT (arg
, lines
/ 2);
5262 int iarg
= XINT (Fprefix_numeric_value (arg
));
5265 iarg
= iarg
+ lines
;
5267 #if 0 /* This code would prevent move-to-window-line from moving point
5268 to a place inside the scroll margins (which would cause the
5269 next redisplay to scroll). I wrote this code, but then concluded
5270 it is probably better not to install it. However, it is here
5271 inside #if 0 so as not to lose it. -- rms. */
5273 /* Don't let it get into the margin at either top or bottom. */
5274 iarg
= max (iarg
, this_scroll_margin
);
5275 iarg
= min (iarg
, lines
- this_scroll_margin
- 1);
5278 arg
= make_number (iarg
);
5281 /* Skip past a partially visible first line. */
5283 XSETINT (arg
, XINT (arg
) + 1);
5285 return Fvertical_motion (arg
, window
);
5290 /***********************************************************************
5291 Window Configuration
5292 ***********************************************************************/
5294 struct save_window_data
5297 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5298 Lisp_Object selected_frame
;
5299 Lisp_Object current_window
;
5300 Lisp_Object current_buffer
;
5301 Lisp_Object minibuf_scroll_window
;
5302 Lisp_Object minibuf_selected_window
;
5303 Lisp_Object root_window
;
5304 Lisp_Object focus_frame
;
5305 /* A vector, each of whose elements is a struct saved_window
5307 Lisp_Object saved_windows
;
5309 /* All fields above are traced by the GC.
5310 From `fame-cols' down, the fields are ignored by the GC. */
5312 int frame_cols
, frame_lines
, frame_menu_bar_lines
;
5313 int frame_tool_bar_lines
;
5316 /* This is saved as a Lisp_Vector */
5319 /* these first two must agree with struct Lisp_Vector in lisp.h */
5321 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
5324 Lisp_Object buffer
, start
, pointm
, mark
;
5325 Lisp_Object left_col
, top_line
, total_cols
, total_lines
;
5326 Lisp_Object normal_cols
, normal_lines
;
5327 Lisp_Object hscroll
, min_hscroll
;
5328 Lisp_Object parent
, prev
;
5329 Lisp_Object start_at_line_beg
;
5330 Lisp_Object display_table
;
5331 Lisp_Object left_margin_cols
, right_margin_cols
;
5332 Lisp_Object left_fringe_width
, right_fringe_width
, fringes_outside_margins
;
5333 Lisp_Object scroll_bar_width
, vertical_scroll_bar_type
, dedicated
;
5334 Lisp_Object inhibit_recombine
;
5335 Lisp_Object window_parameters
;
5338 #define SAVED_WINDOW_N(swv,n) \
5339 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5341 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
5342 doc
: /* Return t if OBJECT is a window-configuration object. */)
5343 (Lisp_Object object
)
5345 return WINDOW_CONFIGURATIONP (object
) ? Qt
: Qnil
;
5348 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
5349 doc
: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5350 (Lisp_Object config
)
5352 register struct save_window_data
*data
;
5353 struct Lisp_Vector
*saved_windows
;
5355 CHECK_WINDOW_CONFIGURATION (config
);
5357 data
= (struct save_window_data
*) XVECTOR (config
);
5358 saved_windows
= XVECTOR (data
->saved_windows
);
5359 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5362 DEFUN ("set-window-configuration", Fset_window_configuration
,
5363 Sset_window_configuration
, 1, 1, 0,
5364 doc
: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5365 CONFIGURATION must be a value previously returned
5366 by `current-window-configuration' (which see).
5367 If CONFIGURATION was made from a frame that is now deleted,
5368 only frame-independent values can be restored. In this case,
5369 the return value is nil. Otherwise the value is t. */)
5370 (Lisp_Object configuration
)
5372 register struct save_window_data
*data
;
5373 struct Lisp_Vector
*saved_windows
;
5374 Lisp_Object new_current_buffer
;
5379 CHECK_WINDOW_CONFIGURATION (configuration
);
5381 data
= (struct save_window_data
*) XVECTOR (configuration
);
5382 saved_windows
= XVECTOR (data
->saved_windows
);
5384 new_current_buffer
= data
->current_buffer
;
5385 if (NILP (XBUFFER (new_current_buffer
)->name
))
5386 new_current_buffer
= Qnil
;
5389 if (XBUFFER (new_current_buffer
) == current_buffer
)
5390 /* The code further down "preserves point" by saving here PT in
5391 old_point and then setting it later back into PT. When the
5392 current-selected-window and the final-selected-window both show
5393 the current buffer, this suffers from the problem that the
5394 current PT is the window-point of the current-selected-window,
5395 while the final PT is the point of the final-selected-window, so
5396 this copy from one PT to the other would end up moving the
5397 window-point of the final-selected-window to the window-point of
5398 the current-selected-window. So we have to be careful which
5399 point of the current-buffer we copy into old_point. */
5400 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5401 && WINDOWP (selected_window
)
5402 && EQ (XWINDOW (selected_window
)->buffer
, new_current_buffer
)
5403 && !EQ (selected_window
, data
->current_window
))
5404 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5408 /* BUF_PT (XBUFFER (new_current_buffer)) gives us the position of
5409 point in new_current_buffer as of the last time this buffer was
5410 used. This can be non-deterministic since it can be changed by
5411 things like jit-lock by mere temporary selection of some random
5412 window that happens to show this buffer.
5413 So if possible we want this arbitrary choice of "which point" to
5414 be the one from the to-be-selected-window so as to prevent this
5415 window's cursor from being copied from another window. */
5416 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
)
5417 /* If current_window = selected_window, its point is in BUF_PT. */
5418 && !EQ (selected_window
, data
->current_window
))
5419 old_point
= XMARKER (XWINDOW (data
->current_window
)->pointm
)->charpos
;
5421 old_point
= BUF_PT (XBUFFER (new_current_buffer
));
5424 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
5427 /* If f is a dead frame, don't bother rebuilding its window tree.
5428 However, there is other stuff we should still try to do below. */
5429 if (FRAME_LIVE_P (f
))
5432 Lisp_Object dead_windows
= Qnil
;
5433 register struct window
*w
;
5434 register struct saved_window
*p
;
5435 struct window
*root_window
;
5436 struct window
**leaf_windows
;
5440 /* If the frame has been resized since this window configuration was
5441 made, we change the frame to the size specified in the
5442 configuration, restore the configuration, and then resize it
5443 back. We keep track of the prevailing height in these variables. */
5444 int previous_frame_lines
= FRAME_LINES (f
);
5445 int previous_frame_cols
= FRAME_COLS (f
);
5446 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5447 int previous_frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5449 /* The mouse highlighting code could get screwed up
5450 if it runs during this. */
5453 if (data
->frame_lines
!= previous_frame_lines
5454 || data
->frame_cols
!= previous_frame_cols
)
5455 change_frame_size (f
, data
->frame_lines
,
5456 data
->frame_cols
, 0, 0, 0);
5457 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5458 if (data
->frame_menu_bar_lines
5459 != previous_frame_menu_bar_lines
)
5460 x_set_menu_bar_lines (f
, make_number (data
->frame_menu_bar_lines
),
5462 #ifdef HAVE_WINDOW_SYSTEM
5463 if (data
->frame_tool_bar_lines
5464 != previous_frame_tool_bar_lines
)
5465 x_set_tool_bar_lines (f
, make_number (data
->frame_tool_bar_lines
),
5470 /* "Swap out" point from the selected window's buffer
5471 into the window itself. (Normally the pointm of the selected
5472 window holds garbage.) We do this now, before
5473 restoring the window contents, and prevent it from
5474 being done later on when we select a new window. */
5475 if (! NILP (XWINDOW (selected_window
)->buffer
))
5477 w
= XWINDOW (selected_window
);
5478 set_marker_both (w
->pointm
,
5480 BUF_PT (XBUFFER (w
->buffer
)),
5481 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5484 windows_or_buffers_changed
++;
5485 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
5487 /* Problem: Freeing all matrices and later allocating them again
5488 is a serious redisplay flickering problem. What we would
5489 really like to do is to free only those matrices not reused
5491 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
5493 = (struct window
**) alloca (count_windows (root_window
)
5494 * sizeof (struct window
*));
5495 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
5498 Mark all windows now on frame as "deleted".
5499 Restoring the new configuration "undeletes" any that are in it.
5501 Save their current buffers in their height fields, since we may
5502 need it later, if a buffer saved in the configuration is now
5504 delete_all_subwindows (FRAME_ROOT_WINDOW (f
));
5506 for (k
= 0; k
< saved_windows
->size
; k
++)
5508 p
= SAVED_WINDOW_N (saved_windows
, k
);
5510 w
= XWINDOW (window
);
5513 if (!NILP (p
->parent
))
5514 w
->parent
= SAVED_WINDOW_N (saved_windows
,
5515 XFASTINT (p
->parent
))->window
;
5519 if (!NILP (p
->prev
))
5521 w
->prev
= SAVED_WINDOW_N (saved_windows
,
5522 XFASTINT (p
->prev
))->window
;
5523 XWINDOW (w
->prev
)->next
= p
->window
;
5528 if (!NILP (w
->parent
))
5530 if (EQ (p
->total_cols
, XWINDOW (w
->parent
)->total_cols
))
5532 XWINDOW (w
->parent
)->vchild
= p
->window
;
5533 XWINDOW (w
->parent
)->hchild
= Qnil
;
5537 XWINDOW (w
->parent
)->hchild
= p
->window
;
5538 XWINDOW (w
->parent
)->vchild
= Qnil
;
5543 /* If we squirreled away the buffer in the window's height,
5545 if (BUFFERP (w
->total_lines
))
5546 w
->buffer
= w
->total_lines
;
5547 w
->left_col
= p
->left_col
;
5548 w
->top_line
= p
->top_line
;
5549 w
->total_cols
= p
->total_cols
;
5550 w
->total_lines
= p
->total_lines
;
5551 w
->normal_cols
= p
->normal_cols
;
5552 w
->normal_lines
= p
->normal_lines
;
5553 w
->hscroll
= p
->hscroll
;
5554 w
->min_hscroll
= p
->min_hscroll
;
5555 w
->display_table
= p
->display_table
;
5556 w
->left_margin_cols
= p
->left_margin_cols
;
5557 w
->right_margin_cols
= p
->right_margin_cols
;
5558 w
->left_fringe_width
= p
->left_fringe_width
;
5559 w
->right_fringe_width
= p
->right_fringe_width
;
5560 w
->fringes_outside_margins
= p
->fringes_outside_margins
;
5561 w
->scroll_bar_width
= p
->scroll_bar_width
;
5562 w
->vertical_scroll_bar_type
= p
->vertical_scroll_bar_type
;
5563 w
->dedicated
= p
->dedicated
;
5564 w
->inhibit_recombine
= p
->inhibit_recombine
;
5565 w
->window_parameters
= p
->window_parameters
;
5566 XSETFASTINT (w
->last_modified
, 0);
5567 XSETFASTINT (w
->last_overlay_modified
, 0);
5569 /* Reinstall the saved buffer and pointers into it. */
5570 if (NILP (p
->buffer
))
5571 /* An internal window. */
5572 w
->buffer
= p
->buffer
;
5573 else if (!NILP (XBUFFER (p
->buffer
)->name
))
5574 /* If saved buffer is alive, install it. */
5576 w
->buffer
= p
->buffer
;
5577 w
->start_at_line_beg
= p
->start_at_line_beg
;
5578 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
5579 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
5580 Fset_marker (XBUFFER (w
->buffer
)->mark
,
5581 p
->mark
, w
->buffer
);
5583 /* As documented in Fcurrent_window_configuration, don't
5584 restore the location of point in the buffer which was
5585 current when the window configuration was recorded. */
5586 if (!EQ (p
->buffer
, new_current_buffer
)
5587 && XBUFFER (p
->buffer
) == current_buffer
)
5588 Fgoto_char (w
->pointm
);
5590 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
5591 /* Else unless window has a live buffer, get one. */
5593 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
5594 /* This will set the markers to beginning of visible
5596 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
5597 set_marker_restricted (w
->pointm
, make_number (0), w
->buffer
);
5598 w
->start_at_line_beg
= Qt
;
5599 if (!NILP (w
->dedicated
))
5600 /* Record this window as window as dead. */
5601 dead_windows
= Fcons (window
, dead_windows
);
5602 /* Make sure window is no more dedicated. */
5603 w
->dedicated
= Qnil
;
5606 /* Keeping window's old buffer; make sure the markers
5609 /* Set window markers at start of visible range. */
5610 if (XMARKER (w
->start
)->buffer
== 0)
5611 set_marker_restricted (w
->start
, make_number (0),
5613 if (XMARKER (w
->pointm
)->buffer
== 0)
5614 set_marker_restricted_both (w
->pointm
, w
->buffer
,
5615 BUF_PT (XBUFFER (w
->buffer
)),
5616 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5617 w
->start_at_line_beg
= Qt
;
5621 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
5622 /* Prevent "swapping out point" in the old selected window
5623 using the buffer that has been restored into it.
5624 We already swapped out point that from that window's old buffer. */
5625 selected_window
= Qnil
;
5627 /* Arrange *not* to restore point in the buffer that was
5628 current when the window configuration was saved. */
5629 if (EQ (XWINDOW (data
->current_window
)->buffer
, new_current_buffer
))
5630 set_marker_restricted (XWINDOW (data
->current_window
)->pointm
,
5631 make_number (old_point
),
5632 XWINDOW (data
->current_window
)->buffer
);
5634 Fselect_window (data
->current_window
, Qnil
);
5635 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
5638 if (NILP (data
->focus_frame
)
5639 || (FRAMEP (data
->focus_frame
)
5640 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
5641 Fredirect_frame_focus (frame
, data
->focus_frame
);
5643 #if 0 /* I don't understand why this is needed, and it causes problems
5644 when the frame's old selected window has been deleted. */
5645 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
5646 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
5650 /* Set the screen height to the value it had before this function. */
5651 if (previous_frame_lines
!= FRAME_LINES (f
)
5652 || previous_frame_cols
!= FRAME_COLS (f
))
5653 change_frame_size (f
, previous_frame_lines
, previous_frame_cols
,
5655 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5656 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
5657 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
5659 #ifdef HAVE_WINDOW_SYSTEM
5660 if (previous_frame_tool_bar_lines
!= FRAME_TOOL_BAR_LINES (f
))
5661 x_set_tool_bar_lines (f
, make_number (previous_frame_tool_bar_lines
),
5666 /* Now, free glyph matrices in windows that were not reused. */
5667 for (i
= n
= 0; i
< n_leaf_windows
; ++i
)
5669 if (NILP (leaf_windows
[i
]->buffer
))
5671 /* Assert it's not reused as a combination. */
5672 xassert (NILP (leaf_windows
[i
]->hchild
)
5673 && NILP (leaf_windows
[i
]->vchild
));
5674 free_window_matrices (leaf_windows
[i
]);
5676 else if (EQ (leaf_windows
[i
]->buffer
, new_current_buffer
))
5683 /* Scan dead buffer windows. */
5684 for (; CONSP (dead_windows
); dead_windows
= XCDR (dead_windows
))
5686 window
= XCAR (dead_windows
);
5687 if (WINDOW_LIVE_P (window
) && !EQ (window
, FRAME_ROOT_WINDOW (f
)))
5688 delete_deletable_window (window
);
5691 /* Fselect_window will have made f the selected frame, so we
5692 reselect the proper frame here. Fhandle_switch_frame will change the
5693 selected window too, but that doesn't make the call to
5694 Fselect_window above totally superfluous; it still sets f's
5696 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
5697 do_switch_frame (data
->selected_frame
, 0, 0, Qnil
);
5699 run_window_configuration_change_hook (f
);
5702 if (!NILP (new_current_buffer
))
5703 Fset_buffer (new_current_buffer
);
5705 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
5706 minibuf_selected_window
= data
->minibuf_selected_window
;
5708 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
5712 /* Delete all subwindows of the parent window of WINDOW. */
5714 delete_all_subwindows (Lisp_Object window
)
5716 register struct window
*w
;
5718 w
= XWINDOW (window
);
5720 if (!NILP (w
->next
))
5721 /* Delete WINDOW's siblings (we traverse postorderly). */
5722 delete_all_subwindows (w
->next
);
5724 w
->total_lines
= w
->buffer
; /* See Fset_window_configuration for excuse. */
5726 if (!NILP (w
->vchild
))
5728 delete_all_subwindows (w
->vchild
);
5731 else if (!NILP (w
->hchild
))
5733 delete_all_subwindows (w
->hchild
);
5736 else if (!NILP (w
->buffer
))
5739 unchain_marker (XMARKER (w
->pointm
));
5740 unchain_marker (XMARKER (w
->start
));
5744 Vwindow_list
= Qnil
;
5748 count_windows (register struct window
*window
)
5750 register int count
= 1;
5751 if (!NILP (window
->next
))
5752 count
+= count_windows (XWINDOW (window
->next
));
5753 if (!NILP (window
->vchild
))
5754 count
+= count_windows (XWINDOW (window
->vchild
));
5755 if (!NILP (window
->hchild
))
5756 count
+= count_windows (XWINDOW (window
->hchild
));
5761 /* Fill vector FLAT with leaf windows under W, starting at index I.
5762 Value is last index + 1. */
5764 get_leaf_windows (struct window
*w
, struct window
**flat
, int i
)
5768 if (!NILP (w
->hchild
))
5769 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
5770 else if (!NILP (w
->vchild
))
5771 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
5775 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
5782 /* Return a pointer to the glyph W's physical cursor is on. Value is
5783 null if W's current matrix is invalid, so that no meaningfull glyph
5786 get_phys_cursor_glyph (struct window
*w
)
5788 struct glyph_row
*row
;
5789 struct glyph
*glyph
;
5791 if (w
->phys_cursor
.vpos
>= 0
5792 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
5793 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
5795 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
5796 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
5805 save_window_save (Lisp_Object window
, struct Lisp_Vector
*vector
, int i
)
5807 register struct saved_window
*p
;
5808 register struct window
*w
;
5809 register Lisp_Object tem
;
5811 for (;!NILP (window
); window
= w
->next
)
5813 p
= SAVED_WINDOW_N (vector
, i
);
5814 w
= XWINDOW (window
);
5816 XSETFASTINT (w
->temslot
, i
); i
++;
5818 p
->buffer
= w
->buffer
;
5819 p
->left_col
= w
->left_col
;
5820 p
->top_line
= w
->top_line
;
5821 p
->total_cols
= w
->total_cols
;
5822 p
->total_lines
= w
->total_lines
;
5823 p
->normal_cols
= w
->normal_cols
;
5824 p
->normal_lines
= w
->normal_lines
;
5825 p
->hscroll
= w
->hscroll
;
5826 p
->min_hscroll
= w
->min_hscroll
;
5827 p
->display_table
= w
->display_table
;
5828 p
->left_margin_cols
= w
->left_margin_cols
;
5829 p
->right_margin_cols
= w
->right_margin_cols
;
5830 p
->left_fringe_width
= w
->left_fringe_width
;
5831 p
->right_fringe_width
= w
->right_fringe_width
;
5832 p
->fringes_outside_margins
= w
->fringes_outside_margins
;
5833 p
->scroll_bar_width
= w
->scroll_bar_width
;
5834 p
->vertical_scroll_bar_type
= w
->vertical_scroll_bar_type
;
5835 p
->dedicated
= w
->dedicated
;
5836 p
->inhibit_recombine
= w
->inhibit_recombine
;
5837 p
->window_parameters
= w
->window_parameters
;
5838 if (!NILP (w
->buffer
))
5840 /* Save w's value of point in the window configuration.
5841 If w is the selected window, then get the value of point
5842 from the buffer; pointm is garbage in the selected window. */
5843 if (EQ (window
, selected_window
))
5845 p
->pointm
= Fmake_marker ();
5846 set_marker_both (p
->pointm
, w
->buffer
,
5847 BUF_PT (XBUFFER (w
->buffer
)),
5848 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
5851 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
5853 p
->start
= Fcopy_marker (w
->start
, Qnil
);
5854 p
->start_at_line_beg
= w
->start_at_line_beg
;
5856 tem
= XBUFFER (w
->buffer
)->mark
;
5857 p
->mark
= Fcopy_marker (tem
, Qnil
);
5864 p
->start_at_line_beg
= Qnil
;
5867 if (NILP (w
->parent
))
5870 p
->parent
= XWINDOW (w
->parent
)->temslot
;
5875 p
->prev
= XWINDOW (w
->prev
)->temslot
;
5877 if (!NILP (w
->vchild
))
5878 i
= save_window_save (w
->vchild
, vector
, i
);
5879 if (!NILP (w
->hchild
))
5880 i
= save_window_save (w
->hchild
, vector
, i
);
5886 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
5887 Scurrent_window_configuration
, 0, 1, 0,
5888 doc
: /* Return an object representing the current window configuration of FRAME.
5889 If FRAME is nil or omitted, use the selected frame.
5890 This describes the number of windows, their sizes and current buffers,
5891 and for each displayed buffer, where display starts, and the positions of
5892 point and mark. An exception is made for point in the current buffer:
5893 its value is -not- saved.
5894 This also records the currently selected frame, and FRAME's focus
5895 redirection (see `redirect-frame-focus'). */)
5898 register Lisp_Object tem
;
5899 register int n_windows
;
5900 register struct save_window_data
*data
;
5905 frame
= selected_frame
;
5906 CHECK_LIVE_FRAME (frame
);
5909 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
5910 data
= ALLOCATE_PSEUDOVECTOR (struct save_window_data
, frame_cols
,
5911 PVEC_WINDOW_CONFIGURATION
);
5913 data
->frame_cols
= FRAME_COLS (f
);
5914 data
->frame_lines
= FRAME_LINES (f
);
5915 data
->frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
5916 data
->frame_tool_bar_lines
= FRAME_TOOL_BAR_LINES (f
);
5917 data
->selected_frame
= selected_frame
;
5918 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
5919 XSETBUFFER (data
->current_buffer
, current_buffer
);
5920 data
->minibuf_scroll_window
= minibuf_level
> 0 ? Vminibuf_scroll_window
: Qnil
;
5921 data
->minibuf_selected_window
= minibuf_level
> 0 ? minibuf_selected_window
: Qnil
;
5922 data
->root_window
= FRAME_ROOT_WINDOW (f
);
5923 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
5924 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
5925 data
->saved_windows
= tem
;
5926 for (i
= 0; i
< n_windows
; i
++)
5927 XVECTOR (tem
)->contents
[i
]
5928 = Fmake_vector (make_number (VECSIZE (struct saved_window
)), Qnil
);
5929 save_window_save (FRAME_ROOT_WINDOW (f
), XVECTOR (tem
), 0);
5930 XSETWINDOW_CONFIGURATION (tem
, data
);
5934 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
5936 doc
: /* Execute BODY, preserving window sizes and contents.
5937 Return the value of the last form in BODY.
5938 Restore which buffer appears in which window, where display starts,
5939 and the value of point and mark for each window.
5940 Also restore the choice of selected window.
5941 Also restore which buffer is current.
5942 Does not restore the value of point in current buffer.
5943 usage: (save-window-excursion BODY...) */)
5946 register Lisp_Object val
;
5947 register int count
= SPECPDL_INDEX ();
5949 record_unwind_protect (Fset_window_configuration
,
5950 Fcurrent_window_configuration (Qnil
));
5951 val
= Fprogn (args
);
5952 return unbind_to (count
, val
);
5955 /***********************************************************************
5957 ***********************************************************************/
5959 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
5961 doc
: /* Set width of marginal areas of window WINDOW.
5962 If WINDOW is nil, set margins of the currently selected window.
5963 Second arg LEFT-WIDTH specifies the number of character cells to
5964 reserve for the left marginal area. Optional third arg RIGHT-WIDTH
5965 does the same for the right marginal area. A nil width parameter
5966 means no margin. */)
5967 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
)
5969 struct window
*w
= decode_window (window
);
5971 /* Translate negative or zero widths to nil.
5972 Margins that are too wide have to be checked elsewhere. */
5974 if (!NILP (left_width
))
5976 CHECK_NUMBER (left_width
);
5977 if (XINT (left_width
) <= 0)
5981 if (!NILP (right_width
))
5983 CHECK_NUMBER (right_width
);
5984 if (XINT (right_width
) <= 0)
5988 if (!EQ (w
->left_margin_cols
, left_width
)
5989 || !EQ (w
->right_margin_cols
, right_width
))
5991 w
->left_margin_cols
= left_width
;
5992 w
->right_margin_cols
= right_width
;
5994 adjust_window_margins (w
);
5996 ++windows_or_buffers_changed
;
5997 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6004 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
6006 doc
: /* Get width of marginal areas of window WINDOW.
6007 If WINDOW is omitted or nil, use the currently selected window.
6008 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
6009 If a marginal area does not exist, its width will be returned
6011 (Lisp_Object window
)
6013 struct window
*w
= decode_window (window
);
6014 return Fcons (w
->left_margin_cols
, w
->right_margin_cols
);
6019 /***********************************************************************
6021 ***********************************************************************/
6023 DEFUN ("set-window-fringes", Fset_window_fringes
, Sset_window_fringes
,
6025 doc
: /* Set the fringe widths of window WINDOW.
6026 If WINDOW is nil, set the fringe widths of the currently selected
6028 Second arg LEFT-WIDTH specifies the number of pixels to reserve for
6029 the left fringe. Optional third arg RIGHT-WIDTH specifies the right
6030 fringe width. If a fringe width arg is nil, that means to use the
6031 frame's default fringe width. Default fringe widths can be set with
6032 the command `set-fringe-style'.
6033 If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6034 outside of the display margins. By default, fringes are drawn between
6035 display marginal areas and the text area. */)
6036 (Lisp_Object window
, Lisp_Object left_width
, Lisp_Object right_width
, Lisp_Object outside_margins
)
6038 struct window
*w
= decode_window (window
);
6040 if (!NILP (left_width
))
6041 CHECK_NATNUM (left_width
);
6042 if (!NILP (right_width
))
6043 CHECK_NATNUM (right_width
);
6045 /* Do nothing on a tty. */
6046 if (FRAME_WINDOW_P (WINDOW_XFRAME (w
))
6047 && (!EQ (w
->left_fringe_width
, left_width
)
6048 || !EQ (w
->right_fringe_width
, right_width
)
6049 || !EQ (w
->fringes_outside_margins
, outside_margins
)))
6051 w
->left_fringe_width
= left_width
;
6052 w
->right_fringe_width
= right_width
;
6053 w
->fringes_outside_margins
= outside_margins
;
6055 adjust_window_margins (w
);
6057 clear_glyph_matrix (w
->current_matrix
);
6058 w
->window_end_valid
= Qnil
;
6060 ++windows_or_buffers_changed
;
6061 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6068 DEFUN ("window-fringes", Fwindow_fringes
, Swindow_fringes
,
6070 doc
: /* Get width of fringes of window WINDOW.
6071 If WINDOW is omitted or nil, use the currently selected window.
6072 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6073 (Lisp_Object window
)
6075 struct window
*w
= decode_window (window
);
6077 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w
)),
6078 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w
)),
6079 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
6080 ? Qt
: Qnil
), Qnil
)));
6085 /***********************************************************************
6087 ***********************************************************************/
6089 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars
, Sset_window_scroll_bars
,
6091 doc
: /* Set width and type of scroll bars of window WINDOW.
6092 If window is nil, set scroll bars of the currently selected window.
6093 Second parameter WIDTH specifies the pixel width for the scroll bar;
6094 this is automatically adjusted to a multiple of the frame column width.
6095 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6096 bar: left, right, or nil.
6097 If WIDTH is nil, use the frame's scroll-bar width.
6098 If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6099 Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6100 (Lisp_Object window
, Lisp_Object width
, Lisp_Object vertical_type
, Lisp_Object horizontal_type
)
6102 struct window
*w
= decode_window (window
);
6106 CHECK_NATNUM (width
);
6108 if (XINT (width
) == 0)
6109 vertical_type
= Qnil
;
6112 if (!(NILP (vertical_type
)
6113 || EQ (vertical_type
, Qleft
)
6114 || EQ (vertical_type
, Qright
)
6115 || EQ (vertical_type
, Qt
)))
6116 error ("Invalid type of vertical scroll bar");
6118 if (!EQ (w
->scroll_bar_width
, width
)
6119 || !EQ (w
->vertical_scroll_bar_type
, vertical_type
))
6121 w
->scroll_bar_width
= width
;
6122 w
->vertical_scroll_bar_type
= vertical_type
;
6124 adjust_window_margins (w
);
6126 clear_glyph_matrix (w
->current_matrix
);
6127 w
->window_end_valid
= Qnil
;
6129 ++windows_or_buffers_changed
;
6130 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
6137 DEFUN ("window-scroll-bars", Fwindow_scroll_bars
, Swindow_scroll_bars
,
6139 doc
: /* Get width and type of scroll bars of window WINDOW.
6140 If WINDOW is omitted or nil, use the currently selected window.
6141 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE).
6142 If WIDTH is nil or TYPE is t, the window is using the frame's corresponding
6144 (Lisp_Object window
)
6146 struct window
*w
= decode_window (window
);
6147 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6148 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
)
6149 : WINDOW_SCROLL_BAR_AREA_WIDTH (w
))),
6150 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w
)),
6151 Fcons (w
->vertical_scroll_bar_type
,
6152 Fcons (Qnil
, Qnil
))));
6157 /***********************************************************************
6159 ***********************************************************************/
6161 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 2, 0,
6162 doc
: /* Return the amount by which WINDOW is scrolled vertically.
6163 Use the selected window if WINDOW is nil or omitted.
6164 Normally, value is a multiple of the canonical character height of WINDOW;
6165 optional second arg PIXELS-P means value is measured in pixels. */)
6166 (Lisp_Object window
, Lisp_Object pixels_p
)
6173 window
= selected_window
;
6175 CHECK_WINDOW (window
);
6176 w
= XWINDOW (window
);
6177 f
= XFRAME (w
->frame
);
6179 if (FRAME_WINDOW_P (f
))
6180 result
= (NILP (pixels_p
)
6181 ? FRAME_CANON_Y_FROM_PIXEL_Y (f
, -w
->vscroll
)
6182 : make_number (-w
->vscroll
));
6184 result
= make_number (0);
6189 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
6191 doc
: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
6192 WINDOW nil means use the selected window. Normally, VSCROLL is a
6193 non-negative multiple of the canonical character height of WINDOW;
6194 optional third arg PIXELS-P non-nil means that VSCROLL is in pixels.
6195 If PIXELS-P is nil, VSCROLL may have to be rounded so that it
6196 corresponds to an integral number of pixels. The return value is the
6197 result of this rounding.
6198 If PIXELS-P is non-nil, the return value is VSCROLL. */)
6199 (Lisp_Object window
, Lisp_Object vscroll
, Lisp_Object pixels_p
)
6205 window
= selected_window
;
6207 CHECK_WINDOW (window
);
6208 CHECK_NUMBER_OR_FLOAT (vscroll
);
6210 w
= XWINDOW (window
);
6211 f
= XFRAME (w
->frame
);
6213 if (FRAME_WINDOW_P (f
))
6215 int old_dy
= w
->vscroll
;
6217 w
->vscroll
= - (NILP (pixels_p
)
6218 ? FRAME_LINE_HEIGHT (f
) * XFLOATINT (vscroll
)
6219 : XFLOATINT (vscroll
));
6220 w
->vscroll
= min (w
->vscroll
, 0);
6222 if (w
->vscroll
!= old_dy
)
6224 /* Adjust glyph matrix of the frame if the virtual display
6225 area becomes larger than before. */
6226 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
6229 /* Prevent redisplay shortcuts. */
6230 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
6234 return Fwindow_vscroll (window
, pixels_p
);
6238 /* Call FN for all leaf windows on frame F. FN is called with the
6239 first argument being a pointer to the leaf window, and with
6240 additional argument USER_DATA. Stops when FN returns 0. */
6243 foreach_window (struct frame
*f
, int (*fn
) (struct window
*, void *), void *user_data
)
6245 /* delete_frame may set FRAME_ROOT_WINDOW (f) to Qnil. */
6246 if (WINDOWP (FRAME_ROOT_WINDOW (f
)))
6247 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, user_data
);
6251 /* Helper function for foreach_window. Call FN for all leaf windows
6252 reachable from W. FN is called with the first argument being a
6253 pointer to the leaf window, and with additional argument USER_DATA.
6254 Stop when FN returns 0. Value is 0 if stopped by FN. */
6257 foreach_window_1 (struct window
*w
, int (*fn
) (struct window
*, void *), void *user_data
)
6261 for (cont
= 1; w
&& cont
;)
6263 if (!NILP (w
->hchild
))
6264 cont
= foreach_window_1 (XWINDOW (w
->hchild
), fn
, user_data
);
6265 else if (!NILP (w
->vchild
))
6266 cont
= foreach_window_1 (XWINDOW (w
->vchild
), fn
, user_data
);
6268 cont
= fn (w
, user_data
);
6270 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
6277 /* Freeze or unfreeze the window start of W unless it is a
6278 mini-window or the selected window. FREEZE_P non-null means freeze
6279 the window start. */
6282 freeze_window_start (struct window
*w
, void *freeze_p
)
6284 if (MINI_WINDOW_P (w
)
6285 || (WINDOWP (selected_window
) /* Can be nil in corner cases. */
6286 && (w
== XWINDOW (selected_window
)
6287 || (MINI_WINDOW_P (XWINDOW (selected_window
))
6288 && ! NILP (Vminibuf_scroll_window
)
6289 && w
== XWINDOW (Vminibuf_scroll_window
)))))
6292 w
->frozen_window_start_p
= freeze_p
!= NULL
;
6297 /* Freeze or unfreeze the window starts of all leaf windows on frame
6298 F, except the selected window and a mini-window. FREEZE_P non-zero
6299 means freeze the window start. */
6302 freeze_window_starts (struct frame
*f
, int freeze_p
)
6304 foreach_window (f
, freeze_window_start
, (void *) (freeze_p
? f
: 0));
6308 /***********************************************************************
6310 ***********************************************************************/
6312 /* Return 1 if window configurations CONFIGURATION1 and CONFIGURATION2
6313 describe the same state of affairs. This is used by Fequal.
6315 ignore_positions non-zero means ignore non-matching scroll positions
6318 This ignores a couple of things like the dedicatedness status of
6319 window, inhibit_recombine and the like. This might have to be
6323 compare_window_configurations (Lisp_Object configuration1
, Lisp_Object configuration2
, int ignore_positions
)
6325 register struct save_window_data
*d1
, *d2
;
6326 struct Lisp_Vector
*sws1
, *sws2
;
6329 CHECK_WINDOW_CONFIGURATION (configuration1
);
6330 CHECK_WINDOW_CONFIGURATION (configuration2
);
6332 d1
= (struct save_window_data
*) XVECTOR (configuration1
);
6333 d2
= (struct save_window_data
*) XVECTOR (configuration2
);
6334 sws1
= XVECTOR (d1
->saved_windows
);
6335 sws2
= XVECTOR (d2
->saved_windows
);
6337 /* Frame settings must match. */
6338 if (d1
->frame_cols
!= d2
->frame_cols
6339 || d1
->frame_lines
!= d2
->frame_lines
6340 || d1
->frame_menu_bar_lines
!= d2
->frame_menu_bar_lines
6341 || !EQ (d1
->selected_frame
, d2
->selected_frame
)
6342 || !EQ (d1
->current_buffer
, d2
->current_buffer
)
6343 || (!ignore_positions
6344 && (!EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
)
6345 || !EQ (d1
->minibuf_selected_window
, d2
->minibuf_selected_window
)))
6346 || !EQ (d1
->focus_frame
, d2
->focus_frame
)
6347 /* Verify that the two configurations have the same number of windows. */
6348 || sws1
->size
!= sws2
->size
)
6351 for (i
= 0; i
< sws1
->size
; i
++)
6353 struct saved_window
*sw1
, *sw2
;
6354 int w1_is_current
, w2_is_current
;
6356 sw1
= SAVED_WINDOW_N (sws1
, i
);
6357 sw2
= SAVED_WINDOW_N (sws2
, i
);
6360 /* The "current" windows in the two configurations must
6361 correspond to each other. */
6362 EQ (d1
->current_window
, sw1
->window
)
6363 != EQ (d2
->current_window
, sw2
->window
)
6364 /* Windows' buffers must match. */
6365 || !EQ (sw1
->buffer
, sw2
->buffer
)
6366 || !EQ (sw1
->left_col
, sw2
->left_col
)
6367 || !EQ (sw1
->top_line
, sw2
->top_line
)
6368 || !EQ (sw1
->total_cols
, sw2
->total_cols
)
6369 || !EQ (sw1
->total_lines
, sw2
->total_lines
)
6370 || !EQ (sw1
->display_table
, sw2
->display_table
)
6371 /* The next two disjuncts check the window structure for
6373 || !EQ (sw1
->parent
, sw2
->parent
)
6374 || !EQ (sw1
->prev
, sw2
->prev
)
6375 || (!ignore_positions
6376 && (!EQ (sw1
->hscroll
, sw2
->hscroll
)
6377 || !EQ (sw1
->min_hscroll
, sw2
->min_hscroll
)
6378 || !EQ (sw1
->start_at_line_beg
, sw2
->start_at_line_beg
)
6379 || NILP (Fequal (sw1
->start
, sw2
->start
))
6380 || NILP (Fequal (sw1
->pointm
, sw2
->pointm
))
6381 || NILP (Fequal (sw1
->mark
, sw2
->mark
))))
6382 || !EQ (sw1
->left_margin_cols
, sw2
->left_margin_cols
)
6383 || !EQ (sw1
->right_margin_cols
, sw2
->right_margin_cols
)
6384 || !EQ (sw1
->left_fringe_width
, sw2
->left_fringe_width
)
6385 || !EQ (sw1
->right_fringe_width
, sw2
->right_fringe_width
)
6386 || !EQ (sw1
->fringes_outside_margins
, sw2
->fringes_outside_margins
)
6387 || !EQ (sw1
->scroll_bar_width
, sw2
->scroll_bar_width
)
6388 || !EQ (sw1
->vertical_scroll_bar_type
, sw2
->vertical_scroll_bar_type
))
6395 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
6396 Scompare_window_configurations
, 2, 2, 0,
6397 doc
: /* Compare two window configurations as regards the structure of windows.
6398 This function ignores details such as the values of point and mark
6399 and scrolling positions. */)
6400 (Lisp_Object x
, Lisp_Object y
)
6402 if (compare_window_configurations (x
, y
, 1))
6408 init_window_once (void)
6410 struct frame
*f
= make_initial_frame ();
6411 XSETFRAME (selected_frame
, f
);
6412 Vterminal_frame
= selected_frame
;
6413 minibuf_window
= f
->minibuffer_window
;
6414 selected_window
= f
->selected_window
;
6415 last_nonminibuf_frame
= f
;
6417 window_initialized
= 1;
6423 Vwindow_list
= Qnil
;
6427 syms_of_window (void)
6429 Qscroll_up
= intern_c_string ("scroll-up");
6430 staticpro (&Qscroll_up
);
6432 Qscroll_down
= intern_c_string ("scroll-down");
6433 staticpro (&Qscroll_down
);
6435 Qscroll_command
= intern_c_string ("scroll-command");
6436 staticpro (&Qscroll_command
);
6438 Fput (Qscroll_up
, Qscroll_command
, Qt
);
6439 Fput (Qscroll_down
, Qscroll_command
, Qt
);
6441 staticpro (&Qwindow_configuration_change_hook
);
6442 Qwindow_configuration_change_hook
6443 = intern_c_string ("window-configuration-change-hook");
6445 Qwindowp
= intern_c_string ("windowp");
6446 staticpro (&Qwindowp
);
6448 Qwindow_configuration_p
= intern_c_string ("window-configuration-p");
6449 staticpro (&Qwindow_configuration_p
);
6451 Qwindow_live_p
= intern_c_string ("window-live-p");
6452 staticpro (&Qwindow_live_p
);
6454 Qwindow_deletable_p
= intern_c_string ("window-deletable-p");
6455 staticpro (&Qwindow_deletable_p
);
6457 Qdelete_window
= intern_c_string ("delete-window");
6458 staticpro (&Qdelete_window
);
6460 Qresize_root_window
= intern_c_string ("resize-root-window");
6461 staticpro (&Qresize_root_window
);
6463 Qresize_root_window_vertically
= intern_c_string ("resize-root-window-vertically");
6464 staticpro (&Qresize_root_window_vertically
);
6466 Qset
= intern_c_string ("set");
6469 Qdisplay_buffer
= intern_c_string ("display-buffer");
6470 staticpro (&Qdisplay_buffer
);
6472 Qget_mru_window
= intern_c_string ("get-mru-window");
6473 staticpro (&Qget_mru_window
);
6475 Qtemp_buffer_show_hook
= intern_c_string ("temp-buffer-show-hook");
6476 staticpro (&Qtemp_buffer_show_hook
);
6478 Qabove
= intern_c_string ("above");
6479 staticpro (&Qabove
);
6481 Qbelow
= intern_c_string ("below");
6482 staticpro (&Qbelow
);
6484 Qnest
= intern_c_string ("nest");
6487 Qresize
= intern_c_string ("resize");
6488 staticpro (&Qresize
);
6490 Qgroup
= intern_c_string ("group");
6491 staticpro (&Qgroup
);
6493 staticpro (&Vwindow_list
);
6495 minibuf_selected_window
= Qnil
;
6496 staticpro (&minibuf_selected_window
);
6498 window_scroll_pixel_based_preserve_x
= -1;
6499 window_scroll_pixel_based_preserve_y
= -1;
6500 window_scroll_preserve_hpos
= -1;
6501 window_scroll_preserve_vpos
= -1;
6503 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
6504 doc
: /* Non-nil means call as function to display a help buffer.
6505 The function is called with one argument, the buffer to be displayed.
6506 Used by `with-output-to-temp-buffer'.
6507 If this function is used, then it must do the entire job of showing
6508 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6509 Vtemp_buffer_show_function
= Qnil
;
6511 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
6512 doc
: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6513 Vminibuf_scroll_window
= Qnil
;
6515 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows
,
6516 doc
: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6517 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6518 is displayed in the `mode-line' face. */);
6519 mode_line_in_non_selected_windows
= 1;
6521 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
6522 doc
: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6523 Vother_window_scroll_buffer
= Qnil
;
6525 DEFVAR_BOOL ("auto-window-vscroll", &auto_window_vscroll_p
,
6526 doc
: /* Non-nil means to automatically adjust `window-vscroll' to view tall lines. */);
6527 auto_window_vscroll_p
= 1;
6529 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
6530 doc
: /* Number of lines of continuity when scrolling by screenfuls. */);
6531 next_screen_context_lines
= 2;
6533 DEFVAR_LISP ("scroll-preserve-screen-position",
6534 &Vscroll_preserve_screen_position
,
6535 doc
: /* Controls if scroll commands move point to keep its screen position unchanged.
6536 A value of nil means point does not keep its screen position except
6537 at the scroll margin or window boundary respectively.
6538 A value of t means point keeps its screen position if the scroll
6539 command moved it vertically out of the window, e.g. when scrolling
6541 Any other value means point always keeps its screen position.
6542 Scroll commands should have the `scroll-command' property
6543 on their symbols to be controlled by this variable. */);
6544 Vscroll_preserve_screen_position
= Qnil
;
6546 DEFVAR_LISP ("window-point-insertion-type", &Vwindow_point_insertion_type
,
6547 doc
: /* Type of marker to use for `window-point'. */);
6548 Vwindow_point_insertion_type
= Qnil
;
6550 DEFVAR_LISP ("window-configuration-change-hook",
6551 &Vwindow_configuration_change_hook
,
6552 doc
: /* Functions to call when window configuration changes.
6553 The buffer-local part is run once per window, with the relevant window
6554 selected; while the global part is run only once for the modified frame,
6555 with the relevant frame selected. */);
6556 Vwindow_configuration_change_hook
= Qnil
;
6558 DEFVAR_LISP ("recenter-redisplay", &Vrecenter_redisplay
,
6559 doc
: /* If non-nil, then the `recenter' command with a nil argument
6560 will redraw the entire frame; the special value `tty' causes the
6561 frame to be redrawn only if it is a tty frame. */);
6562 Vrecenter_redisplay
= Qtty
;
6564 DEFVAR_LISP ("window-splits", &Vwindow_splits
,
6565 doc
: /* Non-nil means splitting windows is handled specially.
6566 If this variable is nil, splitting a window WINDOW will create a new
6567 parent window only if WINDOW has no parent window or WINDOW shall be
6568 split in another direction than the combination WINDOW is part of.
6569 Resizing WINDOW preferably resizes WINDOW's right sibling. Deleting
6570 WINDOW will preferably return space to WINDOW's left sibling.
6572 If this variable equals `nest', splitting WINDOW always creates a new
6573 parent window. Consequently, any frame's window tree is a binary tree
6574 and every window has at most one (left or right) sibling. Resizing
6575 WINDOW will preferably resize WINDOW's sibling. Deleting WINDOW will
6576 preferably return space to WINDOW's sibling.
6578 If this variable equals `resize', splitting, resizing and deleting
6579 WINDOW will try to resize all windows in the same combination as WINDOW
6580 first. This setting allows to split windows that are otherwise too
6581 small or of fixed size. */);
6582 Vwindow_splits
= Qnil
;
6584 defsubr (&Sselected_window
);
6585 defsubr (&Sminibuffer_window
);
6586 defsubr (&Swindow_minibuffer_p
);
6587 defsubr (&Swindowp
);
6588 defsubr (&Swindow_live_p
);
6589 defsubr (&Swindow_frame
);
6590 defsubr (&Sframe_root_window
);
6591 defsubr (&Sframe_first_window
);
6592 defsubr (&Sframe_selected_window
);
6593 defsubr (&Sset_frame_selected_window
);
6594 defsubr (&Spos_visible_in_window_p
);
6595 defsubr (&Swindow_line_height
);
6596 defsubr (&Swindow_buffer
);
6597 defsubr (&Swindow_parent
);
6598 defsubr (&Swindow_vchild
);
6599 defsubr (&Swindow_hchild
);
6600 defsubr (&Swindow_next
);
6601 defsubr (&Swindow_prev
);
6602 defsubr (&Swindow_use_time
);
6603 defsubr (&Swindow_top_line
);
6604 defsubr (&Swindow_left_column
);
6605 defsubr (&Swindow_total_size
);
6606 defsubr (&Swindow_normal_size
);
6607 defsubr (&Swindow_new_total_size
);
6608 defsubr (&Swindow_new_normal_size
);
6609 defsubr (&Sresize_window_total
);
6610 defsubr (&Sresize_window_normal
);
6611 defsubr (&Sresize_window_apply
);
6612 defsubr (&Swindow_body_size
);
6613 defsubr (&Swindow_hscroll
);
6614 defsubr (&Sset_window_hscroll
);
6615 defsubr (&Swindow_redisplay_end_trigger
);
6616 defsubr (&Sset_window_redisplay_end_trigger
);
6617 defsubr (&Swindow_edges
);
6618 defsubr (&Swindow_pixel_edges
);
6619 defsubr (&Swindow_absolute_pixel_edges
);
6620 defsubr (&Swindow_inside_edges
);
6621 defsubr (&Swindow_inside_pixel_edges
);
6622 defsubr (&Swindow_inside_absolute_pixel_edges
);
6623 defsubr (&Scoordinates_in_window_p
);
6624 defsubr (&Swindow_at
);
6625 defsubr (&Swindow_point
);
6626 defsubr (&Swindow_start
);
6627 defsubr (&Swindow_end
);
6628 defsubr (&Sset_window_point
);
6629 defsubr (&Sset_window_start
);
6630 defsubr (&Swindow_dedicated_p
);
6631 defsubr (&Sset_window_dedicated_p
);
6632 defsubr (&Swindow_display_table
);
6633 defsubr (&Sset_window_display_table
);
6634 defsubr (&Snext_window
);
6635 defsubr (&Sprevious_window
);
6636 defsubr (&Sget_buffer_window
);
6637 defsubr (&Sdelete_other_windows_internal
);
6638 defsubr (&Sreplace_buffer_in_windows
);
6639 defsubr (&Sdelete_window_internal
);
6640 defsubr (&Sresize_mini_window_internal
);
6641 defsubr (&Sset_window_buffer
);
6642 defsubr (&Srun_window_configuration_change_hook
);
6643 defsubr (&Sselect_window
);
6644 defsubr (&Sforce_window_update
);
6645 defsubr (&Ssplit_window_internal
);
6646 defsubr (&Sscroll_up
);
6647 defsubr (&Sscroll_down
);
6648 defsubr (&Sscroll_left
);
6649 defsubr (&Sscroll_right
);
6650 defsubr (&Sother_window_for_scrolling
);
6651 defsubr (&Sscroll_other_window
);
6652 defsubr (&Sminibuffer_selected_window
);
6653 defsubr (&Srecenter
);
6654 defsubr (&Swindow_text_height
);
6655 defsubr (&Smove_to_window_line
);
6656 defsubr (&Swindow_configuration_p
);
6657 defsubr (&Swindow_configuration_frame
);
6658 defsubr (&Sset_window_configuration
);
6659 defsubr (&Scurrent_window_configuration
);
6660 defsubr (&Ssave_window_excursion
);
6661 defsubr (&Sset_window_margins
);
6662 defsubr (&Swindow_margins
);
6663 defsubr (&Sset_window_fringes
);
6664 defsubr (&Swindow_fringes
);
6665 defsubr (&Sset_window_scroll_bars
);
6666 defsubr (&Swindow_scroll_bars
);
6667 defsubr (&Swindow_vscroll
);
6668 defsubr (&Sset_window_vscroll
);
6669 defsubr (&Scompare_window_configurations
);
6670 defsubr (&Swindow_list
);
6671 defsubr (&Swindow_list_1
);
6672 defsubr (&Swindow_parameters
);
6673 defsubr (&Swindow_parameter
);
6674 defsubr (&Sset_window_parameter
);
6678 keys_of_window (void)
6680 initial_define_key (control_x_map
, '<', "scroll-left");
6681 initial_define_key (control_x_map
, '>', "scroll-right");
6683 initial_define_key (global_map
, Ctl ('V'), "scroll-up-command");
6684 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
6685 initial_define_key (meta_map
, 'v', "scroll-down-command");
6688 /* arch-tag: 90a9c576-0590-48f1-a5f1-6c96a0452d9f
6689 (do not change this comment) */