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