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