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