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