428
|
1 /* Window creation, deletion and examination for XEmacs.
|
|
2 Copyright (C) 1985-1987, 1992-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
793
|
4 Copyright (C) 1995, 1996, 2002 Ben Wing.
|
428
|
5 Copyright (C) 1996 Chuck Thompson.
|
|
6
|
|
7 This file is part of XEmacs.
|
|
8
|
|
9 XEmacs is free software; you can redistribute it and/or modify it
|
|
10 under the terms of the GNU General Public License as published by the
|
|
11 Free Software Foundation; either version 2, or (at your option) any
|
|
12 later version.
|
|
13
|
|
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
17 for more details.
|
|
18
|
|
19 You should have received a copy of the GNU General Public License
|
|
20 along with XEmacs; see the file COPYING. If not, write to
|
|
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
22 Boston, MA 02111-1307, USA. */
|
|
23
|
|
24 /* Synched up with: FSF 19.30. */
|
|
25 /* Beginning to diverge significantly. */
|
|
26
|
853
|
27 /* Authorship:
|
|
28
|
|
29 Based on code from pre-release FSF 19, c. 1991.
|
|
30 Significantly reworked by Chuck Thompson, 1993-1996.
|
|
31 window mirror stuff added by Chuck Thompson c. 1993.
|
|
32 various cleanup by Ben Wing c. 1995 (window slots, window init code,
|
|
33 memory usage, synch. up to FSF 19.30, other).
|
|
34 Unknown work by Andy Piper.
|
|
35 new window-width/height fns. by Ben Wing, Mar 2000. */
|
|
36
|
428
|
37 /* This file has been Mule-ized. */
|
|
38
|
|
39 #include <config.h>
|
|
40 #include "lisp.h"
|
|
41
|
|
42 #include "buffer.h"
|
800
|
43 #include "commands.h"
|
872
|
44 #include "device-impl.h"
|
800
|
45 #include "elhash.h"
|
428
|
46 #include "faces.h"
|
872
|
47 #include "frame-impl.h"
|
800
|
48 #include "glyphs.h"
|
|
49 #include "gutter.h"
|
428
|
50 #include "objects.h"
|
|
51 #include "redisplay.h"
|
872
|
52 #include "window-impl.h"
|
428
|
53
|
1149
|
54 Lisp_Object Qwindowp, Qwindow_live_p;
|
428
|
55 Lisp_Object Qdisplay_buffer;
|
|
56
|
|
57 #ifdef MEMORY_USAGE_STATS
|
|
58 Lisp_Object Qface_cache, Qglyph_cache, Qline_start_cache, Qother_redisplay;
|
|
59 #ifdef HAVE_SCROLLBARS
|
|
60 Lisp_Object Qscrollbar_instances;
|
|
61 #endif
|
|
62 #endif
|
|
63
|
|
64 EXFUN (Fnext_window, 4);
|
|
65
|
|
66 static int window_pixel_width_to_char_width (struct window *w,
|
|
67 int pixel_width,
|
|
68 int include_margins_p);
|
|
69 static int window_char_width_to_pixel_width (struct window *w,
|
|
70 int char_width,
|
|
71 int include_margins_p);
|
|
72 static int window_pixel_height_to_char_height (struct window *w,
|
|
73 int pixel_height,
|
|
74 int include_gutters_p);
|
|
75 static int window_char_height_to_pixel_height (struct window *w,
|
|
76 int char_height,
|
|
77 int include_gutters_p);
|
444
|
78 static void change_window_height (Lisp_Object window, int delta,
|
|
79 Lisp_Object horizontalp, int inpixels);
|
428
|
80
|
|
81 /* Thickness of shadow border around 3d modelines. */
|
|
82 Lisp_Object Vmodeline_shadow_thickness;
|
|
83
|
|
84 /* Whether vertical dividers are draggable and displayed */
|
|
85 Lisp_Object Vvertical_divider_always_visible_p;
|
|
86
|
|
87 /* Whether a modeline should be displayed. */
|
|
88 Lisp_Object Vhas_modeline_p;
|
|
89
|
|
90 /* Thickness of shadow border around vertical dividers. */
|
|
91 Lisp_Object Vvertical_divider_shadow_thickness;
|
|
92
|
|
93 /* Divider surface width (not counting 3-d borders) */
|
|
94 Lisp_Object Vvertical_divider_line_width;
|
|
95
|
442
|
96 /* Spacing between outer edge of divider border and window edge */
|
428
|
97 Lisp_Object Vvertical_divider_spacing;
|
|
98
|
|
99 /* How much to scroll by per-line. */
|
|
100 Lisp_Object Vwindow_pixel_scroll_increment;
|
|
101
|
|
102 /* Scroll if point lands on the bottom line and that line is partially
|
|
103 clipped. */
|
|
104 int scroll_on_clipped_lines;
|
|
105
|
|
106 /* The minibuffer window of the selected frame.
|
|
107 Note that you cannot test for minibufferness of an arbitrary window
|
|
108 by comparing against this; but you can test for minibufferness of
|
|
109 the selected window. */
|
|
110 Lisp_Object minibuf_window;
|
|
111
|
|
112 /* Non-nil means it is the window for C-M-v to scroll
|
|
113 when the minibuffer is selected. */
|
|
114 Lisp_Object Vminibuffer_scroll_window;
|
|
115
|
|
116 /* Non-nil means this is the buffer whose window C-M-v should scroll. */
|
|
117 Lisp_Object Vother_window_scroll_buffer;
|
|
118
|
|
119 /* Non-nil means it's the function to call to display temp buffers. */
|
|
120 Lisp_Object Vtemp_buffer_show_function;
|
|
121
|
|
122 /* If a window gets smaller than either of these, it is removed. */
|
458
|
123 Fixnum window_min_height;
|
|
124 Fixnum window_min_width;
|
428
|
125
|
|
126 /* Number of lines of continuity in scrolling by screenfuls. */
|
458
|
127 Fixnum next_screen_context_lines;
|
428
|
128
|
1149
|
129 Lisp_Object Qcurrent_window_configuration, Qset_window_configuration;
|
428
|
130
|
707
|
131 Lisp_Object Qtruncate_partial_width_windows;
|
|
132
|
428
|
133 #define SET_LAST_MODIFIED(w, cache_too) \
|
|
134 do { \
|
|
135 (w)->last_modified[CURRENT_DISP] = Qzero; \
|
|
136 (w)->last_modified[DESIRED_DISP] = Qzero; \
|
|
137 (w)->last_modified[CMOTION_DISP] = Qzero; \
|
|
138 if (cache_too) \
|
|
139 (w)->line_cache_last_updated = Qzero; \
|
|
140 } while (0)
|
|
141
|
|
142 #define SET_LAST_FACECHANGE(w) \
|
|
143 do { \
|
|
144 (w)->last_facechange[CURRENT_DISP] = Qzero; \
|
|
145 (w)->last_facechange[DESIRED_DISP] = Qzero; \
|
|
146 (w)->last_facechange[CMOTION_DISP] = Qzero; \
|
|
147 } while (0)
|
|
148
|
|
149
|
1204
|
150
|
|
151 static const struct memory_description int_description_1[] = {
|
|
152 { XD_END }
|
|
153 };
|
|
154
|
|
155 static const struct sized_memory_description int_description = {
|
|
156 sizeof (int),
|
|
157 int_description_1
|
|
158 };
|
|
159
|
|
160 static const struct memory_description int_dynarr_description_1[] = {
|
|
161 XD_DYNARR_DESC (int_dynarr, &int_description),
|
|
162 { XD_END }
|
|
163 };
|
|
164
|
|
165 static const struct sized_memory_description int_dynarr_description = {
|
|
166 sizeof (int_dynarr),
|
|
167 int_dynarr_description_1
|
|
168 };
|
|
169
|
|
170 static const struct memory_description face_cachel_description_1[] = {
|
|
171 { XD_STRUCT_PTR, offsetof (face_cachel, merged_faces),
|
|
172 1, &int_dynarr_description },
|
|
173 { XD_LISP_OBJECT, offsetof (face_cachel, face) },
|
|
174 { XD_LISP_OBJECT, offsetof (face_cachel, foreground) },
|
|
175 { XD_LISP_OBJECT, offsetof (face_cachel, background) },
|
|
176 { XD_LISP_OBJECT_ARRAY, offsetof (face_cachel, font), NUM_LEADING_BYTES },
|
|
177 { XD_LISP_OBJECT, offsetof (face_cachel, display_table) },
|
|
178 { XD_LISP_OBJECT, offsetof (face_cachel, background_pixmap) },
|
|
179 { XD_END }
|
|
180 };
|
|
181
|
|
182 static const struct sized_memory_description face_cachel_description = {
|
|
183 sizeof (face_cachel),
|
|
184 face_cachel_description_1
|
|
185 };
|
|
186
|
|
187 static const struct memory_description face_cachel_dynarr_description_1[] = {
|
|
188 XD_DYNARR_DESC (face_cachel_dynarr, &face_cachel_description),
|
|
189 { XD_END }
|
|
190 };
|
|
191
|
|
192 static const struct sized_memory_description face_cachel_dynarr_description = {
|
|
193 sizeof (face_cachel_dynarr),
|
|
194 face_cachel_dynarr_description_1
|
|
195 };
|
|
196
|
|
197 static const struct memory_description glyph_cachel_description_1[] = {
|
|
198 { XD_LISP_OBJECT, offsetof (glyph_cachel, glyph) },
|
|
199 { XD_END }
|
|
200 };
|
|
201
|
|
202 static const struct sized_memory_description glyph_cachel_description = {
|
|
203 sizeof (glyph_cachel),
|
|
204 glyph_cachel_description_1
|
|
205 };
|
|
206
|
|
207 static const struct memory_description glyph_cachel_dynarr_description_1[] = {
|
|
208 XD_DYNARR_DESC (glyph_cachel_dynarr, &glyph_cachel_description),
|
|
209 { XD_END }
|
|
210 };
|
|
211
|
|
212 static const struct sized_memory_description glyph_cachel_dynarr_description = {
|
|
213 sizeof (glyph_cachel_dynarr),
|
|
214 glyph_cachel_dynarr_description_1
|
|
215 };
|
|
216
|
|
217 static const struct memory_description line_start_cache_description_1[] = {
|
|
218 { XD_END }
|
|
219 };
|
|
220
|
|
221 static const struct sized_memory_description line_start_cache_description = {
|
|
222 sizeof (line_start_cache),
|
|
223 line_start_cache_description_1
|
|
224 };
|
|
225
|
|
226 static const struct memory_description line_start_cache_dynarr_description_1[] = {
|
|
227 XD_DYNARR_DESC (line_start_cache_dynarr, &line_start_cache_description),
|
|
228 { XD_END }
|
|
229 };
|
|
230
|
|
231 static const struct sized_memory_description line_start_cache_dynarr_description = {
|
|
232 sizeof (line_start_cache_dynarr),
|
|
233 line_start_cache_dynarr_description_1
|
|
234 };
|
|
235
|
|
236 static const struct memory_description window_description [] = {
|
|
237 #define WINDOW_SLOT(slot) { XD_LISP_OBJECT, offsetof (struct window, slot) },
|
|
238 #define WINDOW_SLOT_ARRAY(slot, size) \
|
|
239 { XD_LISP_OBJECT_ARRAY, offsetof (struct window, slot), size },
|
|
240 #include "winslots.h"
|
|
241
|
|
242 { XD_STRUCT_PTR, offsetof (struct window, face_cachels),
|
|
243 1, &face_cachel_dynarr_description },
|
|
244 { XD_STRUCT_PTR, offsetof (struct window, glyph_cachels),
|
|
245 1, &glyph_cachel_dynarr_description },
|
|
246 { XD_STRUCT_PTR, offsetof (struct window, line_start_cache),
|
|
247 1, &line_start_cache_dynarr_description },
|
|
248 { XD_END }
|
|
249 };
|
428
|
250
|
|
251 static Lisp_Object
|
|
252 mark_window (Lisp_Object obj)
|
|
253 {
|
|
254 struct window *window = XWINDOW (obj);
|
|
255
|
|
256 mark_face_cachels (window->face_cachels);
|
|
257 mark_glyph_cachels (window->glyph_cachels);
|
|
258
|
617
|
259 #define WINDOW_SLOT(slot) mark_object (window->slot);
|
428
|
260 #include "winslots.h"
|
|
261
|
|
262 return Qnil;
|
|
263 }
|
|
264
|
|
265 static void
|
|
266 print_window (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
267 {
|
|
268 if (print_readably)
|
563
|
269 printing_unreadable_object ("#<window 0x%x>", XWINDOW (obj)->header.uid);
|
428
|
270
|
826
|
271 write_c_string (printcharfun, "#<window");
|
428
|
272 if (!NILP (XWINDOW (obj)->buffer))
|
|
273 {
|
|
274 Lisp_Object name = XBUFFER (XWINDOW (obj)->buffer)->name;
|
800
|
275 write_fmt_string_lisp (printcharfun, " on %S", 1, name);
|
428
|
276 }
|
800
|
277 write_fmt_string (printcharfun, " 0x%x>", XWINDOW (obj)->header.uid);
|
428
|
278 }
|
|
279
|
|
280 static void
|
|
281 finalize_window (void *header, int for_disksave)
|
|
282 {
|
|
283 struct window *w = (struct window *) header;
|
|
284
|
|
285 if (w->line_start_cache)
|
|
286 {
|
|
287 Dynarr_free (w->line_start_cache);
|
|
288 w->line_start_cache = 0;
|
|
289 }
|
|
290
|
|
291 if (w->face_cachels)
|
|
292 {
|
|
293 int i;
|
|
294
|
|
295 for (i = 0; i < Dynarr_length (w->face_cachels); i++)
|
|
296 {
|
|
297 struct face_cachel *cachel = Dynarr_atp (w->face_cachels, i);
|
|
298 if (cachel->merged_faces)
|
|
299 {
|
|
300 Dynarr_free (cachel->merged_faces);
|
|
301 cachel->merged_faces = 0;
|
|
302 }
|
|
303 }
|
|
304 Dynarr_free (w->face_cachels);
|
|
305 w->face_cachels = 0;
|
|
306 }
|
|
307
|
|
308 if (w->glyph_cachels)
|
|
309 {
|
|
310 Dynarr_free (w->glyph_cachels);
|
|
311 w->glyph_cachels = 0;
|
|
312 }
|
|
313 }
|
|
314
|
844
|
315 /* These caches map buffers to markers. They are key-weak so that entries
|
|
316 remain around as long as the buffers do. */
|
|
317
|
|
318 static Lisp_Object
|
|
319 make_saved_buffer_point_cache (void)
|
|
320 {
|
|
321 return make_lisp_hash_table (20, HASH_TABLE_KEY_WEAK, HASH_TABLE_EQ);
|
|
322 }
|
|
323
|
934
|
324 DEFINE_LRECORD_IMPLEMENTATION ("window", window,
|
|
325 0, /*dumpable-flag*/
|
|
326 mark_window, print_window, finalize_window,
|
1204
|
327 0, 0, window_description, struct window);
|
428
|
328
|
|
329 #define INIT_DISP_VARIABLE(field, initialization) \
|
|
330 p->field[CURRENT_DISP] = initialization; \
|
|
331 p->field[DESIRED_DISP] = initialization; \
|
|
332 p->field[CMOTION_DISP] = initialization;
|
|
333
|
|
334 /* We have an implicit assertion that the first two elements (default
|
|
335 and modeline faces) are always present in the face_element_cache.
|
|
336 Normally redisplay ensures this. However, it is possible for a
|
|
337 window to get created and functions which reference these values
|
|
338 called before redisplay works with the window for the first time.
|
|
339 All callers of allocate_window should therefore call
|
|
340 reset_face_cachels on the created window. We can't do it
|
|
341 here because the window must have its frame pointer set or
|
|
342 reset_face_cachels will fail. */
|
|
343 Lisp_Object
|
|
344 allocate_window (void)
|
|
345 {
|
|
346 struct window *p = alloc_lcrecord_type (struct window, &lrecord_window);
|
1204
|
347 Lisp_Object val = wrap_window (p);
|
617
|
348
|
|
349 #define WINDOW_SLOT(slot) p->slot = Qnil;
|
|
350 #include "winslots.h"
|
|
351
|
428
|
352 INIT_DISP_VARIABLE (start, Fmake_marker ());
|
|
353 INIT_DISP_VARIABLE (pointm, Fmake_marker ());
|
|
354 p->sb_point = Fmake_marker ();
|
844
|
355 p->saved_point_cache = make_saved_buffer_point_cache ();
|
|
356 p->saved_last_window_start_cache = make_saved_buffer_point_cache ();
|
428
|
357 p->use_time = Qzero;
|
|
358 INIT_DISP_VARIABLE (last_modified, Qzero);
|
|
359 INIT_DISP_VARIABLE (last_point, Fmake_marker ());
|
|
360 INIT_DISP_VARIABLE (last_start, Fmake_marker ());
|
|
361 INIT_DISP_VARIABLE (last_facechange, Qzero);
|
|
362 p->face_cachels = Dynarr_new (face_cachel);
|
|
363 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
|
364 p->line_start_cache = Dynarr_new (line_start_cache);
|
450
|
365 p->subwindow_instance_cache = make_image_instance_cache_hash_table ();
|
|
366
|
428
|
367 p->line_cache_last_updated = Qzero;
|
442
|
368
|
428
|
369 p->windows_changed = 1;
|
|
370 p->shadow_thickness_changed = 1;
|
|
371
|
|
372 return val;
|
|
373 }
|
|
374 #undef INIT_DISP_VARIABLE
|
|
375
|
617
|
376 /************************************************************************/
|
|
377 /* Window mirror structure */
|
|
378 /************************************************************************/
|
|
379
|
428
|
380 /*
|
|
381 * The redisplay structures used to be stored with each window. While
|
|
382 * they are logically something associated with frames they can't be
|
|
383 * stored there with a redisplay which handles variable height lines.
|
|
384 * Lines in horizontally split windows might not line up. So they get
|
|
385 * stored with the windows.
|
|
386 *
|
|
387 * The problem with this is window configurations. When restoring a
|
|
388 * window configuration it now becomes problematic to do an
|
|
389 * incremental redisplay. The solution is to store the redisplay
|
|
390 * structures with the frame as they should be but laid out in the
|
|
391 * same manner as the window structure. Thus is born the window
|
|
392 * mirror.
|
|
393 *
|
|
394 * It also becomes a convenient place to stick scrollbar instances
|
|
395 * since they extrapolate out to having the same problem described for
|
|
396 * the display structures.
|
|
397 */
|
|
398
|
617
|
399 /* NOTE: The window-mirror structure formerly was not a Lisp object, and
|
|
400 marking was handled specially. I've gotten recurring crashes, however,
|
|
401 using the mouse wheel under Windows, where either the window mirror
|
|
402 accessed through a scrollbar instance, or the frame pointed to by that
|
|
403 window mirror, gets garbaged. Things are tricky under windows because
|
|
404 the scrollbar instances are stored in HWND-specific data. Furthermore,
|
|
405 we have scrollbar-instance caches to complicate things. Both of these
|
|
406 make it very difficult (for me at least, not being intimately familiar
|
|
407 with the redisplay code) to track exactly when and where a particular
|
|
408 window mirror or scrollbar instance has pointers to it, or whether a
|
|
409 window mirror might have a dead frame or buffer in it (i.e. not
|
|
410 necessarily gc-protected by being on a global list). By far the safest
|
|
411 thing, then, is to make both structures Lisp objects and not explicitly
|
|
412 xfree() them. This should make no practical difference in memory usage
|
|
413 because neither structure is created very often (only when windows are
|
|
414 created or deleted). --ben */
|
|
415
|
1204
|
416 static const struct memory_description window_mirror_description [] = {
|
|
417 { XD_LISP_OBJECT, offsetof (struct window_mirror, frame) },
|
|
418 { XD_LISP_OBJECT, offsetof (struct window_mirror, next) },
|
|
419 { XD_LISP_OBJECT, offsetof (struct window_mirror, hchild) },
|
|
420 { XD_LISP_OBJECT, offsetof (struct window_mirror, vchild) },
|
|
421
|
|
422 { XD_STRUCT_PTR, offsetof (struct window_mirror, current_display_lines),
|
|
423 1, &display_line_dynarr_description },
|
|
424 { XD_STRUCT_PTR, offsetof (struct window_mirror, desired_display_lines),
|
|
425 1, &display_line_dynarr_description },
|
|
426
|
|
427 { XD_LISP_OBJECT, offsetof (struct window_mirror, buffer) },
|
|
428
|
|
429 #ifdef HAVE_SCROLLBARS
|
|
430 { XD_LISP_OBJECT, offsetof (struct window_mirror,
|
|
431 scrollbar_vertical_instance) },
|
|
432 { XD_LISP_OBJECT, offsetof (struct window_mirror,
|
|
433 scrollbar_horizontal_instance) },
|
|
434 #endif /* HAVE_SCROLLBARS */
|
|
435
|
934
|
436 { XD_END }
|
|
437 };
|
|
438
|
617
|
439 static Lisp_Object
|
|
440 mark_window_mirror (Lisp_Object obj)
|
|
441 {
|
|
442 struct window_mirror *mir = XWINDOW_MIRROR (obj);
|
|
443
|
|
444 if (mir->current_display_lines)
|
|
445 mark_redisplay_structs (mir->current_display_lines);
|
|
446 if (mir->desired_display_lines)
|
|
447 mark_redisplay_structs (mir->desired_display_lines);
|
|
448
|
|
449 if (mir->hchild)
|
|
450 mark_object (wrap_window_mirror (mir->hchild));
|
|
451 if (mir->vchild)
|
|
452 mark_object (wrap_window_mirror (mir->vchild));
|
|
453
|
|
454 if (mir->frame)
|
|
455 mark_object (wrap_frame (mir->frame));
|
|
456 if (mir->buffer)
|
|
457 mark_object (wrap_buffer (mir->buffer));
|
|
458
|
|
459 #ifdef HAVE_SCROLLBARS
|
|
460 if (mir->scrollbar_vertical_instance)
|
|
461 mark_object (wrap_scrollbar_instance (mir->scrollbar_vertical_instance));
|
|
462 if (mir->scrollbar_horizontal_instance)
|
|
463 mark_object (wrap_scrollbar_instance (mir->scrollbar_horizontal_instance));
|
|
464 #endif /* HAVE_SCROLLBARS */
|
|
465 if (mir->next)
|
|
466 return wrap_window_mirror (mir->next);
|
|
467 else
|
|
468 return Qnil;
|
|
469 }
|
|
470
|
934
|
471 DEFINE_LRECORD_IMPLEMENTATION ("window-mirror", window_mirror,
|
|
472 0, /*dumpable-flag*/
|
|
473 mark_window_mirror, internal_object_printer,
|
1204
|
474 0, 0, 0, window_mirror_description,
|
|
475 struct window_mirror);
|
617
|
476
|
428
|
477 /* Create a new window mirror structure and associated redisplay
|
|
478 structs. */
|
|
479 static struct window_mirror *
|
|
480 new_window_mirror (struct frame *f)
|
|
481 {
|
617
|
482 struct window_mirror *t =
|
|
483 alloc_lcrecord_type (struct window_mirror, &lrecord_window_mirror);
|
428
|
484
|
|
485 t->frame = f;
|
|
486 t->current_display_lines = Dynarr_new (display_line);
|
|
487 t->desired_display_lines = Dynarr_new (display_line);
|
|
488
|
|
489 return t;
|
|
490 }
|
|
491
|
|
492 /* Synchronize the mirror structure with a given window structure.
|
|
493 This is normally called from update_frame_window_mirror with a
|
|
494 starting window of f->root_window. */
|
|
495 static struct window_mirror *
|
|
496 update_mirror_internal (Lisp_Object win, struct window_mirror *mir)
|
|
497 {
|
|
498 if (NILP (win))
|
|
499 {
|
|
500 if (mir)
|
|
501 {
|
|
502 free_window_mirror (mir);
|
|
503 mir = NULL;
|
|
504 }
|
|
505 return mir;
|
|
506 }
|
|
507 else
|
|
508 if (!mir)
|
|
509 mir = new_window_mirror (XFRAME (XWINDOW (win)->frame));
|
|
510
|
1204
|
511 mir->next = update_mirror_internal (XWINDOW (win)->next, mir->next);
|
428
|
512 mir->hchild = update_mirror_internal (XWINDOW (win)->hchild, mir->hchild);
|
|
513 mir->vchild = update_mirror_internal (XWINDOW (win)->vchild, mir->vchild);
|
|
514
|
|
515 /*
|
|
516 * If the redisplay structs are not empty and the mirror has
|
|
517 * children, then this mirror structure was formerly being used for
|
|
518 * display but is no longer. Reset its current display structs so
|
|
519 * that redisplay doesn't accidentally think they are accurate if it
|
|
520 * is later used for display purposes once again. Also, mark the
|
|
521 * scrollbar instance as not active.
|
|
522 */
|
|
523 if (mir->vchild || mir->hchild)
|
|
524 {
|
|
525 /* The redisplay structures are big. Leaving them around in
|
|
526 non-leaf windows can add up to a lot of wasted space. So
|
|
527 don't do it. */
|
|
528 free_display_structs (mir);
|
|
529 mir->current_display_lines = Dynarr_new (display_line);
|
|
530 mir->desired_display_lines = Dynarr_new (display_line);
|
|
531
|
|
532 #ifdef HAVE_SCROLLBARS
|
|
533 update_window_scrollbars (XWINDOW (win), mir, 0, 0);
|
|
534 #endif
|
|
535 mir->buffer = NULL;
|
|
536 }
|
|
537
|
|
538 return mir;
|
|
539 }
|
|
540
|
|
541 /* Given a window mirror, determine which real window it contains the
|
|
542 redisplay structures for. */
|
|
543 static Lisp_Object
|
|
544 real_window_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
545 struct window_mirror *mir)
|
|
546 {
|
|
547 for (; !NILP (win) && rmir ; win = XWINDOW (win)->next, rmir = rmir->next)
|
|
548 {
|
|
549 if (mir == rmir)
|
|
550 return win;
|
|
551 if (!NILP (XWINDOW (win)->vchild))
|
|
552 {
|
|
553 Lisp_Object retval =
|
|
554 real_window_internal (XWINDOW (win)->vchild, rmir->vchild, mir);
|
|
555 if (!NILP (retval))
|
|
556 return retval;
|
|
557 }
|
|
558 if (!NILP (XWINDOW (win)->hchild))
|
|
559 {
|
|
560 Lisp_Object retval =
|
|
561 real_window_internal (XWINDOW (win)->hchild, rmir->hchild, mir);
|
|
562 if (!NILP (retval))
|
|
563 return retval;
|
|
564 }
|
|
565 }
|
|
566
|
|
567 return Qnil;
|
|
568 }
|
|
569
|
|
570 /* Given a real window, find the mirror structure which contains its
|
|
571 redisplay structures. */
|
|
572 static struct window_mirror *
|
|
573 find_window_mirror_internal (Lisp_Object win, struct window_mirror *rmir,
|
|
574 struct window *w)
|
|
575 {
|
|
576 for (; !NILP (win); win = XWINDOW (win)->next, rmir = rmir->next)
|
|
577 {
|
|
578 if (w == XWINDOW (win))
|
|
579 return rmir;
|
|
580
|
|
581 if (!NILP (XWINDOW (win)->vchild))
|
|
582 {
|
|
583 struct window_mirror *retval =
|
|
584 find_window_mirror_internal (XWINDOW (win)->vchild,
|
|
585 rmir->vchild, w);
|
|
586 if (retval) return retval;
|
|
587 }
|
|
588
|
|
589 if (!NILP (XWINDOW (win)->hchild))
|
|
590 {
|
|
591 struct window_mirror *retval =
|
|
592 find_window_mirror_internal (XWINDOW (win)->hchild,
|
|
593 rmir->hchild, w);
|
|
594 if (retval) return retval;
|
|
595 }
|
|
596 }
|
|
597
|
|
598 return 0;
|
|
599 }
|
|
600
|
|
601 /* Update the mirror structure for the given frame. */
|
|
602 void
|
|
603 update_frame_window_mirror (struct frame *f)
|
|
604 {
|
617
|
605 f->root_mirror =
|
|
606 wrap_window_mirror (update_mirror_internal
|
|
607 (f->root_window,
|
|
608 NILP (f->root_mirror) ? 0 :
|
|
609 XWINDOW_MIRROR (f->root_mirror)));
|
428
|
610 f->mirror_dirty = 0;
|
|
611 }
|
|
612
|
|
613 /* Free a given mirror structure along with all of its children as
|
|
614 well as their associated display structures. */
|
|
615 void
|
|
616 free_window_mirror (struct window_mirror *mir)
|
|
617 {
|
|
618 while (mir)
|
|
619 {
|
|
620 if (mir->hchild) free_window_mirror (mir->hchild);
|
|
621 if (mir->vchild) free_window_mirror (mir->vchild);
|
|
622 #ifdef HAVE_SCROLLBARS
|
|
623 release_window_mirror_scrollbars (mir);
|
|
624 #endif
|
|
625 free_display_structs (mir);
|
|
626 mir = mir->next;
|
617
|
627 /* not worth calling free_managed_lcrecord() -- window mirrors
|
|
628 are not created that frequently and it's dangerous. we don't
|
|
629 know for sure that there aren't other pointers around -- e.g.
|
|
630 in a scrollbar instance. */
|
428
|
631 }
|
|
632 }
|
|
633
|
|
634 /* Given a mirror structure, return the window it mirrors. Calls
|
|
635 real_window_internal to do most of the work. */
|
|
636 Lisp_Object
|
|
637 real_window (struct window_mirror *mir, int no_abort)
|
|
638 {
|
617
|
639 Lisp_Object retval =
|
|
640 real_window_internal (mir->frame->root_window,
|
|
641 XWINDOW_MIRROR (mir->frame->root_mirror), mir);
|
428
|
642 if (NILP (retval) && !no_abort)
|
|
643 abort ();
|
|
644
|
|
645 return retval;
|
|
646 }
|
|
647
|
|
648 /* Given a real window, return its mirror structure. Calls
|
|
649 find_window_mirror_internal to do all of the work. */
|
|
650 struct window_mirror *
|
|
651 find_window_mirror (struct window *w)
|
|
652 {
|
|
653 struct frame *f = XFRAME (w->frame);
|
|
654 if (f->mirror_dirty)
|
|
655 update_frame_window_mirror (f);
|
617
|
656 return find_window_mirror_internal (f->root_window,
|
|
657 XWINDOW_MIRROR (f->root_mirror), w);
|
428
|
658 }
|
|
659
|
|
660 /*****************************************************************************
|
|
661 find_window_by_pixel_pos
|
|
662
|
|
663 Given a pixel position relative to a frame, find the window at that
|
|
664 position.
|
|
665 ****************************************************************************/
|
|
666 struct window *
|
|
667 find_window_by_pixel_pos (int pix_x, int pix_y, Lisp_Object win)
|
|
668 {
|
|
669 if (NILP (win))
|
|
670 return 0;
|
|
671
|
|
672 for (; !NILP (win); win = XWINDOW (win)->next)
|
|
673 {
|
|
674 struct window *w;
|
|
675
|
|
676 if (!NILP (XWINDOW (win)->vchild))
|
|
677 {
|
|
678 w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->vchild);
|
|
679 if (w) return w;
|
|
680 }
|
|
681 if (!NILP (XWINDOW (win)->hchild))
|
|
682 {
|
|
683 w = find_window_by_pixel_pos (pix_x, pix_y, XWINDOW (win)->hchild);
|
|
684 if (w) return w;
|
|
685 }
|
|
686 w = XWINDOW (win);
|
|
687 if (pix_x >= WINDOW_LEFT (w)
|
|
688 && pix_x <= WINDOW_RIGHT (w)
|
|
689 && pix_y >= WINDOW_TOP (w)
|
|
690 && pix_y <= WINDOW_BOTTOM (w))
|
|
691 return w;
|
|
692 }
|
|
693 return NULL;
|
|
694 }
|
|
695
|
|
696 /* Return a pointer to the display structures for the given window. */
|
|
697 display_line_dynarr *
|
|
698 window_display_lines (struct window *w, int which)
|
|
699 {
|
|
700 struct window_mirror *t;
|
|
701
|
|
702 if (XFRAME (w->frame)->mirror_dirty)
|
|
703 update_frame_window_mirror (XFRAME (w->frame));
|
|
704 t = find_window_mirror (w);
|
|
705 if (!t)
|
|
706 abort ();
|
|
707
|
|
708 if (which == CURRENT_DISP)
|
|
709 return t->current_display_lines;
|
|
710 else if (which == DESIRED_DISP)
|
|
711 return t->desired_display_lines;
|
|
712 else if (which == CMOTION_DISP)
|
|
713 /* The CMOTION_DISP display lines are global. */
|
|
714 return cmotion_display_lines;
|
|
715 else
|
|
716 abort ();
|
|
717
|
|
718 return 0; /* shut up compiler */
|
|
719 }
|
|
720
|
|
721 struct buffer *
|
|
722 window_display_buffer (struct window *w)
|
|
723 {
|
|
724 struct window_mirror *t;
|
|
725
|
|
726 if (XFRAME (w->frame)->mirror_dirty)
|
|
727 update_frame_window_mirror (XFRAME (w->frame));
|
|
728 t = find_window_mirror (w);
|
|
729 if (!t)
|
|
730 abort ();
|
|
731
|
|
732 return t->buffer;
|
|
733 }
|
|
734
|
|
735 void
|
|
736 set_window_display_buffer (struct window *w, struct buffer *b)
|
|
737 {
|
|
738 struct window_mirror *t;
|
|
739
|
|
740 if (XFRAME (w->frame)->mirror_dirty)
|
|
741 update_frame_window_mirror (XFRAME (w->frame));
|
|
742 t = find_window_mirror (w);
|
|
743 if (!t)
|
|
744 abort ();
|
|
745
|
|
746 t->buffer = b;
|
|
747 }
|
|
748
|
|
749
|
|
750 /* Determining a window's position based solely on its pixel
|
|
751 positioning doesn't work. Instead, we do it the intelligent way,
|
|
752 by checking its positioning in the window hierarchy. */
|
|
753 int
|
|
754 window_is_leftmost (struct window *w)
|
|
755 {
|
|
756 Lisp_Object parent, current_ancestor, window;
|
|
757
|
793
|
758 window = wrap_window (w);
|
428
|
759
|
|
760 parent = XWINDOW (window)->parent;
|
|
761 current_ancestor = window;
|
|
762
|
|
763 while (!NILP (parent))
|
|
764 {
|
|
765 if (!NILP (XWINDOW (parent)->hchild) &&
|
|
766 !EQ (XWINDOW (parent)->hchild, current_ancestor))
|
|
767 return 0;
|
|
768
|
|
769 current_ancestor = parent;
|
|
770 parent = XWINDOW (parent)->parent;
|
|
771 }
|
|
772
|
|
773 return 1;
|
|
774 }
|
|
775
|
|
776 int
|
|
777 window_is_rightmost (struct window *w)
|
|
778 {
|
|
779 Lisp_Object parent, current_ancestor, window;
|
|
780
|
793
|
781 window = wrap_window (w);
|
428
|
782
|
|
783 parent = XWINDOW (window)->parent;
|
|
784 current_ancestor = window;
|
|
785
|
|
786 while (!NILP (parent))
|
|
787 {
|
|
788 if (!NILP (XWINDOW (parent)->hchild)
|
|
789 && !NILP (XWINDOW (current_ancestor)->next))
|
|
790 return 0;
|
|
791
|
|
792 current_ancestor = parent;
|
|
793 parent = XWINDOW (parent)->parent;
|
|
794 }
|
|
795
|
|
796 return 1;
|
|
797 }
|
|
798
|
|
799 static int
|
|
800 window_full_width_p (struct window *w)
|
|
801 {
|
|
802 return window_is_leftmost (w) && window_is_rightmost (w);
|
|
803 }
|
|
804
|
|
805 int
|
|
806 window_is_highest (struct window *w)
|
|
807 {
|
|
808 Lisp_Object parent, current_ancestor, window;
|
|
809
|
793
|
810 window = wrap_window (w);
|
428
|
811
|
|
812 parent = XWINDOW (window)->parent;
|
|
813 current_ancestor = window;
|
|
814
|
|
815 while (!NILP (parent))
|
|
816 {
|
|
817 if (!NILP (XWINDOW (parent)->vchild) &&
|
|
818 !EQ (XWINDOW (parent)->vchild, current_ancestor))
|
|
819 return 0;
|
|
820
|
|
821 current_ancestor = parent;
|
|
822 parent = XWINDOW (parent)->parent;
|
|
823 }
|
|
824
|
|
825 /* This is really to catch the minibuffer but we make it generic in
|
|
826 case we ever change things around to let the minibuffer be on top. */
|
|
827 if (NILP (XWINDOW (current_ancestor)->prev))
|
|
828 return 1;
|
|
829 else
|
|
830 return 0;
|
|
831 }
|
|
832
|
|
833 int
|
|
834 window_is_lowest (struct window *w)
|
|
835 {
|
|
836 Lisp_Object parent, current_ancestor, window;
|
|
837
|
793
|
838 window = wrap_window (w);
|
428
|
839
|
|
840 parent = XWINDOW (window)->parent;
|
|
841 current_ancestor = window;
|
|
842
|
|
843 while (!NILP (parent))
|
|
844 {
|
|
845 if (!NILP (XWINDOW (parent)->vchild)
|
|
846 && !NILP (XWINDOW (current_ancestor)->next))
|
|
847 return 0;
|
|
848
|
|
849 current_ancestor = parent;
|
|
850 parent = XWINDOW (parent)->parent;
|
|
851 }
|
|
852
|
|
853 return 1;
|
|
854 }
|
|
855
|
|
856 #if 0 /* not currently used */
|
|
857
|
|
858 static int
|
|
859 window_full_height_p (struct window *w)
|
|
860 {
|
|
861 return window_is_highest (w) && window_is_lowest (w);
|
|
862 }
|
|
863
|
|
864 #endif
|
|
865
|
|
866 int
|
|
867 window_truncation_on (struct window *w)
|
|
868 {
|
|
869 /* Minibuffer windows are never truncated.
|
440
|
870 #### is this the right way ? */
|
428
|
871 if (MINI_WINDOW_P (w))
|
|
872 return 0;
|
|
873
|
|
874 /* Horizontally scrolled windows are truncated. */
|
|
875 if (w->hscroll)
|
|
876 return 1;
|
|
877
|
|
878 /* If truncate_partial_width_windows is true and the window is not
|
|
879 the full width of the frame it is truncated. */
|
707
|
880 if (!NILP (symbol_value_in_buffer (Qtruncate_partial_width_windows,
|
|
881 w->buffer))
|
428
|
882 && !(window_is_leftmost (w) && window_is_rightmost (w)))
|
|
883 return 1;
|
|
884
|
|
885 /* If the window's buffer's value of truncate_lines is non-nil, then
|
|
886 the window is truncated. */
|
|
887 if (!NILP (XBUFFER (w->buffer)->truncate_lines))
|
|
888 return 1;
|
|
889
|
|
890 return 0;
|
|
891 }
|
|
892
|
|
893 DEFUN ("window-truncated-p", Fwindow_truncated_p, 0, 1, 0, /*
|
442
|
894 Returns non-nil if text in the window is truncated.
|
428
|
895 */
|
|
896 (window))
|
|
897 {
|
|
898 struct window *w = decode_window (window);
|
|
899
|
|
900 return window_truncation_on (w) ? Qt : Qnil;
|
|
901 }
|
|
902
|
|
903
|
|
904 static int
|
|
905 have_undivided_common_edge (struct window *w_right, void *closure)
|
|
906 {
|
|
907 struct window *w_left = (struct window *) closure;
|
|
908 return (WINDOW_RIGHT (w_left) == WINDOW_LEFT (w_right)
|
|
909 && WINDOW_TOP (w_left) < WINDOW_BOTTOM (w_right)
|
|
910 && WINDOW_TOP (w_right) < WINDOW_BOTTOM (w_left)
|
|
911 #ifdef HAVE_SCROLLBARS
|
|
912 && (NILP (w_right->scrollbar_on_left_p)
|
|
913 || NILP (w_right->vertical_scrollbar_visible_p)
|
|
914 || ZEROP (w_right->scrollbar_width))
|
|
915 #endif
|
|
916 );
|
|
917 }
|
|
918
|
|
919 static int
|
|
920 window_needs_vertical_divider_1 (struct window *w)
|
|
921 {
|
|
922 /* Never if we're on the right */
|
|
923 if (window_is_rightmost (w))
|
|
924 return 0;
|
|
925
|
|
926 /* Always if draggable */
|
|
927 if (!NILP (w->vertical_divider_always_visible_p))
|
|
928 return 1;
|
|
929
|
|
930 #ifdef HAVE_SCROLLBARS
|
|
931 /* Our right scrollbar is enough to separate us at the right */
|
|
932 if (NILP (w->scrollbar_on_left_p)
|
|
933 && !NILP (w->vertical_scrollbar_visible_p)
|
|
934 && !ZEROP (w->scrollbar_width))
|
|
935 return 0;
|
|
936 #endif
|
|
937
|
|
938 /* Ok. to determine whether we need a divider on the left, we must
|
|
939 check that our right neighbor windows have scrollbars on their
|
|
940 left sides. We must check all such windows which have common
|
|
941 left edge with our window's right edge. */
|
|
942 return map_windows (XFRAME (WINDOW_FRAME (w)),
|
|
943 have_undivided_common_edge, (void*)w);
|
|
944 }
|
|
945
|
|
946 int
|
|
947 window_needs_vertical_divider (struct window *w)
|
|
948 {
|
|
949 if (!w->need_vertical_divider_valid_p)
|
|
950 {
|
|
951 w->need_vertical_divider_p =
|
|
952 window_needs_vertical_divider_1 (w);
|
|
953 w->need_vertical_divider_valid_p = 1;
|
|
954 }
|
|
955 return w->need_vertical_divider_p;
|
|
956 }
|
|
957
|
|
958 /* Called from invalidate_vertical_divider_cache_in_frame */
|
|
959 int
|
|
960 invalidate_vertical_divider_cache_in_window (struct window *w,
|
|
961 void *u_n_u_s_e_d)
|
|
962 {
|
|
963 w->need_vertical_divider_valid_p = 0;
|
|
964 return 0;
|
|
965 }
|
|
966
|
|
967 /* Calculate width of vertical divider, including its shadows
|
|
968 and spacing. The returned value is effectively the distance
|
|
969 between adjacent window edges. This function does not check
|
|
970 whether a window needs a vertical divider, so the returned
|
|
971 value is a "theoretical" one */
|
|
972 int
|
|
973 window_divider_width (struct window *w)
|
|
974 {
|
|
975 /* the shadow thickness can be negative. This means that the divider
|
|
976 will have a depressed look */
|
|
977
|
|
978 if (FRAME_WIN_P (XFRAME (WINDOW_FRAME (w))))
|
|
979 return
|
|
980 XINT (w->vertical_divider_line_width)
|
|
981 + 2 * XINT (w->vertical_divider_spacing)
|
|
982 + 2 * abs (XINT (w->vertical_divider_shadow_thickness));
|
|
983 else
|
|
984 return XINT (w->vertical_divider_line_width) == 0 ? 0 : 1;
|
|
985 }
|
|
986
|
|
987 int
|
|
988 window_scrollbar_width (struct window *w)
|
|
989 {
|
|
990 #ifdef HAVE_SCROLLBARS
|
|
991 if (!WINDOW_WIN_P (w)
|
|
992 || MINI_WINDOW_P (w)
|
|
993 || NILP (w->buffer)
|
|
994 || NILP (w->vertical_scrollbar_visible_p))
|
|
995 /* #### when does NILP (w->buffer) happen? */
|
|
996 return 0;
|
|
997
|
|
998 return XINT (w->scrollbar_width);
|
|
999 #else
|
|
1000 return 0;
|
|
1001 #endif /* HAVE_SCROLLBARS */
|
|
1002 }
|
|
1003
|
|
1004 /* Horizontal scrollbars are only active on windows with truncation
|
|
1005 turned on. */
|
|
1006 int
|
|
1007 window_scrollbar_height (struct window *w)
|
|
1008 {
|
|
1009 #ifdef HAVE_SCROLLBARS
|
|
1010 if (!WINDOW_WIN_P (w)
|
|
1011 || MINI_WINDOW_P (w)
|
|
1012 || NILP (w->buffer)
|
|
1013 || NILP (w->horizontal_scrollbar_visible_p)
|
|
1014 || !window_truncation_on (w))
|
|
1015 return 0;
|
|
1016
|
|
1017 return XINT (w->scrollbar_height);
|
|
1018 #else
|
|
1019 return 0;
|
|
1020 #endif /* HAVE_SCROLLBARS */
|
|
1021 }
|
|
1022
|
|
1023 int
|
|
1024 window_modeline_height (struct window *w)
|
|
1025 {
|
|
1026 struct frame *f = XFRAME (w->frame);
|
|
1027 int modeline_height;
|
|
1028
|
|
1029 if (MINI_WINDOW_P (w) || NILP (w->buffer))
|
|
1030 {
|
|
1031 modeline_height = 0;
|
|
1032 }
|
|
1033 else if (!WINDOW_HAS_MODELINE_P (w))
|
|
1034 {
|
|
1035 if (window_scrollbar_height (w))
|
|
1036 modeline_height = 0;
|
|
1037 else
|
|
1038 {
|
|
1039 modeline_height = FRAMEMETH (f, divider_height, ());
|
|
1040
|
|
1041 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
1042 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
1043 }
|
|
1044 }
|
|
1045 else
|
|
1046 {
|
|
1047 if (noninteractive)
|
|
1048 modeline_height = 0;
|
|
1049 else
|
|
1050 {
|
|
1051 display_line_dynarr *dla;
|
|
1052
|
|
1053 /* We don't force a regeneration of the modeline here.
|
|
1054 Instead it is now a precondition that any function calling
|
|
1055 this should make sure that one of these structures is
|
|
1056 up-to-date. In practice this only affects two internal
|
|
1057 redisplay functions, regenerate_window and
|
|
1058 regenerate_window_point_center. */
|
|
1059 /* We check DESIRED_DISP because if it is valid it is more
|
|
1060 up-to-date than CURRENT_DISP. For calls to this outside
|
|
1061 of redisplay it doesn't matter which structure we check
|
|
1062 since there is a redisplay condition that these
|
|
1063 structures be identical outside of redisplay. */
|
|
1064 dla = window_display_lines (w, DESIRED_DISP);
|
|
1065 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
1066 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
1067 Dynarr_atp (dla, 0)->descent);
|
|
1068 else
|
|
1069 {
|
|
1070 dla = window_display_lines (w, CURRENT_DISP);
|
|
1071 if (dla && Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
1072 modeline_height = (Dynarr_atp (dla, 0)->ascent +
|
|
1073 Dynarr_atp (dla, 0)->descent);
|
|
1074 else
|
|
1075 /* This should be an abort except I'm not yet 100%
|
|
1076 confident that it won't ever get hit (though I
|
|
1077 haven't been able to trigger it). It is extremely
|
|
1078 unlikely to cause any noticeable problem and even if
|
|
1079 it does it will be a minor display glitch. */
|
|
1080 /* #### Bullshit alert. It does get hit and it causes
|
|
1081 noticeable glitches. real_current_modeline_height
|
|
1082 is a kludge to fix this for 19.14. */
|
|
1083 modeline_height = real_current_modeline_height (w);
|
|
1084 }
|
|
1085
|
|
1086 if (!EQ (Qzero, w->modeline_shadow_thickness) && FRAME_WIN_P (f))
|
|
1087 modeline_height += (2 * MODELINE_SHADOW_THICKNESS (w));
|
|
1088 }
|
|
1089 }
|
|
1090
|
|
1091 return modeline_height;
|
|
1092 }
|
|
1093
|
|
1094 /*****************************************************************************
|
|
1095 margin_width_internal
|
|
1096
|
|
1097 For a given window, return the width in pixels of the specified margin.
|
|
1098 ****************************************************************************/
|
|
1099 static int
|
|
1100 margin_width_internal (struct window *w, int left_margin)
|
|
1101 {
|
|
1102 struct buffer *b;
|
|
1103 int window_cwidth = window_char_width (w, 1);
|
|
1104 int margin_cwidth;
|
|
1105 int font_width;
|
|
1106 Lisp_Object window;
|
|
1107
|
|
1108 /* We might be getting called on a non-leaf. */
|
|
1109 if (NILP (w->buffer))
|
|
1110 return 0;
|
|
1111
|
|
1112 /* The minibuffer never has margins. */
|
|
1113 if (MINI_WINDOW_P (w))
|
|
1114 return 0;
|
|
1115
|
793
|
1116 window = wrap_window (w);
|
428
|
1117 b = XBUFFER (w->buffer);
|
|
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)
|
|
2922 && other_visible_frames (f))
|
|
2923 {
|
|
2924 /* Skip the other windows on this frame.
|
|
2925 There might be one, the minibuffer! */
|
|
2926 if (! EQ (w, last_window))
|
|
2927 while (f == XFRAME (WINDOW_FRAME
|
|
2928 (XWINDOW (next_window))))
|
|
2929 {
|
|
2930 /* As we go, check for the end of the
|
|
2931 loop. We mustn't start going
|
|
2932 around a second time. */
|
|
2933 if (EQ (next_window, last_window))
|
|
2934 {
|
|
2935 last_window = w;
|
|
2936 break;
|
|
2937 }
|
|
2938 next_window = Fnext_window (next_window,
|
|
2939 mini ? Qt : Qnil,
|
|
2940 frame_arg, Qt);
|
|
2941 }
|
|
2942 /* Now we can safely delete the frame. */
|
|
2943 Fdelete_frame (WINDOW_FRAME (p), Qnil);
|
|
2944 }
|
|
2945 else
|
|
2946 /* If we're deleting the buffer displayed in
|
|
2947 the only window on the frame, find a new
|
|
2948 buffer to display there. */
|
|
2949 if (NILP (p->parent))
|
|
2950 {
|
|
2951 Lisp_Object new_buffer;
|
|
2952 new_buffer = Fother_buffer (obj, Qnil, Qnil);
|
|
2953 if (NILP (new_buffer))
|
|
2954 new_buffer = Fget_buffer_create (QSscratch);
|
440
|
2955 Fset_window_buffer (w, new_buffer, Qnil);
|
428
|
2956 if (EQ (w, Fselected_window (Qnil)))
|
|
2957 Fset_buffer (p->buffer);
|
|
2958 }
|
|
2959 else
|
|
2960 Fdelete_window (w, Qnil);
|
|
2961 }
|
|
2962 break;
|
|
2963 }
|
|
2964
|
|
2965 case GET_LARGEST_WINDOW:
|
|
2966 {
|
|
2967 /* Ignore dedicated windows and minibuffers. */
|
|
2968 if (MINI_WINDOW_P (p)
|
|
2969 || (dedicated_too ? 0 : !NILP (p->dedicated)))
|
|
2970 break;
|
|
2971 {
|
|
2972 /* write the check as follows to avoid tripping
|
|
2973 error_check_window() --ben */
|
|
2974 struct window *b = NILP (best_window) ? 0 :
|
|
2975 XWINDOW (best_window);
|
|
2976 if (NILP (best_window)
|
|
2977 || ((WINDOW_HEIGHT (p) * WINDOW_WIDTH (p))
|
|
2978 > (WINDOW_HEIGHT (b) * WINDOW_WIDTH (b))))
|
|
2979 best_window = w;
|
|
2980 }
|
|
2981 break;
|
|
2982 }
|
|
2983
|
|
2984 default:
|
|
2985 abort ();
|
|
2986 }
|
|
2987
|
|
2988 if (EQ (w, last_window))
|
|
2989 break;
|
|
2990
|
|
2991 w = next_window;
|
|
2992 }
|
|
2993 }
|
|
2994
|
|
2995 return type == GET_BUFFER_WINDOW_COUNT ? make_int (count) : best_window;
|
|
2996 }
|
|
2997
|
|
2998 #if 0 /* not currently used */
|
|
2999
|
|
3000 int
|
|
3001 buffer_window_count (struct buffer *b, struct frame *f)
|
|
3002 {
|
|
3003 Lisp_Object buffer, frame;
|
|
3004
|
793
|
3005 frame = wrap_frame (f);
|
|
3006 buffer = wrap_buffer (b);
|
428
|
3007
|
|
3008 return XINT (window_loop (GET_BUFFER_WINDOW_COUNT, buffer, 0, frame, 1,
|
|
3009 Qnil));
|
|
3010 }
|
|
3011
|
|
3012 int
|
|
3013 buffer_window_mru (struct window *w)
|
|
3014 {
|
|
3015 Lisp_Object window =
|
|
3016 window_loop (GET_BUFFER_MRU_WINDOW, w->buffer, 0, w->frame, 1, Qnil);
|
|
3017
|
|
3018 if (NILP (window))
|
|
3019 return 0;
|
|
3020 else if (XWINDOW (window) == w)
|
|
3021 return 1;
|
|
3022 else
|
|
3023 return 0;
|
|
3024 }
|
|
3025
|
|
3026 #endif
|
|
3027
|
|
3028
|
|
3029 DEFUN ("get-lru-window", Fget_lru_window, 0, 2, 0, /*
|
|
3030 Return the window least recently selected or used for display.
|
444
|
3031
|
|
3032 By default, only the windows in the selected frame are considered.
|
|
3033 The optional argument WHICH-FRAMES changes this behavior:
|
|
3034 If optional argument WHICH-FRAMES is `visible', search all visible frames.
|
|
3035 If WHICH-FRAMES is 0, search all visible and iconified frames.
|
|
3036 If WHICH-FRAMES is t, search all frames.
|
|
3037 If WHICH-FRAMES is nil, search only the selected frame.
|
|
3038 If WHICH-FRAMES is a frame, search only that frame.
|
|
3039
|
|
3040 The optional argument WHICH-DEVICES further clarifies on which devices
|
|
3041 to search for frames as specified by WHICH-FRAMES. This value is only
|
|
3042 meaningful if WHICH-FRAMES is non-nil.
|
|
3043 If nil or omitted, search all devices on the selected console.
|
|
3044 If a device, only search that device.
|
|
3045 If a console, search all devices on that console.
|
|
3046 If a device type, search all devices of that type.
|
|
3047 If `window-system', search all devices on window-system consoles.
|
|
3048 Any other non-nil value means search all devices.
|
428
|
3049 */
|
444
|
3050 (which_frames, which_devices))
|
428
|
3051 {
|
|
3052 Lisp_Object w;
|
|
3053 /* First try for a non-dedicated window that is full-width */
|
444
|
3054 w = window_loop (GET_LRU_WINDOW, Qt, 0, which_frames, 0, which_devices);
|
428
|
3055 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
3056 return w;
|
|
3057
|
|
3058 /* Then try for any non-dedicated window */
|
444
|
3059 w = window_loop (GET_LRU_WINDOW, Qnil, 0, which_frames, 0, which_devices);
|
428
|
3060 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
3061 return w;
|
|
3062
|
|
3063 #if 0
|
|
3064 /* FSFmacs never returns a dedicated window here. If we do,
|
|
3065 it makes `display-buffer' not work right. #### All of this
|
|
3066 shit is so disgusting and awful that it needs to be rethought
|
|
3067 from scratch. */
|
|
3068 /* then try for a dedicated window that is full-width */
|
444
|
3069 w = window_loop (GET_LRU_WINDOW, Qt, 0, which_frames, 1, which_devices);
|
428
|
3070 if (!NILP (w) && !EQ (w, Fselected_window (Qnil)))
|
|
3071 return w;
|
|
3072
|
|
3073 /* If none of them, then all windows, dedicated or not. */
|
444
|
3074 w = window_loop (GET_LRU_WINDOW, Qnil, 0, which_frames, 1, which_devices);
|
428
|
3075
|
|
3076 /* At this point we damn well better have found something. */
|
|
3077 if (NILP (w)) abort ();
|
|
3078 #endif
|
|
3079
|
|
3080 return w;
|
|
3081 }
|
|
3082
|
|
3083 DEFUN ("get-largest-window", Fget_largest_window, 0, 2, 0, /*
|
|
3084 Return the window largest in area.
|
444
|
3085
|
|
3086 By default, only the windows in the selected frame are considered.
|
|
3087 The optional argument WHICH-FRAMES changes this behavior:
|
|
3088 If optional argument WHICH-FRAMES is `visible', search all visible frames.
|
|
3089 If WHICH-FRAMES is 0, search all visible and iconified frames.
|
|
3090 If WHICH-FRAMES is t, search all frames.
|
|
3091 If WHICH-FRAMES is nil, search only the selected frame.
|
|
3092 If WHICH-FRAMES is a frame, search only that frame.
|
|
3093
|
|
3094 The optional argument WHICH-DEVICES further clarifies on which devices
|
|
3095 to search for frames as specified by WHICH-FRAMES. This value is only
|
|
3096 meaningful if WHICH-FRAMES is non-nil.
|
|
3097 If nil or omitted, search all devices on the selected console.
|
|
3098 If a device, only search that device.
|
|
3099 If a console, search all devices on that console.
|
|
3100 If a device type, search all devices of that type.
|
|
3101 If `window-system', search all devices on window-system consoles.
|
|
3102 Any other non-nil value means search all devices.
|
428
|
3103 */
|
444
|
3104 (which_frames, which_devices))
|
428
|
3105 {
|
|
3106 /* Don't search dedicated windows because FSFmacs doesn't.
|
|
3107 This stuff is all black magic so don't try to apply common
|
|
3108 sense to it. */
|
444
|
3109 return window_loop (GET_LARGEST_WINDOW, Qnil, 0,
|
|
3110 which_frames, 0, which_devices);
|
428
|
3111 }
|
|
3112
|
|
3113 DEFUN ("get-buffer-window", Fget_buffer_window, 1, 3, 0, /*
|
|
3114 Return a window currently displaying BUFFER, or nil if none.
|
444
|
3115
|
|
3116 By default, only the windows in the selected frame are considered.
|
|
3117 The optional argument WHICH-FRAMES changes this behavior:
|
|
3118 If optional argument WHICH-FRAMES is `visible', search all visible frames.
|
|
3119 If WHICH-FRAMES is 0, search all visible and iconified frames.
|
|
3120 If WHICH-FRAMES is t, search all frames.
|
|
3121 If WHICH-FRAMES is nil, search only the selected frame.
|
|
3122 If WHICH-FRAMES is a frame, search only that frame.
|
|
3123
|
|
3124 The optional argument WHICH-DEVICES further clarifies on which devices
|
|
3125 to search for frames as specified by WHICH-FRAMES. This value is only
|
|
3126 meaningful if WHICH-FRAMES is non-nil.
|
|
3127 If nil or omitted, search all devices on the selected console.
|
|
3128 If a device, only search that device.
|
|
3129 If a console, search all devices on that console.
|
|
3130 If a device type, search all devices of that type.
|
|
3131 If `window-system', search all devices on window-system consoles.
|
|
3132 Any other non-nil value means search all devices.
|
428
|
3133 */
|
444
|
3134 (buffer, which_frames, which_devices))
|
428
|
3135 {
|
|
3136 buffer = Fget_buffer (buffer);
|
|
3137 if (BUFFERP (buffer))
|
|
3138 /* Search dedicated windows too. (Doesn't matter here anyway.) */
|
444
|
3139 return window_loop (GET_BUFFER_WINDOW, buffer, 1,
|
|
3140 which_frames, 1, which_devices);
|
428
|
3141 else
|
|
3142 return Qnil;
|
|
3143 }
|
|
3144
|
|
3145 /* These functions used to be `buffer-left-margin-pixel-width', etc.
|
|
3146 but there is no sensible way to implement those functions, since
|
|
3147 you can't in general derive a window from a buffer. */
|
|
3148
|
|
3149 DEFUN ("window-left-margin-pixel-width", Fwindow_left_margin_pixel_width,
|
|
3150 0, 1, 0, /*
|
|
3151 Return the width in pixels of the left outside margin of window WINDOW.
|
|
3152 If WINDOW is nil, the selected window is assumed.
|
|
3153 */
|
|
3154 (window))
|
|
3155 {
|
|
3156 return make_int (window_left_margin_width (decode_window (window)));
|
|
3157 }
|
|
3158
|
|
3159 DEFUN ("window-right-margin-pixel-width", Fwindow_right_margin_pixel_width,
|
|
3160 0, 1, 0, /*
|
|
3161 Return the width in pixels of the right outside margin of window WINDOW.
|
|
3162 If WINDOW is nil, the selected window is assumed.
|
|
3163 */
|
|
3164 (window))
|
|
3165 {
|
|
3166 return make_int (window_right_margin_width (decode_window (window)));
|
|
3167 }
|
|
3168
|
|
3169 DEFUN ("delete-other-windows", Fdelete_other_windows, 0, 1, "", /*
|
|
3170 Make WINDOW (or the selected window) fill its frame.
|
|
3171 Only the frame WINDOW is on is affected.
|
|
3172 This function tries to reduce display jumps
|
|
3173 by keeping the text previously visible in WINDOW
|
|
3174 in the same place on the frame. Doing this depends on
|
|
3175 the value of (window-start WINDOW), so if calling this function
|
|
3176 in a program gives strange scrolling, make sure the window-start
|
|
3177 value is reasonable when this function is called.
|
|
3178 */
|
|
3179 (window))
|
|
3180 {
|
|
3181 struct window *w = decode_window (window);
|
1207
|
3182 struct buffer *b;
|
665
|
3183 Charbpos start_pos;
|
428
|
3184 int old_top = WINDOW_TOP (w);
|
|
3185
|
1207
|
3186 if (NILP (WINDOW_BUFFER (w)))
|
|
3187 invalid_operation ("Can't delete other windows of combination", window);
|
|
3188
|
793
|
3189 window = wrap_window (w);
|
1207
|
3190 b = XBUFFER (WINDOW_BUFFER (w));
|
428
|
3191
|
|
3192 if (MINI_WINDOW_P (w) && old_top > 0)
|
563
|
3193 invalid_operation ("Can't expand minibuffer to full frame", Qunbound);
|
428
|
3194
|
|
3195 /* Ignore dedicated windows. */
|
|
3196 window_loop (DELETE_OTHER_WINDOWS, window, 0, w->frame, 0, Qnil);
|
|
3197
|
|
3198 start_pos = marker_position (w->start[CURRENT_DISP]);
|
|
3199
|
|
3200 /* Try to minimize scrolling, by setting the window start to the
|
|
3201 point which will cause the text at the old window start to be at
|
|
3202 the same place on the frame. But don't try to do this if the
|
|
3203 window start is outside the visible portion (as might happen when
|
|
3204 the display is not current, due to typeahead). */
|
|
3205 if (start_pos >= BUF_BEGV (b) && start_pos <= BUF_ZV (b)
|
|
3206 && !MINI_WINDOW_P (w))
|
|
3207 {
|
665
|
3208 Charbpos new_start = start_with_line_at_pixpos (w, start_pos, old_top);
|
428
|
3209
|
|
3210 if (new_start >= BUF_BEGV (b) && new_start <= BUF_ZV (b))
|
|
3211 {
|
|
3212 Fset_marker (w->start[CURRENT_DISP], make_int (new_start),
|
|
3213 w->buffer);
|
|
3214 w->start_at_line_beg = beginning_of_line_p (b, new_start);
|
|
3215 }
|
|
3216 /* We need to do this, so that the window-scroll-functions
|
|
3217 get called. */
|
|
3218 w->force_start = 1;
|
|
3219 }
|
|
3220
|
|
3221 return Qnil;
|
|
3222 }
|
|
3223
|
|
3224 DEFUN ("delete-windows-on", Fdelete_windows_on, 1, 3,
|
|
3225 "bDelete windows on (buffer): ", /*
|
|
3226 Delete all windows showing BUFFER.
|
444
|
3227
|
|
3228 Optional second argument WHICH-FRAMES controls which frames are affected.
|
428
|
3229 If nil or omitted, delete all windows showing BUFFER in any frame.
|
|
3230 If t, delete only windows showing BUFFER in the selected frame.
|
|
3231 If `visible', delete all windows showing BUFFER in any visible frame.
|
|
3232 If a frame, delete only windows showing BUFFER in that frame.
|
444
|
3233 Warning: WHICH-FRAMES has the same meaning as with `next-window',
|
|
3234 except that the meanings of nil and t are reversed.
|
|
3235
|
|
3236 The optional third argument WHICH-DEVICES further clarifies on which
|
|
3237 devices to search for frames as specified by WHICH-FRAMES. This value
|
|
3238 is only meaningful if WHICH-FRAMES is not t.
|
|
3239 If nil or omitted, search only the selected console.
|
|
3240 If a device, only search that device.
|
|
3241 If a console, search all devices on that console.
|
|
3242 If a device type, search all devices of that type.
|
|
3243 If `window-system', search all devices on a window system.
|
|
3244 Any other non-nil value means search all devices.
|
428
|
3245 */
|
444
|
3246 (buffer, which_frames, which_devices))
|
428
|
3247 {
|
|
3248 /* This function can GC */
|
444
|
3249 buffer = Fget_buffer (buffer);
|
|
3250 CHECK_BUFFER (buffer);
|
|
3251
|
|
3252 /* WHICH-FRAMES values t and nil mean the opposite of what
|
|
3253 window_loop expects. */
|
|
3254 if (EQ (which_frames, Qnil))
|
|
3255 which_frames = Qt;
|
|
3256 else if (EQ (which_frames, Qt))
|
|
3257 which_frames = Qnil;
|
|
3258
|
|
3259 /* Ignore dedicated windows. */
|
|
3260 window_loop (DELETE_BUFFER_WINDOWS, buffer, 0,
|
|
3261 which_frames, 0, which_devices);
|
428
|
3262 return Qnil;
|
|
3263 }
|
|
3264
|
448
|
3265 static Lisp_Object
|
|
3266 list_windows (struct window *w, Lisp_Object value)
|
|
3267 {
|
|
3268 for (;;)
|
|
3269 {
|
|
3270 if (!NILP (w->hchild))
|
|
3271 value = list_windows (XWINDOW (w->hchild), value);
|
|
3272 else if (!NILP (w->vchild))
|
|
3273 value = list_windows (XWINDOW (w->vchild), value);
|
|
3274 else
|
|
3275 {
|
793
|
3276 Lisp_Object window = wrap_window (w);
|
|
3277
|
448
|
3278 value = Fcons (window, value);
|
|
3279 }
|
|
3280 if (NILP (w->next))
|
|
3281 break;
|
|
3282 w = XWINDOW (w->next);
|
|
3283 }
|
|
3284 return value;
|
|
3285 }
|
|
3286
|
|
3287 static Lisp_Object
|
|
3288 list_all_windows (Lisp_Object frame_spec, Lisp_Object device_spec)
|
|
3289 {
|
|
3290 Lisp_Object devcons, concons;
|
|
3291 Lisp_Object retval = Qnil;
|
|
3292
|
|
3293 DEVICE_LOOP_NO_BREAK (devcons, concons)
|
|
3294 {
|
|
3295 Lisp_Object frame_list, the_window;
|
|
3296 Lisp_Object device, tail;
|
|
3297
|
|
3298 device = XCAR (devcons);
|
|
3299 frame_list = DEVICE_FRAME_LIST (XDEVICE (device));
|
|
3300
|
|
3301 LIST_LOOP (tail, frame_list)
|
|
3302 {
|
|
3303 if ((NILP (frame_spec)
|
|
3304 && !EQ (XCAR (tail), DEVICE_SELECTED_FRAME (XDEVICE (device))))
|
|
3305 || (EQ (frame_spec, Qvisible)
|
|
3306 && !FRAME_VISIBLE_P (XFRAME (XCAR (tail))))
|
|
3307 || (FRAMEP (frame_spec)
|
|
3308 && !EQ (frame_spec, XCAR (tail)))
|
|
3309 || (!NILP (frame_spec)
|
|
3310 && !device_matches_device_spec (device,
|
|
3311 NILP (device_spec) ?
|
|
3312 Vselected_console :
|
|
3313 device_spec)))
|
|
3314 continue;
|
|
3315 the_window = FRAME_ROOT_WINDOW (XFRAME (XCAR (tail)));
|
|
3316 retval = list_windows (XWINDOW (the_window), retval);
|
|
3317 }
|
|
3318 }
|
|
3319 return Fnreverse (retval);
|
|
3320 }
|
|
3321
|
444
|
3322 DEFUN ("replace-buffer-in-windows", Freplace_buffer_in_windows, 1, 3,
|
428
|
3323 "bReplace buffer in windows: ", /*
|
|
3324 Replace BUFFER with some other buffer in all windows showing it.
|
444
|
3325
|
|
3326 Optional second argument WHICH-FRAMES controls which frames are affected.
|
|
3327 If nil or omitted, all frames are affected.
|
|
3328 If t, only the selected frame is affected.
|
|
3329 If `visible', all visible frames are affected.
|
|
3330 If a frame, only that frame is affected.
|
|
3331 Warning: WHICH-FRAMES has the same meaning as with `next-window',
|
|
3332 except that the meanings of nil and t are reversed.
|
|
3333
|
|
3334 The optional third argument WHICH-DEVICES further clarifies on which
|
|
3335 devices to search for frames as specified by WHICH-FRAMES. This value
|
|
3336 is only meaningful if WHICH-FRAMES is not t.
|
|
3337 If nil or omitted, search only the selected console.
|
|
3338 If a device, only search that device.
|
|
3339 If a console, search all devices on that console.
|
|
3340 If a device type, search all devices of that type.
|
|
3341 If `window-system', search all devices on a window system.
|
|
3342 Any other non-nil value means search all devices.
|
428
|
3343 */
|
444
|
3344 (buffer, which_frames, which_devices))
|
428
|
3345 {
|
|
3346 /* This function can GC */
|
448
|
3347 Lisp_Object window_list;
|
|
3348 Lisp_Object tail;
|
|
3349 struct gcpro gcpro1, gcpro2;
|
|
3350
|
444
|
3351 if (EQ (which_frames, Qnil))
|
|
3352 which_frames = Qt;
|
|
3353 else if (EQ (which_frames, Qt))
|
|
3354 which_frames = Qnil;
|
448
|
3355 window_list = list_all_windows (which_frames, which_devices);
|
|
3356
|
|
3357 buffer = Fget_buffer (buffer);
|
|
3358 CHECK_BUFFER (buffer);
|
|
3359
|
|
3360 GCPRO2 (window_list, buffer);
|
|
3361 LIST_LOOP (tail, window_list)
|
|
3362 {
|
|
3363 Lisp_Object window = XCAR (tail);
|
|
3364 if (!MINI_WINDOW_P (XWINDOW (window))
|
|
3365 && EQ (XWINDOW (window)->buffer, buffer))
|
|
3366 {
|
|
3367 Lisp_Object another_buffer = Fother_buffer (buffer, Qnil, Qnil);
|
|
3368 Lisp_Object frame = WINDOW_FRAME (XWINDOW (window));
|
|
3369 if (NILP (another_buffer))
|
|
3370 another_buffer = Fget_buffer_create (QSscratch);
|
|
3371 if (!NILP (XWINDOW (window)->dedicated)
|
|
3372 && EQ (window,
|
|
3373 FRAME_ROOT_WINDOW (XFRAME (frame)))
|
|
3374 && other_visible_frames (XFRAME (frame)))
|
|
3375 {
|
|
3376 delete_frame_internal (XFRAME (frame), 0, 0, 0); /* GC */
|
|
3377 }
|
|
3378 else
|
|
3379 {
|
|
3380 Fset_window_buffer (window, another_buffer, Qnil);
|
|
3381 if (EQ (window, Fselected_window (Qnil)))
|
|
3382 Fset_buffer (XWINDOW (window)->buffer);
|
|
3383 }
|
|
3384 }
|
|
3385 }
|
|
3386 UNGCPRO;
|
428
|
3387 return Qnil;
|
|
3388 }
|
|
3389
|
|
3390 /* The smallest acceptable dimensions for a window. Anything smaller
|
|
3391 might crash Emacs. */
|
|
3392 #define MIN_SAFE_WINDOW_WIDTH (2)
|
|
3393 #define MIN_SAFE_WINDOW_HEIGHT (2)
|
|
3394
|
|
3395 /* Make sure that window_min_height and window_min_width are
|
|
3396 not too small; if they are, set them to safe minima. */
|
|
3397
|
|
3398 static void
|
|
3399 check_min_window_sizes (void)
|
|
3400 {
|
|
3401 /* Smaller values might permit a crash. */
|
|
3402 if (window_min_width < MIN_SAFE_WINDOW_WIDTH)
|
|
3403 window_min_width = MIN_SAFE_WINDOW_WIDTH;
|
|
3404 if (window_min_height < MIN_SAFE_WINDOW_HEIGHT)
|
|
3405 window_min_height = MIN_SAFE_WINDOW_HEIGHT;
|
|
3406 }
|
|
3407
|
440
|
3408 static int
|
|
3409 frame_min_height (struct frame *frame)
|
|
3410 {
|
|
3411 /* For height, we have to see whether the frame has a minibuffer, and
|
|
3412 whether it wants a modeline. */
|
|
3413 return (FRAME_MINIBUF_ONLY_P (frame) ? MIN_SAFE_WINDOW_HEIGHT - 1
|
|
3414 : (! FRAME_HAS_MINIBUF_P (frame)) ? MIN_SAFE_WINDOW_HEIGHT
|
|
3415 : 2 * MIN_SAFE_WINDOW_HEIGHT - 1);
|
|
3416 }
|
|
3417
|
|
3418 /* Return non-zero if both frame sizes are less than or equal to
|
|
3419 minimal allowed values. ROWS and COLS are in characters */
|
|
3420 int
|
|
3421 frame_size_valid_p (struct frame *frame, int rows, int cols)
|
|
3422 {
|
|
3423 return (rows >= frame_min_height (frame)
|
|
3424 && cols >= MIN_SAFE_WINDOW_WIDTH);
|
|
3425 }
|
|
3426
|
|
3427 /* Return non-zero if both frame sizes are less than or equal to
|
|
3428 minimal allowed values. WIDTH and HEIGHT are in pixels */
|
|
3429 int
|
|
3430 frame_pixsize_valid_p (struct frame *frame, int width, int height)
|
|
3431 {
|
|
3432 int rows, cols;
|
|
3433 pixel_to_real_char_size (frame, width, height, &cols, &rows);
|
|
3434 return frame_size_valid_p (frame, rows, cols);
|
|
3435 }
|
|
3436
|
428
|
3437 /* If *ROWS or *COLS are too small a size for FRAME, set them to the
|
|
3438 minimum allowable size. */
|
|
3439 void
|
|
3440 check_frame_size (struct frame *frame, int *rows, int *cols)
|
|
3441 {
|
440
|
3442 int min_height = frame_min_height (frame);
|
428
|
3443
|
|
3444 if (*rows < min_height)
|
|
3445 *rows = min_height;
|
|
3446 if (*cols < MIN_SAFE_WINDOW_WIDTH)
|
|
3447 *cols = MIN_SAFE_WINDOW_WIDTH;
|
|
3448 }
|
|
3449
|
|
3450 /* Normally the window is deleted if it gets too small.
|
|
3451 nodelete nonzero means do not do this.
|
|
3452 (The caller should check later and do so if appropriate) */
|
|
3453 static void
|
|
3454 set_window_pixsize (Lisp_Object window, int new_pixsize, int nodelete,
|
|
3455 int set_height)
|
|
3456 {
|
|
3457 struct window *w = XWINDOW (window);
|
|
3458 struct frame *f = XFRAME (w->frame);
|
|
3459 struct window *c;
|
|
3460 int old_pixsize = (set_height ? WINDOW_HEIGHT (w) : WINDOW_WIDTH (w));
|
|
3461 Lisp_Object child, minor_kid, major_kid;
|
|
3462 int minsize;
|
|
3463 int line_size;
|
|
3464 int defheight, defwidth;
|
|
3465
|
|
3466 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
3467 functions should be called. */
|
|
3468 default_face_height_and_width (window, &defheight, &defwidth);
|
|
3469 line_size = (set_height ? defheight : defwidth);
|
|
3470
|
|
3471 check_min_window_sizes ();
|
|
3472
|
|
3473 minsize = (set_height ? window_min_height : window_min_width);
|
|
3474 minsize *= line_size;
|
|
3475
|
|
3476 if (!nodelete
|
|
3477 && !TOP_LEVEL_WINDOW_P (w)
|
|
3478 && new_pixsize < minsize)
|
|
3479 {
|
|
3480 Fdelete_window (window, Qnil);
|
|
3481 return;
|
|
3482 }
|
|
3483
|
|
3484 SET_LAST_MODIFIED (w, 0);
|
|
3485 SET_LAST_FACECHANGE (w);
|
|
3486 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f); /* multiple windows affected */
|
|
3487 if (set_height)
|
|
3488 {
|
|
3489 WINDOW_HEIGHT (w) = new_pixsize;
|
|
3490 major_kid = w->vchild;
|
|
3491 minor_kid = w->hchild;
|
|
3492 }
|
|
3493 else
|
|
3494 {
|
|
3495 WINDOW_WIDTH (w) = new_pixsize;
|
|
3496 major_kid = w->hchild;
|
|
3497 minor_kid = w->vchild;
|
|
3498 }
|
|
3499
|
|
3500 if (!NILP (minor_kid))
|
|
3501 {
|
|
3502 for (child = minor_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
3503 {
|
|
3504 if (set_height)
|
|
3505 WINDOW_TOP (XWINDOW (child)) = WINDOW_TOP (w);
|
|
3506 else
|
|
3507 WINDOW_LEFT (XWINDOW (child)) = WINDOW_LEFT (w);
|
|
3508
|
|
3509 set_window_pixsize (child, new_pixsize, nodelete, set_height);
|
|
3510 }
|
|
3511 }
|
|
3512 else if (!NILP (major_kid))
|
|
3513 {
|
|
3514 int last_pos, last_old_pos, pos, old_pos, first;
|
|
3515 int pixel_adj_left = new_pixsize - old_pixsize;
|
|
3516 int div_val = old_pixsize << 1;
|
|
3517
|
|
3518 /*
|
|
3519 * Previously we bailed out here if there was no size change.
|
|
3520 * (pixel_adj_left == 0) But this broke toolbar updates. If a
|
|
3521 * toolbar appears or disappears, windows may not change size,
|
|
3522 * but their top and left coordinates need to be updated.
|
|
3523 *
|
|
3524 * So we don't bail until after the loop below.
|
|
3525 */
|
|
3526
|
|
3527 last_pos = first = (set_height ? WINDOW_TOP (w) : WINDOW_LEFT (w));
|
|
3528 last_old_pos = 0;
|
|
3529
|
|
3530 for (child = major_kid; !NILP (child); child = c->next)
|
|
3531 {
|
|
3532 c = XWINDOW (child);
|
|
3533
|
|
3534 if (set_height)
|
|
3535 {
|
|
3536 old_pos = last_old_pos + WINDOW_HEIGHT (c);
|
|
3537 WINDOW_TOP (c) = last_pos;
|
|
3538 }
|
|
3539 else
|
|
3540 {
|
|
3541 old_pos = last_old_pos + WINDOW_WIDTH (c);
|
|
3542 WINDOW_LEFT (c) = last_pos;
|
|
3543 }
|
|
3544
|
|
3545 pos = (((old_pos * new_pixsize) << 1) + old_pixsize) / div_val;
|
|
3546 /* All but the last window should have a height which is
|
|
3547 a multiple of the default line height. */
|
|
3548 if (!NILP (c->next))
|
|
3549 pos = (pos / line_size) * line_size;
|
|
3550
|
|
3551 /* Avoid confusion: don't delete child if it becomes too small */
|
|
3552 set_window_pixsize (child, pos + first - last_pos, 1, set_height);
|
|
3553
|
|
3554 last_pos = pos + first;
|
|
3555 last_old_pos = old_pos;
|
|
3556 }
|
|
3557
|
|
3558 /* Sometimes we may get called with our old size. In that case
|
|
3559 we don't need to do anything else. */
|
|
3560 if (!pixel_adj_left)
|
|
3561 return;
|
|
3562
|
|
3563 /* Now delete any children that became too small. */
|
|
3564 if (!nodelete)
|
|
3565 for (child = major_kid; !NILP (child); child = XWINDOW (child)->next)
|
|
3566 {
|
|
3567 if (set_height)
|
|
3568 set_window_pixheight (child, WINDOW_HEIGHT (XWINDOW (child)), 0);
|
|
3569 else
|
|
3570 set_window_pixwidth (child, WINDOW_WIDTH (XWINDOW (child)), 0);
|
|
3571 }
|
|
3572 }
|
|
3573 }
|
|
3574
|
|
3575 /* Set the height of WINDOW and all its inferiors. */
|
|
3576 void
|
|
3577 set_window_pixheight (Lisp_Object window, int new_pixheight, int nodelete)
|
|
3578 {
|
|
3579 set_window_pixsize (window, new_pixheight, nodelete, 1);
|
|
3580 }
|
|
3581
|
|
3582 /* Recursively set width of WINDOW and its inferiors. */
|
|
3583 void
|
|
3584 set_window_pixwidth (Lisp_Object window, int new_pixwidth, int nodelete)
|
|
3585 {
|
|
3586 set_window_pixsize (window, new_pixwidth, nodelete, 0);
|
|
3587 }
|
|
3588
|
|
3589
|
|
3590 static int window_select_count;
|
|
3591
|
440
|
3592 DEFUN ("set-window-buffer", Fset_window_buffer, 2, 3, 0, /*
|
428
|
3593 Make WINDOW display BUFFER as its contents.
|
|
3594 BUFFER can be a buffer or buffer name.
|
440
|
3595
|
442
|
3596 With non-nil optional argument NORECORD, do not modify the
|
440
|
3597 global or per-frame buffer ordering.
|
428
|
3598 */
|
440
|
3599 (window, buffer, norecord))
|
428
|
3600 {
|
|
3601 Lisp_Object tem;
|
|
3602 struct window *w = decode_window (window);
|
448
|
3603 int old_buffer_local_face_property = 0;
|
428
|
3604
|
|
3605 buffer = Fget_buffer (buffer);
|
|
3606 CHECK_BUFFER (buffer);
|
|
3607
|
|
3608 if (!BUFFER_LIVE_P (XBUFFER (buffer)))
|
563
|
3609 invalid_operation ("Attempt to display deleted buffer", Qunbound);
|
428
|
3610
|
|
3611 tem = w->buffer;
|
|
3612 if (NILP (tem))
|
563
|
3613 invalid_operation ("Window is deleted", Qunbound);
|
428
|
3614 else if (EQ (tem, buffer))
|
|
3615 return Qnil;
|
|
3616 else if (! EQ (tem, Qt)) /* w->buffer is t when the window
|
|
3617 is first being set up. */
|
|
3618 {
|
|
3619 if (!NILP (w->dedicated) && !EQ (tem, buffer))
|
563
|
3620 signal_error (Qinvalid_operation, "Window is dedicated to buffer", tem);
|
428
|
3621
|
448
|
3622 old_buffer_local_face_property =
|
|
3623 XBUFFER (w->buffer)->buffer_local_face_property;
|
428
|
3624 unshow_buffer (w);
|
|
3625 }
|
|
3626
|
|
3627 w->buffer = buffer;
|
|
3628 w->window_end_pos[CURRENT_DISP] = 0;
|
|
3629 w->hscroll = 0;
|
|
3630 w->modeline_hscroll = 0;
|
844
|
3631 #if 0 /* pre point caches */
|
428
|
3632 Fset_marker (w->pointm[CURRENT_DISP],
|
|
3633 make_int (BUF_PT (XBUFFER (buffer))),
|
|
3634 buffer);
|
|
3635 set_marker_restricted (w->start[CURRENT_DISP],
|
|
3636 make_int (XBUFFER (buffer)->last_window_start),
|
|
3637 buffer);
|
844
|
3638 #else
|
|
3639 {
|
|
3640 Lisp_Object marker = Fgethash (buffer, w->saved_point_cache, Qnil);
|
|
3641 Lisp_Object newpoint =
|
|
3642 !NILP (marker) ? make_int (marker_position (marker)) :
|
|
3643 make_int (BUF_PT (XBUFFER (buffer)));
|
|
3644 /* Previously, we had in here set-window-point, which did one of the
|
|
3645 following two, but not both. However, that could result in pointm
|
|
3646 being in a different buffer from the window's buffer! Probably
|
|
3647 not a travesty since it always occurred when the window was
|
|
3648 selected, meaning its value of point was ignored in favor of the
|
|
3649 buffer's; but it tripped an assert() in unshow_buffer(). */
|
|
3650 set_marker_restricted (w->pointm[CURRENT_DISP], newpoint, buffer);
|
|
3651 if (EQ (wrap_window (w), Fselected_window (Qnil)))
|
|
3652 Fgoto_char (newpoint, buffer); /* this will automatically clip to
|
|
3653 accessible */
|
|
3654 marker = Fgethash (buffer, w->saved_last_window_start_cache, Qnil);
|
|
3655 set_marker_restricted (w->start[CURRENT_DISP],
|
|
3656 !NILP (marker) ?
|
|
3657 make_int (marker_position (marker)) :
|
|
3658 make_int (XBUFFER (buffer)->last_window_start),
|
|
3659 buffer);
|
|
3660 }
|
|
3661 #endif
|
|
3662
|
428
|
3663 Fset_marker (w->sb_point, w->start[CURRENT_DISP], buffer);
|
|
3664 /* set start_at_line_beg correctly. GE */
|
844
|
3665 w->start_at_line_beg =
|
|
3666 beginning_of_line_p (XBUFFER (buffer),
|
|
3667 marker_position (w->start[CURRENT_DISP]));
|
|
3668 w->force_start = 0; /* XEmacs fix */
|
428
|
3669 SET_LAST_MODIFIED (w, 1);
|
|
3670 SET_LAST_FACECHANGE (w);
|
|
3671 MARK_WINDOWS_CHANGED (w);
|
448
|
3672 {
|
|
3673 int new_buffer_local_face_property =
|
|
3674 XBUFFER (w->buffer)->buffer_local_face_property;
|
|
3675
|
|
3676 if (new_buffer_local_face_property
|
|
3677 || new_buffer_local_face_property != old_buffer_local_face_property)
|
|
3678 MARK_WINDOW_FACES_CHANGED (w);
|
|
3679 }
|
428
|
3680 recompute_all_cached_specifiers_in_window (w);
|
|
3681 if (EQ (window, Fselected_window (Qnil)))
|
|
3682 {
|
440
|
3683 if (NILP (norecord))
|
|
3684 Frecord_buffer (buffer);
|
|
3685
|
428
|
3686 Fset_buffer (buffer);
|
|
3687 }
|
|
3688 return Qnil;
|
|
3689 }
|
|
3690
|
|
3691 DEFUN ("select-window", Fselect_window, 1, 2, 0, /*
|
|
3692 Select WINDOW. Most editing will apply to WINDOW's buffer.
|
|
3693 The main editor command loop selects the buffer of the selected window
|
|
3694 before each command.
|
|
3695
|
442
|
3696 With non-nil optional argument NORECORD, do not modify the
|
428
|
3697 global or per-frame buffer ordering.
|
|
3698 */
|
|
3699 (window, norecord))
|
|
3700 {
|
|
3701 struct window *w;
|
|
3702 Lisp_Object old_selected_window = Fselected_window (Qnil);
|
|
3703
|
|
3704 CHECK_LIVE_WINDOW (window);
|
|
3705 w = XWINDOW (window);
|
|
3706
|
|
3707 /* we have already caught dead-window errors */
|
|
3708 if (!NILP (w->hchild) || !NILP (w->vchild))
|
563
|
3709 invalid_operation ("Trying to select non-leaf window", Qunbound);
|
428
|
3710
|
|
3711 w->use_time = make_int (++window_select_count);
|
442
|
3712
|
428
|
3713 if (EQ (window, old_selected_window))
|
|
3714 return window;
|
|
3715
|
|
3716 /* deselect the old window, if it exists (it might not exist if
|
|
3717 the selected device has no frames, which occurs at startup) */
|
|
3718 if (!NILP (old_selected_window))
|
|
3719 {
|
|
3720 struct window *ow = XWINDOW (old_selected_window);
|
|
3721
|
|
3722 Fset_marker (ow->pointm[CURRENT_DISP],
|
|
3723 make_int (BUF_PT (XBUFFER (ow->buffer))),
|
|
3724 ow->buffer);
|
|
3725
|
|
3726 MARK_WINDOWS_CHANGED (ow);
|
|
3727 }
|
|
3728
|
|
3729 /* now select the window's frame */
|
|
3730 set_frame_selected_window (XFRAME (WINDOW_FRAME (w)), window);
|
|
3731
|
|
3732 select_frame_1 (WINDOW_FRAME (w));
|
|
3733
|
|
3734 /* also select the window's buffer */
|
|
3735 if (NILP (norecord))
|
|
3736 Frecord_buffer (w->buffer);
|
|
3737 Fset_buffer (w->buffer);
|
|
3738
|
|
3739 /* Go to the point recorded in the window.
|
|
3740 This is important when the buffer is in more
|
|
3741 than one window. It also matters when
|
|
3742 redisplay_window has altered point after scrolling,
|
|
3743 because it makes the change only in the window. */
|
|
3744 {
|
665
|
3745 Charbpos new_point = marker_position (w->pointm[CURRENT_DISP]);
|
428
|
3746 if (new_point < BUF_BEGV (current_buffer))
|
|
3747 new_point = BUF_BEGV (current_buffer);
|
|
3748 else if (new_point > BUF_ZV (current_buffer))
|
|
3749 new_point = BUF_ZV (current_buffer);
|
|
3750
|
|
3751 BUF_SET_PT (current_buffer, new_point);
|
|
3752 }
|
|
3753
|
|
3754 MARK_WINDOWS_CHANGED (w);
|
|
3755
|
|
3756 return window;
|
|
3757 }
|
|
3758
|
|
3759 Lisp_Object
|
|
3760 display_buffer (Lisp_Object buffer, Lisp_Object not_this_window_p,
|
|
3761 Lisp_Object override_frame)
|
|
3762 {
|
|
3763 return call3 (Qdisplay_buffer, buffer, not_this_window_p, override_frame);
|
|
3764 }
|
|
3765
|
|
3766 void
|
|
3767 temp_output_buffer_show (Lisp_Object buf, Lisp_Object same_frame)
|
|
3768 {
|
|
3769 /* This function can GC */
|
|
3770 Lisp_Object window;
|
|
3771 struct window *w;
|
|
3772 struct buffer *b = XBUFFER (buf);
|
|
3773
|
|
3774 BUF_SAVE_MODIFF (XBUFFER (buf)) = BUF_MODIFF (b);
|
|
3775 widen_buffer (b, 0);
|
|
3776 BUF_SET_PT (b, BUF_BEG (b));
|
|
3777
|
|
3778 if (!NILP (Vtemp_buffer_show_function))
|
|
3779 call1 (Vtemp_buffer_show_function, buf);
|
|
3780 else
|
|
3781 {
|
|
3782 window = display_buffer (buf, Qnil, same_frame);
|
|
3783
|
|
3784 if (!EQ (XWINDOW (window)->frame, Fselected_frame (Qnil)))
|
|
3785 Fmake_frame_visible (WINDOW_FRAME (XWINDOW (window)));
|
|
3786
|
|
3787 Vminibuffer_scroll_window = window;
|
|
3788 w = XWINDOW (window);
|
|
3789 w->hscroll = 0;
|
|
3790 w->modeline_hscroll = 0;
|
|
3791 set_marker_restricted (w->start[CURRENT_DISP], make_int (1), buf);
|
|
3792 set_marker_restricted (w->pointm[CURRENT_DISP], make_int (1), buf);
|
|
3793 set_marker_restricted (w->sb_point, make_int (1), buf);
|
|
3794 }
|
|
3795 }
|
|
3796
|
|
3797 static void
|
|
3798 make_dummy_parent (Lisp_Object window)
|
|
3799 {
|
|
3800 Lisp_Object new;
|
|
3801 struct window *o = XWINDOW (window);
|
|
3802 struct window *p = alloc_lcrecord_type (struct window, &lrecord_window);
|
|
3803
|
793
|
3804 new = wrap_window (p);
|
428
|
3805 copy_lcrecord (p, o);
|
|
3806
|
|
3807 /* Don't copy the pointers to the line start cache or the face
|
|
3808 instances. */
|
|
3809 p->line_start_cache = Dynarr_new (line_start_cache);
|
|
3810 p->face_cachels = Dynarr_new (face_cachel);
|
|
3811 p->glyph_cachels = Dynarr_new (glyph_cachel);
|
442
|
3812 p->subwindow_instance_cache =
|
450
|
3813 make_image_instance_cache_hash_table ();
|
428
|
3814
|
|
3815 /* Put new into window structure in place of window */
|
|
3816 replace_window (window, new);
|
|
3817
|
|
3818 o->next = Qnil;
|
|
3819 o->prev = Qnil;
|
|
3820 o->vchild = Qnil;
|
|
3821 o->hchild = Qnil;
|
|
3822 o->parent = new;
|
|
3823
|
|
3824 p->start[CURRENT_DISP] = Qnil;
|
|
3825 p->start[DESIRED_DISP] = Qnil;
|
|
3826 p->start[CMOTION_DISP] = Qnil;
|
|
3827 p->pointm[CURRENT_DISP] = Qnil;
|
|
3828 p->pointm[DESIRED_DISP] = Qnil;
|
|
3829 p->pointm[CMOTION_DISP] = Qnil;
|
|
3830 p->sb_point = Qnil;
|
844
|
3831 p->saved_point_cache = make_saved_buffer_point_cache ();
|
|
3832 p->saved_last_window_start_cache = make_saved_buffer_point_cache ();
|
428
|
3833 p->buffer = Qnil;
|
|
3834 }
|
|
3835
|
|
3836 DEFUN ("split-window", Fsplit_window, 0, 3, "", /*
|
|
3837 Split WINDOW, putting SIZE lines in the first of the pair.
|
444
|
3838 WINDOW defaults to the selected one and SIZE to half its size.
|
707
|
3839 If optional third arg HORFLAG is non-nil, split side by side and put
|
|
3840 SIZE columns in the first of the pair. The newly created window is
|
|
3841 returned.
|
428
|
3842 */
|
444
|
3843 (window, size, horflag))
|
428
|
3844 {
|
|
3845 Lisp_Object new;
|
|
3846 struct window *o, *p;
|
|
3847 struct frame *f;
|
444
|
3848 int csize;
|
428
|
3849 int psize;
|
|
3850
|
|
3851 if (NILP (window))
|
|
3852 window = Fselected_window (Qnil);
|
|
3853 else
|
|
3854 CHECK_LIVE_WINDOW (window);
|
|
3855
|
|
3856 o = XWINDOW (window);
|
|
3857 f = XFRAME (WINDOW_FRAME (o));
|
|
3858
|
444
|
3859 if (NILP (size))
|
428
|
3860 {
|
|
3861 if (!NILP (horflag))
|
|
3862 /* In the new scheme, we are symmetric with respect to separators
|
|
3863 so there is no need to do weird things here. */
|
|
3864 {
|
956
|
3865 psize = (WINDOW_WIDTH (o) + window_divider_width (o)) >> 1;
|
444
|
3866 csize = window_pixel_width_to_char_width (o, psize, 0);
|
428
|
3867 }
|
|
3868 else
|
|
3869 {
|
|
3870 psize = WINDOW_HEIGHT (o) >> 1;
|
444
|
3871 csize = window_pixel_height_to_char_height (o, psize, 1);
|
428
|
3872 }
|
|
3873 }
|
|
3874 else
|
|
3875 {
|
444
|
3876 CHECK_INT (size);
|
|
3877 csize = XINT (size);
|
428
|
3878 if (!NILP (horflag))
|
444
|
3879 psize = window_char_width_to_pixel_width (o, csize, 0);
|
428
|
3880 else
|
444
|
3881 psize = window_char_height_to_pixel_height (o, csize, 1);
|
428
|
3882 }
|
|
3883
|
|
3884 if (MINI_WINDOW_P (o))
|
563
|
3885 invalid_operation ("Attempt to split minibuffer window", Qunbound);
|
428
|
3886 else if (FRAME_NO_SPLIT_P (XFRAME (WINDOW_FRAME (o))))
|
563
|
3887 invalid_operation ("Attempt to split unsplittable frame", Qunbound);
|
428
|
3888
|
|
3889 check_min_window_sizes ();
|
|
3890
|
|
3891 if (NILP (horflag))
|
|
3892 {
|
444
|
3893 if (csize < window_min_height)
|
563
|
3894 signal_error (Qinvalid_operation, "Window height too small (after splitting)", make_int (csize));
|
444
|
3895 if (csize + window_min_height > window_char_height (o, 1))
|
563
|
3896 signal_error (Qinvalid_operation, "Window height too small (after splitting)",
|
|
3897 make_int (window_char_height (o, 1) - csize));
|
428
|
3898 if (NILP (o->parent)
|
|
3899 || NILP (XWINDOW (o->parent)->vchild))
|
|
3900 {
|
|
3901 make_dummy_parent (window);
|
448
|
3902 #if 0
|
|
3903 /* #### I can't understand why you have to reset face
|
|
3904 cachels here. This can cause crash so let's disable it
|
|
3905 and see the difference. See redisplay-tests.el --yh */
|
428
|
3906 reset_face_cachels (XWINDOW (window));
|
448
|
3907 #endif
|
428
|
3908 new = o->parent;
|
|
3909 XWINDOW (new)->vchild = window;
|
|
3910 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3911 }
|
|
3912 }
|
|
3913 else
|
|
3914 {
|
444
|
3915 if (csize < window_min_width)
|
563
|
3916 signal_error (Qinvalid_operation, "Window width too small (after splitting)", make_int (csize));
|
444
|
3917 if (csize + window_min_width > window_char_width (o, 0))
|
563
|
3918 signal_error (Qinvalid_operation, "Window width too small (after splitting)",
|
|
3919 make_int (window_char_width (o, 0) - csize));
|
428
|
3920 if (NILP (o->parent)
|
|
3921 || NILP (XWINDOW (o->parent)->hchild))
|
|
3922 {
|
|
3923 make_dummy_parent (window);
|
448
|
3924 #if 0
|
|
3925 /* #### See above. */
|
428
|
3926 reset_face_cachels (XWINDOW (window));
|
448
|
3927 #endif
|
428
|
3928 new = o->parent;
|
|
3929 XWINDOW (new)->hchild = window;
|
|
3930 XFRAME (o->frame)->mirror_dirty = 1;
|
|
3931 }
|
|
3932 }
|
|
3933
|
|
3934 /* Now we know that window's parent is a vertical combination
|
|
3935 if we are dividing vertically, or a horizontal combination
|
|
3936 if we are making side-by-side windows */
|
|
3937
|
|
3938 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
3939 new = allocate_window ();
|
|
3940 p = XWINDOW (new);
|
|
3941
|
|
3942 p->frame = o->frame;
|
|
3943 p->next = o->next;
|
|
3944 if (!NILP (p->next))
|
|
3945 XWINDOW (p->next)->prev = new;
|
|
3946 p->prev = window;
|
|
3947 o->next = new;
|
|
3948 p->parent = o->parent;
|
|
3949 p->buffer = Qt;
|
|
3950
|
|
3951 reset_face_cachels (p);
|
|
3952 reset_glyph_cachels (p);
|
|
3953
|
|
3954
|
|
3955 /* Apportion the available frame space among the two new windows */
|
|
3956
|
|
3957 if (!NILP (horflag))
|
|
3958 {
|
|
3959 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o);
|
|
3960 WINDOW_TOP (p) = WINDOW_TOP (o);
|
|
3961 WINDOW_WIDTH (p) = WINDOW_WIDTH (o) - psize;
|
|
3962 WINDOW_WIDTH (o) = psize;
|
|
3963 WINDOW_LEFT (p) = WINDOW_LEFT (o) + psize;
|
|
3964 }
|
|
3965 else
|
|
3966 {
|
|
3967 WINDOW_LEFT (p) = WINDOW_LEFT (o);
|
|
3968 WINDOW_WIDTH (p) = WINDOW_WIDTH (o);
|
|
3969 WINDOW_HEIGHT (p) = WINDOW_HEIGHT (o) - psize;
|
|
3970 WINDOW_HEIGHT (o) = psize;
|
|
3971 WINDOW_TOP (p) = WINDOW_TOP (o) + psize;
|
|
3972 }
|
|
3973
|
|
3974 XFRAME (p->frame)->mirror_dirty = 1;
|
853
|
3975
|
|
3976 note_object_created (new);
|
|
3977
|
428
|
3978 /* do this last (after the window is completely initialized and
|
|
3979 the mirror-dirty flag is set) so that specifier recomputation
|
|
3980 caused as a result of this will work properly and not abort. */
|
440
|
3981 Fset_window_buffer (new, o->buffer, Qt);
|
428
|
3982 return new;
|
|
3983 }
|
|
3984
|
|
3985
|
|
3986 DEFUN ("enlarge-window", Fenlarge_window, 1, 3, "_p", /*
|
444
|
3987 Make the selected window COUNT lines taller.
|
|
3988 From program, optional second arg HORIZONTALP non-nil means grow
|
|
3989 sideways COUNT columns, and optional third arg WINDOW specifies the
|
|
3990 window to change instead of the selected window.
|
428
|
3991 */
|
444
|
3992 (count, horizontalp, window))
|
|
3993 {
|
|
3994 CHECK_INT (count);
|
|
3995 change_window_height (window, XINT (count), horizontalp, /* inpixels */ 0);
|
428
|
3996 return Qnil;
|
|
3997 }
|
|
3998
|
|
3999 DEFUN ("enlarge-window-pixels", Fenlarge_window_pixels, 1, 3, "_p", /*
|
444
|
4000 Make the selected window COUNT pixels taller.
|
|
4001 From program, optional second arg HORIZONTALP non-nil means grow
|
|
4002 sideways COUNT pixels, and optional third arg WINDOW specifies the
|
|
4003 window to change instead of the selected window.
|
428
|
4004 */
|
444
|
4005 (count, horizontalp, window))
|
|
4006 {
|
|
4007 CHECK_INT (count);
|
|
4008 change_window_height (window, XINT (count), horizontalp, /* inpixels */ 1);
|
428
|
4009 return Qnil;
|
|
4010 }
|
|
4011
|
|
4012 DEFUN ("shrink-window", Fshrink_window, 1, 3, "_p", /*
|
444
|
4013 Make the selected window COUNT lines shorter.
|
|
4014 From program, optional second arg HORIZONTALP non-nil means shrink
|
|
4015 sideways COUNT columns, and optional third arg WINDOW specifies the
|
|
4016 window to change instead of the selected window.
|
428
|
4017 */
|
444
|
4018 (count, horizontalp, window))
|
|
4019 {
|
|
4020 CHECK_INT (count);
|
|
4021 change_window_height (window, -XINT (count), horizontalp, /* inpixels */ 0);
|
428
|
4022 return Qnil;
|
|
4023 }
|
|
4024
|
|
4025 DEFUN ("shrink-window-pixels", Fshrink_window_pixels, 1, 3, "_p", /*
|
444
|
4026 Make the selected window COUNT pixels smaller.
|
|
4027 From program, optional second arg HORIZONTALP non-nil means shrink
|
|
4028 sideways COUNT pixels, and optional third arg WINDOW specifies the
|
|
4029 window to change instead of the selected window.
|
428
|
4030 */
|
444
|
4031 (count, horizontalp, window))
|
|
4032 {
|
|
4033 CHECK_INT (count);
|
|
4034 change_window_height (window, -XINT (count), horizontalp, /* inpixels */ 1);
|
428
|
4035 return Qnil;
|
|
4036 }
|
|
4037
|
|
4038 static int
|
|
4039 window_pixel_height_to_char_height (struct window *w, int pixel_height,
|
|
4040 int include_gutters_p)
|
|
4041 {
|
|
4042 int avail_height;
|
|
4043 int defheight, defwidth;
|
|
4044 int char_height;
|
793
|
4045 Lisp_Object window = wrap_window (w);
|
|
4046
|
428
|
4047
|
|
4048 avail_height = (pixel_height -
|
|
4049 (include_gutters_p ? 0 :
|
442
|
4050 window_top_window_gutter_height (w) +
|
|
4051 window_bottom_window_gutter_height (w)));
|
428
|
4052
|
|
4053 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4054
|
|
4055 char_height = avail_height / defheight;
|
|
4056
|
|
4057 /* It's the calling function's responsibility to check these values
|
|
4058 and make sure they're not out of range.
|
|
4059
|
|
4060 #### We need to go through the calling functions and actually
|
|
4061 do this. */
|
|
4062 return max (0, char_height);
|
|
4063 }
|
|
4064
|
|
4065 static int
|
|
4066 window_char_height_to_pixel_height (struct window *w, int char_height,
|
|
4067 int include_gutters_p)
|
|
4068 {
|
|
4069 int avail_height;
|
|
4070 int defheight, defwidth;
|
|
4071 int pixel_height;
|
|
4072
|
793
|
4073 Lisp_Object window = wrap_window (w);
|
|
4074
|
428
|
4075
|
|
4076 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4077
|
|
4078 avail_height = char_height * defheight;
|
|
4079 pixel_height = (avail_height +
|
|
4080 (include_gutters_p ? 0 :
|
442
|
4081 window_top_window_gutter_height (w) +
|
|
4082 window_bottom_window_gutter_height (w)));
|
428
|
4083
|
|
4084 /* It's the calling function's responsibility to check these values
|
|
4085 and make sure they're not out of range.
|
|
4086
|
|
4087 #### We need to go through the calling functions and actually
|
|
4088 do this. */
|
|
4089 return max (0, pixel_height);
|
|
4090 }
|
|
4091
|
|
4092 /* Return number of default lines of text can fit in the window W.
|
|
4093 If INCLUDE_GUTTERS_P is 1, include "gutter" space (modeline plus
|
|
4094 horizontal scrollbar) in the space that is used for the calculation.
|
442
|
4095 This doesn't include space used by the frame gutters.
|
428
|
4096 */
|
|
4097 int
|
|
4098 window_char_height (struct window *w, int include_gutters_p)
|
|
4099 {
|
442
|
4100 return window_pixel_height_to_char_height (w, window_pixel_height (w),
|
428
|
4101 include_gutters_p);
|
|
4102 }
|
|
4103
|
|
4104 /*
|
|
4105 * Return number of lines currently displayed in window w. If
|
|
4106 * end-of-buffer is displayed then the area below end-of-buffer is assume
|
|
4107 * to be blank lines of default height.
|
|
4108 * Does not include the modeline.
|
|
4109 */
|
|
4110 int
|
|
4111 window_displayed_height (struct window *w)
|
|
4112 {
|
|
4113 struct buffer *b = XBUFFER (w->buffer);
|
|
4114 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
4115 int num_lines;
|
|
4116 Charcount end_pos = (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b)
|
|
4117 ? -1
|
|
4118 : w->window_end_pos[CURRENT_DISP]);
|
|
4119
|
|
4120 if (!Dynarr_length (dla))
|
|
4121 return window_char_height (w, 0);
|
|
4122
|
|
4123 num_lines = Dynarr_length (dla);
|
|
4124
|
|
4125 /* #### Document and assert somewhere that w->window_end_pos == -1
|
|
4126 indicates that end-of-buffer is being displayed. */
|
|
4127 if (end_pos == -1)
|
|
4128 {
|
|
4129 struct display_line *dl = Dynarr_atp (dla, 0);
|
|
4130 int ypos1 = dl->ypos + dl->descent;
|
|
4131 int ypos2 = WINDOW_TEXT_BOTTOM (w);
|
|
4132 Lisp_Object window;
|
|
4133 int defheight, defwidth;
|
|
4134
|
793
|
4135 window = wrap_window (w);
|
428
|
4136
|
|
4137 if (dl->modeline)
|
|
4138 {
|
|
4139 num_lines--;
|
|
4140
|
|
4141 if (Dynarr_length (dla) == 1)
|
|
4142 ypos1 = WINDOW_TEXT_TOP (w);
|
|
4143 else
|
|
4144 {
|
|
4145 dl = Dynarr_atp (dla, Dynarr_length (dla) - 1);
|
|
4146 /* If this line is clipped then we know that there is no
|
|
4147 blank room between eob and the modeline. If we are
|
|
4148 scrolling on clipped lines just know off the clipped
|
|
4149 line and return .*/
|
|
4150 if (scroll_on_clipped_lines && dl->clip)
|
|
4151 return num_lines - 1;
|
|
4152 ypos1 = dl->ypos + dl->descent - dl->clip;
|
|
4153 }
|
|
4154 }
|
|
4155
|
|
4156 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4157 /* #### This probably needs to know about the clipping area once a
|
|
4158 final definition is decided on. */
|
|
4159 num_lines += ((ypos2 - ypos1) / defheight);
|
|
4160 }
|
|
4161 else
|
|
4162 {
|
|
4163 if (num_lines > 1 && Dynarr_atp (dla, 0)->modeline)
|
|
4164 num_lines--;
|
|
4165
|
|
4166 if (scroll_on_clipped_lines
|
|
4167 && Dynarr_atp (dla, Dynarr_length (dla) - 1)->clip)
|
|
4168 num_lines--;
|
|
4169 }
|
|
4170
|
|
4171 return num_lines;
|
|
4172 }
|
|
4173
|
|
4174 static int
|
|
4175 window_pixel_width (Lisp_Object window)
|
|
4176 {
|
|
4177 return WINDOW_WIDTH (XWINDOW (window));
|
|
4178 }
|
|
4179
|
442
|
4180 /* Calculate the pixel of a window, optionally including margin space
|
|
4181 but no vertical gutters. */
|
428
|
4182 static int
|
|
4183 window_pixel_width_to_char_width (struct window *w, int pixel_width,
|
|
4184 int include_margins_p)
|
|
4185 {
|
|
4186 int avail_width;
|
|
4187 int char_width;
|
|
4188 int defheight, defwidth;
|
793
|
4189 Lisp_Object window = wrap_window (w);
|
|
4190
|
428
|
4191
|
|
4192 avail_width = (pixel_width -
|
|
4193 window_left_gutter_width (w, 0) -
|
|
4194 window_right_gutter_width (w, 0) -
|
|
4195 (include_margins_p ? 0 : window_left_margin_width (w)) -
|
|
4196 (include_margins_p ? 0 : window_right_margin_width (w)));
|
|
4197
|
|
4198 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4199
|
|
4200 char_width = (avail_width / defwidth);
|
|
4201
|
|
4202 /* It's the calling function's responsibility to check these values
|
|
4203 and make sure they're not out of range.
|
|
4204
|
|
4205 #### We need to go through the calling functions and actually
|
|
4206 do this. */
|
|
4207 return max (0, char_width);
|
|
4208 }
|
|
4209
|
|
4210 static int
|
|
4211 window_char_width_to_pixel_width (struct window *w, int char_width,
|
|
4212 int include_margins_p)
|
|
4213 {
|
|
4214 int avail_width;
|
|
4215 int pixel_width;
|
|
4216 int defheight, defwidth;
|
793
|
4217 Lisp_Object window = wrap_window (w);
|
|
4218
|
428
|
4219
|
|
4220 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4221
|
|
4222 avail_width = char_width * defwidth;
|
|
4223 pixel_width = (avail_width +
|
442
|
4224 window_left_window_gutter_width (w, 0) +
|
|
4225 window_right_window_gutter_width (w, 0) +
|
428
|
4226 (include_margins_p ? 0 : window_left_margin_width (w)) +
|
|
4227 (include_margins_p ? 0 : window_right_margin_width (w)));
|
|
4228
|
|
4229 /* It's the calling function's responsibility to check these values
|
|
4230 and make sure they're not out of range.
|
|
4231
|
|
4232 #### We need to go through the calling functions and actually
|
|
4233 do this. */
|
|
4234 return max (0, pixel_width);
|
|
4235 }
|
|
4236
|
|
4237 /* This returns the usable space which doesn't include space needed by
|
|
4238 scrollbars or divider lines. */
|
|
4239 int
|
|
4240 window_char_width (struct window *w, int include_margins_p)
|
|
4241 {
|
|
4242 return window_pixel_width_to_char_width (w, WINDOW_WIDTH (w),
|
|
4243 include_margins_p);
|
|
4244 }
|
|
4245
|
|
4246 #define MINSIZE(w) \
|
|
4247 (widthflag \
|
|
4248 ? window_min_width * defwidth \
|
|
4249 : (defheight * (MINI_WINDOW_P (XWINDOW (w)) ? 1 : window_min_height)))
|
|
4250
|
|
4251 #define CURBEG(w) \
|
|
4252 *(widthflag ? (int *) &WINDOW_LEFT (w) : (int *) &WINDOW_TOP (w))
|
|
4253
|
|
4254 #define CURSIZE(w) \
|
|
4255 *(widthflag ? (int *) &WINDOW_WIDTH (w) : (int *) &WINDOW_HEIGHT (w))
|
|
4256
|
|
4257 #define CURCHARSIZE(w) \
|
|
4258 (widthflag ? window_char_width (w, 0) : window_char_height (w, 1))
|
|
4259
|
|
4260 #define MINCHARSIZE(window) \
|
|
4261 (widthflag ? window_min_width : MINI_WINDOW_P (XWINDOW (window)) \
|
|
4262 ? 1 : window_min_height)
|
|
4263
|
442
|
4264 static int
|
|
4265 window_pixheight (Lisp_Object w)
|
|
4266 {
|
|
4267 return window_pixel_height (XWINDOW (w));
|
|
4268 }
|
|
4269
|
428
|
4270 /* Unlike set_window_pixheight, this function
|
|
4271 also changes the heights of the siblings so as to
|
|
4272 keep everything consistent. */
|
|
4273
|
|
4274 static void
|
444
|
4275 change_window_height (Lisp_Object window, int delta, Lisp_Object horizontalp,
|
428
|
4276 int inpixels)
|
|
4277 {
|
444
|
4278 struct window *win = decode_window (window);
|
|
4279 int widthflag = !NILP (horizontalp);
|
428
|
4280 Lisp_Object parent;
|
|
4281 struct window *w;
|
|
4282 struct frame *f;
|
|
4283 int *sizep;
|
|
4284 int (*sizefun) (Lisp_Object) = (widthflag
|
|
4285 ? window_pixel_width
|
442
|
4286 : window_pixheight);
|
428
|
4287 void (*setsizefun) (Lisp_Object, int, int) = (widthflag
|
|
4288 ? set_window_pixwidth
|
|
4289 : set_window_pixheight);
|
|
4290 int dim;
|
|
4291 int defheight, defwidth;
|
|
4292
|
|
4293 if (delta == 0)
|
|
4294 return;
|
|
4295
|
|
4296 check_min_window_sizes ();
|
|
4297
|
793
|
4298 window = wrap_window (win);
|
428
|
4299 f = XFRAME (win->frame);
|
|
4300 if (EQ (window, FRAME_ROOT_WINDOW (f)))
|
563
|
4301 invalid_operation ("Won't change only window", Qunbound);
|
428
|
4302
|
|
4303 /* #### This is very likely incorrect and instead the char_to_pixel_
|
|
4304 functions should be called. */
|
|
4305 default_face_height_and_width (window, &defheight, &defwidth);
|
|
4306
|
|
4307 while (1)
|
|
4308 {
|
|
4309 w = XWINDOW (window);
|
|
4310 parent = w->parent;
|
|
4311 if (NILP (parent))
|
|
4312 {
|
|
4313 if (widthflag)
|
563
|
4314 invalid_operation ("No other window to side of this one", Qunbound);
|
428
|
4315 break;
|
|
4316 }
|
|
4317 if (widthflag
|
|
4318 ? !NILP (XWINDOW (parent)->hchild)
|
|
4319 : !NILP (XWINDOW (parent)->vchild))
|
|
4320 break;
|
|
4321 window = parent;
|
|
4322 }
|
|
4323
|
|
4324 sizep = &CURSIZE (w);
|
|
4325 dim = CURCHARSIZE (w);
|
|
4326
|
|
4327 if ((inpixels && (*sizep + delta) < MINSIZE (window)) ||
|
|
4328 (!inpixels && (dim + delta) < MINCHARSIZE (window)))
|
|
4329 {
|
|
4330 if (MINI_WINDOW_P (XWINDOW (window)))
|
|
4331 return;
|
|
4332 else if (!NILP (parent))
|
|
4333 {
|
|
4334 Fdelete_window (window, Qnil);
|
|
4335 return;
|
|
4336 }
|
|
4337 }
|
|
4338
|
|
4339 if (!inpixels)
|
|
4340 delta *= (widthflag ? defwidth : defheight);
|
|
4341
|
|
4342 {
|
|
4343 int maxdelta;
|
|
4344
|
|
4345 maxdelta = ((!NILP (parent))
|
|
4346 ? (*sizefun) (parent) - *sizep
|
|
4347 : ((!NILP (w->next))
|
|
4348 ? (*sizefun) (w->next) - MINSIZE (w->next)
|
|
4349 : ((!NILP (w->prev))
|
|
4350 ? (*sizefun) (w->prev) - MINSIZE (w->prev)
|
|
4351 /* This is a frame with only one window,
|
|
4352 a minibuffer-only or a minibufferless frame. */
|
|
4353 : (delta = 0))));
|
|
4354
|
|
4355 if (delta > maxdelta)
|
|
4356 /* This case traps trying to make the minibuffer
|
|
4357 the full frame, or make the only window aside from the
|
|
4358 minibuffer the full frame. */
|
|
4359 delta = maxdelta;
|
|
4360
|
|
4361 if (delta == 0)
|
|
4362 return;
|
|
4363
|
|
4364 #if 0 /* FSFmacs */
|
|
4365 /* #### Chuck: is this correct? */
|
|
4366 if (*sizep + delta < MINSIZE (window))
|
|
4367 {
|
|
4368 Fdelete_window (window);
|
|
4369 return;
|
|
4370 }
|
|
4371 #endif
|
|
4372 }
|
|
4373
|
|
4374 if (!NILP (w->next) &&
|
|
4375 (*sizefun) (w->next) - delta >= (int) MINSIZE (w->next))
|
|
4376 {
|
|
4377 CURBEG (XWINDOW (w->next)) += delta;
|
|
4378 (*setsizefun) (w->next, (*sizefun) (w->next) - delta, 0);
|
|
4379 (*setsizefun) (window, *sizep + delta, 0);
|
|
4380 }
|
|
4381 else if (!NILP (w->prev) &&
|
|
4382 (*sizefun) (w->prev) - delta >= (int) MINSIZE (w->prev))
|
|
4383 {
|
|
4384 (*setsizefun) (w->prev, (*sizefun) (w->prev) - delta, 0);
|
|
4385 CURBEG (w) -= delta;
|
|
4386 (*setsizefun) (window, *sizep + delta, 0);
|
|
4387 }
|
|
4388 else
|
|
4389 {
|
|
4390 int delta1;
|
|
4391 int opht = (*sizefun) (parent);
|
|
4392
|
|
4393 /* If trying to grow this window to or beyond size of the parent,
|
|
4394 make delta1 so big that, on shrinking back down,
|
|
4395 all the siblings end up with less than one line and are deleted. */
|
|
4396 if (opht <= *sizep + delta)
|
|
4397 delta1 = opht * opht * 2;
|
|
4398 /* Otherwise, make delta1 just right so that if we add delta1
|
|
4399 lines to this window and to the parent, and then shrink
|
|
4400 the parent back to its original size, the new proportional
|
|
4401 size of this window will increase by delta. */
|
|
4402 else
|
|
4403 delta1 = (delta * opht * 100) / ((opht - *sizep - delta) * 100);
|
|
4404
|
|
4405 /* Add delta1 lines or columns to this window, and to the parent,
|
|
4406 keeping things consistent while not affecting siblings. */
|
|
4407 CURSIZE (XWINDOW (parent)) = opht + delta1;
|
|
4408 (*setsizefun) (window, *sizep + delta1, 0);
|
|
4409
|
|
4410 /* Squeeze out delta1 lines or columns from our parent,
|
|
4411 shrinking this window and siblings proportionately.
|
|
4412 This brings parent back to correct size.
|
|
4413 Delta1 was calculated so this makes this window the desired size,
|
|
4414 taking it all out of the siblings. */
|
|
4415 (*setsizefun) (parent, opht, 0);
|
|
4416 }
|
|
4417
|
|
4418 SET_LAST_MODIFIED (w, 0);
|
|
4419 SET_LAST_FACECHANGE (w);
|
|
4420 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (f);
|
|
4421 /* overkill maybe, but better to be correct */
|
|
4422 MARK_FRAME_GUTTERS_CHANGED (f);
|
|
4423 }
|
|
4424 #undef MINSIZE
|
|
4425 #undef CURBEG
|
|
4426 #undef CURSIZE
|
|
4427 #undef CURCHARSIZE
|
|
4428 #undef MINCHARSIZE
|
|
4429
|
|
4430
|
|
4431
|
444
|
4432 /* Scroll contents of window WINDOW up COUNT lines.
|
|
4433 If COUNT < (top line height / average line height) then we just adjust
|
|
4434 the top clip. */
|
428
|
4435 void
|
444
|
4436 window_scroll (Lisp_Object window, Lisp_Object count, int direction,
|
578
|
4437 Error_Behavior errb)
|
428
|
4438 {
|
|
4439 struct window *w = XWINDOW (window);
|
|
4440 struct buffer *b = XBUFFER (w->buffer);
|
|
4441 int selected = EQ (window, Fselected_window (Qnil));
|
|
4442 int value = 0;
|
|
4443 Lisp_Object point, tem;
|
|
4444 display_line_dynarr *dla;
|
|
4445 int fheight, fwidth, modeline = 0;
|
|
4446 struct display_line* dl;
|
|
4447
|
|
4448 if (selected)
|
|
4449 point = make_int (BUF_PT (b));
|
|
4450 else
|
|
4451 {
|
665
|
4452 Charbpos pos = marker_position (w->pointm[CURRENT_DISP]);
|
428
|
4453
|
|
4454 if (pos < BUF_BEGV (b))
|
|
4455 pos = BUF_BEGV (b);
|
|
4456 else if (pos > BUF_ZV (b))
|
|
4457 pos = BUF_ZV (b);
|
|
4458
|
|
4459 point = make_int (pos);
|
|
4460 }
|
|
4461
|
|
4462 /* Always set force_start so that redisplay_window will run
|
|
4463 the window-scroll-functions. */
|
|
4464 w->force_start = 1;
|
|
4465
|
|
4466 /* #### When the fuck does this happen? I'm so glad that history has
|
|
4467 completely documented the behavior of the scrolling functions under
|
|
4468 all circumstances. */
|
1708
|
4469 tem = Fpos_visible_in_window_p (point, window, Qnil);
|
428
|
4470 if (NILP (tem))
|
|
4471 {
|
|
4472 Fvertical_motion (make_int (-window_char_height (w, 0) / 2),
|
|
4473 window, Qnil);
|
|
4474 Fset_marker (w->start[CURRENT_DISP], point, w->buffer);
|
|
4475 w->start_at_line_beg = beginning_of_line_p (b, XINT (point));
|
|
4476 WINDOW_TEXT_TOP_CLIP (w) = 0;
|
|
4477 MARK_WINDOWS_CHANGED (w);
|
|
4478 }
|
|
4479
|
444
|
4480 if (!NILP (count))
|
428
|
4481 {
|
444
|
4482 if (EQ (count, Qminus))
|
428
|
4483 direction *= -1;
|
|
4484 else
|
|
4485 {
|
444
|
4486 count = Fprefix_numeric_value (count);
|
|
4487 value = XINT (count) * direction;
|
428
|
4488
|
|
4489 if (!value)
|
|
4490 return; /* someone just made a pointless call */
|
|
4491 }
|
|
4492 }
|
|
4493
|
|
4494 /* If the user didn't specify how far to scroll then we have to figure it
|
|
4495 out by ourselves. */
|
444
|
4496 if (NILP (count) || EQ (count, Qminus))
|
428
|
4497 {
|
|
4498 /* Going forwards is easy. If that is what we are doing then just
|
|
4499 set value and the section which handles the user specifying a
|
|
4500 positive value will work. */
|
|
4501 if (direction == 1)
|
|
4502 {
|
|
4503 value = window_displayed_height (w) - next_screen_context_lines;
|
|
4504 value = (value < 1 ? 1 : value);
|
|
4505 }
|
|
4506
|
|
4507 /* Going backwards is hard. We can't use the same loop used if the
|
|
4508 user specified a negative value because we care about
|
|
4509 next_screen_context_lines. In a variable height world you don't
|
|
4510 know how many lines above you can actually be displayed and still
|
|
4511 have the context lines appear. So we leave value set to 0 and add
|
|
4512 a separate section to deal with this. */
|
|
4513
|
|
4514 }
|
|
4515
|
|
4516 if (direction == 1 && !value)
|
|
4517 {
|
|
4518 return;
|
|
4519 }
|
|
4520
|
|
4521 /* Determine parameters to test for partial line scrolling with. */
|
|
4522 dla = window_display_lines (w, CURRENT_DISP);
|
|
4523
|
|
4524 if (INTP (Vwindow_pixel_scroll_increment))
|
|
4525 fheight = XINT (Vwindow_pixel_scroll_increment);
|
440
|
4526 else if (!NILP (Vwindow_pixel_scroll_increment))
|
428
|
4527 default_face_height_and_width (window, &fheight, &fwidth);
|
438
|
4528
|
428
|
4529 if (Dynarr_length (dla) >= 1)
|
|
4530 modeline = Dynarr_atp (dla, 0)->modeline;
|
|
4531
|
|
4532 dl = Dynarr_atp (dla, modeline);
|
438
|
4533
|
428
|
4534 if (value > 0)
|
|
4535 {
|
|
4536 /* Go for partial display line scrolling. This just means bumping
|
|
4537 the clip by a reasonable amount and redisplaying, everything else
|
|
4538 remains unchanged. */
|
|
4539 if (!NILP (Vwindow_pixel_scroll_increment)
|
|
4540 &&
|
|
4541 Dynarr_length (dla) >= (1 + modeline)
|
|
4542 &&
|
458
|
4543 (dl->ascent - dl->top_clip) > fheight * value)
|
428
|
4544 {
|
|
4545 WINDOW_TEXT_TOP_CLIP (w) += value * fheight;
|
|
4546 MARK_WINDOWS_CHANGED (w);
|
|
4547 }
|
|
4548 else
|
|
4549 {
|
|
4550 int vtarget;
|
665
|
4551 Charbpos startp, old_start;
|
438
|
4552
|
428
|
4553 if (WINDOW_TEXT_TOP_CLIP (w))
|
|
4554 {
|
|
4555 WINDOW_TEXT_TOP_CLIP (w) = 0;
|
|
4556 MARK_WINDOWS_CHANGED (w);
|
|
4557 }
|
|
4558
|
|
4559 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
4560 startp = vmotion (w, old_start, value, &vtarget);
|
438
|
4561
|
428
|
4562 if (vtarget < value &&
|
|
4563 (w->window_end_pos[CURRENT_DISP] == -1
|
|
4564 || (BUF_Z (b) - w->window_end_pos[CURRENT_DISP] > BUF_ZV (b))))
|
|
4565 {
|
563
|
4566 maybe_signal_error_1 (Qend_of_buffer, Qnil, Qwindow, errb);
|
428
|
4567 return;
|
|
4568 }
|
|
4569 else
|
|
4570 {
|
|
4571 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
4572 w->buffer);
|
|
4573 w->force_start = 1;
|
|
4574 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4575 MARK_WINDOWS_CHANGED (w);
|
438
|
4576
|
1708
|
4577 if (!point_would_be_visible (w, startp, XINT (point), 0))
|
844
|
4578 Fset_window_point (wrap_window (w), make_int (startp));
|
428
|
4579 }
|
|
4580 }
|
|
4581 }
|
|
4582 else if (value < 0)
|
|
4583 {
|
|
4584 /* Go for partial display line scrolling. This just means bumping
|
|
4585 the clip by a reasonable amount and redisplaying, everything else
|
|
4586 remains unchanged. */
|
|
4587 if (!NILP (Vwindow_pixel_scroll_increment)
|
|
4588 &&
|
|
4589 Dynarr_length (dla) >= (1 + modeline)
|
|
4590 &&
|
|
4591 (dl->ascent - dl->top_clip) - fheight * value <
|
|
4592 (dl->ascent + dl->descent - dl->clip)
|
|
4593 &&
|
|
4594 WINDOW_TEXT_TOP_CLIP (w) + value * fheight > 0)
|
|
4595 {
|
|
4596 WINDOW_TEXT_TOP_CLIP (w) += value * fheight;
|
|
4597 MARK_WINDOWS_CHANGED (w);
|
|
4598 }
|
|
4599 else
|
|
4600 {
|
|
4601 int vtarget;
|
665
|
4602 Charbpos startp, old_start;
|
438
|
4603
|
428
|
4604 if (WINDOW_TEXT_TOP_CLIP (w))
|
|
4605 {
|
|
4606 WINDOW_TEXT_TOP_CLIP (w) = 0;
|
|
4607 MARK_WINDOWS_CHANGED (w);
|
|
4608 }
|
438
|
4609
|
428
|
4610 old_start = marker_position (w->start[CURRENT_DISP]);
|
|
4611 startp = vmotion (w, old_start, value, &vtarget);
|
438
|
4612
|
428
|
4613 if (vtarget > value
|
|
4614 && marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
4615 {
|
563
|
4616 maybe_signal_error_1 (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
428
|
4617 return;
|
|
4618 }
|
|
4619 else
|
|
4620 {
|
|
4621 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
4622 w->buffer);
|
|
4623 w->force_start = 1;
|
|
4624 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4625 MARK_WINDOWS_CHANGED (w);
|
438
|
4626
|
440
|
4627 /* #### Scroll back by less than a line. This code was
|
|
4628 originally for scrolling over large pixmaps and it
|
|
4629 loses when a line being *exposed* at the top of the
|
|
4630 window is bigger than the current one. However, for
|
|
4631 pixel based scrolling in general we can guess that
|
|
4632 the line we are going to display is probably the same
|
|
4633 size as the one we are on. In that instance we can
|
|
4634 have a reasonable stab at a suitable top clip. Fixing
|
|
4635 this properly is hard (and probably slow) as we would
|
|
4636 have to call redisplay to figure out the exposed line
|
|
4637 size. */
|
|
4638 if (!NILP (Vwindow_pixel_scroll_increment)
|
|
4639 && Dynarr_length (dla) >= (1 + modeline)
|
|
4640 && dl->ascent + fheight * value > 0)
|
|
4641 {
|
|
4642 WINDOW_TEXT_TOP_CLIP (w) = (dl->ascent + fheight * value);
|
|
4643 }
|
|
4644
|
1708
|
4645 if (!point_would_be_visible (w, startp, XINT (point), 0))
|
428
|
4646 {
|
665
|
4647 Charbpos new_point;
|
438
|
4648
|
428
|
4649 if (MINI_WINDOW_P (w))
|
|
4650 new_point = startp;
|
|
4651 else
|
|
4652 new_point = start_of_last_line (w, startp);
|
438
|
4653
|
844
|
4654 Fset_window_point (wrap_window (w), make_int (new_point));
|
428
|
4655 }
|
|
4656 }
|
|
4657 }
|
|
4658 }
|
|
4659 else /* value == 0 && direction == -1 */
|
|
4660 {
|
|
4661 if (WINDOW_TEXT_TOP_CLIP (w))
|
|
4662 {
|
|
4663 WINDOW_TEXT_TOP_CLIP (w) = 0;
|
|
4664 MARK_WINDOWS_CHANGED (w);
|
|
4665 }
|
|
4666 if (marker_position (w->start[CURRENT_DISP]) == BUF_BEGV (b))
|
|
4667 {
|
563
|
4668 maybe_signal_error_1 (Qbeginning_of_buffer, Qnil, Qwindow, errb);
|
428
|
4669 return;
|
|
4670 }
|
|
4671 else
|
|
4672 {
|
|
4673 int vtarget;
|
|
4674 int movement = next_screen_context_lines - 1;
|
665
|
4675 Charbpos old_startp = marker_position (w->start[CURRENT_DISP]);
|
|
4676 Charbpos bottom = vmotion (w, old_startp, movement, &vtarget);
|
|
4677 Charbpos startp =
|
428
|
4678 start_with_point_on_display_line (w, bottom,
|
|
4679 -1 - (movement - vtarget));
|
|
4680
|
|
4681 if (startp >= old_startp)
|
|
4682 startp = vmotion (w, old_startp, -1, NULL);
|
|
4683
|
|
4684 set_marker_restricted (w->start[CURRENT_DISP], make_int (startp),
|
|
4685 w->buffer);
|
|
4686 w->force_start = 1;
|
|
4687 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4688 MARK_WINDOWS_CHANGED (w);
|
|
4689
|
1708
|
4690 if (!point_would_be_visible (w, startp, XINT (point), 0))
|
428
|
4691 {
|
665
|
4692 Charbpos new_point = start_of_last_line (w, startp);
|
428
|
4693
|
844
|
4694 Fset_window_point (wrap_window (w), make_int (new_point));
|
428
|
4695 }
|
|
4696 }
|
|
4697 }
|
|
4698 }
|
|
4699
|
|
4700 DEFUN ("scroll-up", Fscroll_up, 0, 1, "_P", /*
|
444
|
4701 Scroll text of current window up COUNT lines; or near full screen if no arg.
|
428
|
4702 A near full screen is `next-screen-context-lines' less than a full screen.
|
444
|
4703 Negative COUNT means scroll downward.
|
428
|
4704 When calling from a program, supply an integer as argument or nil.
|
|
4705 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
4706 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
4707 signaled.
|
462
|
4708
|
|
4709 The characters that are moved over may be added to the current selection
|
|
4710 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
4711 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
4712 the documentation for this variable for more details.
|
428
|
4713 */
|
444
|
4714 (count))
|
|
4715 {
|
|
4716 window_scroll (Fselected_window (Qnil), count, 1, ERROR_ME);
|
428
|
4717 return Qnil;
|
|
4718 }
|
|
4719
|
|
4720 DEFUN ("scroll-down", Fscroll_down, 0, 1, "_P", /*
|
444
|
4721 Scroll text of current window down COUNT lines; or near full screen if no arg.
|
428
|
4722 A near full screen is `next-screen-context-lines' less than a full screen.
|
444
|
4723 Negative COUNT means scroll upward.
|
428
|
4724 When calling from a program, supply a number as argument or nil.
|
|
4725 On attempt to scroll past end of buffer, `end-of-buffer' is signaled.
|
|
4726 On attempt to scroll past beginning of buffer, `beginning-of-buffer' is
|
|
4727 signaled.
|
462
|
4728
|
|
4729 The characters that are moved over may be added to the current selection
|
|
4730 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
4731 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
4732 the documentation for this variable for more details.
|
428
|
4733 */
|
444
|
4734 (count))
|
|
4735 {
|
|
4736 window_scroll (Fselected_window (Qnil), count, -1, ERROR_ME);
|
428
|
4737 return Qnil;
|
|
4738 }
|
|
4739
|
|
4740 DEFUN ("other-window-for-scrolling", Fother_window_for_scrolling, 0, 0, 0, /*
|
|
4741 Return the other window for "other window scroll" commands.
|
|
4742 If in the minibuffer, `minibuffer-scroll-window' if non-nil
|
|
4743 specifies the window.
|
|
4744 If `other-window-scroll-buffer' is non-nil, a window
|
|
4745 showing that buffer is used.
|
|
4746 */
|
|
4747 ())
|
|
4748 {
|
|
4749 Lisp_Object window;
|
|
4750 Lisp_Object selected_window = Fselected_window (Qnil);
|
|
4751
|
|
4752 if (MINI_WINDOW_P (XWINDOW (selected_window))
|
|
4753 && !NILP (Vminibuffer_scroll_window))
|
|
4754 window = Vminibuffer_scroll_window;
|
|
4755 /* If buffer is specified, scroll that buffer. */
|
|
4756 else if (!NILP (Vother_window_scroll_buffer))
|
|
4757 {
|
|
4758 window = Fget_buffer_window (Vother_window_scroll_buffer, Qnil, Qnil);
|
|
4759 if (NILP (window))
|
|
4760 window = display_buffer (Vother_window_scroll_buffer, Qt, Qnil);
|
|
4761 }
|
|
4762 else
|
|
4763 {
|
|
4764 /* Nothing specified; look for a neighboring window on the same
|
|
4765 frame. */
|
|
4766 window = Fnext_window (selected_window, Qnil, Qnil, Qnil);
|
|
4767
|
|
4768 if (EQ (window, selected_window))
|
|
4769 /* That didn't get us anywhere; look for a window on another
|
|
4770 visible frame. */
|
|
4771 do
|
|
4772 window = Fnext_window (window, Qnil, Qt, Qnil);
|
|
4773 while (! FRAME_VISIBLE_P (XFRAME (WINDOW_FRAME (XWINDOW (window))))
|
|
4774 && ! EQ (window, selected_window));
|
|
4775 }
|
|
4776
|
|
4777 CHECK_LIVE_WINDOW (window);
|
|
4778
|
|
4779 if (EQ (window, selected_window))
|
563
|
4780 invalid_operation ("There is no other window", Qunbound);
|
428
|
4781
|
|
4782 return window;
|
|
4783 }
|
|
4784
|
|
4785 DEFUN ("scroll-other-window", Fscroll_other_window, 0, 1, "_P", /*
|
444
|
4786 Scroll next window upward COUNT lines; or near full frame if no arg.
|
428
|
4787 The next window is the one below the current one; or the one at the top
|
444
|
4788 if the current one is at the bottom. Negative COUNT means scroll downward.
|
428
|
4789 When calling from a program, supply a number as argument or nil.
|
|
4790
|
|
4791 If in the minibuffer, `minibuffer-scroll-window' if non-nil
|
|
4792 specifies the window to scroll.
|
|
4793 If `other-window-scroll-buffer' is non-nil, scroll the window
|
|
4794 showing that buffer, popping the buffer up if necessary.
|
|
4795 */
|
444
|
4796 (count))
|
|
4797 {
|
|
4798 window_scroll (Fother_window_for_scrolling (), count, 1, ERROR_ME);
|
428
|
4799 return Qnil;
|
|
4800 }
|
|
4801
|
|
4802 DEFUN ("scroll-left", Fscroll_left, 0, 1, "_P", /*
|
444
|
4803 Scroll selected window display COUNT columns left.
|
|
4804 Default for COUNT is window width minus 2.
|
462
|
4805
|
|
4806 The characters that are moved over may be added to the current selection
|
|
4807 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
4808 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
4809 the documentation for this variable for more details.
|
428
|
4810 */
|
444
|
4811 (count))
|
428
|
4812 {
|
|
4813 Lisp_Object window = Fselected_window (Qnil);
|
|
4814 struct window *w = XWINDOW (window);
|
444
|
4815 int n = (NILP (count) ?
|
|
4816 window_char_width (w, 0) - 2 :
|
|
4817 XINT (Fprefix_numeric_value (count)));
|
|
4818
|
|
4819 return Fset_window_hscroll (window, make_int (w->hscroll + n));
|
428
|
4820 }
|
|
4821
|
|
4822 DEFUN ("scroll-right", Fscroll_right, 0, 1, "_P", /*
|
444
|
4823 Scroll selected window display COUNT columns right.
|
|
4824 Default for COUNT is window width minus 2.
|
462
|
4825
|
|
4826 The characters that are moved over may be added to the current selection
|
|
4827 \(i.e. active region) if the Shift key is held down, a motion key is used
|
|
4828 to invoke this command, and `shifted-motion-keys-select-region' is t; see
|
|
4829 the documentation for this variable for more details.
|
428
|
4830 */
|
444
|
4831 (count))
|
428
|
4832 {
|
|
4833 Lisp_Object window = Fselected_window (Qnil);
|
|
4834 struct window *w = XWINDOW (window);
|
444
|
4835 int n = (NILP (count) ?
|
|
4836 window_char_width (w, 0) - 2 :
|
|
4837 XINT (Fprefix_numeric_value (count)));
|
|
4838
|
|
4839 return Fset_window_hscroll (window, make_int (w->hscroll - n));
|
428
|
4840 }
|
|
4841
|
|
4842 DEFUN ("center-to-window-line", Fcenter_to_window_line, 0, 2, "_P", /*
|
|
4843 Center point in WINDOW. With N, put point on line N.
|
|
4844 The desired position of point is always relative to the window.
|
|
4845 If WINDOW is nil, the selected window is used.
|
|
4846 */
|
|
4847 (n, window))
|
|
4848 {
|
|
4849 struct window *w = decode_window (window);
|
|
4850 struct buffer *b = XBUFFER (w->buffer);
|
665
|
4851 Charbpos opoint = BUF_PT (b);
|
|
4852 Charbpos startp;
|
428
|
4853
|
|
4854 if (NILP (n))
|
|
4855 startp = start_with_line_at_pixpos (w, opoint, window_half_pixpos (w));
|
|
4856 else
|
|
4857 {
|
|
4858 n = Fprefix_numeric_value (n);
|
|
4859 CHECK_INT (n);
|
|
4860 startp = start_with_point_on_display_line (w, opoint, XINT (n));
|
|
4861 }
|
|
4862
|
|
4863 Fset_marker (w->start[CURRENT_DISP], make_int (startp), w->buffer);
|
|
4864
|
|
4865 w->start_at_line_beg = beginning_of_line_p (b, startp);
|
|
4866 w->force_start = 1;
|
|
4867 MARK_WINDOWS_CHANGED (w);
|
|
4868 return Qnil;
|
|
4869 }
|
|
4870
|
|
4871 DEFUN ("move-to-window-line", Fmove_to_window_line, 1, 2, "_P", /*
|
|
4872 Position point relative to WINDOW.
|
|
4873 With no argument, position text at center of window.
|
|
4874 An argument specifies window line; zero means top of window,
|
|
4875 negative means relative to bottom of window.
|
|
4876 If WINDOW is nil, the selected window is used.
|
|
4877 */
|
|
4878 (arg, window))
|
|
4879 {
|
|
4880 struct window *w;
|
|
4881 struct buffer *b;
|
|
4882 int height;
|
665
|
4883 Charbpos start, new_point;
|
428
|
4884 int selected;
|
|
4885
|
|
4886 /* Don't use decode_window() because we need the new value of
|
|
4887 WINDOW. */
|
|
4888 if (NILP (window))
|
|
4889 window = Fselected_window (Qnil);
|
|
4890 else
|
|
4891 CHECK_LIVE_WINDOW (window);
|
|
4892 w = XWINDOW (window);
|
|
4893 b = XBUFFER (w->buffer);
|
|
4894
|
|
4895 height = window_displayed_height (w);
|
|
4896 selected = EQ (window, Fselected_window (w->frame));
|
|
4897
|
|
4898 if (NILP (arg))
|
|
4899 {
|
|
4900 int retval;
|
|
4901
|
|
4902 if (XINT (w->last_modified[CURRENT_DISP]) >= BUF_MODIFF (b)
|
|
4903 && XINT (w->last_facechange[CURRENT_DISP]) >= BUF_FACECHANGE (b))
|
|
4904 {
|
|
4905 new_point = point_at_center (w, CURRENT_DISP, 0, 0);
|
|
4906
|
844
|
4907 /* #### Here we are checking the selected window of the frame
|
|
4908 instead of the selected window period. Elsewhere we check
|
|
4909 the selected window of the device. What a mess! */
|
428
|
4910 if (selected)
|
|
4911 BUF_SET_PT (b, new_point);
|
|
4912 else
|
|
4913 Fset_window_point (window, make_int (new_point));
|
|
4914
|
|
4915 retval = line_at_center (w, CURRENT_DISP, 0, 0);
|
|
4916 }
|
|
4917 else
|
|
4918 {
|
|
4919 start = marker_position (w->start[CURRENT_DISP]);
|
|
4920 if (start < BUF_BEGV (b))
|
|
4921 start = BUF_BEGV (b);
|
|
4922 else if (start > BUF_ZV (b))
|
|
4923 start = BUF_ZV (b);
|
|
4924
|
|
4925 if (selected)
|
|
4926 new_point = BUF_PT (b);
|
|
4927 else
|
|
4928 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4929
|
|
4930 new_point = point_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4931
|
|
4932 if (selected)
|
|
4933 BUF_SET_PT (b, new_point);
|
|
4934 else
|
|
4935 Fset_window_point (window, make_int (new_point));
|
|
4936
|
|
4937 retval = line_at_center (w, CMOTION_DISP, start, BUF_PT (b));
|
|
4938 }
|
|
4939
|
|
4940 return make_int (retval);
|
|
4941 }
|
|
4942 else
|
|
4943 {
|
|
4944 /* #### Is this going to work right when at eob? */
|
|
4945 arg = Fprefix_numeric_value (arg);
|
|
4946 if (XINT (arg) < 0)
|
793
|
4947 arg = make_int (XINT (arg) + height);
|
428
|
4948 }
|
|
4949
|
|
4950 start = marker_position (w->start[CURRENT_DISP]);
|
|
4951 if (start < BUF_BEGV (b) || start > BUF_ZV (b))
|
|
4952 {
|
|
4953 if (selected)
|
|
4954 new_point = BUF_PT (b);
|
|
4955 else
|
|
4956 new_point = marker_position (w->pointm[CURRENT_DISP]);
|
|
4957
|
|
4958 new_point = vmotion (XWINDOW (window), new_point, -height / 2, 0);
|
|
4959
|
|
4960 if (selected)
|
|
4961 BUF_SET_PT (b, new_point);
|
|
4962 else
|
|
4963 Fset_window_point (window, make_int (new_point));
|
|
4964
|
|
4965 Fset_marker (w->start[CURRENT_DISP], make_int (new_point),
|
|
4966 w->buffer);
|
|
4967 w->start_at_line_beg = beginning_of_line_p (b, new_point);
|
|
4968 w->force_start = 1;
|
|
4969 }
|
|
4970 else
|
|
4971 {
|
|
4972 if (selected)
|
|
4973 BUF_SET_PT (b, start);
|
|
4974 else
|
|
4975 Fset_window_point (window, make_int (start));
|
|
4976 }
|
|
4977
|
|
4978 if (selected)
|
|
4979 return Fvertical_motion (arg, window, Qnil);
|
|
4980 else
|
|
4981 {
|
|
4982 int vpos;
|
|
4983 new_point = vmotion (XWINDOW (window),
|
|
4984 marker_position (w->pointm[CURRENT_DISP]),
|
|
4985 XINT (arg), &vpos);
|
|
4986 Fset_window_point (window, make_int (new_point));
|
|
4987 return make_int (vpos);
|
|
4988 }
|
|
4989 }
|
|
4990
|
|
4991
|
|
4992 static int
|
|
4993 map_windows_1 (Lisp_Object window,
|
|
4994 int (*mapfun) (struct window *w, void *closure),
|
|
4995 void *closure)
|
|
4996 {
|
|
4997 for (; !NILP (window); window = XWINDOW (window)->next)
|
|
4998 {
|
|
4999 int retval;
|
|
5000 struct window *w = XWINDOW (window);
|
|
5001
|
|
5002 if (!NILP (w->vchild))
|
|
5003 retval = map_windows_1 (w->vchild, mapfun, closure);
|
|
5004 else if (!NILP (w->hchild))
|
|
5005 retval = map_windows_1 (w->hchild, mapfun, closure);
|
|
5006 else
|
|
5007 retval = (mapfun) (w, closure);
|
|
5008
|
|
5009 if (retval)
|
|
5010 return retval;
|
|
5011 }
|
|
5012
|
|
5013 return 0;
|
|
5014 }
|
|
5015
|
|
5016 /* Map MAPFUN over the windows in F. CLOSURE is passed to each
|
|
5017 invocation of MAPFUN. If any invocation of MAPFUN returns
|
|
5018 non-zero, the mapping is halted. Otherwise, map_windows() maps
|
|
5019 over all windows in F.
|
|
5020
|
800
|
5021 If F is null, map over all frames on all devices and consoles.
|
|
5022
|
428
|
5023 If MAPFUN creates or deletes windows, the behavior is undefined. */
|
|
5024
|
|
5025 int
|
|
5026 map_windows (struct frame *f, int (*mapfun) (struct window *w, void *closure),
|
|
5027 void *closure)
|
|
5028 {
|
|
5029 if (f)
|
|
5030 return map_windows_1 (FRAME_ROOT_WINDOW (f), mapfun, closure);
|
|
5031 else
|
|
5032 {
|
|
5033 Lisp_Object frmcons, devcons, concons;
|
|
5034
|
|
5035 FRAME_LOOP_NO_BREAK(frmcons, devcons, concons)
|
|
5036 {
|
|
5037 int v = map_windows_1 (FRAME_ROOT_WINDOW (XFRAME (XCAR (frmcons))),
|
|
5038 mapfun, closure);
|
|
5039 if (v)
|
|
5040 return v;
|
|
5041 }
|
|
5042 }
|
|
5043
|
|
5044 return 0;
|
|
5045 }
|
|
5046
|
|
5047
|
|
5048 static void
|
|
5049 modeline_shadow_thickness_changed (Lisp_Object specifier, struct window *w,
|
|
5050 Lisp_Object oldval)
|
|
5051 {
|
|
5052 w->shadow_thickness_changed = 1;
|
|
5053 MARK_WINDOWS_CHANGED (w);
|
|
5054 }
|
|
5055
|
|
5056 static void
|
|
5057 vertical_divider_changed_in_window (Lisp_Object specifier,
|
|
5058 struct window *w,
|
|
5059 Lisp_Object oldval)
|
|
5060 {
|
|
5061 MARK_WINDOWS_CHANGED (w);
|
|
5062 MARK_FRAME_WINDOWS_STRUCTURE_CHANGED (XFRAME (WINDOW_FRAME (w)));
|
|
5063 }
|
|
5064
|
|
5065 /* also used in scrollbar.c */
|
|
5066 void
|
|
5067 some_window_value_changed (Lisp_Object specifier, struct window *w,
|
|
5068 Lisp_Object oldval)
|
|
5069 {
|
|
5070 MARK_WINDOWS_CHANGED (w);
|
|
5071 }
|
|
5072
|
|
5073 #ifdef MEMORY_USAGE_STATS
|
|
5074
|
|
5075 struct window_stats
|
|
5076 {
|
|
5077 int face;
|
|
5078 int glyph;
|
|
5079 #ifdef HAVE_SCROLLBARS
|
|
5080 int scrollbar;
|
|
5081 #endif
|
|
5082 int line_start;
|
|
5083 int other_redisplay;
|
|
5084 int other;
|
|
5085 };
|
|
5086
|
|
5087 static void
|
|
5088 compute_window_mirror_usage (struct window_mirror *mir,
|
|
5089 struct window_stats *stats,
|
|
5090 struct overhead_stats *ovstats)
|
|
5091 {
|
|
5092 if (!mir)
|
|
5093 return;
|
|
5094 stats->other += malloced_storage_size (mir, sizeof (struct window_mirror),
|
|
5095 ovstats);
|
|
5096 #ifdef HAVE_SCROLLBARS
|
|
5097 {
|
|
5098 struct device *d = XDEVICE (FRAME_DEVICE (mir->frame));
|
|
5099
|
|
5100 stats->scrollbar +=
|
|
5101 compute_scrollbar_instance_usage (d, mir->scrollbar_vertical_instance,
|
|
5102 ovstats);
|
|
5103 stats->scrollbar +=
|
|
5104 compute_scrollbar_instance_usage (d, mir->scrollbar_horizontal_instance,
|
|
5105 ovstats);
|
|
5106 }
|
|
5107 #endif /* HAVE_SCROLLBARS */
|
|
5108 stats->other_redisplay +=
|
|
5109 compute_display_line_dynarr_usage (mir->current_display_lines, ovstats);
|
|
5110 stats->other_redisplay +=
|
|
5111 compute_display_line_dynarr_usage (mir->desired_display_lines, ovstats);
|
|
5112 }
|
|
5113
|
|
5114 static void
|
|
5115 compute_window_usage (struct window *w, struct window_stats *stats,
|
|
5116 struct overhead_stats *ovstats)
|
|
5117 {
|
|
5118 xzero (*stats);
|
|
5119 stats->other += malloced_storage_size (w, sizeof (struct window), ovstats);
|
|
5120 stats->face += compute_face_cachel_usage (w->face_cachels, ovstats);
|
|
5121 stats->glyph += compute_glyph_cachel_usage (w->glyph_cachels, ovstats);
|
|
5122 stats->line_start +=
|
|
5123 compute_line_start_cache_dynarr_usage (w->line_start_cache, ovstats);
|
|
5124 compute_window_mirror_usage (find_window_mirror (w), stats, ovstats);
|
|
5125 }
|
|
5126
|
|
5127 DEFUN ("window-memory-usage", Fwindow_memory_usage, 1, 1, 0, /*
|
|
5128 Return stats about the memory usage of window WINDOW.
|
|
5129 The values returned are in the form of an alist of usage types and byte
|
|
5130 counts. The byte counts attempt to encompass all the memory used
|
|
5131 by the window (separate from the memory logically associated with a
|
|
5132 buffer or frame), including internal structures and any malloc()
|
|
5133 overhead associated with them. In practice, the byte counts are
|
|
5134 underestimated because certain memory usage is very hard to determine
|
|
5135 \(e.g. the amount of memory used inside the Xt library or inside the
|
|
5136 X server) and because there is other stuff that might logically
|
|
5137 be associated with a window, buffer, or frame (e.g. window configurations,
|
|
5138 glyphs) but should not obviously be included in the usage counts.
|
|
5139
|
|
5140 Multiple slices of the total memory usage may be returned, separated
|
|
5141 by a nil. Each slice represents a particular view of the memory, a
|
|
5142 particular way of partitioning it into groups. Within a slice, there
|
|
5143 is no overlap between the groups of memory, and each slice collectively
|
|
5144 represents all the memory concerned.
|
|
5145 */
|
|
5146 (window))
|
|
5147 {
|
|
5148 struct window_stats stats;
|
|
5149 struct overhead_stats ovstats;
|
|
5150 Lisp_Object val = Qnil;
|
|
5151
|
|
5152 CHECK_WINDOW (window); /* dead windows should be allowed, no? */
|
|
5153 xzero (ovstats);
|
|
5154 compute_window_usage (XWINDOW (window), &stats, &ovstats);
|
|
5155
|
|
5156 val = acons (Qface_cache, make_int (stats.face), val);
|
|
5157 val = acons (Qglyph_cache, make_int (stats.glyph), val);
|
|
5158 #ifdef HAVE_SCROLLBARS
|
|
5159 val = acons (Qscrollbar_instances, make_int (stats.scrollbar), val);
|
|
5160 #endif
|
|
5161 val = acons (Qline_start_cache, make_int (stats.line_start), val);
|
|
5162 val = acons (Qother_redisplay, make_int (stats.other_redisplay), val);
|
|
5163 val = acons (Qother, make_int (stats.other), val);
|
|
5164 val = Fcons (Qnil, val);
|
|
5165 val = acons (Qactually_requested, make_int (ovstats.was_requested), val);
|
|
5166 val = acons (Qmalloc_overhead, make_int (ovstats.malloc_overhead), val);
|
|
5167 val = acons (Qdynarr_overhead, make_int (ovstats.dynarr_overhead), val);
|
|
5168
|
|
5169 return Fnreverse (val);
|
|
5170 }
|
|
5171
|
|
5172 #endif /* MEMORY_USAGE_STATS */
|
|
5173
|
|
5174 /* Mark all subwindows of a window as deleted. The argument
|
|
5175 W is actually the subwindow tree of the window in question. */
|
|
5176
|
|
5177 void
|
|
5178 delete_all_subwindows (struct window *w)
|
|
5179 {
|
|
5180 if (!NILP (w->next)) delete_all_subwindows (XWINDOW (w->next));
|
|
5181 if (!NILP (w->vchild)) delete_all_subwindows (XWINDOW (w->vchild));
|
|
5182 if (!NILP (w->hchild)) delete_all_subwindows (XWINDOW (w->hchild));
|
|
5183
|
|
5184 mark_window_as_deleted (w);
|
|
5185 }
|
|
5186
|
|
5187 Lisp_Object
|
|
5188 save_window_excursion_unwind (Lisp_Object window_config)
|
|
5189 {
|
1149
|
5190 Lisp_Object val = call1 (Qset_window_configuration, window_config);
|
428
|
5191 return val;
|
|
5192 }
|
|
5193
|
|
5194 DEFUN ("save-window-excursion", Fsave_window_excursion, 0, UNEVALLED, 0, /*
|
|
5195 Execute body, preserving window sizes and contents.
|
|
5196 Restores which buffer appears in which window, where display starts,
|
|
5197 as well as the current buffer.
|
|
5198 Does not restore the value of point in current buffer.
|
|
5199 */
|
|
5200 (args))
|
|
5201 {
|
|
5202 /* This function can GC */
|
|
5203 int speccount = specpdl_depth ();
|
|
5204
|
|
5205 record_unwind_protect (save_window_excursion_unwind,
|
1149
|
5206 call1 (Qcurrent_window_configuration, Qnil));
|
771
|
5207 return unbind_to_1 (speccount, Fprogn (args));
|
428
|
5208 }
|
1149
|
5209
|
428
|
5210 DEFUN ("current-pixel-column", Fcurrent_pixel_column, 0, 2, 0, /*
|
|
5211 Return the horizontal pixel position of POS in window.
|
|
5212 Beginning of line is column 0. This is calculated using the redisplay
|
|
5213 display tables. If WINDOW is nil, the current window is assumed.
|
|
5214 If POS is nil, point is assumed. Note that POS must be visible for
|
|
5215 a non-nil result to be returned.
|
|
5216 */
|
|
5217 (window, pos))
|
|
5218 {
|
|
5219 struct window* w = decode_window (window);
|
|
5220 display_line_dynarr *dla = window_display_lines (w, CURRENT_DISP);
|
|
5221
|
|
5222 struct display_line *dl = 0;
|
|
5223 struct display_block *db = 0;
|
|
5224 struct rune* rb = 0;
|
|
5225 int y = w->last_point_y[CURRENT_DISP];
|
|
5226 int x = w->last_point_x[CURRENT_DISP];
|
|
5227
|
|
5228 if (MINI_WINDOW_P (w))
|
|
5229 return Qnil;
|
|
5230
|
|
5231 if (y<0 || x<0 || y >= Dynarr_length (dla) || !NILP (pos))
|
|
5232 {
|
|
5233 int first_line, i;
|
665
|
5234 Charbpos point;
|
428
|
5235
|
|
5236 if (NILP (pos))
|
|
5237 pos = Fwindow_point (window);
|
438
|
5238
|
428
|
5239 CHECK_INT (pos);
|
|
5240 point = XINT (pos);
|
|
5241
|
|
5242 if (Dynarr_length (dla) && Dynarr_atp (dla, 0)->modeline)
|
|
5243 first_line = 1;
|
|
5244 else
|
|
5245 first_line = 0;
|
|
5246
|
|
5247 for (i = first_line; i < Dynarr_length (dla); i++)
|
|
5248 {
|
|
5249 dl = Dynarr_atp (dla, i);
|
|
5250 /* find the vertical location first */
|
826
|
5251 if (point >= dl->charpos && point <= dl->end_charpos)
|
428
|
5252 {
|
|
5253 db = get_display_block_from_line (dl, TEXT);
|
|
5254 for (i = 0; i < Dynarr_length (db->runes); i++)
|
|
5255 {
|
|
5256 rb = Dynarr_atp (db->runes, i);
|
826
|
5257 if (point <= rb->charpos)
|
|
5258 goto found_charpos;
|
428
|
5259 }
|
|
5260 return Qnil;
|
|
5261 }
|
|
5262 }
|
|
5263 return Qnil;
|
826
|
5264 found_charpos:
|
428
|
5265 ;
|
|
5266 }
|
|
5267 else
|
|
5268 {
|
442
|
5269 /* optimized case */
|
428
|
5270 dl = Dynarr_atp (dla, y);
|
|
5271 db = get_display_block_from_line (dl, TEXT);
|
|
5272
|
|
5273 if (x >= Dynarr_length (db->runes))
|
|
5274 return Qnil;
|
|
5275
|
|
5276 rb = Dynarr_atp (db->runes, x);
|
|
5277 }
|
|
5278
|
|
5279 return make_int (rb->xpos - WINDOW_LEFT (w));
|
|
5280 }
|
|
5281
|
|
5282
|
|
5283 #ifdef DEBUG_XEMACS
|
|
5284 /* This is short and simple in elisp, but... it was written to debug
|
|
5285 problems purely on the C side. That is where we need to call it so
|
|
5286 here it is. */
|
|
5287 static void
|
|
5288 debug_print_window (Lisp_Object window, int level)
|
|
5289 {
|
|
5290 int i;
|
|
5291 Lisp_Object child = Fwindow_first_vchild (window);
|
|
5292
|
|
5293 if (NILP (child))
|
|
5294 child = Fwindow_first_hchild (window);
|
|
5295
|
|
5296 for (i = level; i > 0; i--)
|
442
|
5297 stderr_out ("\t");
|
|
5298
|
|
5299 stderr_out ("#<window");
|
428
|
5300 {
|
|
5301 Lisp_Object buffer = XWINDOW (window)->buffer;
|
|
5302 if (!NILP (buffer) && BUFFERP (buffer))
|
442
|
5303 stderr_out (" on %s", XSTRING_DATA (XBUFFER (buffer)->name));
|
428
|
5304 }
|
442
|
5305 stderr_out (" 0x%x>", XWINDOW (window)->header.uid);
|
428
|
5306
|
|
5307 while (!NILP (child))
|
|
5308 {
|
|
5309 debug_print_window (child, level + 1);
|
|
5310 child = Fwindow_next_child (child);
|
|
5311 }
|
|
5312 }
|
|
5313
|
|
5314 void debug_print_windows (struct frame *f);
|
|
5315 void
|
|
5316 debug_print_windows (struct frame *f)
|
|
5317 {
|
|
5318 debug_print_window (f->root_window, 0);
|
|
5319 putc ('\n', stderr);
|
|
5320 }
|
|
5321 #endif /* DEBUG_XEMACS */
|
|
5322
|
|
5323
|
|
5324 /************************************************************************/
|
|
5325 /* initialization */
|
|
5326 /************************************************************************/
|
|
5327
|
|
5328 void
|
|
5329 syms_of_window (void)
|
|
5330 {
|
442
|
5331 INIT_LRECORD_IMPLEMENTATION (window);
|
617
|
5332 INIT_LRECORD_IMPLEMENTATION (window_mirror);
|
442
|
5333
|
563
|
5334 DEFSYMBOL (Qwindowp);
|
|
5335 DEFSYMBOL (Qwindow_live_p);
|
|
5336 DEFSYMBOL (Qdisplay_buffer);
|
428
|
5337
|
|
5338 #ifdef MEMORY_USAGE_STATS
|
563
|
5339 DEFSYMBOL (Qface_cache);
|
|
5340 DEFSYMBOL (Qglyph_cache);
|
|
5341 DEFSYMBOL (Qline_start_cache);
|
428
|
5342 #ifdef HAVE_SCROLLBARS
|
563
|
5343 DEFSYMBOL (Qscrollbar_instances);
|
428
|
5344 #endif
|
563
|
5345 DEFSYMBOL (Qother_redisplay);
|
428
|
5346 /* Qother in general.c */
|
|
5347 #endif
|
|
5348
|
707
|
5349 DEFSYMBOL (Qtruncate_partial_width_windows);
|
1149
|
5350 DEFSYMBOL (Qcurrent_window_configuration);
|
|
5351 DEFSYMBOL (Qset_window_configuration);
|
707
|
5352
|
428
|
5353 DEFSUBR (Fselected_window);
|
|
5354 DEFSUBR (Flast_nonminibuf_window);
|
|
5355 DEFSUBR (Fminibuffer_window);
|
|
5356 DEFSUBR (Fwindow_minibuffer_p);
|
|
5357 DEFSUBR (Fwindowp);
|
|
5358 DEFSUBR (Fwindow_live_p);
|
|
5359 DEFSUBR (Fwindow_first_hchild);
|
|
5360 DEFSUBR (Fwindow_first_vchild);
|
|
5361 DEFSUBR (Fwindow_next_child);
|
|
5362 DEFSUBR (Fwindow_previous_child);
|
|
5363 DEFSUBR (Fwindow_parent);
|
|
5364 DEFSUBR (Fwindow_lowest_p);
|
|
5365 DEFSUBR (Fwindow_truncated_p);
|
|
5366 DEFSUBR (Fwindow_highest_p);
|
|
5367 DEFSUBR (Fwindow_leftmost_p);
|
|
5368 DEFSUBR (Fwindow_rightmost_p);
|
|
5369 DEFSUBR (Fpos_visible_in_window_p);
|
|
5370 DEFSUBR (Fwindow_buffer);
|
|
5371 DEFSUBR (Fwindow_frame);
|
|
5372 DEFSUBR (Fwindow_height);
|
|
5373 DEFSUBR (Fwindow_displayed_height);
|
|
5374 DEFSUBR (Fwindow_width);
|
442
|
5375 DEFSUBR (Fwindow_full_width);
|
428
|
5376 DEFSUBR (Fwindow_pixel_height);
|
|
5377 DEFSUBR (Fwindow_pixel_width);
|
442
|
5378 DEFSUBR (Fwindow_text_area_height);
|
428
|
5379 DEFSUBR (Fwindow_text_area_pixel_height);
|
|
5380 DEFSUBR (Fwindow_displayed_text_pixel_height);
|
|
5381 DEFSUBR (Fwindow_text_area_pixel_width);
|
|
5382 DEFSUBR (Fwindow_hscroll);
|
438
|
5383 DEFSUBR (Fset_window_hscroll);
|
428
|
5384 DEFSUBR (Fmodeline_hscroll);
|
|
5385 DEFSUBR (Fset_modeline_hscroll);
|
|
5386 DEFSUBR (Fwindow_pixel_edges);
|
|
5387 DEFSUBR (Fwindow_text_area_pixel_edges);
|
|
5388 DEFSUBR (Fwindow_point);
|
|
5389 DEFSUBR (Fwindow_start);
|
|
5390 DEFSUBR (Fwindow_end);
|
442
|
5391 DEFSUBR (Fwindow_last_line_visible_height);
|
428
|
5392 DEFSUBR (Fset_window_point);
|
|
5393 DEFSUBR (Fset_window_start);
|
|
5394 DEFSUBR (Fwindow_dedicated_p);
|
|
5395 DEFSUBR (Fset_window_dedicated_p);
|
|
5396 DEFSUBR (Fnext_window);
|
|
5397 DEFSUBR (Fprevious_window);
|
|
5398 DEFSUBR (Fnext_vertical_window);
|
|
5399 DEFSUBR (Fother_window);
|
|
5400 DEFSUBR (Fget_lru_window);
|
|
5401 DEFSUBR (Fget_largest_window);
|
|
5402 DEFSUBR (Fget_buffer_window);
|
|
5403 DEFSUBR (Fwindow_left_margin_pixel_width);
|
|
5404 DEFSUBR (Fwindow_right_margin_pixel_width);
|
|
5405 DEFSUBR (Fdelete_other_windows);
|
|
5406 DEFSUBR (Fdelete_windows_on);
|
|
5407 DEFSUBR (Freplace_buffer_in_windows);
|
|
5408 DEFSUBR (Fdelete_window);
|
|
5409 DEFSUBR (Fset_window_buffer);
|
|
5410 DEFSUBR (Fselect_window);
|
|
5411 DEFSUBR (Fsplit_window);
|
|
5412 DEFSUBR (Fenlarge_window);
|
|
5413 DEFSUBR (Fenlarge_window_pixels);
|
|
5414 DEFSUBR (Fshrink_window);
|
|
5415 DEFSUBR (Fshrink_window_pixels);
|
|
5416 DEFSUBR (Fscroll_up);
|
|
5417 DEFSUBR (Fscroll_down);
|
|
5418 DEFSUBR (Fscroll_left);
|
|
5419 DEFSUBR (Fscroll_right);
|
|
5420 DEFSUBR (Fother_window_for_scrolling);
|
|
5421 DEFSUBR (Fscroll_other_window);
|
|
5422 DEFSUBR (Fcenter_to_window_line);
|
|
5423 DEFSUBR (Fmove_to_window_line);
|
|
5424 #ifdef MEMORY_USAGE_STATS
|
|
5425 DEFSUBR (Fwindow_memory_usage);
|
|
5426 #endif
|
|
5427 DEFSUBR (Fsave_window_excursion);
|
|
5428 DEFSUBR (Fcurrent_pixel_column);
|
|
5429 }
|
|
5430
|
|
5431 void
|
|
5432 reinit_vars_of_window (void)
|
|
5433 {
|
|
5434 /* Make sure all windows get marked */
|
|
5435 minibuf_window = Qnil;
|
|
5436 staticpro_nodump (&minibuf_window);
|
|
5437 }
|
|
5438
|
|
5439 void
|
|
5440 vars_of_window (void)
|
|
5441 {
|
|
5442 reinit_vars_of_window ();
|
|
5443
|
|
5444 DEFVAR_BOOL ("scroll-on-clipped-lines", &scroll_on_clipped_lines /*
|
|
5445 *Non-nil means to scroll if point lands on a line which is clipped.
|
|
5446 */ );
|
|
5447 scroll_on_clipped_lines = 1;
|
|
5448
|
|
5449 DEFVAR_LISP ("temp-buffer-show-function", &Vtemp_buffer_show_function /*
|
|
5450 Non-nil means call as function to display a help buffer.
|
|
5451 The function is called with one argument, the buffer to be displayed.
|
|
5452 Used by `with-output-to-temp-buffer'.
|
|
5453 If this function is used, then it must do the entire job of showing
|
|
5454 the buffer; `temp-buffer-show-hook' is not run unless this function runs it.
|
442
|
5455 \(`temp-buffer-show-hook' is obsolete. Do not use in new code.)
|
428
|
5456 */ );
|
|
5457 Vtemp_buffer_show_function = Qnil;
|
|
5458
|
|
5459 DEFVAR_LISP ("minibuffer-scroll-window", &Vminibuffer_scroll_window /*
|
|
5460 Non-nil means it is the window that \\<minibuffer-local-map>\\[scroll-other-window] in minibuffer should scroll.
|
|
5461 */ );
|
|
5462 Vminibuffer_scroll_window = Qnil;
|
|
5463
|
|
5464 DEFVAR_LISP ("other-window-scroll-buffer", &Vother_window_scroll_buffer /*
|
|
5465 If non-nil, this is a buffer and \\[scroll-other-window] should scroll its window.
|
|
5466 */ );
|
|
5467 Vother_window_scroll_buffer = Qnil;
|
|
5468
|
|
5469 DEFVAR_LISP ("window-pixel-scroll-increment", &Vwindow_pixel_scroll_increment /*
|
|
5470 *Number of pixels to scroll by per requested line.
|
|
5471 If nil then normal line scrolling occurs regardless of line height.
|
|
5472 If t then scrolling is done in increments equal to the height of the default face.
|
|
5473 */ );
|
|
5474 Vwindow_pixel_scroll_increment = Qt;
|
|
5475
|
|
5476 DEFVAR_INT ("next-screen-context-lines", &next_screen_context_lines /*
|
|
5477 *Number of lines of continuity when scrolling by screenfuls.
|
|
5478 */ );
|
|
5479 next_screen_context_lines = 2;
|
|
5480
|
|
5481 DEFVAR_INT ("window-min-height", &window_min_height /*
|
|
5482 *Delete any window less than this tall (including its modeline).
|
|
5483 */ );
|
|
5484 window_min_height = 4;
|
|
5485
|
|
5486 DEFVAR_INT ("window-min-width", &window_min_width /*
|
|
5487 *Delete any window less than this wide.
|
|
5488 */ );
|
|
5489 window_min_width = 10;
|
|
5490 }
|
|
5491
|
|
5492 void
|
|
5493 specifier_vars_of_window (void)
|
|
5494 {
|
|
5495 DEFVAR_SPECIFIER ("modeline-shadow-thickness", &Vmodeline_shadow_thickness /*
|
|
5496 *How thick to draw 3D shadows around modelines.
|
|
5497 If this is set to 0, modelines will be the traditional 2D. Sizes above
|
|
5498 10 will be accepted but the maximum thickness that will be drawn is 10.
|
|
5499 This is a specifier; use `set-specifier' to change it.
|
|
5500 */ );
|
|
5501 Vmodeline_shadow_thickness = Fmake_specifier (Qinteger);
|
|
5502 /* The initial value for modeline-shadow-thickness is 2, but if the
|
|
5503 user removes all specifications we provide a fallback value of 0,
|
|
5504 which is probably what was expected. */
|
|
5505 set_specifier_fallback (Vmodeline_shadow_thickness,
|
|
5506 list1 (Fcons (Qnil, Qzero)));
|
|
5507 Fadd_spec_to_specifier (Vmodeline_shadow_thickness, make_int (2),
|
|
5508 Qnil, Qnil, Qnil);
|
|
5509 set_specifier_caching (Vmodeline_shadow_thickness,
|
438
|
5510 offsetof (struct window, modeline_shadow_thickness),
|
428
|
5511 modeline_shadow_thickness_changed,
|
444
|
5512 0, 0, 0);
|
428
|
5513
|
|
5514 DEFVAR_SPECIFIER ("has-modeline-p", &Vhas_modeline_p /*
|
|
5515 *Whether the modeline should be displayed.
|
|
5516 This is a specifier; use `set-specifier' to change it.
|
|
5517 */ );
|
|
5518 Vhas_modeline_p = Fmake_specifier (Qboolean);
|
|
5519 set_specifier_fallback (Vhas_modeline_p,
|
|
5520 list1 (Fcons (Qnil, Qt)));
|
|
5521 set_specifier_caching (Vhas_modeline_p,
|
438
|
5522 offsetof (struct window, has_modeline_p),
|
428
|
5523 /* #### It's strange that we need a special
|
|
5524 flag to indicate that the shadow-thickness
|
|
5525 has changed, but not one to indicate that
|
|
5526 the modeline has been turned off or on. */
|
|
5527 some_window_value_changed,
|
444
|
5528 0, 0, 0);
|
428
|
5529
|
|
5530 DEFVAR_SPECIFIER ("vertical-divider-always-visible-p",
|
|
5531 &Vvertical_divider_always_visible_p /*
|
|
5532 *Should XEmacs always display vertical dividers between windows.
|
|
5533
|
|
5534 When this is non-nil, vertical dividers are always shown, and are
|
|
5535 draggable. When it is nil, vertical dividers are shown only when
|
|
5536 there are no scrollbars in between windows, and are not draggable.
|
|
5537
|
|
5538 This is a specifier; use `set-specifier' to change it.
|
|
5539 */ );
|
|
5540 Vvertical_divider_always_visible_p = Fmake_specifier (Qboolean);
|
|
5541 set_specifier_fallback (Vvertical_divider_always_visible_p,
|
|
5542 list1 (Fcons (Qnil, Qt)));
|
|
5543 set_specifier_caching (Vvertical_divider_always_visible_p,
|
438
|
5544 offsetof (struct window,
|
|
5545 vertical_divider_always_visible_p),
|
428
|
5546 vertical_divider_changed_in_window,
|
444
|
5547 0, 0, 0);
|
428
|
5548
|
|
5549 DEFVAR_SPECIFIER ("vertical-divider-shadow-thickness", &Vvertical_divider_shadow_thickness /*
|
|
5550 *How thick to draw 3D shadows around vertical dividers.
|
|
5551 This is a specifier; use `set-specifier' to change it.
|
|
5552 */ );
|
|
5553 Vvertical_divider_shadow_thickness = Fmake_specifier (Qinteger);
|
|
5554 set_specifier_fallback (Vvertical_divider_shadow_thickness,
|
|
5555 list1 (Fcons (Qnil, Qzero)));
|
|
5556 Fadd_spec_to_specifier (Vvertical_divider_shadow_thickness, make_int (2),
|
|
5557 Qnil, Qnil, Qnil);
|
|
5558 set_specifier_caching (Vvertical_divider_shadow_thickness,
|
438
|
5559 offsetof (struct window,
|
|
5560 vertical_divider_shadow_thickness),
|
428
|
5561 vertical_divider_changed_in_window,
|
444
|
5562 0, 0, 0);
|
428
|
5563 DEFVAR_SPECIFIER ("vertical-divider-line-width", &Vvertical_divider_line_width /*
|
|
5564 *The width of the vertical dividers, not including shadows.
|
|
5565
|
|
5566 For TTY windows, divider line is always one character wide. When
|
|
5567 instance of this specifier is zero in a TTY window, no divider is
|
|
5568 drawn at all between windows. When non-zero, a one character wide
|
|
5569 divider is displayed.
|
|
5570
|
|
5571 This is a specifier; use `set-specifier' to change it.
|
|
5572 */ );
|
|
5573
|
|
5574 Vvertical_divider_line_width = Fmake_specifier (Qnatnum);
|
|
5575 {
|
|
5576 Lisp_Object fb = Qnil;
|
|
5577 #ifdef HAVE_TTY
|
|
5578 fb = Fcons (Fcons (list1 (Qtty), make_int (1)), fb);
|
|
5579 #endif
|
462
|
5580 #ifdef HAVE_GTK
|
|
5581 fb = Fcons (Fcons (list1 (Qgtk), make_int (3)), fb);
|
|
5582 #endif
|
428
|
5583 #ifdef HAVE_X_WINDOWS
|
|
5584 fb = Fcons (Fcons (list1 (Qx), make_int (3)), fb);
|
|
5585 #endif
|
|
5586 #ifdef HAVE_MS_WINDOWS
|
|
5587 /* #### This should be made magic and made to obey system settings */
|
|
5588 fb = Fcons (Fcons (list1 (Qmswindows), make_int (3)), fb);
|
|
5589 #endif
|
|
5590 set_specifier_fallback (Vvertical_divider_line_width, fb);
|
|
5591 }
|
|
5592 set_specifier_caching (Vvertical_divider_line_width,
|
438
|
5593 offsetof (struct window,
|
|
5594 vertical_divider_line_width),
|
428
|
5595 vertical_divider_changed_in_window,
|
444
|
5596 0, 0, 0);
|
428
|
5597
|
|
5598 DEFVAR_SPECIFIER ("vertical-divider-spacing", &Vvertical_divider_spacing /*
|
|
5599 *How much space to leave around the vertical dividers.
|
|
5600
|
|
5601 In TTY windows, spacing is always zero, and the value of this
|
|
5602 specifier is ignored.
|
|
5603
|
|
5604 This is a specifier; use `set-specifier' to change it.
|
|
5605 */ );
|
|
5606 Vvertical_divider_spacing = Fmake_specifier (Qnatnum);
|
|
5607 {
|
|
5608 Lisp_Object fb = Qnil;
|
|
5609 #ifdef HAVE_TTY
|
|
5610 fb = Fcons (Fcons (list1 (Qtty), Qzero), fb);
|
|
5611 #endif
|
|
5612 #ifdef HAVE_X_WINDOWS
|
|
5613 /* #### 3D dividers look great on MS Windows with spacing = 0.
|
|
5614 Should not the same value be the fallback under X? - kkm */
|
|
5615 fb = Fcons (Fcons (list1 (Qx), make_int (2)), fb);
|
|
5616 #endif
|
462
|
5617 #ifdef HAVE_GTK
|
|
5618 fb = Fcons (Fcons (list1 (Qgtk), Qzero), fb);
|
|
5619 #endif
|
428
|
5620 #ifdef HAVE_MS_WINDOWS
|
|
5621 fb = Fcons (Fcons (list1 (Qmswindows), Qzero), fb);
|
|
5622 #endif
|
|
5623 set_specifier_fallback (Vvertical_divider_spacing, fb);
|
|
5624 }
|
|
5625 set_specifier_caching (Vvertical_divider_spacing,
|
438
|
5626 offsetof (struct window, vertical_divider_spacing),
|
428
|
5627 vertical_divider_changed_in_window,
|
444
|
5628 0, 0, 0);
|
|
5629 }
|