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