Comment change.
[bpt/emacs.git] / src / window.c
CommitLineData
7ab12479
JB
1/* Window creation, deletion and examination for GNU Emacs.
2 Does not include redisplay.
c6c5df7f 3 Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc.
7ab12479
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
1113d9db 9the Free Software Foundation; either version 2, or (at your option)
7ab12479
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
19the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20
7ab12479
JB
21#include "config.h"
22#include "lisp.h"
23#include "buffer.h"
44fa5b1e 24#include "frame.h"
7ab12479
JB
25#include "window.h"
26#include "commands.h"
27#include "indent.h"
28#include "termchar.h"
29#include "disptab.h"
f8026fd8 30#include "keyboard.h"
7ab12479 31
806b4d9b 32Lisp_Object Qwindowp, Qwindow_live_p;
7ab12479
JB
33
34Lisp_Object Fnext_window (), Fdelete_window (), Fselect_window ();
35Lisp_Object Fset_window_buffer (), Fsplit_window (), Frecenter ();
36
fd482be5 37void delete_all_subwindows ();
7ab12479
JB
38static struct window *decode_window();
39
40/* This is the window in which the terminal's cursor should
41 be left when nothing is being done with it. This must
42 always be a leaf window, and its buffer is selected by
43 the top level editing loop at the end of each command.
44
45 This value is always the same as
44fa5b1e 46 FRAME_SELECTED_WINDOW (selected_frame). */
7ab12479
JB
47
48Lisp_Object selected_window;
49
44fa5b1e 50/* The minibuffer window of the selected frame.
7ab12479
JB
51 Note that you cannot test for minibufferness of an arbitrary window
52 by comparing against this; but you can test for minibufferness of
53 the selected window. */
54Lisp_Object minibuf_window;
55
56/* Non-nil means it is the window for C-M-v to scroll
57 when the minibuffer is selected. */
58Lisp_Object Vminibuf_scroll_window;
59
60/* Non-nil means this is the buffer whose window C-M-v should scroll. */
61Lisp_Object Vother_window_scroll_buffer;
62
7ab12479
JB
63/* Non-nil means it's function to call to display temp buffers. */
64Lisp_Object Vtemp_buffer_show_function;
65
66/* If a window gets smaller than either of these, it is removed. */
67int window_min_height;
68int window_min_width;
69
70/* Nonzero implies Fdisplay_buffer should create windows. */
71int pop_up_windows;
72
44fa5b1e
JB
73/* Nonzero implies make new frames for Fdisplay_buffer. */
74int pop_up_frames;
7ab12479
JB
75
76/* Non-nil means use this function instead of default */
44fa5b1e 77Lisp_Object Vpop_up_frame_function;
7ab12479
JB
78
79/* Function to call to handle Fdisplay_buffer. */
80Lisp_Object Vdisplay_buffer_function;
81
82/* Fdisplay_buffer always splits the largest window
83 if that window is more than this high. */
84int split_height_threshold;
85
86/* Number of lines of continuity in scrolling by screenfuls. */
87int next_screen_context_lines;
88
89/* Incremented for each window created. */
90static int sequence_number;
91
92#define min(a, b) ((a) < (b) ? (a) : (b))
93\f
94DEFUN ("windowp", Fwindowp, Swindowp, 1, 1, 0,
95 "Returns t if OBJ is a window.")
96 (obj)
97 Lisp_Object obj;
98{
99 return XTYPE (obj) == Lisp_Window ? Qt : Qnil;
100}
101
806b4d9b 102DEFUN ("window-live-p", Fwindow_live_p, Swindow_live_p, 1, 1, 0,
605be8af
JB
103 "Returns t if OBJ is a window which is currently visible.")
104 (obj)
105 Lisp_Object obj;
106{
107 return ((XTYPE (obj) == Lisp_Window
108 && ! NILP (XWINDOW (obj)->buffer))
109 ? Qt : Qnil);
110}
111
7ab12479
JB
112Lisp_Object
113make_window ()
114{
115 register Lisp_Object val;
116 register struct window *p;
117
118 /* Add sizeof (Lisp_Object) here because sizeof (struct Lisp_Vector)
119 includes the first element. */
120 val = Fmake_vector (
121 make_number ((sizeof (struct window) - sizeof (struct Lisp_Vector)
122 + sizeof (Lisp_Object))
123 / sizeof (Lisp_Object)),
124 Qnil);
125 XSETTYPE (val, Lisp_Window);
126 p = XWINDOW (val);
127 XFASTINT (p->sequence_number) = ++sequence_number;
128 XFASTINT (p->left) = XFASTINT (p->top)
129 = XFASTINT (p->height) = XFASTINT (p->width)
130 = XFASTINT (p->hscroll) = 0;
131 XFASTINT (p->last_point_x) = XFASTINT (p->last_point_y) = 0;
132 p->start = Fmake_marker ();
133 p->pointm = Fmake_marker ();
134 XFASTINT (p->use_time) = 0;
44fa5b1e 135 p->frame = Qnil;
7ab12479
JB
136 p->display_table = Qnil;
137 p->dedicated = Qnil;
138 return val;
139}
140
141DEFUN ("selected-window", Fselected_window, Sselected_window, 0, 0, 0,
142 "Return the window that the cursor now appears in and commands apply to.")
143 ()
144{
145 return selected_window;
146}
147
83762ba4
JB
148DEFUN ("minibuffer-window", Fminibuffer_window, Sminibuffer_window, 0, 1, 0,
149 "Return the window used now for minibuffers.\n\
150If the optional argument FRAME is specified, return the minibuffer window\n\
151used by that frame.")
152 (frame)
153 Lisp_Object frame;
7ab12479 154{
44fa5b1e 155#ifdef MULTI_FRAME
83762ba4
JB
156 if (NILP (frame))
157 XSET (frame, Lisp_Frame, selected_frame);
158 else
159 CHECK_LIVE_FRAME (frame, 0);
160#endif
161
162 return FRAME_MINIBUF_WINDOW (XFRAME (frame));
7ab12479
JB
163}
164
605be8af 165DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, Swindow_minibuffer_p, 0, 1, 0,
7ab12479
JB
166 "Returns non-nil if WINDOW is a minibuffer window.")
167 (window)
168 Lisp_Object window;
169{
170 struct window *w = decode_window (window);
171 return (MINI_WINDOW_P (w) ? Qt : Qnil);
172}
173
174DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p,
175 Spos_visible_in_window_p, 0, 2, 0,
44fa5b1e 176 "Return t if position POS is currently on the frame in WINDOW.\n\
7ab12479
JB
177Returns nil if that position is scrolled vertically out of view.\n\
178POS defaults to point; WINDOW, to the selected window.")
179 (pos, window)
180 Lisp_Object pos, window;
181{
182 register struct window *w;
183 register int top;
184 register int height;
185 register int posint;
186 register struct buffer *buf;
187 struct position posval;
188
265a9e55 189 if (NILP (pos))
7ab12479
JB
190 posint = point;
191 else
192 {
193 CHECK_NUMBER_COERCE_MARKER (pos, 0);
194 posint = XINT (pos);
195 }
196
605be8af 197 w = decode_window (window);
7ab12479
JB
198 top = marker_position (w->start);
199
200 if (posint < top)
201 return Qnil;
202
203 height = XFASTINT (w->height) - ! MINI_WINDOW_P (w);
204
205 buf = XBUFFER (w->buffer);
206 if (XFASTINT (w->last_modified) >= BUF_MODIFF (buf))
207 {
44fa5b1e 208 /* If frame is up to date,
7ab12479
JB
209 use the info recorded about how much text fit on it. */
210 if (posint < BUF_Z (buf) - XFASTINT (w->window_end_pos)
211 || (XFASTINT (w->window_end_vpos) < height))
212 return Qt;
213 return Qnil;
214 }
215 else
216 {
217 if (posint > BUF_Z (buf))
218 return Qnil;
219
220 /* If that info is not correct, calculate afresh */
221 posval = *compute_motion (top, 0, 0, posint, height, 0,
535e0b8e 222 window_internal_width (w) - 1,
7ab12479
JB
223 XINT (w->hscroll), 0);
224
225 return posval.vpos < height ? Qt : Qnil;
226 }
227}
228\f
229static struct window *
230decode_window (window)
231 register Lisp_Object window;
232{
265a9e55 233 if (NILP (window))
7ab12479
JB
234 return XWINDOW (selected_window);
235
605be8af 236 CHECK_LIVE_WINDOW (window, 0);
7ab12479
JB
237 return XWINDOW (window);
238}
239
240DEFUN ("window-buffer", Fwindow_buffer, Swindow_buffer, 0, 1, 0,
241 "Return the buffer that WINDOW is displaying.")
242 (window)
243 Lisp_Object window;
244{
245 return decode_window (window)->buffer;
246}
247
248DEFUN ("window-height", Fwindow_height, Swindow_height, 0, 1, 0,
249 "Return the number of lines in WINDOW (including its mode line).")
250 (window)
251 Lisp_Object window;
252{
253 return decode_window (window)->height;
254}
255
256DEFUN ("window-width", Fwindow_width, Swindow_width, 0, 1, 0,
257 "Return the number of columns in WINDOW.")
258 (window)
259 Lisp_Object window;
260{
261 register struct window *w = decode_window (window);
7f4161e0 262 register int width = XFASTINT (w->width);
7ab12479 263
535e0b8e 264 return make_number (window_internal_width (w));
7ab12479
JB
265}
266
267DEFUN ("window-hscroll", Fwindow_hscroll, Swindow_hscroll, 0, 1, 0,
268 "Return the number of columns by which WINDOW is scrolled from left margin.")
269 (window)
270 Lisp_Object window;
271{
272 return decode_window (window)->hscroll;
273}
274
275DEFUN ("set-window-hscroll", Fset_window_hscroll, Sset_window_hscroll, 2, 2, 0,
276 "Set number of columns WINDOW is scrolled from left margin to NCOL.\n\
277NCOL should be zero or positive.")
278 (window, ncol)
279 register Lisp_Object window, ncol;
280{
281 register struct window *w;
282
283 CHECK_NUMBER (ncol, 1);
284 if (XINT (ncol) < 0) XFASTINT (ncol) = 0;
285 if (XFASTINT (ncol) >= (1 << (SHORTBITS - 1)))
286 args_out_of_range (ncol, Qnil);
287 w = decode_window (window);
7f4161e0 288 if (XINT (w->hscroll) != XINT (ncol))
7ab12479
JB
289 clip_changed = 1; /* Prevent redisplay shortcuts */
290 w->hscroll = ncol;
291 return ncol;
292}
293
294DEFUN ("window-edges", Fwindow_edges, Swindow_edges, 0, 1, 0,
295 "Return a list of the edge coordinates of WINDOW.\n\
44fa5b1e 296\(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.\n\
7ab12479
JB
297RIGHT is one more than the rightmost column used by WINDOW,\n\
298and BOTTOM is one more than the bottommost row used by WINDOW\n\
299 and its mode-line.")
300 (window)
301 Lisp_Object window;
302{
303 register struct window *w = decode_window (window);
304
305 return Fcons (w->left, Fcons (w->top,
306 Fcons (make_number (XFASTINT (w->left) + XFASTINT (w->width)),
307 Fcons (make_number (XFASTINT (w->top)
308 + XFASTINT (w->height)),
309 Qnil))));
310}
311
d5783c40
JB
312/* Test if the character at column *x, row *y is within window *w.
313 If it is not, return 0;
314 if it is in the window's text area,
315 set *x and *y to its location relative to the upper left corner
316 of the window, and
317 return 1;
318 if it is on the window's modeline, return 2;
319 if it is on the border between the window and its right sibling,
320 return 3. */
321static int
322coordinates_in_window (w, x, y)
323 register struct window *w;
324 register int *x, *y;
325{
326 register int left = XINT (w->left);
327 register int width = XINT (w->width);
328 register int window_height = XINT (w->height);
329 register int top = XFASTINT (w->top);
330
331 if ( *x < left || *x >= left + width
332 || *y < top || *y >= top + window_height)
333 return 0;
334
335 /* Is the character is the mode line? */
336 if (*y == top + window_height - 1
05c2896a 337 && ! MINI_WINDOW_P (w))
d5783c40
JB
338 return 2;
339
340 /* Is the character in the right border? */
341 if (*x == left + width - 1
44fa5b1e 342 && left + width != FRAME_WIDTH (XFRAME (w->frame)))
d5783c40
JB
343 return 3;
344
345 *x -= left;
346 *y -= top;
347 return 1;
348}
349
350DEFUN ("coordinates-in-window-p", Fcoordinates_in_window_p,
351 Scoordinates_in_window_p, 2, 2, 0,
352 "Return non-nil if COORDINATES are in WINDOW.\n\
1113d9db 353COORDINATES is a cons of the form (X . Y), X and Y being distances\n\
44fa5b1e 354measured in characters from the upper-left corner of the frame.\n\
1113d9db 355(0 . 0) denotes the character in the upper left corner of the\n\
44fa5b1e 356frame.\n\
d5783c40
JB
357If COORDINATES are in the text portion of WINDOW,\n\
358 the coordinates relative to the window are returned.\n\
e5d77022 359If they are in the mode line of WINDOW, `mode-line' is returned.\n\
d5783c40 360If they are on the border between WINDOW and its right sibling,\n\
e5d77022 361 `vertical-line' is returned.")
d5783c40
JB
362 (coordinates, window)
363 register Lisp_Object coordinates, window;
364{
365 int x, y;
366
605be8af 367 CHECK_LIVE_WINDOW (window, 0);
d5783c40
JB
368 CHECK_CONS (coordinates, 1);
369 x = XINT (Fcar (coordinates));
370 y = XINT (Fcdr (coordinates));
371
372 switch (coordinates_in_window (XWINDOW (window), &x, &y))
373 {
374 case 0: /* NOT in window at all. */
375 return Qnil;
376
377 case 1: /* In text part of window. */
378 return Fcons (x, y);
379
380 case 2: /* In mode line of window. */
381 return Qmode_line;
382
383 case 3: /* On right border of window. */
e5d77022 384 return Qvertical_line;
d5783c40
JB
385
386 default:
387 abort ();
388 }
389}
390
7ab12479 391/* Find the window containing column x, row y, and return it as a
d5783c40
JB
392 Lisp_Object. If x, y is on the window's modeline, set *part
393 to 1; if it is on the separating line between the window and its
394 right sibling, set it to 2; otherwise set it to 0. If there is no
395 window under x, y return nil and leave *part unmodified. */
7ab12479 396Lisp_Object
44fa5b1e
JB
397window_from_coordinates (frame, x, y, part)
398 FRAME_PTR frame;
7ab12479 399 int x, y;
d5783c40 400 int *part;
7ab12479
JB
401{
402 register Lisp_Object tem, first;
403
44fa5b1e 404 tem = first = FRAME_SELECTED_WINDOW (frame);
7ab12479 405
d5783c40 406 do
7ab12479
JB
407 {
408 int found = coordinates_in_window (XWINDOW (tem), &x, &y);
409
410 if (found)
411 {
d5783c40 412 *part = found - 1;
7ab12479
JB
413 return tem;
414 }
415
d5783c40 416 tem = Fnext_window (tem, Qt, Qlambda);
7ab12479 417 }
d5783c40
JB
418 while (! EQ (tem, first));
419
420 return Qnil;
7ab12479
JB
421}
422
ab17c3f2 423DEFUN ("window-at", Fwindow_at, Swindow_at, 2, 3, 0,
b0c33a94 424 "Return window containing coordinates X and Y on FRAME.\n\
44fa5b1e
JB
425If omitted, FRAME defaults to the currently selected frame.\n\
426The top left corner of the frame is considered to be row 0,\n\
95605e15 427column 0.")
b0c33a94
RS
428 (x, y, frame)
429 Lisp_Object x, y, frame;
7ab12479
JB
430{
431 int part;
432
4b206065 433#ifdef MULTI_FRAME
44fa5b1e
JB
434 if (NILP (frame))
435 XSET (frame, Lisp_Frame, selected_frame);
d5783c40 436 else
44fa5b1e 437 CHECK_LIVE_FRAME (frame, 2);
4b206065 438#endif
b0c33a94
RS
439 CHECK_NUMBER (x, 0);
440 CHECK_NUMBER (y, 1);
7ab12479 441
44fa5b1e 442 return window_from_coordinates (XFRAME (frame),
b0c33a94 443 XINT (x), XINT (y),
7ab12479
JB
444 &part);
445}
446
447DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
448 "Return current value of point in WINDOW.\n\
449For a nonselected window, this is the value point would have\n\
450if that window were selected.\n\
451\n\
452Note that, when WINDOW is the selected window and its buffer\n\
453is also currently selected, the value returned is the same as (point).\n\
454It would be more strictly correct to return the `top-level' value\n\
455of point, outside of any save-excursion forms.\n\
456But that is hard to define.")
457 (window)
458 Lisp_Object window;
459{
460 register struct window *w = decode_window (window);
461
462 if (w == XWINDOW (selected_window)
463 && current_buffer == XBUFFER (w->buffer))
464 return Fpoint ();
465 return Fmarker_position (w->pointm);
466}
467
468DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
469 "Return position at which display currently starts in WINDOW.")
470 (window)
471 Lisp_Object window;
472{
473 return Fmarker_position (decode_window (window)->start);
474}
475
476DEFUN ("window-end", Fwindow_end, Swindow_end, 0, 1, 0,
477 "Return position at which display currently ends in WINDOW.")
478 (window)
479 Lisp_Object window;
480{
481 Lisp_Object value;
482 struct window *w = decode_window (window);
483
484 XSET (value, Lisp_Int,
485 BUF_Z (current_buffer) - XFASTINT (w->window_end_pos));
486
487 return value;
488}
489
490DEFUN ("set-window-point", Fset_window_point, Sset_window_point, 2, 2, 0,
491 "Make point value in WINDOW be at position POS in WINDOW's buffer.")
492 (window, pos)
493 Lisp_Object window, pos;
494{
495 register struct window *w = decode_window (window);
496
497 CHECK_NUMBER_COERCE_MARKER (pos, 1);
498 if (w == XWINDOW (selected_window))
499 Fgoto_char (pos);
500 else
501 set_marker_restricted (w->pointm, pos, w->buffer);
502
503 return pos;
504}
505
506DEFUN ("set-window-start", Fset_window_start, Sset_window_start, 2, 3, 0,
507 "Make display in WINDOW start at position POS in WINDOW's buffer.\n\
508Optional third arg NOFORCE non-nil inhibits next redisplay\n\
509from overriding motion of point in order to display at this exact start.")
510 (window, pos, noforce)
511 Lisp_Object window, pos, noforce;
512{
513 register struct window *w = decode_window (window);
514
515 CHECK_NUMBER_COERCE_MARKER (pos, 1);
516 set_marker_restricted (w->start, pos, w->buffer);
517 /* this is not right, but much easier than doing what is right. */
518 w->start_at_line_beg = Qnil;
265a9e55 519 if (NILP (noforce))
7ab12479
JB
520 w->force_start = Qt;
521 w->update_mode_line = Qt;
522 XFASTINT (w->last_modified) = 0;
62c07cc7
JB
523 if (!EQ (window, selected_window))
524 windows_or_buffers_changed++;
7ab12479
JB
525 return pos;
526}
527
528DEFUN ("window-dedicated-p", Fwindow_dedicated_p, Swindow_dedicated_p,
529 1, 1, 0,
530 "Return WINDOW's dedicated object, usually t or nil.\n\
1f18c48f 531See also `set-window-dedicated-p'.")
7ab12479
JB
532 (window)
533 Lisp_Object window;
534{
535 return decode_window (window)->dedicated;
536}
537
d207b766
RS
538DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p,
539 Sset_window_dedicated_p, 2, 2, 0,
540 "Control whether WINDOW is dedicated to the buffer it displays.\n\
541If it is dedicated, Emacs will not automatically change\n\
542which buffer appears in it.\n\
543The second argument is the new value for the dedication flag;\n\
544non-nil means yes.")
7ab12479
JB
545 (window, arg)
546 Lisp_Object window, arg;
547{
548 register struct window *w = decode_window (window);
549
265a9e55 550 if (NILP (arg))
7ab12479
JB
551 w->dedicated = Qnil;
552 else
d207b766 553 w->dedicated = Qt;
7ab12479
JB
554
555 return w->dedicated;
556}
557
558DEFUN ("window-display-table", Fwindow_display_table, Swindow_display_table,
559 0, 1, 0,
560 "Return the display-table that WINDOW is using.")
561 (window)
562 Lisp_Object window;
563{
564 return decode_window (window)->display_table;
565}
566
567/* Get the display table for use currently on window W.
568 This is either W's display table or W's buffer's display table.
569 Ignore the specified tables if they are not valid;
570 if no valid table is specified, return 0. */
571
572struct Lisp_Vector *
573window_display_table (w)
574 struct window *w;
575{
576 Lisp_Object tem;
577 tem = w->display_table;
578 if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE)
579 return XVECTOR (tem);
580 tem = XBUFFER (w->buffer)->display_table;
581 if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE)
582 return XVECTOR (tem);
583 tem = Vstandard_display_table;
584 if (XTYPE (tem) == Lisp_Vector && XVECTOR (tem)->size == DISP_TABLE_SIZE)
585 return XVECTOR (tem);
586 return 0;
587}
588
3a2712f9 589DEFUN ("set-window-display-table", Fset_window_display_table, Sset_window_display_table, 2, 2, 0,
7ab12479
JB
590 "Set WINDOW's display-table to TABLE.")
591 (window, table)
592 register Lisp_Object window, table;
593{
594 register struct window *w;
595 register Lisp_Object z; /* Return value. */
596
597 w = decode_window (window);
598 w->display_table = table;
599 return table;
600}
601\f
602/* Record info on buffer window w is displaying
603 when it is about to cease to display that buffer. */
604static
605unshow_buffer (w)
606 register struct window *w;
607{
608 Lisp_Object buf = w->buffer;
609
610 if (XBUFFER (buf) != XMARKER (w->pointm)->buffer)
611 abort ();
612
613 if (w == XWINDOW (selected_window)
614 || ! EQ (buf, XWINDOW (selected_window)->buffer))
615 /* Do this except when the selected window's buffer
616 is being removed from some other window. */
617 XBUFFER (buf)->last_window_start = marker_position (w->start);
618
619 /* Point in the selected window's buffer
620 is actually stored in that buffer, and the window's pointm isn't used.
621 So don't clobber point in that buffer. */
622 if (! EQ (buf, XWINDOW (selected_window)->buffer))
623 BUF_PT (XBUFFER (buf))
624 = clip_to_bounds (BUF_BEGV (XBUFFER (buf)),
625 marker_position (w->pointm),
626 BUF_ZV (XBUFFER (buf)));
627}
628
629/* Put replacement into the window structure in place of old. */
630static
631replace_window (old, replacement)
632 Lisp_Object old, replacement;
633{
634 register Lisp_Object tem;
635 register struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
636
44fa5b1e
JB
637 /* If OLD is its frame's root_window, then replacement is the new
638 root_window for that frame. */
7ab12479 639
7f4161e0 640 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
44fa5b1e 641 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
7ab12479
JB
642
643 p->left = o->left;
644 p->top = o->top;
645 p->width = o->width;
646 p->height = o->height;
647
648 p->next = tem = o->next;
265a9e55 649 if (!NILP (tem))
7ab12479
JB
650 XWINDOW (tem)->prev = replacement;
651
652 p->prev = tem = o->prev;
265a9e55 653 if (!NILP (tem))
7ab12479
JB
654 XWINDOW (tem)->next = replacement;
655
656 p->parent = tem = o->parent;
265a9e55 657 if (!NILP (tem))
7ab12479
JB
658 {
659 if (EQ (XWINDOW (tem)->vchild, old))
660 XWINDOW (tem)->vchild = replacement;
661 if (EQ (XWINDOW (tem)->hchild, old))
662 XWINDOW (tem)->hchild = replacement;
663 }
664
665/*** Here, if replacement is a vertical combination
666and so is its new parent, we should make replacement's
667children be children of that parent instead. ***/
668}
669
670DEFUN ("delete-window", Fdelete_window, Sdelete_window, 0, 1, "",
671 "Remove WINDOW from the display. Default is selected window.")
672 (window)
673 register Lisp_Object window;
674{
675 register Lisp_Object tem, parent, sib;
676 register struct window *p;
677 register struct window *par;
678
605be8af
JB
679 /* Because this function is called by other C code on non-leaf
680 windows, the CHECK_LIVE_WINDOW macro would choke inappropriately,
681 so we can't decode_window here. */
265a9e55 682 if (NILP (window))
7ab12479
JB
683 window = selected_window;
684 else
685 CHECK_WINDOW (window, 0);
7ab12479 686 p = XWINDOW (window);
605be8af
JB
687
688 /* It's okay to delete an already-deleted window. */
689 if (NILP (p->buffer)
690 && NILP (p->hchild)
691 && NILP (p->vchild))
692 return Qnil;
693
7ab12479 694 parent = p->parent;
265a9e55 695 if (NILP (parent))
7ab12479
JB
696 error ("Attempt to delete minibuffer or sole ordinary window");
697 par = XWINDOW (parent);
698
699 windows_or_buffers_changed++;
700
605be8af
JB
701 /* Are we trying to delete any frame's selected window? */
702 {
ae3050b3 703 FRAME_PTR frame = WINDOW_FRAME (XWINDOW (window));
605be8af 704
ae3050b3 705 if (EQ (window, FRAME_SELECTED_WINDOW (frame)))
605be8af
JB
706 {
707 Lisp_Object alternative = Fnext_window (window, Qlambda, Qnil);
708
709 /* If we're about to delete the selected window on the
710 selected frame, then we should use Fselect_window to select
711 the new window. On the other hand, if we're about to
712 delete the selected window on any other frame, we shouldn't do
713 anything but set the frame's selected_window slot. */
714 if (EQ (window, selected_window))
715 Fselect_window (alternative);
716 else
ae3050b3 717 FRAME_SELECTED_WINDOW (frame) = alternative;
605be8af
JB
718 }
719 }
7ab12479
JB
720
721 tem = p->buffer;
722 /* tem is null for dummy parent windows
723 (which have inferiors but not any contents themselves) */
265a9e55 724 if (!NILP (tem))
7ab12479
JB
725 {
726 unshow_buffer (p);
727 unchain_marker (p->pointm);
728 unchain_marker (p->start);
7ab12479
JB
729 }
730
731 tem = p->next;
265a9e55 732 if (!NILP (tem))
7ab12479
JB
733 XWINDOW (tem)->prev = p->prev;
734
735 tem = p->prev;
265a9e55 736 if (!NILP (tem))
7ab12479
JB
737 XWINDOW (tem)->next = p->next;
738
739 if (EQ (window, par->hchild))
740 par->hchild = p->next;
741 if (EQ (window, par->vchild))
742 par->vchild = p->next;
743
744 /* Find one of our siblings to give our space to. */
745 sib = p->prev;
265a9e55 746 if (NILP (sib))
7ab12479
JB
747 {
748 /* If p gives its space to its next sibling, that sibling needs
749 to have its top/left side pulled back to where p's is.
750 set_window_{height,width} will re-position the sibling's
751 children. */
752 sib = p->next;
7f4161e0
JB
753 XWINDOW (sib)->top = p->top;
754 XWINDOW (sib)->left = p->left;
7ab12479
JB
755 }
756
757 /* Stretch that sibling. */
265a9e55 758 if (!NILP (par->vchild))
7ab12479
JB
759 set_window_height (sib,
760 XFASTINT (XWINDOW (sib)->height) + XFASTINT (p->height),
761 1);
265a9e55 762 if (!NILP (par->hchild))
7ab12479
JB
763 set_window_width (sib,
764 XFASTINT (XWINDOW (sib)->width) + XFASTINT (p->width),
765 1);
766
767 /* If parent now has only one child,
768 put the child into the parent's place. */
7ab12479 769 tem = par->hchild;
265a9e55 770 if (NILP (tem))
7ab12479 771 tem = par->vchild;
265a9e55 772 if (NILP (XWINDOW (tem)->next))
7ab12479 773 replace_window (parent, tem);
605be8af
JB
774
775 /* Since we may be deleting combination windows, we must make sure that
776 not only p but all its children have been marked as deleted. */
777 if (! NILP (p->hchild))
778 delete_all_subwindows (XWINDOW (p->hchild));
779 else if (! NILP (p->vchild))
780 delete_all_subwindows (XWINDOW (p->vchild));
781
782 /* Mark this window as deleted. */
783 p->buffer = p->hchild = p->vchild = Qnil;
784
7ab12479
JB
785 return Qnil;
786}
787\f
7ab12479 788
44fa5b1e 789extern Lisp_Object next_frame (), prev_frame ();
7ab12479
JB
790
791DEFUN ("next-window", Fnext_window, Snext_window, 0, 3, 0,
792 "Return next window after WINDOW in canonical ordering of windows.\n\
d5783c40
JB
793If omitted, WINDOW defaults to the selected window.\n\
794\n\
795Optional second arg MINIBUF t means count the minibuffer window even\n\
796if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
797it is active. MINIBUF neither t nor nil means not to count the\n\
798minibuffer even if it is active.\n\
799\n\
44fa5b1e
JB
800Several frames may share a single minibuffer; if the minibuffer\n\
801counts, all windows on all frames that share that minibuffer count\n\
d5783c40 802too. This means that next-window may be used to iterate through the\n\
44fa5b1e
JB
803set of windows even when the minibuffer is on another frame. If the\n\
804minibuffer does not count, only windows from WINDOW's frame count.\n\
d5783c40 805\n\
44fa5b1e
JB
806Optional third arg ALL-FRAMES t means include windows on all frames.\n\
807ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
dbc4e1c1
JB
808above. If neither nil nor t, restrict to WINDOW's frame.\n\
809\n\
810If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
811`next-window' to iterate through the entire cycle of acceptable\n\
812windows, eventually ending up back at the window you started with.\n\
813`previous-window' traverses the same cycle, in the reverse order.")
44fa5b1e
JB
814 (window, minibuf, all_frames)
815 register Lisp_Object window, minibuf, all_frames;
7ab12479
JB
816{
817 register Lisp_Object tem;
d5783c40 818 Lisp_Object start_window;
7ab12479 819
265a9e55 820 if (NILP (window))
7ab12479
JB
821 window = selected_window;
822 else
605be8af 823 CHECK_LIVE_WINDOW (window, 0);
7ab12479 824
d5783c40
JB
825 start_window = window;
826
827 /* minibuf == nil may or may not include minibuffers.
828 Decide if it does. */
265a9e55 829 if (NILP (minibuf))
d5783c40
JB
830 minibuf = (minibuf_level ? Qt : Qlambda);
831
44fa5b1e
JB
832 /* all_frames == nil doesn't specify which frames to include.
833 Decide which frames it includes. */
834 if (NILP (all_frames))
835 all_frames = (EQ (minibuf, Qt)
836 ? (FRAME_MINIBUF_WINDOW
837 (XFRAME
838 (WINDOW_FRAME
d5783c40
JB
839 (XWINDOW (window)))))
840 : Qnil);
44fa5b1e
JB
841 else if (! EQ (all_frames, Qt))
842 all_frames = Qnil;
644b477c
RS
843 /* Now all_frames is t meaning search all frames,
844 nil meaning search just current frame,
845 or a window, meaning search the frame that window belongs to. */
7ab12479
JB
846
847 /* Do this loop at least once, to get the next window, and perhaps
848 again, if we hit the minibuffer and that is not acceptable. */
849 do
850 {
851 /* Find a window that actually has a next one. This loop
852 climbs up the tree. */
265a9e55
JB
853 while (tem = XWINDOW (window)->next, NILP (tem))
854 if (tem = XWINDOW (window)->parent, !NILP (tem))
7ab12479 855 window = tem;
d5783c40 856 else
7ab12479 857 {
44fa5b1e
JB
858 /* We've reached the end of this frame.
859 Which other frames are acceptable? */
860 tem = WINDOW_FRAME (XWINDOW (window));
861#ifdef MULTI_FRAME
862 if (! NILP (all_frames))
863 tem = next_frame (tem, all_frames);
7ab12479 864#endif
44fa5b1e 865 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
d5783c40 866
7ab12479
JB
867 break;
868 }
869
870 window = tem;
d5783c40 871
7ab12479
JB
872 /* If we're in a combination window, find its first child and
873 recurse on that. Otherwise, we've found the window we want. */
874 while (1)
875 {
265a9e55 876 if (!NILP (XWINDOW (window)->hchild))
7ab12479 877 window = XWINDOW (window)->hchild;
265a9e55 878 else if (!NILP (XWINDOW (window)->vchild))
7ab12479
JB
879 window = XWINDOW (window)->vchild;
880 else break;
881 }
882 }
d5783c40
JB
883 /* Which windows are acceptible?
884 Exit the loop and accept this window if
7ab12479 885 this isn't a minibuffer window, or
d5783c40
JB
886 we're accepting minibuffer windows, or
887 we've come all the way around and we're back at the original window. */
7ab12479 888 while (MINI_WINDOW_P (XWINDOW (window))
d5783c40 889 && ! EQ (minibuf, Qt)
7f4161e0 890 && ! EQ (window, start_window));
7ab12479
JB
891
892 return window;
893}
894
895DEFUN ("previous-window", Fprevious_window, Sprevious_window, 0, 3, 0,
d5783c40
JB
896 "Return the window preceeding WINDOW in canonical ordering of windows.\n\
897If omitted, WINDOW defaults to the selected window.\n\
898\n\
899Optional second arg MINIBUF t means count the minibuffer window even\n\
900if not active. MINIBUF nil or omitted means count the minibuffer iff\n\
901it is active. MINIBUF neither t nor nil means not to count the\n\
902minibuffer even if it is active.\n\
903\n\
44fa5b1e
JB
904Several frames may share a single minibuffer; if the minibuffer\n\
905counts, all windows on all frames that share that minibuffer count\n\
d5783c40 906too. This means that previous-window may be used to iterate through\n\
44fa5b1e
JB
907the set of windows even when the minibuffer is on another frame. If\n\
908the minibuffer does not count, only windows from WINDOW's frame\n\
d5783c40
JB
909count.\n\
910\n\
44fa5b1e
JB
911Optional third arg ALL-FRAMES t means include windows on all frames.\n\
912ALL-FRAMES nil or omitted means cycle within the frames as specified\n\
dbc4e1c1
JB
913above. If neither nil nor t, restrict to WINDOW's frame.\n\
914\n\
915If you use consistent values for MINIBUF and ALL-FRAMES, you can use\n\
916`previous-window' to iterate through the entire cycle of acceptable\n\
917windows, eventually ending up back at the window you started with.\n\
918`next-window' traverses the same cycle, in the reverse order.")
44fa5b1e
JB
919 (window, minibuf, all_frames)
920 register Lisp_Object window, minibuf, all_frames;
7ab12479
JB
921{
922 register Lisp_Object tem;
d5783c40 923 Lisp_Object start_window;
7ab12479 924
265a9e55 925 if (NILP (window))
7ab12479
JB
926 window = selected_window;
927 else
605be8af 928 CHECK_LIVE_WINDOW (window, 0);
7ab12479 929
d5783c40
JB
930 start_window = window;
931
932 /* minibuf == nil may or may not include minibuffers.
933 Decide if it does. */
265a9e55 934 if (NILP (minibuf))
d5783c40
JB
935 minibuf = (minibuf_level ? Qt : Qlambda);
936
44fa5b1e
JB
937 /* all_frames == nil doesn't specify which frames to include.
938 Decide which frames it includes. */
939 if (NILP (all_frames))
940 all_frames = (EQ (minibuf, Qt)
941 ? (FRAME_MINIBUF_WINDOW
942 (XFRAME
943 (WINDOW_FRAME
d5783c40
JB
944 (XWINDOW (window)))))
945 : Qnil);
44fa5b1e
JB
946 else if (! EQ (all_frames, Qt))
947 all_frames = Qnil;
644b477c
RS
948 /* Now all_frames is t meaning search all frames,
949 nil meaning search just current frame,
950 or a window, meaning search the frame that window belongs to. */
7ab12479
JB
951
952 /* Do this loop at least once, to get the previous window, and perhaps
953 again, if we hit the minibuffer and that is not acceptable. */
954 do
955 {
956 /* Find a window that actually has a previous one. This loop
957 climbs up the tree. */
265a9e55
JB
958 while (tem = XWINDOW (window)->prev, NILP (tem))
959 if (tem = XWINDOW (window)->parent, !NILP (tem))
7ab12479 960 window = tem;
d5783c40 961 else
7ab12479 962 {
44fa5b1e
JB
963 /* We have found the top window on the frame.
964 Which frames are acceptable? */
965 tem = WINDOW_FRAME (XWINDOW (window));
966#ifdef MULTI_FRAME
967 if (! NILP (all_frames))
dbc4e1c1
JB
968 /* It's actually important that we use prev_frame here,
969 rather than next_frame. All the windows acceptable
970 according to the given parameters should form a ring;
971 Fnext_window and Fprevious_window should go back and
972 forth around the ring. If we use next_frame here,
973 then Fnext_window and Fprevious_window take different
974 paths through the set of acceptable windows.
975 window_loop assumes that these `ring' requirement are
976 met. */
977 tem = prev_frame (tem, all_frames);
7ab12479 978#endif
644b477c
RS
979 /* If this frame has a minibuffer, find that window first,
980 because it is conceptually the last window in that frame. */
5e12e32f
JB
981 if (FRAME_HAS_MINIBUF_P (XFRAME (tem)))
982 tem = FRAME_MINIBUF_WINDOW (XFRAME (tem));
983 else
644b477c 984 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
d5783c40 985
7ab12479
JB
986 break;
987 }
988
989 window = tem;
990 /* If we're in a combination window, find its last child and
991 recurse on that. Otherwise, we've found the window we want. */
992 while (1)
993 {
265a9e55 994 if (!NILP (XWINDOW (window)->hchild))
7ab12479 995 window = XWINDOW (window)->hchild;
265a9e55 996 else if (!NILP (XWINDOW (window)->vchild))
7ab12479
JB
997 window = XWINDOW (window)->vchild;
998 else break;
265a9e55 999 while (tem = XWINDOW (window)->next, !NILP (tem))
7ab12479
JB
1000 window = tem;
1001 }
1002 }
d5783c40
JB
1003 /* Which windows are acceptable?
1004 Exit the loop and accept this window if
7ab12479 1005 this isn't a minibuffer window, or
d5783c40
JB
1006 we're accepting minibuffer windows, or
1007 we've come all the way around and we're back at the original window. */
7ab12479 1008 while (MINI_WINDOW_P (XWINDOW (window))
d5783c40 1009 && !EQ (minibuf, Qt)
7f4161e0 1010 && !EQ (window, start_window));
7ab12479
JB
1011
1012 return window;
1013}
1014
62c07cc7 1015DEFUN ("other-window", Fother_window, Sother_window, 1, 2, "p",
44fa5b1e
JB
1016 "Select the ARG'th different window on this frame.\n\
1017All windows on current frame are arranged in a cyclic order.\n\
7ab12479
JB
1018This command selects the window ARG steps away in that order.\n\
1019A negative ARG moves in the opposite order. If the optional second\n\
44fa5b1e
JB
1020argument ALL_FRAMES is non-nil, cycle through all frames.")
1021 (n, all_frames)
1022 register Lisp_Object n, all_frames;
7ab12479
JB
1023{
1024 register int i;
1025 register Lisp_Object w;
1026
1027 CHECK_NUMBER (n, 0);
1028 w = selected_window;
1029 i = XINT (n);
1030
1031 while (i > 0)
1032 {
44fa5b1e 1033 w = Fnext_window (w, Qnil, all_frames);
7ab12479
JB
1034 i--;
1035 }
1036 while (i < 0)
1037 {
44fa5b1e 1038 w = Fprevious_window (w, Qnil, all_frames);
7ab12479
JB
1039 i++;
1040 }
1041 Fselect_window (w);
1042 return Qnil;
1043}
1044\f
1045/* Look at all windows, performing an operation specified by TYPE
1046 with argument OBJ.
44fa5b1e
JB
1047 If FRAMES is Qt, look at all frames, if Qnil, look at just the selected
1048 frame. If FRAMES is a frame, just look at windows on that frame.
7ab12479
JB
1049 If MINI is non-zero, perform the operation on minibuffer windows too.
1050*/
1051
1052enum window_loop
1053{
1054 WINDOW_LOOP_UNUSED,
1055 GET_BUFFER_WINDOW, /* Arg is buffer */
1056 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
1057 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
1058 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
1059 GET_LARGEST_WINDOW,
1060 UNSHOW_BUFFER, /* Arg is buffer */
1061};
1062
1063static Lisp_Object
44fa5b1e 1064window_loop (type, obj, mini, frames)
7ab12479 1065 enum window_loop type;
44fa5b1e 1066 register Lisp_Object obj, frames;
7ab12479
JB
1067 int mini;
1068{
1069 register Lisp_Object w;
1070 register Lisp_Object best_window;
1071 register Lisp_Object next_window;
4b206065 1072 register Lisp_Object last_window;
44fa5b1e
JB
1073 FRAME_PTR frame;
1074
4b206065 1075#ifdef MULTI_FRAME
44fa5b1e
JB
1076 /* If we're only looping through windows on a particular frame,
1077 frame points to that frame. If we're looping through windows
1078 on all frames, frame is 0. */
1079 if (FRAMEP (frames))
1080 frame = XFRAME (frames);
1081 else if (NILP (frames))
1082 frame = selected_frame;
7ab12479 1083 else
44fa5b1e 1084 frame = 0;
4b206065
JB
1085#else
1086 frame = 0;
1087#endif
7ab12479
JB
1088
1089 /* Pick a window to start with. */
1090 if (XTYPE (obj) == Lisp_Window)
4b206065 1091 w = obj;
44fa5b1e 1092 else if (frame)
4b206065 1093 w = FRAME_SELECTED_WINDOW (frame);
7ab12479 1094 else
4b206065
JB
1095 w = FRAME_SELECTED_WINDOW (selected_frame);
1096
1097 /* Figure out the last window we're going to mess with. Since
1098 Fnext_window, given the same options, is guaranteed to go in a
1099 ring, we can just use Fprevious_window to find the last one.
1100
1101 We can't just wait until we hit the first window again, because
1102 it might be deleted. */
1103
1104#ifdef MULTI_FRAME
1105 if (frame)
1106 last_window = Fprevious_window (w, (mini ? Qt : Qnil), Qlambda);
1107 else
1108#endif /* MULTI_FRAME */
1109 /* We know frame is 0, so we're looping through all frames.
1110 Or we know this isn't a MULTI_FRAME Emacs, so who cares? */
1111 last_window = Fprevious_window (w, mini ? Qt : Qnil, Qt);
7ab12479 1112
7ab12479 1113 best_window = Qnil;
4b206065 1114 for (;;)
7ab12479
JB
1115 {
1116 /* Pick the next window now, since some operations will delete
1117 the current window. */
44fa5b1e
JB
1118#ifdef MULTI_FRAME
1119 if (frame)
d5783c40 1120 next_window = Fnext_window (w, (mini ? Qt : Qnil), Qlambda);
7ab12479 1121 else
4b206065 1122#endif /* MULTI_FRAME */
44fa5b1e
JB
1123 /* We know frame is 0, so we're looping through all frames.
1124 Or we know this isn't a MULTI_FRAME Emacs, so who cares? */
7ab12479
JB
1125 next_window = Fnext_window (w, mini ? Qt : Qnil, Qt);
1126
1127 if (!MINI_WINDOW_P (XWINDOW (w))
1128 || (mini && minibuf_level > 0))
1129 switch (type)
1130 {
1131 case GET_BUFFER_WINDOW:
1132#if 0
44fa5b1e
JB
1133 /* Ignore invisible and iconified frames. */
1134 if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))
1135 || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))))
7ab12479
JB
1136 break;
1137#endif
1138 if (XBUFFER (XWINDOW (w)->buffer) == XBUFFER (obj))
1139 return w;
1140 break;
1141
1142 case GET_LRU_WINDOW:
1143 /* t as arg means consider only full-width windows */
e5d77022 1144 if (!NILP (obj) && XFASTINT (XWINDOW (w)->width)
a2db42d6 1145 != FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (w)))))
7ab12479
JB
1146 break;
1147#if 0
44fa5b1e
JB
1148 /* Ignore invisible and iconified frames. */
1149 if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))
1150 || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))))
7ab12479
JB
1151 break;
1152#endif
1153 /* Ignore dedicated windows and minibuffers. */
1154 if (MINI_WINDOW_P (XWINDOW (w))
265a9e55 1155 || !NILP (XWINDOW (w)->dedicated))
7ab12479 1156 break;
265a9e55 1157 if (NILP (best_window)
7ab12479
JB
1158 || (XFASTINT (XWINDOW (best_window)->use_time)
1159 > XFASTINT (XWINDOW (w)->use_time)))
1160 best_window = w;
1161 break;
1162
1163 case DELETE_OTHER_WINDOWS:
1164 if (XWINDOW (w) != XWINDOW (obj))
1165 Fdelete_window (w);
1166 break;
1167
1168 case DELETE_BUFFER_WINDOWS:
1169 if (EQ (XWINDOW (w)->buffer, obj))
1170 {
1171 /* If we're deleting the buffer displayed in the only window
44fa5b1e 1172 on the frame, find a new buffer to display there. */
265a9e55 1173 if (NILP (XWINDOW (w)->parent))
7ab12479 1174 {
faa64cf7 1175 Lisp_Object new_buffer = Fother_buffer (obj, Qnil);
265a9e55 1176 if (NILP (new_buffer))
7ab12479
JB
1177 new_buffer
1178 = Fget_buffer_create (build_string ("*scratch*"));
1179 Fset_window_buffer (w, new_buffer);
1180 Fset_buffer (XWINDOW (w)->buffer);
1181 }
1182 else
1183 Fdelete_window (w);
1184 }
1185 break;
1186
1187 case GET_LARGEST_WINDOW:
1188#if 0
44fa5b1e
JB
1189 /* Ignore invisible and iconified frames. */
1190 if (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (w))))
1191 || FRAME_ICONIFIED_P (XFRAME (WINDOW_FRAME (XWINDOW (w)))))
7ab12479
JB
1192 break;
1193#endif
1194 /* Ignore dedicated windows and minibuffers. */
1195 if (MINI_WINDOW_P (XWINDOW (w))
265a9e55 1196 || !NILP (XWINDOW (w)->dedicated))
7ab12479
JB
1197 break;
1198 {
1199 struct window *best_window_ptr = XWINDOW (best_window);
1200 struct window *w_ptr = XWINDOW (w);
265a9e55 1201 if (NILP (best_window) ||
7ab12479
JB
1202 (XFASTINT (w_ptr->height) * XFASTINT (w_ptr->width))
1203 > (XFASTINT (best_window_ptr->height)
1204 * XFASTINT (best_window_ptr->width)))
1205 best_window = w;
1206 }
1207 break;
1208
1209 case UNSHOW_BUFFER:
1210 if (EQ (XWINDOW (w)->buffer, obj))
1211 {
1212 /* Find another buffer to show in this window. */
faa64cf7 1213 Lisp_Object another_buffer = Fother_buffer (obj, Qnil);
265a9e55 1214 if (NILP (another_buffer))
7ab12479
JB
1215 another_buffer
1216 = Fget_buffer_create (build_string ("*scratch*"));
1217 Fset_window_buffer (w, another_buffer);
1218 if (EQ (w, selected_window))
1219 Fset_buffer (XWINDOW (w)->buffer);
1220 }
1221 break;
1222 }
4b206065
JB
1223
1224 if (EQ (w, last_window))
1225 break;
1226
7ab12479
JB
1227 w = next_window;
1228 }
7ab12479
JB
1229
1230 return best_window;
1231}
605be8af 1232
7ab12479
JB
1233DEFUN ("get-lru-window", Fget_lru_window, Sget_lru_window, 0, 1, 0,
1234 "Return the window least recently selected or used for display.\n\
44fa5b1e
JB
1235If optional argument FRAMES is t, search all frames. If FRAME is a\n\
1236frame, search only that frame.\n")
1237 (frames)
1238 Lisp_Object frames;
7ab12479
JB
1239{
1240 register Lisp_Object w;
1241 /* First try for a window that is full-width */
44fa5b1e 1242 w = window_loop (GET_LRU_WINDOW, Qt, 0, frames);
265a9e55 1243 if (!NILP (w) && !EQ (w, selected_window))
7ab12479
JB
1244 return w;
1245 /* If none of them, try the rest */
44fa5b1e 1246 return window_loop (GET_LRU_WINDOW, Qnil, 0, frames);
7ab12479
JB
1247}
1248
1249DEFUN ("get-largest-window", Fget_largest_window, Sget_largest_window, 0, 1, 0,
1250 "Return the largest window in area.\n\
44fa5b1e
JB
1251If optional argument FRAMES is t, search all frames. If FRAME is a\n\
1252frame, search only that frame.\n")
1253 (frame)
1254 Lisp_Object frame;
7ab12479
JB
1255{
1256 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
44fa5b1e 1257 frame);
7ab12479
JB
1258}
1259
1260DEFUN ("get-buffer-window", Fget_buffer_window, Sget_buffer_window, 1, 2, 0,
1261 "Return a window currently displaying BUFFER, or nil if none.\n\
44fa5b1e
JB
1262If optional argument FRAMES is t, search all frames. If FRAME is a\n\
1263frame, search only that frame.\n")
1264 (buffer, frame)
1265 Lisp_Object buffer, frame;
7ab12479
JB
1266{
1267 buffer = Fget_buffer (buffer);
1268 if (XTYPE (buffer) == Lisp_Buffer)
44fa5b1e 1269 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame);
7ab12479
JB
1270 else
1271 return Qnil;
1272}
1273
1274DEFUN ("delete-other-windows", Fdelete_other_windows, Sdelete_other_windows,
1275 0, 1, "",
44fa5b1e
JB
1276 "Make WINDOW (or the selected window) fill its frame.\n\
1277Only the frame WINDOW is on is affected.")
7ab12479
JB
1278 (window)
1279 Lisp_Object window;
1280{
1281 struct window *w;
1282 int opoint = point;
1283 struct buffer *obuf = current_buffer;
1284 int top;
1285
265a9e55 1286 if (NILP (window))
7ab12479
JB
1287 window = selected_window;
1288 else
605be8af 1289 CHECK_LIVE_WINDOW (window, 0);
7ab12479
JB
1290
1291 w = XWINDOW (window);
1292 top = XFASTINT (w->top);
1293
70728a80 1294 window_loop (DELETE_OTHER_WINDOWS, window, 0, WINDOW_FRAME (w));
7ab12479
JB
1295
1296 Fset_buffer (w->buffer);
1297 SET_PT (marker_position (w->start));
70728a80 1298 Frecenter (make_number (top - FRAME_MENU_BAR_LINES (XFRAME (WINDOW_FRAME (w)))));
7ab12479
JB
1299
1300 set_buffer_internal (obuf);
1301 SET_PT (opoint);
1302 return Qnil;
1303}
1304
1305DEFUN ("delete-windows-on", Fdelete_windows_on, Sdelete_windows_on,
1306 1, 1, "bDelete windows on (buffer): ",
1307 "Delete all windows showing BUFFER.")
1308 (buffer)
1309 Lisp_Object buffer;
1310{
265a9e55 1311 if (!NILP (buffer))
7ab12479
JB
1312 {
1313 buffer = Fget_buffer (buffer);
1314 CHECK_BUFFER (buffer, 0);
1315 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, Qt);
1316 }
1317 return Qnil;
1318}
1319
1320DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows,
1321 Sreplace_buffer_in_windows,
1322 1, 1, "bReplace buffer in windows: ",
1323 "Replace BUFFER with some other buffer in all windows showing it.")
1324 (buffer)
1325 Lisp_Object buffer;
1326{
265a9e55 1327 if (!NILP (buffer))
7ab12479
JB
1328 {
1329 buffer = Fget_buffer (buffer);
1330 CHECK_BUFFER (buffer, 0);
1331 window_loop (UNSHOW_BUFFER, buffer, 0, Qt);
1332 }
1333 return Qnil;
1334}
1335\f
1336/* Set the height of WINDOW and all its inferiors. */
a481b3ea
JB
1337
1338/* The smallest acceptable dimensions for a window. Anything smaller
1339 might crash Emacs. */
1340#define MIN_SAFE_WINDOW_WIDTH (2)
1341#define MIN_SAFE_WINDOW_HEIGHT (2)
1342
1343/* Make sure that window_min_height and window_min_width are
1344 not too small; if they are, set them to safe minima. */
1345
1346static void
1347check_min_window_sizes ()
1348{
1349 /* Smaller values might permit a crash. */
1350 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
1351 window_min_width = MIN_SAFE_WINDOW_WIDTH;
1352 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
1353 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
1354}
1355
1356/* If *ROWS or *COLS are too small a size for FRAME, set them to the
1357 minimum allowable size. */
605be8af 1358void
a481b3ea 1359check_frame_size (frame, rows, cols)
605be8af
JB
1360 FRAME_PTR frame;
1361 int *rows, *cols;
a481b3ea
JB
1362{
1363 /* For height, we have to see whether the frame has a minibuffer, and
1364 whether it wants a mode line. */
1365 int min_height =
1366 ((FRAME_MINIBUF_ONLY_P (frame)
1367 || ! FRAME_HAS_MINIBUF_P (frame))
1368 ? MIN_SAFE_WINDOW_HEIGHT
1369 : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
1370
1371 if (*rows < min_height)
1372 *rows = min_height;
1373 if (*cols < MIN_SAFE_WINDOW_WIDTH)
1374 *cols = MIN_SAFE_WINDOW_WIDTH;
1375}
1376
7ab12479
JB
1377/* Normally the window is deleted if it gets too small.
1378 nodelete nonzero means do not do this.
1379 (The caller should check later and do so if appropriate) */
1380
1381set_window_height (window, height, nodelete)
1382 Lisp_Object window;
1383 int height;
1384 int nodelete;
1385{
1386 register struct window *w = XWINDOW (window);
1387 register struct window *c;
1388 int oheight = XFASTINT (w->height);
1389 int top, pos, lastbot, opos, lastobot;
1390 Lisp_Object child;
1391
a481b3ea
JB
1392 check_min_window_sizes ();
1393
7ab12479 1394 if (!nodelete
265a9e55 1395 && ! NILP (w->parent)
7ab12479
JB
1396 && height < window_min_height)
1397 {
1398 Fdelete_window (window);
1399 return;
1400 }
1401
1402 XFASTINT (w->last_modified) = 0;
1403 windows_or_buffers_changed++;
1404 XFASTINT (w->height) = height;
265a9e55 1405 if (!NILP (w->hchild))
7ab12479 1406 {
265a9e55 1407 for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next)
7ab12479
JB
1408 {
1409 XWINDOW (child)->top = w->top;
1410 set_window_height (child, height, nodelete);
1411 }
1412 }
265a9e55 1413 else if (!NILP (w->vchild))
7ab12479
JB
1414 {
1415 lastbot = top = XFASTINT (w->top);
1416 lastobot = 0;
265a9e55 1417 for (child = w->vchild; !NILP (child); child = c->next)
7ab12479
JB
1418 {
1419 c = XWINDOW (child);
1420
1421 opos = lastobot + XFASTINT (c->height);
1422
1423 XFASTINT (c->top) = lastbot;
1424
1425 pos = (((opos * height) << 1) + oheight) / (oheight << 1);
1426
1427 /* Avoid confusion: inhibit deletion of child if becomes too small */
1428 set_window_height (child, pos + top - lastbot, 1);
1429
1430 /* Now advance child to next window,
1431 and set lastbot if child was not just deleted. */
1432 lastbot = pos + top;
1433 lastobot = opos;
1434 }
1435 /* Now delete any children that became too small. */
1436 if (!nodelete)
265a9e55 1437 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
7ab12479
JB
1438 {
1439 set_window_height (child, XINT (XWINDOW (child)->height), 0);
1440 }
1441 }
1442}
1443
1444/* Recursively set width of WINDOW and its inferiors. */
1445
1446set_window_width (window, width, nodelete)
1447 Lisp_Object window;
1448 int width;
1449 int nodelete;
1450{
1451 register struct window *w = XWINDOW (window);
1452 register struct window *c;
1453 int owidth = XFASTINT (w->width);
1454 int left, pos, lastright, opos, lastoright;
1455 Lisp_Object child;
1456
1457 if (!nodelete && width < window_min_width)
1458 {
1459 Fdelete_window (window);
1460 return;
1461 }
1462
1463 XFASTINT (w->last_modified) = 0;
1464 windows_or_buffers_changed++;
1465 XFASTINT (w->width) = width;
265a9e55 1466 if (!NILP (w->vchild))
7ab12479 1467 {
265a9e55 1468 for (child = w->vchild; !NILP (child); child = XWINDOW (child)->next)
7ab12479
JB
1469 {
1470 XWINDOW (child)->left = w->left;
1471 set_window_width (child, width, nodelete);
1472 }
1473 }
265a9e55 1474 else if (!NILP (w->hchild))
7ab12479
JB
1475 {
1476 lastright = left = XFASTINT (w->left);
1477 lastoright = 0;
265a9e55 1478 for (child = w->hchild; !NILP (child); child = c->next)
7ab12479
JB
1479 {
1480 c = XWINDOW (child);
1481
1482 opos = lastoright + XFASTINT (c->width);
1483
1484 XFASTINT (c->left) = lastright;
1485
1486 pos = (((opos * width) << 1) + owidth) / (owidth << 1);
1487
1488 /* Inhibit deletion for becoming too small */
1489 set_window_width (child, pos + left - lastright, 1);
1490
1491 /* Now advance child to next window,
1492 and set lastright if child was not just deleted. */
1493 lastright = pos + left, lastoright = opos;
1494 }
1495 /* Delete children that became too small */
1496 if (!nodelete)
265a9e55 1497 for (child = w->hchild; !NILP (child); child = XWINDOW (child)->next)
7ab12479
JB
1498 {
1499 set_window_width (child, XINT (XWINDOW (child)->width), 0);
1500 }
1501 }
1502}
1503\f
1d8d96fa 1504int window_select_count;
7ab12479
JB
1505
1506DEFUN ("set-window-buffer", Fset_window_buffer, Sset_window_buffer, 2, 2, 0,
1507 "Make WINDOW display BUFFER as its contents.\n\
1508BUFFER can be a buffer or buffer name.")
1509 (window, buffer)
1510 register Lisp_Object window, buffer;
1511{
1512 register Lisp_Object tem;
1513 register struct window *w = decode_window (window);
1514
1515 buffer = Fget_buffer (buffer);
1516 CHECK_BUFFER (buffer, 1);
1517
265a9e55 1518 if (NILP (XBUFFER (buffer)->name))
7ab12479
JB
1519 error ("Attempt to display deleted buffer");
1520
1521 tem = w->buffer;
265a9e55 1522 if (NILP (tem))
7ab12479
JB
1523 error ("Window is deleted");
1524 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
1525 is first being set up. */
1526 {
265a9e55 1527 if (!NILP (w->dedicated) && !EQ (tem, buffer))
7ab12479
JB
1528 error ("Window is dedicated to %s\n", tem);
1529
1530 unshow_buffer (w);
1531 }
1532
1533 w->buffer = buffer;
270967b2 1534 w->hscroll = 0;
7ab12479
JB
1535 Fset_marker (w->pointm,
1536 make_number (BUF_PT (XBUFFER (buffer))),
1537 buffer);
1538 set_marker_restricted (w->start,
1539 make_number (XBUFFER (buffer)->last_window_start),
1540 buffer);
1541 w->start_at_line_beg = Qnil;
e36ab06b 1542 w->force_start = Qnil;
7ab12479
JB
1543 XFASTINT (w->last_modified) = 0;
1544 windows_or_buffers_changed++;
1545 if (EQ (window, selected_window))
1546 Fset_buffer (buffer);
1547
1548 return Qnil;
1549}
1550
1551DEFUN ("select-window", Fselect_window, Sselect_window, 1, 1, 0,
1552 "Select WINDOW. Most editing will apply to WINDOW's buffer.\n\
1553The main editor command loop selects the buffer of the selected window\n\
1554before each command.")
1555 (window)
1556 register Lisp_Object window;
1557{
1558 register struct window *w;
1559 register struct window *ow = XWINDOW (selected_window);
1560
605be8af 1561 CHECK_LIVE_WINDOW (window, 0);
7ab12479
JB
1562
1563 w = XWINDOW (window);
1564
265a9e55 1565 if (NILP (w->buffer))
7ab12479
JB
1566 error ("Trying to select deleted window or non-leaf window");
1567
1568 XFASTINT (w->use_time) = ++window_select_count;
1569 if (EQ (window, selected_window))
1570 return window;
1571
1572 Fset_marker (ow->pointm, make_number (BUF_PT (XBUFFER (ow->buffer))),
1573 ow->buffer);
1574
1575 selected_window = window;
44fa5b1e
JB
1576#ifdef MULTI_FRAME
1577 if (XFRAME (WINDOW_FRAME (w)) != selected_frame)
7ab12479 1578 {
44fa5b1e 1579 XFRAME (WINDOW_FRAME (w))->selected_window = window;
d5b2799e 1580 Fhandle_switch_frame (WINDOW_FRAME (w), Qnil);
7ab12479
JB
1581 }
1582 else
44fa5b1e 1583 selected_frame->selected_window = window;
7ab12479
JB
1584#endif
1585
1586 record_buffer (w->buffer);
1587 Fset_buffer (w->buffer);
1588
1589 /* Go to the point recorded in the window.
1590 This is important when the buffer is in more
1591 than one window. It also matters when
1592 redisplay_window has altered point after scrolling,
1593 because it makes the change only in the window. */
1594 {
1595 register int new_point = marker_position (w->pointm);
1596 if (new_point < BEGV)
1597 SET_PT (BEGV);
1598 if (new_point > ZV)
1599 SET_PT (ZV);
1600 else
1601 SET_PT (new_point);
1602 }
1603
1604 windows_or_buffers_changed++;
1605 return window;
1606}
1607
35aaf00c 1608DEFUN ("display-buffer", Fdisplay_buffer, Sdisplay_buffer, 1, 2,
6648f23a 1609 "BDisplay buffer: \nP",
7ab12479
JB
1610 "Make BUFFER appear in some window but don't select it.\n\
1611BUFFER can be a buffer or a buffer name.\n\
1612If BUFFER is shown already in some window, just use that one,\n\
1613unless the window is the selected window and the optional second\n\
46d3268a 1614argument NOT-THIS-WINDOW is non-nil (interactively, with prefix arg).\n\
7ab12479
JB
1615Returns the window displaying BUFFER.")
1616 (buffer, not_this_window)
1617 register Lisp_Object buffer, not_this_window;
1618{
1619 register Lisp_Object window;
1620
1621 buffer = Fget_buffer (buffer);
1622 CHECK_BUFFER (buffer, 0);
1623
265a9e55 1624 if (!NILP (Vdisplay_buffer_function))
7ab12479
JB
1625 return call2 (Vdisplay_buffer_function, buffer, not_this_window);
1626
265a9e55 1627 if (NILP (not_this_window)
7ab12479
JB
1628 && XBUFFER (XWINDOW (selected_window)->buffer) == XBUFFER (buffer))
1629 return selected_window;
1630
1631 window = Fget_buffer_window (buffer, Qnil);
265a9e55
JB
1632 if (!NILP (window)
1633 && (NILP (not_this_window) || !EQ (window, selected_window)))
7ab12479
JB
1634 return window;
1635
44fa5b1e
JB
1636#ifdef MULTI_FRAME
1637 /* If there are no frames open that have more than a minibuffer,
1638 we need to create a new frame. */
1639 if (pop_up_frames || last_nonminibuf_frame == 0)
7ab12479
JB
1640 {
1641 window
44fa5b1e 1642 = Fframe_selected_window (call0 (Vpop_up_frame_function));
7ab12479
JB
1643 Fset_window_buffer (window, buffer);
1644#if 0
d5b2799e 1645 Fhandle_switch_frame (XWINDOW (window)->frame, Qnil);
7ab12479
JB
1646#endif
1647 return window;
1648 }
44fa5b1e 1649#endif /* MULTI_FRAME */
7ab12479 1650
43bad991 1651 if (pop_up_windows
44fa5b1e
JB
1652#ifdef MULTI_FRAME
1653 || FRAME_MINIBUF_ONLY_P (selected_frame)
43bad991
JB
1654#endif
1655 )
7ab12479 1656 {
44fa5b1e 1657 Lisp_Object frames = Qnil;
43bad991 1658
44fa5b1e
JB
1659#ifdef MULTI_FRAME
1660 if (FRAME_MINIBUF_ONLY_P (selected_frame))
1661 XSET (frames, Lisp_Frame, last_nonminibuf_frame);
7ab12479
JB
1662#endif
1663 /* Don't try to create a window if would get an error */
1664 if (split_height_threshold < window_min_height << 1)
1665 split_height_threshold = window_min_height << 1;
1666
44fa5b1e 1667 window = Fget_largest_window (frames);
7ab12479 1668
265a9e55 1669 if (!NILP (window)
7ab12479 1670 && window_height (window) >= split_height_threshold
535e0b8e
JB
1671 && (XFASTINT (XWINDOW (window)->width)
1672 == FRAME_WIDTH (XFRAME (WINDOW_FRAME (XWINDOW (window))))))
7ab12479
JB
1673 window = Fsplit_window (window, Qnil, Qnil);
1674 else
1675 {
44fa5b1e 1676 window = Fget_lru_window (frames);
7ab12479
JB
1677 if ((EQ (window, selected_window)
1678 || EQ (XWINDOW (window)->parent, Qnil))
1679 && window_height (window) >= window_min_height << 1)
1680 window = Fsplit_window (window, Qnil, Qnil);
1681 }
1682 }
1683 else
1684 window = Fget_lru_window (Qnil);
1685
1686 Fset_window_buffer (window, buffer);
1687 return window;
1688}
1689
1690void
1691temp_output_buffer_show (buf)
1692 register Lisp_Object buf;
1693{
1694 register struct buffer *old = current_buffer;
1695 register Lisp_Object window;
1696 register struct window *w;
1697
1698 Fset_buffer (buf);
1699 XBUFFER (buf)->save_modified = MODIFF;
1700 BEGV = BEG;
1701 ZV = Z;
1702 SET_PT (BEG);
1703 clip_changed = 1;
1704 set_buffer_internal (old);
1705
1706 if (!EQ (Vtemp_buffer_show_function, Qnil))
1707 call1 (Vtemp_buffer_show_function, buf);
1708 else
1709 {
1710 window = Fdisplay_buffer (buf, Qnil);
1711
44fa5b1e
JB
1712#ifdef MULTI_FRAME
1713 if (XFRAME (XWINDOW (window)->frame) != selected_frame)
1714 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
1715#endif /* MULTI_FRAME */
7ab12479
JB
1716 Vminibuf_scroll_window = window;
1717 w = XWINDOW (window);
1718 XFASTINT (w->hscroll) = 0;
1719 set_marker_restricted (w->start, make_number (1), buf);
1720 set_marker_restricted (w->pointm, make_number (1), buf);
1721 }
1722}
1723\f
1724static
1725make_dummy_parent (window)
1726 Lisp_Object window;
1727{
1728 register Lisp_Object old, new;
1729 register struct window *o, *p;
1730
1731 old = window;
1732 XSETTYPE (old, Lisp_Vector);
1733 new = Fcopy_sequence (old);
1734 XSETTYPE (new, Lisp_Window);
1735
1736 o = XWINDOW (old);
1737 p = XWINDOW (new);
1738 XFASTINT (p->sequence_number) = ++sequence_number;
1739
1740 /* Put new into window structure in place of window */
1741 replace_window (window, new);
1742
1743 o->next = Qnil;
1744 o->prev = Qnil;
1745 o->vchild = Qnil;
1746 o->hchild = Qnil;
1747 o->parent = new;
1748
1749 p->start = Qnil;
1750 p->pointm = Qnil;
1751 p->buffer = Qnil;
1752}
1753
1754DEFUN ("split-window", Fsplit_window, Ssplit_window, 0, 3, "",
1755 "Split WINDOW, putting SIZE lines in the first of the pair.\n\
1756WINDOW defaults to selected one and SIZE to half its size.\n\
1757If optional third arg HOR-FLAG is non-nil, split side by side\n\
1758and put SIZE columns in the first of the pair.")
1759 (window, chsize, horflag)
1760 Lisp_Object window, chsize, horflag;
1761{
1762 register Lisp_Object new;
1763 register struct window *o, *p;
1764 register int size;
1765
265a9e55 1766 if (NILP (window))
7ab12479
JB
1767 window = selected_window;
1768 else
605be8af 1769 CHECK_LIVE_WINDOW (window, 0);
7ab12479
JB
1770
1771 o = XWINDOW (window);
1772
265a9e55 1773 if (NILP (chsize))
7ab12479 1774 {
265a9e55 1775 if (!NILP (horflag))
7ab12479
JB
1776 /* Round odd size up, since this is for the left-hand window,
1777 and it will lose a column for the separators. */
1778 size = ((XFASTINT (o->width) + 1) & -2) >> 1;
1779 else
1780 size = XFASTINT (o->height) >> 1;
1781 }
1782 else
1783 {
1784 CHECK_NUMBER (chsize, 1);
1785 size = XINT (chsize);
1786 }
1787
1788 if (MINI_WINDOW_P (o))
1789 error ("Attempt to split minibuffer window");
44fa5b1e
JB
1790 else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o))))
1791 error ("Attempt to split unsplittable frame");
7ab12479 1792
a481b3ea 1793 check_min_window_sizes ();
7ab12479 1794
265a9e55 1795 if (NILP (horflag))
7ab12479
JB
1796 {
1797 if (size < window_min_height
1798 || size + window_min_height > XFASTINT (o->height))
1799 args_out_of_range_3 (window, chsize, horflag);
265a9e55
JB
1800 if (NILP (o->parent)
1801 || NILP (XWINDOW (o->parent)->vchild))
7ab12479
JB
1802 {
1803 make_dummy_parent (window);
1804 new = o->parent;
1805 XWINDOW (new)->vchild = window;
1806 }
1807 }
1808 else
1809 {
1810 if (size < window_min_width
1811 || size + window_min_width > XFASTINT (o->width))
1812 args_out_of_range_3 (window, chsize, horflag);
265a9e55
JB
1813 if (NILP (o->parent)
1814 || NILP (XWINDOW (o->parent)->hchild))
7ab12479
JB
1815 {
1816 make_dummy_parent (window);
1817 new = o->parent;
1818 XWINDOW (new)->hchild = window;
1819 }
1820 }
1821
1822 /* Now we know that window's parent is a vertical combination
1823 if we are dividing vertically, or a horizontal combination
1824 if we are making side-by-side windows */
1825
1826 windows_or_buffers_changed++;
1827 new = make_window ();
1828 p = XWINDOW (new);
1829
44fa5b1e 1830 p->frame = o->frame;
7ab12479 1831 p->next = o->next;
265a9e55 1832 if (!NILP (p->next))
7ab12479
JB
1833 XWINDOW (p->next)->prev = new;
1834 p->prev = window;
1835 o->next = new;
1836 p->parent = o->parent;
1837 p->buffer = Qt;
1838
1839 Fset_window_buffer (new, o->buffer);
1840
44fa5b1e 1841 /* Apportion the available frame space among the two new windows */
7ab12479 1842
265a9e55 1843 if (!NILP (horflag))
7ab12479
JB
1844 {
1845 p->height = o->height;
1846 p->top = o->top;
1847 XFASTINT (p->width) = XFASTINT (o->width) - size;
1848 XFASTINT (o->width) = size;
1849 XFASTINT (p->left) = XFASTINT (o->left) + size;
1850 }
1851 else
1852 {
1853 p->left = o->left;
1854 p->width = o->width;
1855 XFASTINT (p->height) = XFASTINT (o->height) - size;
1856 XFASTINT (o->height) = size;
1857 XFASTINT (p->top) = XFASTINT (o->top) + size;
1858 }
1859
1860 return new;
1861}
1862\f
1863DEFUN ("enlarge-window", Fenlarge_window, Senlarge_window, 1, 2, "p",
1864 "Make current window ARG lines bigger.\n\
1865From program, optional second arg non-nil means grow sideways ARG columns.")
1866 (n, side)
1867 register Lisp_Object n, side;
1868{
1869 CHECK_NUMBER (n, 0);
265a9e55 1870 change_window_height (XINT (n), !NILP (side));
7ab12479
JB
1871 return Qnil;
1872}
1873
1874DEFUN ("shrink-window", Fshrink_window, Sshrink_window, 1, 2, "p",
1875 "Make current window ARG lines smaller.\n\
1876From program, optional second arg non-nil means shrink sideways ARG columns.")
1877 (n, side)
1878 register Lisp_Object n, side;
1879{
1880 CHECK_NUMBER (n, 0);
265a9e55 1881 change_window_height (-XINT (n), !NILP (side));
7ab12479
JB
1882 return Qnil;
1883}
1884
1885int
1886window_height (window)
1887 Lisp_Object window;
1888{
1889 register struct window *p = XWINDOW (window);
1890 return XFASTINT (p->height);
1891}
1892
1893int
1894window_width (window)
1895 Lisp_Object window;
1896{
1897 register struct window *p = XWINDOW (window);
1898 return XFASTINT (p->width);
1899}
1900
05c2896a
JB
1901#define MINSIZE(w) \
1902 (widthflag \
1903 ? window_min_width \
1904 : (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height))
7ab12479
JB
1905
1906#define CURBEG(w) \
05c2896a 1907 *(widthflag ? (int *) &(XWINDOW (w)->left) : (int *) &(XWINDOW (w)->top))
7ab12479
JB
1908
1909#define CURSIZE(w) \
05c2896a 1910 *(widthflag ? (int *) &(XWINDOW (w)->width) : (int *) &(XWINDOW (w)->height))
7ab12479
JB
1911
1912/* Unlike set_window_height, this function
1913 also changes the heights of the siblings so as to
1914 keep everything consistent. */
1915
1916change_window_height (delta, widthflag)
1917 register int delta;
1918 int widthflag;
1919{
1920 register Lisp_Object parent;
1921 Lisp_Object window;
1922 register struct window *p;
1923 int *sizep;
1924 int (*sizefun) () = widthflag ? window_width : window_height;
1925 register int (*setsizefun) () = (widthflag
1926 ? set_window_width
1927 : set_window_height);
1928
a481b3ea 1929 check_min_window_sizes ();
7ab12479
JB
1930
1931 window = selected_window;
1932 while (1)
1933 {
1934 p = XWINDOW (window);
1935 parent = p->parent;
265a9e55 1936 if (NILP (parent))
7ab12479
JB
1937 {
1938 if (widthflag)
1939 error ("No other window to side of this one");
1940 break;
1941 }
265a9e55
JB
1942 if (widthflag ? !NILP (XWINDOW (parent)->hchild)
1943 : !NILP (XWINDOW (parent)->vchild))
7ab12479
JB
1944 break;
1945 window = parent;
1946 }
1947
05c2896a 1948 sizep = &CURSIZE (window);
7ab12479 1949
05c2896a 1950 if (*sizep + delta < MINSIZE (window))
7ab12479
JB
1951 {
1952 Fdelete_window (window);
1953 return;
1954 }
1955
1956 {
1957 register int maxdelta;
7ab12479 1958
265a9e55
JB
1959 maxdelta = (!NILP (parent) ? (*sizefun) (parent) - *sizep
1960 : !NILP (p->next) ? (*sizefun) (p->next) - MINSIZE (p->next)
1961 : !NILP (p->prev) ? (*sizefun) (p->prev) - MINSIZE (p->prev)
44fa5b1e
JB
1962 /* This is a frame with only one window, a minibuffer-only
1963 or a minibufferless frame. */
d5783c40 1964 : (delta = 0));
7ab12479
JB
1965
1966 if (delta > maxdelta)
1967 /* This case traps trying to make the minibuffer
44fa5b1e
JB
1968 the full frame, or make the only window aside from the
1969 minibuffer the full frame. */
7ab12479 1970 delta = maxdelta;
d5783c40
JB
1971
1972 if (delta == 0)
1973 return;
7ab12479
JB
1974 }
1975
265a9e55 1976 if (!NILP (p->next) &&
7ab12479
JB
1977 (*sizefun) (p->next) - delta >= MINSIZE (p->next))
1978 {
1979 (*setsizefun) (p->next, (*sizefun) (p->next) - delta, 0);
1980 (*setsizefun) (window, *sizep + delta, 0);
05c2896a 1981 CURBEG (p->next) += delta;
7ab12479
JB
1982 /* This does not change size of p->next,
1983 but it propagates the new top edge to its children */
1984 (*setsizefun) (p->next, (*sizefun) (p->next), 0);
1985 }
265a9e55 1986 else if (!NILP (p->prev) &&
7ab12479
JB
1987 (*sizefun) (p->prev) - delta >= MINSIZE (p->prev))
1988 {
1989 (*setsizefun) (p->prev, (*sizefun) (p->prev) - delta, 0);
05c2896a 1990 CURBEG (window) -= delta;
7ab12479
JB
1991 (*setsizefun) (window, *sizep + delta, 0);
1992 }
1993 else
1994 {
1995 register int delta1;
1996 register int opht = (*sizefun) (parent);
1997
1998 /* If trying to grow this window to or beyond size of the parent,
1999 make delta1 so big that, on shrinking back down,
2000 all the siblings end up with less than one line and are deleted. */
2001 if (opht <= *sizep + delta)
2002 delta1 = opht * opht * 2;
2003 /* Otherwise, make delta1 just right so that if we add delta1
2004 lines to this window and to the parent, and then shrink
2005 the parent back to its original size, the new proportional
2006 size of this window will increase by delta. */
2007 else
2008 delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100);
2009
2010 /* Add delta1 lines or columns to this window, and to the parent,
2011 keeping things consistent while not affecting siblings. */
05c2896a 2012 CURSIZE (parent) = opht + delta1;
7ab12479
JB
2013 (*setsizefun) (window, *sizep + delta1, 0);
2014
2015 /* Squeeze out delta1 lines or columns from our parent,
2016 shriking this window and siblings proportionately.
2017 This brings parent back to correct size.
2018 Delta1 was calculated so this makes this window the desired size,
2019 taking it all out of the siblings. */
2020 (*setsizefun) (parent, opht, 0);
2021 }
2022
2023 XFASTINT (p->last_modified) = 0;
2024}
2025#undef MINSIZE
2026#undef CURBEG
2027#undef CURSIZE
2028
2029\f
2030/* Return number of lines of text (not counting mode line) in W. */
2031
2032int
2033window_internal_height (w)
2034 struct window *w;
2035{
2036 int ht = XFASTINT (w->height);
2037
2038 if (MINI_WINDOW_P (w))
2039 return ht;
2040
265a9e55
JB
2041 if (!NILP (w->parent) || !NILP (w->vchild) || !NILP (w->hchild)
2042 || !NILP (w->next) || !NILP (w->prev)
44fa5b1e 2043 || FRAME_WANTS_MODELINE_P (XFRAME (WINDOW_FRAME (w))))
7ab12479
JB
2044 return ht - 1;
2045
2046 return ht;
2047}
2048
535e0b8e
JB
2049
2050/* Return the number of columns in W.
a3c87d4e 2051 Don't count columns occupied by scroll bars or the vertical bar
535e0b8e
JB
2052 separating W from the sibling to its right. */
2053int
2054window_internal_width (w)
2055 struct window *w;
2056{
2057 FRAME_PTR f = XFRAME (WINDOW_FRAME (w));
2058 int left = XINT (w->left);
2059 int width = XINT (w->width);
2060
2061 /* If this window is flush against the right edge of the frame, its
2062 internal width is its full width. */
2063 if (left + width >= FRAME_WIDTH (f))
2064 return width;
2065
2066 /* If we are not flush right, then our rightmost columns are
2067 occupied by some sort of separator. */
2068
a3c87d4e
JB
2069 /* Scroll bars occupy a few columns. */
2070 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f))
2071 return width - VERTICAL_SCROLL_BAR_WIDTH;
535e0b8e
JB
2072
2073 /* The column of `|' characters separating side-by-side windows
2074 occupies one column only. */
2075 return width - 1;
2076}
2077
2078
7ab12479
JB
2079/* Scroll contents of window WINDOW up N lines. */
2080
2081void
f8026fd8 2082window_scroll (window, n, noerror)
7ab12479
JB
2083 Lisp_Object window;
2084 int n;
f8026fd8 2085 int noerror;
7ab12479
JB
2086{
2087 register struct window *w = XWINDOW (window);
2088 register int opoint = point;
2089 register int pos;
2090 register int ht = window_internal_height (w);
2091 register Lisp_Object tem;
2092 int lose;
2093 Lisp_Object bolp, nmoved;
2094
2095 XFASTINT (tem) = point;
2096 tem = Fpos_visible_in_window_p (tem, window);
2097
265a9e55 2098 if (NILP (tem))
7ab12479
JB
2099 {
2100 Fvertical_motion (make_number (- ht / 2));
2101 XFASTINT (tem) = point;
2102 Fset_marker (w->start, tem, w->buffer);
2103 w->force_start = Qt;
2104 }
2105
2106 SET_PT (marker_position (w->start));
2107 lose = n < 0 && point == BEGV;
2108 Fvertical_motion (make_number (n));
2109 pos = point;
2110 bolp = Fbolp ();
2111 SET_PT (opoint);
2112
2113 if (lose)
f8026fd8
JB
2114 {
2115 if (noerror)
2116 return;
2117 else
2118 Fsignal (Qbeginning_of_buffer, Qnil);
2119 }
7ab12479
JB
2120
2121 if (pos < ZV)
7ab12479
JB
2122 {
2123 set_marker_restricted (w->start, make_number (pos), w->buffer);
2124 w->start_at_line_beg = bolp;
2125 w->update_mode_line = Qt;
2126 XFASTINT (w->last_modified) = 0;
2127 if (pos > opoint)
2128 SET_PT (pos);
2129 if (n < 0)
2130 {
2131 SET_PT (pos);
2132 tem = Fvertical_motion (make_number (ht));
2133 if (point > opoint || XFASTINT (tem) < ht)
2134 SET_PT (opoint);
2135 else
2136 Fvertical_motion (make_number (-1));
2137 }
2138 }
2139 else
f8026fd8
JB
2140 {
2141 if (noerror)
2142 return;
2143 else
2144 Fsignal (Qend_of_buffer, Qnil);
2145 }
7ab12479
JB
2146}
2147\f
2148/* This is the guts of Fscroll_up and Fscroll_down. */
2149
2150static void
2151scroll_command (n, direction)
2152 register Lisp_Object n;
2153 int direction;
2154{
2155 register int defalt;
2156 int count = specpdl_ptr - specpdl;
2157
95605e15
JB
2158 /* If selected window's buffer isn't current, make it current for the moment.
2159 But don't screw up if window_scroll gets an error. */
7ab12479 2160 if (XBUFFER (XWINDOW (selected_window)->buffer) != current_buffer)
95605e15
JB
2161 {
2162 record_unwind_protect (save_excursion_restore, save_excursion_save ());
2163 Fset_buffer (XWINDOW (selected_window)->buffer);
2164 }
7ab12479
JB
2165
2166 defalt = (window_internal_height (XWINDOW (selected_window))
2167 - next_screen_context_lines);
2168 defalt = direction * (defalt < 1 ? 1 : defalt);
2169
265a9e55 2170 if (NILP (n))
f8026fd8 2171 window_scroll (selected_window, defalt, 0);
7ab12479 2172 else if (EQ (n, Qminus))
f8026fd8 2173 window_scroll (selected_window, - defalt, 0);
7ab12479
JB
2174 else
2175 {
2176 n = Fprefix_numeric_value (n);
f8026fd8 2177 window_scroll (selected_window, XINT (n) * direction, 0);
7ab12479 2178 }
95605e15
JB
2179
2180 unbind_to (count, Qnil);
7ab12479
JB
2181}
2182
2183DEFUN ("scroll-up", Fscroll_up, Sscroll_up, 0, 1, "P",
2184 "Scroll text of current window upward ARG lines; or near full screen if no ARG.\n\
2185A near full screen is `next-screen-context-lines' less than a full screen.\n\
2186When calling from a program, supply a number as argument or nil.")
2187 (n)
2188 Lisp_Object n;
2189{
2190 scroll_command (n, 1);
2191 return Qnil;
2192}
2193
2194DEFUN ("scroll-down", Fscroll_down, Sscroll_down, 0, 1, "P",
2195 "Scroll text of current window downward ARG lines; or near full screen if no ARG.\n\
2196A near full screen is `next-screen-context-lines' less than a full screen.\n\
2197When calling from a program, supply a number as argument or nil.")
2198 (n)
2199 Lisp_Object n;
2200{
2201 scroll_command (n, -1);
2202 return Qnil;
2203}
2204
2205DEFUN ("scroll-other-window", Fscroll_other_window, Sscroll_other_window, 0, 1, "P",
99e5add3 2206 "Scroll next window upward ARG lines; or near full screen if no ARG.\n\
7ab12479
JB
2207The next window is the one below the current one; or the one at the top\n\
2208if the current one is at the bottom.\n\
2209When calling from a program, supply a number as argument or nil.\n\
2210\n\
2211If in the minibuffer, `minibuf-scroll-window' if non-nil\n\
2212specifies the window to scroll.\n\
2213If `other-window-scroll-buffer' is non-nil, scroll the window\n\
2214showing that buffer, popping the buffer up if necessary.")
2215 (n)
2216 register Lisp_Object n;
2217{
2218 register Lisp_Object window;
2219 register int ht;
2220 register struct window *w;
2221 register int count = specpdl_ptr - specpdl;
2222
2223 if (MINI_WINDOW_P (XWINDOW (selected_window))
265a9e55 2224 && !NILP (Vminibuf_scroll_window))
7ab12479
JB
2225 window = Vminibuf_scroll_window;
2226 /* If buffer is specified, scroll that buffer. */
265a9e55 2227 else if (!NILP (Vother_window_scroll_buffer))
7ab12479
JB
2228 {
2229 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil);
265a9e55 2230 if (NILP (window))
7ab12479
JB
2231 window = Fdisplay_buffer (Vother_window_scroll_buffer, Qt);
2232 }
2233 else
dbc4e1c1
JB
2234 {
2235 /* Nothing specified; look for a neighboring window on the same
2236 frame. */
2237 window = Fnext_window (selected_window, Qnil, Qnil);
2238
2239 if (EQ (window, selected_window))
2240 /* That didn't get us anywhere; look for a window on another
2241 visible frame. */
2242 do
2243 window = Fnext_window (window, Qnil, Qt);
2244 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
2245 && ! EQ (window, selected_window));
2246 }
2247
605be8af 2248 CHECK_LIVE_WINDOW (window, 0);
7ab12479
JB
2249
2250 if (EQ (window, selected_window))
2251 error ("There is no other window");
2252
2253 w = XWINDOW (window);
2254 ht = window_internal_height (w);
2255
2256 /* Don't screw up if window_scroll gets an error. */
2257 record_unwind_protect (save_excursion_restore, save_excursion_save ());
2258
2259 Fset_buffer (w->buffer);
2260 SET_PT (marker_position (w->pointm));
2261
265a9e55 2262 if (NILP (n))
f8026fd8 2263 window_scroll (window, ht - next_screen_context_lines, 1);
7ab12479 2264 else if (EQ (n, Qminus))
f8026fd8 2265 window_scroll (window, next_screen_context_lines - ht, 1);
7ab12479
JB
2266 else
2267 {
2268 if (XTYPE (n) == Lisp_Cons)
2269 n = Fcar (n);
2270 CHECK_NUMBER (n, 0);
f8026fd8 2271 window_scroll (window, XINT (n), 1);
7ab12479
JB
2272 }
2273
2274 Fset_marker (w->pointm, make_number (point), Qnil);
f4e7b2c2 2275 unbind_to (count, Qnil);
7ab12479
JB
2276
2277 return Qnil;
2278}
2279\f
644b477c 2280DEFUN ("scroll-left", Fscroll_left, Sscroll_left, 0, 1, "P",
7ab12479
JB
2281 "Scroll selected window display ARG columns left.\n\
2282Default for ARG is window width minus 2.")
2283 (arg)
2284 register Lisp_Object arg;
2285{
2286
265a9e55 2287 if (NILP (arg))
b8baad40 2288 XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2;
7ab12479
JB
2289 else
2290 arg = Fprefix_numeric_value (arg);
2291
2292 return
2293 Fset_window_hscroll (selected_window,
2294 make_number (XINT (XWINDOW (selected_window)->hscroll)
2295 + XINT (arg)));
2296}
2297
644b477c 2298DEFUN ("scroll-right", Fscroll_right, Sscroll_right, 0, 1, "P",
7ab12479
JB
2299 "Scroll selected window display ARG columns right.\n\
2300Default for ARG is window width minus 2.")
2301 (arg)
2302 register Lisp_Object arg;
2303{
265a9e55 2304 if (NILP (arg))
b8baad40 2305 XFASTINT (arg) = window_internal_width (XWINDOW (selected_window)) - 2;
7ab12479
JB
2306 else
2307 arg = Fprefix_numeric_value (arg);
2308
2309 return
2310 Fset_window_hscroll (selected_window,
2311 make_number (XINT (XWINDOW (selected_window)->hscroll)
2312 - XINT (arg)));
2313}
2314
2315DEFUN ("recenter", Frecenter, Srecenter, 0, 1, "P",
44fa5b1e 2316 "Center point in window and redisplay frame. With ARG, put point on line ARG.\n\
7ab12479 2317The desired position of point is always relative to the current window.\n\
44fa5b1e
JB
2318Just C-u as prefix means put point in the center of the window.\n\
2319No arg (i.e., it is nil) erases the entire frame and then\n\
2320redraws with point in the center of the current window.")
7ab12479
JB
2321 (n)
2322 register Lisp_Object n;
2323{
2324 register struct window *w = XWINDOW (selected_window);
2325 register int ht = window_internal_height (w);
2326 register int opoint = point;
2327
265a9e55 2328 if (NILP (n))
7ab12479 2329 {
44fa5b1e 2330 extern int frame_garbaged;
7ab12479 2331
44fa5b1e 2332 SET_FRAME_GARBAGED (XFRAME (WINDOW_FRAME (w)));
7ab12479
JB
2333 XFASTINT (n) = ht / 2;
2334 }
2335 else if (XTYPE (n) == Lisp_Cons) /* Just C-u. */
2336 {
2337 XFASTINT (n) = ht / 2;
2338 }
2339 else
2340 {
2341 n = Fprefix_numeric_value (n);
2342 CHECK_NUMBER (n, 0);
2343 }
2344
2345 if (XINT (n) < 0)
2346 XSETINT (n, XINT (n) + ht);
2347
2348 XSETINT (n, - XINT (n));
2349
2350 Fvertical_motion (n);
2351 Fset_marker (w->start, make_number (point), w->buffer);
2352 w->start_at_line_beg = Fbolp ();
2353
2354 SET_PT (opoint);
2355 w->force_start = Qt;
2356
2357 return Qnil;
2358}
2359\f
2360DEFUN ("move-to-window-line", Fmove_to_window_line, Smove_to_window_line,
2361 1, 1, "P",
2362 "Position point relative to window.\n\
2363With no argument, position text at center of window.\n\
44fa5b1e 2364An argument specifies frame line; zero means top of window,\n\
7ab12479
JB
2365negative means relative to bottom of window.")
2366 (arg)
2367 register Lisp_Object arg;
2368{
2369 register struct window *w = XWINDOW (selected_window);
2370 register int height = window_internal_height (w);
2371 register int start;
2372
265a9e55 2373 if (NILP (arg))
7ab12479
JB
2374 XFASTINT (arg) = height / 2;
2375 else
2376 {
2377 arg = Fprefix_numeric_value (arg);
2378 if (XINT (arg) < 0)
2379 XSETINT (arg, XINT (arg) + height);
2380 }
2381
2382 start = marker_position (w->start);
2383 if (start < BEGV || start > ZV)
2384 {
2385 Fvertical_motion (make_number (- height / 2));
2386 Fset_marker (w->start, make_number (point), w->buffer);
2387 w->start_at_line_beg = Fbolp ();
2388 w->force_start = Qt;
2389 }
2390 else
2391 SET_PT (start);
2392
2393 return Fvertical_motion (arg);
2394}
2395\f
2396struct save_window_data
2397 {
2398 int size_from_Lisp_Vector_struct;
2399 struct Lisp_Vector *next_from_Lisp_Vector_struct;
44fa5b1e 2400 Lisp_Object frame_width, frame_height;
bdc727bf 2401 Lisp_Object selected_frame;
7ab12479
JB
2402 Lisp_Object current_window;
2403 Lisp_Object current_buffer;
2404 Lisp_Object minibuf_scroll_window;
2405 Lisp_Object root_window;
bdc727bf 2406 Lisp_Object focus_frame;
7ab12479
JB
2407 /* A vector, interpreted as a struct saved_window */
2408 Lisp_Object saved_windows;
2409 };
ff06df24
JB
2410
2411/* Arg to Fmake_vector */
2412#define SAVE_WINDOW_DATA_SIZE \
2413 ((sizeof (struct save_window_data) \
2414 - (sizeof (struct Lisp_Vector) \
2415 /* Don't count the contents member of the struct Lisp_Vector */ \
2416 - sizeof (Lisp_Object))) \
2417 / sizeof (Lisp_Object))
7ab12479
JB
2418
2419/* This is saved as a Lisp_Vector */
2420struct saved_window
2421 {
2422 /* these first two must agree with struct Lisp_Vector in lisp.h */
2423 int size_from_Lisp_Vector_struct;
2424 struct Lisp_Vector *next_from_Lisp_Vector_struct;
2425
2426 Lisp_Object window;
2427 Lisp_Object buffer, start, pointm, mark;
2428 Lisp_Object left, top, width, height, hscroll;
2429 Lisp_Object parent, prev;
2430 Lisp_Object start_at_line_beg;
2431 Lisp_Object display_table;
2432 };
2433#define SAVED_WINDOW_VECTOR_SIZE 14 /* Arg to Fmake_vector */
2434
2435#define SAVED_WINDOW_N(swv,n) \
2436 ((struct saved_window *) (XVECTOR ((swv)->contents[(n)])))
2437
2438DEFUN ("window-configuration-p", Fwindow_configuration_p, Swindow_configuration_p, 1, 1, 0,
2439 "T if OBJECT is a window-configration object.")
2440 (obj)
2441 Lisp_Object obj;
2442{
2443 if (XTYPE (obj) == Lisp_Window_Configuration)
2444 return Qt;
2445 return Qnil;
2446}
2447
2448
d5b2799e
RS
2449DEFUN ("set-window-configuration", Fset_window_configuration,
2450 Sset_window_configuration, 1, 1, 0,
7ab12479
JB
2451 "Set the configuration of windows and buffers as specified by CONFIGURATION.\n\
2452CONFIGURATION must be a value previously returned\n\
2453by `current-window-configuration' (which see).")
2f83aebe
JB
2454 (configuration)
2455 Lisp_Object configuration;
7ab12479 2456{
7ab12479
JB
2457 register struct save_window_data *data;
2458 struct Lisp_Vector *saved_windows;
7ab12479 2459 Lisp_Object new_current_buffer;
fd482be5 2460 Lisp_Object frame;
44fa5b1e 2461 FRAME_PTR f;
7ab12479 2462
2f83aebe 2463 while (XTYPE (configuration) != Lisp_Window_Configuration)
7ab12479 2464 {
2f83aebe
JB
2465 configuration = wrong_type_argument (intern ("window-configuration-p"),
2466 configuration);
7ab12479
JB
2467 }
2468
2f83aebe 2469 data = (struct save_window_data *) XVECTOR (configuration);
7ab12479
JB
2470 saved_windows = XVECTOR (data->saved_windows);
2471
7ab12479 2472 new_current_buffer = data->current_buffer;
265a9e55 2473 if (NILP (XBUFFER (new_current_buffer)->name))
7ab12479
JB
2474 new_current_buffer = Qnil;
2475
fd482be5
JB
2476 frame = XWINDOW (SAVED_WINDOW_N (saved_windows, 0)->window)->frame;
2477 f = XFRAME (frame);
9ace597f 2478
fd482be5
JB
2479 /* If f is a dead frame, don't bother rebuilding its window tree.
2480 However, there is other stuff we should still try to do below. */
2481 if (FRAME_LIVE_P (f))
7ab12479 2482 {
fd482be5
JB
2483 register struct window *w;
2484 register struct saved_window *p;
2485 int k;
2486
2487 /* If the frame has been resized since this window configuration was
2488 made, we change the frame to the size specified in the
2489 configuration, restore the configuration, and then resize it
2490 back. We keep track of the prevailing height in these variables. */
2491 int previous_frame_height = FRAME_HEIGHT (f);
2492 int previous_frame_width = FRAME_WIDTH (f);
2493
2494 if (XFASTINT (data->frame_height) != previous_frame_height
2495 || XFASTINT (data->frame_width) != previous_frame_width)
2496 change_frame_size (f, data->frame_height, data->frame_width, 0, 0);
2497
2498 windows_or_buffers_changed++;
2499
2500 /* Kludge Alert!
2501 Mark all windows now on frame as "deleted".
2502 Restoring the new configuration "undeletes" any that are in it.
2503
2504 Save their current buffers in their height fields, since we may
2505 need it later, if a buffer saved in the configuration is now
2506 dead. */
2507 delete_all_subwindows (XWINDOW (FRAME_ROOT_WINDOW (f)));
2508
2509 for (k = 0; k < saved_windows->size; k++)
2510 {
2511 p = SAVED_WINDOW_N (saved_windows, k);
2512 w = XWINDOW (p->window);
2513 w->next = Qnil;
7ab12479 2514
fd482be5
JB
2515 if (!NILP (p->parent))
2516 w->parent = SAVED_WINDOW_N (saved_windows,
2517 XFASTINT (p->parent))->window;
2518 else
2519 w->parent = Qnil;
7ab12479 2520
fd482be5 2521 if (!NILP (p->prev))
7ab12479 2522 {
fd482be5
JB
2523 w->prev = SAVED_WINDOW_N (saved_windows,
2524 XFASTINT (p->prev))->window;
2525 XWINDOW (w->prev)->next = p->window;
2526 }
2527 else
2528 {
2529 w->prev = Qnil;
2530 if (!NILP (w->parent))
2531 {
2532 if (EQ (p->width, XWINDOW (w->parent)->width))
2533 {
2534 XWINDOW (w->parent)->vchild = p->window;
2535 XWINDOW (w->parent)->hchild = Qnil;
2536 }
2537 else
2538 {
2539 XWINDOW (w->parent)->hchild = p->window;
2540 XWINDOW (w->parent)->vchild = Qnil;
2541 }
2542 }
2543 }
2544
2545 /* If we squirreled away the buffer in the window's height,
2546 restore it now. */
2547 if (XTYPE (w->height) == Lisp_Buffer)
2548 w->buffer = w->height;
2549 w->left = p->left;
2550 w->top = p->top;
2551 w->width = p->width;
2552 w->height = p->height;
2553 w->hscroll = p->hscroll;
2554 w->display_table = p->display_table;
2555 XFASTINT (w->last_modified) = 0;
2556
2557 /* Reinstall the saved buffer and pointers into it. */
2558 if (NILP (p->buffer))
2559 w->buffer = p->buffer;
2560 else
2561 {
2562 if (!NILP (XBUFFER (p->buffer)->name))
2563 /* If saved buffer is alive, install it. */
2564 {
2565 w->buffer = p->buffer;
2566 w->start_at_line_beg = p->start_at_line_beg;
2567 set_marker_restricted (w->start,
2568 Fmarker_position (p->start),
2569 w->buffer);
2570 set_marker_restricted (w->pointm,
2571 Fmarker_position (p->pointm),
2572 w->buffer);
2573 Fset_marker (XBUFFER (w->buffer)->mark,
2574 Fmarker_position (p->mark), w->buffer);
2575
2576 /* As documented in Fcurrent_window_configuration, don't
2577 save the location of point in the buffer which was current
2578 when the window configuration was recorded. */
2579 if (!EQ (p->buffer, new_current_buffer) &&
2580 XBUFFER (p->buffer) == current_buffer)
2581 Fgoto_char (w->pointm);
2582 }
52a68e98
RS
2583 else if (NILP (w->buffer) || NILP (XBUFFER (w->buffer)->name))
2584 /* Else unless window has a live buffer, get one. */
7ab12479 2585 {
fd482be5
JB
2586 w->buffer = Fcdr (Fcar (Vbuffer_alist));
2587 /* This will set the markers to beginning of visible
2588 range. */
2589 set_marker_restricted (w->start, make_number (0), w->buffer);
2590 set_marker_restricted (w->pointm, make_number (0),w->buffer);
2591 w->start_at_line_beg = Qt;
7ab12479
JB
2592 }
2593 else
fd482be5 2594 /* Keeping window's old buffer; make sure the markers
52a68e98 2595 are real. */
7ab12479 2596 {
fd482be5
JB
2597 /* Set window markers at start of visible range. */
2598 if (XMARKER (w->start)->buffer == 0)
2599 set_marker_restricted (w->start, make_number (0),
2600 w->buffer);
2601 if (XMARKER (w->pointm)->buffer == 0)
2602 set_marker_restricted (w->pointm,
2603 (make_number
2604 (BUF_PT (XBUFFER (w->buffer)))),
2605 w->buffer);
2606 w->start_at_line_beg = Qt;
7ab12479
JB
2607 }
2608 }
2609 }
9ace597f 2610
fd482be5
JB
2611 FRAME_ROOT_WINDOW (f) = data->root_window;
2612 Fselect_window (data->current_window);
7ab12479 2613
fd482be5 2614#ifdef MULTI_FRAME
db269683
JB
2615 if (NILP (data->focus_frame)
2616 || (XTYPE (data->focus_frame) == Lisp_Frame
2617 && FRAME_LIVE_P (XFRAME (data->focus_frame))))
2618 Fredirect_frame_focus (frame, data->focus_frame);
fd482be5 2619#endif
7ab12479 2620
fd482be5
JB
2621#if 0 /* I don't understand why this is needed, and it causes problems
2622 when the frame's old selected window has been deleted. */
2623#ifdef MULTI_FRAME
2624 if (f != selected_frame && ! FRAME_TERMCAP_P (f))
d5b2799e 2625 Fhandle_switch_frame (WINDOW_FRAME (XWINDOW (data->root_window)), Qnil);
fd482be5
JB
2626#endif
2627#endif
2628
2629 /* Set the screen height to the value it had before this function. */
2630 if (previous_frame_height != FRAME_HEIGHT (f)
2631 || previous_frame_width != FRAME_WIDTH (f))
2632 change_frame_size (f, previous_frame_height, previous_frame_width,
2633 0, 0);
2634 }
bdc727bf 2635
ad854249 2636#ifdef MULTI_FRAME
bdc727bf 2637 /* Fselect_window will have made f the selected frame, so we
d5b2799e 2638 reselect the proper frame here. Fhandle_switch_frame will change the
bdc727bf
JB
2639 selected window too, but that doesn't make the call to
2640 Fselect_window above totally superfluous; it still sets f's
2641 selected window. */
fd482be5 2642 if (FRAME_LIVE_P (XFRAME (data->selected_frame)))
d5b2799e 2643 Fhandle_switch_frame (data->selected_frame, Qnil);
ad854249 2644#endif
bdc727bf
JB
2645
2646 if (!NILP (new_current_buffer))
2647 Fset_buffer (new_current_buffer);
2648
7ab12479
JB
2649 Vminibuf_scroll_window = data->minibuf_scroll_window;
2650 return (Qnil);
2651}
2652
44fa5b1e 2653/* Mark all windows now on frame as deleted
7ab12479
JB
2654 by setting their buffers to nil. */
2655
fd482be5 2656void
7ab12479
JB
2657delete_all_subwindows (w)
2658 register struct window *w;
2659{
265a9e55 2660 if (!NILP (w->next))
7ab12479 2661 delete_all_subwindows (XWINDOW (w->next));
265a9e55 2662 if (!NILP (w->vchild))
7ab12479 2663 delete_all_subwindows (XWINDOW (w->vchild));
265a9e55 2664 if (!NILP (w->hchild))
7ab12479 2665 delete_all_subwindows (XWINDOW (w->hchild));
605be8af
JB
2666
2667 w->height = w->buffer; /* See Fset_window_configuration for excuse. */
2668
2669 /* We set all three of these fields to nil, to make sure that we can
2670 distinguish this dead window from any live window. Live leaf
2671 windows will have buffer set, and combination windows will have
2672 vchild or hchild set. */
2673 w->buffer = Qnil;
2674 w->vchild = Qnil;
2675 w->hchild = Qnil;
7ab12479
JB
2676}
2677\f
2678static int
2679count_windows (window)
2680 register struct window *window;
2681{
2682 register int count = 1;
265a9e55 2683 if (!NILP (window->next))
7ab12479 2684 count += count_windows (XWINDOW (window->next));
265a9e55 2685 if (!NILP (window->vchild))
7ab12479 2686 count += count_windows (XWINDOW (window->vchild));
265a9e55 2687 if (!NILP (window->hchild))
7ab12479
JB
2688 count += count_windows (XWINDOW (window->hchild));
2689 return count;
2690}
2691
2692static int
2693save_window_save (window, vector, i)
2694 Lisp_Object window;
2695 struct Lisp_Vector *vector;
2696 int i;
2697{
2698 register struct saved_window *p;
2699 register struct window *w;
2700 register Lisp_Object tem;
2701
265a9e55 2702 for (;!NILP (window); window = w->next)
7ab12479
JB
2703 {
2704 p = SAVED_WINDOW_N (vector, i);
2705 w = XWINDOW (window);
2706
2707 XFASTINT (w->temslot) = i++;
2708 p->window = window;
2709 p->buffer = w->buffer;
2710 p->left = w->left;
2711 p->top = w->top;
2712 p->width = w->width;
2713 p->height = w->height;
2714 p->hscroll = w->hscroll;
2715 p->display_table = w->display_table;
265a9e55 2716 if (!NILP (w->buffer))
7ab12479
JB
2717 {
2718 /* Save w's value of point in the window configuration.
2719 If w is the selected window, then get the value of point
2720 from the buffer; pointm is garbage in the selected window. */
2721 if (EQ (window, selected_window))
2722 {
2723 p->pointm = Fmake_marker ();
2724 Fset_marker (p->pointm, BUF_PT (XBUFFER (w->buffer)),
2725 w->buffer);
2726 }
2727 else
2728 p->pointm = Fcopy_marker (w->pointm);
2729
2730 p->start = Fcopy_marker (w->start);
2731 p->start_at_line_beg = w->start_at_line_beg;
2732
2733 tem = XBUFFER (w->buffer)->mark;
2734 p->mark = Fcopy_marker (tem);
2735 }
2736 else
2737 {
2738 p->pointm = Qnil;
2739 p->start = Qnil;
2740 p->mark = Qnil;
2741 p->start_at_line_beg = Qnil;
2742 }
2743
265a9e55 2744 if (NILP (w->parent))
7ab12479
JB
2745 p->parent = Qnil;
2746 else
2747 p->parent = XWINDOW (w->parent)->temslot;
2748
265a9e55 2749 if (NILP (w->prev))
7ab12479
JB
2750 p->prev = Qnil;
2751 else
2752 p->prev = XWINDOW (w->prev)->temslot;
2753
265a9e55 2754 if (!NILP (w->vchild))
7ab12479 2755 i = save_window_save (w->vchild, vector, i);
265a9e55 2756 if (!NILP (w->hchild))
7ab12479
JB
2757 i = save_window_save (w->hchild, vector, i);
2758 }
2759
2760 return i;
2761}
2762
2763DEFUN ("current-window-configuration",
43bad991 2764 Fcurrent_window_configuration, Scurrent_window_configuration, 0, 1, 0,
44fa5b1e
JB
2765 "Return an object representing the current window configuration of FRAME.\n\
2766If FRAME is nil or omitted, use the selected frame.\n\
7ab12479
JB
2767This describes the number of windows, their sizes and current buffers,\n\
2768and for each displayed buffer, where display starts, and the positions of\n\
2769point and mark. An exception is made for point in the current buffer:\n\
bdc727bf
JB
2770its value is -not- saved.\n\
2771This also records the currently selected frame, and FRAME's focus\n\
2772redirection (see `redirect-frame-focus').")
44fa5b1e
JB
2773 (frame)
2774 Lisp_Object frame;
7ab12479
JB
2775{
2776 register Lisp_Object tem;
2777 register int n_windows;
2778 register struct save_window_data *data;
2779 register int i;
44fa5b1e 2780 FRAME_PTR f;
43bad991 2781
44fa5b1e
JB
2782 if (NILP (frame))
2783 f = selected_frame;
43bad991
JB
2784 else
2785 {
44fa5b1e
JB
2786 CHECK_LIVE_FRAME (frame, 0);
2787 f = XFRAME (frame);
43bad991 2788 }
7ab12479 2789
44fa5b1e 2790 n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
7ab12479
JB
2791 data = (struct save_window_data *)
2792 XVECTOR (Fmake_vector (make_number (SAVE_WINDOW_DATA_SIZE),
2793 Qnil));
44fa5b1e
JB
2794 XFASTINT (data->frame_width) = FRAME_WIDTH (f);
2795 XFASTINT (data->frame_height) = FRAME_HEIGHT (f);
ad854249 2796#ifdef MULTI_FRAME
bdc727bf 2797 XSET (data->selected_frame, Lisp_Frame, selected_frame);
ad854249 2798#endif
44fa5b1e 2799 data->current_window = FRAME_SELECTED_WINDOW (f);
7ab12479
JB
2800 XSET (data->current_buffer, Lisp_Buffer, current_buffer);
2801 data->minibuf_scroll_window = Vminibuf_scroll_window;
44fa5b1e 2802 data->root_window = FRAME_ROOT_WINDOW (f);
bdc727bf 2803 data->focus_frame = FRAME_FOCUS_FRAME (f);
7ab12479
JB
2804 tem = Fmake_vector (make_number (n_windows), Qnil);
2805 data->saved_windows = tem;
2806 for (i = 0; i < n_windows; i++)
2807 XVECTOR (tem)->contents[i]
2808 = Fmake_vector (make_number (SAVED_WINDOW_VECTOR_SIZE), Qnil);
44fa5b1e 2809 save_window_save (FRAME_ROOT_WINDOW (f),
7ab12479
JB
2810 XVECTOR (tem), 0);
2811 XSET (tem, Lisp_Window_Configuration, data);
2812 return (tem);
2813}
2814
2815DEFUN ("save-window-excursion", Fsave_window_excursion, Ssave_window_excursion,
2816 0, UNEVALLED, 0,
2817 "Execute body, preserving window sizes and contents.\n\
2818Restores which buffer appears in which window, where display starts,\n\
2819as well as the current buffer.\n\
2820Does not restore the value of point in current buffer.")
2821 (args)
2822 Lisp_Object args;
2823{
2824 register Lisp_Object val;
2825 register int count = specpdl_ptr - specpdl;
2826
2827 record_unwind_protect (Fset_window_configuration,
43bad991 2828 Fcurrent_window_configuration (Qnil));
7ab12479
JB
2829 val = Fprogn (args);
2830 return unbind_to (count, val);
2831}
2832\f
2833init_window_once ()
2834{
44fa5b1e
JB
2835#ifdef MULTI_FRAME
2836 selected_frame = make_terminal_frame ();
2837 minibuf_window = selected_frame->minibuffer_window;
2838 selected_window = selected_frame->selected_window;
2839 last_nonminibuf_frame = selected_frame;
2840#else /* not MULTI_FRAME */
7ab12479
JB
2841 extern Lisp_Object get_minibuffer ();
2842
95605e15 2843 minibuf_window = make_window ();
4b206065 2844 FRAME_ROOT_WINDOW (selected_frame) = make_window ();
7ab12479 2845
44fa5b1e
JB
2846 XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->next = minibuf_window;
2847 XWINDOW (minibuf_window)->prev = FRAME_ROOT_WINDOW (selected_frame);
4b206065 2848 XWINDOW (minibuf_window)->mini_p = Qt;
7ab12479
JB
2849
2850 /* These values 9 and 10 are arbitrary,
2851 just so that there is "something there."
2852 Correct values are put in in init_xdisp */
2853
44fa5b1e 2854 XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->width) = 10;
7ab12479
JB
2855 XFASTINT (XWINDOW (minibuf_window)->width) = 10;
2856
44fa5b1e 2857 XFASTINT (XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->height) = 9;
7ab12479
JB
2858 XFASTINT (XWINDOW (minibuf_window)->top) = 9;
2859 XFASTINT (XWINDOW (minibuf_window)->height) = 1;
2860
2861 /* Prevent error in Fset_window_buffer. */
44fa5b1e 2862 XWINDOW (FRAME_ROOT_WINDOW (selected_frame))->buffer = Qt;
7ab12479
JB
2863 XWINDOW (minibuf_window)->buffer = Qt;
2864
2865 /* Now set them up for real. */
44fa5b1e 2866 Fset_window_buffer (FRAME_ROOT_WINDOW (selected_frame),
e5d77022 2867 Fcurrent_buffer ());
7ab12479
JB
2868 Fset_window_buffer (minibuf_window, get_minibuffer (0));
2869
44fa5b1e 2870 selected_window = FRAME_ROOT_WINDOW (selected_frame);
1d8d96fa
JB
2871 /* Make sure this window seems more recently used than
2872 a newly-created, never-selected window. Increment
2873 window_select_count so the first selection ever will get
2874 something newer than this. */
2875 XFASTINT (XWINDOW (selected_window)->use_time) = ++window_select_count;
44fa5b1e 2876#endif /* not MULTI_FRAME */
7ab12479
JB
2877}
2878
2879syms_of_window ()
2880{
2881 Qwindowp = intern ("windowp");
2882 staticpro (&Qwindowp);
2883
806b4d9b
JB
2884 Qwindow_live_p = intern ("window-live-p");
2885 staticpro (&Qwindow_live_p);
605be8af 2886
2f83aebe 2887#ifndef MULTI_FRAME
7ab12479
JB
2888 /* Make sure all windows get marked */
2889 staticpro (&minibuf_window);
2f83aebe 2890#endif
7ab12479
JB
2891
2892 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function,
2893 "Non-nil means call as function to display a help buffer.\n\
2894Used by `with-output-to-temp-buffer'.");
2895 Vtemp_buffer_show_function = Qnil;
2896
2897 DEFVAR_LISP ("display-buffer-function", &Vdisplay_buffer_function,
2898 "If non-nil, function to call to handle `display-buffer'.\n\
2899It will receive two args, the buffer and a flag which if non-nil means\n\
2900 that the currently selected window is not acceptable.\n\
2901Commands such as `switch-to-buffer-other-window' and `find-file-other-window'\n\
2902work using this function.");
2903 Vdisplay_buffer_function = Qnil;
2904
7ab12479
JB
2905 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuf_scroll_window,
2906 "Non-nil means it is the window that C-M-v in minibuffer should scroll.");
2907 Vminibuf_scroll_window = Qnil;
2908
2909 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer,
2910 "If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.");
2911 Vother_window_scroll_buffer = Qnil;
2912
44fa5b1e 2913 DEFVAR_BOOL ("pop-up-frames", &pop_up_frames,
700f75a4 2914 "*Non-nil means `display-buffer' should make a separate frame.");
44fa5b1e 2915 pop_up_frames = 0;
7ab12479 2916
44fa5b1e
JB
2917 DEFVAR_LISP ("pop-up-frame-function", &Vpop_up_frame_function,
2918 "*If non-nil, function to call to handle automatic new frame creation.\n\
2919It is called with no arguments and should return a newly created frame.\n\
7ab12479 2920\n\
44fa5b1e
JB
2921A typical value might be `(lambda () (new-frame pop-up-frame-alist))'\n\
2922where `pop-up-frame-alist' would hold the default frame parameters.");
2923 Vpop_up_frame_function = Qnil;
7ab12479
JB
2924
2925 DEFVAR_BOOL ("pop-up-windows", &pop_up_windows,
2926 "*Non-nil means display-buffer should make new windows.");
2927 pop_up_windows = 1;
2928
2929 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines,
2930 "*Number of lines of continuity when scrolling by screenfuls.");
2931 next_screen_context_lines = 2;
2932
2933 DEFVAR_INT ("split-height-threshold", &split_height_threshold,
2934 "*display-buffer would prefer to split the largest window if this large.\n\
2935If there is only one window, it is split regardless of this value.");
2936 split_height_threshold = 500;
2937
2938 DEFVAR_INT ("window-min-height", &window_min_height,
2939 "*Delete any window less than this tall (including its mode line).");
2940 window_min_height = 4;
2941
2942 DEFVAR_INT ("window-min-width", &window_min_width,
2943 "*Delete any window less than this wide.");
2944 window_min_width = 10;
2945
2946 defsubr (&Sselected_window);
2947 defsubr (&Sminibuffer_window);
2948 defsubr (&Swindow_minibuffer_p);
2949 defsubr (&Swindowp);
806b4d9b 2950 defsubr (&Swindow_live_p);
7ab12479
JB
2951 defsubr (&Spos_visible_in_window_p);
2952 defsubr (&Swindow_buffer);
2953 defsubr (&Swindow_height);
2954 defsubr (&Swindow_width);
2955 defsubr (&Swindow_hscroll);
2956 defsubr (&Sset_window_hscroll);
2957 defsubr (&Swindow_edges);
d5783c40
JB
2958 defsubr (&Scoordinates_in_window_p);
2959 defsubr (&Swindow_at);
7ab12479
JB
2960 defsubr (&Swindow_point);
2961 defsubr (&Swindow_start);
2962 defsubr (&Swindow_end);
2963 defsubr (&Sset_window_point);
2964 defsubr (&Sset_window_start);
2965 defsubr (&Swindow_dedicated_p);
d207b766 2966 defsubr (&Sset_window_dedicated_p);
7ab12479
JB
2967 defsubr (&Swindow_display_table);
2968 defsubr (&Sset_window_display_table);
2969 defsubr (&Snext_window);
2970 defsubr (&Sprevious_window);
2971 defsubr (&Sother_window);
2972 defsubr (&Sget_lru_window);
2973 defsubr (&Sget_largest_window);
2974 defsubr (&Sget_buffer_window);
2975 defsubr (&Sdelete_other_windows);
2976 defsubr (&Sdelete_windows_on);
2977 defsubr (&Sreplace_buffer_in_windows);
2978 defsubr (&Sdelete_window);
2979 defsubr (&Sset_window_buffer);
2980 defsubr (&Sselect_window);
2981 defsubr (&Sdisplay_buffer);
2982 defsubr (&Ssplit_window);
2983 defsubr (&Senlarge_window);
2984 defsubr (&Sshrink_window);
2985 defsubr (&Sscroll_up);
2986 defsubr (&Sscroll_down);
2987 defsubr (&Sscroll_left);
2988 defsubr (&Sscroll_right);
2989 defsubr (&Sscroll_other_window);
2990 defsubr (&Srecenter);
2991 defsubr (&Smove_to_window_line);
2992 defsubr (&Swindow_configuration_p);
2993 defsubr (&Sset_window_configuration);
2994 defsubr (&Scurrent_window_configuration);
2995 defsubr (&Ssave_window_excursion);
2996}
2997
2998keys_of_window ()
2999{
3000 initial_define_key (control_x_map, '1', "delete-other-windows");
3001 initial_define_key (control_x_map, '2', "split-window");
3002 initial_define_key (control_x_map, '0', "delete-window");
3003 initial_define_key (control_x_map, 'o', "other-window");
3004 initial_define_key (control_x_map, '^', "enlarge-window");
3005 initial_define_key (control_x_map, '<', "scroll-left");
3006 initial_define_key (control_x_map, '>', "scroll-right");
3007
3008 initial_define_key (global_map, Ctl ('V'), "scroll-up");
3009 initial_define_key (meta_map, Ctl ('V'), "scroll-other-window");
3010 initial_define_key (meta_map, 'v', "scroll-down");
3011
3012 initial_define_key (global_map, Ctl('L'), "recenter");
3013 initial_define_key (meta_map, 'r', "move-to-window-line");
3014}