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