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