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