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