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