Add prototypes.
[bpt/emacs.git] / 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,1997 Free Software Foundation, Inc.
4
5 This file is part of GNU Emacs.
6
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22 #include <config.h>
23 #include "lisp.h"
24 #include "buffer.h"
25 #include "frame.h"
26 #include "window.h"
27 #include "commands.h"
28 #include "indent.h"
29 #include "termchar.h"
30 #include "disptab.h"
31 #include "keyboard.h"
32 #include "blockinput.h"
33
34 Lisp_Object Qwindowp, Qwindow_live_p;
35
36 static struct window *decode_window P_ ((Lisp_Object));
37
38 /* This is the window in which the terminal's cursor should
39 be left when nothing is being done with it. This must
40 always be a leaf window, and its buffer is selected by
41 the top level editing loop at the end of each command.
42
43 This value is always the same as
44 FRAME_SELECTED_WINDOW (selected_frame). */
45
46 Lisp_Object selected_window;
47
48 /* The minibuffer window of the selected frame.
49 Note that you cannot test for minibufferness of an arbitrary window
50 by comparing against this; but you can test for minibufferness of
51 the selected window. */
52 Lisp_Object minibuf_window;
53
54 /* Non-nil means it is the window for C-M-v to scroll
55 when the minibuffer is selected. */
56 Lisp_Object Vminibuf_scroll_window;
57
58 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
59 Lisp_Object Vother_window_scroll_buffer;
60
61 /* Non-nil means it's function to call to display temp buffers. */
62 Lisp_Object Vtemp_buffer_show_function;
63
64 /* If a window gets smaller than either of these, it is removed. */
65 int window_min_height;
66 int window_min_width;
67
68 /* Nonzero implies Fdisplay_buffer should create windows. */
69 int pop_up_windows;
70
71 /* Nonzero implies make new frames for Fdisplay_buffer. */
72 int pop_up_frames;
73
74 /* Non-nil means use this function instead of default */
75 Lisp_Object Vpop_up_frame_function;
76
77 /* Function to call to handle Fdisplay_buffer. */
78 Lisp_Object Vdisplay_buffer_function;
79
80 /* List of buffer *names* for buffers that should have their own frames. */
81 Lisp_Object Vspecial_display_buffer_names;
82
83 /* List of regexps for buffer names that should have their own frames. */
84 Lisp_Object Vspecial_display_regexps;
85
86 /* Function to pop up a special frame. */
87 Lisp_Object Vspecial_display_function;
88
89 /* List of buffer *names* for buffers to appear in selected window. */
90 Lisp_Object Vsame_window_buffer_names;
91
92 /* List of regexps for buffer names to appear in selected window. */
93 Lisp_Object Vsame_window_regexps;
94
95 /* Hook run at end of temp_output_buffer_show. */
96 Lisp_Object Qtemp_buffer_show_hook;
97
98 /* Fdisplay_buffer always splits the largest window
99 if that window is more than this high. */
100 int split_height_threshold;
101
102 /* Number of lines of continuity in scrolling by screenfuls. */
103 int next_screen_context_lines;
104
105 /* Incremented for each window created. */
106 static int sequence_number;
107
108 /* Nonzero after init_window_once has finished. */
109 static int window_initialized;
110
111 /* Hook to run when window config changes. */
112 Lisp_Object Qwindow_configuration_change_hook;
113 Lisp_Object Vwindow_configuration_change_hook;
114
115 /* Nonzero means scroll commands try to put point
116 at the same screen height as previously. */
117 static int scroll_preserve_screen_position;
118
119 /* Nonzero means we can split a frame even if it is "unsplittable". */
120 static int inhibit_frame_unsplittable;
121
122 #define min(a, b) ((a) < (b) ? (a) : (b))
123
124 extern int scroll_margin;
125
126 extern Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions;
127 \f
128 DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
129 "Returns t if OBJECT is a window.")
130 (object)
131 Lisp_Object object;
132 {
133 return WINDOWP (object) ? Qt : Qnil;
134 }
135
136 DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
137 "Returns t if OBJECT is a window which is currently visible.")
138 (object)
139 Lisp_Object object;
140 {
141 return (WINDOWP (object) && ! NILP (XWINDOW (object)->buffer) ? Qt : Qnil);
142 }
143
144 Lisp_Object
145 make_window ()
146 {
147 Lisp_Object val;
148 register struct window *p;
149 register struct Lisp_Vector *vec;
150 int i;
151
152 vec = allocate_vectorlike ((EMACS_INT) VECSIZE (struct window));
153 for (i = 0; i < VECSIZE (struct window); i++)
154 vec->contents[i] = Qnil;
155 vec->size = VECSIZE (struct window);
156 p = (struct window *)vec;
157 XSETFASTINT (p->sequence_number, ++sequence_number);
158 XSETFASTINT (p->left, 0);
159 XSETFASTINT (p->top, 0);
160 XSETFASTINT (p->height, 0);
161 XSETFASTINT (p->width, 0);
162 XSETFASTINT (p->hscroll, 0);
163 XSETFASTINT (p->last_point_x, 0);
164 XSETFASTINT (p->last_point_y, 0);
165 p->start = Fmake_marker ();
166 p->pointm = Fmake_marker ();
167 XSETFASTINT (p->use_time, 0);
168 p->frame = Qnil;
169 p->display_table = Qnil;
170 p->dedicated = Qnil;
171 XSETWINDOW (val, p);
172 return val;
173 }
174
175 DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
176 "Return the window that the cursor now appears in and commands apply to.")
177 ()
178 {
179 return selected_window;
180 }
181
182 DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
183 "Return the window used now for minibuffers.\n\
184 If the optional argument FRAME is specified, return the minibuffer window\n\
185 used by that frame.")
186 (frame)
187 Lisp_Object frame;
188 {
189 if (NILP (frame))
190 XSETFRAME (frame, selected_frame);
191 else
192 CHECK_LIVE_FRAME (frame, 0);
193
194 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
195 }
196
197 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
198 "Returns non-nil if WINDOW is a minibuffer window.")
199 (window)
200 Lisp_Object window;
201 {
202 struct window *w = decode_window (window);
203 return (MINI_WINDOW_P (w) ? Qt : Qnil);
204 }
205
206 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
207 Spos_visible_in_window_p, 0, 2, 0,
208 "Return t if position POS is currently on the frame in WINDOW.\n\
209 Returns nil if that position is scrolled vertically out of view.\n\
210 POS defaults to point; WINDOW, to the selected window.")
211 (pos, window)
212 Lisp_Object pos, window;
213 {
214 register struct window *w;
215 register int top;
216 register int height;
217 register int posint;
218 register struct buffer *buf;
219 struct position posval;
220 int hscroll;
221
222 if (NILP (pos))
223 posint = PT;
224 else
225 {
226 CHECK_NUMBER_COERCE_MARKER (pos, 0);
227 posint = XINT (pos);
228 }
229
230 w = decode_window (window);
231 top = marker_position (w->start);
232 hscroll = XINT (w->hscroll);
233
234 if (posint < top)
235 return Qnil;
236
237 height = XFASTINT (w->height) - ! MINI_WINDOW_P (w);
238
239 buf = XBUFFER (w->buffer);
240 if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf)
241 && XFASTINT (w->last_overlay_modified) >= BUF_OVERLAY_MODIFF (buf))
242 {
243 /* If frame is up to date,
244 use the info recorded about how much text fit on it. */
245 if (posint < BUF_Z (buf) - XFASTINT (w->window_end_pos)
246 || (XFASTINT (w->window_end_vpos) < height))
247 return Qt;
248 return Qnil;
249 }
250 else
251 {
252 if (posint > BUF_ZV (buf))
253 return Qnil;
254
255 /* w->start can be out of range. If it is, do something reasonable. */
256 if (top < BUF_BEGV (buf) || top > BUF_ZV (buf))
257 return Qnil;
258
259 /* If that info is not correct, calculate afresh */
260 /* BUG FIX for the 7th arg (TOHPOS).
261
262 '0' is harmless, however, ' - (1 << (BITS_PER_SHORT - 1))' is
263 more appropriate here. In case of HSCROLL > 0, this can avoid
264 needless calculation done until (HPOS == 0).
265
266 We want to determine if the position POSINT is in HEIGHT or
267 not. We don't have to do calculation until (HPOS == 0). We
268 can stop it when VPOS goes beyond HEIGHT. */
269 posval = *compute_motion (top, 0, (hscroll ? 1 - hscroll : 0), 0,
270 posint, height, - (1 << (BITS_PER_SHORT - 1)),
271 window_internal_width (w) - 1,
272 hscroll, 0, w);
273
274 return posval.vpos < height ? Qt : Qnil;
275 }
276 }
277 \f
278 static struct window *
279 decode_window (window)
280 register Lisp_Object window;
281 {
282 if (NILP (window))
283 return XWINDOW (selected_window);
284
285 CHECK_LIVE_WINDOW (window, 0);
286 return XWINDOW (window);
287 }
288
289 DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
290 "Return the buffer that WINDOW is displaying.")
291 (window)
292 Lisp_Object window;
293 {
294 return decode_window (window)->buffer;
295 }
296
297 DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
298 "Return the number of lines in WINDOW (including its mode line).")
299 (window)
300 Lisp_Object window;
301 {
302 return decode_window (window)->height;
303 }
304
305 DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0,
306 "Return the number of display columns in WINDOW.\n\
307 This is the width that is usable columns available for text in WINDOW.\n\
308 If you want to find out how many columns WINDOW takes up,\n\
309 use (let ((edges (window-edges))) (- (nth 2 edges) (nth 0 edges))).")
310 (window)
311 Lisp_Object window;
312 {
313 return make_number (window_internal_width (decode_window (window)));
314 }
315
316 DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
317 "Return the number of columns by which WINDOW is scrolled from left margin.")
318 (window)
319 Lisp_Object window;
320 {
321 return decode_window (window)->hscroll;
322 }
323
324 DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
325 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
326 NCOL should be zero or positive.")
327 (window, ncol)
328 register Lisp_Object window, ncol;
329 {
330 register struct window *w;
331
332 CHECK_NUMBER (ncol, 1);
333 if (XINT (ncol) < 0) XSETFASTINT (ncol, 0);
334 w = decode_window (window);
335 if (XINT (w->hscroll) != XINT (ncol))
336 XBUFFER (w->buffer)->clip_changed = 1; /* Prevent redisplay shortcuts */
337 w->hscroll = ncol;
338 return ncol;
339 }
340
341 DEFUN ("window-redisplay-end-trigger", Fwindow_redisplay_end_trigger,
342 Swindow_redisplay_end_trigger, 0, 1, 0,
343 "Return WINDOW's redisplay end trigger value.\n\
344 See `set-window-redisplay-end-trigger' for more information.")
345 (window)
346 Lisp_Object window;
347 {
348 return decode_window (window)->redisplay_end_trigger;
349 }
350
351 DEFUN ("set-window-redisplay-end-trigger", Fset_window_redisplay_end_trigger,
352 Sset_window_redisplay_end_trigger, 2, 2, 0,
353 "Set WINDOW's redisplay end trigger value to VALUE.\n\
354 VALUE should be a buffer position (typically a marker) or nil.\n\
355 If it is a buffer position, then if redisplay in WINDOW reaches a position\n\
356 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called\n\
357 with two arguments: WINDOW, and the end trigger value.\n\
358 Afterwards the end-trigger value is reset to nil.")
359 (window, value)
360 register Lisp_Object window, value;
361 {
362 register struct window *w;
363
364 w = decode_window (window);
365 w->redisplay_end_trigger = value;
366 return value;
367 }
368
369 DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
370 "Return a list of the edge coordinates of WINDOW.\n\
371 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
372 RIGHT is one more than the rightmost column used by WINDOW,\n\
373 and BOTTOM is one more than the bottommost row used by WINDOW\n\
374 and its mode-line.")
375 (window)
376 Lisp_Object window;
377 {
378 register struct window *w = decode_window (window);
379
380 return Fcons (w->left, Fcons (w->top,
381 Fcons (make_number (WINDOW_RIGHT_EDGE (w)),
382 Fcons (make_number (XFASTINT (w->top)
383 + XFASTINT (w->height)),
384 Qnil))));
385 }
386
387 /* Test if the character at column *x, row *y is within window *w.
388 If it is not, return 0;
389 if it is in the window's text area,
390 set *x and *y to its location relative to the upper left corner
391 of the window, and
392 return 1;
393 if it is on the window's modeline, return 2;
394 if it is on the border between the window and its right sibling,
395 return 3. */
396 static int
397 coordinates_in_window (w, x, y)
398 register struct window *w;
399 register int *x, *y;
400 {
401 register int left = XINT (w->left);
402 register int right_edge = WINDOW_RIGHT_EDGE (w);
403 register int left_margin = WINDOW_LEFT_MARGIN (w);
404 register int right_margin = WINDOW_RIGHT_MARGIN (w);
405 register int window_height = XINT (w->height);
406 register int top = XFASTINT (w->top);
407
408 if ( *x < left || *x >= right_edge
409 || *y < top || *y >= top + window_height)
410 return 0;
411
412 if (left_margin != left && *x < left_margin && *x >= left)
413 return 3;
414
415 if (right_margin != right_edge && *x >= right_margin && *x < right_edge)
416 return 3;
417
418 /* Is the character is the mode line? */
419 if (*y == top + window_height - 1
420 && ! MINI_WINDOW_P (w))
421 return 2;
422
423 *x -= WINDOW_LEFT_MARGIN (w);
424 *y -= top;
425 return 1;
426 }
427
428 DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
429 Scoordinates_in_window_p, 2, 2, 0,
430 "Return non-nil if COORDINATES are in WINDOW.\n\
431 COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
432 measured in characters from the upper-left corner of the frame.\n\
433 (0 . 0) denotes the character in the upper left corner of the\n\
434 frame.\n\
435 If COORDINATES are in the text portion of WINDOW,\n\
436 the coordinates relative to the window are returned.\n\
437 If they are in the mode line of WINDOW, `mode-line' is returned.\n\
438 If they are on the border between WINDOW and its right sibling,\n\
439 `vertical-line' is returned.")
440 (coordinates, window)
441 register Lisp_Object coordinates, window;
442 {
443 int x, y;
444
445 CHECK_LIVE_WINDOW (window, 0);
446 CHECK_CONS (coordinates, 1);
447 x = XINT (Fcar (coordinates));
448 y = XINT (Fcdr (coordinates));
449
450 switch (coordinates_in_window (XWINDOW (window), &x, &y))
451 {
452 case 0: /* NOT in window at all. */
453 return Qnil;
454
455 case 1: /* In text part of window. */
456 return Fcons (make_number (x), make_number (y));
457
458 case 2: /* In mode line of window. */
459 return Qmode_line;
460
461 case 3: /* On right border of window. */
462 return Qvertical_line;
463
464 default:
465 abort ();
466 }
467 }
468
469 /* Find the window containing column x, row y, and return it as a
470 Lisp_Object. If x, y is on the window's modeline, set *part
471 to 1; if it is on the separating line between the window and its
472 right sibling, set it to 2; otherwise set it to 0. If there is no
473 window under x, y return nil and leave *part unmodified. */
474 Lisp_Object
475 window_from_coordinates (frame, x, y, part)
476 FRAME_PTR frame;
477 int x, y;
478 int *part;
479 {
480 register Lisp_Object tem, first;
481
482 tem = first = FRAME_SELECTED_WINDOW (frame);
483
484 do
485 {
486 int found = coordinates_in_window (XWINDOW (tem), &x, &y);
487
488 if (found)
489 {
490 *part = found - 1;
491 return tem;
492 }
493
494 tem = Fnext_window (tem, Qt, Qlambda);
495 }
496 while (! EQ (tem, first));
497
498 return Qnil;
499 }
500
501 DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
502 "Return window containing coordinates X and Y on FRAME.\n\
503 If omitted, FRAME defaults to the currently selected frame.\n\
504 The top left corner of the frame is considered to be row 0,\n\
505 column 0.")
506 (x, y, frame)
507 Lisp_Object x, y, frame;
508 {
509 int part;
510
511 if (NILP (frame))
512 XSETFRAME (frame, selected_frame);
513 else
514 CHECK_LIVE_FRAME (frame, 2);
515 CHECK_NUMBER (x, 0);
516 CHECK_NUMBER (y, 1);
517
518 return window_from_coordinates (XFRAME (frame),
519 XINT (x), XINT (y),
520 &part);
521 }
522
523 DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
524 "Return current value of point in WINDOW.\n\
525 For a nonselected window, this is the value point would have\n\
526 if that window were selected.\n\
527 \n\
528 Note that, when WINDOW is the selected window and its buffer\n\
529 is also currently selected, the value returned is the same as (point).\n\
530 It would be more strictly correct to return the `top-level' value\n\
531 of point, outside of any save-excursion forms.\n\
532 But that is hard to define.")
533 (window)
534 Lisp_Object window;
535 {
536 register struct window *w = decode_window (window);
537
538 if (w == XWINDOW (selected_window)
539 && current_buffer == XBUFFER (w->buffer))
540 return Fpoint ();
541 return Fmarker_position (w->pointm);
542 }
543
544 DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
545 "Return position at which display currently starts in WINDOW.\n\
546 This is updated by redisplay or by calling `set-window-start'.")
547 (window)
548 Lisp_Object window;
549 {
550 return Fmarker_position (decode_window (window)->start);
551 }
552
553 /* This is text temporarily removed from the doc string below.
554
555 This function returns nil if the position is not currently known.\n\
556 That happens when redisplay is preempted and doesn't finish.\n\
557 If in that case you want to compute where the end of the window would\n\
558 have been if redisplay had finished, do this:\n\
559 (save-excursion\n\
560 (goto-char (window-start window))\n\
561 (vertical-motion (1- (window-height window)) window)\n\
562 (point))") */
563
564 DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 1, 0,
565 "Return position at which display currently ends in WINDOW.\n\
566 This is updated by redisplay, when it runs to completion.\n\
567 Simply changing the buffer text or setting `window-start'\n\
568 does not update this value.")
569 (window)
570 Lisp_Object window;
571 {
572 Lisp_Object value;
573 struct window *w = decode_window (window);
574 Lisp_Object buf;
575
576 buf = w->buffer;
577 CHECK_BUFFER (buf, 0);
578
579 #if 0 /* This change broke some things. We should make it later. */
580 /* If we don't know the end position, return nil.
581 The user can compute it with vertical-motion if he wants to.
582 It would be nicer to do it automatically,
583 but that's so slow that it would probably bother people. */
584 if (NILP (w->window_end_valid))
585 return Qnil;
586 #endif
587
588 XSETINT (value,
589 BUF_Z (XBUFFER (buf)) - XFASTINT (w->window_end_pos));
590
591 return value;
592 }
593
594 DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
595 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
596 (window, pos)
597 Lisp_Object window, pos;
598 {
599 register struct window *w = decode_window (window);
600
601 CHECK_NUMBER_COERCE_MARKER (pos, 1);
602 if (w == XWINDOW (selected_window))
603 Fgoto_char (pos);
604 else
605 set_marker_restricted (w->pointm, pos, w->buffer);
606
607 return pos;
608 }
609
610 DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
611 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
612 Optional third arg NOFORCE non-nil inhibits next redisplay\n\
613 from overriding motion of point in order to display at this exact start.")
614 (window, pos, noforce)
615 Lisp_Object window, pos, noforce;
616 {
617 register struct window *w = decode_window (window);
618
619 CHECK_NUMBER_COERCE_MARKER (pos, 1);
620 set_marker_restricted (w->start, pos, w->buffer);
621 /* this is not right, but much easier than doing what is right. */
622 w->start_at_line_beg = Qnil;
623 if (NILP (noforce))
624 w->force_start = Qt;
625 w->update_mode_line = Qt;
626 XSETFASTINT (w->last_modified, 0);
627 XSETFASTINT (w->last_overlay_modified, 0);
628 if (!EQ (window, selected_window))
629 windows_or_buffers_changed++;
630 return pos;
631 }
632
633 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
634 1, 1, 0,
635 "Return WINDOW's dedicated object, usually t or nil.\n\
636 See also `set-window-dedicated-p'.")
637 (window)
638 Lisp_Object window;
639 {
640 return decode_window (window)->dedicated;
641 }
642
643 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
644 Sset_window_dedicated_p, 2, 2, 0,
645 "Control whether WINDOW is dedicated to the buffer it displays.\n\
646 If it is dedicated, Emacs will not automatically change\n\
647 which buffer appears in it.\n\
648 The second argument is the new value for the dedication flag;\n\
649 non-nil means yes.")
650 (window, arg)
651 Lisp_Object window, arg;
652 {
653 register struct window *w = decode_window (window);
654
655 if (NILP (arg))
656 w->dedicated = Qnil;
657 else
658 w->dedicated = Qt;
659
660 return w->dedicated;
661 }
662
663 DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
664 0, 1, 0,
665 "Return the display-table that WINDOW is using.")
666 (window)
667 Lisp_Object window;
668 {
669 return decode_window (window)->display_table;
670 }
671
672 /* Get the display table for use currently on window W.
673 This is either W's display table or W's buffer's display table.
674 Ignore the specified tables if they are not valid;
675 if no valid table is specified, return 0. */
676
677 struct Lisp_Char_Table *
678 window_display_table (w)
679 struct window *w;
680 {
681 Lisp_Object tem;
682 tem = w->display_table;
683 if (DISP_TABLE_P (tem))
684 return XCHAR_TABLE (tem);
685 tem = XBUFFER (w->buffer)->display_table;
686 if (DISP_TABLE_P (tem))
687 return XCHAR_TABLE (tem);
688 tem = Vstandard_display_table;
689 if (DISP_TABLE_P (tem))
690 return XCHAR_TABLE (tem);
691 return 0;
692 }
693
694 DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
695 "Set WINDOW's display-table to TABLE.")
696 (window, table)
697 register Lisp_Object window, table;
698 {
699 register struct window *w;
700 register Lisp_Object z; /* Return value. */
701
702 w = decode_window (window);
703 w->display_table = table;
704 return table;
705 }
706 \f
707 /* Record info on buffer window w is displaying
708 when it is about to cease to display that buffer. */
709 static
710 unshow_buffer (w)
711 register struct window *w;
712 {
713 Lisp_Object buf;
714
715 buf = w->buffer;
716 if (XBUFFER (buf) != XMARKER (w->pointm)->buffer)
717 abort ();
718
719 if (w == XWINDOW (XBUFFER (buf)->last_selected_window))
720 XBUFFER (buf)->last_selected_window = Qnil;
721
722 #if 0
723 if (w == XWINDOW (selected_window)
724 || ! EQ (buf, XWINDOW (selected_window)->buffer))
725 /* Do this except when the selected window's buffer
726 is being removed from some other window. */
727 #endif
728 /* last_window_start records the start position that this buffer
729 had in the last window to be disconnected from it.
730 Now that this statement is unconditional,
731 it is possible for the buffer to be displayed in the
732 selected window, while last_window_start reflects another
733 window which was recently showing the same buffer.
734 Some people might say that might be a good thing. Let's see. */
735 XBUFFER (buf)->last_window_start = marker_position (w->start);
736
737 /* Point in the selected window's buffer
738 is actually stored in that buffer, and the window's pointm isn't used.
739 So don't clobber point in that buffer. */
740 if (! EQ (buf, XWINDOW (selected_window)->buffer))
741 BUF_PT (XBUFFER (buf))
742 = clip_to_bounds (BUF_BEGV (XBUFFER (buf)),
743 marker_position (w->pointm),
744 BUF_ZV (XBUFFER (buf)));
745 }
746
747 /* Put replacement into the window structure in place of old. */
748 static
749 replace_window (old, replacement)
750 Lisp_Object old, replacement;
751 {
752 register Lisp_Object tem;
753 register struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
754
755 /* If OLD is its frame's root_window, then replacement is the new
756 root_window for that frame. */
757
758 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
759 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
760
761 p->left = o->left;
762 p->top = o->top;
763 p->width = o->width;
764 p->height = o->height;
765
766 p->next = tem = o->next;
767 if (!NILP (tem))
768 XWINDOW (tem)->prev = replacement;
769
770 p->prev = tem = o->prev;
771 if (!NILP (tem))
772 XWINDOW (tem)->next = replacement;
773
774 p->parent = tem = o->parent;
775 if (!NILP (tem))
776 {
777 if (EQ (XWINDOW (tem)->vchild, old))
778 XWINDOW (tem)->vchild = replacement;
779 if (EQ (XWINDOW (tem)->hchild, old))
780 XWINDOW (tem)->hchild = replacement;
781 }
782
783 /*** Here, if replacement is a vertical combination
784 and so is its new parent, we should make replacement's
785 children be children of that parent instead. ***/
786 }
787
788 DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
789 "Remove WINDOW from the display. Default is selected window.")
790 (window)
791 register Lisp_Object window;
792 {
793 delete_window (window);
794
795 if (! NILP (Vwindow_configuration_change_hook)
796 && ! NILP (Vrun_hooks))
797 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
798
799 return Qnil;
800 }
801
802 void
803 delete_window (window)
804 register Lisp_Object window;
805 {
806 register Lisp_Object tem, parent, sib;
807 register struct window *p;
808 register struct window *par;
809
810 /* Because this function is called by other C code on non-leaf
811 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
812 so we can't decode_window here. */
813 if (NILP (window))
814 window = selected_window;
815 else
816 CHECK_WINDOW (window, 0);
817 p = XWINDOW (window);
818
819 /* It's okay to delete an already-deleted window. */
820 if (NILP (p->buffer)
821 && NILP (p->hchild)
822 && NILP (p->vchild))
823 return;
824
825 parent = p->parent;
826 if (NILP (parent))
827 error ("Attempt to delete minibuffer or sole ordinary window");
828 par = XWINDOW (parent);
829
830 windows_or_buffers_changed++;
831 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (p))) = 1;
832
833 /* Are we trying to delete any frame's selected window? */
834 {
835 Lisp_Object frame, pwindow;
836
837 /* See if the frame's selected window is either WINDOW
838 or any subwindow of it, by finding all that window's parents
839 and comparing each one with WINDOW. */
840 frame = WINDOW_FRAME (XWINDOW (window));
841 pwindow = FRAME_SELECTED_WINDOW (XFRAME (frame));
842
843 while (!NILP (pwindow))
844 {
845 if (EQ (window, pwindow))
846 break;
847 pwindow = XWINDOW (pwindow)->parent;
848 }
849
850 if (EQ (window, pwindow))
851 {
852 Lisp_Object alternative;
853 alternative = Fnext_window (window, Qlambda, Qnil);
854
855 /* If we're about to delete the selected window on the
856 selected frame, then we should use Fselect_window to select
857 the new window. On the other hand, if we're about to
858 delete the selected window on any other frame, we shouldn't do
859 anything but set the frame's selected_window slot. */
860 if (EQ (window, selected_window))
861 Fselect_window (alternative);
862 else
863 FRAME_SELECTED_WINDOW (XFRAME (frame)) = alternative;
864 }
865 }
866
867 tem = p->buffer;
868 /* tem is null for dummy parent windows
869 (which have inferiors but not any contents themselves) */
870 if (!NILP (tem))
871 {
872 unshow_buffer (p);
873 unchain_marker (p->pointm);
874 unchain_marker (p->start);
875 }
876
877 tem = p->next;
878 if (!NILP (tem))
879 XWINDOW (tem)->prev = p->prev;
880
881 tem = p->prev;
882 if (!NILP (tem))
883 XWINDOW (tem)->next = p->next;
884
885 if (EQ (window, par->hchild))
886 par->hchild = p->next;
887 if (EQ (window, par->vchild))
888 par->vchild = p->next;
889
890 /* Find one of our siblings to give our space to. */
891 sib = p->prev;
892 if (NILP (sib))
893 {
894 /* If p gives its space to its next sibling, that sibling needs
895 to have its top/left side pulled back to where p's is.
896 set_window_{height,width} will re-position the sibling's
897 children. */
898 sib = p->next;
899 XWINDOW (sib)->top = p->top;
900 XWINDOW (sib)->left = p->left;
901 }
902
903 /* Stretch that sibling. */
904 if (!NILP (par->vchild))
905 set_window_height (sib,
906 XFASTINT (XWINDOW (sib)->height) + XFASTINT (p->height),
907 1);
908 if (!NILP (par->hchild))
909 set_window_width (sib,
910 XFASTINT (XWINDOW (sib)->width) + XFASTINT (p->width),
911 1);
912
913 /* If parent now has only one child,
914 put the child into the parent's place. */
915 tem = par->hchild;
916 if (NILP (tem))
917 tem = par->vchild;
918 if (NILP (XWINDOW (tem)->next))
919 replace_window (parent, tem);
920
921 /* Since we may be deleting combination windows, we must make sure that
922 not only p but all its children have been marked as deleted. */
923 if (! NILP (p->hchild))
924 delete_all_subwindows (XWINDOW (p->hchild));
925 else if (! NILP (p->vchild))
926 delete_all_subwindows (XWINDOW (p->vchild));
927
928 /* Mark this window as deleted. */
929 p->buffer = p->hchild = p->vchild = Qnil;
930 }
931 \f
932
933 extern Lisp_Object next_frame (), prev_frame ();
934
935 /* This comment supplies the doc string for `next-window',
936 for make-docfile to see. We cannot put this in the real DEFUN
937 due to limits in the Unix cpp.
938
939 DEFUN ("next-window", Ffoo, Sfoo, 0, 3, 0,
940 "Return next window after WINDOW in canonical ordering of windows.\n\
941 If omitted, WINDOW defaults to the selected window.\n\
942 \n\
943 Optional second arg MINIBUF t means count the minibuffer window even\n\
944 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
945 it is active. MINIBUF neither t nor nil means not to count the\n\
946 minibuffer even if it is active.\n\
947 \n\
948 Several frames may share a single minibuffer; if the minibuffer\n\
949 counts, all windows on all frames that share that minibuffer count\n\
950 too. Therefore, `next-window' can be used to iterate through the\n\
951 set of windows even when the minibuffer is on another frame. If the\n\
952 minibuffer does not count, only windows from WINDOW's frame count.\n\
953 \n\
954 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
955 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
956 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
957 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
958 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
959 Anything else means restrict to WINDOW's frame.\n\
960 \n\
961 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
962 `next-window' to iterate through the entire cycle of acceptable\n\
963 windows, eventually ending up back at the window you started with.\n\
964 `previous-window' traverses the same cycle, in the reverse order.")
965 (window, minibuf, all_frames) */
966
967 DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
968 0)
969 (window, minibuf, all_frames)
970 register Lisp_Object window, minibuf, all_frames;
971 {
972 register Lisp_Object tem;
973 Lisp_Object start_window;
974
975 if (NILP (window))
976 window = selected_window;
977 else
978 CHECK_LIVE_WINDOW (window, 0);
979
980 start_window = window;
981
982 /* minibuf == nil may or may not include minibuffers.
983 Decide if it does. */
984 if (NILP (minibuf))
985 minibuf = (minibuf_level ? minibuf_window : Qlambda);
986 else if (! EQ (minibuf, Qt))
987 minibuf = Qlambda;
988 /* Now minibuf can be t => count all minibuffer windows,
989 lambda => count none of them,
990 or a specific minibuffer window (the active one) to count. */
991
992 /* all_frames == nil doesn't specify which frames to include. */
993 if (NILP (all_frames))
994 all_frames = (! EQ (minibuf, Qlambda)
995 ? (FRAME_MINIBUF_WINDOW
996 (XFRAME
997 (WINDOW_FRAME
998 (XWINDOW (window)))))
999 : Qnil);
1000 else if (EQ (all_frames, Qvisible))
1001 ;
1002 else if (XFASTINT (all_frames) == 0)
1003 ;
1004 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
1005 /* If all_frames is a frame and window arg isn't on that frame, just
1006 return the first window on the frame. */
1007 return Fframe_first_window (all_frames);
1008 else if (! EQ (all_frames, Qt))
1009 all_frames = Qnil;
1010 /* Now all_frames is t meaning search all frames,
1011 nil meaning search just current frame,
1012 visible meaning search just visible frames,
1013 0 meaning search visible and iconified frames,
1014 or a window, meaning search the frame that window belongs to. */
1015
1016 /* Do this loop at least once, to get the next window, and perhaps
1017 again, if we hit the minibuffer and that is not acceptable. */
1018 do
1019 {
1020 /* Find a window that actually has a next one. This loop
1021 climbs up the tree. */
1022 while (tem = XWINDOW (window)->next, NILP (tem))
1023 if (tem = XWINDOW (window)->parent, !NILP (tem))
1024 window = tem;
1025 else
1026 {
1027 /* We've reached the end of this frame.
1028 Which other frames are acceptable? */
1029 tem = WINDOW_FRAME (XWINDOW (window));
1030 if (! NILP (all_frames))
1031 {
1032 Lisp_Object tem1;
1033
1034 tem1 = tem;
1035 tem = next_frame (tem, all_frames);
1036 /* In the case where the minibuffer is active,
1037 and we include its frame as well as the selected one,
1038 next_frame may get stuck in that frame.
1039 If that happens, go back to the selected frame
1040 so we can complete the cycle. */
1041 if (EQ (tem, tem1))
1042 XSETFRAME (tem, selected_frame);
1043 }
1044 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
1045
1046 break;
1047 }
1048
1049 window = tem;
1050
1051 /* If we're in a combination window, find its first child and
1052 recurse on that. Otherwise, we've found the window we want. */
1053 while (1)
1054 {
1055 if (!NILP (XWINDOW (window)->hchild))
1056 window = XWINDOW (window)->hchild;
1057 else if (!NILP (XWINDOW (window)->vchild))
1058 window = XWINDOW (window)->vchild;
1059 else break;
1060 }
1061 }
1062 /* Which windows are acceptable?
1063 Exit the loop and accept this window if
1064 this isn't a minibuffer window,
1065 or we're accepting all minibuffer windows,
1066 or this is the active minibuffer and we are accepting that one, or
1067 we've come all the way around and we're back at the original window. */
1068 while (MINI_WINDOW_P (XWINDOW (window))
1069 && ! EQ (minibuf, Qt)
1070 && ! EQ (minibuf, window)
1071 && ! EQ (window, start_window));
1072
1073 return window;
1074 }
1075
1076 /* This comment supplies the doc string for `previous-window',
1077 for make-docfile to see. We cannot put this in the real DEFUN
1078 due to limits in the Unix cpp.
1079
1080 DEFUN ("previous-window", Ffoo, Sfoo, 0, 3, 0,
1081 "Return the window preceding WINDOW in canonical ordering of windows.\n\
1082 If omitted, WINDOW defaults to the selected window.\n\
1083 \n\
1084 Optional second arg MINIBUF t means count the minibuffer window even\n\
1085 if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
1086 it is active. MINIBUF neither t nor nil means not to count the\n\
1087 minibuffer even if it is active.\n\
1088 \n\
1089 Several frames may share a single minibuffer; if the minibuffer\n\
1090 counts, all windows on all frames that share that minibuffer count\n\
1091 too. Therefore, `previous-window' can be used to iterate through\n\
1092 the set of windows even when the minibuffer is on another frame. If\n\
1093 the minibuffer does not count, only windows from WINDOW's frame count\n\
1094 \n\
1095 Optional third arg ALL-FRAMES t means include windows on all frames.\n\
1096 ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
1097 above. ALL-FRAMES = `visible' means include windows on all visible frames.\n\
1098 ALL-FRAMES = 0 means include windows on all visible and iconified frames.\n\
1099 If ALL-FRAMES is a frame, restrict search to windows on that frame.\n\
1100 Anything else means restrict to WINDOW's frame.\n\
1101 \n\
1102 If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
1103 `previous-window' to iterate through the entire cycle of acceptable\n\
1104 windows, eventually ending up back at the window you started with.\n\
1105 `next-window' traverses the same cycle, in the reverse order.")
1106 (window, minibuf, all_frames) */
1107
1108
1109 DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
1110 0)
1111 (window, minibuf, all_frames)
1112 register Lisp_Object window, minibuf, all_frames;
1113 {
1114 register Lisp_Object tem;
1115 Lisp_Object start_window;
1116
1117 if (NILP (window))
1118 window = selected_window;
1119 else
1120 CHECK_LIVE_WINDOW (window, 0);
1121
1122 start_window = window;
1123
1124 /* minibuf == nil may or may not include minibuffers.
1125 Decide if it does. */
1126 if (NILP (minibuf))
1127 minibuf = (minibuf_level ? minibuf_window : Qlambda);
1128 else if (! EQ (minibuf, Qt))
1129 minibuf = Qlambda;
1130 /* Now minibuf can be t => count all minibuffer windows,
1131 lambda => count none of them,
1132 or a specific minibuffer window (the active one) to count. */
1133
1134 /* all_frames == nil doesn't specify which frames to include.
1135 Decide which frames it includes. */
1136 if (NILP (all_frames))
1137 all_frames = (! EQ (minibuf, Qlambda)
1138 ? (FRAME_MINIBUF_WINDOW
1139 (XFRAME
1140 (WINDOW_FRAME
1141 (XWINDOW (window)))))
1142 : Qnil);
1143 else if (EQ (all_frames, Qvisible))
1144 ;
1145 else if (XFASTINT (all_frames) == 0)
1146 ;
1147 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
1148 /* If all_frames is a frame and window arg isn't on that frame, just
1149 return the first window on the frame. */
1150 return Fframe_first_window (all_frames);
1151 else if (! EQ (all_frames, Qt))
1152 all_frames = Qnil;
1153 /* Now all_frames is t meaning search all frames,
1154 nil meaning search just current frame,
1155 visible meaning search just visible frames,
1156 0 meaning search visible and iconified frames,
1157 or a window, meaning search the frame that window belongs to. */
1158
1159 /* Do this loop at least once, to get the previous window, and perhaps
1160 again, if we hit the minibuffer and that is not acceptable. */
1161 do
1162 {
1163 /* Find a window that actually has a previous one. This loop
1164 climbs up the tree. */
1165 while (tem = XWINDOW (window)->prev, NILP (tem))
1166 if (tem = XWINDOW (window)->parent, !NILP (tem))
1167 window = tem;
1168 else
1169 {
1170 /* We have found the top window on the frame.
1171 Which frames are acceptable? */
1172 tem = WINDOW_FRAME (XWINDOW (window));
1173 if (! NILP (all_frames))
1174 /* It's actually important that we use prev_frame here,
1175 rather than next_frame. All the windows acceptable
1176 according to the given parameters should form a ring;
1177 Fnext_window and Fprevious_window should go back and
1178 forth around the ring. If we use next_frame here,
1179 then Fnext_window and Fprevious_window take different
1180 paths through the set of acceptable windows.
1181 window_loop assumes that these `ring' requirement are
1182 met. */
1183 {
1184 Lisp_Object tem1;
1185
1186 tem1 = tem;
1187 tem = prev_frame (tem, all_frames);
1188 /* In the case where the minibuffer is active,
1189 and we include its frame as well as the selected one,
1190 next_frame may get stuck in that frame.
1191 If that happens, go back to the selected frame
1192 so we can complete the cycle. */
1193 if (EQ (tem, tem1))
1194 XSETFRAME (tem, selected_frame);
1195 }
1196 /* If this frame has a minibuffer, find that window first,
1197 because it is conceptually the last window in that frame. */
1198 if (FRAME_HAS_MINIBUF_P (XFRAME (tem)))
1199 tem = FRAME_MINIBUF_WINDOW (XFRAME (tem));
1200 else
1201 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
1202
1203 break;
1204 }
1205
1206 window = tem;
1207 /* If we're in a combination window, find its last child and
1208 recurse on that. Otherwise, we've found the window we want. */
1209 while (1)
1210 {
1211 if (!NILP (XWINDOW (window)->hchild))
1212 window = XWINDOW (window)->hchild;
1213 else if (!NILP (XWINDOW (window)->vchild))
1214 window = XWINDOW (window)->vchild;
1215 else break;
1216 while (tem = XWINDOW (window)->next, !NILP (tem))
1217 window = tem;
1218 }
1219 }
1220 /* Which windows are acceptable?
1221 Exit the loop and accept this window if
1222 this isn't a minibuffer window,
1223 or we're accepting all minibuffer windows,
1224 or this is the active minibuffer and we are accepting that one, or
1225 we've come all the way around and we're back at the original window. */
1226 while (MINI_WINDOW_P (XWINDOW (window))
1227 && ! EQ (minibuf, Qt)
1228 && ! EQ (minibuf, window)
1229 && ! EQ (window, start_window));
1230
1231 return window;
1232 }
1233
1234 DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
1235 "Select the ARG'th different window on this frame.\n\
1236 All windows on current frame are arranged in a cyclic order.\n\
1237 This command selects the window ARG steps away in that order.\n\
1238 A negative ARG moves in the opposite order. If the optional second\n\
1239 argument ALL_FRAMES is non-nil, cycle through all frames.")
1240 (arg, all_frames)
1241 register Lisp_Object arg, all_frames;
1242 {
1243 register int i;
1244 register Lisp_Object w;
1245
1246 CHECK_NUMBER (arg, 0);
1247 w = selected_window;
1248 i = XINT (arg);
1249
1250 while (i > 0)
1251 {
1252 w = Fnext_window (w, Qnil, all_frames);
1253 i--;
1254 }
1255 while (i < 0)
1256 {
1257 w = Fprevious_window (w, Qnil, all_frames);
1258 i++;
1259 }
1260 Fselect_window (w);
1261 return Qnil;
1262 }
1263 \f
1264 /* Look at all windows, performing an operation specified by TYPE
1265 with argument OBJ.
1266 If FRAMES is Qt, look at all frames;
1267 Qnil, look at just the selected frame;
1268 Qvisible, look at visible frames;
1269 a frame, just look at windows on that frame.
1270 If MINI is non-zero, perform the operation on minibuffer windows too.
1271 */
1272
1273 enum window_loop
1274 {
1275 WINDOW_LOOP_UNUSED,
1276 GET_BUFFER_WINDOW, /* Arg is buffer */
1277 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
1278 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
1279 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
1280 GET_LARGEST_WINDOW,
1281 UNSHOW_BUFFER /* Arg is buffer */
1282 };
1283
1284 static Lisp_Object
1285 window_loop (type, obj, mini, frames)
1286 enum window_loop type;
1287 register Lisp_Object obj, frames;
1288 int mini;
1289 {
1290 register Lisp_Object w;
1291 register Lisp_Object best_window;
1292 register Lisp_Object next_window;
1293 register Lisp_Object last_window;
1294 FRAME_PTR frame;
1295 Lisp_Object frame_arg;
1296 frame_arg = Qt;
1297
1298 /* If we're only looping through windows on a particular frame,
1299 frame points to that frame. If we're looping through windows
1300 on all frames, frame is 0. */
1301 if (FRAMEP (frames))
1302 frame = XFRAME (frames);
1303 else if (NILP (frames))
1304 frame = selected_frame;
1305 else
1306 frame = 0;
1307 if (frame)
1308 frame_arg = Qlambda;
1309 else if (XFASTINT (frames) == 0)
1310 frame_arg = frames;
1311 else if (EQ (frames, Qvisible))
1312 frame_arg = frames;
1313
1314 /* frame_arg is Qlambda to stick to one frame,
1315 Qvisible to consider all visible frames,
1316 or Qt otherwise. */
1317
1318 /* Pick a window to start with. */
1319 if (WINDOWP (obj))
1320 w = obj;
1321 else if (frame)
1322 w = FRAME_SELECTED_WINDOW (frame);
1323 else
1324 w = FRAME_SELECTED_WINDOW (selected_frame);
1325
1326 /* Figure out the last window we're going to mess with. Since
1327 Fnext_window, given the same options, is guaranteed to go in a
1328 ring, we can just use Fprevious_window to find the last one.
1329
1330 We can't just wait until we hit the first window again, because
1331 it might be deleted. */
1332
1333 last_window = Fprevious_window (w, mini ? Qt : Qnil, frame_arg);
1334
1335 best_window = Qnil;
1336 for (;;)
1337 {
1338 FRAME_PTR w_frame = XFRAME (WINDOW_FRAME (XWINDOW (w)));
1339
1340 /* Pick the next window now, since some operations will delete
1341 the current window. */
1342 next_window = Fnext_window (w, mini ? Qt : Qnil, frame_arg);
1343
1344 /* Note that we do not pay attention here to whether
1345 the frame is visible, since Fnext_window skips non-visible frames
1346 if that is desired, under the control of frame_arg. */
1347 if (! MINI_WINDOW_P (XWINDOW (w))
1348 || (mini && minibuf_level > 0))
1349 switch (type)
1350 {
1351 case GET_BUFFER_WINDOW:
1352 if (XBUFFER (XWINDOW (w)->buffer) == XBUFFER (obj)
1353 /* Don't find any minibuffer window
1354 except the one that is currently in use. */
1355 && (MINI_WINDOW_P (XWINDOW (w))
1356 ? EQ (w, minibuf_window) : 1))
1357 return w;
1358 break;
1359
1360 case GET_LRU_WINDOW:
1361 /* t as arg means consider only full-width windows */
1362 if (!NILP (obj) && !WINDOW_FULL_WIDTH_P (XWINDOW (w)))
1363 break;
1364 /* Ignore dedicated windows and minibuffers. */
1365 if (MINI_WINDOW_P (XWINDOW (w))
1366 || !NILP (XWINDOW (w)->dedicated))
1367 break;
1368 if (NILP (best_window)
1369 || (XFASTINT (XWINDOW (best_window)->use_time)
1370 > XFASTINT (XWINDOW (w)->use_time)))
1371 best_window = w;
1372 break;
1373
1374 case DELETE_OTHER_WINDOWS:
1375 if (XWINDOW (w) != XWINDOW (obj))
1376 Fdelete_window (w);
1377 break;
1378
1379 case DELETE_BUFFER_WINDOWS:
1380 if (EQ (XWINDOW (w)->buffer, obj))
1381 {
1382 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w)));
1383
1384 /* If this window is dedicated, and in a frame of its own,
1385 kill the frame. */
1386 if (EQ (w, FRAME_ROOT_WINDOW (f))
1387 && !NILP (XWINDOW (w)->dedicated)
1388 && other_visible_frames (f))
1389 {
1390 /* Skip the other windows on this frame.
1391 There might be one, the minibuffer! */
1392 if (! EQ (w, last_window))
1393 while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window))))
1394 {
1395 /* As we go, check for the end of the loop.
1396 We mustn't start going around a second time. */
1397 if (EQ (next_window, last_window))
1398 {
1399 last_window = w;
1400 break;
1401 }
1402 next_window = Fnext_window (next_window,
1403 mini ? Qt : Qnil,
1404 frame_arg);
1405 }
1406 /* Now we can safely delete the frame. */
1407 Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil);
1408 }
1409 else
1410 /* If we're deleting the buffer displayed in the only window
1411 on the frame, find a new buffer to display there. */
1412 if (NILP (XWINDOW (w)->parent))
1413 {
1414 Lisp_Object new_buffer;
1415 new_buffer = Fother_buffer (obj, Qnil);
1416 if (NILP (new_buffer))
1417 new_buffer
1418 = Fget_buffer_create (build_string ("*scratch*"));
1419 Fset_window_buffer (w, new_buffer);
1420 if (EQ (w, selected_window))
1421 Fset_buffer (XWINDOW (w)->buffer);
1422 }
1423 else
1424 Fdelete_window (w);
1425 }
1426 break;
1427
1428 case GET_LARGEST_WINDOW:
1429 /* Ignore dedicated windows and minibuffers. */
1430 if (MINI_WINDOW_P (XWINDOW (w))
1431 || !NILP (XWINDOW (w)->dedicated))
1432 break;
1433 {
1434 struct window *best_window_ptr = XWINDOW (best_window);
1435 struct window *w_ptr = XWINDOW (w);
1436 if (NILP (best_window)
1437 || (XFASTINT (w_ptr->height) * XFASTINT (w_ptr->width)
1438 > (XFASTINT (best_window_ptr->height)
1439 * XFASTINT (best_window_ptr->width))))
1440 best_window = w;
1441 }
1442 break;
1443
1444 case UNSHOW_BUFFER:
1445 if (EQ (XWINDOW (w)->buffer, obj))
1446 {
1447 /* Find another buffer to show in this window. */
1448 Lisp_Object another_buffer;
1449 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (w)));
1450 another_buffer = Fother_buffer (obj, Qnil);
1451 if (NILP (another_buffer))
1452 another_buffer
1453 = Fget_buffer_create (build_string ("*scratch*"));
1454 /* If this window is dedicated, and in a frame of its own,
1455 kill the frame. */
1456 if (EQ (w, FRAME_ROOT_WINDOW (f))
1457 && !NILP (XWINDOW (w)->dedicated)
1458 && other_visible_frames (f))
1459 {
1460 /* Skip the other windows on this frame.
1461 There might be one, the minibuffer! */
1462 if (! EQ (w, last_window))
1463 while (f == XFRAME (WINDOW_FRAME (XWINDOW (next_window))))
1464 {
1465 /* As we go, check for the end of the loop.
1466 We mustn't start going around a second time. */
1467 if (EQ (next_window, last_window))
1468 {
1469 last_window = w;
1470 break;
1471 }
1472 next_window = Fnext_window (next_window,
1473 mini ? Qt : Qnil,
1474 frame_arg);
1475 }
1476 /* Now we can safely delete the frame. */
1477 Fdelete_frame (WINDOW_FRAME (XWINDOW (w)), Qnil);
1478 }
1479 else
1480 {
1481 /* Otherwise show a different buffer in the window. */
1482 XWINDOW (w)->dedicated = Qnil;
1483 Fset_window_buffer (w, another_buffer);
1484 if (EQ (w, selected_window))
1485 Fset_buffer (XWINDOW (w)->buffer);
1486 }
1487 }
1488 break;
1489 }
1490
1491 if (EQ (w, last_window))
1492 break;
1493
1494 w = next_window;
1495 }
1496
1497 return best_window;
1498 }
1499
1500 DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0,
1501 "Return the window least recently selected or used for display.\n\
1502 If optional argument FRAME is `visible', search all visible frames.\n\
1503 If FRAME is 0, search all visible and iconified frames.\n\
1504 If FRAME is t, search all frames.\n\
1505 If FRAME is nil, search only the selected frame.\n\
1506 If FRAME is a frame, search only that frame.")
1507 (frame)
1508 Lisp_Object frame;
1509 {
1510 register Lisp_Object w;
1511 /* First try for a window that is full-width */
1512 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame);
1513 if (!NILP (w) && !EQ (w, selected_window))
1514 return w;
1515 /* If none of them, try the rest */
1516 return window_loop (GET_LRU_WINDOW, Qnil, 0, frame);
1517 }
1518
1519 DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0,
1520 "Return the largest window in area.\n\
1521 If optional argument FRAME is `visible', search all visible frames.\n\
1522 If FRAME is 0, search all visible and iconified frames.\n\
1523 If FRAME is t, search all frames.\n\
1524 If FRAME is nil, search only the selected frame.\n\
1525 If FRAME is a frame, search only that frame.")
1526 (frame)
1527 Lisp_Object frame;
1528 {
1529 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
1530 frame);
1531 }
1532
1533 DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0,
1534 "Return a window currently displaying BUFFER, or nil if none.\n\
1535 If optional argument FRAME is `visible', search all visible frames.\n\
1536 If optional argument FRAME is 0, search all visible and iconified frames.\n\
1537 If FRAME is t, search all frames.\n\
1538 If FRAME is nil, search only the selected frame.\n\
1539 If FRAME is a frame, search only that frame.")
1540 (buffer, frame)
1541 Lisp_Object buffer, frame;
1542 {
1543 buffer = Fget_buffer (buffer);
1544 if (BUFFERP (buffer))
1545 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame);
1546 else
1547 return Qnil;
1548 }
1549
1550 DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows,
1551 0, 1, "",
1552 "Make WINDOW (or the selected window) fill its frame.\n\
1553 Only the frame WINDOW is on is affected.\n\
1554 This function tries to reduce display jumps\n\
1555 by keeping the text previously visible in WINDOW\n\
1556 in the same place on the frame. Doing this depends on\n\
1557 the value of (window-start WINDOW), so if calling this function\n\
1558 in a program gives strange scrolling, make sure the window-start\n\
1559 value is reasonable when this function is called.")
1560 (window)
1561 Lisp_Object window;
1562 {
1563 struct window *w;
1564 int startpos;
1565 int top;
1566
1567 if (NILP (window))
1568 window = selected_window;
1569 else
1570 CHECK_LIVE_WINDOW (window, 0);
1571
1572 w = XWINDOW (window);
1573
1574 startpos = marker_position (w->start);
1575 top = XFASTINT (w->top) - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w)));
1576
1577 if (MINI_WINDOW_P (w) && top > 0)
1578 error ("Can't expand minibuffer to full frame");
1579
1580 window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w));
1581
1582 /* Try to minimize scrolling, by setting the window start to the point
1583 will cause the text at the old window start to be at the same place
1584 on the frame. But don't try to do this if the window start is
1585 outside the visible portion (as might happen when the display is
1586 not current, due to typeahead). */
1587 if (startpos >= BUF_BEGV (XBUFFER (w->buffer))
1588 && startpos <= BUF_ZV (XBUFFER (w->buffer)))
1589 {
1590 struct position pos;
1591 struct buffer *obuf = current_buffer;
1592
1593 Fset_buffer (w->buffer);
1594 /* This computation used to temporarily move point, but that can
1595 have unwanted side effects due to text properties. */
1596 pos = *vmotion (startpos, -top, w);
1597
1598 Fset_marker (w->start, make_number (pos.bufpos), w->buffer);
1599 w->start_at_line_beg = ((pos.bufpos == BEGV
1600 || FETCH_BYTE (pos.bufpos - 1) == '\n') ? Qt
1601 : Qnil);
1602 /* We need to do this, so that the window-scroll-functions
1603 get called. */
1604 w->optional_new_start = Qt;
1605
1606 set_buffer_internal (obuf);
1607 }
1608 return Qnil;
1609 }
1610
1611 DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on,
1612 1, 2, "bDelete windows on (buffer): ",
1613 "Delete all windows showing BUFFER.\n\
1614 Optional second argument FRAME controls which frames are affected.\n\
1615 If nil or omitted, delete all windows showing BUFFER in any frame.\n\
1616 If t, delete only windows showing BUFFER in the selected frame.\n\
1617 If `visible', delete all windows showing BUFFER in any visible frame.\n\
1618 If a frame, delete only windows showing BUFFER in that frame.")
1619 (buffer, frame)
1620 Lisp_Object buffer, frame;
1621 {
1622 /* FRAME uses t and nil to mean the opposite of what window_loop
1623 expects. */
1624 if (! FRAMEP (frame))
1625 frame = NILP (frame) ? Qt : Qnil;
1626
1627 if (!NILP (buffer))
1628 {
1629 buffer = Fget_buffer (buffer);
1630 CHECK_BUFFER (buffer, 0);
1631 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame);
1632 }
1633 return Qnil;
1634 }
1635
1636 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
1637 Sreplace_buffer_in_windows,
1638 1, 1, "bReplace buffer in windows: ",
1639 "Replace BUFFER with some other buffer in all windows showing it.")
1640 (buffer)
1641 Lisp_Object buffer;
1642 {
1643 if (!NILP (buffer))
1644 {
1645 buffer = Fget_buffer (buffer);
1646 CHECK_BUFFER (buffer, 0);
1647 window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
1648 }
1649 return Qnil;
1650 }
1651
1652 /* Replace BUFFER with some other buffer in all windows
1653 of all frames, even those on other keyboards. */
1654
1655 void
1656 replace_buffer_in_all_windows (buffer)
1657 Lisp_Object buffer;
1658 {
1659 #ifdef MULTI_KBOARD
1660 Lisp_Object tail, frame;
1661
1662 /* A single call to window_loop won't do the job
1663 because it only considers frames on the current keyboard.
1664 So loop manually over frames, and handle each one. */
1665 FOR_EACH_FRAME (tail, frame)
1666 window_loop (UNSHOW_BUFFER, buffer, 1, frame);
1667 #else
1668 window_loop (UNSHOW_BUFFER, buffer, 1, Qt);
1669 #endif
1670 }
1671 \f
1672 /* Set the height of WINDOW and all its inferiors. */
1673
1674 /* The smallest acceptable dimensions for a window. Anything smaller
1675 might crash Emacs. */
1676 #define MIN_SAFE_WINDOW_WIDTH (2)
1677 #define MIN_SAFE_WINDOW_HEIGHT (2)
1678
1679 /* Make sure that window_min_height and window_min_width are
1680 not too small; if they are, set them to safe minima. */
1681
1682 static void
1683 check_min_window_sizes ()
1684 {
1685 /* Smaller values might permit a crash. */
1686 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
1687 window_min_width = MIN_SAFE_WINDOW_WIDTH;
1688 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
1689 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
1690 }
1691
1692 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
1693 minimum allowable size. */
1694 void
1695 check_frame_size (frame, rows, cols)
1696 FRAME_PTR frame;
1697 int *rows, *cols;
1698 {
1699 /* For height, we have to see:
1700 whether the frame has a minibuffer,
1701 whether it wants a mode line, and
1702 whether it has a menu bar. */
1703 int min_height =
1704 (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
1705 : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
1706 : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
1707 if (FRAME_MENU_BAR_LINES (frame) > 0)
1708 min_height += FRAME_MENU_BAR_LINES (frame);
1709
1710 if (*rows < min_height)
1711 *rows = min_height;
1712 if (*cols < MIN_SAFE_WINDOW_WIDTH)
1713 *cols = MIN_SAFE_WINDOW_WIDTH;
1714 }
1715
1716 /* Normally the window is deleted if it gets too small.
1717 nodelete nonzero means do not do this.
1718 (The caller should check later and do so if appropriate) */
1719
1720 void
1721 set_window_height (window, height, nodelete)
1722 Lisp_Object window;
1723 int height;
1724 int nodelete;
1725 {
1726 register struct window *w = XWINDOW (window);
1727 register struct window *c;
1728 int oheight = XFASTINT (w->height);
1729 int top, pos, lastbot, opos, lastobot;
1730 Lisp_Object child;
1731
1732 check_min_window_sizes ();
1733
1734 if (!nodelete
1735 && ! NILP (w->parent)
1736 && (MINI_WINDOW_P (w)
1737 ? height < 1
1738 : height < window_min_height))
1739 {
1740 delete_window (window);
1741 return;
1742 }
1743
1744 XSETFASTINT (w->last_modified, 0);
1745 XSETFASTINT (w->last_overlay_modified, 0);
1746 windows_or_buffers_changed++;
1747 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
1748
1749 XSETFASTINT (w->height, height);
1750 if (!NILP (w->hchild))
1751 {
1752 for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next)
1753 {
1754 XWINDOW (child)->top = w->top;
1755 set_window_height (child, height, nodelete);
1756 }
1757 }
1758 else if (!NILP (w->vchild))
1759 {
1760 lastbot = top = XFASTINT (w->top);
1761 lastobot = 0;
1762 for (child = w->vchild; !NILP (child); child = c->next)
1763 {
1764 c = XWINDOW (child);
1765
1766 opos = lastobot + XFASTINT (c->height);
1767
1768 XSETFASTINT (c->top, lastbot);
1769
1770 pos = (((opos * height) << 1) + oheight) / (oheight << 1);
1771
1772 /* Avoid confusion: inhibit deletion of child if becomes too small */
1773 set_window_height (child, pos + top - lastbot, 1);
1774
1775 /* Now advance child to next window,
1776 and set lastbot if child was not just deleted. */
1777 lastbot = pos + top;
1778 lastobot = opos;
1779 }
1780 /* Now delete any children that became too small. */
1781 if (!nodelete)
1782 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
1783 {
1784 set_window_height (child, XINT (XWINDOW (child)->height), 0);
1785 }
1786 }
1787 }
1788
1789 /* Recursively set width of WINDOW and its inferiors. */
1790
1791 void
1792 set_window_width (window, width, nodelete)
1793 Lisp_Object window;
1794 int width;
1795 int nodelete;
1796 {
1797 register struct window *w = XWINDOW (window);
1798 register struct window *c;
1799 int owidth = XFASTINT (w->width);
1800 int left, pos, lastright, opos, lastoright;
1801 Lisp_Object child;
1802
1803 if (!nodelete && width < window_min_width && !NILP (w->parent))
1804 {
1805 delete_window (window);
1806 return;
1807 }
1808
1809 XSETFASTINT (w->last_modified, 0);
1810 XSETFASTINT (w->last_overlay_modified, 0);
1811 windows_or_buffers_changed++;
1812 FRAME_WINDOW_SIZES_CHANGED (XFRAME (WINDOW_FRAME (w))) = 1;
1813
1814 XSETFASTINT (w->width, width);
1815 if (!NILP (w->vchild))
1816 {
1817 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
1818 {
1819 XWINDOW (child)->left = w->left;
1820 set_window_width (child, width, nodelete);
1821 }
1822 }
1823 else if (!NILP (w->hchild))
1824 {
1825 lastright = left = XFASTINT (w->left);
1826 lastoright = 0;
1827 for (child = w->hchild; !NILP (child); child = c->next)
1828 {
1829 c = XWINDOW (child);
1830
1831 opos = lastoright + XFASTINT (c->width);
1832
1833 XSETFASTINT (c->left, lastright);
1834
1835 pos = (((opos * width) << 1) + owidth) / (owidth << 1);
1836
1837 /* Inhibit deletion for becoming too small */
1838 set_window_width (child, pos + left - lastright, 1);
1839
1840 /* Now advance child to next window,
1841 and set lastright if child was not just deleted. */
1842 lastright = pos + left, lastoright = opos;
1843 }
1844 /* Delete children that became too small */
1845 if (!nodelete)
1846 for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next)
1847 {
1848 set_window_width (child, XINT (XWINDOW (child)->width), 0);
1849 }
1850 }
1851 }
1852 \f
1853 int window_select_count;
1854
1855 Lisp_Object
1856 Fset_window_buffer_unwind (obuf)
1857 Lisp_Object obuf;
1858 {
1859 Fset_buffer (obuf);
1860 return Qnil;
1861 }
1862
1863 DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0,
1864 "Make WINDOW display BUFFER as its contents.\n\
1865 BUFFER can be a buffer or buffer name.")
1866 (window, buffer)
1867 register Lisp_Object window, buffer;
1868 {
1869 register Lisp_Object tem;
1870 register struct window *w = decode_window (window);
1871 int count = specpdl_ptr - specpdl;
1872
1873 buffer = Fget_buffer (buffer);
1874 CHECK_BUFFER (buffer, 1);
1875
1876 if (NILP (XBUFFER (buffer)->name))
1877 error ("Attempt to display deleted buffer");
1878
1879 tem = w->buffer;
1880 if (NILP (tem))
1881 error ("Window is deleted");
1882 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
1883 is first being set up. */
1884 {
1885 if (!NILP (w->dedicated) && !EQ (tem, buffer))
1886 error ("Window is dedicated to `%s'",
1887 XSTRING (XBUFFER (tem)->name)->data);
1888
1889 unshow_buffer (w);
1890 }
1891
1892 w->buffer = buffer;
1893
1894 if (EQ (window, selected_window))
1895 XBUFFER (w->buffer)->last_selected_window = window;
1896 if (INTEGERP (XBUFFER (buffer)->display_count))
1897 XSETINT (XBUFFER (buffer)->display_count,
1898 XINT (XBUFFER (buffer)->display_count) + 1);
1899
1900 XSETFASTINT (w->window_end_pos, 0);
1901 w->window_end_valid = Qnil;
1902 XSETFASTINT (w->hscroll, 0);
1903 Fset_marker (w->pointm,
1904 make_number (BUF_PT (XBUFFER (buffer))),
1905 buffer);
1906 set_marker_restricted (w->start,
1907 make_number (XBUFFER (buffer)->last_window_start),
1908 buffer);
1909 w->start_at_line_beg = Qnil;
1910 w->force_start = Qnil;
1911 XSETFASTINT (w->last_modified, 0);
1912 XSETFASTINT (w->last_overlay_modified, 0);
1913 windows_or_buffers_changed++;
1914
1915 /* We must select BUFFER for running the window-scroll-functions.
1916 If WINDOW is selected, switch permanently.
1917 Otherwise, switch but go back to the ambient buffer afterward. */
1918 if (EQ (window, selected_window))
1919 Fset_buffer (buffer);
1920 /* We can't check ! NILP (Vwindow_scroll_functions) here
1921 because that might itself be a local variable. */
1922 else if (window_initialized)
1923 {
1924 record_unwind_protect (Fset_window_buffer_unwind, Fcurrent_buffer ());
1925 Fset_buffer (buffer);
1926 }
1927
1928 if (! NILP (Vwindow_scroll_functions))
1929 run_hook_with_args_2 (Qwindow_scroll_functions, window,
1930 Fmarker_position (w->start));
1931
1932 if (! NILP (Vwindow_configuration_change_hook)
1933 && ! NILP (Vrun_hooks))
1934 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
1935
1936 unbind_to (count, Qnil);
1937
1938 return Qnil;
1939 }
1940
1941 DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0,
1942 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1943 The main editor command loop selects the buffer of the selected window\n\
1944 before each command.")
1945 (window)
1946 register Lisp_Object window;
1947 {
1948 register struct window *w;
1949 register struct window *ow = XWINDOW (selected_window);
1950
1951 CHECK_LIVE_WINDOW (window, 0);
1952
1953 w = XWINDOW (window);
1954
1955 if (NILP (w->buffer))
1956 error ("Trying to select deleted window or non-leaf window");
1957
1958 XSETFASTINT (w->use_time, ++window_select_count);
1959 if (EQ (window, selected_window))
1960 return window;
1961
1962 Fset_marker (ow->pointm, make_number (BUF_PT (XBUFFER (ow->buffer))),
1963 ow->buffer);
1964
1965 selected_window = window;
1966 if (XFRAME (WINDOW_FRAME (w)) != selected_frame)
1967 {
1968 XFRAME (WINDOW_FRAME (w))->selected_window = window;
1969 /* Use this rather than Fhandle_switch_frame
1970 so that FRAME_FOCUS_FRAME is moved appropriately as we
1971 move around in the state where a minibuffer in a separate
1972 frame is active. */
1973 Fselect_frame (WINDOW_FRAME (w), Qnil);
1974 }
1975 else
1976 selected_frame->selected_window = window;
1977
1978 record_buffer (w->buffer);
1979 Fset_buffer (w->buffer);
1980
1981 XBUFFER (w->buffer)->last_selected_window = window;
1982
1983 /* Go to the point recorded in the window.
1984 This is important when the buffer is in more
1985 than one window. It also matters when
1986 redisplay_window has altered point after scrolling,
1987 because it makes the change only in the window. */
1988 {
1989 register int new_point = marker_position (w->pointm);
1990 if (new_point < BEGV)
1991 SET_PT (BEGV);
1992 else if (new_point > ZV)
1993 SET_PT (ZV);
1994 else
1995 SET_PT (new_point);
1996 }
1997
1998 windows_or_buffers_changed++;
1999 return window;
2000 }
2001
2002 /* Deiconify the frame containing the window WINDOW,
2003 unless it is the selected frame;
2004 then return WINDOW.
2005
2006 The reason for the exception for the selected frame
2007 is that it seems better not to change the selected frames visibility
2008 merely because of displaying a different buffer in it.
2009 The deiconification is useful when a buffer gets shown in
2010 another frame that you were not using lately. */
2011
2012 static Lisp_Object
2013 display_buffer_1 (window)
2014 Lisp_Object window;
2015 {
2016 FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (window)));
2017 FRAME_SAMPLE_VISIBILITY (f);
2018 if (f != selected_frame)
2019 {
2020 if (FRAME_ICONIFIED_P (f))
2021 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
2022 else if (FRAME_VISIBLE_P (f))
2023 Fraise_frame (WINDOW_FRAME (XWINDOW (window)));
2024 }
2025 return window;
2026 }
2027
2028 DEFUN ("special-display-p", Fspecial_display_p, Sspecial_display_p, 1, 1, 0,
2029 "Returns non-nil if a buffer named BUFFER-NAME would be created specially.\n\
2030 The value is actually t if the frame should be called with default frame\n\
2031 parameters, and a list of frame parameters if they were specified.\n\
2032 See `special-display-buffer-names', and `special-display-regexps'.")
2033 (buffer_name)
2034 Lisp_Object buffer_name;
2035 {
2036 Lisp_Object tem;
2037
2038 CHECK_STRING (buffer_name, 1);
2039
2040 tem = Fmember (buffer_name, Vspecial_display_buffer_names);
2041 if (!NILP (tem))
2042 return Qt;
2043
2044 tem = Fassoc (buffer_name, Vspecial_display_buffer_names);
2045 if (!NILP (tem))
2046 return XCDR (tem);
2047
2048 for (tem = Vspecial_display_regexps; CONSP (tem); tem = XCDR (tem))
2049 {
2050 Lisp_Object car = XCAR (tem);
2051 if (STRINGP (car)
2052 && fast_string_match (car, buffer_name) >= 0)
2053 return Qt;
2054 else if (CONSP (car)
2055 && STRINGP (XCAR (car))
2056 && fast_string_match (XCAR (car), buffer_name) >= 0)
2057 return XCDR (tem);
2058 }
2059 return Qnil;
2060 }
2061
2062 DEFUN ("same-window-p", Fsame_window_p, Ssame_window_p, 1, 1, 0,
2063 "Returns non-nil if a new buffer named BUFFER-NAME would use the same window.\n\
2064 See `same-window-buffer-names' and `same-window-regexps'.")
2065 (buffer_name)
2066 Lisp_Object buffer_name;
2067 {
2068 Lisp_Object tem;
2069
2070 CHECK_STRING (buffer_name, 1);
2071
2072 tem = Fmember (buffer_name, Vsame_window_buffer_names);
2073 if (!NILP (tem))
2074 return Qt;
2075
2076 tem = Fassoc (buffer_name, Vsame_window_buffer_names);
2077 if (!NILP (tem))
2078 return Qt;
2079
2080 for (tem = Vsame_window_regexps; CONSP (tem); tem = XCDR (tem))
2081 {
2082 Lisp_Object car = XCAR (tem);
2083 if (STRINGP (car)
2084 && fast_string_match (car, buffer_name) >= 0)
2085 return Qt;
2086 else if (CONSP (car)
2087 && STRINGP (XCAR (car))
2088 && fast_string_match (XCAR (car), buffer_name) >= 0)
2089 return Qt;
2090 }
2091 return Qnil;
2092 }
2093
2094 DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2,
2095 "BDisplay buffer: \nP", /* Use B so the default is (other-buffer). */
2096 "Make BUFFER appear in some window but don't select it.\n\
2097 BUFFER can be a buffer or a buffer name.\n\
2098 If BUFFER is shown already in some window, just use that one,\n\
2099 unless the window is the selected window and the optional second\n\
2100 argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
2101 If `pop-up-frames' is non-nil, make a new frame if no window shows BUFFER.\n\
2102 Returns the window displaying BUFFER.\n\
2103 \n\
2104 The variables `special-display-buffer-names', `special-display-regexps',\n\
2105 `same-window-buffer-names', and `same-window-regexps' customize how certain\n\
2106 buffer names are handled.")
2107 (buffer, not_this_window)
2108 register Lisp_Object buffer, not_this_window;
2109 {
2110 register Lisp_Object window, tem;
2111
2112 buffer = Fget_buffer (buffer);
2113 CHECK_BUFFER (buffer, 0);
2114
2115 if (!NILP (Vdisplay_buffer_function))
2116 return call2 (Vdisplay_buffer_function, buffer, not_this_window);
2117
2118 if (NILP (not_this_window)
2119 && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
2120 return display_buffer_1 (selected_window);
2121
2122 /* See if the user has specified this buffer should appear
2123 in the selected window. */
2124 if (NILP (not_this_window))
2125 {
2126 tem = Fsame_window_p (XBUFFER (buffer)->name);
2127 if (!NILP (tem))
2128 {
2129 Fswitch_to_buffer (buffer, Qnil);
2130 return display_buffer_1 (selected_window);
2131 }
2132 }
2133
2134 /* If pop_up_frames,
2135 look for a window showing BUFFER on any visible or iconified frame.
2136 Otherwise search only the current frame. */
2137 if (pop_up_frames || last_nonminibuf_frame == 0)
2138 XSETFASTINT (tem, 0);
2139 else
2140 XSETFRAME (tem, last_nonminibuf_frame);
2141 window = Fget_buffer_window (buffer, tem);
2142 if (!NILP (window)
2143 && (NILP (not_this_window) || !EQ (window, selected_window)))
2144 {
2145 return display_buffer_1 (window);
2146 }
2147
2148 /* Certain buffer names get special handling. */
2149 if (!NILP (Vspecial_display_function))
2150 {
2151 tem = Fspecial_display_p (XBUFFER (buffer)->name);
2152 if (EQ (tem, Qt))
2153 return call1 (Vspecial_display_function, buffer);
2154 if (CONSP (tem))
2155 return call2 (Vspecial_display_function, buffer, tem);
2156 }
2157
2158 /* If there are no frames open that have more than a minibuffer,
2159 we need to create a new frame. */
2160 if (pop_up_frames || last_nonminibuf_frame == 0)
2161 {
2162 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
2163 Fset_window_buffer (window, buffer);
2164 return display_buffer_1 (window);
2165 }
2166
2167 if (pop_up_windows
2168 || FRAME_MINIBUF_ONLY_P (selected_frame)
2169 /* If the current frame is a special display frame,
2170 don't try to reuse its windows. */
2171 || !NILP (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->dedicated)
2172 )
2173 {
2174 Lisp_Object frames;
2175
2176 frames = Qnil;
2177 if (FRAME_MINIBUF_ONLY_P (selected_frame))
2178 XSETFRAME (frames, last_nonminibuf_frame);
2179 /* Don't try to create a window if would get an error */
2180 if (split_height_threshold < window_min_height << 1)
2181 split_height_threshold = window_min_height << 1;
2182
2183 /* Note that both Fget_largest_window and Fget_lru_window
2184 ignore minibuffers and dedicated windows.
2185 This means they can return nil. */
2186
2187 /* If the frame we would try to split cannot be split,
2188 try other frames. */
2189 if (FRAME_NO_SPLIT_P (NILP (frames) ? selected_frame
2190 : last_nonminibuf_frame))
2191 {
2192 /* Try visible frames first. */
2193 window = Fget_largest_window (Qvisible);
2194 /* If that didn't work, try iconified frames. */
2195 if (NILP (window))
2196 window = Fget_largest_window (make_number (0));
2197 if (NILP (window))
2198 window = Fget_largest_window (Qt);
2199 }
2200 else
2201 window = Fget_largest_window (frames);
2202
2203 /* If we got a tall enough full-width window that can be split,
2204 split it. */
2205 if (!NILP (window)
2206 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
2207 && window_height (window) >= split_height_threshold
2208 && WINDOW_FULL_WIDTH_P (XWINDOW (window)))
2209 window = Fsplit_window (window, Qnil, Qnil);
2210 else
2211 {
2212 Lisp_Object upper, lower, other;
2213
2214 window = Fget_lru_window (frames);
2215 /* If the LRU window is selected, and big enough,
2216 and can be split, split it. */
2217 if (!NILP (window)
2218 && ! FRAME_NO_SPLIT_P (XFRAME (XWINDOW (window)->frame))
2219 && (EQ (window, selected_window)
2220 || EQ (XWINDOW (window)->parent, Qnil))
2221 && window_height (window) >= window_min_height << 1)
2222 window = Fsplit_window (window, Qnil, Qnil);
2223 /* If Fget_lru_window returned nil, try other approaches. */
2224
2225 /* Try visible frames first. */
2226 if (NILP (window))
2227 window = Fget_buffer_window (buffer, Qvisible);
2228 if (NILP (window))
2229 window = Fget_largest_window (Qvisible);
2230 /* If that didn't work, try iconified frames. */
2231 if (NILP (window))
2232 window = Fget_buffer_window (buffer, make_number (0));
2233 if (NILP (window))
2234 window = Fget_largest_window (make_number (0));
2235 /* Try invisible frames. */
2236 if (NILP (window))
2237 window = Fget_buffer_window (buffer, Qt);
2238 if (NILP (window))
2239 window = Fget_largest_window (Qt);
2240 /* As a last resort, make a new frame. */
2241 if (NILP (window))
2242 window = Fframe_selected_window (call0 (Vpop_up_frame_function));
2243 /* If window appears above or below another,
2244 even out their heights. */
2245 other = upper = lower = Qnil;
2246 if (!NILP (XWINDOW (window)->prev))
2247 other = upper = XWINDOW (window)->prev, lower = window;
2248 if (!NILP (XWINDOW (window)->next))
2249 other = lower = XWINDOW (window)->next, upper = window;
2250 if (!NILP (other)
2251 /* Check that OTHER and WINDOW are vertically arrayed. */
2252 && !EQ (XWINDOW (other)->top, XWINDOW (window)->top)
2253 && (XFASTINT (XWINDOW (other)->height)
2254 > XFASTINT (XWINDOW (window)->height)))
2255 {
2256 int total = (XFASTINT (XWINDOW (other)->height)
2257 + XFASTINT (XWINDOW (window)->height));
2258 Lisp_Object old_selected_window;
2259 old_selected_window = selected_window;
2260
2261 selected_window = upper;
2262 change_window_height ((total / 2
2263 - XFASTINT (XWINDOW (upper)->height)),
2264 0);
2265 selected_window = old_selected_window;
2266 }
2267 }
2268 }
2269 else
2270 window = Fget_lru_window (Qnil);
2271
2272 Fset_window_buffer (window, buffer);
2273 return display_buffer_1 (window);
2274 }
2275
2276 void
2277 temp_output_buffer_show (buf)
2278 register Lisp_Object buf;
2279 {
2280 register struct buffer *old = current_buffer;
2281 register Lisp_Object window;
2282 register struct window *w;
2283
2284 XBUFFER (buf)->directory = current_buffer->directory;
2285
2286 Fset_buffer (buf);
2287 BUF_SAVE_MODIFF (XBUFFER (buf)) = MODIFF;
2288 BEGV = BEG;
2289 ZV = Z;
2290 SET_PT (BEG);
2291 XBUFFER (buf)->clip_changed = 1;
2292 set_buffer_internal (old);
2293
2294 if (!EQ (Vtemp_buffer_show_function, Qnil))
2295 call1 (Vtemp_buffer_show_function, buf);
2296 else
2297 {
2298 window = Fdisplay_buffer (buf, Qnil);
2299
2300 if (XFRAME (XWINDOW (window)->frame) != selected_frame)
2301 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
2302 Vminibuf_scroll_window = window;
2303 w = XWINDOW (window);
2304 XSETFASTINT (w->hscroll, 0);
2305 set_marker_restricted (w->start, make_number (1), buf);
2306 set_marker_restricted (w->pointm, make_number (1), buf);
2307
2308 /* Run temp-buffer-show-hook, with the chosen window selected. */
2309 if (!NILP (Vrun_hooks))
2310 {
2311 Lisp_Object tem;
2312 tem = Fboundp (Qtemp_buffer_show_hook);
2313 if (!NILP (tem))
2314 {
2315 tem = Fsymbol_value (Qtemp_buffer_show_hook);
2316 if (!NILP (tem))
2317 {
2318 int count = specpdl_ptr - specpdl;
2319
2320 /* Select the window that was chosen, for running the hook. */
2321 record_unwind_protect (Fset_window_configuration,
2322 Fcurrent_window_configuration (Qnil));
2323
2324 Fselect_window (window);
2325 call1 (Vrun_hooks, Qtemp_buffer_show_hook);
2326 unbind_to (count, Qnil);
2327 }
2328 }
2329 }
2330 }
2331 }
2332 \f
2333 static
2334 make_dummy_parent (window)
2335 Lisp_Object window;
2336 {
2337 Lisp_Object new;
2338 register struct window *o, *p;
2339 register struct Lisp_Vector *vec;
2340 int i;
2341
2342 o = XWINDOW (window);
2343 vec = allocate_vectorlike ((EMACS_INT)VECSIZE (struct window));
2344 for (i = 0; i < VECSIZE (struct window); ++i)
2345 vec->contents[i] = ((struct Lisp_Vector *)o)->contents[i];
2346 vec->size = VECSIZE (struct window);
2347 p = (struct window *)vec;
2348 XSETWINDOW (new, p);
2349
2350 XSETFASTINT (p->sequence_number, ++sequence_number);
2351
2352 /* Put new into window structure in place of window */
2353 replace_window (window, new);
2354
2355 o->next = Qnil;
2356 o->prev = Qnil;
2357 o->vchild = Qnil;
2358 o->hchild = Qnil;
2359 o->parent = new;
2360
2361 p->start = Qnil;
2362 p->pointm = Qnil;
2363 p->buffer = Qnil;
2364 }
2365
2366 DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
2367 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
2368 WINDOW defaults to selected one and SIZE to half its size.\n\
2369 If optional third arg HORFLAG is non-nil, split side by side\n\
2370 and put SIZE columns in the first of the pair.")
2371 (window, size, horflag)
2372 Lisp_Object window, size, horflag;
2373 {
2374 register Lisp_Object new;
2375 register struct window *o, *p;
2376 FRAME_PTR fo;
2377 register int size_int;
2378
2379 if (NILP (window))
2380 window = selected_window;
2381 else
2382 CHECK_LIVE_WINDOW (window, 0);
2383
2384 o = XWINDOW (window);
2385 fo = XFRAME (WINDOW_FRAME (o));
2386
2387 if (NILP (size))
2388 {
2389 if (!NILP (horflag))
2390 /* Calculate the size of the left-hand window, by dividing
2391 the usable space in columns by two. */
2392 size_int = XFASTINT (o->width) >> 1;
2393 else
2394 size_int = XFASTINT (o->height) >> 1;
2395 }
2396 else
2397 {
2398 CHECK_NUMBER (size, 1);
2399 size_int = XINT (size);
2400 }
2401
2402 if (MINI_WINDOW_P (o))
2403 error ("Attempt to split minibuffer window");
2404
2405 check_min_window_sizes ();
2406
2407 if (NILP (horflag))
2408 {
2409 if (size_int < window_min_height)
2410 error ("Window height %d too small (after splitting)", size_int);
2411 if (size_int + window_min_height > XFASTINT (o->height))
2412 error ("Window height %d too small (after splitting)",
2413 XFASTINT (o->height) - size_int);
2414 if (NILP (o->parent)
2415 || NILP (XWINDOW (o->parent)->vchild))
2416 {
2417 make_dummy_parent (window);
2418 new = o->parent;
2419 XWINDOW (new)->vchild = window;
2420 }
2421 }
2422 else
2423 {
2424 if (size_int < window_min_width)
2425 error ("Window width %d too small (after splitting)", size_int);
2426
2427 if (size_int + window_min_width > XFASTINT (o->width))
2428 error ("Window width %d too small (after splitting)",
2429 XFASTINT (o->width) - size_int);
2430 if (NILP (o->parent)
2431 || NILP (XWINDOW (o->parent)->hchild))
2432 {
2433 make_dummy_parent (window);
2434 new = o->parent;
2435 XWINDOW (new)->hchild = window;
2436 }
2437 }
2438
2439 /* Now we know that window's parent is a vertical combination
2440 if we are dividing vertically, or a horizontal combination
2441 if we are making side-by-side windows */
2442
2443 windows_or_buffers_changed++;
2444 FRAME_WINDOW_SIZES_CHANGED (fo) = 1;
2445 new = make_window ();
2446 p = XWINDOW (new);
2447
2448 p->frame = o->frame;
2449 p->next = o->next;
2450 if (!NILP (p->next))
2451 XWINDOW (p->next)->prev = new;
2452 p->prev = window;
2453 o->next = new;
2454 p->parent = o->parent;
2455 p->buffer = Qt;
2456
2457 /* Apportion the available frame space among the two new windows */
2458
2459 if (!NILP (horflag))
2460 {
2461 p->height = o->height;
2462 p->top = o->top;
2463 XSETFASTINT (p->width, XFASTINT (o->width) - size_int);
2464 XSETFASTINT (o->width, size_int);
2465 XSETFASTINT (p->left, XFASTINT (o->left) + size_int);
2466 }
2467 else
2468 {
2469 p->left = o->left;
2470 p->width = o->width;
2471 XSETFASTINT (p->height, XFASTINT (o->height) - size_int);
2472 XSETFASTINT (o->height, size_int);
2473 XSETFASTINT (p->top, XFASTINT (o->top) + size_int);
2474 }
2475
2476 Fset_window_buffer (new, o->buffer);
2477
2478 return new;
2479 }
2480 \f
2481 DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p",
2482 "Make current window ARG lines bigger.\n\
2483 From program, optional second arg non-nil means grow sideways ARG columns.")
2484 (arg, side)
2485 register Lisp_Object arg, side;
2486 {
2487 CHECK_NUMBER (arg, 0);
2488 change_window_height (XINT (arg), !NILP (side));
2489
2490 if (! NILP (Vwindow_configuration_change_hook))
2491 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
2492
2493 return Qnil;
2494 }
2495
2496 DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p",
2497 "Make current window ARG lines smaller.\n\
2498 From program, optional second arg non-nil means shrink sideways arg columns.")
2499 (arg, side)
2500 register Lisp_Object arg, side;
2501 {
2502 CHECK_NUMBER (arg, 0);
2503 change_window_height (-XINT (arg), !NILP (side));
2504
2505 if (! NILP (Vwindow_configuration_change_hook))
2506 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
2507
2508 return Qnil;
2509 }
2510
2511 int
2512 window_height (window)
2513 Lisp_Object window;
2514 {
2515 register struct window *p = XWINDOW (window);
2516 return XFASTINT (p->height);
2517 }
2518
2519 int
2520 window_width (window)
2521 Lisp_Object window;
2522 {
2523 register struct window *p = XWINDOW (window);
2524 return XFASTINT (p->width);
2525 }
2526
2527 #define MINSIZE(w) \
2528 (widthflag \
2529 ? window_min_width \
2530 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
2531
2532 #define CURBEG(w) \
2533 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
2534
2535 #define CURSIZE(w) \
2536 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
2537
2538 /* Unlike set_window_height, this function
2539 also changes the heights of the siblings so as to
2540 keep everything consistent. */
2541
2542 void
2543 change_window_height (delta, widthflag)
2544 register int delta;
2545 int widthflag;
2546 {
2547 register Lisp_Object parent;
2548 Lisp_Object window;
2549 register struct window *p;
2550 int *sizep;
2551 int (*sizefun) P_ ((Lisp_Object))
2552 = widthflag ? window_width : window_height;
2553 register void (*setsizefun) P_ ((Lisp_Object, int, int))
2554 = (widthflag ? set_window_width : set_window_height);
2555 int maximum;
2556 Lisp_Object next, prev;
2557
2558 check_min_window_sizes ();
2559
2560 window = selected_window;
2561 while (1)
2562 {
2563 p = XWINDOW (window);
2564 parent = p->parent;
2565 if (NILP (parent))
2566 {
2567 if (widthflag)
2568 error ("No other window to side of this one");
2569 break;
2570 }
2571 if (widthflag ? !NILP (XWINDOW (parent)->hchild)
2572 : !NILP (XWINDOW (parent)->vchild))
2573 break;
2574 window = parent;
2575 }
2576
2577 sizep = &CURSIZE (window);
2578
2579 {
2580 register int maxdelta;
2581
2582 maxdelta = (!NILP (parent) ? (*sizefun) (parent) - *sizep
2583 : !NILP (p->next) ? (*sizefun) (p->next) - MINSIZE (p->next)
2584 : !NILP (p->prev) ? (*sizefun) (p->prev) - MINSIZE (p->prev)
2585 /* This is a frame with only one window, a minibuffer-only
2586 or a minibufferless frame. */
2587 : (delta = 0));
2588
2589 if (delta > maxdelta)
2590 /* This case traps trying to make the minibuffer
2591 the full frame, or make the only window aside from the
2592 minibuffer the full frame. */
2593 delta = maxdelta;
2594 }
2595
2596 if (*sizep + delta < MINSIZE (window))
2597 {
2598 delete_window (window);
2599 return;
2600 }
2601
2602 if (delta == 0)
2603 return;
2604
2605 /* Find the total we can get from other siblings. */
2606 maximum = 0;
2607 for (next = p->next; ! NILP (next); next = XWINDOW (next)->next)
2608 maximum += (*sizefun) (next) - MINSIZE (next);
2609 for (prev = p->prev; ! NILP (prev); prev = XWINDOW (prev)->prev)
2610 maximum += (*sizefun) (prev) - MINSIZE (prev);
2611
2612 /* If we can get it all from them, do so. */
2613 if (delta <= maximum)
2614 {
2615 Lisp_Object first_unaffected;
2616 Lisp_Object first_affected;
2617
2618 next = p->next;
2619 prev = p->prev;
2620 first_affected = window;
2621 /* Look at one sibling at a time,
2622 moving away from this window in both directions alternately,
2623 and take as much as we can get without deleting that sibling. */
2624 while (delta != 0)
2625 {
2626 if (delta == 0)
2627 break;
2628 if (! NILP (next))
2629 {
2630 int this_one = (*sizefun) (next) - MINSIZE (next);
2631 if (this_one > delta)
2632 this_one = delta;
2633
2634 (*setsizefun) (next, (*sizefun) (next) - this_one, 0);
2635 (*setsizefun) (window, *sizep + this_one, 0);
2636
2637 delta -= this_one;
2638 next = XWINDOW (next)->next;
2639 }
2640 if (delta == 0)
2641 break;
2642 if (! NILP (prev))
2643 {
2644 int this_one = (*sizefun) (prev) - MINSIZE (prev);
2645 if (this_one > delta)
2646 this_one = delta;
2647
2648 first_affected = prev;
2649
2650 (*setsizefun) (prev, (*sizefun) (prev) - this_one, 0);
2651 (*setsizefun) (window, *sizep + this_one, 0);
2652
2653 delta -= this_one;
2654 prev = XWINDOW (prev)->prev;
2655 }
2656 }
2657
2658 /* Now recalculate the edge positions of all the windows affected,
2659 based on the new sizes. */
2660 first_unaffected = next;
2661 prev = first_affected;
2662 for (next = XWINDOW (prev)->next; ! EQ (next, first_unaffected);
2663 prev = next, next = XWINDOW (next)->next)
2664 {
2665 CURBEG (next) = CURBEG (prev) + (*sizefun) (prev);
2666 /* This does not change size of NEXT,
2667 but it propagates the new top edge to its children */
2668 (*setsizefun) (next, (*sizefun) (next), 0);
2669 }
2670 }
2671 else
2672 {
2673 register int delta1;
2674 register int opht = (*sizefun) (parent);
2675
2676 /* If trying to grow this window to or beyond size of the parent,
2677 make delta1 so big that, on shrinking back down,
2678 all the siblings end up with less than one line and are deleted. */
2679 if (opht <= *sizep + delta)
2680 delta1 = opht * opht * 2;
2681 /* Otherwise, make delta1 just right so that if we add delta1
2682 lines to this window and to the parent, and then shrink
2683 the parent back to its original size, the new proportional
2684 size of this window will increase by delta. */
2685 else
2686 delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100);
2687
2688 /* Add delta1 lines or columns to this window, and to the parent,
2689 keeping things consistent while not affecting siblings. */
2690 CURSIZE (parent) = opht + delta1;
2691 (*setsizefun) (window, *sizep + delta1, 0);
2692
2693 /* Squeeze out delta1 lines or columns from our parent,
2694 shriking this window and siblings proportionately.
2695 This brings parent back to correct size.
2696 Delta1 was calculated so this makes this window the desired size,
2697 taking it all out of the siblings. */
2698 (*setsizefun) (parent, opht, 0);
2699 }
2700
2701 XSETFASTINT (p->last_modified, 0);
2702 XSETFASTINT (p->last_overlay_modified, 0);
2703 }
2704 #undef MINSIZE
2705 #undef CURBEG
2706 #undef CURSIZE
2707
2708 \f
2709 /* Return number of lines of text (not counting mode line) in W. */
2710
2711 int
2712 window_internal_height (w)
2713 struct window *w;
2714 {
2715 int ht = XFASTINT (w->height);
2716
2717 if (MINI_WINDOW_P (w))
2718 return ht;
2719
2720 if (!NILP (w->parent) || !NILP (w->vchild) || !NILP (w->hchild)
2721 || !NILP (w->next) || !NILP (w->prev)
2722 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w))))
2723 return ht - 1;
2724
2725 return ht;
2726 }
2727
2728
2729 /* Return the number of columns in W.
2730 Don't count columns occupied by scroll bars or the vertical bar
2731 separating W from the sibling to its right. */
2732 int
2733 window_internal_width (w)
2734 struct window *w;
2735 {
2736 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2737 int width = XINT (w->width);
2738
2739 /* Scroll bars occupy a few columns. */
2740 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2741 return width - FRAME_SCROLL_BAR_COLS (f);
2742
2743 /* The column of `|' characters separating side-by-side windows
2744 occupies one column only. */
2745 if (!WINDOW_RIGHTMOST_P (w) && !WINDOW_FULL_WIDTH_P (w))
2746 return width - 1;
2747
2748 return width;
2749 }
2750
2751
2752 /* Scroll contents of window WINDOW up N lines.
2753 If WHOLE is nonzero, it means scroll N screenfuls instead. */
2754
2755 static void
2756 window_scroll (window, n, whole, noerror)
2757 Lisp_Object window;
2758 int n;
2759 int whole;
2760 int noerror;
2761 {
2762 register struct window *w = XWINDOW (window);
2763 register int opoint = PT;
2764 register int pos;
2765 register int ht = window_internal_height (w);
2766 register Lisp_Object tem;
2767 int lose;
2768 Lisp_Object bolp, nmoved;
2769 int startpos;
2770 struct position posit;
2771 int original_vpos;
2772
2773 startpos = marker_position (w->start);
2774
2775 posit = *compute_motion (startpos, 0, 0, 0,
2776 PT, ht, 0,
2777 window_internal_width (w), XINT (w->hscroll),
2778 0, w);
2779 original_vpos = posit.vpos;
2780
2781 XSETFASTINT (tem, PT);
2782 tem = Fpos_visible_in_window_p (tem, window);
2783
2784 if (NILP (tem))
2785 {
2786 Fvertical_motion (make_number (- (ht / 2)), window);
2787 startpos = PT;
2788 }
2789
2790 SET_PT (startpos);
2791 lose = n < 0 && PT == BEGV;
2792 Fvertical_motion (make_number (n), window);
2793 pos = PT;
2794 bolp = Fbolp ();
2795 SET_PT (opoint);
2796
2797 if (lose)
2798 {
2799 if (noerror)
2800 return;
2801 else
2802 Fsignal (Qbeginning_of_buffer, Qnil);
2803 }
2804
2805 if (pos < ZV)
2806 {
2807 int this_scroll_margin = scroll_margin;
2808
2809 /* Don't use a scroll margin that is negative or too large. */
2810 if (this_scroll_margin < 0)
2811 this_scroll_margin = 0;
2812
2813 if (XINT (w->height) < 4 * scroll_margin)
2814 this_scroll_margin = XINT (w->height) / 4;
2815
2816 set_marker_restricted (w->start, make_number (pos), w->buffer);
2817 w->start_at_line_beg = bolp;
2818 w->update_mode_line = Qt;
2819 XSETFASTINT (w->last_modified, 0);
2820 XSETFASTINT (w->last_overlay_modified, 0);
2821 /* Set force_start so that redisplay_window will run
2822 the window-scroll-functions. */
2823 w->force_start = Qt;
2824
2825 if (whole && scroll_preserve_screen_position)
2826 {
2827 SET_PT (pos);
2828 Fvertical_motion (make_number (original_vpos), window);
2829 }
2830 /* If we scrolled forward, put point enough lines down
2831 that it is outside the scroll margin. */
2832 else if (n > 0)
2833 {
2834 int top_margin;
2835
2836 if (this_scroll_margin > 0)
2837 {
2838 SET_PT (pos);
2839 Fvertical_motion (make_number (this_scroll_margin), window);
2840 top_margin = PT;
2841 }
2842 else
2843 top_margin = pos;
2844
2845 if (top_margin <= opoint)
2846 SET_PT (opoint);
2847 else if (scroll_preserve_screen_position)
2848 {
2849 SET_PT (pos);
2850 Fvertical_motion (make_number (original_vpos), window);
2851 }
2852 else
2853 SET_PT (top_margin);
2854 }
2855 else if (n < 0)
2856 {
2857 int bottom_margin;
2858
2859 /* If we scrolled backward, put point near the end of the window
2860 but not within the scroll margin. */
2861 SET_PT (pos);
2862 tem = Fvertical_motion (make_number (ht - this_scroll_margin), window);
2863 if (XFASTINT (tem) == ht - this_scroll_margin)
2864 bottom_margin = PT;
2865 else
2866 bottom_margin = PT + 1;
2867
2868 if (bottom_margin > opoint)
2869 SET_PT (opoint);
2870 else
2871 {
2872 if (scroll_preserve_screen_position)
2873 {
2874 SET_PT (pos);
2875 Fvertical_motion (make_number (original_vpos), window);
2876 }
2877 else
2878 Fvertical_motion (make_number (-1), window);
2879 }
2880 }
2881 }
2882 else
2883 {
2884 if (noerror)
2885 return;
2886 else
2887 Fsignal (Qend_of_buffer, Qnil);
2888 }
2889 }
2890 \f
2891 /* This is the guts of Fscroll_up and Fscroll_down. */
2892
2893 static void
2894 scroll_command (n, direction)
2895 register Lisp_Object n;
2896 int direction;
2897 {
2898 register int defalt;
2899 int count = specpdl_ptr - specpdl;
2900
2901 /* If selected window's buffer isn't current, make it current for the moment.
2902 But don't screw up if window_scroll gets an error. */
2903 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
2904 {
2905 record_unwind_protect (save_excursion_restore, save_excursion_save ());
2906 Fset_buffer (XWINDOW (selected_window)->buffer);
2907 }
2908
2909 defalt = (window_internal_height (XWINDOW (selected_window))
2910 - next_screen_context_lines);
2911 defalt = direction * (defalt < 1 ? 1 : defalt);
2912
2913 if (NILP (n))
2914 window_scroll (selected_window, defalt, 1, 0);
2915 else if (EQ (n, Qminus))
2916 window_scroll (selected_window, - defalt, 1, 0);
2917 else
2918 {
2919 n = Fprefix_numeric_value (n);
2920 window_scroll (selected_window, XINT (n) * direction, 0, 0);
2921 }
2922
2923 unbind_to (count, Qnil);
2924 }
2925
2926 DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P",
2927 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2928 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2929 Negative ARG means scroll downward.\n\
2930 When calling from a program, supply a number as argument or nil.")
2931 (arg)
2932 Lisp_Object arg;
2933 {
2934 scroll_command (arg, 1);
2935 return Qnil;
2936 }
2937
2938 DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P",
2939 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2940 A near full screen is `next-screen-context-lines' less than a full screen.\n\
2941 Negative ARG means scroll upward.\n\
2942 When calling from a program, supply a number as argument or nil.")
2943 (arg)
2944 Lisp_Object arg;
2945 {
2946 scroll_command (arg, -1);
2947 return Qnil;
2948 }
2949 \f
2950 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, Sother_window_for_scrolling, 0, 0, 0,
2951 "Return the other window for \"other window scroll\" commands.\n\
2952 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
2953 specifies the window.\n\
2954 If `other-window-scroll-buffer' is non-nil, a window\n\
2955 showing that buffer is used.")
2956 ()
2957 {
2958 Lisp_Object window;
2959
2960 if (MINI_WINDOW_P (XWINDOW (selected_window))
2961 && !NILP (Vminibuf_scroll_window))
2962 window = Vminibuf_scroll_window;
2963 /* If buffer is specified, scroll that buffer. */
2964 else if (!NILP (Vother_window_scroll_buffer))
2965 {
2966 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
2967 if (NILP (window))
2968 window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt);
2969 }
2970 else
2971 {
2972 /* Nothing specified; look for a neighboring window on the same
2973 frame. */
2974 window = Fnext_window (selected_window, Qnil, Qnil);
2975
2976 if (EQ (window, selected_window))
2977 /* That didn't get us anywhere; look for a window on another
2978 visible frame. */
2979 do
2980 window = Fnext_window (window, Qnil, Qt);
2981 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
2982 && ! EQ (window, selected_window));
2983 }
2984
2985 CHECK_LIVE_WINDOW (window, 0);
2986
2987 if (EQ (window, selected_window))
2988 error ("There is no other window");
2989
2990 return window;
2991 }
2992
2993 DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
2994 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
2995 The next window is the one below the current one; or the one at the top\n\
2996 if the current one is at the bottom. Negative ARG means scroll downward.\n\
2997 When calling from a program, supply a number as argument or nil.\n\
2998 \n\
2999 If in the minibuffer, `minibuffer-scroll-window' if non-nil\n\
3000 specifies the window to scroll.\n\
3001 If `other-window-scroll-buffer' is non-nil, scroll the window\n\
3002 showing that buffer, popping the buffer up if necessary.")
3003 (arg)
3004 register Lisp_Object arg;
3005 {
3006 register Lisp_Object window;
3007 register int defalt;
3008 register struct window *w;
3009 register int count = specpdl_ptr - specpdl;
3010
3011 window = Fother_window_for_scrolling ();
3012
3013 w = XWINDOW (window);
3014 defalt = window_internal_height (w) - next_screen_context_lines;
3015 if (defalt < 1) defalt = 1;
3016
3017 /* Don't screw up if window_scroll gets an error. */
3018 record_unwind_protect (save_excursion_restore, save_excursion_save ());
3019
3020 Fset_buffer (w->buffer);
3021 SET_PT (marker_position (w->pointm));
3022
3023 if (NILP (arg))
3024 window_scroll (window, defalt, 1, 1);
3025 else if (EQ (arg, Qminus))
3026 window_scroll (window, -defalt, 1, 1);
3027 else
3028 {
3029 if (CONSP (arg))
3030 arg = Fcar (arg);
3031 CHECK_NUMBER (arg, 0);
3032 window_scroll (window, XINT (arg), 0, 1);
3033 }
3034
3035 Fset_marker (w->pointm, make_number (PT), Qnil);
3036 unbind_to (count, Qnil);
3037
3038 return Qnil;
3039 }
3040 \f
3041 DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P",
3042 "Scroll selected window display ARG columns left.\n\
3043 Default for ARG is window width minus 2.")
3044 (arg)
3045 register Lisp_Object arg;
3046 {
3047
3048 if (NILP (arg))
3049 XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2);
3050 else
3051 arg = Fprefix_numeric_value (arg);
3052
3053 return
3054 Fset_window_hscroll (selected_window,
3055 make_number (XINT (XWINDOW (selected_window)->hscroll)
3056 + XINT (arg)));
3057 }
3058
3059 DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P",
3060 "Scroll selected window display ARG columns right.\n\
3061 Default for ARG is window width minus 2.")
3062 (arg)
3063 register Lisp_Object arg;
3064 {
3065 if (NILP (arg))
3066 XSETFASTINT (arg, window_internal_width (XWINDOW (selected_window)) - 2);
3067 else
3068 arg = Fprefix_numeric_value (arg);
3069
3070 return
3071 Fset_window_hscroll (selected_window,
3072 make_number (XINT (XWINDOW (selected_window)->hscroll)
3073 - XINT (arg)));
3074 }
3075
3076 DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
3077 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
3078 The desired position of point is always relative to the current window.\n\
3079 Just C-u as prefix means put point in the center of the window.\n\
3080 If ARG is omitted or nil, erases the entire frame and then\n\
3081 redraws with point in the center of the current window.")
3082 (arg)
3083 register Lisp_Object arg;
3084 {
3085 register struct window *w = XWINDOW (selected_window);
3086 register int ht = window_internal_height (w);
3087 struct position pos;
3088
3089 if (NILP (arg))
3090 {
3091 extern int frame_garbaged;
3092
3093 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
3094 XSETFASTINT (arg, ht / 2);
3095 }
3096 else if (CONSP (arg)) /* Just C-u. */
3097 {
3098 XSETFASTINT (arg, ht / 2);
3099 }
3100 else
3101 {
3102 arg = Fprefix_numeric_value (arg);
3103 CHECK_NUMBER (arg, 0);
3104 }
3105
3106 if (XINT (arg) < 0)
3107 XSETINT (arg, XINT (arg) + ht);
3108
3109 pos = *vmotion (PT, - XINT (arg), w);
3110
3111 Fset_marker (w->start, make_number (pos.bufpos), w->buffer);
3112 w->start_at_line_beg = ((pos.bufpos == BEGV
3113 || FETCH_BYTE (pos.bufpos - 1) == '\n')
3114 ? Qt : Qnil);
3115 w->force_start = Qt;
3116
3117 return Qnil;
3118 }
3119 \f
3120 DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
3121 1, 1, "P",
3122 "Position point relative to window.\n\
3123 With no argument, position point at center of window.\n\
3124 An argument specifies frame line; zero means top of window,\n\
3125 negative means relative to bottom of window.")
3126 (arg)
3127 register Lisp_Object arg;
3128 {
3129 register struct window *w = XWINDOW (selected_window);
3130 register int height = window_internal_height (w);
3131 register int start;
3132 Lisp_Object window;
3133
3134 if (NILP (arg))
3135 XSETFASTINT (arg, height / 2);
3136 else
3137 {
3138 arg = Fprefix_numeric_value (arg);
3139 if (XINT (arg) < 0)
3140 XSETINT (arg, XINT (arg) + height);
3141 }
3142
3143 start = marker_position (w->start);
3144 XSETWINDOW (window, w);
3145 if (start < BEGV || start > ZV)
3146 {
3147 Fvertical_motion (make_number (- (height / 2)), window);
3148 Fset_marker (w->start, make_number (PT), w->buffer);
3149 w->start_at_line_beg = Fbolp ();
3150 w->force_start = Qt;
3151 }
3152 else
3153 SET_PT (start);
3154
3155 return Fvertical_motion (arg, window);
3156 }
3157 \f
3158 struct save_window_data
3159 {
3160 EMACS_INT size_from_Lisp_Vector_struct;
3161 struct Lisp_Vector *next_from_Lisp_Vector_struct;
3162 Lisp_Object frame_width, frame_height, frame_menu_bar_lines;
3163 Lisp_Object selected_frame;
3164 Lisp_Object current_window;
3165 Lisp_Object current_buffer;
3166 Lisp_Object minibuf_scroll_window;
3167 Lisp_Object root_window;
3168 Lisp_Object focus_frame;
3169 /* Record the values of window-min-width and window-min-height
3170 so that window sizes remain consistent with them. */
3171 Lisp_Object min_width, min_height;
3172 /* A vector, interpreted as a struct saved_window */
3173 Lisp_Object saved_windows;
3174 };
3175
3176 /* This is saved as a Lisp_Vector */
3177 struct saved_window
3178 {
3179 /* these first two must agree with struct Lisp_Vector in lisp.h */
3180 EMACS_INT size_from_Lisp_Vector_struct;
3181 struct Lisp_Vector *next_from_Lisp_Vector_struct;
3182
3183 Lisp_Object window;
3184 Lisp_Object buffer, start, pointm, mark;
3185 Lisp_Object left, top, width, height, hscroll;
3186 Lisp_Object parent, prev;
3187 Lisp_Object start_at_line_beg;
3188 Lisp_Object display_table;
3189 };
3190 #define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
3191
3192 #define SAVED_WINDOW_N(swv,n) \
3193 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
3194
3195 DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
3196 "T if OBJECT is a window-configuration object.")
3197 (object)
3198 Lisp_Object object;
3199 {
3200 if (WINDOW_CONFIGURATIONP (object))
3201 return Qt;
3202 return Qnil;
3203 }
3204
3205
3206 DEFUN ("set-window-configuration", Fset_window_configuration,
3207 Sset_window_configuration, 1, 1, 0,
3208 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
3209 CONFIGURATION must be a value previously returned\n\
3210 by `current-window-configuration' (which see).")
3211 (configuration)
3212 Lisp_Object configuration;
3213 {
3214 register struct save_window_data *data;
3215 struct Lisp_Vector *saved_windows;
3216 Lisp_Object new_current_buffer;
3217 Lisp_Object frame;
3218 FRAME_PTR f;
3219 int old_point = -1;
3220
3221 while (!WINDOW_CONFIGURATIONP (configuration))
3222 {
3223 configuration = wrong_type_argument (intern ("window-configuration-p"),
3224 configuration);
3225 }
3226
3227 data = (struct save_window_data *) XVECTOR (configuration);
3228 saved_windows = XVECTOR (data->saved_windows);
3229
3230 new_current_buffer = data->current_buffer;
3231 if (NILP (XBUFFER (new_current_buffer)->name))
3232 new_current_buffer = Qnil;
3233 else
3234 {
3235 if (XBUFFER (new_current_buffer) == current_buffer)
3236 old_point = PT;
3237 }
3238
3239 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
3240 f = XFRAME (frame);
3241
3242 /* If f is a dead frame, don't bother rebuilding its window tree.
3243 However, there is other stuff we should still try to do below. */
3244 if (FRAME_LIVE_P (f))
3245 {
3246 register struct window *w;
3247 register struct saved_window *p;
3248 int k;
3249
3250 /* If the frame has been resized since this window configuration was
3251 made, we change the frame to the size specified in the
3252 configuration, restore the configuration, and then resize it
3253 back. We keep track of the prevailing height in these variables. */
3254 int previous_frame_height = FRAME_HEIGHT (f);
3255 int previous_frame_width = FRAME_WIDTH (f);
3256 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
3257
3258 /* The mouse highlighting code could get screwed up
3259 if it runs during this. */
3260 BLOCK_INPUT;
3261
3262 if (XFASTINT (data->frame_height) != previous_frame_height
3263 || XFASTINT (data->frame_width) != previous_frame_width)
3264 change_frame_size (f, data->frame_height, data->frame_width, 0, 0);
3265 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3266 if (XFASTINT (data->frame_menu_bar_lines)
3267 != previous_frame_menu_bar_lines)
3268 x_set_menu_bar_lines (f, data->frame_menu_bar_lines, 0);
3269 #endif
3270
3271 windows_or_buffers_changed++;
3272 FRAME_WINDOW_SIZES_CHANGED (f) = 1;
3273
3274 /* Temporarily avoid any problems with windows that are smaller
3275 than they are supposed to be. */
3276 window_min_height = 1;
3277 window_min_width = 1;
3278
3279 /* Kludge Alert!
3280 Mark all windows now on frame as "deleted".
3281 Restoring the new configuration "undeletes" any that are in it.
3282
3283 Save their current buffers in their height fields, since we may
3284 need it later, if a buffer saved in the configuration is now
3285 dead. */
3286 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f)));
3287
3288 for (k = 0; k < saved_windows->size; k++)
3289 {
3290 p = SAVED_WINDOW_N (saved_windows, k);
3291 w = XWINDOW (p->window);
3292 w->next = Qnil;
3293
3294 if (!NILP (p->parent))
3295 w->parent = SAVED_WINDOW_N (saved_windows,
3296 XFASTINT (p->parent))->window;
3297 else
3298 w->parent = Qnil;
3299
3300 if (!NILP (p->prev))
3301 {
3302 w->prev = SAVED_WINDOW_N (saved_windows,
3303 XFASTINT (p->prev))->window;
3304 XWINDOW (w->prev)->next = p->window;
3305 }
3306 else
3307 {
3308 w->prev = Qnil;
3309 if (!NILP (w->parent))
3310 {
3311 if (EQ (p->width, XWINDOW (w->parent)->width))
3312 {
3313 XWINDOW (w->parent)->vchild = p->window;
3314 XWINDOW (w->parent)->hchild = Qnil;
3315 }
3316 else
3317 {
3318 XWINDOW (w->parent)->hchild = p->window;
3319 XWINDOW (w->parent)->vchild = Qnil;
3320 }
3321 }
3322 }
3323
3324 /* If we squirreled away the buffer in the window's height,
3325 restore it now. */
3326 if (BUFFERP (w->height))
3327 w->buffer = w->height;
3328 w->left = p->left;
3329 w->top = p->top;
3330 w->width = p->width;
3331 w->height = p->height;
3332 w->hscroll = p->hscroll;
3333 w->display_table = p->display_table;
3334 XSETFASTINT (w->last_modified, 0);
3335 XSETFASTINT (w->last_overlay_modified, 0);
3336
3337 /* Reinstall the saved buffer and pointers into it. */
3338 if (NILP (p->buffer))
3339 w->buffer = p->buffer;
3340 else
3341 {
3342 if (!NILP (XBUFFER (p->buffer)->name))
3343 /* If saved buffer is alive, install it. */
3344 {
3345 w->buffer = p->buffer;
3346 w->start_at_line_beg = p->start_at_line_beg;
3347 set_marker_restricted (w->start,
3348 Fmarker_position (p->start),
3349 w->buffer);
3350 set_marker_restricted (w->pointm,
3351 Fmarker_position (p->pointm),
3352 w->buffer);
3353 Fset_marker (XBUFFER (w->buffer)->mark,
3354 Fmarker_position (p->mark), w->buffer);
3355
3356 /* As documented in Fcurrent_window_configuration, don't
3357 save the location of point in the buffer which was current
3358 when the window configuration was recorded. */
3359 if (!EQ (p->buffer, new_current_buffer)
3360 && XBUFFER (p->buffer) == current_buffer)
3361 Fgoto_char (w->pointm);
3362 }
3363 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
3364 /* Else unless window has a live buffer, get one. */
3365 {
3366 w->buffer = Fcdr (Fcar (Vbuffer_alist));
3367 /* This will set the markers to beginning of visible
3368 range. */
3369 set_marker_restricted (w->start, make_number (0), w->buffer);
3370 set_marker_restricted (w->pointm, make_number (0),w->buffer);
3371 w->start_at_line_beg = Qt;
3372 }
3373 else
3374 /* Keeping window's old buffer; make sure the markers
3375 are real. */
3376 {
3377 /* Set window markers at start of visible range. */
3378 if (XMARKER (w->start)->buffer == 0)
3379 set_marker_restricted (w->start, make_number (0),
3380 w->buffer);
3381 if (XMARKER (w->pointm)->buffer == 0)
3382 set_marker_restricted (w->pointm,
3383 (make_number
3384 (BUF_PT (XBUFFER (w->buffer)))),
3385 w->buffer);
3386 w->start_at_line_beg = Qt;
3387 }
3388 }
3389 }
3390
3391 FRAME_ROOT_WINDOW (f) = data->root_window;
3392 Fselect_window (data->current_window);
3393 XBUFFER (XWINDOW (selected_window)->buffer)->last_selected_window
3394 = selected_window;
3395
3396 if (NILP (data->focus_frame)
3397 || (FRAMEP (data->focus_frame)
3398 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
3399 Fredirect_frame_focus (frame, data->focus_frame);
3400
3401 #if 0 /* I don't understand why this is needed, and it causes problems
3402 when the frame's old selected window has been deleted. */
3403 if (f != selected_frame && FRAME_WINDOW_P (f))
3404 do_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)),
3405 Qnil, 0);
3406 #endif
3407
3408 /* Set the screen height to the value it had before this function. */
3409 if (previous_frame_height != FRAME_HEIGHT (f)
3410 || previous_frame_width != FRAME_WIDTH (f))
3411 change_frame_size (f, previous_frame_height, previous_frame_width,
3412 0, 0);
3413 #if defined (HAVE_WINDOW_SYSTEM) || defined (MSDOS)
3414 if (previous_frame_menu_bar_lines != FRAME_MENU_BAR_LINES (f))
3415 x_set_menu_bar_lines (f, previous_frame_menu_bar_lines, 0);
3416 #endif
3417
3418 UNBLOCK_INPUT;
3419 }
3420
3421 /* Restore the minimum heights recorded in the configuration. */
3422 window_min_height = XINT (data->min_height);
3423 window_min_width = XINT (data->min_width);
3424
3425 /* Fselect_window will have made f the selected frame, so we
3426 reselect the proper frame here. Fhandle_switch_frame will change the
3427 selected window too, but that doesn't make the call to
3428 Fselect_window above totally superfluous; it still sets f's
3429 selected window. */
3430 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
3431 do_switch_frame (data->selected_frame, Qnil, 0);
3432
3433 if (!NILP (new_current_buffer))
3434 {
3435 Fset_buffer (new_current_buffer);
3436
3437 /* If the buffer that is current now is the same
3438 that was current before setting the window configuration,
3439 don't alter its PT. */
3440 if (old_point >= 0)
3441 SET_PT (old_point);
3442 }
3443
3444 Vminibuf_scroll_window = data->minibuf_scroll_window;
3445
3446 if (! NILP (Vwindow_configuration_change_hook)
3447 && ! NILP (Vrun_hooks))
3448 call1 (Vrun_hooks, Qwindow_configuration_change_hook);
3449
3450 return (Qnil);
3451 }
3452
3453 /* Mark all windows now on frame as deleted
3454 by setting their buffers to nil. */
3455
3456 void
3457 delete_all_subwindows (w)
3458 register struct window *w;
3459 {
3460 if (!NILP (w->next))
3461 delete_all_subwindows (XWINDOW (w->next));
3462 if (!NILP (w->vchild))
3463 delete_all_subwindows (XWINDOW (w->vchild));
3464 if (!NILP (w->hchild))
3465 delete_all_subwindows (XWINDOW (w->hchild));
3466
3467 w->height = w->buffer; /* See Fset_window_configuration for excuse. */
3468
3469 if (!NILP (w->buffer))
3470 unshow_buffer (w);
3471
3472 /* We set all three of these fields to nil, to make sure that we can
3473 distinguish this dead window from any live window. Live leaf
3474 windows will have buffer set, and combination windows will have
3475 vchild or hchild set. */
3476 w->buffer = Qnil;
3477 w->vchild = Qnil;
3478 w->hchild = Qnil;
3479 }
3480 \f
3481 static int
3482 count_windows (window)
3483 register struct window *window;
3484 {
3485 register int count = 1;
3486 if (!NILP (window->next))
3487 count += count_windows (XWINDOW (window->next));
3488 if (!NILP (window->vchild))
3489 count += count_windows (XWINDOW (window->vchild));
3490 if (!NILP (window->hchild))
3491 count += count_windows (XWINDOW (window->hchild));
3492 return count;
3493 }
3494
3495 static int
3496 save_window_save (window, vector, i)
3497 Lisp_Object window;
3498 struct Lisp_Vector *vector;
3499 int i;
3500 {
3501 register struct saved_window *p;
3502 register struct window *w;
3503 register Lisp_Object tem;
3504
3505 for (;!NILP (window); window = w->next)
3506 {
3507 p = SAVED_WINDOW_N (vector, i);
3508 w = XWINDOW (window);
3509
3510 XSETFASTINT (w->temslot, i++);
3511 p->window = window;
3512 p->buffer = w->buffer;
3513 p->left = w->left;
3514 p->top = w->top;
3515 p->width = w->width;
3516 p->height = w->height;
3517 p->hscroll = w->hscroll;
3518 p->display_table = w->display_table;
3519 if (!NILP (w->buffer))
3520 {
3521 /* Save w's value of point in the window configuration.
3522 If w is the selected window, then get the value of point
3523 from the buffer; pointm is garbage in the selected window. */
3524 if (EQ (window, selected_window))
3525 {
3526 p->pointm = Fmake_marker ();
3527 Fset_marker (p->pointm,
3528 make_number (BUF_PT (XBUFFER (w->buffer))),
3529 w->buffer);
3530 }
3531 else
3532 p->pointm = Fcopy_marker (w->pointm, Qnil);
3533
3534 p->start = Fcopy_marker (w->start, Qnil);
3535 p->start_at_line_beg = w->start_at_line_beg;
3536
3537 tem = XBUFFER (w->buffer)->mark;
3538 p->mark = Fcopy_marker (tem, Qnil);
3539 }
3540 else
3541 {
3542 p->pointm = Qnil;
3543 p->start = Qnil;
3544 p->mark = Qnil;
3545 p->start_at_line_beg = Qnil;
3546 }
3547
3548 if (NILP (w->parent))
3549 p->parent = Qnil;
3550 else
3551 p->parent = XWINDOW (w->parent)->temslot;
3552
3553 if (NILP (w->prev))
3554 p->prev = Qnil;
3555 else
3556 p->prev = XWINDOW (w->prev)->temslot;
3557
3558 if (!NILP (w->vchild))
3559 i = save_window_save (w->vchild, vector, i);
3560 if (!NILP (w->hchild))
3561 i = save_window_save (w->hchild, vector, i);
3562 }
3563
3564 return i;
3565 }
3566
3567 DEFUN ("current-window-configuration", Fcurrent_window_configuration,
3568 Scurrent_window_configuration, 0, 1, 0,
3569 "Return an object representing the current window configuration of FRAME.\n\
3570 If FRAME is nil or omitted, use the selected frame.\n\
3571 This describes the number of windows, their sizes and current buffers,\n\
3572 and for each displayed buffer, where display starts, and the positions of\n\
3573 point and mark. An exception is made for point in the current buffer:\n\
3574 its value is -not- saved.\n\
3575 This also records the currently selected frame, and FRAME's focus\n\
3576 redirection (see `redirect-frame-focus').")
3577 (frame)
3578 Lisp_Object frame;
3579 {
3580 register Lisp_Object tem;
3581 register int n_windows;
3582 register struct save_window_data *data;
3583 register struct Lisp_Vector *vec;
3584 register int i;
3585 FRAME_PTR f;
3586
3587 if (NILP (frame))
3588 f = selected_frame;
3589 else
3590 {
3591 CHECK_LIVE_FRAME (frame, 0);
3592 f = XFRAME (frame);
3593 }
3594
3595 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
3596 vec = allocate_vectorlike (VECSIZE (struct save_window_data));
3597 for (i = 0; i < VECSIZE (struct save_window_data); i++)
3598 vec->contents[i] = Qnil;
3599 vec->size = VECSIZE (struct save_window_data);
3600 data = (struct save_window_data *)vec;
3601
3602 XSETFASTINT (data->frame_width, FRAME_WIDTH (f));
3603 XSETFASTINT (data->frame_height, FRAME_HEIGHT (f));
3604 XSETFASTINT (data->frame_menu_bar_lines, FRAME_MENU_BAR_LINES (f));
3605 XSETFRAME (data->selected_frame, selected_frame);
3606 data->current_window = FRAME_SELECTED_WINDOW (f);
3607 XSETBUFFER (data->current_buffer, current_buffer);
3608 data->minibuf_scroll_window = Vminibuf_scroll_window;
3609 data->root_window = FRAME_ROOT_WINDOW (f);
3610 data->focus_frame = FRAME_FOCUS_FRAME (f);
3611 XSETINT (data->min_height, window_min_height);
3612 XSETINT (data->min_width, window_min_width);
3613 tem = Fmake_vector (make_number (n_windows), Qnil);
3614 data->saved_windows = tem;
3615 for (i = 0; i < n_windows; i++)
3616 XVECTOR (tem)->contents[i]
3617 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);
3618 save_window_save (FRAME_ROOT_WINDOW (f),
3619 XVECTOR (tem), 0);
3620 XSETWINDOW_CONFIGURATION (tem, data);
3621 return (tem);
3622 }
3623
3624 DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
3625 0, UNEVALLED, 0,
3626 "Execute body, preserving window sizes and contents.\n\
3627 Restore which buffer appears in which window, where display starts,\n\
3628 and the value of point and mark for each window.\n\
3629 Also restore which buffer is current.\n\
3630 But do not preserve point in the current buffer.\n\
3631 Does not restore the value of point in current buffer.")
3632 (args)
3633 Lisp_Object args;
3634 {
3635 register Lisp_Object val;
3636 register int count = specpdl_ptr - specpdl;
3637
3638 record_unwind_protect (Fset_window_configuration,
3639 Fcurrent_window_configuration (Qnil));
3640 val = Fprogn (args);
3641 return unbind_to (count, val);
3642 }
3643 \f
3644 init_window_once ()
3645 {
3646 selected_frame = make_terminal_frame ();
3647 XSETFRAME (Vterminal_frame, selected_frame);
3648 minibuf_window = selected_frame->minibuffer_window;
3649 selected_window = selected_frame->selected_window;
3650 last_nonminibuf_frame = selected_frame;
3651
3652 window_initialized = 1;
3653 }
3654
3655 syms_of_window ()
3656 {
3657 staticpro (&Qwindow_configuration_change_hook);
3658 Qwindow_configuration_change_hook
3659 = intern ("window-configuration-change-hook");
3660
3661 Qwindowp = intern ("windowp");
3662 staticpro (&Qwindowp);
3663
3664 Qwindow_live_p = intern ("window-live-p");
3665 staticpro (&Qwindow_live_p);
3666
3667 Qtemp_buffer_show_hook = intern ("temp-buffer-show-hook");
3668 staticpro (&Qtemp_buffer_show_hook);
3669
3670 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
3671 "Non-nil means call as function to display a help buffer.\n\
3672 The function is called with one argument, the buffer to be displayed.\n\
3673 Used by `with-output-to-temp-buffer'.\n\
3674 If this function is used, then it must do the entire job of showing\n\
3675 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.");
3676 Vtemp_buffer_show_function = Qnil;
3677
3678 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function,
3679 "If non-nil, function to call to handle `display-buffer'.\n\
3680 It will receive two args, the buffer and a flag which if non-nil means\n\
3681 that the currently selected window is not acceptable.\n\
3682 Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
3683 work using this function.");
3684 Vdisplay_buffer_function = Qnil;
3685
3686 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
3687 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
3688 Vminibuf_scroll_window = Qnil;
3689
3690 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
3691 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
3692 Vother_window_scroll_buffer = Qnil;
3693
3694 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
3695 "*Non-nil means `display-buffer' should make a separate frame.");
3696 pop_up_frames = 0;
3697
3698 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function,
3699 "Function to call to handle automatic new frame creation.\n\
3700 It is called with no arguments and should return a newly created frame.\n\
3701 \n\
3702 A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
3703 where `pop-up-frame-alist' would hold the default frame parameters.");
3704 Vpop_up_frame_function = Qnil;
3705
3706 DEFVAR_LISP ("special-display-buffer-names", &Vspecial_display_buffer_names,
3707 "*List of buffer names that should have their own special frames.\n\
3708 Displaying a buffer whose name is in this list makes a special frame for it\n\
3709 using `special-display-function'. See also `special-display-regexps'.\n\
3710 \n\
3711 An element of the list can be a list instead of just a string.\n\
3712 There are two ways to use a list as an element:\n\
3713 (BUFFER FRAME-PARAMETERS...) (BUFFER FUNCTION OTHER-ARGS...)\n\
3714 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3715 In the latter case, FUNCTION is called with BUFFER as the first argument,\n\
3716 followed by OTHER-ARGS--it can display BUFFER in any way it likes.\n\
3717 All this is done by the function found in `special-display-function'.\n\
3718 \n\
3719 If this variable appears \"not to work\", because you add a name to it\n\
3720 but that buffer still appears in the selected window, look at the\n\
3721 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3722 Those variables take precedence over this one.");
3723 Vspecial_display_buffer_names = Qnil;
3724
3725 DEFVAR_LISP ("special-display-regexps", &Vspecial_display_regexps,
3726 "*List of regexps saying which buffers should have their own special frames.\n\
3727 If a buffer name matches one of these regexps, it gets its own frame.\n\
3728 Displaying a buffer whose name is in this list makes a special frame for it\n\
3729 using `special-display-function'.\n\
3730 \n\
3731 An element of the list can be a list instead of just a string.\n\
3732 There are two ways to use a list as an element:\n\
3733 (REGEXP FRAME-PARAMETERS...) (REGEXP FUNCTION OTHER-ARGS...)\n\
3734 In the first case, FRAME-PARAMETERS are used to create the frame.\n\
3735 In the latter case, FUNCTION is called with the buffer as first argument,\n\
3736 followed by OTHER-ARGS--it can display the buffer in any way it likes.\n\
3737 All this is done by the function found in `special-display-function'.\n\
3738 \n\
3739 If this variable appears \"not to work\", because you add a regexp to it\n\
3740 but the matching buffers still appear in the selected window, look at the\n\
3741 values of `same-window-buffer-names' and `same-window-regexps'.\n\
3742 Those variables take precedence over this one.");
3743 Vspecial_display_regexps = Qnil;
3744
3745 DEFVAR_LISP ("special-display-function", &Vspecial_display_function,
3746 "Function to call to make a new frame for a special buffer.\n\
3747 It is called with two arguments, the buffer and optional buffer specific\n\
3748 data, and should return a window displaying that buffer.\n\
3749 The default value makes a separate frame for the buffer,\n\
3750 using `special-display-frame-alist' to specify the frame parameters.\n\
3751 \n\
3752 A buffer is special if its is listed in `special-display-buffer-names'\n\
3753 or matches a regexp in `special-display-regexps'.");
3754 Vspecial_display_function = Qnil;
3755
3756 DEFVAR_LISP ("same-window-buffer-names", &Vsame_window_buffer_names,
3757 "*List of buffer names that should appear in the selected window.\n\
3758 Displaying one of these buffers using `display-buffer' or `pop-to-buffer'\n\
3759 switches to it in the selected window, rather than making it appear\n\
3760 in some other window.\n\
3761 \n\
3762 An element of the list can be a cons cell instead of just a string.\n\
3763 Then the car must be a string, which specifies the buffer name.\n\
3764 This is for compatibility with `special-display-buffer-names';\n\
3765 the cdr of the cons cell is ignored.\n\
3766 \n\
3767 See also `same-window-regexps'.");
3768 Vsame_window_buffer_names = Qnil;
3769
3770 DEFVAR_LISP ("same-window-regexps", &Vsame_window_regexps,
3771 "*List of regexps saying which buffers should appear in the selected window.\n\
3772 If a buffer name matches one of these regexps, then displaying it\n\
3773 using `display-buffer' or `pop-to-buffer' switches to it\n\
3774 in the selected window, rather than making it appear in some other window.\n\
3775 \n\
3776 An element of the list can be a cons cell instead of just a string.\n\
3777 Then the car must be a string, which specifies the buffer name.\n\
3778 This is for compatibility with `special-display-buffer-names';\n\
3779 the cdr of the cons cell is ignored.\n\
3780 \n\
3781 See also `same-window-buffer-names'.");
3782 Vsame_window_regexps = Qnil;
3783
3784 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
3785 "*Non-nil means display-buffer should make new windows.");
3786 pop_up_windows = 1;
3787
3788 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
3789 "*Number of lines of continuity when scrolling by screenfuls.");
3790 next_screen_context_lines = 2;
3791
3792 DEFVAR_INT ("split-height-threshold", &split_height_threshold,
3793 "*display-buffer would prefer to split the largest window if this large.\n\
3794 If there is only one window, it is split regardless of this value.");
3795 split_height_threshold = 500;
3796
3797 DEFVAR_INT ("window-min-height", &window_min_height,
3798 "*Delete any window less than this tall (including its mode line).");
3799 window_min_height = 4;
3800
3801 DEFVAR_INT ("window-min-width", &window_min_width,
3802 "*Delete any window less than this wide.");
3803 window_min_width = 10;
3804
3805 DEFVAR_BOOL ("scroll-preserve-screen-position",
3806 &scroll_preserve_screen_position,
3807 "*Nonzero means scroll commands move point to keep its screen line unchanged.");
3808 scroll_preserve_screen_position = 0;
3809
3810 DEFVAR_LISP ("window-configuration-change-hook",
3811 &Vwindow_configuration_change_hook,
3812 "Functions to call when window configuration changes.\n\
3813 The selected frame is the one whose configuration has changed.");
3814 Vwindow_configuration_change_hook = Qnil;
3815
3816 defsubr (&Sselected_window);
3817 defsubr (&Sminibuffer_window);
3818 defsubr (&Swindow_minibuffer_p);
3819 defsubr (&Swindowp);
3820 defsubr (&Swindow_live_p);
3821 defsubr (&Spos_visible_in_window_p);
3822 defsubr (&Swindow_buffer);
3823 defsubr (&Swindow_height);
3824 defsubr (&Swindow_width);
3825 defsubr (&Swindow_hscroll);
3826 defsubr (&Sset_window_hscroll);
3827 defsubr (&Swindow_redisplay_end_trigger);
3828 defsubr (&Sset_window_redisplay_end_trigger);
3829 defsubr (&Swindow_edges);
3830 defsubr (&Scoordinates_in_window_p);
3831 defsubr (&Swindow_at);
3832 defsubr (&Swindow_point);
3833 defsubr (&Swindow_start);
3834 defsubr (&Swindow_end);
3835 defsubr (&Sset_window_point);
3836 defsubr (&Sset_window_start);
3837 defsubr (&Swindow_dedicated_p);
3838 defsubr (&Sset_window_dedicated_p);
3839 defsubr (&Swindow_display_table);
3840 defsubr (&Sset_window_display_table);
3841 defsubr (&Snext_window);
3842 defsubr (&Sprevious_window);
3843 defsubr (&Sother_window);
3844 defsubr (&Sget_lru_window);
3845 defsubr (&Sget_largest_window);
3846 defsubr (&Sget_buffer_window);
3847 defsubr (&Sdelete_other_windows);
3848 defsubr (&Sdelete_windows_on);
3849 defsubr (&Sreplace_buffer_in_windows);
3850 defsubr (&Sdelete_window);
3851 defsubr (&Sset_window_buffer);
3852 defsubr (&Sselect_window);
3853 defsubr (&Sspecial_display_p);
3854 defsubr (&Ssame_window_p);
3855 defsubr (&Sdisplay_buffer);
3856 defsubr (&Ssplit_window);
3857 defsubr (&Senlarge_window);
3858 defsubr (&Sshrink_window);
3859 defsubr (&Sscroll_up);
3860 defsubr (&Sscroll_down);
3861 defsubr (&Sscroll_left);
3862 defsubr (&Sscroll_right);
3863 defsubr (&Sother_window_for_scrolling);
3864 defsubr (&Sscroll_other_window);
3865 defsubr (&Srecenter);
3866 defsubr (&Smove_to_window_line);
3867 defsubr (&Swindow_configuration_p);
3868 defsubr (&Sset_window_configuration);
3869 defsubr (&Scurrent_window_configuration);
3870 defsubr (&Ssave_window_excursion);
3871 }
3872
3873 keys_of_window ()
3874 {
3875 initial_define_key (control_x_map, '1', "delete-other-windows");
3876 initial_define_key (control_x_map, '2', "split-window");
3877 initial_define_key (control_x_map, '0', "delete-window");
3878 initial_define_key (control_x_map, 'o', "other-window");
3879 initial_define_key (control_x_map, '^', "enlarge-window");
3880 initial_define_key (control_x_map, '<', "scroll-left");
3881 initial_define_key (control_x_map, '>', "scroll-right");
3882
3883 initial_define_key (global_map, Ctl ('V'), "scroll-up");
3884 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
3885 initial_define_key (meta_map, 'v', "scroll-down");
3886
3887 initial_define_key (global_map, Ctl('L'), "recenter");
3888 initial_define_key (meta_map, 'r', "move-to-window-line");
3889 }