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