]> code.delx.au - gnu-emacs/blob - src/window.c
*** empty log message ***
[gnu-emacs] / src / window.c
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,2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23 #include <config.h>
24 #include "lisp.h"
25 #include "buffer.h"
26 #include "keyboard.h"
27 #include "keymap.h"
28 #include "frame.h"
29 #include "window.h"
30 #include "commands.h"
31 #include "indent.h"
32 #include "termchar.h"
33 #include "disptab.h"
34 #include "dispextern.h"
35 #include "blockinput.h"
36 #include "intervals.h"
37
38 #ifdef HAVE_X_WINDOWS
39 #include "xterm.h"
40 #endif /* HAVE_X_WINDOWS */
41 #ifdef WINDOWSNT
42 #include "w32term.h"
43 #endif
44 #ifdef MSDOS
45 #include "msdos.h"
46 #endif
47 #ifdef MAC_OS
48 #include "macterm.h"
49 #endif
50
51
52 Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configuration_p;
53 Lisp_Object Qwindow_size_fixed;
54 extern Lisp_Object Qleft_margin, Qright_margin;
55
56 static int displayed_window_lines P_ ((struct window *));
57 static struct window *decode_window P_ ((Lisp_Object));
58 static int count_windows P_ ((struct window *));
59 static int get_leaf_windows P_ ((struct window *, struct window **, int));
60 static void window_scroll P_ ((Lisp_Object, int, int, int));
61 static void window_scroll_pixel_based P_ ((Lisp_Object, int, int, int));
62 static void window_scroll_line_based P_ ((Lisp_Object, int, int, int));
63 static int window_min_size_1 P_ ((struct window *, int));
64 static int window_min_size P_ ((struct window *, int, int, int *));
65 static void size_window P_ ((Lisp_Object, int, int, int));
66 static int freeze_window_start P_ ((struct window *, void *));
67 static int window_fixed_size_p P_ ((struct window *, int, int));
68 static void enlarge_window P_ ((Lisp_Object, int, int, int));
69 static Lisp_Object window_list P_ ((void));
70 static int add_window_to_list P_ ((struct window *, void *));
71 static int candidate_window_p P_ ((Lisp_Object, Lisp_Object, Lisp_Object,
72 Lisp_Object));
73 static Lisp_Object next_window P_ ((Lisp_Object, Lisp_Object,
74 Lisp_Object, int));
75 static void decode_next_window_args P_ ((Lisp_Object *, Lisp_Object *,
76 Lisp_Object *));
77 static int foreach_window_1 P_ ((struct window *,
78 int (* fn) (struct window *, void *),
79 void *));
80 static Lisp_Object window_list_1 P_ ((Lisp_Object, Lisp_Object, Lisp_Object));
81
82 /* The value of `window-size-fixed'. */
83
84 int window_size_fixed;
85
86 /* This is the window in which the terminal's cursor should
87 be left when nothing is being done with it. This must
88 always be a leaf window, and its buffer is selected by
89 the top level editing loop at the end of each command.
90
91 This value is always the same as
92 FRAME_SELECTED_WINDOW (selected_frame). */
93
94 Lisp_Object selected_window;
95
96 /* A list of all windows for use by next_window and Fwindow_list.
97 Functions creating or deleting windows should invalidate this cache
98 by setting it to nil. */
99
100 Lisp_Object Vwindow_list;
101
102 /* The mini-buffer window of the selected frame.
103 Note that you cannot test for mini-bufferness of an arbitrary window
104 by comparing against this; but you can test for mini-bufferness of
105 the selected window. */
106
107 Lisp_Object minibuf_window;
108
109 /* Non-nil means it is the window whose mode line should be
110 shown as the selected window when the minibuffer is selected. */
111
112 Lisp_Object minibuf_selected_window;
113
114 /* Non-nil means it is the window for C-M-v to scroll
115 when the mini-buffer is selected. */
116
117 Lisp_Object Vminibuf_scroll_window;
118
119 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
120
121 Lisp_Object Vother_window_scroll_buffer;
122
123 /* Non-nil means it's function to call to display temp buffers. */
124
125 Lisp_Object Vtemp_buffer_show_function;
126
127 /* Non-zero means to use mode-line-inactive face in all windows but the
128 selected-window and the minibuffer-scroll-window when the
129 minibuffer is active. */
130 int mode_line_in_non_selected_windows;
131
132 /* If a window gets smaller than either of these, it is removed. */
133
134 EMACS_INT window_min_height;
135 EMACS_INT window_min_width;
136
137 /* Nonzero implies Fdisplay_buffer should create windows. */
138
139 int pop_up_windows;
140
141 /* Nonzero implies make new frames for Fdisplay_buffer. */
142
143 int pop_up_frames;
144
145 /* Nonzero means reuse existing frames for displaying buffers. */
146
147 int display_buffer_reuse_frames;
148
149 /* Non-nil means use this function instead of default */
150
151 Lisp_Object Vpop_up_frame_function;
152
153 /* Function to call to handle Fdisplay_buffer. */
154
155 Lisp_Object Vdisplay_buffer_function;
156
157 /* Non-nil means that Fdisplay_buffer should even the heights of windows. */
158
159 Lisp_Object Veven_window_heights;
160
161 /* List of buffer *names* for buffers that should have their own frames. */
162
163 Lisp_Object Vspecial_display_buffer_names;
164
165 /* List of regexps for buffer names that should have their own frames. */
166
167 Lisp_Object Vspecial_display_regexps;
168
169 /* Function to pop up a special frame. */
170
171 Lisp_Object Vspecial_display_function;
172
173 /* List of buffer *names* for buffers to appear in selected window. */
174
175 Lisp_Object Vsame_window_buffer_names;
176
177 /* List of regexps for buffer names to appear in selected window. */
178
179 Lisp_Object Vsame_window_regexps;
180
181 /* Hook run at end of temp_output_buffer_show. */
182
183 Lisp_Object Qtemp_buffer_show_hook;
184
185 /* Fdisplay_buffer always splits the largest window
186 if that window is more than this high. */
187
188 EMACS_INT split_height_threshold;
189
190 /* Number of lines of continuity in scrolling by screenfuls. */
191
192 EMACS_INT next_screen_context_lines;
193
194 /* Incremented for each window created. */
195
196 static int sequence_number;
197
198 /* Nonzero after init_window_once has finished. */
199
200 static int window_initialized;
201
202 /* Hook to run when window config changes. */
203
204 Lisp_Object Qwindow_configuration_change_hook;
205 Lisp_Object Vwindow_configuration_change_hook;
206
207 /* Nonzero means scroll commands try to put point
208 at the same screen height as previously. */
209
210 Lisp_Object Vscroll_preserve_screen_position;
211
212 #if 0 /* This isn't used anywhere. */
213 /* Nonzero means we can split a frame even if it is "unsplittable". */
214 static int inhibit_frame_unsplittable;
215 #endif /* 0 */
216
217 extern EMACS_INT scroll_margin;
218
219 extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
220 \f
221 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
222 doc: /* Returns t if OBJECT is a window. */)
223 (object)
224 Lisp_Object object;
225 {
226 return WINDOWP (object) ? Qt : Qnil;
227 }
228
229 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
230 doc: /* Returns t if OBJECT is a window which is currently visible. */)
231 (object)
232 Lisp_Object object;
233 {
234 return WINDOW_LIVE_P (object) ? Qt : Qnil;
235 }
236
237 Lisp_Object
238 make_window ()
239 {
240 Lisp_Object val;
241 register struct window *p;
242
243 p = allocate_window ();
244 XSETFASTINT (p->sequence_number, ++sequence_number);
245 XSETFASTINT (p->left_col, 0);
246 XSETFASTINT (p->top_line, 0);
247 XSETFASTINT (p->total_lines, 0);
248 XSETFASTINT (p->total_cols, 0);
249 XSETFASTINT (p->hscroll, 0);
250 XSETFASTINT (p->min_hscroll, 0);
251 p->orig_top_line = p->orig_total_lines = Qnil;
252 p->start = Fmake_marker ();
253 p->pointm = Fmake_marker ();
254 XSETFASTINT (p->use_time, 0);
255 p->frame = Qnil;
256 p->display_table = Qnil;
257 p->dedicated = Qnil;
258 p->pseudo_window_p = 0;
259 bzero (&p->cursor, sizeof (p->cursor));
260 bzero (&p->last_cursor, sizeof (p->last_cursor));
261 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
262 p->desired_matrix = p->current_matrix = 0;
263 p->phys_cursor_type = -1;
264 p->phys_cursor_width = -1;
265 p->must_be_updated_p = 0;
266 XSETFASTINT (p->window_end_vpos, 0);
267 XSETFASTINT (p->window_end_pos, 0);
268 p->window_end_valid = Qnil;
269 p->vscroll = 0;
270 XSETWINDOW (val, p);
271 XSETFASTINT (p->last_point, 0);
272 p->frozen_window_start_p = 0;
273 p->height_fixed_p = 0;
274 p->last_cursor_off_p = p->cursor_off_p = 0;
275 p->left_margin_cols = Qnil;
276 p->right_margin_cols = Qnil;
277 p->left_fringe_width = Qnil;
278 p->right_fringe_width = Qnil;
279 p->fringes_outside_margins = Qnil;
280 p->scroll_bar_width = Qnil;
281 p->vertical_scroll_bar_type = Qt;
282
283 Vwindow_list = Qnil;
284 return val;
285 }
286
287 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
288 doc: /* Return the window that the cursor now appears in and commands apply to. */)
289 ()
290 {
291 return selected_window;
292 }
293
294 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
295 doc: /* Return the window used now for minibuffers.
296 If the optional argument FRAME is specified, return the minibuffer window
297 used by that frame. */)
298 (frame)
299 Lisp_Object frame;
300 {
301 if (NILP (frame))
302 frame = selected_frame;
303 CHECK_LIVE_FRAME (frame);
304 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
305 }
306
307 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
308 doc: /* Returns non-nil if WINDOW is a minibuffer window. */)
309 (window)
310 Lisp_Object window;
311 {
312 struct window *w = decode_window (window);
313 return MINI_WINDOW_P (w) ? Qt : Qnil;
314 }
315
316
317 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
318 Spos_visible_in_window_p, 0, 3, 0,
319 doc: /* Return t if position POS is currently on the frame in WINDOW.
320 Return nil if that position is scrolled vertically out of view.
321 If a character is only partially visible, nil is returned, unless the
322 optional argument PARTIALLY is non-nil.
323 POS defaults to point in WINDOW; WINDOW defaults to the selected window. */)
324 (pos, window, partially)
325 Lisp_Object pos, window, partially;
326 {
327 register struct window *w;
328 register int posint;
329 register struct buffer *buf;
330 struct text_pos top;
331 Lisp_Object in_window;
332 int fully_p;
333
334 w = decode_window (window);
335 buf = XBUFFER (w->buffer);
336 SET_TEXT_POS_FROM_MARKER (top, w->start);
337
338 if (!NILP (pos))
339 {
340 CHECK_NUMBER_COERCE_MARKER (pos);
341 posint = XINT (pos);
342 }
343 else if (w == XWINDOW (selected_window))
344 posint = PT;
345 else
346 posint = XMARKER (w->pointm)->charpos;
347
348 /* If position is above window start, it's not visible. */
349 if (posint < CHARPOS (top))
350 in_window = Qnil;
351 else if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf)
352 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf)
353 && posint < BUF_Z (buf) - XFASTINT (w->window_end_pos))
354 {
355 /* If frame is up-to-date, and POSINT is < window end pos, use
356 that info. This doesn't work for POSINT == end pos, because
357 the window end pos is actually the position _after_ the last
358 char in the window. */
359 if (NILP (partially))
360 {
361 pos_visible_p (w, posint, &fully_p, NILP (partially));
362 in_window = fully_p ? Qt : Qnil;
363 }
364 else
365 in_window = Qt;
366 }
367 else if (posint > BUF_ZV (buf))
368 in_window = Qnil;
369 else if (CHARPOS (top) < BUF_BEGV (buf) || CHARPOS (top) > BUF_ZV (buf))
370 /* If window start is out of range, do something reasonable. */
371 in_window = Qnil;
372 else
373 {
374 if (pos_visible_p (w, posint, &fully_p, NILP (partially)))
375 in_window = !NILP (partially) || fully_p ? Qt : Qnil;
376 else
377 in_window = Qnil;
378 }
379
380 return in_window;
381 }
382
383 \f
384 static struct window *
385 decode_window (window)
386 register Lisp_Object window;
387 {
388 if (NILP (window))
389 return XWINDOW (selected_window);
390
391 CHECK_LIVE_WINDOW (window);
392 return XWINDOW (window);
393 }
394
395 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
396 doc: /* Return the buffer that WINDOW is displaying. */)
397 (window)
398 Lisp_Object window;
399 {
400 return decode_window (window)->buffer;
401 }
402
403 DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
404 doc: /* Return the number of lines in WINDOW (including its mode line). */)
405 (window)
406 Lisp_Object window;
407 {
408 return decode_window (window)->total_lines;
409 }
410
411 DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0,
412 doc: /* Return the number of display columns in WINDOW.
413 This is the width that is usable columns available for text in WINDOW.
414 If you want to find out how many columns WINDOW takes up,
415 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))). */)
416 (window)
417 Lisp_Object window;
418 {
419 return make_number (window_box_text_cols (decode_window (window)));
420 }
421
422 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
423 doc: /* Return the number of columns by which WINDOW is scrolled from left margin. */)
424 (window)
425 Lisp_Object window;
426 {
427 return decode_window (window)->hscroll;
428 }
429
430 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
431 doc: /* Set number of columns WINDOW is scrolled from left margin to NCOL.
432 NCOL should be zero or positive.
433
434 Note that if `automatic-hscrolling' is non-nil, you cannot scroll the
435 window so that the location of point becomes invisible. */)
436 (window, ncol)
437 Lisp_Object window, ncol;
438 {
439 struct window *w = decode_window (window);
440 int hscroll;
441
442 CHECK_NUMBER (ncol);
443 hscroll = max (0, XINT (ncol));
444
445 /* Prevent redisplay shortcuts when changing the hscroll. */
446 if (XINT (w->hscroll) != hscroll)
447 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
448
449 w->hscroll = make_number (hscroll);
450 return ncol;
451 }
452
453 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
454 Swindow_redisplay_end_trigger, 0, 1, 0,
455 doc: /* Return WINDOW's redisplay end trigger value.
456 See `set-window-redisplay-end-trigger' for more information. */)
457 (window)
458 Lisp_Object window;
459 {
460 return decode_window (window)->redisplay_end_trigger;
461 }
462
463 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
464 Sset_window_redisplay_end_trigger, 2, 2, 0,
465 doc: /* Set WINDOW's redisplay end trigger value to VALUE.
466 VALUE should be a buffer position (typically a marker) or nil.
467 If it is a buffer position, then if redisplay in WINDOW reaches a position
468 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
469 with two arguments: WINDOW, and the end trigger value.
470 Afterwards the end-trigger value is reset to nil. */)
471 (window, value)
472 register Lisp_Object window, value;
473 {
474 register struct window *w;
475
476 w = decode_window (window);
477 w->redisplay_end_trigger = value;
478 return value;
479 }
480
481 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
482 doc: /* Return a list of the edge coordinates of WINDOW.
483 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
484 RIGHT is one more than the rightmost column occupied by WINDOW,
485 and BOTTOM is one more than the bottommost row occupied by WINDOW.
486 The edges include the space used by the window's scroll bar,
487 display margins, fringes, header line, and mode line, if it has them.
488 To get the edges of the actual text area, use `window-inside-edges'. */)
489 (window)
490 Lisp_Object window;
491 {
492 register struct window *w = decode_window (window);
493
494 return Fcons (make_number (WINDOW_LEFT_EDGE_COL (w)),
495 Fcons (make_number (WINDOW_TOP_EDGE_LINE (w)),
496 Fcons (make_number (WINDOW_RIGHT_EDGE_COL (w)),
497 Fcons (make_number (WINDOW_BOTTOM_EDGE_LINE (w)),
498 Qnil))));
499 }
500
501 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, Swindow_pixel_edges, 0, 1, 0,
502 doc: /* Return a list of the edge pixel coordinates of WINDOW.
503 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
504 RIGHT is one more than the rightmost x position occupied by WINDOW,
505 and BOTTOM is one more than the bottommost y position occupied by WINDOW.
506 The pixel edges include the space used by the window's scroll bar,
507 display margins, fringes, header line, and mode line, if it has them.
508 To get the edges of the actual text area, use `window-inside-pixel-edges'. */)
509 (window)
510 Lisp_Object window;
511 {
512 register struct window *w = decode_window (window);
513
514 return Fcons (make_number (WINDOW_LEFT_EDGE_X (w)),
515 Fcons (make_number (WINDOW_TOP_EDGE_Y (w)),
516 Fcons (make_number (WINDOW_RIGHT_EDGE_X (w)),
517 Fcons (make_number (WINDOW_BOTTOM_EDGE_Y (w)),
518 Qnil))));
519 }
520
521 DEFUN ("window-inside-edges", Fwindow_inside_edges, Swindow_inside_edges, 0, 1, 0,
522 doc: /* Return a list of the edge coordinates of WINDOW.
523 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
524 RIGHT is one more than the rightmost column used by text in WINDOW,
525 and BOTTOM is one more than the bottommost row used by text in WINDOW.
526 The inside edges do not include the space used by the window's scroll bar,
527 display margins, fringes, header line, and/or mode line. */)
528 (window)
529 Lisp_Object window;
530 {
531 register struct window *w = decode_window (window);
532
533 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_COL (w)
534 + WINDOW_LEFT_MARGIN_COLS (w)
535 + WINDOW_LEFT_FRINGE_COLS (w)),
536 make_number (WINDOW_TOP_EDGE_LINE (w)
537 + WINDOW_HEADER_LINE_LINES (w)),
538 make_number (WINDOW_RIGHT_EDGE_COL (w)
539 - WINDOW_RIGHT_MARGIN_COLS (w)
540 - WINDOW_RIGHT_FRINGE_COLS (w)),
541 make_number (WINDOW_BOTTOM_EDGE_LINE (w)
542 - WINDOW_MODE_LINE_LINES (w)));
543 }
544
545 DEFUN ("window-inside-pixel-edges", Fwindow_inside_pixel_edges, Swindow_inside_pixel_edges, 0, 1, 0,
546 doc: /* Return a list of the edge coordinates of WINDOW.
547 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
548 RIGHT is one more than the rightmost x position used by text in WINDOW,
549 and BOTTOM is one more than the bottommost y position used by text in WINDOW.
550 The inside edges do not include the space used by the window's scroll bar,
551 display margins, fringes, header line, and/or mode line. */)
552 (window)
553 Lisp_Object window;
554 {
555 register struct window *w = decode_window (window);
556
557 return list4 (make_number (WINDOW_BOX_LEFT_EDGE_X (w)
558 + WINDOW_LEFT_MARGIN_WIDTH (w)
559 + WINDOW_LEFT_FRINGE_WIDTH (w)),
560 make_number (WINDOW_TOP_EDGE_Y (w)
561 + WINDOW_HEADER_LINE_HEIGHT (w)),
562 make_number (WINDOW_RIGHT_EDGE_X (w)
563 - WINDOW_RIGHT_MARGIN_WIDTH (w)
564 - WINDOW_RIGHT_FRINGE_WIDTH (w)),
565 make_number (WINDOW_BOTTOM_EDGE_Y (w)
566 - WINDOW_MODE_LINE_HEIGHT (w)));
567 }
568
569 /* Test if the character at column *X, row *Y is within window W.
570 If it is not, return ON_NOTHING;
571 if it is in the window's text area,
572 set *x and *y to its location relative to the upper left corner
573 of the window, and
574 return ON_TEXT;
575 if it is on the window's modeline, return ON_MODE_LINE;
576 if it is on the border between the window and its right sibling,
577 return ON_VERTICAL_BORDER.
578 if it is on the window's top line, return ON_HEADER_LINE;
579 if it is in left or right fringe of the window,
580 return ON_LEFT_FRINGE or ON_RIGHT_FRINGE, and convert *X and *Y
581 to window-relative coordinates;
582 if it is in the marginal area to the left/right of the window,
583 return ON_LEFT_MARGIN or ON_RIGHT_MARGIN, and convert *X and *Y
584 to window-relative coordinates.
585
586 X and Y are frame relative pixel coordinates. */
587
588 static enum window_part
589 coordinates_in_window (w, x, y)
590 register struct window *w;
591 register int *x, *y;
592 {
593 struct frame *f = XFRAME (WINDOW_FRAME (w));
594 int left_x, right_x, top_y, bottom_y;
595 enum window_part part;
596 int ux = FRAME_COLUMN_WIDTH (f);
597 int x0 = WINDOW_LEFT_EDGE_X (w);
598 int x1 = WINDOW_RIGHT_EDGE_X (w);
599 /* The width of the area where the vertical line can be dragged.
600 (Between mode lines for instance. */
601 int grabbable_width = ux;
602 int lmargin_width, rmargin_width, text_left, text_right;
603
604 if (*x < x0 || *x >= x1)
605 return ON_NOTHING;
606
607 /* In what's below, we subtract 1 when computing right_x because we
608 want the rightmost pixel, which is given by left_pixel+width-1. */
609 if (w->pseudo_window_p)
610 {
611 left_x = 0;
612 right_x = WINDOW_TOTAL_WIDTH (w) - 1;
613 top_y = WINDOW_TOP_EDGE_Y (w);
614 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
615 }
616 else
617 {
618 left_x = WINDOW_BOX_LEFT_EDGE_X (w);
619 right_x = WINDOW_BOX_RIGHT_EDGE_X (w) - 1;
620 top_y = WINDOW_TOP_EDGE_Y (w);
621 bottom_y = WINDOW_BOTTOM_EDGE_Y (w);
622 }
623
624 /* Outside any interesting row? */
625 if (*y < top_y || *y >= bottom_y)
626 return ON_NOTHING;
627
628 /* On the mode line or header line? If it's near the start of
629 the mode or header line of window that's has a horizontal
630 sibling, say it's on the vertical line. That's to be able
631 to resize windows horizontally in case we're using toolkit
632 scroll bars. */
633
634 if (WINDOW_WANTS_MODELINE_P (w)
635 && *y >= bottom_y - CURRENT_MODE_LINE_HEIGHT (w)
636 && *y < bottom_y)
637 {
638 part = ON_MODE_LINE;
639
640 header_vertical_border_check:
641 /* We're somewhere on the mode line. We consider the place
642 between mode lines of horizontally adjacent mode lines
643 as the vertical border. If scroll bars on the left,
644 return the right window. */
645 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)
646 || WINDOW_RIGHTMOST_P (w))
647 {
648 if (!WINDOW_LEFTMOST_P (w) && abs (*x - x0) < grabbable_width)
649 return ON_VERTICAL_BORDER;
650 }
651 else
652 {
653 if (abs (*x - x1) < grabbable_width)
654 return ON_VERTICAL_BORDER;
655 }
656
657 return part;
658 }
659
660 if (WINDOW_WANTS_HEADER_LINE_P (w)
661 && *y >= top_y
662 && *y < top_y + CURRENT_HEADER_LINE_HEIGHT (w))
663 {
664 part = ON_HEADER_LINE;
665 goto header_vertical_border_check;
666 }
667
668 /* Outside any interesting column? */
669 if (*x < left_x || *x > right_x)
670 return ON_NOTHING;
671
672 lmargin_width = window_box_width (w, LEFT_MARGIN_AREA);
673 rmargin_width = window_box_width (w, RIGHT_MARGIN_AREA);
674
675 text_left = window_box_left (w, TEXT_AREA);
676 text_right = text_left + window_box_width (w, TEXT_AREA);
677
678 if (FRAME_WINDOW_P (f))
679 {
680 if (!w->pseudo_window_p
681 && !WINDOW_HAS_VERTICAL_SCROLL_BAR (w)
682 && !WINDOW_RIGHTMOST_P (w)
683 && (abs (*x - right_x) < grabbable_width))
684 return ON_VERTICAL_BORDER;
685 }
686 else
687 {
688 /* Need to say "*x > right_x" rather than >=, since on character
689 terminals, the vertical line's x coordinate is right_x. */
690 if (!w->pseudo_window_p
691 && !WINDOW_RIGHTMOST_P (w)
692 && *x > right_x - ux)
693 {
694 /* On the border on the right side of the window? Assume that
695 this area begins at RIGHT_X minus a canonical char width. */
696 return ON_VERTICAL_BORDER;
697 }
698 }
699
700 if (*x < text_left)
701 {
702 if (lmargin_width > 0
703 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
704 ? (*x >= left_x + WINDOW_LEFT_FRINGE_WIDTH (w))
705 : (*x < left_x + lmargin_width)))
706 return ON_LEFT_MARGIN;
707
708 /* Convert X and Y to window-relative pixel coordinates. */
709 *x -= left_x;
710 *y -= top_y;
711 return ON_LEFT_FRINGE;
712 }
713
714 if (*x >= text_right)
715 {
716 if (rmargin_width > 0
717 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
718 ? (*x < right_x - WINDOW_RIGHT_FRINGE_WIDTH (w))
719 : (*x >= right_x - rmargin_width)))
720 return ON_RIGHT_MARGIN;
721
722 /* Convert X and Y to window-relative pixel coordinates. */
723 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
724 *y -= top_y;
725 return ON_RIGHT_FRINGE;
726 }
727
728 /* Everything special ruled out - must be on text area */
729 *x -= left_x + WINDOW_LEFT_FRINGE_WIDTH (w);
730 *y -= top_y;
731 return ON_TEXT;
732 }
733
734
735 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
736 Scoordinates_in_window_p, 2, 2, 0,
737 doc: /* Return non-nil if COORDINATES are in WINDOW.
738 COORDINATES is a cons of the form (X . Y), X and Y being distances
739 measured in characters from the upper-left corner of the frame.
740 \(0 . 0) denotes the character in the upper left corner of the
741 frame.
742 If COORDINATES are in the text portion of WINDOW,
743 the coordinates relative to the window are returned.
744 If they are in the mode line of WINDOW, `mode-line' is returned.
745 If they are in the top mode line of WINDOW, `header-line' is returned.
746 If they are in the left fringe of WINDOW, `left-fringe' is returned.
747 If they are in the right fringe of WINDOW, `right-fringe' is returned.
748 If they are on the border between WINDOW and its right sibling,
749 `vertical-line' is returned.
750 If they are in the windows's left or right marginal areas, `left-margin'\n\
751 or `right-margin' is returned. */)
752 (coordinates, window)
753 register Lisp_Object coordinates, window;
754 {
755 struct window *w;
756 struct frame *f;
757 int x, y;
758 Lisp_Object lx, ly;
759
760 CHECK_LIVE_WINDOW (window);
761 w = XWINDOW (window);
762 f = XFRAME (w->frame);
763 CHECK_CONS (coordinates);
764 lx = Fcar (coordinates);
765 ly = Fcdr (coordinates);
766 CHECK_NUMBER_OR_FLOAT (lx);
767 CHECK_NUMBER_OR_FLOAT (ly);
768 x = FRAME_PIXEL_X_FROM_CANON_X (f, lx);
769 y = FRAME_PIXEL_Y_FROM_CANON_Y (f, ly);
770
771 switch (coordinates_in_window (w, &x, &y))
772 {
773 case ON_NOTHING:
774 return Qnil;
775
776 case ON_TEXT:
777 /* X and Y are now window relative pixel coordinates. Convert
778 them to canonical char units before returning them. */
779 return Fcons (FRAME_CANON_X_FROM_PIXEL_X (f, x),
780 FRAME_CANON_Y_FROM_PIXEL_Y (f, y));
781
782 case ON_MODE_LINE:
783 return Qmode_line;
784
785 case ON_VERTICAL_BORDER:
786 return Qvertical_line;
787
788 case ON_HEADER_LINE:
789 return Qheader_line;
790
791 case ON_LEFT_FRINGE:
792 return Qleft_fringe;
793
794 case ON_RIGHT_FRINGE:
795 return Qright_fringe;
796
797 case ON_LEFT_MARGIN:
798 return Qleft_margin;
799
800 case ON_RIGHT_MARGIN:
801 return Qright_margin;
802
803 default:
804 abort ();
805 }
806 }
807
808
809 /* Callback for foreach_window, used in window_from_coordinates.
810 Check if window W contains coordinates specified by USER_DATA which
811 is actually a pointer to a struct check_window_data CW.
812
813 Check if window W contains coordinates *CW->x and *CW->y. If it
814 does, return W in *CW->window, as Lisp_Object, and return in
815 *CW->part the part of the window under coordinates *X,*Y. Return
816 zero from this function to stop iterating over windows. */
817
818 struct check_window_data
819 {
820 Lisp_Object *window;
821 int *x, *y;
822 enum window_part *part;
823 };
824
825 static int
826 check_window_containing (w, user_data)
827 struct window *w;
828 void *user_data;
829 {
830 struct check_window_data *cw = (struct check_window_data *) user_data;
831 enum window_part found;
832 int continue_p = 1;
833
834 found = coordinates_in_window (w, cw->x, cw->y);
835 if (found != ON_NOTHING)
836 {
837 *cw->part = found;
838 XSETWINDOW (*cw->window, w);
839 continue_p = 0;
840 }
841
842 return continue_p;
843 }
844
845
846 /* Find the window containing frame-relative pixel position X/Y and
847 return it as a Lisp_Object.
848
849 If X, Y is on one of the window's special `window_part' elements,
850 set *PART to the id of that element, and return X and Y converted
851 to window relative coordinates in WX and WY.
852
853 If there is no window under X, Y return nil and leave *PART
854 unmodified. TOOL_BAR_P non-zero means detect tool-bar windows.
855
856 This function was previously implemented with a loop cycling over
857 windows with Fnext_window, and starting with the frame's selected
858 window. It turned out that this doesn't work with an
859 implementation of next_window using Vwindow_list, because
860 FRAME_SELECTED_WINDOW (F) is not always contained in the window
861 tree of F when this function is called asynchronously from
862 note_mouse_highlight. The original loop didn't terminate in this
863 case. */
864
865 Lisp_Object
866 window_from_coordinates (f, x, y, part, wx, wy, tool_bar_p)
867 struct frame *f;
868 int x, y;
869 enum window_part *part;
870 int *wx, *wy;
871 int tool_bar_p;
872 {
873 Lisp_Object window;
874 struct check_window_data cw;
875 enum window_part dummy;
876
877 if (part == 0)
878 part = &dummy;
879
880 window = Qnil;
881 cw.window = &window, cw.x = &x, cw.y = &y; cw.part = part;
882 foreach_window (f, check_window_containing, &cw);
883
884 /* If not found above, see if it's in the tool bar window, if a tool
885 bar exists. */
886 if (NILP (window)
887 && tool_bar_p
888 && WINDOWP (f->tool_bar_window)
889 && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window)) > 0
890 && (coordinates_in_window (XWINDOW (f->tool_bar_window), &x, &y)
891 != ON_NOTHING))
892 {
893 *part = ON_TEXT;
894 window = f->tool_bar_window;
895 }
896
897 if (wx) *wx = x;
898 if (wy) *wy = y;
899
900 return window;
901 }
902
903 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
904 doc: /* Return window containing coordinates X and Y on FRAME.
905 If omitted, FRAME defaults to the currently selected frame.
906 The top left corner of the frame is considered to be row 0,
907 column 0. */)
908 (x, y, frame)
909 Lisp_Object x, y, frame;
910 {
911 struct frame *f;
912
913 if (NILP (frame))
914 frame = selected_frame;
915 CHECK_LIVE_FRAME (frame);
916 f = XFRAME (frame);
917
918 /* Check that arguments are integers or floats. */
919 CHECK_NUMBER_OR_FLOAT (x);
920 CHECK_NUMBER_OR_FLOAT (y);
921
922 return window_from_coordinates (f,
923 FRAME_PIXEL_X_FROM_CANON_X (f, x),
924 FRAME_PIXEL_Y_FROM_CANON_Y (f, y),
925 0, 0, 0, 0);
926 }
927
928 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
929 doc: /* Return current value of point in WINDOW.
930 For a nonselected window, this is the value point would have
931 if that window were selected.
932
933 Note that, when WINDOW is the selected window and its buffer
934 is also currently selected, the value returned is the same as (point).
935 It would be more strictly correct to return the `top-level' value
936 of point, outside of any save-excursion forms.
937 But that is hard to define. */)
938 (window)
939 Lisp_Object window;
940 {
941 register struct window *w = decode_window (window);
942
943 if (w == XWINDOW (selected_window)
944 && current_buffer == XBUFFER (w->buffer))
945 return Fpoint ();
946 return Fmarker_position (w->pointm);
947 }
948
949 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
950 doc: /* Return position at which display currently starts in WINDOW.
951 This is updated by redisplay or by calling `set-window-start'. */)
952 (window)
953 Lisp_Object window;
954 {
955 return Fmarker_position (decode_window (window)->start);
956 }
957
958 /* This is text temporarily removed from the doc string below.
959
960 This function returns nil if the position is not currently known.
961 That happens when redisplay is preempted and doesn't finish.
962 If in that case you want to compute where the end of the window would
963 have been if redisplay had finished, do this:
964 (save-excursion
965 (goto-char (window-start window))
966 (vertical-motion (1- (window-height window)) window)
967 (point))") */
968
969 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 2, 0,
970 doc: /* Return position at which display currently ends in WINDOW.
971 This is updated by redisplay, when it runs to completion.
972 Simply changing the buffer text or setting `window-start'
973 does not update this value.
974 If UPDATE is non-nil, compute the up-to-date position
975 if it isn't already recorded. */)
976 (window, update)
977 Lisp_Object window, update;
978 {
979 Lisp_Object value;
980 struct window *w = decode_window (window);
981 Lisp_Object buf;
982
983 buf = w->buffer;
984 CHECK_BUFFER (buf);
985
986 #if 0 /* This change broke some things. We should make it later. */
987 /* If we don't know the end position, return nil.
988 The user can compute it with vertical-motion if he wants to.
989 It would be nicer to do it automatically,
990 but that's so slow that it would probably bother people. */
991 if (NILP (w->window_end_valid))
992 return Qnil;
993 #endif
994
995 if (! NILP (update)
996 && ! (! NILP (w->window_end_valid)
997 && XFASTINT (w->last_modified) >= MODIFF))
998 {
999 struct text_pos startp;
1000 struct it it;
1001 struct buffer *old_buffer = NULL, *b = XBUFFER (buf);
1002
1003 /* In case W->start is out of the range, use something
1004 reasonable. This situation occurred when loading a file with
1005 `-l' containing a call to `rmail' with subsequent other
1006 commands. At the end, W->start happened to be BEG, while
1007 rmail had already narrowed the buffer. */
1008 if (XMARKER (w->start)->charpos < BEGV)
1009 SET_TEXT_POS (startp, BEGV, BEGV_BYTE);
1010 else if (XMARKER (w->start)->charpos > ZV)
1011 SET_TEXT_POS (startp, ZV, ZV_BYTE);
1012 else
1013 SET_TEXT_POS_FROM_MARKER (startp, w->start);
1014
1015 /* Cannot use Fvertical_motion because that function doesn't
1016 cope with variable-height lines. */
1017 if (b != current_buffer)
1018 {
1019 old_buffer = current_buffer;
1020 set_buffer_internal (b);
1021 }
1022
1023 start_display (&it, w, startp);
1024 move_it_vertically (&it, window_box_height (w));
1025 if (it.current_y < it.last_visible_y)
1026 move_it_past_eol (&it);
1027 value = make_number (IT_CHARPOS (it));
1028
1029 if (old_buffer)
1030 set_buffer_internal (old_buffer);
1031 }
1032 else
1033 XSETINT (value, BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos));
1034
1035 return value;
1036 }
1037
1038 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
1039 doc: /* Make point value in WINDOW be at position POS in WINDOW's buffer. */)
1040 (window, pos)
1041 Lisp_Object window, pos;
1042 {
1043 register struct window *w = decode_window (window);
1044
1045 CHECK_NUMBER_COERCE_MARKER (pos);
1046 if (w == XWINDOW (selected_window)
1047 && XBUFFER (w->buffer) == current_buffer)
1048 Fgoto_char (pos);
1049 else
1050 set_marker_restricted (w->pointm, pos, w->buffer);
1051
1052 /* We have to make sure that redisplay updates the window to show
1053 the new value of point. */
1054 if (!EQ (window, selected_window))
1055 ++windows_or_buffers_changed;
1056
1057 return pos;
1058 }
1059
1060 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
1061 doc: /* Make display in WINDOW start at position POS in WINDOW's buffer.
1062 Optional third arg NOFORCE non-nil inhibits next redisplay
1063 from overriding motion of point in order to display at this exact start. */)
1064 (window, pos, noforce)
1065 Lisp_Object window, pos, noforce;
1066 {
1067 register struct window *w = decode_window (window);
1068
1069 CHECK_NUMBER_COERCE_MARKER (pos);
1070 set_marker_restricted (w->start, pos, w->buffer);
1071 /* this is not right, but much easier than doing what is right. */
1072 w->start_at_line_beg = Qnil;
1073 if (NILP (noforce))
1074 w->force_start = Qt;
1075 w->update_mode_line = Qt;
1076 XSETFASTINT (w->last_modified, 0);
1077 XSETFASTINT (w->last_overlay_modified, 0);
1078 if (!EQ (window, selected_window))
1079 windows_or_buffers_changed++;
1080
1081 return pos;
1082 }
1083
1084 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
1085 1, 1, 0,
1086 doc: /* Return WINDOW's dedicated object, usually t or nil.
1087 See also `set-window-dedicated-p'. */)
1088 (window)
1089 Lisp_Object window;
1090 {
1091 return decode_window (window)->dedicated;
1092 }
1093
1094 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
1095 Sset_window_dedicated_p, 2, 2, 0,
1096 doc: /* Control whether WINDOW is dedicated to the buffer it displays.
1097 If it is dedicated, Emacs will not automatically change
1098 which buffer appears in it.
1099 The second argument is the new value for the dedication flag;
1100 non-nil means yes. */)
1101 (window, arg)
1102 Lisp_Object window, arg;
1103 {
1104 register struct window *w = decode_window (window);
1105
1106 if (NILP (arg))
1107 w->dedicated = Qnil;
1108 else
1109 w->dedicated = Qt;
1110
1111 return w->dedicated;
1112 }
1113
1114 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
1115 0, 1, 0,
1116 doc: /* Return the display-table that WINDOW is using. */)
1117 (window)
1118 Lisp_Object window;
1119 {
1120 return decode_window (window)->display_table;
1121 }
1122
1123 /* Get the display table for use on window W. This is either W's
1124 display table or W's buffer's display table. Ignore the specified
1125 tables if they are not valid; if no valid table is specified,
1126 return 0. */
1127
1128 struct Lisp_Char_Table *
1129 window_display_table (w)
1130 struct window *w;
1131 {
1132 struct Lisp_Char_Table *dp = NULL;
1133
1134 if (DISP_TABLE_P (w->display_table))
1135 dp = XCHAR_TABLE (w->display_table);
1136 else if (BUFFERP (w->buffer))
1137 {
1138 struct buffer *b = XBUFFER (w->buffer);
1139
1140 if (DISP_TABLE_P (b->display_table))
1141 dp = XCHAR_TABLE (b->display_table);
1142 else if (DISP_TABLE_P (Vstandard_display_table))
1143 dp = XCHAR_TABLE (Vstandard_display_table);
1144 }
1145
1146 return dp;
1147 }
1148
1149 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
1150 doc: /* Set WINDOW's display-table to TABLE. */)
1151 (window, table)
1152 register Lisp_Object window, table;
1153 {
1154 register struct window *w;
1155
1156 w = decode_window (window);
1157 w->display_table = table;
1158 return table;
1159 }
1160 \f
1161 /* Record info on buffer window w is displaying
1162 when it is about to cease to display that buffer. */
1163 static void
1164 unshow_buffer (w)
1165 register struct window *w;
1166 {
1167 Lisp_Object buf;
1168 struct buffer *b;
1169
1170 buf = w->buffer;
1171 b = XBUFFER (buf);
1172 if (b != XMARKER (w->pointm)->buffer)
1173 abort ();
1174
1175 #if 0
1176 if (w == XWINDOW (selected_window)
1177 || ! EQ (buf, XWINDOW (selected_window)->buffer))
1178 /* Do this except when the selected window's buffer
1179 is being removed from some other window. */
1180 #endif
1181 /* last_window_start records the start position that this buffer
1182 had in the last window to be disconnected from it.
1183 Now that this statement is unconditional,
1184 it is possible for the buffer to be displayed in the
1185 selected window, while last_window_start reflects another
1186 window which was recently showing the same buffer.
1187 Some people might say that might be a good thing. Let's see. */
1188 b->last_window_start = marker_position (w->start);
1189
1190 /* Point in the selected window's buffer
1191 is actually stored in that buffer, and the window's pointm isn't used.
1192 So don't clobber point in that buffer. */
1193 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1194 /* This line helps to fix Horsley's testbug.el bug. */
1195 && !(WINDOWP (b->last_selected_window)
1196 && w != XWINDOW (b->last_selected_window)
1197 && EQ (buf, XWINDOW (b->last_selected_window)->buffer)))
1198 temp_set_point_both (b,
1199 clip_to_bounds (BUF_BEGV (b),
1200 XMARKER (w->pointm)->charpos,
1201 BUF_ZV (b)),
1202 clip_to_bounds (BUF_BEGV_BYTE (b),
1203 marker_byte_position (w->pointm),
1204 BUF_ZV_BYTE (b)));
1205
1206 if (WINDOWP (b->last_selected_window)
1207 && w == XWINDOW (b->last_selected_window))
1208 b->last_selected_window = Qnil;
1209 }
1210
1211 /* Put replacement into the window structure in place of old. */
1212 static void
1213 replace_window (old, replacement)
1214 Lisp_Object old, replacement;
1215 {
1216 register Lisp_Object tem;
1217 register struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
1218
1219 /* If OLD is its frame's root_window, then replacement is the new
1220 root_window for that frame. */
1221
1222 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
1223 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
1224
1225 p->left_col = o->left_col;
1226 p->top_line = o->top_line;
1227 p->total_cols = o->total_cols;
1228 p->total_lines = o->total_lines;
1229 p->desired_matrix = p->current_matrix = 0;
1230 p->vscroll = 0;
1231 bzero (&p->cursor, sizeof (p->cursor));
1232 bzero (&p->last_cursor, sizeof (p->last_cursor));
1233 bzero (&p->phys_cursor, sizeof (p->phys_cursor));
1234 p->phys_cursor_type = -1;
1235 p->phys_cursor_width = -1;
1236 p->must_be_updated_p = 0;
1237 p->pseudo_window_p = 0;
1238 XSETFASTINT (p->window_end_vpos, 0);
1239 XSETFASTINT (p->window_end_pos, 0);
1240 p->window_end_valid = Qnil;
1241 p->frozen_window_start_p = 0;
1242 p->orig_top_line = p->orig_total_lines = Qnil;
1243
1244 p->next = tem = o->next;
1245 if (!NILP (tem))
1246 XWINDOW (tem)->prev = replacement;
1247
1248 p->prev = tem = o->prev;
1249 if (!NILP (tem))
1250 XWINDOW (tem)->next = replacement;
1251
1252 p->parent = tem = o->parent;
1253 if (!NILP (tem))
1254 {
1255 if (EQ (XWINDOW (tem)->vchild, old))
1256 XWINDOW (tem)->vchild = replacement;
1257 if (EQ (XWINDOW (tem)->hchild, old))
1258 XWINDOW (tem)->hchild = replacement;
1259 }
1260
1261 /*** Here, if replacement is a vertical combination
1262 and so is its new parent, we should make replacement's
1263 children be children of that parent instead. ***/
1264 }
1265
1266 DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
1267 doc: /* Remove WINDOW from the display. Default is selected window. */)
1268 (window)
1269 register Lisp_Object window;
1270 {
1271 delete_window (window);
1272
1273 if (! NILP (Vwindow_configuration_change_hook)
1274 && ! NILP (Vrun_hooks))
1275 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
1276
1277 return Qnil;
1278 }
1279
1280 void
1281 delete_window (window)
1282 register Lisp_Object window;
1283 {
1284 register Lisp_Object tem, parent, sib;
1285 register struct window *p;
1286 register struct window *par;
1287 struct frame *f;
1288
1289 /* Because this function is called by other C code on non-leaf
1290 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
1291 so we can't decode_window here. */
1292 if (NILP (window))
1293 window = selected_window;
1294 else
1295 CHECK_WINDOW (window);
1296 p = XWINDOW (window);
1297
1298 /* It's okay to delete an already-deleted window. */
1299 if (NILP (p->buffer)
1300 && NILP (p->hchild)
1301 && NILP (p->vchild))
1302 return;
1303
1304 parent = p->parent;
1305 if (NILP (parent))
1306 error ("Attempt to delete minibuffer or sole ordinary window");
1307 par = XWINDOW (parent);
1308
1309 windows_or_buffers_changed++;
1310 Vwindow_list = Qnil;
1311 f = XFRAME (WINDOW_FRAME (p));
1312 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
1313
1314 /* Are we trying to delete any frame's selected window? */
1315 {
1316 Lisp_Object swindow, pwindow;
1317
1318 /* See if the frame's selected window is either WINDOW
1319 or any subwindow of it, by finding all that window's parents
1320 and comparing each one with WINDOW. */
1321 swindow = FRAME_SELECTED_WINDOW (f);
1322
1323 while (1)
1324 {
1325 pwindow = swindow;
1326 while (!NILP (pwindow))
1327 {
1328 if (EQ (window, pwindow))
1329 break;
1330 pwindow = XWINDOW (pwindow)->parent;
1331 }
1332
1333 /* If the window being deleted is not a parent of SWINDOW,
1334 then SWINDOW is ok as the new selected window. */
1335 if (!EQ (window, pwindow))
1336 break;
1337 /* Otherwise, try another window for SWINDOW. */
1338 swindow = Fnext_window (swindow, Qlambda, Qnil);;
1339
1340 /* If we get back to the frame's selected window,
1341 it means there was no acceptable alternative,
1342 so we cannot delete. */
1343 if (EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1344 error ("Cannot delete window");
1345 }
1346
1347 /* If we need to change SWINDOW, do it. */
1348 if (! EQ (swindow, FRAME_SELECTED_WINDOW (f)))
1349 {
1350 /* If we're about to delete the selected window on the
1351 selected frame, then we should use Fselect_window to select
1352 the new window. On the other hand, if we're about to
1353 delete the selected window on any other frame, we shouldn't do
1354 anything but set the frame's selected_window slot. */
1355 if (EQ (FRAME_SELECTED_WINDOW (f), selected_window))
1356 Fselect_window (swindow, Qnil);
1357 else
1358 FRAME_SELECTED_WINDOW (f) = swindow;
1359 }
1360 }
1361
1362 tem = p->buffer;
1363 /* tem is null for dummy parent windows
1364 (which have inferiors but not any contents themselves) */
1365 if (!NILP (tem))
1366 {
1367 unshow_buffer (p);
1368 unchain_marker (p->pointm);
1369 unchain_marker (p->start);
1370 }
1371
1372 /* Free window glyph matrices. It is sure that they are allocated
1373 again when ADJUST_GLYPHS is called. Block input so that expose
1374 events and other events that access glyph matrices are not
1375 processed while we are changing them. */
1376 BLOCK_INPUT;
1377 free_window_matrices (XWINDOW (FRAME_ROOT_WINDOW (f)));
1378
1379 tem = p->next;
1380 if (!NILP (tem))
1381 XWINDOW (tem)->prev = p->prev;
1382
1383 tem = p->prev;
1384 if (!NILP (tem))
1385 XWINDOW (tem)->next = p->next;
1386
1387 if (EQ (window, par->hchild))
1388 par->hchild = p->next;
1389 if (EQ (window, par->vchild))
1390 par->vchild = p->next;
1391
1392 /* Find one of our siblings to give our space to. */
1393 sib = p->prev;
1394 if (NILP (sib))
1395 {
1396 /* If p gives its space to its next sibling, that sibling needs
1397 to have its top/left side pulled back to where p's is.
1398 set_window_{height,width} will re-position the sibling's
1399 children. */
1400 sib = p->next;
1401 XWINDOW (sib)->top_line = p->top_line;
1402 XWINDOW (sib)->left_col = p->left_col;
1403 }
1404
1405 /* Stretch that sibling. */
1406 if (!NILP (par->vchild))
1407 set_window_height (sib,
1408 XFASTINT (XWINDOW (sib)->total_lines) + XFASTINT (p->total_lines),
1409 1);
1410 if (!NILP (par->hchild))
1411 set_window_width (sib,
1412 XFASTINT (XWINDOW (sib)->total_cols) + XFASTINT (p->total_cols),
1413 1);
1414
1415 /* If parent now has only one child,
1416 put the child into the parent's place. */
1417 tem = par->hchild;
1418 if (NILP (tem))
1419 tem = par->vchild;
1420 if (NILP (XWINDOW (tem)->next))
1421 replace_window (parent, tem);
1422
1423 /* Since we may be deleting combination windows, we must make sure that
1424 not only p but all its children have been marked as deleted. */
1425 if (! NILP (p->hchild))
1426 delete_all_subwindows (XWINDOW (p->hchild));
1427 else if (! NILP (p->vchild))
1428 delete_all_subwindows (XWINDOW (p->vchild));
1429
1430 /* Mark this window as deleted. */
1431 p->buffer = p->hchild = p->vchild = Qnil;
1432
1433 /* Adjust glyph matrices. */
1434 adjust_glyphs (f);
1435 UNBLOCK_INPUT;
1436 }
1437
1438
1439 \f
1440 /***********************************************************************
1441 Window List
1442 ***********************************************************************/
1443
1444 /* Add window W to *USER_DATA. USER_DATA is actually a Lisp_Object
1445 pointer. This is a callback function for foreach_window, used in
1446 function window_list. */
1447
1448 static int
1449 add_window_to_list (w, user_data)
1450 struct window *w;
1451 void *user_data;
1452 {
1453 Lisp_Object *list = (Lisp_Object *) user_data;
1454 Lisp_Object window;
1455 XSETWINDOW (window, w);
1456 *list = Fcons (window, *list);
1457 return 1;
1458 }
1459
1460
1461 /* Return a list of all windows, for use by next_window. If
1462 Vwindow_list is a list, return that list. Otherwise, build a new
1463 list, cache it in Vwindow_list, and return that. */
1464
1465 static Lisp_Object
1466 window_list ()
1467 {
1468 if (!CONSP (Vwindow_list))
1469 {
1470 Lisp_Object tail;
1471
1472 Vwindow_list = Qnil;
1473 for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail))
1474 {
1475 Lisp_Object args[2];
1476
1477 /* We are visiting windows in canonical order, and add
1478 new windows at the front of args[1], which means we
1479 have to reverse this list at the end. */
1480 args[1] = Qnil;
1481 foreach_window (XFRAME (XCAR (tail)), add_window_to_list, &args[1]);
1482 args[0] = Vwindow_list;
1483 args[1] = Fnreverse (args[1]);
1484 Vwindow_list = Fnconc (2, args);
1485 }
1486 }
1487
1488 return Vwindow_list;
1489 }
1490
1491
1492 /* Value is non-zero if WINDOW satisfies the constraints given by
1493 OWINDOW, MINIBUF and ALL_FRAMES.
1494
1495 MINIBUF t means WINDOW may be minibuffer windows.
1496 `lambda' means WINDOW may not be a minibuffer window.
1497 a window means a specific minibuffer window
1498
1499 ALL_FRAMES t means search all frames,
1500 nil means search just current frame,
1501 `visible' means search just visible frames,
1502 0 means search visible and iconified frames,
1503 a window means search the frame that window belongs to,
1504 a frame means consider windows on that frame, only. */
1505
1506 static int
1507 candidate_window_p (window, owindow, minibuf, all_frames)
1508 Lisp_Object window, owindow, minibuf, all_frames;
1509 {
1510 struct window *w = XWINDOW (window);
1511 struct frame *f = XFRAME (w->frame);
1512 int candidate_p = 1;
1513
1514 if (!BUFFERP (w->buffer))
1515 candidate_p = 0;
1516 else if (MINI_WINDOW_P (w)
1517 && (EQ (minibuf, Qlambda)
1518 || (WINDOWP (minibuf) && !EQ (minibuf, window))))
1519 {
1520 /* If MINIBUF is `lambda' don't consider any mini-windows.
1521 If it is a window, consider only that one. */
1522 candidate_p = 0;
1523 }
1524 else if (EQ (all_frames, Qt))
1525 candidate_p = 1;
1526 else if (NILP (all_frames))
1527 {
1528 xassert (WINDOWP (owindow));
1529 candidate_p = EQ (w->frame, XWINDOW (owindow)->frame);
1530 }
1531 else if (EQ (all_frames, Qvisible))
1532 {
1533 FRAME_SAMPLE_VISIBILITY (f);
1534 candidate_p = FRAME_VISIBLE_P (f);
1535 }
1536 else if (INTEGERP (all_frames) && XINT (all_frames) == 0)
1537 {
1538 FRAME_SAMPLE_VISIBILITY (f);
1539 candidate_p = FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f);
1540 }
1541 else if (WINDOWP (all_frames))
1542 candidate_p = (EQ (FRAME_MINIBUF_WINDOW (f), all_frames)
1543 || EQ (XWINDOW (all_frames)->frame, w->frame)
1544 || EQ (XWINDOW (all_frames)->frame, FRAME_FOCUS_FRAME (f)));
1545 else if (FRAMEP (all_frames))
1546 candidate_p = EQ (all_frames, w->frame);
1547
1548 return candidate_p;
1549 }
1550
1551
1552 /* Decode arguments as allowed by Fnext_window, Fprevious_window, and
1553 Fwindow_list. See there for the meaning of WINDOW, MINIBUF, and
1554 ALL_FRAMES. */
1555
1556 static void
1557 decode_next_window_args (window, minibuf, all_frames)
1558 Lisp_Object *window, *minibuf, *all_frames;
1559 {
1560 if (NILP (*window))
1561 *window = selected_window;
1562 else
1563 CHECK_LIVE_WINDOW (*window);
1564
1565 /* MINIBUF nil may or may not include minibuffers. Decide if it
1566 does. */
1567 if (NILP (*minibuf))
1568 *minibuf = minibuf_level ? minibuf_window : Qlambda;
1569 else if (!EQ (*minibuf, Qt))
1570 *minibuf = Qlambda;
1571
1572 /* Now *MINIBUF can be t => count all minibuffer windows, `lambda'
1573 => count none of them, or a specific minibuffer window (the
1574 active one) to count. */
1575
1576 /* ALL_FRAMES nil doesn't specify which frames to include. */
1577 if (NILP (*all_frames))
1578 *all_frames = (!EQ (*minibuf, Qlambda)
1579 ? FRAME_MINIBUF_WINDOW (XFRAME (XWINDOW (*window)->frame))
1580 : Qnil);
1581 else if (EQ (*all_frames, Qvisible))
1582 ;
1583 else if (XFASTINT (*all_frames) == 0)
1584 ;
1585 else if (FRAMEP (*all_frames))
1586 ;
1587 else if (!EQ (*all_frames, Qt))
1588 *all_frames = Qnil;
1589
1590 /* Now *ALL_FRAMES is t meaning search all frames, nil meaning
1591 search just current frame, `visible' meaning search just visible
1592 frames, 0 meaning search visible and iconified frames, or a
1593 window, meaning search the frame that window belongs to, or a
1594 frame, meaning consider windows on that frame, only. */
1595 }
1596
1597
1598 /* Return the next or previous window of WINDOW in canonical ordering
1599 of windows. NEXT_P non-zero means return the next window. See the
1600 documentation string of next-window for the meaning of MINIBUF and
1601 ALL_FRAMES. */
1602
1603 static Lisp_Object
1604 next_window (window, minibuf, all_frames, next_p)
1605 Lisp_Object window, minibuf, all_frames;
1606 int next_p;
1607 {
1608 decode_next_window_args (&window, &minibuf, &all_frames);
1609
1610 /* If ALL_FRAMES is a frame, and WINDOW isn't on that frame, just
1611 return the first window on the frame. */
1612 if (FRAMEP (all_frames)
1613 && !EQ (all_frames, XWINDOW (window)->frame))
1614 return Fframe_first_window (all_frames);
1615
1616 if (next_p)
1617 {
1618 Lisp_Object list;
1619
1620 /* Find WINDOW in the list of all windows. */
1621 list = Fmemq (window, window_list ());
1622
1623 /* Scan forward from WINDOW to the end of the window list. */
1624 if (CONSP (list))
1625 for (list = XCDR (list); CONSP (list); list = XCDR (list))
1626 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1627 break;
1628
1629 /* Scan from the start of the window list up to WINDOW. */
1630 if (!CONSP (list))
1631 for (list = Vwindow_list;
1632 CONSP (list) && !EQ (XCAR (list), window);
1633 list = XCDR (list))
1634 if (candidate_window_p (XCAR (list), window, minibuf, all_frames))
1635 break;
1636
1637 if (CONSP (list))
1638 window = XCAR (list);
1639 }
1640 else
1641 {
1642 Lisp_Object candidate, list;
1643
1644 /* Scan through the list of windows for candidates. If there are
1645 candidate windows in front of WINDOW, the last one of these
1646 is the one we want. If there are candidates following WINDOW
1647 in the list, again the last one of these is the one we want. */
1648 candidate = Qnil;
1649 for (list = window_list (); CONSP (list); list = XCDR (list))
1650 {
1651 if (EQ (XCAR (list), window))
1652 {
1653 if (WINDOWP (candidate))
1654 break;
1655 }
1656 else if (candidate_window_p (XCAR (list), window, minibuf,
1657 all_frames))
1658 candidate = XCAR (list);
1659 }
1660
1661 if (WINDOWP (candidate))
1662 window = candidate;
1663 }
1664
1665 return window;
1666 }
1667
1668
1669 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
1670 doc: /* Return next window after WINDOW in canonical ordering of windows.
1671 If omitted, WINDOW defaults to the selected window.
1672
1673 Optional second arg MINIBUF t means count the minibuffer window even
1674 if not active. MINIBUF nil or omitted means count the minibuffer iff
1675 it is active. MINIBUF neither t nor nil means not to count the
1676 minibuffer even if it is active.
1677
1678 Several frames may share a single minibuffer; if the minibuffer
1679 counts, all windows on all frames that share that minibuffer count
1680 too. Therefore, `next-window' can be used to iterate through the
1681 set of windows even when the minibuffer is on another frame. If the
1682 minibuffer does not count, only windows from WINDOW's frame count.
1683
1684 Optional third arg ALL-FRAMES t means include windows on all frames.
1685 ALL-FRAMES nil or omitted means cycle within the frames as specified
1686 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1687 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1688 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1689 Anything else means restrict to WINDOW's frame.
1690
1691 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1692 `next-window' to iterate through the entire cycle of acceptable
1693 windows, eventually ending up back at the window you started with.
1694 `previous-window' traverses the same cycle, in the reverse order. */)
1695 (window, minibuf, all_frames)
1696 Lisp_Object window, minibuf, all_frames;
1697 {
1698 return next_window (window, minibuf, all_frames, 1);
1699 }
1700
1701
1702 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
1703 doc: /* Return the window preceding WINDOW in canonical ordering of windows.
1704 If omitted, WINDOW defaults to the selected window.
1705
1706 Optional second arg MINIBUF t means count the minibuffer window even
1707 if not active. MINIBUF nil or omitted means count the minibuffer iff
1708 it is active. MINIBUF neither t nor nil means not to count the
1709 minibuffer even if it is active.
1710
1711 Several frames may share a single minibuffer; if the minibuffer
1712 counts, all windows on all frames that share that minibuffer count
1713 too. Therefore, `previous-window' can be used to iterate through
1714 the set of windows even when the minibuffer is on another frame. If
1715 the minibuffer does not count, only windows from WINDOW's frame count
1716
1717 Optional third arg ALL-FRAMES t means include windows on all frames.
1718 ALL-FRAMES nil or omitted means cycle within the frames as specified
1719 above. ALL-FRAMES = `visible' means include windows on all visible frames.
1720 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
1721 If ALL-FRAMES is a frame, restrict search to windows on that frame.
1722 Anything else means restrict to WINDOW's frame.
1723
1724 If you use consistent values for MINIBUF and ALL-FRAMES, you can use
1725 `previous-window' to iterate through the entire cycle of acceptable
1726 windows, eventually ending up back at the window you started with.
1727 `next-window' traverses the same cycle, in the reverse order. */)
1728 (window, minibuf, all_frames)
1729 Lisp_Object window, minibuf, all_frames;
1730 {
1731 return next_window (window, minibuf, all_frames, 0);
1732 }
1733
1734
1735 DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
1736 doc: /* Select the ARG'th different window on this frame.
1737 All windows on current frame are arranged in a cyclic order.
1738 This command selects the window ARG steps away in that order.
1739 A negative ARG moves in the opposite order. If the optional second
1740 argument ALL_FRAMES is non-nil, cycle through all frames. */)
1741 (arg, all_frames)
1742 Lisp_Object arg, all_frames;
1743 {
1744 Lisp_Object window;
1745 int i;
1746
1747 CHECK_NUMBER (arg);
1748 window = selected_window;
1749
1750 for (i = XINT (arg); i > 0; --i)
1751 window = Fnext_window (window, Qnil, all_frames);
1752 for (; i < 0; ++i)
1753 window = Fprevious_window (window, Qnil, all_frames);
1754
1755 Fselect_window (window, Qnil);
1756 return Qnil;
1757 }
1758
1759
1760 DEFUN ("window-list", Fwindow_list, Swindow_list, 0, 3, 0,
1761 doc: /* Return a list of windows on FRAME, starting with WINDOW.
1762 FRAME nil or omitted means use the selected frame.
1763 WINDOW nil or omitted means use the selected window.
1764 MINIBUF t means include the minibuffer window, even if it isn't active.
1765 MINIBUF nil or omitted means include the minibuffer window only
1766 if it's active.
1767 MINIBUF neither nil nor t means never include the minibuffer window. */)
1768 (frame, minibuf, window)
1769 Lisp_Object frame, minibuf, window;
1770 {
1771 if (NILP (window))
1772 window = selected_window;
1773 if (NILP (frame))
1774 frame = selected_frame;
1775
1776 if (!EQ (frame, XWINDOW (window)->frame))
1777 error ("Window is on a different frame");
1778
1779 return window_list_1 (window, minibuf, frame);
1780 }
1781
1782
1783 /* Return a list of windows in canonical ordering. Arguments are like
1784 for `next-window'. */
1785
1786 static Lisp_Object
1787 window_list_1 (window, minibuf, all_frames)
1788 Lisp_Object window, minibuf, all_frames;
1789 {
1790 Lisp_Object tail, list;
1791
1792 decode_next_window_args (&window, &minibuf, &all_frames);
1793 list = Qnil;
1794
1795 for (tail = window_list (); CONSP (tail); tail = XCDR (tail))
1796 if (candidate_window_p (XCAR (tail), window, minibuf, all_frames))
1797 list = Fcons (XCAR (tail), list);
1798
1799 return Fnreverse (list);
1800 }
1801
1802
1803 \f
1804 /* Look at all windows, performing an operation specified by TYPE
1805 with argument OBJ.
1806 If FRAMES is Qt, look at all frames;
1807 Qnil, look at just the selected frame;
1808 Qvisible, look at visible frames;
1809 a frame, just look at windows on that frame.
1810 If MINI is non-zero, perform the operation on minibuffer windows too. */
1811
1812 enum window_loop
1813 {
1814 WINDOW_LOOP_UNUSED,
1815 GET_BUFFER_WINDOW, /* Arg is buffer */
1816 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
1817 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
1818 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
1819 GET_LARGEST_WINDOW,
1820 UNSHOW_BUFFER, /* Arg is buffer */
1821 CHECK_ALL_WINDOWS
1822 };
1823
1824 static Lisp_Object
1825 window_loop (type, obj, mini, frames)
1826 enum window_loop type;
1827 Lisp_Object obj, frames;
1828 int mini;
1829 {
1830 Lisp_Object window, windows, best_window, frame_arg;
1831 struct frame *f;
1832 struct gcpro gcpro1;
1833
1834 /* If we're only looping through windows on a particular frame,
1835 frame points to that frame. If we're looping through windows
1836 on all frames, frame is 0. */
1837 if (FRAMEP (frames))
1838 f = XFRAME (frames);
1839 else if (NILP (frames))
1840 f = SELECTED_FRAME ();
1841 else
1842 f = NULL;
1843
1844 if (f)
1845 frame_arg = Qlambda;
1846 else if (XFASTINT (frames) == 0)
1847 frame_arg = frames;
1848 else if (EQ (frames, Qvisible))
1849 frame_arg = frames;
1850 else
1851 frame_arg = Qt;
1852
1853 /* frame_arg is Qlambda to stick to one frame,
1854 Qvisible to consider all visible frames,
1855 or Qt otherwise. */
1856
1857 /* Pick a window to start with. */
1858 if (WINDOWP (obj))
1859 window = obj;
1860 else if (f)
1861 window = FRAME_SELECTED_WINDOW (f);
1862 else
1863 window = FRAME_SELECTED_WINDOW (SELECTED_FRAME ());
1864
1865 windows = window_list_1 (window, mini ? Qt : Qnil, frame_arg);
1866 GCPRO1 (windows);
1867 best_window = Qnil;
1868
1869 for (; CONSP (windows); windows = CDR (windows))
1870 {
1871 struct window *w;
1872
1873 window = XCAR (windows);
1874 w = XWINDOW (window);
1875
1876 /* Note that we do not pay attention here to whether the frame
1877 is visible, since Fwindow_list skips non-visible frames if
1878 that is desired, under the control of frame_arg. */
1879 if (!MINI_WINDOW_P (w)
1880 /* For UNSHOW_BUFFER, we must always consider all windows. */
1881 || type == UNSHOW_BUFFER
1882 || (mini && minibuf_level > 0))
1883 switch (type)
1884 {
1885 case GET_BUFFER_WINDOW:
1886 if (EQ (w->buffer, obj)
1887 /* Don't find any minibuffer window
1888 except the one that is currently in use. */
1889 && (MINI_WINDOW_P (w)
1890 ? EQ (window, minibuf_window)
1891 : 1))
1892 {
1893 if (NILP (best_window))
1894 best_window = window;
1895 else if (EQ (window, selected_window))
1896 /* For compatibility with 20.x, prefer to return
1897 selected-window. */
1898 best_window = window;
1899 }
1900 break;
1901
1902 case GET_LRU_WINDOW:
1903 /* t as arg means consider only full-width windows */
1904 if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (w))
1905 break;
1906 /* Ignore dedicated windows and minibuffers. */
1907 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
1908 break;
1909 if (NILP (best_window)
1910 || (XFASTINT (XWINDOW (best_window)->use_time)
1911 > XFASTINT (w->use_time)))
1912 best_window = window;
1913 break;
1914
1915 case DELETE_OTHER_WINDOWS:
1916 if (!EQ (window, obj))
1917 Fdelete_window (window);
1918 break;
1919
1920 case DELETE_BUFFER_WINDOWS:
1921 if (EQ (w->buffer, obj))
1922 {
1923 struct frame *f = XFRAME (WINDOW_FRAME (w));
1924
1925 /* If this window is dedicated, and in a frame of its own,
1926 kill the frame. */
1927 if (EQ (window, FRAME_ROOT_WINDOW (f))
1928 && !NILP (w->dedicated)
1929 && other_visible_frames (f))
1930 {
1931 /* Skip the other windows on this frame.
1932 There might be one, the minibuffer! */
1933 while (CONSP (XCDR (windows))
1934 && EQ (XWINDOW (XCAR (windows))->frame,
1935 XWINDOW (XCAR (XCDR (windows)))->frame))
1936 windows = XCDR (windows);
1937
1938 /* Now we can safely delete the frame. */
1939 Fdelete_frame (w->frame, Qnil);
1940 }
1941 else if (NILP (w->parent))
1942 {
1943 /* If we're deleting the buffer displayed in the
1944 only window on the frame, find a new buffer to
1945 display there. */
1946 Lisp_Object buffer;
1947 buffer = Fother_buffer (obj, Qnil, w->frame);
1948 Fset_window_buffer (window, buffer, Qnil);
1949 if (EQ (window, selected_window))
1950 Fset_buffer (w->buffer);
1951 }
1952 else
1953 Fdelete_window (window);
1954 }
1955 break;
1956
1957 case GET_LARGEST_WINDOW:
1958 {
1959 /* Ignore dedicated windows and minibuffers. */
1960 if (MINI_WINDOW_P (w) || EQ (w->dedicated, Qt))
1961 break;
1962
1963 if (NILP (best_window))
1964 best_window = window;
1965 else
1966 {
1967 struct window *b = XWINDOW (best_window);
1968 if (XFASTINT (w->total_lines) * XFASTINT (w->total_cols)
1969 > XFASTINT (b->total_lines) * XFASTINT (b->total_cols))
1970 best_window = window;
1971 }
1972 }
1973 break;
1974
1975 case UNSHOW_BUFFER:
1976 if (EQ (w->buffer, obj))
1977 {
1978 Lisp_Object buffer;
1979 struct frame *f = XFRAME (w->frame);
1980
1981 /* Find another buffer to show in this window. */
1982 buffer = Fother_buffer (obj, Qnil, w->frame);
1983
1984 /* If this window is dedicated, and in a frame of its own,
1985 kill the frame. */
1986 if (EQ (window, FRAME_ROOT_WINDOW (f))
1987 && !NILP (w->dedicated)
1988 && other_visible_frames (f))
1989 {
1990 /* Skip the other windows on this frame.
1991 There might be one, the minibuffer! */
1992 while (CONSP (XCDR (windows))
1993 && EQ (XWINDOW (XCAR (windows))->frame,
1994 XWINDOW (XCAR (XCDR (windows)))->frame))
1995 windows = XCDR (windows);
1996
1997 /* Now we can safely delete the frame. */
1998 Fdelete_frame (w->frame, Qnil);
1999 }
2000 else if (!NILP (w->dedicated) && !NILP (w->parent))
2001 {
2002 Lisp_Object window;
2003 XSETWINDOW (window, w);
2004 /* If this window is dedicated and not the only window
2005 in its frame, then kill it. */
2006 Fdelete_window (window);
2007 }
2008 else
2009 {
2010 /* Otherwise show a different buffer in the window. */
2011 w->dedicated = Qnil;
2012 Fset_window_buffer (window, buffer, Qnil);
2013 if (EQ (window, selected_window))
2014 Fset_buffer (w->buffer);
2015 }
2016 }
2017 break;
2018
2019 /* Check for a window that has a killed buffer. */
2020 case CHECK_ALL_WINDOWS:
2021 if (! NILP (w->buffer)
2022 && NILP (XBUFFER (w->buffer)->name))
2023 abort ();
2024 break;
2025
2026 case WINDOW_LOOP_UNUSED:
2027 break;
2028 }
2029 }
2030
2031 UNGCPRO;
2032 return best_window;
2033 }
2034
2035 /* Used for debugging. Abort if any window has a dead buffer. */
2036
2037 void
2038 check_all_windows ()
2039 {
2040 window_loop (CHECK_ALL_WINDOWS, Qnil, 1, Qt);
2041 }
2042
2043 DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0,
2044 doc: /* Return the window least recently selected or used for display.
2045 If optional argument FRAME is `visible', search all visible frames.
2046 If FRAME is 0, search all visible and iconified frames.
2047 If FRAME is t, search all frames.
2048 If FRAME is nil, search only the selected frame.
2049 If FRAME is a frame, search only that frame. */)
2050 (frame)
2051 Lisp_Object frame;
2052 {
2053 register Lisp_Object w;
2054 /* First try for a window that is full-width */
2055 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame);
2056 if (!NILP (w) && !EQ (w, selected_window))
2057 return w;
2058 /* If none of them, try the rest */
2059 return window_loop (GET_LRU_WINDOW, Qnil, 0, frame);
2060 }
2061
2062 DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0,
2063 doc: /* Return the largest window in area.
2064 If optional argument FRAME is `visible', search all visible frames.
2065 If FRAME is 0, search all visible and iconified frames.
2066 If FRAME is t, search all frames.
2067 If FRAME is nil, search only the selected frame.
2068 If FRAME is a frame, search only that frame. */)
2069 (frame)
2070 Lisp_Object frame;
2071 {
2072 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
2073 frame);
2074 }
2075
2076 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0,
2077 doc: /* Return a window currently displaying BUFFER, or nil if none.
2078 If optional argument FRAME is `visible', search all visible frames.
2079 If optional argument FRAME is 0, search all visible and iconified frames.
2080 If FRAME is t, search all frames.
2081 If FRAME is nil, search only the selected frame.
2082 If FRAME is a frame, search only that frame. */)
2083 (buffer, frame)
2084 Lisp_Object buffer, frame;
2085 {
2086 buffer = Fget_buffer (buffer);
2087 if (BUFFERP (buffer))
2088 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame);
2089 else
2090 return Qnil;
2091 }
2092
2093 DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows,
2094 0, 1, "",
2095 doc: /* Make WINDOW (or the selected window) fill its frame.
2096 Only the frame WINDOW is on is affected.
2097 This function tries to reduce display jumps
2098 by keeping the text previously visible in WINDOW
2099 in the same place on the frame. Doing this depends on
2100 the value of (window-start WINDOW), so if calling this function
2101 in a program gives strange scrolling, make sure the window-start
2102 value is reasonable when this function is called. */)
2103 (window)
2104 Lisp_Object window;
2105 {
2106 struct window *w;
2107 int startpos;
2108 int top, new_top;
2109
2110 if (NILP (window))
2111 window = selected_window;
2112 else
2113 CHECK_LIVE_WINDOW (window);
2114 w = XWINDOW (window);
2115
2116 startpos = marker_position (w->start);
2117 top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2118
2119 if (MINI_WINDOW_P (w) && top > 0)
2120 error ("Can't expand minibuffer to full frame");
2121
2122 window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w));
2123
2124 /* Try to minimize scrolling, by setting the window start to the point
2125 will cause the text at the old window start to be at the same place
2126 on the frame. But don't try to do this if the window start is
2127 outside the visible portion (as might happen when the display is
2128 not current, due to typeahead). */
2129 new_top = WINDOW_TOP_EDGE_LINE (w) - FRAME_TOP_MARGIN (XFRAME (WINDOW_FRAME (w)));
2130 if (new_top != top
2131 && startpos >= BUF_BEGV (XBUFFER (w->buffer))
2132 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
2133 {
2134 struct position pos;
2135 struct buffer *obuf = current_buffer;
2136
2137 Fset_buffer (w->buffer);
2138 /* This computation used to temporarily move point, but that can
2139 have unwanted side effects due to text properties. */
2140 pos = *vmotion (startpos, -top, w);
2141
2142 set_marker_both (w->start, w->buffer, pos.bufpos, pos.bytepos);
2143 w->window_end_valid = Qnil;
2144 w->start_at_line_beg = ((pos.bytepos == BEGV_BYTE
2145 || FETCH_BYTE (pos.bytepos - 1) == '\n') ? Qt
2146 : Qnil);
2147 /* We need to do this, so that the window-scroll-functions
2148 get called. */
2149 w->optional_new_start = Qt;
2150
2151 set_buffer_internal (obuf);
2152 }
2153
2154 return Qnil;
2155 }
2156
2157 DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on,
2158 1, 2, "bDelete windows on (buffer): ",
2159 doc: /* Delete all windows showing BUFFER.
2160 Optional second argument FRAME controls which frames are affected.
2161 If optional argument FRAME is `visible', search all visible frames.
2162 If FRAME is 0, search all visible and iconified frames.
2163 If FRAME is nil, search all frames.
2164 If FRAME is t, search only the selected frame.
2165 If FRAME is a frame, search only that frame. */)
2166 (buffer, frame)
2167 Lisp_Object buffer, frame;
2168 {
2169 /* FRAME uses t and nil to mean the opposite of what window_loop
2170 expects. */
2171 if (NILP (frame))
2172 frame = Qt;
2173 else if (EQ (frame, Qt))
2174 frame = Qnil;
2175
2176 if (!NILP (buffer))
2177 {
2178 buffer = Fget_buffer (buffer);
2179 CHECK_BUFFER (buffer);
2180 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame);
2181 }
2182
2183 return Qnil;
2184 }
2185
2186 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
2187 Sreplace_buffer_in_windows,
2188 1, 1, "bReplace buffer in windows: ",
2189 doc: /* Replace BUFFER with some other buffer in all windows showing it. */)
2190 (buffer)
2191 Lisp_Object buffer;
2192 {
2193 if (!NILP (buffer))
2194 {
2195 buffer = Fget_buffer (buffer);
2196 CHECK_BUFFER (buffer);
2197 window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
2198 }
2199 return Qnil;
2200 }
2201
2202 /* Replace BUFFER with some other buffer in all windows
2203 of all frames, even those on other keyboards. */
2204
2205 void
2206 replace_buffer_in_all_windows (buffer)
2207 Lisp_Object buffer;
2208 {
2209 #ifdef MULTI_KBOARD
2210 Lisp_Object tail, frame;
2211
2212 /* A single call to window_loop won't do the job
2213 because it only considers frames on the current keyboard.
2214 So loop manually over frames, and handle each one. */
2215 FOR_EACH_FRAME (tail, frame)
2216 window_loop (UNSHOW_BUFFER, buffer, 1, frame);
2217 #else
2218 window_loop (UNSHOW_BUFFER, buffer, 1, Qt);
2219 #endif
2220 }
2221 \f
2222 /* Set the height of WINDOW and all its inferiors. */
2223
2224 /* The smallest acceptable dimensions for a window. Anything smaller
2225 might crash Emacs. */
2226
2227 #define MIN_SAFE_WINDOW_WIDTH (2)
2228 #define MIN_SAFE_WINDOW_HEIGHT (1)
2229
2230 /* Make sure that window_min_height and window_min_width are
2231 not too small; if they are, set them to safe minima. */
2232
2233 static void
2234 check_min_window_sizes ()
2235 {
2236 /* Smaller values might permit a crash. */
2237 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
2238 window_min_width = MIN_SAFE_WINDOW_WIDTH;
2239 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
2240 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
2241 }
2242
2243 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
2244 minimum allowable size. */
2245
2246 void
2247 check_frame_size (frame, rows, cols)
2248 FRAME_PTR frame;
2249 int *rows, *cols;
2250 {
2251 /* For height, we have to see:
2252 how many windows the frame has at minimum (one or two),
2253 and whether it has a menu bar or other special stuff at the top. */
2254 int min_height
2255 = ((FRAME_MINIBUF_ONLY_P (frame) || ! FRAME_HAS_MINIBUF_P (frame))
2256 ? MIN_SAFE_WINDOW_HEIGHT
2257 : 2 * MIN_SAFE_WINDOW_HEIGHT);
2258
2259 if (FRAME_TOP_MARGIN (frame) > 0)
2260 min_height += FRAME_TOP_MARGIN (frame);
2261
2262 if (*rows < min_height)
2263 *rows = min_height;
2264 if (*cols < MIN_SAFE_WINDOW_WIDTH)
2265 *cols = MIN_SAFE_WINDOW_WIDTH;
2266 }
2267
2268
2269 /* Value is non-zero if window W is fixed-size. WIDTH_P non-zero means
2270 check if W's width can be changed, otherwise check W's height.
2271 CHECK_SIBLINGS_P non-zero means check resizablity of WINDOW's
2272 siblings, too. If none of the siblings is resizable, WINDOW isn't
2273 either. */
2274
2275 static int
2276 window_fixed_size_p (w, width_p, check_siblings_p)
2277 struct window *w;
2278 int width_p, check_siblings_p;
2279 {
2280 int fixed_p;
2281 struct window *c;
2282
2283 if (!NILP (w->hchild))
2284 {
2285 c = XWINDOW (w->hchild);
2286
2287 if (width_p)
2288 {
2289 /* A horiz. combination is fixed-width if all of if its
2290 children are. */
2291 while (c && window_fixed_size_p (c, width_p, 0))
2292 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2293 fixed_p = c == NULL;
2294 }
2295 else
2296 {
2297 /* A horiz. combination is fixed-height if one of if its
2298 children is. */
2299 while (c && !window_fixed_size_p (c, width_p, 0))
2300 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2301 fixed_p = c != NULL;
2302 }
2303 }
2304 else if (!NILP (w->vchild))
2305 {
2306 c = XWINDOW (w->vchild);
2307
2308 if (width_p)
2309 {
2310 /* A vert. combination is fixed-width if one of if its
2311 children is. */
2312 while (c && !window_fixed_size_p (c, width_p, 0))
2313 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2314 fixed_p = c != NULL;
2315 }
2316 else
2317 {
2318 /* A vert. combination is fixed-height if all of if its
2319 children are. */
2320 while (c && window_fixed_size_p (c, width_p, 0))
2321 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2322 fixed_p = c == NULL;
2323 }
2324 }
2325 else if (BUFFERP (w->buffer))
2326 {
2327 if (w->height_fixed_p && !width_p)
2328 fixed_p = 1;
2329 else
2330 {
2331 struct buffer *old = current_buffer;
2332 Lisp_Object val;
2333
2334 current_buffer = XBUFFER (w->buffer);
2335 val = find_symbol_value (Qwindow_size_fixed);
2336 current_buffer = old;
2337
2338 fixed_p = 0;
2339 if (!EQ (val, Qunbound))
2340 {
2341 fixed_p = !NILP (val);
2342
2343 if (fixed_p
2344 && ((EQ (val, Qheight) && width_p)
2345 || (EQ (val, Qwidth) && !width_p)))
2346 fixed_p = 0;
2347 }
2348 }
2349
2350 /* Can't tell if this one is resizable without looking at
2351 siblings. If all siblings are fixed-size this one is too. */
2352 if (!fixed_p && check_siblings_p && WINDOWP (w->parent))
2353 {
2354 Lisp_Object child;
2355
2356 for (child = w->prev; !NILP (child); child = XWINDOW (child)->prev)
2357 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2358 break;
2359
2360 if (NILP (child))
2361 for (child = w->next; !NILP (child); child = XWINDOW (child)->next)
2362 if (!window_fixed_size_p (XWINDOW (child), width_p, 0))
2363 break;
2364
2365 if (NILP (child))
2366 fixed_p = 1;
2367 }
2368 }
2369 else
2370 fixed_p = 1;
2371
2372 return fixed_p;
2373 }
2374
2375
2376 /* Return the minimum size of window W, not taking fixed-width windows
2377 into account. WIDTH_P non-zero means return the minimum width,
2378 otherwise return the minimum height. If W is a combination window,
2379 compute the minimum size from the minimum sizes of W's children. */
2380
2381 static int
2382 window_min_size_1 (w, width_p)
2383 struct window *w;
2384 int width_p;
2385 {
2386 struct window *c;
2387 int size;
2388
2389 if (!NILP (w->hchild))
2390 {
2391 c = XWINDOW (w->hchild);
2392 size = 0;
2393
2394 if (width_p)
2395 {
2396 /* The min width of a horizontal combination is
2397 the sum of the min widths of its children. */
2398 while (c)
2399 {
2400 size += window_min_size_1 (c, width_p);
2401 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2402 }
2403 }
2404 else
2405 {
2406 /* The min height a horizontal combination equals
2407 the maximum of all min height of its children. */
2408 while (c)
2409 {
2410 int min_size = window_min_size_1 (c, width_p);
2411 size = max (min_size, size);
2412 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2413 }
2414 }
2415 }
2416 else if (!NILP (w->vchild))
2417 {
2418 c = XWINDOW (w->vchild);
2419 size = 0;
2420
2421 if (width_p)
2422 {
2423 /* The min width of a vertical combination is
2424 the maximum of the min widths of its children. */
2425 while (c)
2426 {
2427 int min_size = window_min_size_1 (c, width_p);
2428 size = max (min_size, size);
2429 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2430 }
2431 }
2432 else
2433 {
2434 /* The min height of a vertical combination equals
2435 the sum of the min height of its children. */
2436 while (c)
2437 {
2438 size += window_min_size_1 (c, width_p);
2439 c = WINDOWP (c->next) ? XWINDOW (c->next) : NULL;
2440 }
2441 }
2442 }
2443 else
2444 {
2445 if (width_p)
2446 size = window_min_width;
2447 else
2448 {
2449 if (MINI_WINDOW_P (w)
2450 || (!WINDOW_WANTS_MODELINE_P (w)
2451 && !WINDOW_WANTS_HEADER_LINE_P (w)))
2452 size = 1;
2453 else
2454 size = window_min_height;
2455 }
2456 }
2457
2458 return size;
2459 }
2460
2461
2462 /* Return the minimum size of window W, taking fixed-size windows into
2463 account. WIDTH_P non-zero means return the minimum width,
2464 otherwise return the minimum height. IGNORE_FIXED_P non-zero means
2465 ignore if W is fixed-size. Set *FIXED to 1 if W is fixed-size
2466 unless FIXED is null. */
2467
2468 static int
2469 window_min_size (w, width_p, ignore_fixed_p, fixed)
2470 struct window *w;
2471 int width_p, ignore_fixed_p, *fixed;
2472 {
2473 int size, fixed_p;
2474
2475 if (ignore_fixed_p)
2476 fixed_p = 0;
2477 else
2478 fixed_p = window_fixed_size_p (w, width_p, 1);
2479
2480 if (fixed)
2481 *fixed = fixed_p;
2482
2483 if (fixed_p)
2484 size = width_p ? XFASTINT (w->total_cols) : XFASTINT (w->total_lines);
2485 else
2486 size = window_min_size_1 (w, width_p);
2487
2488 return size;
2489 }
2490
2491
2492 /* Adjust the margins of window W if text area is too small.
2493 Return 1 if window width is ok after adjustment; 0 if window
2494 is still too narrow. */
2495
2496 static int
2497 adjust_window_margins (w)
2498 struct window *w;
2499 {
2500 int box_cols = (WINDOW_TOTAL_COLS (w)
2501 - WINDOW_FRINGE_COLS (w)
2502 - WINDOW_SCROLL_BAR_COLS (w));
2503 int margin_cols = (WINDOW_LEFT_MARGIN_COLS (w)
2504 + WINDOW_RIGHT_MARGIN_COLS (w));
2505
2506 if (box_cols - margin_cols >= MIN_SAFE_WINDOW_WIDTH)
2507 return 1;
2508
2509 if (margin_cols < 0 || box_cols < MIN_SAFE_WINDOW_WIDTH)
2510 return 0;
2511
2512 /* Window's text area is too narrow, but reducing the window
2513 margins will fix that. */
2514 margin_cols = box_cols - MIN_SAFE_WINDOW_WIDTH;
2515 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
2516 {
2517 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
2518 w->left_margin_cols = w->right_margin_cols
2519 = make_number (margin_cols/2);
2520 else
2521 w->right_margin_cols = make_number (margin_cols);
2522 }
2523 else
2524 w->left_margin_cols = make_number (margin_cols);
2525 return 1;
2526 }
2527
2528
2529 /* Set WINDOW's height or width to SIZE. WIDTH_P non-zero means set
2530 WINDOW's width. Resize WINDOW's children, if any, so that they
2531 keep their proportionate size relative to WINDOW. Propagate
2532 WINDOW's top or left edge position to children. Delete windows
2533 that become too small unless NODELETE_P is non-zero.
2534
2535 If NODELETE_P is 2, that means we do delete windows that are
2536 too small, even if they were too small before! */
2537
2538 static void
2539 size_window (window, size, width_p, nodelete_p)
2540 Lisp_Object window;
2541 int size, width_p, nodelete_p;
2542 {
2543 struct window *w = XWINDOW (window);
2544 struct window *c;
2545 Lisp_Object child, *forward, *sideward;
2546 int old_size, min_size, safe_min_size;
2547
2548 /* We test nodelete_p != 2 and nodelete_p != 1 below, so it
2549 seems like it's too soon to do this here. ++KFS. */
2550 if (nodelete_p == 2)
2551 nodelete_p = 0;
2552
2553 check_min_window_sizes ();
2554 size = max (0, size);
2555
2556 /* If the window has been "too small" at one point,
2557 don't delete it for being "too small" in the future.
2558 Preserve it as long as that is at all possible. */
2559 if (width_p)
2560 {
2561 old_size = WINDOW_TOTAL_COLS (w);
2562 min_size = window_min_width;
2563 /* Ensure that there is room for the scroll bar and fringes!
2564 We may reduce display margins though. */
2565 safe_min_size = (MIN_SAFE_WINDOW_WIDTH
2566 + WINDOW_FRINGE_COLS (w)
2567 + WINDOW_SCROLL_BAR_COLS (w));
2568 }
2569 else
2570 {
2571 old_size = XINT (w->total_lines);
2572 min_size = window_min_height;
2573 safe_min_size = MIN_SAFE_WINDOW_HEIGHT;
2574 }
2575
2576 if (old_size < min_size && nodelete_p != 2)
2577 w->too_small_ok = Qt;
2578
2579 /* Maybe delete WINDOW if it's too small. */
2580 if (nodelete_p != 1 && !NILP (w->parent))
2581 {
2582 if (!MINI_WINDOW_P (w) && !NILP (w->too_small_ok))
2583 min_size = width_p ? MIN_SAFE_WINDOW_WIDTH : MIN_SAFE_WINDOW_HEIGHT;
2584 if (min_size < safe_min_size)
2585 min_size = safe_min_size;
2586 if (size < min_size)
2587 {
2588 delete_window (window);
2589 return;
2590 }
2591 }
2592
2593 /* Set redisplay hints. */
2594 w->last_modified = make_number (0);
2595 w->last_overlay_modified = make_number (0);
2596 windows_or_buffers_changed++;
2597 FRAME_WINDOW_SIZES_CHANGED (XFRAME (w->frame)) = 1;
2598
2599 if (width_p)
2600 {
2601 sideward = &w->vchild;
2602 forward = &w->hchild;
2603 w->total_cols = make_number (size);
2604 adjust_window_margins (w);
2605 }
2606 else
2607 {
2608 sideward = &w->hchild;
2609 forward = &w->vchild;
2610 w->total_lines = make_number (size);
2611 w->orig_total_lines = Qnil;
2612 }
2613
2614 if (!NILP (*sideward))
2615 {
2616 for (child = *sideward; !NILP (child); child = c->next)
2617 {
2618 c = XWINDOW (child);
2619 if (width_p)
2620 c->left_col = w->left_col;
2621 else
2622 c->top_line = w->top_line;
2623 size_window (child, size, width_p, nodelete_p);
2624 }
2625 }
2626 else if (!NILP (*forward))
2627 {
2628 int fixed_size, each, extra, n;
2629 int resize_fixed_p, nfixed;
2630 int last_pos, first_pos, nchildren, total;
2631
2632 /* Determine the fixed-size portion of the this window, and the
2633 number of child windows. */
2634 fixed_size = nchildren = nfixed = total = 0;
2635 for (child = *forward; !NILP (child); child = c->next, ++nchildren)
2636 {
2637 int child_size;
2638
2639 c = XWINDOW (child);
2640 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2641 total += child_size;
2642
2643 if (window_fixed_size_p (c, width_p, 0))
2644 {
2645 fixed_size += child_size;
2646 ++nfixed;
2647 }
2648 }
2649
2650 /* If the new size is smaller than fixed_size, or if there
2651 aren't any resizable windows, allow resizing fixed-size
2652 windows. */
2653 resize_fixed_p = nfixed == nchildren || size < fixed_size;
2654
2655 /* Compute how many lines/columns to add to each child. The
2656 value of extra takes care of rounding errors. */
2657 n = resize_fixed_p ? nchildren : nchildren - nfixed;
2658 each = (size - total) / n;
2659 extra = (size - total) - n * each;
2660
2661 /* Compute new children heights and edge positions. */
2662 first_pos = width_p ? XINT (w->left_col) : XINT (w->top_line);
2663 last_pos = first_pos;
2664 for (child = *forward; !NILP (child); child = c->next)
2665 {
2666 int new_size, old_size;
2667
2668 c = XWINDOW (child);
2669 old_size = width_p ? XFASTINT (c->total_cols) : XFASTINT (c->total_lines);
2670 new_size = old_size;
2671
2672 /* The top or left edge position of this child equals the
2673 bottom or right edge of its predecessor. */
2674 if (width_p)
2675 c->left_col = make_number (last_pos);
2676 else
2677 c->top_line = make_number (last_pos);
2678
2679 /* If this child can be resized, do it. */
2680 if (resize_fixed_p || !window_fixed_size_p (c, width_p, 0))
2681 {
2682 new_size = old_size + each + extra;
2683 extra = 0;
2684 }
2685
2686 /* Set new height. Note that size_window also propagates
2687 edge positions to children, so it's not a no-op if we
2688 didn't change the child's size. */
2689 size_window (child, new_size, width_p, 1);
2690
2691 /* Remember the bottom/right edge position of this child; it
2692 will be used to set the top/left edge of the next child. */
2693 last_pos += new_size;
2694 }
2695
2696 /* We should have covered the parent exactly with child windows. */
2697 xassert (size == last_pos - first_pos);
2698
2699 /* Now delete any children that became too small. */
2700 if (!nodelete_p)
2701 for (child = *forward; !NILP (child); child = c->next)
2702 {
2703 int child_size;
2704 c = XWINDOW (child);
2705 child_size = width_p ? XINT (c->total_cols) : XINT (c->total_lines);
2706 size_window (child, child_size, width_p, 2);
2707 }
2708 }
2709 }
2710
2711 /* Set WINDOW's height to HEIGHT, and recursively change the height of
2712 WINDOW's children. NODELETE non-zero means don't delete windows
2713 that become too small in the process. (The caller should check
2714 later and do so if appropriate.) */
2715
2716 void
2717 set_window_height (window, height, nodelete)
2718 Lisp_Object window;
2719 int height;
2720 int nodelete;
2721 {
2722 size_window (window, height, 0, nodelete);
2723 }
2724
2725
2726 /* Set WINDOW's width to WIDTH, and recursively change the width of
2727 WINDOW's children. NODELETE non-zero means don't delete windows
2728 that become too small in the process. (The caller should check
2729 later and do so if appropriate.) */
2730
2731 void
2732 set_window_width (window, width, nodelete)
2733 Lisp_Object window;
2734 int width;
2735 int nodelete;
2736 {
2737 size_window (window, width, 1, nodelete);
2738 }
2739
2740 /* Change window heights in windows rooted in WINDOW by N lines. */
2741
2742 void
2743 change_window_heights (window, n)
2744 Lisp_Object window;
2745 int n;
2746 {
2747 struct window *w = XWINDOW (window);
2748
2749 XSETFASTINT (w->top_line, XFASTINT (w->top_line) + n);
2750 XSETFASTINT (w->total_lines, XFASTINT (w->total_lines) - n);
2751
2752 if (INTEGERP (w->orig_top_line))
2753 XSETFASTINT (w->orig_top_line, XFASTINT (w->orig_top_line) + n);
2754 if (INTEGERP (w->orig_total_lines))
2755 XSETFASTINT (w->orig_total_lines, XFASTINT (w->orig_total_lines) - n);
2756
2757 /* Handle just the top child in a vertical split. */
2758 if (!NILP (w->vchild))
2759 change_window_heights (w->vchild, n);
2760
2761 /* Adjust all children in a horizontal split. */
2762 for (window = w->hchild; !NILP (window); window = w->next)
2763 {
2764 w = XWINDOW (window);
2765 change_window_heights (window, n);
2766 }
2767 }
2768
2769 \f
2770 int window_select_count;
2771
2772 Lisp_Object
2773 Fset_window_buffer_unwind (obuf)
2774 Lisp_Object obuf;
2775 {
2776 Fset_buffer (obuf);
2777 return Qnil;
2778 }
2779
2780 EXFUN (Fset_window_fringes, 4);
2781 EXFUN (Fset_window_scroll_bars, 4);
2782
2783 /* Make WINDOW display BUFFER as its contents. RUN_HOOKS_P non-zero
2784 means it's allowed to run hooks. See make_frame for a case where
2785 it's not allowed. KEEP_MARGINS_P non-zero means that the current
2786 margins, fringes, and scroll-bar settings of the window are not
2787 reset from the buffer's local settings. */
2788
2789 void
2790 set_window_buffer (window, buffer, run_hooks_p, keep_margins_p)
2791 Lisp_Object window, buffer;
2792 int run_hooks_p, keep_margins_p;
2793 {
2794 struct window *w = XWINDOW (window);
2795 struct buffer *b = XBUFFER (buffer);
2796 int count = SPECPDL_INDEX ();
2797
2798 w->buffer = buffer;
2799
2800 if (EQ (window, selected_window))
2801 b->last_selected_window = window;
2802
2803 /* Update time stamps of buffer display. */
2804 if (INTEGERP (b->display_count))
2805 XSETINT (b->display_count, XINT (b->display_count) + 1);
2806 b->display_time = Fcurrent_time ();
2807
2808 XSETFASTINT (w->window_end_pos, 0);
2809 XSETFASTINT (w->window_end_vpos, 0);
2810 bzero (&w->last_cursor, sizeof w->last_cursor);
2811 w->window_end_valid = Qnil;
2812 w->hscroll = w->min_hscroll = make_number (0);
2813 w->vscroll = 0;
2814 set_marker_both (w->pointm, buffer, BUF_PT (b), BUF_PT_BYTE (b));
2815 set_marker_restricted (w->start,
2816 make_number (b->last_window_start),
2817 buffer);
2818 w->start_at_line_beg = Qnil;
2819 w->force_start = Qnil;
2820 XSETFASTINT (w->last_modified, 0);
2821 XSETFASTINT (w->last_overlay_modified, 0);
2822 windows_or_buffers_changed++;
2823
2824 /* We must select BUFFER for running the window-scroll-functions.
2825 If WINDOW is selected, switch permanently.
2826 Otherwise, switch but go back to the ambient buffer afterward. */
2827 if (EQ (window, selected_window))
2828 Fset_buffer (buffer);
2829 /* We can't check ! NILP (Vwindow_scroll_functions) here
2830 because that might itself be a local variable. */
2831 else if (window_initialized)
2832 {
2833 record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ());
2834 Fset_buffer (buffer);
2835 }
2836
2837 if (!keep_margins_p)
2838 {
2839 /* Set left and right marginal area width etc. from buffer. */
2840
2841 /* This may call adjust_window_margins three times, so
2842 temporarily disable window margins. */
2843 w->left_margin_cols = w->right_margin_cols = Qnil;
2844
2845 Fset_window_fringes (window,
2846 b->left_fringe_width, b->right_fringe_width,
2847 b->fringes_outside_margins);
2848
2849 Fset_window_scroll_bars (window,
2850 b->scroll_bar_width,
2851 b->vertical_scroll_bar_type, Qnil);
2852
2853 Fset_window_margins (window,
2854 b->left_margin_cols, b->right_margin_cols);
2855 }
2856
2857 if (run_hooks_p)
2858 {
2859 if (! NILP (Vwindow_scroll_functions))
2860 run_hook_with_args_2 (Qwindow_scroll_functions, window,
2861 Fmarker_position (w->start));
2862
2863 if (! NILP (Vwindow_configuration_change_hook)
2864 && ! NILP (Vrun_hooks))
2865 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
2866 }
2867
2868 unbind_to (count, Qnil);
2869 }
2870
2871
2872 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 3, 0,
2873 doc: /* Make WINDOW display BUFFER as its contents.
2874 BUFFER can be a buffer or buffer name.
2875 Optional third arg KEEP_MARGINS non-nil means that WINDOW's current
2876 display margins, fringe widths, and scroll bar settings are maintained;
2877 the default is to reset these from BUFFER's local settings or the frame
2878 defaults. */)
2879 (window, buffer, keep_margins)
2880 register Lisp_Object window, buffer, keep_margins;
2881 {
2882 register Lisp_Object tem;
2883 register struct window *w = decode_window (window);
2884
2885 XSETWINDOW (window, w);
2886 buffer = Fget_buffer (buffer);
2887 CHECK_BUFFER (buffer);
2888
2889 if (NILP (XBUFFER (buffer)->name))
2890 error ("Attempt to display deleted buffer");
2891
2892 tem = w->buffer;
2893 if (NILP (tem))
2894 error ("Window is deleted");
2895 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
2896 is first being set up. */
2897 {
2898 if (!NILP (w->dedicated) && !EQ (tem, buffer))
2899 error ("Window is dedicated to `%s'",
2900 SDATA (XBUFFER (tem)->name));
2901
2902 unshow_buffer (w);
2903 }
2904
2905 set_window_buffer (window, buffer, 1, !NILP (keep_margins));
2906 return Qnil;
2907 }
2908
2909 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 2, 0,
2910 doc: /* Select WINDOW. Most editing will apply to WINDOW's buffer.
2911 If WINDOW is not already selected, also make WINDOW's buffer current.
2912 Also make WINDOW the frame's selected window.
2913 Optional second arg NORECORD non-nil means
2914 do not put this buffer at the front of the list of recently selected ones.
2915
2916 Note that the main editor command loop
2917 selects the buffer of the selected window before each command. */)
2918 (window, norecord)
2919 register Lisp_Object window, norecord;
2920 {
2921 register struct window *w;
2922 register struct window *ow;
2923 struct frame *sf;
2924
2925 CHECK_LIVE_WINDOW (window);
2926
2927 w = XWINDOW (window);
2928 w->frozen_window_start_p = 0;
2929
2930 XSETFASTINT (w->use_time, ++window_select_count);
2931 if (EQ (window, selected_window))
2932 return window;
2933
2934 if (!NILP (selected_window))
2935 {
2936 ow = XWINDOW (selected_window);
2937 if (! NILP (ow->buffer))
2938 set_marker_both (ow->pointm, ow->buffer,
2939 BUF_PT (XBUFFER (ow->buffer)),
2940 BUF_PT_BYTE (XBUFFER (ow->buffer)));
2941 }
2942
2943 selected_window = window;
2944 sf = SELECTED_FRAME ();
2945 if (XFRAME (WINDOW_FRAME (w)) != sf)
2946 {
2947 XFRAME (WINDOW_FRAME (w))->selected_window = window;
2948 /* Use this rather than Fhandle_switch_frame
2949 so that FRAME_FOCUS_FRAME is moved appropriately as we
2950 move around in the state where a minibuffer in a separate
2951 frame is active. */
2952 Fselect_frame (WINDOW_FRAME (w), Qnil);
2953 }
2954 else
2955 sf->selected_window = window;
2956
2957 if (NILP (norecord))
2958 record_buffer (w->buffer);
2959 Fset_buffer (w->buffer);
2960
2961 XBUFFER (w->buffer)->last_selected_window = window;
2962
2963 /* Go to the point recorded in the window.
2964 This is important when the buffer is in more
2965 than one window. It also matters when
2966 redisplay_window has altered point after scrolling,
2967 because it makes the change only in the window. */
2968 {
2969 register int new_point = marker_position (w->pointm);
2970 if (new_point < BEGV)
2971 SET_PT (BEGV);
2972 else if (new_point > ZV)
2973 SET_PT (ZV);
2974 else
2975 SET_PT (new_point);
2976 }
2977
2978 windows_or_buffers_changed++;
2979 return window;
2980 }
2981
2982 static Lisp_Object
2983 select_window_norecord (window)
2984 Lisp_Object window;
2985 {
2986 return Fselect_window (window, Qt);
2987 }
2988 \f
2989 /* Deiconify the frame containing the window WINDOW,
2990 unless it is the selected frame;
2991 then return WINDOW.
2992
2993 The reason for the exception for the selected frame
2994 is that it seems better not to change the selected frames visibility
2995 merely because of displaying a different buffer in it.
2996 The deiconification is useful when a buffer gets shown in
2997 another frame that you were not using lately. */
2998
2999 static Lisp_Object
3000 display_buffer_1 (window)
3001 Lisp_Object window;
3002 {
3003 Lisp_Object frame = XWINDOW (window)->frame;
3004 FRAME_PTR f = XFRAME (frame);
3005
3006 FRAME_SAMPLE_VISIBILITY (f);
3007
3008 if (!EQ (frame, selected_frame))
3009 {
3010 if (FRAME_ICONIFIED_P (f))
3011 Fmake_frame_visible (frame);
3012 else if (FRAME_VISIBLE_P (f))
3013 Fraise_frame (frame);
3014 }
3015
3016 return window;
3017 }
3018
3019 DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0,
3020 doc: /* Returns non-nil if a buffer named BUFFER-NAME would be created specially.
3021 The value is actually t if the frame should be called with default frame
3022 parameters, and a list of frame parameters if they were specified.
3023 See `special-display-buffer-names', and `special-display-regexps'. */)
3024 (buffer_name)
3025 Lisp_Object buffer_name;
3026 {
3027 Lisp_Object tem;
3028
3029 CHECK_STRING (buffer_name);
3030
3031 tem = Fmember (buffer_name, Vspecial_display_buffer_names);
3032 if (!NILP (tem))
3033 return Qt;
3034
3035 tem = Fassoc (buffer_name, Vspecial_display_buffer_names);
3036 if (!NILP (tem))
3037 return XCDR (tem);
3038
3039 for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem))
3040 {
3041 Lisp_Object car = XCAR (tem);
3042 if (STRINGP (car)
3043 && fast_string_match (car, buffer_name) >= 0)
3044 return Qt;
3045 else if (CONSP (car)
3046 && STRINGP (XCAR (car))
3047 && fast_string_match (XCAR (car), buffer_name) >= 0)
3048 return XCDR (car);
3049 }
3050 return Qnil;
3051 }
3052
3053 DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0,
3054 doc: /* Returns non-nil if a new buffer named BUFFER-NAME would use the same window.
3055 See `same-window-buffer-names' and `same-window-regexps'. */)
3056 (buffer_name)
3057 Lisp_Object buffer_name;
3058 {
3059 Lisp_Object tem;
3060
3061 CHECK_STRING (buffer_name);
3062
3063 tem = Fmember (buffer_name, Vsame_window_buffer_names);
3064 if (!NILP (tem))
3065 return Qt;
3066
3067 tem = Fassoc (buffer_name, Vsame_window_buffer_names);
3068 if (!NILP (tem))
3069 return Qt;
3070
3071 for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem))
3072 {
3073 Lisp_Object car = XCAR (tem);
3074 if (STRINGP (car)
3075 && fast_string_match (car, buffer_name) >= 0)
3076 return Qt;
3077 else if (CONSP (car)
3078 && STRINGP (XCAR (car))
3079 && fast_string_match (XCAR (car), buffer_name) >= 0)
3080 return Qt;
3081 }
3082 return Qnil;
3083 }
3084
3085 /* Use B so the default is (other-buffer). */
3086 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 3,
3087 "BDisplay buffer: \nP",
3088 doc: /* Make BUFFER appear in some window but don't select it.
3089 BUFFER can be a buffer or a buffer name.
3090 If BUFFER is shown already in some window, just use that one,
3091 unless the window is the selected window and the optional second
3092 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).
3093 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.
3094 Returns the window displaying BUFFER.
3095 If `display-buffer-reuse-frames' is non-nil, and another frame is currently
3096 displaying BUFFER, then simply raise that frame.
3097
3098 The variables `special-display-buffer-names', `special-display-regexps',
3099 `same-window-buffer-names', and `same-window-regexps' customize how certain
3100 buffer names are handled.
3101
3102 If optional argument FRAME is `visible', search all visible frames.
3103 If FRAME is 0, search all visible and iconified frames.
3104 If FRAME is t, search all frames.
3105 If FRAME is a frame, search only that frame.
3106 If FRAME is nil, search only the selected frame
3107 (actually the last nonminibuffer frame),
3108 unless `pop-up-frames' or `display-buffer-reuse-frames' is non-nil,
3109 which means search visible and iconified frames.
3110
3111 If `even-window-heights' is non-nil, window heights will be evened out
3112 if displaying the buffer causes two vertically adjacent windows to be
3113 displayed. */)
3114 (buffer, not_this_window, frame)
3115 register Lisp_Object buffer, not_this_window, frame;
3116 {
3117 register Lisp_Object window, tem, swp;
3118 struct frame *f;
3119
3120 swp = Qnil;
3121 buffer = Fget_buffer (buffer);
3122 CHECK_BUFFER (buffer);
3123
3124 if (!NILP (Vdisplay_buffer_function))
3125 return call2 (Vdisplay_buffer_function, buffer, not_this_window);
3126
3127 if (NILP (not_this_window)
3128 && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
3129 return display_buffer_1 (selected_window);
3130
3131 /* See if the user has specified this buffer should appear
3132 in the selected window. */
3133 if (NILP (not_this_window))
3134 {
3135 swp = Fsame_window_p (XBUFFER (buffer)->name);
3136 if (!NILP (swp) && !no_switch_window (selected_window))
3137 {
3138 Fswitch_to_buffer (buffer, Qnil);
3139 return display_buffer_1 (selected_window);
3140 }
3141 }
3142
3143 /* If the user wants pop-up-frames or display-buffer-reuse-frames,
3144 look for a window showing BUFFER on any visible or iconified frame.
3145 Otherwise search only the current frame. */
3146 if (! NILP (frame))
3147 tem = frame;
3148 else if (pop_up_frames
3149 || display_buffer_reuse_frames
3150 || last_nonminibuf_frame == 0)
3151 XSETFASTINT (tem, 0);
3152 else
3153 XSETFRAME (tem, last_nonminibuf_frame);
3154
3155 window = Fget_buffer_window (buffer, tem);
3156 if (!NILP (window)
3157 && (NILP (not_this_window) || !EQ (window, selected_window)))
3158 return display_buffer_1 (window);
3159
3160 /* Certain buffer names get special handling. */
3161 if (!NILP (Vspecial_display_function) && NILP (swp))
3162 {
3163 tem = Fspecial_display_p (XBUFFER (buffer)->name);
3164 if (EQ (tem, Qt))
3165 return call1 (Vspecial_display_function, buffer);
3166 if (CONSP (tem))
3167 return call2 (Vspecial_display_function, buffer, tem);
3168 }
3169
3170 /* If there are no frames open that have more than a minibuffer,
3171 we need to create a new frame. */
3172 if (pop_up_frames || last_nonminibuf_frame == 0)
3173 {
3174 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3175 Fset_window_buffer (window, buffer, Qnil);
3176 return display_buffer_1 (window);
3177 }
3178
3179 f = SELECTED_FRAME ();
3180 if (pop_up_windows
3181 || FRAME_MINIBUF_ONLY_P (f)
3182 /* If the current frame is a special display frame,
3183 don't try to reuse its windows. */
3184 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (f))->dedicated))
3185 {
3186 Lisp_Object frames;
3187
3188 frames = Qnil;
3189 if (FRAME_MINIBUF_ONLY_P (f))
3190 XSETFRAME (frames, last_nonminibuf_frame);
3191 /* Don't try to create a window if we would get an error. */
3192 if (split_height_threshold < window_min_height << 1)
3193 split_height_threshold = window_min_height << 1;
3194
3195 /* Note that both Fget_largest_window and Fget_lru_window
3196 ignore minibuffers and dedicated windows.
3197 This means they can return nil. */
3198
3199 /* If the frame we would try to split cannot be split,
3200 try other frames. */
3201 if (FRAME_NO_SPLIT_P (NILP (frames) ? f : last_nonminibuf_frame))
3202 {
3203 /* Try visible frames first. */
3204 window = Fget_largest_window (Qvisible);
3205 /* If that didn't work, try iconified frames. */
3206 if (NILP (window))
3207 window = Fget_largest_window (make_number (0));
3208 if (NILP (window))
3209 window = Fget_largest_window (Qt);
3210 }
3211 else
3212 window = Fget_largest_window (frames);
3213
3214 /* If we got a tall enough full-width window that can be split,
3215 split it. */
3216 if (!NILP (window)
3217 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3218 && window_height (window) >= split_height_threshold
3219 && WINDOW_FULL_WIDTH_P (XWINDOW (window)))
3220 window = Fsplit_window (window, Qnil, Qnil);
3221 else
3222 {
3223 Lisp_Object upper, lower, other;
3224
3225 window = Fget_lru_window (frames);
3226 /* If the LRU window is selected, and big enough,
3227 and can be split, split it. */
3228 if (!NILP (window)
3229 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
3230 && (EQ (window, selected_window)
3231 || EQ (XWINDOW (window)->parent, Qnil))
3232 && window_height (window) >= window_min_height << 1)
3233 window = Fsplit_window (window, Qnil, Qnil);
3234 /* If Fget_lru_window returned nil, try other approaches. */
3235
3236 /* Try visible frames first. */
3237 if (NILP (window))
3238 window = Fget_buffer_window (buffer, Qvisible);
3239 if (NILP (window))
3240 window = Fget_largest_window (Qvisible);
3241 /* If that didn't work, try iconified frames. */
3242 if (NILP (window))
3243 window = Fget_buffer_window (buffer, make_number (0));
3244 if (NILP (window))
3245 window = Fget_largest_window (make_number (0));
3246 /* Try invisible frames. */
3247 if (NILP (window))
3248 window = Fget_buffer_window (buffer, Qt);
3249 if (NILP (window))
3250 window = Fget_largest_window (Qt);
3251 /* As a last resort, make a new frame. */
3252 if (NILP (window))
3253 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
3254 /* If window appears above or below another,
3255 even out their heights. */
3256 other = upper = lower = Qnil;
3257 if (!NILP (XWINDOW (window)->prev))
3258 other = upper = XWINDOW (window)->prev, lower = window;
3259 if (!NILP (XWINDOW (window)->next))
3260 other = lower = XWINDOW (window)->next, upper = window;
3261 if (!NILP (other)
3262 && !NILP (Veven_window_heights)
3263 /* Check that OTHER and WINDOW are vertically arrayed. */
3264 && !EQ (XWINDOW (other)->top_line, XWINDOW (window)->top_line)
3265 && (XFASTINT (XWINDOW (other)->total_lines)
3266 > XFASTINT (XWINDOW (window)->total_lines)))
3267 {
3268 int total = (XFASTINT (XWINDOW (other)->total_lines)
3269 + XFASTINT (XWINDOW (window)->total_lines));
3270 enlarge_window (upper,
3271 total / 2 - XFASTINT (XWINDOW (upper)->total_lines),
3272 0, 0);
3273 }
3274 }
3275 }
3276 else
3277 window = Fget_lru_window (Qnil);
3278
3279 Fset_window_buffer (window, buffer, Qnil);
3280 return display_buffer_1 (window);
3281 }
3282
3283 void
3284 temp_output_buffer_show (buf)
3285 register Lisp_Object buf;
3286 {
3287 register struct buffer *old = current_buffer;
3288 register Lisp_Object window;
3289 register struct window *w;
3290
3291 XBUFFER (buf)->directory = current_buffer->directory;
3292
3293 Fset_buffer (buf);
3294 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
3295 BEGV = BEG;
3296 ZV = Z;
3297 SET_PT (BEG);
3298 #if 0 /* rms: there should be no reason for this. */
3299 XBUFFER (buf)->prevent_redisplay_optimizations_p = 1;
3300 #endif
3301 set_buffer_internal (old);
3302
3303 if (!EQ (Vtemp_buffer_show_function, Qnil))
3304 call1 (Vtemp_buffer_show_function, buf);
3305 else
3306 {
3307 window = Fdisplay_buffer (buf, Qnil, Qnil);
3308
3309 if (!EQ (XWINDOW (window)->frame, selected_frame))
3310 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
3311 Vminibuf_scroll_window = window;
3312 w = XWINDOW (window);
3313 XSETFASTINT (w->hscroll, 0);
3314 XSETFASTINT (w->min_hscroll, 0);
3315 set_marker_restricted_both (w->start, buf, 1, 1);
3316 set_marker_restricted_both (w->pointm, buf, 1, 1);
3317
3318 /* Run temp-buffer-show-hook, with the chosen window selected
3319 and its buffer current. */
3320 if (!NILP (Vrun_hooks))
3321 {
3322 Lisp_Object tem;
3323 tem = Fboundp (Qtemp_buffer_show_hook);
3324 if (!NILP (tem))
3325 {
3326 tem = Fsymbol_value (Qtemp_buffer_show_hook);
3327 if (!NILP (tem))
3328 {
3329 int count = SPECPDL_INDEX ();
3330 Lisp_Object prev_window, prev_buffer;
3331 prev_window = selected_window;
3332 XSETBUFFER (prev_buffer, old);
3333
3334 /* Select the window that was chosen, for running the hook.
3335 Note: Both Fselect_window and select_window_norecord may
3336 set-buffer to the buffer displayed in the window,
3337 so we need to save the current buffer. --stef */
3338 record_unwind_protect (Fset_buffer, prev_buffer);
3339 record_unwind_protect (select_window_norecord, prev_window);
3340 Fselect_window (window, Qt);
3341 Fset_buffer (w->buffer);
3342 call1 (Vrun_hooks, Qtemp_buffer_show_hook);
3343 unbind_to (count, Qnil);
3344 }
3345 }
3346 }
3347 }
3348 }
3349 \f
3350 static void
3351 make_dummy_parent (window)
3352 Lisp_Object window;
3353 {
3354 Lisp_Object new;
3355 register struct window *o, *p;
3356 int i;
3357
3358 o = XWINDOW (window);
3359 p = allocate_window ();
3360 for (i = 0; i < VECSIZE (struct window); ++i)
3361 ((struct Lisp_Vector *) p)->contents[i]
3362 = ((struct Lisp_Vector *)o)->contents[i];
3363 XSETWINDOW (new, p);
3364
3365 XSETFASTINT (p->sequence_number, ++sequence_number);
3366
3367 /* Put new into window structure in place of window */
3368 replace_window (window, new);
3369
3370 o->next = Qnil;
3371 o->prev = Qnil;
3372 o->vchild = Qnil;
3373 o->hchild = Qnil;
3374 o->parent = new;
3375
3376 p->start = Qnil;
3377 p->pointm = Qnil;
3378 p->buffer = Qnil;
3379 }
3380
3381 DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
3382 doc: /* Split WINDOW, putting SIZE lines in the first of the pair.
3383 WINDOW defaults to selected one and SIZE to half its size.
3384 If optional third arg HORFLAG is non-nil, split side by side
3385 and put SIZE columns in the first of the pair. In that case,
3386 SIZE includes that window's scroll bar, or the divider column to its right. */)
3387 (window, size, horflag)
3388 Lisp_Object window, size, horflag;
3389 {
3390 register Lisp_Object new;
3391 register struct window *o, *p;
3392 FRAME_PTR fo;
3393 register int size_int;
3394
3395 if (NILP (window))
3396 window = selected_window;
3397 else
3398 CHECK_LIVE_WINDOW (window);
3399
3400 o = XWINDOW (window);
3401 fo = XFRAME (WINDOW_FRAME (o));
3402
3403 if (NILP (size))
3404 {
3405 if (!NILP (horflag))
3406 /* Calculate the size of the left-hand window, by dividing
3407 the usable space in columns by two.
3408 We round up, since the left-hand window may include
3409 a dividing line, while the right-hand may not. */
3410 size_int = (XFASTINT (o->total_cols) + 1) >> 1;
3411 else
3412 size_int = XFASTINT (o->total_lines) >> 1;
3413 }
3414 else
3415 {
3416 CHECK_NUMBER (size);
3417 size_int = XINT (size);
3418 }
3419
3420 if (MINI_WINDOW_P (o))
3421 error ("Attempt to split minibuffer window");
3422 else if (window_fixed_size_p (o, !NILP (horflag), 0))
3423 error ("Attempt to split fixed-size window");
3424
3425 check_min_window_sizes ();
3426
3427 if (NILP (horflag))
3428 {
3429 if (size_int < window_min_height)
3430 error ("Window height %d too small (after splitting)", size_int);
3431 if (size_int + window_min_height > XFASTINT (o->total_lines))
3432 error ("Window height %d too small (after splitting)",
3433 XFASTINT (o->total_lines) - size_int);
3434 if (NILP (o->parent)
3435 || NILP (XWINDOW (o->parent)->vchild))
3436 {
3437 make_dummy_parent (window);
3438 new = o->parent;
3439 XWINDOW (new)->vchild = window;
3440 }
3441 }
3442 else
3443 {
3444 if (size_int < window_min_width)
3445 error ("Window width %d too small (after splitting)", size_int);
3446
3447 if (size_int + window_min_width > XFASTINT (o->total_cols))
3448 error ("Window width %d too small (after splitting)",
3449 XFASTINT (o->total_cols) - size_int);
3450 if (NILP (o->parent)
3451 || NILP (XWINDOW (o->parent)->hchild))
3452 {
3453 make_dummy_parent (window);
3454 new = o->parent;
3455 XWINDOW (new)->hchild = window;
3456 }
3457 }
3458
3459 /* Now we know that window's parent is a vertical combination
3460 if we are dividing vertically, or a horizontal combination
3461 if we are making side-by-side windows */
3462
3463 windows_or_buffers_changed++;
3464 FRAME_WINDOW_SIZES_CHANGED (fo) = 1;
3465 new = make_window ();
3466 p = XWINDOW (new);
3467
3468 p->frame = o->frame;
3469 p->next = o->next;
3470 if (!NILP (p->next))
3471 XWINDOW (p->next)->prev = new;
3472 p->prev = window;
3473 o->next = new;
3474 p->parent = o->parent;
3475 p->buffer = Qt;
3476 p->window_end_valid = Qnil;
3477 bzero (&p->last_cursor, sizeof p->last_cursor);
3478
3479 /* Duplicate special geometry settings. */
3480
3481 p->left_margin_cols = o->left_margin_cols;
3482 p->right_margin_cols = o->right_margin_cols;
3483 p->left_fringe_width = o->left_fringe_width;
3484 p->right_fringe_width = o->right_fringe_width;
3485 p->fringes_outside_margins = o->fringes_outside_margins;
3486 p->scroll_bar_width = o->scroll_bar_width;
3487 p->vertical_scroll_bar_type = o->vertical_scroll_bar_type;
3488
3489 /* Apportion the available frame space among the two new windows */
3490
3491 if (!NILP (horflag))
3492 {
3493 p->total_lines = o->total_lines;
3494 p->top_line = o->top_line;
3495 XSETFASTINT (p->total_cols, XFASTINT (o->total_cols) - size_int);
3496 XSETFASTINT (o->total_cols, size_int);
3497 XSETFASTINT (p->left_col, XFASTINT (o->left_col) + size_int);
3498 adjust_window_margins (p);
3499 adjust_window_margins (o);
3500 }
3501 else
3502 {
3503 p->left_col = o->left_col;
3504 p->total_cols = o->total_cols;
3505 XSETFASTINT (p->total_lines, XFASTINT (o->total_lines) - size_int);
3506 XSETFASTINT (o->total_lines, size_int);
3507 XSETFASTINT (p->top_line, XFASTINT (o->top_line) + size_int);
3508 }
3509
3510 /* Adjust glyph matrices. */
3511 adjust_glyphs (fo);
3512
3513 Fset_window_buffer (new, o->buffer, Qt);
3514 return new;
3515 }
3516 \f
3517 DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 3, "p",
3518 doc: /* Make current window ARG lines bigger.
3519 From program, optional second arg non-nil means grow sideways ARG columns.
3520 Interactively, if an argument is not given, make the window one line bigger.
3521
3522 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3523 of the siblings above or to the left of the selected window. Only
3524 siblings to the right or below are changed. */)
3525 (arg, side, preserve_before)
3526 register Lisp_Object arg, side, preserve_before;
3527 {
3528 CHECK_NUMBER (arg);
3529 enlarge_window (selected_window, XINT (arg), !NILP (side),
3530 !NILP (preserve_before));
3531
3532 if (! NILP (Vwindow_configuration_change_hook))
3533 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3534
3535 return Qnil;
3536 }
3537
3538 DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 3, "p",
3539 doc: /* Make current window ARG lines smaller.
3540 From program, optional second arg non-nil means shrink sideways arg columns.
3541 Interactively, if an argument is not given, make the window one line smaller.
3542
3543 Optional third arg PRESERVE-BEFORE, if non-nil, means do not change the size
3544 of the siblings above or to the left of the selected window. Only
3545 siblings to the right or below are changed. */)
3546 (arg, side, preserve_before)
3547 register Lisp_Object arg, side, preserve_before;
3548 {
3549 CHECK_NUMBER (arg);
3550 enlarge_window (selected_window, -XINT (arg), !NILP (side),
3551 !NILP (preserve_before));
3552
3553 if (! NILP (Vwindow_configuration_change_hook))
3554 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3555
3556 return Qnil;
3557 }
3558
3559 int
3560 window_height (window)
3561 Lisp_Object window;
3562 {
3563 register struct window *p = XWINDOW (window);
3564 return WINDOW_TOTAL_LINES (p);
3565 }
3566
3567 int
3568 window_width (window)
3569 Lisp_Object window;
3570 {
3571 register struct window *p = XWINDOW (window);
3572 return WINDOW_TOTAL_COLS (p);
3573 }
3574
3575
3576 #define CURBEG(w) \
3577 *(widthflag ? &(XWINDOW (w)->left_col) : &(XWINDOW (w)->top_line))
3578
3579 #define CURSIZE(w) \
3580 *(widthflag ? &(XWINDOW (w)->total_cols) : &(XWINDOW (w)->total_lines))
3581
3582
3583 /* Enlarge WINDOW by DELTA. WIDTHFLAG non-zero means
3584 increase its width. Siblings of the selected window are resized to
3585 fulfill the size request. If they become too small in the process,
3586 they will be deleted.
3587
3588 If PRESERVE_BEFORE is nonzero, that means don't alter
3589 the siblings to the left or above WINDOW. */
3590
3591 static void
3592 enlarge_window (window, delta, widthflag, preserve_before)
3593 Lisp_Object window;
3594 int delta, widthflag, preserve_before;
3595 {
3596 Lisp_Object parent, next, prev;
3597 struct window *p;
3598 Lisp_Object *sizep;
3599 int maximum;
3600 int (*sizefun) P_ ((Lisp_Object))
3601 = widthflag ? window_width : window_height;
3602 void (*setsizefun) P_ ((Lisp_Object, int, int))
3603 = (widthflag ? set_window_width : set_window_height);
3604
3605 /* Check values of window_min_width and window_min_height for
3606 validity. */
3607 check_min_window_sizes ();
3608
3609 /* Give up if this window cannot be resized. */
3610 if (window_fixed_size_p (XWINDOW (window), widthflag, 1))
3611 error ("Window is not resizable");
3612
3613 /* Find the parent of the selected window. */
3614 while (1)
3615 {
3616 p = XWINDOW (window);
3617 parent = p->parent;
3618
3619 if (NILP (parent))
3620 {
3621 if (widthflag)
3622 error ("No other window to side of this one");
3623 break;
3624 }
3625
3626 if (widthflag
3627 ? !NILP (XWINDOW (parent)->hchild)
3628 : !NILP (XWINDOW (parent)->vchild))
3629 break;
3630
3631 window = parent;
3632 }
3633
3634 sizep = &CURSIZE (window);
3635
3636 {
3637 register int maxdelta;
3638
3639 /* Compute the maximum size increment this window can have. */
3640
3641 if (preserve_before)
3642 {
3643 if (!NILP (parent))
3644 {
3645 maxdelta = (*sizefun) (parent) - XINT (*sizep);
3646 /* Subtract size of siblings before, since we can't take that. */
3647 maxdelta -= XINT (CURBEG (window)) - XINT (CURBEG (parent));
3648 }
3649 else
3650 maxdelta = (!NILP (p->next) ? ((*sizefun) (p->next)
3651 - window_min_size (XWINDOW (p->next),
3652 widthflag, 0, 0))
3653 : (delta = 0));
3654 }
3655 else
3656 maxdelta = (!NILP (parent) ? (*sizefun) (parent) - XINT (*sizep)
3657 /* This is a main window followed by a minibuffer. */
3658 : !NILP (p->next) ? ((*sizefun) (p->next)
3659 - window_min_size (XWINDOW (p->next),
3660 widthflag, 0, 0))
3661 /* This is a minibuffer following a main window. */
3662 : !NILP (p->prev) ? ((*sizefun) (p->prev)
3663 - window_min_size (XWINDOW (p->prev),
3664 widthflag, 0, 0))
3665 /* This is a frame with only one window, a minibuffer-only
3666 or a minibufferless frame. */
3667 : (delta = 0));
3668
3669 if (delta > maxdelta)
3670 /* This case traps trying to make the minibuffer
3671 the full frame, or make the only window aside from the
3672 minibuffer the full frame. */
3673 delta = maxdelta;
3674 }
3675
3676 if (XINT (*sizep) + delta < window_min_size (XWINDOW (window), widthflag, 0, 0))
3677 {
3678 delete_window (window);
3679 return;
3680 }
3681
3682 if (delta == 0)
3683 return;
3684
3685 /* Find the total we can get from other siblings without deleting them. */
3686 maximum = 0;
3687 for (next = p->next; ! NILP (next); next = XWINDOW (next)->next)
3688 maximum += (*sizefun) (next) - window_min_size (XWINDOW (next),
3689 widthflag, 0, 0);
3690 if (! preserve_before)
3691 for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev)
3692 maximum += (*sizefun) (prev) - window_min_size (XWINDOW (prev),
3693 widthflag, 0, 0);
3694
3695 /* If we can get it all from them without deleting them, do so. */
3696 if (delta <= maximum)
3697 {
3698 Lisp_Object first_unaffected;
3699 Lisp_Object first_affected;
3700 int fixed_p;
3701
3702 next = p->next;
3703 prev = p->prev;
3704 first_affected = window;
3705 /* Look at one sibling at a time,
3706 moving away from this window in both directions alternately,
3707 and take as much as we can get without deleting that sibling. */
3708 while (delta != 0
3709 && (!NILP (next) || (!preserve_before && !NILP (prev))))
3710 {
3711 if (! NILP (next))
3712 {
3713 int this_one = ((*sizefun) (next)
3714 - window_min_size (XWINDOW (next),
3715 widthflag, 0, &fixed_p));
3716 if (!fixed_p)
3717 {
3718 if (this_one > delta)
3719 this_one = delta;
3720
3721 (*setsizefun) (next, (*sizefun) (next) - this_one, 0);
3722 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
3723
3724 delta -= this_one;
3725 }
3726
3727 next = XWINDOW (next)->next;
3728 }
3729
3730 if (delta == 0)
3731 break;
3732
3733 if (!preserve_before && ! NILP (prev))
3734 {
3735 int this_one = ((*sizefun) (prev)
3736 - window_min_size (XWINDOW (prev),
3737 widthflag, 0, &fixed_p));
3738 if (!fixed_p)
3739 {
3740 if (this_one > delta)
3741 this_one = delta;
3742
3743 first_affected = prev;
3744
3745 (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0);
3746 (*setsizefun) (window, XINT (*sizep) + this_one, 0);
3747
3748 delta -= this_one;
3749 }
3750
3751 prev = XWINDOW (prev)->prev;
3752 }
3753 }
3754
3755 xassert (delta == 0);
3756
3757 /* Now recalculate the edge positions of all the windows affected,
3758 based on the new sizes. */
3759 first_unaffected = next;
3760 prev = first_affected;
3761 for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected);
3762 prev = next, next = XWINDOW (next)->next)
3763 {
3764 XSETINT (CURBEG (next), XINT (CURBEG (prev)) + (*sizefun) (prev));
3765 /* This does not change size of NEXT,
3766 but it propagates the new top edge to its children */
3767 (*setsizefun) (next, (*sizefun) (next), 0);
3768 }
3769 }
3770 else
3771 {
3772 register int delta1;
3773 register int opht = (*sizefun) (parent);
3774
3775 if (opht <= XINT (*sizep) + delta)
3776 {
3777 /* If trying to grow this window to or beyond size of the parent,
3778 just delete all the sibling windows. */
3779 Lisp_Object start, tem, next;
3780
3781 start = XWINDOW (parent)->vchild;
3782 if (NILP (start))
3783 start = XWINDOW (parent)->hchild;
3784
3785 /* Delete any siblings that come after WINDOW. */
3786 tem = XWINDOW (window)->next;
3787 while (! NILP (tem))
3788 {
3789 next = XWINDOW (tem)->next;
3790 delete_window (tem);
3791 tem = next;
3792 }
3793
3794 /* Delete any siblings that come after WINDOW.
3795 Note that if START is not WINDOW, then WINDOW still
3796 Fhas siblings, so WINDOW has not yet replaced its parent. */
3797 tem = start;
3798 while (! EQ (tem, window))
3799 {
3800 next = XWINDOW (tem)->next;
3801 delete_window (tem);
3802 tem = next;
3803 }
3804 }
3805 else
3806 {
3807 /* Otherwise, make delta1 just right so that if we add
3808 delta1 lines to this window and to the parent, and then
3809 shrink the parent back to its original size, the new
3810 proportional size of this window will increase by delta.
3811
3812 The function size_window will compute the new height h'
3813 of the window from delta1 as:
3814
3815 e = delta1/n
3816 x = delta1 - delta1/n * n for the 1st resizable child
3817 h' = h + e + x
3818
3819 where n is the number of children that can be resized.
3820 We can ignore x by choosing a delta1 that is a multiple of
3821 n. We want the height of this window to come out as
3822
3823 h' = h + delta
3824
3825 So, delta1 must be
3826
3827 h + e = h + delta
3828 delta1/n = delta
3829 delta1 = n * delta.
3830
3831 The number of children n equals the number of resizable
3832 children of this window + 1 because we know window itself
3833 is resizable (otherwise we would have signalled an error. */
3834
3835 struct window *w = XWINDOW (window);
3836 Lisp_Object s;
3837 int n = 1;
3838
3839 for (s = w->next; !NILP (s); s = XWINDOW (s)->next)
3840 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
3841 ++n;
3842 for (s = w->prev; !NILP (s); s = XWINDOW (s)->prev)
3843 if (!window_fixed_size_p (XWINDOW (s), widthflag, 0))
3844 ++n;
3845
3846 delta1 = n * delta;
3847
3848 /* Add delta1 lines or columns to this window, and to the parent,
3849 keeping things consistent while not affecting siblings. */
3850 XSETINT (CURSIZE (parent), opht + delta1);
3851 (*setsizefun) (window, XINT (*sizep) + delta1, 0);
3852
3853 /* Squeeze out delta1 lines or columns from our parent,
3854 shriking this window and siblings proportionately.
3855 This brings parent back to correct size.
3856 Delta1 was calculated so this makes this window the desired size,
3857 taking it all out of the siblings. */
3858 (*setsizefun) (parent, opht, 0);
3859
3860 }
3861 }
3862
3863 XSETFASTINT (p->last_modified, 0);
3864 XSETFASTINT (p->last_overlay_modified, 0);
3865
3866 /* Adjust glyph matrices. */
3867 adjust_glyphs (XFRAME (WINDOW_FRAME (XWINDOW (window))));
3868 }
3869
3870 #undef CURBEG
3871 #undef CURSIZE
3872
3873
3874 \f
3875 /***********************************************************************
3876 Resizing Mini-Windows
3877 ***********************************************************************/
3878
3879 static void shrink_window_lowest_first P_ ((struct window *, int));
3880
3881 enum save_restore_action
3882 {
3883 CHECK_ORIG_SIZES,
3884 SAVE_ORIG_SIZES,
3885 RESTORE_ORIG_SIZES
3886 };
3887
3888 static int save_restore_orig_size P_ ((struct window *,
3889 enum save_restore_action));
3890
3891 /* Shrink windows rooted in window W to HEIGHT. Take the space needed
3892 from lowest windows first. */
3893
3894 static void
3895 shrink_window_lowest_first (w, height)
3896 struct window *w;
3897 int height;
3898 {
3899 struct window *c;
3900 Lisp_Object child;
3901 int old_height;
3902
3903 xassert (!MINI_WINDOW_P (w));
3904
3905 /* Set redisplay hints. */
3906 XSETFASTINT (w->last_modified, 0);
3907 XSETFASTINT (w->last_overlay_modified, 0);
3908 windows_or_buffers_changed++;
3909 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
3910
3911 old_height = XFASTINT (w->total_lines);
3912 XSETFASTINT (w->total_lines, height);
3913
3914 if (!NILP (w->hchild))
3915 {
3916 for (child = w->hchild; !NILP (child); child = c->next)
3917 {
3918 c = XWINDOW (child);
3919 c->top_line = w->top_line;
3920 shrink_window_lowest_first (c, height);
3921 }
3922 }
3923 else if (!NILP (w->vchild))
3924 {
3925 Lisp_Object last_child;
3926 int delta = old_height - height;
3927 int last_top;
3928
3929 last_child = Qnil;
3930
3931 /* Find the last child. We are taking space from lowest windows
3932 first, so we iterate over children from the last child
3933 backwards. */
3934 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
3935 last_child = child;
3936
3937 /* Assign new heights. We leave only MIN_SAFE_WINDOW_HEIGHT. */
3938 for (child = last_child; delta && !NILP (child); child = c->prev)
3939 {
3940 int this_one;
3941
3942 c = XWINDOW (child);
3943 this_one = XFASTINT (c->total_lines) - MIN_SAFE_WINDOW_HEIGHT;
3944
3945 if (this_one > delta)
3946 this_one = delta;
3947
3948 shrink_window_lowest_first (c, XFASTINT (c->total_lines) - this_one);
3949 delta -= this_one;
3950 }
3951
3952 /* Compute new positions. */
3953 last_top = XINT (w->top_line);
3954 for (child = w->vchild; !NILP (child); child = c->next)
3955 {
3956 c = XWINDOW (child);
3957 c->top_line = make_number (last_top);
3958 shrink_window_lowest_first (c, XFASTINT (c->total_lines));
3959 last_top += XFASTINT (c->total_lines);
3960 }
3961 }
3962 }
3963
3964
3965 /* Save, restore, or check positions and sizes in the window tree
3966 rooted at W. ACTION says what to do.
3967
3968 If ACTION is CHECK_ORIG_SIZES, check if orig_top_line and
3969 orig_total_lines members are valid for all windows in the window
3970 tree. Value is non-zero if they are valid.
3971
3972 If ACTION is SAVE_ORIG_SIZES, save members top and height in
3973 orig_top_line and orig_total_lines for all windows in the tree.
3974
3975 If ACTION is RESTORE_ORIG_SIZES, restore top and height from values
3976 stored in orig_top_line and orig_total_lines for all windows. */
3977
3978 static int
3979 save_restore_orig_size (w, action)
3980 struct window *w;
3981 enum save_restore_action action;
3982 {
3983 int success_p = 1;
3984
3985 while (w)
3986 {
3987 if (!NILP (w->hchild))
3988 {
3989 if (!save_restore_orig_size (XWINDOW (w->hchild), action))
3990 success_p = 0;
3991 }
3992 else if (!NILP (w->vchild))
3993 {
3994 if (!save_restore_orig_size (XWINDOW (w->vchild), action))
3995 success_p = 0;
3996 }
3997
3998 switch (action)
3999 {
4000 case CHECK_ORIG_SIZES:
4001 if (!INTEGERP (w->orig_top_line) || !INTEGERP (w->orig_total_lines))
4002 return 0;
4003 break;
4004
4005 case SAVE_ORIG_SIZES:
4006 w->orig_top_line = w->top_line;
4007 w->orig_total_lines = w->total_lines;
4008 XSETFASTINT (w->last_modified, 0);
4009 XSETFASTINT (w->last_overlay_modified, 0);
4010 break;
4011
4012 case RESTORE_ORIG_SIZES:
4013 xassert (INTEGERP (w->orig_top_line) && INTEGERP (w->orig_total_lines));
4014 w->top_line = w->orig_top_line;
4015 w->total_lines = w->orig_total_lines;
4016 w->orig_total_lines = w->orig_top_line = Qnil;
4017 XSETFASTINT (w->last_modified, 0);
4018 XSETFASTINT (w->last_overlay_modified, 0);
4019 break;
4020
4021 default:
4022 abort ();
4023 }
4024
4025 w = NILP (w->next) ? NULL : XWINDOW (w->next);
4026 }
4027
4028 return success_p;
4029 }
4030
4031
4032 /* Grow mini-window W by DELTA lines, DELTA >= 0, or as much as we can
4033 without deleting other windows. */
4034
4035 void
4036 grow_mini_window (w, delta)
4037 struct window *w;
4038 int delta;
4039 {
4040 struct frame *f = XFRAME (w->frame);
4041 struct window *root;
4042
4043 xassert (MINI_WINDOW_P (w));
4044 xassert (delta >= 0);
4045
4046 /* Check values of window_min_width and window_min_height for
4047 validity. */
4048 check_min_window_sizes ();
4049
4050 /* Compute how much we can enlarge the mini-window without deleting
4051 other windows. */
4052 root = XWINDOW (FRAME_ROOT_WINDOW (f));
4053 if (delta)
4054 {
4055 int min_height = window_min_size (root, 0, 0, 0);
4056 if (XFASTINT (root->total_lines) - delta < min_height)
4057 /* Note that the root window may already be smaller than
4058 min_height. */
4059 delta = max (0, XFASTINT (root->total_lines) - min_height);
4060 }
4061
4062 if (delta)
4063 {
4064 /* Save original window sizes and positions, if not already done. */
4065 if (!save_restore_orig_size (root, CHECK_ORIG_SIZES))
4066 save_restore_orig_size (root, SAVE_ORIG_SIZES);
4067
4068 /* Shrink other windows. */
4069 shrink_window_lowest_first (root, XFASTINT (root->total_lines) - delta);
4070
4071 /* Grow the mini-window. */
4072 w->top_line = make_number (XFASTINT (root->top_line) + XFASTINT (root->total_lines));
4073 w->total_lines = make_number (XFASTINT (w->total_lines) + delta);
4074 XSETFASTINT (w->last_modified, 0);
4075 XSETFASTINT (w->last_overlay_modified, 0);
4076
4077 adjust_glyphs (f);
4078 }
4079 }
4080
4081
4082 /* Shrink mini-window W. If there is recorded info about window sizes
4083 before a call to grow_mini_window, restore recorded window sizes.
4084 Otherwise, if the mini-window is higher than 1 line, resize it to 1
4085 line. */
4086
4087 void
4088 shrink_mini_window (w)
4089 struct window *w;
4090 {
4091 struct frame *f = XFRAME (w->frame);
4092 struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f));
4093
4094 if (save_restore_orig_size (root, CHECK_ORIG_SIZES))
4095 {
4096 save_restore_orig_size (root, RESTORE_ORIG_SIZES);
4097 adjust_glyphs (f);
4098 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
4099 windows_or_buffers_changed = 1;
4100 }
4101 else if (XFASTINT (w->total_lines) > 1)
4102 {
4103 /* Distribute the additional lines of the mini-window
4104 among the other windows. */
4105 Lisp_Object window;
4106 XSETWINDOW (window, w);
4107 enlarge_window (window, 1 - XFASTINT (w->total_lines), 0, 0);
4108 }
4109 }
4110
4111
4112 \f
4113 /* Mark window cursors off for all windows in the window tree rooted
4114 at W by setting their phys_cursor_on_p flag to zero. Called from
4115 xterm.c, e.g. when a frame is cleared and thereby all cursors on
4116 the frame are cleared. */
4117
4118 void
4119 mark_window_cursors_off (w)
4120 struct window *w;
4121 {
4122 while (w)
4123 {
4124 if (!NILP (w->hchild))
4125 mark_window_cursors_off (XWINDOW (w->hchild));
4126 else if (!NILP (w->vchild))
4127 mark_window_cursors_off (XWINDOW (w->vchild));
4128 else
4129 w->phys_cursor_on_p = 0;
4130
4131 w = NILP (w->next) ? 0 : XWINDOW (w->next);
4132 }
4133 }
4134
4135
4136 /* Return number of lines of text (not counting mode lines) in W. */
4137
4138 int
4139 window_internal_height (w)
4140 struct window *w;
4141 {
4142 int ht = XFASTINT (w->total_lines);
4143
4144 if (!MINI_WINDOW_P (w))
4145 {
4146 if (!NILP (w->parent)
4147 || !NILP (w->vchild)
4148 || !NILP (w->hchild)
4149 || !NILP (w->next)
4150 || !NILP (w->prev)
4151 || WINDOW_WANTS_MODELINE_P (w))
4152 --ht;
4153
4154 if (WINDOW_WANTS_HEADER_LINE_P (w))
4155 --ht;
4156 }
4157
4158 return ht;
4159 }
4160
4161
4162 /* Return the number of columns in W.
4163 Don't count columns occupied by scroll bars or the vertical bar
4164 separating W from the sibling to its right. */
4165
4166 int
4167 window_box_text_cols (w)
4168 struct window *w;
4169 {
4170 struct frame *f = XFRAME (WINDOW_FRAME (w));
4171 int width = XINT (w->total_cols);
4172
4173 if (WINDOW_HAS_VERTICAL_SCROLL_BAR (w))
4174 /* Scroll bars occupy a few columns. */
4175 width -= WINDOW_CONFIG_SCROLL_BAR_COLS (w);
4176 else if (!FRAME_WINDOW_P (f)
4177 && !WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
4178 /* The column of `|' characters separating side-by-side windows
4179 occupies one column only. */
4180 width -= 1;
4181
4182 if (FRAME_WINDOW_P (f))
4183 /* On window-systems, fringes and display margins cannot be
4184 used for normal text. */
4185 width -= (WINDOW_FRINGE_COLS (w)
4186 + WINDOW_LEFT_MARGIN_COLS (w)
4187 + WINDOW_RIGHT_MARGIN_COLS (w));
4188
4189 return width;
4190 }
4191
4192 \f
4193 /************************************************************************
4194 Window Scrolling
4195 ***********************************************************************/
4196
4197 /* Scroll contents of window WINDOW up. If WHOLE is non-zero, scroll
4198 N screen-fulls, which is defined as the height of the window minus
4199 next_screen_context_lines. If WHOLE is zero, scroll up N lines
4200 instead. Negative values of N mean scroll down. NOERROR non-zero
4201 means don't signal an error if we try to move over BEGV or ZV,
4202 respectively. */
4203
4204 static void
4205 window_scroll (window, n, whole, noerror)
4206 Lisp_Object window;
4207 int n;
4208 int whole;
4209 int noerror;
4210 {
4211 immediate_quit = 1;
4212
4213 /* If we must, use the pixel-based version which is much slower than
4214 the line-based one but can handle varying line heights. */
4215 if (FRAME_WINDOW_P (XFRAME (XWINDOW (window)->frame)))
4216 window_scroll_pixel_based (window, n, whole, noerror);
4217 else
4218 window_scroll_line_based (window, n, whole, noerror);
4219
4220 immediate_quit = 0;
4221 }
4222
4223
4224 /* Implementation of window_scroll that works based on pixel line
4225 heights. See the comment of window_scroll for parameter
4226 descriptions. */
4227
4228 static void
4229 window_scroll_pixel_based (window, n, whole, noerror)
4230 Lisp_Object window;
4231 int n;
4232 int whole;
4233 int noerror;
4234 {
4235 struct it it;
4236 struct window *w = XWINDOW (window);
4237 struct text_pos start;
4238 Lisp_Object tem;
4239 int this_scroll_margin;
4240 int preserve_y;
4241 /* True if we fiddled the window vscroll field without really scrolling. */
4242 int vscrolled = 0;
4243
4244 SET_TEXT_POS_FROM_MARKER (start, w->start);
4245
4246 /* If PT is not visible in WINDOW, move back one half of
4247 the screen. Allow PT to be partially visible, otherwise
4248 something like (scroll-down 1) with PT in the line before
4249 the partially visible one would recenter. */
4250 tem = Fpos_visible_in_window_p (make_number (PT), window, Qt);
4251 if (NILP (tem))
4252 {
4253 /* Move backward half the height of the window. Performance note:
4254 vmotion used here is about 10% faster, but would give wrong
4255 results for variable height lines. */
4256 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4257 it.current_y = it.last_visible_y;
4258 move_it_vertically (&it, - window_box_height (w) / 2);
4259
4260 /* The function move_iterator_vertically may move over more than
4261 the specified y-distance. If it->w is small, e.g. a
4262 mini-buffer window, we may end up in front of the window's
4263 display area. This is the case when Start displaying at the
4264 start of the line containing PT in this case. */
4265 if (it.current_y <= 0)
4266 {
4267 init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID);
4268 move_it_vertically (&it, 0);
4269 it.current_y = 0;
4270 }
4271
4272 start = it.current.pos;
4273 }
4274
4275 /* If scroll_preserve_screen_position is non-zero, we try to set
4276 point in the same window line as it is now, so get that line. */
4277 if (!NILP (Vscroll_preserve_screen_position))
4278 {
4279 start_display (&it, w, start);
4280 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4281 preserve_y = it.current_y;
4282 }
4283 else
4284 preserve_y = -1;
4285
4286 /* Move iterator it from start the specified distance forward or
4287 backward. The result is the new window start. */
4288 start_display (&it, w, start);
4289 if (whole)
4290 {
4291 int screen_full = (window_box_height (w)
4292 - next_screen_context_lines * FRAME_LINE_HEIGHT (it.f));
4293 int dy = n * screen_full;
4294
4295 /* Note that move_it_vertically always moves the iterator to the
4296 start of a line. So, if the last line doesn't have a newline,
4297 we would end up at the start of the line ending at ZV. */
4298 if (dy <= 0)
4299 move_it_vertically_backward (&it, -dy);
4300 else if (dy > 0)
4301 move_it_to (&it, ZV, -1, it.current_y + dy, -1,
4302 MOVE_TO_POS | MOVE_TO_Y);
4303 }
4304 else
4305 move_it_by_lines (&it, n, 1);
4306
4307 /* We failed if we find ZV is already on the screen (scrolling up,
4308 means there's nothing past the end), or if we can't start any
4309 earlier (scrolling down, means there's nothing past the top). */
4310 if ((n > 0 && IT_CHARPOS (it) == ZV)
4311 || (n < 0 && IT_CHARPOS (it) == CHARPOS (start)))
4312 {
4313 if (IT_CHARPOS (it) == ZV)
4314 {
4315 if (it.current_y < it.last_visible_y
4316 && (it.current_y + it.max_ascent + it.max_descent
4317 >= it.last_visible_y))
4318 {
4319 /* The last line was only partially visible, make it fully
4320 visible. */
4321 w->vscroll = (it.last_visible_y
4322 - it.current_y + it.max_ascent + it.max_descent);
4323 adjust_glyphs (it.f);
4324 }
4325 else if (noerror)
4326 return;
4327 else
4328 Fsignal (Qend_of_buffer, Qnil);
4329 }
4330 else
4331 {
4332 if (w->vscroll != 0)
4333 /* The first line was only partially visible, make it fully
4334 visible. */
4335 w->vscroll = 0;
4336 else if (noerror)
4337 return;
4338 else
4339 Fsignal (Qbeginning_of_buffer, Qnil);
4340 }
4341
4342 /* If control gets here, then we vscrolled. */
4343
4344 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
4345
4346 /* Don't try to change the window start below. */
4347 vscrolled = 1;
4348 }
4349
4350 if (! vscrolled)
4351 {
4352 int pos = IT_CHARPOS (it);
4353 int bytepos;
4354
4355 /* If in the middle of a multi-glyph character move forward to
4356 the next character. */
4357 if (in_display_vector_p (&it))
4358 {
4359 ++pos;
4360 move_it_to (&it, pos, -1, -1, -1, MOVE_TO_POS);
4361 }
4362
4363 /* Set the window start, and set up the window for redisplay. */
4364 set_marker_restricted (w->start, make_number (pos),
4365 w->buffer);
4366 bytepos = XMARKER (w->start)->bytepos;
4367 w->start_at_line_beg = ((pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n')
4368 ? Qt : Qnil);
4369 w->update_mode_line = Qt;
4370 XSETFASTINT (w->last_modified, 0);
4371 XSETFASTINT (w->last_overlay_modified, 0);
4372 /* Set force_start so that redisplay_window will run the
4373 window-scroll-functions. */
4374 w->force_start = Qt;
4375 }
4376
4377 it.current_y = it.vpos = 0;
4378
4379 /* Preserve the screen position if we must. */
4380 if (preserve_y >= 0)
4381 {
4382 move_it_to (&it, -1, -1, preserve_y, -1, MOVE_TO_Y);
4383 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4384 }
4385 else
4386 {
4387 /* Move PT out of scroll margins. */
4388 this_scroll_margin = max (0, scroll_margin);
4389 this_scroll_margin = min (this_scroll_margin, XFASTINT (w->total_lines) / 4);
4390 this_scroll_margin *= FRAME_LINE_HEIGHT (it.f);
4391
4392 if (n > 0)
4393 {
4394 /* We moved the window start towards ZV, so PT may be now
4395 in the scroll margin at the top. */
4396 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4397 while (it.current_y < this_scroll_margin)
4398 {
4399 int prev = it.current_y;
4400 move_it_by_lines (&it, 1, 1);
4401 if (prev == it.current_y)
4402 break;
4403 }
4404 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4405 }
4406 else if (n < 0)
4407 {
4408 int charpos, bytepos;
4409
4410 /* We moved the window start towards BEGV, so PT may be now
4411 in the scroll margin at the bottom. */
4412 move_it_to (&it, PT, -1,
4413 it.last_visible_y - this_scroll_margin - 1, -1,
4414 MOVE_TO_POS | MOVE_TO_Y);
4415
4416 /* Save our position, in case it's correct. */
4417 charpos = IT_CHARPOS (it);
4418 bytepos = IT_BYTEPOS (it);
4419
4420 /* See if point is on a partially visible line at the end. */
4421 move_it_by_lines (&it, 1, 1);
4422 if (it.current_y > it.last_visible_y)
4423 /* The last line was only partially visible, so back up two
4424 lines to make sure we're on a fully visible line. */
4425 {
4426 move_it_by_lines (&it, -2, 0);
4427 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
4428 }
4429 else
4430 /* No, the position we saved is OK, so use it. */
4431 SET_PT_BOTH (charpos, bytepos);
4432 }
4433 }
4434 }
4435
4436
4437 /* Implementation of window_scroll that works based on screen lines.
4438 See the comment of window_scroll for parameter descriptions. */
4439
4440 static void
4441 window_scroll_line_based (window, n, whole, noerror)
4442 Lisp_Object window;
4443 int n;
4444 int whole;
4445 int noerror;
4446 {
4447 register struct window *w = XWINDOW (window);
4448 register int opoint = PT, opoint_byte = PT_BYTE;
4449 register int pos, pos_byte;
4450 register int ht = window_internal_height (w);
4451 register Lisp_Object tem;
4452 int lose;
4453 Lisp_Object bolp;
4454 int startpos;
4455 struct position posit;
4456 int original_vpos;
4457
4458 /* If scrolling screen-fulls, compute the number of lines to
4459 scroll from the window's height. */
4460 if (whole)
4461 n *= max (1, ht - next_screen_context_lines);
4462
4463 startpos = marker_position (w->start);
4464
4465 posit = *compute_motion (startpos, 0, 0, 0,
4466 PT, ht, 0,
4467 window_box_text_cols (w), XINT (w->hscroll),
4468 0, w);
4469 original_vpos = posit.vpos;
4470
4471 XSETFASTINT (tem, PT);
4472 tem = Fpos_visible_in_window_p (tem, window, Qnil);
4473
4474 if (NILP (tem))
4475 {
4476 Fvertical_motion (make_number (- (ht / 2)), window);
4477 startpos = PT;
4478 }
4479
4480 SET_PT (startpos);
4481 lose = n < 0 && PT == BEGV;
4482 Fvertical_motion (make_number (n), window);
4483 pos = PT;
4484 pos_byte = PT_BYTE;
4485 bolp = Fbolp ();
4486 SET_PT_BOTH (opoint, opoint_byte);
4487
4488 if (lose)
4489 {
4490 if (noerror)
4491 return;
4492 else
4493 Fsignal (Qbeginning_of_buffer, Qnil);
4494 }
4495
4496 if (pos < ZV)
4497 {
4498 int this_scroll_margin = scroll_margin;
4499
4500 /* Don't use a scroll margin that is negative or too large. */
4501 if (this_scroll_margin < 0)
4502 this_scroll_margin = 0;
4503
4504 if (XINT (w->total_lines) < 4 * scroll_margin)
4505 this_scroll_margin = XINT (w->total_lines) / 4;
4506
4507 set_marker_restricted_both (w->start, w->buffer, pos, pos_byte);
4508 w->start_at_line_beg = bolp;
4509 w->update_mode_line = Qt;
4510 XSETFASTINT (w->last_modified, 0);
4511 XSETFASTINT (w->last_overlay_modified, 0);
4512 /* Set force_start so that redisplay_window will run
4513 the window-scroll-functions. */
4514 w->force_start = Qt;
4515
4516 if (whole && !NILP (Vscroll_preserve_screen_position))
4517 {
4518 SET_PT_BOTH (pos, pos_byte);
4519 Fvertical_motion (make_number (original_vpos), window);
4520 }
4521 /* If we scrolled forward, put point enough lines down
4522 that it is outside the scroll margin. */
4523 else if (n > 0)
4524 {
4525 int top_margin;
4526
4527 if (this_scroll_margin > 0)
4528 {
4529 SET_PT_BOTH (pos, pos_byte);
4530 Fvertical_motion (make_number (this_scroll_margin), window);
4531 top_margin = PT;
4532 }
4533 else
4534 top_margin = pos;
4535
4536 if (top_margin <= opoint)
4537 SET_PT_BOTH (opoint, opoint_byte);
4538 else if (!NILP (Vscroll_preserve_screen_position))
4539 {
4540 SET_PT_BOTH (pos, pos_byte);
4541 Fvertical_motion (make_number (original_vpos), window);
4542 }
4543 else
4544 SET_PT (top_margin);
4545 }
4546 else if (n < 0)
4547 {
4548 int bottom_margin;
4549
4550 /* If we scrolled backward, put point near the end of the window
4551 but not within the scroll margin. */
4552 SET_PT_BOTH (pos, pos_byte);
4553 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
4554 if (XFASTINT (tem) == ht - this_scroll_margin)
4555 bottom_margin = PT;
4556 else
4557 bottom_margin = PT + 1;
4558
4559 if (bottom_margin > opoint)
4560 SET_PT_BOTH (opoint, opoint_byte);
4561 else
4562 {
4563 if (!NILP (Vscroll_preserve_screen_position))
4564 {
4565 SET_PT_BOTH (pos, pos_byte);
4566 Fvertical_motion (make_number (original_vpos), window);
4567 }
4568 else
4569 Fvertical_motion (make_number (-1), window);
4570 }
4571 }
4572 }
4573 else
4574 {
4575 if (noerror)
4576 return;
4577 else
4578 Fsignal (Qend_of_buffer, Qnil);
4579 }
4580 }
4581
4582
4583 /* Scroll selected_window up or down. If N is nil, scroll a
4584 screen-full which is defined as the height of the window minus
4585 next_screen_context_lines. If N is the symbol `-', scroll.
4586 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll
4587 up. This is the guts of Fscroll_up and Fscroll_down. */
4588
4589 static void
4590 scroll_command (n, direction)
4591 Lisp_Object n;
4592 int direction;
4593 {
4594 int count = SPECPDL_INDEX ();
4595
4596 xassert (abs (direction) == 1);
4597
4598 /* If selected window's buffer isn't current, make it current for
4599 the moment. But don't screw up if window_scroll gets an error. */
4600 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
4601 {
4602 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4603 Fset_buffer (XWINDOW (selected_window)->buffer);
4604
4605 /* Make redisplay consider other windows than just selected_window. */
4606 ++windows_or_buffers_changed;
4607 }
4608
4609 if (NILP (n))
4610 window_scroll (selected_window, direction, 1, 0);
4611 else if (EQ (n, Qminus))
4612 window_scroll (selected_window, -direction, 1, 0);
4613 else
4614 {
4615 n = Fprefix_numeric_value (n);
4616 window_scroll (selected_window, XINT (n) * direction, 0, 0);
4617 }
4618
4619 unbind_to (count, Qnil);
4620 }
4621
4622 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P",
4623 doc: /* Scroll text of current window upward ARG lines; or near full screen if no ARG.
4624 A near full screen is `next-screen-context-lines' less than a full screen.
4625 Negative ARG means scroll downward.
4626 If ARG is the atom `-', scroll downward by nearly full screen.
4627 When calling from a program, supply as argument a number, nil, or `-'. */)
4628 (arg)
4629 Lisp_Object arg;
4630 {
4631 scroll_command (arg, 1);
4632 return Qnil;
4633 }
4634
4635 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P",
4636 doc: /* Scroll text of current window down ARG lines; or near full screen if no ARG.
4637 A near full screen is `next-screen-context-lines' less than a full screen.
4638 Negative ARG means scroll upward.
4639 If ARG is the atom `-', scroll upward by nearly full screen.
4640 When calling from a program, supply as argument a number, nil, or `-'. */)
4641 (arg)
4642 Lisp_Object arg;
4643 {
4644 scroll_command (arg, -1);
4645 return Qnil;
4646 }
4647 \f
4648 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
4649 doc: /* Return the other window for \"other window scroll\" commands.
4650 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4651 specifies the window.
4652 If `other-window-scroll-buffer' is non-nil, a window
4653 showing that buffer is used. */)
4654 ()
4655 {
4656 Lisp_Object window;
4657
4658 if (MINI_WINDOW_P (XWINDOW (selected_window))
4659 && !NILP (Vminibuf_scroll_window))
4660 window = Vminibuf_scroll_window;
4661 /* If buffer is specified, scroll that buffer. */
4662 else if (!NILP (Vother_window_scroll_buffer))
4663 {
4664 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
4665 if (NILP (window))
4666 window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt, Qnil);
4667 }
4668 else
4669 {
4670 /* Nothing specified; look for a neighboring window on the same
4671 frame. */
4672 window = Fnext_window (selected_window, Qnil, Qnil);
4673
4674 if (EQ (window, selected_window))
4675 /* That didn't get us anywhere; look for a window on another
4676 visible frame. */
4677 do
4678 window = Fnext_window (window, Qnil, Qt);
4679 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
4680 && ! EQ (window, selected_window));
4681 }
4682
4683 CHECK_LIVE_WINDOW (window);
4684
4685 if (EQ (window, selected_window))
4686 error ("There is no other window");
4687
4688 return window;
4689 }
4690
4691 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
4692 doc: /* Scroll next window upward ARG lines; or near full screen if no ARG.
4693 A near full screen is `next-screen-context-lines' less than a full screen.
4694 The next window is the one below the current one; or the one at the top
4695 if the current one is at the bottom. Negative ARG means scroll downward.
4696 If ARG is the atom `-', scroll downward by nearly full screen.
4697 When calling from a program, supply as argument a number, nil, or `-'.
4698
4699 If in the minibuffer, `minibuffer-scroll-window' if non-nil
4700 specifies the window to scroll.
4701 If `other-window-scroll-buffer' is non-nil, scroll the window
4702 showing that buffer, popping the buffer up if necessary. */)
4703 (arg)
4704 Lisp_Object arg;
4705 {
4706 Lisp_Object window;
4707 struct window *w;
4708 int count = SPECPDL_INDEX ();
4709
4710 window = Fother_window_for_scrolling ();
4711 w = XWINDOW (window);
4712
4713 /* Don't screw up if window_scroll gets an error. */
4714 record_unwind_protect (save_excursion_restore, save_excursion_save ());
4715 ++windows_or_buffers_changed;
4716
4717 Fset_buffer (w->buffer);
4718 SET_PT (marker_position (w->pointm));
4719
4720 if (NILP (arg))
4721 window_scroll (window, 1, 1, 1);
4722 else if (EQ (arg, Qminus))
4723 window_scroll (window, -1, 1, 1);
4724 else
4725 {
4726 if (CONSP (arg))
4727 arg = Fcar (arg);
4728 CHECK_NUMBER (arg);
4729 window_scroll (window, XINT (arg), 0, 1);
4730 }
4731
4732 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
4733 unbind_to (count, Qnil);
4734
4735 return Qnil;
4736 }
4737 \f
4738 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P",
4739 doc: /* Scroll selected window display ARG columns left.
4740 Default for ARG is window width minus 2.
4741 Value is the total amount of leftward horizontal scrolling in
4742 effect after the change.
4743 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4744 a lower bound for automatic scrolling, i.e. automatic scrolling
4745 will not scroll a window to a column less than the value returned
4746 by this function. */)
4747 (arg)
4748 register Lisp_Object arg;
4749 {
4750 Lisp_Object result;
4751 int hscroll;
4752 struct window *w = XWINDOW (selected_window);
4753
4754 if (NILP (arg))
4755 XSETFASTINT (arg, window_box_text_cols (w) - 2);
4756 else
4757 arg = Fprefix_numeric_value (arg);
4758
4759 hscroll = XINT (w->hscroll) + XINT (arg);
4760 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4761
4762 if (interactive_p (0))
4763 w->min_hscroll = w->hscroll;
4764
4765 return result;
4766 }
4767
4768 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P",
4769 doc: /* Scroll selected window display ARG columns right.
4770 Default for ARG is window width minus 2.
4771 Value is the total amount of leftward horizontal scrolling in
4772 effect after the change.
4773 If `automatic-hscrolling' is non-nil, the argument ARG modifies
4774 a lower bound for automatic scrolling, i.e. automatic scrolling
4775 will not scroll a window to a column less than the value returned
4776 by this function. */)
4777 (arg)
4778 register Lisp_Object arg;
4779 {
4780 Lisp_Object result;
4781 int hscroll;
4782 struct window *w = XWINDOW (selected_window);
4783
4784 if (NILP (arg))
4785 XSETFASTINT (arg, window_box_text_cols (w) - 2);
4786 else
4787 arg = Fprefix_numeric_value (arg);
4788
4789 hscroll = XINT (w->hscroll) - XINT (arg);
4790 result = Fset_window_hscroll (selected_window, make_number (hscroll));
4791
4792 if (interactive_p (0))
4793 w->min_hscroll = w->hscroll;
4794
4795 return result;
4796 }
4797
4798 DEFUN ("minibuffer-selected-window", Fminibuffer_selected_window, Sminibuffer_selected_window, 0, 0, 0,
4799 doc: /* Return the window which was selected when entering the minibuffer.
4800 Returns nil, if current window is not a minibuffer window. */)
4801 ()
4802 {
4803 if (minibuf_level > 0
4804 && MINI_WINDOW_P (XWINDOW (selected_window))
4805 && !NILP (minibuf_selected_window)
4806 && WINDOW_LIVE_P (minibuf_selected_window))
4807 return minibuf_selected_window;
4808
4809 return Qnil;
4810 }
4811
4812 /* Value is the number of lines actually displayed in window W,
4813 as opposed to its height. */
4814
4815 static int
4816 displayed_window_lines (w)
4817 struct window *w;
4818 {
4819 struct it it;
4820 struct text_pos start;
4821 int height = window_box_height (w);
4822 struct buffer *old_buffer;
4823 int bottom_y;
4824
4825 if (XBUFFER (w->buffer) != current_buffer)
4826 {
4827 old_buffer = current_buffer;
4828 set_buffer_internal (XBUFFER (w->buffer));
4829 }
4830 else
4831 old_buffer = NULL;
4832
4833 /* In case W->start is out of the accessible range, do something
4834 reasonable. This happens in Info mode when Info-scroll-down
4835 calls (recenter -1) while W->start is 1. */
4836 if (XMARKER (w->start)->charpos < BEGV)
4837 SET_TEXT_POS (start, BEGV, BEGV_BYTE);
4838 else if (XMARKER (w->start)->charpos > ZV)
4839 SET_TEXT_POS (start, ZV, ZV_BYTE);
4840 else
4841 SET_TEXT_POS_FROM_MARKER (start, w->start);
4842
4843 start_display (&it, w, start);
4844 move_it_vertically (&it, height);
4845 bottom_y = line_bottom_y (&it);
4846
4847 /* rms: On a non-window display,
4848 the value of it.vpos at the bottom of the screen
4849 seems to be 1 larger than window_box_height (w).
4850 This kludge fixes a bug whereby (move-to-window-line -1)
4851 when ZV is on the last screen line
4852 moves to the previous screen line instead of the last one. */
4853 if (! FRAME_WINDOW_P (XFRAME (w->frame)))
4854 height++;
4855
4856 /* Add in empty lines at the bottom of the window. */
4857 if (bottom_y < height)
4858 {
4859 int uy = FRAME_LINE_HEIGHT (it.f);
4860 it.vpos += (height - bottom_y + uy - 1) / uy;
4861 }
4862
4863 if (old_buffer)
4864 set_buffer_internal (old_buffer);
4865
4866 return it.vpos;
4867 }
4868
4869
4870 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
4871 doc: /* Center point in window and redisplay frame.
4872 With prefix argument ARG, recenter putting point on screen line ARG
4873 relative to the current window. If ARG is negative, it counts up from the
4874 bottom of the window. (ARG should be less than the height of the window.)
4875
4876 If ARG is omitted or nil, erase the entire frame and then
4877 redraw with point in the center of the current window.
4878 Just C-u as prefix means put point in the center of the window
4879 and redisplay normally--don't erase and redraw the frame. */)
4880 (arg)
4881 register Lisp_Object arg;
4882 {
4883 struct window *w = XWINDOW (selected_window);
4884 struct buffer *buf = XBUFFER (w->buffer);
4885 struct buffer *obuf = current_buffer;
4886 int center_p = 0;
4887 int charpos, bytepos;
4888
4889 /* If redisplay is suppressed due to an error, try again. */
4890 obuf->display_error_modiff = 0;
4891
4892 if (NILP (arg))
4893 {
4894 int i;
4895
4896 /* Invalidate pixel data calculated for all compositions. */
4897 for (i = 0; i < n_compositions; i++)
4898 composition_table[i]->font = NULL;
4899
4900 Fredraw_frame (w->frame);
4901 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
4902 center_p = 1;
4903 }
4904 else if (CONSP (arg)) /* Just C-u. */
4905 center_p = 1;
4906 else
4907 {
4908 arg = Fprefix_numeric_value (arg);
4909 CHECK_NUMBER (arg);
4910 }
4911
4912 set_buffer_internal (buf);
4913
4914 /* Handle centering on a graphical frame specially. Such frames can
4915 have variable-height lines and centering point on the basis of
4916 line counts would lead to strange effects. */
4917 if (FRAME_WINDOW_P (XFRAME (w->frame)))
4918 {
4919 if (center_p)
4920 {
4921 struct it it;
4922 struct text_pos pt;
4923
4924 SET_TEXT_POS (pt, PT, PT_BYTE);
4925 start_display (&it, w, pt);
4926 move_it_vertically (&it, - window_box_height (w) / 2);
4927 charpos = IT_CHARPOS (it);
4928 bytepos = IT_BYTEPOS (it);
4929 }
4930 else if (XINT (arg) < 0)
4931 {
4932 struct it it;
4933 struct text_pos pt;
4934 int y0, y1, h, nlines;
4935
4936 SET_TEXT_POS (pt, PT, PT_BYTE);
4937 start_display (&it, w, pt);
4938 y0 = it.current_y;
4939
4940 /* The amount of pixels we have to move back is the window
4941 height minus what's displayed in the line containing PT,
4942 and the lines below. */
4943 nlines = - XINT (arg) - 1;
4944 move_it_by_lines (&it, nlines, 1);
4945
4946 y1 = line_bottom_y (&it);
4947
4948 /* If we can't move down NLINES lines because we hit
4949 the end of the buffer, count in some empty lines. */
4950 if (it.vpos < nlines)
4951 y1 += (nlines - it.vpos) * FRAME_LINE_HEIGHT (it.f);
4952
4953 h = window_box_height (w) - (y1 - y0);
4954
4955 start_display (&it, w, pt);
4956 move_it_vertically (&it, - h);
4957 charpos = IT_CHARPOS (it);
4958 bytepos = IT_BYTEPOS (it);
4959 }
4960 else
4961 {
4962 struct position pos;
4963 pos = *vmotion (PT, - XINT (arg), w);
4964 charpos = pos.bufpos;
4965 bytepos = pos.bytepos;
4966 }
4967 }
4968 else
4969 {
4970 struct position pos;
4971 int ht = window_internal_height (w);
4972
4973 if (center_p)
4974 arg = make_number (ht / 2);
4975 else if (XINT (arg) < 0)
4976 arg = make_number (XINT (arg) + ht);
4977
4978 pos = *vmotion (PT, - XINT (arg), w);
4979 charpos = pos.bufpos;
4980 bytepos = pos.bytepos;
4981 }
4982
4983 /* Set the new window start. */
4984 set_marker_both (w->start, w->buffer, charpos, bytepos);
4985 w->window_end_valid = Qnil;
4986
4987 w->optional_new_start = Qt;
4988
4989 if (bytepos == BEGV_BYTE || FETCH_BYTE (bytepos - 1) == '\n')
4990 w->start_at_line_beg = Qt;
4991 else
4992 w->start_at_line_beg = Qnil;
4993
4994 set_buffer_internal (obuf);
4995 return Qnil;
4996 }
4997
4998
4999 DEFUN ("window-text-height", Fwindow_text_height, Swindow_text_height,
5000 0, 1, 0,
5001 doc: /* Return the height in lines of the text display area of WINDOW.
5002 This doesn't include the mode-line (or header-line if any) or any
5003 partial-height lines in the text display area. */)
5004 (window)
5005 Lisp_Object window;
5006 {
5007 struct window *w = decode_window (window);
5008 int pixel_height = window_box_height (w);
5009 int line_height = pixel_height / FRAME_LINE_HEIGHT (XFRAME (w->frame));
5010 return make_number (line_height);
5011 }
5012
5013
5014 \f
5015 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
5016 1, 1, "P",
5017 doc: /* Position point relative to window.
5018 With no argument, position point at center of window.
5019 An argument specifies vertical position within the window;
5020 zero means top of window, negative means relative to bottom of window. */)
5021 (arg)
5022 Lisp_Object arg;
5023 {
5024 struct window *w = XWINDOW (selected_window);
5025 int lines, start;
5026 Lisp_Object window;
5027
5028 window = selected_window;
5029 start = marker_position (w->start);
5030 if (start < BEGV || start > ZV)
5031 {
5032 int height = window_internal_height (w);
5033 Fvertical_motion (make_number (- (height / 2)), window);
5034 set_marker_both (w->start, w->buffer, PT, PT_BYTE);
5035 w->start_at_line_beg = Fbolp ();
5036 w->force_start = Qt;
5037 }
5038 else
5039 Fgoto_char (w->start);
5040
5041 lines = displayed_window_lines (w);
5042 if (NILP (arg))
5043 XSETFASTINT (arg, lines / 2);
5044 else
5045 {
5046 arg = Fprefix_numeric_value (arg);
5047 if (XINT (arg) < 0)
5048 XSETINT (arg, XINT (arg) + lines);
5049 }
5050
5051 /* Skip past a partially visible first line. */
5052 if (w->vscroll)
5053 XSETINT (arg, XINT (arg) + 1);
5054
5055 return Fvertical_motion (arg, window);
5056 }
5057
5058
5059 \f
5060 /***********************************************************************
5061 Window Configuration
5062 ***********************************************************************/
5063
5064 struct save_window_data
5065 {
5066 EMACS_INT size_from_Lisp_Vector_struct;
5067 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5068 Lisp_Object frame_cols, frame_lines, frame_menu_bar_lines;
5069 Lisp_Object frame_tool_bar_lines;
5070 Lisp_Object selected_frame;
5071 Lisp_Object current_window;
5072 Lisp_Object current_buffer;
5073 Lisp_Object minibuf_scroll_window;
5074 Lisp_Object minibuf_selected_window;
5075 Lisp_Object root_window;
5076 Lisp_Object focus_frame;
5077 /* Record the values of window-min-width and window-min-height
5078 so that window sizes remain consistent with them. */
5079 Lisp_Object min_width, min_height;
5080 /* A vector, each of whose elements is a struct saved_window
5081 for one window. */
5082 Lisp_Object saved_windows;
5083 };
5084
5085 /* This is saved as a Lisp_Vector */
5086 struct saved_window
5087 {
5088 /* these first two must agree with struct Lisp_Vector in lisp.h */
5089 EMACS_INT size_from_Lisp_Vector_struct;
5090 struct Lisp_Vector *next_from_Lisp_Vector_struct;
5091
5092 Lisp_Object window;
5093 Lisp_Object buffer, start, pointm, mark;
5094 Lisp_Object left_col, top_line, total_cols, total_lines;
5095 Lisp_Object hscroll, min_hscroll;
5096 Lisp_Object parent, prev;
5097 Lisp_Object start_at_line_beg;
5098 Lisp_Object display_table;
5099 Lisp_Object orig_top_line, orig_total_lines;
5100 Lisp_Object left_margin_cols, right_margin_cols;
5101 Lisp_Object left_fringe_width, right_fringe_width, fringes_outside_margins;
5102 Lisp_Object scroll_bar_width, vertical_scroll_bar_type;
5103 };
5104
5105 #define SAVED_WINDOW_VECTOR_SIZE 24 /* Arg to Fmake_vector */
5106
5107 #define SAVED_WINDOW_N(swv,n) \
5108 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
5109
5110 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
5111 doc: /* Return t if OBJECT is a window-configuration object. */)
5112 (object)
5113 Lisp_Object object;
5114 {
5115 if (WINDOW_CONFIGURATIONP (object))
5116 return Qt;
5117 return Qnil;
5118 }
5119
5120 DEFUN ("window-configuration-frame", Fwindow_configuration_frame, Swindow_configuration_frame, 1, 1, 0,
5121 doc: /* Return the frame that CONFIG, a window-configuration object, is about. */)
5122 (config)
5123 Lisp_Object config;
5124 {
5125 register struct save_window_data *data;
5126 struct Lisp_Vector *saved_windows;
5127
5128 if (! WINDOW_CONFIGURATIONP (config))
5129 wrong_type_argument (Qwindow_configuration_p, config);
5130
5131 data = (struct save_window_data *) XVECTOR (config);
5132 saved_windows = XVECTOR (data->saved_windows);
5133 return XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5134 }
5135
5136 DEFUN ("set-window-configuration", Fset_window_configuration,
5137 Sset_window_configuration, 1, 1, 0,
5138 doc: /* Set the configuration of windows and buffers as specified by CONFIGURATION.
5139 CONFIGURATION must be a value previously returned
5140 by `current-window-configuration' (which see).
5141 If CONFIGURATION was made from a frame that is now deleted,
5142 only frame-independent values can be restored. In this case,
5143 the return value is nil. Otherwise the value is t. */)
5144 (configuration)
5145 Lisp_Object configuration;
5146 {
5147 register struct save_window_data *data;
5148 struct Lisp_Vector *saved_windows;
5149 Lisp_Object new_current_buffer;
5150 Lisp_Object frame;
5151 FRAME_PTR f;
5152 int old_point = -1;
5153
5154 while (!WINDOW_CONFIGURATIONP (configuration))
5155 wrong_type_argument (Qwindow_configuration_p, configuration);
5156
5157 data = (struct save_window_data *) XVECTOR (configuration);
5158 saved_windows = XVECTOR (data->saved_windows);
5159
5160 new_current_buffer = data->current_buffer;
5161 if (NILP (XBUFFER (new_current_buffer)->name))
5162 new_current_buffer = Qnil;
5163 else
5164 {
5165 if (XBUFFER (new_current_buffer) == current_buffer)
5166 old_point = PT;
5167 else
5168 old_point = BUF_PT (XBUFFER (new_current_buffer));
5169 }
5170
5171 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
5172 f = XFRAME (frame);
5173
5174 /* If f is a dead frame, don't bother rebuilding its window tree.
5175 However, there is other stuff we should still try to do below. */
5176 if (FRAME_LIVE_P (f))
5177 {
5178 register struct window *w;
5179 register struct saved_window *p;
5180 struct window *root_window;
5181 struct window **leaf_windows;
5182 int n_leaf_windows;
5183 int k, i, n;
5184
5185 /* If the frame has been resized since this window configuration was
5186 made, we change the frame to the size specified in the
5187 configuration, restore the configuration, and then resize it
5188 back. We keep track of the prevailing height in these variables. */
5189 int previous_frame_lines = FRAME_LINES (f);
5190 int previous_frame_cols = FRAME_COLS (f);
5191 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5192 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5193
5194 /* The mouse highlighting code could get screwed up
5195 if it runs during this. */
5196 BLOCK_INPUT;
5197
5198 if (XFASTINT (data->frame_lines) != previous_frame_lines
5199 || XFASTINT (data->frame_cols) != previous_frame_cols)
5200 change_frame_size (f, XFASTINT (data->frame_lines),
5201 XFASTINT (data->frame_cols), 0, 0, 0);
5202 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5203 if (XFASTINT (data->frame_menu_bar_lines)
5204 != previous_frame_menu_bar_lines)
5205 x_set_menu_bar_lines (f, data->frame_menu_bar_lines, make_number (0));
5206 #ifdef HAVE_WINDOW_SYSTEM
5207 if (XFASTINT (data->frame_tool_bar_lines)
5208 != previous_frame_tool_bar_lines)
5209 x_set_tool_bar_lines (f, data->frame_tool_bar_lines, make_number (0));
5210 #endif
5211 #endif
5212
5213 /* "Swap out" point from the selected window
5214 into its buffer. We do this now, before
5215 restoring the window contents, and prevent it from
5216 being done later on when we select a new window. */
5217 if (! NILP (XWINDOW (selected_window)->buffer))
5218 {
5219 w = XWINDOW (selected_window);
5220 set_marker_both (w->pointm,
5221 w->buffer,
5222 BUF_PT (XBUFFER (w->buffer)),
5223 BUF_PT_BYTE (XBUFFER (w->buffer)));
5224 }
5225
5226 windows_or_buffers_changed++;
5227 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
5228
5229 /* Problem: Freeing all matrices and later allocating them again
5230 is a serious redisplay flickering problem. What we would
5231 really like to do is to free only those matrices not reused
5232 below. */
5233 root_window = XWINDOW (FRAME_ROOT_WINDOW (f));
5234 leaf_windows
5235 = (struct window **) alloca (count_windows (root_window)
5236 * sizeof (struct window *));
5237 n_leaf_windows = get_leaf_windows (root_window, leaf_windows, 0);
5238
5239 /* Temporarily avoid any problems with windows that are smaller
5240 than they are supposed to be. */
5241 window_min_height = 1;
5242 window_min_width = 1;
5243
5244 /* Kludge Alert!
5245 Mark all windows now on frame as "deleted".
5246 Restoring the new configuration "undeletes" any that are in it.
5247
5248 Save their current buffers in their height fields, since we may
5249 need it later, if a buffer saved in the configuration is now
5250 dead. */
5251 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5252
5253 for (k = 0; k < saved_windows->size; k++)
5254 {
5255 p = SAVED_WINDOW_N (saved_windows, k);
5256 w = XWINDOW (p->window);
5257 w->next = Qnil;
5258
5259 if (!NILP (p->parent))
5260 w->parent = SAVED_WINDOW_N (saved_windows,
5261 XFASTINT (p->parent))->window;
5262 else
5263 w->parent = Qnil;
5264
5265 if (!NILP (p->prev))
5266 {
5267 w->prev = SAVED_WINDOW_N (saved_windows,
5268 XFASTINT (p->prev))->window;
5269 XWINDOW (w->prev)->next = p->window;
5270 }
5271 else
5272 {
5273 w->prev = Qnil;
5274 if (!NILP (w->parent))
5275 {
5276 if (EQ (p->total_cols, XWINDOW (w->parent)->total_cols))
5277 {
5278 XWINDOW (w->parent)->vchild = p->window;
5279 XWINDOW (w->parent)->hchild = Qnil;
5280 }
5281 else
5282 {
5283 XWINDOW (w->parent)->hchild = p->window;
5284 XWINDOW (w->parent)->vchild = Qnil;
5285 }
5286 }
5287 }
5288
5289 /* If we squirreled away the buffer in the window's height,
5290 restore it now. */
5291 if (BUFFERP (w->total_lines))
5292 w->buffer = w->total_lines;
5293 w->left_col = p->left_col;
5294 w->top_line = p->top_line;
5295 w->total_cols = p->total_cols;
5296 w->total_lines = p->total_lines;
5297 w->hscroll = p->hscroll;
5298 w->min_hscroll = p->min_hscroll;
5299 w->display_table = p->display_table;
5300 w->orig_top_line = p->orig_top_line;
5301 w->orig_total_lines = p->orig_total_lines;
5302 w->left_margin_cols = p->left_margin_cols;
5303 w->right_margin_cols = p->right_margin_cols;
5304 w->left_fringe_width = p->left_fringe_width;
5305 w->right_fringe_width = p->right_fringe_width;
5306 w->fringes_outside_margins = p->fringes_outside_margins;
5307 w->scroll_bar_width = p->scroll_bar_width;
5308 w->vertical_scroll_bar_type = p->vertical_scroll_bar_type;
5309 XSETFASTINT (w->last_modified, 0);
5310 XSETFASTINT (w->last_overlay_modified, 0);
5311
5312 /* Reinstall the saved buffer and pointers into it. */
5313 if (NILP (p->buffer))
5314 w->buffer = p->buffer;
5315 else
5316 {
5317 if (!NILP (XBUFFER (p->buffer)->name))
5318 /* If saved buffer is alive, install it. */
5319 {
5320 w->buffer = p->buffer;
5321 w->start_at_line_beg = p->start_at_line_beg;
5322 set_marker_restricted (w->start, p->start, w->buffer);
5323 set_marker_restricted (w->pointm, p->pointm, w->buffer);
5324 Fset_marker (XBUFFER (w->buffer)->mark,
5325 p->mark, w->buffer);
5326
5327 /* As documented in Fcurrent_window_configuration, don't
5328 restore the location of point in the buffer which was
5329 current when the window configuration was recorded. */
5330 if (!EQ (p->buffer, new_current_buffer)
5331 && XBUFFER (p->buffer) == current_buffer)
5332 Fgoto_char (w->pointm);
5333 }
5334 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
5335 /* Else unless window has a live buffer, get one. */
5336 {
5337 w->buffer = Fcdr (Fcar (Vbuffer_alist));
5338 /* This will set the markers to beginning of visible
5339 range. */
5340 set_marker_restricted (w->start, make_number (0), w->buffer);
5341 set_marker_restricted (w->pointm, make_number (0),w->buffer);
5342 w->start_at_line_beg = Qt;
5343 }
5344 else
5345 /* Keeping window's old buffer; make sure the markers
5346 are real. */
5347 {
5348 /* Set window markers at start of visible range. */
5349 if (XMARKER (w->start)->buffer == 0)
5350 set_marker_restricted (w->start, make_number (0),
5351 w->buffer);
5352 if (XMARKER (w->pointm)->buffer == 0)
5353 set_marker_restricted_both (w->pointm, w->buffer,
5354 BUF_PT (XBUFFER (w->buffer)),
5355 BUF_PT_BYTE (XBUFFER (w->buffer)));
5356 w->start_at_line_beg = Qt;
5357 }
5358 }
5359 }
5360
5361 FRAME_ROOT_WINDOW (f) = data->root_window;
5362 /* Prevent "swapping out point" in the old selected window
5363 using the buffer that has been restored into it.
5364 Use the point value from the beginning of this function
5365 since unshow_buffer (called from delete_all_subwindows)
5366 could have altered it. */
5367 selected_window = Qnil;
5368 if (EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5369 set_marker_restricted (XWINDOW (data->current_window)->pointm,
5370 make_number (old_point),
5371 XWINDOW (data->current_window)->buffer);
5372
5373 Fselect_window (data->current_window, Qnil);
5374 XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
5375 = selected_window;
5376
5377 if (NILP (data->focus_frame)
5378 || (FRAMEP (data->focus_frame)
5379 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
5380 Fredirect_frame_focus (frame, data->focus_frame);
5381
5382 #if 0 /* I don't understand why this is needed, and it causes problems
5383 when the frame's old selected window has been deleted. */
5384 if (f != selected_frame && FRAME_WINDOW_P (f))
5385 do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
5386 0, 0);
5387 #endif
5388
5389 /* Set the screen height to the value it had before this function. */
5390 if (previous_frame_lines != FRAME_LINES (f)
5391 || previous_frame_cols != FRAME_COLS (f))
5392 change_frame_size (f, previous_frame_lines, previous_frame_cols,
5393 0, 0, 0);
5394 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
5395 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
5396 x_set_menu_bar_lines (f, make_number (previous_frame_menu_bar_lines),
5397 make_number (0));
5398 #ifdef HAVE_WINDOW_SYSTEM
5399 if (previous_frame_tool_bar_lines != FRAME_TOOL_BAR_LINES (f))
5400 x_set_tool_bar_lines (f, make_number (previous_frame_tool_bar_lines),
5401 make_number (0));
5402 #endif
5403 #endif
5404
5405 /* Now, free glyph matrices in windows that were not reused. */
5406 for (i = n = 0; i < n_leaf_windows; ++i)
5407 {
5408 if (NILP (leaf_windows[i]->buffer))
5409 {
5410 /* Assert it's not reused as a combination. */
5411 xassert (NILP (leaf_windows[i]->hchild)
5412 && NILP (leaf_windows[i]->vchild));
5413 free_window_matrices (leaf_windows[i]);
5414 }
5415 else if (EQ (leaf_windows[i]->buffer, new_current_buffer))
5416 ++n;
5417 }
5418
5419 adjust_glyphs (f);
5420
5421 UNBLOCK_INPUT;
5422
5423 /* Fselect_window will have made f the selected frame, so we
5424 reselect the proper frame here. Fhandle_switch_frame will change the
5425 selected window too, but that doesn't make the call to
5426 Fselect_window above totally superfluous; it still sets f's
5427 selected window. */
5428 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
5429 do_switch_frame (data->selected_frame, 0, 0);
5430
5431 if (! NILP (Vwindow_configuration_change_hook)
5432 && ! NILP (Vrun_hooks))
5433 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
5434 }
5435
5436 if (!NILP (new_current_buffer))
5437 Fset_buffer (new_current_buffer);
5438
5439 /* Restore the minimum heights recorded in the configuration. */
5440 window_min_height = XINT (data->min_height);
5441 window_min_width = XINT (data->min_width);
5442
5443 Vminibuf_scroll_window = data->minibuf_scroll_window;
5444 minibuf_selected_window = data->minibuf_selected_window;
5445
5446 return (FRAME_LIVE_P (f) ? Qt : Qnil);
5447 }
5448
5449 /* Mark all windows now on frame as deleted
5450 by setting their buffers to nil. */
5451
5452 void
5453 delete_all_subwindows (w)
5454 register struct window *w;
5455 {
5456 if (!NILP (w->next))
5457 delete_all_subwindows (XWINDOW (w->next));
5458 if (!NILP (w->vchild))
5459 delete_all_subwindows (XWINDOW (w->vchild));
5460 if (!NILP (w->hchild))
5461 delete_all_subwindows (XWINDOW (w->hchild));
5462
5463 w->total_lines = w->buffer; /* See Fset_window_configuration for excuse. */
5464
5465 if (!NILP (w->buffer))
5466 unshow_buffer (w);
5467
5468 /* We set all three of these fields to nil, to make sure that we can
5469 distinguish this dead window from any live window. Live leaf
5470 windows will have buffer set, and combination windows will have
5471 vchild or hchild set. */
5472 w->buffer = Qnil;
5473 w->vchild = Qnil;
5474 w->hchild = Qnil;
5475
5476 Vwindow_list = Qnil;
5477 }
5478 \f
5479 static int
5480 count_windows (window)
5481 register struct window *window;
5482 {
5483 register int count = 1;
5484 if (!NILP (window->next))
5485 count += count_windows (XWINDOW (window->next));
5486 if (!NILP (window->vchild))
5487 count += count_windows (XWINDOW (window->vchild));
5488 if (!NILP (window->hchild))
5489 count += count_windows (XWINDOW (window->hchild));
5490 return count;
5491 }
5492
5493
5494 /* Fill vector FLAT with leaf windows under W, starting at index I.
5495 Value is last index + 1. */
5496
5497 static int
5498 get_leaf_windows (w, flat, i)
5499 struct window *w;
5500 struct window **flat;
5501 int i;
5502 {
5503 while (w)
5504 {
5505 if (!NILP (w->hchild))
5506 i = get_leaf_windows (XWINDOW (w->hchild), flat, i);
5507 else if (!NILP (w->vchild))
5508 i = get_leaf_windows (XWINDOW (w->vchild), flat, i);
5509 else
5510 flat[i++] = w;
5511
5512 w = NILP (w->next) ? 0 : XWINDOW (w->next);
5513 }
5514
5515 return i;
5516 }
5517
5518
5519 /* Return a pointer to the glyph W's physical cursor is on. Value is
5520 null if W's current matrix is invalid, so that no meaningfull glyph
5521 can be returned. */
5522
5523 struct glyph *
5524 get_phys_cursor_glyph (w)
5525 struct window *w;
5526 {
5527 struct glyph_row *row;
5528 struct glyph *glyph;
5529
5530 if (w->phys_cursor.vpos >= 0
5531 && w->phys_cursor.vpos < w->current_matrix->nrows
5532 && (row = MATRIX_ROW (w->current_matrix, w->phys_cursor.vpos),
5533 row->enabled_p)
5534 && row->used[TEXT_AREA] > w->phys_cursor.hpos)
5535 glyph = row->glyphs[TEXT_AREA] + w->phys_cursor.hpos;
5536 else
5537 glyph = NULL;
5538
5539 return glyph;
5540 }
5541
5542
5543 static int
5544 save_window_save (window, vector, i)
5545 Lisp_Object window;
5546 struct Lisp_Vector *vector;
5547 int i;
5548 {
5549 register struct saved_window *p;
5550 register struct window *w;
5551 register Lisp_Object tem;
5552
5553 for (;!NILP (window); window = w->next)
5554 {
5555 p = SAVED_WINDOW_N (vector, i);
5556 w = XWINDOW (window);
5557
5558 XSETFASTINT (w->temslot, i++);
5559 p->window = window;
5560 p->buffer = w->buffer;
5561 p->left_col = w->left_col;
5562 p->top_line = w->top_line;
5563 p->total_cols = w->total_cols;
5564 p->total_lines = w->total_lines;
5565 p->hscroll = w->hscroll;
5566 p->min_hscroll = w->min_hscroll;
5567 p->display_table = w->display_table;
5568 p->orig_top_line = w->orig_top_line;
5569 p->orig_total_lines = w->orig_total_lines;
5570 p->left_margin_cols = w->left_margin_cols;
5571 p->right_margin_cols = w->right_margin_cols;
5572 p->left_fringe_width = w->left_fringe_width;
5573 p->right_fringe_width = w->right_fringe_width;
5574 p->fringes_outside_margins = w->fringes_outside_margins;
5575 p->scroll_bar_width = w->scroll_bar_width;
5576 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
5577 if (!NILP (w->buffer))
5578 {
5579 /* Save w's value of point in the window configuration.
5580 If w is the selected window, then get the value of point
5581 from the buffer; pointm is garbage in the selected window. */
5582 if (EQ (window, selected_window))
5583 {
5584 p->pointm = Fmake_marker ();
5585 set_marker_both (p->pointm, w->buffer,
5586 BUF_PT (XBUFFER (w->buffer)),
5587 BUF_PT_BYTE (XBUFFER (w->buffer)));
5588 }
5589 else
5590 p->pointm = Fcopy_marker (w->pointm, Qnil);
5591
5592 p->start = Fcopy_marker (w->start, Qnil);
5593 p->start_at_line_beg = w->start_at_line_beg;
5594
5595 tem = XBUFFER (w->buffer)->mark;
5596 p->mark = Fcopy_marker (tem, Qnil);
5597 }
5598 else
5599 {
5600 p->pointm = Qnil;
5601 p->start = Qnil;
5602 p->mark = Qnil;
5603 p->start_at_line_beg = Qnil;
5604 }
5605
5606 if (NILP (w->parent))
5607 p->parent = Qnil;
5608 else
5609 p->parent = XWINDOW (w->parent)->temslot;
5610
5611 if (NILP (w->prev))
5612 p->prev = Qnil;
5613 else
5614 p->prev = XWINDOW (w->prev)->temslot;
5615
5616 if (!NILP (w->vchild))
5617 i = save_window_save (w->vchild, vector, i);
5618 if (!NILP (w->hchild))
5619 i = save_window_save (w->hchild, vector, i);
5620 }
5621
5622 return i;
5623 }
5624
5625 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
5626 Scurrent_window_configuration, 0, 1, 0,
5627 doc: /* Return an object representing the current window configuration of FRAME.
5628 If FRAME is nil or omitted, use the selected frame.
5629 This describes the number of windows, their sizes and current buffers,
5630 and for each displayed buffer, where display starts, and the positions of
5631 point and mark. An exception is made for point in the current buffer:
5632 its value is -not- saved.
5633 This also records the currently selected frame, and FRAME's focus
5634 redirection (see `redirect-frame-focus'). */)
5635 (frame)
5636 Lisp_Object frame;
5637 {
5638 register Lisp_Object tem;
5639 register int n_windows;
5640 register struct save_window_data *data;
5641 register struct Lisp_Vector *vec;
5642 register int i;
5643 FRAME_PTR f;
5644
5645 if (NILP (frame))
5646 frame = selected_frame;
5647 CHECK_LIVE_FRAME (frame);
5648 f = XFRAME (frame);
5649
5650 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
5651 vec = allocate_other_vector (VECSIZE (struct save_window_data));
5652 data = (struct save_window_data *)vec;
5653
5654 XSETFASTINT (data->frame_cols, FRAME_COLS (f));
5655 XSETFASTINT (data->frame_lines, FRAME_LINES (f));
5656 XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f));
5657 XSETFASTINT (data->frame_tool_bar_lines, FRAME_TOOL_BAR_LINES (f));
5658 data->selected_frame = selected_frame;
5659 data->current_window = FRAME_SELECTED_WINDOW (f);
5660 XSETBUFFER (data->current_buffer, current_buffer);
5661 data->minibuf_scroll_window = minibuf_level > 0 ? Vminibuf_scroll_window : Qnil;
5662 data->minibuf_selected_window = minibuf_level > 0 ? minibuf_selected_window : Qnil;
5663 data->root_window = FRAME_ROOT_WINDOW (f);
5664 data->focus_frame = FRAME_FOCUS_FRAME (f);
5665 XSETINT (data->min_height, window_min_height);
5666 XSETINT (data->min_width, window_min_width);
5667 tem = Fmake_vector (make_number (n_windows), Qnil);
5668 data->saved_windows = tem;
5669 for (i = 0; i < n_windows; i++)
5670 XVECTOR (tem)->contents[i]
5671 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);
5672 save_window_save (FRAME_ROOT_WINDOW (f), XVECTOR (tem), 0);
5673 XSETWINDOW_CONFIGURATION (tem, data);
5674 return (tem);
5675 }
5676
5677 DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
5678 0, UNEVALLED, 0,
5679 doc: /* Execute body, preserving window sizes and contents.
5680 Restore which buffer appears in which window, where display starts,
5681 and the value of point and mark for each window.
5682 Also restore the choice of selected window.
5683 Also restore which buffer is current.
5684 Does not restore the value of point in current buffer.
5685 usage: (save-window-excursion BODY ...) */)
5686 (args)
5687 Lisp_Object args;
5688 {
5689 register Lisp_Object val;
5690 register int count = SPECPDL_INDEX ();
5691
5692 record_unwind_protect (Fset_window_configuration,
5693 Fcurrent_window_configuration (Qnil));
5694 val = Fprogn (args);
5695 return unbind_to (count, val);
5696 }
5697
5698 \f
5699 /***********************************************************************
5700 Marginal Areas
5701 ***********************************************************************/
5702
5703 DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
5704 2, 3, 0,
5705 doc: /* Set width of marginal areas of window WINDOW.
5706 If window is nil, set margins of the currently selected window.
5707 First parameter LEFT-WIDTH specifies the number of character
5708 cells to reserve for the left marginal area. Second parameter
5709 RIGHT-WIDTH does the same for the right marginal area.
5710 A nil width parameter means no margin. */)
5711 (window, left, right)
5712 Lisp_Object window, left, right;
5713 {
5714 struct window *w = decode_window (window);
5715
5716 /* TODO: It doesn't make sense to use FLOATs here, since
5717 the rest of the code assumes they are integers.
5718 So don't allow floats! ++KFS */
5719
5720 if (!NILP (left))
5721 CHECK_NUMBER_OR_FLOAT (left);
5722 if (!NILP (right))
5723 CHECK_NUMBER_OR_FLOAT (right);
5724
5725 /* Check widths < 0 and translate a zero width to nil.
5726 Margins that are too wide have to be checked elsewhere. */
5727 if ((INTEGERP (left) && XINT (left) < 0)
5728 || (FLOATP (left) && XFLOAT_DATA (left) <= 0))
5729 XSETFASTINT (left, 0);
5730 if (INTEGERP (left) && XFASTINT (left) == 0)
5731 left = Qnil;
5732
5733 if ((INTEGERP (right) && XINT (right) < 0)
5734 || (FLOATP (right) && XFLOAT_DATA (right) <= 0))
5735 XSETFASTINT (right, 0);
5736 if (INTEGERP (right) && XFASTINT (right) == 0)
5737 right = Qnil;
5738
5739 if (!EQ (w->left_margin_cols, left)
5740 || !EQ (w->right_margin_cols, right))
5741 {
5742 w->left_margin_cols = left;
5743 w->right_margin_cols = right;
5744
5745 adjust_window_margins (w);
5746
5747 ++windows_or_buffers_changed;
5748 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
5749 }
5750
5751 return Qnil;
5752 }
5753
5754
5755 DEFUN ("window-margins", Fwindow_margins, Swindow_margins,
5756 0, 1, 0,
5757 doc: /* Get width of marginal areas of window WINDOW.
5758 If WINDOW is omitted or nil, use the currently selected window.
5759 Value is a cons of the form (LEFT-WIDTH . RIGHT-WIDTH).
5760 If a marginal area does not exist, its width will be returned
5761 as nil. */)
5762 (window)
5763 Lisp_Object window;
5764 {
5765 struct window *w = decode_window (window);
5766 return Fcons (w->left_margin_cols, w->right_margin_cols);
5767 }
5768
5769
5770 \f
5771 /***********************************************************************
5772 Fringes
5773 ***********************************************************************/
5774
5775 DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
5776 2, 4, 0,
5777 doc: /* Set width of fringes of window WINDOW.
5778
5779 If window is nil, set fringes of the currently selected window.
5780 Second parameter LEFT-WIDTH specifies the number of pixels to reserve
5781 for the left fringe. Third parameter RIGHT-WIDTH does the same for
5782 the right fringe. Fourth parameter OUTSIDE-MARGINS non-nil specifies
5783 that fringes are drawn outside of the display margins; by default, fringes
5784 are drawn between display marginal areas and the text area.
5785 A nil width parameter means to use the frame's corresponding fringe width. */)
5786 (window, left, right, outside_margins)
5787 Lisp_Object window, left, right, outside_margins;
5788 {
5789 struct window *w = decode_window (window);
5790
5791 if (!NILP (left))
5792 CHECK_NUMBER (left);
5793 if (!NILP (right))
5794 CHECK_NUMBER (right);
5795
5796 if (!EQ (w->left_fringe_width, left)
5797 || !EQ (w->right_fringe_width, right)
5798 || !EQ (w->fringes_outside_margins, outside_margins))
5799 {
5800 w->left_fringe_width = left;
5801 w->right_fringe_width = right;
5802 w->fringes_outside_margins = outside_margins;
5803
5804 adjust_window_margins (w);
5805
5806 clear_glyph_matrix (w->current_matrix);
5807 w->window_end_valid = Qnil;
5808
5809 ++windows_or_buffers_changed;
5810 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
5811 }
5812
5813 return Qnil;
5814 }
5815
5816
5817 DEFUN ("window-fringes", Fwindow_fringes, Swindow_fringes,
5818 0, 1, 0,
5819 doc: /* Get width of fringes of window WINDOW.
5820 If WINDOW is omitted or nil, use the currently selected window.
5821 Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS).
5822 If a window specific fringe width is not set, its width will be returned
5823 as nil. */)
5824 (window)
5825 Lisp_Object window;
5826 {
5827 struct window *w = decode_window (window);
5828 return Fcons (make_number (WINDOW_LEFT_FRINGE_WIDTH (w)),
5829 Fcons (make_number (WINDOW_RIGHT_FRINGE_WIDTH (w)),
5830 Fcons ((WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w) ?
5831 Qt : Qnil), Qnil)));
5832 }
5833
5834
5835 \f
5836 /***********************************************************************
5837 Scroll bars
5838 ***********************************************************************/
5839
5840 DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, Sset_window_scroll_bars,
5841 2, 4, 0,
5842 doc: /* Set width and type of scroll bars of window WINDOW.
5843 If window is nil, set scroll bars of the currently selected window.
5844 Second parameter WIDTH specifies the pixel width for the scroll bar;
5845 this is automatically adjusted to a multiple of the frame column width.
5846 Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
5847 bar: left, right, or nil.
5848 A width of nil and type of t means to use the frame's corresponding value. */)
5849 (window, width, vertical_type, horizontal_type)
5850 Lisp_Object window, width, vertical_type, horizontal_type;
5851 {
5852 struct window *w = decode_window (window);
5853
5854 if (!NILP (width))
5855 CHECK_NUMBER (width);
5856
5857 if (XINT (width) == 0)
5858 vertical_type = Qnil;
5859
5860 if (!EQ (w->scroll_bar_width, width)
5861 || !EQ (w->vertical_scroll_bar_type, vertical_type))
5862 {
5863 w->scroll_bar_width = width;
5864 w->vertical_scroll_bar_type = vertical_type;
5865
5866 adjust_window_margins (w);
5867
5868 clear_glyph_matrix (w->current_matrix);
5869 w->window_end_valid = Qnil;
5870
5871 ++windows_or_buffers_changed;
5872 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
5873 }
5874
5875 return Qnil;
5876 }
5877
5878
5879 DEFUN ("window-scroll-bars", Fwindow_scroll_bars, Swindow_scroll_bars,
5880 0, 1, 0,
5881 doc: /* Get width and type of scroll bars of window WINDOW.
5882 If WINDOW is omitted or nil, use the currently selected window.
5883 Value is a list of the form (WIDTH COLS VERTICAL-TYPE HORIZONTAL-TYPE). */)
5884 (window)
5885 Lisp_Object window;
5886 {
5887 struct window *w = decode_window (window);
5888 return Fcons (make_number ((WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
5889 ? WINDOW_CONFIG_SCROLL_BAR_WIDTH (w)
5890 : WINDOW_SCROLL_BAR_AREA_WIDTH (w))),
5891 Fcons (make_number (WINDOW_SCROLL_BAR_COLS (w)),
5892 Fcons (w->vertical_scroll_bar_type,
5893 Fcons (Qnil, Qnil))));
5894 }
5895
5896
5897 \f
5898 /***********************************************************************
5899 Smooth scrolling
5900 ***********************************************************************/
5901
5902 DEFUN ("window-vscroll", Fwindow_vscroll, Swindow_vscroll, 0, 1, 0,
5903 doc: /* Return the amount by which WINDOW is scrolled vertically.
5904 Use the selected window if WINDOW is nil or omitted.
5905 Value is a multiple of the canonical character height of WINDOW. */)
5906 (window)
5907 Lisp_Object window;
5908 {
5909 Lisp_Object result;
5910 struct frame *f;
5911 struct window *w;
5912
5913 if (NILP (window))
5914 window = selected_window;
5915 else
5916 CHECK_WINDOW (window);
5917 w = XWINDOW (window);
5918 f = XFRAME (w->frame);
5919
5920 if (FRAME_WINDOW_P (f))
5921 result = FRAME_CANON_Y_FROM_PIXEL_Y (f, -w->vscroll);
5922 else
5923 result = make_number (0);
5924 return result;
5925 }
5926
5927
5928 DEFUN ("set-window-vscroll", Fset_window_vscroll, Sset_window_vscroll,
5929 2, 2, 0,
5930 doc: /* Set amount by which WINDOW should be scrolled vertically to VSCROLL.
5931 WINDOW nil means use the selected window. VSCROLL is a non-negative
5932 multiple of the canonical character height of WINDOW. */)
5933 (window, vscroll)
5934 Lisp_Object window, vscroll;
5935 {
5936 struct window *w;
5937 struct frame *f;
5938
5939 if (NILP (window))
5940 window = selected_window;
5941 else
5942 CHECK_WINDOW (window);
5943 CHECK_NUMBER_OR_FLOAT (vscroll);
5944
5945 w = XWINDOW (window);
5946 f = XFRAME (w->frame);
5947
5948 if (FRAME_WINDOW_P (f))
5949 {
5950 int old_dy = w->vscroll;
5951
5952 w->vscroll = - FRAME_LINE_HEIGHT (f) * XFLOATINT (vscroll);
5953 w->vscroll = min (w->vscroll, 0);
5954
5955 /* Adjust glyph matrix of the frame if the virtual display
5956 area becomes larger than before. */
5957 if (w->vscroll < 0 && w->vscroll < old_dy)
5958 adjust_glyphs (f);
5959
5960 /* Prevent redisplay shortcuts. */
5961 XBUFFER (w->buffer)->prevent_redisplay_optimizations_p = 1;
5962 }
5963
5964 return Fwindow_vscroll (window);
5965 }
5966
5967 \f
5968 /* Call FN for all leaf windows on frame F. FN is called with the
5969 first argument being a pointer to the leaf window, and with
5970 additional argument USER_DATA. Stops when FN returns 0. */
5971
5972 void
5973 foreach_window (f, fn, user_data)
5974 struct frame *f;
5975 int (* fn) P_ ((struct window *, void *));
5976 void *user_data;
5977 {
5978 foreach_window_1 (XWINDOW (FRAME_ROOT_WINDOW (f)), fn, user_data);
5979 }
5980
5981
5982 /* Helper function for foreach_window. Call FN for all leaf windows
5983 reachable from W. FN is called with the first argument being a
5984 pointer to the leaf window, and with additional argument USER_DATA.
5985 Stop when FN returns 0. Value is 0 if stopped by FN. */
5986
5987 static int
5988 foreach_window_1 (w, fn, user_data)
5989 struct window *w;
5990 int (* fn) P_ ((struct window *, void *));
5991 void *user_data;
5992 {
5993 int cont;
5994
5995 for (cont = 1; w && cont;)
5996 {
5997 if (!NILP (w->hchild))
5998 cont = foreach_window_1 (XWINDOW (w->hchild), fn, user_data);
5999 else if (!NILP (w->vchild))
6000 cont = foreach_window_1 (XWINDOW (w->vchild), fn, user_data);
6001 else
6002 cont = fn (w, user_data);
6003
6004 w = NILP (w->next) ? 0 : XWINDOW (w->next);
6005 }
6006
6007 return cont;
6008 }
6009
6010
6011 /* Freeze or unfreeze the window start of W unless it is a
6012 mini-window or the selected window. FREEZE_P non-null means freeze
6013 the window start. */
6014
6015 static int
6016 freeze_window_start (w, freeze_p)
6017 struct window *w;
6018 void *freeze_p;
6019 {
6020 if (w == XWINDOW (selected_window)
6021 || MINI_WINDOW_P (w)
6022 || (MINI_WINDOW_P (XWINDOW (selected_window))
6023 && ! NILP (Vminibuf_scroll_window)
6024 && w == XWINDOW (Vminibuf_scroll_window)))
6025 freeze_p = NULL;
6026
6027 w->frozen_window_start_p = freeze_p != NULL;
6028 return 1;
6029 }
6030
6031
6032 /* Freeze or unfreeze the window starts of all leaf windows on frame
6033 F, except the selected window and a mini-window. FREEZE_P non-zero
6034 means freeze the window start. */
6035
6036 void
6037 freeze_window_starts (f, freeze_p)
6038 struct frame *f;
6039 int freeze_p;
6040 {
6041 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6042 }
6043
6044 \f
6045 /***********************************************************************
6046 Initialization
6047 ***********************************************************************/
6048
6049 /* Return 1 if window configurations C1 and C2
6050 describe the same state of affairs. This is used by Fequal. */
6051
6052 int
6053 compare_window_configurations (c1, c2, ignore_positions)
6054 Lisp_Object c1, c2;
6055 int ignore_positions;
6056 {
6057 register struct save_window_data *d1, *d2;
6058 struct Lisp_Vector *sw1, *sw2;
6059 int i;
6060
6061 if (!WINDOW_CONFIGURATIONP (c1))
6062 wrong_type_argument (Qwindow_configuration_p, c1);
6063 if (!WINDOW_CONFIGURATIONP (c2))
6064 wrong_type_argument (Qwindow_configuration_p, c2);
6065
6066 d1 = (struct save_window_data *) XVECTOR (c1);
6067 d2 = (struct save_window_data *) XVECTOR (c2);
6068 sw1 = XVECTOR (d1->saved_windows);
6069 sw2 = XVECTOR (d2->saved_windows);
6070
6071 if (! EQ (d1->frame_cols, d2->frame_cols))
6072 return 0;
6073 if (! EQ (d1->frame_lines, d2->frame_lines))
6074 return 0;
6075 if (! EQ (d1->frame_menu_bar_lines, d2->frame_menu_bar_lines))
6076 return 0;
6077 if (! EQ (d1->selected_frame, d2->selected_frame))
6078 return 0;
6079 /* Don't compare the current_window field directly.
6080 Instead see w1_is_current and w2_is_current, below. */
6081 if (! EQ (d1->current_buffer, d2->current_buffer))
6082 return 0;
6083 if (! ignore_positions)
6084 {
6085 if (! EQ (d1->minibuf_scroll_window, d2->minibuf_scroll_window))
6086 return 0;
6087 if (! EQ (d1->minibuf_selected_window, d2->minibuf_selected_window))
6088 return 0;
6089 }
6090 /* Don't compare the root_window field.
6091 We don't require the two configurations
6092 to use the same window object,
6093 and the two root windows must be equivalent
6094 if everything else compares equal. */
6095 if (! EQ (d1->focus_frame, d2->focus_frame))
6096 return 0;
6097 if (! EQ (d1->min_width, d2->min_width))
6098 return 0;
6099 if (! EQ (d1->min_height, d2->min_height))
6100 return 0;
6101
6102 /* Verify that the two confis have the same number of windows. */
6103 if (sw1->size != sw2->size)
6104 return 0;
6105
6106 for (i = 0; i < sw1->size; i++)
6107 {
6108 struct saved_window *p1, *p2;
6109 int w1_is_current, w2_is_current;
6110
6111 p1 = SAVED_WINDOW_N (sw1, i);
6112 p2 = SAVED_WINDOW_N (sw2, i);
6113
6114 /* Verify that the current windows in the two
6115 configurations correspond to each other. */
6116 w1_is_current = EQ (d1->current_window, p1->window);
6117 w2_is_current = EQ (d2->current_window, p2->window);
6118
6119 if (w1_is_current != w2_is_current)
6120 return 0;
6121
6122 /* Verify that the corresponding windows do match. */
6123 if (! EQ (p1->buffer, p2->buffer))
6124 return 0;
6125 if (! EQ (p1->left_col, p2->left_col))
6126 return 0;
6127 if (! EQ (p1->top_line, p2->top_line))
6128 return 0;
6129 if (! EQ (p1->total_cols, p2->total_cols))
6130 return 0;
6131 if (! EQ (p1->total_lines, p2->total_lines))
6132 return 0;
6133 if (! EQ (p1->display_table, p2->display_table))
6134 return 0;
6135 if (! EQ (p1->parent, p2->parent))
6136 return 0;
6137 if (! EQ (p1->prev, p2->prev))
6138 return 0;
6139 if (! ignore_positions)
6140 {
6141 if (! EQ (p1->hscroll, p2->hscroll))
6142 return 0;
6143 if (!EQ (p1->min_hscroll, p2->min_hscroll))
6144 return 0;
6145 if (! EQ (p1->start_at_line_beg, p2->start_at_line_beg))
6146 return 0;
6147 if (NILP (Fequal (p1->start, p2->start)))
6148 return 0;
6149 if (NILP (Fequal (p1->pointm, p2->pointm)))
6150 return 0;
6151 if (NILP (Fequal (p1->mark, p2->mark)))
6152 return 0;
6153 }
6154 if (! EQ (p1->left_margin_cols, p2->left_margin_cols))
6155 return 0;
6156 if (! EQ (p1->right_margin_cols, p2->right_margin_cols))
6157 return 0;
6158 if (! EQ (p1->left_fringe_width, p2->left_fringe_width))
6159 return 0;
6160 if (! EQ (p1->right_fringe_width, p2->right_fringe_width))
6161 return 0;
6162 if (! EQ (p1->fringes_outside_margins, p2->fringes_outside_margins))
6163 return 0;
6164 if (! EQ (p1->scroll_bar_width, p2->scroll_bar_width))
6165 return 0;
6166 if (! EQ (p1->vertical_scroll_bar_type, p2->vertical_scroll_bar_type))
6167 return 0;
6168 }
6169
6170 return 1;
6171 }
6172
6173 DEFUN ("compare-window-configurations", Fcompare_window_configurations,
6174 Scompare_window_configurations, 2, 2, 0,
6175 doc: /* Compare two window configurations as regards the structure of windows.
6176 This function ignores details such as the values of point and mark
6177 and scrolling positions. */)
6178 (x, y)
6179 Lisp_Object x, y;
6180 {
6181 if (compare_window_configurations (x, y, 1))
6182 return Qt;
6183 return Qnil;
6184 }
6185 \f
6186 void
6187 init_window_once ()
6188 {
6189 struct frame *f = make_terminal_frame ();
6190 XSETFRAME (selected_frame, f);
6191 Vterminal_frame = selected_frame;
6192 minibuf_window = f->minibuffer_window;
6193 selected_window = f->selected_window;
6194 last_nonminibuf_frame = f;
6195
6196 window_initialized = 1;
6197 }
6198
6199 void
6200 init_window ()
6201 {
6202 Vwindow_list = Qnil;
6203 }
6204
6205 void
6206 syms_of_window ()
6207 {
6208 Qwindow_size_fixed = intern ("window-size-fixed");
6209 staticpro (&Qwindow_size_fixed);
6210
6211 staticpro (&Qwindow_configuration_change_hook);
6212 Qwindow_configuration_change_hook
6213 = intern ("window-configuration-change-hook");
6214
6215 Qwindowp = intern ("windowp");
6216 staticpro (&Qwindowp);
6217
6218 Qwindow_configuration_p = intern ("window-configuration-p");
6219 staticpro (&Qwindow_configuration_p);
6220
6221 Qwindow_live_p = intern ("window-live-p");
6222 staticpro (&Qwindow_live_p);
6223
6224 Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook");
6225 staticpro (&Qtemp_buffer_show_hook);
6226
6227 staticpro (&Vwindow_list);
6228
6229 minibuf_selected_window = Qnil;
6230 staticpro (&minibuf_selected_window);
6231
6232 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
6233 doc: /* Non-nil means call as function to display a help buffer.
6234 The function is called with one argument, the buffer to be displayed.
6235 Used by `with-output-to-temp-buffer'.
6236 If this function is used, then it must do the entire job of showing
6237 the buffer; `temp-buffer-show-hook' is not run unless this function runs it. */);
6238 Vtemp_buffer_show_function = Qnil;
6239
6240 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function,
6241 doc: /* If non-nil, function to call to handle `display-buffer'.
6242 It will receive two args, the buffer and a flag which if non-nil means
6243 that the currently selected window is not acceptable.
6244 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'
6245 work using this function. */);
6246 Vdisplay_buffer_function = Qnil;
6247
6248 DEFVAR_LISP ("even-window-heights", &Veven_window_heights,
6249 doc: /* *If non-nil, `display-buffer' should even the window heights.
6250 If nil, `display-buffer' will leave the window configuration alone. */);
6251 Veven_window_heights = Qt;
6252
6253 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
6254 doc: /* Non-nil means it is the window that C-M-v in minibuffer should scroll. */);
6255 Vminibuf_scroll_window = Qnil;
6256
6257 DEFVAR_BOOL ("mode-line-in-non-selected-windows", &mode_line_in_non_selected_windows,
6258 doc: /* Non-nil means to use `mode-line-inactive' face in non-selected windows.
6259 If the minibuffer is active, the `minibuffer-scroll-window' mode line
6260 is displayed in the `mode-line' face. */);
6261 mode_line_in_non_selected_windows = 1;
6262
6263 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
6264 doc: /* If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window. */);
6265 Vother_window_scroll_buffer = Qnil;
6266
6267 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
6268 doc: /* *Non-nil means `display-buffer' should make a separate frame. */);
6269 pop_up_frames = 0;
6270
6271 DEFVAR_BOOL ("display-buffer-reuse-frames", &display_buffer_reuse_frames,
6272 doc: /* *Non-nil means `display-buffer' should reuse frames.
6273 If the buffer in question is already displayed in a frame, raise that frame. */);
6274 display_buffer_reuse_frames = 0;
6275
6276 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function,
6277 doc: /* Function to call to handle automatic new frame creation.
6278 It is called with no arguments and should return a newly created frame.
6279
6280 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'
6281 where `pop-up-frame-alist' would hold the default frame parameters. */);
6282 Vpop_up_frame_function = Qnil;
6283
6284 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names,
6285 doc: /* *List of buffer names that should have their own special frames.
6286 Displaying a buffer whose name is in this list makes a special frame for it
6287 using `special-display-function'. See also `special-display-regexps'.
6288
6289 An element of the list can be a list instead of just a string.
6290 There are two ways to use a list as an element:
6291 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)
6292 In the first case, FRAME-PARAMETERS are used to create the frame.
6293 In the latter case, FUNCTION is called with BUFFER as the first argument,
6294 followed by OTHER-ARGS--it can display BUFFER in any way it likes.
6295 All this is done by the function found in `special-display-function'.
6296
6297 If this variable appears \"not to work\", because you add a name to it
6298 but that buffer still appears in the selected window, look at the
6299 values of `same-window-buffer-names' and `same-window-regexps'.
6300 Those variables take precedence over this one. */);
6301 Vspecial_display_buffer_names = Qnil;
6302
6303 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps,
6304 doc: /* *List of regexps saying which buffers should have their own special frames.
6305 If a buffer name matches one of these regexps, it gets its own frame.
6306 Displaying a buffer whose name is in this list makes a special frame for it
6307 using `special-display-function'.
6308
6309 An element of the list can be a list instead of just a string.
6310 There are two ways to use a list as an element:
6311 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)
6312 In the first case, FRAME-PARAMETERS are used to create the frame.
6313 In the latter case, FUNCTION is called with the buffer as first argument,
6314 followed by OTHER-ARGS--it can display the buffer in any way it likes.
6315 All this is done by the function found in `special-display-function'.
6316
6317 If this variable appears \"not to work\", because you add a regexp to it
6318 but the matching buffers still appear in the selected window, look at the
6319 values of `same-window-buffer-names' and `same-window-regexps'.
6320 Those variables take precedence over this one. */);
6321 Vspecial_display_regexps = Qnil;
6322
6323 DEFVAR_LISP ("special-display-function", &Vspecial_display_function,
6324 doc: /* Function to call to make a new frame for a special buffer.
6325 It is called with two arguments, the buffer and optional buffer specific
6326 data, and should return a window displaying that buffer.
6327 The default value normally makes a separate frame for the buffer,
6328 using `special-display-frame-alist' to specify the frame parameters.
6329 But if the buffer specific data includes (same-buffer . t) then the
6330 buffer is displayed in the current selected window.
6331 Otherwise if it includes (same-frame . t) then the buffer is displayed in
6332 a new window in the currently selected frame.
6333
6334 A buffer is special if it is listed in `special-display-buffer-names'
6335 or matches a regexp in `special-display-regexps'. */);
6336 Vspecial_display_function = Qnil;
6337
6338 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names,
6339 doc: /* *List of buffer names that should appear in the selected window.
6340 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'
6341 switches to it in the selected window, rather than making it appear
6342 in some other window.
6343
6344 An element of the list can be a cons cell instead of just a string.
6345 Then the car must be a string, which specifies the buffer name.
6346 This is for compatibility with `special-display-buffer-names';
6347 the cdr of the cons cell is ignored.
6348
6349 See also `same-window-regexps'. */);
6350 Vsame_window_buffer_names = Qnil;
6351
6352 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps,
6353 doc: /* *List of regexps saying which buffers should appear in the selected window.
6354 If a buffer name matches one of these regexps, then displaying it
6355 using `display-buffer' or `pop-to-buffer' switches to it
6356 in the selected window, rather than making it appear in some other window.
6357
6358 An element of the list can be a cons cell instead of just a string.
6359 Then the car must be a string, which specifies the buffer name.
6360 This is for compatibility with `special-display-buffer-names';
6361 the cdr of the cons cell is ignored.
6362
6363 See also `same-window-buffer-names'. */);
6364 Vsame_window_regexps = Qnil;
6365
6366 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
6367 doc: /* *Non-nil means display-buffer should make new windows. */);
6368 pop_up_windows = 1;
6369
6370 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
6371 doc: /* *Number of lines of continuity when scrolling by screenfuls. */);
6372 next_screen_context_lines = 2;
6373
6374 DEFVAR_INT ("split-height-threshold", &split_height_threshold,
6375 doc: /* *display-buffer would prefer to split the largest window if this large.
6376 If there is only one window, it is split regardless of this value. */);
6377 split_height_threshold = 500;
6378
6379 DEFVAR_INT ("window-min-height", &window_min_height,
6380 doc: /* *Delete any window less than this tall (including its mode line). */);
6381 window_min_height = 4;
6382
6383 DEFVAR_INT ("window-min-width", &window_min_width,
6384 doc: /* *Delete any window less than this wide. */);
6385 window_min_width = 10;
6386
6387 DEFVAR_LISP ("scroll-preserve-screen-position",
6388 &Vscroll_preserve_screen_position,
6389 doc: /* *Non-nil means scroll commands move point to keep its screen line unchanged. */);
6390 Vscroll_preserve_screen_position = Qnil;
6391
6392 DEFVAR_LISP ("window-configuration-change-hook",
6393 &Vwindow_configuration_change_hook,
6394 doc: /* Functions to call when window configuration changes.
6395 The selected frame is the one whose configuration has changed. */);
6396 Vwindow_configuration_change_hook = Qnil;
6397
6398 DEFVAR_BOOL ("window-size-fixed", &window_size_fixed,
6399 doc: /* Non-nil in a buffer means windows displaying the buffer are fixed-size.
6400 Emacs won't change the size of any window displaying that buffer,
6401 unless you explicitly change the size, or Emacs has no other choice.
6402 This variable automatically becomes buffer-local when set. */);
6403 Fmake_variable_buffer_local (Qwindow_size_fixed);
6404 window_size_fixed = 0;
6405
6406 defsubr (&Sselected_window);
6407 defsubr (&Sminibuffer_window);
6408 defsubr (&Swindow_minibuffer_p);
6409 defsubr (&Swindowp);
6410 defsubr (&Swindow_live_p);
6411 defsubr (&Spos_visible_in_window_p);
6412 defsubr (&Swindow_buffer);
6413 defsubr (&Swindow_height);
6414 defsubr (&Swindow_width);
6415 defsubr (&Swindow_hscroll);
6416 defsubr (&Sset_window_hscroll);
6417 defsubr (&Swindow_redisplay_end_trigger);
6418 defsubr (&Sset_window_redisplay_end_trigger);
6419 defsubr (&Swindow_edges);
6420 defsubr (&Swindow_pixel_edges);
6421 defsubr (&Swindow_inside_edges);
6422 defsubr (&Swindow_inside_pixel_edges);
6423 defsubr (&Scoordinates_in_window_p);
6424 defsubr (&Swindow_at);
6425 defsubr (&Swindow_point);
6426 defsubr (&Swindow_start);
6427 defsubr (&Swindow_end);
6428 defsubr (&Sset_window_point);
6429 defsubr (&Sset_window_start);
6430 defsubr (&Swindow_dedicated_p);
6431 defsubr (&Sset_window_dedicated_p);
6432 defsubr (&Swindow_display_table);
6433 defsubr (&Sset_window_display_table);
6434 defsubr (&Snext_window);
6435 defsubr (&Sprevious_window);
6436 defsubr (&Sother_window);
6437 defsubr (&Sget_lru_window);
6438 defsubr (&Sget_largest_window);
6439 defsubr (&Sget_buffer_window);
6440 defsubr (&Sdelete_other_windows);
6441 defsubr (&Sdelete_windows_on);
6442 defsubr (&Sreplace_buffer_in_windows);
6443 defsubr (&Sdelete_window);
6444 defsubr (&Sset_window_buffer);
6445 defsubr (&Sselect_window);
6446 defsubr (&Sspecial_display_p);
6447 defsubr (&Ssame_window_p);
6448 defsubr (&Sdisplay_buffer);
6449 defsubr (&Ssplit_window);
6450 defsubr (&Senlarge_window);
6451 defsubr (&Sshrink_window);
6452 defsubr (&Sscroll_up);
6453 defsubr (&Sscroll_down);
6454 defsubr (&Sscroll_left);
6455 defsubr (&Sscroll_right);
6456 defsubr (&Sother_window_for_scrolling);
6457 defsubr (&Sscroll_other_window);
6458 defsubr (&Sminibuffer_selected_window);
6459 defsubr (&Srecenter);
6460 defsubr (&Swindow_text_height);
6461 defsubr (&Smove_to_window_line);
6462 defsubr (&Swindow_configuration_p);
6463 defsubr (&Swindow_configuration_frame);
6464 defsubr (&Sset_window_configuration);
6465 defsubr (&Scurrent_window_configuration);
6466 defsubr (&Ssave_window_excursion);
6467 defsubr (&Sset_window_margins);
6468 defsubr (&Swindow_margins);
6469 defsubr (&Sset_window_fringes);
6470 defsubr (&Swindow_fringes);
6471 defsubr (&Sset_window_scroll_bars);
6472 defsubr (&Swindow_scroll_bars);
6473 defsubr (&Swindow_vscroll);
6474 defsubr (&Sset_window_vscroll);
6475 defsubr (&Scompare_window_configurations);
6476 defsubr (&Swindow_list);
6477 }
6478
6479 void
6480 keys_of_window ()
6481 {
6482 initial_define_key (control_x_map, '1', "delete-other-windows");
6483 initial_define_key (control_x_map, '2', "split-window");
6484 initial_define_key (control_x_map, '0', "delete-window");
6485 initial_define_key (control_x_map, 'o', "other-window");
6486 initial_define_key (control_x_map, '^', "enlarge-window");
6487 initial_define_key (control_x_map, '<', "scroll-left");
6488 initial_define_key (control_x_map, '>', "scroll-right");
6489
6490 initial_define_key (global_map, Ctl ('V'), "scroll-up");
6491 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
6492 initial_define_key (meta_map, 'v', "scroll-down");
6493
6494 initial_define_key (global_map, Ctl('L'), "recenter");
6495 initial_define_key (meta_map, 'r', "move-to-window-line");
6496 }