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