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