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