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