1 /* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
3 Copyright (C) 1985,86,87,93,94,95,96,97,1998 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "dispextern.h"
33 #include "blockinput.h"
34 #include "intervals.h"
38 #endif /* HAVE_X_WINDOWS */
41 #define max(a, b) ((a) < (b) ? (b) : (a))
45 Lisp_Object Qwindowp
, Qwindow_live_p
, Qwindow_configuration_p
;
46 Lisp_Object Qwindow_size_fixed
, Qleft_bitmap_area
, Qright_bitmap_area
;
47 extern Lisp_Object Qheight
, Qwidth
;
49 static struct window
*decode_window
P_ ((Lisp_Object
));
50 static Lisp_Object select_window_1
P_ ((Lisp_Object
, int));
51 static int count_windows
P_ ((struct window
*));
52 static int get_leaf_windows
P_ ((struct window
*, struct window
**, int));
53 static void window_scroll
P_ ((Lisp_Object
, int, int, int));
54 static void window_scroll_pixel_based
P_ ((Lisp_Object
, int, int, int));
55 static void window_scroll_line_based
P_ ((Lisp_Object
, int, int, int));
56 static int window_min_size_1
P_ ((struct window
*, int));
57 static int window_min_size
P_ ((struct window
*, int, int *));
58 static int window_fixed_size_p
P_ ((struct window
*, int, int));
59 static void size_window
P_ ((Lisp_Object
, int, int, int));
60 static void foreach_window_1
P_ ((struct window
*, void (*fn
) (), int, int,
62 static void freeze_window_start
P_ ((struct window
*, int));
65 /* This is the window in which the terminal's cursor should
66 be left when nothing is being done with it. This must
67 always be a leaf window, and its buffer is selected by
68 the top level editing loop at the end of each command.
70 This value is always the same as
71 FRAME_SELECTED_WINDOW (selected_frame). */
73 Lisp_Object selected_window
;
75 /* The mini-buffer window of the selected frame.
76 Note that you cannot test for mini-bufferness of an arbitrary window
77 by comparing against this; but you can test for mini-bufferness of
78 the selected window. */
80 Lisp_Object minibuf_window
;
82 /* Non-nil means it is the window for C-M-v to scroll
83 when the mini-buffer is selected. */
85 Lisp_Object Vminibuf_scroll_window
;
87 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
89 Lisp_Object Vother_window_scroll_buffer
;
91 /* Non-nil means it's function to call to display temp buffers. */
93 Lisp_Object Vtemp_buffer_show_function
;
95 /* If a window gets smaller than either of these, it is removed. */
97 int window_min_height
;
100 /* Nonzero implies Fdisplay_buffer should create windows. */
104 /* Nonzero implies make new frames for Fdisplay_buffer. */
108 /* Non-nil means use this function instead of default */
110 Lisp_Object Vpop_up_frame_function
;
112 /* Function to call to handle Fdisplay_buffer. */
114 Lisp_Object Vdisplay_buffer_function
;
116 /* List of buffer *names* for buffers that should have their own frames. */
118 Lisp_Object Vspecial_display_buffer_names
;
120 /* List of regexps for buffer names that should have their own frames. */
122 Lisp_Object Vspecial_display_regexps
;
124 /* Function to pop up a special frame. */
126 Lisp_Object Vspecial_display_function
;
128 /* List of buffer *names* for buffers to appear in selected window. */
130 Lisp_Object Vsame_window_buffer_names
;
132 /* List of regexps for buffer names to appear in selected window. */
134 Lisp_Object Vsame_window_regexps
;
136 /* Hook run at end of temp_output_buffer_show. */
138 Lisp_Object Qtemp_buffer_show_hook
;
140 /* Fdisplay_buffer always splits the largest window
141 if that window is more than this high. */
143 int split_height_threshold
;
145 /* Number of lines of continuity in scrolling by screenfuls. */
147 int next_screen_context_lines
;
149 /* Incremented for each window created. */
151 static int sequence_number
;
153 /* Nonzero after init_window_once has finished. */
155 static int window_initialized
;
157 /* Hook to run when window config changes. */
159 Lisp_Object Qwindow_configuration_change_hook
;
160 Lisp_Object Vwindow_configuration_change_hook
;
162 /* Nonzero means scroll commands try to put point
163 at the same screen height as previously. */
165 Lisp_Object Vscroll_preserve_screen_position
;
167 #if 0 /* This isn't used anywhere. */
168 /* Nonzero means we can split a frame even if it is "unsplittable". */
169 static int inhibit_frame_unsplittable
;
172 #define min(a, b) ((a) < (b) ? (a) : (b))
174 extern int scroll_margin
;
176 extern Lisp_Object Qwindow_scroll_functions
, Vwindow_scroll_functions
;
178 DEFUN ("windowp", Fwindowp
, Swindowp
, 1, 1, 0,
179 "Returns t if OBJECT is a window.")
183 return WINDOWP (object
) ? Qt
: Qnil
;
186 DEFUN ("window-live-p", Fwindow_live_p
, Swindow_live_p
, 1, 1, 0,
187 "Returns t if OBJECT is a window which is currently visible.")
191 return (WINDOWP (object
) && ! NILP (XWINDOW (object
)->buffer
) ? Qt
: Qnil
);
198 register struct window
*p
;
199 register struct Lisp_Vector
*vec
;
202 vec
= allocate_vectorlike ((EMACS_INT
) VECSIZE (struct window
));
203 for (i
= 0; i
< VECSIZE (struct window
); i
++)
204 vec
->contents
[i
] = Qnil
;
205 vec
->size
= VECSIZE (struct window
);
206 p
= (struct window
*) vec
;
207 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
208 XSETFASTINT (p
->left
, 0);
209 XSETFASTINT (p
->top
, 0);
210 XSETFASTINT (p
->height
, 0);
211 XSETFASTINT (p
->width
, 0);
212 XSETFASTINT (p
->hscroll
, 0);
213 p
->start
= Fmake_marker ();
214 p
->pointm
= Fmake_marker ();
215 XSETFASTINT (p
->use_time
, 0);
217 p
->display_table
= Qnil
;
219 p
->pseudo_window_p
= 0;
220 bzero (&p
->cursor
, sizeof (p
->cursor
));
221 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
222 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
223 p
->desired_matrix
= p
->current_matrix
= 0;
224 p
->phys_cursor_type
= -1;
225 p
->must_be_updated_p
= 0;
226 XSETFASTINT (p
->window_end_vpos
, 0);
227 XSETFASTINT (p
->window_end_pos
, 0);
228 p
->window_end_valid
= Qnil
;
231 XSETFASTINT (p
->last_point
, 0);
232 p
->frozen_window_start_p
= 0;
236 DEFUN ("selected-window", Fselected_window
, Sselected_window
, 0, 0, 0,
237 "Return the window that the cursor now appears in and commands apply to.")
240 return selected_window
;
243 DEFUN ("minibuffer-window", Fminibuffer_window
, Sminibuffer_window
, 0, 1, 0,
244 "Return the window used now for minibuffers.\n\
245 If the optional argument FRAME is specified, return the minibuffer window\n\
246 used by that frame.")
251 XSETFRAME (frame
, selected_frame
);
253 CHECK_LIVE_FRAME (frame
, 0);
255 return FRAME_MINIBUF_WINDOW (XFRAME (frame
));
258 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p
, Swindow_minibuffer_p
, 0, 1, 0,
259 "Returns non-nil if WINDOW is a minibuffer window.")
263 struct window
*w
= decode_window (window
);
264 return (MINI_WINDOW_P (w
) ? Qt
: Qnil
);
267 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p
,
268 Spos_visible_in_window_p
, 0, 2, 0,
269 "Return t if position POS is currently on the frame in WINDOW.\n\
270 Returns nil if that position is scrolled vertically out of view.\n\
271 POS defaults to point; WINDOW, to the selected window.")
273 Lisp_Object pos
, window
;
275 register struct window
*w
;
277 register struct buffer
*buf
;
279 Lisp_Object in_window
;
285 CHECK_NUMBER_COERCE_MARKER (pos
, 0);
289 w
= decode_window (window
);
290 buf
= XBUFFER (w
->buffer
);
291 SET_TEXT_POS_FROM_MARKER (top
, w
->start
);
293 /* If position above window, it's not visible. */
294 if (posint
< CHARPOS (top
))
296 else if (XFASTINT (w
->last_modified
) >= BUF_MODIFF (buf
)
297 && XFASTINT (w
->last_overlay_modified
) >= BUF_OVERLAY_MODIFF (buf
)
298 && posint
< BUF_Z (buf
) - XFASTINT (w
->window_end_pos
))
299 /* If frame is up to date, and POSINT is < window end pos, use
300 that info. This doesn't work for POSINT == end pos, because
301 the window end pos is actually the position _after_ the last
302 char in the window. */
304 else if (posint
> BUF_ZV (buf
))
306 else if (CHARPOS (top
) < BUF_BEGV (buf
) || CHARPOS (top
) > BUF_ZV (buf
))
307 /* If window start is out of range, do something reasonable. */
312 start_display (&it
, w
, top
);
313 move_it_to (&it
, posint
, 0, it
.last_visible_y
, -1,
314 MOVE_TO_POS
| MOVE_TO_X
| MOVE_TO_Y
);
315 in_window
= IT_CHARPOS (it
) == posint
? Qt
: Qnil
;
321 static struct window
*
322 decode_window (window
)
323 register Lisp_Object window
;
326 return XWINDOW (selected_window
);
328 CHECK_LIVE_WINDOW (window
, 0);
329 return XWINDOW (window
);
332 DEFUN ("window-buffer", Fwindow_buffer
, Swindow_buffer
, 0, 1, 0,
333 "Return the buffer that WINDOW is displaying.")
337 return decode_window (window
)->buffer
;
340 DEFUN ("window-height", Fwindow_height
, Swindow_height
, 0, 1, 0,
341 "Return the number of lines in WINDOW (including its mode line).")
345 return decode_window (window
)->height
;
348 DEFUN ("window-width", Fwindow_width
, Swindow_width
, 0, 1, 0,
349 "Return the number of display columns in WINDOW.\n\
350 This is the width that is usable columns available for text in WINDOW.\n\
351 If you want to find out how many columns WINDOW takes up,\n\
352 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
356 return make_number (window_internal_width (decode_window (window
)));
359 DEFUN ("window-hscroll", Fwindow_hscroll
, Swindow_hscroll
, 0, 1, 0,
360 "Return the number of columns by which WINDOW is scrolled from left margin.")
364 return decode_window (window
)->hscroll
;
367 DEFUN ("set-window-hscroll", Fset_window_hscroll
, Sset_window_hscroll
, 2, 2, 0,
368 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
369 NCOL should be zero or positive.")
371 register Lisp_Object window
, ncol
;
373 register struct window
*w
;
375 CHECK_NUMBER (ncol
, 1);
376 if (XINT (ncol
) < 0) XSETFASTINT (ncol
, 0);
377 w
= decode_window (window
);
378 if (XINT (w
->hscroll
) != XINT (ncol
))
379 /* Prevent redisplay shortcuts */
380 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
385 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger
,
386 Swindow_redisplay_end_trigger
, 0, 1, 0,
387 "Return WINDOW's redisplay end trigger value.\n\
388 See `set-window-redisplay-end-trigger' for more information.")
392 return decode_window (window
)->redisplay_end_trigger
;
395 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger
,
396 Sset_window_redisplay_end_trigger
, 2, 2, 0,
397 "Set WINDOW's redisplay end trigger value to VALUE.\n\
398 VALUE should be a buffer position (typically a marker) or nil.\n\
399 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
400 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
401 with two arguments: WINDOW, and the end trigger value.\n\
402 Afterwards the end-trigger value is reset to nil.")
404 register Lisp_Object window
, value
;
406 register struct window
*w
;
408 w
= decode_window (window
);
409 w
->redisplay_end_trigger
= value
;
413 DEFUN ("window-edges", Fwindow_edges
, Swindow_edges
, 0, 1, 0,
414 "Return a list of the edge coordinates of WINDOW.\n\
415 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
416 RIGHT is one more than the rightmost column used by WINDOW,\n\
417 and BOTTOM is one more than the bottommost row used by WINDOW\n\
422 register struct window
*w
= decode_window (window
);
424 return Fcons (w
->left
, Fcons (w
->top
,
425 Fcons (make_number (WINDOW_RIGHT_EDGE (w
)),
426 Fcons (make_number (XFASTINT (w
->top
)
427 + XFASTINT (w
->height
)),
431 /* Test if the character at column *X, row *Y is within window W.
432 If it is not, return 0;
433 if it is in the window's text area,
434 set *x and *y to its location relative to the upper left corner
437 if it is on the window's modeline, return 2;
438 if it is on the border between the window and its right sibling,
440 if it is on the window's top line, return 4;
441 if it is in the bitmap area to the left/right of the window,
442 return 5 or 6, and convert *X and *Y to window-relative corrdinates.
444 X and Y are frame relative pixel coordinates. */
447 coordinates_in_window (w
, x
, y
)
448 register struct window
*w
;
451 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
452 int left_x
, right_x
, top_y
, bottom_y
;
453 int flags_area_width
= FRAME_LEFT_FLAGS_AREA_WIDTH (f
);
455 if (w
->pseudo_window_p
)
458 right_x
= XFASTINT (w
->width
) * CANON_Y_UNIT (f
);
459 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
460 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
464 left_x
= WINDOW_DISPLAY_LEFT_EDGE_PIXEL_X (w
);
465 right_x
= WINDOW_DISPLAY_RIGHT_EDGE_PIXEL_X (w
);
466 top_y
= WINDOW_DISPLAY_TOP_EDGE_PIXEL_Y (w
);
467 bottom_y
= WINDOW_DISPLAY_BOTTOM_EDGE_PIXEL_Y (w
);
474 - (FRAME_LEFT_SCROLL_BAR_WIDTH (f
)
476 || *x
> right_x
+ flags_area_width
)
477 /* Completely outside anything interesting. */
479 else if (WINDOW_WANTS_MODELINE_P (w
)
480 && *y
>= bottom_y
- CURRENT_MODE_LINE_HEIGHT (w
))
481 /* On the mode line. */
483 else if (WINDOW_WANTS_TOP_LINE_P (w
)
484 && *y
< top_y
+ CURRENT_TOP_LINE_HEIGHT (w
))
485 /* On the top line. */
487 else if (*x
< left_x
|| *x
>= right_x
)
489 /* Other lines than the mode line don't include flags areas and
490 scroll bars on the left. */
492 /* Convert X and Y to window-relative pixel coordinates. */
495 return *x
< left_x
? 5 : 6;
497 else if (!w
->pseudo_window_p
498 && !WINDOW_RIGHTMOST_P (w
)
499 && *x
>= right_x
- CANON_X_UNIT (f
))
500 /* On the border on the right side of the window? Assume that
501 this area begins at RIGHT_X minus a canonical char width. */
505 /* Convert X and Y to window-relative pixel coordinates. */
512 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p
,
513 Scoordinates_in_window_p
, 2, 2, 0,
514 "Return non-nil if COORDINATES are in WINDOW.\n\
515 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
516 measured in characters from the upper-left corner of the frame.\n\
517 (0 . 0) denotes the character in the upper left corner of the\n\
519 If COORDINATES are in the text portion of WINDOW,\n\
520 the coordinates relative to the window are returned.\n\
521 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
522 If they are in the top mode line of WINDOW, `top-line' is returned.\n\
523 If they are in the bitmap-area to the left of the window,\n\
524 `left-bitmap-area' is returned, if they are in the area on the right of\n\
525 the window, `right-bitmap-area' is returned.\n\
526 If they are on the border between WINDOW and its right sibling,\n\
527 `vertical-line' is returned.")
528 (coordinates
, window
)
529 register Lisp_Object coordinates
, window
;
536 CHECK_LIVE_WINDOW (window
, 0);
537 w
= XWINDOW (window
);
538 f
= XFRAME (w
->frame
);
539 CHECK_CONS (coordinates
, 1);
540 lx
= Fcar (coordinates
);
541 ly
= Fcdr (coordinates
);
542 CHECK_NUMBER_OR_FLOAT (lx
, 1);
543 CHECK_NUMBER_OR_FLOAT (ly
, 1);
544 x
= PIXEL_X_FROM_CANON_X (f
, lx
);
545 y
= PIXEL_Y_FROM_CANON_Y (f
, ly
);
547 switch (coordinates_in_window (w
, &x
, &y
))
549 case 0: /* NOT in window at all. */
552 case 1: /* In text part of window. */
553 /* X and Y are now window relative pixel coordinates.
554 Convert them to canonical char units before returning
556 return Fcons (CANON_X_FROM_PIXEL_X (f
, x
),
557 CANON_Y_FROM_PIXEL_Y (f
, y
));
559 case 2: /* In mode line of window. */
562 case 3: /* On right border of window. */
563 return Qvertical_line
;
569 return Qleft_bitmap_area
;
572 return Qright_bitmap_area
;
579 /* Find the window containing frame-relative pixel position X/Y and
580 return it as a Lisp_Object. If X, Y is on the window's modeline,
581 set *PART to 1; if it is on the separating line between the window
582 and its right sibling, set it to 2; otherwise set it to 0. If
583 there is no window under X, Y return nil and leave *PART
584 unmodified. TOOLBAR_P non-zero means detect toolbar windows. */
587 window_from_coordinates (frame
, x
, y
, part
, toolbar_p
)
593 register Lisp_Object tem
, first
;
596 tem
= first
= FRAME_SELECTED_WINDOW (frame
);
600 found
= coordinates_in_window (XWINDOW (tem
), &x
, &y
);
608 tem
= Fnext_window (tem
, Qt
, Qlambda
);
610 while (!EQ (tem
, first
));
612 /* See if it's in the toolbar window, if a toolbar exists. */
614 && WINDOWP (frame
->toolbar_window
)
615 && XFASTINT (XWINDOW (frame
->toolbar_window
)->height
)
616 && coordinates_in_window (XWINDOW (frame
->toolbar_window
), &x
, &y
))
619 return frame
->toolbar_window
;
625 DEFUN ("window-at", Fwindow_at
, Swindow_at
, 2, 3, 0,
626 "Return window containing coordinates X and Y on FRAME.\n\
627 If omitted, FRAME defaults to the currently selected frame.\n\
628 The top left corner of the frame is considered to be row 0,\n\
631 Lisp_Object x
, y
, frame
;
637 XSETFRAME (frame
, selected_frame
);
639 CHECK_LIVE_FRAME (frame
, 2);
642 /* Check that arguments are integers or floats. */
643 CHECK_NUMBER_OR_FLOAT (x
, 0);
644 CHECK_NUMBER_OR_FLOAT (y
, 1);
646 return window_from_coordinates (f
,
647 PIXEL_X_FROM_CANON_X (f
, x
),
648 PIXEL_Y_FROM_CANON_Y (f
, y
),
652 DEFUN ("window-point", Fwindow_point
, Swindow_point
, 0, 1, 0,
653 "Return current value of point in WINDOW.\n\
654 For a nonselected window, this is the value point would have\n\
655 if that window were selected.\n\
657 Note that, when WINDOW is the selected window and its buffer\n\
658 is also currently selected, the value returned is the same as (point).\n\
659 It would be more strictly correct to return the `top-level' value\n\
660 of point, outside of any save-excursion forms.\n\
661 But that is hard to define.")
665 register struct window
*w
= decode_window (window
);
667 if (w
== XWINDOW (selected_window
)
668 && current_buffer
== XBUFFER (w
->buffer
))
670 return Fmarker_position (w
->pointm
);
673 DEFUN ("window-start", Fwindow_start
, Swindow_start
, 0, 1, 0,
674 "Return position at which display currently starts in WINDOW.\n\
675 This is updated by redisplay or by calling `set-window-start'.")
679 return Fmarker_position (decode_window (window
)->start
);
682 /* This is text temporarily removed from the doc string below.
684 This function returns nil if the position is not currently known.\n\
685 That happens when redisplay is preempted and doesn't finish.\n\
686 If in that case you want to compute where the end of the window would\n\
687 have been if redisplay had finished, do this:\n\
689 (goto-char (window-start window))\n\
690 (vertical-motion (1- (window-height window)) window)\n\
693 DEFUN ("window-end", Fwindow_end
, Swindow_end
, 0, 2, 0,
694 "Return position at which display currently ends in WINDOW.\n\
695 This is updated by redisplay, when it runs to completion.\n\
696 Simply changing the buffer text or setting `window-start'\n\
697 does not update this value.\n\
698 If UP-TO-DATE is non-nil, compute the up-to-date position\n\
699 if it isn't already recorded.")
701 Lisp_Object window
, update
;
704 struct window
*w
= decode_window (window
);
708 CHECK_BUFFER (buf
, 0);
710 #if 0 /* This change broke some things. We should make it later. */
711 /* If we don't know the end position, return nil.
712 The user can compute it with vertical-motion if he wants to.
713 It would be nicer to do it automatically,
714 but that's so slow that it would probably bother people. */
715 if (NILP (w
->window_end_valid
))
720 && ! (! NILP (w
->window_end_valid
)
721 && XFASTINT (w
->last_modified
) >= MODIFF
))
723 int opoint
= PT
, opoint_byte
= PT_BYTE
;
724 TEMP_SET_PT_BOTH (XMARKER (w
->start
)->charpos
,
725 XMARKER (w
->start
)->bytepos
);
726 Fvertical_motion (make_number (window_internal_height (w
)), Qnil
);
728 TEMP_SET_PT_BOTH (opoint
, opoint_byte
);
732 BUF_Z (XBUFFER (buf
)) - XFASTINT (w
->window_end_pos
));
737 DEFUN ("set-window-point", Fset_window_point
, Sset_window_point
, 2, 2, 0,
738 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
740 Lisp_Object window
, pos
;
742 register struct window
*w
= decode_window (window
);
744 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
745 if (w
== XWINDOW (selected_window
)
746 && XBUFFER (w
->buffer
) == current_buffer
)
749 set_marker_restricted (w
->pointm
, pos
, w
->buffer
);
754 DEFUN ("set-window-start", Fset_window_start
, Sset_window_start
, 2, 3, 0,
755 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
756 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
757 from overriding motion of point in order to display at this exact start.")
758 (window
, pos
, noforce
)
759 Lisp_Object window
, pos
, noforce
;
761 register struct window
*w
= decode_window (window
);
763 CHECK_NUMBER_COERCE_MARKER (pos
, 1);
764 set_marker_restricted (w
->start
, pos
, w
->buffer
);
765 /* this is not right, but much easier than doing what is right. */
766 w
->start_at_line_beg
= Qnil
;
769 w
->update_mode_line
= Qt
;
770 XSETFASTINT (w
->last_modified
, 0);
771 XSETFASTINT (w
->last_overlay_modified
, 0);
772 if (!EQ (window
, selected_window
))
773 windows_or_buffers_changed
++;
778 DEFUN ("window-dedicated-p", Fwindow_dedicated_p
, Swindow_dedicated_p
,
780 "Return WINDOW's dedicated object, usually t or nil.\n\
781 See also `set-window-dedicated-p'.")
785 return decode_window (window
)->dedicated
;
788 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p
,
789 Sset_window_dedicated_p
, 2, 2, 0,
790 "Control whether WINDOW is dedicated to the buffer it displays.\n\
791 If it is dedicated, Emacs will not automatically change\n\
792 which buffer appears in it.\n\
793 The second argument is the new value for the dedication flag;\n\
796 Lisp_Object window
, arg
;
798 register struct window
*w
= decode_window (window
);
808 DEFUN ("window-display-table", Fwindow_display_table
, Swindow_display_table
,
810 "Return the display-table that WINDOW is using.")
814 return decode_window (window
)->display_table
;
817 /* Get the display table for use on window W. This is either W's
818 display table or W's buffer's display table. Ignore the specified
819 tables if they are not valid; if no valid table is specified,
822 struct Lisp_Char_Table
*
823 window_display_table (w
)
827 tem
= w
->display_table
;
828 if (DISP_TABLE_P (tem
))
829 return XCHAR_TABLE (tem
);
830 if (NILP (w
->buffer
))
833 tem
= XBUFFER (w
->buffer
)->display_table
;
834 if (DISP_TABLE_P (tem
))
835 return XCHAR_TABLE (tem
);
836 tem
= Vstandard_display_table
;
837 if (DISP_TABLE_P (tem
))
838 return XCHAR_TABLE (tem
);
842 DEFUN ("set-window-display-table", Fset_window_display_table
, Sset_window_display_table
, 2, 2, 0,
843 "Set WINDOW's display-table to TABLE.")
845 register Lisp_Object window
, table
;
847 register struct window
*w
;
849 w
= decode_window (window
);
850 w
->display_table
= table
;
854 /* Record info on buffer window w is displaying
855 when it is about to cease to display that buffer. */
858 register struct window
*w
;
865 if (b
!= XMARKER (w
->pointm
)->buffer
)
868 if (w
== XWINDOW (b
->last_selected_window
))
869 b
->last_selected_window
= Qnil
;
872 if (w
== XWINDOW (selected_window
)
873 || ! EQ (buf
, XWINDOW (selected_window
)->buffer
))
874 /* Do this except when the selected window's buffer
875 is being removed from some other window. */
877 /* last_window_start records the start position that this buffer
878 had in the last window to be disconnected from it.
879 Now that this statement is unconditional,
880 it is possible for the buffer to be displayed in the
881 selected window, while last_window_start reflects another
882 window which was recently showing the same buffer.
883 Some people might say that might be a good thing. Let's see. */
884 b
->last_window_start
= marker_position (w
->start
);
886 /* Point in the selected window's buffer
887 is actually stored in that buffer, and the window's pointm isn't used.
888 So don't clobber point in that buffer. */
889 if (! EQ (buf
, XWINDOW (selected_window
)->buffer
))
890 temp_set_point_both (b
,
891 clip_to_bounds (BUF_BEGV (b
),
892 XMARKER (w
->pointm
)->charpos
,
894 clip_to_bounds (BUF_BEGV_BYTE (b
),
895 marker_byte_position (w
->pointm
),
899 /* Put replacement into the window structure in place of old. */
901 replace_window (old
, replacement
)
902 Lisp_Object old
, replacement
;
904 register Lisp_Object tem
;
905 register struct window
*o
= XWINDOW (old
), *p
= XWINDOW (replacement
);
907 /* If OLD is its frame's root_window, then replacement is the new
908 root_window for that frame. */
910 if (EQ (old
, FRAME_ROOT_WINDOW (XFRAME (o
->frame
))))
911 FRAME_ROOT_WINDOW (XFRAME (o
->frame
)) = replacement
;
916 p
->height
= o
->height
;
917 p
->desired_matrix
= p
->current_matrix
= 0;
919 bzero (&p
->cursor
, sizeof (p
->cursor
));
920 bzero (&p
->last_cursor
, sizeof (p
->last_cursor
));
921 bzero (&p
->phys_cursor
, sizeof (p
->phys_cursor
));
922 p
->phys_cursor_type
= -1;
923 p
->must_be_updated_p
= 0;
924 p
->pseudo_window_p
= 0;
925 XSETFASTINT (p
->window_end_vpos
, 0);
926 XSETFASTINT (p
->window_end_pos
, 0);
927 p
->window_end_valid
= Qnil
;
928 p
->frozen_window_start_p
= 0;
930 p
->next
= tem
= o
->next
;
932 XWINDOW (tem
)->prev
= replacement
;
934 p
->prev
= tem
= o
->prev
;
936 XWINDOW (tem
)->next
= replacement
;
938 p
->parent
= tem
= o
->parent
;
941 if (EQ (XWINDOW (tem
)->vchild
, old
))
942 XWINDOW (tem
)->vchild
= replacement
;
943 if (EQ (XWINDOW (tem
)->hchild
, old
))
944 XWINDOW (tem
)->hchild
= replacement
;
947 /*** Here, if replacement is a vertical combination
948 and so is its new parent, we should make replacement's
949 children be children of that parent instead. ***/
952 DEFUN ("delete-window", Fdelete_window
, Sdelete_window
, 0, 1, "",
953 "Remove WINDOW from the display. Default is selected window.")
955 register Lisp_Object window
;
957 delete_window (window
);
959 if (! NILP (Vwindow_configuration_change_hook
)
960 && ! NILP (Vrun_hooks
))
961 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
967 delete_window (window
)
968 register Lisp_Object window
;
970 register Lisp_Object tem
, parent
, sib
;
971 register struct window
*p
;
972 register struct window
*par
;
975 /* Because this function is called by other C code on non-leaf
976 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
977 so we can't decode_window here. */
979 window
= selected_window
;
981 CHECK_WINDOW (window
, 0);
982 p
= XWINDOW (window
);
984 /* It's okay to delete an already-deleted window. */
992 error ("Attempt to delete minibuffer or sole ordinary window");
993 par
= XWINDOW (parent
);
995 windows_or_buffers_changed
++;
996 frame
= XFRAME (WINDOW_FRAME (p
));
997 FRAME_WINDOW_SIZES_CHANGED (frame
) = 1;
999 /* Are we trying to delete any frame's selected window? */
1001 Lisp_Object frame
, pwindow
;
1003 /* See if the frame's selected window is either WINDOW
1004 or any subwindow of it, by finding all that window's parents
1005 and comparing each one with WINDOW. */
1006 frame
= WINDOW_FRAME (XWINDOW (window
));
1007 pwindow
= FRAME_SELECTED_WINDOW (XFRAME (frame
));
1009 while (!NILP (pwindow
))
1011 if (EQ (window
, pwindow
))
1013 pwindow
= XWINDOW (pwindow
)->parent
;
1016 if (EQ (window
, pwindow
))
1018 Lisp_Object alternative
;
1019 alternative
= Fnext_window (window
, Qlambda
, Qnil
);
1021 /* If we're about to delete the selected window on the
1022 selected frame, then we should use Fselect_window to select
1023 the new window. On the other hand, if we're about to
1024 delete the selected window on any other frame, we shouldn't do
1025 anything but set the frame's selected_window slot. */
1026 if (EQ (window
, selected_window
))
1027 Fselect_window (alternative
);
1029 FRAME_SELECTED_WINDOW (XFRAME (frame
)) = alternative
;
1034 /* tem is null for dummy parent windows
1035 (which have inferiors but not any contents themselves) */
1039 unchain_marker (p
->pointm
);
1040 unchain_marker (p
->start
);
1043 /* Free window glyph matrices.
1044 It is sure that they are allocated again when ADJUST_GLYPHS
1046 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (frame
)));
1050 XWINDOW (tem
)->prev
= p
->prev
;
1054 XWINDOW (tem
)->next
= p
->next
;
1056 if (EQ (window
, par
->hchild
))
1057 par
->hchild
= p
->next
;
1058 if (EQ (window
, par
->vchild
))
1059 par
->vchild
= p
->next
;
1061 /* Find one of our siblings to give our space to. */
1065 /* If p gives its space to its next sibling, that sibling needs
1066 to have its top/left side pulled back to where p's is.
1067 set_window_{height,width} will re-position the sibling's
1070 XWINDOW (sib
)->top
= p
->top
;
1071 XWINDOW (sib
)->left
= p
->left
;
1074 /* Stretch that sibling. */
1075 if (!NILP (par
->vchild
))
1076 set_window_height (sib
,
1077 XFASTINT (XWINDOW (sib
)->height
) + XFASTINT (p
->height
),
1079 if (!NILP (par
->hchild
))
1080 set_window_width (sib
,
1081 XFASTINT (XWINDOW (sib
)->width
) + XFASTINT (p
->width
),
1084 /* If parent now has only one child,
1085 put the child into the parent's place. */
1089 if (NILP (XWINDOW (tem
)->next
))
1090 replace_window (parent
, tem
);
1092 /* Since we may be deleting combination windows, we must make sure that
1093 not only p but all its children have been marked as deleted. */
1094 if (! NILP (p
->hchild
))
1095 delete_all_subwindows (XWINDOW (p
->hchild
));
1096 else if (! NILP (p
->vchild
))
1097 delete_all_subwindows (XWINDOW (p
->vchild
));
1099 /* Mark this window as deleted. */
1100 p
->buffer
= p
->hchild
= p
->vchild
= Qnil
;
1102 /* Adjust glyph matrices. */
1103 adjust_glyphs (frame
);
1107 extern Lisp_Object
next_frame (), prev_frame ();
1109 /* This comment supplies the doc string for `next-window',
1110 for make-docfile to see. We cannot put this in the real DEFUN
1111 due to limits in the Unix cpp.
1113 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
1114 "Return next window after WINDOW in canonical ordering of windows.\n\
1115 If omitted, WINDOW defaults to the selected window.\n\
1117 Optional second arg MINIBUF t means count the minibuffer window even\n\
1118 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1119 it is active. MINIBUF neither t nor nil means not to count the\n\
1120 minibuffer even if it is active.\n\
1122 Several frames may share a single minibuffer; if the minibuffer\n\
1123 counts, all windows on all frames that share that minibuffer count\n\
1124 too. Therefore, `next-window' can be used to iterate through the\n\
1125 set of windows even when the minibuffer is on another frame. If the\n\
1126 minibuffer does not count, only windows from WINDOW's frame count.\n\
1128 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1129 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1130 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1131 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1132 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1133 Anything else means restrict to WINDOW's frame.\n\
1135 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1136 `next-window' to iterate through the entire cycle of acceptable\n\
1137 windows, eventually ending up back at the window you started with.\n\
1138 `previous-window' traverses the same cycle, in the reverse order.")
1139 (window, minibuf, all_frames) */
1141 DEFUN ("next-window", Fnext_window
, Snext_window
, 0, 3, 0,
1143 (window
, minibuf
, all_frames
)
1144 register Lisp_Object window
, minibuf
, all_frames
;
1146 register Lisp_Object tem
;
1147 Lisp_Object start_window
;
1150 window
= selected_window
;
1152 CHECK_LIVE_WINDOW (window
, 0);
1154 start_window
= window
;
1156 /* minibuf == nil may or may not include minibuffers.
1157 Decide if it does. */
1159 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1160 else if (! EQ (minibuf
, Qt
))
1162 /* Now minibuf can be t => count all minibuffer windows,
1163 lambda => count none of them,
1164 or a specific minibuffer window (the active one) to count. */
1166 /* all_frames == nil doesn't specify which frames to include. */
1167 if (NILP (all_frames
))
1168 all_frames
= (! EQ (minibuf
, Qlambda
)
1169 ? (FRAME_MINIBUF_WINDOW
1172 (XWINDOW (window
)))))
1174 else if (EQ (all_frames
, Qvisible
))
1176 else if (XFASTINT (all_frames
) == 0)
1178 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1179 /* If all_frames is a frame and window arg isn't on that frame, just
1180 return the first window on the frame. */
1181 return Fframe_first_window (all_frames
);
1182 else if (! EQ (all_frames
, Qt
))
1184 /* Now all_frames is t meaning search all frames,
1185 nil meaning search just current frame,
1186 visible meaning search just visible frames,
1187 0 meaning search visible and iconified frames,
1188 or a window, meaning search the frame that window belongs to. */
1190 /* Do this loop at least once, to get the next window, and perhaps
1191 again, if we hit the minibuffer and that is not acceptable. */
1194 /* Find a window that actually has a next one. This loop
1195 climbs up the tree. */
1196 while (tem
= XWINDOW (window
)->next
, NILP (tem
))
1197 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1201 /* We've reached the end of this frame.
1202 Which other frames are acceptable? */
1203 tem
= WINDOW_FRAME (XWINDOW (window
));
1204 if (! NILP (all_frames
))
1209 tem
= next_frame (tem
, all_frames
);
1210 /* In the case where the minibuffer is active,
1211 and we include its frame as well as the selected one,
1212 next_frame may get stuck in that frame.
1213 If that happens, go back to the selected frame
1214 so we can complete the cycle. */
1216 XSETFRAME (tem
, selected_frame
);
1218 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1225 /* If we're in a combination window, find its first child and
1226 recurse on that. Otherwise, we've found the window we want. */
1229 if (!NILP (XWINDOW (window
)->hchild
))
1230 window
= XWINDOW (window
)->hchild
;
1231 else if (!NILP (XWINDOW (window
)->vchild
))
1232 window
= XWINDOW (window
)->vchild
;
1236 /* Which windows are acceptable?
1237 Exit the loop and accept this window if
1238 this isn't a minibuffer window,
1239 or we're accepting all minibuffer windows,
1240 or this is the active minibuffer and we are accepting that one, or
1241 we've come all the way around and we're back at the original window. */
1242 while (MINI_WINDOW_P (XWINDOW (window
))
1243 && ! EQ (minibuf
, Qt
)
1244 && ! EQ (minibuf
, window
)
1245 && ! EQ (window
, start_window
));
1250 /* This comment supplies the doc string for `previous-window',
1251 for make-docfile to see. We cannot put this in the real DEFUN
1252 due to limits in the Unix cpp.
1254 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1255 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1256 If omitted, WINDOW defaults to the selected window.\n\
1258 Optional second arg MINIBUF t means count the minibuffer window even\n\
1259 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1260 it is active. MINIBUF neither t nor nil means not to count the\n\
1261 minibuffer even if it is active.\n\
1263 Several frames may share a single minibuffer; if the minibuffer\n\
1264 counts, all windows on all frames that share that minibuffer count\n\
1265 too. Therefore, `previous-window' can be used to iterate through\n\
1266 the set of windows even when the minibuffer is on another frame. If\n\
1267 the minibuffer does not count, only windows from WINDOW's frame count\n\
1269 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1270 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1271 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1272 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1273 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1274 Anything else means restrict to WINDOW's frame.\n\
1276 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1277 `previous-window' to iterate through the entire cycle of acceptable\n\
1278 windows, eventually ending up back at the window you started with.\n\
1279 `next-window' traverses the same cycle, in the reverse order.")
1280 (window, minibuf, all_frames) */
1283 DEFUN ("previous-window", Fprevious_window
, Sprevious_window
, 0, 3, 0,
1285 (window
, minibuf
, all_frames
)
1286 register Lisp_Object window
, minibuf
, all_frames
;
1288 register Lisp_Object tem
;
1289 Lisp_Object start_window
;
1292 window
= selected_window
;
1294 CHECK_LIVE_WINDOW (window
, 0);
1296 start_window
= window
;
1298 /* minibuf == nil may or may not include minibuffers.
1299 Decide if it does. */
1301 minibuf
= (minibuf_level
? minibuf_window
: Qlambda
);
1302 else if (! EQ (minibuf
, Qt
))
1304 /* Now minibuf can be t => count all minibuffer windows,
1305 lambda => count none of them,
1306 or a specific minibuffer window (the active one) to count. */
1308 /* all_frames == nil doesn't specify which frames to include.
1309 Decide which frames it includes. */
1310 if (NILP (all_frames
))
1311 all_frames
= (! EQ (minibuf
, Qlambda
)
1312 ? (FRAME_MINIBUF_WINDOW
1315 (XWINDOW (window
)))))
1317 else if (EQ (all_frames
, Qvisible
))
1319 else if (XFASTINT (all_frames
) == 0)
1321 else if (FRAMEP (all_frames
) && ! EQ (all_frames
, Fwindow_frame (window
)))
1322 /* If all_frames is a frame and window arg isn't on that frame, just
1323 return the first window on the frame. */
1324 return Fframe_first_window (all_frames
);
1325 else if (! EQ (all_frames
, Qt
))
1327 /* Now all_frames is t meaning search all frames,
1328 nil meaning search just current frame,
1329 visible meaning search just visible frames,
1330 0 meaning search visible and iconified frames,
1331 or a window, meaning search the frame that window belongs to. */
1333 /* Do this loop at least once, to get the previous window, and perhaps
1334 again, if we hit the minibuffer and that is not acceptable. */
1337 /* Find a window that actually has a previous one. This loop
1338 climbs up the tree. */
1339 while (tem
= XWINDOW (window
)->prev
, NILP (tem
))
1340 if (tem
= XWINDOW (window
)->parent
, !NILP (tem
))
1344 /* We have found the top window on the frame.
1345 Which frames are acceptable? */
1346 tem
= WINDOW_FRAME (XWINDOW (window
));
1347 if (! NILP (all_frames
))
1348 /* It's actually important that we use prev_frame here,
1349 rather than next_frame. All the windows acceptable
1350 according to the given parameters should form a ring;
1351 Fnext_window and Fprevious_window should go back and
1352 forth around the ring. If we use next_frame here,
1353 then Fnext_window and Fprevious_window take different
1354 paths through the set of acceptable windows.
1355 window_loop assumes that these `ring' requirement are
1361 tem
= prev_frame (tem
, all_frames
);
1362 /* In the case where the minibuffer is active,
1363 and we include its frame as well as the selected one,
1364 next_frame may get stuck in that frame.
1365 If that happens, go back to the selected frame
1366 so we can complete the cycle. */
1368 XSETFRAME (tem
, selected_frame
);
1370 /* If this frame has a minibuffer, find that window first,
1371 because it is conceptually the last window in that frame. */
1372 if (FRAME_HAS_MINIBUF_P (XFRAME (tem
)))
1373 tem
= FRAME_MINIBUF_WINDOW (XFRAME (tem
));
1375 tem
= FRAME_ROOT_WINDOW (XFRAME (tem
));
1381 /* If we're in a combination window, find its last child and
1382 recurse on that. Otherwise, we've found the window we want. */
1385 if (!NILP (XWINDOW (window
)->hchild
))
1386 window
= XWINDOW (window
)->hchild
;
1387 else if (!NILP (XWINDOW (window
)->vchild
))
1388 window
= XWINDOW (window
)->vchild
;
1390 while (tem
= XWINDOW (window
)->next
, !NILP (tem
))
1394 /* Which windows are acceptable?
1395 Exit the loop and accept this window if
1396 this isn't a minibuffer window,
1397 or we're accepting all minibuffer windows,
1398 or this is the active minibuffer and we are accepting that one, or
1399 we've come all the way around and we're back at the original window. */
1400 while (MINI_WINDOW_P (XWINDOW (window
))
1401 && ! EQ (minibuf
, Qt
)
1402 && ! EQ (minibuf
, window
)
1403 && ! EQ (window
, start_window
));
1408 DEFUN ("other-window", Fother_window
, Sother_window
, 1, 2, "p",
1409 "Select the ARG'th different window on this frame.\n\
1410 All windows on current frame are arranged in a cyclic order.\n\
1411 This command selects the window ARG steps away in that order.\n\
1412 A negative ARG moves in the opposite order. If the optional second\n\
1413 argument ALL_FRAMES is non-nil, cycle through all frames.")
1415 register Lisp_Object arg
, all_frames
;
1418 register Lisp_Object w
;
1420 CHECK_NUMBER (arg
, 0);
1421 w
= selected_window
;
1426 w
= Fnext_window (w
, Qnil
, all_frames
);
1431 w
= Fprevious_window (w
, Qnil
, all_frames
);
1438 /* Look at all windows, performing an operation specified by TYPE
1440 If FRAMES is Qt, look at all frames;
1441 Qnil, look at just the selected frame;
1442 Qvisible, look at visible frames;
1443 a frame, just look at windows on that frame.
1444 If MINI is non-zero, perform the operation on minibuffer windows too.
1450 GET_BUFFER_WINDOW
, /* Arg is buffer */
1451 GET_LRU_WINDOW
, /* Arg is t for full-width windows only */
1452 DELETE_OTHER_WINDOWS
, /* Arg is window not to delete */
1453 DELETE_BUFFER_WINDOWS
, /* Arg is buffer */
1455 UNSHOW_BUFFER
, /* Arg is buffer */
1460 window_loop (type
, obj
, mini
, frames
)
1461 enum window_loop type
;
1462 register Lisp_Object obj
, frames
;
1465 register Lisp_Object w
;
1466 register Lisp_Object best_window
;
1467 register Lisp_Object next_window
;
1468 register Lisp_Object last_window
;
1470 Lisp_Object frame_arg
;
1473 /* If we're only looping through windows on a particular frame,
1474 frame points to that frame. If we're looping through windows
1475 on all frames, frame is 0. */
1476 if (FRAMEP (frames
))
1477 frame
= XFRAME (frames
);
1478 else if (NILP (frames
))
1479 frame
= selected_frame
;
1483 frame_arg
= Qlambda
;
1484 else if (XFASTINT (frames
) == 0)
1486 else if (EQ (frames
, Qvisible
))
1489 /* frame_arg is Qlambda to stick to one frame,
1490 Qvisible to consider all visible frames,
1493 /* Pick a window to start with. */
1497 w
= FRAME_SELECTED_WINDOW (frame
);
1499 w
= FRAME_SELECTED_WINDOW (selected_frame
);
1501 /* Figure out the last window we're going to mess with. Since
1502 Fnext_window, given the same options, is guaranteed to go in a
1503 ring, we can just use Fprevious_window to find the last one.
1505 We can't just wait until we hit the first window again, because
1506 it might be deleted. */
1508 last_window
= Fprevious_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1513 /* Pick the next window now, since some operations will delete
1514 the current window. */
1515 next_window
= Fnext_window (w
, mini
? Qt
: Qnil
, frame_arg
);
1517 /* Note that we do not pay attention here to whether
1518 the frame is visible, since Fnext_window skips non-visible frames
1519 if that is desired, under the control of frame_arg. */
1520 if (! MINI_WINDOW_P (XWINDOW (w
))
1521 /* For UNSHOW_BUFFER, we must always consider all windows. */
1522 || type
== UNSHOW_BUFFER
1523 || (mini
&& minibuf_level
> 0))
1526 case GET_BUFFER_WINDOW
:
1527 if (XBUFFER (XWINDOW (w
)->buffer
) == XBUFFER (obj
)
1528 /* Don't find any minibuffer window
1529 except the one that is currently in use. */
1530 && (MINI_WINDOW_P (XWINDOW (w
))
1531 ? EQ (w
, minibuf_window
) : 1))
1535 case GET_LRU_WINDOW
:
1536 /* t as arg means consider only full-width windows */
1537 if (!NILP (obj
) && !WINDOW_FULL_WIDTH_P (XWINDOW (w
)))
1539 /* Ignore dedicated windows and minibuffers. */
1540 if (MINI_WINDOW_P (XWINDOW (w
))
1541 || !NILP (XWINDOW (w
)->dedicated
))
1543 if (NILP (best_window
)
1544 || (XFASTINT (XWINDOW (best_window
)->use_time
)
1545 > XFASTINT (XWINDOW (w
)->use_time
)))
1549 case DELETE_OTHER_WINDOWS
:
1550 if (XWINDOW (w
) != XWINDOW (obj
))
1554 case DELETE_BUFFER_WINDOWS
:
1555 if (EQ (XWINDOW (w
)->buffer
, obj
))
1557 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1559 /* If this window is dedicated, and in a frame of its own,
1561 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1562 && !NILP (XWINDOW (w
)->dedicated
)
1563 && other_visible_frames (f
))
1565 /* Skip the other windows on this frame.
1566 There might be one, the minibuffer! */
1567 if (! EQ (w
, last_window
))
1568 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1570 /* As we go, check for the end of the loop.
1571 We mustn't start going around a second time. */
1572 if (EQ (next_window
, last_window
))
1577 next_window
= Fnext_window (next_window
,
1581 /* Now we can safely delete the frame. */
1582 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1585 /* If we're deleting the buffer displayed in the only window
1586 on the frame, find a new buffer to display there. */
1587 if (NILP (XWINDOW (w
)->parent
))
1589 Lisp_Object new_buffer
;
1590 new_buffer
= Fother_buffer (obj
, Qnil
,
1591 XWINDOW (w
)->frame
);
1592 if (NILP (new_buffer
))
1594 = Fget_buffer_create (build_string ("*scratch*"));
1595 Fset_window_buffer (w
, new_buffer
);
1596 if (EQ (w
, selected_window
))
1597 Fset_buffer (XWINDOW (w
)->buffer
);
1604 case GET_LARGEST_WINDOW
:
1605 /* Ignore dedicated windows and minibuffers. */
1606 if (MINI_WINDOW_P (XWINDOW (w
))
1607 || !NILP (XWINDOW (w
)->dedicated
))
1610 struct window
*best_window_ptr
= XWINDOW (best_window
);
1611 struct window
*w_ptr
= XWINDOW (w
);
1612 if (NILP (best_window
)
1613 || (XFASTINT (w_ptr
->height
) * XFASTINT (w_ptr
->width
)
1614 > (XFASTINT (best_window_ptr
->height
)
1615 * XFASTINT (best_window_ptr
->width
))))
1621 if (EQ (XWINDOW (w
)->buffer
, obj
))
1623 /* Find another buffer to show in this window. */
1624 Lisp_Object another_buffer
;
1625 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (w
)));
1626 another_buffer
= Fother_buffer (obj
, Qnil
, XWINDOW (w
)->frame
);
1627 if (NILP (another_buffer
))
1629 = Fget_buffer_create (build_string ("*scratch*"));
1630 /* If this window is dedicated, and in a frame of its own,
1632 if (EQ (w
, FRAME_ROOT_WINDOW (f
))
1633 && !NILP (XWINDOW (w
)->dedicated
)
1634 && other_visible_frames (f
))
1636 /* Skip the other windows on this frame.
1637 There might be one, the minibuffer! */
1638 if (! EQ (w
, last_window
))
1639 while (f
== XFRAME (WINDOW_FRAME (XWINDOW (next_window
))))
1641 /* As we go, check for the end of the loop.
1642 We mustn't start going around a second time. */
1643 if (EQ (next_window
, last_window
))
1648 next_window
= Fnext_window (next_window
,
1652 /* Now we can safely delete the frame. */
1653 Fdelete_frame (WINDOW_FRAME (XWINDOW (w
)), Qnil
);
1657 /* Otherwise show a different buffer in the window. */
1658 XWINDOW (w
)->dedicated
= Qnil
;
1659 Fset_window_buffer (w
, another_buffer
);
1660 if (EQ (w
, selected_window
))
1661 Fset_buffer (XWINDOW (w
)->buffer
);
1666 /* Check for a window that has a killed buffer. */
1667 case CHECK_ALL_WINDOWS
:
1668 if (! NILP (XWINDOW (w
)->buffer
)
1669 && NILP (XBUFFER (XWINDOW (w
)->buffer
)->name
))
1673 if (EQ (w
, last_window
))
1682 /* Used for debugging. Abort if any window has a dead buffer. */
1685 check_all_windows ()
1687 window_loop (CHECK_ALL_WINDOWS
, Qnil
, 1, Qt
);
1690 DEFUN ("get-lru-window", Fget_lru_window
, Sget_lru_window
, 0, 1, 0,
1691 "Return the window least recently selected or used for display.\n\
1692 If optional argument FRAME is `visible', search all visible frames.\n\
1693 If FRAME is 0, search all visible and iconified frames.\n\
1694 If FRAME is t, search all frames.\n\
1695 If FRAME is nil, search only the selected frame.\n\
1696 If FRAME is a frame, search only that frame.")
1700 register Lisp_Object w
;
1701 /* First try for a window that is full-width */
1702 w
= window_loop (GET_LRU_WINDOW
, Qt
, 0, frame
);
1703 if (!NILP (w
) && !EQ (w
, selected_window
))
1705 /* If none of them, try the rest */
1706 return window_loop (GET_LRU_WINDOW
, Qnil
, 0, frame
);
1709 DEFUN ("get-largest-window", Fget_largest_window
, Sget_largest_window
, 0, 1, 0,
1710 "Return the largest window in area.\n\
1711 If optional argument FRAME is `visible', search all visible frames.\n\
1712 If FRAME is 0, search all visible and iconified frames.\n\
1713 If FRAME is t, search all frames.\n\
1714 If FRAME is nil, search only the selected frame.\n\
1715 If FRAME is a frame, search only that frame.")
1719 return window_loop (GET_LARGEST_WINDOW
, Qnil
, 0,
1723 DEFUN ("get-buffer-window", Fget_buffer_window
, Sget_buffer_window
, 1, 2, 0,
1724 "Return a window currently displaying BUFFER, or nil if none.\n\
1725 If optional argument FRAME is `visible', search all visible frames.\n\
1726 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1727 If FRAME is t, search all frames.\n\
1728 If FRAME is nil, search only the selected frame.\n\
1729 If FRAME is a frame, search only that frame.")
1731 Lisp_Object buffer
, frame
;
1733 buffer
= Fget_buffer (buffer
);
1734 if (BUFFERP (buffer
))
1735 return window_loop (GET_BUFFER_WINDOW
, buffer
, 1, frame
);
1740 DEFUN ("delete-other-windows", Fdelete_other_windows
, Sdelete_other_windows
,
1742 "Make WINDOW (or the selected window) fill its frame.\n\
1743 Only the frame WINDOW is on is affected.\n\
1744 This function tries to reduce display jumps\n\
1745 by keeping the text previously visible in WINDOW\n\
1746 in the same place on the frame. Doing this depends on\n\
1747 the value of (window-start WINDOW), so if calling this function\n\
1748 in a program gives strange scrolling, make sure the window-start\n\
1749 value is reasonable when this function is called.")
1758 window
= selected_window
;
1760 CHECK_LIVE_WINDOW (window
, 0);
1762 w
= XWINDOW (window
);
1764 startpos
= marker_position (w
->start
);
1765 top
= XFASTINT (w
->top
) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w
)));
1767 if (MINI_WINDOW_P (w
) && top
> 0)
1768 error ("Can't expand minibuffer to full frame");
1770 window_loop (DELETE_OTHER_WINDOWS
, window
, 0, WINDOW_FRAME (w
));
1772 /* Try to minimize scrolling, by setting the window start to the point
1773 will cause the text at the old window start to be at the same place
1774 on the frame. But don't try to do this if the window start is
1775 outside the visible portion (as might happen when the display is
1776 not current, due to typeahead). */
1777 if (startpos
>= BUF_BEGV (XBUFFER (w
->buffer
))
1778 && startpos
<= BUF_ZV (XBUFFER (w
->buffer
)))
1780 struct position pos
;
1781 struct buffer
*obuf
= current_buffer
;
1783 Fset_buffer (w
->buffer
);
1784 /* This computation used to temporarily move point, but that can
1785 have unwanted side effects due to text properties. */
1786 pos
= *vmotion (startpos
, -top
, w
);
1788 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
1789 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
1790 || FETCH_BYTE (pos
.bytepos
- 1) == '\n') ? Qt
1792 /* We need to do this, so that the window-scroll-functions
1794 w
->optional_new_start
= Qt
;
1796 set_buffer_internal (obuf
);
1802 DEFUN ("delete-windows-on", Fdelete_windows_on
, Sdelete_windows_on
,
1803 1, 2, "bDelete windows on (buffer): ",
1804 "Delete all windows showing BUFFER.\n\
1805 Optional second argument FRAME controls which frames are affected.\n\
1806 If optional argument FRAME is `visible', search all visible frames.\n\
1807 If FRAME is 0, search all visible and iconified frames.\n\
1808 If FRAME is nil, search all frames.\n\
1809 If FRAME is t, search only the selected frame.\n\
1810 If FRAME is a frame, search only that frame.")
1812 Lisp_Object buffer
, frame
;
1814 /* FRAME uses t and nil to mean the opposite of what window_loop
1818 else if (EQ (frame
, Qt
))
1823 buffer
= Fget_buffer (buffer
);
1824 CHECK_BUFFER (buffer
, 0);
1825 window_loop (DELETE_BUFFER_WINDOWS
, buffer
, 0, frame
);
1831 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows
,
1832 Sreplace_buffer_in_windows
,
1833 1, 1, "bReplace buffer in windows: ",
1834 "Replace BUFFER with some other buffer in all windows showing it.")
1840 buffer
= Fget_buffer (buffer
);
1841 CHECK_BUFFER (buffer
, 0);
1842 window_loop (UNSHOW_BUFFER
, buffer
, 0, Qt
);
1847 /* Replace BUFFER with some other buffer in all windows
1848 of all frames, even those on other keyboards. */
1851 replace_buffer_in_all_windows (buffer
)
1855 Lisp_Object tail
, frame
;
1857 /* A single call to window_loop won't do the job
1858 because it only considers frames on the current keyboard.
1859 So loop manually over frames, and handle each one. */
1860 FOR_EACH_FRAME (tail
, frame
)
1861 window_loop (UNSHOW_BUFFER
, buffer
, 1, frame
);
1863 window_loop (UNSHOW_BUFFER
, buffer
, 1, Qt
);
1867 /* Set the height of WINDOW and all its inferiors. */
1869 /* The smallest acceptable dimensions for a window. Anything smaller
1870 might crash Emacs. */
1872 #define MIN_SAFE_WINDOW_WIDTH (2)
1873 #define MIN_SAFE_WINDOW_HEIGHT (2)
1875 /* Make sure that window_min_height and window_min_width are
1876 not too small; if they are, set them to safe minima. */
1879 check_min_window_sizes ()
1881 /* Smaller values might permit a crash. */
1882 if (window_min_width
< MIN_SAFE_WINDOW_WIDTH
)
1883 window_min_width
= MIN_SAFE_WINDOW_WIDTH
;
1884 if (window_min_height
< MIN_SAFE_WINDOW_HEIGHT
)
1885 window_min_height
= MIN_SAFE_WINDOW_HEIGHT
;
1888 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1889 minimum allowable size. */
1892 check_frame_size (frame
, rows
, cols
)
1896 /* For height, we have to see:
1897 whether the frame has a minibuffer,
1898 whether it wants a mode line, and
1899 whether it has a menu bar. */
1901 (FRAME_MINIBUF_ONLY_P (frame
) ? MIN_SAFE_WINDOW_HEIGHT
- 1
1902 : (! FRAME_HAS_MINIBUF_P (frame
)) ? MIN_SAFE_WINDOW_HEIGHT
1903 : 2 * MIN_SAFE_WINDOW_HEIGHT
- 1);
1905 if (FRAME_TOP_MARGIN (frame
) > 0)
1906 min_height
+= FRAME_TOP_MARGIN (frame
);
1908 if (*rows
< min_height
)
1910 if (*cols
< MIN_SAFE_WINDOW_WIDTH
)
1911 *cols
= MIN_SAFE_WINDOW_WIDTH
;
1915 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
1916 check if W's width can be changed, otherwise check W's height.
1917 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
1918 siblings, too. If none of the siblings is resizable, WINDOW isn't
1922 window_fixed_size_p (w
, width_p
, check_siblings_p
)
1924 int width_p
, check_siblings_p
;
1929 if (!NILP (w
->hchild
))
1931 c
= XWINDOW (w
->hchild
);
1935 /* A horiz. combination is fixed-width if all of if its
1937 while (c
&& window_fixed_size_p (c
, width_p
, 0))
1938 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1939 fixed_p
= c
== NULL
;
1943 /* A horiz. combination is fixed-height if one of if its
1945 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
1946 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1947 fixed_p
= c
!= NULL
;
1950 else if (!NILP (w
->vchild
))
1952 c
= XWINDOW (w
->vchild
);
1956 /* A vert. combination is fixed-width if one of if its
1958 while (c
&& !window_fixed_size_p (c
, width_p
, 0))
1959 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1960 fixed_p
= c
!= NULL
;
1964 /* A vert. combination is fixed-height if all of if its
1966 while (c
&& window_fixed_size_p (c
, width_p
, 0))
1967 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
1968 fixed_p
= c
== NULL
;
1971 else if (BUFFERP (w
->buffer
))
1974 struct buffer
*old
= current_buffer
;
1976 current_buffer
= XBUFFER (w
->buffer
);
1977 val
= find_symbol_value (Qwindow_size_fixed
);
1978 current_buffer
= old
;
1981 if (!EQ (val
, Qunbound
))
1983 fixed_p
= !NILP (val
);
1986 && ((EQ (val
, Qheight
) && width_p
)
1987 || (EQ (val
, Qwidth
) && !width_p
)))
1991 /* Can't tell if this one is resizable without looking at
1992 siblings. If all siblings are fixed-size this one is too. */
1993 if (!fixed_p
&& check_siblings_p
&& WINDOWP (w
->parent
))
1997 for (child
= w
->prev
; !NILP (child
); child
= XWINDOW (child
)->prev
)
1998 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2002 for (child
= w
->next
; !NILP (child
); child
= XWINDOW (child
)->next
)
2003 if (!window_fixed_size_p (XWINDOW (child
), width_p
, 0))
2017 /* Return the minimum size of window W, not taking fixed-width windows
2018 into account. WIDTH_P non-zero means return the minimum width,
2019 otherwise return the minimum height. If W is a combination window,
2020 compute the minimum size from the minimum sizes of W's children. */
2023 window_min_size_1 (w
, width_p
)
2030 if (!NILP (w
->hchild
))
2032 c
= XWINDOW (w
->hchild
);
2037 /* The min width of a horizontal combination is
2038 the sum of the min widths of its children. */
2041 size
+= window_min_size_1 (c
, width_p
);
2042 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2047 /* The min height a horizontal combination equals
2048 the maximum of all min height of its children. */
2051 int min_size
= window_min_size_1 (c
, width_p
);
2052 size
= max (min_size
, size
);
2053 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2057 else if (!NILP (w
->vchild
))
2059 c
= XWINDOW (w
->vchild
);
2064 /* The min width of a vertical combination is
2065 the maximum of the min widths of its children. */
2068 int min_size
= window_min_size_1 (c
, width_p
);
2069 size
= max (min_size
, size
);
2070 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2075 /* The min height of a vertical combination equals
2076 the sum of the min height of its children. */
2079 size
+= window_min_size_1 (c
, width_p
);
2080 c
= WINDOWP (c
->next
) ? XWINDOW (c
->next
) : NULL
;
2087 size
= window_min_width
;
2090 if (MINI_WINDOW_P (w
)
2091 || (!WINDOW_WANTS_MODELINE_P (w
)
2092 && !WINDOW_WANTS_TOP_LINE_P (w
)))
2095 size
= window_min_height
;
2103 /* Return the minimum size of window W, taking fixed-size windows into
2104 account. WIDTH_P non-zero means return the minimum width,
2105 otherwise return the minimum height. Set *FIXED to 1 if W is
2106 fixed-size unless FIXED is null. */
2109 window_min_size (w
, width_p
, fixed
)
2111 int width_p
, *fixed
;
2115 fixed_p
= window_fixed_size_p (w
, width_p
, 1);
2120 size
= width_p
? XFASTINT (w
->width
) : XFASTINT (w
->height
);
2122 size
= window_min_size_1 (w
, width_p
);
2128 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2129 WINDOW's width. Resize WINDOW's children, if any, so that they
2130 keep their proportionate size relative to WINDOW. Propagate
2131 WINDOW's top or left edge position to children. Delete windows
2132 that become too small unless NODELETE_P is non-zero. */
2135 size_window (window
, size
, width_p
, nodelete_p
)
2137 int size
, width_p
, nodelete_p
;
2139 struct window
*w
= XWINDOW (window
);
2141 Lisp_Object child
, *forward
, *sideward
;
2142 int old_size
, min_size
;
2144 check_min_window_sizes ();
2146 /* If the window has been "too small" at one point,
2147 don't delete it for being "too small" in the future.
2148 Preserve it as long as that is at all possible. */
2151 old_size
= XFASTINT (w
->width
);
2152 min_size
= window_min_width
;
2156 old_size
= XFASTINT (w
->height
);
2157 min_size
= window_min_height
;
2160 if (old_size
< window_min_width
)
2161 w
->too_small_ok
= Qt
;
2163 /* Maybe delete WINDOW if it's too small. */
2164 if (!nodelete_p
&& !NILP (w
->parent
))
2168 if (!MINI_WINDOW_P (w
) && !NILP (w
->too_small_ok
))
2169 min_size
= width_p
? MIN_SAFE_WINDOW_WIDTH
: MIN_SAFE_WINDOW_HEIGHT
;
2171 min_size
= width_p
? window_min_width
: window_min_height
;
2173 if (size
< min_size
)
2175 delete_window (window
);
2180 /* Set redisplay hints. */
2181 XSETFASTINT (w
->last_modified
, 0);
2182 XSETFASTINT (w
->last_overlay_modified
, 0);
2183 windows_or_buffers_changed
++;
2184 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w
))) = 1;
2188 sideward
= &w
->vchild
;
2189 forward
= &w
->hchild
;
2190 XSETFASTINT (w
->width
, size
);
2194 sideward
= &w
->hchild
;
2195 forward
= &w
->vchild
;
2196 XSETFASTINT (w
->height
, size
);
2199 if (!NILP (*sideward
))
2201 for (child
= *sideward
; !NILP (child
); child
= c
->next
)
2203 c
= XWINDOW (child
);
2208 size_window (child
, size
, width_p
, nodelete_p
);
2211 else if (!NILP (*forward
))
2213 int fixed_size
, each
, extra
, n
;
2214 int resize_fixed_p
, nfixed
;
2215 int last_pos
, first_pos
, nchildren
;
2217 /* Determine the fixed-size portion of the this window, and the
2218 number of child windows. */
2219 fixed_size
= nchildren
= nfixed
= 0;
2220 for (child
= *forward
; !NILP (child
); child
= c
->next
, ++nchildren
)
2222 c
= XWINDOW (child
);
2223 if (window_fixed_size_p (c
, width_p
, 0))
2225 fixed_size
+= (width_p
2226 ? XFASTINT (c
->width
) : XFASTINT (c
->height
));
2231 /* If the new size is smaller than fixed_size, or if there
2232 aren't any resizable windows, allow resizing fixed-size
2234 resize_fixed_p
= nfixed
== nchildren
|| size
< fixed_size
;
2236 /* Compute how many lines/columns to add to each child. The
2237 value of extra takes care of rounding errors. */
2238 n
= resize_fixed_p
? nchildren
: nchildren
- nfixed
;
2239 each
= (size
- old_size
) / n
;
2240 extra
= (size
- old_size
) - n
* each
;
2242 /* Compute new children heights and edge positions. */
2243 first_pos
= width_p
? XFASTINT (w
->left
) : XFASTINT (w
->top
);
2244 last_pos
= first_pos
;
2245 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2247 int new_size
, old_size
;
2249 c
= XWINDOW (child
);
2250 old_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2251 new_size
= old_size
;
2253 /* The top or left edge position of this child equals the
2254 bottom or right edge of its predecessor. */
2256 c
->left
= make_number (last_pos
);
2258 c
->top
= make_number (last_pos
);
2260 /* If this child can be resized, do it. */
2261 if (resize_fixed_p
|| !window_fixed_size_p (c
, width_p
, 0))
2263 new_size
= old_size
+ each
+ extra
;
2267 /* Set new height. Note that size_window also propagates
2268 edge positions to children, so it's not a no-op if we
2269 didn't change the child's size. */
2270 size_window (child
, new_size
, width_p
, 1);
2272 /* Remember the bottom/right edge position of this child; it
2273 will be used to set the top/left edge of the next child. */
2274 last_pos
+= new_size
;
2277 /* We should have covered the parent exactly with child windows. */
2278 xassert (size
== last_pos
- first_pos
);
2280 /* Now delete any children that became too small. */
2282 for (child
= *forward
; !NILP (child
); child
= c
->next
)
2285 c
= XWINDOW (child
);
2286 child_size
= width_p
? XFASTINT (c
->width
) : XFASTINT (c
->height
);
2287 size_window (child
, child_size
, width_p
, 0);
2292 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2293 WINDOW's children. NODELETE non-zero means don't delete windows
2294 that become too small in the process. (The caller should check
2295 later and do so if appropriate.) */
2298 set_window_height (window
, height
, nodelete
)
2303 size_window (window
, height
, 0, nodelete
);
2307 /* Set WINDOW's width to WIDTH, and recursively change the width of
2308 WINDOW's children. NODELETE non-zero means don't delete windows
2309 that become too small in the process. (The caller should check
2310 later and do so if appropriate.) */
2313 set_window_width (window
, width
, nodelete
)
2318 size_window (window
, width
, 1, nodelete
);
2322 int window_select_count
;
2325 Fset_window_buffer_unwind (obuf
)
2333 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2334 means it's allowed to run hooks. See make_frame for a case where
2335 it's not allowed. */
2338 set_window_buffer (window
, buffer
, run_hooks_p
)
2339 Lisp_Object window
, buffer
;
2342 struct window
*w
= XWINDOW (window
);
2343 struct buffer
*b
= XBUFFER (buffer
);
2344 int count
= specpdl_ptr
- specpdl
;
2348 if (EQ (window
, selected_window
))
2349 b
->last_selected_window
= window
;
2351 /* Update time stamps of buffer display. */
2352 if (INTEGERP (b
->display_count
))
2353 XSETINT (b
->display_count
, XINT (b
->display_count
) + 1);
2354 b
->display_time
= Fcurrent_time ();
2356 XSETFASTINT (w
->window_end_pos
, 0);
2357 XSETFASTINT (w
->window_end_vpos
, 0);
2358 bzero (&w
->last_cursor
, sizeof w
->last_cursor
);
2359 w
->window_end_valid
= Qnil
;
2360 XSETFASTINT (w
->hscroll
, 0);
2361 set_marker_both (w
->pointm
, buffer
, BUF_PT (b
), BUF_PT_BYTE (b
));
2362 set_marker_restricted (w
->start
,
2363 make_number (b
->last_window_start
),
2365 w
->start_at_line_beg
= Qnil
;
2366 w
->force_start
= Qnil
;
2367 XSETFASTINT (w
->last_modified
, 0);
2368 XSETFASTINT (w
->last_overlay_modified
, 0);
2369 windows_or_buffers_changed
++;
2371 /* We must select BUFFER for running the window-scroll-functions.
2372 If WINDOW is selected, switch permanently.
2373 Otherwise, switch but go back to the ambient buffer afterward. */
2374 if (EQ (window
, selected_window
))
2375 Fset_buffer (buffer
);
2376 /* We can't check ! NILP (Vwindow_scroll_functions) here
2377 because that might itself be a local variable. */
2378 else if (window_initialized
)
2380 record_unwind_protect (Fset_window_buffer_unwind
, Fcurrent_buffer ());
2381 Fset_buffer (buffer
);
2384 /* Set left and right marginal area width from buffer. */
2385 Fset_window_margins (b
->left_margin_width
, b
->right_margin_width
,
2390 if (! NILP (Vwindow_scroll_functions
))
2391 run_hook_with_args_2 (Qwindow_scroll_functions
, window
,
2392 Fmarker_position (w
->start
));
2394 if (! NILP (Vwindow_configuration_change_hook
)
2395 && ! NILP (Vrun_hooks
))
2396 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
2399 unbind_to (count
, Qnil
);
2403 DEFUN ("set-window-buffer", Fset_window_buffer
, Sset_window_buffer
, 2, 2, 0,
2404 "Make WINDOW display BUFFER as its contents.\n\
2405 BUFFER can be a buffer or buffer name.")
2407 register Lisp_Object window
, buffer
;
2409 register Lisp_Object tem
;
2410 register struct window
*w
= decode_window (window
);
2413 buffer
= Fget_buffer (buffer
);
2414 CHECK_BUFFER (buffer
, 1);
2416 if (NILP (XBUFFER (buffer
)->name
))
2417 error ("Attempt to display deleted buffer");
2421 error ("Window is deleted");
2422 else if (! EQ (tem
, Qt
)) /* w->buffer is t when the window
2423 is first being set up. */
2425 if (!NILP (w
->dedicated
) && !EQ (tem
, buffer
))
2426 error ("Window is dedicated to `%s'",
2427 XSTRING (XBUFFER (tem
)->name
)->data
);
2432 set_window_buffer (window
, buffer
, 1);
2436 DEFUN ("select-window", Fselect_window
, Sselect_window
, 1, 1, 0,
2437 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
2438 If WINDOW is not already selected, also make WINDOW's buffer current.\n\
2439 Note that the main editor command loop\n\
2440 selects the buffer of the selected window before each command.")
2442 register Lisp_Object window
;
2444 return select_window_1 (window
, 1);
2448 select_window_1 (window
, recordflag
)
2449 register Lisp_Object window
;
2452 register struct window
*w
;
2453 register struct window
*ow
= XWINDOW (selected_window
);
2455 CHECK_LIVE_WINDOW (window
, 0);
2457 w
= XWINDOW (window
);
2459 if (NILP (w
->buffer
))
2460 error ("Trying to select deleted window or non-leaf window");
2462 XSETFASTINT (w
->use_time
, ++window_select_count
);
2463 if (EQ (window
, selected_window
))
2466 if (! NILP (ow
->buffer
))
2467 set_marker_both (ow
->pointm
, ow
->buffer
,
2468 BUF_PT (XBUFFER (ow
->buffer
)),
2469 BUF_PT_BYTE (XBUFFER (ow
->buffer
)));
2471 selected_window
= window
;
2472 if (XFRAME (WINDOW_FRAME (w
)) != selected_frame
)
2474 XFRAME (WINDOW_FRAME (w
))->selected_window
= window
;
2475 /* Use this rather than Fhandle_switch_frame
2476 so that FRAME_FOCUS_FRAME is moved appropriately as we
2477 move around in the state where a minibuffer in a separate
2479 Fselect_frame (WINDOW_FRAME (w
), Qnil
);
2482 selected_frame
->selected_window
= window
;
2485 record_buffer (w
->buffer
);
2486 Fset_buffer (w
->buffer
);
2488 XBUFFER (w
->buffer
)->last_selected_window
= window
;
2490 /* Go to the point recorded in the window.
2491 This is important when the buffer is in more
2492 than one window. It also matters when
2493 redisplay_window has altered point after scrolling,
2494 because it makes the change only in the window. */
2496 register int new_point
= marker_position (w
->pointm
);
2497 if (new_point
< BEGV
)
2499 else if (new_point
> ZV
)
2505 windows_or_buffers_changed
++;
2509 /* Deiconify the frame containing the window WINDOW,
2510 unless it is the selected frame;
2513 The reason for the exception for the selected frame
2514 is that it seems better not to change the selected frames visibility
2515 merely because of displaying a different buffer in it.
2516 The deiconification is useful when a buffer gets shown in
2517 another frame that you were not using lately. */
2520 display_buffer_1 (window
)
2523 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (window
)));
2524 FRAME_SAMPLE_VISIBILITY (f
);
2525 if (f
!= selected_frame
)
2527 if (FRAME_ICONIFIED_P (f
))
2528 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2529 else if (FRAME_VISIBLE_P (f
))
2530 Fraise_frame (WINDOW_FRAME (XWINDOW (window
)));
2535 DEFUN ("special-display-p", Fspecial_display_p
, Sspecial_display_p
, 1, 1, 0,
2536 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2537 The value is actually t if the frame should be called with default frame\n\
2538 parameters, and a list of frame parameters if they were specified.\n\
2539 See `special-display-buffer-names', and `special-display-regexps'.")
2541 Lisp_Object buffer_name
;
2545 CHECK_STRING (buffer_name
, 1);
2547 tem
= Fmember (buffer_name
, Vspecial_display_buffer_names
);
2551 tem
= Fassoc (buffer_name
, Vspecial_display_buffer_names
);
2555 for (tem
= Vspecial_display_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2557 Lisp_Object car
= XCAR (tem
);
2559 && fast_string_match (car
, buffer_name
) >= 0)
2561 else if (CONSP (car
)
2562 && STRINGP (XCAR (car
))
2563 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2569 DEFUN ("same-window-p", Fsame_window_p
, Ssame_window_p
, 1, 1, 0,
2570 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2571 See `same-window-buffer-names' and `same-window-regexps'.")
2573 Lisp_Object buffer_name
;
2577 CHECK_STRING (buffer_name
, 1);
2579 tem
= Fmember (buffer_name
, Vsame_window_buffer_names
);
2583 tem
= Fassoc (buffer_name
, Vsame_window_buffer_names
);
2587 for (tem
= Vsame_window_regexps
; CONSP (tem
); tem
= XCDR (tem
))
2589 Lisp_Object car
= XCAR (tem
);
2591 && fast_string_match (car
, buffer_name
) >= 0)
2593 else if (CONSP (car
)
2594 && STRINGP (XCAR (car
))
2595 && fast_string_match (XCAR (car
), buffer_name
) >= 0)
2601 /* Use B so the default is (other-buffer). */
2602 DEFUN ("display-buffer", Fdisplay_buffer
, Sdisplay_buffer
, 1, 3,
2603 "BDisplay buffer: \nP",
2604 "Make BUFFER appear in some window but don't select it.\n\
2605 BUFFER can be a buffer or a buffer name.\n\
2606 If BUFFER is shown already in some window, just use that one,\n\
2607 unless the window is the selected window and the optional second\n\
2608 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2609 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2610 Returns the window displaying BUFFER.\n\
2612 The variables `special-display-buffer-names', `special-display-regexps',\n\
2613 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2614 buffer names are handled.\n\
2616 If optional argument FRAME is `visible', search all visible frames.\n\
2617 If FRAME is 0, search all visible and iconified frames.\n\
2618 If FRAME is t, search all frames.\n\
2619 If FRAME is a frame, search only that frame.\n\
2620 If FRAME is nil, search only the selected frame\n\
2621 (actually the last nonminibuffer frame),\n\
2622 unless `pop-up-frames' is non-nil,\n\
2623 which means search visible and iconified frames.")
2624 (buffer
, not_this_window
, frame
)
2625 register Lisp_Object buffer
, not_this_window
, frame
;
2627 register Lisp_Object window
, tem
, swp
;
2630 buffer
= Fget_buffer (buffer
);
2631 CHECK_BUFFER (buffer
, 0);
2633 if (!NILP (Vdisplay_buffer_function
))
2634 return call2 (Vdisplay_buffer_function
, buffer
, not_this_window
);
2636 if (NILP (not_this_window
)
2637 && XBUFFER (XWINDOW (selected_window
)->buffer
) == XBUFFER (buffer
))
2638 return display_buffer_1 (selected_window
);
2640 /* See if the user has specified this buffer should appear
2641 in the selected window. */
2642 if (NILP (not_this_window
))
2644 swp
= Fsame_window_p (XBUFFER (buffer
)->name
);
2645 if (!NILP (swp
) && !no_switch_window (selected_window
))
2647 Fswitch_to_buffer (buffer
, Qnil
);
2648 return display_buffer_1 (selected_window
);
2652 /* If pop_up_frames,
2653 look for a window showing BUFFER on any visible or iconified frame.
2654 Otherwise search only the current frame. */
2657 else if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2658 XSETFASTINT (tem
, 0);
2660 XSETFRAME (tem
, last_nonminibuf_frame
);
2661 window
= Fget_buffer_window (buffer
, tem
);
2663 && (NILP (not_this_window
) || !EQ (window
, selected_window
)))
2665 return display_buffer_1 (window
);
2668 /* Certain buffer names get special handling. */
2669 if (!NILP (Vspecial_display_function
) && NILP (swp
))
2671 tem
= Fspecial_display_p (XBUFFER (buffer
)->name
);
2673 return call1 (Vspecial_display_function
, buffer
);
2675 return call2 (Vspecial_display_function
, buffer
, tem
);
2678 /* If there are no frames open that have more than a minibuffer,
2679 we need to create a new frame. */
2680 if (pop_up_frames
|| last_nonminibuf_frame
== 0)
2682 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2683 Fset_window_buffer (window
, buffer
);
2684 return display_buffer_1 (window
);
2688 || FRAME_MINIBUF_ONLY_P (selected_frame
)
2689 /* If the current frame is a special display frame,
2690 don't try to reuse its windows. */
2691 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame
))->dedicated
)
2697 if (FRAME_MINIBUF_ONLY_P (selected_frame
))
2698 XSETFRAME (frames
, last_nonminibuf_frame
);
2699 /* Don't try to create a window if would get an error */
2700 if (split_height_threshold
< window_min_height
<< 1)
2701 split_height_threshold
= window_min_height
<< 1;
2703 /* Note that both Fget_largest_window and Fget_lru_window
2704 ignore minibuffers and dedicated windows.
2705 This means they can return nil. */
2707 /* If the frame we would try to split cannot be split,
2708 try other frames. */
2709 if (FRAME_NO_SPLIT_P (NILP (frames
) ? selected_frame
2710 : last_nonminibuf_frame
))
2712 /* Try visible frames first. */
2713 window
= Fget_largest_window (Qvisible
);
2714 /* If that didn't work, try iconified frames. */
2716 window
= Fget_largest_window (make_number (0));
2718 window
= Fget_largest_window (Qt
);
2721 window
= Fget_largest_window (frames
);
2723 /* If we got a tall enough full-width window that can be split,
2726 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2727 && window_height (window
) >= split_height_threshold
2728 && WINDOW_FULL_WIDTH_P (XWINDOW (window
)))
2729 window
= Fsplit_window (window
, Qnil
, Qnil
);
2732 Lisp_Object upper
, lower
, other
;
2734 window
= Fget_lru_window (frames
);
2735 /* If the LRU window is selected, and big enough,
2736 and can be split, split it. */
2738 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window
)->frame
))
2739 && (EQ (window
, selected_window
)
2740 || EQ (XWINDOW (window
)->parent
, Qnil
))
2741 && window_height (window
) >= window_min_height
<< 1)
2742 window
= Fsplit_window (window
, Qnil
, Qnil
);
2743 /* If Fget_lru_window returned nil, try other approaches. */
2745 /* Try visible frames first. */
2747 window
= Fget_buffer_window (buffer
, Qvisible
);
2749 window
= Fget_largest_window (Qvisible
);
2750 /* If that didn't work, try iconified frames. */
2752 window
= Fget_buffer_window (buffer
, make_number (0));
2754 window
= Fget_largest_window (make_number (0));
2755 /* Try invisible frames. */
2757 window
= Fget_buffer_window (buffer
, Qt
);
2759 window
= Fget_largest_window (Qt
);
2760 /* As a last resort, make a new frame. */
2762 window
= Fframe_selected_window (call0 (Vpop_up_frame_function
));
2763 /* If window appears above or below another,
2764 even out their heights. */
2765 other
= upper
= lower
= Qnil
;
2766 if (!NILP (XWINDOW (window
)->prev
))
2767 other
= upper
= XWINDOW (window
)->prev
, lower
= window
;
2768 if (!NILP (XWINDOW (window
)->next
))
2769 other
= lower
= XWINDOW (window
)->next
, upper
= window
;
2771 /* Check that OTHER and WINDOW are vertically arrayed. */
2772 && !EQ (XWINDOW (other
)->top
, XWINDOW (window
)->top
)
2773 && (XFASTINT (XWINDOW (other
)->height
)
2774 > XFASTINT (XWINDOW (window
)->height
)))
2776 int total
= (XFASTINT (XWINDOW (other
)->height
)
2777 + XFASTINT (XWINDOW (window
)->height
));
2778 Lisp_Object old_selected_window
;
2779 old_selected_window
= selected_window
;
2781 selected_window
= upper
;
2782 change_window_height ((total
/ 2
2783 - XFASTINT (XWINDOW (upper
)->height
)),
2785 selected_window
= old_selected_window
;
2790 window
= Fget_lru_window (Qnil
);
2792 Fset_window_buffer (window
, buffer
);
2793 return display_buffer_1 (window
);
2797 temp_output_buffer_show (buf
)
2798 register Lisp_Object buf
;
2800 register struct buffer
*old
= current_buffer
;
2801 register Lisp_Object window
;
2802 register struct window
*w
;
2804 XBUFFER (buf
)->directory
= current_buffer
->directory
;
2807 BUF_SAVE_MODIFF (XBUFFER (buf
)) = MODIFF
;
2811 XBUFFER (buf
)->prevent_redisplay_optimizations_p
= 1;
2812 set_buffer_internal (old
);
2814 if (!EQ (Vtemp_buffer_show_function
, Qnil
))
2815 call1 (Vtemp_buffer_show_function
, buf
);
2818 window
= Fdisplay_buffer (buf
, Qnil
, Qnil
);
2820 if (XFRAME (XWINDOW (window
)->frame
) != selected_frame
)
2821 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window
)));
2822 Vminibuf_scroll_window
= window
;
2823 w
= XWINDOW (window
);
2824 XSETFASTINT (w
->hscroll
, 0);
2825 set_marker_restricted_both (w
->start
, buf
, 1, 1);
2826 set_marker_restricted_both (w
->pointm
, buf
, 1, 1);
2828 /* Run temp-buffer-show-hook, with the chosen window selected
2829 and it sbuffer current. */
2830 if (!NILP (Vrun_hooks
))
2833 tem
= Fboundp (Qtemp_buffer_show_hook
);
2836 tem
= Fsymbol_value (Qtemp_buffer_show_hook
);
2839 int count
= specpdl_ptr
- specpdl
;
2840 Lisp_Object prev_window
;
2841 prev_window
= selected_window
;
2843 /* Select the window that was chosen, for running the hook. */
2844 record_unwind_protect (Fselect_window
, prev_window
);
2845 select_window_1 (window
, 0);
2846 Fset_buffer (w
->buffer
);
2847 call1 (Vrun_hooks
, Qtemp_buffer_show_hook
);
2848 select_window_1 (prev_window
, 0);
2849 unbind_to (count
, Qnil
);
2857 make_dummy_parent (window
)
2861 register struct window
*o
, *p
;
2862 register struct Lisp_Vector
*vec
;
2865 o
= XWINDOW (window
);
2866 vec
= allocate_vectorlike ((EMACS_INT
)VECSIZE (struct window
));
2867 for (i
= 0; i
< VECSIZE (struct window
); ++i
)
2868 vec
->contents
[i
] = ((struct Lisp_Vector
*)o
)->contents
[i
];
2869 vec
->size
= VECSIZE (struct window
);
2870 p
= (struct window
*)vec
;
2871 XSETWINDOW (new, p
);
2873 XSETFASTINT (p
->sequence_number
, ++sequence_number
);
2875 /* Put new into window structure in place of window */
2876 replace_window (window
, new);
2889 DEFUN ("split-window", Fsplit_window
, Ssplit_window
, 0, 3, "",
2890 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2891 WINDOW defaults to selected one and SIZE to half its size.\n\
2892 If optional third arg HORFLAG is non-nil, split side by side\n\
2893 and put SIZE columns in the first of the pair. In that case,\n\
2894 SIZE includes that window's scroll bar, or the divider column to its right.")
2895 (window
, size
, horflag
)
2896 Lisp_Object window
, size
, horflag
;
2898 register Lisp_Object
new;
2899 register struct window
*o
, *p
;
2901 register int size_int
;
2904 window
= selected_window
;
2906 CHECK_LIVE_WINDOW (window
, 0);
2908 o
= XWINDOW (window
);
2909 fo
= XFRAME (WINDOW_FRAME (o
));
2913 if (!NILP (horflag
))
2914 /* Calculate the size of the left-hand window, by dividing
2915 the usable space in columns by two.
2916 We round up, since the left-hand window may include
2917 a dividing line, while the right-hand may not. */
2918 size_int
= (XFASTINT (o
->width
) + 1) >> 1;
2920 size_int
= XFASTINT (o
->height
) >> 1;
2924 CHECK_NUMBER (size
, 1);
2925 size_int
= XINT (size
);
2928 if (MINI_WINDOW_P (o
))
2929 error ("Attempt to split minibuffer window");
2930 else if (window_fixed_size_p (o
, !NILP (horflag
), 0))
2931 error ("Attempt to split fixed-size window");
2933 check_min_window_sizes ();
2937 if (size_int
< window_min_height
)
2938 error ("Window height %d too small (after splitting)", size_int
);
2939 if (size_int
+ window_min_height
> XFASTINT (o
->height
))
2940 error ("Window height %d too small (after splitting)",
2941 XFASTINT (o
->height
) - size_int
);
2942 if (NILP (o
->parent
)
2943 || NILP (XWINDOW (o
->parent
)->vchild
))
2945 make_dummy_parent (window
);
2947 XWINDOW (new)->vchild
= window
;
2952 if (size_int
< window_min_width
)
2953 error ("Window width %d too small (after splitting)", size_int
);
2955 if (size_int
+ window_min_width
> XFASTINT (o
->width
))
2956 error ("Window width %d too small (after splitting)",
2957 XFASTINT (o
->width
) - size_int
);
2958 if (NILP (o
->parent
)
2959 || NILP (XWINDOW (o
->parent
)->hchild
))
2961 make_dummy_parent (window
);
2963 XWINDOW (new)->hchild
= window
;
2967 /* Now we know that window's parent is a vertical combination
2968 if we are dividing vertically, or a horizontal combination
2969 if we are making side-by-side windows */
2971 windows_or_buffers_changed
++;
2972 FRAME_WINDOW_SIZES_CHANGED (fo
) = 1;
2973 new = make_window ();
2976 p
->frame
= o
->frame
;
2978 if (!NILP (p
->next
))
2979 XWINDOW (p
->next
)->prev
= new;
2982 p
->parent
= o
->parent
;
2984 p
->window_end_valid
= Qnil
;
2985 bzero (&p
->last_cursor
, sizeof p
->last_cursor
);
2987 /* Apportion the available frame space among the two new windows */
2989 if (!NILP (horflag
))
2991 p
->height
= o
->height
;
2993 XSETFASTINT (p
->width
, XFASTINT (o
->width
) - size_int
);
2994 XSETFASTINT (o
->width
, size_int
);
2995 XSETFASTINT (p
->left
, XFASTINT (o
->left
) + size_int
);
3000 p
->width
= o
->width
;
3001 XSETFASTINT (p
->height
, XFASTINT (o
->height
) - size_int
);
3002 XSETFASTINT (o
->height
, size_int
);
3003 XSETFASTINT (p
->top
, XFASTINT (o
->top
) + size_int
);
3006 /* Adjust glyph matrices. */
3008 Fset_window_buffer (new, o
->buffer
);
3012 DEFUN ("enlarge-window", Fenlarge_window
, Senlarge_window
, 1, 2, "p",
3013 "Make current window ARG lines bigger.\n\
3014 From program, optional second arg non-nil means grow sideways ARG columns.")
3016 register Lisp_Object arg
, side
;
3018 CHECK_NUMBER (arg
, 0);
3019 change_window_height (XINT (arg
), !NILP (side
));
3021 if (! NILP (Vwindow_configuration_change_hook
))
3022 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3027 DEFUN ("shrink-window", Fshrink_window
, Sshrink_window
, 1, 2, "p",
3028 "Make current window ARG lines smaller.\n\
3029 From program, optional second arg non-nil means shrink sideways arg columns.")
3031 register Lisp_Object arg
, side
;
3033 CHECK_NUMBER (arg
, 0);
3034 change_window_height (-XINT (arg
), !NILP (side
));
3036 if (! NILP (Vwindow_configuration_change_hook
))
3037 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
3043 window_height (window
)
3046 register struct window
*p
= XWINDOW (window
);
3047 return XFASTINT (p
->height
);
3051 window_width (window
)
3054 register struct window
*p
= XWINDOW (window
);
3055 return XFASTINT (p
->width
);
3060 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
3062 #define CURSIZE(w) \
3063 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
3066 /* Enlarge selected_window by DELTA. WIDTHFLAG non-zero means
3067 increase its width. Siblings of the selected window are resized to
3068 fullfil the size request. If they become too small in the process,
3069 they will be deleted. */
3072 change_window_height (delta
, widthflag
)
3073 int delta
, widthflag
;
3075 Lisp_Object parent
, window
, next
, prev
;
3077 int *sizep
, maximum
;
3078 int (*sizefun
) P_ ((Lisp_Object
))
3079 = widthflag
? window_width
: window_height
;
3080 void (*setsizefun
) P_ ((Lisp_Object
, int, int))
3081 = (widthflag
? set_window_width
: set_window_height
);
3083 /* Check values of window_min_width and window_min_height for
3085 check_min_window_sizes ();
3087 /* Give up if this window cannot be resized. */
3088 window
= selected_window
;
3089 if (window_fixed_size_p (XWINDOW (window
), widthflag
, 1))
3090 error ("Window is not resizable");
3092 /* Find the parent of the selected window. */
3095 p
= XWINDOW (window
);
3101 error ("No other window to side of this one");
3106 ? !NILP (XWINDOW (parent
)->hchild
)
3107 : !NILP (XWINDOW (parent
)->vchild
))
3113 sizep
= &CURSIZE (window
);
3116 register int maxdelta
;
3118 maxdelta
= (!NILP (parent
) ? (*sizefun
) (parent
) - *sizep
3119 : !NILP (p
->next
) ? ((*sizefun
) (p
->next
)
3120 - window_min_size (XWINDOW (p
->next
),
3122 : !NILP (p
->prev
) ? ((*sizefun
) (p
->prev
)
3123 - window_min_size (XWINDOW (p
->prev
),
3125 /* This is a frame with only one window, a minibuffer-only
3126 or a minibufferless frame. */
3129 if (delta
> maxdelta
)
3130 /* This case traps trying to make the minibuffer
3131 the full frame, or make the only window aside from the
3132 minibuffer the full frame. */
3136 if (*sizep
+ delta
< window_min_size (XWINDOW (window
), widthflag
, 0))
3138 delete_window (window
);
3145 /* Find the total we can get from other siblings. */
3147 for (next
= p
->next
; ! NILP (next
); next
= XWINDOW (next
)->next
)
3148 maximum
+= (*sizefun
) (next
) - window_min_size (XWINDOW (next
),
3150 for (prev
= p
->prev
; ! NILP (prev
); prev
= XWINDOW (prev
)->prev
)
3151 maximum
+= (*sizefun
) (prev
) - window_min_size (XWINDOW (prev
),
3154 /* If we can get it all from them, do so. */
3155 if (delta
<= maximum
)
3157 Lisp_Object first_unaffected
;
3158 Lisp_Object first_affected
;
3163 first_affected
= window
;
3164 /* Look at one sibling at a time,
3165 moving away from this window in both directions alternately,
3166 and take as much as we can get without deleting that sibling. */
3167 while (delta
!= 0 && (!NILP (next
) || !NILP (prev
)))
3171 int this_one
= ((*sizefun
) (next
)
3172 - window_min_size (XWINDOW (next
),
3173 widthflag
, &fixed_p
));
3176 if (this_one
> delta
)
3179 (*setsizefun
) (next
, (*sizefun
) (next
) - this_one
, 0);
3180 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
3185 next
= XWINDOW (next
)->next
;
3193 int this_one
= ((*sizefun
) (prev
)
3194 - window_min_size (XWINDOW (prev
),
3195 widthflag
, &fixed_p
));
3198 if (this_one
> delta
)
3201 first_affected
= prev
;
3203 (*setsizefun
) (prev
, (*sizefun
) (prev
) - this_one
, 0);
3204 (*setsizefun
) (window
, *sizep
+ this_one
, 0);
3209 prev
= XWINDOW (prev
)->prev
;
3213 xassert (delta
== 0);
3215 /* Now recalculate the edge positions of all the windows affected,
3216 based on the new sizes. */
3217 first_unaffected
= next
;
3218 prev
= first_affected
;
3219 for (next
= XWINDOW (prev
)->next
; ! EQ (next
, first_unaffected
);
3220 prev
= next
, next
= XWINDOW (next
)->next
)
3222 CURBEG (next
) = CURBEG (prev
) + (*sizefun
) (prev
);
3223 /* This does not change size of NEXT,
3224 but it propagates the new top edge to its children */
3225 (*setsizefun
) (next
, (*sizefun
) (next
), 0);
3230 register int delta1
;
3231 register int opht
= (*sizefun
) (parent
);
3233 /* If trying to grow this window to or beyond size of the parent,
3234 make delta1 so big that, on shrinking back down,
3235 all the siblings end up with less than one line and are deleted. */
3236 if (opht
<= *sizep
+ delta
)
3237 delta1
= opht
* opht
* 2;
3240 /* Otherwise, make delta1 just right so that if we add
3241 delta1 lines to this window and to the parent, and then
3242 shrink the parent back to its original size, the new
3243 proportional size of this window will increase by delta.
3245 The function size_window will compute the new height h'
3246 of the window from delta1 as:
3249 x = delta1 - delta1/n * n for the 1st resizable child
3252 where n is the number of children that can be resized.
3253 We can ignore x by choosing a delta1 that is a multiple of
3254 n. We want the height of this window to come out as
3264 The number of children n rquals the number of resizable
3265 children of this window + 1 because we know window itself
3266 is resizable (otherwise we would have signalled an error. */
3268 struct window
*w
= XWINDOW (window
);
3272 for (s
= w
->next
; !NILP (s
); s
= XWINDOW (s
)->next
)
3273 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3275 for (s
= w
->prev
; !NILP (s
); s
= XWINDOW (s
)->prev
)
3276 if (!window_fixed_size_p (XWINDOW (s
), widthflag
, 0))
3282 /* Add delta1 lines or columns to this window, and to the parent,
3283 keeping things consistent while not affecting siblings. */
3284 CURSIZE (parent
) = opht
+ delta1
;
3285 (*setsizefun
) (window
, *sizep
+ delta1
, 0);
3287 /* Squeeze out delta1 lines or columns from our parent,
3288 shriking this window and siblings proportionately.
3289 This brings parent back to correct size.
3290 Delta1 was calculated so this makes this window the desired size,
3291 taking it all out of the siblings. */
3292 (*setsizefun
) (parent
, opht
, 0);
3295 XSETFASTINT (p
->last_modified
, 0);
3296 XSETFASTINT (p
->last_overlay_modified
, 0);
3298 /* Adjust glyph matrices. */
3299 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window
))));
3306 /* Mark window cursors off for all windows in the window tree rooted
3307 at W by setting their phys_cursor_on_p flag to zero. Called from
3308 xterm.c, e.g. when a frame is cleared and thereby all cursors on
3309 the frame are cleared. */
3312 mark_window_cursors_off (w
)
3317 if (!NILP (w
->hchild
))
3318 mark_window_cursors_off (XWINDOW (w
->hchild
));
3319 else if (!NILP (w
->vchild
))
3320 mark_window_cursors_off (XWINDOW (w
->vchild
));
3322 w
->phys_cursor_on_p
= 0;
3324 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
3329 /* Return number of lines of text (not counting mode line) in W. */
3332 window_internal_height (w
)
3335 int ht
= XFASTINT (w
->height
);
3337 if (MINI_WINDOW_P (w
))
3340 if (!NILP (w
->parent
) || !NILP (w
->vchild
) || !NILP (w
->hchild
)
3341 || !NILP (w
->next
) || !NILP (w
->prev
)
3342 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w
))))
3349 /* Return the number of columns in W.
3350 Don't count columns occupied by scroll bars or the vertical bar
3351 separating W from the sibling to its right. */
3354 window_internal_width (w
)
3357 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
3358 int width
= XINT (w
->width
);
3360 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
3361 /* Scroll bars occupy a few columns. */
3362 width
-= FRAME_SCROLL_BAR_COLS (f
);
3363 else if (!WINDOW_RIGHTMOST_P (w
) && !WINDOW_FULL_WIDTH_P (w
))
3364 /* The column of `|' characters separating side-by-side windows
3365 occupies one column only. */
3368 /* On window-systems, areas to the left and right of the window
3369 are used to display bitmaps there. */
3370 if (FRAME_WINDOW_P (f
))
3371 width
-= FRAME_FLAGS_AREA_COLS (f
);
3377 /************************************************************************
3379 ***********************************************************************/
3381 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
3382 one screen-full, which is defined as the height of the window minus
3383 next_screen_context_lines. If WHOLE is zero, scroll up N lines
3384 instead. Negative values of N mean scroll down. NOERROR non-zero
3385 means don't signal an error if we try to move over BEGV or ZV,
3389 window_scroll (window
, n
, whole
, noerror
)
3395 /* If we must, use the pixel-based version which is much slower than
3396 the line-based one but can handle varying line heights. */
3397 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window
)->frame
)))
3398 window_scroll_pixel_based (window
, n
, whole
, noerror
);
3400 window_scroll_line_based (window
, n
, whole
, noerror
);
3404 /* Implementation of window_scroll that works based on pixel line
3405 heights. See the comment of window_scroll for parameter
3409 window_scroll_pixel_based (window
, n
, whole
, noerror
)
3416 struct window
*w
= XWINDOW (window
);
3417 struct text_pos start
;
3419 int this_scroll_margin
;
3422 SET_TEXT_POS_FROM_MARKER (start
, w
->start
);
3424 /* If PT is not visible in WINDOW, move back one half of
3426 XSETFASTINT (tem
, PT
);
3427 tem
= Fpos_visible_in_window_p (tem
, window
);
3430 /* Move backward half the height of the window. Performance note:
3431 vmotion used here is about 10% faster, but would give wrong
3432 results for variable height lines. */
3433 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3434 it
.current_y
= it
.last_visible_y
;
3435 move_it_vertically (&it
, -it
.last_visible_y
/ 2);
3437 /* The function move_iterator_vertically may move over more than
3438 the specified y-distance. If it->w is small, e.g. a
3439 mini-buffer window, we may end up in front of the window's
3440 display area. This is the case when Start displaying at the
3441 start of the line containing PT in this case. */
3442 if (it
.current_y
<= 0)
3444 init_iterator (&it
, w
, PT
, PT_BYTE
, NULL
, DEFAULT_FACE_ID
);
3445 move_it_vertically (&it
, 0);
3449 start
= it
.current
.pos
;
3452 /* If scroll_preserve_screen_position is non-zero, we try to set
3453 point in the same window line as it is now, so get that line. */
3454 if (!NILP (Vscroll_preserve_screen_position
))
3456 start_display (&it
, w
, start
);
3457 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3458 preserve_y
= it
.current_y
;
3463 /* Move iterator it from start the specified distance forward or
3464 backward. The result is the new window start. */
3465 start_display (&it
, w
, start
);
3468 int screen_full
= (it
.last_visible_y
3469 - next_screen_context_lines
* CANON_Y_UNIT (it
.f
));
3470 int direction
= n
< 0 ? -1 : 1;
3471 move_it_vertically (&it
, direction
* screen_full
);
3474 move_it_by_lines (&it
, n
, 1);
3476 /* End if we end up at ZV or BEGV. */
3477 if ((n
> 0 && IT_CHARPOS (it
) == ZV
)
3478 || (n
< 0 && IT_CHARPOS (it
) == CHARPOS (start
)))
3482 else if (IT_CHARPOS (it
) == ZV
)
3483 Fsignal (Qend_of_buffer
, Qnil
);
3485 Fsignal (Qbeginning_of_buffer
, Qnil
);
3488 /* Set the window start, and set up the window for redisplay. */
3489 set_marker_restricted (w
->start
, make_number (IT_CHARPOS (it
)), w
->buffer
);
3490 w
->start_at_line_beg
= Fbolp ();
3491 w
->update_mode_line
= Qt
;
3492 XSETFASTINT (w
->last_modified
, 0);
3493 XSETFASTINT (w
->last_overlay_modified
, 0);
3494 /* Set force_start so that redisplay_window will run the
3495 window-scroll-functions. */
3496 w
->force_start
= Qt
;
3498 it
.current_y
= it
.vpos
= 0;
3500 /* Preserve the screen position if we must. */
3501 if (preserve_y
>= 0)
3503 move_it_to (&it
, -1, -1, preserve_y
, -1, MOVE_TO_Y
);
3504 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3508 /* Move PT out of scroll margins. */
3509 this_scroll_margin
= max (0, scroll_margin
);
3510 this_scroll_margin
= min (this_scroll_margin
, XFASTINT (w
->height
) / 4);
3511 this_scroll_margin
*= CANON_Y_UNIT (it
.f
);
3515 /* We moved the window start towards ZV, so PT may be now
3516 in the scroll margin at the top. */
3517 move_it_to (&it
, PT
, -1, -1, -1, MOVE_TO_POS
);
3518 while (it
.current_y
< this_scroll_margin
)
3519 move_it_by_lines (&it
, 1, 1);
3520 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3524 /* We moved the window start towards BEGV, so PT may be now
3525 in the scroll margin at the bottom. */
3526 move_it_to (&it
, PT
, -1,
3527 it
.last_visible_y
- this_scroll_margin
- 1, -1,
3528 MOVE_TO_POS
| MOVE_TO_Y
);
3530 /* Don't put point on a partially visible line at the end. */
3531 if (it
.current_y
+ it
.max_ascent
+ it
.max_descent
3532 > it
.last_visible_y
)
3533 move_it_by_lines (&it
, -1, 0);
3535 SET_PT_BOTH (IT_CHARPOS (it
), IT_BYTEPOS (it
));
3541 /* Implementation of window_scroll that works based on screen lines.
3542 See the comment of window_scroll for parameter descriptions. */
3545 window_scroll_line_based (window
, n
, whole
, noerror
)
3551 register struct window
*w
= XWINDOW (window
);
3552 register int opoint
= PT
, opoint_byte
= PT_BYTE
;
3553 register int pos
, pos_byte
;
3554 register int ht
= window_internal_height (w
);
3555 register Lisp_Object tem
;
3559 struct position posit
;
3562 startpos
= marker_position (w
->start
);
3564 posit
= *compute_motion (startpos
, 0, 0, 0,
3566 window_internal_width (w
), XINT (w
->hscroll
),
3568 original_vpos
= posit
.vpos
;
3570 XSETFASTINT (tem
, PT
);
3571 tem
= Fpos_visible_in_window_p (tem
, window
);
3575 Fvertical_motion (make_number (- (ht
/ 2)), window
);
3580 lose
= n
< 0 && PT
== BEGV
;
3581 Fvertical_motion (make_number (n
), window
);
3585 SET_PT_BOTH (opoint
, opoint_byte
);
3592 Fsignal (Qbeginning_of_buffer
, Qnil
);
3597 int this_scroll_margin
= scroll_margin
;
3599 /* Don't use a scroll margin that is negative or too large. */
3600 if (this_scroll_margin
< 0)
3601 this_scroll_margin
= 0;
3603 if (XINT (w
->height
) < 4 * scroll_margin
)
3604 this_scroll_margin
= XINT (w
->height
) / 4;
3606 set_marker_restricted_both (w
->start
, w
->buffer
, pos
, pos_byte
);
3607 w
->start_at_line_beg
= bolp
;
3608 w
->update_mode_line
= Qt
;
3609 XSETFASTINT (w
->last_modified
, 0);
3610 XSETFASTINT (w
->last_overlay_modified
, 0);
3611 /* Set force_start so that redisplay_window will run
3612 the window-scroll-functions. */
3613 w
->force_start
= Qt
;
3615 if (whole
&& !NILP (Vscroll_preserve_screen_position
))
3617 SET_PT_BOTH (pos
, pos_byte
);
3618 Fvertical_motion (make_number (original_vpos
), window
);
3620 /* If we scrolled forward, put point enough lines down
3621 that it is outside the scroll margin. */
3626 if (this_scroll_margin
> 0)
3628 SET_PT_BOTH (pos
, pos_byte
);
3629 Fvertical_motion (make_number (this_scroll_margin
), window
);
3635 if (top_margin
<= opoint
)
3636 SET_PT_BOTH (opoint
, opoint_byte
);
3637 else if (!NILP (Vscroll_preserve_screen_position
))
3639 SET_PT_BOTH (pos
, pos_byte
);
3640 Fvertical_motion (make_number (original_vpos
), window
);
3643 SET_PT (top_margin
);
3649 /* If we scrolled backward, put point near the end of the window
3650 but not within the scroll margin. */
3651 SET_PT_BOTH (pos
, pos_byte
);
3652 tem
= Fvertical_motion (make_number (ht
- this_scroll_margin
), window
);
3653 if (XFASTINT (tem
) == ht
- this_scroll_margin
)
3656 bottom_margin
= PT
+ 1;
3658 if (bottom_margin
> opoint
)
3659 SET_PT_BOTH (opoint
, opoint_byte
);
3662 if (!NILP (Vscroll_preserve_screen_position
))
3664 SET_PT_BOTH (pos
, pos_byte
);
3665 Fvertical_motion (make_number (original_vpos
), window
);
3668 Fvertical_motion (make_number (-1), window
);
3677 Fsignal (Qend_of_buffer
, Qnil
);
3682 /* Scroll selected_window up or down. If N is nil, scroll a
3683 screen-full which is defined as the height of the window minus
3684 next_screen_context_lines. If N is the symbol `-', scroll.
3685 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
3686 up. This is the guts of Fscroll_up and Fscroll_down. */
3689 scroll_command (n
, direction
)
3693 register int defalt
;
3694 int count
= specpdl_ptr
- specpdl
;
3696 xassert (abs (direction
) == 1);
3698 /* If selected window's buffer isn't current, make it current for
3699 the moment. But don't screw up if window_scroll gets an error. */
3700 if (XBUFFER (XWINDOW (selected_window
)->buffer
) != current_buffer
)
3702 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3703 Fset_buffer (XWINDOW (selected_window
)->buffer
);
3705 /* Make redisplay consider other windows than just selected_window. */
3706 ++windows_or_buffers_changed
;
3709 defalt
= (window_internal_height (XWINDOW (selected_window
))
3710 - next_screen_context_lines
);
3711 defalt
= direction
* (defalt
< 1 ? 1 : defalt
);
3714 window_scroll (selected_window
, defalt
, 1, 0);
3715 else if (EQ (n
, Qminus
))
3716 window_scroll (selected_window
, - defalt
, 1, 0);
3719 n
= Fprefix_numeric_value (n
);
3720 window_scroll (selected_window
, XINT (n
) * direction
, 0, 0);
3723 unbind_to (count
, Qnil
);
3726 DEFUN ("scroll-up", Fscroll_up
, Sscroll_up
, 0, 1, "P",
3727 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
3728 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3729 Negative ARG means scroll downward.\n\
3730 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3731 When calling from a program, supply as argument a number, nil, or `-'.")
3735 scroll_command (arg
, 1);
3739 DEFUN ("scroll-down", Fscroll_down
, Sscroll_down
, 0, 1, "P",
3740 "Scroll text of current window down ARG lines; or near full screen if no ARG.\n\
3741 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3742 Negative ARG means scroll upward.\n\
3743 If ARG is the atom `-', scroll upward by nearly full screen.\n\
3744 When calling from a program, supply as argument a number, nil, or `-'.")
3748 scroll_command (arg
, -1);
3752 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling
, Sother_window_for_scrolling
, 0, 0, 0,
3753 "Return the other window for \"other window scroll\" commands.\n\
3754 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3755 specifies the window.\n\
3756 If `other-window-scroll-buffer' is non-nil, a window\n\
3757 showing that buffer is used.")
3762 if (MINI_WINDOW_P (XWINDOW (selected_window
))
3763 && !NILP (Vminibuf_scroll_window
))
3764 window
= Vminibuf_scroll_window
;
3765 /* If buffer is specified, scroll that buffer. */
3766 else if (!NILP (Vother_window_scroll_buffer
))
3768 window
= Fget_buffer_window (Vother_window_scroll_buffer
, Qnil
);
3770 window
= Fdisplay_buffer (Vother_window_scroll_buffer
, Qt
, Qnil
);
3774 /* Nothing specified; look for a neighboring window on the same
3776 window
= Fnext_window (selected_window
, Qnil
, Qnil
);
3778 if (EQ (window
, selected_window
))
3779 /* That didn't get us anywhere; look for a window on another
3782 window
= Fnext_window (window
, Qnil
, Qt
);
3783 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window
))))
3784 && ! EQ (window
, selected_window
));
3787 CHECK_LIVE_WINDOW (window
, 0);
3789 if (EQ (window
, selected_window
))
3790 error ("There is no other window");
3795 DEFUN ("scroll-other-window", Fscroll_other_window
, Sscroll_other_window
, 0, 1, "P",
3796 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
3797 A near full screen is `next-screen-context-lines' less than a full screen.\n\
3798 The next window is the one below the current one; or the one at the top\n\
3799 if the current one is at the bottom. Negative ARG means scroll downward.\n\
3800 If ARG is the atom `-', scroll downward by nearly full screen.\n\
3801 When calling from a program, supply as argument a number, nil, or `-'.\n\
3803 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3804 specifies the window to scroll.\n\
3805 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3806 showing that buffer, popping the buffer up if necessary.")
3808 register Lisp_Object arg
;
3810 register Lisp_Object window
;
3811 register int defalt
;
3812 register struct window
*w
;
3813 register int count
= specpdl_ptr
- specpdl
;
3815 window
= Fother_window_for_scrolling ();
3817 w
= XWINDOW (window
);
3818 defalt
= window_internal_height (w
) - next_screen_context_lines
;
3819 if (defalt
< 1) defalt
= 1;
3821 /* Don't screw up if window_scroll gets an error. */
3822 record_unwind_protect (save_excursion_restore
, save_excursion_save ());
3823 ++windows_or_buffers_changed
;
3825 Fset_buffer (w
->buffer
);
3826 SET_PT (marker_position (w
->pointm
));
3829 window_scroll (window
, defalt
, 1, 1);
3830 else if (EQ (arg
, Qminus
))
3831 window_scroll (window
, -defalt
, 1, 1);
3836 CHECK_NUMBER (arg
, 0);
3837 window_scroll (window
, XINT (arg
), 0, 1);
3840 set_marker_both (w
->pointm
, Qnil
, PT
, PT_BYTE
);
3841 unbind_to (count
, Qnil
);
3846 DEFUN ("scroll-left", Fscroll_left
, Sscroll_left
, 0, 1, "P",
3847 "Scroll selected window display ARG columns left.\n\
3848 Default for ARG is window width minus 2.")
3850 register Lisp_Object arg
;
3854 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3856 arg
= Fprefix_numeric_value (arg
);
3859 Fset_window_hscroll (selected_window
,
3860 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3864 DEFUN ("scroll-right", Fscroll_right
, Sscroll_right
, 0, 1, "P",
3865 "Scroll selected window display ARG columns right.\n\
3866 Default for ARG is window width minus 2.")
3868 register Lisp_Object arg
;
3871 XSETFASTINT (arg
, window_internal_width (XWINDOW (selected_window
)) - 2);
3873 arg
= Fprefix_numeric_value (arg
);
3876 Fset_window_hscroll (selected_window
,
3877 make_number (XINT (XWINDOW (selected_window
)->hscroll
)
3881 DEFUN ("recenter", Frecenter
, Srecenter
, 0, 1, "P",
3882 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3883 The desired position of point is always relative to the current window.\n\
3884 Just C-u as prefix means put point in the center of the window.\n\
3885 If ARG is omitted or nil, erases the entire frame and then\n\
3886 redraws with point in the center of the current window.")
3888 register Lisp_Object arg
;
3890 register struct window
*w
= XWINDOW (selected_window
);
3891 register int ht
= window_internal_height (w
);
3892 struct position pos
;
3893 struct buffer
*buf
= XBUFFER (w
->buffer
);
3894 struct buffer
*obuf
= current_buffer
;
3898 extern int frame_garbaged
;
3900 Fredraw_frame (w
->frame
);
3901 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w
)));
3902 XSETFASTINT (arg
, ht
/ 2);
3904 else if (CONSP (arg
)) /* Just C-u. */
3906 XSETFASTINT (arg
, ht
/ 2);
3910 arg
= Fprefix_numeric_value (arg
);
3911 CHECK_NUMBER (arg
, 0);
3915 XSETINT (arg
, XINT (arg
) + ht
);
3917 set_buffer_internal (buf
);
3918 pos
= *vmotion (PT
, - XINT (arg
), w
);
3920 set_marker_both (w
->start
, w
->buffer
, pos
.bufpos
, pos
.bytepos
);
3921 w
->start_at_line_beg
= ((pos
.bytepos
== BEGV_BYTE
3922 || FETCH_BYTE (pos
.bytepos
- 1) == '\n')
3924 w
->force_start
= Qt
;
3925 set_buffer_internal (obuf
);
3930 DEFUN ("move-to-window-line", Fmove_to_window_line
, Smove_to_window_line
,
3932 "Position point relative to window.\n\
3933 With no argument, position point at center of window.\n\
3934 An argument specifies vertical position within the window;\n\
3935 zero means top of window, negative means relative to bottom of window.")
3937 register Lisp_Object arg
;
3939 register struct window
*w
= XWINDOW (selected_window
);
3940 register int height
= window_internal_height (w
);
3945 XSETFASTINT (arg
, height
/ 2);
3948 arg
= Fprefix_numeric_value (arg
);
3950 XSETINT (arg
, XINT (arg
) + height
);
3953 start
= marker_position (w
->start
);
3954 XSETWINDOW (window
, w
);
3955 if (start
< BEGV
|| start
> ZV
)
3957 Fvertical_motion (make_number (- (height
/ 2)), window
);
3958 set_marker_both (w
->start
, w
->buffer
, PT
, PT_BYTE
);
3959 w
->start_at_line_beg
= Fbolp ();
3960 w
->force_start
= Qt
;
3963 Fgoto_char (w
->start
);
3965 return Fvertical_motion (arg
, window
);
3970 /***********************************************************************
3971 Window Configuration
3972 ***********************************************************************/
3974 struct save_window_data
3976 EMACS_INT size_from_Lisp_Vector_struct
;
3977 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
3978 Lisp_Object frame_width
, frame_height
, frame_menu_bar_lines
;
3979 Lisp_Object frame_toolbar_lines
;
3980 Lisp_Object selected_frame
;
3981 Lisp_Object current_window
;
3982 Lisp_Object current_buffer
;
3983 Lisp_Object minibuf_scroll_window
;
3984 Lisp_Object root_window
;
3985 Lisp_Object focus_frame
;
3986 /* Record the values of window-min-width and window-min-height
3987 so that window sizes remain consistent with them. */
3988 Lisp_Object min_width
, min_height
;
3989 /* A vector, each of whose elements is a struct saved_window
3991 Lisp_Object saved_windows
;
3994 /* This is saved as a Lisp_Vector */
3997 /* these first two must agree with struct Lisp_Vector in lisp.h */
3998 EMACS_INT size_from_Lisp_Vector_struct
;
3999 struct Lisp_Vector
*next_from_Lisp_Vector_struct
;
4002 Lisp_Object buffer
, start
, pointm
, mark
;
4003 Lisp_Object left
, top
, width
, height
, hscroll
;
4004 Lisp_Object parent
, prev
;
4005 Lisp_Object start_at_line_beg
;
4006 Lisp_Object display_table
;
4008 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
4010 #define SAVED_WINDOW_N(swv,n) \
4011 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
4013 DEFUN ("window-configuration-p", Fwindow_configuration_p
, Swindow_configuration_p
, 1, 1, 0,
4014 "Return t if OBJECT is a window-configuration object.")
4018 if (WINDOW_CONFIGURATIONP (object
))
4023 DEFUN ("window-configuration-frame", Fwindow_configuration_frame
, Swindow_configuration_frame
, 1, 1, 0,
4024 "Return the frame that CONFIG, a window-configuration object, is about.")
4028 register struct save_window_data
*data
;
4029 struct Lisp_Vector
*saved_windows
;
4031 if (! WINDOW_CONFIGURATIONP (config
))
4032 wrong_type_argument (Qwindow_configuration_p
, config
);
4034 data
= (struct save_window_data
*) XVECTOR (config
);
4035 saved_windows
= XVECTOR (data
->saved_windows
);
4036 return XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4039 DEFUN ("set-window-configuration", Fset_window_configuration
,
4040 Sset_window_configuration
, 1, 1, 0,
4041 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
4042 CONFIGURATION must be a value previously returned\n\
4043 by `current-window-configuration' (which see).\n\
4044 If CONFIGURATION was made from a frame that is now deleted,\n\
4045 only frame-independent values can be restored. In this case,\n\
4046 the return value is nil. Otherwise the value is t.")
4048 Lisp_Object configuration
;
4050 register struct save_window_data
*data
;
4051 struct Lisp_Vector
*saved_windows
;
4052 Lisp_Object new_current_buffer
;
4057 while (!WINDOW_CONFIGURATIONP (configuration
))
4058 wrong_type_argument (Qwindow_configuration_p
, configuration
);
4060 data
= (struct save_window_data
*) XVECTOR (configuration
);
4061 saved_windows
= XVECTOR (data
->saved_windows
);
4063 new_current_buffer
= data
->current_buffer
;
4064 if (NILP (XBUFFER (new_current_buffer
)->name
))
4065 new_current_buffer
= Qnil
;
4068 if (XBUFFER (new_current_buffer
) == current_buffer
)
4073 frame
= XWINDOW (SAVED_WINDOW_N (saved_windows
, 0)->window
)->frame
;
4076 /* If f is a dead frame, don't bother rebuilding its window tree.
4077 However, there is other stuff we should still try to do below. */
4078 if (FRAME_LIVE_P (f
))
4080 register struct window
*w
;
4081 register struct saved_window
*p
;
4082 struct window
*root_window
;
4083 struct window
**leaf_windows
;
4087 /* If the frame has been resized since this window configuration was
4088 made, we change the frame to the size specified in the
4089 configuration, restore the configuration, and then resize it
4090 back. We keep track of the prevailing height in these variables. */
4091 int previous_frame_height
= FRAME_HEIGHT (f
);
4092 int previous_frame_width
= FRAME_WIDTH (f
);
4093 int previous_frame_menu_bar_lines
= FRAME_MENU_BAR_LINES (f
);
4094 int previous_frame_toolbar_lines
= FRAME_TOOLBAR_LINES (f
);
4096 /* The mouse highlighting code could get screwed up
4097 if it runs during this. */
4100 if (XFASTINT (data
->frame_height
) != previous_frame_height
4101 || XFASTINT (data
->frame_width
) != previous_frame_width
)
4102 change_frame_size (f
, XFASTINT (data
->frame_height
),
4103 XFASTINT (data
->frame_width
), 0, 0, 0);
4104 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4105 if (XFASTINT (data
->frame_menu_bar_lines
)
4106 != previous_frame_menu_bar_lines
)
4107 x_set_menu_bar_lines (f
, data
->frame_menu_bar_lines
, make_number (0));
4108 #ifdef HAVE_WINDOW_SYSTEM
4109 if (XFASTINT (data
->frame_toolbar_lines
)
4110 != previous_frame_toolbar_lines
)
4111 x_set_toolbar_lines (f
, data
->frame_toolbar_lines
, make_number (0));
4115 if (! NILP (XWINDOW (selected_window
)->buffer
))
4117 w
= XWINDOW (selected_window
);
4118 set_marker_both (w
->pointm
,
4120 BUF_PT (XBUFFER (w
->buffer
)),
4121 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4124 windows_or_buffers_changed
++;
4125 FRAME_WINDOW_SIZES_CHANGED (f
) = 1;
4127 /* Problem: Freeing all matrices and later allocating them again
4128 is a serious redisplay flickering problem. What we would
4129 really like to do is to free only those matrices not reused
4131 root_window
= XWINDOW (FRAME_ROOT_WINDOW (f
));
4133 = (struct window
**) alloca (count_windows (root_window
)
4134 * sizeof (struct window
*));
4135 n_leaf_windows
= get_leaf_windows (root_window
, leaf_windows
, 0);
4137 /* Temporarily avoid any problems with windows that are smaller
4138 than they are supposed to be. */
4139 window_min_height
= 1;
4140 window_min_width
= 1;
4143 Mark all windows now on frame as "deleted".
4144 Restoring the new configuration "undeletes" any that are in it.
4146 Save their current buffers in their height fields, since we may
4147 need it later, if a buffer saved in the configuration is now
4149 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4151 for (k
= 0; k
< saved_windows
->size
; k
++)
4153 p
= SAVED_WINDOW_N (saved_windows
, k
);
4154 w
= XWINDOW (p
->window
);
4157 if (!NILP (p
->parent
))
4158 w
->parent
= SAVED_WINDOW_N (saved_windows
,
4159 XFASTINT (p
->parent
))->window
;
4163 if (!NILP (p
->prev
))
4165 w
->prev
= SAVED_WINDOW_N (saved_windows
,
4166 XFASTINT (p
->prev
))->window
;
4167 XWINDOW (w
->prev
)->next
= p
->window
;
4172 if (!NILP (w
->parent
))
4174 if (EQ (p
->width
, XWINDOW (w
->parent
)->width
))
4176 XWINDOW (w
->parent
)->vchild
= p
->window
;
4177 XWINDOW (w
->parent
)->hchild
= Qnil
;
4181 XWINDOW (w
->parent
)->hchild
= p
->window
;
4182 XWINDOW (w
->parent
)->vchild
= Qnil
;
4187 /* If we squirreled away the buffer in the window's height,
4189 if (BUFFERP (w
->height
))
4190 w
->buffer
= w
->height
;
4193 w
->width
= p
->width
;
4194 w
->height
= p
->height
;
4195 w
->hscroll
= p
->hscroll
;
4196 w
->display_table
= p
->display_table
;
4197 XSETFASTINT (w
->last_modified
, 0);
4198 XSETFASTINT (w
->last_overlay_modified
, 0);
4200 /* Reinstall the saved buffer and pointers into it. */
4201 if (NILP (p
->buffer
))
4202 w
->buffer
= p
->buffer
;
4205 if (!NILP (XBUFFER (p
->buffer
)->name
))
4206 /* If saved buffer is alive, install it. */
4208 w
->buffer
= p
->buffer
;
4209 w
->start_at_line_beg
= p
->start_at_line_beg
;
4210 set_marker_restricted (w
->start
, p
->start
, w
->buffer
);
4211 set_marker_restricted (w
->pointm
, p
->pointm
, w
->buffer
);
4212 Fset_marker (XBUFFER (w
->buffer
)->mark
,
4213 p
->mark
, w
->buffer
);
4215 /* As documented in Fcurrent_window_configuration, don't
4216 save the location of point in the buffer which was current
4217 when the window configuration was recorded. */
4218 if (!EQ (p
->buffer
, new_current_buffer
)
4219 && XBUFFER (p
->buffer
) == current_buffer
)
4220 Fgoto_char (w
->pointm
);
4222 else if (NILP (w
->buffer
) || NILP (XBUFFER (w
->buffer
)->name
))
4223 /* Else unless window has a live buffer, get one. */
4225 w
->buffer
= Fcdr (Fcar (Vbuffer_alist
));
4226 /* This will set the markers to beginning of visible
4228 set_marker_restricted (w
->start
, make_number (0), w
->buffer
);
4229 set_marker_restricted (w
->pointm
, make_number (0),w
->buffer
);
4230 w
->start_at_line_beg
= Qt
;
4233 /* Keeping window's old buffer; make sure the markers
4236 /* Set window markers at start of visible range. */
4237 if (XMARKER (w
->start
)->buffer
== 0)
4238 set_marker_restricted (w
->start
, make_number (0),
4240 if (XMARKER (w
->pointm
)->buffer
== 0)
4241 set_marker_restricted_both (w
->pointm
, w
->buffer
,
4242 BUF_PT (XBUFFER (w
->buffer
)),
4243 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4244 w
->start_at_line_beg
= Qt
;
4249 FRAME_ROOT_WINDOW (f
) = data
->root_window
;
4250 Fselect_window (data
->current_window
);
4251 XBUFFER (XWINDOW (selected_window
)->buffer
)->last_selected_window
4254 if (NILP (data
->focus_frame
)
4255 || (FRAMEP (data
->focus_frame
)
4256 && FRAME_LIVE_P (XFRAME (data
->focus_frame
))))
4257 Fredirect_frame_focus (frame
, data
->focus_frame
);
4259 #if 0 /* I don't understand why this is needed, and it causes problems
4260 when the frame's old selected window has been deleted. */
4261 if (f
!= selected_frame
&& FRAME_WINDOW_P (f
))
4262 do_switch_frame (WINDOW_FRAME (XWINDOW (data
->root_window
)),
4266 /* Set the screen height to the value it had before this function. */
4267 if (previous_frame_height
!= FRAME_HEIGHT (f
)
4268 || previous_frame_width
!= FRAME_WIDTH (f
))
4269 change_frame_size (f
, previous_frame_height
, previous_frame_width
,
4271 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
4272 if (previous_frame_menu_bar_lines
!= FRAME_MENU_BAR_LINES (f
))
4273 x_set_menu_bar_lines (f
, make_number (previous_frame_menu_bar_lines
),
4275 #ifdef HAVE_WINDOW_SYSTEM
4276 if (previous_frame_toolbar_lines
!= FRAME_TOOLBAR_LINES (f
))
4277 x_set_toolbar_lines (f
, make_number (previous_frame_toolbar_lines
),
4282 /* Now, free glyph matrices in windows that were not reused. */
4283 for (i
= 0; i
< n_leaf_windows
; ++i
)
4284 if (NILP (leaf_windows
[i
]->buffer
))
4286 /* Assert it's not reused as a combination. */
4287 xassert (NILP (leaf_windows
[i
]->hchild
)
4288 && NILP (leaf_windows
[i
]->vchild
));
4289 free_window_matrices (leaf_windows
[i
]);
4290 SET_FRAME_GARBAGED (f
);
4297 /* Fselect_window will have made f the selected frame, so we
4298 reselect the proper frame here. Fhandle_switch_frame will change the
4299 selected window too, but that doesn't make the call to
4300 Fselect_window above totally superfluous; it still sets f's
4302 if (FRAME_LIVE_P (XFRAME (data
->selected_frame
)))
4303 do_switch_frame (data
->selected_frame
, Qnil
, 0);
4305 if (! NILP (Vwindow_configuration_change_hook
)
4306 && ! NILP (Vrun_hooks
))
4307 call1 (Vrun_hooks
, Qwindow_configuration_change_hook
);
4310 if (!NILP (new_current_buffer
))
4312 Fset_buffer (new_current_buffer
);
4314 /* If the buffer that is current now is the same
4315 that was current before setting the window configuration,
4316 don't alter its PT. */
4321 /* Restore the minimum heights recorded in the configuration. */
4322 window_min_height
= XINT (data
->min_height
);
4323 window_min_width
= XINT (data
->min_width
);
4325 Vminibuf_scroll_window
= data
->minibuf_scroll_window
;
4327 return (FRAME_LIVE_P (f
) ? Qt
: Qnil
);
4330 /* Mark all windows now on frame as deleted
4331 by setting their buffers to nil. */
4334 delete_all_subwindows (w
)
4335 register struct window
*w
;
4337 if (!NILP (w
->next
))
4338 delete_all_subwindows (XWINDOW (w
->next
));
4339 if (!NILP (w
->vchild
))
4340 delete_all_subwindows (XWINDOW (w
->vchild
));
4341 if (!NILP (w
->hchild
))
4342 delete_all_subwindows (XWINDOW (w
->hchild
));
4344 w
->height
= w
->buffer
; /* See Fset_window_configuration for excuse. */
4346 if (!NILP (w
->buffer
))
4349 /* We set all three of these fields to nil, to make sure that we can
4350 distinguish this dead window from any live window. Live leaf
4351 windows will have buffer set, and combination windows will have
4352 vchild or hchild set. */
4359 count_windows (window
)
4360 register struct window
*window
;
4362 register int count
= 1;
4363 if (!NILP (window
->next
))
4364 count
+= count_windows (XWINDOW (window
->next
));
4365 if (!NILP (window
->vchild
))
4366 count
+= count_windows (XWINDOW (window
->vchild
));
4367 if (!NILP (window
->hchild
))
4368 count
+= count_windows (XWINDOW (window
->hchild
));
4373 /* Fill vector FLAT with leaf windows under W, starting at index I.
4374 Value is last index + 1. */
4377 get_leaf_windows (w
, flat
, i
)
4379 struct window
**flat
;
4384 if (!NILP (w
->hchild
))
4385 i
= get_leaf_windows (XWINDOW (w
->hchild
), flat
, i
);
4386 else if (!NILP (w
->vchild
))
4387 i
= get_leaf_windows (XWINDOW (w
->vchild
), flat
, i
);
4391 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4398 /* Return a pointer to the glyph W's physical cursor is on. Value is
4399 null if W's current matrix is invalid, so that no meaningfull glyph
4403 get_phys_cursor_glyph (w
)
4406 struct glyph_row
*row
;
4407 struct glyph
*glyph
;
4409 if (w
->phys_cursor
.vpos
>= 0
4410 && w
->phys_cursor
.vpos
< w
->current_matrix
->nrows
4411 && (row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
),
4413 && row
->used
[TEXT_AREA
] > w
->phys_cursor
.hpos
)
4414 glyph
= row
->glyphs
[TEXT_AREA
] + w
->phys_cursor
.hpos
;
4423 save_window_save (window
, vector
, i
)
4425 struct Lisp_Vector
*vector
;
4428 register struct saved_window
*p
;
4429 register struct window
*w
;
4430 register Lisp_Object tem
;
4432 for (;!NILP (window
); window
= w
->next
)
4434 p
= SAVED_WINDOW_N (vector
, i
);
4435 w
= XWINDOW (window
);
4437 XSETFASTINT (w
->temslot
, i
++);
4439 p
->buffer
= w
->buffer
;
4442 p
->width
= w
->width
;
4443 p
->height
= w
->height
;
4444 p
->hscroll
= w
->hscroll
;
4445 p
->display_table
= w
->display_table
;
4446 if (!NILP (w
->buffer
))
4448 /* Save w's value of point in the window configuration.
4449 If w is the selected window, then get the value of point
4450 from the buffer; pointm is garbage in the selected window. */
4451 if (EQ (window
, selected_window
))
4453 p
->pointm
= Fmake_marker ();
4454 set_marker_both (p
->pointm
, w
->buffer
,
4455 BUF_PT (XBUFFER (w
->buffer
)),
4456 BUF_PT_BYTE (XBUFFER (w
->buffer
)));
4459 p
->pointm
= Fcopy_marker (w
->pointm
, Qnil
);
4461 p
->start
= Fcopy_marker (w
->start
, Qnil
);
4462 p
->start_at_line_beg
= w
->start_at_line_beg
;
4464 tem
= XBUFFER (w
->buffer
)->mark
;
4465 p
->mark
= Fcopy_marker (tem
, Qnil
);
4472 p
->start_at_line_beg
= Qnil
;
4475 if (NILP (w
->parent
))
4478 p
->parent
= XWINDOW (w
->parent
)->temslot
;
4483 p
->prev
= XWINDOW (w
->prev
)->temslot
;
4485 if (!NILP (w
->vchild
))
4486 i
= save_window_save (w
->vchild
, vector
, i
);
4487 if (!NILP (w
->hchild
))
4488 i
= save_window_save (w
->hchild
, vector
, i
);
4494 DEFUN ("current-window-configuration", Fcurrent_window_configuration
,
4495 Scurrent_window_configuration
, 0, 1, 0,
4496 "Return an object representing the current window configuration of FRAME.\n\
4497 If FRAME is nil or omitted, use the selected frame.\n\
4498 This describes the number of windows, their sizes and current buffers,\n\
4499 and for each displayed buffer, where display starts, and the positions of\n\
4500 point and mark. An exception is made for point in the current buffer:\n\
4501 its value is -not- saved.\n\
4502 This also records the currently selected frame, and FRAME's focus\n\
4503 redirection (see `redirect-frame-focus').")
4507 register Lisp_Object tem
;
4508 register int n_windows
;
4509 register struct save_window_data
*data
;
4510 register struct Lisp_Vector
*vec
;
4518 CHECK_LIVE_FRAME (frame
, 0);
4522 n_windows
= count_windows (XWINDOW (FRAME_ROOT_WINDOW (f
)));
4523 vec
= allocate_vectorlike (VECSIZE (struct save_window_data
));
4524 for (i
= 0; i
< VECSIZE (struct save_window_data
); i
++)
4525 vec
->contents
[i
] = Qnil
;
4526 vec
->size
= VECSIZE (struct save_window_data
);
4527 data
= (struct save_window_data
*)vec
;
4529 XSETFASTINT (data
->frame_width
, FRAME_WIDTH (f
));
4530 XSETFASTINT (data
->frame_height
, FRAME_HEIGHT (f
));
4531 XSETFASTINT (data
->frame_menu_bar_lines
, FRAME_MENU_BAR_LINES (f
));
4532 XSETFASTINT (data
->frame_toolbar_lines
, FRAME_TOOLBAR_LINES (f
));
4533 XSETFRAME (data
->selected_frame
, selected_frame
);
4534 data
->current_window
= FRAME_SELECTED_WINDOW (f
);
4535 XSETBUFFER (data
->current_buffer
, current_buffer
);
4536 data
->minibuf_scroll_window
= Vminibuf_scroll_window
;
4537 data
->root_window
= FRAME_ROOT_WINDOW (f
);
4538 data
->focus_frame
= FRAME_FOCUS_FRAME (f
);
4539 XSETINT (data
->min_height
, window_min_height
);
4540 XSETINT (data
->min_width
, window_min_width
);
4541 tem
= Fmake_vector (make_number (n_windows
), Qnil
);
4542 data
->saved_windows
= tem
;
4543 for (i
= 0; i
< n_windows
; i
++)
4544 XVECTOR (tem
)->contents
[i
]
4545 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE
), Qnil
);
4546 save_window_save (FRAME_ROOT_WINDOW (f
),
4548 XSETWINDOW_CONFIGURATION (tem
, data
);
4552 DEFUN ("save-window-excursion", Fsave_window_excursion
, Ssave_window_excursion
,
4554 "Execute body, preserving window sizes and contents.\n\
4555 Restore which buffer appears in which window, where display starts,\n\
4556 and the value of point and mark for each window.\n\
4557 Also restore which buffer is current.\n\
4558 But do not preserve point in the current buffer.\n\
4559 Does not restore the value of point in current buffer.")
4563 register Lisp_Object val
;
4564 register int count
= specpdl_ptr
- specpdl
;
4566 record_unwind_protect (Fset_window_configuration
,
4567 Fcurrent_window_configuration (Qnil
));
4568 val
= Fprogn (args
);
4569 return unbind_to (count
, val
);
4573 /***********************************************************************
4575 ***********************************************************************/
4577 DEFUN ("set-window-margins", Fset_window_margins
, Sset_window_margins
,
4579 "Set width of marginal areas of window WINDOW.\n\
4580 If window is nil or omitted, set margins of the currently selected window.\n\
4581 First parameter LEFT-WIDTH specifies the number of character\n\
4582 cells to reserve for the left marginal area. Second parameter\n\
4583 RIGHT-WIDTH does the same for the right marginal area.\n\
4584 A nil width parameter means no margin.")
4585 (left
, right
, window
)
4586 Lisp_Object window
, left
, right
;
4588 struct window
*w
= decode_window (window
);
4589 struct frame
*f
= XFRAME (w
->frame
);
4592 CHECK_NUMBER_OR_FLOAT (left
, 0);
4594 CHECK_NUMBER_OR_FLOAT (right
, 0);
4596 /* Check widths < 0 and translate a zero width to nil.
4597 Margins that are too wide have to be checked elsewhere. */
4598 if ((INTEGERP (left
) && XINT (left
) < 0)
4599 || (FLOATP (left
) && XFLOAT (left
)->data
<= 0))
4600 XSETFASTINT (left
, 0);
4601 if (INTEGERP (left
) && XFASTINT (left
) == 0)
4604 if ((INTEGERP (right
) && XINT (right
) < 0)
4605 || (FLOATP (right
) && XFLOAT (right
)->data
<= 0))
4606 XSETFASTINT (right
, 0);
4607 if (INTEGERP (right
) && XFASTINT (right
) == 0)
4610 w
->left_margin_width
= left
;
4611 w
->right_margin_width
= right
;
4613 ++windows_or_buffers_changed
;
4614 adjust_glyphs (XFRAME (WINDOW_FRAME (w
)));
4619 DEFUN ("window-margins", Fwindow_margins
, Swindow_margins
,
4621 "Get width of marginal areas of window WINDOW.\n\
4622 If WINDOW is omitted or nil, use the currently selected window.\n\
4623 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).\n\
4624 If a marginal area does not exist, its width will be returned\n\
4629 struct window
*w
= decode_window (window
);
4630 return Fcons (w
->left_margin_width
, w
->right_margin_width
);
4635 /***********************************************************************
4637 ***********************************************************************/
4639 DEFUN ("window-vscroll", Fwindow_vscroll
, Swindow_vscroll
, 0, 1, 0,
4640 "Return the amount by which WINDOW is scrolled vertically.\n\
4641 Use the selected window if WINDOW is nil or omitted.\n\
4642 Value is a multiple of the canonical character height of WINDOW.")
4650 window
= selected_window
;
4651 w
= XWINDOW (window
);
4652 f
= XFRAME (w
->frame
);
4654 if (FRAME_WINDOW_P (f
))
4655 return CANON_Y_FROM_PIXEL_Y (f
, w
->vscroll
);
4657 return make_number (0);
4661 DEFUN ("set-window-vscroll", Fset_window_vscroll
, Sset_window_vscroll
,
4663 "Set amount by WINDOW should be scrolled vertically to VSCROLL.\n\
4664 WINDOW nil or omitted means use the selected window. VSCROLL is a\n\
4665 multiple of the canonical character height of WINDOW.")
4667 Lisp_Object vscroll
, window
;
4672 CHECK_NUMBER_OR_FLOAT (vscroll
, 0);
4675 window
= selected_window
;
4676 w
= XWINDOW (window
);
4677 f
= XFRAME (w
->frame
);
4679 if (FRAME_WINDOW_P (f
))
4681 int old_dy
= w
->vscroll
;
4682 w
->vscroll
= min (0, CANON_Y_UNIT (f
) * XFLOATINT (vscroll
));
4684 /* Adjust glyph matrix of the frame if the virtual display
4685 area becomes larger than before. */
4686 if (w
->vscroll
< 0 && w
->vscroll
< old_dy
)
4689 /* Prevent redisplay shortcuts. */
4690 XBUFFER (w
->buffer
)->prevent_redisplay_optimizations_p
= 1;
4697 /* Call FN for all leaf windows on frame F. FN is called with the
4698 first argument being a pointer to the leaf window, and with
4699 additional arguments A1..A4. */
4702 foreach_window (f
, fn
, a1
, a2
, a3
, a4
)
4707 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f
)), fn
, a1
, a2
, a3
, a4
);
4711 /* Helper function for foreach_window. Call FN for all leaf windows
4712 reachable from W. FN is called with the first argument being a
4713 pointer to the leaf window, and with additional arguments A1..A4. */
4716 foreach_window_1 (w
, fn
, a1
, a2
, a3
, a4
)
4723 if (!NILP (w
->hchild
))
4724 foreach_window_1 (XWINDOW (w
->hchild
), fn
, a1
, a2
, a3
, a4
);
4725 else if (!NILP (w
->vchild
))
4726 foreach_window_1 (XWINDOW (w
->vchild
), fn
, a1
, a2
, a3
, a4
);
4728 fn (w
, a1
, a2
, a3
, a4
);
4730 w
= NILP (w
->next
) ? 0 : XWINDOW (w
->next
);
4735 /* Freeze or unfreeze the window start of W if unless it is a
4736 mini-window or the selected window. FREEZE_P non-zero means freeze
4737 the window start. */
4740 freeze_window_start (w
, freeze_p
)
4744 if (w
== XWINDOW (selected_window
)
4745 || MINI_WINDOW_P (w
)
4746 || (MINI_WINDOW_P (XWINDOW (selected_window
))
4747 && w
== XWINDOW (Vminibuf_scroll_window
)))
4750 w
->frozen_window_start_p
= freeze_p
;
4754 /* Freeze or unfreeze the window starts of all leaf windows on frame
4755 F, except the selected window and a mini-window. FREEZE_P non-zero
4756 means freeze the window start. */
4759 freeze_window_starts (f
, freeze_p
)
4763 foreach_window (f
, freeze_window_start
, freeze_p
);
4767 /***********************************************************************
4769 ***********************************************************************/
4771 /* Return 1 if window configurations C1 and C2
4772 describe the same state of affairs. This is used by Fequal. */
4775 compare_window_configurations (c1
, c2
, ignore_positions
)
4777 int ignore_positions
;
4779 register struct save_window_data
*d1
, *d2
;
4780 struct Lisp_Vector
*sw1
, *sw2
;
4783 d1
= (struct save_window_data
*) XVECTOR (c1
);
4784 d2
= (struct save_window_data
*) XVECTOR (c2
);
4785 sw1
= XVECTOR (d1
->saved_windows
);
4786 sw2
= XVECTOR (d2
->saved_windows
);
4788 if (! EQ (d1
->frame_width
, d2
->frame_width
))
4790 if (! EQ (d1
->frame_height
, d2
->frame_height
))
4792 if (! EQ (d1
->frame_menu_bar_lines
, d2
->frame_menu_bar_lines
))
4794 if (! EQ (d1
->selected_frame
, d2
->selected_frame
))
4796 /* Don't compare the current_window field directly.
4797 Instead see w1_is_current and w2_is_current, below. */
4798 if (! EQ (d1
->current_buffer
, d2
->current_buffer
))
4800 if (! ignore_positions
)
4801 if (! EQ (d1
->minibuf_scroll_window
, d2
->minibuf_scroll_window
))
4803 /* Don't compare the root_window field.
4804 We don't require the two configurations
4805 to use the same window object,
4806 and the two root windows must be equivalent
4807 if everything else compares equal. */
4808 if (! EQ (d1
->focus_frame
, d2
->focus_frame
))
4810 if (! EQ (d1
->min_width
, d2
->min_width
))
4812 if (! EQ (d1
->min_height
, d2
->min_height
))
4815 /* Verify that the two confis have the same number of windows. */
4816 if (sw1
->size
!= sw2
->size
)
4819 for (i
= 0; i
< sw1
->size
; i
++)
4821 struct saved_window
*p1
, *p2
;
4822 int w1_is_current
, w2_is_current
;
4824 p1
= SAVED_WINDOW_N (sw1
, i
);
4825 p2
= SAVED_WINDOW_N (sw2
, i
);
4827 /* Verify that the current windows in the two
4828 configurations correspond to each other. */
4829 w1_is_current
= EQ (d1
->current_window
, p1
->window
);
4830 w2_is_current
= EQ (d2
->current_window
, p2
->window
);
4832 if (w1_is_current
!= w2_is_current
)
4835 /* Verify that the corresponding windows do match. */
4836 if (! EQ (p1
->buffer
, p2
->buffer
))
4838 if (! EQ (p1
->left
, p2
->left
))
4840 if (! EQ (p1
->top
, p2
->top
))
4842 if (! EQ (p1
->width
, p2
->width
))
4844 if (! EQ (p1
->height
, p2
->height
))
4846 if (! EQ (p1
->display_table
, p2
->display_table
))
4848 if (! EQ (p1
->parent
, p2
->parent
))
4850 if (! EQ (p1
->prev
, p2
->prev
))
4852 if (! ignore_positions
)
4854 if (! EQ (p1
->hscroll
, p2
->hscroll
))
4856 if (! EQ (p1
->start_at_line_beg
, p2
->start_at_line_beg
))
4858 if (NILP (Fequal (p1
->start
, p2
->start
)))
4860 if (NILP (Fequal (p1
->pointm
, p2
->pointm
)))
4862 if (NILP (Fequal (p1
->mark
, p2
->mark
)))
4870 DEFUN ("compare-window-configurations", Fcompare_window_configurations
,
4871 Scompare_window_configurations
, 2, 2, 0,
4872 "Compare two window configurations as regards the structure of windows.\n\
4873 This function ignores details such as the values of point and mark\n\
4874 and scrolling positions.")
4878 if (compare_window_configurations (x
, y
, 1))
4886 selected_frame
= make_terminal_frame ();
4887 XSETFRAME (Vterminal_frame
, selected_frame
);
4888 minibuf_window
= selected_frame
->minibuffer_window
;
4889 selected_window
= selected_frame
->selected_window
;
4890 last_nonminibuf_frame
= selected_frame
;
4892 window_initialized
= 1;
4898 Qleft_bitmap_area
= intern ("left-bitmap-area");
4899 staticpro (&Qleft_bitmap_area
);
4900 Qright_bitmap_area
= intern ("right-bitmap-area");
4901 staticpro (&Qright_bitmap_area
);
4903 Qwindow_size_fixed
= intern ("window-size-fixed");
4904 staticpro (&Qwindow_size_fixed
);
4906 staticpro (&Qwindow_configuration_change_hook
);
4907 Qwindow_configuration_change_hook
4908 = intern ("window-configuration-change-hook");
4910 Qwindowp
= intern ("windowp");
4911 staticpro (&Qwindowp
);
4913 Qwindow_configuration_p
= intern ("window-configuration-p");
4914 staticpro (&Qwindow_configuration_p
);
4916 Qwindow_live_p
= intern ("window-live-p");
4917 staticpro (&Qwindow_live_p
);
4919 Qtemp_buffer_show_hook
= intern ("temp-buffer-show-hook");
4920 staticpro (&Qtemp_buffer_show_hook
);
4922 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function
,
4923 "Non-nil means call as function to display a help buffer.\n\
4924 The function is called with one argument, the buffer to be displayed.\n\
4925 Used by `with-output-to-temp-buffer'.\n\
4926 If this function is used, then it must do the entire job of showing\n\
4927 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
4928 Vtemp_buffer_show_function
= Qnil
;
4930 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function
,
4931 "If non-nil, function to call to handle `display-buffer'.\n\
4932 It will receive two args, the buffer and a flag which if non-nil means\n\
4933 that the currently selected window is not acceptable.\n\
4934 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
4935 work using this function.");
4936 Vdisplay_buffer_function
= Qnil
;
4938 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window
,
4939 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
4940 Vminibuf_scroll_window
= Qnil
;
4942 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer
,
4943 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
4944 Vother_window_scroll_buffer
= Qnil
;
4946 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames
,
4947 "*Non-nil means `display-buffer' should make a separate frame.");
4950 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function
,
4951 "Function to call to handle automatic new frame creation.\n\
4952 It is called with no arguments and should return a newly created frame.\n\
4954 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
4955 where `pop-up-frame-alist' would hold the default frame parameters.");
4956 Vpop_up_frame_function
= Qnil
;
4958 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names
,
4959 "*List of buffer names that should have their own special frames.\n\
4960 Displaying a buffer whose name is in this list makes a special frame for it\n\
4961 using `special-display-function'. See also `special-display-regexps'.\n\
4963 An element of the list can be a list instead of just a string.\n\
4964 There are two ways to use a list as an element:\n\
4965 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
4966 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4967 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
4968 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
4969 All this is done by the function found in `special-display-function'.\n\
4971 If this variable appears \"not to work\", because you add a name to it\n\
4972 but that buffer still appears in the selected window, look at the\n\
4973 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4974 Those variables take precedence over this one.");
4975 Vspecial_display_buffer_names
= Qnil
;
4977 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps
,
4978 "*List of regexps saying which buffers should have their own special frames.\n\
4979 If a buffer name matches one of these regexps, it gets its own frame.\n\
4980 Displaying a buffer whose name is in this list makes a special frame for it\n\
4981 using `special-display-function'.\n\
4983 An element of the list can be a list instead of just a string.\n\
4984 There are two ways to use a list as an element:\n\
4985 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
4986 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
4987 In the latter case, FUNCTION is called with the buffer as first argument,\n\
4988 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
4989 All this is done by the function found in `special-display-function'.\n\
4991 If this variable appears \"not to work\", because you add a regexp to it\n\
4992 but the matching buffers still appear in the selected window, look at the\n\
4993 values of `same-window-buffer-names' and `same-window-regexps'.\n\
4994 Those variables take precedence over this one.");
4995 Vspecial_display_regexps
= Qnil
;
4997 DEFVAR_LISP ("special-display-function", &Vspecial_display_function
,
4998 "Function to call to make a new frame for a special buffer.\n\
4999 It is called with two arguments, the buffer and optional buffer specific\n\
5000 data, and should return a window displaying that buffer.\n\
5001 The default value makes a separate frame for the buffer,\n\
5002 using `special-display-frame-alist' to specify the frame parameters.\n\
5004 A buffer is special if its is listed in `special-display-buffer-names'\n\
5005 or matches a regexp in `special-display-regexps'.");
5006 Vspecial_display_function
= Qnil
;
5008 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names
,
5009 "*List of buffer names that should appear in the selected window.\n\
5010 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
5011 switches to it in the selected window, rather than making it appear\n\
5012 in some other window.\n\
5014 An element of the list can be a cons cell instead of just a string.\n\
5015 Then the car must be a string, which specifies the buffer name.\n\
5016 This is for compatibility with `special-display-buffer-names';\n\
5017 the cdr of the cons cell is ignored.\n\
5019 See also `same-window-regexps'.");
5020 Vsame_window_buffer_names
= Qnil
;
5022 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps
,
5023 "*List of regexps saying which buffers should appear in the selected window.\n\
5024 If a buffer name matches one of these regexps, then displaying it\n\
5025 using `display-buffer' or `pop-to-buffer' switches to it\n\
5026 in the selected window, rather than making it appear in some other window.\n\
5028 An element of the list can be a cons cell instead of just a string.\n\
5029 Then the car must be a string, which specifies the buffer name.\n\
5030 This is for compatibility with `special-display-buffer-names';\n\
5031 the cdr of the cons cell is ignored.\n\
5033 See also `same-window-buffer-names'.");
5034 Vsame_window_regexps
= Qnil
;
5036 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows
,
5037 "*Non-nil means display-buffer should make new windows.");
5040 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines
,
5041 "*Number of lines of continuity when scrolling by screenfuls.");
5042 next_screen_context_lines
= 2;
5044 DEFVAR_INT ("split-height-threshold", &split_height_threshold
,
5045 "*display-buffer would prefer to split the largest window if this large.\n\
5046 If there is only one window, it is split regardless of this value.");
5047 split_height_threshold
= 500;
5049 DEFVAR_INT ("window-min-height", &window_min_height
,
5050 "*Delete any window less than this tall (including its mode line).");
5051 window_min_height
= 4;
5053 DEFVAR_INT ("window-min-width", &window_min_width
,
5054 "*Delete any window less than this wide.");
5055 window_min_width
= 10;
5057 DEFVAR_LISP ("scroll-preserve-screen-position",
5058 &Vscroll_preserve_screen_position
,
5059 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
5060 Vscroll_preserve_screen_position
= Qnil
;
5062 DEFVAR_LISP ("window-configuration-change-hook",
5063 &Vwindow_configuration_change_hook
,
5064 "Functions to call when window configuration changes.\n\
5065 The selected frame is the one whose configuration has changed.");
5066 Vwindow_configuration_change_hook
= Qnil
;
5068 defsubr (&Sselected_window
);
5069 defsubr (&Sminibuffer_window
);
5070 defsubr (&Swindow_minibuffer_p
);
5071 defsubr (&Swindowp
);
5072 defsubr (&Swindow_live_p
);
5073 defsubr (&Spos_visible_in_window_p
);
5074 defsubr (&Swindow_buffer
);
5075 defsubr (&Swindow_height
);
5076 defsubr (&Swindow_width
);
5077 defsubr (&Swindow_hscroll
);
5078 defsubr (&Sset_window_hscroll
);
5079 defsubr (&Swindow_redisplay_end_trigger
);
5080 defsubr (&Sset_window_redisplay_end_trigger
);
5081 defsubr (&Swindow_edges
);
5082 defsubr (&Scoordinates_in_window_p
);
5083 defsubr (&Swindow_at
);
5084 defsubr (&Swindow_point
);
5085 defsubr (&Swindow_start
);
5086 defsubr (&Swindow_end
);
5087 defsubr (&Sset_window_point
);
5088 defsubr (&Sset_window_start
);
5089 defsubr (&Swindow_dedicated_p
);
5090 defsubr (&Sset_window_dedicated_p
);
5091 defsubr (&Swindow_display_table
);
5092 defsubr (&Sset_window_display_table
);
5093 defsubr (&Snext_window
);
5094 defsubr (&Sprevious_window
);
5095 defsubr (&Sother_window
);
5096 defsubr (&Sget_lru_window
);
5097 defsubr (&Sget_largest_window
);
5098 defsubr (&Sget_buffer_window
);
5099 defsubr (&Sdelete_other_windows
);
5100 defsubr (&Sdelete_windows_on
);
5101 defsubr (&Sreplace_buffer_in_windows
);
5102 defsubr (&Sdelete_window
);
5103 defsubr (&Sset_window_buffer
);
5104 defsubr (&Sselect_window
);
5105 defsubr (&Sspecial_display_p
);
5106 defsubr (&Ssame_window_p
);
5107 defsubr (&Sdisplay_buffer
);
5108 defsubr (&Ssplit_window
);
5109 defsubr (&Senlarge_window
);
5110 defsubr (&Sshrink_window
);
5111 defsubr (&Sscroll_up
);
5112 defsubr (&Sscroll_down
);
5113 defsubr (&Sscroll_left
);
5114 defsubr (&Sscroll_right
);
5115 defsubr (&Sother_window_for_scrolling
);
5116 defsubr (&Sscroll_other_window
);
5117 defsubr (&Srecenter
);
5118 defsubr (&Smove_to_window_line
);
5119 defsubr (&Swindow_configuration_p
);
5120 defsubr (&Swindow_configuration_frame
);
5121 defsubr (&Sset_window_configuration
);
5122 defsubr (&Scurrent_window_configuration
);
5123 defsubr (&Ssave_window_excursion
);
5124 defsubr (&Sset_window_margins
);
5125 defsubr (&Swindow_margins
);
5126 defsubr (&Swindow_vscroll
);
5127 defsubr (&Sset_window_vscroll
);
5128 defsubr (&Scompare_window_configurations
);
5134 initial_define_key (control_x_map
, '1', "delete-other-windows");
5135 initial_define_key (control_x_map
, '2', "split-window");
5136 initial_define_key (control_x_map
, '0', "delete-window");
5137 initial_define_key (control_x_map
, 'o', "other-window");
5138 initial_define_key (control_x_map
, '^', "enlarge-window");
5139 initial_define_key (control_x_map
, '<', "scroll-left");
5140 initial_define_key (control_x_map
, '>', "scroll-right");
5142 initial_define_key (global_map
, Ctl ('V'), "scroll-up");
5143 initial_define_key (meta_map
, Ctl ('V'), "scroll-other-window");
5144 initial_define_key (meta_map
, 'v', "scroll-down");
5146 initial_define_key (global_map
, Ctl('L'), "recenter");
5147 initial_define_key (meta_map
, 'r', "move-to-window-line");