0
|
1 /* Window creation, deletion and examination for XEmacs.
|
|
2 Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
4 Copyright (C) 1995, 1996 Ben Wing.
|
|
5 Copyright (C) 1996 Chuck Thompson.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: FSF 19.30. */
|
|
25 /* Beginning to diverge significantly. */
|
|
26
|
|
27 /* This file has been Mule-ized. */
|
|
28
|
|
29 #include <config.h>
|
|
30 #include "lisp.h"
|
|
31
|
|
32 #include "buffer.h"
|
|
33 #include "faces.h"
|
|
34 #include "frame.h"
|
|
35 #include "objects.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "redisplay.h"
|
|
38 #include "window.h"
|
|
39 #include "commands.h"
|
|
40
|
272
|
41 Lisp_Object Qwindowp, Qwindow_live_p, Qwindow_configurationp;
|
|
42 Lisp_Object Qscroll_up, Qscroll_down, Qdisplay_buffer;
|
0
|
43
|
|
44 #ifdef MEMORY_USAGE_STATS
|
272
|
45 Lisp_Object Qface_cache, Qglyph_cache, Qline_start_cache, Qother_redisplay;
|
0
|
46 #ifdef HAVE_SCROLLBARS
|
|
47 Lisp_Object Qscrollbar_instances;
|
|
48 #endif
|
|
49 #endif
|
|
50
|
272
|
51 EXFUN (Fnext_window, 4);
|
|
52
|
0
|
53 static int window_pixel_width_to_char_width (struct window *w,
|
|
54 int pixel_width,
|
|
55 int include_margins_p);
|
|
56 static int window_char_width_to_pixel_width (struct window *w,
|
|
57 int char_width,
|
|
58 int include_margins_p);
|
|
59 static int window_pixel_height_to_char_height (struct window *w,
|
|
60 int pixel_height,
|
|
61 int include_gutters_p);
|
|
62 static int window_char_height_to_pixel_height (struct window *w,
|
|
63 int char_height,
|
|
64 int include_gutters_p);
|
263
|
65 static void change_window_height (struct window *w, int delta, int widthflag,
|
|
66 int inpixels);
|
0
|
67
|
|
68 /* Thickness of shadow border around 3d modelines. */
|
|
69 Lisp_Object Vmodeline_shadow_thickness;
|
|
70
|
284
|
71 /* Whether vertical dividers are draggable and displayed */
|
|
72 Lisp_Object Vvertical_divider_draggable_p;
|
|
73
|
0
|
74 /* Whether a modeline should be displayed. */
|
|
75 Lisp_Object Vhas_modeline_p;
|
|
76
|
284
|
77 /* Thickness of shadow border around vertical dividers. */
|
|
78 Lisp_Object Vvertical_divider_shadow_thickness;
|
|
79
|
|
80 /* Divider surface width (not counting 3-d borders) */
|
|
81 Lisp_Object Vvertical_divider_line_width;
|
|
82
|
|
83 /* Spacing between outer egde of divider border and window edge */
|
|
84 Lisp_Object Vvertical_divider_spacing;
|
|
85
|
0
|
86 /* Scroll if point lands on the bottom line and that line is partially
|
|
87 clipped. */
|
|
88 int scroll_on_clipped_lines;
|
|
89
|
|
90 /* The minibuffer window of the selected frame.
|
|
91 Note that you cannot test for minibufferness of an arbitrary window
|
|
92 by comparing against this; but you can test for minibufferness of
|
|
93 the selected window. */
|
|
94 Lisp_Object minibuf_window;
|
|
95
|
|
96 /* Non-nil means it is the window for C-M-v to scroll
|
|
97 when the minibuffer is selected. */
|
274
|
98 Lisp_Object Vminibuffer_scroll_window;
|
0
|
99
|
|
100 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
|
|
101 Lisp_Object Vother_window_scroll_buffer;
|
|
102
|
102
|
103 /* Non-nil means it's the function to call to display temp buffers. */
|
0
|
104 Lisp_Object Vtemp_buffer_show_function;
|
|
105
|
|
106 Lisp_Object Vtemp_buffer_show_hook;
|
|
107
|
|
108 /* If a window gets smaller than either of these, it is removed. */
|
|
109 int window_min_height;
|
|
110 int window_min_width;
|
|
111
|
|
112 /* Hook run at end of temp_output_buffer_show. */
|
|
113 Lisp_Object Qtemp_buffer_show_hook;
|
|
114
|
|
115 /* Number of lines of continuity in scrolling by screenfuls. */
|
|
116 int next_screen_context_lines;
|
|
117
|
|
118 /* List of freed window configurations with 1 - 10 windows. */
|
|
119 Lisp_Object Vwindow_configuration_free_list[10];
|
|
120
|
|
121 #define SET_LAST_MODIFIED(w, cache_too) \
|
|
122 do { \
|
|
123 (w)->last_modified[CURRENT_DISP] = Qzero; \
|
|
124 (w)->last_modified[DESIRED_DISP] = Qzero; \
|
|
125 (w)->last_modified[CMOTION_DISP] = Qzero; \
|
|
126 if (cache_too) \
|
|
127 (w)->line_cache_last_updated = Qzero; \
|
|
128 } while (0)
|
|
129
|
|
130 #define SET_LAST_FACECHANGE(w) \
|
|
131 do { \
|
|
132 (w)->last_facechange[CURRENT_DISP] = Qzero; \
|
|
133 (w)->last_facechange[DESIRED_DISP] = Qzero; \
|
|
134 (w)->last_facechange[CMOTION_DISP] = Qzero; \
|
|
135 } while (0)
|
|
136
|
|
137
|
102
|
138 #define MARK_DISP_VARIABLE(field) \
|
|
139 ((markobj) (window->field[CURRENT_DISP])); \
|
|
140 ((markobj) (window->field[DESIRED_DISP])); \
|
0
|
141 ((markobj) (window->field[CMOTION_DISP]));
|
|
142
|
|
143 static Lisp_Object
|
|
144 mark_window (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
145 {
|
|
146 struct window *window = XWINDOW (obj);
|
|
147 ((markobj) (window->frame));
|
|
148 ((markobj) (window->mini_p));
|
|
149 ((markobj) (window->next));
|
|
150 ((markobj) (window->prev));
|
|
151 ((markobj) (window->hchild));
|
|
152 ((markobj) (window->vchild));
|
|
153 ((markobj) (window->parent));
|
|
154 ((markobj) (window->buffer));
|
|
155 MARK_DISP_VARIABLE (start);
|
|
156 MARK_DISP_VARIABLE (pointm);
|
|
157 ((markobj) (window->sb_point)); /* #### move to scrollbar.c? */
|
|
158 ((markobj) (window->use_time));
|
|
159 MARK_DISP_VARIABLE (last_modified);
|
|
160 MARK_DISP_VARIABLE (last_point);
|
|
161 MARK_DISP_VARIABLE (last_start);
|
|
162 MARK_DISP_VARIABLE (last_facechange);
|
|
163 ((markobj) (window->line_cache_last_updated));
|
|
164 ((markobj) (window->redisplay_end_trigger));
|
|
165 mark_face_cachels (window->face_cachels, markobj);
|
|
166 mark_glyph_cachels (window->glyph_cachels, markobj);
|
284
|
167
|
|
168 #define WINDOW_SLOT(slot, compare) ((markobj) (window->slot))
|
|
169 #include "winslots.h"
|
|
170
|
173
|
171 return Qnil;
|
0
|
172 }
|
|
173
|
|
174 static void
|
|
175 print_window (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
176 {
|
|
177 char buf[200];
|
|
178
|
|
179 if (print_readably)
|
|
180 error ("printing unreadable object #<window 0x%x>",
|
|
181 XWINDOW (obj)->header.uid);
|
185
|
182
|
0
|
183 write_c_string ("#<window", printcharfun);
|
|
184 if (!NILP (XWINDOW (obj)->buffer))
|
|
185 {
|
|
186 Lisp_Object name = XBUFFER (XWINDOW (obj)->buffer)->name;
|
|
187 write_c_string (" on ", printcharfun);
|
|
188 print_internal (name, printcharfun, 1);
|
|
189 }
|
|
190 sprintf (buf, " 0x%x>", XWINDOW (obj)->header.uid);
|
|
191 write_c_string (buf, printcharfun);
|
|
192 }
|
|
193
|
|
194 static void
|
|
195 finalize_window (void *header, int for_disksave)
|
|
196 {
|
|
197 struct window *w = (struct window *) header;
|
|
198
|
|
199 if (w->line_start_cache)
|
|
200 {
|
|
201 Dynarr_free (w->line_start_cache);
|
|
202 w->line_start_cache = 0;
|
|
203 }
|
|
204
|
|
205 if (w->face_cachels)
|
|
206 {
|
|
207 int i;
|
|
208
|
|
209 for (i = 0; i < Dynarr_length (w->face_cachels); i++)
|
|
210 {
|
|
211 struct face_cachel *cachel = Dynarr_atp (w->face_cachels, i);
|
|
212 if (cachel->merged_faces)
|
|
213 {
|
|
214 Dynarr_free (cachel->merged_faces);
|
|
215 cachel->merged_faces = 0;
|
|
216 }
|
|
217 }
|
|
218 Dynarr_free (w->face_cachels);
|
|
219 w->face_cachels = 0;
|
|
220 }
|
|
221
|
|
222 if (w->glyph_cachels)
|
|
223 {
|
|
224 Dynarr_free (w->glyph_cachels);
|
|
225 w->glyph_cachels = 0;
|
|
226 }
|
|
227 }
|
|
228
|
272
|
229 DEFINE_LRECORD_IMPLEMENTATION ("window", window,
|
|
230 mark_window, print_window, finalize_window,
|
|
231 0, 0, struct window);
|
|
232
|
|
233
|
0
|
234 #define INIT_DISP_VARIABLE(field, initialization) \
|
|
235 p->field[CURRENT_DISP] = initialization; \
|
|
236 p->field[DESIRED_DISP] = initialization; \
|
|
237 p->field[CMOTION_DISP] = initialization;
|
|
238
|
|
239 /* We have an implicit assertion that the first two elements (default
|
|
240 and modeline faces) are always present in the face_element_cache.
|
|
241 Normally redisplay ensures this. However, it is possible for a
|
|
242 window to get created and functions which reference these values
|
|
243 called before redisplay works with the window for the first time.
|
|
244 All callers of allocate_window should therefore call
|
|
245 reset_face_cachels on the created window. We can't do it
|
|
246 here because the window must have its frame pointer set or
|
|
247 reset_face_cachels will fail. */
|
|
248 Lisp_Object
|
|
249 allocate_window (void)
|
|
250 {
|
272
|
251 Lisp_Object val;
|
185
|
252 struct window *p = alloc_lcrecord_type (struct window, lrecord_window);
|
0
|
253
|
|
254 zero_lcrecord (p);
|
|
255 XSETWINDOW (val, p);
|
|
256
|
|
257 p->dead = 0;
|
|
258 p->frame = Qnil;
|
|
259 p->mini_p = Qnil;
|
|
260 p->next = Qnil;
|
|
261 p->prev = Qnil;
|
185
|
262 p->hchild = Qnil;
|
|
263 p->vchild = Qnil;
|
0
|
264 p->parent = Qnil;
|
|
265 p->buffer = Qnil;
|
|
266 INIT_DISP_VARIABLE (start, Fmake_marker ());
|
|
267 INIT_DISP_VARIABLE (pointm, Fmake_marker ());
|
|
268 p->sb_point = Fmake_marker ();
|
|
269 p->use_time = Qzero;
|
|
270 INIT_DISP_VARIABLE (last_modified, Qzero);
|
|
271 INIT_DISP_VARIABLE (last_point, Fmake_marker ());
|
|
272 INIT_DISP_VARIABLE (last_start, Fmake_marker ());
|
|
273 INIT_DISP_VARIABLE (last_facechange, Qzero);
|
185
|
274 p->face_cachels = Dynarr_new (face_cachel);
|
|
275 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
|
276 p->line_start_cache = Dynarr_new (line_start_cache);
|
0
|
277 p->line_cache_last_updated = Qzero;
|
|
278 INIT_DISP_VARIABLE (last_point_x, 0);
|
|
279 INIT_DISP_VARIABLE (last_point_y, 0);
|
|
280 INIT_DISP_VARIABLE (window_end_pos, 0);
|
|
281 p->redisplay_end_trigger = Qnil;
|
284
|
282
|
|
283 #define WINDOW_SLOT(slot, compare) p->slot = Qnil
|
|
284 #include "winslots.h"
|
|
285
|
0
|
286 p->windows_changed = 1;
|
|
287 p->shadow_thickness_changed = 1;
|
|
288
|
173
|
289 return val;
|
0
|
290 }
|
|
291 #undef INIT_DISP_VARIABLE
|
|
292
|
|
293 /*
|
|
294 * The redisplay structures used to be stored with each window. While
|
|
295 * they are logically something associated with frames they can't be
|
|
296 * stored there with a redisplay which handles variable height lines.
|
|
297 * Lines in horizontally split windows might not line up. So they get
|
|
298 * stored with the windows.
|
|
299 *
|
|
300 * The problem with this is window configurations. When restoring a
|
|
301 * window configuration it now becomes problematic to do an
|
|
302 * incremental redisplay. The solution is to store the redisplay
|
|
303 * structures with the frame as they should be but laid out in the
|
|
304 * same manner as the window structure. Thus is born the window
|
|
305 * mirror.
|
|
306 *
|
|
307 * It also becomes a convenient place to stick scrollbar instances
|
|
308 * since they extrapolate out to having the same problem described for
|
|
309 * the display structures.
|
|
310 */
|
|
311
|
102
|
312 /* Create a new window mirror structure and associated redisplay
|
0
|
313 structs. */
|
|
314 static struct window_mirror *
|
|
315 new_window_mirror (struct frame *f)
|
|
316 {
|
185
|
317 struct window_mirror *t = xnew_and_zero (struct window_mirror);
|
0
|
318
|
|
319 t->frame = f;
|
|
320
|
185
|
321 t->current_display_lines = Dynarr_new (display_line);
|
|
322 t->desired_display_lines = Dynarr_new (display_line);
|
0
|
323 t->buffer = NULL;
|
|
324
|
|
325 #ifdef HAVE_SCROLLBARS
|
|
326 t->scrollbar_vertical_instance = NULL;
|
|
327 t->scrollbar_horizontal_instance = NULL;
|
|
328 #endif
|
|
329
|
|
330 return t;
|
|
331 }
|
|
332
|
|
333 /* Synchronize the mirror structure with a given window structure.
|
|
334 This is normally called from update_frame_window_mirror with a
|
|
335 starting window of f->root_window. */
|
|
336 static struct window_mirror *
|
|
337 update_mirror_internal (Lisp_Object win, struct window_mirror *mir)
|
|
338 {
|
|
339 if (NILP (win))
|
|
340 {
|
|
341 if (mir)
|
|
342 {
|
|
343 free_window_mirror (mir);
|
272
|
344 mir = NULL;
|
0
|
345 }
|
|
346 return mir;
|
|
347 }
|
|
348 else
|
|
349 if (!mir)
|
|
350 mir = new_window_mirror (XFRAME (XWINDOW (win)->frame));
|
|
351
|
102
|
352 mir->next = update_mirror_internal (XWINDOW (win)->next, mir->next);
|
0
|
353 mir->hchild = update_mirror_internal (XWINDOW (win)->hchild, mir->hchild);
|
|
354 mir->vchild = update_mirror_internal (XWINDOW (win)->vchild, mir->vchild);
|
|
355
|
|
356 /*
|
|
357 * If the redisplay structs are not empty and the mirror has
|
|
358 * children, then this mirror structure was formerly being used for
|
|
359 * display but is no longer. Reset its current display structs so
|
|
360 * that redisplay doesn't accidentally think they are accurate if it
|
|
361 * is later used for display purposes once again. Also, mark the
|
|
362 * scrollbar instance as not active.
|
|
363 */
|
|
364 if (mir->vchild || mir->hchild)
|
|
365 {
|
|
366 /* The redisplay structures are big. Leaving them around in
|
|
367 non-leaf windows can add up to a lot of wasted space. So
|
|
368 don't do it. */
|
|
369 free_display_structs (mir);
|
185
|
370 mir->current_display_lines = Dynarr_new (display_line);
|
|
371 mir->desired_display_lines = Dynarr_new (display_line);
|
0
|
372
|
|
373 #ifdef HAVE_SCROLLBARS
|
|
374 update_window_scrollbars (XWINDOW (win), mir, 0, 0);
|
|
375 #endif
|
|
376 mir->buffer = NULL;
|
|
377 }
|
|
378
|
|
379 return mir;
|
|
380 }
|
|
381
|
|
382 /* Given a window mirror, determine which real window it contains the
|
|
383 redisplay structures for. */
|
|
384 static Lisp_Object
|
|
385 real_window_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
386 struct window_mirror *mir)
|
|
387 {
|
|
388 Lisp_Object retval;
|
|
389
|
|
390 for (; !NILP (win) && rmir ; win = XWINDOW (win)->next, rmir = rmir->next)
|
|
391 {
|
|
392 if (mir == rmir)
|
|
393 return win;
|
|
394 if (!NILP (XWINDOW (win)->vchild))
|
|
395 {
|
|
396 retval = real_window_internal (XWINDOW (win)->vchild, rmir->vchild,
|
|
397 mir);
|
|
398 if (!NILP (retval))
|
|
399 return retval;
|
|
400 }
|
|
401 if (!NILP (XWINDOW (win)->hchild))
|
|
402 {
|
|
403 retval = real_window_internal (XWINDOW (win)->hchild, rmir->hchild,
|
|
404 mir);
|
|
405 if (!NILP (retval))
|
|
406 return retval;
|
|
407 }
|
|
408 }
|
|
409
|
|
410 return Qnil;
|
|
411 }
|
|
412
|
|
413 /* Given a real window, find the mirror structure which contains its
|
|
414 redisplay structures. */
|
|
415 static struct window_mirror *
|
|
416 find_window_mirror_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
417 struct window *w)
|
|
418 {
|
|
419 for (; !NILP (win); win = XWINDOW (win)->next, rmir = rmir->next)
|
|
420 {
|
|
421 if (w == XWINDOW (win))
|
|
422 return rmir;
|
272
|
423
|
|
424 if (!NILP (XWINDOW (win)->vchild))
|
|
425 {
|
|
426 struct window_mirror *retval =
|
|
427 find_window_mirror_internal (XWINDOW (win)->vchild,
|
|
428 rmir->vchild, w);
|
|
429 if (retval) return retval;
|
|
430 }
|
|
431
|
|
432 if (!NILP (XWINDOW (win)->hchild))
|
|
433 {
|
|
434 struct window_mirror *retval =
|
|
435 find_window_mirror_internal (XWINDOW (win)->hchild,
|
|
436 rmir->hchild, w);
|
|
437 if (retval) return retval;
|
|
438 }
|
0
|
439 }
|
|
440
|
|
441 return 0;
|
|
442 }
|
|
443
|
|
444 /* Update the mirror structure for the given frame. */
|
|
445 void
|
|
446 update_frame_window_mirror (struct frame *f)
|
|
447 {
|
|
448 f->root_mirror = update_mirror_internal (f->root_window, f->root_mirror);
|
|
449 f->mirror_dirty = 0;
|
|
450 }
|
|
451
|
|
452 /* Free a given mirror structure along with all of its children as
|
|
453 well as their associated display structures. */
|
|
454 void
|
|
455 free_window_mirror (struct window_mirror *mir)
|
|
456 {
|
|
457 while (mir)
|
|
458 {
|
272
|
459 struct window_mirror *prev = mir;
|
0
|
460 if (mir->hchild) free_window_mirror (mir->hchild);
|
|
461 if (mir->vchild) free_window_mirror (mir->vchild);
|
|
462 #ifdef HAVE_SCROLLBARS
|
|
463 release_window_mirror_scrollbars (mir);
|
|
464 #endif
|
|
465 free_display_structs (mir);
|
|
466 mir = mir->next;
|
272
|
467 xfree (prev);
|
0
|
468 }
|
|
469 }
|
|
470
|
|
471 /* Given a mirror structure, return the window it mirrors. Calls
|
|
472 real_window_internal to do most of the work. */
|
|
473 Lisp_Object
|
|
474 real_window (struct window_mirror *mir, int no_abort)
|
|
475 {
|
272
|
476 Lisp_Object retval = real_window_internal (mir->frame->root_window,
|
|
477 mir->frame->root_mirror, mir);
|
0
|
478 if (NILP (retval) && !no_abort)
|
|
479 abort ();
|
|
480
|
|
481 return retval;
|
|
482 }
|
|
483
|
|
484 /* Given a real window, return its mirror structure. Calls
|
|
485 find_window_mirror_internal to do all of the work. */
|
|
486 struct window_mirror *
|
|
487 find_window_mirror (struct window *w)
|
|
488 {
|
|
489 struct frame *f = XFRAME (w->frame);
|
|
490 if (f->mirror_dirty)
|
|
491 update_frame_window_mirror (f);
|
|
492 return find_window_mirror_internal (f->root_window, f->root_mirror, w);
|
|
493 }
|
|
494
|
|
495 /*****************************************************************************
|
|
496 find_window_by_pixel_pos
|
|
497
|
|
498 Given a pixel position relative to a frame, find the window at that
|
|
499 position.
|
|
500 ****************************************************************************/
|
|
501 struct window *
|
272
|
502 find_window_by_pixel_pos (int pix_x, int pix_y, Lisp_Object win)
|
0
|
503 {
|
|
504 if (NILP (win))
|
|
505 return 0;
|
|
506
|
|
507 for (; !NILP (win); win = XWINDOW (win)->next)
|
|
508 {
|
272
|
509 struct window *w;
|
|
510
|
|
511 if (!NILP (XWINDOW (win)->vchild))
|
|
512 {
|
|
513 w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->vchild);
|
|
514 if (w) return w;
|
|
515 }
|
|
516 if (!NILP (XWINDOW (win)->hchild))
|
|
517 {
|
|
518 w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->hchild);
|
|
519 if (w) return w;
|
|
520 }
|
0
|
521 w = XWINDOW (win);
|
|
522 if (pix_x >= WINDOW_LEFT (w)
|
|
523 && pix_x <= WINDOW_RIGHT (w)
|
|
524 && pix_y >= WINDOW_TOP (w)
|
|
525 && pix_y <= WINDOW_BOTTOM (w))
|
|
526 return w;
|
|
527 }
|
272
|
528 return NULL;
|
0
|
529 }
|
|
530
|
|
531 /* Return a pointer to the display structures for the given window. */
|
|
532 display_line_dynarr *
|
|
533 window_display_lines (struct window *w, int which)
|
|
534 {
|
|
535 struct window_mirror *t;
|
|
536
|
|
537 if (XFRAME (w->frame)->mirror_dirty)
|
|
538 update_frame_window_mirror (XFRAME (w->frame));
|
|
539 t = find_window_mirror (w);
|
|
540 if (!t)
|
|
541 abort ();
|
|
542
|
|
543 if (which == CURRENT_DISP)
|
|
544 return t->current_display_lines;
|
|
545 else if (which == DESIRED_DISP)
|
|
546 return t->desired_display_lines;
|
|
547 else if (which == CMOTION_DISP)
|
|
548 /* The CMOTION_DISP display lines are global. */
|
|
549 return cmotion_display_lines;
|
|
550 else
|
|
551 abort ();
|
|
552
|
|
553 return 0; /* shut up compiler */
|
|
554 }
|
|
555
|
|
556 struct buffer *
|
|
557 window_display_buffer (struct window *w)
|
|
558 {
|
|
559 struct window_mirror *t;
|
|
560
|
|
561 if (XFRAME (w->frame)->mirror_dirty)
|
|
562 update_frame_window_mirror (XFRAME (w->frame));
|
|
563 t = find_window_mirror (w);
|
|
564 if (!t)
|
|
565 abort ();
|
|
566
|
|
567 return t->buffer;
|
|
568 }
|
|
569
|
|
570 void
|
|
571 set_window_display_buffer (struct window *w, struct buffer *b)
|
|
572 {
|
|
573 struct window_mirror *t;
|
|
574
|
|
575 if (XFRAME (w->frame)->mirror_dirty)
|
|
576 update_frame_window_mirror (XFRAME (w->frame));
|
|
577 t = find_window_mirror (w);
|
|
578 if (!t)
|
|
579 abort ();
|
|
580
|
|
581 t->buffer = b;
|
|
582 }
|
|
583
|
|
584
|
102
|
585 /* Determining a window's position based solely on its pixel
|
0
|
586 positioning doesn't work. Instead, we do it the intelligent way,
|
|
587 by checking its positioning in the window hierarchy. */
|
|
588 int
|
|
589 window_is_leftmost (struct window *w)
|
|
590 {
|
|
591 Lisp_Object parent, current_ancestor, window;
|
|
592
|
|
593 XSETWINDOW (window, w);
|
|
594
|
|
595 parent = XWINDOW (window)->parent;
|
|
596 current_ancestor = window;
|
|
597
|
|
598 while (!NILP (parent))
|
|
599 {
|
|
600 if (!NILP (XWINDOW (parent)->hchild) &&
|
|
601 !EQ (XWINDOW (parent)->hchild, current_ancestor))
|
|
602 return 0;
|
|
603
|
|
604 current_ancestor = parent;
|
|
605 parent = XWINDOW (parent)->parent;
|
|
606 }
|
|
607
|
|
608 return 1;
|
|
609 }
|
|
610
|
|
611 int
|
|
612 window_is_rightmost (struct window *w)
|
|
613 {
|
|
614 Lisp_Object parent, current_ancestor, window;
|
|
615
|
|
616 XSETWINDOW (window, w);
|
|
617
|
|
618 parent = XWINDOW (window)->parent;
|
|
619 current_ancestor = window;
|
|
620
|
|
621 while (!NILP (parent))
|
|
622 {
|
|
623 if (!NILP (XWINDOW (parent)->hchild)
|
|
624 && !NILP (XWINDOW (current_ancestor)->next))
|
|
625 return 0;
|
|
626
|
|
627 current_ancestor = parent;
|
|
628 parent = XWINDOW (parent)->parent;
|
|
629 }
|
|
630
|
|
631 return 1;
|
|
632 }
|
|
633
|
|
634 static int
|
|
635 window_full_width_p (struct window *w)
|
|
636 {
|
|
637 return window_is_leftmost (w) && window_is_rightmost (w);
|
|
638 }
|
|
639
|
|
640 static int
|
|
641 window_is_highest (struct window *w)
|
|
642 {
|
|
643 Lisp_Object parent, current_ancestor, window;
|
|
644
|
|
645 XSETWINDOW (window, w);
|
|
646
|
|
647 parent = XWINDOW (window)->parent;
|
|
648 current_ancestor = window;
|
|
649
|
|
650 while (!NILP (parent))
|
|
651 {
|
|
652 if (!NILP (XWINDOW (parent)->vchild) &&
|
|
653 !EQ (XWINDOW (parent)->vchild, current_ancestor))
|
|
654 return 0;
|
|
655
|
|
656 current_ancestor = parent;
|
|
657 parent = XWINDOW (parent)->parent;
|
|
658 }
|
|
659
|
|
660 /* This is really to catch the minibuffer but we make it generic in
|
|
661 case we ever change things around to let the minibuffer be on top. */
|
|
662 if (NILP (XWINDOW (current_ancestor)->prev))
|
|
663 return 1;
|
|
664 else
|
|
665 return 0;
|
|
666 }
|
|
667
|
|
668 static int
|
|
669 window_is_lowest (struct window *w)
|
|
670 {
|
|
671 Lisp_Object parent, current_ancestor, window;
|
|
672
|
|
673 XSETWINDOW (window, w);
|
|
674
|
|
675 parent = XWINDOW (window)->parent;
|
|
676 current_ancestor = window;
|
|
677
|
|
678 while (!NILP (parent))
|
|
679 {
|
|
680 if (!NILP (XWINDOW (parent)->vchild)
|
|
681 && !NILP (XWINDOW (current_ancestor)->next))
|
|
682 return 0;
|
|
683
|
|
684 current_ancestor = parent;
|
|
685 parent = XWINDOW (parent)->parent;
|
|
686 }
|
|
687
|
|
688 return 1;
|
|
689 }
|
|
690
|
|
691 #if 0 /* not currently used */
|
|
692
|
|
693 static int
|
|
694 window_full_height_p (struct window *w)
|
|
695 {
|
|
696 return window_is_highest (w) && window_is_lowest (w);
|
|
697 }
|
|
698
|
|
699 #endif
|
|
700
|
|
701 int
|
|
702 window_truncation_on (struct window *w)
|
|
703 {
|
|
704 /* Horizontally scrolled windows are truncated. */
|
|
705 if (w->hscroll)
|
|
706 return 1;
|
|
707
|
|
708 /* If truncate_partial_width_windows is true and the window is not
|
|
709 the full width of the frame it is truncated. */
|
|
710 if (truncate_partial_width_windows
|
|
711 && !(window_is_leftmost (w) && window_is_rightmost (w)))
|
|
712 return 1;
|
|
713
|
|
714 /* If the window's buffer's value of truncate_lines is non-nil, then
|
|
715 the window is truncated. */
|
|
716 if (!NILP (XBUFFER (w->buffer)->truncate_lines))
|
|
717 return 1;
|
|
718
|
|
719 return 0;
|
|
720 }
|
|
721
|
286
|
722 static int
|
284
|
723 have_undivided_common_edge (struct window *w_right, void *closure)
|
|
724 {
|
|
725 struct window *w_left = (struct window *) closure;
|
|
726 return (WINDOW_RIGHT (w_left) == WINDOW_LEFT (w_right)
|
|
727 && WINDOW_TOP (w_left) < WINDOW_BOTTOM (w_right)
|
|
728 && WINDOW_TOP (w_right) < WINDOW_BOTTOM (w_left)
|
|
729 #ifdef HAVE_SCROLLBARS
|
|
730 && (NILP (w_right->scrollbar_on_left_p)
|
|
731 || NILP (w_right->vertical_scrollbar_visible_p)
|
|
732 || ZEROP (w_right->scrollbar_width))
|
|
733 #endif
|
|
734 );
|
|
735 }
|
|
736
|
|
737 static int
|
|
738 window_needs_vertical_divider_1 (struct window *w)
|
|
739 {
|
|
740 /* Never if we're on the right */
|
|
741 if (window_is_rightmost (w))
|
|
742 return 0;
|
|
743
|
|
744 /* Always if draggable */
|
|
745 if (!NILP (w->vertical_divider_draggable_p))
|
|
746 return 1;
|
|
747
|
|
748 #ifdef HAVE_SCROLLBARS
|
|
749 /* Our right scrollabr is enough to separate us at the right */
|
|
750 if (NILP (w->scrollbar_on_left_p)
|
|
751 && !NILP (w->vertical_scrollbar_visible_p)
|
|
752 && !ZEROP (w->scrollbar_width))
|
|
753 return 0;
|
|
754 #endif
|
|
755
|
|
756 /* Ok. to determine whether we need a divider on the left, we must
|
286
|
757 check that our right neighbor windows have scrollbars on their
|
|
758 left sides. We must check all such windows which have common
|
284
|
759 left edge with our window's right edge. */
|
|
760 return map_windows (XFRAME (WINDOW_FRAME (w)),
|
|
761 have_undivided_common_edge, (void*)w);
|
|
762 }
|
|
763
|
|
764 int
|
0
|
765 window_needs_vertical_divider (struct window *w)
|
|
766 {
|
284
|
767 if (!w->need_vertical_divider_valid_p)
|
|
768 {
|
|
769 w->need_vertical_divider_p =
|
|
770 window_needs_vertical_divider_1 (w);
|
|
771 w->need_vertical_divider_valid_p = 1;
|
|
772 }
|
|
773 return w->need_vertical_divider_p;
|
|
774 }
|
|
775
|
|
776 /* Called from invalidate_vertical_divider_cache_in_frame */
|
|
777 int
|
|
778 invalidate_vertical_divider_cache_in_window (struct window *w,
|
|
779 void *u_n_u_s_e_d)
|
|
780 {
|
|
781 w->need_vertical_divider_valid_p = 0;
|
|
782 return 0;
|
|
783 }
|
|
784
|
|
785 /* Calculate width of vertical divider, including its shadows
|
|
786 and spacing. The returned value is effectively the distance
|
|
787 between adjacent window edges. This function does not check
|
|
788 whether a windows needs vertival divider, so the returned
|
|
789 value is a "theoretical" one */
|
|
790 int
|
|
791 window_divider_width (struct window *w)
|
|
792 {
|
|
793 /* the shadow thickness can be negative. This means that the divider
|
|
794 will have a depressed look */
|
|
795
|
|
796 if (FRAME_WIN_P (XFRAME (WINDOW_FRAME (w))))
|
|
797 return
|
|
798 XINT (w->vertical_divider_line_width)
|
|
799 + 2 * XINT (w->vertical_divider_spacing)
|
|
800 + 2 * abs (XINT (w->vertical_divider_shadow_thickness));
|
|
801 else
|
|
802 return XINT (w->vertical_divider_line_width) == 0 ? 0 : 1;
|
0
|
803 }
|
|
804
|
|
805 int
|
|
806 window_scrollbar_width (struct window *w)
|
|
807 {
|
|
808 #ifdef HAVE_SCROLLBARS
|
|
809 if (!WINDOW_WIN_P (w)
|
|
810 || MINI_WINDOW_P (w)
|
282
|
811 || NILP (w->buffer)
|
|
812 || NILP (w->vertical_scrollbar_visible_p))
|
0
|
813 /* #### when does NILP (w->buffer) happen? */
|
|
814 return 0;
|
|
815
|
|
816 return XINT (w->scrollbar_width);
|
|
817 #else
|
|
818 return 0;
|
102
|
819 #endif /* HAVE_SCROLLBARS */
|
0
|
820 }
|
|
821
|
|
822 /* Horizontal scrollbars are only active on windows with truncation
|
|
823 turned on. */
|
|
824 int
|
|
825 window_scrollbar_height (struct window *w)
|
|
826 {
|
|
827 #ifdef HAVE_SCROLLBARS
|
|
828 if (!WINDOW_WIN_P (w)
|
|
829 || MINI_WINDOW_P (w)
|
|
830 || NILP (w->buffer)
|
282
|
831 || NILP (w->horizontal_scrollbar_visible_p)
|
0
|
832 || !window_truncation_on (w))
|
|
833 return 0;
|
|
834
|
|
835 return XINT (w->scrollbar_height);
|
|
836 #else
|
|
837 return 0;
|
102
|
838 #endif /* HAVE_SCROLLBARS */
|
0
|
839 }
|
|
840
|
|
841 int
|
|
842 window_modeline_height (struct window *w)
|
|
843 {
|
|
844 struct frame *f = XFRAME (w->frame);
|
|
845 int modeline_height;
|
|
846
|
|
847 if (MINI_WINDOW_P (w) || NILP (w->buffer))
|
|
848 {
|
|
849 modeline_height = 0;
|
|
850 }
|
|
851 else if (!WINDOW_HAS_MODELINE_P (w))
|
|
852 {
|
|
853 if (window_scrollbar_height (w))
|
|
854 modeline_height = 0;
|
|
855 else
|
|
856 {
|
|
857 modeline_height = FRAMEMETH (f, divider_height, ());
|
|
858
|
|
859 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
860 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
861 }
|
|
862 }
|
|
863 else
|
|
864 {
|
|
865 if (noninteractive)
|
|
866 modeline_height = 0;
|
|
867 else
|
|
868 {
|
|
869 display_line_dynarr *dla;
|
|
870
|
|
871 /* We don't force a regeneration of the modeline here.
|
|
872 Instead it is now a precondition that any function calling
|
|
873 this should make sure that one of these structures is
|
|
874 up-to-date. In practice this only affects two internal
|
|
875 redisplay functions, regenerate_window and
|
|
876 regenerate_window_point_center. */
|
|
877 /* We check DESIRED_DISP because if it is valid it is more
|
|
878 up-to-date than CURRENT_DISP. For calls to this outside
|
|
879 of redisplay it doesn't matter which structure we check
|
|
880 since there is a redisplay condition that these
|
|
881 structures be identical outside of redisplay. */
|
|
882 dla = window_display_lines (w, DESIRED_DISP);
|
|
883 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
884 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
885 Dynarr_atp (dla, 0)->descent);
|
|
886 else
|
|
887 {
|
|
888 dla = window_display_lines (w, CURRENT_DISP);
|
|
889 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
890 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
891 Dynarr_atp (dla, 0)->descent);
|
|
892 else
|
|
893 /* This should be an abort except I'm not yet 100%
|
|
894 confident that it won't ever get hit (though I
|
|
895 haven't been able to trigger it). It is extremely
|
|
896 unlikely to cause any noticable problem and even if
|
|
897 it does it will be a minor display glitch. */
|
|
898 /* #### Bullshit alert. It does get hit and it causes
|
|
899 noticeable glitches. real_current_modeline_height
|
|
900 is a kludge to fix this for 19.14. */
|
|
901 modeline_height = real_current_modeline_height (w);
|
|
902 }
|
|
903
|
|
904 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
905 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
906 }
|
|
907 }
|
|
908
|
|
909 return modeline_height;
|
|
910 }
|
|
911
|
|
912 /*****************************************************************************
|
|
913 margin_width_internal
|
|
914
|
|
915 For a given window, return the width in pixels of the specified margin.
|
|
916 ****************************************************************************/
|
|
917 static int
|
|
918 margin_width_internal (struct window *w, int left_margin)
|
|
919 {
|
|
920 struct buffer *b;
|
|
921 int window_cwidth = window_char_width (w, 1);
|
|
922 int margin_cwidth;
|
|
923 int font_width;
|
272
|
924 Lisp_Object window;
|
0
|
925
|
|
926 /* We might be getting called on a non-leaf. */
|
|
927 if (NILP (w->buffer))
|
|
928 return 0;
|
|
929
|
|
930 /* The minibuffer never has margins. */
|
|
931 if (MINI_WINDOW_P (w))
|
|
932 return 0;
|
|
933
|
|
934 XSETWINDOW (window, w);
|
|
935 b = XBUFFER (w->buffer);
|
|
936 margin_cwidth = (left_margin ? XINT (w->left_margin_width) :
|
|
937 XINT (w->right_margin_width));
|
|
938
|
|
939 default_face_height_and_width (window, 0, &font_width);
|
|
940
|
|
941 /* The left margin takes precedence over the right margin so we
|
|
942 subtract its width from the space available for the right
|
|
943 margin. */
|
|
944 if (!left_margin)
|
|
945 window_cwidth -= XINT (w->left_margin_width);
|
|
946
|
|
947 /* The margin cannot be wider than the window is. We allow the
|
|
948 value to be bigger since it is possible for the user to enlarge
|
|
949 the window such that the left margin value would no longer be too
|
|
950 big, but we won't return a value that is larger. */
|
|
951 if (margin_cwidth > window_cwidth)
|
|
952 margin_cwidth = window_cwidth;
|
|
953
|
|
954 /* At the user level the margin is always specified in characters.
|
|
955 Internally however it is manipulated in terms of pixels. */
|
173
|
956 return margin_cwidth * font_width;
|
0
|
957 }
|
|
958
|
|
959 int
|
|
960 window_left_margin_width (struct window *w)
|
|
961 {
|
|
962 return margin_width_internal (w, 1);
|
|
963 }
|
|
964
|
|
965 int
|
|
966 window_right_margin_width (struct window *w)
|
|
967 {
|
|
968 return margin_width_internal (w, 0);
|
|
969 }
|
|
970
|
|
971 static int
|
|
972 window_top_toolbar_height (struct window *w)
|
|
973 {
|
|
974 /* #### implement this shit. */
|
|
975 return 0;
|
|
976 }
|
|
977
|
|
978 /* #### Currently used in scrollbar.c. Does it actually need to be? */
|
|
979 int
|
|
980 window_bottom_toolbar_height (struct window *w)
|
|
981 {
|
|
982 return 0;
|
|
983 }
|
|
984
|
|
985 static int
|
|
986 window_left_toolbar_width (struct window *w)
|
|
987 {
|
|
988 return 0;
|
|
989 }
|
|
990
|
|
991 static int
|
|
992 window_right_toolbar_width (struct window *w)
|
|
993 {
|
|
994 return 0;
|
|
995 }
|
|
996
|
|
997 /*****************************************************************************
|
|
998 Window Gutters
|
|
999
|
|
1000 The gutters of a window are those areas in the boundary defined by
|
|
1001 w->pixel_top, w->pixel_left, w->pixel_height and w->pixel_width which
|
|
1002 do not contain text. Items which may be in the gutters include
|
|
1003 scrollbars, toolbars and modelines. The margin areas are not
|
|
1004 included. This is an exception made because redisplay special cases
|
|
1005 the handling of those areas in many places in such a way that
|
|
1006 including them in the gutter area would make life difficult.
|
|
1007
|
|
1008 The size functions refer to height for the bottom and top gutters and
|
|
1009 width for the left and right gutters. The starting position
|
|
1010 functions refer to the Y coord for bottom and top gutters and the X
|
|
1011 coord for left and right gutters. All starting positions are
|
|
1012 relative to the frame, not the window.
|
|
1013 ****************************************************************************/
|
|
1014
|
|
1015 int
|
|
1016 window_top_gutter_height (struct window *w)
|
|
1017 {
|
|
1018 int toolbar_height = window_top_toolbar_height (w);
|
|
1019
|
|
1020 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1021 return 0;
|
|
1022
|
|
1023 #ifdef HAVE_SCROLLBARS
|
282
|
1024 if (!NILP (w->scrollbar_on_top_p))
|
0
|
1025 return window_scrollbar_height (w) + toolbar_height;
|
|
1026 else
|
|
1027 #endif
|
|
1028 return toolbar_height;
|
|
1029 }
|
|
1030
|
|
1031 int
|
|
1032 window_bottom_gutter_height (struct window *w)
|
|
1033 {
|
185
|
1034 int other_height;
|
0
|
1035
|
|
1036 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1037 return 0;
|
|
1038 else
|
|
1039 other_height =
|
|
1040 window_modeline_height (w) + window_bottom_toolbar_height (w);
|
|
1041
|
|
1042 #ifdef HAVE_SCROLLBARS
|
282
|
1043 if (NILP (w->scrollbar_on_top_p))
|
0
|
1044 return window_scrollbar_height (w) + other_height;
|
|
1045 else
|
|
1046 #endif
|
|
1047 return other_height;
|
|
1048 }
|
|
1049
|
|
1050 int
|
|
1051 window_left_gutter_width (struct window *w, int modeline)
|
|
1052 {
|
284
|
1053 int gutter = window_left_toolbar_width (w);
|
|
1054
|
0
|
1055 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1056 return 0;
|
|
1057
|
284
|
1058
|
0
|
1059 #ifdef HAVE_SCROLLBARS
|
284
|
1060 if (!modeline && !NILP (w->scrollbar_on_left_p))
|
|
1061 gutter += window_scrollbar_width (w);
|
0
|
1062 #endif
|
284
|
1063
|
|
1064 return gutter;
|
0
|
1065 }
|
|
1066
|
|
1067 int
|
|
1068 window_right_gutter_width (struct window *w, int modeline)
|
|
1069 {
|
284
|
1070 int gutter = window_left_toolbar_width (w);
|
|
1071
|
0
|
1072 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
1073 return 0;
|
|
1074
|
|
1075 #ifdef HAVE_SCROLLBARS
|
284
|
1076 if (!modeline && NILP (w->scrollbar_on_left_p))
|
|
1077 gutter += window_scrollbar_width (w);
|
0
|
1078 #endif
|
284
|
1079
|
|
1080 if (window_needs_vertical_divider (w))
|
|
1081 gutter += window_divider_width (w);
|
|
1082
|
|
1083 return gutter;
|
0
|
1084 }
|
|
1085
|
|
1086
|
20
|
1087 DEFUN ("windowp", Fwindowp, 1, 1, 0, /*
|
0
|
1088 Return t if OBJ is a window.
|
20
|
1089 */
|
|
1090 (obj))
|
0
|
1091 {
|
173
|
1092 return WINDOWP (obj) ? Qt : Qnil;
|
0
|
1093 }
|
|
1094
|
20
|
1095 DEFUN ("window-live-p", Fwindow_live_p, 1, 1, 0, /*
|
0
|
1096 Return t if OBJ is a window which is currently visible.
|
20
|
1097 */
|
|
1098 (obj))
|
0
|
1099 {
|
173
|
1100 return WINDOWP (obj) && WINDOW_LIVE_P (XWINDOW (obj)) ? Qt : Qnil;
|
0
|
1101 }
|
|
1102
|
20
|
1103 DEFUN ("selected-window", Fselected_window, 0, 1, 0, /*
|
0
|
1104 Return the window that the cursor now appears in and commands apply to.
|
|
1105 If the optional argument CON-DEV-OR-FRAME is specified and is a frame, return
|
|
1106 the selected window used by that frame. If CON-DEV-OR-FRAME is a device,
|
|
1107 then the selected frame on that device will be used. If CON-DEV-OR-FRAME
|
|
1108 is a console, the selected frame on that console's selected device will
|
|
1109 be used. Otherwise, the selected frame is used.
|
20
|
1110 */
|
|
1111 (con_dev_or_frame))
|
0
|
1112 {
|
|
1113 if (NILP (con_dev_or_frame) && NILP (Fselected_device (Qnil)))
|
|
1114 return Qnil; /* happens at startup */
|
|
1115
|
272
|
1116 {
|
|
1117 struct frame *f = decode_frame_or_selected (con_dev_or_frame);
|
|
1118 return FRAME_SELECTED_WINDOW (f);
|
|
1119 }
|
0
|
1120 }
|
|
1121
|
20
|
1122 DEFUN ("minibuffer-window", Fminibuffer_window, 0, 1, 0, /*
|
0
|
1123 Return the window used now for minibuffers.
|
|
1124 If the optional argument CON-DEV-OR-FRAME is specified and is a frame, return
|
|
1125 the minibuffer window used by that frame. If CON-DEV-OR-FRAME is a device,
|
|
1126 then the selected frame on that device will be used. If CON-DEV-OR-FRAME
|
|
1127 is a console, the selected frame on that console's selected device will
|
|
1128 be used. Otherwise, the selected frame is used.
|
20
|
1129 */
|
|
1130 (con_dev_or_frame))
|
0
|
1131 {
|
272
|
1132 return FRAME_MINIBUF_WINDOW (decode_frame_or_selected (con_dev_or_frame));
|
0
|
1133 }
|
|
1134
|
20
|
1135 DEFUN ("window-minibuffer-p", Fwindow_minibuffer_p, 1, 1, 0, /*
|
0
|
1136 Return non-nil if WINDOW is a minibuffer window.
|
20
|
1137 */
|
|
1138 (window))
|
0
|
1139 {
|
173
|
1140 return MINI_WINDOW_P (decode_window (window)) ? Qt : Qnil;
|
0
|
1141 }
|
|
1142
|
20
|
1143 DEFUN ("window-first-hchild", Fwindow_first_hchild, 1, 1, 0, /*
|
0
|
1144 Return the first horizontal child of WINDOW, or nil.
|
20
|
1145 */
|
|
1146 (window))
|
0
|
1147 {
|
102
|
1148 return decode_window (window)->hchild;
|
0
|
1149 }
|
|
1150
|
20
|
1151 DEFUN ("window-first-vchild", Fwindow_first_vchild, 1, 1, 0, /*
|
0
|
1152 Return the first vertical child of WINDOW, or nil.
|
20
|
1153 */
|
|
1154 (window))
|
0
|
1155 {
|
102
|
1156 return decode_window (window)->vchild;
|
0
|
1157 }
|
|
1158
|
20
|
1159 DEFUN ("window-next-child", Fwindow_next_child, 1, 1, 0, /*
|
0
|
1160 Return the next window on the same level as WINDOW, or nil.
|
20
|
1161 */
|
|
1162 (window))
|
0
|
1163 {
|
102
|
1164 return decode_window (window)->next;
|
0
|
1165 }
|
|
1166
|
20
|
1167 DEFUN ("window-previous-child", Fwindow_previous_child, 1, 1, 0, /*
|
0
|
1168 Return the previous window on the same level as WINDOW, or nil.
|
20
|
1169 */
|
|
1170 (window))
|
0
|
1171 {
|
102
|
1172 return decode_window (window)->prev;
|
0
|
1173 }
|
|
1174
|
20
|
1175 DEFUN ("window-parent", Fwindow_parent, 1, 1, 0, /*
|
0
|
1176 Return the parent of WINDOW, or nil.
|
20
|
1177 */
|
|
1178 (window))
|
0
|
1179 {
|
102
|
1180 return decode_window (window)->parent;
|
0
|
1181 }
|
|
1182
|
20
|
1183 DEFUN ("window-lowest-p", Fwindow_lowest_p, 1, 1, 0, /*
|
0
|
1184 Return non-nil if WINDOW is along the bottom of its frame.
|
20
|
1185 */
|
|
1186 (window))
|
0
|
1187 {
|
102
|
1188 return window_is_lowest (decode_window (window)) ? Qt : Qnil;
|
0
|
1189 }
|
|
1190
|
20
|
1191 DEFUN ("window-highest-p", Fwindow_highest_p, 1, 1, 0, /*
|
0
|
1192 Return non-nil if WINDOW is along the top of its frame.
|
20
|
1193 */
|
|
1194 (window))
|
0
|
1195 {
|
102
|
1196 return window_is_highest (decode_window (window)) ? Qt : Qnil;
|
0
|
1197 }
|
|
1198
|
20
|
1199 DEFUN ("window-leftmost-p", Fwindow_leftmost_p, 1, 1, 0, /*
|
0
|
1200 Return non-nil if WINDOW is along the left edge of its frame.
|
20
|
1201 */
|
|
1202 (window))
|
0
|
1203 {
|
102
|
1204 return window_is_leftmost (decode_window (window)) ? Qt : Qnil;
|
0
|
1205 }
|
|
1206
|
20
|
1207 DEFUN ("window-rightmost-p", Fwindow_rightmost_p, 1, 1, 0, /*
|
0
|
1208 Return non-nil if WINDOW is along the right edge of its frame.
|
20
|
1209 */
|
|
1210 (window))
|
0
|
1211 {
|
102
|
1212 return window_is_rightmost (decode_window (window)) ? Qt : Qnil;
|
0
|
1213 }
|
|
1214
|
20
|
1215 DEFUN ("pos-visible-in-window-p", Fpos_visible_in_window_p, 0, 2, 0, /*
|
0
|
1216 Return t if position POS is currently on the frame in WINDOW.
|
|
1217 Returns nil if that position is scrolled vertically out of view.
|
|
1218 POS defaults to point in WINDOW's buffer; WINDOW, to the selected window.
|
20
|
1219 */
|
|
1220 (pos, window))
|
0
|
1221 {
|
102
|
1222 struct window *w = decode_window (window);
|
272
|
1223 Bufpos top = marker_position (w->start[CURRENT_DISP]);
|
0
|
1224 Bufpos posint;
|
272
|
1225 struct buffer *buf = XBUFFER (w->buffer);
|
0
|
1226
|
|
1227 if (NILP (pos))
|
|
1228 posint = BUF_PT (buf);
|
|
1229 else
|
|
1230 {
|
|
1231 CHECK_INT_COERCE_MARKER (pos);
|
|
1232 posint = XINT (pos);
|
|
1233 }
|
|
1234
|
|
1235 if (posint < top || posint > BUF_ZV (buf))
|
|
1236 return Qnil;
|
|
1237
|
|
1238 /* w->start can be out of range. If it is, do something reasonable. */
|
|
1239 if (top < BUF_BEGV (buf) || top > BUF_ZV (buf))
|
|
1240 return Qnil;
|
|
1241
|
272
|
1242 return point_would_be_visible (w, top, posint) ? Qt : Qnil;
|
0
|
1243 }
|
|
1244
|
|
1245
|
|
1246 struct window *
|
|
1247 decode_window (Lisp_Object window)
|
|
1248 {
|
|
1249 if (NILP (window))
|
|
1250 return XWINDOW (Fselected_window (Qnil));
|
|
1251
|
|
1252 CHECK_LIVE_WINDOW (window);
|
|
1253 return XWINDOW (window);
|
|
1254 }
|
|
1255
|
20
|
1256 DEFUN ("window-buffer", Fwindow_buffer, 0, 1, 0, /*
|
0
|
1257 Return the buffer that WINDOW is displaying.
|
20
|
1258 */
|
|
1259 (window))
|
0
|
1260 {
|
|
1261 return decode_window (window)->buffer;
|
|
1262 }
|
|
1263
|
20
|
1264 DEFUN ("window-frame", Fwindow_frame, 0, 1, 0, /*
|
0
|
1265 Return the frame that window WINDOW is on.
|
20
|
1266 */
|
|
1267 (window))
|
0
|
1268 {
|
|
1269 return decode_window (window)->frame;
|
|
1270 }
|
|
1271
|
20
|
1272 DEFUN ("window-height", Fwindow_height, 0, 1, 0, /*
|
0
|
1273 Return the number of default lines in WINDOW.
|
|
1274 This actually works by dividing the window's pixel height (including
|
|
1275 the modeline and horizontal scrollbar, if any) by the height of the
|
|
1276 default font; therefore, the number of displayed lines will probably
|
|
1277 be different.
|
|
1278 Use `window-height' to get consistent results in geometry calculations.
|
|
1279 Use `window-displayed-height' to get the actual number of lines
|
|
1280 currently displayed in a window.
|
20
|
1281 */
|
|
1282 (window))
|
0
|
1283 {
|
|
1284 return make_int (window_char_height (decode_window (window), 1));
|
|
1285 }
|
|
1286
|
20
|
1287 DEFUN ("window-displayed-height", Fwindow_displayed_height, 0, 1, 0, /*
|
0
|
1288 Return the number of lines currently displayed in WINDOW.
|
|
1289 This counts the actual number of lines displayed in WINDOW
|
272
|
1290 \(as opposed to `window-height'). The modeline and horizontal
|
0
|
1291 scrollbar do not count as lines. If there is some blank space
|
|
1292 between the end of the buffer and the end of the window, this
|
|
1293 function pretends that there are lines of text in the default
|
|
1294 font there.
|
20
|
1295 */
|
70
|
1296 (window))
|
0
|
1297 {
|
|
1298 return make_int (window_displayed_height (decode_window (window)));
|
|
1299 }
|
|
1300
|
20
|
1301 DEFUN ("window-pixel-height", Fwindow_pixel_height, 0, 1, 0, /*
|
0
|
1302 Return the height of WINDOW in pixels. Defaults to current window.
|
|
1303 This includes the window's modeline and horizontal scrollbar (if any).
|
20
|
1304 */
|
|
1305 (window))
|
0
|
1306 {
|
173
|
1307 return make_int (decode_window (window)->pixel_height);
|
0
|
1308 }
|
|
1309
|
276
|
1310 DEFUN ("window-text-pixel-height", Fwindow_text_pixel_height, 0, 1, 0, /*
|
|
1311 Return the height in pixels of the text-displaying portion of WINDOW.
|
|
1312 Unlike `window-pixel-height', the space occupied by the modeline and
|
|
1313 horizontal scrollbar, if any, is not counted.
|
263
|
1314 */
|
|
1315 (window))
|
|
1316 {
|
276
|
1317 struct window *w = decode_window (window);
|
|
1318
|
|
1319 return make_int (WINDOW_TEXT_HEIGHT (w));
|
263
|
1320 }
|
|
1321
|
20
|
1322 DEFUN ("window-width", Fwindow_width, 0, 1, 0, /*
|
0
|
1323 Return the number of display columns in WINDOW.
|
|
1324 This is the width that is usable columns available for text in WINDOW.
|
20
|
1325 */
|
|
1326 (window))
|
0
|
1327 {
|
173
|
1328 return make_int (window_char_width (decode_window (window), 0));
|
0
|
1329 }
|
|
1330
|
20
|
1331 DEFUN ("window-pixel-width", Fwindow_pixel_width, 0, 1, 0, /*
|
0
|
1332 Return the width of WINDOW in pixels. Defaults to current window.
|
20
|
1333 */
|
|
1334 (window))
|
0
|
1335 {
|
173
|
1336 return make_int (decode_window (window)->pixel_width);
|
0
|
1337 }
|
|
1338
|
276
|
1339 DEFUN ("window-text-pixel-width", Fwindow_text_pixel_width, 0, 1, 0, /*
|
|
1340 Return the width in pixels of the text-displaying portion of WINDOW.
|
|
1341 Unlike `window-pixel-width', the space occupied by the vertical
|
|
1342 scrollbar or divider, if any, is not counted.
|
|
1343 */
|
|
1344 (window))
|
|
1345 {
|
|
1346 struct window *w = decode_window (window);
|
|
1347
|
|
1348 return make_int (WINDOW_TEXT_WIDTH (w));
|
|
1349 }
|
|
1350
|
20
|
1351 DEFUN ("window-hscroll", Fwindow_hscroll, 0, 1, 0, /*
|
0
|
1352 Return the number of columns by which WINDOW is scrolled from left margin.
|
20
|
1353 */
|
|
1354 (window))
|
0
|
1355 {
|
173
|
1356 return make_int (decode_window (window)->hscroll);
|
0
|
1357 }
|
|
1358
|
267
|
1359 #ifdef MODELINE_IS_SCROLLABLE
|
257
|
1360 DEFUN ("modeline-hscroll", Fmodeline_hscroll, 0, 1, 0, /*
|
272
|
1361 Return the number of columns by which WINDOW's modeline is scrolled from
|
257
|
1362 left margin. If the window has no modeline, return nil.
|
|
1363 */
|
|
1364 (window))
|
|
1365 {
|
280
|
1366 struct window *w = decode_window (window);
|
|
1367
|
257
|
1368 return (WINDOW_HAS_MODELINE_P (w)) ? make_int (w->modeline_hscroll) : Qnil;
|
|
1369 }
|
272
|
1370
|
257
|
1371 DEFUN ("set-modeline-hscroll", Fset_modeline_hscroll, 2, 2, 0, /*
|
|
1372 Set number of columns WINDOW's modeline is scrolled from left margin to NCOL.
|
|
1373 NCOL should be zero or positive. If NCOL is negative, it will be forced to 0.
|
|
1374 If the window has no modeline, do nothing and return nil.
|
|
1375 */
|
|
1376 (window, ncol))
|
|
1377 {
|
280
|
1378 struct window *w = decode_window (window);
|
|
1379
|
257
|
1380 if (WINDOW_HAS_MODELINE_P (w))
|
|
1381 {
|
280
|
1382 int ncols;
|
257
|
1383 CHECK_INT (ncol);
|
|
1384 ncols = XINT (ncol);
|
|
1385 if (ncols < 0) ncols = 0;
|
|
1386 if (w->modeline_hscroll != ncols)
|
|
1387 MARK_MODELINE_CHANGED;
|
|
1388 w->modeline_hscroll = ncols;
|
|
1389 return ncol;
|
|
1390 }
|
|
1391 return Qnil;
|
|
1392 }
|
272
|
1393 #endif /* MODELINE_IS_SCROLLABLE */
|
|
1394
|
|
1395 DEFUN ("set-window-hscroll", Fset_window_hscroll, 2, 2, 0, /*
|
|
1396 Set number of columns WINDOW is scrolled from left margin to NCOL.
|
|
1397 NCOL should be zero or positive.
|
|
1398 */
|
|
1399 (window, ncol))
|
|
1400 {
|
|
1401 struct window *w;
|
|
1402 int ncols;
|
|
1403
|
|
1404 CHECK_INT (ncol);
|
|
1405 ncols = XINT (ncol);
|
|
1406 if (ncols < 0) ncols = 0;
|
|
1407 w = decode_window (window);
|
|
1408 if (w->hscroll != ncols)
|
|
1409 MARK_CLIP_CHANGED; /* FSF marks differently but we aren't FSF. */
|
|
1410 w->hscroll = ncols;
|
|
1411 return ncol;
|
|
1412 }
|
257
|
1413
|
276
|
1414 #if 0 /* bogus FSF crock */
|
0
|
1415
|
149
|
1416 xxDEFUN ("window-redisplay-end-trigger",
|
|
1417 Fwindow_redisplay_end_trigger, 0, 1, 0, /*
|
0
|
1418 Return WINDOW's redisplay end trigger value.
|
|
1419 See `set-window-redisplay-end-trigger' for more information.
|
102
|
1420 */
|
|
1421 (window))
|
0
|
1422 {
|
|
1423 return decode_window (window)->redisplay_end_trigger;
|
|
1424 }
|
|
1425
|
149
|
1426 xxDEFUN ("set-window-redisplay-end-trigger",
|
|
1427 Fset_window_redisplay_end_trigger, 2, 2, 0, /*
|
0
|
1428 Set WINDOW's redisplay end trigger value to VALUE.
|
|
1429 VALUE should be a buffer position (typically a marker) or nil.
|
|
1430 If it is a buffer position, then if redisplay in WINDOW reaches a position
|
|
1431 beyond VALUE, the functions in `redisplay-end-trigger-functions' are called
|
|
1432 with two arguments: WINDOW, and the end trigger value.
|
|
1433 Afterwards the end-trigger value is reset to nil.
|
185
|
1434 */
|
102
|
1435 (window, value))
|
0
|
1436 {
|
102
|
1437 return (decode_window (window)->redisplay_end_trigger = value);
|
0
|
1438 }
|
|
1439
|
|
1440 #endif /* 0 */
|
|
1441
|
20
|
1442 DEFUN ("window-pixel-edges", Fwindow_pixel_edges, 0, 1, 0, /*
|
0
|
1443 Return a list of the pixel edge coordinates of WINDOW.
|
|
1444 \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at top left corner of frame.
|
|
1445 The frame toolbars and menubars are considered to be outside of this area.
|
20
|
1446 */
|
|
1447 (window))
|
0
|
1448 {
|
|
1449 struct window *w = decode_window (window);
|
|
1450 struct frame *f = XFRAME (w->frame);
|
149
|
1451
|
|
1452 int left = w->pixel_left - FRAME_LEFT_BORDER_END (f);
|
|
1453 int top = w->pixel_top - FRAME_TOP_BORDER_END (f);
|
0
|
1454
|
|
1455 return list4 (make_int (left),
|
|
1456 make_int (top),
|
|
1457 make_int (left + w->pixel_width),
|
|
1458 make_int (top + w->pixel_height));
|
|
1459 }
|
|
1460
|
276
|
1461 DEFUN ("window-text-pixel-edges", Fwindow_text_pixel_edges, 0, 1, 0, /*
|
|
1462 Return a list of the pixel edge coordinates of the text area of WINDOW.
|
|
1463 Returns the list \(LEFT TOP RIGHT BOTTOM), all relative to 0, 0 at the
|
|
1464 top left corner of the window.
|
|
1465 */
|
|
1466 (window))
|
|
1467 {
|
|
1468 struct window *w = decode_window (window);
|
|
1469
|
|
1470 int left = window_left_gutter_width (w, /* modeline = */ 0);
|
|
1471 int top = window_top_gutter_height (w);
|
|
1472 int right = WINDOW_WIDTH (w) - window_right_gutter_width (w, 0);
|
|
1473 int bottom = WINDOW_HEIGHT (w) - window_bottom_gutter_height (w);
|
|
1474
|
|
1475 return list4 (make_int (left),
|
|
1476 make_int (top),
|
|
1477 make_int (right),
|
|
1478 make_int (bottom));
|
|
1479 }
|
|
1480
|
20
|
1481 DEFUN ("window-point", Fwindow_point, 0, 1, 0, /*
|
0
|
1482 Return current value of point in WINDOW.
|
|
1483 For a nonselected window, this is the value point would have
|
|
1484 if that window were selected.
|
|
1485
|
|
1486 Note that, when WINDOW is the selected window and its buffer
|
|
1487 is also currently selected, the value returned is the same as (point).
|
|
1488 It would be more strictly correct to return the `top-level' value
|
|
1489 of point, outside of any save-excursion forms.
|
|
1490 But that is hard to define.
|
20
|
1491 */
|
|
1492 (window))
|
0
|
1493 {
|
|
1494 struct window *w = decode_window (window);
|
|
1495
|
|
1496 /* The special check for current buffer is necessary for this
|
|
1497 function to work as defined when called within an excursion. */
|
|
1498 if (w == XWINDOW (Fselected_window (XFRAME (w->frame)->device))
|
|
1499 && current_buffer == XBUFFER (w->buffer))
|
|
1500 return Fpoint (Qnil);
|
|
1501 return Fmarker_position (w->pointm[CURRENT_DISP]);
|
|
1502 }
|
|
1503
|
20
|
1504 DEFUN ("window-start", Fwindow_start, 0, 1, 0, /*
|
0
|
1505 Return position at which display currently starts in WINDOW.
|
|
1506 This is updated by redisplay or by calling `set-window-start'.
|
20
|
1507 */
|
|
1508 (window))
|
0
|
1509 {
|
|
1510 return Fmarker_position (decode_window (window)->start[CURRENT_DISP]);
|
|
1511 }
|
|
1512
|
20
|
1513 DEFUN ("window-end", Fwindow_end, 0, 2, 0, /*
|
0
|
1514 Return position at which display currently ends in WINDOW.
|
|
1515 This is updated by redisplay, when it runs to completion.
|
|
1516 Simply changing the buffer text or setting `window-start'
|
|
1517 does not update this value.
|
|
1518 If GUARANTEE is non-nil, then the return value is guaranteed to be
|
|
1519 the value of window-end at the end of the next full redisplay assuming
|
|
1520 nothing else changes in the meantime. This function is potentially much
|
|
1521 slower with this flag set.
|
20
|
1522 */
|
|
1523 (window, guarantee))
|
0
|
1524 {
|
|
1525 struct window *w = decode_window (window);
|
|
1526
|
|
1527 if (NILP (guarantee))
|
|
1528 {
|
280
|
1529 Lisp_Object buf;
|
|
1530 buf = w->buffer;
|
0
|
1531 CHECK_BUFFER (buf);
|
272
|
1532 return make_int (BUF_Z (XBUFFER (buf)) - w->window_end_pos[CURRENT_DISP]);
|
0
|
1533 }
|
|
1534 else
|
|
1535 {
|
|
1536 Bufpos startp = marker_position (w->start[CURRENT_DISP]);
|
173
|
1537 return make_int (end_of_last_line (w, startp));
|
0
|
1538 }
|
|
1539 }
|
|
1540
|
20
|
1541 DEFUN ("set-window-point", Fset_window_point, 2, 2, 0, /*
|
0
|
1542 Make point value in WINDOW be at position POS in WINDOW's buffer.
|
20
|
1543 */
|
|
1544 (window, pos))
|
0
|
1545 {
|
|
1546 struct window *w = decode_window (window);
|
|
1547
|
|
1548 CHECK_INT_COERCE_MARKER (pos);
|
|
1549 if (w == XWINDOW (Fselected_window (Qnil)))
|
223
|
1550 Fgoto_char (pos, Qnil);
|
0
|
1551 else
|
|
1552 set_marker_restricted (w->pointm[CURRENT_DISP], pos, w->buffer);
|
|
1553
|
|
1554 MARK_POINT_CHANGED;
|
|
1555 return pos;
|
|
1556 }
|
|
1557
|
20
|
1558 DEFUN ("set-window-start", Fset_window_start, 2, 3, 0, /*
|
0
|
1559 Make display in WINDOW start at position POS in WINDOW's buffer.
|
|
1560 Optional third arg NOFORCE non-nil inhibits next redisplay
|
|
1561 from overriding motion of point in order to display at this exact start.
|
20
|
1562 */
|
|
1563 (window, pos, noforce))
|
0
|
1564 {
|
|
1565 struct window *w = decode_window (window);
|
|
1566
|
|
1567 CHECK_INT_COERCE_MARKER (pos);
|
|
1568 set_marker_restricted (w->start[CURRENT_DISP], pos, w->buffer);
|
|
1569 /* this is not right, but much easier than doing what is right. */
|
|
1570 w->start_at_line_beg = 0;
|
|
1571 if (NILP (noforce))
|
|
1572 w->force_start = 1;
|
|
1573 w->redo_modeline = 1;
|
|
1574 SET_LAST_MODIFIED (w, 0);
|
|
1575 SET_LAST_FACECHANGE (w);
|
|
1576
|
|
1577 MARK_WINDOWS_CHANGED (w);
|
|
1578
|
|
1579 return pos;
|
|
1580 }
|
|
1581
|
20
|
1582 DEFUN ("window-dedicated-p", Fwindow_dedicated_p, 1, 1, 0, /*
|
0
|
1583 Return WINDOW's dedicated object, usually t or nil.
|
|
1584 See also `set-window-dedicated-p'.
|
20
|
1585 */
|
|
1586 (window))
|
0
|
1587 {
|
|
1588 return decode_window (window)->dedicated;
|
|
1589 }
|
|
1590
|
20
|
1591 DEFUN ("set-window-dedicated-p", Fset_window_dedicated_p, 2, 2, 0, /*
|
0
|
1592 Control whether WINDOW is dedicated to the buffer it displays.
|
|
1593 If it is dedicated, Emacs will not automatically change
|
|
1594 which buffer appears in it.
|
|
1595 The second argument is the new value for the dedication flag;
|
|
1596 non-nil means yes.
|
20
|
1597 */
|
|
1598 (window, arg))
|
0
|
1599 {
|
272
|
1600 struct window *w = decode_window (window);
|
0
|
1601
|
149
|
1602 w->dedicated = NILP (arg) ? Qnil : Qt;
|
0
|
1603
|
|
1604 return w->dedicated;
|
|
1605 }
|
|
1606
|
|
1607 /* FSFmacs has window-display-table here. We have display table as a
|
|
1608 specifier. */
|
|
1609
|
|
1610
|
|
1611 /* Record info on buffer window w is displaying
|
|
1612 when it is about to cease to display that buffer. */
|
|
1613 static void
|
|
1614 unshow_buffer (struct window *w)
|
|
1615 {
|
|
1616 Lisp_Object buf = w->buffer;
|
|
1617
|
|
1618 if (XBUFFER (buf) != XMARKER (w->pointm[CURRENT_DISP])->buffer)
|
|
1619 abort ();
|
|
1620
|
|
1621 /* FSF disables this check, so I'll do it too. I hope it won't
|
|
1622 break things. --ben */
|
|
1623 #if 0
|
|
1624 if (w == XWINDOW (Fselected_window (Qnil))
|
|
1625 || ! EQ (buf, XWINDOW (Fselected_window (Qnil))->buffer))
|
|
1626 /* Do this except when the selected window's buffer
|
|
1627 is being removed from some other window. */
|
|
1628 #endif
|
|
1629 /* last_window_start records the start position that this buffer
|
|
1630 had in the last window to be disconnected from it.
|
|
1631 Now that this statement is unconditional,
|
|
1632 it is possible for the buffer to be displayed in the
|
|
1633 selected window, while last_window_start reflects another
|
|
1634 window which was recently showing the same buffer.
|
|
1635 Some people might say that might be a good thing. Let's see. */
|
|
1636 XBUFFER (buf)->last_window_start =
|
|
1637 marker_position (w->start[CURRENT_DISP]);
|
|
1638
|
|
1639 /* Point in the selected window's buffer
|
|
1640 is actually stored in that buffer, and the window's pointm isn't used.
|
|
1641 So don't clobber point in that buffer. */
|
|
1642 if (! EQ (buf, XWINDOW (Fselected_window (Qnil))->buffer))
|
|
1643 {
|
|
1644 struct buffer *b= XBUFFER (buf);
|
|
1645 BUF_SET_PT (b, bufpos_clip_to_bounds (BUF_BEGV (b),
|
|
1646 marker_position (w->pointm[CURRENT_DISP]),
|
|
1647 BUF_ZV (b)));
|
|
1648 }
|
|
1649 }
|
|
1650
|
|
1651 /* Put REPLACEMENT into the window structure in place of OLD. */
|
|
1652 static void
|
|
1653 replace_window (Lisp_Object old, Lisp_Object replacement)
|
|
1654 {
|
|
1655 Lisp_Object tem;
|
|
1656 struct window *o = XWINDOW (old), *p = XWINDOW (replacement);
|
|
1657
|
|
1658 /* If OLD is its frame's root_window, then replacement is the new
|
|
1659 root_window for that frame. */
|
|
1660
|
|
1661 if (EQ (old, FRAME_ROOT_WINDOW (XFRAME (o->frame))))
|
|
1662 FRAME_ROOT_WINDOW (XFRAME (o->frame)) = replacement;
|
|
1663
|
|
1664 WINDOW_LEFT (p) = WINDOW_LEFT (o);
|
|
1665 WINDOW_TOP (p) = WINDOW_TOP (o);
|
|
1666 WINDOW_WIDTH (p) = WINDOW_WIDTH (o);
|
|
1667 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o);
|
|
1668
|
|
1669 p->next = tem = o->next;
|
|
1670 if (!NILP (tem))
|
|
1671 XWINDOW (tem)->prev = replacement;
|
|
1672
|
|
1673 p->prev = tem = o->prev;
|
|
1674 if (!NILP (tem))
|
|
1675 XWINDOW (tem)->next = replacement;
|
|
1676
|
|
1677 p->parent = tem = o->parent;
|
|
1678 if (!NILP (tem))
|
|
1679 {
|
|
1680 if (EQ (XWINDOW (tem)->vchild, old))
|
|
1681 XWINDOW (tem)->vchild = replacement;
|
|
1682 if (EQ (XWINDOW (tem)->hchild, old))
|
|
1683 XWINDOW (tem)->hchild = replacement;
|
|
1684 }
|
|
1685
|
|
1686 /* #### Here, if replacement is a vertical combination
|
|
1687 and so is its new parent, we should make replacement's
|
|
1688 children be children of that parent instead. */
|
|
1689 }
|
|
1690
|
|
1691 /* we're deleting W; set the structure of W to indicate this. */
|
|
1692
|
|
1693 static void
|
|
1694 mark_window_as_deleted (struct window *w)
|
|
1695 {
|
|
1696 /* In the loop
|
|
1697 (while t (split-window) (delete-window))
|
|
1698 we end up with a tree of deleted windows which are all connected
|
|
1699 through the `next' slot. This might not seem so bad, as they're
|
|
1700 deleted, and will presumably be GCed - but if even *one* of those
|
|
1701 windows is still being pointed to, by the user, or by a window
|
|
1702 configuration, then *all* of those windows stick around.
|
|
1703
|
|
1704 Since the window-configuration code doesn't need any of the
|
|
1705 pointers to other windows (they are all recreated from the
|
|
1706 window-config data), we set them all to nil so that we
|
|
1707 are able to collect more actual garbage.
|
|
1708 */
|
|
1709 w->next = Qnil;
|
|
1710 w->prev = Qnil;
|
|
1711 w->hchild = Qnil;
|
|
1712 w->vchild = Qnil;
|
|
1713 w->parent = Qnil;
|
|
1714
|
|
1715 w->dead = 1;
|
|
1716
|
|
1717 /* Free the extra data structures attached to windows immediately so
|
|
1718 they don't sit around consuming excess space. They will be
|
|
1719 reinitialized by the window-configuration code as necessary. */
|
|
1720 finalize_window ((void *) w, 0);
|
|
1721 }
|
|
1722
|
20
|
1723 DEFUN ("delete-window", Fdelete_window, 0, 2, "", /*
|
0
|
1724 Remove WINDOW from the display. Default is selected window.
|
|
1725 If window is the only one on the frame, the frame is destroyed.
|
|
1726 Normally, you cannot delete the last non-minibuffer-only frame (you must
|
|
1727 use `save-buffers-kill-emacs' or `kill-emacs'). However, if optional
|
|
1728 second argument FORCE is non-nil, you can delete the last frame. (This
|
|
1729 will automatically call `save-buffers-kill-emacs'.)
|
20
|
1730 */
|
|
1731 (window, force))
|
0
|
1732 {
|
|
1733 /* This function can GC if this is the only window in the frame */
|
|
1734 struct window *w;
|
|
1735 Lisp_Object parent;
|
|
1736 struct window *par;
|
|
1737 Lisp_Object frame;
|
|
1738 struct frame *f;
|
|
1739 struct device *d;
|
|
1740
|
|
1741 /* Note: this function is called by other C code on non-leaf
|
|
1742 windows. */
|
|
1743
|
|
1744 /* Do the equivalent of decode_window() but don't error out on
|
|
1745 deleted window; it's OK to delete an already-deleted window. */
|
|
1746 if (NILP (window))
|
|
1747 window = Fselected_window (Qnil);
|
|
1748 else
|
|
1749 CHECK_WINDOW (window);
|
|
1750 w = XWINDOW (window);
|
|
1751
|
|
1752 /* It's okay to delete an already-deleted window. */
|
|
1753 if (! WINDOW_LIVE_P (w))
|
|
1754 return Qnil;
|
|
1755
|
|
1756 frame = WINDOW_FRAME (w);
|
|
1757 f = XFRAME (frame);
|
|
1758 d = XDEVICE (FRAME_DEVICE (f));
|
|
1759
|
|
1760 if (TOP_LEVEL_WINDOW_P (w))
|
|
1761 {
|
|
1762 if (NILP (memq_no_quit (frame, DEVICE_FRAME_LIST (d))))
|
|
1763 /* this frame isn't fully initialized yet; don't blow up. */
|
|
1764 return Qnil;
|
|
1765
|
|
1766 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
1767 error ("Attempt to delete the minibuffer window");
|
|
1768
|
|
1769 /* It has been suggested that it's a good thing for C-x 0 to have this
|
|
1770 behavior, but not such a good idea for #'delete-window to have it.
|
|
1771 Maybe C-x 0 should be bound to something else, or maybe frame
|
|
1772 deletion should only happen when this is called interactively.
|
|
1773 */
|
|
1774 delete_frame_internal (f, !NILP (force), 0, 0);
|
|
1775 return Qnil;
|
|
1776 }
|
|
1777
|
|
1778 /* At this point, we know the window has a parent. */
|
|
1779 parent = w->parent;
|
|
1780 par = XWINDOW (parent);
|
|
1781
|
|
1782 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
1783
|
|
1784 /* Are we trying to delete any frame's selected window?
|
|
1785 Note that we could be dealing with a non-leaf window
|
|
1786 where the selected window is one of our children.
|
|
1787 So, we check by scanning all the ancestors of the
|
|
1788 frame's selected window and comparing each one with
|
|
1789 WINDOW. */
|
|
1790 {
|
|
1791 Lisp_Object pwindow;
|
185
|
1792
|
0
|
1793 pwindow = FRAME_SELECTED_WINDOW (f);
|
185
|
1794
|
0
|
1795 while (!NILP (pwindow))
|
|
1796 {
|
|
1797 if (EQ (window, pwindow))
|
|
1798 break;
|
|
1799 pwindow = XWINDOW (pwindow)->parent;
|
|
1800 }
|
|
1801
|
|
1802 if (EQ (window, pwindow))
|
|
1803 {
|
|
1804 /* OK, we found it. */
|
|
1805 Lisp_Object alternative;
|
|
1806 alternative = Fnext_window (window, Qlambda, Qnil, Qnil);
|
185
|
1807
|
0
|
1808 /* If we're about to delete the selected window on the
|
|
1809 selected frame, then we should use Fselect_window to select
|
|
1810 the new window. On the other hand, if we're about to
|
|
1811 delete the selected window on any other frame, we shouldn't do
|
|
1812 anything but set the frame's selected_window slot. */
|
|
1813 if (EQ (frame, Fselected_frame (Qnil)))
|
282
|
1814 Fselect_window (alternative, Qnil);
|
0
|
1815 else
|
|
1816 set_frame_selected_window (f, alternative);
|
|
1817 }
|
|
1818 }
|
|
1819
|
|
1820 /* w->buffer is nil in a non-leaf window; in this case,
|
|
1821 get rid of the markers we maintain that point into that buffer. */
|
|
1822 if (!NILP (w->buffer))
|
|
1823 {
|
|
1824 unshow_buffer (w);
|
|
1825 unchain_marker (w->pointm[CURRENT_DISP]);
|
|
1826 unchain_marker (w->pointm[DESIRED_DISP]);
|
|
1827 unchain_marker (w->pointm[CMOTION_DISP]);
|
|
1828 unchain_marker (w->start[CURRENT_DISP]);
|
|
1829 unchain_marker (w->start[DESIRED_DISP]);
|
|
1830 unchain_marker (w->start[CMOTION_DISP]);
|
|
1831 unchain_marker (w->sb_point);
|
|
1832 /* This breaks set-window-configuration if windows in the saved
|
|
1833 configuration get deleted and multiple frames are in use. */
|
|
1834 /* w->buffer = Qnil; */
|
|
1835 }
|
185
|
1836
|
0
|
1837 /* close up the hole in the sibling list */
|
|
1838 if (!NILP (w->next))
|
|
1839 XWINDOW (w->next)->prev = w->prev;
|
|
1840 if (!NILP (w->prev))
|
|
1841 XWINDOW (w->prev)->next = w->next;
|
|
1842 if (EQ (window, par->hchild))
|
|
1843 par->hchild = w->next;
|
|
1844 if (EQ (window, par->vchild))
|
|
1845 par->vchild = w->next;
|
|
1846
|
|
1847 /* Find one of our siblings to give our space to. */
|
|
1848 {
|
|
1849 Lisp_Object sib = w->prev;
|
|
1850 if (NILP (sib))
|
|
1851 {
|
|
1852 /* If w gives its space to its next sibling, that sibling needs
|
|
1853 to have its top/left side pulled back to where w's is.
|
|
1854 set_window_{height,width} will re-position the sibling's
|
|
1855 children. */
|
|
1856 sib = w->next;
|
|
1857 WINDOW_TOP (XWINDOW (sib)) = WINDOW_TOP (w);
|
|
1858 WINDOW_LEFT (XWINDOW (sib)) = WINDOW_LEFT (w);
|
|
1859 }
|
185
|
1860
|
0
|
1861 /* Stretch that sibling. */
|
|
1862 if (!NILP (par->vchild))
|
|
1863 set_window_pixheight
|
|
1864 (sib, (WINDOW_HEIGHT (XWINDOW (sib)) + WINDOW_HEIGHT (w)), 1);
|
|
1865 if (!NILP (par->hchild))
|
|
1866 set_window_pixwidth
|
|
1867 (sib, (WINDOW_WIDTH (XWINDOW (sib)) + WINDOW_WIDTH (w)), 1);
|
|
1868 }
|
|
1869
|
|
1870 /* If parent now has only one child,
|
|
1871 put the child into the parent's place. */
|
|
1872 {
|
|
1873 Lisp_Object parchild = par->hchild;
|
|
1874 if (NILP (parchild))
|
|
1875 parchild = par->vchild;
|
|
1876 if (NILP (XWINDOW (parchild)->next))
|
|
1877 {
|
|
1878 replace_window (parent, parchild);
|
|
1879 mark_window_as_deleted (XWINDOW (parent));
|
|
1880 }
|
|
1881 }
|
|
1882
|
|
1883 /* Since we may be deleting combination windows, we must make sure that
|
|
1884 not only W but all its children have been marked as deleted. */
|
|
1885 if (!NILP (w->hchild))
|
|
1886 delete_all_subwindows (XWINDOW (w->hchild));
|
|
1887 else if (!NILP (w->vchild))
|
|
1888 delete_all_subwindows (XWINDOW (w->vchild));
|
|
1889
|
|
1890 mark_window_as_deleted (w);
|
|
1891
|
|
1892 f->mirror_dirty = 1;
|
|
1893 return Qnil;
|
|
1894 }
|
|
1895
|
|
1896
|
20
|
1897 DEFUN ("next-window", Fnext_window, 0, 4, 0, /*
|
0
|
1898 Return next window after WINDOW in canonical ordering of windows.
|
|
1899 If omitted, WINDOW defaults to the selected window.
|
|
1900
|
|
1901 Optional second arg MINIBUF t means count the minibuffer window even
|
|
1902 if not active. MINIBUF nil or omitted means count the minibuffer iff
|
|
1903 it is active. MINIBUF neither t nor nil means not to count the
|
|
1904 minibuffer even if it is active.
|
|
1905
|
|
1906 Several frames may share a single minibuffer; if the minibuffer
|
|
1907 counts, all windows on all frames that share that minibuffer count
|
|
1908 too. Therefore, `next-window' can be used to iterate through the
|
|
1909 set of windows even when the minibuffer is on another frame. If the
|
|
1910 minibuffer does not count, only windows from WINDOW's frame count.
|
|
1911
|
|
1912 Optional third arg ALL-FRAMES t means include windows on all frames.
|
|
1913 ALL-FRAMES nil or omitted means cycle within the frames as specified
|
|
1914 above. ALL-FRAMES = `visible' means include windows on all visible frames.
|
|
1915 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
|
|
1916 If ALL-FRAMES is a frame, restrict search to windows on that frame.
|
|
1917 Anything else means restrict to WINDOW's frame.
|
|
1918
|
|
1919 Optional fourth argument CONSOLE controls which consoles or devices the
|
|
1920 returned window may be on. If CONSOLE is a console, return windows only
|
|
1921 on that console. If CONSOLE is a device, return windows only on that
|
|
1922 device. If CONSOLE is a console type, return windows only on consoles
|
|
1923 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
1924 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
1925 on WINDOW's console. Otherwise, all windows are considered.
|
|
1926
|
|
1927 If you use consistent values for MINIBUF, ALL-FRAMES, and CONSOLE, you
|
|
1928 can use `next-window' to iterate through the entire cycle of acceptable
|
|
1929 windows, eventually ending up back at the window you started with.
|
|
1930 `previous-window' traverses the same cycle, in the reverse order.
|
20
|
1931 */
|
70
|
1932 (window, minibuf, all_frames, console))
|
0
|
1933 {
|
|
1934 Lisp_Object tem;
|
|
1935 Lisp_Object start_window;
|
|
1936
|
|
1937 if (NILP (window))
|
|
1938 window = Fselected_window (Qnil);
|
|
1939 else
|
|
1940 CHECK_LIVE_WINDOW (window);
|
|
1941
|
|
1942 start_window = window;
|
|
1943
|
|
1944 /* minibuf == nil may or may not include minibuffers.
|
|
1945 Decide if it does. */
|
|
1946 if (NILP (minibuf))
|
|
1947 minibuf = (minibuf_level ? minibuf_window : Qlambda);
|
|
1948 else if (! EQ (minibuf, Qt))
|
|
1949 minibuf = Qlambda;
|
|
1950 /* Now minibuf can be t => count all minibuffer windows,
|
|
1951 lambda => count none of them,
|
|
1952 or a specific minibuffer window (the active one) to count. */
|
|
1953
|
|
1954 /* all_frames == nil doesn't specify which frames to include. */
|
|
1955 if (NILP (all_frames))
|
|
1956 all_frames = (! EQ (minibuf, Qlambda)
|
|
1957 ? (FRAME_MINIBUF_WINDOW
|
|
1958 (XFRAME
|
|
1959 (WINDOW_FRAME
|
|
1960 (XWINDOW (window)))))
|
|
1961 : Qnil);
|
|
1962 else if (EQ (all_frames, Qvisible))
|
|
1963 ;
|
|
1964 else if (ZEROP (all_frames))
|
|
1965 ;
|
|
1966 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
|
|
1967 /* If all_frames is a frame and window arg isn't on that frame, just
|
|
1968 return the first window on the frame. */
|
|
1969 return frame_first_window (XFRAME (all_frames));
|
|
1970 else if (! EQ (all_frames, Qt))
|
|
1971 all_frames = Qnil;
|
|
1972 /* Now all_frames is t meaning search all frames,
|
|
1973 nil meaning search just current frame,
|
|
1974 visible meaning search just visible frames,
|
|
1975 0 meaning search visible and iconified frames,
|
|
1976 or a window, meaning search the frame that window belongs to. */
|
|
1977
|
|
1978 /* Do this loop at least once, to get the next window, and perhaps
|
|
1979 again, if we hit the minibuffer and that is not acceptable. */
|
|
1980 do
|
|
1981 {
|
|
1982 /* Find a window that actually has a next one. This loop
|
|
1983 climbs up the tree. */
|
|
1984 while (tem = XWINDOW (window)->next, NILP (tem))
|
|
1985 if (tem = XWINDOW (window)->parent, !NILP (tem))
|
|
1986 window = tem;
|
|
1987 else /* window must be minibuffer window now */
|
|
1988 {
|
|
1989 /* We've reached the end of this frame.
|
|
1990 Which other frames are acceptable? */
|
|
1991 tem = WINDOW_FRAME (XWINDOW (window));
|
|
1992
|
|
1993 if (! NILP (all_frames))
|
|
1994 {
|
|
1995 Lisp_Object tem1;
|
|
1996
|
|
1997 tem1 = tem;
|
|
1998 tem = next_frame (tem, all_frames, console);
|
|
1999 /* In the case where the minibuffer is active,
|
|
2000 and we include its frame as well as the selected one,
|
|
2001 next_frame may get stuck in that frame.
|
|
2002 If that happens, go back to the selected frame
|
|
2003 so we can complete the cycle. */
|
|
2004 if (EQ (tem, tem1))
|
|
2005 XSETFRAME (tem, selected_frame ());
|
|
2006 }
|
|
2007
|
|
2008 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
|
|
2009 break;
|
|
2010 }
|
|
2011
|
|
2012 window = tem;
|
|
2013
|
|
2014 /* If we're in a combination window, find its first child and
|
|
2015 recurse on that. Otherwise, we've found the window we want. */
|
|
2016 while (1)
|
|
2017 {
|
|
2018 if (!NILP (XWINDOW (window)->hchild))
|
|
2019 window = XWINDOW (window)->hchild;
|
|
2020 else if (!NILP (XWINDOW (window)->vchild))
|
|
2021 window = XWINDOW (window)->vchild;
|
|
2022 else break;
|
|
2023 }
|
|
2024 }
|
|
2025 /* "acceptable" is the correct spelling. */
|
|
2026 /* Which windows are acceptable?
|
|
2027 Exit the loop and accept this window if
|
|
2028 this isn't a minibuffer window,
|
|
2029 or we're accepting all minibuffer windows,
|
|
2030 or this is the active minibuffer and we are accepting that one, or
|
|
2031 we've come all the way around and we're back at the original window. */
|
|
2032 while (MINI_WINDOW_P (XWINDOW (window))
|
|
2033 && ! EQ (minibuf, Qt)
|
|
2034 && ! EQ (minibuf, window)
|
|
2035 && ! EQ (window, start_window));
|
|
2036
|
|
2037 return window;
|
|
2038 }
|
|
2039
|
20
|
2040 DEFUN ("previous-window", Fprevious_window, 0, 4, 0, /*
|
110
|
2041 Return the window preceding WINDOW in canonical ordering of windows.
|
0
|
2042 If omitted, WINDOW defaults to the selected window.
|
|
2043
|
|
2044 Optional second arg MINIBUF t means count the minibuffer window even
|
|
2045 if not active. MINIBUF nil or omitted means count the minibuffer iff
|
|
2046 it is active. MINIBUF neither t nor nil means not to count the
|
|
2047 minibuffer even if it is active.
|
|
2048
|
|
2049 Several frames may share a single minibuffer; if the minibuffer
|
|
2050 counts, all windows on all frames that share that minibuffer count
|
|
2051 too. Therefore, `previous-window' can be used to iterate through
|
|
2052 the set of windows even when the minibuffer is on another frame. If
|
|
2053 the minibuffer does not count, only windows from WINDOW's frame count
|
|
2054
|
|
2055 If optional third arg ALL-FRAMES t means include windows on all frames.
|
|
2056 ALL-FRAMES nil or omitted means cycle within the frames as specified
|
|
2057 above. ALL-FRAMES = `visible' means include windows on all visible frames.
|
|
2058 ALL-FRAMES = 0 means include windows on all visible and iconified frames.
|
|
2059 If ALL-FRAMES is a frame, restrict search to windows on that frame.
|
|
2060 Anything else means restrict to WINDOW's frame.
|
|
2061
|
|
2062 Optional fourth argument CONSOLE controls which consoles or devices the
|
|
2063 returned window may be on. If CONSOLE is a console, return windows only
|
|
2064 on that console. If CONSOLE is a device, return windows only on that
|
|
2065 device. If CONSOLE is a console type, return windows only on consoles
|
|
2066 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2067 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2068 on WINDOW's console. Otherwise, all windows are considered.
|
|
2069
|
|
2070 If you use consistent values for MINIBUF, ALL-FRAMES, and CONSOLE, you
|
|
2071 can use `previous-window' to iterate through the entire cycle of acceptable
|
|
2072 windows, eventually ending up back at the window you started with.
|
|
2073 `next-window' traverses the same cycle, in the reverse order.
|
20
|
2074 */
|
70
|
2075 (window, minibuf, all_frames, console))
|
0
|
2076 {
|
|
2077 Lisp_Object tem;
|
|
2078 Lisp_Object start_window;
|
|
2079
|
|
2080 if (NILP (window))
|
|
2081 window = Fselected_window (Qnil);
|
|
2082 else
|
|
2083 CHECK_LIVE_WINDOW (window);
|
|
2084
|
|
2085 start_window = window;
|
|
2086
|
|
2087 /* minibuf == nil may or may not include minibuffers.
|
|
2088 Decide if it does. */
|
|
2089 if (NILP (minibuf))
|
|
2090 minibuf = (minibuf_level ? minibuf_window : Qlambda);
|
|
2091 else if (! EQ (minibuf, Qt))
|
|
2092 minibuf = Qlambda;
|
|
2093 /* Now minibuf can be t => count all minibuffer windows,
|
|
2094 lambda => count none of them,
|
|
2095 or a specific minibuffer window (the active one) to count. */
|
|
2096
|
|
2097 /* all_frames == nil doesn't specify which frames to include.
|
|
2098 Decide which frames it includes. */
|
|
2099 if (NILP (all_frames))
|
|
2100 all_frames = (! EQ (minibuf, Qlambda)
|
|
2101 ? (FRAME_MINIBUF_WINDOW
|
|
2102 (XFRAME
|
|
2103 (WINDOW_FRAME
|
|
2104 (XWINDOW (window)))))
|
|
2105 : Qnil);
|
|
2106 else if (EQ (all_frames, Qvisible))
|
|
2107 ;
|
|
2108 else if (ZEROP (all_frames))
|
|
2109 ;
|
|
2110 else if (FRAMEP (all_frames) && ! EQ (all_frames, Fwindow_frame (window)))
|
|
2111 /* If all_frames is a frame and window arg isn't on that frame, just
|
|
2112 return the first window on the frame. */
|
|
2113 return frame_first_window (XFRAME (all_frames));
|
|
2114 else if (! EQ (all_frames, Qt))
|
|
2115 all_frames = Qnil;
|
|
2116 /* Now all_frames is t meaning search all frames,
|
|
2117 nil meaning search just current frame,
|
|
2118 visible meaning search just visible frames,
|
|
2119 0 meaning search visible and iconified frames,
|
|
2120 or a window, meaning search the frame that window belongs to. */
|
|
2121
|
|
2122 /* Do this loop at least once, to get the next window, and perhaps
|
|
2123 again, if we hit the minibuffer and that is not acceptable. */
|
|
2124 do
|
|
2125 {
|
|
2126 /* Find a window that actually has a next one. This loop
|
|
2127 climbs up the tree. */
|
|
2128 while (tem = XWINDOW (window)->prev, NILP (tem))
|
|
2129 if (tem = XWINDOW (window)->parent, !NILP (tem))
|
|
2130 window = tem;
|
|
2131 else /* window must be minibuffer window now */
|
|
2132 {
|
|
2133 /* We have found the top window on the frame.
|
|
2134 Which frames are acceptable? */
|
|
2135 tem = WINDOW_FRAME (XWINDOW (window));
|
|
2136
|
|
2137 if (! NILP (all_frames))
|
|
2138 /* It's actually important that we use prev_frame here,
|
|
2139 rather than next_frame. All the windows acceptable
|
|
2140 according to the given parameters should form a ring;
|
|
2141 Fnext_window and Fprevious_window should go back and
|
|
2142 forth around the ring. If we use next_frame here,
|
|
2143 then Fnext_window and Fprevious_window take different
|
|
2144 paths through the set of acceptable windows.
|
|
2145 window_loop assumes that these `ring' requirement are
|
|
2146 met. */
|
|
2147 {
|
|
2148 Lisp_Object tem1;
|
|
2149
|
|
2150 tem1 = tem;
|
|
2151 tem = prev_frame (tem, all_frames, console);
|
|
2152 /* In the case where the minibuffer is active,
|
|
2153 and we include its frame as well as the selected one,
|
|
2154 next_frame may get stuck in that frame.
|
|
2155 If that happens, go back to the selected frame
|
|
2156 so we can complete the cycle. */
|
|
2157 if (EQ (tem, tem1))
|
|
2158 XSETFRAME (tem, selected_frame ());
|
|
2159 }
|
|
2160
|
|
2161 /* If this frame has a minibuffer, find that window first,
|
|
2162 because it is conceptually the last window in that frame. */
|
|
2163 if (FRAME_HAS_MINIBUF_P (XFRAME (tem)))
|
|
2164 tem = FRAME_MINIBUF_WINDOW (XFRAME (tem));
|
|
2165 else
|
|
2166 tem = FRAME_ROOT_WINDOW (XFRAME (tem));
|
|
2167
|
|
2168 break;
|
|
2169 }
|
|
2170
|
|
2171 window = tem;
|
|
2172
|
|
2173 /* If we're in a combination window, find its first child and
|
|
2174 recurse on that. Otherwise, we've found the window we want. */
|
|
2175 while (1)
|
|
2176 {
|
|
2177 if (!NILP (XWINDOW (window)->hchild))
|
|
2178 window = XWINDOW (window)->hchild;
|
|
2179 else if (!NILP (XWINDOW (window)->vchild))
|
|
2180 window = XWINDOW (window)->vchild;
|
|
2181 else break;
|
|
2182 while (tem = XWINDOW (window)->next, !NILP (tem))
|
|
2183 window = tem;
|
|
2184 }
|
|
2185 }
|
|
2186 /* Which windows are acceptable?
|
|
2187 Exit the loop and accept this window if
|
|
2188 this isn't a minibuffer window,
|
|
2189 or we're accepting all minibuffer windows,
|
|
2190 or this is the active minibuffer and we are accepting that one, or
|
|
2191 we've come all the way around and we're back at the original window. */
|
|
2192 while (MINI_WINDOW_P (XWINDOW (window))
|
|
2193 && ! EQ (minibuf, Qt)
|
|
2194 && ! EQ (minibuf, window)
|
|
2195 && ! EQ (window, start_window));
|
|
2196
|
|
2197 return window;
|
|
2198 }
|
|
2199
|
20
|
2200 DEFUN ("next-vertical-window", Fnext_vertical_window, 0, 1, 0, /*
|
0
|
2201 Return the next window which is vertically after WINDOW.
|
20
|
2202 */
|
|
2203 (window))
|
0
|
2204 {
|
|
2205 Lisp_Object root;
|
|
2206 struct window *w = decode_window (window);
|
|
2207 XSETWINDOW (window, w);
|
|
2208
|
|
2209 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
2210 return Qnil;
|
|
2211
|
|
2212 root = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (XWINDOW (window))));
|
|
2213
|
|
2214 if (EQ (window, root))
|
|
2215 {
|
|
2216 while (1)
|
|
2217 if (!NILP (XWINDOW (window)->hchild))
|
|
2218 window = XWINDOW (window)->hchild;
|
|
2219 else if (!NILP (XWINDOW (window)->vchild))
|
|
2220 window = XWINDOW (window)->vchild;
|
|
2221 else
|
|
2222 return window;
|
|
2223 }
|
|
2224
|
|
2225 do
|
|
2226 {
|
|
2227 if (!NILP (XWINDOW (window)->parent) &&
|
|
2228 !NILP (XWINDOW (XWINDOW (window)->parent)->vchild))
|
|
2229 {
|
|
2230 if (!NILP (XWINDOW (window)->next))
|
|
2231 return XWINDOW (window)->next;
|
|
2232 else
|
|
2233 window = XWINDOW (window)->parent;
|
|
2234 }
|
|
2235 else
|
|
2236 window = XWINDOW (window)->parent;
|
|
2237 }
|
|
2238 while (!EQ (window, root));
|
|
2239
|
|
2240 while (1)
|
|
2241 if (!NILP (XWINDOW (window)->hchild))
|
|
2242 window = XWINDOW (window)->hchild;
|
|
2243 else if (!NILP (XWINDOW (window)->vchild))
|
|
2244 window = XWINDOW (window)->vchild;
|
|
2245 else
|
|
2246 return window;
|
|
2247 }
|
|
2248
|
20
|
2249 DEFUN ("other-window", Fother_window, 1, 3, "p", /*
|
0
|
2250 Select the N'th different window on this frame.
|
|
2251 All windows on current frame are arranged in a cyclic order.
|
|
2252 This command selects the window N steps away in that order.
|
|
2253 A negative N moves in the opposite order.
|
|
2254
|
|
2255 If optional argument FRAME is `visible', search all visible frames.
|
|
2256 If FRAME is 0, search all visible and iconified frames.
|
|
2257 If FRAME is t, search all frames.
|
|
2258 If FRAME is nil, search only the selected frame.
|
|
2259 If FRAME is a frame, search only that frame.
|
|
2260
|
|
2261 Optional third argument CONSOLE controls which consoles or devices the
|
|
2262 returned window may be on. If CONSOLE is a console, return windows only
|
|
2263 on that console. If CONSOLE is a device, return windows only on that
|
|
2264 device. If CONSOLE is a console type, return windows only on consoles
|
|
2265 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2266 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2267 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2268 Otherwise, all windows are considered.
|
20
|
2269 */
|
|
2270 (n, frame, console))
|
0
|
2271 {
|
|
2272 int i;
|
|
2273 Lisp_Object w;
|
|
2274
|
|
2275 CHECK_INT (n);
|
|
2276 w = Fselected_window (Qnil);
|
|
2277 i = XINT (n);
|
|
2278
|
|
2279 while (i > 0)
|
|
2280 {
|
|
2281 w = Fnext_window (w, Qnil, frame, console);
|
|
2282 i--;
|
|
2283 }
|
|
2284 while (i < 0)
|
|
2285 {
|
|
2286 w = Fprevious_window (w, Qnil, frame, console);
|
|
2287 i++;
|
|
2288 }
|
282
|
2289 Fselect_window (w, Qnil);
|
0
|
2290 return Qnil;
|
|
2291 }
|
|
2292
|
|
2293
|
|
2294 /* Look at all windows, performing an operation specified by TYPE
|
|
2295 with argument OBJ.
|
|
2296
|
|
2297 If FRAMES is Qt, look at all frames, if Qnil, look at just the selected
|
|
2298 frame. If FRAMES is a frame, just look at windows on that frame.
|
|
2299 If MINI is non-zero, perform the operation on minibuffer windows too.
|
|
2300 */
|
|
2301
|
|
2302 enum window_loop
|
|
2303 {
|
|
2304 WINDOW_LOOP_UNUSED,
|
|
2305 GET_BUFFER_WINDOW, /* Arg is buffer */
|
|
2306 GET_LRU_WINDOW, /* Arg is t for full-width windows only */
|
|
2307 DELETE_OTHER_WINDOWS, /* Arg is window not to delete */
|
|
2308 DELETE_BUFFER_WINDOWS, /* Arg is buffer */
|
|
2309 GET_LARGEST_WINDOW,
|
|
2310 UNSHOW_BUFFER, /* Arg is buffer */
|
|
2311 GET_BUFFER_WINDOW_COUNT, /* Arg is buffer */
|
|
2312 GET_BUFFER_MRU_WINDOW /* Arg is buffer */
|
|
2313 };
|
|
2314
|
|
2315 static Lisp_Object
|
|
2316 window_loop (enum window_loop type,
|
185
|
2317 Lisp_Object obj,
|
0
|
2318 int mini,
|
|
2319 Lisp_Object frames,
|
|
2320 int dedicated_too,
|
|
2321 Lisp_Object console)
|
|
2322 {
|
|
2323 /* This function can GC if type == DELETE_BUFFER_WINDOWS or UNSHOW_BUFFER */
|
|
2324 Lisp_Object w;
|
|
2325 Lisp_Object best_window = Qnil;
|
|
2326 Lisp_Object next_window;
|
|
2327 Lisp_Object last_window;
|
|
2328 struct frame *frame;
|
|
2329 Lisp_Object frame_arg = Qt;
|
|
2330 int count = 0; /* for GET_BUFFER_WINDOW_COUNT */
|
|
2331 /* #### I think the change of "precomputing" last_window and next_window
|
|
2332 * #### catch the lossage this is meant(?) to punt on...
|
|
2333 */
|
185
|
2334 int lose_lose = 0;
|
0
|
2335 Lisp_Object devcons, concons;
|
|
2336
|
|
2337 /* FRAME_ARG is Qlambda to stick to one frame,
|
|
2338 Qvisible to consider all visible frames,
|
|
2339 or Qt otherwise. */
|
|
2340
|
|
2341 /* If we're only looping through windows on a particular frame,
|
|
2342 FRAME points to that frame. If we're looping through windows
|
|
2343 on all frames, FRAME is 0. */
|
|
2344
|
|
2345 if (FRAMEP (frames))
|
|
2346 frame = XFRAME (frames);
|
|
2347 else if (NILP (frames))
|
|
2348 frame = selected_frame ();
|
|
2349 else
|
|
2350 frame = 0;
|
|
2351 if (frame)
|
|
2352 frame_arg = Qlambda;
|
|
2353 else if (ZEROP (frames))
|
|
2354 frame_arg = frames;
|
|
2355 else if (EQ (frames, Qvisible))
|
|
2356 frame_arg = frames;
|
185
|
2357
|
0
|
2358 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
2359 {
|
|
2360 Lisp_Object device = XCAR (devcons);
|
272
|
2361 Lisp_Object the_frame;
|
0
|
2362
|
|
2363 if (frame)
|
|
2364 XSETFRAME (the_frame, frame);
|
|
2365 else
|
|
2366 the_frame = DEVICE_SELECTED_FRAME (XDEVICE (device));
|
|
2367
|
|
2368 if (NILP (the_frame))
|
|
2369 continue;
|
|
2370
|
|
2371 if (!device_matches_console_spec (the_frame, device, console))
|
|
2372 continue;
|
|
2373
|
|
2374 /* Pick a window to start with. */
|
|
2375 if (WINDOWP (obj))
|
|
2376 w = obj;
|
|
2377 else
|
|
2378 w = FRAME_SELECTED_WINDOW (XFRAME (the_frame));
|
|
2379
|
|
2380 /* Figure out the last window we're going to mess with. Since
|
|
2381 Fnext_window, given the same options, is guaranteed to go in a
|
|
2382 ring, we can just use Fprevious_window to find the last one.
|
|
2383
|
|
2384 We can't just wait until we hit the first window again,
|
|
2385 because it might be deleted. */
|
|
2386
|
|
2387 last_window = Fprevious_window (w, mini ? Qt : Qnil, frame_arg, Qt);
|
|
2388
|
|
2389 best_window = Qnil;
|
|
2390 for (;;)
|
|
2391 {
|
|
2392 struct window *p = XWINDOW (w);
|
|
2393 struct frame *w_frame = XFRAME (WINDOW_FRAME (p));
|
|
2394
|
|
2395 /* Pick the next window now, since some operations will delete
|
|
2396 the current window. */
|
|
2397 next_window = Fnext_window (w, mini ? Qt : Qnil, frame_arg, Qt);
|
|
2398
|
|
2399 /* #### Still needed ?? */
|
185
|
2400 /* Given the outstanding quality of the rest of this code,
|
0
|
2401 I feel no shame about putting this piece of shit in. */
|
|
2402 if (++lose_lose >= 500)
|
|
2403 return Qnil;
|
|
2404
|
|
2405 /* Note that we do not pay attention here to whether
|
|
2406 the frame is visible, since Fnext_window skips non-visible frames
|
|
2407 if that is desired, under the control of frame_arg. */
|
|
2408 if (! MINI_WINDOW_P (p)
|
|
2409 || (mini && minibuf_level > 0))
|
|
2410 switch (type)
|
|
2411 {
|
|
2412 case GET_BUFFER_WINDOW:
|
|
2413 {
|
|
2414 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2415 return w;
|
|
2416 break;
|
|
2417 }
|
|
2418
|
|
2419 case GET_BUFFER_WINDOW_COUNT:
|
|
2420 {
|
|
2421 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2422 count++;
|
|
2423 break;
|
|
2424 }
|
|
2425
|
|
2426 case GET_LRU_WINDOW:
|
|
2427 {
|
|
2428 /* t as arg means consider only full-width windows */
|
|
2429 if (!NILP (obj)
|
|
2430 && !window_full_width_p (p))
|
|
2431 break;
|
|
2432 /* Ignore dedicated windows and minibuffers. */
|
|
2433 if (MINI_WINDOW_P (p)
|
|
2434 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2435 break;
|
|
2436 if (NILP (best_window)
|
|
2437 || (XINT (XWINDOW (best_window)->use_time)
|
|
2438 > XINT (p->use_time)))
|
|
2439 best_window = w;
|
|
2440 break;
|
|
2441 }
|
|
2442
|
|
2443 case GET_BUFFER_MRU_WINDOW:
|
|
2444 {
|
|
2445 /* #### what about the first check in GET_LRU_WINDOW? */
|
|
2446 /* Ignore dedicated windows and minibuffers. */
|
|
2447 if (MINI_WINDOW_P (p)
|
|
2448 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2449 break;
|
|
2450
|
|
2451 if (XBUFFER (p->buffer) == XBUFFER (obj))
|
|
2452 {
|
|
2453 if (NILP (best_window)
|
|
2454 || (XINT (XWINDOW (best_window)->use_time)
|
|
2455 < XINT (p->use_time)))
|
|
2456 best_window = w;
|
|
2457 }
|
|
2458 break;
|
|
2459 }
|
|
2460
|
|
2461 case DELETE_OTHER_WINDOWS:
|
|
2462 {
|
|
2463 /* Don't delete the last window on a frame; this can
|
|
2464 happen when the minibuffer is selected, and would
|
|
2465 cause the frame to be deleted. */
|
|
2466 if (p != XWINDOW (obj) && !TOP_LEVEL_WINDOW_P (XWINDOW (w)))
|
|
2467 Fdelete_window (w, Qnil);
|
|
2468 break;
|
|
2469 }
|
|
2470
|
|
2471 case DELETE_BUFFER_WINDOWS:
|
|
2472 {
|
|
2473 if (EQ (p->buffer, obj))
|
|
2474 {
|
|
2475 struct frame *f = XFRAME (WINDOW_FRAME (p));
|
|
2476
|
|
2477 /* If this window is dedicated, and in a frame
|
|
2478 of its own, kill the frame. */
|
|
2479 if (EQ (w, FRAME_ROOT_WINDOW (f))
|
|
2480 && !NILP (p->dedicated)
|
|
2481 && other_visible_frames (f))
|
|
2482 {
|
|
2483 /* Skip the other windows on this frame.
|
|
2484 There might be one, the minibuffer! */
|
|
2485 if (! EQ (w, last_window))
|
|
2486 while (f == XFRAME (WINDOW_FRAME
|
|
2487 (XWINDOW (next_window))))
|
|
2488 {
|
|
2489 /* As we go, check for the end of the
|
|
2490 loop. We mustn't start going
|
|
2491 around a second time. */
|
|
2492 if (EQ (next_window, last_window))
|
|
2493 {
|
|
2494 last_window = w;
|
|
2495 break;
|
|
2496 }
|
|
2497 next_window = Fnext_window (next_window,
|
|
2498 mini ? Qt : Qnil,
|
|
2499 frame_arg, Qt);
|
|
2500 }
|
|
2501 /* Now we can safely delete the frame. */
|
|
2502 Fdelete_frame (WINDOW_FRAME (p), Qnil);
|
|
2503 }
|
|
2504 else
|
|
2505 /* If we're deleting the buffer displayed in
|
|
2506 the only window on the frame, find a new
|
|
2507 buffer to display there. */
|
|
2508 if (NILP (p->parent))
|
|
2509 {
|
|
2510 Lisp_Object new_buffer;
|
|
2511 new_buffer = Fother_buffer (obj, Qnil, Qnil);
|
|
2512 if (NILP (new_buffer))
|
|
2513 new_buffer = Fget_buffer_create (QSscratch);
|
|
2514 Fset_window_buffer (w, new_buffer);
|
|
2515 if (EQ (w, Fselected_window (Qnil)))
|
|
2516 Fset_buffer (p->buffer);
|
|
2517 }
|
|
2518 else
|
|
2519 Fdelete_window (w, Qnil);
|
|
2520 }
|
|
2521 break;
|
|
2522 }
|
|
2523
|
|
2524 case GET_LARGEST_WINDOW:
|
|
2525 {
|
|
2526 /* Ignore dedicated windows and minibuffers. */
|
|
2527 if (MINI_WINDOW_P (p)
|
|
2528 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2529 break;
|
|
2530 {
|
|
2531 /* write the check as follows to avoid tripping
|
|
2532 error_check_window() --ben */
|
|
2533 struct window *b = NILP (best_window) ? 0 :
|
|
2534 XWINDOW (best_window);
|
|
2535 if (NILP (best_window)
|
|
2536 || ((WINDOW_HEIGHT (p) * WINDOW_WIDTH (p))
|
|
2537 > (WINDOW_HEIGHT (b) * WINDOW_WIDTH (b))))
|
|
2538 best_window = w;
|
|
2539 }
|
|
2540 break;
|
|
2541 }
|
|
2542
|
|
2543 case UNSHOW_BUFFER:
|
|
2544 {
|
|
2545 if (EQ (p->buffer, obj))
|
|
2546 {
|
|
2547 /* Find another buffer to show in this window. */
|
|
2548 Lisp_Object another_buffer =
|
|
2549 Fother_buffer (obj, Qnil, Qnil);
|
|
2550 if (NILP (another_buffer))
|
|
2551 another_buffer
|
|
2552 = Fget_buffer_create (QSscratch);
|
|
2553 /* If this window is dedicated, and in a frame
|
|
2554 of its own, kill the frame. */
|
|
2555 if (EQ (w, FRAME_ROOT_WINDOW (w_frame))
|
|
2556 && !NILP (p->dedicated)
|
|
2557 && other_visible_frames (w_frame))
|
|
2558 {
|
|
2559 /* Skip the other windows on this frame.
|
|
2560 There might be one, the minibuffer! */
|
|
2561 if (! EQ (w, last_window))
|
|
2562 while (w_frame == XFRAME (WINDOW_FRAME
|
|
2563 (XWINDOW (next_window))))
|
|
2564 {
|
|
2565 /* As we go, check for the end of the
|
|
2566 loop. We mustn't start going
|
|
2567 around a second time. */
|
|
2568 if (EQ (next_window, last_window))
|
|
2569 {
|
|
2570 last_window = w;
|
|
2571 break;
|
|
2572 }
|
|
2573 next_window = Fnext_window (next_window,
|
|
2574 mini ? Qt : Qnil,
|
|
2575 frame_arg, Qt);
|
|
2576 }
|
|
2577 /* Now we can safely delete the frame. */
|
|
2578 delete_frame_internal (XFRAME (WINDOW_FRAME (p)),
|
|
2579 0, 0, 0);
|
|
2580 }
|
|
2581 else
|
|
2582 {
|
|
2583 /* Otherwise show a different buffer in the
|
|
2584 window. */
|
|
2585 p->dedicated = Qnil;
|
|
2586 Fset_window_buffer (w, another_buffer);
|
|
2587 if (EQ (w, Fselected_window (Qnil)))
|
|
2588 Fset_buffer (p->buffer);
|
|
2589 }
|
|
2590 }
|
|
2591 break;
|
|
2592 }
|
|
2593
|
185
|
2594 default:
|
0
|
2595 abort ();
|
|
2596 }
|
|
2597
|
|
2598 if (EQ (w, last_window))
|
|
2599 break;
|
|
2600
|
|
2601 w = next_window;
|
|
2602 }
|
|
2603 }
|
|
2604
|
173
|
2605 return type == GET_BUFFER_WINDOW_COUNT ? make_int (count) : best_window;
|
0
|
2606 }
|
|
2607
|
|
2608 #if 0 /* not currently used */
|
|
2609
|
|
2610 int
|
|
2611 buffer_window_count (struct buffer *b, struct frame *f)
|
|
2612 {
|
|
2613 Lisp_Object buffer, frame;
|
|
2614
|
|
2615 XSETFRAME (frame, f);
|
|
2616 XSETBUFFER (buffer, b);
|
|
2617
|
|
2618 return XINT (window_loop (GET_BUFFER_WINDOW_COUNT, buffer, 0, frame, 1,
|
|
2619 Qnil));
|
|
2620 }
|
|
2621
|
|
2622 int
|
|
2623 buffer_window_mru (struct window *w)
|
|
2624 {
|
185
|
2625 Lisp_Object window =
|
0
|
2626 window_loop (GET_BUFFER_MRU_WINDOW, w->buffer, 0, w->frame, 1, Qnil);
|
|
2627
|
|
2628 if (NILP (window))
|
|
2629 return 0;
|
|
2630 else if (XWINDOW (window) == w)
|
|
2631 return 1;
|
|
2632 else
|
|
2633 return 0;
|
|
2634 }
|
|
2635
|
|
2636 #endif
|
|
2637
|
|
2638
|
20
|
2639 DEFUN ("get-lru-window", Fget_lru_window, 0, 2, 0, /*
|
0
|
2640 Return the window least recently selected or used for display.
|
|
2641 If optional argument FRAME is `visible', search all visible frames.
|
|
2642 If FRAME is 0, search all visible and iconified frames.
|
|
2643 If FRAME is t, search all frames.
|
|
2644 If FRAME is nil, search only the selected frame.
|
|
2645 If FRAME is a frame, search only that frame.
|
|
2646
|
|
2647 Optional second argument CONSOLE controls which consoles or devices the
|
|
2648 returned window may be on. If CONSOLE is a console, return windows only
|
|
2649 on that console. If CONSOLE is a device, return windows only on that
|
|
2650 device. If CONSOLE is a console type, return windows only on consoles
|
|
2651 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2652 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2653 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2654 Otherwise, all windows are considered.
|
20
|
2655 */
|
|
2656 (frame, console))
|
0
|
2657 {
|
|
2658 Lisp_Object w;
|
|
2659 /* First try for a non-dedicated window that is full-width */
|
|
2660 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame, 0, console);
|
|
2661 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2662 return w;
|
|
2663
|
|
2664 /* Then try for any non-dedicated window */
|
|
2665 w = window_loop (GET_LRU_WINDOW, Qnil, 0, frame, 0, console);
|
|
2666 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2667 return w;
|
|
2668
|
|
2669 #if 0
|
|
2670 /* FSFmacs never returns a dedicated window here. If we do,
|
|
2671 it makes `display-buffer' not work right. #### All of this
|
|
2672 shit is so disgusting and awful that it needs to be rethought
|
|
2673 from scratch. */
|
|
2674 /* then try for a dedicated window that is full-width */
|
|
2675 w = window_loop (GET_LRU_WINDOW, Qt, 0, frame, 1, console);
|
|
2676 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
2677 return w;
|
|
2678
|
|
2679 /* If none of them, then all windows, dedicated or not. */
|
|
2680 w = window_loop (GET_LRU_WINDOW, Qnil, 0, frame, 1, console);
|
|
2681
|
|
2682 /* At this point we damn well better have found something. */
|
|
2683 if (NILP (w)) abort ();
|
|
2684 #endif
|
|
2685
|
173
|
2686 return w;
|
0
|
2687 }
|
|
2688
|
20
|
2689 DEFUN ("get-largest-window", Fget_largest_window, 0, 2, 0, /*
|
0
|
2690 Return the window largest in area.
|
|
2691 If optional argument FRAME is `visible', search all visible frames.
|
|
2692 If FRAME is 0, search all visible and iconified frames.
|
|
2693 If FRAME is t, search all frames.
|
|
2694 If FRAME is nil, search only the selected frame.
|
|
2695 If FRAME is a frame, search only that frame.
|
|
2696
|
|
2697 Optional second argument CONSOLE controls which consoles or devices the
|
|
2698 returned window may be on. If CONSOLE is a console, return windows only
|
|
2699 on that console. If CONSOLE is a device, return windows only on that
|
|
2700 device. If CONSOLE is a console type, return windows only on consoles
|
|
2701 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2702 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2703 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2704 Otherwise, all windows are considered.
|
20
|
2705 */
|
|
2706 (frame, console))
|
0
|
2707 {
|
|
2708 /* Don't search dedicated windows because FSFmacs doesn't.
|
|
2709 This stuff is all black magic so don't try to apply common
|
|
2710 sense to it. */
|
|
2711 return window_loop (GET_LARGEST_WINDOW, Qnil, 0, frame, 0, console);
|
|
2712 }
|
|
2713
|
20
|
2714 DEFUN ("get-buffer-window", Fget_buffer_window, 1, 3, 0, /*
|
0
|
2715 Return a window currently displaying BUFFER, or nil if none.
|
|
2716 If optional argument FRAME is `visible', search all visible frames.
|
|
2717 If optional argument FRAME is 0, search all visible and iconified frames.
|
|
2718 If FRAME is t, search all frames.
|
|
2719 If FRAME is nil, search only the selected frame.
|
|
2720 If FRAME is a frame, search only that frame.
|
|
2721
|
|
2722 Optional third argument CONSOLE controls which consoles or devices the
|
|
2723 returned window may be on. If CONSOLE is a console, return windows only
|
|
2724 on that console. If CONSOLE is a device, return windows only on that
|
|
2725 device. If CONSOLE is a console type, return windows only on consoles
|
|
2726 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2727 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2728 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2729 Otherwise, all windows are considered.
|
20
|
2730 */
|
|
2731 (buffer, frame, console))
|
0
|
2732 {
|
|
2733 buffer = Fget_buffer (buffer);
|
|
2734 if (BUFFERP (buffer))
|
|
2735 /* Search dedicated windows too. (Doesn't matter here anyway.) */
|
|
2736 return window_loop (GET_BUFFER_WINDOW, buffer, 1, frame, 1, console);
|
|
2737 else
|
|
2738 return Qnil;
|
|
2739 }
|
|
2740
|
|
2741 /* These functions used to be `buffer-left-margin-pixel-width', etc.
|
|
2742 but there is no sensible way to implement those functions, since
|
|
2743 you can't in general derive a window from a buffer. */
|
|
2744
|
280
|
2745 DEFUN ("window-left-margin-pixel-width", Fwindow_left_margin_pixel_width,
|
|
2746 0, 1, 0, /*
|
0
|
2747 Return the width in pixels of the left outside margin of window WINDOW.
|
|
2748 If WINDOW is nil, the selected window is assumed.
|
20
|
2749 */
|
|
2750 (window))
|
0
|
2751 {
|
149
|
2752 return make_int (window_left_margin_width (decode_window (window)));
|
0
|
2753 }
|
|
2754
|
280
|
2755 DEFUN ("window-right-margin-pixel-width", Fwindow_right_margin_pixel_width,
|
|
2756 0, 1, 0, /*
|
0
|
2757 Return the width in pixels of the right outside margin of window WINDOW.
|
|
2758 If WINDOW is nil, the selected window is assumed.
|
20
|
2759 */
|
|
2760 (window))
|
0
|
2761 {
|
149
|
2762 return make_int (window_right_margin_width (decode_window (window)));
|
0
|
2763 }
|
|
2764
|
20
|
2765 DEFUN ("delete-other-windows", Fdelete_other_windows, 0, 1, "", /*
|
0
|
2766 Make WINDOW (or the selected window) fill its frame.
|
|
2767 Only the frame WINDOW is on is affected.
|
|
2768 This function tries to reduce display jumps
|
|
2769 by keeping the text previously visible in WINDOW
|
|
2770 in the same place on the frame. Doing this depends on
|
|
2771 the value of (window-start WINDOW), so if calling this function
|
|
2772 in a program gives strange scrolling, make sure the window-start
|
|
2773 value is reasonable when this function is called.
|
20
|
2774 */
|
|
2775 (window))
|
0
|
2776 {
|
|
2777 struct window *w = decode_window (window);
|
|
2778 struct buffer *b = XBUFFER (w->buffer);
|
|
2779 Bufpos start_pos;
|
|
2780 int old_top = WINDOW_TOP (w);
|
|
2781
|
|
2782 XSETWINDOW (window, w);
|
|
2783
|
|
2784 if (MINI_WINDOW_P (w) && old_top > 0)
|
|
2785 error ("Can't expand minibuffer to full frame");
|
|
2786
|
|
2787 /* Ignore dedicated windows. */
|
|
2788 window_loop (DELETE_OTHER_WINDOWS, window, 0, w->frame, 0, Qnil);
|
|
2789
|
|
2790 start_pos = marker_position (w->start[CURRENT_DISP]);
|
|
2791
|
|
2792 /* Try to minimize scrolling, by setting the window start to the
|
|
2793 point which will cause the text at the old window start to be at
|
|
2794 the same place on the frame. But don't try to do this if the
|
|
2795 window start is outside the visible portion (as might happen when
|
|
2796 the display is not current, due to typeahead). */
|
|
2797 if (start_pos >= BUF_BEGV (b) && start_pos <= BUF_ZV (b)
|
|
2798 && !MINI_WINDOW_P (w))
|
|
2799 {
|
|
2800 Bufpos new_start = start_with_line_at_pixpos (w, start_pos, old_top);
|
|
2801
|
|
2802 if (new_start >= BUF_BEGV (b) && new_start <= BUF_ZV (b))
|
|
2803 {
|
|
2804 Fset_marker (w->start[CURRENT_DISP], make_int (new_start),
|
|
2805 w->buffer);
|
|
2806 w->start_at_line_beg = beginning_of_line_p (b, new_start);
|
|
2807 }
|
|
2808 /* We need to do this, so that the window-scroll-functions
|
|
2809 get called. */
|
|
2810 w->force_start = 1;
|
|
2811 }
|
|
2812
|
|
2813 return Qnil;
|
|
2814 }
|
|
2815
|
20
|
2816 DEFUN ("delete-windows-on", Fdelete_windows_on, 1, 3,
|
|
2817 "bDelete windows on (buffer): ", /*
|
0
|
2818 Delete all windows showing BUFFER.
|
|
2819 Optional second argument FRAME controls which frames are affected.
|
|
2820 If nil or omitted, delete all windows showing BUFFER in any frame.
|
|
2821 If t, delete only windows showing BUFFER in the selected frame.
|
|
2822 If `visible', delete all windows showing BUFFER in any visible frame.
|
|
2823 If a frame, delete only windows showing BUFFER in that frame.
|
|
2824
|
|
2825 Optional third argument CONSOLE controls which consoles or devices the
|
|
2826 returned window may be on. If CONSOLE is a console, return windows only
|
|
2827 on that console. If CONSOLE is a device, return windows only on that
|
|
2828 device. If CONSOLE is a console type, return windows only on consoles
|
|
2829 of that type. If CONSOLE is 'window-system, return any windows on any
|
|
2830 window-system consoles. If CONSOLE is nil or omitted, return windows only
|
|
2831 on FRAME'S console, or on the selected console if FRAME is not a frame.
|
|
2832 Otherwise, all windows are considered.
|
20
|
2833 */
|
|
2834 (buffer, frame, console))
|
0
|
2835 {
|
|
2836 /* This function can GC */
|
|
2837 /* FRAME uses t and nil to mean the opposite of what window_loop
|
|
2838 expects. */
|
|
2839 if (!FRAMEP (frame))
|
|
2840 frame = NILP (frame) ? Qt : Qnil;
|
|
2841
|
|
2842 if (!NILP (buffer))
|
|
2843 {
|
|
2844 buffer = Fget_buffer (buffer);
|
|
2845 CHECK_BUFFER (buffer);
|
|
2846 /* Ignore dedicated windows. */
|
|
2847 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0, frame, 0, console);
|
|
2848 }
|
|
2849 return Qnil;
|
|
2850 }
|
|
2851
|
20
|
2852 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, 1, 1,
|
|
2853 "bReplace buffer in windows: ", /*
|
0
|
2854 Replace BUFFER with some other buffer in all windows showing it.
|
20
|
2855 */
|
|
2856 (buffer))
|
0
|
2857 {
|
|
2858 /* This function can GC */
|
|
2859 if (!NILP (buffer))
|
|
2860 {
|
|
2861 buffer = Fget_buffer (buffer);
|
|
2862 CHECK_BUFFER (buffer);
|
|
2863 /* Ignore dedicated windows. */
|
|
2864 window_loop (UNSHOW_BUFFER, buffer, 0, Qt, 0, Qnil);
|
|
2865 }
|
|
2866 return Qnil;
|
|
2867 }
|
|
2868
|
|
2869 /* The smallest acceptable dimensions for a window. Anything smaller
|
|
2870 might crash Emacs. */
|
|
2871 #define MIN_SAFE_WINDOW_WIDTH (2)
|
|
2872 #define MIN_SAFE_WINDOW_HEIGHT (2)
|
|
2873
|
|
2874 /* Make sure that window_min_height and window_min_width are
|
|
2875 not too small; if they are, set them to safe minima. */
|
|
2876
|
|
2877 static void
|
|
2878 check_min_window_sizes (void)
|
|
2879 {
|
|
2880 /* Smaller values might permit a crash. */
|
|
2881 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
|
|
2882 window_min_width = MIN_SAFE_WINDOW_WIDTH;
|
|
2883 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
|
|
2884 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
|
|
2885 }
|
|
2886
|
|
2887 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
|
|
2888 minimum allowable size. */
|
|
2889 void
|
|
2890 check_frame_size (struct frame *frame, int *rows, int *cols)
|
|
2891 {
|
|
2892 /* For height, we have to see whether the frame has a minibuffer, and
|
|
2893 whether it wants a modeline. */
|
|
2894 int min_height =
|
|
2895 (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
|
|
2896 : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
|
|
2897 : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
|
|
2898
|
|
2899 if (*rows < min_height)
|
|
2900 *rows = min_height;
|
|
2901 if (*cols < MIN_SAFE_WINDOW_WIDTH)
|
|
2902 *cols = MIN_SAFE_WINDOW_WIDTH;
|
|
2903 }
|
|
2904
|
|
2905 /* Normally the window is deleted if it gets too small.
|
|
2906 nodelete nonzero means do not do this.
|
|
2907 (The caller should check later and do so if appropriate) */
|
|
2908 static void
|
|
2909 set_window_pixsize (Lisp_Object window, int new_pixsize, int nodelete,
|
|
2910 int set_height)
|
|
2911 {
|
|
2912 struct window *w = XWINDOW (window);
|
|
2913 struct frame *f = XFRAME (w->frame);
|
|
2914 struct window *c;
|
|
2915 int old_pixsize = (set_height ? WINDOW_HEIGHT (w) : WINDOW_WIDTH (w));
|
|
2916 Lisp_Object child, minor_kid, major_kid;
|
|
2917 int minsize;
|
|
2918 int line_size;
|
|
2919 int defheight, defwidth;
|
|
2920
|
|
2921 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
2922 functions should be called. */
|
|
2923 default_face_height_and_width (window, &defheight, &defwidth);
|
|
2924 line_size = (set_height ? defheight : defwidth);
|
|
2925
|
272
|
2926 check_min_window_sizes ();
|
|
2927
|
0
|
2928 minsize = (set_height ? window_min_height : window_min_width);
|
|
2929 minsize *= line_size;
|
|
2930
|
|
2931 if (!nodelete
|
|
2932 && !TOP_LEVEL_WINDOW_P (w)
|
|
2933 && new_pixsize < minsize)
|
|
2934 {
|
|
2935 Fdelete_window (window, Qnil);
|
|
2936 return;
|
|
2937 }
|
|
2938
|
|
2939 SET_LAST_MODIFIED (w, 0);
|
|
2940 SET_LAST_FACECHANGE (w);
|
|
2941 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f); /* multiple windows affected */
|
|
2942 if (set_height)
|
|
2943 {
|
|
2944 WINDOW_HEIGHT (w) = new_pixsize;
|
|
2945 major_kid = w->vchild;
|
|
2946 minor_kid = w->hchild;
|
|
2947 }
|
|
2948 else
|
|
2949 {
|
|
2950 WINDOW_WIDTH (w) = new_pixsize;
|
|
2951 major_kid = w->hchild;
|
|
2952 minor_kid = w->vchild;
|
|
2953 }
|
|
2954
|
|
2955 if (!NILP (minor_kid))
|
|
2956 {
|
|
2957 for (child = minor_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
2958 {
|
|
2959 if (set_height)
|
|
2960 WINDOW_TOP (XWINDOW (child)) = WINDOW_TOP (w);
|
|
2961 else
|
|
2962 WINDOW_LEFT (XWINDOW (child)) = WINDOW_LEFT (w);
|
|
2963
|
|
2964 set_window_pixsize (child, new_pixsize, nodelete, set_height);
|
|
2965 }
|
|
2966 }
|
|
2967 else if (!NILP (major_kid))
|
|
2968 {
|
|
2969 int last_pos, last_old_pos, pos, old_pos, first;
|
215
|
2970 int pixel_adj_left = new_pixsize - old_pixsize;
|
0
|
2971 int div_val = old_pixsize << 1;
|
|
2972
|
209
|
2973 /*
|
|
2974 * Previously we bailed out here if there was no size change.
|
215
|
2975 * (pixel_adj_left == 0) But this broke toolbar updates. If a
|
|
2976 * toolbar appears or disappears, windows may not change size,
|
|
2977 * but their top and left coordinates need to be updated.
|
209
|
2978 *
|
215
|
2979 * So we don't bail until after the loop below.
|
209
|
2980 */
|
0
|
2981
|
|
2982 last_pos = first = (set_height ? WINDOW_TOP (w) : WINDOW_LEFT (w));
|
|
2983 last_old_pos = 0;
|
|
2984
|
|
2985 for (child = major_kid; !NILP (child); child = c->next)
|
|
2986 {
|
|
2987 c = XWINDOW (child);
|
|
2988
|
|
2989 if (set_height)
|
|
2990 {
|
|
2991 old_pos = last_old_pos + WINDOW_HEIGHT (c);
|
|
2992 WINDOW_TOP (c) = last_pos;
|
|
2993 }
|
|
2994 else
|
|
2995 {
|
|
2996 old_pos = last_old_pos + WINDOW_WIDTH (c);
|
|
2997 WINDOW_LEFT (c) = last_pos;
|
|
2998 }
|
|
2999
|
|
3000 pos = (((old_pos * new_pixsize) << 1) + old_pixsize) / div_val;
|
2
|
3001 /* All but the last window should have a height which is
|
0
|
3002 a multiple of the default line height. */
|
|
3003 if (!NILP (c->next))
|
|
3004 pos = (pos / line_size) * line_size;
|
|
3005
|
|
3006 /* Avoid confusion: don't delete child if it becomes too small */
|
|
3007 set_window_pixsize (child, pos + first - last_pos, 1, set_height);
|
|
3008
|
|
3009 last_pos = pos + first;
|
|
3010 last_old_pos = old_pos;
|
|
3011 }
|
|
3012
|
215
|
3013 /* Sometimes we may get called with our old size. In that case
|
|
3014 we don't need to do anything else. */
|
|
3015 if (!pixel_adj_left)
|
|
3016 return;
|
|
3017
|
0
|
3018 /* Now delete any children that became too small. */
|
|
3019 if (!nodelete)
|
|
3020 for (child = major_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
3021 {
|
|
3022 if (set_height)
|
|
3023 set_window_pixheight (child, WINDOW_HEIGHT (XWINDOW (child)), 0);
|
|
3024 else
|
|
3025 set_window_pixwidth (child, WINDOW_WIDTH (XWINDOW (child)), 0);
|
|
3026 }
|
|
3027 }
|
|
3028 }
|
|
3029
|
|
3030 /* Set the height of WINDOW and all its inferiors. */
|
|
3031 void
|
|
3032 set_window_pixheight (Lisp_Object window, int new_pixheight, int nodelete)
|
|
3033 {
|
|
3034 set_window_pixsize (window, new_pixheight, nodelete, 1);
|
|
3035 }
|
|
3036
|
|
3037 /* Recursively set width of WINDOW and its inferiors. */
|
|
3038 void
|
|
3039 set_window_pixwidth (Lisp_Object window, int new_pixwidth, int nodelete)
|
|
3040 {
|
|
3041 set_window_pixsize (window, new_pixwidth, nodelete, 0);
|
|
3042 }
|
|
3043
|
|
3044
|
|
3045 static int window_select_count;
|
|
3046
|
20
|
3047 DEFUN ("set-window-buffer", Fset_window_buffer, 2, 2, 0, /*
|
0
|
3048 Make WINDOW display BUFFER as its contents.
|
|
3049 BUFFER can be a buffer or buffer name.
|
20
|
3050 */
|
|
3051 (window, buffer))
|
0
|
3052 {
|
|
3053 Lisp_Object tem;
|
|
3054 struct window *w = decode_window (window);
|
|
3055
|
|
3056 buffer = Fget_buffer (buffer);
|
|
3057 CHECK_BUFFER (buffer);
|
|
3058
|
|
3059 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
|
|
3060 error ("Attempt to display deleted buffer");
|
|
3061
|
|
3062 tem = w->buffer;
|
|
3063 if (NILP (tem))
|
|
3064 error ("Window is deleted");
|
|
3065
|
|
3066 /* While this seems like a logical thing to do, it causes problems
|
|
3067 because of saved window configurations. It is possible for a
|
|
3068 buffer to get restored into a window in which it is already being
|
|
3069 displayed, but start and point are actually at completely
|
|
3070 different locations. So we let this function complete fully and
|
|
3071 it will then make sure redisplay correctly updates things.
|
|
3072
|
|
3073 #### This is a kludge. The correct approach is not to do this
|
|
3074 but to fix set-window-configuration. */
|
|
3075 #if 0
|
|
3076 else if (EQ (tem, buffer))
|
149
|
3077 return Qnil;
|
0
|
3078 #endif
|
|
3079 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
|
|
3080 is first being set up. */
|
|
3081 {
|
|
3082 if (!NILP (w->dedicated) && !EQ (tem, buffer))
|
|
3083 error ("Window is dedicated to buffer %s",
|
16
|
3084 XSTRING_DATA (XBUFFER (tem)->name));
|
0
|
3085
|
|
3086 unshow_buffer (w);
|
|
3087 }
|
|
3088
|
|
3089 w->buffer = buffer;
|
|
3090 w->window_end_pos[CURRENT_DISP] = 0;
|
259
|
3091 w->hscroll = 0;
|
|
3092 w->modeline_hscroll = 0;
|
0
|
3093 Fset_marker (w->pointm[CURRENT_DISP],
|
|
3094 make_int (BUF_PT (XBUFFER (buffer))),
|
|
3095 buffer);
|
|
3096 set_marker_restricted (w->start[CURRENT_DISP],
|
|
3097 make_int (XBUFFER (buffer)->last_window_start),
|
|
3098 buffer);
|
|
3099 Fset_marker (w->sb_point, w->start[CURRENT_DISP], buffer);
|
|
3100 w->start_at_line_beg = 0;
|
|
3101 w->force_start = 0; /* Lucid fix */
|
|
3102 SET_LAST_MODIFIED (w, 1);
|
|
3103 SET_LAST_FACECHANGE (w);
|
|
3104 MARK_WINDOWS_CHANGED (w);
|
|
3105 recompute_all_cached_specifiers_in_window (w);
|
|
3106 if (EQ (window, Fselected_window (Qnil)))
|
|
3107 {
|
|
3108 Fset_buffer (buffer);
|
|
3109 }
|
|
3110 return Qnil;
|
|
3111 }
|
|
3112
|
282
|
3113 DEFUN ("select-window", Fselect_window, 1, 2, 0, /*
|
0
|
3114 Select WINDOW. Most editing will apply to WINDOW's buffer.
|
|
3115 The main editor command loop selects the buffer of the selected window
|
|
3116 before each command.
|
282
|
3117
|
|
3118 With non-nil optional argument `norecord', do not modify the
|
|
3119 global or per-frame buffer ordering.
|
20
|
3120 */
|
282
|
3121 (window, norecord))
|
0
|
3122 {
|
|
3123 struct window *w;
|
|
3124 Lisp_Object old_selected_window = Fselected_window (Qnil);
|
185
|
3125
|
0
|
3126 CHECK_LIVE_WINDOW (window);
|
|
3127 w = XWINDOW (window);
|
|
3128
|
|
3129 /* we have already caught dead-window errors */
|
|
3130 if (!NILP (w->hchild) || !NILP (w->vchild))
|
|
3131 error ("Trying to select non-leaf window");
|
|
3132
|
|
3133 w->use_time = make_int (++window_select_count);
|
|
3134 if (EQ (window, old_selected_window))
|
|
3135 return window;
|
|
3136
|
|
3137 /* deselect the old window, if it exists (it might not exist if
|
|
3138 the selected device has no frames, which occurs at startup) */
|
|
3139 if (!NILP (old_selected_window))
|
|
3140 {
|
|
3141 struct window *ow = XWINDOW (old_selected_window);
|
|
3142
|
|
3143 Fset_marker (ow->pointm[CURRENT_DISP],
|
|
3144 make_int (BUF_PT (XBUFFER (ow->buffer))),
|
|
3145 ow->buffer);
|
|
3146
|
|
3147 MARK_WINDOWS_CHANGED (ow);
|
|
3148 }
|
|
3149
|
|
3150 /* now select the window's frame */
|
|
3151 set_frame_selected_window (XFRAME (WINDOW_FRAME (w)), window);
|
185
|
3152
|
0
|
3153 select_frame_1 (WINDOW_FRAME (w));
|
|
3154
|
|
3155 /* also select the window's buffer */
|
282
|
3156 if (NILP (norecord))
|
|
3157 Frecord_buffer (w->buffer);
|
0
|
3158 Fset_buffer (w->buffer);
|
|
3159
|
|
3160 /* Go to the point recorded in the window.
|
|
3161 This is important when the buffer is in more
|
|
3162 than one window. It also matters when
|
|
3163 redisplay_window has altered point after scrolling,
|
|
3164 because it makes the change only in the window. */
|
|
3165 {
|
|
3166 Bufpos new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
3167 if (new_point < BUF_BEGV (current_buffer))
|
|
3168 new_point = BUF_BEGV (current_buffer);
|
|
3169 else if (new_point > BUF_ZV (current_buffer))
|
|
3170 new_point = BUF_ZV (current_buffer);
|
|
3171
|
|
3172 BUF_SET_PT (current_buffer, new_point);
|
|
3173 }
|
|
3174
|
|
3175 MARK_WINDOWS_CHANGED (w);
|
|
3176
|
|
3177 return window;
|
|
3178 }
|
|
3179
|
|
3180 Lisp_Object
|
|
3181 display_buffer (Lisp_Object buffer, Lisp_Object not_this_window_p,
|
|
3182 Lisp_Object override_frame)
|
|
3183 {
|
|
3184 return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame);
|
|
3185 }
|
|
3186
|
|
3187 void
|
|
3188 temp_output_buffer_show (Lisp_Object buf, Lisp_Object same_frame)
|
|
3189 {
|
|
3190 /* This function can GC */
|
|
3191 Lisp_Object window;
|
|
3192 struct window *w;
|
|
3193 struct buffer *b = XBUFFER (buf);
|
|
3194
|
|
3195 BUF_SAVE_MODIFF (XBUFFER (buf)) = BUF_MODIFF (b);
|
|
3196 widen_buffer (b, 0);
|
|
3197 BUF_SET_PT (b, BUF_BEG (b));
|
|
3198
|
272
|
3199 if (!NILP (Vtemp_buffer_show_function))
|
0
|
3200 call1 (Vtemp_buffer_show_function, buf);
|
|
3201 else
|
|
3202 {
|
|
3203 window = display_buffer (buf, Qnil, same_frame);
|
|
3204
|
|
3205 if (!EQ (XWINDOW (window)->frame, Fselected_frame (Qnil)))
|
|
3206 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
|
|
3207
|
274
|
3208 Vminibuffer_scroll_window = window;
|
0
|
3209 w = XWINDOW (window);
|
|
3210 w->hscroll = 0;
|
257
|
3211 w->modeline_hscroll = 0;
|
0
|
3212 set_marker_restricted (w->start[CURRENT_DISP], make_int (1), buf);
|
|
3213 set_marker_restricted (w->pointm[CURRENT_DISP], make_int (1), buf);
|
|
3214 set_marker_restricted (w->sb_point, make_int (1), buf);
|
|
3215
|
185
|
3216 /* Run temp-buffer-show-hook, with the chosen window selected. */
|
0
|
3217 if (!preparing_for_armageddon)
|
|
3218 {
|
|
3219 Lisp_Object tem;
|
|
3220 tem = Fboundp (Qtemp_buffer_show_hook);
|
|
3221 if (!NILP (tem))
|
|
3222 {
|
|
3223 tem = Fsymbol_value (Qtemp_buffer_show_hook);
|
|
3224 if (!NILP (tem))
|
|
3225 {
|
|
3226 int count = specpdl_depth ();
|
|
3227
|
|
3228 /* Select the window that was chosen, for running
|
|
3229 the hook. */
|
|
3230 record_unwind_protect (save_window_excursion_unwind,
|
|
3231 Fcurrent_window_configuration (Qnil));
|
|
3232
|
282
|
3233 Fselect_window (window, Qnil);
|
0
|
3234 run_hook (Qtemp_buffer_show_hook);
|
|
3235 unbind_to (count, Qnil);
|
|
3236 }
|
|
3237 }
|
|
3238 }
|
|
3239 }
|
|
3240 }
|
|
3241
|
|
3242 static void
|
|
3243 make_dummy_parent (Lisp_Object window)
|
|
3244 {
|
272
|
3245 Lisp_Object new;
|
0
|
3246 struct window *o = XWINDOW (window);
|
185
|
3247 struct window *p = alloc_lcrecord_type (struct window, lrecord_window);
|
0
|
3248
|
|
3249 XSETWINDOW (new, p);
|
|
3250 copy_lcrecord (p, o);
|
|
3251
|
|
3252 /* Don't copy the pointers to the line start cache or the face
|
|
3253 instances. */
|
185
|
3254 p->line_start_cache = Dynarr_new (line_start_cache);
|
|
3255 p->face_cachels = Dynarr_new (face_cachel);
|
|
3256 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
0
|
3257
|
|
3258 /* Put new into window structure in place of window */
|
|
3259 replace_window (window, new);
|
|
3260
|
|
3261 o->next = Qnil;
|
|
3262 o->prev = Qnil;
|
|
3263 o->vchild = Qnil;
|
|
3264 o->hchild = Qnil;
|
|
3265 o->parent = new;
|
|
3266
|
|
3267 p->start[CURRENT_DISP] = Qnil;
|
|
3268 p->start[DESIRED_DISP] = Qnil;
|
|
3269 p->start[CMOTION_DISP] = Qnil;
|
|
3270 p->pointm[CURRENT_DISP] = Qnil;
|
|
3271 p->pointm[DESIRED_DISP] = Qnil;
|
|
3272 p->pointm[CMOTION_DISP] = Qnil;
|
|
3273 p->sb_point = Qnil;
|
|
3274 p->buffer = Qnil;
|
|
3275 }
|
|
3276
|
20
|
3277 DEFUN ("split-window", Fsplit_window, 0, 3, "", /*
|
0
|
3278 Split WINDOW, putting SIZE lines in the first of the pair.
|
|
3279 WINDOW defaults to selected one and SIZE to half its size.
|
|
3280 If optional third arg HOR-FLAG is non-nil, split side by side
|
|
3281 and put SIZE columns in the first of the pair.
|
20
|
3282 */
|
|
3283 (window, chsize, horflag))
|
0
|
3284 {
|
|
3285 Lisp_Object new;
|
|
3286 struct window *o, *p;
|
|
3287 struct frame *f;
|
|
3288 int size;
|
|
3289 int psize;
|
|
3290
|
|
3291 if (NILP (window))
|
|
3292 window = Fselected_window (Qnil);
|
|
3293 else
|
|
3294 CHECK_WINDOW (window);
|
|
3295
|
|
3296 o = XWINDOW (window);
|
|
3297 f = XFRAME (WINDOW_FRAME (o));
|
|
3298
|
|
3299 if (NILP (chsize))
|
|
3300 {
|
|
3301 if (!NILP (horflag))
|
|
3302 /* In the new scheme, we are symmetric with respect to separators
|
|
3303 so there is no need to do weird things here. */
|
|
3304 {
|
|
3305 psize = WINDOW_WIDTH (o) >> 1;
|
|
3306 size = window_pixel_width_to_char_width (o, psize, 0);
|
|
3307 }
|
|
3308 else
|
|
3309 {
|
|
3310 psize = WINDOW_HEIGHT (o) >> 1;
|
|
3311 size = window_pixel_height_to_char_height (o, psize, 1);
|
|
3312 }
|
|
3313 }
|
|
3314 else
|
|
3315 {
|
|
3316 CHECK_INT (chsize);
|
|
3317 size = XINT (chsize);
|
|
3318 if (!NILP (horflag))
|
|
3319 psize = window_char_width_to_pixel_width (o, size, 0);
|
|
3320 else
|
|
3321 psize = window_char_height_to_pixel_height (o, size, 1);
|
|
3322 }
|
|
3323
|
|
3324 if (MINI_WINDOW_P (o))
|
|
3325 error ("Attempt to split minibuffer window");
|
|
3326 else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o))))
|
|
3327 error ("Attempt to split unsplittable frame");
|
|
3328
|
|
3329 check_min_window_sizes ();
|
|
3330
|
|
3331 if (NILP (horflag))
|
|
3332 {
|
|
3333 if (size < window_min_height)
|
|
3334 error ("Window height %d too small (after splitting)", size);
|
|
3335 if (size + window_min_height > window_char_height (o, 1))
|
185
|
3336 error ("Window height %d too small (after splitting)",
|
0
|
3337 window_char_height (o, 1) - size);
|
|
3338 if (NILP (o->parent)
|
|
3339 || NILP (XWINDOW (o->parent)->vchild))
|
|
3340 {
|
|
3341 make_dummy_parent (window);
|
|
3342 reset_face_cachels (XWINDOW (window));
|
|
3343 new = o->parent;
|
|
3344 XWINDOW (new)->vchild = window;
|
|
3345 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3346 }
|
|
3347 }
|
|
3348 else
|
|
3349 {
|
|
3350 if (size < window_min_width)
|
|
3351 error ("Window width %d too small (after splitting)", size);
|
|
3352 if (size + window_min_width > window_char_width (o, 0))
|
185
|
3353 error ("Window width %d too small (after splitting)",
|
0
|
3354 window_char_width (o, 0) - size);
|
|
3355 if (NILP (o->parent)
|
|
3356 || NILP (XWINDOW (o->parent)->hchild))
|
|
3357 {
|
|
3358 make_dummy_parent (window);
|
|
3359 reset_face_cachels (XWINDOW (window));
|
|
3360 new = o->parent;
|
|
3361 XWINDOW (new)->hchild = window;
|
|
3362 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3363 }
|
|
3364 }
|
|
3365
|
|
3366 /* Now we know that window's parent is a vertical combination
|
|
3367 if we are dividing vertically, or a horizontal combination
|
|
3368 if we are making side-by-side windows */
|
|
3369
|
|
3370 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
3371 new = allocate_window ();
|
|
3372 p = XWINDOW (new);
|
|
3373
|
|
3374 p->frame = o->frame;
|
|
3375 p->next = o->next;
|
|
3376 if (!NILP (p->next))
|
|
3377 XWINDOW (p->next)->prev = new;
|
|
3378 p->prev = window;
|
|
3379 o->next = new;
|
|
3380 p->parent = o->parent;
|
|
3381 p->buffer = Qt;
|
|
3382
|
|
3383 reset_face_cachels (p);
|
|
3384 reset_glyph_cachels (p);
|
185
|
3385
|
0
|
3386
|
|
3387 /* Apportion the available frame space among the two new windows */
|
|
3388
|
|
3389 if (!NILP (horflag))
|
|
3390 {
|
|
3391 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o);
|
|
3392 WINDOW_TOP (p) = WINDOW_TOP (o);
|
|
3393 WINDOW_WIDTH (p) = WINDOW_WIDTH (o) - psize;
|
|
3394 WINDOW_WIDTH (o) = psize;
|
|
3395 WINDOW_LEFT (p) = WINDOW_LEFT (o) + psize;
|
|
3396 }
|
|
3397 else
|
|
3398 {
|
|
3399 WINDOW_LEFT (p) = WINDOW_LEFT (o);
|
|
3400 WINDOW_WIDTH (p) = WINDOW_WIDTH (o);
|
|
3401 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o) - psize;
|
|
3402 WINDOW_HEIGHT (o) = psize;
|
|
3403 WINDOW_TOP (p) = WINDOW_TOP (o) + psize;
|
|
3404 }
|
|
3405
|
|
3406 XFRAME (p->frame)->mirror_dirty = 1;
|
|
3407 /* do this last (after the window is completely initialized and
|
|
3408 the mirror-dirty flag is set) so that specifier recomputation
|
|
3409 caused as a result of this will work properly and not abort. */
|
|
3410 Fset_window_buffer (new, o->buffer);
|
|
3411 return new;
|
|
3412 }
|
|
3413
|
|
3414
|
20
|
3415 DEFUN ("enlarge-window", Fenlarge_window, 1, 3, "_p", /*
|
0
|
3416 Make the selected window ARG lines bigger.
|
|
3417 From program, optional second arg non-nil means grow sideways ARG columns,
|
|
3418 and optional third ARG specifies the window to change instead of the
|
|
3419 selected window.
|
20
|
3420 */
|
|
3421 (n, side, window))
|
0
|
3422 {
|
|
3423 struct window *w = decode_window (window);
|
|
3424 CHECK_INT (n);
|
263
|
3425 change_window_height (w, XINT (n), !NILP (side), /* inpixels */ 0);
|
|
3426 return Qnil;
|
|
3427 }
|
|
3428
|
|
3429 DEFUN ("enlarge-window-pixels", Fenlarge_window_pixels, 1, 3, "_p", /*
|
|
3430 Make the selected window ARG pixels bigger.
|
|
3431 From program, optional second arg non-nil means grow sideways ARG pixels,
|
|
3432 and optional third ARG specifies the window to change instead of the
|
|
3433 selected window.
|
|
3434 */
|
|
3435 (n, side, window))
|
|
3436 {
|
|
3437 struct window *w = decode_window (window);
|
|
3438 CHECK_INT (n);
|
|
3439 change_window_height (w, XINT (n), !NILP (side), /* inpixels */ 1);
|
0
|
3440 return Qnil;
|
|
3441 }
|
|
3442
|
20
|
3443 DEFUN ("shrink-window", Fshrink_window, 1, 3, "_p", /*
|
0
|
3444 Make the selected window ARG lines smaller.
|
|
3445 From program, optional second arg non-nil means shrink sideways ARG columns,
|
|
3446 and optional third ARG specifies the window to change instead of the
|
|
3447 selected window.
|
20
|
3448 */
|
|
3449 (n, side, window))
|
0
|
3450 {
|
|
3451 CHECK_INT (n);
|
263
|
3452 change_window_height (decode_window (window), -XINT (n), !NILP (side),
|
|
3453 /* inpixels */ 0);
|
|
3454 return Qnil;
|
|
3455 }
|
|
3456
|
|
3457 DEFUN ("shrink-window-pixels", Fshrink_window_pixels, 1, 3, "_p", /*
|
|
3458 Make the selected window ARG pixels smaller.
|
|
3459 From program, optional second arg non-nil means shrink sideways ARG pixels,
|
|
3460 and optional third ARG specifies the window to change instead of the
|
|
3461 selected window.
|
|
3462 */
|
|
3463 (n, side, window))
|
|
3464 {
|
|
3465 CHECK_INT (n);
|
|
3466 change_window_height (decode_window (window), -XINT (n), !NILP (side),
|
|
3467 /* inpixels */ 1);
|
0
|
3468 return Qnil;
|
|
3469 }
|
|
3470
|
|
3471 static int
|
|
3472 window_pixel_height (Lisp_Object window)
|
|
3473 {
|
149
|
3474 return WINDOW_HEIGHT (XWINDOW (window));
|
0
|
3475 }
|
|
3476
|
|
3477 static int
|
|
3478 window_pixel_height_to_char_height (struct window *w, int pixel_height,
|
|
3479 int include_gutters_p)
|
|
3480 {
|
|
3481 int avail_height;
|
|
3482 int defheight, defwidth;
|
|
3483 int char_height;
|
|
3484 Lisp_Object window;
|
185
|
3485
|
0
|
3486 XSETWINDOW (window, w);
|
185
|
3487
|
0
|
3488 avail_height = (pixel_height -
|
|
3489 (include_gutters_p ? 0 :
|
|
3490 window_top_gutter_height (w) +
|
|
3491 window_bottom_gutter_height (w)));
|
185
|
3492
|
0
|
3493 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3494
|
|
3495 char_height = avail_height / defheight;
|
|
3496
|
|
3497 /* It's the calling function's responsibility to check these values
|
|
3498 and make sure they're not out of range.
|
|
3499
|
|
3500 #### We need to go through the calling functions and actually
|
|
3501 do this. */
|
272
|
3502 return max (0, char_height);
|
0
|
3503 }
|
|
3504
|
|
3505 static int
|
|
3506 window_char_height_to_pixel_height (struct window *w, int char_height,
|
|
3507 int include_gutters_p)
|
|
3508 {
|
|
3509 int avail_height;
|
|
3510 int defheight, defwidth;
|
|
3511 int pixel_height;
|
|
3512
|
|
3513 Lisp_Object window;
|
185
|
3514
|
0
|
3515 XSETWINDOW (window, w);
|
185
|
3516
|
0
|
3517 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3518
|
|
3519 avail_height = char_height * defheight;
|
|
3520 pixel_height = (avail_height +
|
|
3521 (include_gutters_p ? 0 :
|
|
3522 window_top_gutter_height (w) +
|
|
3523 window_bottom_gutter_height (w)));
|
|
3524
|
|
3525 /* It's the calling function's responsibility to check these values
|
|
3526 and make sure they're not out of range.
|
|
3527
|
|
3528 #### We need to go through the calling functions and actually
|
|
3529 do this. */
|
272
|
3530 return max (0, pixel_height);
|
0
|
3531 }
|
|
3532
|
|
3533 /* Return number of default lines of text can fit in the window W.
|
|
3534 If INCLUDE_GUTTERS_P is 1, include "gutter" space (modeline plus
|
|
3535 horizontal scrollbar) in the space that is used for the calculation.
|
|
3536 */
|
|
3537 int
|
|
3538 window_char_height (struct window *w, int include_gutters_p)
|
|
3539 {
|
|
3540 return window_pixel_height_to_char_height (w, WINDOW_HEIGHT (w),
|
|
3541 include_gutters_p);
|
|
3542 }
|
|
3543
|
|
3544 /*
|
|
3545 * Return number of lines currently displayed in window w. If
|
|
3546 * end-of-buffer is displayed then the area below end-of-buffer is assume
|
|
3547 * to be blank lines of default height.
|
|
3548 * Does not include the modeline.
|
|
3549 */
|
|
3550 int
|
|
3551 window_displayed_height (struct window *w)
|
|
3552 {
|
|
3553 struct buffer *b = XBUFFER (w->buffer);
|
|
3554 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
3555 int num_lines;
|
|
3556 Charcount end_pos = (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b)
|
|
3557 ? -1
|
|
3558 : w->window_end_pos[CURRENT_DISP]);
|
|
3559
|
|
3560 if (!Dynarr_length (dla))
|
|
3561 return window_char_height (w, 0);
|
|
3562
|
|
3563 num_lines = Dynarr_length (dla);
|
|
3564
|
|
3565 /* #### Document and assert somewhere that w->window_end_pos == -1
|
|
3566 indicates that end-of-buffer is being displayed. */
|
|
3567 if (end_pos == -1)
|
|
3568 {
|
|
3569 struct display_line *dl = Dynarr_atp (dla, 0);
|
|
3570 int ypos1 = dl->ypos + dl->descent;
|
|
3571 int ypos2 = WINDOW_TEXT_BOTTOM (w);
|
|
3572 Lisp_Object window;
|
|
3573 int defheight, defwidth;
|
|
3574
|
|
3575 XSETWINDOW (window, w);
|
|
3576
|
|
3577 if (dl->modeline)
|
|
3578 {
|
|
3579 num_lines--;
|
|
3580
|
|
3581 if (Dynarr_length (dla) == 1)
|
|
3582 ypos1 = WINDOW_TEXT_TOP (w);
|
|
3583 else
|
|
3584 {
|
|
3585 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
3586 /* If this line is clipped then we know that there is no
|
|
3587 blank room between eob and the modeline. If we are
|
|
3588 scrolling on clipped lines just know off the clipped
|
|
3589 line and return .*/
|
|
3590 if (scroll_on_clipped_lines && dl->clip)
|
149
|
3591 return num_lines - 1;
|
0
|
3592 ypos1 = dl->ypos + dl->descent - dl->clip;
|
|
3593 }
|
|
3594 }
|
|
3595
|
|
3596 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3597 /* #### This probably needs to know about the clipping area once a
|
|
3598 final definition is decided on. */
|
|
3599 num_lines += ((ypos2 - ypos1) / defheight);
|
|
3600 }
|
|
3601 else
|
|
3602 {
|
|
3603 if (num_lines > 1 && Dynarr_atp (dla, 0)->modeline)
|
|
3604 num_lines--;
|
|
3605
|
|
3606 if (scroll_on_clipped_lines
|
|
3607 && Dynarr_atp (dla, Dynarr_length (dla) - 1)->clip)
|
|
3608 num_lines--;
|
|
3609 }
|
|
3610
|
|
3611 return num_lines;
|
|
3612 }
|
|
3613
|
|
3614 static int
|
|
3615 window_pixel_width (Lisp_Object window)
|
|
3616 {
|
149
|
3617 return WINDOW_WIDTH (XWINDOW (window));
|
0
|
3618 }
|
|
3619
|
|
3620 static int
|
|
3621 window_pixel_width_to_char_width (struct window *w, int pixel_width,
|
|
3622 int include_margins_p)
|
|
3623 {
|
|
3624 int avail_width;
|
|
3625 int char_width;
|
|
3626 int defheight, defwidth;
|
|
3627 Lisp_Object window;
|
185
|
3628
|
0
|
3629 XSETWINDOW (window, w);
|
185
|
3630
|
0
|
3631 avail_width = (pixel_width -
|
|
3632 window_left_gutter_width (w, 0) -
|
|
3633 window_right_gutter_width (w, 0) -
|
|
3634 (include_margins_p ? 0 : window_left_margin_width (w)) -
|
|
3635 (include_margins_p ? 0 : window_right_margin_width (w)));
|
185
|
3636
|
0
|
3637 default_face_height_and_width (window, &defheight, &defwidth);
|
185
|
3638
|
0
|
3639 char_width = (avail_width / defwidth);
|
|
3640
|
|
3641 /* It's the calling function's responsibility to check these values
|
|
3642 and make sure they're not out of range.
|
|
3643
|
|
3644 #### We need to go through the calling functions and actually
|
|
3645 do this. */
|
272
|
3646 return max (0, char_width);
|
0
|
3647 }
|
|
3648
|
|
3649 static int
|
|
3650 window_char_width_to_pixel_width (struct window *w, int char_width,
|
|
3651 int include_margins_p)
|
|
3652 {
|
|
3653 int avail_width;
|
|
3654 int pixel_width;
|
|
3655 int defheight, defwidth;
|
|
3656 Lisp_Object window;
|
|
3657
|
|
3658 XSETWINDOW (window, w);
|
|
3659
|
|
3660 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3661
|
|
3662 avail_width = char_width * defwidth;
|
|
3663 pixel_width = (avail_width +
|
|
3664 window_left_gutter_width (w, 0) +
|
|
3665 window_right_gutter_width (w, 0) +
|
|
3666 (include_margins_p ? 0 : window_left_margin_width (w)) +
|
|
3667 (include_margins_p ? 0 : window_right_margin_width (w)));
|
|
3668
|
|
3669 /* It's the calling function's responsibility to check these values
|
|
3670 and make sure they're not out of range.
|
|
3671
|
|
3672 #### We need to go through the calling functions and actually
|
|
3673 do this. */
|
272
|
3674 return max (0, pixel_width);
|
0
|
3675 }
|
|
3676
|
|
3677 /* This returns the usable space which doesn't include space needed by
|
|
3678 scrollbars or divider lines. */
|
|
3679 int
|
|
3680 window_char_width (struct window *w, int include_margins_p)
|
|
3681 {
|
|
3682 return window_pixel_width_to_char_width (w, WINDOW_WIDTH (w),
|
|
3683 include_margins_p);
|
|
3684 }
|
|
3685
|
|
3686 #define MINSIZE(w) \
|
|
3687 (widthflag \
|
|
3688 ? window_min_width * defwidth \
|
|
3689 : (defheight * (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height)))
|
|
3690
|
|
3691 #define CURBEG(w) \
|
|
3692 *(widthflag ? (int *) &WINDOW_LEFT (w) : (int *) &WINDOW_TOP (w))
|
|
3693
|
|
3694 #define CURSIZE(w) \
|
|
3695 *(widthflag ? (int *) &WINDOW_WIDTH (w) : (int *) &WINDOW_HEIGHT (w))
|
|
3696
|
|
3697 #define CURCHARSIZE(w) \
|
|
3698 (widthflag ? window_char_width (w, 0) : window_char_height (w, 1))
|
|
3699
|
|
3700 #define MINCHARSIZE(window) \
|
|
3701 (widthflag ? window_min_width : MINI_WINDOW_P (XWINDOW (window)) \
|
|
3702 ? 1 : window_min_height)
|
|
3703
|
|
3704 /* Unlike set_window_pixheight, this function
|
|
3705 also changes the heights of the siblings so as to
|
|
3706 keep everything consistent. */
|
|
3707
|
|
3708 static void
|
263
|
3709 change_window_height (struct window *win, int delta, int widthflag,
|
|
3710 int inpixels)
|
0
|
3711 {
|
|
3712 Lisp_Object parent;
|
272
|
3713 Lisp_Object window;
|
0
|
3714 struct window *w;
|
|
3715 struct frame *f;
|
|
3716 int *sizep;
|
|
3717 int (*sizefun) (Lisp_Object) = (widthflag
|
|
3718 ? window_pixel_width
|
|
3719 : window_pixel_height);
|
|
3720 void (*setsizefun) (Lisp_Object, int, int) = (widthflag
|
|
3721 ? set_window_pixwidth
|
|
3722 : set_window_pixheight);
|
|
3723 int dim;
|
|
3724 int defheight, defwidth;
|
|
3725
|
|
3726 if (delta == 0)
|
|
3727 return;
|
|
3728
|
|
3729 check_min_window_sizes ();
|
|
3730
|
|
3731 XSETWINDOW (window, win);
|
|
3732 f = XFRAME (win->frame);
|
|
3733 if (EQ (window, FRAME_ROOT_WINDOW (f)))
|
|
3734 error ("Won't change only window");
|
|
3735
|
|
3736 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
3737 functions should be called. */
|
|
3738 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3739
|
|
3740 while (1)
|
|
3741 {
|
|
3742 w = XWINDOW (window);
|
|
3743 parent = w->parent;
|
|
3744 if (NILP (parent))
|
|
3745 {
|
|
3746 if (widthflag)
|
|
3747 error ("No other window to side of this one");
|
|
3748 break;
|
|
3749 }
|
|
3750 if (widthflag
|
|
3751 ? !NILP (XWINDOW (parent)->hchild)
|
|
3752 : !NILP (XWINDOW (parent)->vchild))
|
|
3753 break;
|
|
3754 window = parent;
|
|
3755 }
|
|
3756
|
|
3757 sizep = &CURSIZE (w);
|
|
3758 dim = CURCHARSIZE (w);
|
|
3759
|
263
|
3760 if ((inpixels && (*sizep + delta) < MINSIZE (window)) ||
|
|
3761 (!inpixels && (dim + delta) < MINCHARSIZE (window)))
|
0
|
3762 {
|
|
3763 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
3764 return;
|
|
3765 else if (!NILP (parent))
|
|
3766 {
|
|
3767 Fdelete_window (window, Qnil);
|
|
3768 return;
|
|
3769 }
|
|
3770 }
|
|
3771
|
263
|
3772 if (!inpixels)
|
|
3773 delta *= (widthflag ? defwidth : defheight);
|
0
|
3774
|
|
3775 {
|
|
3776 int maxdelta;
|
|
3777
|
|
3778 maxdelta = ((!NILP (parent))
|
|
3779 ? (*sizefun) (parent) - *sizep
|
|
3780 : ((!NILP (w->next))
|
|
3781 ? (*sizefun) (w->next) - MINSIZE (w->next)
|
|
3782 : ((!NILP (w->prev))
|
|
3783 ? (*sizefun) (w->prev) - MINSIZE (w->prev)
|
185
|
3784 /* This is a frame with only one window,
|
0
|
3785 a minibuffer-only or a minibufferless frame. */
|
|
3786 : (delta = 0))));
|
|
3787
|
|
3788 if (delta > maxdelta)
|
|
3789 /* This case traps trying to make the minibuffer
|
|
3790 the full frame, or make the only window aside from the
|
|
3791 minibuffer the full frame. */
|
|
3792 delta = maxdelta;
|
|
3793
|
|
3794 if (delta == 0)
|
|
3795 return;
|
|
3796
|
|
3797 #if 0 /* FSFmacs */
|
|
3798 /* #### Chuck: is this correct? */
|
|
3799 if (*sizep + delta < MINSIZE (window))
|
|
3800 {
|
|
3801 Fdelete_window (window);
|
|
3802 return;
|
|
3803 }
|
|
3804 #endif
|
|
3805 }
|
|
3806
|
|
3807 if (!NILP (w->next) &&
|
|
3808 (*sizefun) (w->next) - delta >= (int) MINSIZE (w->next))
|
|
3809 {
|
|
3810 CURBEG (XWINDOW (w->next)) += delta;
|
|
3811 (*setsizefun) (w->next, (*sizefun) (w->next) - delta, 0);
|
|
3812 (*setsizefun) (window, *sizep + delta, 0);
|
|
3813 }
|
|
3814 else if (!NILP (w->prev) &&
|
|
3815 (*sizefun) (w->prev) - delta >= (int) MINSIZE (w->prev))
|
|
3816 {
|
|
3817 (*setsizefun) (w->prev, (*sizefun) (w->prev) - delta, 0);
|
|
3818 CURBEG (w) -= delta;
|
|
3819 (*setsizefun) (window, *sizep + delta, 0);
|
|
3820 }
|
|
3821 else
|
|
3822 {
|
|
3823 int delta1;
|
|
3824 int opht = (*sizefun) (parent);
|
|
3825
|
|
3826 /* If trying to grow this window to or beyond size of the parent,
|
|
3827 make delta1 so big that, on shrinking back down,
|
|
3828 all the siblings end up with less than one line and are deleted. */
|
|
3829 if (opht <= *sizep + delta)
|
|
3830 delta1 = opht * opht * 2;
|
|
3831 /* Otherwise, make delta1 just right so that if we add delta1
|
|
3832 lines to this window and to the parent, and then shrink
|
|
3833 the parent back to its original size, the new proportional
|
|
3834 size of this window will increase by delta. */
|
|
3835 else
|
|
3836 delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100);
|
|
3837
|
|
3838 /* Add delta1 lines or columns to this window, and to the parent,
|
|
3839 keeping things consistent while not affecting siblings. */
|
|
3840 CURSIZE (XWINDOW (parent)) = opht + delta1;
|
|
3841 (*setsizefun) (window, *sizep + delta1, 0);
|
|
3842
|
|
3843 /* Squeeze out delta1 lines or columns from our parent,
|
|
3844 shriking this window and siblings proportionately.
|
|
3845 This brings parent back to correct size.
|
|
3846 Delta1 was calculated so this makes this window the desired size,
|
|
3847 taking it all out of the siblings. */
|
|
3848 (*setsizefun) (parent, opht, 0);
|
|
3849 }
|
|
3850
|
|
3851 SET_LAST_MODIFIED (w, 0);
|
|
3852 SET_LAST_FACECHANGE (w);
|
|
3853 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
3854 }
|
|
3855 #undef MINSIZE
|
|
3856 #undef CURBEG
|
|
3857 #undef CURSIZE
|
|
3858 #undef CURCHARSIZE
|
|
3859 #undef MINCHARSIZE
|
|
3860
|
|
3861
|
|
3862
|
|
3863 /* Scroll contents of window WINDOW up N lines. */
|
|
3864 void
|
|
3865 window_scroll (Lisp_Object window, Lisp_Object n, int direction,
|
|
3866 Error_behavior errb)
|
|
3867 {
|
|
3868 struct window *w = XWINDOW (window);
|
|
3869 struct buffer *b = XBUFFER (w->buffer);
|
|
3870 int selected = EQ (window, Fselected_window (Qnil));
|
|
3871 int value = 0;
|
|
3872 Lisp_Object point, tem;
|
|
3873
|
|
3874 if (selected)
|
|
3875 point = make_int (BUF_PT (b));
|
|
3876 else
|
|
3877 {
|
|
3878 Bufpos pos = marker_position (w->pointm[CURRENT_DISP]);
|
|
3879
|
|
3880 if (pos < BUF_BEGV (b))
|
|
3881 pos = BUF_BEGV (b);
|
|
3882 else if (pos > BUF_ZV (b))
|
|
3883 pos = BUF_ZV (b);
|
|
3884
|
|
3885 point = make_int (pos);
|
|
3886 }
|
|
3887
|
|
3888 /* Always set force_start so that redisplay_window will run
|
|
3889 thw window-scroll-functions. */
|
|
3890 w->force_start = 1;
|
|
3891
|
|
3892 /* #### When the fuck does this happen? I'm so glad that history has
|
|
3893 completely documented the behavior of the scrolling functions under
|
|
3894 all circumstances. */
|
|
3895 tem = Fpos_visible_in_window_p (point, window);
|
|
3896 if (NILP (tem))
|
|
3897 {
|
|
3898 Fvertical_motion (make_int (-window_char_height (w, 0) / 2), window);
|
|
3899 Fset_marker (w->start[CURRENT_DISP], point, w->buffer);
|
|
3900 w->start_at_line_beg = beginning_of_line_p (b, XINT (point));
|
|
3901 MARK_WINDOWS_CHANGED (w);
|
|
3902 }
|
|
3903
|
|
3904 if (!NILP (n))
|
|
3905 {
|
|
3906 if (EQ (n, Qminus))
|
|
3907 direction *= -1;
|
|
3908 else
|
|
3909 {
|
|
3910 n = Fprefix_numeric_value (n);
|
|
3911 value = XINT (n) * direction;
|
|
3912
|
|
3913 if (!value)
|
|
3914 return; /* someone just made a pointless call */
|
|
3915 }
|
|
3916 }
|
|
3917
|
|
3918 /* If the user didn't specify how far to scroll then we have to figure it
|
|
3919 out by ourselves. */
|
|
3920 if (NILP (n) || EQ (n, Qminus))
|
|
3921 {
|
|
3922 /* Going forwards is easy. If that is what we are doing then just
|
|
3923 set value and the section which handles the user specifying a
|
|
3924 positive value will work. */
|
|
3925 if (direction == 1)
|
|
3926 {
|
|
3927 value = window_displayed_height (w) - next_screen_context_lines;
|
|
3928 value = (value < 1 ? 1 : value);
|
|
3929 }
|
|
3930
|
|
3931 /* Going backwards is hard. We can't use the same loop used if the
|
|
3932 user specified a negative value because we care about
|
|
3933 next_screen_context_lines. In a variable height world you don't
|
|
3934 know how many lines above you can actually be displayed and still
|
|
3935 have the context lines appear. So we leave value set to 0 and add
|
|
3936 a separate section to deal with this. */
|
|
3937
|
|
3938 }
|
|
3939
|
|
3940 if (direction == 1 && !value)
|
|
3941 {
|
|
3942 return;
|
|
3943 }
|
|
3944 else if (value > 0)
|
|
3945 {
|
|
3946 int vtarget;
|
|
3947 Bufpos startp, old_start;
|
|
3948
|
|
3949 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
3950 startp = vmotion (w, old_start, value, &vtarget);
|
|
3951
|
|
3952 if (vtarget < value &&
|
|
3953 (w->window_end_pos[CURRENT_DISP] == -1
|
|
3954 || (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b))))
|
|
3955 {
|
|
3956 maybe_signal_error (Qend_of_buffer, Qnil, Qwindow, errb);
|
|
3957 return;
|
|
3958 }
|
|
3959 else
|
|
3960 {
|
|
3961 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
3962 w->buffer);
|
|
3963 w->force_start = 1;
|
|
3964 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
3965 MARK_WINDOWS_CHANGED (w);
|
|
3966
|
|
3967 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
3968 {
|
|
3969 if (selected)
|
|
3970 BUF_SET_PT (b, startp);
|
|
3971 else
|
|
3972 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
3973 make_int (startp),
|
|
3974 w->buffer);
|
|
3975 }
|
|
3976 }
|
|
3977 }
|
|
3978 else if (value < 0)
|
|
3979 {
|
|
3980 int vtarget;
|
|
3981 Bufpos startp, old_start;
|
|
3982
|
|
3983 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
3984 startp = vmotion (w, old_start, value, &vtarget);
|
|
3985
|
|
3986 if (vtarget > value
|
|
3987 && marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
3988 {
|
|
3989 maybe_signal_error (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
|
3990 return;
|
|
3991 }
|
|
3992 else
|
|
3993 {
|
|
3994 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
3995 w->buffer);
|
|
3996 w->force_start = 1;
|
|
3997 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
3998 MARK_WINDOWS_CHANGED (w);
|
|
3999
|
|
4000 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
4001 {
|
|
4002 Bufpos new_point;
|
|
4003
|
|
4004 if (MINI_WINDOW_P (w))
|
|
4005 new_point = startp;
|
|
4006 else
|
|
4007 new_point = start_of_last_line (w, startp);
|
|
4008
|
|
4009 if (selected)
|
|
4010 BUF_SET_PT (b, new_point);
|
|
4011 else
|
|
4012 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
4013 make_int (new_point),
|
|
4014 w->buffer);
|
|
4015 }
|
|
4016 }
|
|
4017 }
|
|
4018 else /* value == 0 && direction == -1 */
|
|
4019 {
|
|
4020 if (marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
4021 {
|
|
4022 maybe_signal_error (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
|
4023 return;
|
|
4024 }
|
|
4025 else
|
|
4026 {
|
|
4027 int vtarget;
|
|
4028 int movement = next_screen_context_lines - 1;
|
|
4029 Bufpos old_startp = marker_position (w->start[CURRENT_DISP]);
|
|
4030 Bufpos bottom = vmotion (w, old_startp, movement, &vtarget);
|
|
4031 Bufpos startp =
|
|
4032 start_with_point_on_display_line (w, bottom,
|
|
4033 -1 - (movement - vtarget));
|
|
4034
|
|
4035 if (startp >= old_startp)
|
|
4036 startp = vmotion (w, old_startp, -1, NULL);
|
|
4037
|
|
4038 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
4039 w->buffer);
|
|
4040 w->force_start = 1;
|
|
4041 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4042 MARK_WINDOWS_CHANGED (w);
|
|
4043
|
|
4044 if (!point_would_be_visible (w, startp, XINT (point)))
|
|
4045 {
|
|
4046 Bufpos new_point = start_of_last_line (w, startp);
|
|
4047
|
|
4048 if (selected)
|
|
4049 BUF_SET_PT (b, new_point);
|
|
4050 else
|
|
4051 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
4052 make_int (new_point),
|
|
4053 w->buffer);
|
|
4054 }
|
|
4055 }
|
|
4056 }
|
|
4057
|
|
4058 }
|
|
4059
|
20
|
4060 DEFUN ("scroll-up", Fscroll_up, 0, 1, "_P", /*
|
0
|
4061 Scroll text of current window upward ARG lines; or near full screen if no ARG.
|
|
4062 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
4063 Negative ARG means scroll downward.
|
|
4064 When calling from a program, supply a number as argument or nil.
|
265
|
4065 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
4066 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
4067 signaled.
|
20
|
4068 */
|
|
4069 (n))
|
0
|
4070 {
|
265
|
4071 window_scroll (Fselected_window (Qnil), n, 1, ERROR_ME);
|
0
|
4072 return Qnil;
|
|
4073 }
|
|
4074
|
20
|
4075 DEFUN ("scroll-down", Fscroll_down, 0, 1, "_P", /*
|
0
|
4076 Scroll text of current window downward ARG lines; or near full screen if no ARG.
|
|
4077 A near full screen is `next-screen-context-lines' less than a full screen.
|
|
4078 Negative ARG means scroll upward.
|
|
4079 When calling from a program, supply a number as argument or nil.
|
265
|
4080 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
4081 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
4082 signaled.
|
20
|
4083 */
|
|
4084 (n))
|
0
|
4085 {
|
265
|
4086 window_scroll (Fselected_window (Qnil), n, -1, ERROR_ME);
|
0
|
4087 return Qnil;
|
|
4088 }
|
|
4089
|
20
|
4090 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, 0, 0, 0, /*
|
185
|
4091 Return the other window for "other window scroll" commands.
|
0
|
4092 If in the minibuffer, `minibuffer-scroll-window' if non-nil
|
|
4093 specifies the window.
|
|
4094 If `other-window-scroll-buffer' is non-nil, a window
|
|
4095 showing that buffer is used.
|
20
|
4096 */
|
|
4097 ())
|
0
|
4098 {
|
|
4099 Lisp_Object window;
|
|
4100 Lisp_Object selected_window = Fselected_window (Qnil);
|
|
4101
|
|
4102 if (MINI_WINDOW_P (XWINDOW (selected_window))
|
274
|
4103 && !NILP (Vminibuffer_scroll_window))
|
|
4104 window = Vminibuffer_scroll_window;
|
0
|
4105 /* If buffer is specified, scroll that buffer. */
|
|
4106 else if (!NILP (Vother_window_scroll_buffer))
|
|
4107 {
|
|
4108 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil, Qnil);
|
|
4109 if (NILP (window))
|
|
4110 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
|
|
4111 }
|
|
4112 else
|
|
4113 {
|
|
4114 /* Nothing specified; look for a neighboring window on the same
|
|
4115 frame. */
|
|
4116 window = Fnext_window (selected_window, Qnil, Qnil, Qnil);
|
|
4117
|
|
4118 if (EQ (window, selected_window))
|
|
4119 /* That didn't get us anywhere; look for a window on another
|
|
4120 visible frame. */
|
|
4121 do
|
|
4122 window = Fnext_window (window, Qnil, Qt, Qnil);
|
|
4123 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
|
|
4124 && ! EQ (window, selected_window));
|
|
4125 }
|
|
4126
|
|
4127 CHECK_LIVE_WINDOW (window);
|
|
4128
|
|
4129 if (EQ (window, selected_window))
|
|
4130 error ("There is no other window");
|
|
4131
|
|
4132 return window;
|
|
4133 }
|
|
4134
|
20
|
4135 DEFUN ("scroll-other-window", Fscroll_other_window, 0, 1, "_P", /*
|
0
|
4136 Scroll next window upward ARG lines; or near full frame if no ARG.
|
|
4137 The next window is the one below the current one; or the one at the top
|
|
4138 if the current one is at the bottom. Negative ARG means scroll downward.
|
|
4139 When calling from a program, supply a number as argument or nil.
|
|
4140
|
274
|
4141 If in the minibuffer, `minibuffer-scroll-window' if non-nil
|
0
|
4142 specifies the window to scroll.
|
|
4143 If `other-window-scroll-buffer' is non-nil, scroll the window
|
|
4144 showing that buffer, popping the buffer up if necessary.
|
20
|
4145 */
|
|
4146 (n))
|
0
|
4147 {
|
|
4148 window_scroll (Fother_window_for_scrolling (), n, 1, ERROR_ME);
|
|
4149 return Qnil;
|
|
4150 }
|
|
4151
|
20
|
4152 DEFUN ("scroll-left", Fscroll_left, 0, 1, "_P", /*
|
0
|
4153 Scroll selected window display ARG columns left.
|
|
4154 Default for ARG is window width minus 2.
|
20
|
4155 */
|
|
4156 (arg))
|
0
|
4157 {
|
|
4158 Lisp_Object window = Fselected_window (Qnil);
|
|
4159 struct window *w = XWINDOW (window);
|
|
4160
|
|
4161 if (NILP (arg))
|
|
4162 arg = make_int (window_char_width (w, 0) - 2);
|
|
4163 else
|
|
4164 arg = Fprefix_numeric_value (arg);
|
|
4165
|
149
|
4166 return Fset_window_hscroll (window, make_int (w->hscroll + XINT (arg)));
|
0
|
4167 }
|
|
4168
|
20
|
4169 DEFUN ("scroll-right", Fscroll_right, 0, 1, "_P", /*
|
0
|
4170 Scroll selected window display ARG columns right.
|
|
4171 Default for ARG is window width minus 2.
|
20
|
4172 */
|
|
4173 (arg))
|
0
|
4174 {
|
|
4175 Lisp_Object window = Fselected_window (Qnil);
|
|
4176 struct window *w = XWINDOW (window);
|
|
4177
|
|
4178 if (NILP (arg))
|
|
4179 arg = make_int (window_char_width (w, 0) - 2);
|
|
4180 else
|
|
4181 arg = Fprefix_numeric_value (arg);
|
|
4182
|
149
|
4183 return Fset_window_hscroll (window, make_int (w->hscroll - XINT (arg)));
|
0
|
4184 }
|
280
|
4185
|
|
4186 DEFUN ("center-to-window-line", Fcenter_to_window_line, 0, 2, "_P", /*
|
|
4187 Center point in WINDOW. With N, put point on line N.
|
0
|
4188 The desired position of point is always relative to the window.
|
|
4189 If WINDOW is nil, the selected window is used.
|
20
|
4190 */
|
|
4191 (n, window))
|
0
|
4192 {
|
280
|
4193 struct window *w = decode_window (window);
|
|
4194 struct buffer *b = XBUFFER (w->buffer);
|
|
4195 Bufpos opoint = BUF_PT (b);
|
0
|
4196 Bufpos startp;
|
280
|
4197
|
|
4198 if (NILP (n))
|
|
4199 startp = start_with_line_at_pixpos (w, opoint, window_half_pixpos (w));
|
0
|
4200 else
|
|
4201 {
|
|
4202 n = Fprefix_numeric_value (n);
|
|
4203 CHECK_INT (n);
|
|
4204 startp = start_with_point_on_display_line (w, opoint, XINT (n));
|
|
4205 }
|
|
4206
|
|
4207 Fset_marker (w->start[CURRENT_DISP], make_int (startp), w->buffer);
|
185
|
4208
|
0
|
4209 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4210 w->force_start = 1;
|
|
4211 MARK_WINDOWS_CHANGED (w);
|
|
4212 return Qnil;
|
|
4213 }
|
280
|
4214
|
20
|
4215 DEFUN ("move-to-window-line", Fmove_to_window_line, 1, 2, "_P", /*
|
0
|
4216 Position point relative to WINDOW.
|
|
4217 With no argument, position text at center of window.
|
|
4218 An argument specifies window line; zero means top of window,
|
|
4219 negative means relative to bottom of window.
|
|
4220 If WINDOW is nil, the selected window is used.
|
20
|
4221 */
|
|
4222 (arg, window))
|
0
|
4223 {
|
|
4224 struct window *w;
|
|
4225 struct buffer *b;
|
|
4226 int height;
|
|
4227 Bufpos start, new_point;
|
|
4228 int selected;
|
|
4229
|
280
|
4230 /* Don't use decode_window() because we need the new value of
|
|
4231 WINDOW. */
|
0
|
4232 if (NILP (window))
|
|
4233 window = Fselected_window (Qnil);
|
|
4234 else
|
|
4235 CHECK_WINDOW (window);
|
|
4236 w = XWINDOW (window);
|
|
4237 b = XBUFFER (w->buffer);
|
|
4238
|
|
4239 height = window_displayed_height (w);
|
|
4240 selected = EQ (window, Fselected_window (w->frame));
|
|
4241
|
|
4242 if (NILP (arg))
|
|
4243 {
|
|
4244 int retval;
|
|
4245
|
|
4246 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
|
|
4247 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b))
|
|
4248 {
|
|
4249 new_point = point_at_center (w, CURRENT_DISP, 0, 0);
|
|
4250
|
|
4251 if (selected)
|
|
4252 BUF_SET_PT (b, new_point);
|
|
4253 else
|
|
4254 Fset_window_point (window, make_int (new_point));
|
|
4255
|
|
4256 retval = line_at_center (w, CURRENT_DISP, 0, 0);
|
|
4257 }
|
|
4258 else
|
|
4259 {
|
|
4260 start = marker_position (w->start[CURRENT_DISP]);
|
|
4261 if (start < BUF_BEGV (b))
|
|
4262 start = BUF_BEGV (b);
|
|
4263 else if (start > BUF_ZV (b))
|
|
4264 start = BUF_ZV (b);
|
|
4265
|
|
4266 if (selected)
|
|
4267 new_point = BUF_PT (b);
|
|
4268 else
|
|
4269 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4270
|
|
4271 new_point = point_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4272
|
|
4273 if (selected)
|
|
4274 BUF_SET_PT (b, new_point);
|
|
4275 else
|
|
4276 Fset_window_point (window, make_int (new_point));
|
|
4277
|
|
4278 retval = line_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4279 }
|
|
4280
|
149
|
4281 return make_int (retval);
|
0
|
4282 }
|
|
4283 else
|
|
4284 {
|
|
4285 /* #### Is this going to work right when at eob? */
|
|
4286 arg = Fprefix_numeric_value (arg);
|
|
4287 if (XINT (arg) < 0)
|
|
4288 XSETINT (arg, XINT (arg) + height);
|
|
4289 }
|
|
4290
|
|
4291 start = marker_position (w->start[CURRENT_DISP]);
|
|
4292 if (start < BUF_BEGV (b) || start > BUF_ZV (b))
|
|
4293 {
|
|
4294 if (selected)
|
|
4295 new_point = BUF_PT (b);
|
|
4296 else
|
|
4297 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4298
|
|
4299 new_point = vmotion (XWINDOW (window), new_point, -height / 2, 0);
|
|
4300
|
|
4301 if (selected)
|
|
4302 BUF_SET_PT (b, new_point);
|
|
4303 else
|
|
4304 Fset_window_point (window, make_int (new_point));
|
|
4305
|
|
4306 Fset_marker (w->start[CURRENT_DISP], make_int (new_point),
|
|
4307 w->buffer);
|
|
4308 w->start_at_line_beg = beginning_of_line_p (b, new_point);
|
|
4309 w->force_start = 1;
|
|
4310 }
|
|
4311 else
|
|
4312 {
|
|
4313 if (selected)
|
|
4314 BUF_SET_PT (b, start);
|
|
4315 else
|
|
4316 Fset_window_point (window, make_int (start));
|
|
4317 }
|
|
4318
|
|
4319 if (selected)
|
|
4320 return Fvertical_motion (arg, window);
|
|
4321 else
|
|
4322 {
|
|
4323 int vpos;
|
|
4324 new_point = vmotion (XWINDOW (window),
|
|
4325 marker_position (w->pointm[CURRENT_DISP]),
|
|
4326 XINT (arg), &vpos);
|
|
4327 Fset_window_point (window, make_int (new_point));
|
|
4328 return make_int (vpos);
|
|
4329 }
|
|
4330 }
|
|
4331
|
|
4332
|
|
4333 static int
|
|
4334 map_windows_1 (Lisp_Object window,
|
|
4335 int (*mapfun) (struct window *w, void *closure),
|
|
4336 void *closure)
|
|
4337 {
|
|
4338 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
4339 {
|
272
|
4340 int retval;
|
0
|
4341 struct window *w = XWINDOW (window);
|
251
|
4342
|
0
|
4343 if (!NILP (w->vchild))
|
|
4344 retval = map_windows_1 (w->vchild, mapfun, closure);
|
|
4345 else if (!NILP (w->hchild))
|
|
4346 retval = map_windows_1 (w->hchild, mapfun, closure);
|
|
4347 else
|
|
4348 retval = (mapfun) (w, closure);
|
272
|
4349
|
0
|
4350 if (retval)
|
|
4351 return retval;
|
|
4352 }
|
|
4353
|
272
|
4354 return 0;
|
0
|
4355 }
|
|
4356
|
|
4357 /* Map MAPFUN over the windows in F. CLOSURE is passed to each
|
251
|
4358 invocation of MAPFUN. If any invocation of MAPFUN returns
|
|
4359 non-zero, the mapping is halted. Otherwise, map_windows() maps
|
|
4360 over all windows in F.
|
|
4361
|
286
|
4362 If MAPFUN creates or deletes windows, the behaviour is undefined. */
|
251
|
4363
|
284
|
4364 int
|
0
|
4365 map_windows (struct frame *f, int (*mapfun) (struct window *w, void *closure),
|
|
4366 void *closure)
|
|
4367 {
|
251
|
4368 if (f)
|
284
|
4369 return map_windows_1 (FRAME_ROOT_WINDOW (f), mapfun, closure);
|
251
|
4370 else
|
|
4371 {
|
|
4372 Lisp_Object frmcons, devcons, concons;
|
|
4373
|
|
4374 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons)
|
|
4375 {
|
284
|
4376 int v = map_windows_1 (FRAME_ROOT_WINDOW (XFRAME (XCAR (frmcons))),
|
|
4377 mapfun, closure);
|
|
4378 if (v)
|
|
4379 return v;
|
251
|
4380 }
|
|
4381 }
|
286
|
4382
|
|
4383 return 0;
|
0
|
4384 }
|
|
4385
|
|
4386
|
|
4387 static void
|
|
4388 modeline_shadow_thickness_changed (Lisp_Object specifier, struct window *w,
|
|
4389 Lisp_Object oldval)
|
|
4390 {
|
|
4391 w->shadow_thickness_changed = 1;
|
|
4392 MARK_WINDOWS_CHANGED (w);
|
|
4393 }
|
|
4394
|
284
|
4395 static void
|
|
4396 vertical_divider_changed_in_window (Lisp_Object specifier,
|
|
4397 struct window *w,
|
|
4398 Lisp_Object oldval)
|
|
4399 {
|
|
4400 MARK_WINDOWS_CHANGED (w);
|
|
4401 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (XFRAME (WINDOW_FRAME (w)));
|
|
4402 }
|
|
4403
|
0
|
4404 /* also used in scrollbar.c */
|
|
4405 void
|
|
4406 some_window_value_changed (Lisp_Object specifier, struct window *w,
|
|
4407 Lisp_Object oldval)
|
|
4408 {
|
|
4409 MARK_WINDOWS_CHANGED (w);
|
|
4410 }
|
|
4411
|
|
4412 #ifdef MEMORY_USAGE_STATS
|
|
4413
|
|
4414 struct window_stats
|
|
4415 {
|
|
4416 int face;
|
|
4417 int glyph;
|
|
4418 #ifdef HAVE_SCROLLBARS
|
|
4419 int scrollbar;
|
|
4420 #endif
|
|
4421 int line_start;
|
|
4422 int other_redisplay;
|
|
4423 int other;
|
|
4424 };
|
|
4425
|
|
4426 static void
|
|
4427 compute_window_mirror_usage (struct window_mirror *mir,
|
|
4428 struct window_stats *stats,
|
|
4429 struct overhead_stats *ovstats)
|
|
4430 {
|
|
4431 if (!mir)
|
|
4432 return;
|
|
4433 stats->other += malloced_storage_size (mir, sizeof (struct window_mirror),
|
|
4434 ovstats);
|
|
4435 #ifdef HAVE_SCROLLBARS
|
|
4436 {
|
|
4437 struct device *d = XDEVICE (FRAME_DEVICE (mir->frame));
|
|
4438
|
|
4439 stats->scrollbar +=
|
|
4440 compute_scrollbar_instance_usage (d, mir->scrollbar_vertical_instance,
|
|
4441 ovstats);
|
|
4442 stats->scrollbar +=
|
|
4443 compute_scrollbar_instance_usage (d, mir->scrollbar_horizontal_instance,
|
|
4444 ovstats);
|
|
4445 }
|
149
|
4446 #endif /* HAVE_SCROLLBARS */
|
0
|
4447 stats->other_redisplay +=
|
|
4448 compute_display_line_dynarr_usage (mir->current_display_lines, ovstats);
|
|
4449 stats->other_redisplay +=
|
|
4450 compute_display_line_dynarr_usage (mir->desired_display_lines, ovstats);
|
|
4451 }
|
|
4452
|
|
4453 static void
|
|
4454 compute_window_usage (struct window *w, struct window_stats *stats,
|
|
4455 struct overhead_stats *ovstats)
|
|
4456 {
|
272
|
4457 xzero (*stats);
|
0
|
4458 stats->other += malloced_storage_size (w, sizeof (struct window), ovstats);
|
|
4459 stats->face += compute_face_cachel_usage (w->face_cachels, ovstats);
|
|
4460 stats->glyph += compute_glyph_cachel_usage (w->glyph_cachels, ovstats);
|
|
4461 stats->line_start +=
|
|
4462 compute_line_start_cache_dynarr_usage (w->line_start_cache, ovstats);
|
|
4463 compute_window_mirror_usage (find_window_mirror (w), stats, ovstats);
|
|
4464 }
|
|
4465
|
20
|
4466 DEFUN ("window-memory-usage", Fwindow_memory_usage, 1, 1, 0, /*
|
0
|
4467 Return stats about the memory usage of window WINDOW.
|
272
|
4468 The values returned are in the form of an alist of usage types and byte
|
0
|
4469 counts. The byte counts attempt to encompass all the memory used
|
|
4470 by the window (separate from the memory logically associated with a
|
|
4471 buffer or frame), including internal structures and any malloc()
|
|
4472 overhead associated with them. In practice, the byte counts are
|
|
4473 underestimated because certain memory usage is very hard to determine
|
272
|
4474 \(e.g. the amount of memory used inside the Xt library or inside the
|
0
|
4475 X server) and because there is other stuff that might logically
|
|
4476 be associated with a window, buffer, or frame (e.g. window configurations,
|
|
4477 glyphs) but should not obviously be included in the usage counts.
|
|
4478
|
|
4479 Multiple slices of the total memory usage may be returned, separated
|
|
4480 by a nil. Each slice represents a particular view of the memory, a
|
|
4481 particular way of partitioning it into groups. Within a slice, there
|
|
4482 is no overlap between the groups of memory, and each slice collectively
|
|
4483 represents all the memory concerned.
|
20
|
4484 */
|
|
4485 (window))
|
0
|
4486 {
|
|
4487 struct window_stats stats;
|
|
4488 struct overhead_stats ovstats;
|
272
|
4489 Lisp_Object val = Qnil;
|
0
|
4490
|
|
4491 CHECK_WINDOW (window); /* dead windows should be allowed, no? */
|
272
|
4492 xzero (ovstats);
|
0
|
4493 compute_window_usage (XWINDOW (window), &stats, &ovstats);
|
|
4494
|
272
|
4495 val = acons (Qface_cache, make_int (stats.face), val);
|
|
4496 val = acons (Qglyph_cache, make_int (stats.glyph), val);
|
0
|
4497 #ifdef HAVE_SCROLLBARS
|
272
|
4498 val = acons (Qscrollbar_instances, make_int (stats.scrollbar), val);
|
0
|
4499 #endif
|
272
|
4500 val = acons (Qline_start_cache, make_int (stats.line_start), val);
|
|
4501 val = acons (Qother_redisplay, make_int (stats.other_redisplay), val);
|
|
4502 val = acons (Qother, make_int (stats.other), val);
|
|
4503 val = Fcons (Qnil, val);
|
|
4504 val = acons (Qactually_requested, make_int (ovstats.was_requested), val);
|
|
4505 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val);
|
|
4506 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val);
|
|
4507
|
|
4508 return Fnreverse (val);
|
0
|
4509 }
|
|
4510
|
|
4511 #endif /* MEMORY_USAGE_STATS */
|
|
4512
|
|
4513
|
|
4514 /************************************************************************/
|
|
4515 /* Window configurations */
|
|
4516 /************************************************************************/
|
|
4517
|
|
4518 /* #### This window configuration stuff has had serious bugs lurking in it
|
|
4519 for years; it would be a -huge- win if this was reimplemented in lisp.
|
|
4520 */
|
|
4521
|
|
4522 /* If you add anything to this structure make sure saved_window_equal
|
|
4523 knows about it. */
|
|
4524 struct saved_window
|
|
4525 {
|
|
4526 Lisp_Object window; /* window */
|
|
4527 Lisp_Object buffer; /* buffer */
|
|
4528 Lisp_Object start; /* copied marker */
|
|
4529 Lisp_Object pointm; /* copied marker */
|
|
4530 Lisp_Object sb_point; /* copied marker */
|
|
4531 Lisp_Object mark; /* copied marker */
|
|
4532 int pixel_left;
|
|
4533 int pixel_top;
|
|
4534 int pixel_width;
|
|
4535 int pixel_height;
|
|
4536 int hscroll;
|
257
|
4537 int modeline_hscroll;
|
0
|
4538 int parent_index; /* index into saved_windows */
|
|
4539 int prev_index; /* index into saved_windows */
|
|
4540 char start_at_line_beg; /* boolean */
|
284
|
4541
|
|
4542 #define WINDOW_SLOT_DECLARATION
|
|
4543 #define WINDOW_SLOT(slot, compare) Lisp_Object slot
|
|
4544 #include "winslots.h"
|
0
|
4545 };
|
|
4546
|
|
4547 /* If you add anything to this structure make sure window_config_equal
|
|
4548 knows about it. */
|
|
4549 struct window_config
|
|
4550 {
|
|
4551 struct lcrecord_header header;
|
|
4552 int frame_width;
|
|
4553 int frame_height;
|
|
4554 #if 0 /* FSFmacs */
|
|
4555 Lisp_Object selected_frame;
|
|
4556 #endif
|
|
4557 Lisp_Object current_window;
|
|
4558 Lisp_Object current_buffer;
|
274
|
4559 Lisp_Object minibuffer_scroll_window;
|
0
|
4560 Lisp_Object root_window;
|
|
4561 /* Record the values of window-min-width and window-min-height
|
|
4562 so that window sizes remain consistent with them. */
|
|
4563 int min_width, min_height;
|
|
4564 int saved_windows_count;
|
|
4565 /* Zero-sized arrays aren't ANSI C */
|
|
4566 struct saved_window saved_windows[1];
|
|
4567 };
|
272
|
4568
|
0
|
4569 #define SAVED_WINDOW_N(conf, n) (&((conf)->saved_windows[(n)]))
|
|
4570 #define XWINDOW_CONFIGURATION(x) XRECORD (x, window_configuration, struct window_config)
|
|
4571 #define XSETWINDOW_CONFIGURATION(x, p) XSETRECORD (x, p, window_configuration)
|
|
4572 #define WINDOW_CONFIGURATIONP(x) RECORDP (x, window_configuration)
|
|
4573 #define GC_WINDOW_CONFIGURATIONP(x) GC_RECORDP (x, window_configuration)
|
|
4574 #define CHECK_WINDOW_CONFIGURATION(x) CHECK_RECORD (x, window_configuration)
|
|
4575
|
|
4576 static Lisp_Object
|
|
4577 mark_window_config (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
4578 {
|
|
4579 struct window_config *config = XWINDOW_CONFIGURATION (obj);
|
|
4580 int i;
|
|
4581 ((markobj) (config->current_window));
|
|
4582 ((markobj) (config->current_buffer));
|
274
|
4583 ((markobj) (config->minibuffer_scroll_window));
|
0
|
4584 ((markobj) (config->root_window));
|
217
|
4585
|
0
|
4586 for (i = 0; i < config->saved_windows_count; i++)
|
|
4587 {
|
|
4588 struct saved_window *s = SAVED_WINDOW_N (config, i);
|
|
4589 ((markobj) (s->window));
|
|
4590 ((markobj) (s->buffer));
|
|
4591 ((markobj) (s->start));
|
|
4592 ((markobj) (s->pointm));
|
|
4593 ((markobj) (s->sb_point));
|
|
4594 ((markobj) (s->mark));
|
284
|
4595 #if 0
|
|
4596 /* #### This looked like this. I do not see why specifier cached
|
|
4597 values should not be marked, as such specifiers as toolbars
|
|
4598 might have GC-able instances. Freed configs are not marked,
|
|
4599 aren't they? -- kkm */
|
0
|
4600 ((markobj) (s->dedicated));
|
284
|
4601 #else
|
|
4602 #define WINDOW_SLOT(slot, compare) ((markobj) (s->slot))
|
|
4603 #include "winslots.h"
|
|
4604 #endif
|
0
|
4605 }
|
149
|
4606 return Qnil;
|
0
|
4607 }
|
|
4608
|
272
|
4609 static size_t
|
0
|
4610 sizeof_window_config_for_n_windows (int n)
|
|
4611 {
|
|
4612 return (sizeof (struct window_config) +
|
|
4613 /* n - 1 because zero-sized arrays aren't ANSI C */
|
|
4614 (n - 1) *sizeof (struct saved_window));
|
|
4615 }
|
|
4616
|
272
|
4617 static size_t
|
0
|
4618 sizeof_window_config (CONST void *h)
|
|
4619 {
|
185
|
4620 CONST struct window_config *c = (CONST struct window_config *) h;
|
0
|
4621 return sizeof_window_config_for_n_windows (c->saved_windows_count);
|
|
4622 }
|
|
4623
|
|
4624 static void
|
|
4625 print_window_config (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
4626 {
|
|
4627 struct window_config *config = XWINDOW_CONFIGURATION (obj);
|
|
4628 char buf[200];
|
|
4629 if (print_readably)
|
|
4630 error ("printing unreadable object #<window-configuration 0x%x>",
|
|
4631 config->header.uid);
|
|
4632 write_c_string ("#<window-configuration ", printcharfun);
|
|
4633 sprintf (buf, "0x%x>", config->header.uid);
|
|
4634 write_c_string (buf, printcharfun);
|
|
4635 }
|
|
4636
|
272
|
4637 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("window-configuration",
|
|
4638 window_configuration,
|
|
4639 mark_window_config,
|
|
4640 print_window_config,
|
|
4641 0, 0, 0, sizeof_window_config,
|
|
4642 struct window_config);
|
|
4643
|
|
4644
|
0
|
4645 /* Returns a boolean indicating whether the two saved windows are
|
|
4646 identical. */
|
|
4647 static int
|
|
4648 saved_window_equal (struct saved_window *win1, struct saved_window *win2)
|
|
4649 {
|
284
|
4650 #define WINDOW_SLOT(slot, compare) \
|
|
4651 if (!compare (win1->slot, win2->slot)) \
|
|
4652 return 0;
|
|
4653 #include "winslots.h"
|
|
4654
|
149
|
4655 return
|
|
4656 EQ (win1->window, win2->window) &&
|
|
4657 EQ (win1->buffer, win2->buffer) &&
|
195
|
4658 internal_equal (win1->start, win2->start, 0) &&
|
|
4659 internal_equal (win1->pointm, win2->pointm, 0) &&
|
|
4660 internal_equal (win1->sb_point, win2->sb_point, 0) &&
|
|
4661 internal_equal (win1->mark, win2->mark, 0) &&
|
149
|
4662 win1->pixel_left == win2->pixel_left &&
|
|
4663 win1->pixel_top == win2->pixel_top &&
|
|
4664 win1->pixel_width == win2->pixel_width &&
|
|
4665 win1->pixel_height == win2->pixel_height &&
|
|
4666 win1->hscroll == win2->hscroll &&
|
257
|
4667 win1->modeline_hscroll == win2->modeline_hscroll &&
|
149
|
4668 win1->parent_index == win2->parent_index &&
|
|
4669 win1->prev_index == win2->prev_index &&
|
284
|
4670 win1->start_at_line_beg == win2->start_at_line_beg;
|
0
|
4671 }
|
|
4672
|
|
4673 /* Returns a boolean indicating whether the two given configurations
|
|
4674 are identical. */
|
|
4675 static int
|
|
4676 window_config_equal (Lisp_Object conf1, Lisp_Object conf2)
|
|
4677 {
|
|
4678 struct window_config *fig1, *fig2;
|
|
4679 int i;
|
|
4680
|
|
4681 /* First check if they are truly the same. */
|
|
4682 if (EQ (conf1, conf2))
|
|
4683 return 1;
|
|
4684
|
|
4685 fig1 = XWINDOW_CONFIGURATION (conf1);
|
|
4686 fig2 = XWINDOW_CONFIGURATION (conf2);
|
|
4687
|
149
|
4688 if (!((fig1->saved_windows_count == fig2->saved_windows_count) &&
|
274
|
4689 EQ (fig1->current_window, fig2->current_window) &&
|
|
4690 EQ (fig1->current_buffer, fig2->current_buffer) &&
|
|
4691 EQ (fig1->root_window, fig2->root_window) &&
|
|
4692 EQ (fig1->minibuffer_scroll_window, fig2->minibuffer_scroll_window) &&
|
149
|
4693 fig1->frame_width == fig2->frame_width &&
|
|
4694 fig1->frame_height == fig2->frame_height))
|
0
|
4695 return 0;
|
|
4696
|
|
4697 for (i = 0; i < fig1->saved_windows_count; i++)
|
|
4698 {
|
|
4699 if (!saved_window_equal (SAVED_WINDOW_N (fig1, i),
|
|
4700 SAVED_WINDOW_N (fig2, i)))
|
|
4701 return 0;
|
|
4702 }
|
|
4703
|
|
4704 return 1;
|
|
4705 }
|
|
4706
|
20
|
4707 DEFUN ("window-configuration-p", Fwindow_configuration_p, 1, 1, 0, /*
|
272
|
4708 Return t if OBJECT is a window-configuration object.
|
20
|
4709 */
|
|
4710 (obj))
|
0
|
4711 {
|
149
|
4712 return WINDOW_CONFIGURATIONP (obj) ? Qt : Qnil;
|
0
|
4713 }
|
|
4714
|
251
|
4715 static int
|
|
4716 mark_windows_in_use_closure (struct window *w, void *closure)
|
0
|
4717 {
|
251
|
4718 int mark = *(int *)closure;
|
|
4719 w->config_mark = mark;
|
|
4720 return 0;
|
|
4721 }
|
|
4722
|
|
4723 static void
|
|
4724 mark_windows_in_use (struct frame *f, int mark)
|
|
4725 {
|
|
4726 map_windows (f, mark_windows_in_use_closure, &mark);
|
0
|
4727 }
|
|
4728
|
|
4729 /* Lisp_Object return value so it can be used in record_unwind_protect() */
|
|
4730 static Lisp_Object
|
|
4731 free_window_configuration (Lisp_Object window_config)
|
|
4732 {
|
|
4733 int i;
|
|
4734 struct window_config *config = XWINDOW_CONFIGURATION (window_config);
|
|
4735
|
|
4736 /* Free all the markers. It's not completely necessary that
|
|
4737 we do this (window configs sitting in a free list aren't
|
|
4738 marked normally so the markers wouldn't be marked anyway)
|
|
4739 but it's more efficient. */
|
|
4740 for (i = 0; i < config->saved_windows_count; i++)
|
|
4741 {
|
|
4742 struct saved_window *p = SAVED_WINDOW_N (config, i);
|
|
4743
|
|
4744 if (!NILP (p->pointm))
|
|
4745 {
|
|
4746 free_marker (XMARKER (p->pointm));
|
|
4747 p->pointm = Qnil;
|
|
4748 }
|
|
4749 if (!NILP (p->start))
|
|
4750 {
|
|
4751 free_marker (XMARKER (p->start));
|
|
4752 p->start = Qnil;
|
|
4753 }
|
|
4754 if (!NILP (p->sb_point))
|
|
4755 {
|
|
4756 free_marker (XMARKER (p->sb_point));
|
|
4757 p->sb_point = Qnil;
|
|
4758 }
|
|
4759 if (!NILP (p->mark))
|
|
4760 {
|
|
4761 free_marker (XMARKER (p->mark));
|
|
4762 p->mark = Qnil;
|
|
4763 }
|
|
4764 }
|
|
4765
|
|
4766 if (config->saved_windows_count <= countof (Vwindow_configuration_free_list))
|
|
4767 free_managed_lcrecord (Vwindow_configuration_free_list
|
|
4768 [config->saved_windows_count - 1],
|
|
4769 window_config);
|
|
4770
|
|
4771 return Qnil;
|
|
4772 }
|
|
4773
|
20
|
4774 DEFUN ("set-window-configuration", Fset_window_configuration, 1, 1, 0, /*
|
0
|
4775 Set the configuration of windows and buffers as specified by CONFIGURATION.
|
|
4776 CONFIGURATION must be a value previously returned
|
|
4777 by `current-window-configuration' (which see).
|
20
|
4778 */
|
|
4779 (configuration))
|
0
|
4780 {
|
|
4781 struct window *w;
|
|
4782 struct window_config *config;
|
|
4783 struct saved_window *p;
|
|
4784 Lisp_Object new_current_buffer;
|
|
4785 int k;
|
|
4786 Lisp_Object frame;
|
|
4787 struct frame *f;
|
|
4788 struct gcpro gcpro1;
|
|
4789 Lisp_Object old_window_config;
|
|
4790 int previous_frame_height;
|
|
4791 int previous_frame_width;
|
|
4792 int specpdl_count = specpdl_depth ();
|
|
4793
|
|
4794 GCPRO1 (configuration);
|
|
4795
|
|
4796 CHECK_WINDOW_CONFIGURATION (configuration);
|
|
4797 config = XWINDOW_CONFIGURATION (configuration);
|
|
4798
|
|
4799 frame = XWINDOW (SAVED_WINDOW_N (config, 0)->window)->frame;
|
|
4800 f = XFRAME (frame);
|
|
4801
|
|
4802 /* Do not signal an error here if the frame was deleted. There are
|
|
4803 reasonable cases where we could get here with a deleted frame and
|
|
4804 just want to do close to nothing instead. */
|
|
4805
|
|
4806 if (FRAME_LIVE_P (f))
|
|
4807 {
|
|
4808 /* restore the frame characteristics */
|
185
|
4809
|
0
|
4810 new_current_buffer = config->current_buffer;
|
|
4811 if (!BUFFER_LIVE_P (XBUFFER (new_current_buffer)))
|
|
4812 new_current_buffer = Qnil;
|
|
4813
|
|
4814 /*
|
|
4815 * Assumed precondition: w->config_mark = 0 for all w
|
|
4816 * This procedure should ensure this is true by the time it exits
|
|
4817 * to ensure the precondition for future calls.
|
|
4818 *
|
|
4819 * We use w->config_mark to know whether we're modifying a
|
|
4820 * window that is currently visible on the frame (#### we
|
|
4821 * should just be able to check whether the window is dead
|
|
4822 * or not, but this way is safer?). As we process each
|
|
4823 * window, we set its config_mark to 0. At the end, we
|
|
4824 * go through all the windows that used to be on the frame,
|
|
4825 * set each one's config_mark to 0 (to maintain the
|
|
4826 * assumed precondition) and delete each one that's no
|
|
4827 * longer in use.
|
|
4828 *
|
|
4829 * #### Using a window-configuration to keep track of
|
|
4830 * the current windows is wasteful. All we need is the
|
|
4831 * list of windows, so we could just use a dynarr.
|
|
4832 */
|
|
4833 old_window_config = Fcurrent_window_configuration (frame);
|
|
4834
|
|
4835 /* If the new configuration is already equal to the old, then stop
|
|
4836 right here. This saves the work below and it also saves
|
|
4837 triggering a full redisplay of this window. This is a huge win
|
|
4838 when using the mouse since the mode motion code uses
|
|
4839 save-window-excursion extensively but will rarely cause the
|
|
4840 configuration to actually change. */
|
|
4841 if (window_config_equal (configuration, old_window_config))
|
|
4842 {
|
|
4843 free_window_configuration (old_window_config);
|
|
4844 UNGCPRO;
|
|
4845 return Qnil;
|
|
4846 }
|
|
4847
|
|
4848 /* We can't quit or even check for quit because that may cause
|
|
4849 investigation of the frame state, which may crash if the frame is
|
|
4850 in an inconsistent state. */
|
|
4851 begin_dont_check_for_quit ();
|
|
4852 record_unwind_protect (free_window_configuration, old_window_config);
|
|
4853
|
251
|
4854 mark_windows_in_use (f, 1);
|
0
|
4855
|
|
4856 previous_frame_width = FRAME_WIDTH (f);
|
|
4857 previous_frame_height = FRAME_HEIGHT (f);
|
|
4858 /* If the frame has been resized since this window configuration was
|
|
4859 made, we change the frame to the size specified in the
|
|
4860 configuration, restore the configuration, and then resize it
|
|
4861 back. We keep track of the prevailing height in these variables. */
|
|
4862 if (config->frame_height != FRAME_HEIGHT (f)
|
|
4863 || config->frame_width != FRAME_WIDTH (f))
|
|
4864 change_frame_size (f, config->frame_height, config->frame_width, 0);
|
|
4865
|
|
4866 /* Temporarily avoid any problems with windows that are smaller
|
|
4867 than they are supposed to be. */
|
|
4868 window_min_height = 1;
|
|
4869 window_min_width = 1;
|
|
4870
|
|
4871 /* OK, now restore all the windows in the window config.
|
|
4872 This may involve "undeleting" windows, since the
|
|
4873 windows in the window config may be deleted.
|
|
4874 */
|
|
4875 for (k = 0; k < config->saved_windows_count; k++)
|
|
4876 {
|
|
4877 p = SAVED_WINDOW_N (config, k);
|
|
4878 w = XWINDOW (p->window);
|
|
4879 w->next = Qnil;
|
|
4880
|
|
4881 /* The window might be dead. In this case, its redisplay
|
|
4882 structures were freed, so we need to reallocate them. */
|
|
4883 if (!w->face_cachels)
|
|
4884 {
|
185
|
4885 w->face_cachels = Dynarr_new (face_cachel);
|
0
|
4886 reset_face_cachels (w);
|
|
4887 }
|
|
4888 if (!w->glyph_cachels)
|
185
|
4889 w->glyph_cachels = Dynarr_new (glyph_cachel);
|
0
|
4890 if (!w->line_start_cache)
|
185
|
4891 w->line_start_cache = Dynarr_new (line_start_cache);
|
0
|
4892 w->dead = 0;
|
|
4893
|
|
4894 if (p->parent_index >= 0)
|
|
4895 w->parent = SAVED_WINDOW_N (config, p->parent_index)->window;
|
|
4896 else
|
|
4897 w->parent = Qnil;
|
|
4898
|
|
4899 if (p->prev_index >= 0)
|
|
4900 {
|
|
4901 w->prev = SAVED_WINDOW_N (config, p->prev_index)->window;
|
|
4902
|
|
4903 /* This is true for a minibuffer-only frame. */
|
|
4904 if (!NILP (w->mini_p) && EQ (w->prev, p->window))
|
|
4905 w->next = Qnil;
|
|
4906 else
|
|
4907 XWINDOW (w->prev)->next = p->window;
|
|
4908 }
|
|
4909 else
|
|
4910 {
|
|
4911 w->prev = Qnil;
|
|
4912 if (!NILP (w->parent))
|
|
4913 {
|
|
4914 if (WINDOW_WIDTH (p) == WINDOW_WIDTH (XWINDOW (w->parent)))
|
|
4915 {
|
|
4916 XWINDOW (w->parent)->vchild = p->window;
|
|
4917 XWINDOW (w->parent)->hchild = Qnil;
|
|
4918 }
|
|
4919 else
|
|
4920 {
|
|
4921 XWINDOW (w->parent)->hchild = p->window;
|
|
4922 XWINDOW (w->parent)->vchild = Qnil;
|
|
4923 }
|
|
4924 }
|
|
4925 }
|
|
4926 if (!w->config_mark)
|
|
4927 {
|
|
4928 /* #### This should be equivalent to the window previously
|
|
4929 having been dead. If we're brave, we'll put in an
|
|
4930 assertion to this effect. */
|
|
4931 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
4932 }
|
|
4933 else /* if (!EQ (w->buffer, p->buffer)) */
|
|
4934 {
|
|
4935 /* With the new redisplay we let it know that a change has
|
|
4936 been made and it will take care of the rest. If we don't
|
|
4937 tell it something has possibly changed it could lead to
|
|
4938 incorrect display. */
|
|
4939 MARK_WINDOWS_CHANGED (w);
|
|
4940 }
|
|
4941
|
|
4942 WINDOW_LEFT (w) = WINDOW_LEFT (p);
|
|
4943 WINDOW_TOP (w) = WINDOW_TOP (p);
|
|
4944 WINDOW_WIDTH (w) = WINDOW_WIDTH (p);
|
|
4945 WINDOW_HEIGHT (w) = WINDOW_HEIGHT (p);
|
|
4946 w->hscroll = p->hscroll;
|
257
|
4947 w->modeline_hscroll = p->modeline_hscroll;
|
0
|
4948 w->line_cache_last_updated = Qzero;
|
|
4949 SET_LAST_MODIFIED (w, 1);
|
|
4950 SET_LAST_FACECHANGE (w);
|
|
4951 w->config_mark = 0;
|
|
4952
|
284
|
4953 #define WINDOW_SLOT(slot, compare) w->slot = p->slot;
|
|
4954 #include "winslots.h"
|
|
4955
|
0
|
4956 /* Reinstall the saved buffer and pointers into it. */
|
|
4957 if (NILP (p->buffer))
|
|
4958 w->buffer = p->buffer;
|
|
4959 else
|
|
4960 {
|
|
4961 if (BUFFER_LIVE_P (XBUFFER (p->buffer)))
|
|
4962 /* If saved buffer is alive, install it. */
|
|
4963 {
|
|
4964 w->buffer = p->buffer;
|
|
4965 w->start_at_line_beg = p->start_at_line_beg;
|
|
4966 set_marker_restricted (w->start[CURRENT_DISP],
|
|
4967 Fmarker_position (p->start),
|
|
4968 w->buffer);
|
|
4969 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
4970 Fmarker_position (p->pointm),
|
|
4971 w->buffer);
|
|
4972 set_marker_restricted (w->sb_point,
|
|
4973 Fmarker_position (p->sb_point),
|
|
4974 w->buffer);
|
|
4975 Fset_marker (XBUFFER (w->buffer)->mark,
|
|
4976 Fmarker_position (p->mark), w->buffer);
|
|
4977
|
|
4978 /* As documented in Fcurrent_window_configuration, don't
|
|
4979 save the location of point in the buffer which was current
|
|
4980 when the window configuration was recorded. */
|
|
4981 if (!EQ (p->buffer, new_current_buffer) &&
|
|
4982 XBUFFER (p->buffer) == current_buffer)
|
223
|
4983 Fgoto_char (w->pointm[CURRENT_DISP], Qnil);
|
0
|
4984 }
|
|
4985 else if (NILP (w->buffer) ||
|
|
4986 !BUFFER_LIVE_P (XBUFFER (w->buffer)))
|
|
4987 /* Else if window's old buffer is dead too, get a live one. */
|
|
4988 {
|
|
4989 /* #### The following line makes me nervous... */
|
|
4990 /* w->buffer = Fcdr (Fcar (XFRAME (w->frame)->buffer_alist));*/
|
|
4991 w->buffer = Fget_buffer_create (QSscratch);
|
|
4992 /* w->buffer = Fother_buffer (Qnil, w->frame, Qnil); */
|
|
4993 /* This will set the markers to beginning of visible
|
|
4994 range. */
|
|
4995 set_marker_restricted (w->start[CURRENT_DISP], Qzero, w->buffer);
|
|
4996 set_marker_restricted (w->pointm[CURRENT_DISP], Qzero,
|
|
4997 w->buffer);
|
|
4998 set_marker_restricted (w->sb_point, Qzero, w->buffer);
|
|
4999 w->start_at_line_beg = 1;
|
|
5000 }
|
|
5001 else
|
|
5002 /* Keeping window's old buffer; make sure the markers
|
|
5003 are real. */
|
|
5004 {
|
|
5005 /* Set window markers at start of visible range. */
|
|
5006 if (XMARKER (w->start[CURRENT_DISP])->buffer == 0)
|
|
5007 set_marker_restricted (w->start[CURRENT_DISP], Qzero,
|
|
5008 w->buffer);
|
|
5009 if (XMARKER (w->sb_point)->buffer == 0)
|
|
5010 set_marker_restricted (w->sb_point, Qzero, w->buffer);
|
|
5011 if (XMARKER (w->pointm[CURRENT_DISP])->buffer == 0)
|
|
5012 set_marker_restricted (w->pointm[CURRENT_DISP],
|
|
5013 make_int
|
|
5014 (BUF_PT (XBUFFER (w->buffer))),
|
|
5015 w->buffer);
|
|
5016 w->start_at_line_beg = 1;
|
|
5017 }
|
|
5018 }
|
|
5019 }
|
|
5020
|
|
5021 FRAME_ROOT_WINDOW (f) = config->root_window;
|
|
5022 /* Note that FSFmacs unilaterally calls Fselect_window() here, and
|
|
5023 then calls do_switch_frame() below to select the frame that was
|
|
5024 recorded in the window config as being selected.
|
|
5025
|
|
5026 Instead, we don't ever change the selected frame, and either
|
|
5027 call Fselect_window() below if the window config's frame is
|
|
5028 currently selected, or just set the selected window of the
|
|
5029 window config's frame. */
|
|
5030
|
|
5031 /* Set the frame height to the value it had before this function. */
|
|
5032 if (previous_frame_height != FRAME_HEIGHT (f)
|
|
5033 || previous_frame_width != FRAME_WIDTH (f))
|
|
5034 change_frame_size (f, previous_frame_height, previous_frame_width, 0);
|
|
5035
|
|
5036 /* If restoring in the current frame make the window current,
|
|
5037 otherwise just update the frame selected_window slot to be
|
|
5038 the restored current_window. */
|
|
5039 if (f == selected_frame ())
|
|
5040 {
|
|
5041 /* When using `pop-window-configuration', often the minibuffer
|
|
5042 ends up as the selected window even though it's not active ...
|
|
5043 I really don't know the cause of this, but it should never
|
|
5044 happen. This kludge should fix it.
|
|
5045
|
|
5046 #### Find out why this is really going wrong. */
|
|
5047 if (!minibuf_level &&
|
|
5048 MINI_WINDOW_P (XWINDOW (config->current_window)))
|
|
5049 Fselect_window (Fnext_window (config->current_window,
|
282
|
5050 Qnil, Qnil, Qnil),
|
|
5051 Qnil);
|
0
|
5052 else
|
282
|
5053 Fselect_window (config->current_window, Qnil);
|
0
|
5054 if (!NILP (new_current_buffer))
|
|
5055 Fset_buffer (new_current_buffer);
|
|
5056 else
|
|
5057 Fset_buffer (XWINDOW (Fselected_window (Qnil))->buffer);
|
|
5058 }
|
|
5059 else
|
|
5060 set_frame_selected_window (f, config->current_window);
|
|
5061 }
|
173
|
5062 else
|
|
5063 old_window_config = Qnil; /* Warning suppression */
|
0
|
5064
|
|
5065 /* Restore the minimum heights recorded in the configuration. */
|
|
5066 window_min_height = config->min_height;
|
|
5067 window_min_width = config->min_width;
|
|
5068
|
|
5069 #if 0 /* FSFmacs */
|
|
5070 /* see above comment */
|
|
5071 /* Fselect_window will have made f the selected frame, so we
|
|
5072 reselect the proper frame here. Fhandle_switch_frame will change the
|
|
5073 selected window too, but that doesn't make the call to
|
|
5074 Fselect_window above totally superfluous; it still sets f's
|
|
5075 selected window. */
|
|
5076 if (FRAME_LIVE_P (XFRAME (config->selected_frame)))
|
|
5077 do_switch_frame (config->selected_frame, Qnil, 0);
|
|
5078 #endif
|
|
5079
|
274
|
5080 Vminibuffer_scroll_window = config->minibuffer_scroll_window;
|
0
|
5081
|
|
5082 if (FRAME_LIVE_P (f))
|
|
5083 {
|
|
5084 /* Do this before calling recompute_all_cached_specifiers_in_window()
|
|
5085 so that things like redisplay_redraw_cursor() won't abort due
|
|
5086 to no window mirror present. */
|
|
5087 f->mirror_dirty = 1;
|
|
5088
|
|
5089 config = XWINDOW_CONFIGURATION (old_window_config);
|
|
5090 for (k = 0; k < config->saved_windows_count; k++)
|
|
5091 {
|
|
5092 p = SAVED_WINDOW_N (config, k);
|
|
5093 w = XWINDOW (p->window);
|
|
5094 /* Remember, we set w->config_mark on all currently visible
|
|
5095 windows, and reset it on all newly visible windows.
|
|
5096 Any windows still marked need to be deleted. */
|
|
5097 if (w->config_mark)
|
|
5098 {
|
|
5099 mark_window_as_deleted (w);
|
|
5100 w->config_mark = 0;
|
|
5101 }
|
|
5102 else
|
|
5103 {
|
|
5104 /* We just potentially changed the window's buffer and
|
|
5105 potentially turned a dead window into a live one,
|
|
5106 so we need to recompute the cached specifier values. */
|
|
5107 recompute_all_cached_specifiers_in_window (w);
|
|
5108 }
|
|
5109 }
|
|
5110 }
|
|
5111
|
|
5112 /* Now restore things, when everything else if OK. */
|
|
5113
|
|
5114 unbind_to (specpdl_count, Qnil);
|
|
5115
|
|
5116 UNGCPRO;
|
|
5117
|
149
|
5118 return Qnil;
|
0
|
5119 }
|
|
5120
|
|
5121 /* Mark all subwindows of a window as deleted. The argument
|
|
5122 W is actually the subwindow tree of the window in question. */
|
|
5123
|
|
5124 void
|
|
5125 delete_all_subwindows (struct window *w)
|
|
5126 {
|
272
|
5127 if (!NILP (w->next)) delete_all_subwindows (XWINDOW (w->next));
|
|
5128 if (!NILP (w->vchild)) delete_all_subwindows (XWINDOW (w->vchild));
|
|
5129 if (!NILP (w->hchild)) delete_all_subwindows (XWINDOW (w->hchild));
|
0
|
5130
|
|
5131 mark_window_as_deleted (w);
|
|
5132 }
|
|
5133
|
|
5134
|
|
5135 static int
|
|
5136 count_windows (struct window *window)
|
|
5137 {
|
272
|
5138 return 1 +
|
|
5139 (!NILP (window->next) ? count_windows (XWINDOW (window->next)) : 0) +
|
|
5140 (!NILP (window->vchild) ? count_windows (XWINDOW (window->vchild)) : 0) +
|
|
5141 (!NILP (window->hchild) ? count_windows (XWINDOW (window->hchild)) : 0);
|
0
|
5142 }
|
|
5143
|
|
5144 static int
|
|
5145 saved_window_index (Lisp_Object window, struct window_config *config, int lim)
|
|
5146 {
|
|
5147 int j;
|
|
5148 for (j = 0; j < lim; j++)
|
|
5149 {
|
|
5150 if (EQ (SAVED_WINDOW_N (config, j)->window, window))
|
149
|
5151 return j;
|
272
|
5152 }
|
0
|
5153 abort ();
|
|
5154 return 0; /* suppress compiler warning */
|
|
5155 }
|
|
5156
|
|
5157 static int
|
|
5158 save_window_save (Lisp_Object window, struct window_config *config, int i)
|
|
5159 {
|
|
5160 struct window *w;
|
|
5161
|
|
5162 for (; !NILP (window); window = w->next)
|
|
5163 {
|
272
|
5164 struct saved_window *p = SAVED_WINDOW_N (config, i);
|
|
5165
|
0
|
5166 w = XWINDOW (window);
|
|
5167 i++;
|
|
5168 p->window = window;
|
|
5169 p->buffer = w->buffer;
|
|
5170 WINDOW_LEFT (p) = WINDOW_LEFT (w);
|
|
5171 WINDOW_TOP (p) = WINDOW_TOP (w);
|
|
5172 WINDOW_WIDTH (p) = WINDOW_WIDTH (w);
|
|
5173 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (w);
|
|
5174 p->hscroll = w->hscroll;
|
257
|
5175 p->modeline_hscroll = w->modeline_hscroll;
|
284
|
5176
|
|
5177 #define WINDOW_SLOT(slot, compare) p->slot = w->slot;
|
|
5178 #include "winslots.h"
|
255
|
5179
|
0
|
5180 if (!NILP (w->buffer))
|
|
5181 {
|
|
5182 /* Save w's value of point in the window configuration.
|
|
5183 If w is the selected window, then get the value of point
|
|
5184 from the buffer; pointm is garbage in the selected window. */
|
|
5185 if (EQ (window, Fselected_window (Qnil)))
|
|
5186 {
|
|
5187 p->pointm = noseeum_make_marker ();
|
|
5188 Fset_marker (p->pointm,
|
|
5189 make_int (BUF_PT (XBUFFER (w->buffer))),
|
|
5190 w->buffer);
|
|
5191 }
|
|
5192 else
|
|
5193 p->pointm = noseeum_copy_marker (w->pointm[CURRENT_DISP], Qnil);
|
|
5194
|
|
5195 p->start = noseeum_copy_marker (w->start[CURRENT_DISP], Qnil);
|
|
5196 p->sb_point = noseeum_copy_marker (w->sb_point, Qnil);
|
|
5197 p->start_at_line_beg = w->start_at_line_beg;
|
|
5198
|
|
5199 p->mark = noseeum_copy_marker (XBUFFER (w->buffer)->mark, Qnil);
|
|
5200 }
|
|
5201 else
|
|
5202 {
|
|
5203 p->pointm = Qnil;
|
|
5204 p->start = Qnil;
|
|
5205 p->sb_point = Qnil;
|
|
5206 p->mark = Qnil;
|
|
5207 p->start_at_line_beg = 0;
|
|
5208 }
|
|
5209
|
|
5210 if (NILP (w->parent))
|
|
5211 p->parent_index = -1;
|
|
5212 else
|
|
5213 p->parent_index = saved_window_index (w->parent, config, i);
|
|
5214 if (NILP (w->prev))
|
|
5215 p->prev_index = -1;
|
|
5216 else
|
|
5217 p->prev_index = saved_window_index (w->prev, config, i);
|
|
5218 if (!NILP (w->vchild))
|
|
5219 i = save_window_save (w->vchild, config, i);
|
|
5220 if (!NILP (w->hchild))
|
|
5221 i = save_window_save (w->hchild, config, i);
|
|
5222 }
|
|
5223
|
|
5224 return i;
|
|
5225 }
|
|
5226
|
|
5227 #if 0 /* FSFmacs */
|
|
5228 /* Added to doc string:
|
|
5229
|
|
5230 This also records the currently selected frame, and FRAME's focus
|
|
5231 redirection (see `redirect-frame-focus').
|
|
5232
|
|
5233 */
|
|
5234 #endif
|
|
5235
|
20
|
5236 DEFUN ("current-window-configuration", Fcurrent_window_configuration, 0, 1, 0, /*
|
0
|
5237 Return an object representing the current window configuration of FRAME.
|
|
5238 If FRAME is nil or omitted, use the selected frame.
|
|
5239 This describes the number of windows, their sizes and current buffers,
|
|
5240 and for each displayed buffer, where display starts, and the positions of
|
|
5241 point and mark. An exception is made for point in the current buffer:
|
|
5242 its value is -not- saved.
|
20
|
5243 */
|
|
5244 (frame))
|
0
|
5245 {
|
272
|
5246 Lisp_Object result;
|
|
5247 struct frame *f = decode_frame (frame);
|
0
|
5248 struct window_config *config;
|
272
|
5249 int n_windows = count_windows (XWINDOW (FRAME_ROOT_WINDOW (f)));
|
|
5250
|
0
|
5251 if (n_windows <= countof (Vwindow_configuration_free_list))
|
272
|
5252 config = XWINDOW_CONFIGURATION (allocate_managed_lcrecord
|
|
5253 (Vwindow_configuration_free_list
|
|
5254 [n_windows - 1]));
|
0
|
5255 else
|
|
5256 /* More than ten windows; just allocate directly */
|
185
|
5257 config = (struct window_config *)
|
|
5258 alloc_lcrecord (sizeof_window_config_for_n_windows (n_windows),
|
|
5259 lrecord_window_configuration);
|
0
|
5260 XSETWINDOW_CONFIGURATION (result, config);
|
|
5261
|
|
5262 config->frame_width = FRAME_WIDTH (f);
|
|
5263 config->frame_height = FRAME_HEIGHT (f);
|
|
5264 config->current_window = FRAME_SELECTED_WINDOW (f);
|
|
5265 XSETBUFFER (config->current_buffer, current_buffer);
|
274
|
5266 config->minibuffer_scroll_window = Vminibuffer_scroll_window;
|
0
|
5267 config->root_window = FRAME_ROOT_WINDOW (f);
|
|
5268 config->min_height = window_min_height;
|
|
5269 config->min_width = window_min_width;
|
|
5270 config->saved_windows_count = n_windows;
|
|
5271 save_window_save (FRAME_ROOT_WINDOW (f), config, 0);
|
149
|
5272 return result;
|
0
|
5273 }
|
|
5274
|
|
5275 Lisp_Object
|
|
5276 save_window_excursion_unwind (Lisp_Object window_config)
|
|
5277 {
|
|
5278 Lisp_Object val = Fset_window_configuration (window_config);
|
|
5279 free_window_configuration (window_config);
|
|
5280 return val;
|
|
5281 }
|
|
5282
|
20
|
5283 DEFUN ("save-window-excursion", Fsave_window_excursion, 0, UNEVALLED, 0, /*
|
0
|
5284 Execute body, preserving window sizes and contents.
|
|
5285 Restores which buffer appears in which window, where display starts,
|
|
5286 as well as the current buffer.
|
|
5287 Does not restore the value of point in current buffer.
|
20
|
5288 */
|
|
5289 (args))
|
0
|
5290 {
|
|
5291 /* This function can GC */
|
|
5292 Lisp_Object val;
|
|
5293 int speccount = specpdl_depth ();
|
|
5294
|
|
5295 record_unwind_protect (save_window_excursion_unwind,
|
|
5296 Fcurrent_window_configuration (Qnil));
|
|
5297 val = Fprogn (args);
|
|
5298 return unbind_to (speccount, val);
|
|
5299 }
|
|
5300
|
|
5301
|
|
5302 #ifdef DEBUG_XEMACS
|
|
5303 /* This is short and simple in elisp, but... it was written to debug
|
|
5304 problems purely on the C side. That is where we need to call it so
|
|
5305 here it is. */
|
|
5306 static void
|
|
5307 debug_print_window (Lisp_Object window, int level)
|
|
5308 {
|
272
|
5309 int i;
|
|
5310 Lisp_Object child = Fwindow_first_vchild (window);
|
|
5311
|
0
|
5312 if (NILP (child))
|
|
5313 child = Fwindow_first_hchild (window);
|
|
5314
|
272
|
5315 for (i = level; i > 0; i--)
|
|
5316 putc ('\t', stderr);
|
|
5317
|
|
5318 fputs ("#<window", stderr);
|
|
5319 {
|
|
5320 Lisp_Object buffer = XWINDOW (window)->buffer;
|
|
5321 if (!NILP (buffer) && BUFFERP (buffer))
|
|
5322 fprintf (stderr, " on %s", XSTRING_DATA (XBUFFER (buffer)->name));
|
|
5323 }
|
0
|
5324 fprintf (stderr, " 0x%x>", XWINDOW (window)->header.uid);
|
|
5325
|
|
5326 while (!NILP (child))
|
|
5327 {
|
|
5328 debug_print_window (child, level + 1);
|
|
5329 child = Fwindow_next_child (child);
|
|
5330 }
|
|
5331 }
|
|
5332
|
|
5333 void debug_print_windows (struct frame *f);
|
|
5334 void
|
|
5335 debug_print_windows (struct frame *f)
|
|
5336 {
|
|
5337 debug_print_window (f->root_window, 0);
|
272
|
5338 putc ('\n', stderr);
|
0
|
5339 }
|
|
5340 #endif /* DEBUG_XEMACS */
|
|
5341
|
|
5342
|
|
5343 /************************************************************************/
|
|
5344 /* initialization */
|
|
5345 /************************************************************************/
|
|
5346
|
|
5347 void
|
|
5348 syms_of_window (void)
|
|
5349 {
|
|
5350 defsymbol (&Qwindowp, "windowp");
|
|
5351 defsymbol (&Qwindow_live_p, "window-live-p");
|
|
5352 defsymbol (&Qwindow_configurationp, "window-configuration-p");
|
|
5353 defsymbol (&Qscroll_up, "scroll-up");
|
|
5354 defsymbol (&Qscroll_down, "scroll-down");
|
|
5355 defsymbol (&Qtemp_buffer_show_hook, "temp-buffer-show-hook");
|
|
5356 defsymbol (&Qdisplay_buffer, "display-buffer");
|
|
5357
|
|
5358 #ifdef MEMORY_USAGE_STATS
|
|
5359 defsymbol (&Qface_cache, "face-cache");
|
|
5360 defsymbol (&Qglyph_cache, "glyph-cache");
|
|
5361 defsymbol (&Qline_start_cache, "line-start-cache");
|
|
5362 #ifdef HAVE_SCROLLBARS
|
|
5363 defsymbol (&Qscrollbar_instances, "scrollbar-instances");
|
|
5364 #endif
|
|
5365 defsymbol (&Qother_redisplay, "other-redisplay");
|
|
5366 /* Qother in general.c */
|
|
5367 #endif
|
|
5368
|
20
|
5369 DEFSUBR (Fselected_window);
|
|
5370 DEFSUBR (Fminibuffer_window);
|
|
5371 DEFSUBR (Fwindow_minibuffer_p);
|
|
5372 DEFSUBR (Fwindowp);
|
|
5373 DEFSUBR (Fwindow_live_p);
|
|
5374 DEFSUBR (Fwindow_first_hchild);
|
|
5375 DEFSUBR (Fwindow_first_vchild);
|
|
5376 DEFSUBR (Fwindow_next_child);
|
|
5377 DEFSUBR (Fwindow_previous_child);
|
|
5378 DEFSUBR (Fwindow_parent);
|
|
5379 DEFSUBR (Fwindow_lowest_p);
|
|
5380 DEFSUBR (Fwindow_highest_p);
|
|
5381 DEFSUBR (Fwindow_leftmost_p);
|
|
5382 DEFSUBR (Fwindow_rightmost_p);
|
|
5383 DEFSUBR (Fpos_visible_in_window_p);
|
|
5384 DEFSUBR (Fwindow_buffer);
|
|
5385 DEFSUBR (Fwindow_frame);
|
|
5386 DEFSUBR (Fwindow_height);
|
|
5387 DEFSUBR (Fwindow_displayed_height);
|
|
5388 DEFSUBR (Fwindow_width);
|
|
5389 DEFSUBR (Fwindow_pixel_height);
|
|
5390 DEFSUBR (Fwindow_pixel_width);
|
276
|
5391 DEFSUBR (Fwindow_text_pixel_height);
|
|
5392 DEFSUBR (Fwindow_text_pixel_width);
|
20
|
5393 DEFSUBR (Fwindow_hscroll);
|
265
|
5394 #ifdef MODELINE_IS_SCROLLABLE
|
257
|
5395 DEFSUBR (Fmodeline_hscroll);
|
272
|
5396 DEFSUBR (Fset_modeline_hscroll);
|
265
|
5397 #endif /* MODELINE_IS_SCROLLABLE */
|
276
|
5398 #if 0 /* bogus FSF crock */
|
20
|
5399 DEFSUBR (Fwindow_redisplay_end_trigger);
|
|
5400 DEFSUBR (Fset_window_redisplay_end_trigger);
|
0
|
5401 #endif
|
20
|
5402 DEFSUBR (Fset_window_hscroll);
|
|
5403 DEFSUBR (Fwindow_pixel_edges);
|
276
|
5404 DEFSUBR (Fwindow_text_pixel_edges);
|
20
|
5405 DEFSUBR (Fwindow_point);
|
|
5406 DEFSUBR (Fwindow_start);
|
|
5407 DEFSUBR (Fwindow_end);
|
|
5408 DEFSUBR (Fset_window_point);
|
|
5409 DEFSUBR (Fset_window_start);
|
|
5410 DEFSUBR (Fwindow_dedicated_p);
|
|
5411 DEFSUBR (Fset_window_dedicated_p);
|
|
5412 DEFSUBR (Fnext_window);
|
|
5413 DEFSUBR (Fprevious_window);
|
|
5414 DEFSUBR (Fnext_vertical_window);
|
|
5415 DEFSUBR (Fother_window);
|
|
5416 DEFSUBR (Fget_lru_window);
|
|
5417 DEFSUBR (Fget_largest_window);
|
|
5418 DEFSUBR (Fget_buffer_window);
|
|
5419 DEFSUBR (Fwindow_left_margin_pixel_width);
|
|
5420 DEFSUBR (Fwindow_right_margin_pixel_width);
|
|
5421 DEFSUBR (Fdelete_other_windows);
|
|
5422 DEFSUBR (Fdelete_windows_on);
|
|
5423 DEFSUBR (Freplace_buffer_in_windows);
|
|
5424 DEFSUBR (Fdelete_window);
|
|
5425 DEFSUBR (Fset_window_buffer);
|
|
5426 DEFSUBR (Fselect_window);
|
|
5427 DEFSUBR (Fsplit_window);
|
|
5428 DEFSUBR (Fenlarge_window);
|
263
|
5429 DEFSUBR (Fenlarge_window_pixels);
|
20
|
5430 DEFSUBR (Fshrink_window);
|
263
|
5431 DEFSUBR (Fshrink_window_pixels);
|
20
|
5432 DEFSUBR (Fscroll_up);
|
|
5433 DEFSUBR (Fscroll_down);
|
|
5434 DEFSUBR (Fscroll_left);
|
|
5435 DEFSUBR (Fscroll_right);
|
|
5436 DEFSUBR (Fother_window_for_scrolling);
|
|
5437 DEFSUBR (Fscroll_other_window);
|
280
|
5438 DEFSUBR (Fcenter_to_window_line);
|
20
|
5439 DEFSUBR (Fmove_to_window_line);
|
0
|
5440 #ifdef MEMORY_USAGE_STATS
|
20
|
5441 DEFSUBR (Fwindow_memory_usage);
|
0
|
5442 #endif
|
20
|
5443 DEFSUBR (Fwindow_configuration_p);
|
|
5444 DEFSUBR (Fset_window_configuration);
|
|
5445 DEFSUBR (Fcurrent_window_configuration);
|
|
5446 DEFSUBR (Fsave_window_excursion);
|
0
|
5447 }
|
|
5448
|
|
5449 void
|
|
5450 vars_of_window (void)
|
|
5451 {
|
|
5452 /* Make sure all windows get marked */
|
|
5453 minibuf_window = Qnil;
|
|
5454 staticpro (&minibuf_window);
|
|
5455
|
|
5456 DEFVAR_BOOL ("scroll-on-clipped-lines", &scroll_on_clipped_lines /*
|
|
5457 *Non-nil means to scroll if point lands on a line which is clipped.
|
|
5458 */ );
|
|
5459 scroll_on_clipped_lines = 1;
|
|
5460
|
|
5461 DEFVAR_LISP ("temp-buffer-show-hook", &Vtemp_buffer_show_hook /*
|
|
5462 See `temp-buffer-show-function'.
|
|
5463 */ );
|
|
5464 Vtemp_buffer_show_hook = Qnil;
|
|
5465
|
|
5466 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function /*
|
|
5467 Non-nil means call as function to display a help buffer.
|
|
5468 The function is called with one argument, the buffer to be displayed.
|
|
5469 Used by `with-output-to-temp-buffer'.
|
|
5470 If this function is used, then it must do the entire job of showing
|
|
5471 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.
|
|
5472 */ );
|
|
5473 Vtemp_buffer_show_function = Qnil;
|
|
5474
|
274
|
5475 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuffer_scroll_window /*
|
0
|
5476 Non-nil means it is the window that \\<minibuffer-local-map>\\[scroll-other-window] in minibuffer should scroll.
|
|
5477 */ );
|
274
|
5478 Vminibuffer_scroll_window = Qnil;
|
0
|
5479
|
|
5480 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer /*
|
|
5481 If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.
|
|
5482 */ );
|
|
5483 Vother_window_scroll_buffer = Qnil;
|
|
5484
|
|
5485 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines /*
|
|
5486 *Number of lines of continuity when scrolling by screenfuls.
|
|
5487 */ );
|
|
5488 next_screen_context_lines = 2;
|
|
5489
|
|
5490 DEFVAR_INT ("window-min-height", &window_min_height /*
|
|
5491 *Delete any window less than this tall (including its modeline).
|
|
5492 */ );
|
|
5493 window_min_height = 4;
|
|
5494
|
|
5495 DEFVAR_INT ("window-min-width", &window_min_width /*
|
|
5496 *Delete any window less than this wide.
|
|
5497 */ );
|
|
5498 window_min_width = 10;
|
|
5499
|
|
5500 {
|
|
5501 int i;
|
|
5502
|
|
5503 for (i = 0; i < countof (Vwindow_configuration_free_list); i++)
|
|
5504 {
|
|
5505 Vwindow_configuration_free_list[i] =
|
|
5506 make_lcrecord_list (sizeof_window_config_for_n_windows (i + 1),
|
|
5507 lrecord_window_configuration);
|
|
5508 staticpro (&Vwindow_configuration_free_list[i]);
|
|
5509 }
|
|
5510 }
|
|
5511 }
|
|
5512
|
|
5513 void
|
|
5514 specifier_vars_of_window (void)
|
|
5515 {
|
|
5516 DEFVAR_SPECIFIER ("modeline-shadow-thickness", &Vmodeline_shadow_thickness /*
|
|
5517 *How thick to draw 3D shadows around modelines.
|
|
5518 If this is set to 0, modelines will be the traditional 2D. Sizes above
|
|
5519 10 will be accepted but the maximum thickness that will be drawn is 10.
|
|
5520 This is a specifier; use `set-specifier' to change it.
|
|
5521 */ );
|
|
5522 Vmodeline_shadow_thickness = Fmake_specifier (Qinteger);
|
|
5523 /* The initial value for modeline-shadow-thickness is 2, but if the
|
|
5524 user removes all specifications we provide a fallback value of 0,
|
|
5525 which is probably what was expected. */
|
|
5526 set_specifier_fallback (Vmodeline_shadow_thickness,
|
|
5527 list1 (Fcons (Qnil, Qzero)));
|
|
5528 Fadd_spec_to_specifier (Vmodeline_shadow_thickness, make_int (2),
|
|
5529 Qnil, Qnil, Qnil);
|
|
5530 set_specifier_caching (Vmodeline_shadow_thickness,
|
|
5531 slot_offset (struct window,
|
|
5532 modeline_shadow_thickness),
|
|
5533 modeline_shadow_thickness_changed,
|
|
5534 0, 0);
|
284
|
5535
|
0
|
5536 DEFVAR_SPECIFIER ("has-modeline-p", &Vhas_modeline_p /*
|
|
5537 *Whether the modeline should be displayed.
|
|
5538 This is a specifier; use `set-specifier' to change it.
|
|
5539 */ );
|
|
5540 Vhas_modeline_p = Fmake_specifier (Qboolean);
|
|
5541 set_specifier_fallback (Vhas_modeline_p,
|
|
5542 list1 (Fcons (Qnil, Qt)));
|
|
5543 set_specifier_caching (Vhas_modeline_p,
|
|
5544 slot_offset (struct window,
|
|
5545 has_modeline_p),
|
|
5546 /* #### It's strange that we need a special
|
|
5547 flag to indicate that the shadow-thickness
|
|
5548 has changed, but not one to indicate that
|
|
5549 the modeline has been turned off or on. */
|
|
5550 some_window_value_changed,
|
|
5551 0, 0);
|
284
|
5552
|
|
5553 DEFVAR_SPECIFIER ("vertical-divider-draggable-p", &Vvertical_divider_draggable_p /*
|
|
5554 *Should XEmacs allow resizing windows by dragging vertical dividers.
|
|
5555 When t, vertical dividers are always shown, and are draggable.
|
|
5556 When nil, vertical dividers are shown only when there are no scrollbars
|
|
5557 in between windows, and not draggable.
|
|
5558 This is a specifier; use `set-specifier' to change it.
|
|
5559 */ );
|
|
5560 Vvertical_divider_draggable_p = Fmake_specifier (Qboolean);
|
|
5561 set_specifier_fallback (Vvertical_divider_draggable_p,
|
|
5562 list1 (Fcons (Qnil, Qt)));
|
|
5563 set_specifier_caching (Vvertical_divider_draggable_p,
|
|
5564 slot_offset (struct window,
|
|
5565 vertical_divider_draggable_p),
|
|
5566 vertical_divider_changed_in_window,
|
|
5567 0, 0);
|
|
5568
|
|
5569 DEFVAR_SPECIFIER ("vertical-divider-shadow-thickness", &Vvertical_divider_shadow_thickness /*
|
|
5570 *How thick to draw shadows around the vertical dividers.
|
|
5571 This is a specifier; use `set-specifier' to change it.
|
|
5572 */ );
|
|
5573 Vvertical_divider_shadow_thickness = Fmake_specifier (Qinteger);
|
|
5574 set_specifier_fallback (Vvertical_divider_shadow_thickness,
|
|
5575 list1 (Fcons (Qnil, Qzero)));
|
|
5576 Fadd_spec_to_specifier (Vvertical_divider_shadow_thickness, make_int (2),
|
|
5577 Qnil, Qnil, Qnil);
|
|
5578 set_specifier_caching (Vvertical_divider_shadow_thickness,
|
|
5579 slot_offset (struct window,
|
|
5580 vertical_divider_shadow_thickness),
|
|
5581 vertical_divider_changed_in_window,
|
|
5582 0, 0);
|
|
5583 DEFVAR_SPECIFIER ("vertical-divider-line-width", &Vvertical_divider_line_width /*
|
|
5584 *The width of the vertical dividers, not including shadows.
|
|
5585
|
|
5586 For TTY windows, divider line is always one character wide. When
|
|
5587 instance of this specifier is zero in a TTY window, no divider is
|
|
5588 drawn at all between windows. When non-zero, one character wide
|
|
5589 divider is displayed.
|
|
5590
|
|
5591 This is a specifier; use `set-specifier' to change it.
|
|
5592 */ );
|
|
5593
|
|
5594 Vvertical_divider_line_width = Fmake_specifier (Qnatnum);
|
|
5595 {
|
|
5596 Lisp_Object fb = Qnil;
|
|
5597 #ifdef HAVE_TTY
|
|
5598 fb = Fcons (Fcons (list1 (Qtty), Qzero), fb);
|
|
5599 #endif
|
|
5600 #ifdef HAVE_X_WINDOWS
|
|
5601 fb = Fcons (Fcons (list1 (Qx), make_int (3)), fb);
|
|
5602 #endif
|
|
5603 #ifdef HAVE_MS_WINDOWS
|
|
5604 /* #### This should be made magic and made to obey system settings */
|
|
5605 fb = Fcons (Fcons (list1 (Qmswindows), make_int (3)), fb);
|
|
5606 #endif
|
|
5607 set_specifier_fallback (Vvertical_divider_line_width, fb);
|
|
5608 }
|
|
5609 set_specifier_caching (Vvertical_divider_line_width,
|
|
5610 slot_offset (struct window,
|
|
5611 vertical_divider_line_width),
|
|
5612 vertical_divider_changed_in_window,
|
|
5613 0, 0);
|
|
5614
|
|
5615 DEFVAR_SPECIFIER ("vertical-divider-spacing", &Vvertical_divider_spacing /*
|
|
5616 *How much space to leave around the vertical dividers.
|
|
5617
|
|
5618 In TTY windows, spacing is always zero, and the value of this
|
|
5619 specifier is ignored.
|
|
5620
|
|
5621 This is a specifier; use `set-specifier' to change it.
|
|
5622 */ );
|
|
5623 Vvertical_divider_spacing = Fmake_specifier (Qnatnum);
|
|
5624 {
|
|
5625 Lisp_Object fb = Qnil;
|
|
5626 #ifdef HAVE_TTY
|
|
5627 fb = Fcons (Fcons (list1 (Qtty), Qzero), fb);
|
|
5628 #endif
|
|
5629 #ifdef HAVE_X_WINDOWS
|
|
5630 /* #### 3D dividers look great on MS Windows with spacing = 0.
|
286
|
5631 Should not the same value be the fallback under X? - kkm */
|
284
|
5632 fb = Fcons (Fcons (list1 (Qx), make_int (2)), fb);
|
|
5633 #endif
|
|
5634 #ifdef HAVE_MS_WINDOWS
|
|
5635 fb = Fcons (Fcons (list1 (Qmswindows), Qzero), fb);
|
|
5636 #endif
|
|
5637 set_specifier_fallback (Vvertical_divider_spacing, fb);
|
|
5638 }
|
|
5639 set_specifier_caching (Vvertical_divider_spacing,
|
|
5640 slot_offset (struct window,
|
|
5641 vertical_divider_spacing),
|
|
5642 vertical_divider_changed_in_window,
|
|
5643 0, 0);
|
0
|
5644 }
|