Commit | Line | Data |
---|---|---|
a2889657 | 1 | /* Display generation from window structure and buffer text. |
5f5c8ee5 GM |
2 | Copyright (C) 1985, 86, 87, 88, 93, 94, 95, 97, 98, 99 |
3 | Free Software Foundation, Inc. | |
a2889657 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
b1d1124b | 9 | the Free Software Foundation; either version 2, or (at your option) |
a2889657 JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
a2889657 | 21 | |
5f5c8ee5 GM |
22 | /* New redisplay written by Gerd Moellmann <gerd@gnu.org>. |
23 | ||
24 | Redisplay. | |
25 | ||
26 | Emacs separates the task of updating the display from code | |
27 | modifying global state, e.g. buffer text. This way functions | |
28 | operating on buffers don't also have to be concerned with updating | |
29 | the display. | |
30 | ||
31 | Updating the display is triggered by the Lisp interpreter when it | |
32 | decides it's time to do it. This is done either automatically for | |
33 | you as part of the interpreter's command loop or as the result of | |
34 | calling Lisp functions like `sit-for'. The C function `redisplay' | |
35 | in xdisp.c is the only entry into the inner redisplay code. (Or, | |
36 | let's say almost---see the the description of direct update | |
37 | operations, below.). | |
38 | ||
39 | The following diagram shows how redisplay code is invoked. As you | |
40 | can see, Lisp calls redisplay and vice versa. Under window systems | |
41 | like X, some portions of the redisplay code are also called | |
42 | asynchronously during mouse movement or expose events. It is very | |
43 | important that these code parts do NOT use the C library (malloc, | |
44 | free) because many C libraries under Unix are not reentrant. They | |
45 | may also NOT call functions of the Lisp interpreter which could | |
46 | change the interpreter's state. If you don't follow these rules, | |
47 | you will encounter bugs which are very hard to explain. | |
48 | ||
49 | (Direct functions, see below) | |
50 | direct_output_for_insert, | |
51 | direct_forward_char (dispnew.c) | |
52 | +---------------------------------+ | |
53 | | | | |
54 | | V | |
55 | +--------------+ redisplay() +----------------+ | |
56 | | Lisp machine |---------------->| Redisplay code |<--+ | |
57 | +--------------+ (xdisp.c) +----------------+ | | |
58 | ^ | | | |
59 | +----------------------------------+ | | |
60 | Don't use this path when called | | |
61 | asynchronously! | | |
62 | | | |
63 | expose_window (asynchronous) | | |
64 | | | |
65 | X expose events -----+ | |
66 | ||
67 | What does redisplay? Obviously, it has to figure out somehow what | |
68 | has been changed since the last time the display has been updated, | |
69 | and to make these changes visible. Preferably it would do that in | |
70 | a moderately intelligent way, i.e. fast. | |
71 | ||
72 | Changes in buffer text can be deduced from window and buffer | |
73 | structures, and from some global variables like `beg_unchanged' and | |
74 | `end_unchanged'. The contents of the display are additionally | |
75 | recorded in a `glyph matrix', a two-dimensional matrix of glyph | |
76 | structures. Each row in such a matrix corresponds to a line on the | |
77 | display, and each glyph in a row corresponds to a column displaying | |
78 | a character, an image, or what else. This matrix is called the | |
79 | `current glyph matrix' or `current matrix' in redisplay | |
80 | terminology. | |
81 | ||
82 | For buffer parts that have been changed since the last update, a | |
83 | second glyph matrix is constructed, the so called `desired glyph | |
84 | matrix' or short `desired matrix'. Current and desired matrix are | |
85 | then compared to find a cheap way to update the display, e.g. by | |
86 | reusing part of the display by scrolling lines. | |
87 | ||
88 | ||
89 | Direct operations. | |
90 | ||
91 | You will find a lot of of redisplay optimizations when you start | |
92 | looking at the innards of redisplay. The overall goal of all these | |
93 | optimizations is to make redisplay fast because it is done | |
94 | frequently. | |
95 | ||
96 | Two optimizations are not found in xdisp.c. These are the direct | |
97 | operations mentioned above. As the name suggests they follow a | |
98 | different principle than the rest of redisplay. Instead of | |
99 | building a desired matrix and then comparing it with the current | |
100 | display, they perform their actions directly on the display and on | |
101 | the current matrix. | |
102 | ||
103 | One direct operation updates the display after one character has | |
104 | been entered. The other one moves the cursor by one position | |
105 | forward or backward. You find these functions under the names | |
106 | `direct_output_for_insert' and `direct_output_forward_char' in | |
107 | dispnew.c. | |
108 | ||
109 | ||
110 | Desired matrices. | |
111 | ||
112 | Desired matrices are always built per Emacs window. The function | |
113 | `display_line' is the central function to look at if you are | |
114 | interested. It constructs one row in a desired matrix given an | |
115 | iterator structure containing both a buffer position and a | |
116 | description of the environment in which the text is to be | |
117 | displayed. But this is too early, read on. | |
118 | ||
119 | Characters and pixmaps displayed for a range of buffer text depend | |
120 | on various settings of buffers and windows, on overlays and text | |
121 | properties, on display tables, on selective display. The good news | |
122 | is that all this hairy stuff is hidden behind a small set of | |
123 | interface functions taking a iterator structure (struct it) | |
124 | argument. | |
125 | ||
126 | Iteration over things to be be displayed is then simple. It is | |
127 | started by initializing an iterator with a call to init_iterator | |
128 | (or init_string_iterator for that matter). Calls to | |
129 | get_next_display_element fill the iterator structure with relevant | |
130 | information about the next thing to display. Calls to | |
131 | set_iterator_to_next move the iterator to the next thing. | |
132 | ||
133 | Besides this, an iterator also contains information about the | |
134 | display environment in which glyphs for display elements are to be | |
135 | produced. It has fields for the width and height of the display, | |
136 | the information whether long lines are truncated or continued, a | |
137 | current X and Y position, and lots of other stuff you can better | |
138 | see in dispextern.h. | |
139 | ||
140 | Glyphs in a desired matrix are normally constructed in a loop | |
141 | calling get_next_display_element and then produce_glyphs. The call | |
142 | to produce_glyphs will fill the iterator structure with pixel | |
143 | information about the element being displayed and at the same time | |
144 | produce glyphs for it. If the display element fits on the line | |
145 | being displayed, set_iterator_to_next is called next, otherwise the | |
146 | glyphs produced are discarded. | |
147 | ||
148 | ||
149 | Frame matrices. | |
150 | ||
151 | That just couldn't be all, could it? What about terminal types not | |
152 | supporting operations on sub-windows of the screen? To update the | |
153 | display on such a terminal, window-based glyph matrices are not | |
154 | well suited. To be able to reuse part of the display (scrolling | |
155 | lines up and down), we must instead have a view of the whole | |
156 | screen. This is what `frame matrices' are for. They are a trick. | |
157 | ||
158 | Frames on terminals like above have a glyph pool. Windows on such | |
159 | a frame sub-allocate their glyph memory from their frame's glyph | |
160 | pool. The frame itself is given its own glyph matrices. By | |
161 | coincidence---or maybe something else---rows in window glyph | |
162 | matrices are slices of corresponding rows in frame matrices. Thus | |
163 | writing to window matrices implicitly updates a frame matrix which | |
164 | provides us with the view of the whole screen that we originally | |
165 | wanted to have without having to move many bytes around. To be | |
166 | honest, there is a little bit more done, but not much more. If you | |
167 | plan to extend that code, take a look at dispnew.c. The function | |
168 | build_frame_matrix is a good starting point. */ | |
a2889657 | 169 | |
18160b98 | 170 | #include <config.h> |
a2889657 | 171 | #include <stdio.h> |
a2889657 | 172 | #include "lisp.h" |
44fa5b1e | 173 | #include "frame.h" |
a2889657 JB |
174 | #include "window.h" |
175 | #include "termchar.h" | |
176 | #include "dispextern.h" | |
177 | #include "buffer.h" | |
1c9241f5 | 178 | #include "charset.h" |
a2889657 JB |
179 | #include "indent.h" |
180 | #include "commands.h" | |
181 | #include "macros.h" | |
182 | #include "disptab.h" | |
30c566e4 | 183 | #include "termhooks.h" |
b0a0fbda | 184 | #include "intervals.h" |
fe8b0cf8 | 185 | #include "keyboard.h" |
1c9241f5 KH |
186 | #include "coding.h" |
187 | #include "process.h" | |
dfcf069d AS |
188 | #include "region-cache.h" |
189 | ||
6d55d620 | 190 | #ifdef HAVE_X_WINDOWS |
dfcf069d AS |
191 | #include "xterm.h" |
192 | #endif | |
a75dfea0 AI |
193 | #ifdef WINDOWSNT |
194 | #include "w32term.h" | |
195 | #endif | |
a2889657 | 196 | |
5f5c8ee5 GM |
197 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
198 | #define max(a, b) ((a) > (b) ? (a) : (b)) | |
199 | ||
200 | #define INFINITY 10000000 | |
201 | ||
8f3343d0 | 202 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
76412d64 | 203 | extern void set_frame_menubar (); |
cd6dfed6 | 204 | extern int pending_menu_activation; |
76412d64 RS |
205 | #endif |
206 | ||
a2889657 JB |
207 | extern int interrupt_input; |
208 | extern int command_loop_level; | |
209 | ||
b6436d4e RS |
210 | extern int minibuffer_auto_raise; |
211 | ||
c4628384 RS |
212 | extern Lisp_Object Qface; |
213 | ||
399164b4 KH |
214 | extern Lisp_Object Voverriding_local_map; |
215 | extern Lisp_Object Voverriding_local_map_menu_flag; | |
5f5c8ee5 | 216 | extern Lisp_Object Qmenu_item; |
399164b4 | 217 | |
d46fb96a | 218 | Lisp_Object Qoverriding_local_map, Qoverriding_terminal_local_map; |
75c43375 | 219 | Lisp_Object Qwindow_scroll_functions, Vwindow_scroll_functions; |
e0bfbde6 | 220 | Lisp_Object Qredisplay_end_trigger_functions; |
2e54982e | 221 | Lisp_Object Qinhibit_point_motion_hooks; |
9499d71b | 222 | Lisp_Object QCeval, Qwhen, QCfile, QCdata; |
5f5c8ee5 GM |
223 | Lisp_Object Qfontified; |
224 | ||
225 | /* Functions called to fontify regions of text. */ | |
226 | ||
227 | Lisp_Object Vfontification_functions; | |
228 | Lisp_Object Qfontification_functions; | |
229 | ||
e037b9ec | 230 | /* Non-zero means draw tool bar buttons raised when the mouse moves |
5f5c8ee5 GM |
231 | over them. */ |
232 | ||
e037b9ec | 233 | int auto_raise_tool_bar_buttons_p; |
5f5c8ee5 | 234 | |
e037b9ec | 235 | /* Margin around tool bar buttons in pixels. */ |
5f5c8ee5 | 236 | |
e037b9ec | 237 | int tool_bar_button_margin; |
5f5c8ee5 | 238 | |
e037b9ec | 239 | /* Thickness of shadow to draw around tool bar buttons. */ |
5f5c8ee5 | 240 | |
e037b9ec | 241 | int tool_bar_button_relief; |
5f5c8ee5 | 242 | |
e037b9ec | 243 | /* Non-zero means automatically resize tool-bars so that all tool-bar |
5f5c8ee5 GM |
244 | items are visible, and no blank lines remain. */ |
245 | ||
e037b9ec | 246 | int auto_resize_tool_bars_p; |
399164b4 | 247 | |
735c094c KH |
248 | /* Non-nil means don't actually do any redisplay. */ |
249 | ||
250 | Lisp_Object Vinhibit_redisplay, Qinhibit_redisplay; | |
251 | ||
5f5c8ee5 GM |
252 | /* Names of text properties relevant for redisplay. */ |
253 | ||
a7e27ef7 DL |
254 | Lisp_Object Qdisplay, Qrelative_width, Qalign_to; |
255 | extern Lisp_Object Qface, Qinvisible, Qimage, Qwidth; | |
5f5c8ee5 GM |
256 | |
257 | /* Symbols used in text property values. */ | |
258 | ||
259 | Lisp_Object Qspace, QCalign_to, QCrelative_width, QCrelative_height; | |
a7e27ef7 | 260 | Lisp_Object Qleft_margin, Qright_margin, Qspace_width, Qraise; |
f3751a65 | 261 | Lisp_Object Qmargin; |
a7e27ef7 | 262 | extern Lisp_Object Qheight; |
5f5c8ee5 | 263 | |
8f897821 | 264 | /* Non-nil means highlight trailing whitespace. */ |
5f5c8ee5 | 265 | |
8f897821 | 266 | Lisp_Object Vshow_trailing_whitespace; |
5f5c8ee5 GM |
267 | |
268 | /* Name of the face used to highlight trailing whitespace. */ | |
269 | ||
270 | Lisp_Object Qtrailing_whitespace; | |
271 | ||
272 | /* The symbol `image' which is the car of the lists used to represent | |
273 | images in Lisp. */ | |
274 | ||
275 | Lisp_Object Qimage; | |
276 | ||
277 | /* Non-zero means print newline to stdout before next mini-buffer | |
278 | message. */ | |
a2889657 JB |
279 | |
280 | int noninteractive_need_newline; | |
281 | ||
5f5c8ee5 | 282 | /* Non-zero means print newline to message log before next message. */ |
f88eb0b6 | 283 | |
3c6595e0 | 284 | static int message_log_need_newline; |
f88eb0b6 | 285 | |
5f5c8ee5 GM |
286 | \f |
287 | /* The buffer position of the first character appearing entirely or | |
288 | partially on the line of the selected window which contains the | |
289 | cursor; <= 0 if not known. Set by set_cursor_from_row, used for | |
290 | redisplay optimization in redisplay_internal. */ | |
a2889657 | 291 | |
5f5c8ee5 | 292 | static struct text_pos this_line_start_pos; |
a2889657 | 293 | |
5f5c8ee5 GM |
294 | /* Number of characters past the end of the line above, including the |
295 | terminating newline. */ | |
296 | ||
297 | static struct text_pos this_line_end_pos; | |
298 | ||
299 | /* The vertical positions and the height of this line. */ | |
a2889657 | 300 | |
a2889657 | 301 | static int this_line_vpos; |
5f5c8ee5 GM |
302 | static int this_line_y; |
303 | static int this_line_pixel_height; | |
304 | ||
305 | /* X position at which this display line starts. Usually zero; | |
306 | negative if first character is partially visible. */ | |
307 | ||
308 | static int this_line_start_x; | |
a2889657 | 309 | |
5f5c8ee5 | 310 | /* Buffer that this_line_.* variables are referring to. */ |
a2889657 | 311 | |
a2889657 JB |
312 | static struct buffer *this_line_buffer; |
313 | ||
5f5c8ee5 GM |
314 | /* Nonzero means truncate lines in all windows less wide than the |
315 | frame. */ | |
a2889657 | 316 | |
a2889657 JB |
317 | int truncate_partial_width_windows; |
318 | ||
7bbe686f | 319 | /* A flag to control how to display unibyte 8-bit character. */ |
5f5c8ee5 | 320 | |
7bbe686f | 321 | int unibyte_display_via_language_environment; |
5f5c8ee5 GM |
322 | |
323 | /* Nonzero means we have more than one non-mini-buffer-only frame. | |
324 | Not guaranteed to be accurate except while parsing | |
325 | frame-title-format. */ | |
7bbe686f | 326 | |
d39b6696 KH |
327 | int multiple_frames; |
328 | ||
a2889657 JB |
329 | Lisp_Object Vglobal_mode_string; |
330 | ||
331 | /* Marker for where to display an arrow on top of the buffer text. */ | |
5f5c8ee5 | 332 | |
a2889657 JB |
333 | Lisp_Object Voverlay_arrow_position; |
334 | ||
5f5c8ee5 GM |
335 | /* String to display for the arrow. Only used on terminal frames. */ |
336 | ||
a2889657 JB |
337 | Lisp_Object Voverlay_arrow_string; |
338 | ||
5f5c8ee5 GM |
339 | /* Values of those variables at last redisplay. However, if |
340 | Voverlay_arrow_position is a marker, last_arrow_position is its | |
341 | numerical position. */ | |
342 | ||
d45de95b RS |
343 | static Lisp_Object last_arrow_position, last_arrow_string; |
344 | ||
5f5c8ee5 GM |
345 | /* Like mode-line-format, but for the title bar on a visible frame. */ |
346 | ||
d39b6696 KH |
347 | Lisp_Object Vframe_title_format; |
348 | ||
5f5c8ee5 GM |
349 | /* Like mode-line-format, but for the title bar on an iconified frame. */ |
350 | ||
d39b6696 KH |
351 | Lisp_Object Vicon_title_format; |
352 | ||
08b610e4 RS |
353 | /* List of functions to call when a window's size changes. These |
354 | functions get one arg, a frame on which one or more windows' sizes | |
355 | have changed. */ | |
5f5c8ee5 | 356 | |
08b610e4 RS |
357 | static Lisp_Object Vwindow_size_change_functions; |
358 | ||
cf074754 RS |
359 | Lisp_Object Qmenu_bar_update_hook; |
360 | ||
a2889657 | 361 | /* Nonzero if overlay arrow has been displayed once in this window. */ |
a2889657 | 362 | |
5f5c8ee5 | 363 | static int overlay_arrow_seen; |
ca26e1c8 | 364 | |
fba9ce76 | 365 | /* Nonzero means highlight the region even in nonselected windows. */ |
fba9ce76 | 366 | |
5f5c8ee5 GM |
367 | int highlight_nonselected_windows; |
368 | ||
369 | /* If cursor motion alone moves point off frame, try scrolling this | |
370 | many lines up or down if that will bring it back. */ | |
371 | ||
14510fee | 372 | static int scroll_step; |
a2889657 | 373 | |
5f5c8ee5 GM |
374 | /* Non-0 means scroll just far enough to bring point back on the |
375 | screen, when appropriate. */ | |
376 | ||
0789adb2 RS |
377 | static int scroll_conservatively; |
378 | ||
5f5c8ee5 GM |
379 | /* Recenter the window whenever point gets within this many lines of |
380 | the top or bottom of the window. This value is translated into a | |
381 | pixel value by multiplying it with CANON_Y_UNIT, which means that | |
382 | there is really a fixed pixel height scroll margin. */ | |
383 | ||
9afd2168 RS |
384 | int scroll_margin; |
385 | ||
5f5c8ee5 GM |
386 | /* Number of windows showing the buffer of the selected window (or |
387 | another buffer with the same base buffer). keyboard.c refers to | |
388 | this. */ | |
a2889657 | 389 | |
a2889657 JB |
390 | int buffer_shared; |
391 | ||
5f5c8ee5 | 392 | /* Vector containing glyphs for an ellipsis `...'. */ |
a2889657 | 393 | |
5f5c8ee5 | 394 | static Lisp_Object default_invis_vector[3]; |
a2889657 | 395 | |
5f5c8ee5 | 396 | /* Nonzero means display mode line highlighted. */ |
a2889657 | 397 | |
a2889657 JB |
398 | int mode_line_inverse_video; |
399 | ||
5f5c8ee5 GM |
400 | /* Prompt to display in front of the mini-buffer contents. */ |
401 | ||
8c5b6a0a | 402 | Lisp_Object minibuf_prompt; |
a2889657 | 403 | |
5f5c8ee5 GM |
404 | /* Width of current mini-buffer prompt. Only set after display_line |
405 | of the line that contains the prompt. */ | |
406 | ||
a2889657 | 407 | int minibuf_prompt_width; |
5f5c8ee5 GM |
408 | int minibuf_prompt_pixel_width; |
409 | ||
5f5c8ee5 GM |
410 | /* This is the window where the echo area message was displayed. It |
411 | is always a mini-buffer window, but it may not be the same window | |
412 | currently active as a mini-buffer. */ | |
413 | ||
73af359d RS |
414 | Lisp_Object echo_area_window; |
415 | ||
c6e89d6c GM |
416 | /* List of pairs (MESSAGE . MULTIBYTE). The function save_message |
417 | pushes the current message and the value of | |
418 | message_enable_multibyte on the stack, the function restore_message | |
419 | pops the stack and displays MESSAGE again. */ | |
420 | ||
421 | Lisp_Object Vmessage_stack; | |
422 | ||
a3788d53 RS |
423 | /* Nonzero means multibyte characters were enabled when the echo area |
424 | message was specified. */ | |
5f5c8ee5 | 425 | |
a3788d53 RS |
426 | int message_enable_multibyte; |
427 | ||
5f5c8ee5 GM |
428 | /* True if we should redraw the mode lines on the next redisplay. */ |
429 | ||
a2889657 JB |
430 | int update_mode_lines; |
431 | ||
5f5c8ee5 GM |
432 | /* Nonzero if window sizes or contents have changed since last |
433 | redisplay that finished */ | |
434 | ||
a2889657 JB |
435 | int windows_or_buffers_changed; |
436 | ||
5f5c8ee5 GM |
437 | /* Nonzero after display_mode_line if %l was used and it displayed a |
438 | line number. */ | |
439 | ||
aa6d10fa RS |
440 | int line_number_displayed; |
441 | ||
442 | /* Maximum buffer size for which to display line numbers. */ | |
5f5c8ee5 | 443 | |
14510fee | 444 | static int line_number_display_limit; |
5992c4f7 | 445 | |
5d121aec KH |
446 | /* line width to consider when repostioning for line number display */ |
447 | ||
448 | static int line_number_display_limit_width; | |
449 | ||
5f5c8ee5 GM |
450 | /* Number of lines to keep in the message log buffer. t means |
451 | infinite. nil means don't log at all. */ | |
452 | ||
5992c4f7 | 453 | Lisp_Object Vmessage_log_max; |
d45de95b | 454 | |
c6e89d6c GM |
455 | /* Current, index 0, and last displayed echo area message. Either |
456 | buffers from echo_buffers, or nil to indicate no message. */ | |
457 | ||
458 | Lisp_Object echo_area_buffer[2]; | |
459 | ||
460 | /* The buffers referenced from echo_area_buffer. */ | |
461 | ||
462 | static Lisp_Object echo_buffer[2]; | |
463 | ||
464 | /* A vector saved used in with_area_buffer to reduce consing. */ | |
465 | ||
466 | static Lisp_Object Vwith_echo_area_save_vector; | |
467 | ||
468 | /* Non-zero means display_echo_area should display the last echo area | |
469 | message again. Set by redisplay_preserve_echo_area. */ | |
470 | ||
471 | static int display_last_displayed_message_p; | |
472 | ||
473 | /* Nonzero if echo area is being used by print; zero if being used by | |
474 | message. */ | |
475 | ||
476 | int message_buf_print; | |
477 | ||
9142dd5b GM |
478 | /* Maximum height for resizing mini-windows. Either a float |
479 | specifying a fraction of the available height, or an integer | |
480 | specifying a number of lines. */ | |
c6e89d6c GM |
481 | |
482 | static Lisp_Object Vmax_mini_window_height; | |
483 | ||
d6d26ed3 GM |
484 | /* Non-zero means we want a hollow cursor in windows that are not |
485 | selected. Zero means there's no cursor in such windows. */ | |
486 | ||
487 | int cursor_in_non_selected_windows; | |
488 | ||
5f5c8ee5 GM |
489 | /* A scratch glyph row with contents used for generating truncation |
490 | glyphs. Also used in direct_output_for_insert. */ | |
12adba34 | 491 | |
5f5c8ee5 GM |
492 | #define MAX_SCRATCH_GLYPHS 100 |
493 | struct glyph_row scratch_glyph_row; | |
494 | static struct glyph scratch_glyphs[MAX_SCRATCH_GLYPHS]; | |
1adc55de | 495 | |
5f5c8ee5 GM |
496 | /* Ascent and height of the last line processed by move_it_to. */ |
497 | ||
498 | static int last_max_ascent, last_height; | |
499 | ||
500 | /* The maximum distance to look ahead for text properties. Values | |
501 | that are too small let us call compute_char_face and similar | |
502 | functions too often which is expensive. Values that are too large | |
503 | let us call compute_char_face and alike too often because we | |
504 | might not be interested in text properties that far away. */ | |
505 | ||
506 | #define TEXT_PROP_DISTANCE_LIMIT 100 | |
507 | ||
508 | /* Non-zero means print traces of redisplay if compiled with | |
509 | GLYPH_DEBUG != 0. */ | |
510 | ||
511 | #if GLYPH_DEBUG | |
512 | int trace_redisplay_p; | |
513 | #endif | |
514 | ||
d475bcb8 GM |
515 | /* Non-zero means automatically scroll windows horizontally to make |
516 | point visible. */ | |
517 | ||
518 | int automatic_hscrolling_p; | |
519 | ||
e00daaa0 GM |
520 | /* A list of symbols, one for each supported image type. */ |
521 | ||
522 | Lisp_Object Vimage_types; | |
523 | ||
5f5c8ee5 GM |
524 | /* Value returned from text property handlers (see below). */ |
525 | ||
526 | enum prop_handled | |
3c6595e0 | 527 | { |
5f5c8ee5 GM |
528 | HANDLED_NORMALLY, |
529 | HANDLED_RECOMPUTE_PROPS, | |
530 | HANDLED_OVERLAY_STRING_CONSUMED, | |
531 | HANDLED_RETURN | |
532 | }; | |
3c6595e0 | 533 | |
5f5c8ee5 GM |
534 | /* A description of text properties that redisplay is interested |
535 | in. */ | |
3c6595e0 | 536 | |
5f5c8ee5 GM |
537 | struct props |
538 | { | |
539 | /* The name of the property. */ | |
540 | Lisp_Object *name; | |
90adcf20 | 541 | |
5f5c8ee5 GM |
542 | /* A unique index for the property. */ |
543 | enum prop_idx idx; | |
544 | ||
545 | /* A handler function called to set up iterator IT from the property | |
546 | at IT's current position. Value is used to steer handle_stop. */ | |
547 | enum prop_handled (*handler) P_ ((struct it *it)); | |
548 | }; | |
549 | ||
550 | static enum prop_handled handle_face_prop P_ ((struct it *)); | |
551 | static enum prop_handled handle_invisible_prop P_ ((struct it *)); | |
552 | static enum prop_handled handle_display_prop P_ ((struct it *)); | |
260a86a0 | 553 | static enum prop_handled handle_composition_prop P_ ((struct it *)); |
5f5c8ee5 GM |
554 | static enum prop_handled handle_overlay_change P_ ((struct it *)); |
555 | static enum prop_handled handle_fontified_prop P_ ((struct it *)); | |
556 | ||
557 | /* Properties handled by iterators. */ | |
558 | ||
559 | static struct props it_props[] = | |
5992c4f7 | 560 | { |
5f5c8ee5 GM |
561 | {&Qfontified, FONTIFIED_PROP_IDX, handle_fontified_prop}, |
562 | /* Handle `face' before `display' because some sub-properties of | |
563 | `display' need to know the face. */ | |
564 | {&Qface, FACE_PROP_IDX, handle_face_prop}, | |
565 | {&Qdisplay, DISPLAY_PROP_IDX, handle_display_prop}, | |
566 | {&Qinvisible, INVISIBLE_PROP_IDX, handle_invisible_prop}, | |
260a86a0 | 567 | {&Qcomposition, COMPOSITION_PROP_IDX, handle_composition_prop}, |
5f5c8ee5 GM |
568 | {NULL, 0, NULL} |
569 | }; | |
5992c4f7 | 570 | |
5f5c8ee5 GM |
571 | /* Value is the position described by X. If X is a marker, value is |
572 | the marker_position of X. Otherwise, value is X. */ | |
12adba34 | 573 | |
5f5c8ee5 | 574 | #define COERCE_MARKER(X) (MARKERP ((X)) ? Fmarker_position (X) : (X)) |
12adba34 | 575 | |
5f5c8ee5 | 576 | /* Enumeration returned by some move_it_.* functions internally. */ |
12adba34 | 577 | |
5f5c8ee5 GM |
578 | enum move_it_result |
579 | { | |
580 | /* Not used. Undefined value. */ | |
581 | MOVE_UNDEFINED, | |
bab29e15 | 582 | |
5f5c8ee5 GM |
583 | /* Move ended at the requested buffer position or ZV. */ |
584 | MOVE_POS_MATCH_OR_ZV, | |
bab29e15 | 585 | |
5f5c8ee5 GM |
586 | /* Move ended at the requested X pixel position. */ |
587 | MOVE_X_REACHED, | |
12adba34 | 588 | |
5f5c8ee5 GM |
589 | /* Move within a line ended at the end of a line that must be |
590 | continued. */ | |
591 | MOVE_LINE_CONTINUED, | |
592 | ||
593 | /* Move within a line ended at the end of a line that would | |
594 | be displayed truncated. */ | |
595 | MOVE_LINE_TRUNCATED, | |
ff6c30e5 | 596 | |
5f5c8ee5 GM |
597 | /* Move within a line ended at a line end. */ |
598 | MOVE_NEWLINE_OR_CR | |
599 | }; | |
12adba34 | 600 | |
ff6c30e5 | 601 | |
5f5c8ee5 GM |
602 | \f |
603 | /* Function prototypes. */ | |
604 | ||
5bcfeb49 | 605 | static void ensure_echo_area_buffers P_ ((void)); |
e037b9ec GM |
606 | static struct glyph_row *row_containing_pos P_ ((struct window *, int, |
607 | struct glyph_row *, | |
608 | struct glyph_row *)); | |
c6e89d6c GM |
609 | static Lisp_Object unwind_with_echo_area_buffer P_ ((Lisp_Object)); |
610 | static Lisp_Object with_echo_area_buffer_unwind_data P_ ((struct window *)); | |
c6e89d6c GM |
611 | static void clear_garbaged_frames P_ ((void)); |
612 | static int current_message_1 P_ ((Lisp_Object *)); | |
613 | static int truncate_message_1 P_ ((int)); | |
614 | static int set_message_1 P_ ((char *s, Lisp_Object, int, int)); | |
615 | static int display_echo_area P_ ((struct window *)); | |
616 | static int display_echo_area_1 P_ ((struct window *)); | |
28514cd9 | 617 | static Lisp_Object unwind_redisplay P_ ((Lisp_Object)); |
4fdb80f2 | 618 | static int string_char_and_length P_ ((unsigned char *, int, int *)); |
5f5c8ee5 GM |
619 | static struct text_pos display_prop_end P_ ((struct it *, Lisp_Object, |
620 | struct text_pos)); | |
621 | static int compute_window_start_on_continuation_line P_ ((struct window *)); | |
622 | static Lisp_Object eval_handler P_ ((Lisp_Object)); | |
623 | static Lisp_Object eval_form P_ ((Lisp_Object)); | |
624 | static void insert_left_trunc_glyphs P_ ((struct it *)); | |
625 | static struct glyph_row *get_overlay_arrow_glyph_row P_ ((struct window *)); | |
626 | static void extend_face_to_end_of_line P_ ((struct it *)); | |
80c6cb1f | 627 | static int append_space P_ ((struct it *, int)); |
5f5c8ee5 GM |
628 | static void make_cursor_line_fully_visible P_ ((struct window *)); |
629 | static int try_scrolling P_ ((Lisp_Object, int, int, int, int)); | |
630 | static int trailing_whitespace_p P_ ((int)); | |
631 | static int message_log_check_duplicate P_ ((int, int, int, int)); | |
632 | int invisible_p P_ ((Lisp_Object, Lisp_Object)); | |
633 | int invisible_ellipsis_p P_ ((Lisp_Object, Lisp_Object)); | |
634 | static void push_it P_ ((struct it *)); | |
635 | static void pop_it P_ ((struct it *)); | |
636 | static void sync_frame_with_window_matrix_rows P_ ((struct window *)); | |
637 | static void redisplay_internal P_ ((int)); | |
c6e89d6c | 638 | static int echo_area_display P_ ((int)); |
5f5c8ee5 GM |
639 | static void redisplay_windows P_ ((Lisp_Object)); |
640 | static void redisplay_window P_ ((Lisp_Object, int)); | |
641 | static void update_menu_bar P_ ((struct frame *, int)); | |
642 | static int try_window_reusing_current_matrix P_ ((struct window *)); | |
643 | static int try_window_id P_ ((struct window *)); | |
644 | static int display_line P_ ((struct it *)); | |
645 | static void display_mode_lines P_ ((struct window *)); | |
646 | static void display_mode_line P_ ((struct window *, enum face_id, | |
647 | Lisp_Object)); | |
648 | static int display_mode_element P_ ((struct it *, int, int, int, Lisp_Object)); | |
68c45bf0 | 649 | static char *decode_mode_spec P_ ((struct window *, int, int, int)); |
5f5c8ee5 GM |
650 | static void display_menu_bar P_ ((struct window *)); |
651 | static int display_count_lines P_ ((int, int, int, int, int *)); | |
652 | static int display_string P_ ((unsigned char *, Lisp_Object, Lisp_Object, | |
653 | int, int, struct it *, int, int, int, int)); | |
654 | static void compute_line_metrics P_ ((struct it *)); | |
655 | static void run_redisplay_end_trigger_hook P_ ((struct it *)); | |
656 | static int get_overlay_strings P_ ((struct it *)); | |
657 | static void next_overlay_string P_ ((struct it *)); | |
658 | void set_iterator_to_next P_ ((struct it *)); | |
659 | static void reseat P_ ((struct it *, struct text_pos, int)); | |
660 | static void reseat_1 P_ ((struct it *, struct text_pos, int)); | |
661 | static void back_to_previous_visible_line_start P_ ((struct it *)); | |
662 | static void reseat_at_previous_visible_line_start P_ ((struct it *)); | |
312246d1 | 663 | static void reseat_at_next_visible_line_start P_ ((struct it *, int)); |
5f5c8ee5 GM |
664 | static int next_element_from_display_vector P_ ((struct it *)); |
665 | static int next_element_from_string P_ ((struct it *)); | |
666 | static int next_element_from_c_string P_ ((struct it *)); | |
667 | static int next_element_from_buffer P_ ((struct it *)); | |
260a86a0 | 668 | static int next_element_from_composition P_ ((struct it *)); |
5f5c8ee5 GM |
669 | static int next_element_from_image P_ ((struct it *)); |
670 | static int next_element_from_stretch P_ ((struct it *)); | |
671 | static void load_overlay_strings P_ ((struct it *)); | |
672 | static void init_from_display_pos P_ ((struct it *, struct window *, | |
673 | struct display_pos *)); | |
674 | static void reseat_to_string P_ ((struct it *, unsigned char *, | |
675 | Lisp_Object, int, int, int, int)); | |
5f5c8ee5 GM |
676 | static enum move_it_result move_it_in_display_line_to P_ ((struct it *, |
677 | int, int, int)); | |
678 | void move_it_vertically_backward P_ ((struct it *, int)); | |
679 | static void init_to_row_start P_ ((struct it *, struct window *, | |
680 | struct glyph_row *)); | |
681 | static void init_to_row_end P_ ((struct it *, struct window *, | |
682 | struct glyph_row *)); | |
683 | static void back_to_previous_line_start P_ ((struct it *)); | |
684 | static void forward_to_next_line_start P_ ((struct it *)); | |
685 | static struct text_pos string_pos_nchars_ahead P_ ((struct text_pos, | |
686 | Lisp_Object, int)); | |
687 | static struct text_pos string_pos P_ ((int, Lisp_Object)); | |
688 | static struct text_pos c_string_pos P_ ((int, unsigned char *, int)); | |
689 | static int number_of_chars P_ ((unsigned char *, int)); | |
690 | static void compute_stop_pos P_ ((struct it *)); | |
691 | static void compute_string_pos P_ ((struct text_pos *, struct text_pos, | |
692 | Lisp_Object)); | |
693 | static int face_before_or_after_it_pos P_ ((struct it *, int)); | |
694 | static int next_overlay_change P_ ((int)); | |
695 | static int handle_single_display_prop P_ ((struct it *, Lisp_Object, | |
696 | Lisp_Object, struct text_pos *)); | |
697 | ||
698 | #define face_before_it_pos(IT) face_before_or_after_it_pos ((IT), 1) | |
699 | #define face_after_it_pos(IT) face_before_or_after_it_pos ((IT), 0) | |
ff6c30e5 | 700 | |
5f5c8ee5 | 701 | #ifdef HAVE_WINDOW_SYSTEM |
12adba34 | 702 | |
e037b9ec GM |
703 | static void update_tool_bar P_ ((struct frame *, int)); |
704 | static void build_desired_tool_bar_string P_ ((struct frame *f)); | |
705 | static int redisplay_tool_bar P_ ((struct frame *)); | |
706 | static void display_tool_bar_line P_ ((struct it *)); | |
12adba34 | 707 | |
5f5c8ee5 | 708 | #endif /* HAVE_WINDOW_SYSTEM */ |
12adba34 | 709 | |
5f5c8ee5 GM |
710 | \f |
711 | /*********************************************************************** | |
712 | Window display dimensions | |
713 | ***********************************************************************/ | |
12adba34 | 714 | |
5f5c8ee5 GM |
715 | /* Return the window-relative maximum y + 1 for glyph rows displaying |
716 | text in window W. This is the height of W minus the height of a | |
717 | mode line, if any. */ | |
718 | ||
719 | INLINE int | |
720 | window_text_bottom_y (w) | |
721 | struct window *w; | |
722 | { | |
723 | struct frame *f = XFRAME (w->frame); | |
724 | int height = XFASTINT (w->height) * CANON_Y_UNIT (f); | |
725 | ||
726 | if (WINDOW_WANTS_MODELINE_P (w)) | |
727 | height -= CURRENT_MODE_LINE_HEIGHT (w); | |
728 | return height; | |
f88eb0b6 KH |
729 | } |
730 | ||
f82aff7c | 731 | |
5f5c8ee5 GM |
732 | /* Return the pixel width of display area AREA of window W. AREA < 0 |
733 | means return the total width of W, not including bitmap areas to | |
734 | the left and right of the window. */ | |
ff6c30e5 | 735 | |
5f5c8ee5 GM |
736 | INLINE int |
737 | window_box_width (w, area) | |
738 | struct window *w; | |
739 | int area; | |
740 | { | |
741 | struct frame *f = XFRAME (w->frame); | |
742 | int width = XFASTINT (w->width); | |
743 | ||
744 | if (!w->pseudo_window_p) | |
ff6c30e5 | 745 | { |
050d82d7 | 746 | width -= FRAME_SCROLL_BAR_WIDTH (f) + FRAME_FLAGS_AREA_COLS (f); |
5f5c8ee5 GM |
747 | |
748 | if (area == TEXT_AREA) | |
749 | { | |
750 | if (INTEGERP (w->left_margin_width)) | |
751 | width -= XFASTINT (w->left_margin_width); | |
752 | if (INTEGERP (w->right_margin_width)) | |
753 | width -= XFASTINT (w->right_margin_width); | |
754 | } | |
755 | else if (area == LEFT_MARGIN_AREA) | |
756 | width = (INTEGERP (w->left_margin_width) | |
757 | ? XFASTINT (w->left_margin_width) : 0); | |
758 | else if (area == RIGHT_MARGIN_AREA) | |
759 | width = (INTEGERP (w->right_margin_width) | |
760 | ? XFASTINT (w->right_margin_width) : 0); | |
ff6c30e5 | 761 | } |
5f5c8ee5 GM |
762 | |
763 | return width * CANON_X_UNIT (f); | |
ff6c30e5 | 764 | } |
1adc55de | 765 | |
1adc55de | 766 | |
5f5c8ee5 GM |
767 | /* Return the pixel height of the display area of window W, not |
768 | including mode lines of W, if any.. */ | |
f88eb0b6 | 769 | |
5f5c8ee5 GM |
770 | INLINE int |
771 | window_box_height (w) | |
772 | struct window *w; | |
f88eb0b6 | 773 | { |
5f5c8ee5 GM |
774 | struct frame *f = XFRAME (w->frame); |
775 | int height = XFASTINT (w->height) * CANON_Y_UNIT (f); | |
776 | ||
777 | if (WINDOW_WANTS_MODELINE_P (w)) | |
778 | height -= CURRENT_MODE_LINE_HEIGHT (w); | |
779 | ||
045dee35 GM |
780 | if (WINDOW_WANTS_HEADER_LINE_P (w)) |
781 | height -= CURRENT_HEADER_LINE_HEIGHT (w); | |
5f5c8ee5 GM |
782 | |
783 | return height; | |
5992c4f7 KH |
784 | } |
785 | ||
786 | ||
5f5c8ee5 GM |
787 | /* Return the frame-relative coordinate of the left edge of display |
788 | area AREA of window W. AREA < 0 means return the left edge of the | |
789 | whole window, to the right of any bitmap area at the left side of | |
790 | W. */ | |
5992c4f7 | 791 | |
5f5c8ee5 GM |
792 | INLINE int |
793 | window_box_left (w, area) | |
794 | struct window *w; | |
795 | int area; | |
90adcf20 | 796 | { |
5f5c8ee5 GM |
797 | struct frame *f = XFRAME (w->frame); |
798 | int x = FRAME_INTERNAL_BORDER_WIDTH_SAFE (f); | |
a3788d53 | 799 | |
5f5c8ee5 | 800 | if (!w->pseudo_window_p) |
90adcf20 | 801 | { |
5f5c8ee5 | 802 | x += (WINDOW_LEFT_MARGIN (w) * CANON_X_UNIT (f) |
050d82d7 | 803 | + FRAME_LEFT_FLAGS_AREA_WIDTH (f)); |
5f5c8ee5 GM |
804 | |
805 | if (area == TEXT_AREA) | |
806 | x += window_box_width (w, LEFT_MARGIN_AREA); | |
807 | else if (area == RIGHT_MARGIN_AREA) | |
808 | x += (window_box_width (w, LEFT_MARGIN_AREA) | |
809 | + window_box_width (w, TEXT_AREA)); | |
90adcf20 | 810 | } |
73af359d | 811 | |
5f5c8ee5 GM |
812 | return x; |
813 | } | |
90adcf20 | 814 | |
b6436d4e | 815 | |
5f5c8ee5 GM |
816 | /* Return the frame-relative coordinate of the right edge of display |
817 | area AREA of window W. AREA < 0 means return the left edge of the | |
818 | whole window, to the left of any bitmap area at the right side of | |
819 | W. */ | |
ded34426 | 820 | |
5f5c8ee5 GM |
821 | INLINE int |
822 | window_box_right (w, area) | |
823 | struct window *w; | |
824 | int area; | |
825 | { | |
826 | return window_box_left (w, area) + window_box_width (w, area); | |
827 | } | |
828 | ||
829 | ||
830 | /* Get the bounding box of the display area AREA of window W, without | |
831 | mode lines, in frame-relative coordinates. AREA < 0 means the | |
832 | whole window, not including bitmap areas to the left and right of | |
833 | the window. Return in *BOX_X and *BOX_Y the frame-relative pixel | |
834 | coordinates of the upper-left corner of the box. Return in | |
835 | *BOX_WIDTH, and *BOX_HEIGHT the pixel width and height of the box. */ | |
836 | ||
837 | INLINE void | |
838 | window_box (w, area, box_x, box_y, box_width, box_height) | |
839 | struct window *w; | |
840 | int area; | |
841 | int *box_x, *box_y, *box_width, *box_height; | |
842 | { | |
843 | struct frame *f = XFRAME (w->frame); | |
844 | ||
845 | *box_width = window_box_width (w, area); | |
846 | *box_height = window_box_height (w); | |
847 | *box_x = window_box_left (w, area); | |
848 | *box_y = (FRAME_INTERNAL_BORDER_WIDTH_SAFE (f) | |
849 | + XFASTINT (w->top) * CANON_Y_UNIT (f)); | |
045dee35 GM |
850 | if (WINDOW_WANTS_HEADER_LINE_P (w)) |
851 | *box_y += CURRENT_HEADER_LINE_HEIGHT (w); | |
ded34426 | 852 | } |
1adc55de | 853 | |
1adc55de | 854 | |
5f5c8ee5 GM |
855 | /* Get the bounding box of the display area AREA of window W, without |
856 | mode lines. AREA < 0 means the whole window, not including bitmap | |
857 | areas to the left and right of the window. Return in *TOP_LEFT_X | |
858 | and TOP_LEFT_Y the frame-relative pixel coordinates of the | |
859 | upper-left corner of the box. Return in *BOTTOM_RIGHT_X, and | |
860 | *BOTTOM_RIGHT_Y the coordinates of the bottom-right corner of the | |
861 | box. */ | |
ded34426 | 862 | |
5f5c8ee5 GM |
863 | INLINE void |
864 | window_box_edges (w, area, top_left_x, top_left_y, | |
865 | bottom_right_x, bottom_right_y) | |
866 | struct window *w; | |
867 | int area; | |
868 | int *top_left_x, *top_left_y, *bottom_right_x, *bottom_right_y; | |
48ae5f0a | 869 | { |
5f5c8ee5 GM |
870 | window_box (w, area, top_left_x, top_left_y, bottom_right_x, |
871 | bottom_right_y); | |
872 | *bottom_right_x += *top_left_x; | |
873 | *bottom_right_y += *top_left_y; | |
48ae5f0a KH |
874 | } |
875 | ||
5f5c8ee5 GM |
876 | |
877 | \f | |
878 | /*********************************************************************** | |
879 | Utilities | |
880 | ***********************************************************************/ | |
881 | ||
4fdb80f2 GM |
882 | /* Return the next character from STR which is MAXLEN bytes long. |
883 | Return in *LEN the length of the character. This is like | |
884 | STRING_CHAR_AND_LENGTH but never returns an invalid character. If | |
9ab8560d | 885 | we find one, we return a `?', but with the length of the invalid |
4fdb80f2 GM |
886 | character. */ |
887 | ||
888 | static INLINE int | |
7a5b8a93 | 889 | string_char_and_length (str, maxlen, len) |
4fdb80f2 | 890 | unsigned char *str; |
7a5b8a93 | 891 | int maxlen, *len; |
4fdb80f2 GM |
892 | { |
893 | int c; | |
894 | ||
895 | c = STRING_CHAR_AND_LENGTH (str, maxlen, *len); | |
896 | if (!CHAR_VALID_P (c, 1)) | |
897 | /* We may not change the length here because other places in Emacs | |
9ab8560d | 898 | don't use this function, i.e. they silently accept invalid |
4fdb80f2 GM |
899 | characters. */ |
900 | c = '?'; | |
901 | ||
902 | return c; | |
903 | } | |
904 | ||
905 | ||
906 | ||
5f5c8ee5 GM |
907 | /* Given a position POS containing a valid character and byte position |
908 | in STRING, return the position NCHARS ahead (NCHARS >= 0). */ | |
909 | ||
910 | static struct text_pos | |
911 | string_pos_nchars_ahead (pos, string, nchars) | |
912 | struct text_pos pos; | |
913 | Lisp_Object string; | |
914 | int nchars; | |
0b1005ef | 915 | { |
5f5c8ee5 GM |
916 | xassert (STRINGP (string) && nchars >= 0); |
917 | ||
918 | if (STRING_MULTIBYTE (string)) | |
919 | { | |
920 | int rest = STRING_BYTES (XSTRING (string)) - BYTEPOS (pos); | |
921 | unsigned char *p = XSTRING (string)->data + BYTEPOS (pos); | |
922 | int len; | |
923 | ||
924 | while (nchars--) | |
925 | { | |
4fdb80f2 | 926 | string_char_and_length (p, rest, &len); |
5f5c8ee5 GM |
927 | p += len, rest -= len; |
928 | xassert (rest >= 0); | |
929 | CHARPOS (pos) += 1; | |
930 | BYTEPOS (pos) += len; | |
931 | } | |
932 | } | |
933 | else | |
934 | SET_TEXT_POS (pos, CHARPOS (pos) + nchars, BYTEPOS (pos) + nchars); | |
935 | ||
936 | return pos; | |
0a9dc68b RS |
937 | } |
938 | ||
0a9dc68b | 939 | |
5f5c8ee5 GM |
940 | /* Value is the text position, i.e. character and byte position, |
941 | for character position CHARPOS in STRING. */ | |
942 | ||
943 | static INLINE struct text_pos | |
944 | string_pos (charpos, string) | |
945 | int charpos; | |
0a9dc68b | 946 | Lisp_Object string; |
0a9dc68b | 947 | { |
5f5c8ee5 GM |
948 | struct text_pos pos; |
949 | xassert (STRINGP (string)); | |
950 | xassert (charpos >= 0); | |
951 | SET_TEXT_POS (pos, charpos, string_char_to_byte (string, charpos)); | |
952 | return pos; | |
953 | } | |
954 | ||
955 | ||
956 | /* Value is a text position, i.e. character and byte position, for | |
957 | character position CHARPOS in C string S. MULTIBYTE_P non-zero | |
958 | means recognize multibyte characters. */ | |
959 | ||
960 | static struct text_pos | |
961 | c_string_pos (charpos, s, multibyte_p) | |
962 | int charpos; | |
963 | unsigned char *s; | |
964 | int multibyte_p; | |
965 | { | |
966 | struct text_pos pos; | |
967 | ||
968 | xassert (s != NULL); | |
969 | xassert (charpos >= 0); | |
970 | ||
971 | if (multibyte_p) | |
0a9dc68b | 972 | { |
5f5c8ee5 GM |
973 | int rest = strlen (s), len; |
974 | ||
975 | SET_TEXT_POS (pos, 0, 0); | |
976 | while (charpos--) | |
0a9dc68b | 977 | { |
4fdb80f2 | 978 | string_char_and_length (s, rest, &len); |
5f5c8ee5 GM |
979 | s += len, rest -= len; |
980 | xassert (rest >= 0); | |
981 | CHARPOS (pos) += 1; | |
982 | BYTEPOS (pos) += len; | |
0a9dc68b RS |
983 | } |
984 | } | |
5f5c8ee5 GM |
985 | else |
986 | SET_TEXT_POS (pos, charpos, charpos); | |
0a9dc68b | 987 | |
5f5c8ee5 GM |
988 | return pos; |
989 | } | |
0a9dc68b | 990 | |
0a9dc68b | 991 | |
5f5c8ee5 GM |
992 | /* Value is the number of characters in C string S. MULTIBYTE_P |
993 | non-zero means recognize multibyte characters. */ | |
0a9dc68b | 994 | |
5f5c8ee5 GM |
995 | static int |
996 | number_of_chars (s, multibyte_p) | |
997 | unsigned char *s; | |
998 | int multibyte_p; | |
999 | { | |
1000 | int nchars; | |
1001 | ||
1002 | if (multibyte_p) | |
1003 | { | |
1004 | int rest = strlen (s), len; | |
1005 | unsigned char *p = (unsigned char *) s; | |
0a9dc68b | 1006 | |
5f5c8ee5 GM |
1007 | for (nchars = 0; rest > 0; ++nchars) |
1008 | { | |
4fdb80f2 | 1009 | string_char_and_length (p, rest, &len); |
5f5c8ee5 | 1010 | rest -= len, p += len; |
0a9dc68b RS |
1011 | } |
1012 | } | |
5f5c8ee5 GM |
1013 | else |
1014 | nchars = strlen (s); | |
1015 | ||
1016 | return nchars; | |
0b1005ef KH |
1017 | } |
1018 | ||
5f5c8ee5 GM |
1019 | |
1020 | /* Compute byte position NEWPOS->bytepos corresponding to | |
1021 | NEWPOS->charpos. POS is a known position in string STRING. | |
1022 | NEWPOS->charpos must be >= POS.charpos. */ | |
76412d64 | 1023 | |
5f5c8ee5 GM |
1024 | static void |
1025 | compute_string_pos (newpos, pos, string) | |
1026 | struct text_pos *newpos, pos; | |
1027 | Lisp_Object string; | |
76412d64 | 1028 | { |
5f5c8ee5 GM |
1029 | xassert (STRINGP (string)); |
1030 | xassert (CHARPOS (*newpos) >= CHARPOS (pos)); | |
1031 | ||
1032 | if (STRING_MULTIBYTE (string)) | |
6fc556fd KR |
1033 | *newpos = string_pos_nchars_ahead (pos, string, |
1034 | CHARPOS (*newpos) - CHARPOS (pos)); | |
5f5c8ee5 GM |
1035 | else |
1036 | BYTEPOS (*newpos) = CHARPOS (*newpos); | |
76412d64 RS |
1037 | } |
1038 | ||
9c74a0dd | 1039 | |
5f5c8ee5 GM |
1040 | \f |
1041 | /*********************************************************************** | |
1042 | Lisp form evaluation | |
1043 | ***********************************************************************/ | |
1044 | ||
1045 | /* Error handler for eval_form. */ | |
1046 | ||
1047 | static Lisp_Object | |
1048 | eval_handler (arg) | |
1049 | Lisp_Object arg; | |
1050 | { | |
1051 | return Qnil; | |
1052 | } | |
1053 | ||
1054 | ||
1055 | /* Evaluate SEXPR and return the result, or nil if something went | |
1056 | wrong. */ | |
1057 | ||
1058 | static Lisp_Object | |
1059 | eval_form (sexpr) | |
1060 | Lisp_Object sexpr; | |
1061 | { | |
1062 | int count = specpdl_ptr - specpdl; | |
1063 | Lisp_Object val; | |
1064 | specbind (Qinhibit_redisplay, Qt); | |
1065 | val = internal_condition_case_1 (Feval, sexpr, Qerror, eval_handler); | |
1066 | return unbind_to (count, val); | |
1067 | } | |
1068 | ||
1069 | ||
1070 | \f | |
1071 | /*********************************************************************** | |
1072 | Debugging | |
1073 | ***********************************************************************/ | |
1074 | ||
1075 | #if 0 | |
1076 | ||
1077 | /* Define CHECK_IT to perform sanity checks on iterators. | |
1078 | This is for debugging. It is too slow to do unconditionally. */ | |
1079 | ||
1080 | static void | |
1081 | check_it (it) | |
1082 | struct it *it; | |
1083 | { | |
1084 | if (it->method == next_element_from_string) | |
a2889657 | 1085 | { |
5f5c8ee5 GM |
1086 | xassert (STRINGP (it->string)); |
1087 | xassert (IT_STRING_CHARPOS (*it) >= 0); | |
1088 | } | |
1089 | else if (it->method == next_element_from_buffer) | |
1090 | { | |
1091 | /* Check that character and byte positions agree. */ | |
1092 | xassert (IT_CHARPOS (*it) == BYTE_TO_CHAR (IT_BYTEPOS (*it))); | |
1093 | } | |
73af359d | 1094 | |
5f5c8ee5 GM |
1095 | if (it->dpvec) |
1096 | xassert (it->current.dpvec_index >= 0); | |
1097 | else | |
1098 | xassert (it->current.dpvec_index < 0); | |
1099 | } | |
1f40cad2 | 1100 | |
5f5c8ee5 GM |
1101 | #define CHECK_IT(IT) check_it ((IT)) |
1102 | ||
1103 | #else /* not 0 */ | |
1104 | ||
1105 | #define CHECK_IT(IT) (void) 0 | |
1106 | ||
1107 | #endif /* not 0 */ | |
1108 | ||
1109 | ||
1110 | #if GLYPH_DEBUG | |
1111 | ||
1112 | /* Check that the window end of window W is what we expect it | |
1113 | to be---the last row in the current matrix displaying text. */ | |
1114 | ||
1115 | static void | |
1116 | check_window_end (w) | |
1117 | struct window *w; | |
1118 | { | |
1119 | if (!MINI_WINDOW_P (w) | |
1120 | && !NILP (w->window_end_valid)) | |
1121 | { | |
1122 | struct glyph_row *row; | |
1123 | xassert ((row = MATRIX_ROW (w->current_matrix, | |
1124 | XFASTINT (w->window_end_vpos)), | |
1125 | !row->enabled_p | |
1126 | || MATRIX_ROW_DISPLAYS_TEXT_P (row) | |
1127 | || MATRIX_ROW_VPOS (row, w->current_matrix) == 0)); | |
1128 | } | |
1129 | } | |
1130 | ||
1131 | #define CHECK_WINDOW_END(W) check_window_end ((W)) | |
1132 | ||
1133 | #else /* not GLYPH_DEBUG */ | |
1134 | ||
1135 | #define CHECK_WINDOW_END(W) (void) 0 | |
1136 | ||
1137 | #endif /* not GLYPH_DEBUG */ | |
1138 | ||
1139 | ||
1140 | \f | |
1141 | /*********************************************************************** | |
1142 | Iterator initialization | |
1143 | ***********************************************************************/ | |
1144 | ||
1145 | /* Initialize IT for displaying current_buffer in window W, starting | |
1146 | at character position CHARPOS. CHARPOS < 0 means that no buffer | |
1147 | position is specified which is useful when the iterator is assigned | |
1148 | a position later. BYTEPOS is the byte position corresponding to | |
1149 | CHARPOS. BYTEPOS <= 0 means compute it from CHARPOS. | |
1150 | ||
1151 | If ROW is not null, calls to produce_glyphs with IT as parameter | |
1152 | will produce glyphs in that row. | |
1153 | ||
1154 | BASE_FACE_ID is the id of a base face to use. It must be one of | |
1155 | DEFAULT_FACE_ID for normal text, MODE_LINE_FACE_ID or | |
045dee35 | 1156 | HEADER_LINE_FACE_ID for displaying mode lines, or TOOL_BAR_FACE_ID for |
e037b9ec | 1157 | displaying the tool-bar. |
5f5c8ee5 GM |
1158 | |
1159 | If ROW is null and BASE_FACE_ID is equal to MODE_LINE_FACE_ID or | |
045dee35 | 1160 | HEADER_LINE_FACE_ID, the iterator will be initialized to use the |
5f5c8ee5 GM |
1161 | corresponding mode line glyph row of the desired matrix of W. */ |
1162 | ||
1163 | void | |
1164 | init_iterator (it, w, charpos, bytepos, row, base_face_id) | |
1165 | struct it *it; | |
1166 | struct window *w; | |
1167 | int charpos, bytepos; | |
1168 | struct glyph_row *row; | |
1169 | enum face_id base_face_id; | |
1170 | { | |
1171 | int highlight_region_p; | |
5f5c8ee5 GM |
1172 | |
1173 | /* Some precondition checks. */ | |
1174 | xassert (w != NULL && it != NULL); | |
5f5c8ee5 GM |
1175 | xassert (charpos < 0 || (charpos > 0 && charpos <= ZV)); |
1176 | ||
1177 | /* If face attributes have been changed since the last redisplay, | |
1178 | free realized faces now because they depend on face definitions | |
1179 | that might have changed. */ | |
1180 | if (face_change_count) | |
1181 | { | |
1182 | face_change_count = 0; | |
1183 | free_all_realized_faces (Qnil); | |
1184 | } | |
1185 | ||
1186 | /* Use one of the mode line rows of W's desired matrix if | |
1187 | appropriate. */ | |
1188 | if (row == NULL) | |
1189 | { | |
1190 | if (base_face_id == MODE_LINE_FACE_ID) | |
1191 | row = MATRIX_MODE_LINE_ROW (w->desired_matrix); | |
045dee35 GM |
1192 | else if (base_face_id == HEADER_LINE_FACE_ID) |
1193 | row = MATRIX_HEADER_LINE_ROW (w->desired_matrix); | |
5f5c8ee5 GM |
1194 | } |
1195 | ||
1196 | /* Clear IT. */ | |
1197 | bzero (it, sizeof *it); | |
1198 | it->current.overlay_string_index = -1; | |
1199 | it->current.dpvec_index = -1; | |
5f5c8ee5 GM |
1200 | it->base_face_id = base_face_id; |
1201 | ||
1202 | /* The window in which we iterate over current_buffer: */ | |
1203 | XSETWINDOW (it->window, w); | |
1204 | it->w = w; | |
1205 | it->f = XFRAME (w->frame); | |
1206 | ||
d475bcb8 GM |
1207 | /* Extra space between lines (on window systems only). */ |
1208 | if (base_face_id == DEFAULT_FACE_ID | |
1209 | && FRAME_WINDOW_P (it->f)) | |
1210 | { | |
1211 | if (NATNUMP (current_buffer->extra_line_spacing)) | |
1212 | it->extra_line_spacing = XFASTINT (current_buffer->extra_line_spacing); | |
1213 | else if (it->f->extra_line_spacing > 0) | |
1214 | it->extra_line_spacing = it->f->extra_line_spacing; | |
1215 | } | |
1216 | ||
5f5c8ee5 GM |
1217 | /* If realized faces have been removed, e.g. because of face |
1218 | attribute changes of named faces, recompute them. */ | |
1219 | if (FRAME_FACE_CACHE (it->f)->used == 0) | |
1220 | recompute_basic_faces (it->f); | |
1221 | ||
5f5c8ee5 GM |
1222 | /* Current value of the `space-width', and 'height' properties. */ |
1223 | it->space_width = Qnil; | |
1224 | it->font_height = Qnil; | |
1225 | ||
1226 | /* Are control characters displayed as `^C'? */ | |
1227 | it->ctl_arrow_p = !NILP (current_buffer->ctl_arrow); | |
1228 | ||
1229 | /* -1 means everything between a CR and the following line end | |
1230 | is invisible. >0 means lines indented more than this value are | |
1231 | invisible. */ | |
1232 | it->selective = (INTEGERP (current_buffer->selective_display) | |
1233 | ? XFASTINT (current_buffer->selective_display) | |
1234 | : (!NILP (current_buffer->selective_display) | |
1235 | ? -1 : 0)); | |
1236 | it->selective_display_ellipsis_p | |
1237 | = !NILP (current_buffer->selective_display_ellipses); | |
1238 | ||
1239 | /* Display table to use. */ | |
1240 | it->dp = window_display_table (w); | |
1241 | ||
1242 | /* Are multibyte characters enabled in current_buffer? */ | |
1243 | it->multibyte_p = !NILP (current_buffer->enable_multibyte_characters); | |
1244 | ||
1245 | /* Non-zero if we should highlight the region. */ | |
1246 | highlight_region_p | |
1247 | = (!NILP (Vtransient_mark_mode) | |
1248 | && !NILP (current_buffer->mark_active) | |
1249 | && XMARKER (current_buffer->mark)->buffer != 0); | |
1250 | ||
1251 | /* Set IT->region_beg_charpos and IT->region_end_charpos to the | |
1252 | start and end of a visible region in window IT->w. Set both to | |
1253 | -1 to indicate no region. */ | |
1254 | if (highlight_region_p | |
1255 | /* Maybe highlight only in selected window. */ | |
1256 | && (/* Either show region everywhere. */ | |
1257 | highlight_nonselected_windows | |
1258 | /* Or show region in the selected window. */ | |
1259 | || w == XWINDOW (selected_window) | |
1260 | /* Or show the region if we are in the mini-buffer and W is | |
1261 | the window the mini-buffer refers to. */ | |
1262 | || (MINI_WINDOW_P (XWINDOW (selected_window)) | |
1263 | && w == XWINDOW (Vminibuf_scroll_window)))) | |
1264 | { | |
1265 | int charpos = marker_position (current_buffer->mark); | |
1266 | it->region_beg_charpos = min (PT, charpos); | |
1267 | it->region_end_charpos = max (PT, charpos); | |
1268 | } | |
1269 | else | |
1270 | it->region_beg_charpos = it->region_end_charpos = -1; | |
1271 | ||
1272 | /* Get the position at which the redisplay_end_trigger hook should | |
1273 | be run, if it is to be run at all. */ | |
1274 | if (MARKERP (w->redisplay_end_trigger) | |
1275 | && XMARKER (w->redisplay_end_trigger)->buffer != 0) | |
1276 | it->redisplay_end_trigger_charpos | |
1277 | = marker_position (w->redisplay_end_trigger); | |
1278 | else if (INTEGERP (w->redisplay_end_trigger)) | |
1279 | it->redisplay_end_trigger_charpos = XINT (w->redisplay_end_trigger); | |
1280 | ||
1281 | /* Correct bogus values of tab_width. */ | |
1282 | it->tab_width = XINT (current_buffer->tab_width); | |
1283 | if (it->tab_width <= 0 || it->tab_width > 1000) | |
1284 | it->tab_width = 8; | |
1285 | ||
1286 | /* Are lines in the display truncated? */ | |
1287 | it->truncate_lines_p | |
1288 | = (base_face_id != DEFAULT_FACE_ID | |
1289 | || XINT (it->w->hscroll) | |
1290 | || (truncate_partial_width_windows | |
1291 | && !WINDOW_FULL_WIDTH_P (it->w)) | |
1292 | || !NILP (current_buffer->truncate_lines)); | |
1293 | ||
1294 | /* Get dimensions of truncation and continuation glyphs. These are | |
1295 | displayed as bitmaps under X, so we don't need them for such | |
1296 | frames. */ | |
1297 | if (!FRAME_WINDOW_P (it->f)) | |
1298 | { | |
1299 | if (it->truncate_lines_p) | |
1300 | { | |
1301 | /* We will need the truncation glyph. */ | |
1302 | xassert (it->glyph_row == NULL); | |
1303 | produce_special_glyphs (it, IT_TRUNCATION); | |
1304 | it->truncation_pixel_width = it->pixel_width; | |
1305 | } | |
1306 | else | |
1307 | { | |
1308 | /* We will need the continuation glyph. */ | |
1309 | xassert (it->glyph_row == NULL); | |
1310 | produce_special_glyphs (it, IT_CONTINUATION); | |
1311 | it->continuation_pixel_width = it->pixel_width; | |
1312 | } | |
1313 | ||
1314 | /* Reset these values to zero becaue the produce_special_glyphs | |
1315 | above has changed them. */ | |
1316 | it->pixel_width = it->ascent = it->descent = 0; | |
312246d1 | 1317 | it->phys_ascent = it->phys_descent = 0; |
5f5c8ee5 GM |
1318 | } |
1319 | ||
1320 | /* Set this after getting the dimensions of truncation and | |
1321 | continuation glyphs, so that we don't produce glyphs when calling | |
1322 | produce_special_glyphs, above. */ | |
1323 | it->glyph_row = row; | |
1324 | it->area = TEXT_AREA; | |
1325 | ||
1326 | /* Get the dimensions of the display area. The display area | |
1327 | consists of the visible window area plus a horizontally scrolled | |
1328 | part to the left of the window. All x-values are relative to the | |
1329 | start of this total display area. */ | |
1330 | if (base_face_id != DEFAULT_FACE_ID) | |
1331 | { | |
1332 | /* Mode lines, menu bar in terminal frames. */ | |
1333 | it->first_visible_x = 0; | |
1334 | it->last_visible_x = XFASTINT (w->width) * CANON_X_UNIT (it->f); | |
1335 | } | |
1336 | else | |
1337 | { | |
1338 | it->first_visible_x | |
1339 | = XFASTINT (it->w->hscroll) * CANON_X_UNIT (it->f); | |
1340 | it->last_visible_x = (it->first_visible_x | |
1341 | + window_box_width (w, TEXT_AREA)); | |
1342 | ||
1343 | /* If we truncate lines, leave room for the truncator glyph(s) at | |
1344 | the right margin. Otherwise, leave room for the continuation | |
1345 | glyph(s). Truncation and continuation glyphs are not inserted | |
1346 | for window-based redisplay. */ | |
1347 | if (!FRAME_WINDOW_P (it->f)) | |
1348 | { | |
1349 | if (it->truncate_lines_p) | |
1350 | it->last_visible_x -= it->truncation_pixel_width; | |
1351 | else | |
1352 | it->last_visible_x -= it->continuation_pixel_width; | |
1353 | } | |
1354 | ||
045dee35 GM |
1355 | it->header_line_p = WINDOW_WANTS_HEADER_LINE_P (w); |
1356 | it->current_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w) + w->vscroll; | |
5f5c8ee5 GM |
1357 | } |
1358 | ||
1359 | /* Leave room for a border glyph. */ | |
1360 | if (!FRAME_WINDOW_P (it->f) | |
1361 | && !WINDOW_RIGHTMOST_P (it->w)) | |
1362 | it->last_visible_x -= 1; | |
1363 | ||
1364 | it->last_visible_y = window_text_bottom_y (w); | |
1365 | ||
1366 | /* For mode lines and alike, arrange for the first glyph having a | |
1367 | left box line if the face specifies a box. */ | |
1368 | if (base_face_id != DEFAULT_FACE_ID) | |
1369 | { | |
1370 | struct face *face; | |
1371 | ||
1372 | it->face_id = base_face_id; | |
1373 | ||
1374 | /* If we have a boxed mode line, make the first character appear | |
1375 | with a left box line. */ | |
1376 | face = FACE_FROM_ID (it->f, base_face_id); | |
1377 | if (face->box != FACE_NO_BOX) | |
1378 | it->start_of_box_run_p = 1; | |
1379 | } | |
1380 | ||
1381 | /* If a buffer position was specified, set the iterator there, | |
1382 | getting overlays and face properties from that position. */ | |
1383 | if (charpos > 0) | |
1384 | { | |
1385 | it->end_charpos = ZV; | |
1386 | it->face_id = -1; | |
1387 | IT_CHARPOS (*it) = charpos; | |
1388 | ||
1389 | /* Compute byte position if not specified. */ | |
1390 | if (bytepos <= 0) | |
1391 | IT_BYTEPOS (*it) = CHAR_TO_BYTE (charpos); | |
1392 | else | |
1393 | IT_BYTEPOS (*it) = bytepos; | |
1394 | ||
1395 | /* Compute faces etc. */ | |
1396 | reseat (it, it->current.pos, 1); | |
1397 | } | |
1398 | ||
1399 | CHECK_IT (it); | |
1400 | } | |
1401 | ||
1402 | ||
1403 | /* Initialize IT for the display of window W with window start POS. */ | |
1404 | ||
1405 | void | |
1406 | start_display (it, w, pos) | |
1407 | struct it *it; | |
1408 | struct window *w; | |
1409 | struct text_pos pos; | |
1410 | { | |
1411 | int start_at_line_beg_p; | |
1412 | struct glyph_row *row; | |
045dee35 | 1413 | int first_vpos = WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0; |
5f5c8ee5 GM |
1414 | int first_y; |
1415 | ||
1416 | row = w->desired_matrix->rows + first_vpos; | |
1417 | init_iterator (it, w, CHARPOS (pos), BYTEPOS (pos), row, DEFAULT_FACE_ID); | |
1418 | first_y = it->current_y; | |
1419 | ||
1420 | /* If window start is not at a line start, move back to the line | |
1421 | start. This makes sure that we take continuation lines into | |
1422 | account. */ | |
1423 | start_at_line_beg_p = (CHARPOS (pos) == BEGV | |
1424 | || FETCH_BYTE (BYTEPOS (pos) - 1) == '\n'); | |
1425 | if (!start_at_line_beg_p) | |
1426 | reseat_at_previous_visible_line_start (it); | |
1427 | ||
5f5c8ee5 GM |
1428 | /* If window start is not at a line start, skip forward to POS to |
1429 | get the correct continuation_lines_width and current_x. */ | |
1430 | if (!start_at_line_beg_p) | |
1431 | { | |
1432 | move_it_to (it, CHARPOS (pos), -1, -1, -1, MOVE_TO_POS); | |
1433 | ||
1434 | /* If lines are continued, this line may end in the middle of a | |
1435 | multi-glyph character (e.g. a control character displayed as | |
1436 | \003, or in the middle of an overlay string). In this case | |
1437 | move_it_to above will not have taken us to the start of | |
1438 | the continuation line but to the end of the continued line. */ | |
1439 | if (!it->truncate_lines_p && it->current_x > 0) | |
1440 | { | |
1441 | if (it->current.dpvec_index >= 0 | |
1442 | || it->current.overlay_string_index >= 0) | |
1443 | { | |
1444 | set_iterator_to_next (it); | |
1445 | move_it_in_display_line_to (it, -1, -1, 0); | |
1446 | } | |
1447 | it->continuation_lines_width += it->current_x; | |
1448 | } | |
1449 | ||
1450 | it->current_y = first_y; | |
1451 | it->vpos = 0; | |
1452 | it->current_x = it->hpos = 0; | |
1453 | } | |
1454 | ||
1455 | #if 0 /* Don't assert the following because start_display is sometimes | |
1456 | called intentionally with a window start that is not at a | |
1457 | line start. Please leave this code in as a comment. */ | |
1458 | ||
1459 | /* Window start should be on a line start, now. */ | |
1460 | xassert (it->continuation_lines_width | |
1461 | || IT_CHARPOS (it) == BEGV | |
1462 | || FETCH_BYTE (IT_BYTEPOS (it) - 1) == '\n'); | |
1463 | #endif /* 0 */ | |
1464 | } | |
1465 | ||
1466 | ||
1467 | /* Initialize IT for stepping through current_buffer in window W, | |
1468 | starting at position POS that includes overlay string and display | |
1469 | vector/ control character translation position information. */ | |
1470 | ||
1471 | static void | |
1472 | init_from_display_pos (it, w, pos) | |
1473 | struct it *it; | |
1474 | struct window *w; | |
1475 | struct display_pos *pos; | |
1476 | { | |
1477 | /* Keep in mind: the call to reseat in init_iterator skips invisible | |
1478 | text, so we might end up at a position different from POS. This | |
1479 | is only a problem when POS is a row start after a newline and an | |
1480 | overlay starts there with an after-string, and the overlay has an | |
1481 | invisible property. Since we don't skip invisible text in | |
1482 | display_line and elsewhere immediately after consuming the | |
1483 | newline before the row start, such a POS will not be in a string, | |
1484 | but the call to init_iterator below will move us to the | |
1485 | after-string. */ | |
1486 | init_iterator (it, w, CHARPOS (pos->pos), BYTEPOS (pos->pos), | |
1487 | NULL, DEFAULT_FACE_ID); | |
1488 | ||
1489 | /* If position is within an overlay string, set up IT to | |
1490 | the right overlay string. */ | |
1491 | if (pos->overlay_string_index >= 0) | |
1492 | { | |
1493 | int relative_index; | |
1494 | ||
1495 | /* We already have the first chunk of overlay strings in | |
1496 | IT->overlay_strings. Load more until the one for | |
1497 | pos->overlay_string_index is in IT->overlay_strings. */ | |
1498 | if (pos->overlay_string_index >= OVERLAY_STRING_CHUNK_SIZE) | |
1499 | { | |
1500 | int n = pos->overlay_string_index / OVERLAY_STRING_CHUNK_SIZE; | |
1501 | it->current.overlay_string_index = 0; | |
1502 | while (n--) | |
1503 | { | |
1504 | load_overlay_strings (it); | |
1505 | it->current.overlay_string_index += OVERLAY_STRING_CHUNK_SIZE; | |
1506 | } | |
1507 | } | |
1508 | ||
1509 | it->current.overlay_string_index = pos->overlay_string_index; | |
1510 | relative_index = (it->current.overlay_string_index | |
1511 | % OVERLAY_STRING_CHUNK_SIZE); | |
1512 | it->string = it->overlay_strings[relative_index]; | |
1513 | it->current.string_pos = pos->string_pos; | |
1514 | it->method = next_element_from_string; | |
1515 | } | |
1516 | else if (CHARPOS (pos->string_pos) >= 0) | |
1517 | { | |
1518 | /* Recorded position is not in an overlay string, but in another | |
1519 | string. This can only be a string from a `display' property. | |
1520 | IT should already be filled with that string. */ | |
1521 | it->current.string_pos = pos->string_pos; | |
1522 | xassert (STRINGP (it->string)); | |
1523 | } | |
1524 | ||
1525 | /* Restore position in display vector translations or control | |
1526 | character translations. */ | |
1527 | if (pos->dpvec_index >= 0) | |
1528 | { | |
1529 | /* This fills IT->dpvec. */ | |
1530 | get_next_display_element (it); | |
1531 | xassert (it->dpvec && it->current.dpvec_index == 0); | |
1532 | it->current.dpvec_index = pos->dpvec_index; | |
1533 | } | |
1534 | ||
1535 | CHECK_IT (it); | |
1536 | } | |
1537 | ||
1538 | ||
1539 | /* Initialize IT for stepping through current_buffer in window W | |
1540 | starting at ROW->start. */ | |
1541 | ||
1542 | static void | |
1543 | init_to_row_start (it, w, row) | |
1544 | struct it *it; | |
1545 | struct window *w; | |
1546 | struct glyph_row *row; | |
1547 | { | |
1548 | init_from_display_pos (it, w, &row->start); | |
1549 | it->continuation_lines_width = row->continuation_lines_width; | |
1550 | CHECK_IT (it); | |
1551 | } | |
1552 | ||
1553 | ||
1554 | /* Initialize IT for stepping through current_buffer in window W | |
1555 | starting in the line following ROW, i.e. starting at ROW->end. */ | |
1556 | ||
1557 | static void | |
1558 | init_to_row_end (it, w, row) | |
1559 | struct it *it; | |
1560 | struct window *w; | |
1561 | struct glyph_row *row; | |
1562 | { | |
1563 | init_from_display_pos (it, w, &row->end); | |
1564 | ||
1565 | if (row->continued_p) | |
1566 | it->continuation_lines_width = (row->continuation_lines_width | |
1567 | + row->pixel_width); | |
1568 | CHECK_IT (it); | |
1569 | } | |
1570 | ||
1571 | ||
1572 | ||
1573 | \f | |
1574 | /*********************************************************************** | |
1575 | Text properties | |
1576 | ***********************************************************************/ | |
1577 | ||
1578 | /* Called when IT reaches IT->stop_charpos. Handle text property and | |
1579 | overlay changes. Set IT->stop_charpos to the next position where | |
1580 | to stop. */ | |
1581 | ||
1582 | static void | |
1583 | handle_stop (it) | |
1584 | struct it *it; | |
1585 | { | |
1586 | enum prop_handled handled; | |
1587 | int handle_overlay_change_p = 1; | |
1588 | struct props *p; | |
1589 | ||
1590 | it->dpvec = NULL; | |
1591 | it->current.dpvec_index = -1; | |
1592 | ||
1593 | do | |
1594 | { | |
1595 | handled = HANDLED_NORMALLY; | |
1596 | ||
1597 | /* Call text property handlers. */ | |
1598 | for (p = it_props; p->handler; ++p) | |
1599 | { | |
1600 | handled = p->handler (it); | |
1601 | ||
1602 | if (handled == HANDLED_RECOMPUTE_PROPS) | |
1603 | break; | |
1604 | else if (handled == HANDLED_RETURN) | |
1605 | return; | |
1606 | else if (handled == HANDLED_OVERLAY_STRING_CONSUMED) | |
1607 | handle_overlay_change_p = 0; | |
1608 | } | |
1609 | ||
1610 | if (handled != HANDLED_RECOMPUTE_PROPS) | |
1611 | { | |
1612 | /* Don't check for overlay strings below when set to deliver | |
1613 | characters from a display vector. */ | |
1614 | if (it->method == next_element_from_display_vector) | |
1615 | handle_overlay_change_p = 0; | |
1616 | ||
1617 | /* Handle overlay changes. */ | |
1618 | if (handle_overlay_change_p) | |
1619 | handled = handle_overlay_change (it); | |
1620 | ||
1621 | /* Determine where to stop next. */ | |
1622 | if (handled == HANDLED_NORMALLY) | |
1623 | compute_stop_pos (it); | |
1624 | } | |
1625 | } | |
1626 | while (handled == HANDLED_RECOMPUTE_PROPS); | |
1627 | } | |
1628 | ||
1629 | ||
1630 | /* Compute IT->stop_charpos from text property and overlay change | |
1631 | information for IT's current position. */ | |
1632 | ||
1633 | static void | |
1634 | compute_stop_pos (it) | |
1635 | struct it *it; | |
1636 | { | |
1637 | register INTERVAL iv, next_iv; | |
1638 | Lisp_Object object, limit, position; | |
1639 | ||
1640 | /* If nowhere else, stop at the end. */ | |
1641 | it->stop_charpos = it->end_charpos; | |
1642 | ||
1643 | if (STRINGP (it->string)) | |
1644 | { | |
1645 | /* Strings are usually short, so don't limit the search for | |
1646 | properties. */ | |
1647 | object = it->string; | |
1648 | limit = Qnil; | |
1649 | XSETFASTINT (position, IT_STRING_CHARPOS (*it)); | |
1650 | } | |
1651 | else | |
1652 | { | |
1653 | int charpos; | |
1654 | ||
1655 | /* If next overlay change is in front of the current stop pos | |
1656 | (which is IT->end_charpos), stop there. Note: value of | |
1657 | next_overlay_change is point-max if no overlay change | |
1658 | follows. */ | |
1659 | charpos = next_overlay_change (IT_CHARPOS (*it)); | |
1660 | if (charpos < it->stop_charpos) | |
1661 | it->stop_charpos = charpos; | |
1662 | ||
1663 | /* If showing the region, we have to stop at the region | |
1664 | start or end because the face might change there. */ | |
1665 | if (it->region_beg_charpos > 0) | |
1666 | { | |
1667 | if (IT_CHARPOS (*it) < it->region_beg_charpos) | |
1668 | it->stop_charpos = min (it->stop_charpos, it->region_beg_charpos); | |
1669 | else if (IT_CHARPOS (*it) < it->region_end_charpos) | |
1670 | it->stop_charpos = min (it->stop_charpos, it->region_end_charpos); | |
1671 | } | |
1672 | ||
1673 | /* Set up variables for computing the stop position from text | |
1674 | property changes. */ | |
1675 | XSETBUFFER (object, current_buffer); | |
1676 | XSETFASTINT (limit, IT_CHARPOS (*it) + TEXT_PROP_DISTANCE_LIMIT); | |
1677 | XSETFASTINT (position, IT_CHARPOS (*it)); | |
1678 | ||
1679 | } | |
1680 | ||
1681 | /* Get the interval containing IT's position. Value is a null | |
1682 | interval if there isn't such an interval. */ | |
1683 | iv = validate_interval_range (object, &position, &position, 0); | |
1684 | if (!NULL_INTERVAL_P (iv)) | |
1685 | { | |
1686 | Lisp_Object values_here[LAST_PROP_IDX]; | |
1687 | struct props *p; | |
1688 | ||
1689 | /* Get properties here. */ | |
1690 | for (p = it_props; p->handler; ++p) | |
1691 | values_here[p->idx] = textget (iv->plist, *p->name); | |
1692 | ||
1693 | /* Look for an interval following iv that has different | |
1694 | properties. */ | |
1695 | for (next_iv = next_interval (iv); | |
1696 | (!NULL_INTERVAL_P (next_iv) | |
1697 | && (NILP (limit) | |
1698 | || XFASTINT (limit) > next_iv->position)); | |
1699 | next_iv = next_interval (next_iv)) | |
1700 | { | |
1701 | for (p = it_props; p->handler; ++p) | |
1702 | { | |
1703 | Lisp_Object new_value; | |
1704 | ||
1705 | new_value = textget (next_iv->plist, *p->name); | |
1706 | if (!EQ (values_here[p->idx], new_value)) | |
1707 | break; | |
1708 | } | |
1709 | ||
1710 | if (p->handler) | |
1711 | break; | |
1712 | } | |
1713 | ||
1714 | if (!NULL_INTERVAL_P (next_iv)) | |
1715 | { | |
1716 | if (INTEGERP (limit) | |
1717 | && next_iv->position >= XFASTINT (limit)) | |
1718 | /* No text property change up to limit. */ | |
1719 | it->stop_charpos = min (XFASTINT (limit), it->stop_charpos); | |
1720 | else | |
1721 | /* Text properties change in next_iv. */ | |
1722 | it->stop_charpos = min (it->stop_charpos, next_iv->position); | |
1723 | } | |
1724 | } | |
1725 | ||
1726 | xassert (STRINGP (it->string) | |
1727 | || (it->stop_charpos >= BEGV | |
1728 | && it->stop_charpos >= IT_CHARPOS (*it))); | |
1729 | } | |
1730 | ||
1731 | ||
1732 | /* Return the position of the next overlay change after POS in | |
1733 | current_buffer. Value is point-max if no overlay change | |
1734 | follows. This is like `next-overlay-change' but doesn't use | |
1735 | xmalloc. */ | |
1736 | ||
1737 | static int | |
1738 | next_overlay_change (pos) | |
1739 | int pos; | |
1740 | { | |
1741 | int noverlays; | |
1742 | int endpos; | |
1743 | Lisp_Object *overlays; | |
1744 | int len; | |
1745 | int i; | |
1746 | ||
1747 | /* Get all overlays at the given position. */ | |
1748 | len = 10; | |
1749 | overlays = (Lisp_Object *) alloca (len * sizeof *overlays); | |
1750 | noverlays = overlays_at (pos, 0, &overlays, &len, &endpos, NULL); | |
1751 | if (noverlays > len) | |
1752 | { | |
1753 | len = noverlays; | |
1754 | overlays = (Lisp_Object *) alloca (len * sizeof *overlays); | |
1755 | noverlays = overlays_at (pos, 0, &overlays, &len, &endpos, NULL); | |
1756 | } | |
1757 | ||
1758 | /* If any of these overlays ends before endpos, | |
1759 | use its ending point instead. */ | |
1760 | for (i = 0; i < noverlays; ++i) | |
1761 | { | |
1762 | Lisp_Object oend; | |
1763 | int oendpos; | |
1764 | ||
1765 | oend = OVERLAY_END (overlays[i]); | |
1766 | oendpos = OVERLAY_POSITION (oend); | |
1767 | endpos = min (endpos, oendpos); | |
1768 | } | |
1769 | ||
1770 | return endpos; | |
1771 | } | |
1772 | ||
1773 | ||
1774 | \f | |
1775 | /*********************************************************************** | |
1776 | Fontification | |
1777 | ***********************************************************************/ | |
1778 | ||
1779 | /* Handle changes in the `fontified' property of the current buffer by | |
1780 | calling hook functions from Qfontification_functions to fontify | |
1781 | regions of text. */ | |
1782 | ||
1783 | static enum prop_handled | |
1784 | handle_fontified_prop (it) | |
1785 | struct it *it; | |
1786 | { | |
1787 | Lisp_Object prop, pos; | |
1788 | enum prop_handled handled = HANDLED_NORMALLY; | |
2bf6fa4b | 1789 | struct gcpro gcpro1; |
5f5c8ee5 GM |
1790 | |
1791 | /* Get the value of the `fontified' property at IT's current buffer | |
1792 | position. (The `fontified' property doesn't have a special | |
1793 | meaning in strings.) If the value is nil, call functions from | |
1794 | Qfontification_functions. */ | |
1795 | if (!STRINGP (it->string) | |
1796 | && it->s == NULL | |
1797 | && !NILP (Vfontification_functions) | |
1798 | && (pos = make_number (IT_CHARPOS (*it)), | |
1799 | prop = Fget_char_property (pos, Qfontified, Qnil), | |
1800 | NILP (prop))) | |
1801 | { | |
1802 | Lisp_Object args[2]; | |
1803 | ||
2bf6fa4b | 1804 | GCPRO1 (pos); |
5f5c8ee5 GM |
1805 | /* Run the hook functions. */ |
1806 | args[0] = Qfontification_functions; | |
1807 | args[1] = pos; | |
6fc556fd | 1808 | Frun_hook_with_args (2, args); |
5f5c8ee5 GM |
1809 | |
1810 | /* Return HANDLED_RECOMPUTE_PROPS only if function fontified | |
1811 | something. This avoids an endless loop if they failed to | |
1812 | fontify the text for which reason ever. */ | |
1813 | if (!NILP (Fget_char_property (pos, Qfontified, Qnil))) | |
1814 | handled = HANDLED_RECOMPUTE_PROPS; | |
2bf6fa4b | 1815 | UNGCPRO; |
5f5c8ee5 GM |
1816 | } |
1817 | ||
1818 | return handled; | |
1819 | } | |
1820 | ||
1821 | ||
1822 | \f | |
1823 | /*********************************************************************** | |
1824 | Faces | |
1825 | ***********************************************************************/ | |
1826 | ||
1827 | /* Set up iterator IT from face properties at its current position. | |
1828 | Called from handle_stop. */ | |
1829 | ||
1830 | static enum prop_handled | |
1831 | handle_face_prop (it) | |
1832 | struct it *it; | |
1833 | { | |
1834 | int new_face_id, next_stop; | |
1835 | ||
1836 | if (!STRINGP (it->string)) | |
1837 | { | |
1838 | new_face_id | |
1839 | = face_at_buffer_position (it->w, | |
1840 | IT_CHARPOS (*it), | |
1841 | it->region_beg_charpos, | |
1842 | it->region_end_charpos, | |
1843 | &next_stop, | |
1844 | (IT_CHARPOS (*it) | |
1845 | + TEXT_PROP_DISTANCE_LIMIT), | |
1846 | 0); | |
1847 | ||
1848 | /* Is this a start of a run of characters with box face? | |
1849 | Caveat: this can be called for a freshly initialized | |
1850 | iterator; face_id is -1 is this case. We know that the new | |
1851 | face will not change until limit, i.e. if the new face has a | |
1852 | box, all characters up to limit will have one. But, as | |
1853 | usual, we don't know whether limit is really the end. */ | |
1854 | if (new_face_id != it->face_id) | |
1855 | { | |
1856 | struct face *new_face = FACE_FROM_ID (it->f, new_face_id); | |
1857 | ||
1858 | /* If new face has a box but old face has not, this is | |
1859 | the start of a run of characters with box, i.e. it has | |
1860 | a shadow on the left side. The value of face_id of the | |
1861 | iterator will be -1 if this is the initial call that gets | |
1862 | the face. In this case, we have to look in front of IT's | |
1863 | position and see whether there is a face != new_face_id. */ | |
1864 | it->start_of_box_run_p | |
1865 | = (new_face->box != FACE_NO_BOX | |
1866 | && (it->face_id >= 0 | |
1867 | || IT_CHARPOS (*it) == BEG | |
1868 | || new_face_id != face_before_it_pos (it))); | |
1869 | it->face_box_p = new_face->box != FACE_NO_BOX; | |
1870 | } | |
1871 | } | |
1872 | else | |
1873 | { | |
1874 | new_face_id | |
1875 | = face_at_string_position (it->w, | |
1876 | it->string, | |
1877 | IT_STRING_CHARPOS (*it), | |
1878 | (it->current.overlay_string_index >= 0 | |
1879 | ? IT_CHARPOS (*it) | |
1880 | : 0), | |
1881 | it->region_beg_charpos, | |
1882 | it->region_end_charpos, | |
1883 | &next_stop, | |
1884 | it->base_face_id); | |
1885 | ||
1886 | #if 0 /* This shouldn't be neccessary. Let's check it. */ | |
1887 | /* If IT is used to display a mode line we would really like to | |
1888 | use the mode line face instead of the frame's default face. */ | |
1889 | if (it->glyph_row == MATRIX_MODE_LINE_ROW (it->w->desired_matrix) | |
1890 | && new_face_id == DEFAULT_FACE_ID) | |
1891 | new_face_id = MODE_LINE_FACE_ID; | |
1892 | #endif | |
1893 | ||
1894 | /* Is this a start of a run of characters with box? Caveat: | |
1895 | this can be called for a freshly allocated iterator; face_id | |
1896 | is -1 is this case. We know that the new face will not | |
1897 | change until the next check pos, i.e. if the new face has a | |
1898 | box, all characters up to that position will have a | |
1899 | box. But, as usual, we don't know whether that position | |
1900 | is really the end. */ | |
1901 | if (new_face_id != it->face_id) | |
1902 | { | |
1903 | struct face *new_face = FACE_FROM_ID (it->f, new_face_id); | |
1904 | struct face *old_face = FACE_FROM_ID (it->f, it->face_id); | |
1905 | ||
1906 | /* If new face has a box but old face hasn't, this is the | |
1907 | start of a run of characters with box, i.e. it has a | |
1908 | shadow on the left side. */ | |
1909 | it->start_of_box_run_p | |
1910 | = new_face->box && (old_face == NULL || !old_face->box); | |
1911 | it->face_box_p = new_face->box != FACE_NO_BOX; | |
1912 | } | |
1913 | } | |
1914 | ||
1915 | it->face_id = new_face_id; | |
5f5c8ee5 GM |
1916 | return HANDLED_NORMALLY; |
1917 | } | |
1918 | ||
1919 | ||
1920 | /* Compute the face one character before or after the current position | |
1921 | of IT. BEFORE_P non-zero means get the face in front of IT's | |
1922 | position. Value is the id of the face. */ | |
1923 | ||
1924 | static int | |
1925 | face_before_or_after_it_pos (it, before_p) | |
1926 | struct it *it; | |
1927 | int before_p; | |
1928 | { | |
1929 | int face_id, limit; | |
1930 | int next_check_charpos; | |
1931 | struct text_pos pos; | |
1932 | ||
1933 | xassert (it->s == NULL); | |
1934 | ||
1935 | if (STRINGP (it->string)) | |
1936 | { | |
1937 | /* No face change past the end of the string (for the case | |
1938 | we are padding with spaces). No face change before the | |
1939 | string start. */ | |
1940 | if (IT_STRING_CHARPOS (*it) >= XSTRING (it->string)->size | |
1941 | || (IT_STRING_CHARPOS (*it) == 0 && before_p)) | |
1942 | return it->face_id; | |
1943 | ||
1944 | /* Set pos to the position before or after IT's current position. */ | |
1945 | if (before_p) | |
1946 | pos = string_pos (IT_STRING_CHARPOS (*it) - 1, it->string); | |
1947 | else | |
260a86a0 KH |
1948 | /* For composition, we must check the character after the |
1949 | composition. */ | |
1950 | pos = (it->what == IT_COMPOSITION | |
1951 | ? string_pos (IT_STRING_CHARPOS (*it) + it->cmp_len, it->string) | |
1952 | : string_pos (IT_STRING_CHARPOS (*it) + 1, it->string)); | |
5f5c8ee5 GM |
1953 | |
1954 | /* Get the face for ASCII, or unibyte. */ | |
1955 | face_id | |
1956 | = face_at_string_position (it->w, | |
1957 | it->string, | |
1958 | CHARPOS (pos), | |
1959 | (it->current.overlay_string_index >= 0 | |
1960 | ? IT_CHARPOS (*it) | |
1961 | : 0), | |
1962 | it->region_beg_charpos, | |
1963 | it->region_end_charpos, | |
1964 | &next_check_charpos, | |
1965 | it->base_face_id); | |
1966 | ||
1967 | /* Correct the face for charsets different from ASCII. Do it | |
1968 | for the multibyte case only. The face returned above is | |
1969 | suitable for unibyte text if IT->string is unibyte. */ | |
1970 | if (STRING_MULTIBYTE (it->string)) | |
1971 | { | |
1972 | unsigned char *p = XSTRING (it->string)->data + BYTEPOS (pos); | |
1973 | int rest = STRING_BYTES (XSTRING (it->string)) - BYTEPOS (pos); | |
980806b6 KH |
1974 | int c, len; |
1975 | struct face *face = FACE_FROM_ID (it->f, face_id); | |
5f5c8ee5 | 1976 | |
4fdb80f2 | 1977 | c = string_char_and_length (p, rest, &len); |
980806b6 | 1978 | face_id = FACE_FOR_CHAR (it->f, face, c); |
5f5c8ee5 GM |
1979 | } |
1980 | } | |
1981 | else | |
1982 | { | |
70851746 GM |
1983 | if ((IT_CHARPOS (*it) >= ZV && !before_p) |
1984 | || (IT_CHARPOS (*it) <= BEGV && before_p)) | |
1985 | return it->face_id; | |
1986 | ||
5f5c8ee5 GM |
1987 | limit = IT_CHARPOS (*it) + TEXT_PROP_DISTANCE_LIMIT; |
1988 | pos = it->current.pos; | |
1989 | ||
1990 | if (before_p) | |
c1005d06 | 1991 | DEC_TEXT_POS (pos, it->multibyte_p); |
5f5c8ee5 | 1992 | else |
260a86a0 KH |
1993 | { |
1994 | if (it->what == IT_COMPOSITION) | |
1995 | /* For composition, we must check the position after the | |
1996 | composition. */ | |
1997 | pos.charpos += it->cmp_len, pos.bytepos += it->len; | |
1998 | else | |
c1005d06 | 1999 | INC_TEXT_POS (pos, it->multibyte_p); |
260a86a0 | 2000 | } |
5f5c8ee5 GM |
2001 | /* Determine face for CHARSET_ASCII, or unibyte. */ |
2002 | face_id = face_at_buffer_position (it->w, | |
2003 | CHARPOS (pos), | |
2004 | it->region_beg_charpos, | |
2005 | it->region_end_charpos, | |
2006 | &next_check_charpos, | |
2007 | limit, 0); | |
2008 | ||
2009 | /* Correct the face for charsets different from ASCII. Do it | |
2010 | for the multibyte case only. The face returned above is | |
2011 | suitable for unibyte text if current_buffer is unibyte. */ | |
2012 | if (it->multibyte_p) | |
2013 | { | |
980806b6 KH |
2014 | int c = FETCH_MULTIBYTE_CHAR (CHARPOS (pos)); |
2015 | struct face *face = FACE_FROM_ID (it->f, face_id); | |
2016 | face_id = FACE_FOR_CHAR (it->f, face, c); | |
5f5c8ee5 GM |
2017 | } |
2018 | } | |
2019 | ||
2020 | return face_id; | |
2021 | } | |
2022 | ||
2023 | ||
2024 | \f | |
2025 | /*********************************************************************** | |
2026 | Invisible text | |
2027 | ***********************************************************************/ | |
2028 | ||
2029 | /* Set up iterator IT from invisible properties at its current | |
2030 | position. Called from handle_stop. */ | |
2031 | ||
2032 | static enum prop_handled | |
2033 | handle_invisible_prop (it) | |
2034 | struct it *it; | |
2035 | { | |
2036 | enum prop_handled handled = HANDLED_NORMALLY; | |
2037 | ||
2038 | if (STRINGP (it->string)) | |
2039 | { | |
2040 | extern Lisp_Object Qinvisible; | |
2041 | Lisp_Object prop, end_charpos, limit, charpos; | |
2042 | ||
2043 | /* Get the value of the invisible text property at the | |
2044 | current position. Value will be nil if there is no such | |
2045 | property. */ | |
2046 | XSETFASTINT (charpos, IT_STRING_CHARPOS (*it)); | |
2047 | prop = Fget_text_property (charpos, Qinvisible, it->string); | |
2048 | ||
eadc0bf8 GM |
2049 | if (!NILP (prop) |
2050 | && IT_STRING_CHARPOS (*it) < it->end_charpos) | |
5f5c8ee5 GM |
2051 | { |
2052 | handled = HANDLED_RECOMPUTE_PROPS; | |
2053 | ||
2054 | /* Get the position at which the next change of the | |
2055 | invisible text property can be found in IT->string. | |
2056 | Value will be nil if the property value is the same for | |
2057 | all the rest of IT->string. */ | |
2058 | XSETINT (limit, XSTRING (it->string)->size); | |
2059 | end_charpos = Fnext_single_property_change (charpos, Qinvisible, | |
2060 | it->string, limit); | |
2061 | ||
2062 | /* Text at current position is invisible. The next | |
2063 | change in the property is at position end_charpos. | |
2064 | Move IT's current position to that position. */ | |
2065 | if (INTEGERP (end_charpos) | |
2066 | && XFASTINT (end_charpos) < XFASTINT (limit)) | |
2067 | { | |
2068 | struct text_pos old; | |
2069 | old = it->current.string_pos; | |
2070 | IT_STRING_CHARPOS (*it) = XFASTINT (end_charpos); | |
2071 | compute_string_pos (&it->current.string_pos, old, it->string); | |
2072 | } | |
2073 | else | |
2074 | { | |
2075 | /* The rest of the string is invisible. If this is an | |
2076 | overlay string, proceed with the next overlay string | |
2077 | or whatever comes and return a character from there. */ | |
2078 | if (it->current.overlay_string_index >= 0) | |
2079 | { | |
2080 | next_overlay_string (it); | |
2081 | /* Don't check for overlay strings when we just | |
2082 | finished processing them. */ | |
2083 | handled = HANDLED_OVERLAY_STRING_CONSUMED; | |
2084 | } | |
2085 | else | |
2086 | { | |
2087 | struct Lisp_String *s = XSTRING (it->string); | |
2088 | IT_STRING_CHARPOS (*it) = s->size; | |
2089 | IT_STRING_BYTEPOS (*it) = STRING_BYTES (s); | |
2090 | } | |
2091 | } | |
2092 | } | |
2093 | } | |
2094 | else | |
2095 | { | |
2096 | int visible_p, newpos, next_stop; | |
2097 | Lisp_Object pos, prop; | |
2098 | ||
2099 | /* First of all, is there invisible text at this position? */ | |
2100 | XSETFASTINT (pos, IT_CHARPOS (*it)); | |
2101 | prop = Fget_char_property (pos, Qinvisible, it->window); | |
2102 | ||
2103 | /* If we are on invisible text, skip over it. */ | |
eadc0bf8 GM |
2104 | if (TEXT_PROP_MEANS_INVISIBLE (prop) |
2105 | && IT_CHARPOS (*it) < it->end_charpos) | |
5f5c8ee5 GM |
2106 | { |
2107 | /* Record whether we have to display an ellipsis for the | |
2108 | invisible text. */ | |
2109 | int display_ellipsis_p | |
2110 | = TEXT_PROP_MEANS_INVISIBLE_WITH_ELLIPSIS (prop); | |
2111 | ||
2112 | handled = HANDLED_RECOMPUTE_PROPS; | |
2113 | ||
2114 | /* Loop skipping over invisible text. The loop is left at | |
2115 | ZV or with IT on the first char being visible again. */ | |
2116 | do | |
2117 | { | |
2118 | /* Try to skip some invisible text. Return value is the | |
2119 | position reached which can be equal to IT's position | |
2120 | if there is nothing invisible here. This skips both | |
2121 | over invisible text properties and overlays with | |
2122 | invisible property. */ | |
2123 | newpos = skip_invisible (IT_CHARPOS (*it), | |
2124 | &next_stop, ZV, it->window); | |
2125 | ||
2126 | /* If we skipped nothing at all we weren't at invisible | |
2127 | text in the first place. If everything to the end of | |
2128 | the buffer was skipped, end the loop. */ | |
2129 | if (newpos == IT_CHARPOS (*it) || newpos >= ZV) | |
2130 | visible_p = 1; | |
2131 | else | |
2132 | { | |
2133 | /* We skipped some characters but not necessarily | |
2134 | all there are. Check if we ended up on visible | |
2135 | text. Fget_char_property returns the property of | |
2136 | the char before the given position, i.e. if we | |
2137 | get visible_p = 1, this means that the char at | |
2138 | newpos is visible. */ | |
2139 | XSETFASTINT (pos, newpos); | |
2140 | prop = Fget_char_property (pos, Qinvisible, it->window); | |
2141 | visible_p = !TEXT_PROP_MEANS_INVISIBLE (prop); | |
2142 | } | |
2143 | ||
2144 | /* If we ended up on invisible text, proceed to | |
2145 | skip starting with next_stop. */ | |
2146 | if (!visible_p) | |
2147 | IT_CHARPOS (*it) = next_stop; | |
2148 | } | |
2149 | while (!visible_p); | |
2150 | ||
2151 | /* The position newpos is now either ZV or on visible text. */ | |
2152 | IT_CHARPOS (*it) = newpos; | |
2153 | IT_BYTEPOS (*it) = CHAR_TO_BYTE (newpos); | |
2154 | ||
2155 | /* Maybe return `...' next for the end of the invisible text. */ | |
2156 | if (display_ellipsis_p) | |
2157 | { | |
2158 | if (it->dp | |
2159 | && VECTORP (DISP_INVIS_VECTOR (it->dp))) | |
2160 | { | |
2161 | struct Lisp_Vector *v = XVECTOR (DISP_INVIS_VECTOR (it->dp)); | |
2162 | it->dpvec = v->contents; | |
2163 | it->dpend = v->contents + v->size; | |
2164 | } | |
2165 | else | |
2166 | { | |
2167 | /* Default `...'. */ | |
2168 | it->dpvec = default_invis_vector; | |
2169 | it->dpend = default_invis_vector + 3; | |
2170 | } | |
2171 | ||
2172 | /* The ellipsis display does not replace the display of | |
2173 | the character at the new position. Indicate this by | |
2174 | setting IT->dpvec_char_len to zero. */ | |
2175 | it->dpvec_char_len = 0; | |
2176 | ||
2177 | it->current.dpvec_index = 0; | |
2178 | it->method = next_element_from_display_vector; | |
2179 | } | |
2180 | } | |
2181 | } | |
2182 | ||
2183 | return handled; | |
2184 | } | |
2185 | ||
2186 | ||
2187 | \f | |
2188 | /*********************************************************************** | |
2189 | 'display' property | |
2190 | ***********************************************************************/ | |
2191 | ||
2192 | /* Set up iterator IT from `display' property at its current position. | |
2193 | Called from handle_stop. */ | |
2194 | ||
2195 | static enum prop_handled | |
2196 | handle_display_prop (it) | |
2197 | struct it *it; | |
2198 | { | |
2199 | Lisp_Object prop, object; | |
2200 | struct text_pos *position; | |
2201 | int space_or_image_found_p; | |
2202 | ||
2203 | if (STRINGP (it->string)) | |
2204 | { | |
2205 | object = it->string; | |
2206 | position = &it->current.string_pos; | |
2207 | } | |
2208 | else | |
2209 | { | |
2210 | object = Qnil; | |
2211 | position = &it->current.pos; | |
2212 | } | |
2213 | ||
2214 | /* Reset those iterator values set from display property values. */ | |
2215 | it->font_height = Qnil; | |
2216 | it->space_width = Qnil; | |
2217 | it->voffset = 0; | |
2218 | ||
2219 | /* We don't support recursive `display' properties, i.e. string | |
2220 | values that have a string `display' property, that have a string | |
2221 | `display' property etc. */ | |
2222 | if (!it->string_from_display_prop_p) | |
2223 | it->area = TEXT_AREA; | |
2224 | ||
2225 | prop = Fget_char_property (make_number (position->charpos), | |
2226 | Qdisplay, object); | |
2227 | if (NILP (prop)) | |
2228 | return HANDLED_NORMALLY; | |
2229 | ||
2230 | space_or_image_found_p = 0; | |
f3751a65 GM |
2231 | if (CONSP (prop) |
2232 | && CONSP (XCAR (prop)) | |
2233 | && !EQ (Qmargin, XCAR (XCAR (prop)))) | |
5f5c8ee5 | 2234 | { |
f3751a65 | 2235 | /* A list of sub-properties. */ |
5f5c8ee5 GM |
2236 | while (CONSP (prop)) |
2237 | { | |
2238 | if (handle_single_display_prop (it, XCAR (prop), object, position)) | |
2239 | space_or_image_found_p = 1; | |
2240 | prop = XCDR (prop); | |
2241 | } | |
2242 | } | |
2243 | else if (VECTORP (prop)) | |
2244 | { | |
2245 | int i; | |
2246 | for (i = 0; i < XVECTOR (prop)->size; ++i) | |
2247 | if (handle_single_display_prop (it, XVECTOR (prop)->contents[i], | |
2248 | object, position)) | |
2249 | space_or_image_found_p = 1; | |
2250 | } | |
2251 | else | |
2252 | { | |
2253 | if (handle_single_display_prop (it, prop, object, position)) | |
2254 | space_or_image_found_p = 1; | |
2255 | } | |
2256 | ||
2257 | return space_or_image_found_p ? HANDLED_RETURN : HANDLED_NORMALLY; | |
2258 | } | |
2259 | ||
2260 | ||
6c577098 | 2261 | /* Value is the position of the end of the `display' property starting |
5f5c8ee5 GM |
2262 | at START_POS in OBJECT. */ |
2263 | ||
2264 | static struct text_pos | |
2265 | display_prop_end (it, object, start_pos) | |
2266 | struct it *it; | |
2267 | Lisp_Object object; | |
2268 | struct text_pos start_pos; | |
2269 | { | |
2270 | Lisp_Object end; | |
2271 | struct text_pos end_pos; | |
5f5c8ee5 | 2272 | |
6c577098 GM |
2273 | end = next_single_char_property_change (make_number (CHARPOS (start_pos)), |
2274 | Qdisplay, object, Qnil); | |
2275 | CHARPOS (end_pos) = XFASTINT (end); | |
2276 | if (STRINGP (object)) | |
5f5c8ee5 GM |
2277 | compute_string_pos (&end_pos, start_pos, it->string); |
2278 | else | |
6c577098 | 2279 | BYTEPOS (end_pos) = CHAR_TO_BYTE (XFASTINT (end)); |
5f5c8ee5 GM |
2280 | |
2281 | return end_pos; | |
2282 | } | |
2283 | ||
2284 | ||
2285 | /* Set up IT from a single `display' sub-property value PROP. OBJECT | |
2286 | is the object in which the `display' property was found. *POSITION | |
2287 | is the position at which it was found. | |
2288 | ||
2289 | If PROP is a `space' or `image' sub-property, set *POSITION to the | |
2290 | end position of the `display' property. | |
2291 | ||
2292 | Value is non-zero if a `space' or `image' property value was found. */ | |
2293 | ||
2294 | static int | |
2295 | handle_single_display_prop (it, prop, object, position) | |
2296 | struct it *it; | |
2297 | Lisp_Object prop; | |
2298 | Lisp_Object object; | |
2299 | struct text_pos *position; | |
2300 | { | |
2301 | Lisp_Object value; | |
2302 | int space_or_image_found_p = 0; | |
2303 | ||
2304 | Lisp_Object form; | |
2305 | ||
d3acf96b | 2306 | /* If PROP is a list of the form `(when FORM . VALUE)', FORM is |
5a4c88c4 | 2307 | evaluated. If the result is nil, VALUE is ignored. */ |
5f5c8ee5 | 2308 | form = Qt; |
d3acf96b | 2309 | if (CONSP (prop) && EQ (XCAR (prop), Qwhen)) |
5f5c8ee5 GM |
2310 | { |
2311 | prop = XCDR (prop); | |
2312 | if (!CONSP (prop)) | |
2313 | return 0; | |
2314 | form = XCAR (prop); | |
2315 | prop = XCDR (prop); | |
5f5c8ee5 GM |
2316 | } |
2317 | ||
2318 | if (!NILP (form) && !EQ (form, Qt)) | |
2319 | { | |
2320 | struct gcpro gcpro1; | |
2321 | struct text_pos end_pos, pt; | |
2322 | ||
5f5c8ee5 | 2323 | GCPRO1 (form); |
c7aca1ad | 2324 | end_pos = display_prop_end (it, object, *position); |
5f5c8ee5 GM |
2325 | |
2326 | /* Temporarily set point to the end position, and then evaluate | |
2327 | the form. This makes `(eolp)' work as FORM. */ | |
c7aca1ad GM |
2328 | if (BUFFERP (object)) |
2329 | { | |
2330 | CHARPOS (pt) = PT; | |
2331 | BYTEPOS (pt) = PT_BYTE; | |
2332 | TEMP_SET_PT_BOTH (CHARPOS (end_pos), BYTEPOS (end_pos)); | |
2333 | } | |
2334 | ||
5f5c8ee5 | 2335 | form = eval_form (form); |
c7aca1ad GM |
2336 | |
2337 | if (BUFFERP (object)) | |
2338 | TEMP_SET_PT_BOTH (CHARPOS (pt), BYTEPOS (pt)); | |
5f5c8ee5 GM |
2339 | UNGCPRO; |
2340 | } | |
2341 | ||
2342 | if (NILP (form)) | |
2343 | return 0; | |
2344 | ||
2345 | if (CONSP (prop) | |
2346 | && EQ (XCAR (prop), Qheight) | |
2347 | && CONSP (XCDR (prop))) | |
2348 | { | |
2349 | if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) | |
2350 | return 0; | |
2351 | ||
2352 | /* `(height HEIGHT)'. */ | |
2353 | it->font_height = XCAR (XCDR (prop)); | |
2354 | if (!NILP (it->font_height)) | |
2355 | { | |
2356 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
2357 | int new_height = -1; | |
2358 | ||
2359 | if (CONSP (it->font_height) | |
2360 | && (EQ (XCAR (it->font_height), Qplus) | |
2361 | || EQ (XCAR (it->font_height), Qminus)) | |
2362 | && CONSP (XCDR (it->font_height)) | |
2363 | && INTEGERP (XCAR (XCDR (it->font_height)))) | |
2364 | { | |
2365 | /* `(+ N)' or `(- N)' where N is an integer. */ | |
2366 | int steps = XINT (XCAR (XCDR (it->font_height))); | |
2367 | if (EQ (XCAR (it->font_height), Qplus)) | |
2368 | steps = - steps; | |
2369 | it->face_id = smaller_face (it->f, it->face_id, steps); | |
2370 | } | |
2371 | else if (SYMBOLP (it->font_height)) | |
2372 | { | |
2373 | /* Call function with current height as argument. | |
2374 | Value is the new height. */ | |
2375 | Lisp_Object form, height; | |
2376 | struct gcpro gcpro1; | |
2377 | ||
2378 | height = face->lface[LFACE_HEIGHT_INDEX]; | |
2379 | form = Fcons (it->font_height, Fcons (height, Qnil)); | |
2380 | GCPRO1 (form); | |
2381 | height = eval_form (form); | |
2382 | if (NUMBERP (height)) | |
2383 | new_height = XFLOATINT (height); | |
2384 | UNGCPRO; | |
2385 | } | |
2386 | else if (NUMBERP (it->font_height)) | |
2387 | { | |
2388 | /* Value is a multiple of the canonical char height. */ | |
2389 | struct face *face; | |
2390 | ||
2391 | face = FACE_FROM_ID (it->f, DEFAULT_FACE_ID); | |
2392 | new_height = (XFLOATINT (it->font_height) | |
2393 | * XINT (face->lface[LFACE_HEIGHT_INDEX])); | |
2394 | } | |
2395 | else | |
2396 | { | |
2397 | /* Evaluate IT->font_height with `height' bound to the | |
2398 | current specified height to get the new height. */ | |
2399 | Lisp_Object value; | |
2400 | int count = specpdl_ptr - specpdl; | |
2401 | ||
2402 | specbind (Qheight, face->lface[LFACE_HEIGHT_INDEX]); | |
2403 | value = eval_form (it->font_height); | |
2404 | unbind_to (count, Qnil); | |
2405 | ||
2406 | if (NUMBERP (value)) | |
2407 | new_height = XFLOATINT (value); | |
2408 | } | |
2409 | ||
2410 | if (new_height > 0) | |
2411 | it->face_id = face_with_height (it->f, it->face_id, new_height); | |
2412 | } | |
2413 | } | |
2414 | else if (CONSP (prop) | |
2415 | && EQ (XCAR (prop), Qspace_width) | |
2416 | && CONSP (XCDR (prop))) | |
2417 | { | |
2418 | /* `(space_width WIDTH)'. */ | |
2419 | if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) | |
2420 | return 0; | |
2421 | ||
2422 | value = XCAR (XCDR (prop)); | |
2423 | if (NUMBERP (value) && XFLOATINT (value) > 0) | |
2424 | it->space_width = value; | |
2425 | } | |
2426 | else if (CONSP (prop) | |
2427 | && EQ (XCAR (prop), Qraise) | |
2428 | && CONSP (XCDR (prop))) | |
2429 | { | |
5f5c8ee5 GM |
2430 | /* `(raise FACTOR)'. */ |
2431 | if (FRAME_TERMCAP_P (it->f) || FRAME_MSDOS_P (it->f)) | |
2432 | return 0; | |
2433 | ||
fb3842a8 | 2434 | #ifdef HAVE_WINDOW_SYSTEM |
5f5c8ee5 GM |
2435 | value = XCAR (XCDR (prop)); |
2436 | if (NUMBERP (value)) | |
2437 | { | |
2438 | struct face *face = FACE_FROM_ID (it->f, it->face_id); | |
2439 | it->voffset = - (XFLOATINT (value) | |
1ab3e082 | 2440 | * (FONT_HEIGHT (face->font))); |
5f5c8ee5 GM |
2441 | } |
2442 | #endif /* HAVE_WINDOW_SYSTEM */ | |
2443 | } | |
2444 | else if (!it->string_from_display_prop_p) | |
2445 | { | |
f3751a65 GM |
2446 | /* `((margin left-margin) VALUE)' or `((margin right-margin) |
2447 | VALUE) or `((margin nil) VALUE)' or VALUE. */ | |
5f5c8ee5 GM |
2448 | Lisp_Object location, value; |
2449 | struct text_pos start_pos; | |
2450 | int valid_p; | |
2451 | ||
2452 | /* Characters having this form of property are not displayed, so | |
2453 | we have to find the end of the property. */ | |
5f5c8ee5 GM |
2454 | start_pos = *position; |
2455 | *position = display_prop_end (it, object, start_pos); | |
15e26c76 | 2456 | value = Qnil; |
5f5c8ee5 GM |
2457 | |
2458 | /* Let's stop at the new position and assume that all | |
2459 | text properties change there. */ | |
2460 | it->stop_charpos = position->charpos; | |
2461 | ||
f3751a65 GM |
2462 | location = Qunbound; |
2463 | if (CONSP (prop) && CONSP (XCAR (prop))) | |
5f5c8ee5 | 2464 | { |
f3751a65 GM |
2465 | Lisp_Object tem; |
2466 | ||
5f5c8ee5 | 2467 | value = XCDR (prop); |
f3751a65 GM |
2468 | if (CONSP (value)) |
2469 | value = XCAR (value); | |
2470 | ||
2471 | tem = XCAR (prop); | |
2472 | if (EQ (XCAR (tem), Qmargin) | |
2473 | && (tem = XCDR (tem), | |
2474 | tem = CONSP (tem) ? XCAR (tem) : Qnil, | |
2475 | (NILP (tem) | |
2476 | || EQ (tem, Qleft_margin) | |
2477 | || EQ (tem, Qright_margin)))) | |
2478 | location = tem; | |
5f5c8ee5 | 2479 | } |
f3751a65 GM |
2480 | |
2481 | if (EQ (location, Qunbound)) | |
5f5c8ee5 GM |
2482 | { |
2483 | location = Qnil; | |
2484 | value = prop; | |
2485 | } | |
2486 | ||
2487 | #ifdef HAVE_WINDOW_SYSTEM | |
fb3842a8 | 2488 | if (FRAME_TERMCAP_P (it->f)) |
5f5c8ee5 GM |
2489 | valid_p = STRINGP (value); |
2490 | else | |
2491 | valid_p = (STRINGP (value) | |
2492 | || (CONSP (value) && EQ (XCAR (value), Qspace)) | |
2493 | || valid_image_p (value)); | |
2494 | #else /* not HAVE_WINDOW_SYSTEM */ | |
2495 | valid_p = STRINGP (value); | |
2496 | #endif /* not HAVE_WINDOW_SYSTEM */ | |
2497 | ||
2498 | if ((EQ (location, Qleft_margin) | |
2499 | || EQ (location, Qright_margin) | |
2500 | || NILP (location)) | |
2501 | && valid_p) | |
2502 | { | |
a21a3943 GM |
2503 | space_or_image_found_p = 1; |
2504 | ||
5f5c8ee5 GM |
2505 | /* Save current settings of IT so that we can restore them |
2506 | when we are finished with the glyph property value. */ | |
2507 | push_it (it); | |
2508 | ||
2509 | if (NILP (location)) | |
2510 | it->area = TEXT_AREA; | |
2511 | else if (EQ (location, Qleft_margin)) | |
2512 | it->area = LEFT_MARGIN_AREA; | |
2513 | else | |
2514 | it->area = RIGHT_MARGIN_AREA; | |
2515 | ||
2516 | if (STRINGP (value)) | |
2517 | { | |
2518 | it->string = value; | |
2519 | it->multibyte_p = STRING_MULTIBYTE (it->string); | |
2520 | it->current.overlay_string_index = -1; | |
2521 | IT_STRING_CHARPOS (*it) = IT_STRING_BYTEPOS (*it) = 0; | |
2522 | it->end_charpos = it->string_nchars | |
2523 | = XSTRING (it->string)->size; | |
2524 | it->method = next_element_from_string; | |
2525 | it->stop_charpos = 0; | |
2526 | it->string_from_display_prop_p = 1; | |
2527 | } | |
2528 | else if (CONSP (value) && EQ (XCAR (value), Qspace)) | |
2529 | { | |
2530 | it->method = next_element_from_stretch; | |
2531 | it->object = value; | |
2532 | it->current.pos = it->position = start_pos; | |
2533 | } | |
2534 | #ifdef HAVE_WINDOW_SYSTEM | |
2535 | else | |
2536 | { | |
2537 | it->what = IT_IMAGE; | |
2538 | it->image_id = lookup_image (it->f, value); | |
2539 | it->position = start_pos; | |
2540 | it->object = NILP (object) ? it->w->buffer : object; | |
2541 | it->method = next_element_from_image; | |
2542 | ||
02513cdd | 2543 | /* Say that we haven't consumed the characters with |
5f5c8ee5 GM |
2544 | `display' property yet. The call to pop_it in |
2545 | set_iterator_to_next will clean this up. */ | |
2546 | *position = start_pos; | |
2547 | } | |
2548 | #endif /* HAVE_WINDOW_SYSTEM */ | |
2549 | } | |
a21a3943 GM |
2550 | else |
2551 | /* Invalid property or property not supported. Restore | |
2552 | the position to what it was before. */ | |
2553 | *position = start_pos; | |
5f5c8ee5 GM |
2554 | } |
2555 | ||
2556 | return space_or_image_found_p; | |
2557 | } | |
2558 | ||
2559 | ||
2560 | \f | |
260a86a0 KH |
2561 | /*********************************************************************** |
2562 | `composition' property | |
2563 | ***********************************************************************/ | |
2564 | ||
2565 | /* Set up iterator IT from `composition' property at its current | |
2566 | position. Called from handle_stop. */ | |
2567 | ||
2568 | static enum prop_handled | |
2569 | handle_composition_prop (it) | |
2570 | struct it *it; | |
2571 | { | |
2572 | Lisp_Object prop, string; | |
2573 | int pos, pos_byte, end; | |
2574 | enum prop_handled handled = HANDLED_NORMALLY; | |
2575 | ||
2576 | if (STRINGP (it->string)) | |
2577 | { | |
2578 | pos = IT_STRING_CHARPOS (*it); | |
2579 | pos_byte = IT_STRING_BYTEPOS (*it); | |
2580 | string = it->string; | |
2581 | } | |
2582 | else | |
2583 | { | |
2584 | pos = IT_CHARPOS (*it); | |
2585 | pos_byte = IT_BYTEPOS (*it); | |
2586 | string = Qnil; | |
2587 | } | |
2588 | ||
2589 | /* If there's a valid composition and point is not inside of the | |
2590 | composition (in the case that the composition is from the current | |
2591 | buffer), draw a glyph composed from the composition components. */ | |
2592 | if (find_composition (pos, -1, &pos, &end, &prop, string) | |
2593 | && COMPOSITION_VALID_P (pos, end, prop) | |
2594 | && (STRINGP (it->string) || (PT <= pos || PT >= end))) | |
2595 | { | |
2596 | int id = get_composition_id (pos, pos_byte, end - pos, prop, string); | |
2597 | ||
2598 | if (id >= 0) | |
2599 | { | |
2600 | it->method = next_element_from_composition; | |
2601 | it->cmp_id = id; | |
2602 | it->cmp_len = COMPOSITION_LENGTH (prop); | |
2603 | /* For a terminal, draw only the first character of the | |
2604 | components. */ | |
2605 | it->c = COMPOSITION_GLYPH (composition_table[id], 0); | |
2606 | it->len = (STRINGP (it->string) | |
2607 | ? string_char_to_byte (it->string, end) | |
2608 | : CHAR_TO_BYTE (end)) - pos_byte; | |
2609 | it->stop_charpos = end; | |
2610 | handled = HANDLED_RETURN; | |
2611 | } | |
2612 | } | |
2613 | ||
2614 | return handled; | |
2615 | } | |
2616 | ||
2617 | ||
2618 | \f | |
5f5c8ee5 GM |
2619 | /*********************************************************************** |
2620 | Overlay strings | |
2621 | ***********************************************************************/ | |
2622 | ||
2623 | /* The following structure is used to record overlay strings for | |
2624 | later sorting in load_overlay_strings. */ | |
2625 | ||
2626 | struct overlay_entry | |
2627 | { | |
2628 | Lisp_Object string; | |
2629 | int priority; | |
2630 | int after_string_p; | |
2631 | }; | |
2632 | ||
2633 | ||
2634 | /* Set up iterator IT from overlay strings at its current position. | |
2635 | Called from handle_stop. */ | |
2636 | ||
2637 | static enum prop_handled | |
2638 | handle_overlay_change (it) | |
2639 | struct it *it; | |
2640 | { | |
2641 | /* Overlays are handled in current_buffer only. */ | |
2642 | if (STRINGP (it->string)) | |
2643 | return HANDLED_NORMALLY; | |
2644 | else | |
2645 | return (get_overlay_strings (it) | |
2646 | ? HANDLED_RECOMPUTE_PROPS | |
2647 | : HANDLED_NORMALLY); | |
2648 | } | |
2649 | ||
2650 | ||
2651 | /* Set up the next overlay string for delivery by IT, if there is an | |
2652 | overlay string to deliver. Called by set_iterator_to_next when the | |
2653 | end of the current overlay string is reached. If there are more | |
2654 | overlay strings to display, IT->string and | |
2655 | IT->current.overlay_string_index are set appropriately here. | |
2656 | Otherwise IT->string is set to nil. */ | |
2657 | ||
2658 | static void | |
2659 | next_overlay_string (it) | |
2660 | struct it *it; | |
2661 | { | |
2662 | ++it->current.overlay_string_index; | |
2663 | if (it->current.overlay_string_index == it->n_overlay_strings) | |
2664 | { | |
2665 | /* No more overlay strings. Restore IT's settings to what | |
2666 | they were before overlay strings were processed, and | |
2667 | continue to deliver from current_buffer. */ | |
2668 | pop_it (it); | |
2669 | xassert (it->stop_charpos >= BEGV | |
2670 | && it->stop_charpos <= it->end_charpos); | |
2671 | it->string = Qnil; | |
2672 | it->current.overlay_string_index = -1; | |
2673 | SET_TEXT_POS (it->current.string_pos, -1, -1); | |
2674 | it->n_overlay_strings = 0; | |
2675 | it->method = next_element_from_buffer; | |
2676 | } | |
2677 | else | |
2678 | { | |
2679 | /* There are more overlay strings to process. If | |
2680 | IT->current.overlay_string_index has advanced to a position | |
2681 | where we must load IT->overlay_strings with more strings, do | |
2682 | it. */ | |
2683 | int i = it->current.overlay_string_index % OVERLAY_STRING_CHUNK_SIZE; | |
2684 | ||
2685 | if (it->current.overlay_string_index && i == 0) | |
2686 | load_overlay_strings (it); | |
2687 | ||
2688 | /* Initialize IT to deliver display elements from the overlay | |
2689 | string. */ | |
2690 | it->string = it->overlay_strings[i]; | |
2691 | it->multibyte_p = STRING_MULTIBYTE (it->string); | |
2692 | SET_TEXT_POS (it->current.string_pos, 0, 0); | |
2693 | it->method = next_element_from_string; | |
2694 | it->stop_charpos = 0; | |
2695 | } | |
2696 | ||
2697 | CHECK_IT (it); | |
2698 | } | |
2699 | ||
2700 | ||
2701 | /* Compare two overlay_entry structures E1 and E2. Used as a | |
2702 | comparison function for qsort in load_overlay_strings. Overlay | |
2703 | strings for the same position are sorted so that | |
2704 | ||
2705 | 1. All after-strings come in front of before-strings. | |
2706 | ||
2707 | 2. Within after-strings, strings are sorted so that overlay strings | |
2708 | from overlays with higher priorities come first. | |
2709 | ||
2710 | 2. Within before-strings, strings are sorted so that overlay | |
2711 | strings from overlays with higher priorities come last. | |
2712 | ||
2713 | Value is analogous to strcmp. */ | |
2714 | ||
2715 | ||
2716 | static int | |
2717 | compare_overlay_entries (e1, e2) | |
2718 | void *e1, *e2; | |
2719 | { | |
2720 | struct overlay_entry *entry1 = (struct overlay_entry *) e1; | |
2721 | struct overlay_entry *entry2 = (struct overlay_entry *) e2; | |
2722 | int result; | |
2723 | ||
2724 | if (entry1->after_string_p != entry2->after_string_p) | |
2725 | /* Let after-strings appear in front of before-strings. */ | |
2726 | result = entry1->after_string_p ? -1 : 1; | |
2727 | else if (entry1->after_string_p) | |
2728 | /* After-strings sorted in order of decreasing priority. */ | |
2729 | result = entry2->priority - entry1->priority; | |
2730 | else | |
2731 | /* Before-strings sorted in order of increasing priority. */ | |
2732 | result = entry1->priority - entry2->priority; | |
2733 | ||
2734 | return result; | |
2735 | } | |
2736 | ||
2737 | ||
2738 | /* Load the vector IT->overlay_strings with overlay strings from IT's | |
2739 | current buffer position. Set IT->n_overlays to the total number of | |
2740 | overlay strings found. | |
2741 | ||
2742 | Overlay strings are processed OVERLAY_STRING_CHUNK_SIZE strings at | |
2743 | a time. On entry into load_overlay_strings, | |
2744 | IT->current.overlay_string_index gives the number of overlay | |
2745 | strings that have already been loaded by previous calls to this | |
2746 | function. | |
2747 | ||
2748 | Overlay strings are sorted so that after-string strings come in | |
2749 | front of before-string strings. Within before and after-strings, | |
2750 | strings are sorted by overlay priority. See also function | |
2751 | compare_overlay_entries. */ | |
2752 | ||
2753 | static void | |
2754 | load_overlay_strings (it) | |
2755 | struct it *it; | |
2756 | { | |
2757 | extern Lisp_Object Qafter_string, Qbefore_string, Qwindow, Qpriority; | |
2758 | Lisp_Object ov, overlay, window, str; | |
2759 | int start, end; | |
2760 | int size = 20; | |
2761 | int n = 0, i, j; | |
2762 | struct overlay_entry *entries | |
2763 | = (struct overlay_entry *) alloca (size * sizeof *entries); | |
2764 | ||
2765 | /* Append the overlay string STRING of overlay OVERLAY to vector | |
2766 | `entries' which has size `size' and currently contains `n' | |
2767 | elements. AFTER_P non-zero means STRING is an after-string of | |
2768 | OVERLAY. */ | |
2769 | #define RECORD_OVERLAY_STRING(OVERLAY, STRING, AFTER_P) \ | |
2770 | do \ | |
2771 | { \ | |
2772 | Lisp_Object priority; \ | |
2773 | \ | |
2774 | if (n == size) \ | |
2775 | { \ | |
2776 | int new_size = 2 * size; \ | |
2777 | struct overlay_entry *old = entries; \ | |
2778 | entries = \ | |
2779 | (struct overlay_entry *) alloca (new_size \ | |
2780 | * sizeof *entries); \ | |
2781 | bcopy (old, entries, size * sizeof *entries); \ | |
2782 | size = new_size; \ | |
2783 | } \ | |
2784 | \ | |
2785 | entries[n].string = (STRING); \ | |
2786 | priority = Foverlay_get ((OVERLAY), Qpriority); \ | |
2787 | entries[n].priority \ | |
2788 | = INTEGERP (priority) ? XFASTINT (priority) : 0; \ | |
2789 | entries[n].after_string_p = (AFTER_P); \ | |
2790 | ++n; \ | |
2791 | } \ | |
2792 | while (0) | |
2793 | ||
2794 | /* Process overlay before the overlay center. */ | |
2795 | for (ov = current_buffer->overlays_before; | |
2796 | CONSP (ov); | |
9472f927 | 2797 | ov = XCDR (ov)) |
5f5c8ee5 | 2798 | { |
9472f927 | 2799 | overlay = XCAR (ov); |
5f5c8ee5 GM |
2800 | xassert (OVERLAYP (overlay)); |
2801 | start = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
2802 | end = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
2803 | ||
2804 | if (end < IT_CHARPOS (*it)) | |
2805 | break; | |
2806 | ||
2807 | /* Skip this overlay if it doesn't start or end at IT's current | |
2808 | position. */ | |
2809 | if (end != IT_CHARPOS (*it) && start != IT_CHARPOS (*it)) | |
2810 | continue; | |
2811 | ||
2812 | /* Skip this overlay if it doesn't apply to IT->w. */ | |
2813 | window = Foverlay_get (overlay, Qwindow); | |
2814 | if (WINDOWP (window) && XWINDOW (window) != it->w) | |
2815 | continue; | |
2816 | ||
2817 | /* If overlay has a non-empty before-string, record it. */ | |
2818 | if (start == IT_CHARPOS (*it) | |
2819 | && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)) | |
2820 | && XSTRING (str)->size) | |
2821 | RECORD_OVERLAY_STRING (overlay, str, 0); | |
2822 | ||
2823 | /* If overlay has a non-empty after-string, record it. */ | |
2824 | if (end == IT_CHARPOS (*it) | |
2825 | && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)) | |
2826 | && XSTRING (str)->size) | |
2827 | RECORD_OVERLAY_STRING (overlay, str, 1); | |
2828 | } | |
2829 | ||
2830 | /* Process overlays after the overlay center. */ | |
2831 | for (ov = current_buffer->overlays_after; | |
2832 | CONSP (ov); | |
9472f927 | 2833 | ov = XCDR (ov)) |
5f5c8ee5 | 2834 | { |
9472f927 | 2835 | overlay = XCAR (ov); |
5f5c8ee5 GM |
2836 | xassert (OVERLAYP (overlay)); |
2837 | start = OVERLAY_POSITION (OVERLAY_START (overlay)); | |
2838 | end = OVERLAY_POSITION (OVERLAY_END (overlay)); | |
2839 | ||
2840 | if (start > IT_CHARPOS (*it)) | |
2841 | break; | |
2842 | ||
2843 | /* Skip this overlay if it doesn't start or end at IT's current | |
2844 | position. */ | |
2845 | if (end != IT_CHARPOS (*it) && start != IT_CHARPOS (*it)) | |
2846 | continue; | |
2847 | ||
2848 | /* Skip this overlay if it doesn't apply to IT->w. */ | |
2849 | window = Foverlay_get (overlay, Qwindow); | |
2850 | if (WINDOWP (window) && XWINDOW (window) != it->w) | |
2851 | continue; | |
2852 | ||
2853 | /* If overlay has a non-empty before-string, record it. */ | |
2854 | if (start == IT_CHARPOS (*it) | |
2855 | && (str = Foverlay_get (overlay, Qbefore_string), STRINGP (str)) | |
2856 | && XSTRING (str)->size) | |
2857 | RECORD_OVERLAY_STRING (overlay, str, 0); | |
2858 | ||
2859 | /* If overlay has a non-empty after-string, record it. */ | |
2860 | if (end == IT_CHARPOS (*it) | |
2861 | && (str = Foverlay_get (overlay, Qafter_string), STRINGP (str)) | |
2862 | && XSTRING (str)->size) | |
2863 | RECORD_OVERLAY_STRING (overlay, str, 1); | |
2864 | } | |
2865 | ||
2866 | #undef RECORD_OVERLAY_STRING | |
2867 | ||
2868 | /* Sort entries. */ | |
2869 | qsort (entries, n, sizeof *entries, compare_overlay_entries); | |
2870 | ||
2871 | /* Record the total number of strings to process. */ | |
2872 | it->n_overlay_strings = n; | |
2873 | ||
2874 | /* IT->current.overlay_string_index is the number of overlay strings | |
2875 | that have already been consumed by IT. Copy some of the | |
2876 | remaining overlay strings to IT->overlay_strings. */ | |
2877 | i = 0; | |
2878 | j = it->current.overlay_string_index; | |
2879 | while (i < OVERLAY_STRING_CHUNK_SIZE && j < n) | |
2880 | it->overlay_strings[i++] = entries[j++].string; | |
2881 | ||
2882 | CHECK_IT (it); | |
2883 | } | |
2884 | ||
2885 | ||
2886 | /* Get the first chunk of overlay strings at IT's current buffer | |
2887 | position. Value is non-zero if at least one overlay string was | |
2888 | found. */ | |
2889 | ||
2890 | static int | |
2891 | get_overlay_strings (it) | |
2892 | struct it *it; | |
2893 | { | |
2894 | /* Get the first OVERLAY_STRING_CHUNK_SIZE overlay strings to | |
2895 | process. This fills IT->overlay_strings with strings, and sets | |
2896 | IT->n_overlay_strings to the total number of strings to process. | |
2897 | IT->pos.overlay_string_index has to be set temporarily to zero | |
2898 | because load_overlay_strings needs this; it must be set to -1 | |
2899 | when no overlay strings are found because a zero value would | |
2900 | indicate a position in the first overlay string. */ | |
2901 | it->current.overlay_string_index = 0; | |
2902 | load_overlay_strings (it); | |
2903 | ||
2904 | /* If we found overlay strings, set up IT to deliver display | |
2905 | elements from the first one. Otherwise set up IT to deliver | |
2906 | from current_buffer. */ | |
2907 | if (it->n_overlay_strings) | |
2908 | { | |
2909 | /* Make sure we know settings in current_buffer, so that we can | |
2910 | restore meaningful values when we're done with the overlay | |
2911 | strings. */ | |
2912 | compute_stop_pos (it); | |
2913 | xassert (it->face_id >= 0); | |
2914 | ||
2915 | /* Save IT's settings. They are restored after all overlay | |
2916 | strings have been processed. */ | |
2917 | xassert (it->sp == 0); | |
2918 | push_it (it); | |
2919 | ||
2920 | /* Set up IT to deliver display elements from the first overlay | |
2921 | string. */ | |
2922 | IT_STRING_CHARPOS (*it) = IT_STRING_BYTEPOS (*it) = 0; | |
2923 | it->stop_charpos = 0; | |
2924 | it->string = it->overlay_strings[0]; | |
2925 | it->multibyte_p = STRING_MULTIBYTE (it->string); | |
2926 | xassert (STRINGP (it->string)); | |
2927 | it->method = next_element_from_string; | |
2928 | } | |
2929 | else | |
2930 | { | |
2931 | it->string = Qnil; | |
2932 | it->current.overlay_string_index = -1; | |
2933 | it->method = next_element_from_buffer; | |
2934 | } | |
2935 | ||
2936 | CHECK_IT (it); | |
2937 | ||
2938 | /* Value is non-zero if we found at least one overlay string. */ | |
2939 | return STRINGP (it->string); | |
2940 | } | |
2941 | ||
2942 | ||
2943 | \f | |
2944 | /*********************************************************************** | |
2945 | Saving and restoring state | |
2946 | ***********************************************************************/ | |
2947 | ||
2948 | /* Save current settings of IT on IT->stack. Called, for example, | |
2949 | before setting up IT for an overlay string, to be able to restore | |
2950 | IT's settings to what they were after the overlay string has been | |
2951 | processed. */ | |
2952 | ||
2953 | static void | |
2954 | push_it (it) | |
2955 | struct it *it; | |
2956 | { | |
2957 | struct iterator_stack_entry *p; | |
2958 | ||
2959 | xassert (it->sp < 2); | |
2960 | p = it->stack + it->sp; | |
2961 | ||
2962 | p->stop_charpos = it->stop_charpos; | |
2963 | xassert (it->face_id >= 0); | |
2964 | p->face_id = it->face_id; | |
2965 | p->string = it->string; | |
2966 | p->pos = it->current; | |
2967 | p->end_charpos = it->end_charpos; | |
2968 | p->string_nchars = it->string_nchars; | |
2969 | p->area = it->area; | |
2970 | p->multibyte_p = it->multibyte_p; | |
2971 | p->space_width = it->space_width; | |
2972 | p->font_height = it->font_height; | |
2973 | p->voffset = it->voffset; | |
2974 | p->string_from_display_prop_p = it->string_from_display_prop_p; | |
2975 | ++it->sp; | |
2976 | } | |
2977 | ||
2978 | ||
2979 | /* Restore IT's settings from IT->stack. Called, for example, when no | |
2980 | more overlay strings must be processed, and we return to delivering | |
2981 | display elements from a buffer, or when the end of a string from a | |
2982 | `display' property is reached and we return to delivering display | |
2983 | elements from an overlay string, or from a buffer. */ | |
2984 | ||
2985 | static void | |
2986 | pop_it (it) | |
2987 | struct it *it; | |
2988 | { | |
2989 | struct iterator_stack_entry *p; | |
2990 | ||
2991 | xassert (it->sp > 0); | |
2992 | --it->sp; | |
2993 | p = it->stack + it->sp; | |
2994 | it->stop_charpos = p->stop_charpos; | |
2995 | it->face_id = p->face_id; | |
2996 | it->string = p->string; | |
2997 | it->current = p->pos; | |
2998 | it->end_charpos = p->end_charpos; | |
2999 | it->string_nchars = p->string_nchars; | |
3000 | it->area = p->area; | |
3001 | it->multibyte_p = p->multibyte_p; | |
3002 | it->space_width = p->space_width; | |
3003 | it->font_height = p->font_height; | |
3004 | it->voffset = p->voffset; | |
3005 | it->string_from_display_prop_p = p->string_from_display_prop_p; | |
3006 | } | |
3007 | ||
3008 | ||
3009 | \f | |
3010 | /*********************************************************************** | |
3011 | Moving over lines | |
3012 | ***********************************************************************/ | |
3013 | ||
3014 | /* Set IT's current position to the previous line start. */ | |
3015 | ||
3016 | static void | |
3017 | back_to_previous_line_start (it) | |
3018 | struct it *it; | |
3019 | { | |
3020 | IT_CHARPOS (*it) = find_next_newline_no_quit (IT_CHARPOS (*it) - 1, -1); | |
3021 | IT_BYTEPOS (*it) = CHAR_TO_BYTE (IT_CHARPOS (*it)); | |
3022 | } | |
3023 | ||
3024 | ||
3025 | /* Set IT's current position to the next line start. */ | |
3026 | ||
3027 | static void | |
3028 | forward_to_next_line_start (it) | |
3029 | struct it *it; | |
3030 | { | |
3031 | IT_CHARPOS (*it) = find_next_newline_no_quit (IT_CHARPOS (*it), 1); | |
3032 | IT_BYTEPOS (*it) = CHAR_TO_BYTE (IT_CHARPOS (*it)); | |
3033 | } | |
3034 | ||
3035 | ||
3036 | /* Set IT's current position to the previous visible line start. Skip | |
3037 | invisible text that is so either due to text properties or due to | |
3038 | selective display. Caution: this does not change IT->current_x and | |
3039 | IT->hpos. */ | |
3040 | ||
3041 | static void | |
3042 | back_to_previous_visible_line_start (it) | |
3043 | struct it *it; | |
3044 | { | |
3045 | int visible_p = 0; | |
3046 | ||
3047 | /* Go back one newline if not on BEGV already. */ | |
3048 | if (IT_CHARPOS (*it) > BEGV) | |
3049 | back_to_previous_line_start (it); | |
3050 | ||
3051 | /* Move over lines that are invisible because of selective display | |
3052 | or text properties. */ | |
3053 | while (IT_CHARPOS (*it) > BEGV | |
3054 | && !visible_p) | |
3055 | { | |
3056 | visible_p = 1; | |
3057 | ||
3058 | /* If selective > 0, then lines indented more than that values | |
3059 | are invisible. */ | |
3060 | if (it->selective > 0 | |
3061 | && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it), | |
3062 | it->selective)) | |
3063 | visible_p = 0; | |
5f5c8ee5 GM |
3064 | else |
3065 | { | |
3066 | Lisp_Object prop; | |
3067 | ||
6fc556fd KR |
3068 | prop = Fget_char_property (make_number (IT_CHARPOS (*it)), |
3069 | Qinvisible, it->window); | |
5f5c8ee5 GM |
3070 | if (TEXT_PROP_MEANS_INVISIBLE (prop)) |
3071 | visible_p = 0; | |
3072 | } | |
5f5c8ee5 GM |
3073 | |
3074 | /* Back one more newline if the current one is invisible. */ | |
3075 | if (!visible_p) | |
3076 | back_to_previous_line_start (it); | |
3077 | } | |
3078 | ||
3079 | xassert (IT_CHARPOS (*it) >= BEGV); | |
3080 | xassert (IT_CHARPOS (*it) == BEGV | |
3081 | || FETCH_BYTE (IT_BYTEPOS (*it) - 1) == '\n'); | |
3082 | CHECK_IT (it); | |
3083 | } | |
3084 | ||
3085 | ||
3086 | /* Reseat iterator IT at the previous visible line start. Skip | |
3087 | invisible text that is so either due to text properties or due to | |
3088 | selective display. At the end, update IT's overlay information, | |
3089 | face information etc. */ | |
3090 | ||
3091 | static void | |
3092 | reseat_at_previous_visible_line_start (it) | |
3093 | struct it *it; | |
3094 | { | |
3095 | back_to_previous_visible_line_start (it); | |
3096 | reseat (it, it->current.pos, 1); | |
3097 | CHECK_IT (it); | |
3098 | } | |
3099 | ||
3100 | ||
3101 | /* Reseat iterator IT on the next visible line start in the current | |
312246d1 GM |
3102 | buffer. ON_NEWLINE_P non-zero means position IT on the newline |
3103 | preceding the line start. Skip over invisible text that is so | |
3104 | because of selective display. Compute faces, overlays etc at the | |
3105 | new position. Note that this function does not skip over text that | |
3106 | is invisible because of text properties. */ | |
5f5c8ee5 GM |
3107 | |
3108 | static void | |
312246d1 | 3109 | reseat_at_next_visible_line_start (it, on_newline_p) |
5f5c8ee5 | 3110 | struct it *it; |
312246d1 | 3111 | int on_newline_p; |
5f5c8ee5 GM |
3112 | { |
3113 | /* Restore the buffer position when currently not delivering display | |
3114 | elements from the current buffer. This is the case, for example, | |
3115 | when called at the end of a truncated overlay string. */ | |
3116 | while (it->sp) | |
3117 | pop_it (it); | |
3118 | it->method = next_element_from_buffer; | |
3119 | ||
3120 | /* Otherwise, scan_buffer would not work. */ | |
3121 | if (IT_CHARPOS (*it) < ZV) | |
3122 | { | |
3123 | /* If on a newline, advance past it. Otherwise, find the next | |
3124 | newline which automatically gives us the position following | |
3125 | the newline. */ | |
3126 | if (FETCH_BYTE (IT_BYTEPOS (*it)) == '\n') | |
3127 | { | |
3128 | ++IT_CHARPOS (*it); | |
3129 | ++IT_BYTEPOS (*it); | |
3130 | } | |
3131 | else | |
3132 | forward_to_next_line_start (it); | |
3133 | ||
3134 | /* We must either have reached the end of the buffer or end up | |
3135 | after a newline. */ | |
3136 | xassert (IT_CHARPOS (*it) == ZV | |
3137 | || FETCH_BYTE (IT_BYTEPOS (*it) - 1) == '\n'); | |
3138 | ||
3139 | /* Skip over lines that are invisible because they are indented | |
3140 | more than the value of IT->selective. */ | |
3141 | if (it->selective > 0) | |
3142 | while (IT_CHARPOS (*it) < ZV | |
3143 | && indented_beyond_p (IT_CHARPOS (*it), IT_BYTEPOS (*it), | |
3144 | it->selective)) | |
3145 | forward_to_next_line_start (it); | |
312246d1 GM |
3146 | |
3147 | /* Position on the newline if we should. */ | |
13f19968 GM |
3148 | if (on_newline_p |
3149 | && IT_CHARPOS (*it) > BEGV | |
3150 | && FETCH_BYTE (IT_BYTEPOS (*it) - 1) == '\n') | |
312246d1 GM |
3151 | { |
3152 | --IT_CHARPOS (*it); | |
3153 | IT_BYTEPOS (*it) = CHAR_TO_BYTE (IT_CHARPOS (*it)); | |
3154 | } | |
5f5c8ee5 GM |
3155 | |
3156 | /* Set the iterator there. The 0 as the last parameter of | |
3157 | reseat means don't force a text property lookup. The lookup | |
3158 | is then only done if we've skipped past the iterator's | |
3159 | check_charpos'es. This optimization is important because | |
3160 | text property lookups tend to be expensive. */ | |
3161 | reseat (it, it->current.pos, 0); | |
3162 | } | |
3163 | ||
3164 | CHECK_IT (it); | |
3165 | } | |
3166 | ||
3167 | ||
3168 | \f | |
3169 | /*********************************************************************** | |
3170 | Changing an iterator's position | |
3171 | ***********************************************************************/ | |
3172 | ||
3173 | /* Change IT's current position to POS in current_buffer. If FORCE_P | |
3174 | is non-zero, always check for text properties at the new position. | |
3175 | Otherwise, text properties are only looked up if POS >= | |
3176 | IT->check_charpos of a property. */ | |
3177 | ||
3178 | static void | |
3179 | reseat (it, pos, force_p) | |
3180 | struct it *it; | |
3181 | struct text_pos pos; | |
3182 | int force_p; | |
3183 | { | |
3184 | int original_pos = IT_CHARPOS (*it); | |
3185 | ||
3186 | reseat_1 (it, pos, 0); | |
3187 | ||
3188 | /* Determine where to check text properties. Avoid doing it | |
3189 | where possible because text property lookup is very expensive. */ | |
3190 | if (force_p | |
3191 | || CHARPOS (pos) > it->stop_charpos | |
3192 | || CHARPOS (pos) < original_pos) | |
3193 | handle_stop (it); | |
3194 | ||
3195 | CHECK_IT (it); | |
3196 | } | |
3197 | ||
3198 | ||
3199 | /* Change IT's buffer position to POS. SET_STOP_P non-zero means set | |
3200 | IT->stop_pos to POS, also. */ | |
3201 | ||
3202 | static void | |
3203 | reseat_1 (it, pos, set_stop_p) | |
3204 | struct it *it; | |
3205 | struct text_pos pos; | |
3206 | int set_stop_p; | |
3207 | { | |
3208 | /* Don't call this function when scanning a C string. */ | |
3209 | xassert (it->s == NULL); | |
3210 | ||
3211 | /* POS must be a reasonable value. */ | |
3212 | xassert (CHARPOS (pos) >= BEGV && CHARPOS (pos) <= ZV); | |
3213 | ||
3214 | it->current.pos = it->position = pos; | |
3215 | XSETBUFFER (it->object, current_buffer); | |
3216 | it->dpvec = NULL; | |
3217 | it->current.dpvec_index = -1; | |
3218 | it->current.overlay_string_index = -1; | |
3219 | IT_STRING_CHARPOS (*it) = -1; | |
3220 | IT_STRING_BYTEPOS (*it) = -1; | |
3221 | it->string = Qnil; | |
3222 | it->method = next_element_from_buffer; | |
3223 | it->sp = 0; | |
3224 | ||
3225 | if (set_stop_p) | |
3226 | it->stop_charpos = CHARPOS (pos); | |
3227 | } | |
3228 | ||
3229 | ||
3230 | /* Set up IT for displaying a string, starting at CHARPOS in window W. | |
3231 | If S is non-null, it is a C string to iterate over. Otherwise, | |
3232 | STRING gives a Lisp string to iterate over. | |
3233 | ||
3234 | If PRECISION > 0, don't return more then PRECISION number of | |
3235 | characters from the string. | |
3236 | ||
3237 | If FIELD_WIDTH > 0, return padding spaces until FIELD_WIDTH | |
3238 | characters have been returned. FIELD_WIDTH < 0 means an infinite | |
3239 | field width. | |
3240 | ||
3241 | MULTIBYTE = 0 means disable processing of multibyte characters, | |
3242 | MULTIBYTE > 0 means enable it, | |
3243 | MULTIBYTE < 0 means use IT->multibyte_p. | |
3244 | ||
3245 | IT must be initialized via a prior call to init_iterator before | |
3246 | calling this function. */ | |
3247 | ||
3248 | static void | |
3249 | reseat_to_string (it, s, string, charpos, precision, field_width, multibyte) | |
3250 | struct it *it; | |
3251 | unsigned char *s; | |
3252 | Lisp_Object string; | |
3253 | int charpos; | |
3254 | int precision, field_width, multibyte; | |
3255 | { | |
3256 | /* No region in strings. */ | |
3257 | it->region_beg_charpos = it->region_end_charpos = -1; | |
3258 | ||
3259 | /* No text property checks performed by default, but see below. */ | |
3260 | it->stop_charpos = -1; | |
3261 | ||
3262 | /* Set iterator position and end position. */ | |
3263 | bzero (&it->current, sizeof it->current); | |
3264 | it->current.overlay_string_index = -1; | |
3265 | it->current.dpvec_index = -1; | |
5f5c8ee5 GM |
3266 | xassert (charpos >= 0); |
3267 | ||
3268 | /* Use the setting of MULTIBYTE if specified. */ | |
3269 | if (multibyte >= 0) | |
3270 | it->multibyte_p = multibyte > 0; | |
3271 | ||
3272 | if (s == NULL) | |
3273 | { | |
3274 | xassert (STRINGP (string)); | |
3275 | it->string = string; | |
3276 | it->s = NULL; | |
3277 | it->end_charpos = it->string_nchars = XSTRING (string)->size; | |
3278 | it->method = next_element_from_string; | |
3279 | it->current.string_pos = string_pos (charpos, string); | |
3280 | } | |
3281 | else | |
3282 | { | |
3283 | it->s = s; | |
3284 | it->string = Qnil; | |
3285 | ||
3286 | /* Note that we use IT->current.pos, not it->current.string_pos, | |
3287 | for displaying C strings. */ | |
3288 | IT_STRING_CHARPOS (*it) = IT_STRING_BYTEPOS (*it) = -1; | |
3289 | if (it->multibyte_p) | |
3290 | { | |
3291 | it->current.pos = c_string_pos (charpos, s, 1); | |
3292 | it->end_charpos = it->string_nchars = number_of_chars (s, 1); | |
3293 | } | |
3294 | else | |
3295 | { | |
3296 | IT_CHARPOS (*it) = IT_BYTEPOS (*it) = charpos; | |
3297 | it->end_charpos = it->string_nchars = strlen (s); | |
3298 | } | |
3299 | ||
3300 | it->method = next_element_from_c_string; | |
3301 | } | |
3302 | ||
3303 | /* PRECISION > 0 means don't return more than PRECISION characters | |
3304 | from the string. */ | |
3305 | if (precision > 0 && it->end_charpos - charpos > precision) | |
3306 | it->end_charpos = it->string_nchars = charpos + precision; | |
3307 | ||
3308 | /* FIELD_WIDTH > 0 means pad with spaces until FIELD_WIDTH | |
3309 | characters have been returned. FIELD_WIDTH == 0 means don't pad, | |
3310 | FIELD_WIDTH < 0 means infinite field width. This is useful for | |
3311 | padding with `-' at the end of a mode line. */ | |
3312 | if (field_width < 0) | |
3313 | field_width = INFINITY; | |
3314 | if (field_width > it->end_charpos - charpos) | |
3315 | it->end_charpos = charpos + field_width; | |
3316 | ||
3317 | /* Use the standard display table for displaying strings. */ | |
3318 | if (DISP_TABLE_P (Vstandard_display_table)) | |
3319 | it->dp = XCHAR_TABLE (Vstandard_display_table); | |
3320 | ||
3321 | it->stop_charpos = charpos; | |
3322 | CHECK_IT (it); | |
3323 | } | |
3324 | ||
3325 | ||
3326 | \f | |
3327 | /*********************************************************************** | |
3328 | Iteration | |
3329 | ***********************************************************************/ | |
3330 | ||
3331 | /* Load IT's display element fields with information about the next | |
3332 | display element from the current position of IT. Value is zero if | |
3333 | end of buffer (or C string) is reached. */ | |
3334 | ||
3335 | int | |
3336 | get_next_display_element (it) | |
3337 | struct it *it; | |
3338 | { | |
3339 | /* Non-zero means that we found an display element. Zero means that | |
3340 | we hit the end of what we iterate over. Performance note: the | |
3341 | function pointer `method' used here turns out to be faster than | |
3342 | using a sequence of if-statements. */ | |
3343 | int success_p = (*it->method) (it); | |
5f5c8ee5 GM |
3344 | |
3345 | if (it->what == IT_CHARACTER) | |
3346 | { | |
3347 | /* Map via display table or translate control characters. | |
3348 | IT->c, IT->len etc. have been set to the next character by | |
3349 | the function call above. If we have a display table, and it | |
3350 | contains an entry for IT->c, translate it. Don't do this if | |
3351 | IT->c itself comes from a display table, otherwise we could | |
3352 | end up in an infinite recursion. (An alternative could be to | |
3353 | count the recursion depth of this function and signal an | |
3354 | error when a certain maximum depth is reached.) Is it worth | |
3355 | it? */ | |
3356 | if (success_p && it->dpvec == NULL) | |
3357 | { | |
3358 | Lisp_Object dv; | |
3359 | ||
3360 | if (it->dp | |
3361 | && (dv = DISP_CHAR_VECTOR (it->dp, it->c), | |
3362 | VECTORP (dv))) | |
3363 | { | |
3364 | struct Lisp_Vector *v = XVECTOR (dv); | |
3365 | ||
3366 | /* Return the first character from the display table | |
3367 | entry, if not empty. If empty, don't display the | |
3368 | current character. */ | |
3369 | if (v->size) | |
3370 | { | |
3371 | it->dpvec_char_len = it->len; | |
3372 | it->dpvec = v->contents; | |
3373 | it->dpend = v->contents + v->size; | |
3374 | it->current.dpvec_index = 0; | |
3375 | it->method = next_element_from_display_vector; | |
3376 | } | |
3377 | ||
3378 | success_p = get_next_display_element (it); | |
3379 | } | |
3380 | ||
3381 | /* Translate control characters into `\003' or `^C' form. | |
3382 | Control characters coming from a display table entry are | |
3383 | currently not translated because we use IT->dpvec to hold | |
3384 | the translation. This could easily be changed but I | |
197516c2 KH |
3385 | don't believe that it is worth doing. |
3386 | ||
3387 | Non-printable multibyte characters are also translated | |
3388 | octal form. */ | |
5f5c8ee5 GM |
3389 | else if ((it->c < ' ' |
3390 | && (it->area != TEXT_AREA | |
c6e89d6c | 3391 | || (it->c != '\n' && it->c != '\t'))) |
54c85a23 | 3392 | || (it->c >= 127 |
197516c2 KH |
3393 | && it->len == 1) |
3394 | || !CHAR_PRINTABLE_P (it->c)) | |
5f5c8ee5 GM |
3395 | { |
3396 | /* IT->c is a control character which must be displayed | |
3397 | either as '\003' or as `^C' where the '\\' and '^' | |
3398 | can be defined in the display table. Fill | |
3399 | IT->ctl_chars with glyphs for what we have to | |
3400 | display. Then, set IT->dpvec to these glyphs. */ | |
3401 | GLYPH g; | |
3402 | ||
54c85a23 | 3403 | if (it->c < 128 && it->ctl_arrow_p) |
5f5c8ee5 GM |
3404 | { |
3405 | /* Set IT->ctl_chars[0] to the glyph for `^'. */ | |
3406 | if (it->dp | |
3407 | && INTEGERP (DISP_CTRL_GLYPH (it->dp)) | |
3408 | && GLYPH_CHAR_VALID_P (XINT (DISP_CTRL_GLYPH (it->dp)))) | |
3409 | g = XINT (DISP_CTRL_GLYPH (it->dp)); | |
3410 | else | |
3411 | g = FAST_MAKE_GLYPH ('^', 0); | |
3412 | XSETINT (it->ctl_chars[0], g); | |
3413 | ||
3414 | g = FAST_MAKE_GLYPH (it->c ^ 0100, 0); | |
3415 | XSETINT (it->ctl_chars[1], g); | |
3416 | ||
3417 | /* Set up IT->dpvec and return first character from it. */ | |
3418 | it->dpvec_char_len = it->len; | |
3419 | it->dpvec = it->ctl_chars; | |
3420 | it->dpend = it->dpvec + 2; | |
3421 | it->current.dpvec_index = 0; | |
3422 | it->method = next_element_from_display_vector; | |
3423 | get_next_display_element (it); | |
3424 | } | |
3425 | else | |
3426 | { | |
260a86a0 | 3427 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
c5924f47 | 3428 | int len; |
197516c2 KH |
3429 | int i; |
3430 | GLYPH escape_glyph; | |
3431 | ||
5f5c8ee5 GM |
3432 | /* Set IT->ctl_chars[0] to the glyph for `\\'. */ |
3433 | if (it->dp | |
3434 | && INTEGERP (DISP_ESCAPE_GLYPH (it->dp)) | |
3435 | && GLYPH_CHAR_VALID_P (XFASTINT (DISP_ESCAPE_GLYPH (it->dp)))) | |
197516c2 | 3436 | escape_glyph = XFASTINT (DISP_ESCAPE_GLYPH (it->dp)); |
5f5c8ee5 | 3437 | else |
197516c2 KH |
3438 | escape_glyph = FAST_MAKE_GLYPH ('\\', 0); |
3439 | ||
c5924f47 KH |
3440 | if (SINGLE_BYTE_CHAR_P (it->c)) |
3441 | str[0] = it->c, len = 1; | |
3442 | else | |
3443 | len = CHAR_STRING (it->c, str); | |
3444 | ||
197516c2 KH |
3445 | for (i = 0; i < len; i++) |
3446 | { | |
3447 | XSETINT (it->ctl_chars[i * 4], escape_glyph); | |
3448 | /* Insert three more glyphs into IT->ctl_chars for | |
3449 | the octal display of the character. */ | |
3450 | g = FAST_MAKE_GLYPH (((str[i] >> 6) & 7) + '0', 0); | |
3451 | XSETINT (it->ctl_chars[i * 4 + 1], g); | |
3452 | g = FAST_MAKE_GLYPH (((str[i] >> 3) & 7) + '0', 0); | |
3453 | XSETINT (it->ctl_chars[i * 4 + 2], g); | |
3454 | g = FAST_MAKE_GLYPH ((str[i] & 7) + '0', 0); | |
3455 | XSETINT (it->ctl_chars[i * 4 + 3], g); | |
3456 | } | |
5f5c8ee5 GM |
3457 | |
3458 | /* Set up IT->dpvec and return the first character | |
3459 | from it. */ | |
3460 | it->dpvec_char_len = it->len; | |
3461 | it->dpvec = it->ctl_chars; | |
197516c2 | 3462 | it->dpend = it->dpvec + len * 4; |
5f5c8ee5 GM |
3463 | it->current.dpvec_index = 0; |
3464 | it->method = next_element_from_display_vector; | |
3465 | get_next_display_element (it); | |
3466 | } | |
3467 | } | |
3468 | } | |
3469 | ||
980806b6 KH |
3470 | /* Adjust face id for a multibyte character. There are no |
3471 | multibyte character in unibyte text. */ | |
5f5c8ee5 GM |
3472 | if (it->multibyte_p |
3473 | && success_p | |
980806b6 | 3474 | && FRAME_WINDOW_P (it->f)) |
5f5c8ee5 | 3475 | { |
980806b6 KH |
3476 | struct face *face = FACE_FROM_ID (it->f, it->face_id); |
3477 | it->face_id = FACE_FOR_CHAR (it->f, face, it->c); | |
5f5c8ee5 GM |
3478 | } |
3479 | } | |
3480 | ||
3481 | /* Is this character the last one of a run of characters with | |
3482 | box? If yes, set IT->end_of_box_run_p to 1. */ | |
3483 | if (it->face_box_p | |
3484 | && it->s == NULL) | |
3485 | { | |
3486 | int face_id; | |
3487 | struct face *face; | |
3488 | ||
3489 | it->end_of_box_run_p | |
3490 | = ((face_id = face_after_it_pos (it), | |
3491 | face_id != it->face_id) | |
3492 | && (face = FACE_FROM_ID (it->f, face_id), | |
3493 | face->box == FACE_NO_BOX)); | |
3494 | } | |
3495 | ||
3496 | /* Value is 0 if end of buffer or string reached. */ | |
3497 | return success_p; | |
3498 | } | |
3499 | ||
3500 | ||
3501 | /* Move IT to the next display element. | |
3502 | ||
3503 | Functions get_next_display_element and set_iterator_to_next are | |
3504 | separate because I find this arrangement easier to handle than a | |
3505 | get_next_display_element function that also increments IT's | |
3506 | position. The way it is we can first look at an iterator's current | |
3507 | display element, decide whether it fits on a line, and if it does, | |
3508 | increment the iterator position. The other way around we probably | |
3509 | would either need a flag indicating whether the iterator has to be | |
3510 | incremented the next time, or we would have to implement a | |
3511 | decrement position function which would not be easy to write. */ | |
3512 | ||
3513 | void | |
3514 | set_iterator_to_next (it) | |
3515 | struct it *it; | |
3516 | { | |
3517 | if (it->method == next_element_from_buffer) | |
3518 | { | |
3519 | /* The current display element of IT is a character from | |
3520 | current_buffer. Advance in the buffer, and maybe skip over | |
3521 | invisible lines that are so because of selective display. */ | |
3522 | if (ITERATOR_AT_END_OF_LINE_P (it)) | |
312246d1 | 3523 | reseat_at_next_visible_line_start (it, 0); |
5f5c8ee5 GM |
3524 | else |
3525 | { | |
3526 | xassert (it->len != 0); | |
3527 | IT_BYTEPOS (*it) += it->len; | |
3528 | IT_CHARPOS (*it) += 1; | |
3529 | xassert (IT_BYTEPOS (*it) == CHAR_TO_BYTE (IT_CHARPOS (*it))); | |
3530 | } | |
3531 | } | |
260a86a0 KH |
3532 | else if (it->method == next_element_from_composition) |
3533 | { | |
3534 | xassert (it->cmp_id >= 0 && it ->cmp_id < n_compositions); | |
3535 | if (STRINGP (it->string)) | |
3536 | { | |
3537 | IT_STRING_BYTEPOS (*it) += it->len; | |
3538 | IT_STRING_CHARPOS (*it) += it->cmp_len; | |
3539 | it->method = next_element_from_string; | |
3540 | goto consider_string_end; | |
3541 | } | |
3542 | else | |
3543 | { | |
3544 | IT_BYTEPOS (*it) += it->len; | |
3545 | IT_CHARPOS (*it) += it->cmp_len; | |
3546 | it->method = next_element_from_buffer; | |
3547 | } | |
3548 | } | |
5f5c8ee5 GM |
3549 | else if (it->method == next_element_from_c_string) |
3550 | { | |
3551 | /* Current display element of IT is from a C string. */ | |
3552 | IT_BYTEPOS (*it) += it->len; | |
3553 | IT_CHARPOS (*it) += 1; | |
3554 | } | |
3555 | else if (it->method == next_element_from_display_vector) | |
3556 | { | |
3557 | /* Current display element of IT is from a display table entry. | |
3558 | Advance in the display table definition. Reset it to null if | |
3559 | end reached, and continue with characters from buffers/ | |
3560 | strings. */ | |
3561 | ++it->current.dpvec_index; | |
286bcbc9 | 3562 | |
980806b6 KH |
3563 | /* Restore face of the iterator to what they were before the |
3564 | display vector entry (these entries may contain faces). */ | |
5f5c8ee5 | 3565 | it->face_id = it->saved_face_id; |
286bcbc9 | 3566 | |
5f5c8ee5 GM |
3567 | if (it->dpvec + it->current.dpvec_index == it->dpend) |
3568 | { | |
3569 | if (it->s) | |
3570 | it->method = next_element_from_c_string; | |
3571 | else if (STRINGP (it->string)) | |
3572 | it->method = next_element_from_string; | |
3573 | else | |
3574 | it->method = next_element_from_buffer; | |
3575 | ||
3576 | it->dpvec = NULL; | |
3577 | it->current.dpvec_index = -1; | |
3578 | ||
312246d1 GM |
3579 | /* Skip over characters which were displayed via IT->dpvec. */ |
3580 | if (it->dpvec_char_len < 0) | |
3581 | reseat_at_next_visible_line_start (it, 1); | |
3582 | else if (it->dpvec_char_len > 0) | |
5f5c8ee5 GM |
3583 | { |
3584 | it->len = it->dpvec_char_len; | |
3585 | set_iterator_to_next (it); | |
3586 | } | |
3587 | } | |
3588 | } | |
3589 | else if (it->method == next_element_from_string) | |
3590 | { | |
3591 | /* Current display element is a character from a Lisp string. */ | |
3592 | xassert (it->s == NULL && STRINGP (it->string)); | |
3593 | IT_STRING_BYTEPOS (*it) += it->len; | |
3594 | IT_STRING_CHARPOS (*it) += 1; | |
3595 | ||
3596 | consider_string_end: | |
3597 | ||
3598 | if (it->current.overlay_string_index >= 0) | |
3599 | { | |
3600 | /* IT->string is an overlay string. Advance to the | |
3601 | next, if there is one. */ | |
3602 | if (IT_STRING_CHARPOS (*it) >= XSTRING (it->string)->size) | |
3603 | next_overlay_string (it); | |
3604 | } | |
3605 | else | |
3606 | { | |
3607 | /* IT->string is not an overlay string. If we reached | |
3608 | its end, and there is something on IT->stack, proceed | |
3609 | with what is on the stack. This can be either another | |
3610 | string, this time an overlay string, or a buffer. */ | |
3611 | if (IT_STRING_CHARPOS (*it) == XSTRING (it->string)->size | |
3612 | && it->sp > 0) | |
3613 | { | |
3614 | pop_it (it); | |
3615 | if (!STRINGP (it->string)) | |
3616 | it->method = next_element_from_buffer; | |
3617 | } | |
3618 | } | |
3619 | } | |
3620 | else if (it->method == next_element_from_image | |
3621 | || it->method == next_element_from_stretch) | |
3622 | { | |
3623 | /* The position etc with which we have to proceed are on | |
3624 | the stack. The position may be at the end of a string, | |
3625 | if the `display' property takes up the whole string. */ | |
3626 | pop_it (it); | |
3627 | it->image_id = 0; | |
3628 | if (STRINGP (it->string)) | |
3629 | { | |
3630 | it->method = next_element_from_string; | |
3631 | goto consider_string_end; | |
3632 | } | |
3633 | else | |
3634 | it->method = next_element_from_buffer; | |
3635 | } | |
3636 | else | |
3637 | /* There are no other methods defined, so this should be a bug. */ | |
3638 | abort (); | |
3639 | ||
3640 | /* Reset flags indicating start and end of a sequence of | |
3641 | characters with box. */ | |
3642 | it->start_of_box_run_p = it->end_of_box_run_p = 0; | |
3643 | ||
3644 | xassert (it->method != next_element_from_string | |
3645 | || (STRINGP (it->string) | |
3646 | && IT_STRING_CHARPOS (*it) >= 0)); | |
3647 | } | |
3648 | ||
3649 | ||
3650 | /* Load IT's display element fields with information about the next | |
3651 | display element which comes from a display table entry or from the | |
3652 | result of translating a control character to one of the forms `^C' | |
3653 | or `\003'. IT->dpvec holds the glyphs to return as characters. */ | |
3654 | ||
3655 | static int | |
3656 | next_element_from_display_vector (it) | |
3657 | struct it *it; | |
3658 | { | |
3659 | /* Precondition. */ | |
3660 | xassert (it->dpvec && it->current.dpvec_index >= 0); | |
3661 | ||
3662 | /* Remember the current face id in case glyphs specify faces. | |
3663 | IT's face is restored in set_iterator_to_next. */ | |
3664 | it->saved_face_id = it->face_id; | |
3665 | ||
3666 | if (INTEGERP (*it->dpvec) | |
3667 | && GLYPH_CHAR_VALID_P (XFASTINT (*it->dpvec))) | |
3668 | { | |
3669 | int lface_id; | |
3670 | GLYPH g; | |
3671 | ||
3672 | g = XFASTINT (it->dpvec[it->current.dpvec_index]); | |
3673 | it->c = FAST_GLYPH_CHAR (g); | |
c5924f47 | 3674 | it->len = CHAR_BYTES (it->c); |
5f5c8ee5 GM |
3675 | |
3676 | /* The entry may contain a face id to use. Such a face id is | |
3677 | the id of a Lisp face, not a realized face. A face id of | |
3678 | zero means no face. */ | |
3679 | lface_id = FAST_GLYPH_FACE (g); | |
3680 | if (lface_id) | |
3681 | { | |
3682 | int face_id = ascii_face_of_lisp_face (it->f, lface_id); | |
3683 | if (face_id >= 0) | |
3684 | { | |
3685 | it->face_id = face_id; | |
5f5c8ee5 GM |
3686 | } |
3687 | } | |
3688 | } | |
3689 | else | |
3690 | /* Display table entry is invalid. Return a space. */ | |
3691 | it->c = ' ', it->len = 1; | |
3692 | ||
3693 | /* Don't change position and object of the iterator here. They are | |
3694 | still the values of the character that had this display table | |
3695 | entry or was translated, and that's what we want. */ | |
3696 | it->what = IT_CHARACTER; | |
3697 | return 1; | |
3698 | } | |
3699 | ||
3700 | ||
3701 | /* Load IT with the next display element from Lisp string IT->string. | |
3702 | IT->current.string_pos is the current position within the string. | |
3703 | If IT->current.overlay_string_index >= 0, the Lisp string is an | |
3704 | overlay string. */ | |
3705 | ||
3706 | static int | |
3707 | next_element_from_string (it) | |
3708 | struct it *it; | |
3709 | { | |
3710 | struct text_pos position; | |
3711 | ||
3712 | xassert (STRINGP (it->string)); | |
3713 | xassert (IT_STRING_CHARPOS (*it) >= 0); | |
3714 | position = it->current.string_pos; | |
3715 | ||
3716 | /* Time to check for invisible text? */ | |
3717 | if (IT_STRING_CHARPOS (*it) < it->end_charpos | |
3718 | && IT_STRING_CHARPOS (*it) == it->stop_charpos) | |
3719 | { | |
3720 | handle_stop (it); | |
3721 | ||
3722 | /* Since a handler may have changed IT->method, we must | |
3723 | recurse here. */ | |
3724 | return get_next_display_element (it); | |
3725 | } | |
3726 | ||
3727 | if (it->current.overlay_string_index >= 0) | |
3728 | { | |
3729 | /* Get the next character from an overlay string. In overlay | |
3730 | strings, There is no field width or padding with spaces to | |
3731 | do. */ | |
3732 | if (IT_STRING_CHARPOS (*it) >= XSTRING (it->string)->size) | |
3733 | { | |
3734 | it->what = IT_EOB; | |
3735 | return 0; | |
3736 | } | |
3737 | else if (STRING_MULTIBYTE (it->string)) | |
3738 | { | |
3739 | int remaining = (STRING_BYTES (XSTRING (it->string)) | |
3740 | - IT_STRING_BYTEPOS (*it)); | |
3741 | unsigned char *s = (XSTRING (it->string)->data | |
3742 | + IT_STRING_BYTEPOS (*it)); | |
4fdb80f2 | 3743 | it->c = string_char_and_length (s, remaining, &it->len); |
5f5c8ee5 GM |
3744 | } |
3745 | else | |
3746 | { | |
3747 | it->c = XSTRING (it->string)->data[IT_STRING_BYTEPOS (*it)]; | |
3748 | it->len = 1; | |
3749 | } | |
3750 | } | |
3751 | else | |
3752 | { | |
3753 | /* Get the next character from a Lisp string that is not an | |
3754 | overlay string. Such strings come from the mode line, for | |
3755 | example. We may have to pad with spaces, or truncate the | |
3756 | string. See also next_element_from_c_string. */ | |
3757 | if (IT_STRING_CHARPOS (*it) >= it->end_charpos) | |
3758 | { | |
3759 | it->what = IT_EOB; | |
3760 | return 0; | |
3761 | } | |
3762 | else if (IT_STRING_CHARPOS (*it) >= it->string_nchars) | |
3763 | { | |
3764 | /* Pad with spaces. */ | |
3765 | it->c = ' ', it->len = 1; | |
3766 | CHARPOS (position) = BYTEPOS (position) = -1; | |
3767 | } | |
3768 | else if (STRING_MULTIBYTE (it->string)) | |
3769 | { | |
3770 | int maxlen = (STRING_BYTES (XSTRING (it->string)) | |
3771 | - IT_STRING_BYTEPOS (*it)); | |
3772 | unsigned char *s = (XSTRING (it->string)->data | |
3773 | + IT_STRING_BYTEPOS (*it)); | |
4fdb80f2 | 3774 | it->c = string_char_and_length (s, maxlen, &it->len); |
5f5c8ee5 GM |
3775 | } |
3776 | else | |
3777 | { | |
3778 | it->c = XSTRING (it->string)->data[IT_STRING_BYTEPOS (*it)]; | |
3779 | it->len = 1; | |
3780 | } | |
3781 | } | |
3782 | ||
3783 | /* Record what we have and where it came from. Note that we store a | |
3784 | buffer position in IT->position although it could arguably be a | |
3785 | string position. */ | |
3786 | it->what = IT_CHARACTER; | |
3787 | it->object = it->string; | |
3788 | it->position = position; | |
3789 | return 1; | |
3790 | } | |
3791 | ||
3792 | ||
3793 | /* Load IT with next display element from C string IT->s. | |
3794 | IT->string_nchars is the maximum number of characters to return | |
3795 | from the string. IT->end_charpos may be greater than | |
3796 | IT->string_nchars when this function is called, in which case we | |
3797 | may have to return padding spaces. Value is zero if end of string | |
3798 | reached, including padding spaces. */ | |
3799 | ||
3800 | static int | |
3801 | next_element_from_c_string (it) | |
3802 | struct it *it; | |
3803 | { | |
3804 | int success_p = 1; | |
3805 | ||
3806 | xassert (it->s); | |
3807 | it->what = IT_CHARACTER; | |
3808 | BYTEPOS (it->position) = CHARPOS (it->position) = 0; | |
3809 | it->object = Qnil; | |
3810 | ||
3811 | /* IT's position can be greater IT->string_nchars in case a field | |
3812 | width or precision has been specified when the iterator was | |
3813 | initialized. */ | |
3814 | if (IT_CHARPOS (*it) >= it->end_charpos) | |
3815 | { | |
3816 | /* End of the game. */ | |
3817 | it->what = IT_EOB; | |
3818 | success_p = 0; | |
3819 | } | |
3820 | else if (IT_CHARPOS (*it) >= it->string_nchars) | |
3821 | { | |
3822 | /* Pad with spaces. */ | |
3823 | it->c = ' ', it->len = 1; | |
3824 | BYTEPOS (it->position) = CHARPOS (it->position) = -1; | |
3825 | } | |
3826 | else if (it->multibyte_p) | |
3827 | { | |
3828 | /* Implementation note: The calls to strlen apparently aren't a | |
3829 | performance problem because there is no noticeable performance | |
3830 | difference between Emacs running in unibyte or multibyte mode. */ | |
3831 | int maxlen = strlen (it->s) - IT_BYTEPOS (*it); | |
4fdb80f2 GM |
3832 | it->c = string_char_and_length (it->s + IT_BYTEPOS (*it), |
3833 | maxlen, &it->len); | |
5f5c8ee5 GM |
3834 | } |
3835 | else | |
3836 | it->c = it->s[IT_BYTEPOS (*it)], it->len = 1; | |
3837 | ||
3838 | return success_p; | |
3839 | } | |
3840 | ||
3841 | ||
3842 | /* Set up IT to return characters from an ellipsis, if appropriate. | |
3843 | The definition of the ellipsis glyphs may come from a display table | |
3844 | entry. This function Fills IT with the first glyph from the | |
3845 | ellipsis if an ellipsis is to be displayed. */ | |
3846 | ||
13f19968 | 3847 | static int |
5f5c8ee5 GM |
3848 | next_element_from_ellipsis (it) |
3849 | struct it *it; | |
3850 | { | |
13f19968 | 3851 | if (it->selective_display_ellipsis_p) |
5f5c8ee5 | 3852 | { |
13f19968 GM |
3853 | if (it->dp && VECTORP (DISP_INVIS_VECTOR (it->dp))) |
3854 | { | |
3855 | /* Use the display table definition for `...'. Invalid glyphs | |
3856 | will be handled by the method returning elements from dpvec. */ | |
3857 | struct Lisp_Vector *v = XVECTOR (DISP_INVIS_VECTOR (it->dp)); | |
3858 | it->dpvec_char_len = it->len; | |
3859 | it->dpvec = v->contents; | |
3860 | it->dpend = v->contents + v->size; | |
3861 | it->current.dpvec_index = 0; | |
3862 | it->method = next_element_from_display_vector; | |
3863 | } | |
3864 | else | |
3865 | { | |
3866 | /* Use default `...' which is stored in default_invis_vector. */ | |
3867 | it->dpvec_char_len = it->len; | |
3868 | it->dpvec = default_invis_vector; | |
3869 | it->dpend = default_invis_vector + 3; | |
3870 | it->current.dpvec_index = 0; | |
3871 | it->method = next_element_from_display_vector; | |
3872 | } | |
5f5c8ee5 | 3873 | } |
13f19968 GM |
3874 | else |
3875 | reseat_at_next_visible_line_start (it, 1); | |
3876 | ||
3877 | return get_next_display_element (it); | |
5f5c8ee5 GM |
3878 | } |
3879 | ||
3880 | ||
3881 | /* Deliver an image display element. The iterator IT is already | |
3882 | filled with image information (done in handle_display_prop). Value | |
3883 | is always 1. */ | |
3884 | ||
3885 | ||
3886 | static int | |
3887 | next_element_from_image (it) | |
3888 | struct it *it; | |
3889 | { | |
3890 | it->what = IT_IMAGE; | |
3891 | return 1; | |
3892 | } | |
3893 | ||
3894 | ||
3895 | /* Fill iterator IT with next display element from a stretch glyph | |
3896 | property. IT->object is the value of the text property. Value is | |
3897 | always 1. */ | |
3898 | ||
3899 | static int | |
3900 | next_element_from_stretch (it) | |
3901 | struct it *it; | |
3902 | { | |
3903 | it->what = IT_STRETCH; | |
3904 | return 1; | |
3905 | } | |
3906 | ||
3907 | ||
3908 | /* Load IT with the next display element from current_buffer. Value | |
3909 | is zero if end of buffer reached. IT->stop_charpos is the next | |
3910 | position at which to stop and check for text properties or buffer | |
3911 | end. */ | |
3912 | ||
3913 | static int | |
3914 | next_element_from_buffer (it) | |
3915 | struct it *it; | |
3916 | { | |
3917 | int success_p = 1; | |
3918 | ||
3919 | /* Check this assumption, otherwise, we would never enter the | |
3920 | if-statement, below. */ | |
3921 | xassert (IT_CHARPOS (*it) >= BEGV | |
3922 | && IT_CHARPOS (*it) <= it->stop_charpos); | |
3923 | ||
3924 | if (IT_CHARPOS (*it) >= it->stop_charpos) | |
3925 | { | |
3926 | if (IT_CHARPOS (*it) >= it->end_charpos) | |
3927 | { | |
3928 | int overlay_strings_follow_p; | |
3929 | ||
3930 | /* End of the game, except when overlay strings follow that | |
3931 | haven't been returned yet. */ | |
3932 | if (it->overlay_strings_at_end_processed_p) | |
3933 | overlay_strings_follow_p = 0; | |
3934 | else | |
3935 | { | |
3936 | it->overlay_strings_at_end_processed_p = 1; | |
c880678e | 3937 | overlay_strings_follow_p = get_overlay_strings (it); |
5f5c8ee5 GM |
3938 | } |
3939 | ||
3940 | if (overlay_strings_follow_p) | |
3941 | success_p = get_next_display_element (it); | |
3942 | else | |
3943 | { | |
3944 | it->what = IT_EOB; | |
3945 | it->position = it->current.pos; | |
3946 | success_p = 0; | |
3947 | } | |
3948 | } | |
3949 | else | |
3950 | { | |
3951 | handle_stop (it); | |
3952 | return get_next_display_element (it); | |
3953 | } | |
3954 | } | |
3955 | else | |
3956 | { | |
3957 | /* No face changes, overlays etc. in sight, so just return a | |
3958 | character from current_buffer. */ | |
3959 | unsigned char *p; | |
3960 | ||
3961 | /* Maybe run the redisplay end trigger hook. Performance note: | |
3962 | This doesn't seem to cost measurable time. */ | |
3963 | if (it->redisplay_end_trigger_charpos | |
3964 | && it->glyph_row | |
3965 | && IT_CHARPOS (*it) >= it->redisplay_end_trigger_charpos) | |
3966 | run_redisplay_end_trigger_hook (it); | |
3967 | ||
3968 | /* Get the next character, maybe multibyte. */ | |
3969 | p = BYTE_POS_ADDR (IT_BYTEPOS (*it)); | |
260a86a0 | 3970 | if (it->multibyte_p && !ASCII_BYTE_P (*p)) |
5f5c8ee5 GM |
3971 | { |
3972 | int maxlen = ((IT_BYTEPOS (*it) >= GPT_BYTE ? ZV_BYTE : GPT_BYTE) | |
3973 | - IT_BYTEPOS (*it)); | |
4fdb80f2 | 3974 | it->c = string_char_and_length (p, maxlen, &it->len); |
5f5c8ee5 GM |
3975 | } |
3976 | else | |
3977 | it->c = *p, it->len = 1; | |
3978 | ||
3979 | /* Record what we have and where it came from. */ | |
3980 | it->what = IT_CHARACTER;; | |
3981 | it->object = it->w->buffer; | |
3982 | it->position = it->current.pos; | |
3983 | ||
3984 | /* Normally we return the character found above, except when we | |
3985 | really want to return an ellipsis for selective display. */ | |
3986 | if (it->selective) | |
3987 | { | |
3988 | if (it->c == '\n') | |
3989 | { | |
3990 | /* A value of selective > 0 means hide lines indented more | |
3991 | than that number of columns. */ | |
3992 | if (it->selective > 0 | |
3993 | && IT_CHARPOS (*it) + 1 < ZV | |
3994 | && indented_beyond_p (IT_CHARPOS (*it) + 1, | |
3995 | IT_BYTEPOS (*it) + 1, | |
3996 | it->selective)) | |
312246d1 | 3997 | { |
13f19968 | 3998 | success_p = next_element_from_ellipsis (it); |
312246d1 GM |
3999 | it->dpvec_char_len = -1; |
4000 | } | |
5f5c8ee5 GM |
4001 | } |
4002 | else if (it->c == '\r' && it->selective == -1) | |
4003 | { | |
4004 | /* A value of selective == -1 means that everything from the | |
4005 | CR to the end of the line is invisible, with maybe an | |
4006 | ellipsis displayed for it. */ | |
13f19968 | 4007 | success_p = next_element_from_ellipsis (it); |
312246d1 | 4008 | it->dpvec_char_len = -1; |
5f5c8ee5 GM |
4009 | } |
4010 | } | |
4011 | } | |
4012 | ||
4013 | /* Value is zero if end of buffer reached. */ | |
c880678e | 4014 | xassert (!success_p || it->what != IT_CHARACTER || it->len > 0); |
5f5c8ee5 GM |
4015 | return success_p; |
4016 | } | |
4017 | ||
4018 | ||
4019 | /* Run the redisplay end trigger hook for IT. */ | |
4020 | ||
4021 | static void | |
4022 | run_redisplay_end_trigger_hook (it) | |
4023 | struct it *it; | |
4024 | { | |
4025 | Lisp_Object args[3]; | |
4026 | ||
4027 | /* IT->glyph_row should be non-null, i.e. we should be actually | |
4028 | displaying something, or otherwise we should not run the hook. */ | |
4029 | xassert (it->glyph_row); | |
4030 | ||
4031 | /* Set up hook arguments. */ | |
4032 | args[0] = Qredisplay_end_trigger_functions; | |
4033 | args[1] = it->window; | |
4034 | XSETINT (args[2], it->redisplay_end_trigger_charpos); | |
4035 | it->redisplay_end_trigger_charpos = 0; | |
4036 | ||
4037 | /* Since we are *trying* to run these functions, don't try to run | |
4038 | them again, even if they get an error. */ | |
4039 | it->w->redisplay_end_trigger = Qnil; | |
4040 | Frun_hook_with_args (3, args); | |
4041 | ||
4042 | /* Notice if it changed the face of the character we are on. */ | |
4043 | handle_face_prop (it); | |
4044 | } | |
4045 | ||
4046 | ||
260a86a0 KH |
4047 | /* Deliver a composition display element. The iterator IT is already |
4048 | filled with composition information (done in | |
4049 | handle_composition_prop). Value is always 1. */ | |
4050 | ||
4051 | static int | |
4052 | next_element_from_composition (it) | |
4053 | struct it *it; | |
4054 | { | |
4055 | it->what = IT_COMPOSITION; | |
4056 | it->position = (STRINGP (it->string) | |
4057 | ? it->current.string_pos | |
4058 | : it->current.pos); | |
4059 | return 1; | |
4060 | } | |
4061 | ||
4062 | ||
5f5c8ee5 GM |
4063 | \f |
4064 | /*********************************************************************** | |
4065 | Moving an iterator without producing glyphs | |
4066 | ***********************************************************************/ | |
4067 | ||
4068 | /* Move iterator IT to a specified buffer or X position within one | |
4069 | line on the display without producing glyphs. | |
4070 | ||
4071 | Begin to skip at IT's current position. Skip to TO_CHARPOS or TO_X | |
4072 | whichever is reached first. | |
4073 | ||
4074 | TO_CHARPOS <= 0 means no TO_CHARPOS is specified. | |
4075 | ||
4076 | TO_X < 0 means that no TO_X is specified. TO_X is normally a value | |
4077 | 0 <= TO_X <= IT->last_visible_x. This means in particular, that | |
4078 | TO_X includes the amount by which a window is horizontally | |
4079 | scrolled. | |
4080 | ||
4081 | Value is | |
4082 | ||
4083 | MOVE_POS_MATCH_OR_ZV | |
4084 | - when TO_POS or ZV was reached. | |
4085 | ||
4086 | MOVE_X_REACHED | |
4087 | -when TO_X was reached before TO_POS or ZV were reached. | |
4088 | ||
4089 | MOVE_LINE_CONTINUED | |
4090 | - when we reached the end of the display area and the line must | |
4091 | be continued. | |
4092 | ||
4093 | MOVE_LINE_TRUNCATED | |
4094 | - when we reached the end of the display area and the line is | |
4095 | truncated. | |
4096 | ||
4097 | MOVE_NEWLINE_OR_CR | |
4098 | - when we stopped at a line end, i.e. a newline or a CR and selective | |
4099 | display is on. */ | |
4100 | ||
701552dd | 4101 | static enum move_it_result |
5f5c8ee5 GM |
4102 | move_it_in_display_line_to (it, to_charpos, to_x, op) |
4103 | struct it *it; | |
4104 | int to_charpos, to_x, op; | |
4105 | { | |
4106 | enum move_it_result result = MOVE_UNDEFINED; | |
4107 | struct glyph_row *saved_glyph_row; | |
4108 | ||
4109 | /* Don't produce glyphs in produce_glyphs. */ | |
4110 | saved_glyph_row = it->glyph_row; | |
4111 | it->glyph_row = NULL; | |
4112 | ||
5f5c8ee5 GM |
4113 | while (1) |
4114 | { | |
4115 | int x, i; | |
4116 | ||
4117 | /* Stop when ZV or TO_CHARPOS reached. */ | |
4118 | if (!get_next_display_element (it) | |
4119 | || ((op & MOVE_TO_POS) != 0 | |
4120 | && BUFFERP (it->object) | |
4121 | && IT_CHARPOS (*it) >= to_charpos)) | |
4122 | { | |
4123 | result = MOVE_POS_MATCH_OR_ZV; | |
4124 | break; | |
4125 | } | |
4126 | ||
4127 | /* The call to produce_glyphs will get the metrics of the | |
4128 | display element IT is loaded with. We record in x the | |
4129 | x-position before this display element in case it does not | |
4130 | fit on the line. */ | |
4131 | x = it->current_x; | |
4132 | PRODUCE_GLYPHS (it); | |
4133 | ||
4134 | if (it->area != TEXT_AREA) | |
4135 | { | |
4136 | set_iterator_to_next (it); | |
4137 | continue; | |
4138 | } | |
4139 | ||
4140 | /* The number of glyphs we get back in IT->nglyphs will normally | |
4141 | be 1 except when IT->c is (i) a TAB, or (ii) a multi-glyph | |
4142 | character on a terminal frame, or (iii) a line end. For the | |
4143 | second case, IT->nglyphs - 1 padding glyphs will be present | |
4144 | (on X frames, there is only one glyph produced for a | |
4145 | composite character. | |
4146 | ||
4147 | The behavior implemented below means, for continuation lines, | |
4148 | that as many spaces of a TAB as fit on the current line are | |
4149 | displayed there. For terminal frames, as many glyphs of a | |
4150 | multi-glyph character are displayed in the current line, too. | |
4151 | This is what the old redisplay code did, and we keep it that | |
4152 | way. Under X, the whole shape of a complex character must | |
4153 | fit on the line or it will be completely displayed in the | |
4154 | next line. | |
4155 | ||
4156 | Note that both for tabs and padding glyphs, all glyphs have | |
4157 | the same width. */ | |
4158 | if (it->nglyphs) | |
4159 | { | |
4160 | /* More than one glyph or glyph doesn't fit on line. All | |
4161 | glyphs have the same width. */ | |
4162 | int single_glyph_width = it->pixel_width / it->nglyphs; | |
4163 | int new_x; | |
4164 | ||
4165 | for (i = 0; i < it->nglyphs; ++i, x = new_x) | |
4166 | { | |
4167 | new_x = x + single_glyph_width; | |
4168 | ||
4169 | /* We want to leave anything reaching TO_X to the caller. */ | |
4170 | if ((op & MOVE_TO_X) && new_x > to_x) | |
4171 | { | |
4172 | it->current_x = x; | |
4173 | result = MOVE_X_REACHED; | |
4174 | break; | |
4175 | } | |
4176 | else if (/* Lines are continued. */ | |
4177 | !it->truncate_lines_p | |
4178 | && (/* And glyph doesn't fit on the line. */ | |
4179 | new_x > it->last_visible_x | |
4180 | /* Or it fits exactly and we're on a window | |
4181 | system frame. */ | |
4182 | || (new_x == it->last_visible_x | |
4183 | && FRAME_WINDOW_P (it->f)))) | |
4184 | { | |
4185 | if (/* IT->hpos == 0 means the very first glyph | |
4186 | doesn't fit on the line, e.g. a wide image. */ | |
4187 | it->hpos == 0 | |
4188 | || (new_x == it->last_visible_x | |
4189 | && FRAME_WINDOW_P (it->f))) | |
4190 | { | |
4191 | ++it->hpos; | |
4192 | it->current_x = new_x; | |
4193 | if (i == it->nglyphs - 1) | |
4194 | set_iterator_to_next (it); | |
4195 | } | |
4196 | else | |
4197 | it->current_x = x; | |
4198 | ||
4199 | result = MOVE_LINE_CONTINUED; | |
4200 | break; | |
4201 | } | |
4202 | else if (new_x > it->first_visible_x) | |
4203 | { | |
4204 | /* Glyph is visible. Increment number of glyphs that | |
4205 | would be displayed. */ | |
4206 | ++it->hpos; | |
4207 | } | |
4208 | else | |
4209 | { | |
4210 | /* Glyph is completely off the left margin of the display | |
4211 | area. Nothing to do. */ | |
4212 | } | |
4213 | } | |
4214 | ||
4215 | if (result != MOVE_UNDEFINED) | |
4216 | break; | |
4217 | } | |
4218 | else if ((op & MOVE_TO_X) && it->current_x >= to_x) | |
4219 | { | |
4220 | /* Stop when TO_X specified and reached. This check is | |
4221 | necessary here because of lines consisting of a line end, | |
4222 | only. The line end will not produce any glyphs and we | |
4223 | would never get MOVE_X_REACHED. */ | |
4224 | xassert (it->nglyphs == 0); | |
4225 | result = MOVE_X_REACHED; | |
4226 | break; | |
4227 | } | |
4228 | ||
4229 | /* Is this a line end? If yes, we're done. */ | |
4230 | if (ITERATOR_AT_END_OF_LINE_P (it)) | |
4231 | { | |
4232 | result = MOVE_NEWLINE_OR_CR; | |
4233 | break; | |
4234 | } | |
4235 | ||
4236 | /* The current display element has been consumed. Advance | |
4237 | to the next. */ | |
4238 | set_iterator_to_next (it); | |
4239 | ||
4240 | /* Stop if lines are truncated and IT's current x-position is | |
4241 | past the right edge of the window now. */ | |
4242 | if (it->truncate_lines_p | |
4243 | && it->current_x >= it->last_visible_x) | |
4244 | { | |
4245 | result = MOVE_LINE_TRUNCATED; | |
4246 | break; | |
4247 | } | |
4248 | } | |
4249 | ||
4250 | /* Restore the iterator settings altered at the beginning of this | |
4251 | function. */ | |
4252 | it->glyph_row = saved_glyph_row; | |
4253 | return result; | |
4254 | } | |
4255 | ||
4256 | ||
4257 | /* Move IT forward to a specified buffer position TO_CHARPOS, TO_X, | |
4258 | TO_Y, TO_VPOS. OP is a bit-mask that specifies where to stop. See | |
4259 | the description of enum move_operation_enum. | |
4260 | ||
4261 | If TO_CHARPOS is in invisible text, e.g. a truncated part of a | |
4262 | screen line, this function will set IT to the next position > | |
4263 | TO_CHARPOS. */ | |
4264 | ||
4265 | void | |
4266 | move_it_to (it, to_charpos, to_x, to_y, to_vpos, op) | |
4267 | struct it *it; | |
4268 | int to_charpos, to_x, to_y, to_vpos; | |
4269 | int op; | |
4270 | { | |
4271 | enum move_it_result skip, skip2 = MOVE_X_REACHED; | |
4272 | int line_height; | |
4273 | ||
5f5c8ee5 GM |
4274 | while (1) |
4275 | { | |
4276 | if (op & MOVE_TO_VPOS) | |
4277 | { | |
4278 | /* If no TO_CHARPOS and no TO_X specified, stop at the | |
4279 | start of the line TO_VPOS. */ | |
4280 | if ((op & (MOVE_TO_X | MOVE_TO_POS)) == 0) | |
4281 | { | |
4282 | if (it->vpos == to_vpos) | |
4283 | break; | |
4284 | skip = move_it_in_display_line_to (it, -1, -1, 0); | |
4285 | } | |
4286 | else | |
4287 | { | |
4288 | /* TO_VPOS >= 0 means stop at TO_X in the line at | |
4289 | TO_VPOS, or at TO_POS, whichever comes first. */ | |
4290 | skip = move_it_in_display_line_to (it, to_charpos, to_x, op); | |
4291 | ||
4292 | if (skip == MOVE_POS_MATCH_OR_ZV || it->vpos == to_vpos) | |
4293 | break; | |
4294 | else if (skip == MOVE_X_REACHED && it->vpos != to_vpos) | |
4295 | { | |
4296 | /* We have reached TO_X but not in the line we want. */ | |
4297 | skip = move_it_in_display_line_to (it, to_charpos, | |
4298 | -1, MOVE_TO_POS); | |
4299 | if (skip == MOVE_POS_MATCH_OR_ZV) | |
4300 | break; | |
4301 | } | |
4302 | } | |
4303 | } | |
4304 | else if (op & MOVE_TO_Y) | |
4305 | { | |
4306 | struct it it_backup; | |
4307 | int done_p; | |
4308 | ||
4309 | /* TO_Y specified means stop at TO_X in the line containing | |
4310 | TO_Y---or at TO_CHARPOS if this is reached first. The | |
4311 | problem is that we can't really tell whether the line | |
4312 | contains TO_Y before we have completely scanned it, and | |
4313 | this may skip past TO_X. What we do is to first scan to | |
4314 | TO_X. | |
4315 | ||
4316 | If TO_X is not specified, use a TO_X of zero. The reason | |
4317 | is to make the outcome of this function more predictable. | |
4318 | If we didn't use TO_X == 0, we would stop at the end of | |
4319 | the line which is probably not what a caller would expect | |
4320 | to happen. */ | |
4321 | skip = move_it_in_display_line_to (it, to_charpos, | |
4322 | ((op & MOVE_TO_X) | |
4323 | ? to_x : 0), | |
4324 | (MOVE_TO_X | |
4325 | | (op & MOVE_TO_POS))); | |
4326 | ||
4327 | /* If TO_CHARPOS is reached or ZV, we don't have to do more. */ | |
4328 | if (skip == MOVE_POS_MATCH_OR_ZV) | |
4329 | break; | |
4330 | ||
4331 | /* If TO_X was reached, we would like to know whether TO_Y | |
4332 | is in the line. This can only be said if we know the | |
4333 | total line height which requires us to scan the rest of | |
4334 | the line. */ | |
4335 | done_p = 0; | |
4336 | if (skip == MOVE_X_REACHED) | |
4337 | { | |
4338 | it_backup = *it; | |
4339 | skip2 = move_it_in_display_line_to (it, to_charpos, -1, | |
4340 | op & MOVE_TO_POS); | |
4341 | } | |
4342 | ||
4343 | /* Now, decide whether TO_Y is in this line. */ | |
4344 | line_height = it->max_ascent + it->max_descent; | |
4345 | ||
4346 | if (to_y >= it->current_y | |
4347 | && to_y < it->current_y + line_height) | |
4348 | { | |
4349 | if (skip == MOVE_X_REACHED) | |
4350 | /* If TO_Y is in this line and TO_X was reached above, | |
4351 | we scanned too far. We have to restore IT's settings | |
4352 | to the ones before skipping. */ | |
4353 | *it = it_backup; | |
4354 | done_p = 1; | |
4355 | } | |
4356 | else if (skip == MOVE_X_REACHED) | |
4357 | { | |
4358 | skip = skip2; | |
4359 | if (skip == MOVE_POS_MATCH_OR_ZV) | |
4360 | done_p = 1; | |
4361 | } | |
4362 | ||
4363 | if (done_p) | |
4364 | break; | |
4365 | } | |
4366 | else | |
4367 | skip = move_it_in_display_line_to (it, to_charpos, -1, MOVE_TO_POS); | |
4368 | ||
4369 | switch (skip) | |
4370 | { | |
4371 | case MOVE_POS_MATCH_OR_ZV: | |
4372 | return; | |
4373 | ||
4374 | case MOVE_NEWLINE_OR_CR: | |
4375 | set_iterator_to_next (it); | |
4376 | it->continuation_lines_width = 0; | |
4377 | break; | |
4378 | ||
4379 | case MOVE_LINE_TRUNCATED: | |
4380 | it->continuation_lines_width = 0; | |
312246d1 | 4381 | reseat_at_next_visible_line_start (it, 0); |
5f5c8ee5 GM |
4382 | if ((op & MOVE_TO_POS) != 0 |
4383 | && IT_CHARPOS (*it) > to_charpos) | |
4384 | goto out; | |
4385 | break; | |
4386 | ||
4387 | case MOVE_LINE_CONTINUED: | |
4388 | it->continuation_lines_width += it->current_x; | |
4389 | break; | |
4390 | ||
4391 | default: | |
4392 | abort (); | |
4393 | } | |
4394 | ||
4395 | /* Reset/increment for the next run. */ | |
4396 | recenter_overlay_lists (current_buffer, IT_CHARPOS (*it)); | |
4397 | it->current_x = it->hpos = 0; | |
4398 | it->current_y += it->max_ascent + it->max_descent; | |
4399 | ++it->vpos; | |
4400 | last_height = it->max_ascent + it->max_descent; | |
4401 | last_max_ascent = it->max_ascent; | |
4402 | it->max_ascent = it->max_descent = 0; | |
4403 | } | |
4404 | out:; | |
4405 | } | |
4406 | ||
4407 | ||
4408 | /* Move iterator IT backward by a specified y-distance DY, DY >= 0. | |
4409 | ||
4410 | If DY > 0, move IT backward at least that many pixels. DY = 0 | |
4411 | means move IT backward to the preceding line start or BEGV. This | |
4412 | function may move over more than DY pixels if IT->current_y - DY | |
4413 | ends up in the middle of a line; in this case IT->current_y will be | |
4414 | set to the top of the line moved to. */ | |
4415 | ||
4416 | void | |
4417 | move_it_vertically_backward (it, dy) | |
4418 | struct it *it; | |
4419 | int dy; | |
4420 | { | |
4421 | int nlines, h, line_height; | |
4422 | struct it it2; | |
4423 | int start_pos = IT_CHARPOS (*it); | |
4424 | ||
4425 | xassert (dy >= 0); | |
4426 | ||
4427 | /* Estimate how many newlines we must move back. */ | |
4428 | nlines = max (1, dy / CANON_Y_UNIT (it->f)); | |
4429 | ||
4430 | /* Set the iterator's position that many lines back. */ | |
4431 | while (nlines-- && IT_CHARPOS (*it) > BEGV) | |
4432 | back_to_previous_visible_line_start (it); | |
4433 | ||
4434 | /* Reseat the iterator here. When moving backward, we don't want | |
4435 | reseat to skip forward over invisible text, set up the iterator | |
4436 | to deliver from overlay strings at the new position etc. So, | |
4437 | use reseat_1 here. */ | |
4438 | reseat_1 (it, it->current.pos, 1); | |
4439 | ||
4440 | /* We are now surely at a line start. */ | |
4441 | it->current_x = it->hpos = 0; | |
4442 | ||
4443 | /* Move forward and see what y-distance we moved. First move to the | |
4444 | start of the next line so that we get its height. We need this | |
4445 | height to be able to tell whether we reached the specified | |
4446 | y-distance. */ | |
4447 | it2 = *it; | |
4448 | it2.max_ascent = it2.max_descent = 0; | |
4449 | move_it_to (&it2, start_pos, -1, -1, it2.vpos + 1, | |
4450 | MOVE_TO_POS | MOVE_TO_VPOS); | |
4451 | xassert (IT_CHARPOS (*it) >= BEGV); | |
4452 | line_height = it2.max_ascent + it2.max_descent; | |
4453 | move_it_to (&it2, start_pos, -1, -1, -1, MOVE_TO_POS); | |
4454 | xassert (IT_CHARPOS (*it) >= BEGV); | |
4455 | h = it2.current_y - it->current_y; | |
4456 | nlines = it2.vpos - it->vpos; | |
4457 | ||
4458 | /* Correct IT's y and vpos position. */ | |
4459 | it->vpos -= nlines; | |
4460 | it->current_y -= h; | |
4461 | ||
4462 | if (dy == 0) | |
4463 | { | |
4464 | /* DY == 0 means move to the start of the screen line. The | |
4465 | value of nlines is > 0 if continuation lines were involved. */ | |
4466 | if (nlines > 0) | |
4467 | move_it_by_lines (it, nlines, 1); | |
4468 | xassert (IT_CHARPOS (*it) <= start_pos); | |
4469 | } | |
4470 | else if (nlines) | |
4471 | { | |
4472 | /* The y-position we try to reach. Note that h has been | |
4473 | subtracted in front of the if-statement. */ | |
4474 | int target_y = it->current_y + h - dy; | |
4475 | ||
4476 | /* If we did not reach target_y, try to move further backward if | |
4477 | we can. If we moved too far backward, try to move forward. */ | |
4478 | if (target_y < it->current_y | |
4479 | && IT_CHARPOS (*it) > BEGV) | |
4480 | { | |
4481 | move_it_vertically (it, target_y - it->current_y); | |
4482 | xassert (IT_CHARPOS (*it) >= BEGV); | |
4483 | } | |
4484 | else if (target_y >= it->current_y + line_height | |
4485 | && IT_CHARPOS (*it) < ZV) | |
4486 | { | |
4487 | move_it_vertically (it, target_y - (it->current_y + line_height)); | |
4488 | xassert (IT_CHARPOS (*it) >= BEGV); | |
4489 | } | |
4490 | } | |
4491 | } | |
4492 | ||
4493 | ||
4494 | /* Move IT by a specified amount of pixel lines DY. DY negative means | |
4495 | move backwards. DY = 0 means move to start of screen line. At the | |
4496 | end, IT will be on the start of a screen line. */ | |
4497 | ||
4498 | void | |
4499 | move_it_vertically (it, dy) | |
4500 | struct it *it; | |
4501 | int dy; | |
4502 | { | |
4503 | if (dy <= 0) | |
4504 | move_it_vertically_backward (it, -dy); | |
4505 | else if (dy > 0) | |
4506 | { | |
4507 | move_it_to (it, ZV, -1, it->current_y + dy, -1, | |
4508 | MOVE_TO_POS | MOVE_TO_Y); | |
4509 | ||
4510 | /* If buffer ends in ZV without a newline, move to the start of | |
4511 | the line to satisfy the post-condition. */ | |
4512 | if (IT_CHARPOS (*it) == ZV | |
4513 | && FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n') | |
4514 | move_it_by_lines (it, 0, 0); | |
4515 | } | |
4516 | } | |
4517 | ||
4518 | ||
4519 | /* Return non-zero if some text between buffer positions START_CHARPOS | |
4520 | and END_CHARPOS is invisible. IT->window is the window for text | |
4521 | property lookup. */ | |
4522 | ||
4523 | static int | |
4524 | invisible_text_between_p (it, start_charpos, end_charpos) | |
4525 | struct it *it; | |
4526 | int start_charpos, end_charpos; | |
4527 | { | |
5f5c8ee5 GM |
4528 | Lisp_Object prop, limit; |
4529 | int invisible_found_p; | |
4530 | ||
4531 | xassert (it != NULL && start_charpos <= end_charpos); | |
4532 | ||
4533 | /* Is text at START invisible? */ | |
4534 | prop = Fget_char_property (make_number (start_charpos), Qinvisible, | |
4535 | it->window); | |
4536 | if (TEXT_PROP_MEANS_INVISIBLE (prop)) | |
4537 | invisible_found_p = 1; | |
4538 | else | |
4539 | { | |
6c577098 GM |
4540 | limit = next_single_char_property_change (make_number (start_charpos), |
4541 | Qinvisible, Qnil, | |
4542 | make_number (end_charpos)); | |
5f5c8ee5 GM |
4543 | invisible_found_p = XFASTINT (limit) < end_charpos; |
4544 | } | |
4545 | ||
4546 | return invisible_found_p; | |
5f5c8ee5 GM |
4547 | } |
4548 | ||
4549 | ||
4550 | /* Move IT by a specified number DVPOS of screen lines down. DVPOS | |
4551 | negative means move up. DVPOS == 0 means move to the start of the | |
4552 | screen line. NEED_Y_P non-zero means calculate IT->current_y. If | |
4553 | NEED_Y_P is zero, IT->current_y will be left unchanged. | |
4554 | ||
4555 | Further optimization ideas: If we would know that IT->f doesn't use | |
4556 | a face with proportional font, we could be faster for | |
4557 | truncate-lines nil. */ | |
4558 | ||
4559 | void | |
4560 | move_it_by_lines (it, dvpos, need_y_p) | |
4561 | struct it *it; | |
4562 | int dvpos, need_y_p; | |
4563 | { | |
4564 | struct position pos; | |
4565 | ||
4566 | if (!FRAME_WINDOW_P (it->f)) | |
4567 | { | |
4568 | struct text_pos textpos; | |
4569 | ||
4570 | /* We can use vmotion on frames without proportional fonts. */ | |
4571 | pos = *vmotion (IT_CHARPOS (*it), dvpos, it->w); | |
4572 | SET_TEXT_POS (textpos, pos.bufpos, pos.bytepos); | |
4573 | reseat (it, textpos, 1); | |
4574 | it->vpos += pos.vpos; | |
4575 | it->current_y += pos.vpos; | |
4576 | } | |
4577 | else if (dvpos == 0) | |
4578 | { | |
4579 | /* DVPOS == 0 means move to the start of the screen line. */ | |
4580 | move_it_vertically_backward (it, 0); | |
4581 | xassert (it->current_x == 0 && it->hpos == 0); | |
4582 | } | |
4583 | else if (dvpos > 0) | |
4584 | { | |
4585 | /* If there are no continuation lines, and if there is no | |
4586 | selective display, try the simple method of moving forward | |
4587 | DVPOS newlines, then see where we are. */ | |
4588 | if (!need_y_p && it->truncate_lines_p && it->selective == 0) | |
4589 | { | |
4590 | int shortage = 0, charpos; | |
4591 | ||
4592 | if (FETCH_BYTE (IT_BYTEPOS (*it) == '\n')) | |
4593 | charpos = IT_CHARPOS (*it) + 1; | |
4594 | else | |
4595 | charpos = scan_buffer ('\n', IT_CHARPOS (*it), 0, dvpos, | |
4596 | &shortage, 0); | |
4597 | ||
4598 | if (!invisible_text_between_p (it, IT_CHARPOS (*it), charpos)) | |
4599 | { | |
4600 | struct text_pos pos; | |
4601 | CHARPOS (pos) = charpos; | |
4602 | BYTEPOS (pos) = CHAR_TO_BYTE (charpos); | |
4603 | reseat (it, pos, 1); | |
4604 | it->vpos += dvpos - shortage; | |
4605 | it->hpos = it->current_x = 0; | |
4606 | return; | |
4607 | } | |
4608 | } | |
4609 | ||
4610 | move_it_to (it, -1, -1, -1, it->vpos + dvpos, MOVE_TO_VPOS); | |
4611 | } | |
4612 | else | |
4613 | { | |
4614 | struct it it2; | |
4615 | int start_charpos, i; | |
4616 | ||
4617 | /* If there are no continuation lines, and if there is no | |
4618 | selective display, try the simple method of moving backward | |
4619 | -DVPOS newlines. */ | |
4620 | if (!need_y_p && it->truncate_lines_p && it->selective == 0) | |
4621 | { | |
4622 | int shortage; | |
4623 | int charpos = IT_CHARPOS (*it); | |
4624 | int bytepos = IT_BYTEPOS (*it); | |
4625 | ||
4626 | /* If in the middle of a line, go to its start. */ | |
4627 | if (charpos > BEGV && FETCH_BYTE (bytepos - 1) != '\n') | |
4628 | { | |
4629 | charpos = find_next_newline_no_quit (charpos, -1); | |
4630 | bytepos = CHAR_TO_BYTE (charpos); | |
4631 | } | |
4632 | ||
4633 | if (charpos == BEGV) | |
4634 | { | |
4635 | struct text_pos pos; | |
4636 | CHARPOS (pos) = charpos; | |
4637 | BYTEPOS (pos) = bytepos; | |
4638 | reseat (it, pos, 1); | |
4639 | it->hpos = it->current_x = 0; | |
4640 | return; | |
4641 | } | |
4642 | else | |
4643 | { | |
4644 | charpos = scan_buffer ('\n', charpos - 1, 0, dvpos, &shortage, 0); | |
4645 | if (!invisible_text_between_p (it, charpos, IT_CHARPOS (*it))) | |
4646 | { | |
4647 | struct text_pos pos; | |
4648 | CHARPOS (pos) = charpos; | |
4649 | BYTEPOS (pos) = CHAR_TO_BYTE (charpos); | |
4650 | reseat (it, pos, 1); | |
4651 | it->vpos += dvpos + (shortage ? shortage - 1 : 0); | |
4652 | it->hpos = it->current_x = 0; | |
4653 | return; | |
4654 | } | |
4655 | } | |
4656 | } | |
4657 | ||
4658 | /* Go back -DVPOS visible lines and reseat the iterator there. */ | |
4659 | start_charpos = IT_CHARPOS (*it); | |
4660 | for (i = -dvpos; i && IT_CHARPOS (*it) > BEGV; --i) | |
4661 | back_to_previous_visible_line_start (it); | |
4662 | reseat (it, it->current.pos, 1); | |
4663 | it->current_x = it->hpos = 0; | |
4664 | ||
4665 | /* Above call may have moved too far if continuation lines | |
4666 | are involved. Scan forward and see if it did. */ | |
4667 | it2 = *it; | |
4668 | it2.vpos = it2.current_y = 0; | |
4669 | move_it_to (&it2, start_charpos, -1, -1, -1, MOVE_TO_POS); | |
4670 | it->vpos -= it2.vpos; | |
4671 | it->current_y -= it2.current_y; | |
4672 | it->current_x = it->hpos = 0; | |
4673 | ||
4674 | /* If we moved too far, move IT some lines forward. */ | |
4675 | if (it2.vpos > -dvpos) | |
4676 | { | |
4677 | int delta = it2.vpos + dvpos; | |
4678 | move_it_to (it, -1, -1, -1, it->vpos + delta, MOVE_TO_VPOS); | |
4679 | } | |
4680 | } | |
4681 | } | |
4682 | ||
4683 | ||
4684 | \f | |
4685 | /*********************************************************************** | |
4686 | Messages | |
4687 | ***********************************************************************/ | |
4688 | ||
4689 | ||
937248bc GM |
4690 | /* Add a message with format string FORMAT and arguments ARG1 and ARG2 |
4691 | to *Messages*. */ | |
4692 | ||
4693 | void | |
4694 | add_to_log (format, arg1, arg2) | |
4695 | char *format; | |
4696 | Lisp_Object arg1, arg2; | |
4697 | { | |
4698 | Lisp_Object args[3]; | |
4699 | Lisp_Object msg, fmt; | |
4700 | char *buffer; | |
4701 | int len; | |
4702 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
4703 | ||
4704 | fmt = msg = Qnil; | |
4705 | GCPRO4 (fmt, msg, arg1, arg2); | |
4706 | ||
4707 | args[0] = fmt = build_string (format); | |
4708 | args[1] = arg1; | |
4709 | args[2] = arg2; | |
6fc556fd | 4710 | msg = Fformat (3, args); |
937248bc GM |
4711 | |
4712 | len = STRING_BYTES (XSTRING (msg)) + 1; | |
4713 | buffer = (char *) alloca (len); | |
4714 | strcpy (buffer, XSTRING (msg)->data); | |
4715 | ||
796184bc | 4716 | message_dolog (buffer, len - 1, 1, 0); |
937248bc GM |
4717 | UNGCPRO; |
4718 | } | |
4719 | ||
4720 | ||
5f5c8ee5 GM |
4721 | /* Output a newline in the *Messages* buffer if "needs" one. */ |
4722 | ||
4723 | void | |
4724 | message_log_maybe_newline () | |
4725 | { | |
4726 | if (message_log_need_newline) | |
4727 | message_dolog ("", 0, 1, 0); | |
4728 | } | |
4729 | ||
4730 | ||
4731 | /* Add a string M of length LEN to the message log, optionally | |
4732 | terminated with a newline when NLFLAG is non-zero. MULTIBYTE, if | |
4733 | nonzero, means interpret the contents of M as multibyte. This | |
4734 | function calls low-level routines in order to bypass text property | |
4735 | hooks, etc. which might not be safe to run. */ | |
4736 | ||
4737 | void | |
4738 | message_dolog (m, len, nlflag, multibyte) | |
4739 | char *m; | |
4740 | int len, nlflag, multibyte; | |
4741 | { | |
4742 | if (!NILP (Vmessage_log_max)) | |
4743 | { | |
4744 | struct buffer *oldbuf; | |
4745 | Lisp_Object oldpoint, oldbegv, oldzv; | |
4746 | int old_windows_or_buffers_changed = windows_or_buffers_changed; | |
4747 | int point_at_end = 0; | |
4748 | int zv_at_end = 0; | |
4749 | Lisp_Object old_deactivate_mark, tem; | |
4750 | struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
4751 | ||
4752 | old_deactivate_mark = Vdeactivate_mark; | |
4753 | oldbuf = current_buffer; | |
4754 | Fset_buffer (Fget_buffer_create (build_string ("*Messages*"))); | |
4755 | current_buffer->undo_list = Qt; | |
4756 | ||
4757 | oldpoint = Fpoint_marker (); | |
4758 | oldbegv = Fpoint_min_marker (); | |
4759 | oldzv = Fpoint_max_marker (); | |
4760 | GCPRO4 (oldpoint, oldbegv, oldzv, old_deactivate_mark); | |
4761 | ||
4762 | if (PT == Z) | |
4763 | point_at_end = 1; | |
4764 | if (ZV == Z) | |
4765 | zv_at_end = 1; | |
4766 | ||
4767 | BEGV = BEG; | |
4768 | BEGV_BYTE = BEG_BYTE; | |
4769 | ZV = Z; | |
4770 | ZV_BYTE = Z_BYTE; | |
4771 | TEMP_SET_PT_BOTH (Z, Z_BYTE); | |
4772 | ||
4773 | /* Insert the string--maybe converting multibyte to single byte | |
4774 | or vice versa, so that all the text fits the buffer. */ | |
4775 | if (multibyte | |
4776 | && NILP (current_buffer->enable_multibyte_characters)) | |
4777 | { | |
4778 | int i, c, nbytes; | |
4779 | unsigned char work[1]; | |
4780 | ||
4781 | /* Convert a multibyte string to single-byte | |
4782 | for the *Message* buffer. */ | |
4783 | for (i = 0; i < len; i += nbytes) | |
4784 | { | |
4fdb80f2 | 4785 | c = string_char_and_length (m + i, len - i, &nbytes); |
5f5c8ee5 GM |
4786 | work[0] = (SINGLE_BYTE_CHAR_P (c) |
4787 | ? c | |
4788 | : multibyte_char_to_unibyte (c, Qnil)); | |
4789 | insert_1_both (work, 1, 1, 1, 0, 0); | |
4790 | } | |
4791 | } | |
4792 | else if (! multibyte | |
4793 | && ! NILP (current_buffer->enable_multibyte_characters)) | |
4794 | { | |
4795 | int i, c, nbytes; | |
4796 | unsigned char *msg = (unsigned char *) m; | |
260a86a0 | 4797 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
5f5c8ee5 GM |
4798 | /* Convert a single-byte string to multibyte |
4799 | for the *Message* buffer. */ | |
4800 | for (i = 0; i < len; i++) | |
4801 | { | |
4802 | c = unibyte_char_to_multibyte (msg[i]); | |
260a86a0 KH |
4803 | nbytes = CHAR_STRING (c, str); |
4804 | insert_1_both (str, 1, nbytes, 1, 0, 0); | |
5f5c8ee5 GM |
4805 | } |
4806 | } | |
4807 | else if (len) | |
4808 | insert_1 (m, len, 1, 0, 0); | |
4809 | ||
4810 | if (nlflag) | |
4811 | { | |
4812 | int this_bol, this_bol_byte, prev_bol, prev_bol_byte, dup; | |
4813 | insert_1 ("\n", 1, 1, 0, 0); | |
4814 | ||
4815 | scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, -2, 0); | |
4816 | this_bol = PT; | |
4817 | this_bol_byte = PT_BYTE; | |
4818 | ||
4819 | if (this_bol > BEG) | |
4820 | { | |
4821 | scan_newline (PT, PT_BYTE, BEG, BEG_BYTE, -2, 0); | |
4822 | prev_bol = PT; | |
4823 | prev_bol_byte = PT_BYTE; | |
4824 | ||
4825 | dup = message_log_check_duplicate (prev_bol, prev_bol_byte, | |
4826 | this_bol, this_bol_byte); | |
4827 | if (dup) | |
4828 | { | |
4829 | del_range_both (prev_bol, prev_bol_byte, | |
4830 | this_bol, this_bol_byte, 0); | |
4831 | if (dup > 1) | |
4832 | { | |
4833 | char dupstr[40]; | |
4834 | int duplen; | |
4835 | ||
4836 | /* If you change this format, don't forget to also | |
4837 | change message_log_check_duplicate. */ | |
4838 | sprintf (dupstr, " [%d times]", dup); | |
4839 | duplen = strlen (dupstr); | |
4840 | TEMP_SET_PT_BOTH (Z - 1, Z_BYTE - 1); | |
4841 | insert_1 (dupstr, duplen, 1, 0, 1); | |
4842 | } | |
4843 | } | |
4844 | } | |
4845 | ||
4846 | if (NATNUMP (Vmessage_log_max)) | |
4847 | { | |
4848 | scan_newline (Z, Z_BYTE, BEG, BEG_BYTE, | |
4849 | -XFASTINT (Vmessage_log_max) - 1, 0); | |
4850 | del_range_both (BEG, BEG_BYTE, PT, PT_BYTE, 0); | |
4851 | } | |
4852 | } | |
4853 | BEGV = XMARKER (oldbegv)->charpos; | |
4854 | BEGV_BYTE = marker_byte_position (oldbegv); | |
4855 | ||
4856 | if (zv_at_end) | |
4857 | { | |
4858 | ZV = Z; | |
4859 | ZV_BYTE = Z_BYTE; | |
4860 | } | |
4861 | else | |
4862 | { | |
4863 | ZV = XMARKER (oldzv)->charpos; | |
4864 | ZV_BYTE = marker_byte_position (oldzv); | |
4865 | } | |
4866 | ||
4867 | if (point_at_end) | |
4868 | TEMP_SET_PT_BOTH (Z, Z_BYTE); | |
4869 | else | |
4870 | /* We can't do Fgoto_char (oldpoint) because it will run some | |
4871 | Lisp code. */ | |
4872 | TEMP_SET_PT_BOTH (XMARKER (oldpoint)->charpos, | |
4873 | XMARKER (oldpoint)->bytepos); | |
4874 | ||
4875 | UNGCPRO; | |
4876 | free_marker (oldpoint); | |
4877 | free_marker (oldbegv); | |
4878 | free_marker (oldzv); | |
4879 | ||
4880 | tem = Fget_buffer_window (Fcurrent_buffer (), Qt); | |
4881 | set_buffer_internal (oldbuf); | |
4882 | if (NILP (tem)) | |
4883 | windows_or_buffers_changed = old_windows_or_buffers_changed; | |
4884 | message_log_need_newline = !nlflag; | |
4885 | Vdeactivate_mark = old_deactivate_mark; | |
4886 | } | |
4887 | } | |
4888 | ||
4889 | ||
4890 | /* We are at the end of the buffer after just having inserted a newline. | |
4891 | (Note: We depend on the fact we won't be crossing the gap.) | |
4892 | Check to see if the most recent message looks a lot like the previous one. | |
4893 | Return 0 if different, 1 if the new one should just replace it, or a | |
4894 | value N > 1 if we should also append " [N times]". */ | |
4895 | ||
4896 | static int | |
4897 | message_log_check_duplicate (prev_bol, prev_bol_byte, this_bol, this_bol_byte) | |
4898 | int prev_bol, this_bol; | |
4899 | int prev_bol_byte, this_bol_byte; | |
4900 | { | |
4901 | int i; | |
4902 | int len = Z_BYTE - 1 - this_bol_byte; | |
4903 | int seen_dots = 0; | |
4904 | unsigned char *p1 = BUF_BYTE_ADDRESS (current_buffer, prev_bol_byte); | |
4905 | unsigned char *p2 = BUF_BYTE_ADDRESS (current_buffer, this_bol_byte); | |
4906 | ||
4907 | for (i = 0; i < len; i++) | |
4908 | { | |
4909 | if (i >= 3 && p1[i-3] == '.' && p1[i-2] == '.' && p1[i-1] == '.' | |
4910 | && p1[i] != '\n') | |
4911 | seen_dots = 1; | |
4912 | if (p1[i] != p2[i]) | |
4913 | return seen_dots; | |
4914 | } | |
4915 | p1 += len; | |
4916 | if (*p1 == '\n') | |
4917 | return 2; | |
4918 | if (*p1++ == ' ' && *p1++ == '[') | |
4919 | { | |
4920 | int n = 0; | |
4921 | while (*p1 >= '0' && *p1 <= '9') | |
4922 | n = n * 10 + *p1++ - '0'; | |
4923 | if (strncmp (p1, " times]\n", 8) == 0) | |
4924 | return n+1; | |
4925 | } | |
4926 | return 0; | |
4927 | } | |
4928 | ||
4929 | ||
4930 | /* Display an echo area message M with a specified length of LEN | |
4931 | chars. The string may include null characters. If M is 0, clear | |
4932 | out any existing message, and let the mini-buffer text show through. | |
4933 | ||
4934 | The buffer M must continue to exist until after the echo area gets | |
4935 | cleared or some other message gets displayed there. This means do | |
4936 | not pass text that is stored in a Lisp string; do not pass text in | |
4937 | a buffer that was alloca'd. */ | |
4938 | ||
4939 | void | |
4940 | message2 (m, len, multibyte) | |
4941 | char *m; | |
4942 | int len; | |
4943 | int multibyte; | |
4944 | { | |
4945 | /* First flush out any partial line written with print. */ | |
4946 | message_log_maybe_newline (); | |
4947 | if (m) | |
4948 | message_dolog (m, len, 1, multibyte); | |
4949 | message2_nolog (m, len, multibyte); | |
4950 | } | |
4951 | ||
4952 | ||
4953 | /* The non-logging counterpart of message2. */ | |
4954 | ||
4955 | void | |
4956 | message2_nolog (m, len, multibyte) | |
4957 | char *m; | |
4958 | int len; | |
4959 | { | |
886bd6f2 | 4960 | struct frame *sf = SELECTED_FRAME (); |
5f5c8ee5 GM |
4961 | message_enable_multibyte = multibyte; |
4962 | ||
4963 | if (noninteractive) | |
4964 | { | |
4965 | if (noninteractive_need_newline) | |
4966 | putc ('\n', stderr); | |
4967 | noninteractive_need_newline = 0; | |
4968 | if (m) | |
4969 | fwrite (m, len, 1, stderr); | |
4970 | if (cursor_in_echo_area == 0) | |
4971 | fprintf (stderr, "\n"); | |
4972 | fflush (stderr); | |
4973 | } | |
4974 | /* A null message buffer means that the frame hasn't really been | |
4975 | initialized yet. Error messages get reported properly by | |
4976 | cmd_error, so this must be just an informative message; toss it. */ | |
4977 | else if (INTERACTIVE | |
886bd6f2 GM |
4978 | && sf->glyphs_initialized_p |
4979 | && FRAME_MESSAGE_BUF (sf)) | |
5f5c8ee5 GM |
4980 | { |
4981 | Lisp_Object mini_window; | |
4982 | struct frame *f; | |
4983 | ||
4984 | /* Get the frame containing the mini-buffer | |
4985 | that the selected frame is using. */ | |
886bd6f2 | 4986 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
5f5c8ee5 GM |
4987 | f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window))); |
4988 | ||
4989 | FRAME_SAMPLE_VISIBILITY (f); | |
886bd6f2 | 4990 | if (FRAME_VISIBLE_P (sf) |
5f5c8ee5 GM |
4991 | && ! FRAME_VISIBLE_P (f)) |
4992 | Fmake_frame_visible (WINDOW_FRAME (XWINDOW (mini_window))); | |
4993 | ||
4994 | if (m) | |
4995 | { | |
c6e89d6c | 4996 | set_message (m, Qnil, len, multibyte); |
5f5c8ee5 GM |
4997 | if (minibuffer_auto_raise) |
4998 | Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window))); | |
4999 | } | |
5000 | else | |
c6e89d6c | 5001 | clear_message (1, 1); |
5f5c8ee5 | 5002 | |
c6e89d6c | 5003 | do_pending_window_change (0); |
5f5c8ee5 | 5004 | echo_area_display (1); |
c6e89d6c | 5005 | do_pending_window_change (0); |
5f5c8ee5 GM |
5006 | if (frame_up_to_date_hook != 0 && ! gc_in_progress) |
5007 | (*frame_up_to_date_hook) (f); | |
5008 | } | |
5009 | } | |
5010 | ||
5011 | ||
c6e89d6c GM |
5012 | /* Display an echo area message M with a specified length of NBYTES |
5013 | bytes. The string may include null characters. If M is not a | |
5f5c8ee5 GM |
5014 | string, clear out any existing message, and let the mini-buffer |
5015 | text show through. */ | |
5016 | ||
5017 | void | |
c6e89d6c | 5018 | message3 (m, nbytes, multibyte) |
5f5c8ee5 | 5019 | Lisp_Object m; |
c6e89d6c | 5020 | int nbytes; |
5f5c8ee5 GM |
5021 | int multibyte; |
5022 | { | |
5023 | struct gcpro gcpro1; | |
5024 | ||
5025 | GCPRO1 (m); | |
5026 | ||
5027 | /* First flush out any partial line written with print. */ | |
5028 | message_log_maybe_newline (); | |
5029 | if (STRINGP (m)) | |
c6e89d6c GM |
5030 | message_dolog (XSTRING (m)->data, nbytes, 1, multibyte); |
5031 | message3_nolog (m, nbytes, multibyte); | |
5f5c8ee5 GM |
5032 | |
5033 | UNGCPRO; | |
5034 | } | |
5035 | ||
5036 | ||
5037 | /* The non-logging version of message3. */ | |
5038 | ||
5039 | void | |
c6e89d6c | 5040 | message3_nolog (m, nbytes, multibyte) |
5f5c8ee5 | 5041 | Lisp_Object m; |
c6e89d6c | 5042 | int nbytes, multibyte; |
5f5c8ee5 | 5043 | { |
886bd6f2 | 5044 | struct frame *sf = SELECTED_FRAME (); |
5f5c8ee5 GM |
5045 | message_enable_multibyte = multibyte; |
5046 | ||
5047 | if (noninteractive) | |
5048 | { | |
5049 | if (noninteractive_need_newline) | |
5050 | putc ('\n', stderr); | |
5051 | noninteractive_need_newline = 0; | |
5052 | if (STRINGP (m)) | |
c6e89d6c | 5053 | fwrite (XSTRING (m)->data, nbytes, 1, stderr); |
5f5c8ee5 GM |
5054 | if (cursor_in_echo_area == 0) |
5055 | fprintf (stderr, "\n"); | |
5056 | fflush (stderr); | |
5057 | } | |
5058 | /* A null message buffer means that the frame hasn't really been | |
5059 | initialized yet. Error messages get reported properly by | |
5060 | cmd_error, so this must be just an informative message; toss it. */ | |
5061 | else if (INTERACTIVE | |
886bd6f2 GM |
5062 | && sf->glyphs_initialized_p |
5063 | && FRAME_MESSAGE_BUF (sf)) | |
5f5c8ee5 GM |
5064 | { |
5065 | Lisp_Object mini_window; | |
c6e89d6c | 5066 | Lisp_Object frame; |
5f5c8ee5 GM |
5067 | struct frame *f; |
5068 | ||
5069 | /* Get the frame containing the mini-buffer | |
5070 | that the selected frame is using. */ | |
886bd6f2 | 5071 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
c6e89d6c GM |
5072 | frame = XWINDOW (mini_window)->frame; |
5073 | f = XFRAME (frame); | |
5f5c8ee5 GM |
5074 | |
5075 | FRAME_SAMPLE_VISIBILITY (f); | |
886bd6f2 | 5076 | if (FRAME_VISIBLE_P (sf) |
c6e89d6c GM |
5077 | && !FRAME_VISIBLE_P (f)) |
5078 | Fmake_frame_visible (frame); | |
5f5c8ee5 | 5079 | |
c6e89d6c | 5080 | if (STRINGP (m) && XSTRING (m)->size) |
5f5c8ee5 | 5081 | { |
c6e89d6c | 5082 | set_message (NULL, m, nbytes, multibyte); |
468155d7 GM |
5083 | if (minibuffer_auto_raise) |
5084 | Fraise_frame (frame); | |
5f5c8ee5 GM |
5085 | } |
5086 | else | |
c6e89d6c | 5087 | clear_message (1, 1); |
5f5c8ee5 | 5088 | |
c6e89d6c | 5089 | do_pending_window_change (0); |
5f5c8ee5 | 5090 | echo_area_display (1); |
c6e89d6c | 5091 | do_pending_window_change (0); |
5f5c8ee5 GM |
5092 | if (frame_up_to_date_hook != 0 && ! gc_in_progress) |
5093 | (*frame_up_to_date_hook) (f); | |
5094 | } | |
5095 | } | |
5096 | ||
5097 | ||
5098 | /* Display a null-terminated echo area message M. If M is 0, clear | |
5099 | out any existing message, and let the mini-buffer text show through. | |
5100 | ||
5101 | The buffer M must continue to exist until after the echo area gets | |
5102 | cleared or some other message gets displayed there. Do not pass | |
5103 | text that is stored in a Lisp string. Do not pass text in a buffer | |
5104 | that was alloca'd. */ | |
5105 | ||
5106 | void | |
5107 | message1 (m) | |
5108 | char *m; | |
5109 | { | |
5110 | message2 (m, (m ? strlen (m) : 0), 0); | |
5111 | } | |
5112 | ||
5113 | ||
5114 | /* The non-logging counterpart of message1. */ | |
5115 | ||
5116 | void | |
5117 | message1_nolog (m) | |
5118 | char *m; | |
5119 | { | |
5120 | message2_nolog (m, (m ? strlen (m) : 0), 0); | |
5121 | } | |
5122 | ||
5123 | /* Display a message M which contains a single %s | |
5124 | which gets replaced with STRING. */ | |
5125 | ||
5126 | void | |
5127 | message_with_string (m, string, log) | |
5128 | char *m; | |
5129 | Lisp_Object string; | |
5130 | int log; | |
5131 | { | |
5132 | if (noninteractive) | |
5133 | { | |
5134 | if (m) | |
5135 | { | |
5136 | if (noninteractive_need_newline) | |
5137 | putc ('\n', stderr); | |
5138 | noninteractive_need_newline = 0; | |
5139 | fprintf (stderr, m, XSTRING (string)->data); | |
5140 | if (cursor_in_echo_area == 0) | |
5141 | fprintf (stderr, "\n"); | |
5142 | fflush (stderr); | |
5143 | } | |
5144 | } | |
5145 | else if (INTERACTIVE) | |
5146 | { | |
5147 | /* The frame whose minibuffer we're going to display the message on. | |
5148 | It may be larger than the selected frame, so we need | |
5149 | to use its buffer, not the selected frame's buffer. */ | |
5150 | Lisp_Object mini_window; | |
886bd6f2 | 5151 | struct frame *f, *sf = SELECTED_FRAME (); |
5f5c8ee5 GM |
5152 | |
5153 | /* Get the frame containing the minibuffer | |
5154 | that the selected frame is using. */ | |
886bd6f2 | 5155 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
5f5c8ee5 GM |
5156 | f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window))); |
5157 | ||
5158 | /* A null message buffer means that the frame hasn't really been | |
5159 | initialized yet. Error messages get reported properly by | |
5160 | cmd_error, so this must be just an informative message; toss it. */ | |
5161 | if (FRAME_MESSAGE_BUF (f)) | |
5162 | { | |
5163 | int len; | |
5164 | char *a[1]; | |
5165 | a[0] = (char *) XSTRING (string)->data; | |
5166 | ||
5167 | len = doprnt (FRAME_MESSAGE_BUF (f), | |
5168 | FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a); | |
5169 | ||
5170 | if (log) | |
5171 | message2 (FRAME_MESSAGE_BUF (f), len, | |
5172 | STRING_MULTIBYTE (string)); | |
5173 | else | |
5174 | message2_nolog (FRAME_MESSAGE_BUF (f), len, | |
5175 | STRING_MULTIBYTE (string)); | |
5176 | ||
5177 | /* Print should start at the beginning of the message | |
5178 | buffer next time. */ | |
5179 | message_buf_print = 0; | |
5180 | } | |
5181 | } | |
5182 | } | |
5183 | ||
5184 | ||
5f5c8ee5 GM |
5185 | /* Dump an informative message to the minibuf. If M is 0, clear out |
5186 | any existing message, and let the mini-buffer text show through. */ | |
5187 | ||
5188 | /* VARARGS 1 */ | |
5189 | void | |
5190 | message (m, a1, a2, a3) | |
5191 | char *m; | |
5192 | EMACS_INT a1, a2, a3; | |
5193 | { | |
5194 | if (noninteractive) | |
5195 | { | |
5196 | if (m) | |
5197 | { | |
5198 | if (noninteractive_need_newline) | |
5199 | putc ('\n', stderr); | |
5200 | noninteractive_need_newline = 0; | |
5201 | fprintf (stderr, m, a1, a2, a3); | |
5202 | if (cursor_in_echo_area == 0) | |
5203 | fprintf (stderr, "\n"); | |
5204 | fflush (stderr); | |
5205 | } | |
5206 | } | |
5207 | else if (INTERACTIVE) | |
5208 | { | |
5209 | /* The frame whose mini-buffer we're going to display the message | |
5210 | on. It may be larger than the selected frame, so we need to | |
5211 | use its buffer, not the selected frame's buffer. */ | |
5212 | Lisp_Object mini_window; | |
886bd6f2 | 5213 | struct frame *f, *sf = SELECTED_FRAME (); |
5f5c8ee5 GM |
5214 | |
5215 | /* Get the frame containing the mini-buffer | |
5216 | that the selected frame is using. */ | |
886bd6f2 | 5217 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
5f5c8ee5 GM |
5218 | f = XFRAME (WINDOW_FRAME (XWINDOW (mini_window))); |
5219 | ||
5220 | /* A null message buffer means that the frame hasn't really been | |
5221 | initialized yet. Error messages get reported properly by | |
5222 | cmd_error, so this must be just an informative message; toss | |
5223 | it. */ | |
5224 | if (FRAME_MESSAGE_BUF (f)) | |
5225 | { | |
5226 | if (m) | |
5227 | { | |
5228 | int len; | |
5229 | #ifdef NO_ARG_ARRAY | |
5230 | char *a[3]; | |
5231 | a[0] = (char *) a1; | |
5232 | a[1] = (char *) a2; | |
5233 | a[2] = (char *) a3; | |
5234 | ||
5235 | len = doprnt (FRAME_MESSAGE_BUF (f), | |
5236 | FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, a); | |
5237 | #else | |
5238 | len = doprnt (FRAME_MESSAGE_BUF (f), | |
5239 | FRAME_MESSAGE_BUF_SIZE (f), m, (char *)0, 3, | |
5240 | (char **) &a1); | |
5241 | #endif /* NO_ARG_ARRAY */ | |
5242 | ||
5243 | message2 (FRAME_MESSAGE_BUF (f), len, 0); | |
5244 | } | |
5245 | else | |
5246 | message1 (0); | |
5247 | ||
5248 | /* Print should start at the beginning of the message | |
5249 | buffer next time. */ | |
5250 | message_buf_print = 0; | |
5251 | } | |
5252 | } | |
5253 | } | |
5254 | ||
5255 | ||
5256 | /* The non-logging version of message. */ | |
5257 | ||
5258 | void | |
5259 | message_nolog (m, a1, a2, a3) | |
5260 | char *m; | |
5261 | EMACS_INT a1, a2, a3; | |
5262 | { | |
5263 | Lisp_Object old_log_max; | |
5264 | old_log_max = Vmessage_log_max; | |
5265 | Vmessage_log_max = Qnil; | |
5266 | message (m, a1, a2, a3); | |
5267 | Vmessage_log_max = old_log_max; | |
5268 | } | |
5269 | ||
5270 | ||
c6e89d6c GM |
5271 | /* Display the current message in the current mini-buffer. This is |
5272 | only called from error handlers in process.c, and is not time | |
5273 | critical. */ | |
5f5c8ee5 GM |
5274 | |
5275 | void | |
5276 | update_echo_area () | |
5277 | { | |
c6e89d6c GM |
5278 | if (!NILP (echo_area_buffer[0])) |
5279 | { | |
5280 | Lisp_Object string; | |
5281 | string = Fcurrent_message (); | |
5282 | message3 (string, XSTRING (string)->size, | |
5283 | !NILP (current_buffer->enable_multibyte_characters)); | |
5284 | } | |
5285 | } | |
5286 | ||
5287 | ||
5bcfeb49 GM |
5288 | /* Make sure echo area buffers in echo_buffers[] are life. If they |
5289 | aren't, make new ones. */ | |
5290 | ||
5291 | static void | |
5292 | ensure_echo_area_buffers () | |
5293 | { | |
5294 | int i; | |
5295 | ||
5296 | for (i = 0; i < 2; ++i) | |
5297 | if (!BUFFERP (echo_buffer[i]) | |
5298 | || NILP (XBUFFER (echo_buffer[i])->name)) | |
5299 | { | |
5300 | char name[30]; | |
5301 | sprintf (name, " *Echo Area %d*", i); | |
5302 | echo_buffer[i] = Fget_buffer_create (build_string (name)); | |
5303 | } | |
5304 | } | |
5305 | ||
5306 | ||
c6e89d6c GM |
5307 | /* Call FN with args A1..A5 with either the current or last displayed |
5308 | echo_area_buffer as current buffer. | |
5309 | ||
5310 | WHICH zero means use the current message buffer | |
5311 | echo_area_buffer[0]. If that is nil, choose a suitable buffer | |
5312 | from echo_buffer[] and clear it. | |
5313 | ||
5314 | WHICH > 0 means use echo_area_buffer[1]. If that is nil, choose a | |
5315 | suitable buffer from echo_buffer[] and clear it. | |
5316 | ||
5317 | If WHICH < 0, set echo_area_buffer[1] to echo_area_buffer[0], so | |
5318 | that the current message becomes the last displayed one, make | |
5319 | choose a suitable buffer for echo_area_buffer[0], and clear it. | |
5320 | ||
5321 | Value is what FN returns. */ | |
5322 | ||
5323 | static int | |
62694e5a | 5324 | with_echo_area_buffer (w, which, fn, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) |
c6e89d6c GM |
5325 | struct window *w; |
5326 | int which; | |
5327 | int (*fn) (); | |
62694e5a | 5328 | int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10; |
c6e89d6c GM |
5329 | { |
5330 | Lisp_Object buffer; | |
15e26c76 | 5331 | int this_one, the_other, clear_buffer_p, rc; |
c6e89d6c GM |
5332 | int count = specpdl_ptr - specpdl; |
5333 | ||
5334 | /* If buffers aren't life, make new ones. */ | |
5bcfeb49 | 5335 | ensure_echo_area_buffers (); |
c6e89d6c GM |
5336 | |
5337 | clear_buffer_p = 0; | |
5338 | ||
5339 | if (which == 0) | |
5340 | this_one = 0, the_other = 1; | |
5341 | else if (which > 0) | |
5342 | this_one = 1, the_other = 0; | |
5f5c8ee5 | 5343 | else |
c6e89d6c GM |
5344 | { |
5345 | this_one = 0, the_other = 1; | |
5346 | clear_buffer_p = 1; | |
5347 | ||
5348 | /* We need a fresh one in case the current echo buffer equals | |
5349 | the one containing the last displayed echo area message. */ | |
5350 | if (!NILP (echo_area_buffer[this_one]) | |
5351 | && EQ (echo_area_buffer[this_one], echo_area_buffer[the_other])) | |
5352 | echo_area_buffer[this_one] = Qnil; | |
c6e89d6c GM |
5353 | } |
5354 | ||
5355 | /* Choose a suitable buffer from echo_buffer[] is we don't | |
5356 | have one. */ | |
5357 | if (NILP (echo_area_buffer[this_one])) | |
5358 | { | |
5359 | echo_area_buffer[this_one] | |
5360 | = (EQ (echo_area_buffer[the_other], echo_buffer[this_one]) | |
5361 | ? echo_buffer[the_other] | |
5362 | : echo_buffer[this_one]); | |
5363 | clear_buffer_p = 1; | |
5364 | } | |
5365 | ||
5366 | buffer = echo_area_buffer[this_one]; | |
5367 | ||
5368 | record_unwind_protect (unwind_with_echo_area_buffer, | |
5369 | with_echo_area_buffer_unwind_data (w)); | |
5370 | ||
5371 | /* Make the echo area buffer current. Note that for display | |
5372 | purposes, it is not necessary that the displayed window's buffer | |
5373 | == current_buffer, except for text property lookup. So, let's | |
5374 | only set that buffer temporarily here without doing a full | |
5375 | Fset_window_buffer. We must also change w->pointm, though, | |
5376 | because otherwise an assertions in unshow_buffer fails, and Emacs | |
5377 | aborts. */ | |
9142dd5b | 5378 | set_buffer_internal_1 (XBUFFER (buffer)); |
c6e89d6c GM |
5379 | if (w) |
5380 | { | |
5381 | w->buffer = buffer; | |
5382 | set_marker_both (w->pointm, buffer, BEG, BEG_BYTE); | |
5383 | } | |
5384 | current_buffer->truncate_lines = Qnil; | |
5385 | current_buffer->undo_list = Qt; | |
5386 | current_buffer->read_only = Qnil; | |
5387 | ||
5388 | if (clear_buffer_p && Z > BEG) | |
5389 | del_range (BEG, Z); | |
5390 | ||
5391 | xassert (BEGV >= BEG); | |
5392 | xassert (ZV <= Z && ZV >= BEGV); | |
5393 | ||
5394 | rc = fn (a1, a2, a3, a4, a5); | |
5395 | ||
5396 | xassert (BEGV >= BEG); | |
5397 | xassert (ZV <= Z && ZV >= BEGV); | |
5398 | ||
5399 | unbind_to (count, Qnil); | |
5400 | return rc; | |
5f5c8ee5 GM |
5401 | } |
5402 | ||
5403 | ||
c6e89d6c GM |
5404 | /* Save state that should be preserved around the call to the function |
5405 | FN called in with_echo_area_buffer. */ | |
5f5c8ee5 | 5406 | |
c6e89d6c GM |
5407 | static Lisp_Object |
5408 | with_echo_area_buffer_unwind_data (w) | |
5409 | struct window *w; | |
5f5c8ee5 | 5410 | { |
c6e89d6c GM |
5411 | int i = 0; |
5412 | Lisp_Object vector; | |
5f5c8ee5 | 5413 | |
c6e89d6c GM |
5414 | /* Reduce consing by keeping one vector in |
5415 | Vwith_echo_area_save_vector. */ | |
5416 | vector = Vwith_echo_area_save_vector; | |
5417 | Vwith_echo_area_save_vector = Qnil; | |
5418 | ||
5419 | if (NILP (vector)) | |
9142dd5b | 5420 | vector = Fmake_vector (make_number (7), Qnil); |
c6e89d6c GM |
5421 | |
5422 | XSETBUFFER (XVECTOR (vector)->contents[i], current_buffer); ++i; | |
5423 | XVECTOR (vector)->contents[i++] = Vdeactivate_mark; | |
5424 | XVECTOR (vector)->contents[i++] = make_number (windows_or_buffers_changed); | |
c6e89d6c GM |
5425 | |
5426 | if (w) | |
5427 | { | |
5428 | XSETWINDOW (XVECTOR (vector)->contents[i], w); ++i; | |
5429 | XVECTOR (vector)->contents[i++] = w->buffer; | |
5430 | XVECTOR (vector)->contents[i++] | |
5431 | = make_number (XMARKER (w->pointm)->charpos); | |
5432 | XVECTOR (vector)->contents[i++] | |
5433 | = make_number (XMARKER (w->pointm)->bytepos); | |
5434 | } | |
5435 | else | |
5436 | { | |
5437 | int end = i + 4; | |
5438 | while (i < end) | |
5439 | XVECTOR (vector)->contents[i++] = Qnil; | |
5440 | } | |
5f5c8ee5 | 5441 | |
c6e89d6c GM |
5442 | xassert (i == XVECTOR (vector)->size); |
5443 | return vector; | |
5444 | } | |
5f5c8ee5 | 5445 | |
5f5c8ee5 | 5446 | |
c6e89d6c GM |
5447 | /* Restore global state from VECTOR which was created by |
5448 | with_echo_area_buffer_unwind_data. */ | |
5449 | ||
5450 | static Lisp_Object | |
5451 | unwind_with_echo_area_buffer (vector) | |
5452 | Lisp_Object vector; | |
5453 | { | |
5454 | int i = 0; | |
5455 | ||
9142dd5b | 5456 | set_buffer_internal_1 (XBUFFER (XVECTOR (vector)->contents[i])); ++i; |
c6e89d6c GM |
5457 | Vdeactivate_mark = XVECTOR (vector)->contents[i]; ++i; |
5458 | windows_or_buffers_changed = XFASTINT (XVECTOR (vector)->contents[i]); ++i; | |
c6e89d6c GM |
5459 | |
5460 | if (WINDOWP (XVECTOR (vector)->contents[i])) | |
5461 | { | |
5462 | struct window *w; | |
5463 | Lisp_Object buffer, charpos, bytepos; | |
5464 | ||
5465 | w = XWINDOW (XVECTOR (vector)->contents[i]); ++i; | |
5466 | buffer = XVECTOR (vector)->contents[i]; ++i; | |
5467 | charpos = XVECTOR (vector)->contents[i]; ++i; | |
5468 | bytepos = XVECTOR (vector)->contents[i]; ++i; | |
5469 | ||
5470 | w->buffer = buffer; | |
5471 | set_marker_both (w->pointm, buffer, | |
5472 | XFASTINT (charpos), XFASTINT (bytepos)); | |
5473 | } | |
5474 | ||
5475 | Vwith_echo_area_save_vector = vector; | |
5476 | return Qnil; | |
5477 | } | |
5478 | ||
5479 | ||
5480 | /* Set up the echo area for use by print functions. MULTIBYTE_P | |
5481 | non-zero means we will print multibyte. */ | |
5482 | ||
5483 | void | |
5484 | setup_echo_area_for_printing (multibyte_p) | |
5485 | int multibyte_p; | |
5486 | { | |
5bcfeb49 GM |
5487 | ensure_echo_area_buffers (); |
5488 | ||
c6e89d6c GM |
5489 | if (!message_buf_print) |
5490 | { | |
5491 | /* A message has been output since the last time we printed. | |
5492 | Choose a fresh echo area buffer. */ | |
5493 | if (EQ (echo_area_buffer[1], echo_buffer[0])) | |
5494 | echo_area_buffer[0] = echo_buffer[1]; | |
5495 | else | |
5496 | echo_area_buffer[0] = echo_buffer[0]; | |
5497 | ||
5498 | /* Switch to that buffer and clear it. */ | |
5499 | set_buffer_internal (XBUFFER (echo_area_buffer[0])); | |
5500 | if (Z > BEG) | |
5501 | del_range (BEG, Z); | |
5502 | TEMP_SET_PT_BOTH (BEG, BEG_BYTE); | |
5503 | ||
5504 | /* Set up the buffer for the multibyteness we need. */ | |
5505 | if (multibyte_p | |
5506 | != !NILP (current_buffer->enable_multibyte_characters)) | |
5507 | Fset_buffer_multibyte (multibyte_p ? Qt : Qnil); | |
5508 | ||
5509 | /* Raise the frame containing the echo area. */ | |
5510 | if (minibuffer_auto_raise) | |
5511 | { | |
886bd6f2 | 5512 | struct frame *sf = SELECTED_FRAME (); |
c6e89d6c | 5513 | Lisp_Object mini_window; |
886bd6f2 | 5514 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
c6e89d6c GM |
5515 | Fraise_frame (WINDOW_FRAME (XWINDOW (mini_window))); |
5516 | } | |
5517 | ||
5518 | message_buf_print = 1; | |
5519 | } | |
fa77249f GM |
5520 | else |
5521 | { | |
5522 | if (NILP (echo_area_buffer[0])) | |
5523 | { | |
5524 | if (EQ (echo_area_buffer[1], echo_buffer[0])) | |
5525 | echo_area_buffer[0] = echo_buffer[1]; | |
5526 | else | |
5527 | echo_area_buffer[0] = echo_buffer[0]; | |
5528 | } | |
5529 | ||
5530 | if (current_buffer != XBUFFER (echo_area_buffer[0])) | |
5531 | /* Someone switched buffers between print requests. */ | |
5532 | set_buffer_internal (XBUFFER (echo_area_buffer[0])); | |
5533 | } | |
c6e89d6c GM |
5534 | } |
5535 | ||
5536 | ||
dd2eb166 GM |
5537 | /* Display an echo area message in window W. Value is non-zero if W's |
5538 | height is changed. If display_last_displayed_message_p is | |
5539 | non-zero, display the message that was last displayed, otherwise | |
5540 | display the current message. */ | |
c6e89d6c GM |
5541 | |
5542 | static int | |
5543 | display_echo_area (w) | |
5544 | struct window *w; | |
5545 | { | |
25edb08f GM |
5546 | int i, no_message_p, window_height_changed_p, count; |
5547 | ||
5548 | /* Temporarily disable garbage collections while displaying the echo | |
5549 | area. This is done because a GC can print a message itself. | |
5550 | That message would modify the echo area buffer's contents while a | |
5551 | redisplay of the buffer is going on, and seriously confuse | |
5552 | redisplay. */ | |
5553 | count = inhibit_garbage_collection (); | |
dd2eb166 GM |
5554 | |
5555 | /* If there is no message, we must call display_echo_area_1 | |
5556 | nevertheless because it resizes the window. But we will have to | |
5557 | reset the echo_area_buffer in question to nil at the end because | |
5558 | with_echo_area_buffer will sets it to an empty buffer. */ | |
5559 | i = display_last_displayed_message_p ? 1 : 0; | |
5560 | no_message_p = NILP (echo_area_buffer[i]); | |
5561 | ||
5562 | window_height_changed_p | |
5563 | = with_echo_area_buffer (w, display_last_displayed_message_p, | |
5564 | (int (*) ()) display_echo_area_1, w); | |
5565 | ||
5566 | if (no_message_p) | |
5567 | echo_area_buffer[i] = Qnil; | |
25edb08f GM |
5568 | |
5569 | unbind_to (count, Qnil); | |
dd2eb166 | 5570 | return window_height_changed_p; |
c6e89d6c GM |
5571 | } |
5572 | ||
5573 | ||
5574 | /* Helper for display_echo_area. Display the current buffer which | |
5575 | contains the current echo area message in window W, a mini-window. | |
5576 | Change the height of W so that all of the message is displayed. | |
5577 | Value is non-zero if height of W was changed. */ | |
5578 | ||
5579 | static int | |
5580 | display_echo_area_1 (w) | |
5581 | struct window *w; | |
5582 | { | |
5583 | Lisp_Object window; | |
c6e89d6c GM |
5584 | struct text_pos start; |
5585 | int window_height_changed_p = 0; | |
5586 | ||
5587 | /* Do this before displaying, so that we have a large enough glyph | |
5588 | matrix for the display. */ | |
92a90e89 | 5589 | window_height_changed_p = resize_mini_window (w, 0); |
c6e89d6c GM |
5590 | |
5591 | /* Display. */ | |
5592 | clear_glyph_matrix (w->desired_matrix); | |
5593 | XSETWINDOW (window, w); | |
5594 | SET_TEXT_POS (start, BEG, BEG_BYTE); | |
5595 | try_window (window, start); | |
5596 | ||
c6e89d6c GM |
5597 | return window_height_changed_p; |
5598 | } | |
5599 | ||
5600 | ||
92a90e89 GM |
5601 | /* Resize the echo area window to exactly the size needed for the |
5602 | currently displayed message, if there is one. */ | |
5603 | ||
5604 | void | |
5605 | resize_echo_area_axactly () | |
5606 | { | |
5607 | if (BUFFERP (echo_area_buffer[0]) | |
5608 | && WINDOWP (echo_area_window)) | |
5609 | { | |
5610 | struct window *w = XWINDOW (echo_area_window); | |
5611 | int resized_p; | |
5612 | ||
5613 | resized_p = with_echo_area_buffer (w, 0, | |
5614 | (int (*) ()) resize_mini_window, | |
5615 | w, 1); | |
5616 | if (resized_p) | |
5617 | { | |
5618 | ++windows_or_buffers_changed; | |
5619 | ++update_mode_lines; | |
5620 | redisplay_internal (0); | |
5621 | } | |
5622 | } | |
5623 | } | |
5624 | ||
5625 | ||
5626 | /* Resize mini-window W to fit the size of its contents. EXACT:P | |
5627 | means size the window exactly to the size needed. Otherwise, it's | |
5628 | only enlarged until W's buffer is empty. Value is non-zero if | |
5629 | the window height has been changed. */ | |
c6e89d6c | 5630 | |
9472f927 | 5631 | int |
92a90e89 | 5632 | resize_mini_window (w, exact_p) |
c6e89d6c | 5633 | struct window *w; |
92a90e89 | 5634 | int exact_p; |
c6e89d6c GM |
5635 | { |
5636 | struct frame *f = XFRAME (w->frame); | |
5637 | int window_height_changed_p = 0; | |
5638 | ||
5639 | xassert (MINI_WINDOW_P (w)); | |
97cafc0f GM |
5640 | |
5641 | /* Nil means don't try to resize. */ | |
00f6d59e GM |
5642 | if (NILP (Vmax_mini_window_height) |
5643 | || (FRAME_X_P (f) && f->output_data.x == NULL)) | |
97cafc0f | 5644 | return 0; |
c6e89d6c GM |
5645 | |
5646 | if (!FRAME_MINIBUF_ONLY_P (f)) | |
5647 | { | |
5648 | struct it it; | |
dd2eb166 GM |
5649 | struct window *root = XWINDOW (FRAME_ROOT_WINDOW (f)); |
5650 | int total_height = XFASTINT (root->height) + XFASTINT (w->height); | |
5651 | int height, max_height; | |
5652 | int unit = CANON_Y_UNIT (f); | |
5653 | struct text_pos start; | |
9142dd5b | 5654 | |
c6e89d6c | 5655 | init_iterator (&it, w, BEGV, BEGV_BYTE, NULL, DEFAULT_FACE_ID); |
c6e89d6c | 5656 | |
dd2eb166 GM |
5657 | /* Compute the max. number of lines specified by the user. */ |
5658 | if (FLOATP (Vmax_mini_window_height)) | |
5659 | max_height = XFLOATINT (Vmax_mini_window_height) * total_height; | |
5660 | else if (INTEGERP (Vmax_mini_window_height)) | |
5661 | max_height = XINT (Vmax_mini_window_height); | |
97cafc0f GM |
5662 | else |
5663 | max_height = total_height / 4; | |
dd2eb166 GM |
5664 | |
5665 | /* Correct that max. height if it's bogus. */ | |
5666 | max_height = max (1, max_height); | |
5667 | max_height = min (total_height, max_height); | |
5668 | ||
5669 | /* Find out the height of the text in the window. */ | |
55b064bd | 5670 | last_height = 0; |
dd2eb166 | 5671 | move_it_to (&it, ZV, -1, -1, -1, MOVE_TO_POS); |
55b064bd GM |
5672 | if (it.max_ascent == 0 && it.max_descent == 0) |
5673 | height = it.current_y + last_height; | |
5674 | else | |
5675 | height = it.current_y + it.max_ascent + it.max_descent; | |
5676 | height = (height + unit - 1) / unit; | |
dd2eb166 GM |
5677 | |
5678 | /* Compute a suitable window start. */ | |
5679 | if (height > max_height) | |
5680 | { | |
5681 | height = max_height; | |
5682 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
5683 | move_it_vertically_backward (&it, (height - 1) * unit); | |
5684 | start = it.current.pos; | |
5685 | } | |
5686 | else | |
5687 | SET_TEXT_POS (start, BEGV, BEGV_BYTE); | |
5688 | SET_MARKER_FROM_TEXT_POS (w->start, start); | |
c59c668a | 5689 | |
9472f927 GM |
5690 | /* Let it grow only, until we display an empty message, in which |
5691 | case the window shrinks again. */ | |
da448723 | 5692 | if (height > XFASTINT (w->height)) |
dd2eb166 | 5693 | { |
d2c48e86 | 5694 | int old_height = XFASTINT (w->height); |
da448723 GM |
5695 | freeze_window_starts (f, 1); |
5696 | grow_mini_window (w, height - XFASTINT (w->height)); | |
5697 | window_height_changed_p = XFASTINT (w->height) != old_height; | |
5698 | } | |
5699 | else if (height < XFASTINT (w->height) | |
5700 | && (exact_p || BEGV == ZV)) | |
5701 | { | |
5702 | int old_height = XFASTINT (w->height); | |
5703 | freeze_window_starts (f, 0); | |
5704 | shrink_mini_window (w); | |
d2c48e86 | 5705 | window_height_changed_p = XFASTINT (w->height) != old_height; |
9142dd5b | 5706 | } |
c6e89d6c GM |
5707 | } |
5708 | ||
5709 | return window_height_changed_p; | |
5710 | } | |
5711 | ||
5712 | ||
5713 | /* Value is the current message, a string, or nil if there is no | |
5714 | current message. */ | |
5715 | ||
5716 | Lisp_Object | |
5717 | current_message () | |
5718 | { | |
5719 | Lisp_Object msg; | |
5720 | ||
5721 | if (NILP (echo_area_buffer[0])) | |
5722 | msg = Qnil; | |
5723 | else | |
5724 | { | |
5725 | with_echo_area_buffer (0, 0, (int (*) ()) current_message_1, &msg); | |
5726 | if (NILP (msg)) | |
5727 | echo_area_buffer[0] = Qnil; | |
5728 | } | |
5729 | ||
5730 | return msg; | |
5731 | } | |
5732 | ||
5733 | ||
5734 | static int | |
5735 | current_message_1 (msg) | |
5736 | Lisp_Object *msg; | |
5737 | { | |
5738 | if (Z > BEG) | |
5739 | *msg = make_buffer_string (BEG, Z, 1); | |
5740 | else | |
5741 | *msg = Qnil; | |
5742 | return 0; | |
5743 | } | |
5744 | ||
5745 | ||
5746 | /* Push the current message on Vmessage_stack for later restauration | |
5747 | by restore_message. Value is non-zero if the current message isn't | |
5748 | empty. This is a relatively infrequent operation, so it's not | |
5749 | worth optimizing. */ | |
5750 | ||
5751 | int | |
5752 | push_message () | |
5753 | { | |
5754 | Lisp_Object msg; | |
5755 | msg = current_message (); | |
5756 | Vmessage_stack = Fcons (msg, Vmessage_stack); | |
5757 | return STRINGP (msg); | |
5758 | } | |
5759 | ||
5760 | ||
5761 | /* Restore message display from the top of Vmessage_stack. */ | |
5762 | ||
5763 | void | |
5764 | restore_message () | |
5765 | { | |
5766 | Lisp_Object msg; | |
5767 | ||
5768 | xassert (CONSP (Vmessage_stack)); | |
5769 | msg = XCAR (Vmessage_stack); | |
5770 | if (STRINGP (msg)) | |
5771 | message3_nolog (msg, STRING_BYTES (XSTRING (msg)), STRING_MULTIBYTE (msg)); | |
5772 | else | |
5773 | message3_nolog (msg, 0, 0); | |
5774 | } | |
5775 | ||
5776 | ||
5777 | /* Pop the top-most entry off Vmessage_stack. */ | |
5778 | ||
5779 | void | |
5780 | pop_message () | |
5781 | { | |
5782 | xassert (CONSP (Vmessage_stack)); | |
5783 | Vmessage_stack = XCDR (Vmessage_stack); | |
5784 | } | |
5785 | ||
5786 | ||
5787 | /* Check that Vmessage_stack is nil. Called from emacs.c when Emacs | |
5788 | exits. If the stack is not empty, we have a missing pop_message | |
5789 | somewhere. */ | |
5790 | ||
5791 | void | |
5792 | check_message_stack () | |
5793 | { | |
5794 | if (!NILP (Vmessage_stack)) | |
5795 | abort (); | |
5796 | } | |
5797 | ||
5798 | ||
5799 | /* Truncate to NCHARS what will be displayed in the echo area the next | |
5800 | time we display it---but don't redisplay it now. */ | |
5801 | ||
5802 | void | |
5803 | truncate_echo_area (nchars) | |
5804 | int nchars; | |
5805 | { | |
5806 | if (nchars == 0) | |
5807 | echo_area_buffer[0] = Qnil; | |
5808 | /* A null message buffer means that the frame hasn't really been | |
5809 | initialized yet. Error messages get reported properly by | |
5810 | cmd_error, so this must be just an informative message; toss it. */ | |
5811 | else if (!noninteractive | |
5812 | && INTERACTIVE | |
c6e89d6c | 5813 | && !NILP (echo_area_buffer[0])) |
886bd6f2 GM |
5814 | { |
5815 | struct frame *sf = SELECTED_FRAME (); | |
5816 | if (FRAME_MESSAGE_BUF (sf)) | |
5817 | with_echo_area_buffer (0, 0, (int (*) ()) truncate_message_1, nchars); | |
5818 | } | |
c6e89d6c GM |
5819 | } |
5820 | ||
5821 | ||
5822 | /* Helper function for truncate_echo_area. Truncate the current | |
5823 | message to at most NCHARS characters. */ | |
5824 | ||
5825 | static int | |
5826 | truncate_message_1 (nchars) | |
5827 | int nchars; | |
5828 | { | |
5829 | if (BEG + nchars < Z) | |
5830 | del_range (BEG + nchars, Z); | |
5831 | if (Z == BEG) | |
5832 | echo_area_buffer[0] = Qnil; | |
5833 | return 0; | |
5834 | } | |
5835 | ||
5836 | ||
5837 | /* Set the current message to a substring of S or STRING. | |
5838 | ||
5839 | If STRING is a Lisp string, set the message to the first NBYTES | |
5840 | bytes from STRING. NBYTES zero means use the whole string. If | |
5841 | STRING is multibyte, the message will be displayed multibyte. | |
5842 | ||
5843 | If S is not null, set the message to the first LEN bytes of S. LEN | |
5844 | zero means use the whole string. MULTIBYTE_P non-zero means S is | |
5845 | multibyte. Display the message multibyte in that case. */ | |
5846 | ||
5847 | void | |
5848 | set_message (s, string, nbytes, multibyte_p) | |
5849 | char *s; | |
5850 | Lisp_Object string; | |
5851 | int nbytes; | |
5852 | { | |
5853 | message_enable_multibyte | |
5854 | = ((s && multibyte_p) | |
5855 | || (STRINGP (string) && STRING_MULTIBYTE (string))); | |
5856 | ||
5857 | with_echo_area_buffer (0, -1, (int (*) ()) set_message_1, | |
5858 | s, string, nbytes, multibyte_p); | |
5859 | message_buf_print = 0; | |
5860 | } | |
5861 | ||
5862 | ||
5863 | /* Helper function for set_message. Arguments have the same meaning | |
5864 | as there. This function is called with the echo area buffer being | |
5865 | current. */ | |
5866 | ||
5867 | static int | |
5868 | set_message_1 (s, string, nbytes, multibyte_p) | |
5869 | char *s; | |
5870 | Lisp_Object string; | |
5871 | int nbytes, multibyte_p; | |
5872 | { | |
5873 | xassert (BEG == Z); | |
5874 | ||
5875 | /* Change multibyteness of the echo buffer appropriately. */ | |
5876 | if (message_enable_multibyte | |
5877 | != !NILP (current_buffer->enable_multibyte_characters)) | |
5878 | Fset_buffer_multibyte (message_enable_multibyte ? Qt : Qnil); | |
5879 | ||
5880 | /* Insert new message at BEG. */ | |
5881 | TEMP_SET_PT_BOTH (BEG, BEG_BYTE); | |
5882 | ||
5883 | if (STRINGP (string)) | |
5884 | { | |
5885 | int nchars; | |
5886 | ||
5887 | if (nbytes == 0) | |
5888 | nbytes = XSTRING (string)->size_byte; | |
5889 | nchars = string_byte_to_char (string, nbytes); | |
5890 | ||
5891 | /* This function takes care of single/multibyte conversion. We | |
5892 | just have to ensure that the echo area buffer has the right | |
5893 | setting of enable_multibyte_characters. */ | |
5894 | insert_from_string (string, 0, 0, nchars, nbytes, 1); | |
5895 | } | |
5896 | else if (s) | |
5897 | { | |
5898 | if (nbytes == 0) | |
5899 | nbytes = strlen (s); | |
5900 | ||
5901 | if (multibyte_p && NILP (current_buffer->enable_multibyte_characters)) | |
5902 | { | |
5903 | /* Convert from multi-byte to single-byte. */ | |
5904 | int i, c, n; | |
5905 | unsigned char work[1]; | |
5906 | ||
5907 | /* Convert a multibyte string to single-byte. */ | |
5908 | for (i = 0; i < nbytes; i += n) | |
5909 | { | |
5910 | c = string_char_and_length (s + i, nbytes - i, &n); | |
5911 | work[0] = (SINGLE_BYTE_CHAR_P (c) | |
5912 | ? c | |
5913 | : multibyte_char_to_unibyte (c, Qnil)); | |
5914 | insert_1_both (work, 1, 1, 1, 0, 0); | |
5915 | } | |
5916 | } | |
5917 | else if (!multibyte_p | |
5918 | && !NILP (current_buffer->enable_multibyte_characters)) | |
5919 | { | |
5920 | /* Convert from single-byte to multi-byte. */ | |
5921 | int i, c, n; | |
5922 | unsigned char *msg = (unsigned char *) s; | |
260a86a0 | 5923 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
c6e89d6c GM |
5924 | |
5925 | /* Convert a single-byte string to multibyte. */ | |
5926 | for (i = 0; i < nbytes; i++) | |
5927 | { | |
5928 | c = unibyte_char_to_multibyte (msg[i]); | |
260a86a0 KH |
5929 | n = CHAR_STRING (c, str); |
5930 | insert_1_both (str, 1, n, 1, 0, 0); | |
c6e89d6c GM |
5931 | } |
5932 | } | |
5933 | else | |
5934 | insert_1 (s, nbytes, 1, 0, 0); | |
5935 | } | |
5936 | ||
5937 | return 0; | |
5938 | } | |
5939 | ||
5940 | ||
5941 | /* Clear messages. CURRENT_P non-zero means clear the current | |
5942 | message. LAST_DISPLAYED_P non-zero means clear the message | |
5943 | last displayed. */ | |
5944 | ||
5945 | void | |
5946 | clear_message (current_p, last_displayed_p) | |
5947 | int current_p, last_displayed_p; | |
5948 | { | |
5949 | if (current_p) | |
5950 | echo_area_buffer[0] = Qnil; | |
5951 | ||
5952 | if (last_displayed_p) | |
5953 | echo_area_buffer[1] = Qnil; | |
5954 | ||
5955 | message_buf_print = 0; | |
5956 | } | |
5957 | ||
5958 | /* Clear garbaged frames. | |
5959 | ||
5960 | This function is used where the old redisplay called | |
5961 | redraw_garbaged_frames which in turn called redraw_frame which in | |
5962 | turn called clear_frame. The call to clear_frame was a source of | |
5963 | flickering. I believe a clear_frame is not necessary. It should | |
5964 | suffice in the new redisplay to invalidate all current matrices, | |
5965 | and ensure a complete redisplay of all windows. */ | |
5966 | ||
5967 | static void | |
5968 | clear_garbaged_frames () | |
5969 | { | |
5f5c8ee5 GM |
5970 | if (frame_garbaged) |
5971 | { | |
5f5c8ee5 GM |
5972 | Lisp_Object tail, frame; |
5973 | ||
5974 | FOR_EACH_FRAME (tail, frame) | |
5975 | { | |
5976 | struct frame *f = XFRAME (frame); | |
5977 | ||
5978 | if (FRAME_VISIBLE_P (f) && FRAME_GARBAGED_P (f)) | |
5979 | { | |
5980 | clear_current_matrices (f); | |
5981 | f->garbaged = 0; | |
5982 | } | |
5983 | } | |
5984 | ||
5985 | frame_garbaged = 0; | |
5986 | ++windows_or_buffers_changed; | |
5987 | } | |
c6e89d6c | 5988 | } |
5f5c8ee5 | 5989 | |
5f5c8ee5 | 5990 | |
886bd6f2 GM |
5991 | /* Redisplay the echo area of the selected frame. If UPDATE_FRAME_P |
5992 | is non-zero update selected_frame. Value is non-zero if the | |
c6e89d6c | 5993 | mini-windows height has been changed. */ |
5f5c8ee5 | 5994 | |
c6e89d6c GM |
5995 | static int |
5996 | echo_area_display (update_frame_p) | |
5997 | int update_frame_p; | |
5998 | { | |
5999 | Lisp_Object mini_window; | |
6000 | struct window *w; | |
6001 | struct frame *f; | |
6002 | int window_height_changed_p = 0; | |
886bd6f2 | 6003 | struct frame *sf = SELECTED_FRAME (); |
c6e89d6c | 6004 | |
886bd6f2 | 6005 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
c6e89d6c GM |
6006 | w = XWINDOW (mini_window); |
6007 | f = XFRAME (WINDOW_FRAME (w)); | |
6008 | ||
6009 | /* Don't display if frame is invisible or not yet initialized. */ | |
6010 | if (!FRAME_VISIBLE_P (f) || !f->glyphs_initialized_p) | |
6011 | return 0; | |
5f5c8ee5 | 6012 | |
1ab3e082 | 6013 | #ifdef HAVE_WINDOW_SYSTEM |
c6e89d6c GM |
6014 | /* When Emacs starts, selected_frame may be a visible terminal |
6015 | frame, even if we run under a window system. If we let this | |
6016 | through, a message would be displayed on the terminal. */ | |
622e3754 GM |
6017 | if (EQ (selected_frame, Vterminal_frame) |
6018 | && !NILP (Vwindow_system)) | |
c6e89d6c | 6019 | return 0; |
1ab3e082 | 6020 | #endif /* HAVE_WINDOW_SYSTEM */ |
c6e89d6c GM |
6021 | |
6022 | /* Redraw garbaged frames. */ | |
6023 | if (frame_garbaged) | |
6024 | clear_garbaged_frames (); | |
6025 | ||
6026 | if (!NILP (echo_area_buffer[0]) || minibuf_level == 0) | |
6027 | { | |
6028 | echo_area_window = mini_window; | |
6029 | window_height_changed_p = display_echo_area (w); | |
5f5c8ee5 | 6030 | w->must_be_updated_p = 1; |
c59c668a | 6031 | |
5f5c8ee5 GM |
6032 | if (update_frame_p) |
6033 | { | |
c59c668a GM |
6034 | /* Not called from redisplay_internal. If we changed |
6035 | window configuration, we must redisplay thoroughly. | |
6036 | Otherwise, we can do with updating what we displayed | |
6037 | above. */ | |
6038 | if (window_height_changed_p) | |
6039 | { | |
6040 | ++windows_or_buffers_changed; | |
6041 | ++update_mode_lines; | |
6042 | redisplay_internal (0); | |
6043 | } | |
6044 | else if (FRAME_WINDOW_P (f)) | |
5f5c8ee5 GM |
6045 | { |
6046 | update_single_window (w, 1); | |
6047 | rif->flush_display (f); | |
6048 | } | |
6049 | else | |
6050 | update_frame (f, 1, 1); | |
6051 | } | |
6052 | } | |
6053 | else if (!EQ (mini_window, selected_window)) | |
6054 | windows_or_buffers_changed++; | |
c59c668a GM |
6055 | |
6056 | /* Last displayed message is now the current message. */ | |
dd2eb166 GM |
6057 | echo_area_buffer[1] = echo_area_buffer[0]; |
6058 | ||
5f5c8ee5 GM |
6059 | /* Prevent redisplay optimization in redisplay_internal by resetting |
6060 | this_line_start_pos. This is done because the mini-buffer now | |
6061 | displays the message instead of its buffer text. */ | |
6062 | if (EQ (mini_window, selected_window)) | |
6063 | CHARPOS (this_line_start_pos) = 0; | |
c6e89d6c GM |
6064 | |
6065 | return window_height_changed_p; | |
5f5c8ee5 GM |
6066 | } |
6067 | ||
6068 | ||
6069 | \f | |
6070 | /*********************************************************************** | |
6071 | Frame Titles | |
6072 | ***********************************************************************/ | |
6073 | ||
6074 | ||
6075 | #ifdef HAVE_WINDOW_SYSTEM | |
6076 | ||
6077 | /* A buffer for constructing frame titles in it; allocated from the | |
6078 | heap in init_xdisp and resized as needed in store_frame_title_char. */ | |
6079 | ||
6080 | static char *frame_title_buf; | |
6081 | ||
6082 | /* The buffer's end, and a current output position in it. */ | |
6083 | ||
6084 | static char *frame_title_buf_end; | |
6085 | static char *frame_title_ptr; | |
6086 | ||
6087 | ||
6088 | /* Store a single character C for the frame title in frame_title_buf. | |
6089 | Re-allocate frame_title_buf if necessary. */ | |
6090 | ||
6091 | static void | |
6092 | store_frame_title_char (c) | |
6093 | char c; | |
6094 | { | |
6095 | /* If output position has reached the end of the allocated buffer, | |
6096 | double the buffer's size. */ | |
6097 | if (frame_title_ptr == frame_title_buf_end) | |
6098 | { | |
6099 | int len = frame_title_ptr - frame_title_buf; | |
6100 | int new_size = 2 * len * sizeof *frame_title_buf; | |
6101 | frame_title_buf = (char *) xrealloc (frame_title_buf, new_size); | |
6102 | frame_title_buf_end = frame_title_buf + new_size; | |
6103 | frame_title_ptr = frame_title_buf + len; | |
6104 | } | |
6105 | ||
6106 | *frame_title_ptr++ = c; | |
6107 | } | |
6108 | ||
6109 | ||
6110 | /* Store part of a frame title in frame_title_buf, beginning at | |
6111 | frame_title_ptr. STR is the string to store. Do not copy more | |
6112 | than PRECISION number of bytes from STR; PRECISION <= 0 means copy | |
6113 | the whole string. Pad with spaces until FIELD_WIDTH number of | |
6114 | characters have been copied; FIELD_WIDTH <= 0 means don't pad. | |
6115 | Called from display_mode_element when it is used to build a frame | |
6116 | title. */ | |
6117 | ||
6118 | static int | |
6119 | store_frame_title (str, field_width, precision) | |
6120 | unsigned char *str; | |
6121 | int field_width, precision; | |
6122 | { | |
6123 | int n = 0; | |
6124 | ||
6125 | /* Copy at most PRECISION chars from STR. */ | |
6126 | while ((precision <= 0 || n < precision) | |
6127 | && *str) | |
6128 | { | |
6129 | store_frame_title_char (*str++); | |
6130 | ++n; | |
6131 | } | |
6132 | ||
6133 | /* Fill up with spaces until FIELD_WIDTH reached. */ | |
6134 | while (field_width > 0 | |
6135 | && n < field_width) | |
6136 | { | |
6137 | store_frame_title_char (' '); | |
6138 | ++n; | |
6139 | } | |
6140 | ||
6141 | return n; | |
6142 | } | |
6143 | ||
6144 | ||
6145 | /* Set the title of FRAME, if it has changed. The title format is | |
6146 | Vicon_title_format if FRAME is iconified, otherwise it is | |
6147 | frame_title_format. */ | |
6148 | ||
6149 | static void | |
6150 | x_consider_frame_title (frame) | |
6151 | Lisp_Object frame; | |
6152 | { | |
6153 | struct frame *f = XFRAME (frame); | |
6154 | ||
6155 | if (FRAME_WINDOW_P (f) | |
6156 | || FRAME_MINIBUF_ONLY_P (f) | |
6157 | || f->explicit_name) | |
6158 | { | |
6159 | /* Do we have more than one visible frame on this X display? */ | |
6160 | Lisp_Object tail; | |
6161 | Lisp_Object fmt; | |
6162 | struct buffer *obuf; | |
6163 | int len; | |
6164 | struct it it; | |
6165 | ||
9472f927 | 6166 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
5f5c8ee5 | 6167 | { |
9472f927 | 6168 | struct frame *tf = XFRAME (XCAR (tail)); |
5f5c8ee5 GM |
6169 | |
6170 | if (tf != f | |
6171 | && FRAME_KBOARD (tf) == FRAME_KBOARD (f) | |
6172 | && !FRAME_MINIBUF_ONLY_P (tf) | |
6173 | && (FRAME_VISIBLE_P (tf) || FRAME_ICONIFIED_P (tf))) | |
6174 | break; | |
6175 | } | |
6176 | ||
6177 | /* Set global variable indicating that multiple frames exist. */ | |
6178 | multiple_frames = CONSP (tail); | |
6179 | ||
6180 | /* Switch to the buffer of selected window of the frame. Set up | |
6181 | frame_title_ptr so that display_mode_element will output into it; | |
6182 | then display the title. */ | |
6183 | obuf = current_buffer; | |
6184 | Fset_buffer (XWINDOW (f->selected_window)->buffer); | |
6185 | fmt = FRAME_ICONIFIED_P (f) ? Vicon_title_format : Vframe_title_format; | |
6186 | frame_title_ptr = frame_title_buf; | |
6187 | init_iterator (&it, XWINDOW (f->selected_window), -1, -1, | |
6188 | NULL, DEFAULT_FACE_ID); | |
6189 | len = display_mode_element (&it, 0, -1, -1, fmt); | |
6190 | frame_title_ptr = NULL; | |
6191 | set_buffer_internal (obuf); | |
6192 | ||
6193 | /* Set the title only if it's changed. This avoids consing in | |
6194 | the common case where it hasn't. (If it turns out that we've | |
6195 | already wasted too much time by walking through the list with | |
6196 | display_mode_element, then we might need to optimize at a | |
6197 | higher level than this.) */ | |
6198 | if (! STRINGP (f->name) | |
6199 | || STRING_BYTES (XSTRING (f->name)) != len | |
6200 | || bcmp (frame_title_buf, XSTRING (f->name)->data, len) != 0) | |
6201 | x_implicitly_set_name (f, make_string (frame_title_buf, len), Qnil); | |
6202 | } | |
6203 | } | |
6204 | ||
6205 | #else /* not HAVE_WINDOW_SYSTEM */ | |
6206 | ||
6207 | #define frame_title_ptr ((char *)0) | |
6208 | #define store_frame_title(str, mincol, maxcol) 0 | |
6209 | ||
6210 | #endif /* not HAVE_WINDOW_SYSTEM */ | |
6211 | ||
6212 | ||
6213 | ||
6214 | \f | |
6215 | /*********************************************************************** | |
6216 | Menu Bars | |
6217 | ***********************************************************************/ | |
6218 | ||
6219 | ||
6220 | /* Prepare for redisplay by updating menu-bar item lists when | |
6221 | appropriate. This can call eval. */ | |
6222 | ||
6223 | void | |
6224 | prepare_menu_bars () | |
6225 | { | |
6226 | int all_windows; | |
6227 | struct gcpro gcpro1, gcpro2; | |
6228 | struct frame *f; | |
6229 | struct frame *tooltip_frame; | |
6230 | ||
6231 | #ifdef HAVE_X_WINDOWS | |
6232 | tooltip_frame = tip_frame; | |
6233 | #else | |
6234 | tooltip_frame = NULL; | |
6235 | #endif | |
6236 | ||
6237 | /* Update all frame titles based on their buffer names, etc. We do | |
6238 | this before the menu bars so that the buffer-menu will show the | |
6239 | up-to-date frame titles. */ | |
6240 | #ifdef HAVE_WINDOW_SYSTEM | |
6241 | if (windows_or_buffers_changed || update_mode_lines) | |
6242 | { | |
6243 | Lisp_Object tail, frame; | |
6244 | ||
6245 | FOR_EACH_FRAME (tail, frame) | |
6246 | { | |
6247 | f = XFRAME (frame); | |
6248 | if (f != tooltip_frame | |
6249 | && (FRAME_VISIBLE_P (f) || FRAME_ICONIFIED_P (f))) | |
6250 | x_consider_frame_title (frame); | |
6251 | } | |
6252 | } | |
6253 | #endif /* HAVE_WINDOW_SYSTEM */ | |
6254 | ||
6255 | /* Update the menu bar item lists, if appropriate. This has to be | |
6256 | done before any actual redisplay or generation of display lines. */ | |
6257 | all_windows = (update_mode_lines | |
6258 | || buffer_shared > 1 | |
6259 | || windows_or_buffers_changed); | |
6260 | if (all_windows) | |
6261 | { | |
6262 | Lisp_Object tail, frame; | |
6263 | int count = specpdl_ptr - specpdl; | |
6264 | ||
6265 | record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); | |
6266 | ||
6267 | FOR_EACH_FRAME (tail, frame) | |
6268 | { | |
6269 | f = XFRAME (frame); | |
6270 | ||
6271 | /* Ignore tooltip frame. */ | |
6272 | if (f == tooltip_frame) | |
6273 | continue; | |
6274 | ||
6275 | /* If a window on this frame changed size, report that to | |
6276 | the user and clear the size-change flag. */ | |
6277 | if (FRAME_WINDOW_SIZES_CHANGED (f)) | |
6278 | { | |
6279 | Lisp_Object functions; | |
6280 | ||
6281 | /* Clear flag first in case we get an error below. */ | |
6282 | FRAME_WINDOW_SIZES_CHANGED (f) = 0; | |
6283 | functions = Vwindow_size_change_functions; | |
6284 | GCPRO2 (tail, functions); | |
6285 | ||
6286 | while (CONSP (functions)) | |
6287 | { | |
6288 | call1 (XCAR (functions), frame); | |
6289 | functions = XCDR (functions); | |
6290 | } | |
6291 | UNGCPRO; | |
6292 | } | |
6293 | ||
6294 | GCPRO1 (tail); | |
6295 | update_menu_bar (f, 0); | |
6296 | #ifdef HAVE_WINDOW_SYSTEM | |
e037b9ec | 6297 | update_tool_bar (f, 0); |
5f5c8ee5 GM |
6298 | #endif |
6299 | UNGCPRO; | |
6300 | } | |
6301 | ||
6302 | unbind_to (count, Qnil); | |
6303 | } | |
6304 | else | |
6305 | { | |
886bd6f2 GM |
6306 | struct frame *sf = SELECTED_FRAME (); |
6307 | update_menu_bar (sf, 1); | |
5f5c8ee5 | 6308 | #ifdef HAVE_WINDOW_SYSTEM |
886bd6f2 | 6309 | update_tool_bar (sf, 1); |
5f5c8ee5 GM |
6310 | #endif |
6311 | } | |
6312 | ||
6313 | /* Motif needs this. See comment in xmenu.c. Turn it off when | |
6314 | pending_menu_activation is not defined. */ | |
6315 | #ifdef USE_X_TOOLKIT | |
6316 | pending_menu_activation = 0; | |
6317 | #endif | |
6318 | } | |
6319 | ||
6320 | ||
6321 | /* Update the menu bar item list for frame F. This has to be done | |
6322 | before we start to fill in any display lines, because it can call | |
6323 | eval. | |
6324 | ||
6325 | If SAVE_MATCH_DATA is non-zero, we must save and restore it here. */ | |
6326 | ||
6327 | static void | |
6328 | update_menu_bar (f, save_match_data) | |
6329 | struct frame *f; | |
6330 | int save_match_data; | |
6331 | { | |
6332 | Lisp_Object window; | |
6333 | register struct window *w; | |
6334 | ||
6335 | window = FRAME_SELECTED_WINDOW (f); | |
6336 | w = XWINDOW (window); | |
6337 | ||
6338 | if (update_mode_lines) | |
6339 | w->update_mode_line = Qt; | |
6340 | ||
6341 | if (FRAME_WINDOW_P (f) | |
6342 | ? | |
6343 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) | |
6344 | FRAME_EXTERNAL_MENU_BAR (f) | |
6345 | #else | |
6346 | FRAME_MENU_BAR_LINES (f) > 0 | |
6347 | #endif | |
6348 | : FRAME_MENU_BAR_LINES (f) > 0) | |
6349 | { | |
6350 | /* If the user has switched buffers or windows, we need to | |
6351 | recompute to reflect the new bindings. But we'll | |
6352 | recompute when update_mode_lines is set too; that means | |
6353 | that people can use force-mode-line-update to request | |
6354 | that the menu bar be recomputed. The adverse effect on | |
6355 | the rest of the redisplay algorithm is about the same as | |
6356 | windows_or_buffers_changed anyway. */ | |
6357 | if (windows_or_buffers_changed | |
6358 | || !NILP (w->update_mode_line) | |
6359 | || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer)) | |
6360 | < BUF_MODIFF (XBUFFER (w->buffer))) | |
6361 | != !NILP (w->last_had_star)) | |
6362 | || ((!NILP (Vtransient_mark_mode) | |
6363 | && !NILP (XBUFFER (w->buffer)->mark_active)) | |
6364 | != !NILP (w->region_showing))) | |
6365 | { | |
6366 | struct buffer *prev = current_buffer; | |
6367 | int count = specpdl_ptr - specpdl; | |
6368 | ||
6369 | set_buffer_internal_1 (XBUFFER (w->buffer)); | |
6370 | if (save_match_data) | |
6371 | record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); | |
6372 | if (NILP (Voverriding_local_map_menu_flag)) | |
6373 | { | |
6374 | specbind (Qoverriding_terminal_local_map, Qnil); | |
6375 | specbind (Qoverriding_local_map, Qnil); | |
6376 | } | |
6377 | ||
6378 | /* Run the Lucid hook. */ | |
6379 | call1 (Vrun_hooks, Qactivate_menubar_hook); | |
6380 | ||
6381 | /* If it has changed current-menubar from previous value, | |
6382 | really recompute the menu-bar from the value. */ | |
6383 | if (! NILP (Vlucid_menu_bar_dirty_flag)) | |
6384 | call0 (Qrecompute_lucid_menubar); | |
6385 | ||
6386 | safe_run_hooks (Qmenu_bar_update_hook); | |
6387 | FRAME_MENU_BAR_ITEMS (f) = menu_bar_items (FRAME_MENU_BAR_ITEMS (f)); | |
6388 | ||
6389 | /* Redisplay the menu bar in case we changed it. */ | |
6390 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) | |
6391 | if (FRAME_WINDOW_P (f)) | |
6392 | set_frame_menubar (f, 0, 0); | |
6393 | else | |
6394 | /* On a terminal screen, the menu bar is an ordinary screen | |
6395 | line, and this makes it get updated. */ | |
6396 | w->update_mode_line = Qt; | |
6397 | #else /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */ | |
6398 | /* In the non-toolkit version, the menu bar is an ordinary screen | |
6399 | line, and this makes it get updated. */ | |
6400 | w->update_mode_line = Qt; | |
6401 | #endif /* ! (USE_X_TOOLKIT || HAVE_NTGUI) */ | |
6402 | ||
6403 | unbind_to (count, Qnil); | |
6404 | set_buffer_internal_1 (prev); | |
6405 | } | |
6406 | } | |
6407 | } | |
6408 | ||
6409 | ||
6410 | \f | |
6411 | /*********************************************************************** | |
e037b9ec | 6412 | Tool-bars |
5f5c8ee5 GM |
6413 | ***********************************************************************/ |
6414 | ||
6415 | #ifdef HAVE_WINDOW_SYSTEM | |
6416 | ||
e037b9ec | 6417 | /* Update the tool-bar item list for frame F. This has to be done |
5f5c8ee5 GM |
6418 | before we start to fill in any display lines. Called from |
6419 | prepare_menu_bars. If SAVE_MATCH_DATA is non-zero, we must save | |
6420 | and restore it here. */ | |
6421 | ||
6422 | static void | |
e037b9ec | 6423 | update_tool_bar (f, save_match_data) |
5f5c8ee5 GM |
6424 | struct frame *f; |
6425 | int save_match_data; | |
6426 | { | |
e037b9ec GM |
6427 | if (WINDOWP (f->tool_bar_window) |
6428 | && XFASTINT (XWINDOW (f->tool_bar_window)->height) > 0) | |
5f5c8ee5 GM |
6429 | { |
6430 | Lisp_Object window; | |
6431 | struct window *w; | |
6432 | ||
6433 | window = FRAME_SELECTED_WINDOW (f); | |
6434 | w = XWINDOW (window); | |
6435 | ||
6436 | /* If the user has switched buffers or windows, we need to | |
6437 | recompute to reflect the new bindings. But we'll | |
6438 | recompute when update_mode_lines is set too; that means | |
6439 | that people can use force-mode-line-update to request | |
6440 | that the menu bar be recomputed. The adverse effect on | |
6441 | the rest of the redisplay algorithm is about the same as | |
6442 | windows_or_buffers_changed anyway. */ | |
6443 | if (windows_or_buffers_changed | |
6444 | || !NILP (w->update_mode_line) | |
6445 | || ((BUF_SAVE_MODIFF (XBUFFER (w->buffer)) | |
6446 | < BUF_MODIFF (XBUFFER (w->buffer))) | |
6447 | != !NILP (w->last_had_star)) | |
6448 | || ((!NILP (Vtransient_mark_mode) | |
6449 | && !NILP (XBUFFER (w->buffer)->mark_active)) | |
6450 | != !NILP (w->region_showing))) | |
6451 | { | |
6452 | struct buffer *prev = current_buffer; | |
6453 | int count = specpdl_ptr - specpdl; | |
a2889657 | 6454 | |
5f5c8ee5 GM |
6455 | /* Set current_buffer to the buffer of the selected |
6456 | window of the frame, so that we get the right local | |
6457 | keymaps. */ | |
6458 | set_buffer_internal_1 (XBUFFER (w->buffer)); | |
1f40cad2 | 6459 | |
5f5c8ee5 GM |
6460 | /* Save match data, if we must. */ |
6461 | if (save_match_data) | |
6462 | record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); | |
6463 | ||
6464 | /* Make sure that we don't accidentally use bogus keymaps. */ | |
6465 | if (NILP (Voverriding_local_map_menu_flag)) | |
6466 | { | |
6467 | specbind (Qoverriding_terminal_local_map, Qnil); | |
6468 | specbind (Qoverriding_local_map, Qnil); | |
1f40cad2 | 6469 | } |
1f40cad2 | 6470 | |
e037b9ec GM |
6471 | /* Build desired tool-bar items from keymaps. */ |
6472 | f->desired_tool_bar_items | |
6473 | = tool_bar_items (f->desired_tool_bar_items, | |
6474 | &f->n_desired_tool_bar_items); | |
5f5c8ee5 | 6475 | |
e037b9ec | 6476 | /* Redisplay the tool-bar in case we changed it. */ |
5f5c8ee5 GM |
6477 | w->update_mode_line = Qt; |
6478 | ||
6479 | unbind_to (count, Qnil); | |
6480 | set_buffer_internal_1 (prev); | |
81d478f3 | 6481 | } |
a2889657 JB |
6482 | } |
6483 | } | |
6484 | ||
6c4429a5 | 6485 | |
e037b9ec GM |
6486 | /* Set F->desired_tool_bar_string to a Lisp string representing frame |
6487 | F's desired tool-bar contents. F->desired_tool_bar_items must have | |
5f5c8ee5 GM |
6488 | been set up previously by calling prepare_menu_bars. */ |
6489 | ||
a2889657 | 6490 | static void |
e037b9ec | 6491 | build_desired_tool_bar_string (f) |
5f5c8ee5 | 6492 | struct frame *f; |
a2889657 | 6493 | { |
5f5c8ee5 GM |
6494 | int i, size, size_needed, string_idx; |
6495 | struct gcpro gcpro1, gcpro2, gcpro3; | |
6496 | Lisp_Object image, plist, props; | |
a2889657 | 6497 | |
5f5c8ee5 GM |
6498 | image = plist = props = Qnil; |
6499 | GCPRO3 (image, plist, props); | |
a2889657 | 6500 | |
e037b9ec | 6501 | /* Prepare F->desired_tool_bar_string. If we can reuse it, do so. |
5f5c8ee5 GM |
6502 | Otherwise, make a new string. */ |
6503 | ||
6504 | /* The size of the string we might be able to reuse. */ | |
e037b9ec GM |
6505 | size = (STRINGP (f->desired_tool_bar_string) |
6506 | ? XSTRING (f->desired_tool_bar_string)->size | |
5f5c8ee5 GM |
6507 | : 0); |
6508 | ||
6509 | /* Each image in the string we build is preceded by a space, | |
6510 | and there is a space at the end. */ | |
e037b9ec | 6511 | size_needed = f->n_desired_tool_bar_items + 1; |
5f5c8ee5 | 6512 | |
e037b9ec | 6513 | /* Reuse f->desired_tool_bar_string, if possible. */ |
5f5c8ee5 | 6514 | if (size < size_needed) |
6fc556fd KR |
6515 | f->desired_tool_bar_string = Fmake_string (make_number (size_needed), |
6516 | make_number (' ')); | |
5f5c8ee5 GM |
6517 | else |
6518 | { | |
6519 | props = list4 (Qdisplay, Qnil, Qmenu_item, Qnil); | |
6520 | Fremove_text_properties (make_number (0), make_number (size), | |
e037b9ec | 6521 | props, f->desired_tool_bar_string); |
5f5c8ee5 | 6522 | } |
a2889657 | 6523 | |
5f5c8ee5 | 6524 | /* Put a `display' property on the string for the images to display, |
e037b9ec GM |
6525 | put a `menu_item' property on tool-bar items with a value that |
6526 | is the index of the item in F's tool-bar item vector. */ | |
5f5c8ee5 | 6527 | for (i = 0, string_idx = 0; |
e037b9ec | 6528 | i < f->n_desired_tool_bar_items; |
5f5c8ee5 | 6529 | ++i, string_idx += 1) |
a2889657 | 6530 | { |
5f5c8ee5 | 6531 | #define PROP(IDX) \ |
e037b9ec GM |
6532 | (XVECTOR (f->desired_tool_bar_items) \ |
6533 | ->contents[i * TOOL_BAR_ITEM_NSLOTS + (IDX)]) | |
5f5c8ee5 | 6534 | |
e037b9ec GM |
6535 | int enabled_p = !NILP (PROP (TOOL_BAR_ITEM_ENABLED_P)); |
6536 | int selected_p = !NILP (PROP (TOOL_BAR_ITEM_SELECTED_P)); | |
5f5c8ee5 GM |
6537 | int margin, relief; |
6538 | extern Lisp_Object QCrelief, QCmargin, QCalgorithm, Qimage; | |
6539 | extern Lisp_Object Qlaplace; | |
6540 | ||
6541 | /* If image is a vector, choose the image according to the | |
6542 | button state. */ | |
e037b9ec | 6543 | image = PROP (TOOL_BAR_ITEM_IMAGES); |
5f5c8ee5 GM |
6544 | if (VECTORP (image)) |
6545 | { | |
e037b9ec | 6546 | enum tool_bar_item_image idx; |
5f5c8ee5 GM |
6547 | |
6548 | if (enabled_p) | |
6549 | idx = (selected_p | |
e037b9ec GM |
6550 | ? TOOL_BAR_IMAGE_ENABLED_SELECTED |
6551 | : TOOL_BAR_IMAGE_ENABLED_DESELECTED); | |
5f5c8ee5 GM |
6552 | else |
6553 | idx = (selected_p | |
e037b9ec GM |
6554 | ? TOOL_BAR_IMAGE_DISABLED_SELECTED |
6555 | : TOOL_BAR_IMAGE_DISABLED_DESELECTED); | |
5f5c8ee5 GM |
6556 | |
6557 | xassert (XVECTOR (image)->size >= idx); | |
6558 | image = XVECTOR (image)->contents[idx]; | |
6559 | } | |
6560 | ||
6561 | /* Ignore invalid image specifications. */ | |
6562 | if (!valid_image_p (image)) | |
6563 | continue; | |
6564 | ||
e037b9ec | 6565 | /* Display the tool-bar button pressed, or depressed. */ |
5f5c8ee5 GM |
6566 | plist = Fcopy_sequence (XCDR (image)); |
6567 | ||
6568 | /* Compute margin and relief to draw. */ | |
e037b9ec GM |
6569 | relief = tool_bar_button_relief > 0 ? tool_bar_button_relief : 3; |
6570 | margin = relief + max (0, tool_bar_button_margin); | |
5f5c8ee5 | 6571 | |
e037b9ec | 6572 | if (auto_raise_tool_bar_buttons_p) |
5f5c8ee5 GM |
6573 | { |
6574 | /* Add a `:relief' property to the image spec if the item is | |
6575 | selected. */ | |
6576 | if (selected_p) | |
6577 | { | |
6578 | plist = Fplist_put (plist, QCrelief, make_number (-relief)); | |
6579 | margin -= relief; | |
6580 | } | |
6581 | } | |
6582 | else | |
6583 | { | |
6584 | /* If image is selected, display it pressed, i.e. with a | |
6585 | negative relief. If it's not selected, display it with a | |
6586 | raised relief. */ | |
6587 | plist = Fplist_put (plist, QCrelief, | |
6588 | (selected_p | |
6589 | ? make_number (-relief) | |
6590 | : make_number (relief))); | |
6591 | margin -= relief; | |
6592 | } | |
6593 | ||
6594 | /* Put a margin around the image. */ | |
6595 | if (margin) | |
6596 | plist = Fplist_put (plist, QCmargin, make_number (margin)); | |
6597 | ||
6598 | /* If button is not enabled, make the image appear disabled by | |
6599 | applying an appropriate algorithm to it. */ | |
6600 | if (!enabled_p) | |
6601 | plist = Fplist_put (plist, QCalgorithm, Qlaplace); | |
6602 | ||
6603 | /* Put a `display' text property on the string for the image to | |
6604 | display. Put a `menu-item' property on the string that gives | |
e037b9ec | 6605 | the start of this item's properties in the tool-bar items |
5f5c8ee5 GM |
6606 | vector. */ |
6607 | image = Fcons (Qimage, plist); | |
6608 | props = list4 (Qdisplay, image, | |
e037b9ec | 6609 | Qmenu_item, make_number (i * TOOL_BAR_ITEM_NSLOTS)), |
5f5c8ee5 GM |
6610 | Fadd_text_properties (make_number (string_idx), |
6611 | make_number (string_idx + 1), | |
e037b9ec | 6612 | props, f->desired_tool_bar_string); |
5f5c8ee5 | 6613 | #undef PROP |
a2889657 JB |
6614 | } |
6615 | ||
5f5c8ee5 GM |
6616 | UNGCPRO; |
6617 | } | |
6618 | ||
6619 | ||
e037b9ec | 6620 | /* Display one line of the tool-bar of frame IT->f. */ |
5f5c8ee5 GM |
6621 | |
6622 | static void | |
e037b9ec | 6623 | display_tool_bar_line (it) |
5f5c8ee5 GM |
6624 | struct it *it; |
6625 | { | |
6626 | struct glyph_row *row = it->glyph_row; | |
6627 | int max_x = it->last_visible_x; | |
6628 | struct glyph *last; | |
6629 | ||
6630 | prepare_desired_row (row); | |
6631 | row->y = it->current_y; | |
6632 | ||
6633 | while (it->current_x < max_x) | |
a2889657 | 6634 | { |
5f5c8ee5 | 6635 | int x_before, x, n_glyphs_before, i, nglyphs; |
a2f016e3 | 6636 | |
5f5c8ee5 GM |
6637 | /* Get the next display element. */ |
6638 | if (!get_next_display_element (it)) | |
6639 | break; | |
73af359d | 6640 | |
5f5c8ee5 GM |
6641 | /* Produce glyphs. */ |
6642 | x_before = it->current_x; | |
6643 | n_glyphs_before = it->glyph_row->used[TEXT_AREA]; | |
6644 | PRODUCE_GLYPHS (it); | |
daa37602 | 6645 | |
5f5c8ee5 GM |
6646 | nglyphs = it->glyph_row->used[TEXT_AREA] - n_glyphs_before; |
6647 | i = 0; | |
6648 | x = x_before; | |
6649 | while (i < nglyphs) | |
6650 | { | |
6651 | struct glyph *glyph = row->glyphs[TEXT_AREA] + n_glyphs_before + i; | |
6652 | ||
6653 | if (x + glyph->pixel_width > max_x) | |
6654 | { | |
6655 | /* Glyph doesn't fit on line. */ | |
6656 | it->glyph_row->used[TEXT_AREA] = n_glyphs_before + i; | |
6657 | it->current_x = x; | |
6658 | goto out; | |
6659 | } | |
daa37602 | 6660 | |
5f5c8ee5 GM |
6661 | ++it->hpos; |
6662 | x += glyph->pixel_width; | |
6663 | ++i; | |
6664 | } | |
6665 | ||
6666 | /* Stop at line ends. */ | |
6667 | if (ITERATOR_AT_END_OF_LINE_P (it)) | |
6668 | break; | |
6669 | ||
6670 | set_iterator_to_next (it); | |
a2889657 | 6671 | } |
a2889657 | 6672 | |
5f5c8ee5 | 6673 | out:; |
a2889657 | 6674 | |
5f5c8ee5 GM |
6675 | row->displays_text_p = row->used[TEXT_AREA] != 0; |
6676 | extend_face_to_end_of_line (it); | |
6677 | last = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA] - 1; | |
6678 | last->right_box_line_p = 1; | |
6679 | compute_line_metrics (it); | |
6680 | ||
e037b9ec | 6681 | /* If line is empty, make it occupy the rest of the tool-bar. */ |
5f5c8ee5 GM |
6682 | if (!row->displays_text_p) |
6683 | { | |
312246d1 GM |
6684 | row->height = row->phys_height = it->last_visible_y - row->y; |
6685 | row->ascent = row->phys_ascent = 0; | |
5f5c8ee5 GM |
6686 | } |
6687 | ||
6688 | row->full_width_p = 1; | |
6689 | row->continued_p = 0; | |
6690 | row->truncated_on_left_p = 0; | |
6691 | row->truncated_on_right_p = 0; | |
6692 | ||
6693 | it->current_x = it->hpos = 0; | |
6694 | it->current_y += row->height; | |
6695 | ++it->vpos; | |
6696 | ++it->glyph_row; | |
a2889657 | 6697 | } |
96a410bc | 6698 | |
5f5c8ee5 | 6699 | |
e037b9ec | 6700 | /* Value is the number of screen lines needed to make all tool-bar |
5f5c8ee5 | 6701 | items of frame F visible. */ |
96a410bc | 6702 | |
d39b6696 | 6703 | static int |
e037b9ec | 6704 | tool_bar_lines_needed (f) |
5f5c8ee5 | 6705 | struct frame *f; |
d39b6696 | 6706 | { |
e037b9ec | 6707 | struct window *w = XWINDOW (f->tool_bar_window); |
5f5c8ee5 GM |
6708 | struct it it; |
6709 | ||
e037b9ec GM |
6710 | /* Initialize an iterator for iteration over |
6711 | F->desired_tool_bar_string in the tool-bar window of frame F. */ | |
6712 | init_iterator (&it, w, -1, -1, w->desired_matrix->rows, TOOL_BAR_FACE_ID); | |
5f5c8ee5 GM |
6713 | it.first_visible_x = 0; |
6714 | it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f); | |
e037b9ec | 6715 | reseat_to_string (&it, NULL, f->desired_tool_bar_string, 0, 0, 0, -1); |
5f5c8ee5 GM |
6716 | |
6717 | while (!ITERATOR_AT_END_P (&it)) | |
6718 | { | |
6719 | it.glyph_row = w->desired_matrix->rows; | |
6720 | clear_glyph_row (it.glyph_row); | |
e037b9ec | 6721 | display_tool_bar_line (&it); |
5f5c8ee5 GM |
6722 | } |
6723 | ||
6724 | return (it.current_y + CANON_Y_UNIT (f) - 1) / CANON_Y_UNIT (f); | |
d39b6696 | 6725 | } |
96a410bc | 6726 | |
5f5c8ee5 | 6727 | |
e037b9ec | 6728 | /* Display the tool-bar of frame F. Value is non-zero if tool-bar's |
5f5c8ee5 GM |
6729 | height should be changed. */ |
6730 | ||
6731 | static int | |
e037b9ec | 6732 | redisplay_tool_bar (f) |
5f5c8ee5 | 6733 | struct frame *f; |
96a410bc | 6734 | { |
5f5c8ee5 GM |
6735 | struct window *w; |
6736 | struct it it; | |
6737 | struct glyph_row *row; | |
6738 | int change_height_p = 0; | |
6739 | ||
e037b9ec GM |
6740 | /* If frame hasn't a tool-bar window or if it is zero-height, don't |
6741 | do anything. This means you must start with tool-bar-lines | |
5f5c8ee5 | 6742 | non-zero to get the auto-sizing effect. Or in other words, you |
e037b9ec GM |
6743 | can turn off tool-bars by specifying tool-bar-lines zero. */ |
6744 | if (!WINDOWP (f->tool_bar_window) | |
6745 | || (w = XWINDOW (f->tool_bar_window), | |
5f5c8ee5 GM |
6746 | XFASTINT (w->height) == 0)) |
6747 | return 0; | |
96a410bc | 6748 | |
e037b9ec GM |
6749 | /* Set up an iterator for the tool-bar window. */ |
6750 | init_iterator (&it, w, -1, -1, w->desired_matrix->rows, TOOL_BAR_FACE_ID); | |
5f5c8ee5 GM |
6751 | it.first_visible_x = 0; |
6752 | it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f); | |
6753 | row = it.glyph_row; | |
3450d04c | 6754 | |
e037b9ec GM |
6755 | /* Build a string that represents the contents of the tool-bar. */ |
6756 | build_desired_tool_bar_string (f); | |
6757 | reseat_to_string (&it, NULL, f->desired_tool_bar_string, 0, 0, 0, -1); | |
3450d04c | 6758 | |
e037b9ec | 6759 | /* Display as many lines as needed to display all tool-bar items. */ |
5f5c8ee5 | 6760 | while (it.current_y < it.last_visible_y) |
e037b9ec | 6761 | display_tool_bar_line (&it); |
3450d04c | 6762 | |
e037b9ec | 6763 | /* It doesn't make much sense to try scrolling in the tool-bar |
5f5c8ee5 GM |
6764 | window, so don't do it. */ |
6765 | w->desired_matrix->no_scrolling_p = 1; | |
6766 | w->must_be_updated_p = 1; | |
3450d04c | 6767 | |
e037b9ec | 6768 | if (auto_resize_tool_bars_p) |
5f5c8ee5 GM |
6769 | { |
6770 | int nlines; | |
6771 | ||
6772 | /* If there are blank lines at the end, except for a partially | |
6773 | visible blank line at the end that is smaller than | |
e037b9ec | 6774 | CANON_Y_UNIT, change the tool-bar's height. */ |
5f5c8ee5 GM |
6775 | row = it.glyph_row - 1; |
6776 | if (!row->displays_text_p | |
6777 | && row->height >= CANON_Y_UNIT (f)) | |
6778 | change_height_p = 1; | |
6779 | ||
e037b9ec GM |
6780 | /* If row displays tool-bar items, but is partially visible, |
6781 | change the tool-bar's height. */ | |
5f5c8ee5 GM |
6782 | if (row->displays_text_p |
6783 | && MATRIX_ROW_BOTTOM_Y (row) > it.last_visible_y) | |
6784 | change_height_p = 1; | |
6785 | ||
e037b9ec | 6786 | /* Resize windows as needed by changing the `tool-bar-lines' |
5f5c8ee5 GM |
6787 | frame parameter. */ |
6788 | if (change_height_p | |
e037b9ec | 6789 | && (nlines = tool_bar_lines_needed (f), |
5f5c8ee5 GM |
6790 | nlines != XFASTINT (w->height))) |
6791 | { | |
e037b9ec | 6792 | extern Lisp_Object Qtool_bar_lines; |
5f5c8ee5 GM |
6793 | Lisp_Object frame; |
6794 | ||
6795 | XSETFRAME (frame, f); | |
6796 | clear_glyph_matrix (w->desired_matrix); | |
6797 | Fmodify_frame_parameters (frame, | |
e037b9ec | 6798 | Fcons (Fcons (Qtool_bar_lines, |
5f5c8ee5 GM |
6799 | make_number (nlines)), |
6800 | Qnil)); | |
6801 | fonts_changed_p = 1; | |
6802 | } | |
6803 | } | |
3450d04c | 6804 | |
5f5c8ee5 | 6805 | return change_height_p; |
96a410bc | 6806 | } |
90adcf20 | 6807 | |
5f5c8ee5 | 6808 | |
e037b9ec GM |
6809 | /* Get information about the tool-bar item which is displayed in GLYPH |
6810 | on frame F. Return in *PROP_IDX the index where tool-bar item | |
6811 | properties start in F->current_tool_bar_items. Value is zero if | |
6812 | GLYPH doesn't display a tool-bar item. */ | |
5f5c8ee5 GM |
6813 | |
6814 | int | |
e037b9ec | 6815 | tool_bar_item_info (f, glyph, prop_idx) |
5f5c8ee5 GM |
6816 | struct frame *f; |
6817 | struct glyph *glyph; | |
6818 | int *prop_idx; | |
90adcf20 | 6819 | { |
5f5c8ee5 GM |
6820 | Lisp_Object prop; |
6821 | int success_p; | |
6822 | ||
6823 | /* Get the text property `menu-item' at pos. The value of that | |
6824 | property is the start index of this item's properties in | |
e037b9ec | 6825 | F->current_tool_bar_items. */ |
5f5c8ee5 | 6826 | prop = Fget_text_property (make_number (glyph->charpos), |
e037b9ec | 6827 | Qmenu_item, f->current_tool_bar_string); |
5f5c8ee5 GM |
6828 | if (INTEGERP (prop)) |
6829 | { | |
6830 | *prop_idx = XINT (prop); | |
6831 | success_p = 1; | |
6832 | } | |
6833 | else | |
6834 | success_p = 0; | |
90adcf20 | 6835 | |
5f5c8ee5 GM |
6836 | return success_p; |
6837 | } | |
6838 | ||
6839 | #endif /* HAVE_WINDOW_SYSTEM */ | |
90adcf20 | 6840 | |
feb0c42f | 6841 | |
5f5c8ee5 GM |
6842 | \f |
6843 | /************************************************************************ | |
6844 | Horizontal scrolling | |
6845 | ************************************************************************/ | |
feb0c42f | 6846 | |
5f5c8ee5 GM |
6847 | static int hscroll_window_tree P_ ((Lisp_Object)); |
6848 | static int hscroll_windows P_ ((Lisp_Object)); | |
feb0c42f | 6849 | |
5f5c8ee5 GM |
6850 | /* For all leaf windows in the window tree rooted at WINDOW, set their |
6851 | hscroll value so that PT is (i) visible in the window, and (ii) so | |
6852 | that it is not within a certain margin at the window's left and | |
6853 | right border. Value is non-zero if any window's hscroll has been | |
6854 | changed. */ | |
6855 | ||
6856 | static int | |
6857 | hscroll_window_tree (window) | |
6858 | Lisp_Object window; | |
6859 | { | |
6860 | int hscrolled_p = 0; | |
6861 | ||
6862 | while (WINDOWP (window)) | |
90adcf20 | 6863 | { |
5f5c8ee5 GM |
6864 | struct window *w = XWINDOW (window); |
6865 | ||
6866 | if (WINDOWP (w->hchild)) | |
6867 | hscrolled_p |= hscroll_window_tree (w->hchild); | |
6868 | else if (WINDOWP (w->vchild)) | |
6869 | hscrolled_p |= hscroll_window_tree (w->vchild); | |
6870 | else if (w->cursor.vpos >= 0) | |
6871 | { | |
6872 | int hscroll_margin, text_area_x, text_area_y; | |
6873 | int text_area_width, text_area_height; | |
92a90e89 GM |
6874 | struct glyph_row *current_cursor_row |
6875 | = MATRIX_ROW (w->current_matrix, w->cursor.vpos); | |
6876 | struct glyph_row *desired_cursor_row | |
6877 | = MATRIX_ROW (w->desired_matrix, w->cursor.vpos); | |
6878 | struct glyph_row *cursor_row | |
6879 | = (desired_cursor_row->enabled_p | |
6880 | ? desired_cursor_row | |
6881 | : current_cursor_row); | |
a2725ab2 | 6882 | |
5f5c8ee5 GM |
6883 | window_box (w, TEXT_AREA, &text_area_x, &text_area_y, |
6884 | &text_area_width, &text_area_height); | |
90adcf20 | 6885 | |
5f5c8ee5 GM |
6886 | /* Scroll when cursor is inside this scroll margin. */ |
6887 | hscroll_margin = 5 * CANON_X_UNIT (XFRAME (w->frame)); | |
6888 | ||
6889 | if ((XFASTINT (w->hscroll) | |
6890 | && w->cursor.x < hscroll_margin) | |
92a90e89 GM |
6891 | || (cursor_row->enabled_p |
6892 | && cursor_row->truncated_on_right_p | |
5f5c8ee5 | 6893 | && (w->cursor.x > text_area_width - hscroll_margin))) |
08b610e4 | 6894 | { |
5f5c8ee5 GM |
6895 | struct it it; |
6896 | int hscroll; | |
6897 | struct buffer *saved_current_buffer; | |
6898 | int pt; | |
6899 | ||
6900 | /* Find point in a display of infinite width. */ | |
6901 | saved_current_buffer = current_buffer; | |
6902 | current_buffer = XBUFFER (w->buffer); | |
6903 | ||
6904 | if (w == XWINDOW (selected_window)) | |
6905 | pt = BUF_PT (current_buffer); | |
6906 | else | |
08b610e4 | 6907 | { |
5f5c8ee5 GM |
6908 | pt = marker_position (w->pointm); |
6909 | pt = max (BEGV, pt); | |
6910 | pt = min (ZV, pt); | |
6911 | } | |
6912 | ||
6913 | /* Move iterator to pt starting at cursor_row->start in | |
6914 | a line with infinite width. */ | |
6915 | init_to_row_start (&it, w, cursor_row); | |
6916 | it.last_visible_x = INFINITY; | |
6917 | move_it_in_display_line_to (&it, pt, -1, MOVE_TO_POS); | |
6918 | current_buffer = saved_current_buffer; | |
6919 | ||
6920 | /* Center cursor in window. */ | |
6921 | hscroll = (max (0, it.current_x - text_area_width / 2) | |
6922 | / CANON_X_UNIT (it.f)); | |
6923 | ||
6924 | /* Don't call Fset_window_hscroll if value hasn't | |
6925 | changed because it will prevent redisplay | |
6926 | optimizations. */ | |
6927 | if (XFASTINT (w->hscroll) != hscroll) | |
6928 | { | |
6929 | Fset_window_hscroll (window, make_number (hscroll)); | |
6930 | hscrolled_p = 1; | |
08b610e4 | 6931 | } |
08b610e4 | 6932 | } |
08b610e4 | 6933 | } |
a2725ab2 | 6934 | |
5f5c8ee5 | 6935 | window = w->next; |
90adcf20 | 6936 | } |
cd6dfed6 | 6937 | |
5f5c8ee5 GM |
6938 | /* Value is non-zero if hscroll of any leaf window has been changed. */ |
6939 | return hscrolled_p; | |
6940 | } | |
6941 | ||
6942 | ||
6943 | /* Set hscroll so that cursor is visible and not inside horizontal | |
6944 | scroll margins for all windows in the tree rooted at WINDOW. See | |
6945 | also hscroll_window_tree above. Value is non-zero if any window's | |
6946 | hscroll has been changed. If it has, desired matrices on the frame | |
6947 | of WINDOW are cleared. */ | |
6948 | ||
6949 | static int | |
6950 | hscroll_windows (window) | |
6951 | Lisp_Object window; | |
6952 | { | |
d475bcb8 GM |
6953 | int hscrolled_p; |
6954 | ||
6955 | if (automatic_hscrolling_p) | |
6956 | { | |
6957 | hscrolled_p = hscroll_window_tree (window); | |
6958 | if (hscrolled_p) | |
6959 | clear_desired_matrices (XFRAME (WINDOW_FRAME (XWINDOW (window)))); | |
6960 | } | |
6961 | else | |
6962 | hscrolled_p = 0; | |
5f5c8ee5 | 6963 | return hscrolled_p; |
90adcf20 | 6964 | } |
5f5c8ee5 GM |
6965 | |
6966 | ||
90adcf20 | 6967 | \f |
5f5c8ee5 GM |
6968 | /************************************************************************ |
6969 | Redisplay | |
6970 | ************************************************************************/ | |
6971 | ||
6972 | /* Variables holding some state of redisplay if GLYPH_DEBUG is defined | |
6973 | to a non-zero value. This is sometimes handy to have in a debugger | |
6974 | session. */ | |
6975 | ||
6976 | #if GLYPH_DEBUG | |
a2889657 | 6977 | |
5f5c8ee5 GM |
6978 | /* First and last unchanged row for try_window_id. */ |
6979 | ||
6980 | int debug_first_unchanged_at_end_vpos; | |
6981 | int debug_last_unchanged_at_beg_vpos; | |
6982 | ||
6983 | /* Delta vpos and y. */ | |
6984 | ||
6985 | int debug_dvpos, debug_dy; | |
6986 | ||
6987 | /* Delta in characters and bytes for try_window_id. */ | |
6988 | ||
6989 | int debug_delta, debug_delta_bytes; | |
6990 | ||
6991 | /* Values of window_end_pos and window_end_vpos at the end of | |
6992 | try_window_id. */ | |
6993 | ||
6994 | int debug_end_pos, debug_end_vpos; | |
6995 | ||
6996 | /* Append a string to W->desired_matrix->method. FMT is a printf | |
6997 | format string. A1...A9 are a supplement for a variable-length | |
6998 | argument list. If trace_redisplay_p is non-zero also printf the | |
6999 | resulting string to stderr. */ | |
7000 | ||
7001 | static void | |
7002 | debug_method_add (w, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9) | |
7003 | struct window *w; | |
7004 | char *fmt; | |
7005 | int a1, a2, a3, a4, a5, a6, a7, a8, a9; | |
7006 | { | |
7007 | char buffer[512]; | |
7008 | char *method = w->desired_matrix->method; | |
7009 | int len = strlen (method); | |
7010 | int size = sizeof w->desired_matrix->method; | |
7011 | int remaining = size - len - 1; | |
7012 | ||
7013 | sprintf (buffer, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9); | |
7014 | if (len && remaining) | |
7015 | { | |
7016 | method[len] = '|'; | |
7017 | --remaining, ++len; | |
7018 | } | |
7019 | ||
7020 | strncpy (method + len, buffer, remaining); | |
7021 | ||
7022 | if (trace_redisplay_p) | |
7023 | fprintf (stderr, "%p (%s): %s\n", | |
7024 | w, | |
7025 | ((BUFFERP (w->buffer) | |
7026 | && STRINGP (XBUFFER (w->buffer)->name)) | |
7027 | ? (char *) XSTRING (XBUFFER (w->buffer)->name)->data | |
7028 | : "no buffer"), | |
7029 | buffer); | |
7030 | } | |
a2889657 | 7031 | |
5f5c8ee5 | 7032 | #endif /* GLYPH_DEBUG */ |
90adcf20 | 7033 | |
a2889657 | 7034 | |
5f5c8ee5 GM |
7035 | /* This counter is used to clear the face cache every once in a while |
7036 | in redisplay_internal. It is incremented for each redisplay. | |
7037 | Every CLEAR_FACE_CACHE_COUNT full redisplays, the face cache is | |
7038 | cleared. */ | |
0d231165 | 7039 | |
5f5c8ee5 | 7040 | #define CLEAR_FACE_CACHE_COUNT 10000 |
463f6b91 RS |
7041 | static int clear_face_cache_count; |
7042 | ||
20de20dc | 7043 | /* Record the previous terminal frame we displayed. */ |
5f5c8ee5 GM |
7044 | |
7045 | static struct frame *previous_terminal_frame; | |
7046 | ||
7047 | /* Non-zero while redisplay_internal is in progress. */ | |
7048 | ||
7049 | int redisplaying_p; | |
7050 | ||
7051 | ||
7052 | /* Value is non-zero if all changes in window W, which displays | |
7053 | current_buffer, are in the text between START and END. START is a | |
7054 | buffer position, END is given as a distance from Z. Used in | |
7055 | redisplay_internal for display optimization. */ | |
7056 | ||
7057 | static INLINE int | |
7058 | text_outside_line_unchanged_p (w, start, end) | |
7059 | struct window *w; | |
7060 | int start, end; | |
7061 | { | |
7062 | int unchanged_p = 1; | |
7063 | ||
7064 | /* If text or overlays have changed, see where. */ | |
7065 | if (XFASTINT (w->last_modified) < MODIFF | |
7066 | || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF) | |
7067 | { | |
7068 | /* Gap in the line? */ | |
7069 | if (GPT < start || Z - GPT < end) | |
7070 | unchanged_p = 0; | |
7071 | ||
7072 | /* Changes start in front of the line, or end after it? */ | |
7073 | if (unchanged_p | |
9142dd5b GM |
7074 | && (BEG_UNCHANGED < start - 1 |
7075 | || END_UNCHANGED < end)) | |
5f5c8ee5 GM |
7076 | unchanged_p = 0; |
7077 | ||
7078 | /* If selective display, can't optimize if changes start at the | |
7079 | beginning of the line. */ | |
7080 | if (unchanged_p | |
7081 | && INTEGERP (current_buffer->selective_display) | |
7082 | && XINT (current_buffer->selective_display) > 0 | |
9142dd5b | 7083 | && (BEG_UNCHANGED < start || GPT <= start)) |
5f5c8ee5 GM |
7084 | unchanged_p = 0; |
7085 | } | |
7086 | ||
7087 | return unchanged_p; | |
7088 | } | |
7089 | ||
7090 | ||
7091 | /* Do a frame update, taking possible shortcuts into account. This is | |
7092 | the main external entry point for redisplay. | |
7093 | ||
7094 | If the last redisplay displayed an echo area message and that message | |
7095 | is no longer requested, we clear the echo area or bring back the | |
7096 | mini-buffer if that is in use. */ | |
20de20dc | 7097 | |
a2889657 JB |
7098 | void |
7099 | redisplay () | |
e9874cee RS |
7100 | { |
7101 | redisplay_internal (0); | |
7102 | } | |
7103 | ||
260a86a0 KH |
7104 | /* Return 1 if point moved out of or into a composition. Otherwise |
7105 | return 0. PREV_BUF and PREV_PT are the last point buffer and | |
7106 | position. BUF and PT are the current point buffer and position. */ | |
7107 | ||
7108 | int | |
7109 | check_point_in_composition (prev_buf, prev_pt, buf, pt) | |
7110 | struct buffer *prev_buf, *buf; | |
7111 | int prev_pt, pt; | |
7112 | { | |
7113 | int start, end; | |
7114 | Lisp_Object prop; | |
7115 | Lisp_Object buffer; | |
7116 | ||
7117 | XSETBUFFER (buffer, buf); | |
7118 | /* Check a composition at the last point if point moved within the | |
7119 | same buffer. */ | |
7120 | if (prev_buf == buf) | |
7121 | { | |
7122 | if (prev_pt == pt) | |
7123 | /* Point didn't move. */ | |
7124 | return 0; | |
7125 | ||
7126 | if (prev_pt > BUF_BEGV (buf) && prev_pt < BUF_ZV (buf) | |
7127 | && find_composition (prev_pt, -1, &start, &end, &prop, buffer) | |
7128 | && COMPOSITION_VALID_P (start, end, prop) | |
7129 | && start < prev_pt && end > prev_pt) | |
7130 | /* The last point was within the composition. Return 1 iff | |
7131 | point moved out of the composition. */ | |
7132 | return (pt <= start || pt >= end); | |
7133 | } | |
7134 | ||
7135 | /* Check a composition at the current point. */ | |
7136 | return (pt > BUF_BEGV (buf) && pt < BUF_ZV (buf) | |
7137 | && find_composition (pt, -1, &start, &end, &prop, buffer) | |
7138 | && COMPOSITION_VALID_P (start, end, prop) | |
7139 | && start < pt && end > pt); | |
7140 | } | |
5f5c8ee5 | 7141 | |
9142dd5b GM |
7142 | /* Reconsider the setting of B->clip_changed which is displayed |
7143 | in window W. */ | |
7144 | ||
7145 | static INLINE void | |
7146 | reconsider_clip_changes (w, b) | |
7147 | struct window *w; | |
7148 | struct buffer *b; | |
7149 | { | |
7150 | if (b->prevent_redisplay_optimizations_p) | |
7151 | b->clip_changed = 1; | |
7152 | else if (b->clip_changed | |
7153 | && !NILP (w->window_end_valid) | |
7154 | && w->current_matrix->buffer == b | |
7155 | && w->current_matrix->zv == BUF_ZV (b) | |
7156 | && w->current_matrix->begv == BUF_BEGV (b)) | |
7157 | b->clip_changed = 0; | |
260a86a0 KH |
7158 | |
7159 | /* If display wasn't paused, and W is not a tool bar window, see if | |
7160 | point has been moved into or out of a composition. In that case, | |
7161 | we set b->clip_changed to 1 to force updating the screen. If | |
7162 | b->clip_changed has already been set to 1, we can skip this | |
7163 | check. */ | |
7164 | if (!b->clip_changed | |
7165 | && BUFFERP (w->buffer) && !NILP (w->window_end_valid)) | |
7166 | { | |
7167 | int pt; | |
7168 | ||
7169 | if (w == XWINDOW (selected_window)) | |
7170 | pt = BUF_PT (current_buffer); | |
7171 | else | |
7172 | pt = marker_position (w->pointm); | |
7173 | ||
7174 | if ((w->current_matrix->buffer != XBUFFER (w->buffer) | |
6fc556fd | 7175 | || pt != XINT (w->last_point)) |
260a86a0 | 7176 | && check_point_in_composition (w->current_matrix->buffer, |
6fc556fd | 7177 | XINT (w->last_point), |
260a86a0 KH |
7178 | XBUFFER (w->buffer), pt)) |
7179 | b->clip_changed = 1; | |
7180 | } | |
9142dd5b GM |
7181 | } |
7182 | ||
7183 | ||
5f5c8ee5 GM |
7184 | /* If PRESERVE_ECHO_AREA is nonzero, it means this redisplay is not in |
7185 | response to any user action; therefore, we should preserve the echo | |
7186 | area. (Actually, our caller does that job.) Perhaps in the future | |
7187 | avoid recentering windows if it is not necessary; currently that | |
7188 | causes some problems. */ | |
e9874cee RS |
7189 | |
7190 | static void | |
7191 | redisplay_internal (preserve_echo_area) | |
7192 | int preserve_echo_area; | |
a2889657 | 7193 | { |
5f5c8ee5 GM |
7194 | struct window *w = XWINDOW (selected_window); |
7195 | struct frame *f = XFRAME (w->frame); | |
7196 | int pause; | |
a2889657 | 7197 | int must_finish = 0; |
5f5c8ee5 | 7198 | struct text_pos tlbufpos, tlendpos; |
89819bdd | 7199 | int number_of_visible_frames; |
28514cd9 | 7200 | int count; |
886bd6f2 | 7201 | struct frame *sf = SELECTED_FRAME (); |
a2889657 | 7202 | |
5f5c8ee5 GM |
7203 | /* Non-zero means redisplay has to consider all windows on all |
7204 | frames. Zero means, only selected_window is considered. */ | |
7205 | int consider_all_windows_p; | |
7206 | ||
7207 | TRACE ((stderr, "redisplay_internal %d\n", redisplaying_p)); | |
7208 | ||
7209 | /* No redisplay if running in batch mode or frame is not yet fully | |
7210 | initialized, or redisplay is explicitly turned off by setting | |
7211 | Vinhibit_redisplay. */ | |
7212 | if (noninteractive | |
7213 | || !NILP (Vinhibit_redisplay) | |
7214 | || !f->glyphs_initialized_p) | |
a2889657 JB |
7215 | return; |
7216 | ||
5f5c8ee5 GM |
7217 | /* The flag redisplay_performed_directly_p is set by |
7218 | direct_output_for_insert when it already did the whole screen | |
7219 | update necessary. */ | |
7220 | if (redisplay_performed_directly_p) | |
7221 | { | |
7222 | redisplay_performed_directly_p = 0; | |
7223 | if (!hscroll_windows (selected_window)) | |
7224 | return; | |
7225 | } | |
7226 | ||
15f0cf78 RS |
7227 | #ifdef USE_X_TOOLKIT |
7228 | if (popup_activated ()) | |
7229 | return; | |
7230 | #endif | |
7231 | ||
28514cd9 | 7232 | /* I don't think this happens but let's be paranoid. */ |
5f5c8ee5 | 7233 | if (redisplaying_p) |
735c094c KH |
7234 | return; |
7235 | ||
28514cd9 GM |
7236 | /* Record a function that resets redisplaying_p to its old value |
7237 | when we leave this function. */ | |
7238 | count = specpdl_ptr - specpdl; | |
7239 | record_unwind_protect (unwind_redisplay, make_number (redisplaying_p)); | |
7240 | ++redisplaying_p; | |
7241 | ||
8b32d885 RS |
7242 | retry: |
7243 | ||
9142dd5b GM |
7244 | reconsider_clip_changes (w, current_buffer); |
7245 | ||
5f5c8ee5 GM |
7246 | /* If new fonts have been loaded that make a glyph matrix adjustment |
7247 | necessary, do it. */ | |
7248 | if (fonts_changed_p) | |
7249 | { | |
7250 | adjust_glyphs (NULL); | |
7251 | ++windows_or_buffers_changed; | |
7252 | fonts_changed_p = 0; | |
7253 | } | |
7254 | ||
886bd6f2 GM |
7255 | if (! FRAME_WINDOW_P (sf) |
7256 | && previous_terminal_frame != sf) | |
20de20dc | 7257 | { |
5f5c8ee5 GM |
7258 | /* Since frames on an ASCII terminal share the same display |
7259 | area, displaying a different frame means redisplay the whole | |
7260 | thing. */ | |
20de20dc | 7261 | windows_or_buffers_changed++; |
886bd6f2 GM |
7262 | SET_FRAME_GARBAGED (sf); |
7263 | XSETFRAME (Vterminal_frame, sf); | |
20de20dc | 7264 | } |
886bd6f2 | 7265 | previous_terminal_frame = sf; |
20de20dc | 7266 | |
5f5c8ee5 GM |
7267 | /* Set the visible flags for all frames. Do this before checking |
7268 | for resized or garbaged frames; they want to know if their frames | |
7269 | are visible. See the comment in frame.h for | |
7270 | FRAME_SAMPLE_VISIBILITY. */ | |
d724d989 | 7271 | { |
35f56f96 | 7272 | Lisp_Object tail, frame; |
d724d989 | 7273 | |
89819bdd RS |
7274 | number_of_visible_frames = 0; |
7275 | ||
35f56f96 | 7276 | FOR_EACH_FRAME (tail, frame) |
f82aff7c | 7277 | { |
5f5c8ee5 GM |
7278 | struct frame *f = XFRAME (frame); |
7279 | ||
7280 | FRAME_SAMPLE_VISIBILITY (f); | |
7281 | if (FRAME_VISIBLE_P (f)) | |
7282 | ++number_of_visible_frames; | |
7283 | clear_desired_matrices (f); | |
f82aff7c | 7284 | } |
d724d989 JB |
7285 | } |
7286 | ||
44fa5b1e | 7287 | /* Notice any pending interrupt request to change frame size. */ |
c6e89d6c | 7288 | do_pending_window_change (1); |
a2889657 | 7289 | |
5f5c8ee5 | 7290 | /* Clear frames marked as garbaged. */ |
44fa5b1e | 7291 | if (frame_garbaged) |
c6e89d6c | 7292 | clear_garbaged_frames (); |
a2889657 | 7293 | |
e037b9ec | 7294 | /* Build menubar and tool-bar items. */ |
f82aff7c RS |
7295 | prepare_menu_bars (); |
7296 | ||
28995e67 | 7297 | if (windows_or_buffers_changed) |
a2889657 JB |
7298 | update_mode_lines++; |
7299 | ||
538f13d4 RS |
7300 | /* Detect case that we need to write or remove a star in the mode line. */ |
7301 | if ((SAVE_MODIFF < MODIFF) != !NILP (w->last_had_star)) | |
a2889657 JB |
7302 | { |
7303 | w->update_mode_line = Qt; | |
7304 | if (buffer_shared > 1) | |
7305 | update_mode_lines++; | |
7306 | } | |
7307 | ||
5f5c8ee5 | 7308 | /* If %c is in the mode line, update it if needed. */ |
28995e67 RS |
7309 | if (!NILP (w->column_number_displayed) |
7310 | /* This alternative quickly identifies a common case | |
7311 | where no change is needed. */ | |
7312 | && !(PT == XFASTINT (w->last_point) | |
8850a573 RS |
7313 | && XFASTINT (w->last_modified) >= MODIFF |
7314 | && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF) | |
28995e67 RS |
7315 | && XFASTINT (w->column_number_displayed) != current_column ()) |
7316 | w->update_mode_line = Qt; | |
7317 | ||
44fa5b1e | 7318 | FRAME_SCROLL_BOTTOM_VPOS (XFRAME (w->frame)) = -1; |
a2889657 | 7319 | |
5f5c8ee5 GM |
7320 | /* The variable buffer_shared is set in redisplay_window and |
7321 | indicates that we redisplay a buffer in different windows. See | |
7322 | there. */ | |
7323 | consider_all_windows_p = update_mode_lines || buffer_shared > 1; | |
a2889657 JB |
7324 | |
7325 | /* If specs for an arrow have changed, do thorough redisplay | |
7326 | to ensure we remove any arrow that should no longer exist. */ | |
d45de95b | 7327 | if (! EQ (COERCE_MARKER (Voverlay_arrow_position), last_arrow_position) |
ded34426 | 7328 | || ! EQ (Voverlay_arrow_string, last_arrow_string)) |
5f5c8ee5 | 7329 | consider_all_windows_p = windows_or_buffers_changed = 1; |
a2889657 | 7330 | |
90adcf20 RS |
7331 | /* Normally the message* functions will have already displayed and |
7332 | updated the echo area, but the frame may have been trashed, or | |
7333 | the update may have been preempted, so display the echo area | |
c6e89d6c GM |
7334 | again here. Checking both message buffers captures the case that |
7335 | the echo area should be cleared. */ | |
7336 | if (!NILP (echo_area_buffer[0]) || !NILP (echo_area_buffer[1])) | |
90adcf20 | 7337 | { |
c6e89d6c | 7338 | int window_height_changed_p = echo_area_display (0); |
90adcf20 | 7339 | must_finish = 1; |
dd2eb166 | 7340 | |
c6e89d6c GM |
7341 | if (fonts_changed_p) |
7342 | goto retry; | |
7343 | else if (window_height_changed_p) | |
7344 | { | |
7345 | consider_all_windows_p = 1; | |
7346 | ++update_mode_lines; | |
7347 | ++windows_or_buffers_changed; | |
9142dd5b GM |
7348 | |
7349 | /* If window configuration was changed, frames may have been | |
7350 | marked garbaged. Clear them or we will experience | |
7351 | surprises wrt scrolling. */ | |
7352 | if (frame_garbaged) | |
7353 | clear_garbaged_frames (); | |
c6e89d6c | 7354 | } |
90adcf20 | 7355 | } |
dd2eb166 GM |
7356 | else if (w == XWINDOW (minibuf_window) |
7357 | && (current_buffer->clip_changed | |
7358 | || XFASTINT (w->last_modified) < MODIFF | |
7359 | || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF) | |
92a90e89 | 7360 | && resize_mini_window (w, 0)) |
c6e89d6c GM |
7361 | { |
7362 | /* Resized active mini-window to fit the size of what it is | |
dd2eb166 GM |
7363 | showing if its contents might have changed. */ |
7364 | must_finish = 1; | |
7365 | consider_all_windows_p = 1; | |
c6e89d6c | 7366 | ++windows_or_buffers_changed; |
dd2eb166 | 7367 | ++update_mode_lines; |
9142dd5b GM |
7368 | |
7369 | /* If window configuration was changed, frames may have been | |
7370 | marked garbaged. Clear them or we will experience | |
7371 | surprises wrt scrolling. */ | |
7372 | if (frame_garbaged) | |
7373 | clear_garbaged_frames (); | |
c6e89d6c GM |
7374 | } |
7375 | ||
90adcf20 | 7376 | |
5f5c8ee5 GM |
7377 | /* If showing the region, and mark has changed, we must redisplay |
7378 | the whole window. The assignment to this_line_start_pos prevents | |
7379 | the optimization directly below this if-statement. */ | |
bd66d1ba RS |
7380 | if (((!NILP (Vtransient_mark_mode) |
7381 | && !NILP (XBUFFER (w->buffer)->mark_active)) | |
7382 | != !NILP (w->region_showing)) | |
82d04750 JB |
7383 | || (!NILP (w->region_showing) |
7384 | && !EQ (w->region_showing, | |
7385 | Fmarker_position (XBUFFER (w->buffer)->mark)))) | |
5f5c8ee5 GM |
7386 | CHARPOS (this_line_start_pos) = 0; |
7387 | ||
7388 | /* Optimize the case that only the line containing the cursor in the | |
7389 | selected window has changed. Variables starting with this_ are | |
7390 | set in display_line and record information about the line | |
7391 | containing the cursor. */ | |
7392 | tlbufpos = this_line_start_pos; | |
7393 | tlendpos = this_line_end_pos; | |
7394 | if (!consider_all_windows_p | |
7395 | && CHARPOS (tlbufpos) > 0 | |
7396 | && NILP (w->update_mode_line) | |
73af359d | 7397 | && !current_buffer->clip_changed |
44fa5b1e | 7398 | && FRAME_VISIBLE_P (XFRAME (w->frame)) |
f21ef775 | 7399 | && !FRAME_OBSCURED_P (XFRAME (w->frame)) |
5f5c8ee5 | 7400 | /* Make sure recorded data applies to current buffer, etc. */ |
a2889657 JB |
7401 | && this_line_buffer == current_buffer |
7402 | && current_buffer == XBUFFER (w->buffer) | |
265a9e55 | 7403 | && NILP (w->force_start) |
5f5c8ee5 GM |
7404 | /* Point must be on the line that we have info recorded about. */ |
7405 | && PT >= CHARPOS (tlbufpos) | |
7406 | && PT <= Z - CHARPOS (tlendpos) | |
a2889657 JB |
7407 | /* All text outside that line, including its final newline, |
7408 | must be unchanged */ | |
5f5c8ee5 GM |
7409 | && text_outside_line_unchanged_p (w, CHARPOS (tlbufpos), |
7410 | CHARPOS (tlendpos))) | |
7411 | { | |
7412 | if (CHARPOS (tlbufpos) > BEGV | |
7413 | && FETCH_BYTE (BYTEPOS (tlbufpos) - 1) != '\n' | |
7414 | && (CHARPOS (tlbufpos) == ZV | |
7415 | || FETCH_BYTE (BYTEPOS (tlbufpos)) == '\n')) | |
a2889657 JB |
7416 | /* Former continuation line has disappeared by becoming empty */ |
7417 | goto cancel; | |
7418 | else if (XFASTINT (w->last_modified) < MODIFF | |
8850a573 | 7419 | || XFASTINT (w->last_overlay_modified) < OVERLAY_MODIFF |
a2889657 JB |
7420 | || MINI_WINDOW_P (w)) |
7421 | { | |
1c9241f5 KH |
7422 | /* We have to handle the case of continuation around a |
7423 | wide-column character (See the comment in indent.c around | |
7424 | line 885). | |
7425 | ||
7426 | For instance, in the following case: | |
7427 | ||
7428 | -------- Insert -------- | |
7429 | K_A_N_\\ `a' K_A_N_a\ `X_' are wide-column chars. | |
7430 | J_I_ ==> J_I_ `^^' are cursors. | |
7431 | ^^ ^^ | |
7432 | -------- -------- | |
7433 | ||
7434 | As we have to redraw the line above, we should goto cancel. */ | |
7435 | ||
5f5c8ee5 GM |
7436 | struct it it; |
7437 | int line_height_before = this_line_pixel_height; | |
7438 | ||
7439 | /* Note that start_display will handle the case that the | |
7440 | line starting at tlbufpos is a continuation lines. */ | |
7441 | start_display (&it, w, tlbufpos); | |
7442 | ||
7443 | /* Implementation note: It this still necessary? */ | |
7444 | if (it.current_x != this_line_start_x) | |
1c9241f5 KH |
7445 | goto cancel; |
7446 | ||
5f5c8ee5 GM |
7447 | TRACE ((stderr, "trying display optimization 1\n")); |
7448 | w->cursor.vpos = -1; | |
a2889657 | 7449 | overlay_arrow_seen = 0; |
5f5c8ee5 GM |
7450 | it.vpos = this_line_vpos; |
7451 | it.current_y = this_line_y; | |
7452 | it.glyph_row = MATRIX_ROW (w->desired_matrix, this_line_vpos); | |
7453 | display_line (&it); | |
7454 | ||
a2889657 | 7455 | /* If line contains point, is not continued, |
5f5c8ee5 GM |
7456 | and ends at same distance from eob as before, we win */ |
7457 | if (w->cursor.vpos >= 0 | |
7458 | /* Line is not continued, otherwise this_line_start_pos | |
7459 | would have been set to 0 in display_line. */ | |
7460 | && CHARPOS (this_line_start_pos) | |
7461 | /* Line ends as before. */ | |
7462 | && CHARPOS (this_line_end_pos) == CHARPOS (tlendpos) | |
7463 | /* Line has same height as before. Otherwise other lines | |
7464 | would have to be shifted up or down. */ | |
7465 | && this_line_pixel_height == line_height_before) | |
a2889657 | 7466 | { |
5f5c8ee5 GM |
7467 | /* If this is not the window's last line, we must adjust |
7468 | the charstarts of the lines below. */ | |
7469 | if (it.current_y < it.last_visible_y) | |
7470 | { | |
7471 | struct glyph_row *row | |
7472 | = MATRIX_ROW (w->current_matrix, this_line_vpos + 1); | |
7473 | int delta, delta_bytes; | |
7474 | ||
7475 | if (Z - CHARPOS (tlendpos) == ZV) | |
7476 | { | |
7477 | /* This line ends at end of (accessible part of) | |
7478 | buffer. There is no newline to count. */ | |
7479 | delta = (Z | |
7480 | - CHARPOS (tlendpos) | |
7481 | - MATRIX_ROW_START_CHARPOS (row)); | |
7482 | delta_bytes = (Z_BYTE | |
7483 | - BYTEPOS (tlendpos) | |
7484 | - MATRIX_ROW_START_BYTEPOS (row)); | |
7485 | } | |
7486 | else | |
7487 | { | |
7488 | /* This line ends in a newline. Must take | |
7489 | account of the newline and the rest of the | |
7490 | text that follows. */ | |
7491 | delta = (Z | |
7492 | - CHARPOS (tlendpos) | |
7493 | - MATRIX_ROW_START_CHARPOS (row)); | |
7494 | delta_bytes = (Z_BYTE | |
7495 | - BYTEPOS (tlendpos) | |
7496 | - MATRIX_ROW_START_BYTEPOS (row)); | |
7497 | } | |
7498 | ||
f2d86d7a GM |
7499 | increment_matrix_positions (w->current_matrix, |
7500 | this_line_vpos + 1, | |
7501 | w->current_matrix->nrows, | |
7502 | delta, delta_bytes); | |
85bcef6c | 7503 | } |
46db8486 | 7504 | |
5f5c8ee5 GM |
7505 | /* If this row displays text now but previously didn't, |
7506 | or vice versa, w->window_end_vpos may have to be | |
7507 | adjusted. */ | |
7508 | if ((it.glyph_row - 1)->displays_text_p) | |
7509 | { | |
7510 | if (XFASTINT (w->window_end_vpos) < this_line_vpos) | |
7511 | XSETINT (w->window_end_vpos, this_line_vpos); | |
7512 | } | |
7513 | else if (XFASTINT (w->window_end_vpos) == this_line_vpos | |
7514 | && this_line_vpos > 0) | |
7515 | XSETINT (w->window_end_vpos, this_line_vpos - 1); | |
7516 | w->window_end_valid = Qnil; | |
7517 | ||
7518 | /* Update hint: No need to try to scroll in update_window. */ | |
7519 | w->desired_matrix->no_scrolling_p = 1; | |
7520 | ||
7521 | #if GLYPH_DEBUG | |
7522 | *w->desired_matrix->method = 0; | |
7523 | debug_method_add (w, "optimization 1"); | |
7524 | #endif | |
a2889657 JB |
7525 | goto update; |
7526 | } | |
7527 | else | |
7528 | goto cancel; | |
7529 | } | |
5f5c8ee5 GM |
7530 | else if (/* Cursor position hasn't changed. */ |
7531 | PT == XFASTINT (w->last_point) | |
b6f0fe04 RS |
7532 | /* Make sure the cursor was last displayed |
7533 | in this window. Otherwise we have to reposition it. */ | |
5f5c8ee5 GM |
7534 | && 0 <= w->cursor.vpos |
7535 | && XINT (w->height) > w->cursor.vpos) | |
a2889657 JB |
7536 | { |
7537 | if (!must_finish) | |
7538 | { | |
c6e89d6c | 7539 | do_pending_window_change (1); |
5f5c8ee5 GM |
7540 | |
7541 | /* We used to always goto end_of_redisplay here, but this | |
7542 | isn't enough if we have a blinking cursor. */ | |
7543 | if (w->cursor_off_p == w->last_cursor_off_p) | |
7544 | goto end_of_redisplay; | |
a2889657 JB |
7545 | } |
7546 | goto update; | |
7547 | } | |
8b51f1e3 KH |
7548 | /* If highlighting the region, or if the cursor is in the echo area, |
7549 | then we can't just move the cursor. */ | |
bd66d1ba RS |
7550 | else if (! (!NILP (Vtransient_mark_mode) |
7551 | && !NILP (current_buffer->mark_active)) | |
293a54ce RS |
7552 | && (w == XWINDOW (current_buffer->last_selected_window) |
7553 | || highlight_nonselected_windows) | |
8b51f1e3 | 7554 | && NILP (w->region_showing) |
8f897821 | 7555 | && NILP (Vshow_trailing_whitespace) |
8b51f1e3 | 7556 | && !cursor_in_echo_area) |
a2889657 | 7557 | { |
5f5c8ee5 GM |
7558 | struct it it; |
7559 | struct glyph_row *row; | |
7560 | ||
7561 | /* Skip from tlbufpos to PT and see where it is. Note that | |
7562 | PT may be in invisible text. If so, we will end at the | |
7563 | next visible position. */ | |
7564 | init_iterator (&it, w, CHARPOS (tlbufpos), BYTEPOS (tlbufpos), | |
7565 | NULL, DEFAULT_FACE_ID); | |
7566 | it.current_x = this_line_start_x; | |
7567 | it.current_y = this_line_y; | |
7568 | it.vpos = this_line_vpos; | |
7569 | ||
7570 | /* The call to move_it_to stops in front of PT, but | |
7571 | moves over before-strings. */ | |
7572 | move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); | |
7573 | ||
7574 | if (it.vpos == this_line_vpos | |
7575 | && (row = MATRIX_ROW (w->current_matrix, this_line_vpos), | |
7576 | row->enabled_p)) | |
a2889657 | 7577 | { |
5f5c8ee5 GM |
7578 | xassert (this_line_vpos == it.vpos); |
7579 | xassert (this_line_y == it.current_y); | |
7580 | set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0); | |
a2889657 JB |
7581 | goto update; |
7582 | } | |
7583 | else | |
7584 | goto cancel; | |
7585 | } | |
5f5c8ee5 | 7586 | |
a2889657 | 7587 | cancel: |
5f5c8ee5 GM |
7588 | /* Text changed drastically or point moved off of line. */ |
7589 | SET_MATRIX_ROW_ENABLED_P (w->desired_matrix, this_line_vpos, 0); | |
a2889657 JB |
7590 | } |
7591 | ||
5f5c8ee5 GM |
7592 | CHARPOS (this_line_start_pos) = 0; |
7593 | consider_all_windows_p |= buffer_shared > 1; | |
7594 | ++clear_face_cache_count; | |
a2889657 | 7595 | |
5f5c8ee5 GM |
7596 | |
7597 | /* Build desired matrices. If consider_all_windows_p is non-zero, | |
7598 | do it for all windows on all frames. Otherwise do it for | |
7599 | selected_window, only. */ | |
463f6b91 | 7600 | |
5f5c8ee5 | 7601 | if (consider_all_windows_p) |
a2889657 | 7602 | { |
35f56f96 | 7603 | Lisp_Object tail, frame; |
a2889657 | 7604 | |
5f5c8ee5 GM |
7605 | /* Clear the face cache eventually. */ |
7606 | if (clear_face_cache_count > CLEAR_FACE_CACHE_COUNT) | |
463f6b91 | 7607 | { |
5f5c8ee5 | 7608 | clear_face_cache (0); |
463f6b91 RS |
7609 | clear_face_cache_count = 0; |
7610 | } | |
31b24551 | 7611 | |
5f5c8ee5 GM |
7612 | /* Recompute # windows showing selected buffer. This will be |
7613 | incremented each time such a window is displayed. */ | |
a2889657 JB |
7614 | buffer_shared = 0; |
7615 | ||
35f56f96 | 7616 | FOR_EACH_FRAME (tail, frame) |
30c566e4 | 7617 | { |
5f5c8ee5 | 7618 | struct frame *f = XFRAME (frame); |
886bd6f2 | 7619 | if (FRAME_WINDOW_P (f) || f == sf) |
9769686d | 7620 | { |
5f5c8ee5 GM |
7621 | /* Mark all the scroll bars to be removed; we'll redeem |
7622 | the ones we want when we redisplay their windows. */ | |
9769686d RS |
7623 | if (condemn_scroll_bars_hook) |
7624 | (*condemn_scroll_bars_hook) (f); | |
30c566e4 | 7625 | |
f21ef775 | 7626 | if (FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f)) |
5f5c8ee5 | 7627 | redisplay_windows (FRAME_ROOT_WINDOW (f)); |
30c566e4 | 7628 | |
5f5c8ee5 GM |
7629 | /* Any scroll bars which redisplay_windows should have |
7630 | nuked should now go away. */ | |
9769686d RS |
7631 | if (judge_scroll_bars_hook) |
7632 | (*judge_scroll_bars_hook) (f); | |
7633 | } | |
30c566e4 | 7634 | } |
a2889657 | 7635 | } |
886bd6f2 GM |
7636 | else if (FRAME_VISIBLE_P (sf) |
7637 | && !FRAME_OBSCURED_P (sf)) | |
5f5c8ee5 GM |
7638 | redisplay_window (selected_window, 1); |
7639 | ||
7640 | ||
7641 | /* Compare desired and current matrices, perform output. */ | |
7642 | ||
7643 | update: | |
7644 | ||
7645 | /* If fonts changed, display again. */ | |
7646 | if (fonts_changed_p) | |
7647 | goto retry; | |
a2889657 | 7648 | |
a2889657 JB |
7649 | /* Prevent various kinds of signals during display update. |
7650 | stdio is not robust about handling signals, | |
7651 | which can cause an apparent I/O error. */ | |
7652 | if (interrupt_input) | |
7653 | unrequest_sigio (); | |
7654 | stop_polling (); | |
7655 | ||
5f5c8ee5 | 7656 | if (consider_all_windows_p) |
a2889657 JB |
7657 | { |
7658 | Lisp_Object tail; | |
92a90e89 GM |
7659 | struct frame *f; |
7660 | int hscrolled_p; | |
a2889657 JB |
7661 | |
7662 | pause = 0; | |
92a90e89 | 7663 | hscrolled_p = 0; |
a2889657 | 7664 | |
92a90e89 | 7665 | /* See if we have to hscroll. */ |
9472f927 | 7666 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
92a90e89 GM |
7667 | if (FRAMEP (XCAR (tail))) |
7668 | { | |
7669 | f = XFRAME (XCAR (tail)); | |
7670 | ||
7671 | if ((FRAME_WINDOW_P (f) | |
886bd6f2 | 7672 | || f == sf) |
92a90e89 GM |
7673 | && FRAME_VISIBLE_P (f) |
7674 | && !FRAME_OBSCURED_P (f) | |
7675 | && hscroll_windows (f->root_window)) | |
7676 | hscrolled_p = 1; | |
7677 | } | |
7678 | ||
7679 | if (hscrolled_p) | |
7680 | goto retry; | |
a2889657 | 7681 | |
92a90e89 GM |
7682 | for (tail = Vframe_list; CONSP (tail); tail = XCDR (tail)) |
7683 | { | |
9472f927 | 7684 | if (!FRAMEP (XCAR (tail))) |
a2889657 JB |
7685 | continue; |
7686 | ||
9472f927 | 7687 | f = XFRAME (XCAR (tail)); |
1af9f229 | 7688 | |
886bd6f2 | 7689 | if ((FRAME_WINDOW_P (f) || f == sf) |
f21ef775 | 7690 | && FRAME_VISIBLE_P (f) && !FRAME_OBSCURED_P (f)) |
a2889657 | 7691 | { |
5f5c8ee5 GM |
7692 | /* Mark all windows as to be updated. */ |
7693 | set_window_update_flags (XWINDOW (f->root_window), 1); | |
44fa5b1e | 7694 | pause |= update_frame (f, 0, 0); |
a2889657 | 7695 | if (!pause) |
efc63ef0 RS |
7696 | { |
7697 | mark_window_display_accurate (f->root_window, 1); | |
7698 | if (frame_up_to_date_hook != 0) | |
7699 | (*frame_up_to_date_hook) (f); | |
7700 | } | |
a2889657 JB |
7701 | } |
7702 | } | |
7703 | } | |
7704 | else | |
6e8290aa | 7705 | { |
886bd6f2 GM |
7706 | if (FRAME_VISIBLE_P (sf) |
7707 | && !FRAME_OBSCURED_P (sf)) | |
5f5c8ee5 | 7708 | { |
92a90e89 GM |
7709 | if (hscroll_windows (selected_window)) |
7710 | goto retry; | |
7711 | ||
5f5c8ee5 | 7712 | XWINDOW (selected_window)->must_be_updated_p = 1; |
886bd6f2 | 7713 | pause = update_frame (sf, 0, 0); |
5f5c8ee5 | 7714 | } |
4d641a15 KH |
7715 | else |
7716 | pause = 0; | |
d724d989 | 7717 | |
8de2d90b | 7718 | /* We may have called echo_area_display at the top of this |
44fa5b1e JB |
7719 | function. If the echo area is on another frame, that may |
7720 | have put text on a frame other than the selected one, so the | |
7721 | above call to update_frame would not have caught it. Catch | |
8de2d90b JB |
7722 | it here. */ |
7723 | { | |
84faf44c | 7724 | Lisp_Object mini_window; |
5f5c8ee5 | 7725 | struct frame *mini_frame; |
84faf44c | 7726 | |
886bd6f2 | 7727 | mini_window = FRAME_MINIBUF_WINDOW (sf); |
84faf44c | 7728 | mini_frame = XFRAME (WINDOW_FRAME (XWINDOW (mini_window))); |
8de2d90b | 7729 | |
886bd6f2 | 7730 | if (mini_frame != sf && FRAME_WINDOW_P (mini_frame)) |
5f5c8ee5 GM |
7731 | { |
7732 | XWINDOW (mini_window)->must_be_updated_p = 1; | |
7733 | pause |= update_frame (mini_frame, 0, 0); | |
7734 | if (!pause && hscroll_windows (mini_window)) | |
7735 | goto retry; | |
7736 | } | |
8de2d90b | 7737 | } |
6e8290aa | 7738 | } |
a2889657 | 7739 | |
5f5c8ee5 GM |
7740 | /* If display was paused because of pending input, make sure we do a |
7741 | thorough update the next time. */ | |
a2889657 JB |
7742 | if (pause) |
7743 | { | |
5f5c8ee5 GM |
7744 | /* Prevent the optimization at the beginning of |
7745 | redisplay_internal that tries a single-line update of the | |
7746 | line containing the cursor in the selected window. */ | |
7747 | CHARPOS (this_line_start_pos) = 0; | |
7748 | ||
7749 | /* Let the overlay arrow be updated the next time. */ | |
265a9e55 | 7750 | if (!NILP (last_arrow_position)) |
a2889657 JB |
7751 | { |
7752 | last_arrow_position = Qt; | |
7753 | last_arrow_string = Qt; | |
7754 | } | |
5f5c8ee5 GM |
7755 | |
7756 | /* If we pause after scrolling, some rows in the current | |
7757 | matrices of some windows are not valid. */ | |
7758 | if (!WINDOW_FULL_WIDTH_P (w) | |
7759 | && !FRAME_WINDOW_P (XFRAME (w->frame))) | |
a2889657 JB |
7760 | update_mode_lines = 1; |
7761 | } | |
7762 | ||
5f5c8ee5 GM |
7763 | /* Now text on frame agrees with windows, so put info into the |
7764 | windows for partial redisplay to follow. */ | |
a2889657 JB |
7765 | if (!pause) |
7766 | { | |
7767 | register struct buffer *b = XBUFFER (w->buffer); | |
7768 | ||
9142dd5b GM |
7769 | BUF_UNCHANGED_MODIFIED (b) = BUF_MODIFF (b); |
7770 | BUF_OVERLAY_UNCHANGED_MODIFIED (b) = BUF_OVERLAY_MODIFF (b); | |
7771 | BUF_BEG_UNCHANGED (b) = BUF_GPT (b) - BUF_BEG (b); | |
7772 | BUF_END_UNCHANGED (b) = BUF_Z (b) - BUF_GPT (b); | |
a2889657 | 7773 | |
5f5c8ee5 | 7774 | if (consider_all_windows_p) |
886bd6f2 | 7775 | mark_window_display_accurate (FRAME_ROOT_WINDOW (sf), 1); |
a2889657 JB |
7776 | else |
7777 | { | |
5f5c8ee5 GM |
7778 | XSETFASTINT (w->last_point, BUF_PT (b)); |
7779 | w->last_cursor = w->cursor; | |
7780 | w->last_cursor_off_p = w->cursor_off_p; | |
7781 | ||
28995e67 | 7782 | b->clip_changed = 0; |
9142dd5b | 7783 | b->prevent_redisplay_optimizations_p = 0; |
a2889657 | 7784 | w->update_mode_line = Qnil; |
c2213350 | 7785 | XSETFASTINT (w->last_modified, BUF_MODIFF (b)); |
8850a573 | 7786 | XSETFASTINT (w->last_overlay_modified, BUF_OVERLAY_MODIFF (b)); |
538f13d4 RS |
7787 | w->last_had_star |
7788 | = (BUF_MODIFF (XBUFFER (w->buffer)) > BUF_SAVE_MODIFF (XBUFFER (w->buffer)) | |
7789 | ? Qt : Qnil); | |
3ee4159a RS |
7790 | |
7791 | /* Record if we are showing a region, so can make sure to | |
7792 | update it fully at next redisplay. */ | |
7793 | w->region_showing = (!NILP (Vtransient_mark_mode) | |
293a54ce RS |
7794 | && (w == XWINDOW (current_buffer->last_selected_window) |
7795 | || highlight_nonselected_windows) | |
3ee4159a RS |
7796 | && !NILP (XBUFFER (w->buffer)->mark_active) |
7797 | ? Fmarker_position (XBUFFER (w->buffer)->mark) | |
7798 | : Qnil); | |
7799 | ||
d2f84654 | 7800 | w->window_end_valid = w->buffer; |
d45de95b | 7801 | last_arrow_position = COERCE_MARKER (Voverlay_arrow_position); |
a2889657 | 7802 | last_arrow_string = Voverlay_arrow_string; |
efc63ef0 | 7803 | if (frame_up_to_date_hook != 0) |
886bd6f2 | 7804 | (*frame_up_to_date_hook) (sf); |
9142dd5b GM |
7805 | |
7806 | w->current_matrix->buffer = b; | |
7807 | w->current_matrix->begv = BUF_BEGV (b); | |
7808 | w->current_matrix->zv = BUF_ZV (b); | |
a2889657 | 7809 | } |
15e26c76 | 7810 | |
a2889657 JB |
7811 | update_mode_lines = 0; |
7812 | windows_or_buffers_changed = 0; | |
7813 | } | |
7814 | ||
5f5c8ee5 GM |
7815 | /* Start SIGIO interrupts coming again. Having them off during the |
7816 | code above makes it less likely one will discard output, but not | |
7817 | impossible, since there might be stuff in the system buffer here. | |
a2889657 | 7818 | But it is much hairier to try to do anything about that. */ |
a2889657 JB |
7819 | if (interrupt_input) |
7820 | request_sigio (); | |
7821 | start_polling (); | |
7822 | ||
5f5c8ee5 GM |
7823 | /* If a frame has become visible which was not before, redisplay |
7824 | again, so that we display it. Expose events for such a frame | |
7825 | (which it gets when becoming visible) don't call the parts of | |
7826 | redisplay constructing glyphs, so simply exposing a frame won't | |
7827 | display anything in this case. So, we have to display these | |
7828 | frames here explicitly. */ | |
11c52c4f RS |
7829 | if (!pause) |
7830 | { | |
7831 | Lisp_Object tail, frame; | |
7832 | int new_count = 0; | |
7833 | ||
7834 | FOR_EACH_FRAME (tail, frame) | |
7835 | { | |
7836 | int this_is_visible = 0; | |
8e83f802 RS |
7837 | |
7838 | if (XFRAME (frame)->visible) | |
7839 | this_is_visible = 1; | |
7840 | FRAME_SAMPLE_VISIBILITY (XFRAME (frame)); | |
7841 | if (XFRAME (frame)->visible) | |
7842 | this_is_visible = 1; | |
11c52c4f RS |
7843 | |
7844 | if (this_is_visible) | |
7845 | new_count++; | |
7846 | } | |
7847 | ||
89819bdd | 7848 | if (new_count != number_of_visible_frames) |
11c52c4f RS |
7849 | windows_or_buffers_changed++; |
7850 | } | |
7851 | ||
44fa5b1e | 7852 | /* Change frame size now if a change is pending. */ |
c6e89d6c | 7853 | do_pending_window_change (1); |
d8e242fd | 7854 | |
8b32d885 RS |
7855 | /* If we just did a pending size change, or have additional |
7856 | visible frames, redisplay again. */ | |
3c8c72e0 | 7857 | if (windows_or_buffers_changed && !pause) |
8b32d885 | 7858 | goto retry; |
5f5c8ee5 GM |
7859 | |
7860 | end_of_redisplay:; | |
c6e89d6c | 7861 | |
28514cd9 | 7862 | unbind_to (count, Qnil); |
a2889657 JB |
7863 | } |
7864 | ||
5f5c8ee5 GM |
7865 | |
7866 | /* Redisplay, but leave alone any recent echo area message unless | |
7867 | another message has been requested in its place. | |
a2889657 JB |
7868 | |
7869 | This is useful in situations where you need to redisplay but no | |
7870 | user action has occurred, making it inappropriate for the message | |
7871 | area to be cleared. See tracking_off and | |
7872 | wait_reading_process_input for examples of these situations. */ | |
7873 | ||
8991bb31 | 7874 | void |
a2889657 JB |
7875 | redisplay_preserve_echo_area () |
7876 | { | |
c6e89d6c | 7877 | if (!NILP (echo_area_buffer[1])) |
a2889657 | 7878 | { |
c6e89d6c GM |
7879 | /* We have a previously displayed message, but no current |
7880 | message. Redisplay the previous message. */ | |
7881 | display_last_displayed_message_p = 1; | |
e9874cee | 7882 | redisplay_internal (1); |
c6e89d6c | 7883 | display_last_displayed_message_p = 0; |
a2889657 JB |
7884 | } |
7885 | else | |
e9874cee | 7886 | redisplay_internal (1); |
a2889657 JB |
7887 | } |
7888 | ||
5f5c8ee5 | 7889 | |
28514cd9 GM |
7890 | /* Function registered with record_unwind_protect in |
7891 | redisplay_internal. Clears the flag indicating that a redisplay is | |
7892 | in progress. */ | |
7893 | ||
7894 | static Lisp_Object | |
7895 | unwind_redisplay (old_redisplaying_p) | |
7896 | Lisp_Object old_redisplaying_p; | |
7897 | { | |
7898 | redisplaying_p = XFASTINT (old_redisplaying_p); | |
c6e89d6c | 7899 | return Qnil; |
28514cd9 GM |
7900 | } |
7901 | ||
7902 | ||
5f5c8ee5 GM |
7903 | /* Mark the display of windows in the window tree rooted at WINDOW as |
7904 | accurate or inaccurate. If FLAG is non-zero mark display of WINDOW | |
7905 | as accurate. If FLAG is zero arrange for WINDOW to be redisplayed | |
7906 | the next time redisplay_internal is called. */ | |
7907 | ||
a2889657 | 7908 | void |
5f5c8ee5 | 7909 | mark_window_display_accurate (window, accurate_p) |
a2889657 | 7910 | Lisp_Object window; |
5f5c8ee5 | 7911 | int accurate_p; |
a2889657 | 7912 | { |
5f5c8ee5 GM |
7913 | struct window *w; |
7914 | ||
7915 | for (; !NILP (window); window = w->next) | |
a2889657 JB |
7916 | { |
7917 | w = XWINDOW (window); | |
7918 | ||
5f5c8ee5 | 7919 | if (BUFFERP (w->buffer)) |
bd66d1ba | 7920 | { |
5f5c8ee5 GM |
7921 | struct buffer *b = XBUFFER (w->buffer); |
7922 | ||
c2213350 | 7923 | XSETFASTINT (w->last_modified, |
5f5c8ee5 | 7924 | accurate_p ? BUF_MODIFF (b) : 0); |
8850a573 | 7925 | XSETFASTINT (w->last_overlay_modified, |
5f5c8ee5 GM |
7926 | accurate_p ? BUF_OVERLAY_MODIFF (b) : 0); |
7927 | w->last_had_star = (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b) | |
7928 | ? Qt : Qnil); | |
bd66d1ba | 7929 | |
5f5c8ee5 GM |
7930 | #if 0 /* I don't think this is necessary because display_line does it. |
7931 | Let's check it. */ | |
bd66d1ba RS |
7932 | /* Record if we are showing a region, so can make sure to |
7933 | update it fully at next redisplay. */ | |
5f5c8ee5 GM |
7934 | w->region_showing |
7935 | = (!NILP (Vtransient_mark_mode) | |
7936 | && (w == XWINDOW (current_buffer->last_selected_window) | |
7937 | || highlight_nonselected_windows) | |
7938 | && (!NILP (b->mark_active) | |
7939 | ? Fmarker_position (b->mark) | |
7940 | : Qnil)); | |
7941 | #endif | |
7942 | ||
7943 | if (accurate_p) | |
7944 | { | |
7945 | b->clip_changed = 0; | |
9142dd5b GM |
7946 | b->prevent_redisplay_optimizations_p = 0; |
7947 | w->current_matrix->buffer = b; | |
7948 | w->current_matrix->begv = BUF_BEGV (b); | |
7949 | w->current_matrix->zv = BUF_ZV (b); | |
5f5c8ee5 GM |
7950 | w->last_cursor = w->cursor; |
7951 | w->last_cursor_off_p = w->cursor_off_p; | |
7952 | if (w == XWINDOW (selected_window)) | |
6fc556fd | 7953 | w->last_point = make_number (BUF_PT (b)); |
5f5c8ee5 | 7954 | else |
6fc556fd | 7955 | w->last_point = make_number (XMARKER (w->pointm)->charpos); |
5f5c8ee5 | 7956 | } |
bd66d1ba RS |
7957 | } |
7958 | ||
d2f84654 | 7959 | w->window_end_valid = w->buffer; |
a2889657 JB |
7960 | w->update_mode_line = Qnil; |
7961 | ||
265a9e55 | 7962 | if (!NILP (w->vchild)) |
5f5c8ee5 | 7963 | mark_window_display_accurate (w->vchild, accurate_p); |
265a9e55 | 7964 | if (!NILP (w->hchild)) |
5f5c8ee5 | 7965 | mark_window_display_accurate (w->hchild, accurate_p); |
a2889657 JB |
7966 | } |
7967 | ||
5f5c8ee5 | 7968 | if (accurate_p) |
a2889657 | 7969 | { |
d45de95b | 7970 | last_arrow_position = COERCE_MARKER (Voverlay_arrow_position); |
a2889657 JB |
7971 | last_arrow_string = Voverlay_arrow_string; |
7972 | } | |
7973 | else | |
7974 | { | |
5f5c8ee5 GM |
7975 | /* Force a thorough redisplay the next time by setting |
7976 | last_arrow_position and last_arrow_string to t, which is | |
7977 | unequal to any useful value of Voverlay_arrow_... */ | |
a2889657 JB |
7978 | last_arrow_position = Qt; |
7979 | last_arrow_string = Qt; | |
7980 | } | |
7981 | } | |
5f5c8ee5 GM |
7982 | |
7983 | ||
7984 | /* Return value in display table DP (Lisp_Char_Table *) for character | |
7985 | C. Since a display table doesn't have any parent, we don't have to | |
7986 | follow parent. Do not call this function directly but use the | |
7987 | macro DISP_CHAR_VECTOR. */ | |
7988 | ||
7989 | Lisp_Object | |
7990 | disp_char_vector (dp, c) | |
7991 | struct Lisp_Char_Table *dp; | |
7992 | int c; | |
7993 | { | |
7994 | int code[4], i; | |
7995 | Lisp_Object val; | |
7996 | ||
7997 | if (SINGLE_BYTE_CHAR_P (c)) | |
7998 | return (dp->contents[c]); | |
7999 | ||
c5924f47 | 8000 | SPLIT_CHAR (c, code[0], code[1], code[2]); |
260a86a0 KH |
8001 | if (code[1] < 32) |
8002 | code[1] = -1; | |
8003 | else if (code[2] < 32) | |
8004 | code[2] = -1; | |
5f5c8ee5 GM |
8005 | |
8006 | /* Here, the possible range of code[0] (== charset ID) is | |
8007 | 128..max_charset. Since the top level char table contains data | |
8008 | for multibyte characters after 256th element, we must increment | |
8009 | code[0] by 128 to get a correct index. */ | |
8010 | code[0] += 128; | |
8011 | code[3] = -1; /* anchor */ | |
8012 | ||
8013 | for (i = 0; code[i] >= 0; i++, dp = XCHAR_TABLE (val)) | |
8014 | { | |
8015 | val = dp->contents[code[i]]; | |
8016 | if (!SUB_CHAR_TABLE_P (val)) | |
8017 | return (NILP (val) ? dp->defalt : val); | |
8018 | } | |
8019 | ||
8020 | /* Here, val is a sub char table. We return the default value of | |
8021 | it. */ | |
8022 | return (dp->defalt); | |
8023 | } | |
8024 | ||
8025 | ||
a2889657 | 8026 | \f |
5f5c8ee5 GM |
8027 | /*********************************************************************** |
8028 | Window Redisplay | |
8029 | ***********************************************************************/ | |
a2725ab2 | 8030 | |
5f5c8ee5 | 8031 | /* Redisplay all leaf windows in the window tree rooted at WINDOW. */ |
90adcf20 RS |
8032 | |
8033 | static void | |
5f5c8ee5 GM |
8034 | redisplay_windows (window) |
8035 | Lisp_Object window; | |
90adcf20 | 8036 | { |
5f5c8ee5 GM |
8037 | while (!NILP (window)) |
8038 | { | |
8039 | struct window *w = XWINDOW (window); | |
8040 | ||
8041 | if (!NILP (w->hchild)) | |
8042 | redisplay_windows (w->hchild); | |
8043 | else if (!NILP (w->vchild)) | |
8044 | redisplay_windows (w->vchild); | |
8045 | else | |
8046 | redisplay_window (window, 0); | |
a2725ab2 | 8047 | |
5f5c8ee5 GM |
8048 | window = w->next; |
8049 | } | |
8050 | } | |
8051 | ||
8052 | ||
8053 | /* Set cursor position of W. PT is assumed to be displayed in ROW. | |
8054 | DELTA is the number of bytes by which positions recorded in ROW | |
8055 | differ from current buffer positions. */ | |
8056 | ||
8057 | void | |
8058 | set_cursor_from_row (w, row, matrix, delta, delta_bytes, dy, dvpos) | |
8059 | struct window *w; | |
8060 | struct glyph_row *row; | |
8061 | struct glyph_matrix *matrix; | |
8062 | int delta, delta_bytes, dy, dvpos; | |
8063 | { | |
8064 | struct glyph *glyph = row->glyphs[TEXT_AREA]; | |
8065 | struct glyph *end = glyph + row->used[TEXT_AREA]; | |
8066 | int x = row->x; | |
8067 | int pt_old = PT - delta; | |
8068 | ||
8069 | /* Skip over glyphs not having an object at the start of the row. | |
8070 | These are special glyphs like truncation marks on terminal | |
8071 | frames. */ | |
8072 | if (row->displays_text_p) | |
8073 | while (glyph < end | |
6fc556fd | 8074 | && INTEGERP (glyph->object) |
5f5c8ee5 GM |
8075 | && glyph->charpos < 0) |
8076 | { | |
8077 | x += glyph->pixel_width; | |
8078 | ++glyph; | |
8079 | } | |
8080 | ||
8081 | while (glyph < end | |
6fc556fd | 8082 | && !INTEGERP (glyph->object) |
5f5c8ee5 GM |
8083 | && (!BUFFERP (glyph->object) |
8084 | || glyph->charpos < pt_old)) | |
8085 | { | |
8086 | x += glyph->pixel_width; | |
8087 | ++glyph; | |
8088 | } | |
8089 | ||
8090 | w->cursor.hpos = glyph - row->glyphs[TEXT_AREA]; | |
8091 | w->cursor.x = x; | |
8092 | w->cursor.vpos = MATRIX_ROW_VPOS (row, matrix) + dvpos; | |
8093 | w->cursor.y = row->y + dy; | |
8094 | ||
8095 | if (w == XWINDOW (selected_window)) | |
8096 | { | |
8097 | if (!row->continued_p | |
8098 | && !MATRIX_ROW_CONTINUATION_LINE_P (row) | |
8099 | && row->x == 0) | |
8100 | { | |
8101 | this_line_buffer = XBUFFER (w->buffer); | |
8102 | ||
8103 | CHARPOS (this_line_start_pos) | |
8104 | = MATRIX_ROW_START_CHARPOS (row) + delta; | |
8105 | BYTEPOS (this_line_start_pos) | |
8106 | = MATRIX_ROW_START_BYTEPOS (row) + delta_bytes; | |
8107 | ||
8108 | CHARPOS (this_line_end_pos) | |
8109 | = Z - (MATRIX_ROW_END_CHARPOS (row) + delta); | |
8110 | BYTEPOS (this_line_end_pos) | |
8111 | = Z_BYTE - (MATRIX_ROW_END_BYTEPOS (row) + delta_bytes); | |
8112 | ||
8113 | this_line_y = w->cursor.y; | |
8114 | this_line_pixel_height = row->height; | |
8115 | this_line_vpos = w->cursor.vpos; | |
8116 | this_line_start_x = row->x; | |
8117 | } | |
8118 | else | |
8119 | CHARPOS (this_line_start_pos) = 0; | |
8120 | } | |
8121 | } | |
8122 | ||
8123 | ||
8124 | /* Run window scroll functions, if any, for WINDOW with new window | |
756a3cb6 RS |
8125 | start STARTP. Sets the window start of WINDOW to that position. |
8126 | ||
8127 | We assume that the window's buffer is really current. */ | |
5f5c8ee5 GM |
8128 | |
8129 | static INLINE struct text_pos | |
8130 | run_window_scroll_functions (window, startp) | |
8131 | Lisp_Object window; | |
8132 | struct text_pos startp; | |
8133 | { | |
8134 | struct window *w = XWINDOW (window); | |
8135 | SET_MARKER_FROM_TEXT_POS (w->start, startp); | |
756a3cb6 RS |
8136 | |
8137 | if (current_buffer != XBUFFER (w->buffer)) | |
8138 | abort (); | |
8139 | ||
5f5c8ee5 GM |
8140 | if (!NILP (Vwindow_scroll_functions)) |
8141 | { | |
8142 | run_hook_with_args_2 (Qwindow_scroll_functions, window, | |
8143 | make_number (CHARPOS (startp))); | |
8144 | SET_TEXT_POS_FROM_MARKER (startp, w->start); | |
756a3cb6 RS |
8145 | /* In case the hook functions switch buffers. */ |
8146 | if (current_buffer != XBUFFER (w->buffer)) | |
8147 | set_buffer_internal_1 (XBUFFER (w->buffer)); | |
5f5c8ee5 | 8148 | } |
90adcf20 | 8149 | |
5f5c8ee5 GM |
8150 | return startp; |
8151 | } | |
8152 | ||
8153 | ||
8154 | /* Modify the desired matrix of window W and W->vscroll so that the | |
8155 | line containing the cursor is fully visible. */ | |
8156 | ||
8157 | static void | |
8158 | make_cursor_line_fully_visible (w) | |
8159 | struct window *w; | |
8160 | { | |
8161 | struct glyph_matrix *matrix; | |
8162 | struct glyph_row *row; | |
045dee35 | 8163 | int header_line_height; |
5f5c8ee5 GM |
8164 | |
8165 | /* It's not always possible to find the cursor, e.g, when a window | |
8166 | is full of overlay strings. Don't do anything in that case. */ | |
8167 | if (w->cursor.vpos < 0) | |
8168 | return; | |
8169 | ||
8170 | matrix = w->desired_matrix; | |
8171 | row = MATRIX_ROW (matrix, w->cursor.vpos); | |
8172 | ||
a943a5ca GM |
8173 | if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_TOP_P (w, row) |
8174 | /* The row may be partially visible at the top because we | |
8175 | already have chosen a vscroll to align the bottom of the | |
8176 | row with the bottom of the window. This happens for rows | |
8177 | taller than the window. */ | |
8178 | && row->y + row->height < window_box_height (w)) | |
5f5c8ee5 GM |
8179 | { |
8180 | int dy = row->height - row->visible_height; | |
8181 | w->vscroll = 0; | |
8182 | w->cursor.y += dy; | |
8183 | shift_glyph_matrix (w, matrix, 0, matrix->nrows, dy); | |
8184 | } | |
a943a5ca GM |
8185 | else if (MATRIX_ROW_PARTIALLY_VISIBLE_AT_BOTTOM_P (w, row) |
8186 | /* The row may be partially visible at the bottom because | |
8187 | we chose a vscroll to align the row's top with the | |
8188 | window's top. This happens for rows taller than the | |
8189 | window. */ | |
8190 | && row->y > WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w)) | |
5f5c8ee5 GM |
8191 | { |
8192 | int dy = - (row->height - row->visible_height); | |
8193 | w->vscroll = dy; | |
8194 | w->cursor.y += dy; | |
8195 | shift_glyph_matrix (w, matrix, 0, matrix->nrows, dy); | |
8196 | } | |
8197 | ||
8198 | /* When we change the cursor y-position of the selected window, | |
8199 | change this_line_y as well so that the display optimization for | |
8200 | the cursor line of the selected window in redisplay_internal uses | |
8201 | the correct y-position. */ | |
8202 | if (w == XWINDOW (selected_window)) | |
8203 | this_line_y = w->cursor.y; | |
8204 | } | |
8205 | ||
8206 | ||
8207 | /* Try scrolling PT into view in window WINDOW. JUST_THIS_ONE_P | |
8208 | non-zero means only WINDOW is redisplayed in redisplay_internal. | |
8209 | TEMP_SCROLL_STEP has the same meaning as scroll_step, and is used | |
8210 | in redisplay_window to bring a partially visible line into view in | |
8211 | the case that only the cursor has moved. | |
8212 | ||
8213 | Value is | |
8214 | ||
8215 | 1 if scrolling succeeded | |
8216 | ||
8217 | 0 if scrolling didn't find point. | |
8218 | ||
8219 | -1 if new fonts have been loaded so that we must interrupt | |
8220 | redisplay, adjust glyph matrices, and try again. */ | |
8221 | ||
8222 | static int | |
8223 | try_scrolling (window, just_this_one_p, scroll_conservatively, | |
8224 | scroll_step, temp_scroll_step) | |
8225 | Lisp_Object window; | |
8226 | int just_this_one_p; | |
8227 | int scroll_conservatively, scroll_step; | |
8228 | int temp_scroll_step; | |
8229 | { | |
8230 | struct window *w = XWINDOW (window); | |
8231 | struct frame *f = XFRAME (w->frame); | |
8232 | struct text_pos scroll_margin_pos; | |
8233 | struct text_pos pos; | |
8234 | struct text_pos startp; | |
8235 | struct it it; | |
8236 | Lisp_Object window_end; | |
8237 | int this_scroll_margin; | |
8238 | int dy = 0; | |
8239 | int scroll_max; | |
8240 | int line_height, rc; | |
8241 | int amount_to_scroll = 0; | |
8242 | Lisp_Object aggressive; | |
8243 | int height; | |
8244 | ||
8245 | #if GLYPH_DEBUG | |
8246 | debug_method_add (w, "try_scrolling"); | |
78614721 | 8247 | #endif |
5f5c8ee5 GM |
8248 | |
8249 | SET_TEXT_POS_FROM_MARKER (startp, w->start); | |
8250 | ||
8251 | /* Compute scroll margin height in pixels. We scroll when point is | |
8252 | within this distance from the top or bottom of the window. */ | |
8253 | if (scroll_margin > 0) | |
90adcf20 | 8254 | { |
5f5c8ee5 GM |
8255 | this_scroll_margin = min (scroll_margin, XINT (w->height) / 4); |
8256 | this_scroll_margin *= CANON_Y_UNIT (f); | |
8257 | } | |
8258 | else | |
8259 | this_scroll_margin = 0; | |
8260 | ||
8261 | /* Compute how much we should try to scroll maximally to bring point | |
8262 | into view. */ | |
8263 | if (scroll_step) | |
8264 | scroll_max = scroll_step; | |
8265 | else if (scroll_conservatively) | |
8266 | scroll_max = scroll_conservatively; | |
8267 | else if (temp_scroll_step) | |
8268 | scroll_max = temp_scroll_step; | |
8269 | else if (NUMBERP (current_buffer->scroll_down_aggressively) | |
8270 | || NUMBERP (current_buffer->scroll_up_aggressively)) | |
8271 | /* We're trying to scroll because of aggressive scrolling | |
8272 | but no scroll_step is set. Choose an arbitrary one. Maybe | |
8273 | there should be a variable for this. */ | |
8274 | scroll_max = 10; | |
8275 | else | |
8276 | scroll_max = 0; | |
8277 | scroll_max *= CANON_Y_UNIT (f); | |
8278 | ||
8279 | /* Decide whether we have to scroll down. Start at the window end | |
8280 | and move this_scroll_margin up to find the position of the scroll | |
8281 | margin. */ | |
8282 | window_end = Fwindow_end (window, Qt); | |
8283 | CHARPOS (scroll_margin_pos) = XINT (window_end); | |
8284 | BYTEPOS (scroll_margin_pos) = CHAR_TO_BYTE (CHARPOS (scroll_margin_pos)); | |
8285 | if (this_scroll_margin) | |
8286 | { | |
8287 | start_display (&it, w, scroll_margin_pos); | |
8288 | move_it_vertically (&it, - this_scroll_margin); | |
8289 | scroll_margin_pos = it.current.pos; | |
8290 | } | |
8291 | ||
8292 | if (PT >= CHARPOS (scroll_margin_pos)) | |
8293 | { | |
8294 | int y0; | |
8295 | ||
8296 | /* Point is in the scroll margin at the bottom of the window, or | |
8297 | below. Compute a new window start that makes point visible. */ | |
8298 | ||
8299 | /* Compute the distance from the scroll margin to PT. | |
8300 | Give up if the distance is greater than scroll_max. */ | |
8301 | start_display (&it, w, scroll_margin_pos); | |
8302 | y0 = it.current_y; | |
8303 | move_it_to (&it, PT, 0, it.last_visible_y, -1, | |
8304 | MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); | |
8305 | line_height = (it.max_ascent + it.max_descent | |
8306 | ? it.max_ascent + it.max_descent | |
8307 | : last_height); | |
8308 | dy = it.current_y + line_height - y0; | |
8309 | if (dy > scroll_max) | |
8310 | return 0; | |
8311 | ||
8312 | /* Move the window start down. If scrolling conservatively, | |
8313 | move it just enough down to make point visible. If | |
8314 | scroll_step is set, move it down by scroll_step. */ | |
8315 | start_display (&it, w, startp); | |
8316 | ||
8317 | if (scroll_conservatively) | |
8318 | amount_to_scroll = dy; | |
8319 | else if (scroll_step || temp_scroll_step) | |
8320 | amount_to_scroll = scroll_max; | |
8321 | else | |
90adcf20 | 8322 | { |
5f5c8ee5 GM |
8323 | aggressive = current_buffer->scroll_down_aggressively; |
8324 | height = (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w) | |
045dee35 | 8325 | - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w)); |
5f5c8ee5 GM |
8326 | if (NUMBERP (aggressive)) |
8327 | amount_to_scroll = XFLOATINT (aggressive) * height; | |
8328 | } | |
a2725ab2 | 8329 | |
5f5c8ee5 GM |
8330 | if (amount_to_scroll <= 0) |
8331 | return 0; | |
a2725ab2 | 8332 | |
5f5c8ee5 GM |
8333 | move_it_vertically (&it, amount_to_scroll); |
8334 | startp = it.current.pos; | |
8335 | } | |
8336 | else | |
8337 | { | |
8338 | /* See if point is inside the scroll margin at the top of the | |
8339 | window. */ | |
8340 | scroll_margin_pos = startp; | |
8341 | if (this_scroll_margin) | |
8342 | { | |
8343 | start_display (&it, w, startp); | |
8344 | move_it_vertically (&it, this_scroll_margin); | |
8345 | scroll_margin_pos = it.current.pos; | |
8346 | } | |
8347 | ||
8348 | if (PT < CHARPOS (scroll_margin_pos)) | |
8349 | { | |
8350 | /* Point is in the scroll margin at the top of the window or | |
8351 | above what is displayed in the window. */ | |
8352 | int y0; | |
8353 | ||
8354 | /* Compute the vertical distance from PT to the scroll | |
8355 | margin position. Give up if distance is greater than | |
8356 | scroll_max. */ | |
8357 | SET_TEXT_POS (pos, PT, PT_BYTE); | |
8358 | start_display (&it, w, pos); | |
8359 | y0 = it.current_y; | |
8360 | move_it_to (&it, CHARPOS (scroll_margin_pos), 0, | |
8361 | it.last_visible_y, -1, | |
8362 | MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); | |
8363 | dy = it.current_y - y0; | |
8364 | if (dy > scroll_max) | |
8365 | return 0; | |
8366 | ||
8367 | /* Compute new window start. */ | |
8368 | start_display (&it, w, startp); | |
8369 | ||
8370 | if (scroll_conservatively) | |
8371 | amount_to_scroll = dy; | |
8372 | else if (scroll_step || temp_scroll_step) | |
8373 | amount_to_scroll = scroll_max; | |
538f13d4 | 8374 | else |
5f5c8ee5 GM |
8375 | { |
8376 | aggressive = current_buffer->scroll_up_aggressively; | |
8377 | height = (WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (w) | |
045dee35 | 8378 | - WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w)); |
5f5c8ee5 GM |
8379 | if (NUMBERP (aggressive)) |
8380 | amount_to_scroll = XFLOATINT (aggressive) * height; | |
8381 | } | |
a2725ab2 | 8382 | |
5f5c8ee5 GM |
8383 | if (amount_to_scroll <= 0) |
8384 | return 0; | |
8385 | ||
8386 | move_it_vertically (&it, - amount_to_scroll); | |
8387 | startp = it.current.pos; | |
90adcf20 RS |
8388 | } |
8389 | } | |
a2889657 | 8390 | |
5f5c8ee5 GM |
8391 | /* Run window scroll functions. */ |
8392 | startp = run_window_scroll_functions (window, startp); | |
90adcf20 | 8393 | |
5f5c8ee5 GM |
8394 | /* Display the window. Give up if new fonts are loaded, or if point |
8395 | doesn't appear. */ | |
8396 | if (!try_window (window, startp)) | |
8397 | rc = -1; | |
8398 | else if (w->cursor.vpos < 0) | |
8399 | { | |
8400 | clear_glyph_matrix (w->desired_matrix); | |
8401 | rc = 0; | |
8402 | } | |
8403 | else | |
8404 | { | |
8405 | /* Maybe forget recorded base line for line number display. */ | |
8406 | if (!just_this_one_p | |
8407 | || current_buffer->clip_changed | |
9142dd5b | 8408 | || BEG_UNCHANGED < CHARPOS (startp)) |
5f5c8ee5 GM |
8409 | w->base_line_number = Qnil; |
8410 | ||
8411 | /* If cursor ends up on a partially visible line, shift display | |
8412 | lines up or down. */ | |
8413 | make_cursor_line_fully_visible (w); | |
8414 | rc = 1; | |
8415 | } | |
8416 | ||
8417 | return rc; | |
a2889657 JB |
8418 | } |
8419 | ||
5f5c8ee5 GM |
8420 | |
8421 | /* Compute a suitable window start for window W if display of W starts | |
8422 | on a continuation line. Value is non-zero if a new window start | |
8423 | was computed. | |
8424 | ||
8425 | The new window start will be computed, based on W's width, starting | |
8426 | from the start of the continued line. It is the start of the | |
8427 | screen line with the minimum distance from the old start W->start. */ | |
8428 | ||
8429 | static int | |
8430 | compute_window_start_on_continuation_line (w) | |
8431 | struct window *w; | |
1f1ff51d | 8432 | { |
5f5c8ee5 GM |
8433 | struct text_pos pos, start_pos; |
8434 | int window_start_changed_p = 0; | |
1f1ff51d | 8435 | |
5f5c8ee5 | 8436 | SET_TEXT_POS_FROM_MARKER (start_pos, w->start); |
1f1ff51d | 8437 | |
5f5c8ee5 GM |
8438 | /* If window start is on a continuation line... Window start may be |
8439 | < BEGV in case there's invisible text at the start of the | |
8440 | buffer (M-x rmail, for example). */ | |
8441 | if (CHARPOS (start_pos) > BEGV | |
8442 | && FETCH_BYTE (BYTEPOS (start_pos) - 1) != '\n') | |
1f1ff51d | 8443 | { |
5f5c8ee5 GM |
8444 | struct it it; |
8445 | struct glyph_row *row; | |
f3751a65 GM |
8446 | |
8447 | /* Handle the case that the window start is out of range. */ | |
8448 | if (CHARPOS (start_pos) < BEGV) | |
8449 | SET_TEXT_POS (start_pos, BEGV, BEGV_BYTE); | |
8450 | else if (CHARPOS (start_pos) > ZV) | |
8451 | SET_TEXT_POS (start_pos, ZV, ZV_BYTE); | |
5f5c8ee5 GM |
8452 | |
8453 | /* Find the start of the continued line. This should be fast | |
8454 | because scan_buffer is fast (newline cache). */ | |
045dee35 | 8455 | row = w->desired_matrix->rows + (WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0); |
5f5c8ee5 GM |
8456 | init_iterator (&it, w, CHARPOS (start_pos), BYTEPOS (start_pos), |
8457 | row, DEFAULT_FACE_ID); | |
8458 | reseat_at_previous_visible_line_start (&it); | |
8459 | ||
8460 | /* If the line start is "too far" away from the window start, | |
8461 | say it takes too much time to compute a new window start. */ | |
8462 | if (CHARPOS (start_pos) - IT_CHARPOS (it) | |
8463 | < XFASTINT (w->height) * XFASTINT (w->width)) | |
8464 | { | |
8465 | int min_distance, distance; | |
8466 | ||
8467 | /* Move forward by display lines to find the new window | |
8468 | start. If window width was enlarged, the new start can | |
8469 | be expected to be > the old start. If window width was | |
8470 | decreased, the new window start will be < the old start. | |
8471 | So, we're looking for the display line start with the | |
8472 | minimum distance from the old window start. */ | |
8473 | pos = it.current.pos; | |
8474 | min_distance = INFINITY; | |
8475 | while ((distance = abs (CHARPOS (start_pos) - IT_CHARPOS (it))), | |
8476 | distance < min_distance) | |
8477 | { | |
8478 | min_distance = distance; | |
8479 | pos = it.current.pos; | |
8480 | move_it_by_lines (&it, 1, 0); | |
8481 | } | |
8482 | ||
8483 | /* Set the window start there. */ | |
8484 | SET_MARKER_FROM_TEXT_POS (w->start, pos); | |
8485 | window_start_changed_p = 1; | |
8486 | } | |
1f1ff51d | 8487 | } |
5f5c8ee5 GM |
8488 | |
8489 | return window_start_changed_p; | |
1f1ff51d KH |
8490 | } |
8491 | ||
5f5c8ee5 GM |
8492 | |
8493 | /* Redisplay leaf window WINDOW. JUST_THIS_ONE_P non-zero means only | |
8494 | selected_window is redisplayed. */ | |
90adcf20 | 8495 | |
a2889657 | 8496 | static void |
5f5c8ee5 | 8497 | redisplay_window (window, just_this_one_p) |
a2889657 | 8498 | Lisp_Object window; |
5f5c8ee5 | 8499 | int just_this_one_p; |
a2889657 | 8500 | { |
5f5c8ee5 GM |
8501 | struct window *w = XWINDOW (window); |
8502 | struct frame *f = XFRAME (w->frame); | |
8503 | struct buffer *buffer = XBUFFER (w->buffer); | |
a2889657 | 8504 | struct buffer *old = current_buffer; |
5f5c8ee5 | 8505 | struct text_pos lpoint, opoint, startp; |
e481f960 | 8506 | int update_mode_line; |
5f5c8ee5 GM |
8507 | int tem; |
8508 | struct it it; | |
8509 | /* Record it now because it's overwritten. */ | |
8510 | int current_matrix_up_to_date_p = 0; | |
5ba50c51 | 8511 | int really_switched_buffer = 0; |
5f5c8ee5 | 8512 | int temp_scroll_step = 0; |
2e54982e | 8513 | int count = specpdl_ptr - specpdl; |
a2889657 | 8514 | |
5f5c8ee5 GM |
8515 | SET_TEXT_POS (lpoint, PT, PT_BYTE); |
8516 | opoint = lpoint; | |
a2889657 | 8517 | |
5f5c8ee5 GM |
8518 | /* W must be a leaf window here. */ |
8519 | xassert (!NILP (w->buffer)); | |
8520 | #if GLYPH_DEBUG | |
8521 | *w->desired_matrix->method = 0; | |
8522 | #endif | |
2e54982e RS |
8523 | |
8524 | specbind (Qinhibit_point_motion_hooks, Qt); | |
9142dd5b GM |
8525 | |
8526 | reconsider_clip_changes (w, buffer); | |
8527 | ||
5f5c8ee5 GM |
8528 | /* Has the mode line to be updated? */ |
8529 | update_mode_line = (!NILP (w->update_mode_line) | |
8530 | || update_mode_lines | |
8531 | || buffer->clip_changed); | |
8de2d90b JB |
8532 | |
8533 | if (MINI_WINDOW_P (w)) | |
8534 | { | |
5f5c8ee5 | 8535 | if (w == XWINDOW (echo_area_window) |
c6e89d6c | 8536 | && !NILP (echo_area_buffer[0])) |
5f5c8ee5 GM |
8537 | { |
8538 | if (update_mode_line) | |
8539 | /* We may have to update a tty frame's menu bar or a | |
e037b9ec | 8540 | tool-bar. Example `M-x C-h C-h C-g'. */ |
5f5c8ee5 GM |
8541 | goto finish_menu_bars; |
8542 | else | |
8543 | /* We've already displayed the echo area glyphs in this window. */ | |
8544 | goto finish_scroll_bars; | |
8545 | } | |
73af359d | 8546 | else if (w != XWINDOW (minibuf_window)) |
8de2d90b | 8547 | { |
5f5c8ee5 GM |
8548 | /* W is a mini-buffer window, but it's not the currently |
8549 | active one, so clear it. */ | |
8550 | int yb = window_text_bottom_y (w); | |
8551 | struct glyph_row *row; | |
8552 | int y; | |
8553 | ||
8554 | for (y = 0, row = w->desired_matrix->rows; | |
8555 | y < yb; | |
8556 | y += row->height, ++row) | |
8557 | blank_row (w, row, y); | |
88f22aff | 8558 | goto finish_scroll_bars; |
8de2d90b JB |
8559 | } |
8560 | } | |
a2889657 | 8561 | |
5f5c8ee5 GM |
8562 | /* Otherwise set up data on this window; select its buffer and point |
8563 | value. */ | |
e481f960 | 8564 | if (update_mode_line) |
5ba50c51 | 8565 | { |
5f5c8ee5 GM |
8566 | /* Really select the buffer, for the sake of buffer-local |
8567 | variables. */ | |
5ba50c51 RS |
8568 | set_buffer_internal_1 (XBUFFER (w->buffer)); |
8569 | really_switched_buffer = 1; | |
8570 | } | |
e481f960 RS |
8571 | else |
8572 | set_buffer_temp (XBUFFER (w->buffer)); | |
5f5c8ee5 GM |
8573 | SET_TEXT_POS (opoint, PT, PT_BYTE); |
8574 | ||
8575 | current_matrix_up_to_date_p | |
8576 | = (!NILP (w->window_end_valid) | |
8577 | && !current_buffer->clip_changed | |
8578 | && XFASTINT (w->last_modified) >= MODIFF | |
8579 | && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF); | |
e481f960 | 8580 | |
5f5c8ee5 GM |
8581 | /* When windows_or_buffers_changed is non-zero, we can't rely on |
8582 | the window end being valid, so set it to nil there. */ | |
8583 | if (windows_or_buffers_changed) | |
8584 | { | |
8585 | /* If window starts on a continuation line, maybe adjust the | |
8586 | window start in case the window's width changed. */ | |
8587 | if (XMARKER (w->start)->buffer == current_buffer) | |
8588 | compute_window_start_on_continuation_line (w); | |
8589 | ||
8590 | w->window_end_valid = Qnil; | |
8591 | } | |
12adba34 | 8592 | |
5f5c8ee5 GM |
8593 | /* Some sanity checks. */ |
8594 | CHECK_WINDOW_END (w); | |
8595 | if (Z == Z_BYTE && CHARPOS (opoint) != BYTEPOS (opoint)) | |
12adba34 | 8596 | abort (); |
5f5c8ee5 | 8597 | if (BYTEPOS (opoint) < CHARPOS (opoint)) |
12adba34 | 8598 | abort (); |
a2889657 | 8599 | |
28995e67 RS |
8600 | /* If %c is in mode line, update it if needed. */ |
8601 | if (!NILP (w->column_number_displayed) | |
8602 | /* This alternative quickly identifies a common case | |
8603 | where no change is needed. */ | |
8604 | && !(PT == XFASTINT (w->last_point) | |
8850a573 RS |
8605 | && XFASTINT (w->last_modified) >= MODIFF |
8606 | && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF) | |
28995e67 RS |
8607 | && XFASTINT (w->column_number_displayed) != current_column ()) |
8608 | update_mode_line = 1; | |
8609 | ||
5f5c8ee5 GM |
8610 | /* Count number of windows showing the selected buffer. An indirect |
8611 | buffer counts as its base buffer. */ | |
8612 | if (!just_this_one_p) | |
42640f83 RS |
8613 | { |
8614 | struct buffer *current_base, *window_base; | |
8615 | current_base = current_buffer; | |
8616 | window_base = XBUFFER (XWINDOW (selected_window)->buffer); | |
8617 | if (current_base->base_buffer) | |
8618 | current_base = current_base->base_buffer; | |
8619 | if (window_base->base_buffer) | |
8620 | window_base = window_base->base_buffer; | |
8621 | if (current_base == window_base) | |
8622 | buffer_shared++; | |
8623 | } | |
a2889657 | 8624 | |
5f5c8ee5 GM |
8625 | /* Point refers normally to the selected window. For any other |
8626 | window, set up appropriate value. */ | |
a2889657 JB |
8627 | if (!EQ (window, selected_window)) |
8628 | { | |
12adba34 RS |
8629 | int new_pt = XMARKER (w->pointm)->charpos; |
8630 | int new_pt_byte = marker_byte_position (w->pointm); | |
f67a0f51 | 8631 | if (new_pt < BEGV) |
a2889657 | 8632 | { |
f67a0f51 | 8633 | new_pt = BEGV; |
12adba34 RS |
8634 | new_pt_byte = BEGV_BYTE; |
8635 | set_marker_both (w->pointm, Qnil, BEGV, BEGV_BYTE); | |
a2889657 | 8636 | } |
f67a0f51 | 8637 | else if (new_pt > (ZV - 1)) |
a2889657 | 8638 | { |
f67a0f51 | 8639 | new_pt = ZV; |
12adba34 RS |
8640 | new_pt_byte = ZV_BYTE; |
8641 | set_marker_both (w->pointm, Qnil, ZV, ZV_BYTE); | |
a2889657 | 8642 | } |
5f5c8ee5 | 8643 | |
f67a0f51 | 8644 | /* We don't use SET_PT so that the point-motion hooks don't run. */ |
12adba34 | 8645 | TEMP_SET_PT_BOTH (new_pt, new_pt_byte); |
a2889657 JB |
8646 | } |
8647 | ||
f4faa47c | 8648 | /* If any of the character widths specified in the display table |
5f5c8ee5 GM |
8649 | have changed, invalidate the width run cache. It's true that |
8650 | this may be a bit late to catch such changes, but the rest of | |
f4faa47c JB |
8651 | redisplay goes (non-fatally) haywire when the display table is |
8652 | changed, so why should we worry about doing any better? */ | |
8653 | if (current_buffer->width_run_cache) | |
8654 | { | |
f908610f | 8655 | struct Lisp_Char_Table *disptab = buffer_display_table (); |
f4faa47c JB |
8656 | |
8657 | if (! disptab_matches_widthtab (disptab, | |
8658 | XVECTOR (current_buffer->width_table))) | |
8659 | { | |
8660 | invalidate_region_cache (current_buffer, | |
8661 | current_buffer->width_run_cache, | |
8662 | BEG, Z); | |
8663 | recompute_width_table (current_buffer, disptab); | |
8664 | } | |
8665 | } | |
8666 | ||
a2889657 | 8667 | /* If window-start is screwed up, choose a new one. */ |
a2889657 JB |
8668 | if (XMARKER (w->start)->buffer != current_buffer) |
8669 | goto recenter; | |
8670 | ||
5f5c8ee5 | 8671 | SET_TEXT_POS_FROM_MARKER (startp, w->start); |
a2889657 | 8672 | |
cf0df6ab RS |
8673 | /* If someone specified a new starting point but did not insist, |
8674 | check whether it can be used. */ | |
cfad01b4 GM |
8675 | if (!NILP (w->optional_new_start) |
8676 | && CHARPOS (startp) >= BEGV | |
8677 | && CHARPOS (startp) <= ZV) | |
cf0df6ab RS |
8678 | { |
8679 | w->optional_new_start = Qnil; | |
5f5c8ee5 GM |
8680 | /* This takes a mini-buffer prompt into account. */ |
8681 | start_display (&it, w, startp); | |
8682 | move_it_to (&it, PT, 0, it.last_visible_y, -1, | |
8683 | MOVE_TO_POS | MOVE_TO_X | MOVE_TO_Y); | |
8684 | if (IT_CHARPOS (it) == PT) | |
cf0df6ab RS |
8685 | w->force_start = Qt; |
8686 | } | |
8687 | ||
8de2d90b | 8688 | /* Handle case where place to start displaying has been specified, |
aa6d10fa | 8689 | unless the specified location is outside the accessible range. */ |
9472f927 GM |
8690 | if (!NILP (w->force_start) |
8691 | || w->frozen_window_start_p) | |
a2889657 | 8692 | { |
e63574d7 | 8693 | w->force_start = Qnil; |
5f5c8ee5 | 8694 | w->vscroll = 0; |
b5174a51 | 8695 | w->window_end_valid = Qnil; |
5f5c8ee5 GM |
8696 | |
8697 | /* Forget any recorded base line for line number display. */ | |
8698 | if (!current_matrix_up_to_date_p | |
8699 | || current_buffer->clip_changed) | |
8700 | w->base_line_number = Qnil; | |
8701 | ||
75c43375 RS |
8702 | /* Redisplay the mode line. Select the buffer properly for that. |
8703 | Also, run the hook window-scroll-functions | |
8704 | because we have scrolled. */ | |
e63574d7 RS |
8705 | /* Note, we do this after clearing force_start because |
8706 | if there's an error, it is better to forget about force_start | |
8707 | than to get into an infinite loop calling the hook functions | |
8708 | and having them get more errors. */ | |
75c43375 RS |
8709 | if (!update_mode_line |
8710 | || ! NILP (Vwindow_scroll_functions)) | |
e481f960 | 8711 | { |
5ba50c51 RS |
8712 | if (!really_switched_buffer) |
8713 | { | |
8714 | set_buffer_temp (old); | |
8715 | set_buffer_internal_1 (XBUFFER (w->buffer)); | |
5f5c8ee5 | 8716 | really_switched_buffer = 1; |
5ba50c51 | 8717 | } |
5f5c8ee5 | 8718 | |
e481f960 RS |
8719 | update_mode_line = 1; |
8720 | w->update_mode_line = Qt; | |
5f5c8ee5 | 8721 | startp = run_window_scroll_functions (window, startp); |
e481f960 | 8722 | } |
5f5c8ee5 | 8723 | |
c2213350 | 8724 | XSETFASTINT (w->last_modified, 0); |
8850a573 | 8725 | XSETFASTINT (w->last_overlay_modified, 0); |
5f5c8ee5 GM |
8726 | if (CHARPOS (startp) < BEGV) |
8727 | SET_TEXT_POS (startp, BEGV, BEGV_BYTE); | |
8728 | else if (CHARPOS (startp) > ZV) | |
8729 | SET_TEXT_POS (startp, ZV, ZV_BYTE); | |
8730 | ||
8731 | /* Redisplay, then check if cursor has been set during the | |
8732 | redisplay. Give up if new fonts were loaded. */ | |
8733 | if (!try_window (window, startp)) | |
8734 | { | |
8735 | w->force_start = Qt; | |
8736 | clear_glyph_matrix (w->desired_matrix); | |
8737 | goto restore_buffers; | |
8738 | } | |
8739 | ||
9472f927 | 8740 | if (w->cursor.vpos < 0 && !w->frozen_window_start_p) |
5f5c8ee5 GM |
8741 | { |
8742 | /* If point does not appear, or on a line that is not fully | |
8743 | visible, move point so it does appear. The desired | |
8744 | matrix has been built above, so we can use it. */ | |
8745 | int height = window_box_height (w) / 2; | |
8746 | struct glyph_row *row = MATRIX_ROW (w->desired_matrix, 0); | |
8747 | ||
8748 | while (row->y < height) | |
8749 | ++row; | |
8750 | ||
8751 | TEMP_SET_PT_BOTH (MATRIX_ROW_START_CHARPOS (row), | |
8752 | MATRIX_ROW_START_BYTEPOS (row)); | |
8753 | ||
90adcf20 | 8754 | if (w != XWINDOW (selected_window)) |
12adba34 | 8755 | set_marker_both (w->pointm, Qnil, PT, PT_BYTE); |
5f5c8ee5 GM |
8756 | else if (current_buffer == old) |
8757 | SET_TEXT_POS (lpoint, PT, PT_BYTE); | |
8758 | ||
8759 | set_cursor_from_row (w, row, w->desired_matrix, 0, 0, 0, 0); | |
8760 | ||
8761 | /* If we are highlighting the region, then we just changed | |
8762 | the region, so redisplay to show it. */ | |
df0b5ea1 RS |
8763 | if (!NILP (Vtransient_mark_mode) |
8764 | && !NILP (current_buffer->mark_active)) | |
6f27fa9b | 8765 | { |
5f5c8ee5 GM |
8766 | clear_glyph_matrix (w->desired_matrix); |
8767 | if (!try_window (window, startp)) | |
8768 | goto restore_buffers; | |
6f27fa9b | 8769 | } |
a2889657 | 8770 | } |
5f5c8ee5 GM |
8771 | |
8772 | make_cursor_line_fully_visible (w); | |
8773 | #if GLYPH_DEBUG | |
8774 | debug_method_add (w, "forced window start"); | |
8775 | #endif | |
a2889657 JB |
8776 | goto done; |
8777 | } | |
8778 | ||
5f5c8ee5 GM |
8779 | /* Handle case where text has not changed, only point, and it has |
8780 | not moved off the frame. */ | |
8781 | if (current_matrix_up_to_date_p | |
8782 | /* Point may be in this window. */ | |
8783 | && PT >= CHARPOS (startp) | |
8784 | /* If we don't check this, we are called to move the cursor in a | |
8785 | horizontally split window with a current matrix that doesn't | |
8786 | fit the display. */ | |
8787 | && !windows_or_buffers_changed | |
8788 | /* Selective display hasn't changed. */ | |
8789 | && !current_buffer->clip_changed | |
b1aa6cb3 RS |
8790 | /* If force-mode-line-update was called, really redisplay; |
8791 | that's how redisplay is forced after e.g. changing | |
8792 | buffer-invisibility-spec. */ | |
632ab665 | 8793 | && NILP (w->update_mode_line) |
5f5c8ee5 GM |
8794 | /* Can't use this case if highlighting a region. When a |
8795 | region exists, cursor movement has to do more than just | |
8796 | set the cursor. */ | |
8797 | && !(!NILP (Vtransient_mark_mode) | |
8798 | && !NILP (current_buffer->mark_active)) | |
bd66d1ba | 8799 | && NILP (w->region_showing) |
8f897821 | 8800 | && NILP (Vshow_trailing_whitespace) |
5f5c8ee5 GM |
8801 | /* Right after splitting windows, last_point may be nil. */ |
8802 | && INTEGERP (w->last_point) | |
8803 | /* This code is not used for mini-buffer for the sake of the case | |
8804 | of redisplaying to replace an echo area message; since in | |
8805 | that case the mini-buffer contents per se are usually | |
8806 | unchanged. This code is of no real use in the mini-buffer | |
8807 | since the handling of this_line_start_pos, etc., in redisplay | |
8808 | handles the same cases. */ | |
d45de95b | 8809 | && !EQ (window, minibuf_window) |
5f5c8ee5 GM |
8810 | /* When splitting windows or for new windows, it happens that |
8811 | redisplay is called with a nil window_end_vpos or one being | |
8812 | larger than the window. This should really be fixed in | |
8813 | window.c. I don't have this on my list, now, so we do | |
8814 | approximately the same as the old redisplay code. --gerd. */ | |
8815 | && INTEGERP (w->window_end_vpos) | |
8816 | && XFASTINT (w->window_end_vpos) < w->current_matrix->nrows | |
8817 | && (FRAME_WINDOW_P (f) | |
8818 | || !MARKERP (Voverlay_arrow_position) | |
377dbd97 | 8819 | || current_buffer != XMARKER (Voverlay_arrow_position)->buffer)) |
a2889657 | 8820 | { |
5f5c8ee5 GM |
8821 | int this_scroll_margin; |
8822 | struct glyph_row *row; | |
8823 | int scroll_p; | |
a2889657 | 8824 | |
5f5c8ee5 GM |
8825 | #if GLYPH_DEBUG |
8826 | debug_method_add (w, "cursor movement"); | |
8827 | #endif | |
9afd2168 | 8828 | |
5f5c8ee5 GM |
8829 | /* Scroll if point within this distance from the top or bottom |
8830 | of the window. This is a pixel value. */ | |
8831 | this_scroll_margin = max (0, scroll_margin); | |
8832 | this_scroll_margin = min (this_scroll_margin, XFASTINT (w->height) / 4); | |
8833 | this_scroll_margin *= CANON_Y_UNIT (f); | |
8834 | ||
8835 | /* Start with the row the cursor was displayed during the last | |
8836 | not paused redisplay. Give up if that row is not valid. */ | |
8837 | if (w->last_cursor.vpos >= w->current_matrix->nrows) | |
8838 | goto try_to_scroll; | |
8839 | row = MATRIX_ROW (w->current_matrix, w->last_cursor.vpos); | |
8840 | if (row->mode_line_p) | |
8841 | ++row; | |
8842 | if (!row->enabled_p) | |
8843 | goto try_to_scroll; | |
8844 | ||
8845 | scroll_p = 0; | |
8846 | if (PT > XFASTINT (w->last_point)) | |
8847 | { | |
8848 | /* Point has moved forward. */ | |
8849 | int last_y = window_text_bottom_y (w) - this_scroll_margin; | |
8850 | ||
8851 | while ((MATRIX_ROW_END_CHARPOS (row) < PT | |
8852 | /* The end position of a row equals the start | |
8853 | position of the next row. If PT is there, we | |
8854 | would rather display it in the next line, except | |
8855 | when this line ends in ZV. */ | |
8856 | || (MATRIX_ROW_END_CHARPOS (row) == PT | |
8857 | && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row) | |
8858 | || !row->ends_at_zv_p))) | |
8859 | && MATRIX_ROW_BOTTOM_Y (row) < last_y) | |
8860 | { | |
8861 | xassert (row->enabled_p); | |
8862 | ++row; | |
8863 | } | |
9afd2168 | 8864 | |
5f5c8ee5 GM |
8865 | /* If within the scroll margin, scroll. Note that |
8866 | MATRIX_ROW_BOTTOM_Y gives the pixel position at which the | |
8867 | next line would be drawn, and that this_scroll_margin can | |
8868 | be zero. */ | |
8869 | if (MATRIX_ROW_BOTTOM_Y (row) > last_y | |
8870 | || PT > MATRIX_ROW_END_CHARPOS (row) | |
8871 | /* Line is completely visible last line in window and PT | |
8872 | is to be set in the next line. */ | |
8873 | || (MATRIX_ROW_BOTTOM_Y (row) == last_y | |
8874 | && PT == MATRIX_ROW_END_CHARPOS (row) | |
8875 | && !row->ends_at_zv_p | |
8876 | && !MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row))) | |
8877 | scroll_p = 1; | |
8878 | } | |
8879 | else if (PT < XFASTINT (w->last_point)) | |
a2889657 | 8880 | { |
5f5c8ee5 GM |
8881 | /* Cursor has to be moved backward. Note that PT >= |
8882 | CHARPOS (startp) because of the outer if-statement. */ | |
8883 | while (!row->mode_line_p | |
8884 | && (MATRIX_ROW_START_CHARPOS (row) > PT | |
8885 | || (MATRIX_ROW_START_CHARPOS (row) == PT | |
8886 | && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row))) | |
8887 | && (row->y > this_scroll_margin | |
8888 | || CHARPOS (startp) == BEGV)) | |
a2889657 | 8889 | { |
5f5c8ee5 GM |
8890 | xassert (row->enabled_p); |
8891 | --row; | |
a2889657 | 8892 | } |
abb4c08f | 8893 | |
5f5c8ee5 GM |
8894 | /* Consider the following case: Window starts at BEGV, there |
8895 | is invisible, intangible text at BEGV, so that display | |
8896 | starts at some point START > BEGV. It can happen that | |
8897 | we are called with PT somewhere between BEGV and START. | |
8898 | Try to handle that case. */ | |
8899 | if (row < w->current_matrix->rows | |
8900 | || row->mode_line_p) | |
8901 | { | |
8902 | row = w->current_matrix->rows; | |
8903 | if (row->mode_line_p) | |
8904 | ++row; | |
8905 | } | |
8906 | ||
8907 | /* Due to newlines in overlay strings, we may have to skip | |
8908 | forward over overlay strings. */ | |
8909 | while (MATRIX_ROW_END_CHARPOS (row) == PT | |
8910 | && MATRIX_ROW_ENDS_IN_OVERLAY_STRING_P (row) | |
8911 | && !row->ends_at_zv_p) | |
8912 | ++row; | |
8913 | ||
8914 | /* If within the scroll margin, scroll. */ | |
8915 | if (row->y < this_scroll_margin | |
8916 | && CHARPOS (startp) != BEGV) | |
8917 | scroll_p = 1; | |
8918 | } | |
8919 | ||
8920 | /* if PT is not in the glyph row, give up. */ | |
8921 | if (PT < MATRIX_ROW_START_CHARPOS (row) | |
8922 | || PT > MATRIX_ROW_END_CHARPOS (row)) | |
8923 | goto try_to_scroll; | |
8924 | ||
8925 | /* If we end up in a partially visible line, let's make it fully | |
8926 | visible. This can be done most easily by using the existing | |
8927 | scrolling code. */ | |
8928 | if (MATRIX_ROW_PARTIALLY_VISIBLE_P (row)) | |
8929 | { | |
8930 | temp_scroll_step = 1; | |
8931 | goto try_to_scroll; | |
a2889657 | 8932 | } |
5f5c8ee5 GM |
8933 | else if (scroll_p) |
8934 | goto try_to_scroll; | |
8935 | ||
8936 | set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0); | |
8937 | goto done; | |
a2889657 | 8938 | } |
5f5c8ee5 | 8939 | |
a2889657 JB |
8940 | /* If current starting point was originally the beginning of a line |
8941 | but no longer is, find a new starting point. */ | |
265a9e55 | 8942 | else if (!NILP (w->start_at_line_beg) |
5f5c8ee5 GM |
8943 | && !(CHARPOS (startp) <= BEGV |
8944 | || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n')) | |
a2889657 | 8945 | { |
5f5c8ee5 GM |
8946 | #if GLYPH_DEBUG |
8947 | debug_method_add (w, "recenter 1"); | |
8948 | #endif | |
a2889657 JB |
8949 | goto recenter; |
8950 | } | |
5f5c8ee5 GM |
8951 | |
8952 | /* Try scrolling with try_window_id. */ | |
9142dd5b GM |
8953 | else if (/* Windows and buffers haven't changed. */ |
8954 | !windows_or_buffers_changed | |
5f5c8ee5 GM |
8955 | /* Window must be either use window-based redisplay or |
8956 | be full width. */ | |
8957 | && (FRAME_WINDOW_P (f) | |
c59c668a | 8958 | || (line_ins_del_ok && WINDOW_FULL_WIDTH_P (w))) |
5f5c8ee5 GM |
8959 | && !MINI_WINDOW_P (w) |
8960 | /* Point is not known NOT to appear in window. */ | |
8961 | && PT >= CHARPOS (startp) | |
a2889657 | 8962 | && XFASTINT (w->last_modified) |
5f5c8ee5 GM |
8963 | /* Window is not hscrolled. */ |
8964 | && XFASTINT (w->hscroll) == 0 | |
8965 | /* Selective display has not changed. */ | |
8966 | && !current_buffer->clip_changed | |
8967 | /* Current matrix is up to date. */ | |
8968 | && !NILP (w->window_end_valid) | |
8969 | /* Can't use this case if highlighting a region because | |
8970 | a cursor movement will do more than just set the cursor. */ | |
bd66d1ba RS |
8971 | && !(!NILP (Vtransient_mark_mode) |
8972 | && !NILP (current_buffer->mark_active)) | |
8973 | && NILP (w->region_showing) | |
8f897821 | 8974 | && NILP (Vshow_trailing_whitespace) |
5f5c8ee5 | 8975 | /* Overlay arrow position and string not changed. */ |
d45de95b | 8976 | && EQ (last_arrow_position, COERCE_MARKER (Voverlay_arrow_position)) |
a2889657 | 8977 | && EQ (last_arrow_string, Voverlay_arrow_string) |
5f5c8ee5 GM |
8978 | /* Value is > 0 if update has been done, it is -1 if we |
8979 | know that the same window start will not work. It is 0 | |
8980 | if unsuccessful for some other reason. */ | |
8981 | && (tem = try_window_id (w)) != 0) | |
a2889657 | 8982 | { |
5f5c8ee5 GM |
8983 | #if GLYPH_DEBUG |
8984 | debug_method_add (w, "try_window_id"); | |
8985 | #endif | |
8986 | ||
8987 | if (fonts_changed_p) | |
8988 | goto restore_buffers; | |
a2889657 JB |
8989 | if (tem > 0) |
8990 | goto done; | |
5f5c8ee5 GM |
8991 | /* Otherwise try_window_id has returned -1 which means that we |
8992 | don't want the alternative below this comment to execute. */ | |
a2889657 | 8993 | } |
5f5c8ee5 GM |
8994 | else if (CHARPOS (startp) >= BEGV |
8995 | && CHARPOS (startp) <= ZV | |
8996 | && PT >= CHARPOS (startp) | |
8997 | && (CHARPOS (startp) < ZV | |
e9874cee | 8998 | /* Avoid starting at end of buffer. */ |
5f5c8ee5 | 8999 | || CHARPOS (startp) == BEGV |
8850a573 RS |
9000 | || (XFASTINT (w->last_modified) >= MODIFF |
9001 | && XFASTINT (w->last_overlay_modified) >= OVERLAY_MODIFF))) | |
a2889657 | 9002 | { |
5f5c8ee5 GM |
9003 | #if GLYPH_DEBUG |
9004 | debug_method_add (w, "same window start"); | |
9005 | #endif | |
9006 | ||
9007 | /* Try to redisplay starting at same place as before. | |
9008 | If point has not moved off frame, accept the results. */ | |
9009 | if (!current_matrix_up_to_date_p | |
9010 | /* Don't use try_window_reusing_current_matrix in this case | |
15e26c76 GM |
9011 | because a window scroll function can have changed the |
9012 | buffer. */ | |
5f5c8ee5 GM |
9013 | || !NILP (Vwindow_scroll_functions) |
9014 | || MINI_WINDOW_P (w) | |
9015 | || !try_window_reusing_current_matrix (w)) | |
9016 | { | |
9017 | IF_DEBUG (debug_method_add (w, "1")); | |
9018 | try_window (window, startp); | |
9019 | } | |
9020 | ||
9021 | if (fonts_changed_p) | |
9022 | goto restore_buffers; | |
9023 | ||
9024 | if (w->cursor.vpos >= 0) | |
aa6d10fa | 9025 | { |
5f5c8ee5 GM |
9026 | if (!just_this_one_p |
9027 | || current_buffer->clip_changed | |
9142dd5b | 9028 | || BEG_UNCHANGED < CHARPOS (startp)) |
aa6d10fa RS |
9029 | /* Forget any recorded base line for line number display. */ |
9030 | w->base_line_number = Qnil; | |
5f5c8ee5 GM |
9031 | |
9032 | make_cursor_line_fully_visible (w); | |
aa6d10fa RS |
9033 | goto done; |
9034 | } | |
a2889657 | 9035 | else |
5f5c8ee5 | 9036 | clear_glyph_matrix (w->desired_matrix); |
a2889657 JB |
9037 | } |
9038 | ||
5f5c8ee5 GM |
9039 | try_to_scroll: |
9040 | ||
c2213350 | 9041 | XSETFASTINT (w->last_modified, 0); |
8850a573 | 9042 | XSETFASTINT (w->last_overlay_modified, 0); |
5f5c8ee5 | 9043 | |
e481f960 RS |
9044 | /* Redisplay the mode line. Select the buffer properly for that. */ |
9045 | if (!update_mode_line) | |
9046 | { | |
5ba50c51 RS |
9047 | if (!really_switched_buffer) |
9048 | { | |
9049 | set_buffer_temp (old); | |
9050 | set_buffer_internal_1 (XBUFFER (w->buffer)); | |
5f5c8ee5 | 9051 | really_switched_buffer = 1; |
5ba50c51 | 9052 | } |
e481f960 RS |
9053 | update_mode_line = 1; |
9054 | w->update_mode_line = Qt; | |
9055 | } | |
a2889657 | 9056 | |
5f5c8ee5 GM |
9057 | /* Try to scroll by specified few lines. */ |
9058 | if ((scroll_conservatively | |
9059 | || scroll_step | |
9060 | || temp_scroll_step | |
9061 | || NUMBERP (current_buffer->scroll_up_aggressively) | |
9062 | || NUMBERP (current_buffer->scroll_down_aggressively)) | |
09cacf9c | 9063 | && !current_buffer->clip_changed |
5f5c8ee5 GM |
9064 | && CHARPOS (startp) >= BEGV |
9065 | && CHARPOS (startp) <= ZV) | |
0789adb2 | 9066 | { |
5f5c8ee5 GM |
9067 | /* The function returns -1 if new fonts were loaded, 1 if |
9068 | successful, 0 if not successful. */ | |
9069 | int rc = try_scrolling (window, just_this_one_p, | |
9070 | scroll_conservatively, | |
9071 | scroll_step, | |
9072 | temp_scroll_step); | |
9073 | if (rc > 0) | |
9074 | goto done; | |
9075 | else if (rc < 0) | |
9076 | goto restore_buffers; | |
9077 | } | |
f9c8af06 | 9078 | |
5f5c8ee5 | 9079 | /* Finally, just choose place to start which centers point */ |
5936754e | 9080 | |
5f5c8ee5 | 9081 | recenter: |
44173109 | 9082 | |
5f5c8ee5 GM |
9083 | #if GLYPH_DEBUG |
9084 | debug_method_add (w, "recenter"); | |
9085 | #endif | |
0789adb2 | 9086 | |
5f5c8ee5 | 9087 | /* w->vscroll = 0; */ |
0789adb2 | 9088 | |
5f5c8ee5 GM |
9089 | /* Forget any previously recorded base line for line number display. */ |
9090 | if (!current_matrix_up_to_date_p | |
9091 | || current_buffer->clip_changed) | |
9092 | w->base_line_number = Qnil; | |
9093 | ||
9094 | /* Move backward half the height of the window. */ | |
9095 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
9096 | it.current_y = it.last_visible_y; | |
9097 | move_it_vertically_backward (&it, it.last_visible_y / 2); | |
9098 | xassert (IT_CHARPOS (it) >= BEGV); | |
9099 | ||
9100 | /* The function move_it_vertically_backward may move over more | |
9101 | than the specified y-distance. If it->w is small, e.g. a | |
9102 | mini-buffer window, we may end up in front of the window's | |
9103 | display area. Start displaying at the start of the line | |
9104 | containing PT in this case. */ | |
9105 | if (it.current_y <= 0) | |
9106 | { | |
9107 | init_iterator (&it, w, PT, PT_BYTE, NULL, DEFAULT_FACE_ID); | |
9108 | move_it_vertically (&it, 0); | |
9109 | xassert (IT_CHARPOS (it) <= PT); | |
9110 | it.current_y = 0; | |
0789adb2 RS |
9111 | } |
9112 | ||
5f5c8ee5 GM |
9113 | it.current_x = it.hpos = 0; |
9114 | ||
9115 | /* Set startp here explicitly in case that helps avoid an infinite loop | |
9116 | in case the window-scroll-functions functions get errors. */ | |
9117 | set_marker_both (w->start, Qnil, IT_CHARPOS (it), IT_BYTEPOS (it)); | |
9118 | ||
9119 | /* Run scroll hooks. */ | |
9120 | startp = run_window_scroll_functions (window, it.current.pos); | |
9121 | ||
9122 | /* Redisplay the window. */ | |
9123 | if (!current_matrix_up_to_date_p | |
9124 | || windows_or_buffers_changed | |
9125 | /* Don't use try_window_reusing_current_matrix in this case | |
9126 | because it can have changed the buffer. */ | |
9127 | || !NILP (Vwindow_scroll_functions) | |
9128 | || !just_this_one_p | |
9129 | || MINI_WINDOW_P (w) | |
9130 | || !try_window_reusing_current_matrix (w)) | |
9131 | try_window (window, startp); | |
9132 | ||
9133 | /* If new fonts have been loaded (due to fontsets), give up. We | |
9134 | have to start a new redisplay since we need to re-adjust glyph | |
9135 | matrices. */ | |
9136 | if (fonts_changed_p) | |
9137 | goto restore_buffers; | |
9138 | ||
9139 | /* If cursor did not appear assume that the middle of the window is | |
9140 | in the first line of the window. Do it again with the next line. | |
9141 | (Imagine a window of height 100, displaying two lines of height | |
9142 | 60. Moving back 50 from it->last_visible_y will end in the first | |
9143 | line.) */ | |
9144 | if (w->cursor.vpos < 0) | |
a2889657 | 9145 | { |
5f5c8ee5 GM |
9146 | if (!NILP (w->window_end_valid) |
9147 | && PT >= Z - XFASTINT (w->window_end_pos)) | |
a2889657 | 9148 | { |
5f5c8ee5 GM |
9149 | clear_glyph_matrix (w->desired_matrix); |
9150 | move_it_by_lines (&it, 1, 0); | |
9151 | try_window (window, it.current.pos); | |
a2889657 | 9152 | } |
5f5c8ee5 | 9153 | else if (PT < IT_CHARPOS (it)) |
a2889657 | 9154 | { |
5f5c8ee5 GM |
9155 | clear_glyph_matrix (w->desired_matrix); |
9156 | move_it_by_lines (&it, -1, 0); | |
9157 | try_window (window, it.current.pos); | |
9158 | } | |
9159 | else | |
9160 | { | |
9161 | /* Not much we can do about it. */ | |
a2889657 | 9162 | } |
a2889657 | 9163 | } |
010494d0 | 9164 | |
5f5c8ee5 GM |
9165 | /* Consider the following case: Window starts at BEGV, there is |
9166 | invisible, intangible text at BEGV, so that display starts at | |
9167 | some point START > BEGV. It can happen that we are called with | |
9168 | PT somewhere between BEGV and START. Try to handle that case. */ | |
9169 | if (w->cursor.vpos < 0) | |
835766b6 | 9170 | { |
5f5c8ee5 GM |
9171 | struct glyph_row *row = w->current_matrix->rows; |
9172 | if (row->mode_line_p) | |
9173 | ++row; | |
9174 | set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0); | |
835766b6 | 9175 | } |
5f5c8ee5 GM |
9176 | |
9177 | make_cursor_line_fully_visible (w); | |
b5174a51 | 9178 | |
74d481ac GM |
9179 | done: |
9180 | ||
5f5c8ee5 GM |
9181 | SET_TEXT_POS_FROM_MARKER (startp, w->start); |
9182 | w->start_at_line_beg = ((CHARPOS (startp) == BEGV | |
9183 | || FETCH_BYTE (BYTEPOS (startp) - 1) == '\n') | |
9184 | ? Qt : Qnil); | |
a2889657 | 9185 | |
5f5c8ee5 | 9186 | /* Display the mode line, if we must. */ |
e481f960 | 9187 | if ((update_mode_line |
aa6d10fa | 9188 | /* If window not full width, must redo its mode line |
5f5c8ee5 GM |
9189 | if (a) the window to its side is being redone and |
9190 | (b) we do a frame-based redisplay. This is a consequence | |
9191 | of how inverted lines are drawn in frame-based redisplay. */ | |
9192 | || (!just_this_one_p | |
9193 | && !FRAME_WINDOW_P (f) | |
9194 | && !WINDOW_FULL_WIDTH_P (w)) | |
9195 | /* Line number to display. */ | |
155ef550 | 9196 | || INTEGERP (w->base_line_pos) |
5f5c8ee5 | 9197 | /* Column number is displayed and different from the one displayed. */ |
155ef550 KH |
9198 | || (!NILP (w->column_number_displayed) |
9199 | && XFASTINT (w->column_number_displayed) != current_column ())) | |
5f5c8ee5 GM |
9200 | /* This means that the window has a mode line. */ |
9201 | && (WINDOW_WANTS_MODELINE_P (w) | |
045dee35 | 9202 | || WINDOW_WANTS_HEADER_LINE_P (w))) |
5ba50c51 | 9203 | { |
5f5c8ee5 GM |
9204 | display_mode_lines (w); |
9205 | ||
9206 | /* If mode line height has changed, arrange for a thorough | |
9207 | immediate redisplay using the correct mode line height. */ | |
9208 | if (WINDOW_WANTS_MODELINE_P (w) | |
9209 | && CURRENT_MODE_LINE_HEIGHT (w) != DESIRED_MODE_LINE_HEIGHT (w)) | |
5ba50c51 | 9210 | { |
5f5c8ee5 GM |
9211 | fonts_changed_p = 1; |
9212 | MATRIX_MODE_LINE_ROW (w->current_matrix)->height | |
9213 | = DESIRED_MODE_LINE_HEIGHT (w); | |
5ba50c51 | 9214 | } |
5f5c8ee5 GM |
9215 | |
9216 | /* If top line height has changed, arrange for a thorough | |
9217 | immediate redisplay using the correct mode line height. */ | |
045dee35 GM |
9218 | if (WINDOW_WANTS_HEADER_LINE_P (w) |
9219 | && CURRENT_HEADER_LINE_HEIGHT (w) != DESIRED_HEADER_LINE_HEIGHT (w)) | |
5f5c8ee5 GM |
9220 | { |
9221 | fonts_changed_p = 1; | |
045dee35 GM |
9222 | MATRIX_HEADER_LINE_ROW (w->current_matrix)->height |
9223 | = DESIRED_HEADER_LINE_HEIGHT (w); | |
5f5c8ee5 GM |
9224 | } |
9225 | ||
9226 | if (fonts_changed_p) | |
9227 | goto restore_buffers; | |
5ba50c51 | 9228 | } |
5f5c8ee5 GM |
9229 | |
9230 | if (!line_number_displayed | |
9231 | && !BUFFERP (w->base_line_pos)) | |
aa6d10fa RS |
9232 | { |
9233 | w->base_line_pos = Qnil; | |
9234 | w->base_line_number = Qnil; | |
9235 | } | |
a2889657 | 9236 | |
5f5c8ee5 GM |
9237 | finish_menu_bars: |
9238 | ||
7ce2c095 | 9239 | /* When we reach a frame's selected window, redo the frame's menu bar. */ |
e481f960 | 9240 | if (update_mode_line |
5f5c8ee5 GM |
9241 | && EQ (FRAME_SELECTED_WINDOW (f), window)) |
9242 | { | |
9243 | int redisplay_menu_p = 0; | |
9244 | ||
9245 | if (FRAME_WINDOW_P (f)) | |
9246 | { | |
dc937613 | 9247 | #if defined (USE_X_TOOLKIT) || defined (HAVE_NTGUI) |
5f5c8ee5 | 9248 | redisplay_menu_p = FRAME_EXTERNAL_MENU_BAR (f); |
76412d64 | 9249 | #else |
5f5c8ee5 | 9250 | redisplay_menu_p = FRAME_MENU_BAR_LINES (f) > 0; |
76412d64 | 9251 | #endif |
5f5c8ee5 GM |
9252 | } |
9253 | else | |
9254 | redisplay_menu_p = FRAME_MENU_BAR_LINES (f) > 0; | |
9255 | ||
9256 | if (redisplay_menu_p) | |
9257 | display_menu_bar (w); | |
9258 | ||
9259 | #ifdef HAVE_WINDOW_SYSTEM | |
e037b9ec GM |
9260 | if (WINDOWP (f->tool_bar_window) |
9261 | && (FRAME_TOOL_BAR_LINES (f) > 0 | |
9262 | || auto_resize_tool_bars_p)) | |
9263 | redisplay_tool_bar (f); | |
5f5c8ee5 GM |
9264 | #endif |
9265 | } | |
7ce2c095 | 9266 | |
88f22aff | 9267 | finish_scroll_bars: |
5f5c8ee5 | 9268 | |
88f22aff | 9269 | if (FRAME_HAS_VERTICAL_SCROLL_BARS (f)) |
30c566e4 | 9270 | { |
b1d1124b | 9271 | int start, end, whole; |
30c566e4 | 9272 | |
b1d1124b | 9273 | /* Calculate the start and end positions for the current window. |
3505ea70 JB |
9274 | At some point, it would be nice to choose between scrollbars |
9275 | which reflect the whole buffer size, with special markers | |
9276 | indicating narrowing, and scrollbars which reflect only the | |
9277 | visible region. | |
9278 | ||
5f5c8ee5 | 9279 | Note that mini-buffers sometimes aren't displaying any text. */ |
c6e89d6c | 9280 | if (!MINI_WINDOW_P (w) |
5f5c8ee5 | 9281 | || (w == XWINDOW (minibuf_window) |
c6e89d6c | 9282 | && NILP (echo_area_buffer[0]))) |
b1d1124b | 9283 | { |
8a9311d7 | 9284 | whole = ZV - BEGV; |
4d641a15 | 9285 | start = marker_position (w->start) - BEGV; |
b1d1124b JB |
9286 | /* I don't think this is guaranteed to be right. For the |
9287 | moment, we'll pretend it is. */ | |
5f5c8ee5 | 9288 | end = (Z - XFASTINT (w->window_end_pos)) - BEGV; |
3505ea70 | 9289 | |
5f5c8ee5 GM |
9290 | if (end < start) |
9291 | end = start; | |
9292 | if (whole < (end - start)) | |
9293 | whole = end - start; | |
b1d1124b JB |
9294 | } |
9295 | else | |
9296 | start = end = whole = 0; | |
30c566e4 | 9297 | |
88f22aff | 9298 | /* Indicate what this scroll bar ought to be displaying now. */ |
7eb9ba41 | 9299 | (*set_vertical_scroll_bar_hook) (w, end - start, whole, start); |
30c566e4 | 9300 | |
5f5c8ee5 GM |
9301 | /* Note that we actually used the scroll bar attached to this |
9302 | window, so it shouldn't be deleted at the end of redisplay. */ | |
88f22aff | 9303 | (*redeem_scroll_bar_hook) (w); |
30c566e4 | 9304 | } |
b1d1124b | 9305 | |
5f5c8ee5 GM |
9306 | restore_buffers: |
9307 | ||
9308 | /* Restore current_buffer and value of point in it. */ | |
9309 | TEMP_SET_PT_BOTH (CHARPOS (opoint), BYTEPOS (opoint)); | |
5ba50c51 | 9310 | if (really_switched_buffer) |
f72df6ac | 9311 | set_buffer_internal_1 (old); |
e481f960 RS |
9312 | else |
9313 | set_buffer_temp (old); | |
5f5c8ee5 | 9314 | TEMP_SET_PT_BOTH (CHARPOS (lpoint), BYTEPOS (lpoint)); |
2e54982e RS |
9315 | |
9316 | unbind_to (count, Qnil); | |
a2889657 | 9317 | } |
a2889657 | 9318 | |
5f5c8ee5 GM |
9319 | |
9320 | /* Build the complete desired matrix of WINDOW with a window start | |
9321 | buffer position POS. Value is non-zero if successful. It is zero | |
9322 | if fonts were loaded during redisplay which makes re-adjusting | |
9323 | glyph matrices necessary. */ | |
9324 | ||
9325 | int | |
a2889657 JB |
9326 | try_window (window, pos) |
9327 | Lisp_Object window; | |
5f5c8ee5 GM |
9328 | struct text_pos pos; |
9329 | { | |
9330 | struct window *w = XWINDOW (window); | |
9331 | struct it it; | |
9332 | struct glyph_row *last_text_row = NULL; | |
9cbab4ff | 9333 | |
5f5c8ee5 GM |
9334 | /* Make POS the new window start. */ |
9335 | set_marker_both (w->start, Qnil, CHARPOS (pos), BYTEPOS (pos)); | |
12adba34 | 9336 | |
5f5c8ee5 GM |
9337 | /* Mark cursor position as unknown. No overlay arrow seen. */ |
9338 | w->cursor.vpos = -1; | |
a2889657 | 9339 | overlay_arrow_seen = 0; |
642eefc6 | 9340 | |
5f5c8ee5 GM |
9341 | /* Initialize iterator and info to start at POS. */ |
9342 | start_display (&it, w, pos); | |
a2889657 | 9343 | |
5f5c8ee5 GM |
9344 | /* Display all lines of W. */ |
9345 | while (it.current_y < it.last_visible_y) | |
9346 | { | |
9347 | if (display_line (&it)) | |
9348 | last_text_row = it.glyph_row - 1; | |
9349 | if (fonts_changed_p) | |
9350 | return 0; | |
9351 | } | |
a2889657 | 9352 | |
5f5c8ee5 GM |
9353 | /* If bottom moved off end of frame, change mode line percentage. */ |
9354 | if (XFASTINT (w->window_end_pos) <= 0 | |
9355 | && Z != IT_CHARPOS (it)) | |
a2889657 JB |
9356 | w->update_mode_line = Qt; |
9357 | ||
5f5c8ee5 GM |
9358 | /* Set window_end_pos to the offset of the last character displayed |
9359 | on the window from the end of current_buffer. Set | |
9360 | window_end_vpos to its row number. */ | |
9361 | if (last_text_row) | |
9362 | { | |
9363 | xassert (MATRIX_ROW_DISPLAYS_TEXT_P (last_text_row)); | |
9364 | w->window_end_bytepos | |
9365 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row); | |
9366 | XSETFASTINT (w->window_end_pos, | |
9367 | Z - MATRIX_ROW_END_CHARPOS (last_text_row)); | |
9368 | XSETFASTINT (w->window_end_vpos, | |
9369 | MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)); | |
9370 | xassert (MATRIX_ROW (w->desired_matrix, XFASTINT (w->window_end_vpos)) | |
9371 | ->displays_text_p); | |
9372 | } | |
9373 | else | |
9374 | { | |
9375 | w->window_end_bytepos = 0; | |
9376 | XSETFASTINT (w->window_end_pos, 0); | |
9377 | XSETFASTINT (w->window_end_vpos, 0); | |
9378 | } | |
9379 | ||
a2889657 JB |
9380 | /* But that is not valid info until redisplay finishes. */ |
9381 | w->window_end_valid = Qnil; | |
5f5c8ee5 | 9382 | return 1; |
a2889657 | 9383 | } |
5f5c8ee5 GM |
9384 | |
9385 | ||
a2889657 | 9386 | \f |
5f5c8ee5 GM |
9387 | /************************************************************************ |
9388 | Window redisplay reusing current matrix when buffer has not changed | |
9389 | ************************************************************************/ | |
9390 | ||
9391 | /* Try redisplay of window W showing an unchanged buffer with a | |
9392 | different window start than the last time it was displayed by | |
9393 | reusing its current matrix. Value is non-zero if successful. | |
9394 | W->start is the new window start. */ | |
a2889657 JB |
9395 | |
9396 | static int | |
5f5c8ee5 GM |
9397 | try_window_reusing_current_matrix (w) |
9398 | struct window *w; | |
a2889657 | 9399 | { |
5f5c8ee5 GM |
9400 | struct frame *f = XFRAME (w->frame); |
9401 | struct glyph_row *row, *bottom_row; | |
9402 | struct it it; | |
9403 | struct run run; | |
9404 | struct text_pos start, new_start; | |
9405 | int nrows_scrolled, i; | |
9406 | struct glyph_row *last_text_row; | |
9407 | struct glyph_row *last_reused_text_row; | |
9408 | struct glyph_row *start_row; | |
9409 | int start_vpos, min_y, max_y; | |
9410 | ||
9411 | /* Right now this function doesn't handle terminal frames. */ | |
9412 | if (!FRAME_WINDOW_P (f)) | |
9413 | return 0; | |
a2889657 | 9414 | |
5f5c8ee5 GM |
9415 | /* Can't do this if region may have changed. */ |
9416 | if ((!NILP (Vtransient_mark_mode) | |
9417 | && !NILP (current_buffer->mark_active)) | |
8f897821 GM |
9418 | || !NILP (w->region_showing) |
9419 | || !NILP (Vshow_trailing_whitespace)) | |
5f5c8ee5 | 9420 | return 0; |
a2889657 | 9421 | |
5f5c8ee5 | 9422 | /* If top-line visibility has changed, give up. */ |
045dee35 GM |
9423 | if (WINDOW_WANTS_HEADER_LINE_P (w) |
9424 | != MATRIX_HEADER_LINE_ROW (w->current_matrix)->mode_line_p) | |
5f5c8ee5 GM |
9425 | return 0; |
9426 | ||
9427 | /* Give up if old or new display is scrolled vertically. We could | |
9428 | make this function handle this, but right now it doesn't. */ | |
9429 | start_row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
9430 | if (w->vscroll || MATRIX_ROW_PARTIALLY_VISIBLE_P (start_row)) | |
9431 | return 0; | |
9432 | ||
9433 | /* The variable new_start now holds the new window start. The old | |
9434 | start `start' can be determined from the current matrix. */ | |
9435 | SET_TEXT_POS_FROM_MARKER (new_start, w->start); | |
9436 | start = start_row->start.pos; | |
9437 | start_vpos = MATRIX_ROW_VPOS (start_row, w->current_matrix); | |
a2889657 | 9438 | |
5f5c8ee5 GM |
9439 | /* Clear the desired matrix for the display below. */ |
9440 | clear_glyph_matrix (w->desired_matrix); | |
9441 | ||
9442 | if (CHARPOS (new_start) <= CHARPOS (start)) | |
9443 | { | |
9444 | int first_row_y; | |
9445 | ||
9446 | IF_DEBUG (debug_method_add (w, "twu1")); | |
9447 | ||
9448 | /* Display up to a row that can be reused. The variable | |
9449 | last_text_row is set to the last row displayed that displays | |
9450 | text. */ | |
9451 | start_display (&it, w, new_start); | |
9452 | first_row_y = it.current_y; | |
9453 | w->cursor.vpos = -1; | |
9454 | last_text_row = last_reused_text_row = NULL; | |
9455 | while (it.current_y < it.last_visible_y | |
9456 | && IT_CHARPOS (it) < CHARPOS (start) | |
9457 | && !fonts_changed_p) | |
9458 | if (display_line (&it)) | |
9459 | last_text_row = it.glyph_row - 1; | |
9460 | ||
9461 | /* A value of current_y < last_visible_y means that we stopped | |
9462 | at the previous window start, which in turn means that we | |
9463 | have at least one reusable row. */ | |
9464 | if (it.current_y < it.last_visible_y) | |
a2889657 | 9465 | { |
5f5c8ee5 GM |
9466 | nrows_scrolled = it.vpos; |
9467 | ||
9468 | /* Find PT if not already found in the lines displayed. */ | |
9469 | if (w->cursor.vpos < 0) | |
a2889657 | 9470 | { |
5f5c8ee5 GM |
9471 | int dy = it.current_y - first_row_y; |
9472 | ||
9473 | row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
9474 | while (MATRIX_ROW_DISPLAYS_TEXT_P (row)) | |
9475 | { | |
9476 | if (PT >= MATRIX_ROW_START_CHARPOS (row) | |
9477 | && PT < MATRIX_ROW_END_CHARPOS (row)) | |
9478 | { | |
9479 | set_cursor_from_row (w, row, w->current_matrix, 0, 0, | |
9480 | dy, nrows_scrolled); | |
9481 | break; | |
9482 | } | |
9483 | ||
9484 | if (MATRIX_ROW_BOTTOM_Y (row) + dy >= it.last_visible_y) | |
9485 | break; | |
9486 | ||
9487 | ++row; | |
9488 | } | |
9489 | ||
9490 | /* Give up if point was not found. This shouldn't | |
9491 | happen often; not more often than with try_window | |
9492 | itself. */ | |
9493 | if (w->cursor.vpos < 0) | |
9494 | { | |
9495 | clear_glyph_matrix (w->desired_matrix); | |
9496 | return 0; | |
9497 | } | |
a2889657 | 9498 | } |
5f5c8ee5 GM |
9499 | |
9500 | /* Scroll the display. Do it before the current matrix is | |
9501 | changed. The problem here is that update has not yet | |
9502 | run, i.e. part of the current matrix is not up to date. | |
9503 | scroll_run_hook will clear the cursor, and use the | |
9504 | current matrix to get the height of the row the cursor is | |
9505 | in. */ | |
9506 | run.current_y = first_row_y; | |
9507 | run.desired_y = it.current_y; | |
9508 | run.height = it.last_visible_y - it.current_y; | |
15e26c76 GM |
9509 | if (run.height > 0 |
9510 | && run.current_y != run.desired_y) | |
a2889657 | 9511 | { |
5f5c8ee5 GM |
9512 | update_begin (f); |
9513 | rif->update_window_begin_hook (w); | |
9514 | rif->scroll_run_hook (w, &run); | |
9515 | rif->update_window_end_hook (w, 0); | |
9516 | update_end (f); | |
a2889657 | 9517 | } |
5f5c8ee5 GM |
9518 | |
9519 | /* Shift current matrix down by nrows_scrolled lines. */ | |
9520 | bottom_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w); | |
9521 | rotate_matrix (w->current_matrix, | |
9522 | start_vpos, | |
9523 | MATRIX_ROW_VPOS (bottom_row, w->current_matrix), | |
9524 | nrows_scrolled); | |
9525 | ||
9526 | /* Disable lines not reused. */ | |
9527 | for (i = 0; i < it.vpos; ++i) | |
9528 | MATRIX_ROW (w->current_matrix, i)->enabled_p = 0; | |
9529 | ||
9530 | /* Re-compute Y positions. */ | |
9531 | row = MATRIX_FIRST_TEXT_ROW (w->current_matrix) + nrows_scrolled; | |
045dee35 | 9532 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
5f5c8ee5 GM |
9533 | max_y = it.last_visible_y; |
9534 | while (row < bottom_row) | |
d2f84654 | 9535 | { |
5f5c8ee5 GM |
9536 | row->y = it.current_y; |
9537 | ||
9538 | if (row->y < min_y) | |
9539 | row->visible_height = row->height - (min_y - row->y); | |
9540 | else if (row->y + row->height > max_y) | |
9541 | row->visible_height | |
9542 | = row->height - (row->y + row->height - max_y); | |
9543 | else | |
9544 | row->visible_height = row->height; | |
9545 | ||
9546 | it.current_y += row->height; | |
9547 | ++it.vpos; | |
9548 | ||
9549 | if (MATRIX_ROW_DISPLAYS_TEXT_P (row)) | |
9550 | last_reused_text_row = row; | |
9551 | if (MATRIX_ROW_BOTTOM_Y (row) >= it.last_visible_y) | |
9552 | break; | |
9553 | ++row; | |
d2f84654 | 9554 | } |
a2889657 | 9555 | } |
5f5c8ee5 GM |
9556 | |
9557 | /* Update window_end_pos etc.; last_reused_text_row is the last | |
9558 | reused row from the current matrix containing text, if any. | |
9559 | The value of last_text_row is the last displayed line | |
9560 | containing text. */ | |
9561 | if (last_reused_text_row) | |
a2889657 | 9562 | { |
5f5c8ee5 GM |
9563 | w->window_end_bytepos |
9564 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_reused_text_row); | |
9565 | XSETFASTINT (w->window_end_pos, | |
9566 | Z - MATRIX_ROW_END_CHARPOS (last_reused_text_row)); | |
9567 | XSETFASTINT (w->window_end_vpos, | |
9568 | MATRIX_ROW_VPOS (last_reused_text_row, | |
9569 | w->current_matrix)); | |
a2889657 | 9570 | } |
5f5c8ee5 GM |
9571 | else if (last_text_row) |
9572 | { | |
9573 | w->window_end_bytepos | |
9574 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row); | |
9575 | XSETFASTINT (w->window_end_pos, | |
9576 | Z - MATRIX_ROW_END_CHARPOS (last_text_row)); | |
9577 | XSETFASTINT (w->window_end_vpos, | |
9578 | MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)); | |
9579 | } | |
9580 | else | |
9581 | { | |
9582 | /* This window must be completely empty. */ | |
9583 | w->window_end_bytepos = 0; | |
9584 | XSETFASTINT (w->window_end_pos, 0); | |
9585 | XSETFASTINT (w->window_end_vpos, 0); | |
9586 | } | |
9587 | w->window_end_valid = Qnil; | |
a2889657 | 9588 | |
5f5c8ee5 GM |
9589 | /* Update hint: don't try scrolling again in update_window. */ |
9590 | w->desired_matrix->no_scrolling_p = 1; | |
9591 | ||
9592 | #if GLYPH_DEBUG | |
9593 | debug_method_add (w, "try_window_reusing_current_matrix 1"); | |
9594 | #endif | |
9595 | return 1; | |
a2889657 | 9596 | } |
5f5c8ee5 GM |
9597 | else if (CHARPOS (new_start) > CHARPOS (start)) |
9598 | { | |
9599 | struct glyph_row *pt_row, *row; | |
9600 | struct glyph_row *first_reusable_row; | |
9601 | struct glyph_row *first_row_to_display; | |
9602 | int dy; | |
9603 | int yb = window_text_bottom_y (w); | |
9604 | ||
9605 | IF_DEBUG (debug_method_add (w, "twu2")); | |
9606 | ||
9607 | /* Find the row starting at new_start, if there is one. Don't | |
9608 | reuse a partially visible line at the end. */ | |
9609 | first_reusable_row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
9610 | while (first_reusable_row->enabled_p | |
9611 | && MATRIX_ROW_BOTTOM_Y (first_reusable_row) < yb | |
9612 | && (MATRIX_ROW_START_CHARPOS (first_reusable_row) | |
9613 | < CHARPOS (new_start))) | |
9614 | ++first_reusable_row; | |
9615 | ||
9616 | /* Give up if there is no row to reuse. */ | |
9617 | if (MATRIX_ROW_BOTTOM_Y (first_reusable_row) >= yb | |
28514cd9 GM |
9618 | || !first_reusable_row->enabled_p |
9619 | || (MATRIX_ROW_START_CHARPOS (first_reusable_row) | |
9620 | != CHARPOS (new_start))) | |
5f5c8ee5 GM |
9621 | return 0; |
9622 | ||
5f5c8ee5 GM |
9623 | /* We can reuse fully visible rows beginning with |
9624 | first_reusable_row to the end of the window. Set | |
9625 | first_row_to_display to the first row that cannot be reused. | |
9626 | Set pt_row to the row containing point, if there is any. */ | |
9627 | first_row_to_display = first_reusable_row; | |
9628 | pt_row = NULL; | |
9629 | while (MATRIX_ROW_BOTTOM_Y (first_row_to_display) < yb) | |
9630 | { | |
9631 | if (PT >= MATRIX_ROW_START_CHARPOS (first_row_to_display) | |
9632 | && PT < MATRIX_ROW_END_CHARPOS (first_row_to_display)) | |
9633 | pt_row = first_row_to_display; | |
a2889657 | 9634 | |
5f5c8ee5 GM |
9635 | ++first_row_to_display; |
9636 | } | |
a2889657 | 9637 | |
5f5c8ee5 GM |
9638 | /* Start displaying at the start of first_row_to_display. */ |
9639 | xassert (first_row_to_display->y < yb); | |
9640 | init_to_row_start (&it, w, first_row_to_display); | |
9641 | nrows_scrolled = MATRIX_ROW_VPOS (first_reusable_row, w->current_matrix); | |
9642 | it.vpos = (MATRIX_ROW_VPOS (first_row_to_display, w->current_matrix) | |
9643 | - nrows_scrolled); | |
9644 | it.current_y = first_row_to_display->y - first_reusable_row->y; | |
9645 | ||
9646 | /* Display lines beginning with first_row_to_display in the | |
9647 | desired matrix. Set last_text_row to the last row displayed | |
9648 | that displays text. */ | |
9649 | it.glyph_row = MATRIX_ROW (w->desired_matrix, it.vpos); | |
9650 | if (pt_row == NULL) | |
9651 | w->cursor.vpos = -1; | |
9652 | last_text_row = NULL; | |
9653 | while (it.current_y < it.last_visible_y && !fonts_changed_p) | |
9654 | if (display_line (&it)) | |
9655 | last_text_row = it.glyph_row - 1; | |
9656 | ||
9657 | /* Give up If point isn't in a row displayed or reused. */ | |
9658 | if (w->cursor.vpos < 0) | |
9659 | { | |
9660 | clear_glyph_matrix (w->desired_matrix); | |
9661 | return 0; | |
9662 | } | |
12adba34 | 9663 | |
5f5c8ee5 GM |
9664 | /* If point is in a reused row, adjust y and vpos of the cursor |
9665 | position. */ | |
9666 | if (pt_row) | |
9667 | { | |
9668 | w->cursor.vpos -= MATRIX_ROW_VPOS (first_reusable_row, | |
9669 | w->current_matrix); | |
9670 | w->cursor.y -= first_reusable_row->y; | |
a2889657 JB |
9671 | } |
9672 | ||
5f5c8ee5 GM |
9673 | /* Scroll the display. */ |
9674 | run.current_y = first_reusable_row->y; | |
045dee35 | 9675 | run.desired_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
5f5c8ee5 GM |
9676 | run.height = it.last_visible_y - run.current_y; |
9677 | if (run.height) | |
9678 | { | |
9679 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
9680 | update_begin (f); | |
9681 | rif->update_window_begin_hook (w); | |
9682 | rif->scroll_run_hook (w, &run); | |
9683 | rif->update_window_end_hook (w, 0); | |
9684 | update_end (f); | |
9685 | } | |
a2889657 | 9686 | |
5f5c8ee5 GM |
9687 | /* Adjust Y positions of reused rows. */ |
9688 | bottom_row = MATRIX_BOTTOM_TEXT_ROW (w->current_matrix, w); | |
9689 | row = first_reusable_row; | |
9690 | dy = first_reusable_row->y; | |
045dee35 | 9691 | min_y = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (w); |
5f5c8ee5 GM |
9692 | max_y = it.last_visible_y; |
9693 | while (row < first_row_to_display) | |
9694 | { | |
9695 | row->y -= dy; | |
9696 | if (row->y < min_y) | |
9697 | row->visible_height = row->height - (min_y - row->y); | |
9698 | else if (row->y + row->height > max_y) | |
9699 | row->visible_height | |
9700 | = row->height - (row->y + row->height - max_y); | |
9701 | else | |
9702 | row->visible_height = row->height; | |
9703 | ++row; | |
9704 | } | |
a2889657 | 9705 | |
5f5c8ee5 GM |
9706 | /* Disable rows not reused. */ |
9707 | while (row < bottom_row) | |
9708 | { | |
9709 | row->enabled_p = 0; | |
9710 | ++row; | |
9711 | } | |
9712 | ||
9713 | /* Scroll the current matrix. */ | |
9714 | xassert (nrows_scrolled > 0); | |
9715 | rotate_matrix (w->current_matrix, | |
9716 | start_vpos, | |
9717 | MATRIX_ROW_VPOS (bottom_row, w->current_matrix), | |
9718 | -nrows_scrolled); | |
9719 | ||
9720 | /* Adjust window end. A null value of last_text_row means that | |
9721 | the window end is in reused rows which in turn means that | |
9722 | only its vpos can have changed. */ | |
9723 | if (last_text_row) | |
9724 | { | |
9725 | w->window_end_bytepos | |
9726 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row); | |
9727 | XSETFASTINT (w->window_end_pos, | |
9728 | Z - MATRIX_ROW_END_CHARPOS (last_text_row)); | |
9729 | XSETFASTINT (w->window_end_vpos, | |
9730 | MATRIX_ROW_VPOS (last_text_row, w->desired_matrix)); | |
9731 | } | |
9732 | else | |
a2889657 | 9733 | { |
e8e536a9 | 9734 | XSETFASTINT (w->window_end_vpos, |
5f5c8ee5 | 9735 | XFASTINT (w->window_end_vpos) - nrows_scrolled); |
a2889657 | 9736 | } |
5f5c8ee5 GM |
9737 | |
9738 | w->window_end_valid = Qnil; | |
9739 | w->desired_matrix->no_scrolling_p = 1; | |
9740 | ||
9741 | #if GLYPH_DEBUG | |
9742 | debug_method_add (w, "try_window_reusing_current_matrix 2"); | |
9743 | #endif | |
9744 | return 1; | |
a2889657 | 9745 | } |
5f5c8ee5 GM |
9746 | |
9747 | return 0; | |
9748 | } | |
a2889657 | 9749 | |
a2889657 | 9750 | |
5f5c8ee5 GM |
9751 | \f |
9752 | /************************************************************************ | |
9753 | Window redisplay reusing current matrix when buffer has changed | |
9754 | ************************************************************************/ | |
9755 | ||
9756 | static struct glyph_row *get_last_unchanged_at_beg_row P_ ((struct window *)); | |
9757 | static struct glyph_row *get_first_unchanged_at_end_row P_ ((struct window *, | |
9758 | int *, int *)); | |
9759 | static struct glyph_row * | |
9760 | find_last_row_displaying_text P_ ((struct glyph_matrix *, struct it *, | |
9761 | struct glyph_row *)); | |
9762 | ||
9763 | ||
9764 | /* Return the last row in MATRIX displaying text. If row START is | |
9765 | non-null, start searching with that row. IT gives the dimensions | |
9766 | of the display. Value is null if matrix is empty; otherwise it is | |
9767 | a pointer to the row found. */ | |
9768 | ||
9769 | static struct glyph_row * | |
9770 | find_last_row_displaying_text (matrix, it, start) | |
9771 | struct glyph_matrix *matrix; | |
9772 | struct it *it; | |
9773 | struct glyph_row *start; | |
9774 | { | |
9775 | struct glyph_row *row, *row_found; | |
9776 | ||
9777 | /* Set row_found to the last row in IT->w's current matrix | |
9778 | displaying text. The loop looks funny but think of partially | |
9779 | visible lines. */ | |
9780 | row_found = NULL; | |
9781 | row = start ? start : MATRIX_FIRST_TEXT_ROW (matrix); | |
9782 | while (MATRIX_ROW_DISPLAYS_TEXT_P (row)) | |
9783 | { | |
9784 | xassert (row->enabled_p); | |
9785 | row_found = row; | |
9786 | if (MATRIX_ROW_BOTTOM_Y (row) >= it->last_visible_y) | |
9787 | break; | |
9788 | ++row; | |
a2889657 | 9789 | } |
5f5c8ee5 GM |
9790 | |
9791 | return row_found; | |
9792 | } | |
9793 | ||
a2889657 | 9794 | |
5f5c8ee5 GM |
9795 | /* Return the last row in the current matrix of W that is not affected |
9796 | by changes at the start of current_buffer that occurred since the | |
9797 | last time W was redisplayed. Value is null if no such row exists. | |
a2889657 | 9798 | |
5f5c8ee5 GM |
9799 | The global variable beg_unchanged has to contain the number of |
9800 | bytes unchanged at the start of current_buffer. BEG + | |
9801 | beg_unchanged is the buffer position of the first changed byte in | |
9802 | current_buffer. Characters at positions < BEG + beg_unchanged are | |
9803 | at the same buffer positions as they were when the current matrix | |
9804 | was built. */ | |
9805 | ||
9806 | static struct glyph_row * | |
9807 | get_last_unchanged_at_beg_row (w) | |
9808 | struct window *w; | |
9809 | { | |
9142dd5b | 9810 | int first_changed_pos = BEG + BEG_UNCHANGED; |
5f5c8ee5 GM |
9811 | struct glyph_row *row; |
9812 | struct glyph_row *row_found = NULL; | |
9813 | int yb = window_text_bottom_y (w); | |
9814 | ||
9815 | /* Find the last row displaying unchanged text. */ | |
9816 | row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
9817 | while (MATRIX_ROW_DISPLAYS_TEXT_P (row) | |
9818 | && MATRIX_ROW_START_CHARPOS (row) < first_changed_pos) | |
a2889657 | 9819 | { |
5f5c8ee5 GM |
9820 | if (/* If row ends before first_changed_pos, it is unchanged, |
9821 | except in some case. */ | |
9822 | MATRIX_ROW_END_CHARPOS (row) <= first_changed_pos | |
9823 | /* When row ends in ZV and we write at ZV it is not | |
9824 | unchanged. */ | |
9825 | && !row->ends_at_zv_p | |
9826 | /* When first_changed_pos is the end of a continued line, | |
9827 | row is not unchanged because it may be no longer | |
9828 | continued. */ | |
9829 | && !(MATRIX_ROW_END_CHARPOS (row) == first_changed_pos | |
9830 | && row->continued_p)) | |
9831 | row_found = row; | |
9832 | ||
9833 | /* Stop if last visible row. */ | |
9834 | if (MATRIX_ROW_BOTTOM_Y (row) >= yb) | |
9835 | break; | |
9836 | ||
9837 | ++row; | |
a2889657 JB |
9838 | } |
9839 | ||
5f5c8ee5 | 9840 | return row_found; |
a2889657 | 9841 | } |
5f5c8ee5 GM |
9842 | |
9843 | ||
9844 | /* Find the first glyph row in the current matrix of W that is not | |
9845 | affected by changes at the end of current_buffer since the last | |
9846 | time the window was redisplayed. Return in *DELTA the number of | |
c59c668a GM |
9847 | chars by which buffer positions in unchanged text at the end of |
9848 | current_buffer must be adjusted. Return in *DELTA_BYTES the | |
9849 | corresponding number of bytes. Value is null if no such row | |
9850 | exists, i.e. all rows are affected by changes. */ | |
5f5c8ee5 GM |
9851 | |
9852 | static struct glyph_row * | |
9853 | get_first_unchanged_at_end_row (w, delta, delta_bytes) | |
9854 | struct window *w; | |
9855 | int *delta, *delta_bytes; | |
a2889657 | 9856 | { |
5f5c8ee5 GM |
9857 | struct glyph_row *row; |
9858 | struct glyph_row *row_found = NULL; | |
c581d710 | 9859 | |
5f5c8ee5 | 9860 | *delta = *delta_bytes = 0; |
b2a76982 | 9861 | |
5f5c8ee5 GM |
9862 | /* A value of window_end_pos >= end_unchanged means that the window |
9863 | end is in the range of changed text. If so, there is no | |
9864 | unchanged row at the end of W's current matrix. */ | |
9865 | xassert (!NILP (w->window_end_valid)); | |
9142dd5b | 9866 | if (XFASTINT (w->window_end_pos) >= END_UNCHANGED) |
5f5c8ee5 GM |
9867 | return NULL; |
9868 | ||
9869 | /* Set row to the last row in W's current matrix displaying text. */ | |
9870 | row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); | |
9871 | ||
5f5c8ee5 GM |
9872 | /* If matrix is entirely empty, no unchanged row exists. */ |
9873 | if (MATRIX_ROW_DISPLAYS_TEXT_P (row)) | |
9874 | { | |
9875 | /* The value of row is the last glyph row in the matrix having a | |
9876 | meaningful buffer position in it. The end position of row | |
9877 | corresponds to window_end_pos. This allows us to translate | |
9878 | buffer positions in the current matrix to current buffer | |
9879 | positions for characters not in changed text. */ | |
9880 | int Z_old = MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos); | |
9881 | int Z_BYTE_old = MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos; | |
9882 | int last_unchanged_pos, last_unchanged_pos_old; | |
9883 | struct glyph_row *first_text_row | |
9884 | = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
9885 | ||
9886 | *delta = Z - Z_old; | |
9887 | *delta_bytes = Z_BYTE - Z_BYTE_old; | |
9888 | ||
9889 | /* Set last_unchanged_pos to the buffer position of the last | |
9890 | character in the buffer that has not been changed. Z is the | |
9891 | index + 1 of the last byte in current_buffer, i.e. by | |
9892 | subtracting end_unchanged we get the index of the last | |
9893 | unchanged character, and we have to add BEG to get its buffer | |
9894 | position. */ | |
9142dd5b | 9895 | last_unchanged_pos = Z - END_UNCHANGED + BEG; |
5f5c8ee5 GM |
9896 | last_unchanged_pos_old = last_unchanged_pos - *delta; |
9897 | ||
9898 | /* Search backward from ROW for a row displaying a line that | |
9899 | starts at a minimum position >= last_unchanged_pos_old. */ | |
9900 | while (row >= first_text_row) | |
9901 | { | |
9902 | xassert (row->enabled_p); | |
9903 | xassert (MATRIX_ROW_DISPLAYS_TEXT_P (row)); | |
9904 | ||
9905 | if (MATRIX_ROW_START_CHARPOS (row) >= last_unchanged_pos_old) | |
9906 | row_found = row; | |
9907 | --row; | |
9908 | } | |
9909 | } | |
9910 | ||
9911 | xassert (!row_found || MATRIX_ROW_DISPLAYS_TEXT_P (row_found)); | |
9912 | return row_found; | |
c581d710 RS |
9913 | } |
9914 | ||
c581d710 | 9915 | |
5f5c8ee5 GM |
9916 | /* Make sure that glyph rows in the current matrix of window W |
9917 | reference the same glyph memory as corresponding rows in the | |
9918 | frame's frame matrix. This function is called after scrolling W's | |
9919 | current matrix on a terminal frame in try_window_id and | |
9920 | try_window_reusing_current_matrix. */ | |
9921 | ||
9922 | static void | |
9923 | sync_frame_with_window_matrix_rows (w) | |
9924 | struct window *w; | |
c581d710 | 9925 | { |
5f5c8ee5 GM |
9926 | struct frame *f = XFRAME (w->frame); |
9927 | struct glyph_row *window_row, *window_row_end, *frame_row; | |
9928 | ||
9929 | /* Preconditions: W must be a leaf window and full-width. Its frame | |
9930 | must have a frame matrix. */ | |
9931 | xassert (NILP (w->hchild) && NILP (w->vchild)); | |
9932 | xassert (WINDOW_FULL_WIDTH_P (w)); | |
9933 | xassert (!FRAME_WINDOW_P (f)); | |
9934 | ||
9935 | /* If W is a full-width window, glyph pointers in W's current matrix | |
9936 | have, by definition, to be the same as glyph pointers in the | |
9937 | corresponding frame matrix. */ | |
9938 | window_row = w->current_matrix->rows; | |
9939 | window_row_end = window_row + w->current_matrix->nrows; | |
9940 | frame_row = f->current_matrix->rows + XFASTINT (w->top); | |
9941 | while (window_row < window_row_end) | |
659a218f | 9942 | { |
5f5c8ee5 | 9943 | int area; |
f002db93 | 9944 | |
5f5c8ee5 GM |
9945 | for (area = LEFT_MARGIN_AREA; area <= LAST_AREA; ++area) |
9946 | frame_row->glyphs[area] = window_row->glyphs[area]; | |
f002db93 GM |
9947 | |
9948 | /* Disable frame rows whose corresponding window rows have | |
9949 | been disabled in try_window_id. */ | |
9950 | if (!window_row->enabled_p) | |
9951 | frame_row->enabled_p = 0; | |
9952 | ||
5f5c8ee5 | 9953 | ++window_row, ++frame_row; |
659a218f | 9954 | } |
a2889657 | 9955 | } |
5f5c8ee5 GM |
9956 | |
9957 | ||
e037b9ec GM |
9958 | /* Find the glyph row in window W containing CHARPOS. Consider all |
9959 | rows between START and END (not inclusive). END null means search | |
9960 | all rows to the end of the display area of W. Value is the row | |
9961 | containing CHARPOS or null. */ | |
9962 | ||
9963 | static struct glyph_row * | |
9964 | row_containing_pos (w, charpos, start, end) | |
9965 | struct window *w; | |
9966 | int charpos; | |
9967 | struct glyph_row *start, *end; | |
9968 | { | |
9969 | struct glyph_row *row = start; | |
9970 | int last_y; | |
9971 | ||
9972 | /* If we happen to start on a header-line, skip that. */ | |
9973 | if (row->mode_line_p) | |
9974 | ++row; | |
9975 | ||
9976 | if ((end && row >= end) || !row->enabled_p) | |
9977 | return NULL; | |
9978 | ||
9979 | last_y = window_text_bottom_y (w); | |
9980 | ||
9981 | while ((end == NULL || row < end) | |
9982 | && (MATRIX_ROW_END_CHARPOS (row) < charpos | |
9983 | /* The end position of a row equals the start | |
9984 | position of the next row. If CHARPOS is there, we | |
9985 | would rather display it in the next line, except | |
9986 | when this line ends in ZV. */ | |
9987 | || (MATRIX_ROW_END_CHARPOS (row) == charpos | |
9988 | && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row) | |
9989 | || !row->ends_at_zv_p))) | |
9990 | && MATRIX_ROW_BOTTOM_Y (row) < last_y) | |
9991 | ++row; | |
9992 | ||
9993 | /* Give up if CHARPOS not found. */ | |
9994 | if ((end && row >= end) | |
9995 | || charpos < MATRIX_ROW_START_CHARPOS (row) | |
9996 | || charpos > MATRIX_ROW_END_CHARPOS (row)) | |
9997 | row = NULL; | |
9998 | ||
9999 | return row; | |
10000 | } | |
10001 | ||
10002 | ||
5f5c8ee5 GM |
10003 | /* Try to redisplay window W by reusing its existing display. W's |
10004 | current matrix must be up to date when this function is called, | |
10005 | i.e. window_end_valid must not be nil. | |
10006 | ||
10007 | Value is | |
10008 | ||
10009 | 1 if display has been updated | |
10010 | 0 if otherwise unsuccessful | |
10011 | -1 if redisplay with same window start is known not to succeed | |
10012 | ||
10013 | The following steps are performed: | |
10014 | ||
10015 | 1. Find the last row in the current matrix of W that is not | |
10016 | affected by changes at the start of current_buffer. If no such row | |
10017 | is found, give up. | |
10018 | ||
10019 | 2. Find the first row in W's current matrix that is not affected by | |
10020 | changes at the end of current_buffer. Maybe there is no such row. | |
10021 | ||
10022 | 3. Display lines beginning with the row + 1 found in step 1 to the | |
10023 | row found in step 2 or, if step 2 didn't find a row, to the end of | |
10024 | the window. | |
10025 | ||
10026 | 4. If cursor is not known to appear on the window, give up. | |
10027 | ||
10028 | 5. If display stopped at the row found in step 2, scroll the | |
10029 | display and current matrix as needed. | |
10030 | ||
10031 | 6. Maybe display some lines at the end of W, if we must. This can | |
10032 | happen under various circumstances, like a partially visible line | |
10033 | becoming fully visible, or because newly displayed lines are displayed | |
10034 | in smaller font sizes. | |
10035 | ||
10036 | 7. Update W's window end information. */ | |
10037 | ||
10038 | /* Check that window end is what we expect it to be. */ | |
12adba34 RS |
10039 | |
10040 | static int | |
5f5c8ee5 | 10041 | try_window_id (w) |
12adba34 | 10042 | struct window *w; |
12adba34 | 10043 | { |
5f5c8ee5 GM |
10044 | struct frame *f = XFRAME (w->frame); |
10045 | struct glyph_matrix *current_matrix = w->current_matrix; | |
10046 | struct glyph_matrix *desired_matrix = w->desired_matrix; | |
10047 | struct glyph_row *last_unchanged_at_beg_row; | |
10048 | struct glyph_row *first_unchanged_at_end_row; | |
10049 | struct glyph_row *row; | |
10050 | struct glyph_row *bottom_row; | |
10051 | int bottom_vpos; | |
10052 | struct it it; | |
10053 | int delta = 0, delta_bytes = 0, stop_pos, dvpos, dy; | |
10054 | struct text_pos start_pos; | |
10055 | struct run run; | |
10056 | int first_unchanged_at_end_vpos = 0; | |
10057 | struct glyph_row *last_text_row, *last_text_row_at_end; | |
10058 | struct text_pos start; | |
10059 | ||
10060 | SET_TEXT_POS_FROM_MARKER (start, w->start); | |
10061 | ||
10062 | /* Check pre-conditions. Window end must be valid, otherwise | |
10063 | the current matrix would not be up to date. */ | |
10064 | xassert (!NILP (w->window_end_valid)); | |
10065 | xassert (FRAME_WINDOW_P (XFRAME (w->frame)) | |
10066 | || (line_ins_del_ok && WINDOW_FULL_WIDTH_P (w))); | |
10067 | ||
10068 | /* Make sure beg_unchanged and end_unchanged are up to date. Do it | |
10069 | only if buffer has really changed. The reason is that the gap is | |
10070 | initially at Z for freshly visited files. The code below would | |
10071 | set end_unchanged to 0 in that case. */ | |
28ee91c0 GM |
10072 | if (MODIFF > SAVE_MODIFF |
10073 | /* This seems to happen sometimes after saving a buffer. */ | |
10074 | || BEG_UNCHANGED + END_UNCHANGED > Z_BYTE) | |
5f5c8ee5 | 10075 | { |
9142dd5b GM |
10076 | if (GPT - BEG < BEG_UNCHANGED) |
10077 | BEG_UNCHANGED = GPT - BEG; | |
10078 | if (Z - GPT < END_UNCHANGED) | |
10079 | END_UNCHANGED = Z - GPT; | |
5f5c8ee5 | 10080 | } |
bf9249e3 | 10081 | |
5f5c8ee5 GM |
10082 | /* If window starts after a line end, and the last change is in |
10083 | front of that newline, then changes don't affect the display. | |
f2d86d7a GM |
10084 | This case happens with stealth-fontification. Note that although |
10085 | the display is unchanged, glyph positions in the matrix have to | |
10086 | be adjusted, of course. */ | |
5f5c8ee5 GM |
10087 | row = MATRIX_ROW (w->current_matrix, XFASTINT (w->window_end_vpos)); |
10088 | if (CHARPOS (start) > BEGV | |
9142dd5b | 10089 | && Z - END_UNCHANGED < CHARPOS (start) - 1 |
5f5c8ee5 GM |
10090 | && FETCH_BYTE (BYTEPOS (start) - 1) == '\n' |
10091 | && PT < MATRIX_ROW_END_CHARPOS (row)) | |
10092 | { | |
f2d86d7a GM |
10093 | struct glyph_row *r0 = MATRIX_FIRST_TEXT_ROW (current_matrix); |
10094 | int delta = CHARPOS (start) - MATRIX_ROW_START_CHARPOS (r0); | |
10095 | ||
10096 | if (delta) | |
10097 | { | |
10098 | struct glyph_row *r1 = MATRIX_BOTTOM_TEXT_ROW (current_matrix, w); | |
10099 | int delta_bytes = BYTEPOS (start) - MATRIX_ROW_START_BYTEPOS (r0); | |
10100 | ||
10101 | increment_matrix_positions (w->current_matrix, | |
10102 | MATRIX_ROW_VPOS (r0, current_matrix), | |
10103 | MATRIX_ROW_VPOS (r1, current_matrix), | |
10104 | delta, delta_bytes); | |
10105 | } | |
10106 | ||
10107 | #if 0 /* If changes are all in front of the window start, the | |
10108 | distance of the last displayed glyph from Z hasn't | |
10109 | changed. */ | |
5f5c8ee5 GM |
10110 | w->window_end_pos |
10111 | = make_number (Z - MATRIX_ROW_END_CHARPOS (row)); | |
10112 | w->window_end_bytepos | |
6fc556fd | 10113 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row); |
f2d86d7a GM |
10114 | #endif |
10115 | ||
5f5c8ee5 GM |
10116 | return 1; |
10117 | } | |
10118 | ||
10119 | /* Return quickly if changes are all below what is displayed in the | |
10120 | window, and if PT is in the window. */ | |
9142dd5b | 10121 | if (BEG_UNCHANGED > MATRIX_ROW_END_CHARPOS (row) |
5f5c8ee5 GM |
10122 | && PT < MATRIX_ROW_END_CHARPOS (row)) |
10123 | { | |
10124 | /* We have to update window end positions because the buffer's | |
10125 | size has changed. */ | |
10126 | w->window_end_pos | |
10127 | = make_number (Z - MATRIX_ROW_END_CHARPOS (row)); | |
10128 | w->window_end_bytepos | |
6fc556fd | 10129 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row); |
5f5c8ee5 GM |
10130 | return 1; |
10131 | } | |
10132 | ||
10133 | /* Check that window start agrees with the start of the first glyph | |
10134 | row in its current matrix. Check this after we know the window | |
10135 | start is not in changed text, otherwise positions would not be | |
10136 | comparable. */ | |
10137 | row = MATRIX_FIRST_TEXT_ROW (w->current_matrix); | |
10138 | if (!TEXT_POS_EQUAL_P (start, row->start.pos)) | |
10139 | return 0; | |
10140 | ||
5f5c8ee5 GM |
10141 | /* Compute the position at which we have to start displaying new |
10142 | lines. Some of the lines at the top of the window might be | |
10143 | reusable because they are not displaying changed text. Find the | |
10144 | last row in W's current matrix not affected by changes at the | |
10145 | start of current_buffer. Value is null if changes start in the | |
10146 | first line of window. */ | |
10147 | last_unchanged_at_beg_row = get_last_unchanged_at_beg_row (w); | |
10148 | if (last_unchanged_at_beg_row) | |
10149 | { | |
10150 | init_to_row_end (&it, w, last_unchanged_at_beg_row); | |
10151 | start_pos = it.current.pos; | |
10152 | ||
10153 | /* Start displaying new lines in the desired matrix at the same | |
10154 | vpos we would use in the current matrix, i.e. below | |
10155 | last_unchanged_at_beg_row. */ | |
10156 | it.vpos = 1 + MATRIX_ROW_VPOS (last_unchanged_at_beg_row, | |
10157 | current_matrix); | |
10158 | it.glyph_row = MATRIX_ROW (desired_matrix, it.vpos); | |
10159 | it.current_y = MATRIX_ROW_BOTTOM_Y (last_unchanged_at_beg_row); | |
10160 | ||
10161 | xassert (it.hpos == 0 && it.current_x == 0); | |
10162 | } | |
10163 | else | |
10164 | { | |
10165 | /* There are no reusable lines at the start of the window. | |
10166 | Start displaying in the first line. */ | |
10167 | start_display (&it, w, start); | |
10168 | start_pos = it.current.pos; | |
10169 | } | |
10170 | ||
5f5c8ee5 GM |
10171 | /* Find the first row that is not affected by changes at the end of |
10172 | the buffer. Value will be null if there is no unchanged row, in | |
10173 | which case we must redisplay to the end of the window. delta | |
10174 | will be set to the value by which buffer positions beginning with | |
10175 | first_unchanged_at_end_row have to be adjusted due to text | |
10176 | changes. */ | |
10177 | first_unchanged_at_end_row | |
10178 | = get_first_unchanged_at_end_row (w, &delta, &delta_bytes); | |
10179 | IF_DEBUG (debug_delta = delta); | |
10180 | IF_DEBUG (debug_delta_bytes = delta_bytes); | |
10181 | ||
10182 | /* Set stop_pos to the buffer position up to which we will have to | |
10183 | display new lines. If first_unchanged_at_end_row != NULL, this | |
10184 | is the buffer position of the start of the line displayed in that | |
10185 | row. For first_unchanged_at_end_row == NULL, use 0 to indicate | |
10186 | that we don't stop at a buffer position. */ | |
10187 | stop_pos = 0; | |
10188 | if (first_unchanged_at_end_row) | |
10189 | { | |
10190 | xassert (last_unchanged_at_beg_row == NULL | |
10191 | || first_unchanged_at_end_row >= last_unchanged_at_beg_row); | |
10192 | ||
10193 | /* If this is a continuation line, move forward to the next one | |
10194 | that isn't. Changes in lines above affect this line. | |
10195 | Caution: this may move first_unchanged_at_end_row to a row | |
10196 | not displaying text. */ | |
10197 | while (MATRIX_ROW_CONTINUATION_LINE_P (first_unchanged_at_end_row) | |
10198 | && MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row) | |
10199 | && (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row) | |
10200 | < it.last_visible_y)) | |
10201 | ++first_unchanged_at_end_row; | |
10202 | ||
10203 | if (!MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row) | |
10204 | || (MATRIX_ROW_BOTTOM_Y (first_unchanged_at_end_row) | |
10205 | >= it.last_visible_y)) | |
10206 | first_unchanged_at_end_row = NULL; | |
10207 | else | |
10208 | { | |
10209 | stop_pos = (MATRIX_ROW_START_CHARPOS (first_unchanged_at_end_row) | |
10210 | + delta); | |
10211 | first_unchanged_at_end_vpos | |
10212 | = MATRIX_ROW_VPOS (first_unchanged_at_end_row, current_matrix); | |
9142dd5b | 10213 | xassert (stop_pos >= Z - END_UNCHANGED); |
5f5c8ee5 GM |
10214 | } |
10215 | } | |
10216 | else if (last_unchanged_at_beg_row == NULL) | |
10217 | return 0; | |
10218 | ||
10219 | ||
10220 | #if GLYPH_DEBUG | |
10221 | ||
10222 | /* Either there is no unchanged row at the end, or the one we have | |
10223 | now displays text. This is a necessary condition for the window | |
10224 | end pos calculation at the end of this function. */ | |
10225 | xassert (first_unchanged_at_end_row == NULL | |
10226 | || MATRIX_ROW_DISPLAYS_TEXT_P (first_unchanged_at_end_row)); | |
10227 | ||
10228 | debug_last_unchanged_at_beg_vpos | |
10229 | = (last_unchanged_at_beg_row | |
10230 | ? MATRIX_ROW_VPOS (last_unchanged_at_beg_row, current_matrix) | |
10231 | : -1); | |
10232 | debug_first_unchanged_at_end_vpos = first_unchanged_at_end_vpos; | |
10233 | ||
10234 | #endif /* GLYPH_DEBUG != 0 */ | |
10235 | ||
10236 | ||
10237 | /* Display new lines. Set last_text_row to the last new line | |
10238 | displayed which has text on it, i.e. might end up as being the | |
10239 | line where the window_end_vpos is. */ | |
10240 | w->cursor.vpos = -1; | |
10241 | last_text_row = NULL; | |
10242 | overlay_arrow_seen = 0; | |
10243 | while (it.current_y < it.last_visible_y | |
10244 | && !fonts_changed_p | |
10245 | && (first_unchanged_at_end_row == NULL | |
10246 | || IT_CHARPOS (it) < stop_pos)) | |
10247 | { | |
10248 | if (display_line (&it)) | |
10249 | last_text_row = it.glyph_row - 1; | |
10250 | } | |
10251 | ||
10252 | if (fonts_changed_p) | |
10253 | return -1; | |
10254 | ||
10255 | ||
10256 | /* Compute differences in buffer positions, y-positions etc. for | |
10257 | lines reused at the bottom of the window. Compute what we can | |
10258 | scroll. */ | |
ca42b2e8 GM |
10259 | if (first_unchanged_at_end_row |
10260 | /* No lines reused because we displayed everything up to the | |
10261 | bottom of the window. */ | |
10262 | && it.current_y < it.last_visible_y) | |
5f5c8ee5 GM |
10263 | { |
10264 | dvpos = (it.vpos | |
10265 | - MATRIX_ROW_VPOS (first_unchanged_at_end_row, | |
10266 | current_matrix)); | |
10267 | dy = it.current_y - first_unchanged_at_end_row->y; | |
10268 | run.current_y = first_unchanged_at_end_row->y; | |
10269 | run.desired_y = run.current_y + dy; | |
10270 | run.height = it.last_visible_y - max (run.current_y, run.desired_y); | |
10271 | } | |
10272 | else | |
ca42b2e8 GM |
10273 | { |
10274 | delta = dvpos = dy = run.current_y = run.desired_y = run.height = 0; | |
10275 | first_unchanged_at_end_row = NULL; | |
10276 | } | |
5f5c8ee5 GM |
10277 | IF_DEBUG (debug_dvpos = dvpos; debug_dy = dy); |
10278 | ||
8f8ba186 | 10279 | |
5f5c8ee5 GM |
10280 | /* Find the cursor if not already found. We have to decide whether |
10281 | PT will appear on this window (it sometimes doesn't, but this is | |
10282 | not a very frequent case.) This decision has to be made before | |
10283 | the current matrix is altered. A value of cursor.vpos < 0 means | |
10284 | that PT is either in one of the lines beginning at | |
10285 | first_unchanged_at_end_row or below the window. Don't care for | |
10286 | lines that might be displayed later at the window end; as | |
10287 | mentioned, this is not a frequent case. */ | |
10288 | if (w->cursor.vpos < 0) | |
10289 | { | |
5f5c8ee5 GM |
10290 | /* Cursor in unchanged rows at the top? */ |
10291 | if (PT < CHARPOS (start_pos) | |
10292 | && last_unchanged_at_beg_row) | |
10293 | { | |
e037b9ec GM |
10294 | row = row_containing_pos (w, PT, |
10295 | MATRIX_FIRST_TEXT_ROW (w->current_matrix), | |
10296 | last_unchanged_at_beg_row + 1); | |
10297 | xassert (row && row <= last_unchanged_at_beg_row); | |
5f5c8ee5 GM |
10298 | set_cursor_from_row (w, row, w->current_matrix, 0, 0, 0, 0); |
10299 | } | |
10300 | ||
10301 | /* Start from first_unchanged_at_end_row looking for PT. */ | |
10302 | else if (first_unchanged_at_end_row) | |
10303 | { | |
e037b9ec GM |
10304 | row = row_containing_pos (w, PT - delta, |
10305 | first_unchanged_at_end_row, NULL); | |
10306 | if (row) | |
468155d7 GM |
10307 | set_cursor_from_row (w, row, w->current_matrix, delta, |
10308 | delta_bytes, dy, dvpos); | |
5f5c8ee5 GM |
10309 | } |
10310 | ||
10311 | /* Give up if cursor was not found. */ | |
10312 | if (w->cursor.vpos < 0) | |
10313 | { | |
10314 | clear_glyph_matrix (w->desired_matrix); | |
10315 | return -1; | |
10316 | } | |
10317 | } | |
10318 | ||
10319 | /* Don't let the cursor end in the scroll margins. */ | |
10320 | { | |
10321 | int this_scroll_margin, cursor_height; | |
10322 | ||
10323 | this_scroll_margin = max (0, scroll_margin); | |
10324 | this_scroll_margin = min (this_scroll_margin, | |
10325 | XFASTINT (w->height) / 4); | |
10326 | this_scroll_margin *= CANON_Y_UNIT (it.f); | |
10327 | cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height; | |
10328 | ||
10329 | if ((w->cursor.y < this_scroll_margin | |
10330 | && CHARPOS (start) > BEGV) | |
10331 | /* Don't take scroll margin into account at the bottom because | |
10332 | old redisplay didn't do it either. */ | |
10333 | || w->cursor.y + cursor_height > it.last_visible_y) | |
10334 | { | |
10335 | w->cursor.vpos = -1; | |
10336 | clear_glyph_matrix (w->desired_matrix); | |
10337 | return -1; | |
10338 | } | |
10339 | } | |
10340 | ||
10341 | /* Scroll the display. Do it before changing the current matrix so | |
10342 | that xterm.c doesn't get confused about where the cursor glyph is | |
10343 | found. */ | |
fa77249f | 10344 | if (dy && run.height) |
5f5c8ee5 GM |
10345 | { |
10346 | update_begin (f); | |
10347 | ||
10348 | if (FRAME_WINDOW_P (f)) | |
10349 | { | |
10350 | rif->update_window_begin_hook (w); | |
10351 | rif->scroll_run_hook (w, &run); | |
10352 | rif->update_window_end_hook (w, 0); | |
10353 | } | |
10354 | else | |
10355 | { | |
10356 | /* Terminal frame. In this case, dvpos gives the number of | |
10357 | lines to scroll by; dvpos < 0 means scroll up. */ | |
10358 | int first_unchanged_at_end_vpos | |
10359 | = MATRIX_ROW_VPOS (first_unchanged_at_end_row, w->current_matrix); | |
10360 | int from = XFASTINT (w->top) + first_unchanged_at_end_vpos; | |
10361 | int end = XFASTINT (w->top) + window_internal_height (w); | |
10362 | ||
10363 | /* Perform the operation on the screen. */ | |
10364 | if (dvpos > 0) | |
10365 | { | |
10366 | /* Scroll last_unchanged_at_beg_row to the end of the | |
10367 | window down dvpos lines. */ | |
10368 | set_terminal_window (end); | |
10369 | ||
10370 | /* On dumb terminals delete dvpos lines at the end | |
10371 | before inserting dvpos empty lines. */ | |
10372 | if (!scroll_region_ok) | |
10373 | ins_del_lines (end - dvpos, -dvpos); | |
10374 | ||
10375 | /* Insert dvpos empty lines in front of | |
10376 | last_unchanged_at_beg_row. */ | |
10377 | ins_del_lines (from, dvpos); | |
10378 | } | |
10379 | else if (dvpos < 0) | |
10380 | { | |
10381 | /* Scroll up last_unchanged_at_beg_vpos to the end of | |
10382 | the window to last_unchanged_at_beg_vpos - |dvpos|. */ | |
10383 | set_terminal_window (end); | |
10384 | ||
10385 | /* Delete dvpos lines in front of | |
10386 | last_unchanged_at_beg_vpos. ins_del_lines will set | |
10387 | the cursor to the given vpos and emit |dvpos| delete | |
10388 | line sequences. */ | |
10389 | ins_del_lines (from + dvpos, dvpos); | |
10390 | ||
10391 | /* On a dumb terminal insert dvpos empty lines at the | |
10392 | end. */ | |
10393 | if (!scroll_region_ok) | |
10394 | ins_del_lines (end + dvpos, -dvpos); | |
10395 | } | |
10396 | ||
10397 | set_terminal_window (0); | |
10398 | } | |
10399 | ||
10400 | update_end (f); | |
10401 | } | |
10402 | ||
ca42b2e8 GM |
10403 | /* Shift reused rows of the current matrix to the right position. |
10404 | BOTTOM_ROW is the last + 1 row in the current matrix reserved for | |
10405 | text. */ | |
10406 | bottom_row = MATRIX_BOTTOM_TEXT_ROW (current_matrix, w); | |
10407 | bottom_vpos = MATRIX_ROW_VPOS (bottom_row, current_matrix); | |
5f5c8ee5 GM |
10408 | if (dvpos < 0) |
10409 | { | |
10410 | rotate_matrix (current_matrix, first_unchanged_at_end_vpos + dvpos, | |
10411 | bottom_vpos, dvpos); | |
10412 | enable_glyph_matrix_rows (current_matrix, bottom_vpos + dvpos, | |
10413 | bottom_vpos, 0); | |
10414 | } | |
10415 | else if (dvpos > 0) | |
10416 | { | |
10417 | rotate_matrix (current_matrix, first_unchanged_at_end_vpos, | |
10418 | bottom_vpos, dvpos); | |
10419 | enable_glyph_matrix_rows (current_matrix, first_unchanged_at_end_vpos, | |
10420 | first_unchanged_at_end_vpos + dvpos, 0); | |
10421 | } | |
10422 | ||
10423 | /* For frame-based redisplay, make sure that current frame and window | |
10424 | matrix are in sync with respect to glyph memory. */ | |
10425 | if (!FRAME_WINDOW_P (f)) | |
10426 | sync_frame_with_window_matrix_rows (w); | |
10427 | ||
10428 | /* Adjust buffer positions in reused rows. */ | |
10429 | if (delta) | |
f2d86d7a GM |
10430 | increment_matrix_positions (current_matrix, |
10431 | first_unchanged_at_end_vpos + dvpos, | |
10432 | bottom_vpos, delta, delta_bytes); | |
5f5c8ee5 GM |
10433 | |
10434 | /* Adjust Y positions. */ | |
10435 | if (dy) | |
10436 | shift_glyph_matrix (w, current_matrix, | |
10437 | first_unchanged_at_end_vpos + dvpos, | |
10438 | bottom_vpos, dy); | |
10439 | ||
10440 | if (first_unchanged_at_end_row) | |
10441 | first_unchanged_at_end_row += dvpos; | |
10442 | ||
10443 | /* If scrolling up, there may be some lines to display at the end of | |
10444 | the window. */ | |
10445 | last_text_row_at_end = NULL; | |
10446 | if (dy < 0) | |
10447 | { | |
10448 | /* Set last_row to the glyph row in the current matrix where the | |
10449 | window end line is found. It has been moved up or down in | |
10450 | the matrix by dvpos. */ | |
10451 | int last_vpos = XFASTINT (w->window_end_vpos) + dvpos; | |
10452 | struct glyph_row *last_row = MATRIX_ROW (current_matrix, last_vpos); | |
10453 | ||
10454 | /* If last_row is the window end line, it should display text. */ | |
10455 | xassert (last_row->displays_text_p); | |
10456 | ||
10457 | /* If window end line was partially visible before, begin | |
10458 | displaying at that line. Otherwise begin displaying with the | |
10459 | line following it. */ | |
10460 | if (MATRIX_ROW_BOTTOM_Y (last_row) - dy >= it.last_visible_y) | |
10461 | { | |
10462 | init_to_row_start (&it, w, last_row); | |
10463 | it.vpos = last_vpos; | |
10464 | it.current_y = last_row->y; | |
10465 | } | |
10466 | else | |
10467 | { | |
10468 | init_to_row_end (&it, w, last_row); | |
10469 | it.vpos = 1 + last_vpos; | |
10470 | it.current_y = MATRIX_ROW_BOTTOM_Y (last_row); | |
10471 | ++last_row; | |
10472 | } | |
12adba34 | 10473 | |
5f5c8ee5 GM |
10474 | /* We may start in a continuation line. If so, we have to get |
10475 | the right continuation_lines_width and current_x. */ | |
10476 | it.continuation_lines_width = last_row->continuation_lines_width; | |
10477 | it.hpos = it.current_x = 0; | |
10478 | ||
10479 | /* Display the rest of the lines at the window end. */ | |
10480 | it.glyph_row = MATRIX_ROW (desired_matrix, it.vpos); | |
10481 | while (it.current_y < it.last_visible_y | |
10482 | && !fonts_changed_p) | |
10483 | { | |
10484 | /* Is it always sure that the display agrees with lines in | |
10485 | the current matrix? I don't think so, so we mark rows | |
10486 | displayed invalid in the current matrix by setting their | |
10487 | enabled_p flag to zero. */ | |
10488 | MATRIX_ROW (w->current_matrix, it.vpos)->enabled_p = 0; | |
10489 | if (display_line (&it)) | |
10490 | last_text_row_at_end = it.glyph_row - 1; | |
10491 | } | |
10492 | } | |
12adba34 | 10493 | |
5f5c8ee5 GM |
10494 | /* Update window_end_pos and window_end_vpos. */ |
10495 | if (first_unchanged_at_end_row | |
10496 | && first_unchanged_at_end_row->y < it.last_visible_y | |
10497 | && !last_text_row_at_end) | |
10498 | { | |
10499 | /* Window end line if one of the preserved rows from the current | |
10500 | matrix. Set row to the last row displaying text in current | |
10501 | matrix starting at first_unchanged_at_end_row, after | |
10502 | scrolling. */ | |
10503 | xassert (first_unchanged_at_end_row->displays_text_p); | |
10504 | row = find_last_row_displaying_text (w->current_matrix, &it, | |
10505 | first_unchanged_at_end_row); | |
10506 | xassert (row && MATRIX_ROW_DISPLAYS_TEXT_P (row)); | |
10507 | ||
10508 | XSETFASTINT (w->window_end_pos, Z - MATRIX_ROW_END_CHARPOS (row)); | |
10509 | w->window_end_bytepos = Z_BYTE - MATRIX_ROW_END_BYTEPOS (row); | |
10510 | XSETFASTINT (w->window_end_vpos, | |
10511 | MATRIX_ROW_VPOS (row, w->current_matrix)); | |
10512 | } | |
10513 | else if (last_text_row_at_end) | |
10514 | { | |
10515 | XSETFASTINT (w->window_end_pos, | |
10516 | Z - MATRIX_ROW_END_CHARPOS (last_text_row_at_end)); | |
10517 | w->window_end_bytepos | |
10518 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row_at_end); | |
10519 | XSETFASTINT (w->window_end_vpos, | |
10520 | MATRIX_ROW_VPOS (last_text_row_at_end, desired_matrix)); | |
10521 | } | |
10522 | else if (last_text_row) | |
10523 | { | |
10524 | /* We have displayed either to the end of the window or at the | |
10525 | end of the window, i.e. the last row with text is to be found | |
10526 | in the desired matrix. */ | |
10527 | XSETFASTINT (w->window_end_pos, | |
10528 | Z - MATRIX_ROW_END_CHARPOS (last_text_row)); | |
10529 | w->window_end_bytepos | |
10530 | = Z_BYTE - MATRIX_ROW_END_BYTEPOS (last_text_row); | |
10531 | XSETFASTINT (w->window_end_vpos, | |
10532 | MATRIX_ROW_VPOS (last_text_row, desired_matrix)); | |
10533 | } | |
10534 | else if (first_unchanged_at_end_row == NULL | |
10535 | && last_text_row == NULL | |
10536 | && last_text_row_at_end == NULL) | |
10537 | { | |
10538 | /* Displayed to end of window, but no line containing text was | |
10539 | displayed. Lines were deleted at the end of the window. */ | |
10540 | int vpos; | |
045dee35 | 10541 | int header_line_p = WINDOW_WANTS_HEADER_LINE_P (w) ? 1 : 0; |
5f5c8ee5 GM |
10542 | |
10543 | for (vpos = XFASTINT (w->window_end_vpos); vpos > 0; --vpos) | |
045dee35 GM |
10544 | if ((w->desired_matrix->rows[vpos + header_line_p].enabled_p |
10545 | && w->desired_matrix->rows[vpos + header_line_p].displays_text_p) | |
10546 | || (!w->desired_matrix->rows[vpos + header_line_p].enabled_p | |
10547 | && w->current_matrix->rows[vpos + header_line_p].displays_text_p)) | |
5f5c8ee5 | 10548 | break; |
12adba34 | 10549 | |
5f5c8ee5 GM |
10550 | w->window_end_vpos = make_number (vpos); |
10551 | } | |
10552 | else | |
10553 | abort (); | |
10554 | ||
10555 | IF_DEBUG (debug_end_pos = XFASTINT (w->window_end_pos); | |
10556 | debug_end_vpos = XFASTINT (w->window_end_vpos)); | |
12adba34 | 10557 | |
5f5c8ee5 GM |
10558 | /* Record that display has not been completed. */ |
10559 | w->window_end_valid = Qnil; | |
10560 | w->desired_matrix->no_scrolling_p = 1; | |
10561 | return 1; | |
12adba34 | 10562 | } |
0f9c0ff0 | 10563 | |
a2889657 | 10564 | |
5f5c8ee5 GM |
10565 | \f |
10566 | /*********************************************************************** | |
10567 | More debugging support | |
10568 | ***********************************************************************/ | |
a2889657 | 10569 | |
5f5c8ee5 | 10570 | #if GLYPH_DEBUG |
a2889657 | 10571 | |
5f5c8ee5 GM |
10572 | void dump_glyph_row P_ ((struct glyph_matrix *, int, int)); |
10573 | static void dump_glyph_matrix P_ ((struct glyph_matrix *, int)); | |
1c9241f5 | 10574 | |
31b24551 | 10575 | |
5f5c8ee5 GM |
10576 | /* Dump the contents of glyph matrix MATRIX on stderr. If |
10577 | WITH_GLYPHS_P is non-zero, dump glyph contents as well. */ | |
ca26e1c8 | 10578 | |
5f5c8ee5 GM |
10579 | void |
10580 | dump_glyph_matrix (matrix, with_glyphs_p) | |
10581 | struct glyph_matrix *matrix; | |
10582 | int with_glyphs_p; | |
10583 | { | |
efc63ef0 | 10584 | int i; |
5f5c8ee5 GM |
10585 | for (i = 0; i < matrix->nrows; ++i) |
10586 | dump_glyph_row (matrix, i, with_glyphs_p); | |
10587 | } | |
31b24551 | 10588 | |
68a37fa8 | 10589 | |
5f5c8ee5 GM |
10590 | /* Dump the contents of glyph row at VPOS in MATRIX to stderr. |
10591 | WITH_GLYPH_SP non-zero means dump glyph contents, too. */ | |
a2889657 | 10592 | |
5f5c8ee5 GM |
10593 | void |
10594 | dump_glyph_row (matrix, vpos, with_glyphs_p) | |
10595 | struct glyph_matrix *matrix; | |
10596 | int vpos, with_glyphs_p; | |
10597 | { | |
10598 | struct glyph_row *row; | |
10599 | ||
10600 | if (vpos < 0 || vpos >= matrix->nrows) | |
10601 | return; | |
10602 | ||
10603 | row = MATRIX_ROW (matrix, vpos); | |
10604 | ||
10605 | fprintf (stderr, "Row Start End Used oEI><O\\CTZF X Y W\n"); | |
10606 | fprintf (stderr, "=============================================\n"); | |
10607 | ||
10608 | fprintf (stderr, "%3d %5d %5d %4d %1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d%1.1d %4d %4d %4d\n", | |
10609 | row - matrix->rows, | |
10610 | MATRIX_ROW_START_CHARPOS (row), | |
10611 | MATRIX_ROW_END_CHARPOS (row), | |
10612 | row->used[TEXT_AREA], | |
10613 | row->contains_overlapping_glyphs_p, | |
10614 | row->enabled_p, | |
10615 | row->inverse_p, | |
10616 | row->truncated_on_left_p, | |
10617 | row->truncated_on_right_p, | |
10618 | row->overlay_arrow_p, | |
10619 | row->continued_p, | |
10620 | MATRIX_ROW_CONTINUATION_LINE_P (row), | |
10621 | row->displays_text_p, | |
10622 | row->ends_at_zv_p, | |
10623 | row->fill_line_p, | |
10624 | row->x, | |
10625 | row->y, | |
10626 | row->pixel_width); | |
10627 | fprintf (stderr, "%9d %5d\n", row->start.overlay_string_index, | |
10628 | row->end.overlay_string_index); | |
10629 | fprintf (stderr, "%9d %5d\n", | |
10630 | CHARPOS (row->start.string_pos), | |
10631 | CHARPOS (row->end.string_pos)); | |
10632 | fprintf (stderr, "%9d %5d\n", row->start.dpvec_index, | |
10633 | row->end.dpvec_index); | |
10634 | ||
10635 | if (with_glyphs_p) | |
bd66d1ba | 10636 | { |
5f5c8ee5 GM |
10637 | struct glyph *glyph, *glyph_end; |
10638 | int prev_had_glyphs_p; | |
10639 | ||
10640 | glyph = row->glyphs[TEXT_AREA]; | |
10641 | glyph_end = glyph + row->used[TEXT_AREA]; | |
10642 | ||
10643 | /* Glyph for a line end in text. */ | |
10644 | if (glyph == glyph_end && glyph->charpos > 0) | |
10645 | ++glyph_end; | |
10646 | ||
10647 | if (glyph < glyph_end) | |
bd66d1ba | 10648 | { |
5f5c8ee5 GM |
10649 | fprintf (stderr, " Glyph Type Pos W Code C Face LR\n"); |
10650 | prev_had_glyphs_p = 1; | |
bd66d1ba RS |
10651 | } |
10652 | else | |
5f5c8ee5 GM |
10653 | prev_had_glyphs_p = 0; |
10654 | ||
10655 | while (glyph < glyph_end) | |
f7b4b63a | 10656 | { |
5f5c8ee5 GM |
10657 | if (glyph->type == CHAR_GLYPH) |
10658 | { | |
10659 | fprintf (stderr, | |
10660 | " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n", | |
10661 | glyph - row->glyphs[TEXT_AREA], | |
10662 | 'C', | |
10663 | glyph->charpos, | |
10664 | glyph->pixel_width, | |
43d120d8 KH |
10665 | glyph->u.ch, |
10666 | (glyph->u.ch < 0x80 && glyph->u.ch >= ' ' | |
10667 | ? glyph->u.ch | |
5f5c8ee5 | 10668 | : '.'), |
43d120d8 | 10669 | glyph->face_id, |
5f5c8ee5 GM |
10670 | glyph->left_box_line_p, |
10671 | glyph->right_box_line_p); | |
10672 | } | |
10673 | else if (glyph->type == STRETCH_GLYPH) | |
10674 | { | |
10675 | fprintf (stderr, | |
10676 | " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n", | |
10677 | glyph - row->glyphs[TEXT_AREA], | |
10678 | 'S', | |
10679 | glyph->charpos, | |
10680 | glyph->pixel_width, | |
10681 | 0, | |
10682 | '.', | |
bcdda9a4 | 10683 | glyph->face_id, |
5f5c8ee5 GM |
10684 | glyph->left_box_line_p, |
10685 | glyph->right_box_line_p); | |
10686 | } | |
10687 | else if (glyph->type == IMAGE_GLYPH) | |
10688 | { | |
10689 | fprintf (stderr, | |
10690 | " %5d %4c %6d %3d 0x%05x %c %4d %1.1d%1.1d\n", | |
10691 | glyph - row->glyphs[TEXT_AREA], | |
10692 | 'I', | |
10693 | glyph->charpos, | |
10694 | glyph->pixel_width, | |
43d120d8 | 10695 | glyph->u.img_id, |
5f5c8ee5 | 10696 | '.', |
bcdda9a4 | 10697 | glyph->face_id, |
5f5c8ee5 GM |
10698 | glyph->left_box_line_p, |
10699 | glyph->right_box_line_p); | |
10700 | } | |
10701 | ++glyph; | |
f7b4b63a | 10702 | } |
f4faa47c | 10703 | } |
5f5c8ee5 | 10704 | } |
f4faa47c | 10705 | |
a2889657 | 10706 | |
5f5c8ee5 GM |
10707 | DEFUN ("dump-glyph-matrix", Fdump_glyph_matrix, |
10708 | Sdump_glyph_matrix, 0, 1, "p", | |
10709 | "Dump the current matrix of the selected window to stderr.\n\ | |
10710 | Shows contents of glyph row structures. With non-nil optional\n\ | |
10711 | parameter WITH-GLYPHS-P, dump glyphs as well.") | |
10712 | (with_glyphs_p) | |
02513cdd | 10713 | Lisp_Object with_glyphs_p; |
5f5c8ee5 GM |
10714 | { |
10715 | struct window *w = XWINDOW (selected_window); | |
10716 | struct buffer *buffer = XBUFFER (w->buffer); | |
10717 | ||
10718 | fprintf (stderr, "PT = %d, BEGV = %d. ZV = %d\n", | |
10719 | BUF_PT (buffer), BUF_BEGV (buffer), BUF_ZV (buffer)); | |
10720 | fprintf (stderr, "Cursor x = %d, y = %d, hpos = %d, vpos = %d\n", | |
10721 | w->cursor.x, w->cursor.y, w->cursor.hpos, w->cursor.vpos); | |
10722 | fprintf (stderr, "=============================================\n"); | |
10723 | dump_glyph_matrix (w->current_matrix, !NILP (with_glyphs_p)); | |
10724 | return Qnil; | |
10725 | } | |
1c2250c2 | 10726 | |
1fca3fae | 10727 | |
5f5c8ee5 GM |
10728 | DEFUN ("dump-glyph-row", Fdump_glyph_row, Sdump_glyph_row, 1, 1, "", |
10729 | "Dump glyph row ROW to stderr.") | |
10730 | (row) | |
10731 | Lisp_Object row; | |
10732 | { | |
10733 | CHECK_NUMBER (row, 0); | |
10734 | dump_glyph_row (XWINDOW (selected_window)->current_matrix, XINT (row), 1); | |
10735 | return Qnil; | |
10736 | } | |
1fca3fae | 10737 | |
67481ae5 | 10738 | |
e037b9ec | 10739 | DEFUN ("dump-tool-bar-row", Fdump_tool_bar_row, Sdump_tool_bar_row, |
5f5c8ee5 GM |
10740 | 0, 0, "", "") |
10741 | () | |
10742 | { | |
886bd6f2 GM |
10743 | struct frame *sf = SELECTED_FRAME (); |
10744 | struct glyph_matrix *m = (XWINDOW (sf->tool_bar_window) | |
5f5c8ee5 GM |
10745 | ->current_matrix); |
10746 | dump_glyph_row (m, 0, 1); | |
10747 | return Qnil; | |
10748 | } | |
ca26e1c8 | 10749 | |
0f9c0ff0 | 10750 | |
5f5c8ee5 GM |
10751 | DEFUN ("trace-redisplay-toggle", Ftrace_redisplay_toggle, |
10752 | Strace_redisplay_toggle, 0, 0, "", | |
10753 | "Toggle tracing of redisplay.") | |
10754 | () | |
10755 | { | |
10756 | trace_redisplay_p = !trace_redisplay_p; | |
10757 | return Qnil; | |
10758 | } | |
bf9249e3 GM |
10759 | |
10760 | ||
10761 | DEFUN ("trace-to-stderr", Ftrace_to_stderr, Strace_to_stderr, 1, 1, "", | |
10762 | "Print STRING to stderr.") | |
10763 | (string) | |
10764 | Lisp_Object string; | |
10765 | { | |
10766 | CHECK_STRING (string, 0); | |
10767 | fprintf (stderr, "%s", XSTRING (string)->data); | |
10768 | return Qnil; | |
10769 | } | |
5f5c8ee5 GM |
10770 | |
10771 | #endif /* GLYPH_DEBUG */ | |
ca26e1c8 | 10772 | |
ca26e1c8 | 10773 | |
5f5c8ee5 GM |
10774 | \f |
10775 | /*********************************************************************** | |
10776 | Building Desired Matrix Rows | |
10777 | ***********************************************************************/ | |
a2889657 | 10778 | |
5f5c8ee5 GM |
10779 | /* Return a temporary glyph row holding the glyphs of an overlay |
10780 | arrow. Only used for non-window-redisplay windows. */ | |
ca26e1c8 | 10781 | |
5f5c8ee5 GM |
10782 | static struct glyph_row * |
10783 | get_overlay_arrow_glyph_row (w) | |
10784 | struct window *w; | |
10785 | { | |
10786 | struct frame *f = XFRAME (WINDOW_FRAME (w)); | |
10787 | struct buffer *buffer = XBUFFER (w->buffer); | |
10788 | struct buffer *old = current_buffer; | |
10789 | unsigned char *arrow_string = XSTRING (Voverlay_arrow_string)->data; | |
10790 | int arrow_len = XSTRING (Voverlay_arrow_string)->size; | |
10791 | unsigned char *arrow_end = arrow_string + arrow_len; | |
10792 | unsigned char *p; | |
10793 | struct it it; | |
10794 | int multibyte_p; | |
10795 | int n_glyphs_before; | |
10796 | ||
10797 | set_buffer_temp (buffer); | |
10798 | init_iterator (&it, w, -1, -1, &scratch_glyph_row, DEFAULT_FACE_ID); | |
10799 | it.glyph_row->used[TEXT_AREA] = 0; | |
10800 | SET_TEXT_POS (it.position, 0, 0); | |
10801 | ||
10802 | multibyte_p = !NILP (buffer->enable_multibyte_characters); | |
10803 | p = arrow_string; | |
10804 | while (p < arrow_end) | |
10805 | { | |
10806 | Lisp_Object face, ilisp; | |
10807 | ||
10808 | /* Get the next character. */ | |
10809 | if (multibyte_p) | |
4fdb80f2 | 10810 | it.c = string_char_and_length (p, arrow_len, &it.len); |
5f5c8ee5 GM |
10811 | else |
10812 | it.c = *p, it.len = 1; | |
10813 | p += it.len; | |
10814 | ||
10815 | /* Get its face. */ | |
10816 | XSETFASTINT (ilisp, p - arrow_string); | |
10817 | face = Fget_text_property (ilisp, Qface, Voverlay_arrow_string); | |
10818 | it.face_id = compute_char_face (f, it.c, face); | |
10819 | ||
10820 | /* Compute its width, get its glyphs. */ | |
10821 | n_glyphs_before = it.glyph_row->used[TEXT_AREA]; | |
337042a9 | 10822 | SET_TEXT_POS (it.position, -1, -1); |
5f5c8ee5 GM |
10823 | PRODUCE_GLYPHS (&it); |
10824 | ||
10825 | /* If this character doesn't fit any more in the line, we have | |
10826 | to remove some glyphs. */ | |
10827 | if (it.current_x > it.last_visible_x) | |
10828 | { | |
10829 | it.glyph_row->used[TEXT_AREA] = n_glyphs_before; | |
10830 | break; | |
10831 | } | |
10832 | } | |
10833 | ||
10834 | set_buffer_temp (old); | |
10835 | return it.glyph_row; | |
10836 | } | |
ca26e1c8 | 10837 | |
b0a0fbda | 10838 | |
5f5c8ee5 GM |
10839 | /* Insert truncation glyphs at the start of IT->glyph_row. Truncation |
10840 | glyphs are only inserted for terminal frames since we can't really | |
10841 | win with truncation glyphs when partially visible glyphs are | |
10842 | involved. Which glyphs to insert is determined by | |
10843 | produce_special_glyphs. */ | |
67481ae5 | 10844 | |
5f5c8ee5 GM |
10845 | static void |
10846 | insert_left_trunc_glyphs (it) | |
10847 | struct it *it; | |
10848 | { | |
10849 | struct it truncate_it; | |
10850 | struct glyph *from, *end, *to, *toend; | |
10851 | ||
10852 | xassert (!FRAME_WINDOW_P (it->f)); | |
10853 | ||
10854 | /* Get the truncation glyphs. */ | |
10855 | truncate_it = *it; | |
5f5c8ee5 GM |
10856 | truncate_it.current_x = 0; |
10857 | truncate_it.face_id = DEFAULT_FACE_ID; | |
10858 | truncate_it.glyph_row = &scratch_glyph_row; | |
10859 | truncate_it.glyph_row->used[TEXT_AREA] = 0; | |
10860 | CHARPOS (truncate_it.position) = BYTEPOS (truncate_it.position) = -1; | |
6fc556fd | 10861 | truncate_it.object = make_number (0); |
5f5c8ee5 GM |
10862 | produce_special_glyphs (&truncate_it, IT_TRUNCATION); |
10863 | ||
10864 | /* Overwrite glyphs from IT with truncation glyphs. */ | |
10865 | from = truncate_it.glyph_row->glyphs[TEXT_AREA]; | |
10866 | end = from + truncate_it.glyph_row->used[TEXT_AREA]; | |
10867 | to = it->glyph_row->glyphs[TEXT_AREA]; | |
10868 | toend = to + it->glyph_row->used[TEXT_AREA]; | |
10869 | ||
10870 | while (from < end) | |
10871 | *to++ = *from++; | |
10872 | ||
10873 | /* There may be padding glyphs left over. Remove them. */ | |
10874 | from = to; | |
10875 | while (from < toend && CHAR_GLYPH_PADDING_P (*from)) | |
10876 | ++from; | |
10877 | while (from < toend) | |
10878 | *to++ = *from++; | |
10879 | ||
10880 | it->glyph_row->used[TEXT_AREA] = to - it->glyph_row->glyphs[TEXT_AREA]; | |
10881 | } | |
e0bfbde6 | 10882 | |
e0bfbde6 | 10883 | |
5f5c8ee5 | 10884 | /* Compute the pixel height and width of IT->glyph_row. |
9c49d3d7 | 10885 | |
5f5c8ee5 GM |
10886 | Most of the time, ascent and height of a display line will be equal |
10887 | to the max_ascent and max_height values of the display iterator | |
10888 | structure. This is not the case if | |
67481ae5 | 10889 | |
5f5c8ee5 GM |
10890 | 1. We hit ZV without displaying anything. In this case, max_ascent |
10891 | and max_height will be zero. | |
1c9241f5 | 10892 | |
5f5c8ee5 GM |
10893 | 2. We have some glyphs that don't contribute to the line height. |
10894 | (The glyph row flag contributes_to_line_height_p is for future | |
10895 | pixmap extensions). | |
f6fd109b | 10896 | |
5f5c8ee5 GM |
10897 | The first case is easily covered by using default values because in |
10898 | these cases, the line height does not really matter, except that it | |
10899 | must not be zero. */ | |
67481ae5 | 10900 | |
5f5c8ee5 GM |
10901 | static void |
10902 | compute_line_metrics (it) | |
10903 | struct it *it; | |
10904 | { | |
10905 | struct glyph_row *row = it->glyph_row; | |
10906 | int area, i; | |
1c2250c2 | 10907 | |
5f5c8ee5 GM |
10908 | if (FRAME_WINDOW_P (it->f)) |
10909 | { | |
045dee35 | 10910 | int i, header_line_height; |
1c2250c2 | 10911 | |
5f5c8ee5 GM |
10912 | /* The line may consist of one space only, that was added to |
10913 | place the cursor on it. If so, the row's height hasn't been | |
10914 | computed yet. */ | |
10915 | if (row->height == 0) | |
10916 | { | |
10917 | if (it->max_ascent + it->max_descent == 0) | |
312246d1 | 10918 | it->max_descent = it->max_phys_descent = CANON_Y_UNIT (it->f); |
5f5c8ee5 GM |
10919 | row->ascent = it->max_ascent; |
10920 | row->height = it->max_ascent + it->max_descent; | |
312246d1 GM |
10921 | row->phys_ascent = it->max_phys_ascent; |
10922 | row->phys_height = it->max_phys_ascent + it->max_phys_descent; | |
5f5c8ee5 GM |
10923 | } |
10924 | ||
10925 | /* Compute the width of this line. */ | |
10926 | row->pixel_width = row->x; | |
10927 | for (i = 0; i < row->used[TEXT_AREA]; ++i) | |
10928 | row->pixel_width += row->glyphs[TEXT_AREA][i].pixel_width; | |
10929 | ||
10930 | xassert (row->pixel_width >= 0); | |
10931 | xassert (row->ascent >= 0 && row->height > 0); | |
10932 | ||
312246d1 GM |
10933 | row->overlapping_p = (MATRIX_ROW_OVERLAPS_SUCC_P (row) |
10934 | || MATRIX_ROW_OVERLAPS_PRED_P (row)); | |
10935 | ||
10936 | /* If first line's physical ascent is larger than its logical | |
10937 | ascent, use the physical ascent, and make the row taller. | |
10938 | This makes accented characters fully visible. */ | |
10939 | if (row == it->w->desired_matrix->rows | |
10940 | && row->phys_ascent > row->ascent) | |
10941 | { | |
10942 | row->height += row->phys_ascent - row->ascent; | |
10943 | row->ascent = row->phys_ascent; | |
10944 | } | |
10945 | ||
5f5c8ee5 GM |
10946 | /* Compute how much of the line is visible. */ |
10947 | row->visible_height = row->height; | |
10948 | ||
045dee35 GM |
10949 | header_line_height = WINDOW_DISPLAY_HEADER_LINE_HEIGHT (it->w); |
10950 | if (row->y < header_line_height) | |
10951 | row->visible_height -= header_line_height - row->y; | |
5f5c8ee5 GM |
10952 | else |
10953 | { | |
10954 | int max_y = WINDOW_DISPLAY_HEIGHT_NO_MODE_LINE (it->w); | |
10955 | if (row->y + row->height > max_y) | |
10956 | row->visible_height -= row->y + row->height - max_y; | |
10957 | } | |
10958 | } | |
10959 | else | |
10960 | { | |
10961 | row->pixel_width = row->used[TEXT_AREA]; | |
312246d1 GM |
10962 | row->ascent = row->phys_ascent = 0; |
10963 | row->height = row->phys_height = row->visible_height = 1; | |
5f5c8ee5 | 10964 | } |
67481ae5 | 10965 | |
5f5c8ee5 GM |
10966 | /* Compute a hash code for this row. */ |
10967 | row->hash = 0; | |
10968 | for (area = LEFT_MARGIN_AREA; area < LAST_AREA; ++area) | |
10969 | for (i = 0; i < row->used[area]; ++i) | |
10970 | row->hash = ((((row->hash << 4) + (row->hash >> 24)) & 0x0fffffff) | |
10971 | + row->glyphs[area][i].u.val | |
43d120d8 KH |
10972 | + row->glyphs[area][i].face_id |
10973 | + row->glyphs[area][i].padding_p | |
5f5c8ee5 | 10974 | + (row->glyphs[area][i].type << 2)); |
a2889657 | 10975 | |
5f5c8ee5 | 10976 | it->max_ascent = it->max_descent = 0; |
312246d1 | 10977 | it->max_phys_ascent = it->max_phys_descent = 0; |
5f5c8ee5 | 10978 | } |
12adba34 | 10979 | |
ca26e1c8 | 10980 | |
5f5c8ee5 GM |
10981 | /* Append one space to the glyph row of iterator IT if doing a |
10982 | window-based redisplay. DEFAULT_FACE_P non-zero means let the | |
10983 | space have the default face, otherwise let it have the same face as | |
80c6cb1f | 10984 | IT->face_id. Value is non-zero if a space was added. |
c6e89d6c GM |
10985 | |
10986 | This function is called to make sure that there is always one glyph | |
10987 | at the end of a glyph row that the cursor can be set on under | |
10988 | window-systems. (If there weren't such a glyph we would not know | |
10989 | how wide and tall a box cursor should be displayed). | |
10990 | ||
10991 | At the same time this space let's a nicely handle clearing to the | |
10992 | end of the line if the row ends in italic text. */ | |
ca26e1c8 | 10993 | |
80c6cb1f | 10994 | static int |
5f5c8ee5 GM |
10995 | append_space (it, default_face_p) |
10996 | struct it *it; | |
10997 | int default_face_p; | |
10998 | { | |
10999 | if (FRAME_WINDOW_P (it->f)) | |
11000 | { | |
11001 | int n = it->glyph_row->used[TEXT_AREA]; | |
ca26e1c8 | 11002 | |
5f5c8ee5 GM |
11003 | if (it->glyph_row->glyphs[TEXT_AREA] + n |
11004 | < it->glyph_row->glyphs[1 + TEXT_AREA]) | |
a2889657 | 11005 | { |
5f5c8ee5 GM |
11006 | /* Save some values that must not be changed. */ |
11007 | int saved_x = it->current_x; | |
11008 | struct text_pos saved_pos; | |
11009 | int saved_what = it->what; | |
11010 | int saved_face_id = it->face_id; | |
5f5c8ee5 | 11011 | Lisp_Object saved_object; |
980806b6 | 11012 | struct face *face; |
5f5c8ee5 GM |
11013 | |
11014 | saved_object = it->object; | |
11015 | saved_pos = it->position; | |
11016 | ||
11017 | it->what = IT_CHARACTER; | |
11018 | bzero (&it->position, sizeof it->position); | |
6fc556fd | 11019 | it->object = make_number (0); |
5f5c8ee5 GM |
11020 | it->c = ' '; |
11021 | it->len = 1; | |
5f5c8ee5 GM |
11022 | |
11023 | if (default_face_p) | |
11024 | it->face_id = DEFAULT_FACE_ID; | |
980806b6 KH |
11025 | face = FACE_FROM_ID (it->f, it->face_id); |
11026 | it->face_id = FACE_FOR_CHAR (it->f, face, 0); | |
1842fc1a | 11027 | |
5f5c8ee5 GM |
11028 | PRODUCE_GLYPHS (it); |
11029 | ||
11030 | it->current_x = saved_x; | |
11031 | it->object = saved_object; | |
11032 | it->position = saved_pos; | |
11033 | it->what = saved_what; | |
11034 | it->face_id = saved_face_id; | |
80c6cb1f | 11035 | return 1; |
5f5c8ee5 GM |
11036 | } |
11037 | } | |
80c6cb1f GM |
11038 | |
11039 | return 0; | |
5f5c8ee5 | 11040 | } |
12adba34 | 11041 | |
1842fc1a | 11042 | |
5f5c8ee5 GM |
11043 | /* Extend the face of the last glyph in the text area of IT->glyph_row |
11044 | to the end of the display line. Called from display_line. | |
11045 | If the glyph row is empty, add a space glyph to it so that we | |
11046 | know the face to draw. Set the glyph row flag fill_line_p. */ | |
11047 | ||
11048 | static void | |
11049 | extend_face_to_end_of_line (it) | |
11050 | struct it *it; | |
11051 | { | |
11052 | struct face *face; | |
11053 | struct frame *f = it->f; | |
1842fc1a | 11054 | |
5f5c8ee5 GM |
11055 | /* If line is already filled, do nothing. */ |
11056 | if (it->current_x >= it->last_visible_x) | |
11057 | return; | |
11058 | ||
11059 | /* Face extension extends the background and box of IT->face_id | |
11060 | to the end of the line. If the background equals the background | |
11061 | of the frame, we haven't to do anything. */ | |
11062 | face = FACE_FROM_ID (f, it->face_id); | |
11063 | if (FRAME_WINDOW_P (f) | |
11064 | && face->box == FACE_NO_BOX | |
11065 | && face->background == FRAME_BACKGROUND_PIXEL (f) | |
11066 | && !face->stipple) | |
11067 | return; | |
1842fc1a | 11068 | |
5f5c8ee5 GM |
11069 | /* Set the glyph row flag indicating that the face of the last glyph |
11070 | in the text area has to be drawn to the end of the text area. */ | |
11071 | it->glyph_row->fill_line_p = 1; | |
545e04f6 | 11072 | |
980806b6 KH |
11073 | /* If current character of IT is not ASCII, make sure we have the |
11074 | ASCII face. This will be automatically undone the next time | |
11075 | get_next_display_element returns a multibyte character. Note | |
11076 | that the character will always be single byte in unibyte text. */ | |
11077 | if (!SINGLE_BYTE_CHAR_P (it->c)) | |
5f5c8ee5 | 11078 | { |
980806b6 | 11079 | it->face_id = FACE_FOR_CHAR (f, face, 0); |
5f5c8ee5 | 11080 | } |
545e04f6 | 11081 | |
5f5c8ee5 GM |
11082 | if (FRAME_WINDOW_P (f)) |
11083 | { | |
11084 | /* If the row is empty, add a space with the current face of IT, | |
11085 | so that we know which face to draw. */ | |
11086 | if (it->glyph_row->used[TEXT_AREA] == 0) | |
a2889657 | 11087 | { |
5f5c8ee5 | 11088 | it->glyph_row->glyphs[TEXT_AREA][0] = space_glyph; |
43d120d8 | 11089 | it->glyph_row->glyphs[TEXT_AREA][0].face_id = it->face_id; |
5f5c8ee5 | 11090 | it->glyph_row->used[TEXT_AREA] = 1; |
a2889657 | 11091 | } |
5f5c8ee5 GM |
11092 | } |
11093 | else | |
11094 | { | |
11095 | /* Save some values that must not be changed. */ | |
11096 | int saved_x = it->current_x; | |
11097 | struct text_pos saved_pos; | |
11098 | Lisp_Object saved_object; | |
11099 | int saved_what = it->what; | |
11100 | ||
11101 | saved_object = it->object; | |
11102 | saved_pos = it->position; | |
11103 | ||
11104 | it->what = IT_CHARACTER; | |
11105 | bzero (&it->position, sizeof it->position); | |
6fc556fd | 11106 | it->object = make_number (0); |
5f5c8ee5 GM |
11107 | it->c = ' '; |
11108 | it->len = 1; | |
11109 | ||
11110 | PRODUCE_GLYPHS (it); | |
11111 | ||
11112 | while (it->current_x <= it->last_visible_x) | |
11113 | PRODUCE_GLYPHS (it); | |
11114 | ||
11115 | /* Don't count these blanks really. It would let us insert a left | |
11116 | truncation glyph below and make us set the cursor on them, maybe. */ | |
11117 | it->current_x = saved_x; | |
11118 | it->object = saved_object; | |
11119 | it->position = saved_pos; | |
11120 | it->what = saved_what; | |
11121 | } | |
11122 | } | |
12adba34 | 11123 | |
545e04f6 | 11124 | |
5f5c8ee5 GM |
11125 | /* Value is non-zero if text starting at CHARPOS in current_buffer is |
11126 | trailing whitespace. */ | |
1c9241f5 | 11127 | |
5f5c8ee5 GM |
11128 | static int |
11129 | trailing_whitespace_p (charpos) | |
11130 | int charpos; | |
11131 | { | |
11132 | int bytepos = CHAR_TO_BYTE (charpos); | |
11133 | int c = 0; | |
7bbe686f | 11134 | |
5f5c8ee5 GM |
11135 | while (bytepos < ZV_BYTE |
11136 | && (c = FETCH_CHAR (bytepos), | |
11137 | c == ' ' || c == '\t')) | |
11138 | ++bytepos; | |
0d09d1e6 | 11139 | |
8f897821 GM |
11140 | if (bytepos >= ZV_BYTE || c == '\n' || c == '\r') |
11141 | { | |
11142 | if (bytepos != PT_BYTE) | |
11143 | return 1; | |
11144 | } | |
11145 | return 0; | |
5f5c8ee5 | 11146 | } |
31b24551 | 11147 | |
545e04f6 | 11148 | |
5f5c8ee5 | 11149 | /* Highlight trailing whitespace, if any, in ROW. */ |
545e04f6 | 11150 | |
5f5c8ee5 GM |
11151 | void |
11152 | highlight_trailing_whitespace (f, row) | |
11153 | struct frame *f; | |
11154 | struct glyph_row *row; | |
11155 | { | |
11156 | int used = row->used[TEXT_AREA]; | |
11157 | ||
11158 | if (used) | |
11159 | { | |
11160 | struct glyph *start = row->glyphs[TEXT_AREA]; | |
11161 | struct glyph *glyph = start + used - 1; | |
11162 | ||
11163 | /* Skip over the space glyph inserted to display the | |
11164 | cursor at the end of a line. */ | |
11165 | if (glyph->type == CHAR_GLYPH | |
43d120d8 | 11166 | && glyph->u.ch == ' ' |
6fc556fd | 11167 | && INTEGERP (glyph->object)) |
5f5c8ee5 GM |
11168 | --glyph; |
11169 | ||
11170 | /* If last glyph is a space or stretch, and it's trailing | |
11171 | whitespace, set the face of all trailing whitespace glyphs in | |
11172 | IT->glyph_row to `trailing-whitespace'. */ | |
11173 | if (glyph >= start | |
11174 | && BUFFERP (glyph->object) | |
11175 | && (glyph->type == STRETCH_GLYPH | |
11176 | || (glyph->type == CHAR_GLYPH | |
43d120d8 | 11177 | && glyph->u.ch == ' ')) |
5f5c8ee5 | 11178 | && trailing_whitespace_p (glyph->charpos)) |
545e04f6 | 11179 | { |
980806b6 | 11180 | int face_id = lookup_named_face (f, Qtrailing_whitespace, 0); |
5f5c8ee5 GM |
11181 | |
11182 | while (glyph >= start | |
11183 | && BUFFERP (glyph->object) | |
11184 | && (glyph->type == STRETCH_GLYPH | |
11185 | || (glyph->type == CHAR_GLYPH | |
43d120d8 KH |
11186 | && glyph->u.ch == ' '))) |
11187 | (glyph--)->face_id = face_id; | |
545e04f6 | 11188 | } |
a2889657 | 11189 | } |
5f5c8ee5 | 11190 | } |
a2889657 | 11191 | |
5fcbb24d | 11192 | |
5f5c8ee5 GM |
11193 | /* Construct the glyph row IT->glyph_row in the desired matrix of |
11194 | IT->w from text at the current position of IT. See dispextern.h | |
11195 | for an overview of struct it. Value is non-zero if | |
11196 | IT->glyph_row displays text, as opposed to a line displaying ZV | |
11197 | only. */ | |
11198 | ||
11199 | static int | |
11200 | display_line (it) | |
11201 | struct it *it; | |
11202 | { | |
11203 | struct glyph_row *row = it->glyph_row; | |
11204 | ||
11205 | /* We always start displaying at hpos zero even if hscrolled. */ | |
11206 | xassert (it->hpos == 0 && it->current_x == 0); | |
a2889657 | 11207 | |
5f5c8ee5 GM |
11208 | /* We must not display in a row that's not a text row. */ |
11209 | xassert (MATRIX_ROW_VPOS (row, it->w->desired_matrix) | |
11210 | < it->w->desired_matrix->nrows); | |
12adba34 | 11211 | |
5f5c8ee5 GM |
11212 | /* Is IT->w showing the region? */ |
11213 | it->w->region_showing = it->region_beg_charpos > 0 ? Qt : Qnil; | |
12adba34 | 11214 | |
5f5c8ee5 GM |
11215 | /* Clear the result glyph row and enable it. */ |
11216 | prepare_desired_row (row); | |
12adba34 | 11217 | |
5f5c8ee5 GM |
11218 | row->y = it->current_y; |
11219 | row->start = it->current; | |
11220 | row->continuation_lines_width = it->continuation_lines_width; | |
11221 | row->displays_text_p = 1; | |
11222 | ||
11223 | /* Arrange the overlays nicely for our purposes. Usually, we call | |
11224 | display_line on only one line at a time, in which case this | |
11225 | can't really hurt too much, or we call it on lines which appear | |
11226 | one after another in the buffer, in which case all calls to | |
11227 | recenter_overlay_lists but the first will be pretty cheap. */ | |
11228 | recenter_overlay_lists (current_buffer, IT_CHARPOS (*it)); | |
11229 | ||
5f5c8ee5 GM |
11230 | /* Move over display elements that are not visible because we are |
11231 | hscrolled. This may stop at an x-position < IT->first_visible_x | |
11232 | if the first glyph is partially visible or if we hit a line end. */ | |
11233 | if (it->current_x < it->first_visible_x) | |
11234 | move_it_in_display_line_to (it, ZV, it->first_visible_x, | |
11235 | MOVE_TO_POS | MOVE_TO_X); | |
11236 | ||
11237 | /* Get the initial row height. This is either the height of the | |
11238 | text hscrolled, if there is any, or zero. */ | |
11239 | row->ascent = it->max_ascent; | |
11240 | row->height = it->max_ascent + it->max_descent; | |
312246d1 GM |
11241 | row->phys_ascent = it->max_phys_ascent; |
11242 | row->phys_height = it->max_phys_ascent + it->max_phys_descent; | |
5f5c8ee5 GM |
11243 | |
11244 | /* Loop generating characters. The loop is left with IT on the next | |
11245 | character to display. */ | |
11246 | while (1) | |
11247 | { | |
11248 | int n_glyphs_before, hpos_before, x_before; | |
11249 | int x, i, nglyphs; | |
e6819faf | 11250 | int ascent, descent, phys_ascent, phys_descent; |
5f5c8ee5 GM |
11251 | |
11252 | /* Retrieve the next thing to display. Value is zero if end of | |
11253 | buffer reached. */ | |
11254 | if (!get_next_display_element (it)) | |
11255 | { | |
11256 | /* Maybe add a space at the end of this line that is used to | |
1b335865 GM |
11257 | display the cursor there under X. Set the charpos of the |
11258 | first glyph of blank lines not corresponding to any text | |
11259 | to -1. */ | |
11260 | if ((append_space (it, 1) && row->used[TEXT_AREA] == 1) | |
11261 | || row->used[TEXT_AREA] == 0) | |
a2889657 | 11262 | { |
5f5c8ee5 GM |
11263 | row->glyphs[TEXT_AREA]->charpos = -1; |
11264 | row->displays_text_p = 0; | |
11265 | ||
11266 | if (!NILP (XBUFFER (it->w->buffer)->indicate_empty_lines)) | |
11267 | row->indicate_empty_line_p = 1; | |
a2889657 | 11268 | } |
5f5c8ee5 GM |
11269 | |
11270 | it->continuation_lines_width = 0; | |
11271 | row->ends_at_zv_p = 1; | |
11272 | break; | |
a2889657 | 11273 | } |
a2889657 | 11274 | |
5f5c8ee5 GM |
11275 | /* Now, get the metrics of what we want to display. This also |
11276 | generates glyphs in `row' (which is IT->glyph_row). */ | |
11277 | n_glyphs_before = row->used[TEXT_AREA]; | |
11278 | x = it->current_x; | |
e6819faf GM |
11279 | |
11280 | /* Remember the line height so far in case the next element doesn't | |
11281 | fit on the line. */ | |
11282 | if (!it->truncate_lines_p) | |
11283 | { | |
11284 | ascent = it->max_ascent; | |
11285 | descent = it->max_descent; | |
11286 | phys_ascent = it->max_phys_ascent; | |
11287 | phys_descent = it->max_phys_descent; | |
11288 | } | |
11289 | ||
5f5c8ee5 | 11290 | PRODUCE_GLYPHS (it); |
a2889657 | 11291 | |
5f5c8ee5 GM |
11292 | /* If this display element was in marginal areas, continue with |
11293 | the next one. */ | |
11294 | if (it->area != TEXT_AREA) | |
a2889657 | 11295 | { |
5f5c8ee5 GM |
11296 | row->ascent = max (row->ascent, it->max_ascent); |
11297 | row->height = max (row->height, it->max_ascent + it->max_descent); | |
312246d1 GM |
11298 | row->phys_ascent = max (row->phys_ascent, it->max_phys_ascent); |
11299 | row->phys_height = max (row->phys_height, | |
11300 | it->max_phys_ascent + it->max_phys_descent); | |
5f5c8ee5 GM |
11301 | set_iterator_to_next (it); |
11302 | continue; | |
11303 | } | |
5936754e | 11304 | |
5f5c8ee5 GM |
11305 | /* Does the display element fit on the line? If we truncate |
11306 | lines, we should draw past the right edge of the window. If | |
11307 | we don't truncate, we want to stop so that we can display the | |
11308 | continuation glyph before the right margin. If lines are | |
11309 | continued, there are two possible strategies for characters | |
11310 | resulting in more than 1 glyph (e.g. tabs): Display as many | |
11311 | glyphs as possible in this line and leave the rest for the | |
11312 | continuation line, or display the whole element in the next | |
11313 | line. Original redisplay did the former, so we do it also. */ | |
11314 | nglyphs = row->used[TEXT_AREA] - n_glyphs_before; | |
11315 | hpos_before = it->hpos; | |
11316 | x_before = x; | |
11317 | ||
11318 | if (nglyphs == 1 | |
11319 | && it->current_x < it->last_visible_x) | |
11320 | { | |
11321 | ++it->hpos; | |
11322 | row->ascent = max (row->ascent, it->max_ascent); | |
11323 | row->height = max (row->height, it->max_ascent + it->max_descent); | |
312246d1 GM |
11324 | row->phys_ascent = max (row->phys_ascent, it->max_phys_ascent); |
11325 | row->phys_height = max (row->phys_height, | |
11326 | it->max_phys_ascent + it->max_phys_descent); | |
5f5c8ee5 GM |
11327 | if (it->current_x - it->pixel_width < it->first_visible_x) |
11328 | row->x = x - it->first_visible_x; | |
11329 | } | |
11330 | else | |
11331 | { | |
11332 | int new_x; | |
11333 | struct glyph *glyph; | |
11334 | ||
11335 | for (i = 0; i < nglyphs; ++i, x = new_x) | |
b5bbc9a5 | 11336 | { |
5f5c8ee5 GM |
11337 | glyph = row->glyphs[TEXT_AREA] + n_glyphs_before + i; |
11338 | new_x = x + glyph->pixel_width; | |
11339 | ||
11340 | if (/* Lines are continued. */ | |
11341 | !it->truncate_lines_p | |
11342 | && (/* Glyph doesn't fit on the line. */ | |
11343 | new_x > it->last_visible_x | |
11344 | /* Or it fits exactly on a window system frame. */ | |
11345 | || (new_x == it->last_visible_x | |
11346 | && FRAME_WINDOW_P (it->f)))) | |
a2889657 | 11347 | { |
5f5c8ee5 GM |
11348 | /* End of a continued line. */ |
11349 | ||
11350 | if (it->hpos == 0 | |
11351 | || (new_x == it->last_visible_x | |
11352 | && FRAME_WINDOW_P (it->f))) | |
11353 | { | |
e6819faf GM |
11354 | /* Current glyph is the only one on the line or |
11355 | fits exactly on the line. We must continue | |
11356 | the line because we can't draw the cursor | |
11357 | after the glyph. */ | |
5f5c8ee5 GM |
11358 | row->continued_p = 1; |
11359 | it->current_x = new_x; | |
11360 | it->continuation_lines_width += new_x; | |
11361 | ++it->hpos; | |
11362 | if (i == nglyphs - 1) | |
11363 | set_iterator_to_next (it); | |
11364 | } | |
11365 | else | |
5936754e | 11366 | { |
5f5c8ee5 GM |
11367 | /* Display element draws past the right edge of |
11368 | the window. Restore positions to values | |
11369 | before the element. The next line starts | |
11370 | with current_x before the glyph that could | |
11371 | not be displayed, so that TAB works right. */ | |
11372 | row->used[TEXT_AREA] = n_glyphs_before + i; | |
11373 | ||
11374 | /* Display continuation glyphs. */ | |
11375 | if (!FRAME_WINDOW_P (it->f)) | |
11376 | produce_special_glyphs (it, IT_CONTINUATION); | |
11377 | row->continued_p = 1; | |
11378 | ||
11379 | it->current_x = x; | |
11380 | it->continuation_lines_width += x; | |
e6819faf GM |
11381 | |
11382 | /* Restore the height to what it was before the | |
11383 | element not fitting on the line. */ | |
11384 | it->max_ascent = ascent; | |
11385 | it->max_descent = descent; | |
11386 | it->max_phys_ascent = phys_ascent; | |
11387 | it->max_phys_descent = phys_descent; | |
5936754e | 11388 | } |
e6819faf | 11389 | |
5f5c8ee5 GM |
11390 | break; |
11391 | } | |
11392 | else if (new_x > it->first_visible_x) | |
11393 | { | |
11394 | /* Increment number of glyphs actually displayed. */ | |
11395 | ++it->hpos; | |
11396 | ||
11397 | if (x < it->first_visible_x) | |
11398 | /* Glyph is partially visible, i.e. row starts at | |
11399 | negative X position. */ | |
11400 | row->x = x - it->first_visible_x; | |
11401 | } | |
11402 | else | |
11403 | { | |
11404 | /* Glyph is completely off the left margin of the | |
11405 | window. This should not happen because of the | |
11406 | move_it_in_display_line at the start of | |
11407 | this function. */ | |
11408 | abort (); | |
a2889657 | 11409 | } |
a2889657 | 11410 | } |
5f5c8ee5 GM |
11411 | |
11412 | row->ascent = max (row->ascent, it->max_ascent); | |
11413 | row->height = max (row->height, it->max_ascent + it->max_descent); | |
312246d1 GM |
11414 | row->phys_ascent = max (row->phys_ascent, it->max_phys_ascent); |
11415 | row->phys_height = max (row->phys_height, | |
11416 | it->max_phys_ascent + it->max_phys_descent); | |
5f5c8ee5 GM |
11417 | |
11418 | /* End of this display line if row is continued. */ | |
11419 | if (row->continued_p) | |
11420 | break; | |
a2889657 | 11421 | } |
a2889657 | 11422 | |
5f5c8ee5 GM |
11423 | /* Is this a line end? If yes, we're also done, after making |
11424 | sure that a non-default face is extended up to the right | |
11425 | margin of the window. */ | |
11426 | if (ITERATOR_AT_END_OF_LINE_P (it)) | |
1c9241f5 | 11427 | { |
5f5c8ee5 GM |
11428 | int used_before = row->used[TEXT_AREA]; |
11429 | ||
11430 | /* Add a space at the end of the line that is used to | |
11431 | display the cursor there. */ | |
11432 | append_space (it, 0); | |
11433 | ||
11434 | /* Extend the face to the end of the line. */ | |
11435 | extend_face_to_end_of_line (it); | |
11436 | ||
11437 | /* Make sure we have the position. */ | |
11438 | if (used_before == 0) | |
11439 | row->glyphs[TEXT_AREA]->charpos = CHARPOS (it->position); | |
11440 | ||
11441 | /* Consume the line end. This skips over invisible lines. */ | |
11442 | set_iterator_to_next (it); | |
11443 | it->continuation_lines_width = 0; | |
11444 | break; | |
1c9241f5 | 11445 | } |
a2889657 | 11446 | |
5f5c8ee5 GM |
11447 | /* Proceed with next display element. Note that this skips |
11448 | over lines invisible because of selective display. */ | |
11449 | set_iterator_to_next (it); | |
b1d1124b | 11450 | |
5f5c8ee5 GM |
11451 | /* If we truncate lines, we are done when the last displayed |
11452 | glyphs reach past the right margin of the window. */ | |
11453 | if (it->truncate_lines_p | |
11454 | && (FRAME_WINDOW_P (it->f) | |
11455 | ? (it->current_x >= it->last_visible_x) | |
11456 | : (it->current_x > it->last_visible_x))) | |
75d13c64 | 11457 | { |
5f5c8ee5 GM |
11458 | /* Maybe add truncation glyphs. */ |
11459 | if (!FRAME_WINDOW_P (it->f)) | |
11460 | { | |
11461 | --it->glyph_row->used[TEXT_AREA]; | |
11462 | produce_special_glyphs (it, IT_TRUNCATION); | |
11463 | } | |
11464 | ||
11465 | row->truncated_on_right_p = 1; | |
11466 | it->continuation_lines_width = 0; | |
312246d1 | 11467 | reseat_at_next_visible_line_start (it, 0); |
5f5c8ee5 GM |
11468 | row->ends_at_zv_p = FETCH_BYTE (IT_BYTEPOS (*it) - 1) != '\n'; |
11469 | it->hpos = hpos_before; | |
11470 | it->current_x = x_before; | |
11471 | break; | |
75d13c64 | 11472 | } |
a2889657 | 11473 | } |
a2889657 | 11474 | |
5f5c8ee5 GM |
11475 | /* If line is not empty and hscrolled, maybe insert truncation glyphs |
11476 | at the left window margin. */ | |
11477 | if (it->first_visible_x | |
11478 | && IT_CHARPOS (*it) != MATRIX_ROW_START_CHARPOS (row)) | |
11479 | { | |
11480 | if (!FRAME_WINDOW_P (it->f)) | |
11481 | insert_left_trunc_glyphs (it); | |
11482 | row->truncated_on_left_p = 1; | |
11483 | } | |
a2889657 | 11484 | |
5f5c8ee5 GM |
11485 | /* If the start of this line is the overlay arrow-position, then |
11486 | mark this glyph row as the one containing the overlay arrow. | |
11487 | This is clearly a mess with variable size fonts. It would be | |
11488 | better to let it be displayed like cursors under X. */ | |
e24c997d | 11489 | if (MARKERP (Voverlay_arrow_position) |
a2889657 | 11490 | && current_buffer == XMARKER (Voverlay_arrow_position)->buffer |
5f5c8ee5 GM |
11491 | && (MATRIX_ROW_START_CHARPOS (row) |
11492 | == marker_position (Voverlay_arrow_position)) | |
e24c997d | 11493 | && STRINGP (Voverlay_arrow_string) |
a2889657 JB |
11494 | && ! overlay_arrow_seen) |
11495 | { | |
5f5c8ee5 GM |
11496 | /* Overlay arrow in window redisplay is a bitmap. */ |
11497 | if (!FRAME_WINDOW_P (it->f)) | |
c4628384 | 11498 | { |
5f5c8ee5 GM |
11499 | struct glyph_row *arrow_row = get_overlay_arrow_glyph_row (it->w); |
11500 | struct glyph *glyph = arrow_row->glyphs[TEXT_AREA]; | |
11501 | struct glyph *arrow_end = glyph + arrow_row->used[TEXT_AREA]; | |
11502 | struct glyph *p = row->glyphs[TEXT_AREA]; | |
11503 | struct glyph *p2, *end; | |
11504 | ||
11505 | /* Copy the arrow glyphs. */ | |
11506 | while (glyph < arrow_end) | |
11507 | *p++ = *glyph++; | |
11508 | ||
11509 | /* Throw away padding glyphs. */ | |
11510 | p2 = p; | |
11511 | end = row->glyphs[TEXT_AREA] + row->used[TEXT_AREA]; | |
11512 | while (p2 < end && CHAR_GLYPH_PADDING_P (*p2)) | |
11513 | ++p2; | |
11514 | if (p2 > p) | |
212e4f87 | 11515 | { |
5f5c8ee5 GM |
11516 | while (p2 < end) |
11517 | *p++ = *p2++; | |
11518 | row->used[TEXT_AREA] = p2 - row->glyphs[TEXT_AREA]; | |
c4628384 | 11519 | } |
c4628384 | 11520 | } |
5f5c8ee5 | 11521 | |
a2889657 | 11522 | overlay_arrow_seen = 1; |
5f5c8ee5 | 11523 | row->overlay_arrow_p = 1; |
a2889657 JB |
11524 | } |
11525 | ||
5f5c8ee5 GM |
11526 | /* Compute pixel dimensions of this line. */ |
11527 | compute_line_metrics (it); | |
11528 | ||
11529 | /* Remember the position at which this line ends. */ | |
11530 | row->end = it->current; | |
11531 | ||
11532 | /* Maybe set the cursor. If you change this, it's probably a good | |
11533 | idea to also change the code in redisplay_window for cursor | |
11534 | movement in an unchanged window. */ | |
11535 | if (it->w->cursor.vpos < 0 | |
11536 | && PT >= MATRIX_ROW_START_CHARPOS (row) | |
11537 | && MATRIX_ROW_END_CHARPOS (row) >= PT | |
11538 | && !(MATRIX_ROW_END_CHARPOS (row) == PT | |
11539 | && (MATRIX_ROW_ENDS_IN_MIDDLE_OF_CHAR_P (row) | |
11540 | || !row->ends_at_zv_p))) | |
11541 | set_cursor_from_row (it->w, row, it->w->desired_matrix, 0, 0, 0, 0); | |
11542 | ||
11543 | /* Highlight trailing whitespace. */ | |
8f897821 | 11544 | if (!NILP (Vshow_trailing_whitespace)) |
5f5c8ee5 GM |
11545 | highlight_trailing_whitespace (it->f, it->glyph_row); |
11546 | ||
11547 | /* Prepare for the next line. This line starts horizontally at (X | |
11548 | HPOS) = (0 0). Vertical positions are incremented. As a | |
11549 | convenience for the caller, IT->glyph_row is set to the next | |
11550 | row to be used. */ | |
11551 | it->current_x = it->hpos = 0; | |
11552 | it->current_y += row->height; | |
11553 | ++it->vpos; | |
11554 | ++it->glyph_row; | |
11555 | return row->displays_text_p; | |
a2889657 | 11556 | } |
5f5c8ee5 GM |
11557 | |
11558 | ||
a2889657 | 11559 | \f |
5f5c8ee5 GM |
11560 | /*********************************************************************** |
11561 | Menu Bar | |
11562 | ***********************************************************************/ | |
11563 | ||
11564 | /* Redisplay the menu bar in the frame for window W. | |
11565 | ||
11566 | The menu bar of X frames that don't have X toolkit support is | |
11567 | displayed in a special window W->frame->menu_bar_window. | |
11568 | ||
11569 | The menu bar of terminal frames is treated specially as far as | |
11570 | glyph matrices are concerned. Menu bar lines are not part of | |
11571 | windows, so the update is done directly on the frame matrix rows | |
11572 | for the menu bar. */ | |
7ce2c095 RS |
11573 | |
11574 | static void | |
11575 | display_menu_bar (w) | |
11576 | struct window *w; | |
11577 | { | |
5f5c8ee5 GM |
11578 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
11579 | struct it it; | |
11580 | Lisp_Object items; | |
8351baf2 | 11581 | int i; |
7ce2c095 | 11582 | |
5f5c8ee5 | 11583 | /* Don't do all this for graphical frames. */ |
dc937613 | 11584 | #ifdef HAVE_NTGUI |
d129c4c2 KH |
11585 | if (!NILP (Vwindow_system)) |
11586 | return; | |
dc937613 | 11587 | #endif |
dc937613 | 11588 | #ifdef USE_X_TOOLKIT |
d3413a53 | 11589 | if (FRAME_X_P (f)) |
7ce2c095 | 11590 | return; |
5f5c8ee5 GM |
11591 | #endif |
11592 | ||
11593 | #ifdef USE_X_TOOLKIT | |
11594 | xassert (!FRAME_WINDOW_P (f)); | |
52377a47 | 11595 | init_iterator (&it, w, -1, -1, f->desired_matrix->rows, MENU_FACE_ID); |
5f5c8ee5 GM |
11596 | it.first_visible_x = 0; |
11597 | it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f); | |
11598 | #else /* not USE_X_TOOLKIT */ | |
11599 | if (FRAME_WINDOW_P (f)) | |
11600 | { | |
11601 | /* Menu bar lines are displayed in the desired matrix of the | |
11602 | dummy window menu_bar_window. */ | |
11603 | struct window *menu_w; | |
11604 | xassert (WINDOWP (f->menu_bar_window)); | |
11605 | menu_w = XWINDOW (f->menu_bar_window); | |
11606 | init_iterator (&it, menu_w, -1, -1, menu_w->desired_matrix->rows, | |
52377a47 | 11607 | MENU_FACE_ID); |
5f5c8ee5 GM |
11608 | it.first_visible_x = 0; |
11609 | it.last_visible_x = FRAME_WINDOW_WIDTH (f) * CANON_X_UNIT (f); | |
11610 | } | |
11611 | else | |
11612 | { | |
11613 | /* This is a TTY frame, i.e. character hpos/vpos are used as | |
11614 | pixel x/y. */ | |
11615 | init_iterator (&it, w, -1, -1, f->desired_matrix->rows, | |
52377a47 | 11616 | MENU_FACE_ID); |
5f5c8ee5 GM |
11617 | it.first_visible_x = 0; |
11618 | it.last_visible_x = FRAME_WIDTH (f); | |
11619 | } | |
11620 | #endif /* not USE_X_TOOLKIT */ | |
11621 | ||
11622 | /* Clear all rows of the menu bar. */ | |
11623 | for (i = 0; i < FRAME_MENU_BAR_LINES (f); ++i) | |
11624 | { | |
11625 | struct glyph_row *row = it.glyph_row + i; | |
11626 | clear_glyph_row (row); | |
11627 | row->enabled_p = 1; | |
11628 | row->full_width_p = 1; | |
11629 | } | |
7ce2c095 | 11630 | |
5f5c8ee5 GM |
11631 | /* Make the first line of the menu bar appear in reverse video. */ |
11632 | it.glyph_row->inverse_p = mode_line_inverse_video != 0; | |
7ce2c095 | 11633 | |
5f5c8ee5 GM |
11634 | /* Display all items of the menu bar. */ |
11635 | items = FRAME_MENU_BAR_ITEMS (it.f); | |
469937ac | 11636 | for (i = 0; i < XVECTOR (items)->size; i += 4) |
7ce2c095 | 11637 | { |
5f5c8ee5 GM |
11638 | Lisp_Object string; |
11639 | ||
11640 | /* Stop at nil string. */ | |
8351baf2 RS |
11641 | string = XVECTOR (items)->contents[i + 1]; |
11642 | if (NILP (string)) | |
11643 | break; | |
2d66ad19 | 11644 | |
5f5c8ee5 GM |
11645 | /* Remember where item was displayed. */ |
11646 | XSETFASTINT (XVECTOR (items)->contents[i + 3], it.hpos); | |
7ce2c095 | 11647 | |
5f5c8ee5 GM |
11648 | /* Display the item, pad with one space. */ |
11649 | if (it.current_x < it.last_visible_x) | |
11650 | display_string (NULL, string, Qnil, 0, 0, &it, | |
11651 | XSTRING (string)->size + 1, 0, 0, -1); | |
7ce2c095 RS |
11652 | } |
11653 | ||
2d66ad19 | 11654 | /* Fill out the line with spaces. */ |
5f5c8ee5 GM |
11655 | if (it.current_x < it.last_visible_x) |
11656 | display_string ("", Qnil, Qnil, 0, 0, &it, -1, 0, 0, -1); | |
db6f348c | 11657 | |
5f5c8ee5 GM |
11658 | /* Compute the total height of the lines. */ |
11659 | compute_line_metrics (&it); | |
7ce2c095 | 11660 | } |
5f5c8ee5 GM |
11661 | |
11662 | ||
7ce2c095 | 11663 | \f |
5f5c8ee5 GM |
11664 | /*********************************************************************** |
11665 | Mode Line | |
11666 | ***********************************************************************/ | |
11667 | ||
11668 | /* Display the mode and/or top line of window W. */ | |
a2889657 JB |
11669 | |
11670 | static void | |
5f5c8ee5 | 11671 | display_mode_lines (w) |
a2889657 JB |
11672 | struct window *w; |
11673 | { | |
5f5c8ee5 | 11674 | /* These will be set while the mode line specs are processed. */ |
aa6d10fa | 11675 | line_number_displayed = 0; |
155ef550 | 11676 | w->column_number_displayed = Qnil; |
aa6d10fa | 11677 | |
5f5c8ee5 | 11678 | if (WINDOW_WANTS_MODELINE_P (w)) |
045dee35 GM |
11679 | display_mode_line (w, MODE_LINE_FACE_ID, |
11680 | current_buffer->mode_line_format); | |
5f5c8ee5 | 11681 | |
045dee35 GM |
11682 | if (WINDOW_WANTS_HEADER_LINE_P (w)) |
11683 | display_mode_line (w, HEADER_LINE_FACE_ID, | |
11684 | current_buffer->header_line_format); | |
5f5c8ee5 | 11685 | } |
03b294dc | 11686 | |
03b294dc | 11687 | |
5f5c8ee5 | 11688 | /* Display mode or top line of window W. FACE_ID specifies which line |
045dee35 | 11689 | to display; it is either MODE_LINE_FACE_ID or HEADER_LINE_FACE_ID. |
5f5c8ee5 | 11690 | FORMAT is the mode line format to display. */ |
03b294dc | 11691 | |
5f5c8ee5 GM |
11692 | static void |
11693 | display_mode_line (w, face_id, format) | |
11694 | struct window *w; | |
11695 | enum face_id face_id; | |
11696 | Lisp_Object format; | |
11697 | { | |
11698 | struct it it; | |
11699 | struct face *face; | |
03b294dc | 11700 | |
5f5c8ee5 GM |
11701 | init_iterator (&it, w, -1, -1, NULL, face_id); |
11702 | prepare_desired_row (it.glyph_row); | |
11703 | ||
11704 | /* Temporarily make frame's keyboard the current kboard so that | |
11705 | kboard-local variables in the mode_line_format will get the right | |
11706 | values. */ | |
11707 | push_frame_kboard (it.f); | |
11708 | display_mode_element (&it, 0, 0, 0, format); | |
11709 | pop_frame_kboard (); | |
a2889657 | 11710 | |
5f5c8ee5 GM |
11711 | /* Fill up with spaces. */ |
11712 | display_string (" ", Qnil, Qnil, 0, 0, &it, 10000, -1, -1, 0); | |
11713 | ||
11714 | compute_line_metrics (&it); | |
11715 | it.glyph_row->full_width_p = 1; | |
11716 | it.glyph_row->mode_line_p = 1; | |
11717 | it.glyph_row->inverse_p = mode_line_inverse_video != 0; | |
11718 | it.glyph_row->continued_p = 0; | |
11719 | it.glyph_row->truncated_on_left_p = 0; | |
11720 | it.glyph_row->truncated_on_right_p = 0; | |
11721 | ||
11722 | /* Make a 3D mode-line have a shadow at its right end. */ | |
11723 | face = FACE_FROM_ID (it.f, face_id); | |
11724 | extend_face_to_end_of_line (&it); | |
11725 | if (face->box != FACE_NO_BOX) | |
d7eb09a0 | 11726 | { |
5f5c8ee5 GM |
11727 | struct glyph *last = (it.glyph_row->glyphs[TEXT_AREA] |
11728 | + it.glyph_row->used[TEXT_AREA] - 1); | |
11729 | last->right_box_line_p = 1; | |
d7eb09a0 | 11730 | } |
a2889657 JB |
11731 | } |
11732 | ||
a2889657 | 11733 | |
5f5c8ee5 GM |
11734 | /* Contribute ELT to the mode line for window IT->w. How it |
11735 | translates into text depends on its data type. | |
a2889657 | 11736 | |
5f5c8ee5 | 11737 | IT describes the display environment in which we display, as usual. |
a2889657 JB |
11738 | |
11739 | DEPTH is the depth in recursion. It is used to prevent | |
11740 | infinite recursion here. | |
11741 | ||
5f5c8ee5 GM |
11742 | FIELD_WIDTH is the number of characters the display of ELT should |
11743 | occupy in the mode line, and PRECISION is the maximum number of | |
11744 | characters to display from ELT's representation. See | |
11745 | display_string for details. * | |
a2889657 | 11746 | |
5f5c8ee5 | 11747 | Returns the hpos of the end of the text generated by ELT. */ |
a2889657 JB |
11748 | |
11749 | static int | |
5f5c8ee5 GM |
11750 | display_mode_element (it, depth, field_width, precision, elt) |
11751 | struct it *it; | |
a2889657 | 11752 | int depth; |
5f5c8ee5 GM |
11753 | int field_width, precision; |
11754 | Lisp_Object elt; | |
a2889657 | 11755 | { |
5f5c8ee5 GM |
11756 | int n = 0, field, prec; |
11757 | ||
a2889657 JB |
11758 | tail_recurse: |
11759 | if (depth > 10) | |
11760 | goto invalid; | |
11761 | ||
11762 | depth++; | |
11763 | ||
0220c518 | 11764 | switch (SWITCH_ENUM_CAST (XTYPE (elt))) |
a2889657 JB |
11765 | { |
11766 | case Lisp_String: | |
11767 | { | |
11768 | /* A string: output it and check for %-constructs within it. */ | |
5f5c8ee5 GM |
11769 | unsigned char c; |
11770 | unsigned char *this = XSTRING (elt)->data; | |
11771 | unsigned char *lisp_string = this; | |
11772 | ||
11773 | while ((precision <= 0 || n < precision) | |
11774 | && *this | |
11775 | && (frame_title_ptr | |
11776 | || it->current_x < it->last_visible_x)) | |
a2889657 JB |
11777 | { |
11778 | unsigned char *last = this; | |
5f5c8ee5 GM |
11779 | |
11780 | /* Advance to end of string or next format specifier. */ | |
a2889657 JB |
11781 | while ((c = *this++) != '\0' && c != '%') |
11782 | ; | |
5f5c8ee5 | 11783 | |
a2889657 JB |
11784 | if (this - 1 != last) |
11785 | { | |
5f5c8ee5 GM |
11786 | /* Output to end of string or up to '%'. Field width |
11787 | is length of string. Don't output more than | |
11788 | PRECISION allows us. */ | |
11789 | prec = --this - last; | |
11790 | if (precision > 0 && prec > precision - n) | |
11791 | prec = precision - n; | |
11792 | ||
d39b6696 | 11793 | if (frame_title_ptr) |
5f5c8ee5 | 11794 | n += store_frame_title (last, prec, prec); |
d39b6696 | 11795 | else |
5f5c8ee5 GM |
11796 | n += display_string (NULL, elt, Qnil, 0, last - lisp_string, |
11797 | it, 0, prec, 0, -1); | |
a2889657 JB |
11798 | } |
11799 | else /* c == '%' */ | |
11800 | { | |
5f5c8ee5 GM |
11801 | unsigned char *percent_position = this; |
11802 | ||
11803 | /* Get the specified minimum width. Zero means | |
11804 | don't pad. */ | |
11805 | field = 0; | |
a2889657 | 11806 | while ((c = *this++) >= '0' && c <= '9') |
5f5c8ee5 | 11807 | field = field * 10 + c - '0'; |
a2889657 | 11808 | |
5f5c8ee5 GM |
11809 | /* Don't pad beyond the total padding allowed. */ |
11810 | if (field_width - n > 0 && field > field_width - n) | |
11811 | field = field_width - n; | |
a2889657 | 11812 | |
5f5c8ee5 GM |
11813 | /* Note that either PRECISION <= 0 or N < PRECISION. */ |
11814 | prec = precision - n; | |
11815 | ||
a2889657 | 11816 | if (c == 'M') |
5f5c8ee5 GM |
11817 | n += display_mode_element (it, depth, field, prec, |
11818 | Vglobal_mode_string); | |
a2889657 | 11819 | else if (c != 0) |
d39b6696 | 11820 | { |
5f5c8ee5 GM |
11821 | unsigned char *spec |
11822 | = decode_mode_spec (it->w, c, field, prec); | |
11823 | ||
d39b6696 | 11824 | if (frame_title_ptr) |
5f5c8ee5 | 11825 | n += store_frame_title (spec, field, prec); |
d39b6696 | 11826 | else |
5f5c8ee5 GM |
11827 | { |
11828 | int nglyphs_before | |
11829 | = it->glyph_row->used[TEXT_AREA]; | |
11830 | int charpos | |
11831 | = percent_position - XSTRING (elt)->data; | |
11832 | int nwritten | |
11833 | = display_string (spec, Qnil, elt, charpos, 0, it, | |
11834 | field, prec, 0, -1); | |
11835 | ||
11836 | /* Assign to the glyphs written above the | |
11837 | string where the `%x' came from, position | |
11838 | of the `%'. */ | |
11839 | if (nwritten > 0) | |
11840 | { | |
11841 | struct glyph *glyph | |
11842 | = (it->glyph_row->glyphs[TEXT_AREA] | |
11843 | + nglyphs_before); | |
11844 | int i; | |
11845 | ||
11846 | for (i = 0; i < nwritten; ++i) | |
11847 | { | |
11848 | glyph[i].object = elt; | |
11849 | glyph[i].charpos = charpos; | |
11850 | } | |
11851 | ||
11852 | n += nwritten; | |
11853 | } | |
11854 | } | |
d39b6696 | 11855 | } |
a2889657 JB |
11856 | } |
11857 | } | |
11858 | } | |
11859 | break; | |
11860 | ||
11861 | case Lisp_Symbol: | |
11862 | /* A symbol: process the value of the symbol recursively | |
11863 | as if it appeared here directly. Avoid error if symbol void. | |
11864 | Special case: if value of symbol is a string, output the string | |
11865 | literally. */ | |
11866 | { | |
11867 | register Lisp_Object tem; | |
11868 | tem = Fboundp (elt); | |
265a9e55 | 11869 | if (!NILP (tem)) |
a2889657 JB |
11870 | { |
11871 | tem = Fsymbol_value (elt); | |
11872 | /* If value is a string, output that string literally: | |
11873 | don't check for % within it. */ | |
e24c997d | 11874 | if (STRINGP (tem)) |
d39b6696 | 11875 | { |
5f5c8ee5 GM |
11876 | prec = XSTRING (tem)->size; |
11877 | if (precision > 0 && prec > precision - n) | |
11878 | prec = precision - n; | |
d39b6696 | 11879 | if (frame_title_ptr) |
5f5c8ee5 | 11880 | n += store_frame_title (XSTRING (tem)->data, -1, prec); |
d39b6696 | 11881 | else |
5f5c8ee5 GM |
11882 | n += display_string (NULL, tem, Qnil, 0, 0, it, |
11883 | 0, prec, 0, -1); | |
d39b6696 | 11884 | } |
a2889657 | 11885 | else if (!EQ (tem, elt)) |
5f5c8ee5 GM |
11886 | { |
11887 | /* Give up right away for nil or t. */ | |
11888 | elt = tem; | |
11889 | goto tail_recurse; | |
11890 | } | |
a2889657 JB |
11891 | } |
11892 | } | |
11893 | break; | |
11894 | ||
11895 | case Lisp_Cons: | |
11896 | { | |
11897 | register Lisp_Object car, tem; | |
11898 | ||
11899 | /* A cons cell: three distinct cases. | |
11900 | If first element is a string or a cons, process all the elements | |
11901 | and effectively concatenate them. | |
11902 | If first element is a negative number, truncate displaying cdr to | |
11903 | at most that many characters. If positive, pad (with spaces) | |
11904 | to at least that many characters. | |
11905 | If first element is a symbol, process the cadr or caddr recursively | |
11906 | according to whether the symbol's value is non-nil or nil. */ | |
9472f927 | 11907 | car = XCAR (elt); |
5f5c8ee5 GM |
11908 | if (EQ (car, QCeval) && CONSP (XCDR (elt))) |
11909 | { | |
11910 | /* An element of the form (:eval FORM) means evaluate FORM | |
11911 | and use the result as mode line elements. */ | |
11912 | struct gcpro gcpro1; | |
11913 | Lisp_Object spec; | |
11914 | ||
11915 | spec = eval_form (XCAR (XCDR (elt))); | |
11916 | GCPRO1 (spec); | |
11917 | n += display_mode_element (it, depth, field_width - n, | |
11918 | precision - n, spec); | |
11919 | UNGCPRO; | |
11920 | } | |
11921 | else if (SYMBOLP (car)) | |
a2889657 JB |
11922 | { |
11923 | tem = Fboundp (car); | |
9472f927 | 11924 | elt = XCDR (elt); |
e24c997d | 11925 | if (!CONSP (elt)) |
a2889657 JB |
11926 | goto invalid; |
11927 | /* elt is now the cdr, and we know it is a cons cell. | |
11928 | Use its car if CAR has a non-nil value. */ | |
265a9e55 | 11929 | if (!NILP (tem)) |
a2889657 JB |
11930 | { |
11931 | tem = Fsymbol_value (car); | |
265a9e55 | 11932 | if (!NILP (tem)) |
9472f927 GM |
11933 | { |
11934 | elt = XCAR (elt); | |
11935 | goto tail_recurse; | |
11936 | } | |
a2889657 JB |
11937 | } |
11938 | /* Symbol's value is nil (or symbol is unbound) | |
11939 | Get the cddr of the original list | |
11940 | and if possible find the caddr and use that. */ | |
9472f927 | 11941 | elt = XCDR (elt); |
265a9e55 | 11942 | if (NILP (elt)) |
a2889657 | 11943 | break; |
e24c997d | 11944 | else if (!CONSP (elt)) |
a2889657 | 11945 | goto invalid; |
9472f927 | 11946 | elt = XCAR (elt); |
a2889657 JB |
11947 | goto tail_recurse; |
11948 | } | |
e24c997d | 11949 | else if (INTEGERP (car)) |
a2889657 JB |
11950 | { |
11951 | register int lim = XINT (car); | |
9472f927 | 11952 | elt = XCDR (elt); |
a2889657 | 11953 | if (lim < 0) |
5f5c8ee5 GM |
11954 | { |
11955 | /* Negative int means reduce maximum width. */ | |
11956 | if (precision <= 0) | |
11957 | precision = -lim; | |
11958 | else | |
11959 | precision = min (precision, -lim); | |
11960 | } | |
a2889657 JB |
11961 | else if (lim > 0) |
11962 | { | |
11963 | /* Padding specified. Don't let it be more than | |
11964 | current maximum. */ | |
5f5c8ee5 GM |
11965 | if (precision > 0) |
11966 | lim = min (precision, lim); | |
11967 | ||
a2889657 JB |
11968 | /* If that's more padding than already wanted, queue it. |
11969 | But don't reduce padding already specified even if | |
11970 | that is beyond the current truncation point. */ | |
5f5c8ee5 | 11971 | field_width = max (lim, field_width); |
a2889657 JB |
11972 | } |
11973 | goto tail_recurse; | |
11974 | } | |
e24c997d | 11975 | else if (STRINGP (car) || CONSP (car)) |
a2889657 JB |
11976 | { |
11977 | register int limit = 50; | |
5f5c8ee5 GM |
11978 | /* Limit is to protect against circular lists. */ |
11979 | while (CONSP (elt) | |
11980 | && --limit > 0 | |
11981 | && (precision <= 0 || n < precision)) | |
a2889657 | 11982 | { |
5f5c8ee5 | 11983 | n += display_mode_element (it, depth, field_width - n, |
9472f927 GM |
11984 | precision - n, XCAR (elt)); |
11985 | elt = XCDR (elt); | |
a2889657 JB |
11986 | } |
11987 | } | |
11988 | } | |
11989 | break; | |
11990 | ||
11991 | default: | |
11992 | invalid: | |
d39b6696 | 11993 | if (frame_title_ptr) |
5f5c8ee5 | 11994 | n += store_frame_title ("*invalid*", 0, precision - n); |
d39b6696 | 11995 | else |
5f5c8ee5 GM |
11996 | n += display_string ("*invalid*", Qnil, Qnil, 0, 0, it, 0, |
11997 | precision - n, 0, 0); | |
11998 | return n; | |
a2889657 JB |
11999 | } |
12000 | ||
5f5c8ee5 GM |
12001 | /* Pad to FIELD_WIDTH. */ |
12002 | if (field_width > 0 && n < field_width) | |
12003 | { | |
12004 | if (frame_title_ptr) | |
12005 | n += store_frame_title ("", field_width - n, 0); | |
12006 | else | |
12007 | n += display_string ("", Qnil, Qnil, 0, 0, it, field_width - n, | |
12008 | 0, 0, 0); | |
12009 | } | |
12010 | ||
12011 | return n; | |
a2889657 | 12012 | } |
5f5c8ee5 GM |
12013 | |
12014 | ||
766525bc RS |
12015 | /* Write a null-terminated, right justified decimal representation of |
12016 | the positive integer D to BUF using a minimal field width WIDTH. */ | |
12017 | ||
12018 | static void | |
12019 | pint2str (buf, width, d) | |
12020 | register char *buf; | |
12021 | register int width; | |
12022 | register int d; | |
12023 | { | |
12024 | register char *p = buf; | |
12025 | ||
12026 | if (d <= 0) | |
5f5c8ee5 | 12027 | *p++ = '0'; |
766525bc | 12028 | else |
5f5c8ee5 | 12029 | { |
766525bc | 12030 | while (d > 0) |
5f5c8ee5 | 12031 | { |
766525bc RS |
12032 | *p++ = d % 10 + '0'; |
12033 | d /= 10; | |
5f5c8ee5 GM |
12034 | } |
12035 | } | |
12036 | ||
12037 | for (width -= (int) (p - buf); width > 0; --width) | |
12038 | *p++ = ' '; | |
766525bc RS |
12039 | *p-- = '\0'; |
12040 | while (p > buf) | |
5f5c8ee5 | 12041 | { |
766525bc RS |
12042 | d = *buf; |
12043 | *buf++ = *p; | |
12044 | *p-- = d; | |
5f5c8ee5 | 12045 | } |
766525bc RS |
12046 | } |
12047 | ||
5f5c8ee5 | 12048 | /* Set a mnemonic character for coding_system (Lisp symbol) in BUF. |
1c9241f5 KH |
12049 | If EOL_FLAG is 1, set also a mnemonic character for end-of-line |
12050 | type of CODING_SYSTEM. Return updated pointer into BUF. */ | |
12051 | ||
6693a99a | 12052 | static unsigned char invalid_eol_type[] = "(*invalid*)"; |
d24715e8 | 12053 | |
1c9241f5 KH |
12054 | static char * |
12055 | decode_mode_spec_coding (coding_system, buf, eol_flag) | |
12056 | Lisp_Object coding_system; | |
12057 | register char *buf; | |
12058 | int eol_flag; | |
12059 | { | |
1e1078d6 | 12060 | Lisp_Object val; |
916848d8 | 12061 | int multibyte = !NILP (current_buffer->enable_multibyte_characters); |
302f2b38 EZ |
12062 | unsigned char *eol_str; |
12063 | int eol_str_len; | |
12064 | /* The EOL conversion we are using. */ | |
12065 | Lisp_Object eoltype; | |
1e1078d6 | 12066 | |
4a09dee0 | 12067 | val = Fget (coding_system, Qcoding_system); |
1c9241f5 | 12068 | |
4a09dee0 | 12069 | if (!VECTORP (val)) /* Not yet decided. */ |
1c9241f5 | 12070 | { |
916848d8 RS |
12071 | if (multibyte) |
12072 | *buf++ = '-'; | |
21e989e3 | 12073 | if (eol_flag) |
302f2b38 | 12074 | eoltype = eol_mnemonic_undecided; |
1e1078d6 | 12075 | /* Don't mention EOL conversion if it isn't decided. */ |
1c9241f5 KH |
12076 | } |
12077 | else | |
12078 | { | |
1e1078d6 RS |
12079 | Lisp_Object eolvalue; |
12080 | ||
12081 | eolvalue = Fget (coding_system, Qeol_type); | |
12082 | ||
916848d8 RS |
12083 | if (multibyte) |
12084 | *buf++ = XFASTINT (XVECTOR (val)->contents[1]); | |
12085 | ||
1c9241f5 KH |
12086 | if (eol_flag) |
12087 | { | |
1e1078d6 RS |
12088 | /* The EOL conversion that is normal on this system. */ |
12089 | ||
12090 | if (NILP (eolvalue)) /* Not yet decided. */ | |
12091 | eoltype = eol_mnemonic_undecided; | |
12092 | else if (VECTORP (eolvalue)) /* Not yet decided. */ | |
12093 | eoltype = eol_mnemonic_undecided; | |
12094 | else /* INTEGERP (eolvalue) -- 0:LF, 1:CRLF, 2:CR */ | |
12095 | eoltype = (XFASTINT (eolvalue) == 0 | |
12096 | ? eol_mnemonic_unix | |
12097 | : (XFASTINT (eolvalue) == 1 | |
12098 | ? eol_mnemonic_dos : eol_mnemonic_mac)); | |
302f2b38 EZ |
12099 | } |
12100 | } | |
5f5c8ee5 | 12101 | |
302f2b38 EZ |
12102 | if (eol_flag) |
12103 | { | |
12104 | /* Mention the EOL conversion if it is not the usual one. */ | |
12105 | if (STRINGP (eoltype)) | |
12106 | { | |
12107 | eol_str = XSTRING (eoltype)->data; | |
12108 | eol_str_len = XSTRING (eoltype)->size; | |
12109 | } | |
f30b3499 KH |
12110 | else if (INTEGERP (eoltype) |
12111 | && CHAR_VALID_P (XINT (eoltype), 0)) | |
12112 | { | |
4a09dee0 | 12113 | eol_str = (unsigned char *) alloca (MAX_MULTIBYTE_LENGTH); |
260a86a0 | 12114 | eol_str_len = CHAR_STRING (XINT (eoltype), eol_str); |
f30b3499 | 12115 | } |
302f2b38 EZ |
12116 | else |
12117 | { | |
12118 | eol_str = invalid_eol_type; | |
12119 | eol_str_len = sizeof (invalid_eol_type) - 1; | |
1c9241f5 | 12120 | } |
f30b3499 | 12121 | bcopy (eol_str, buf, eol_str_len); |
302f2b38 | 12122 | buf += eol_str_len; |
1c9241f5 | 12123 | } |
302f2b38 | 12124 | |
1c9241f5 KH |
12125 | return buf; |
12126 | } | |
12127 | ||
a2889657 | 12128 | /* Return a string for the output of a mode line %-spec for window W, |
5f5c8ee5 GM |
12129 | generated by character C. PRECISION >= 0 means don't return a |
12130 | string longer than that value. FIELD_WIDTH > 0 means pad the | |
12131 | string returned with spaces to that value. */ | |
a2889657 | 12132 | |
11e82b76 JB |
12133 | static char lots_of_dashes[] = "--------------------------------------------------------------------------------------------------------------------------------------------"; |
12134 | ||
a2889657 | 12135 | static char * |
5f5c8ee5 | 12136 | decode_mode_spec (w, c, field_width, precision) |
a2889657 | 12137 | struct window *w; |
68c45bf0 | 12138 | register int c; |
5f5c8ee5 | 12139 | int field_width, precision; |
a2889657 | 12140 | { |
0b67772d | 12141 | Lisp_Object obj; |
5f5c8ee5 GM |
12142 | struct frame *f = XFRAME (WINDOW_FRAME (w)); |
12143 | char *decode_mode_spec_buf = f->decode_mode_spec_buffer; | |
d39b6696 | 12144 | struct buffer *b = XBUFFER (w->buffer); |
a2889657 | 12145 | |
0b67772d | 12146 | obj = Qnil; |
a2889657 JB |
12147 | |
12148 | switch (c) | |
12149 | { | |
1af9f229 RS |
12150 | case '*': |
12151 | if (!NILP (b->read_only)) | |
12152 | return "%"; | |
12153 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
12154 | return "*"; | |
12155 | return "-"; | |
12156 | ||
12157 | case '+': | |
12158 | /* This differs from %* only for a modified read-only buffer. */ | |
12159 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
12160 | return "*"; | |
12161 | if (!NILP (b->read_only)) | |
12162 | return "%"; | |
12163 | return "-"; | |
12164 | ||
12165 | case '&': | |
12166 | /* This differs from %* in ignoring read-only-ness. */ | |
12167 | if (BUF_MODIFF (b) > BUF_SAVE_MODIFF (b)) | |
12168 | return "*"; | |
12169 | return "-"; | |
12170 | ||
12171 | case '%': | |
12172 | return "%"; | |
12173 | ||
12174 | case '[': | |
12175 | { | |
12176 | int i; | |
12177 | char *p; | |
12178 | ||
12179 | if (command_loop_level > 5) | |
12180 | return "[[[... "; | |
12181 | p = decode_mode_spec_buf; | |
12182 | for (i = 0; i < command_loop_level; i++) | |
12183 | *p++ = '['; | |
12184 | *p = 0; | |
12185 | return decode_mode_spec_buf; | |
12186 | } | |
12187 | ||
12188 | case ']': | |
12189 | { | |
12190 | int i; | |
12191 | char *p; | |
12192 | ||
12193 | if (command_loop_level > 5) | |
12194 | return " ...]]]"; | |
12195 | p = decode_mode_spec_buf; | |
12196 | for (i = 0; i < command_loop_level; i++) | |
12197 | *p++ = ']'; | |
12198 | *p = 0; | |
12199 | return decode_mode_spec_buf; | |
12200 | } | |
12201 | ||
12202 | case '-': | |
12203 | { | |
1af9f229 | 12204 | register int i; |
5f5c8ee5 GM |
12205 | |
12206 | /* Let lots_of_dashes be a string of infinite length. */ | |
12207 | if (field_width <= 0 | |
12208 | || field_width > sizeof (lots_of_dashes)) | |
1af9f229 | 12209 | { |
5f5c8ee5 GM |
12210 | for (i = 0; i < FRAME_MESSAGE_BUF_SIZE (f) - 1; ++i) |
12211 | decode_mode_spec_buf[i] = '-'; | |
12212 | decode_mode_spec_buf[i] = '\0'; | |
12213 | return decode_mode_spec_buf; | |
1af9f229 | 12214 | } |
5f5c8ee5 GM |
12215 | else |
12216 | return lots_of_dashes; | |
1af9f229 RS |
12217 | } |
12218 | ||
a2889657 | 12219 | case 'b': |
d39b6696 | 12220 | obj = b->name; |
a2889657 JB |
12221 | break; |
12222 | ||
1af9f229 RS |
12223 | case 'c': |
12224 | { | |
12225 | int col = current_column (); | |
12226 | XSETFASTINT (w->column_number_displayed, col); | |
5f5c8ee5 | 12227 | pint2str (decode_mode_spec_buf, field_width, col); |
1af9f229 RS |
12228 | return decode_mode_spec_buf; |
12229 | } | |
12230 | ||
12231 | case 'F': | |
12232 | /* %F displays the frame name. */ | |
5f5c8ee5 | 12233 | if (!NILP (f->title)) |
95184b48 | 12234 | return (char *) XSTRING (f->title)->data; |
fd8ff63d | 12235 | if (f->explicit_name || ! FRAME_WINDOW_P (f)) |
95184b48 | 12236 | return (char *) XSTRING (f->name)->data; |
9c6da96f | 12237 | return "Emacs"; |
1af9f229 | 12238 | |
a2889657 | 12239 | case 'f': |
d39b6696 | 12240 | obj = b->filename; |
a2889657 JB |
12241 | break; |
12242 | ||
aa6d10fa RS |
12243 | case 'l': |
12244 | { | |
12adba34 RS |
12245 | int startpos = XMARKER (w->start)->charpos; |
12246 | int startpos_byte = marker_byte_position (w->start); | |
12247 | int line, linepos, linepos_byte, topline; | |
aa6d10fa | 12248 | int nlines, junk; |
aa6d10fa RS |
12249 | int height = XFASTINT (w->height); |
12250 | ||
12251 | /* If we decided that this buffer isn't suitable for line numbers, | |
12252 | don't forget that too fast. */ | |
12253 | if (EQ (w->base_line_pos, w->buffer)) | |
766525bc | 12254 | goto no_value; |
5300fd39 RS |
12255 | /* But do forget it, if the window shows a different buffer now. */ |
12256 | else if (BUFFERP (w->base_line_pos)) | |
12257 | w->base_line_pos = Qnil; | |
aa6d10fa RS |
12258 | |
12259 | /* If the buffer is very big, don't waste time. */ | |
d39b6696 | 12260 | if (BUF_ZV (b) - BUF_BEGV (b) > line_number_display_limit) |
aa6d10fa RS |
12261 | { |
12262 | w->base_line_pos = Qnil; | |
12263 | w->base_line_number = Qnil; | |
766525bc | 12264 | goto no_value; |
aa6d10fa RS |
12265 | } |
12266 | ||
12267 | if (!NILP (w->base_line_number) | |
12268 | && !NILP (w->base_line_pos) | |
12adba34 | 12269 | && XFASTINT (w->base_line_pos) <= startpos) |
aa6d10fa RS |
12270 | { |
12271 | line = XFASTINT (w->base_line_number); | |
12272 | linepos = XFASTINT (w->base_line_pos); | |
12adba34 | 12273 | linepos_byte = buf_charpos_to_bytepos (b, linepos); |
aa6d10fa RS |
12274 | } |
12275 | else | |
12276 | { | |
12277 | line = 1; | |
d39b6696 | 12278 | linepos = BUF_BEGV (b); |
12adba34 | 12279 | linepos_byte = BUF_BEGV_BYTE (b); |
aa6d10fa RS |
12280 | } |
12281 | ||
12282 | /* Count lines from base line to window start position. */ | |
12adba34 RS |
12283 | nlines = display_count_lines (linepos, linepos_byte, |
12284 | startpos_byte, | |
12285 | startpos, &junk); | |
aa6d10fa RS |
12286 | |
12287 | topline = nlines + line; | |
12288 | ||
12289 | /* Determine a new base line, if the old one is too close | |
12290 | or too far away, or if we did not have one. | |
12291 | "Too close" means it's plausible a scroll-down would | |
12292 | go back past it. */ | |
d39b6696 | 12293 | if (startpos == BUF_BEGV (b)) |
aa6d10fa | 12294 | { |
c2213350 KH |
12295 | XSETFASTINT (w->base_line_number, topline); |
12296 | XSETFASTINT (w->base_line_pos, BUF_BEGV (b)); | |
aa6d10fa RS |
12297 | } |
12298 | else if (nlines < height + 25 || nlines > height * 3 + 50 | |
d39b6696 | 12299 | || linepos == BUF_BEGV (b)) |
aa6d10fa | 12300 | { |
d39b6696 | 12301 | int limit = BUF_BEGV (b); |
12adba34 | 12302 | int limit_byte = BUF_BEGV_BYTE (b); |
aa6d10fa | 12303 | int position; |
5d121aec | 12304 | int distance = (height * 2 + 30) * line_number_display_limit_width; |
aa6d10fa RS |
12305 | |
12306 | if (startpos - distance > limit) | |
12adba34 RS |
12307 | { |
12308 | limit = startpos - distance; | |
12309 | limit_byte = CHAR_TO_BYTE (limit); | |
12310 | } | |
aa6d10fa | 12311 | |
12adba34 RS |
12312 | nlines = display_count_lines (startpos, startpos_byte, |
12313 | limit_byte, | |
12314 | - (height * 2 + 30), | |
aa6d10fa RS |
12315 | &position); |
12316 | /* If we couldn't find the lines we wanted within | |
5d121aec | 12317 | line_number_display_limit_width chars per line, |
aa6d10fa | 12318 | give up on line numbers for this window. */ |
12adba34 | 12319 | if (position == limit_byte && limit == startpos - distance) |
aa6d10fa RS |
12320 | { |
12321 | w->base_line_pos = w->buffer; | |
12322 | w->base_line_number = Qnil; | |
766525bc | 12323 | goto no_value; |
aa6d10fa RS |
12324 | } |
12325 | ||
c2213350 | 12326 | XSETFASTINT (w->base_line_number, topline - nlines); |
12adba34 | 12327 | XSETFASTINT (w->base_line_pos, BYTE_TO_CHAR (position)); |
aa6d10fa RS |
12328 | } |
12329 | ||
12330 | /* Now count lines from the start pos to point. */ | |
12adba34 RS |
12331 | nlines = display_count_lines (startpos, startpos_byte, |
12332 | PT_BYTE, PT, &junk); | |
aa6d10fa RS |
12333 | |
12334 | /* Record that we did display the line number. */ | |
12335 | line_number_displayed = 1; | |
12336 | ||
12337 | /* Make the string to show. */ | |
5f5c8ee5 | 12338 | pint2str (decode_mode_spec_buf, field_width, topline + nlines); |
aa6d10fa | 12339 | return decode_mode_spec_buf; |
766525bc RS |
12340 | no_value: |
12341 | { | |
12342 | char* p = decode_mode_spec_buf; | |
5f5c8ee5 GM |
12343 | int pad = field_width - 2; |
12344 | while (pad-- > 0) | |
12345 | *p++ = ' '; | |
12346 | *p++ = '?'; | |
12347 | *p = '?'; | |
766525bc RS |
12348 | return decode_mode_spec_buf; |
12349 | } | |
aa6d10fa RS |
12350 | } |
12351 | break; | |
12352 | ||
a2889657 | 12353 | case 'm': |
d39b6696 | 12354 | obj = b->mode_name; |
a2889657 JB |
12355 | break; |
12356 | ||
12357 | case 'n': | |
d39b6696 | 12358 | if (BUF_BEGV (b) > BUF_BEG (b) || BUF_ZV (b) < BUF_Z (b)) |
a2889657 JB |
12359 | return " Narrow"; |
12360 | break; | |
12361 | ||
a2889657 JB |
12362 | case 'p': |
12363 | { | |
12364 | int pos = marker_position (w->start); | |
d39b6696 | 12365 | int total = BUF_ZV (b) - BUF_BEGV (b); |
a2889657 | 12366 | |
d39b6696 | 12367 | if (XFASTINT (w->window_end_pos) <= BUF_Z (b) - BUF_ZV (b)) |
a2889657 | 12368 | { |
d39b6696 | 12369 | if (pos <= BUF_BEGV (b)) |
a2889657 JB |
12370 | return "All"; |
12371 | else | |
12372 | return "Bottom"; | |
12373 | } | |
d39b6696 | 12374 | else if (pos <= BUF_BEGV (b)) |
a2889657 JB |
12375 | return "Top"; |
12376 | else | |
12377 | { | |
3c7d31b9 RS |
12378 | if (total > 1000000) |
12379 | /* Do it differently for a large value, to avoid overflow. */ | |
12380 | total = ((pos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100); | |
12381 | else | |
12382 | total = ((pos - BUF_BEGV (b)) * 100 + total - 1) / total; | |
a2889657 JB |
12383 | /* We can't normally display a 3-digit number, |
12384 | so get us a 2-digit number that is close. */ | |
12385 | if (total == 100) | |
12386 | total = 99; | |
12387 | sprintf (decode_mode_spec_buf, "%2d%%", total); | |
12388 | return decode_mode_spec_buf; | |
12389 | } | |
12390 | } | |
12391 | ||
8ffcb79f RS |
12392 | /* Display percentage of size above the bottom of the screen. */ |
12393 | case 'P': | |
12394 | { | |
12395 | int toppos = marker_position (w->start); | |
d39b6696 KH |
12396 | int botpos = BUF_Z (b) - XFASTINT (w->window_end_pos); |
12397 | int total = BUF_ZV (b) - BUF_BEGV (b); | |
8ffcb79f | 12398 | |
d39b6696 | 12399 | if (botpos >= BUF_ZV (b)) |
8ffcb79f | 12400 | { |
d39b6696 | 12401 | if (toppos <= BUF_BEGV (b)) |
8ffcb79f RS |
12402 | return "All"; |
12403 | else | |
12404 | return "Bottom"; | |
12405 | } | |
12406 | else | |
12407 | { | |
3c7d31b9 RS |
12408 | if (total > 1000000) |
12409 | /* Do it differently for a large value, to avoid overflow. */ | |
12410 | total = ((botpos - BUF_BEGV (b)) + (total / 100) - 1) / (total / 100); | |
12411 | else | |
12412 | total = ((botpos - BUF_BEGV (b)) * 100 + total - 1) / total; | |
8ffcb79f RS |
12413 | /* We can't normally display a 3-digit number, |
12414 | so get us a 2-digit number that is close. */ | |
12415 | if (total == 100) | |
12416 | total = 99; | |
d39b6696 | 12417 | if (toppos <= BUF_BEGV (b)) |
8ffcb79f RS |
12418 | sprintf (decode_mode_spec_buf, "Top%2d%%", total); |
12419 | else | |
12420 | sprintf (decode_mode_spec_buf, "%2d%%", total); | |
12421 | return decode_mode_spec_buf; | |
12422 | } | |
12423 | } | |
12424 | ||
1af9f229 RS |
12425 | case 's': |
12426 | /* status of process */ | |
12427 | obj = Fget_buffer_process (w->buffer); | |
12428 | if (NILP (obj)) | |
12429 | return "no process"; | |
12430 | #ifdef subprocesses | |
12431 | obj = Fsymbol_name (Fprocess_status (obj)); | |
12432 | #endif | |
12433 | break; | |
d39b6696 | 12434 | |
1af9f229 RS |
12435 | case 't': /* indicate TEXT or BINARY */ |
12436 | #ifdef MODE_LINE_BINARY_TEXT | |
12437 | return MODE_LINE_BINARY_TEXT (b); | |
12438 | #else | |
12439 | return "T"; | |
12440 | #endif | |
1c9241f5 KH |
12441 | |
12442 | case 'z': | |
12443 | /* coding-system (not including end-of-line format) */ | |
12444 | case 'Z': | |
12445 | /* coding-system (including end-of-line type) */ | |
12446 | { | |
12447 | int eol_flag = (c == 'Z'); | |
539b4d41 | 12448 | char *p = decode_mode_spec_buf; |
1c9241f5 | 12449 | |
d30e754b | 12450 | if (! FRAME_WINDOW_P (f)) |
1c9241f5 | 12451 | { |
11c52c4f RS |
12452 | /* No need to mention EOL here--the terminal never needs |
12453 | to do EOL conversion. */ | |
12454 | p = decode_mode_spec_coding (keyboard_coding.symbol, p, 0); | |
12455 | p = decode_mode_spec_coding (terminal_coding.symbol, p, 0); | |
1c9241f5 | 12456 | } |
f13c925f | 12457 | p = decode_mode_spec_coding (b->buffer_file_coding_system, |
539b4d41 | 12458 | p, eol_flag); |
f13c925f | 12459 | |
11c52c4f | 12460 | #if 0 /* This proves to be annoying; I think we can do without. -- rms. */ |
1c9241f5 KH |
12461 | #ifdef subprocesses |
12462 | obj = Fget_buffer_process (Fcurrent_buffer ()); | |
12463 | if (PROCESSP (obj)) | |
12464 | { | |
12465 | p = decode_mode_spec_coding (XPROCESS (obj)->decode_coding_system, | |
12466 | p, eol_flag); | |
12467 | p = decode_mode_spec_coding (XPROCESS (obj)->encode_coding_system, | |
12468 | p, eol_flag); | |
12469 | } | |
12470 | #endif /* subprocesses */ | |
11c52c4f | 12471 | #endif /* 0 */ |
1c9241f5 KH |
12472 | *p = 0; |
12473 | return decode_mode_spec_buf; | |
12474 | } | |
a2889657 | 12475 | } |
d39b6696 | 12476 | |
e24c997d | 12477 | if (STRINGP (obj)) |
a2889657 JB |
12478 | return (char *) XSTRING (obj)->data; |
12479 | else | |
12480 | return ""; | |
12481 | } | |
5f5c8ee5 GM |
12482 | |
12483 | ||
12adba34 RS |
12484 | /* Count up to COUNT lines starting from START / START_BYTE. |
12485 | But don't go beyond LIMIT_BYTE. | |
12486 | Return the number of lines thus found (always nonnegative). | |
59b49f63 | 12487 | |
12adba34 | 12488 | Set *BYTE_POS_PTR to 1 if we found COUNT lines, 0 if we hit LIMIT. */ |
59b49f63 RS |
12489 | |
12490 | static int | |
12adba34 RS |
12491 | display_count_lines (start, start_byte, limit_byte, count, byte_pos_ptr) |
12492 | int start, start_byte, limit_byte, count; | |
12493 | int *byte_pos_ptr; | |
59b49f63 | 12494 | { |
59b49f63 RS |
12495 | register unsigned char *cursor; |
12496 | unsigned char *base; | |
12497 | ||
12498 | register int ceiling; | |
12499 | register unsigned char *ceiling_addr; | |
12adba34 | 12500 | int orig_count = count; |
59b49f63 RS |
12501 | |
12502 | /* If we are not in selective display mode, | |
12503 | check only for newlines. */ | |
12adba34 RS |
12504 | int selective_display = (!NILP (current_buffer->selective_display) |
12505 | && !INTEGERP (current_buffer->selective_display)); | |
59b49f63 RS |
12506 | |
12507 | if (count > 0) | |
12adba34 RS |
12508 | { |
12509 | while (start_byte < limit_byte) | |
12510 | { | |
12511 | ceiling = BUFFER_CEILING_OF (start_byte); | |
12512 | ceiling = min (limit_byte - 1, ceiling); | |
12513 | ceiling_addr = BYTE_POS_ADDR (ceiling) + 1; | |
12514 | base = (cursor = BYTE_POS_ADDR (start_byte)); | |
12515 | while (1) | |
12516 | { | |
12517 | if (selective_display) | |
12518 | while (*cursor != '\n' && *cursor != 015 && ++cursor != ceiling_addr) | |
12519 | ; | |
12520 | else | |
12521 | while (*cursor != '\n' && ++cursor != ceiling_addr) | |
12522 | ; | |
12523 | ||
12524 | if (cursor != ceiling_addr) | |
12525 | { | |
12526 | if (--count == 0) | |
12527 | { | |
12528 | start_byte += cursor - base + 1; | |
12529 | *byte_pos_ptr = start_byte; | |
12530 | return orig_count; | |
12531 | } | |
12532 | else | |
12533 | if (++cursor == ceiling_addr) | |
12534 | break; | |
12535 | } | |
12536 | else | |
12537 | break; | |
12538 | } | |
12539 | start_byte += cursor - base; | |
12540 | } | |
12541 | } | |
59b49f63 RS |
12542 | else |
12543 | { | |
12adba34 RS |
12544 | while (start_byte > limit_byte) |
12545 | { | |
12546 | ceiling = BUFFER_FLOOR_OF (start_byte - 1); | |
12547 | ceiling = max (limit_byte, ceiling); | |
12548 | ceiling_addr = BYTE_POS_ADDR (ceiling) - 1; | |
12549 | base = (cursor = BYTE_POS_ADDR (start_byte - 1) + 1); | |
59b49f63 RS |
12550 | while (1) |
12551 | { | |
12adba34 RS |
12552 | if (selective_display) |
12553 | while (--cursor != ceiling_addr | |
12554 | && *cursor != '\n' && *cursor != 015) | |
12555 | ; | |
12556 | else | |
12557 | while (--cursor != ceiling_addr && *cursor != '\n') | |
12558 | ; | |
12559 | ||
59b49f63 RS |
12560 | if (cursor != ceiling_addr) |
12561 | { | |
12562 | if (++count == 0) | |
12563 | { | |
12adba34 RS |
12564 | start_byte += cursor - base + 1; |
12565 | *byte_pos_ptr = start_byte; | |
12566 | /* When scanning backwards, we should | |
12567 | not count the newline posterior to which we stop. */ | |
12568 | return - orig_count - 1; | |
59b49f63 RS |
12569 | } |
12570 | } | |
12571 | else | |
12572 | break; | |
12573 | } | |
12adba34 RS |
12574 | /* Here we add 1 to compensate for the last decrement |
12575 | of CURSOR, which took it past the valid range. */ | |
12576 | start_byte += cursor - base + 1; | |
59b49f63 RS |
12577 | } |
12578 | } | |
12579 | ||
12adba34 | 12580 | *byte_pos_ptr = limit_byte; |
aa6d10fa | 12581 | |
12adba34 RS |
12582 | if (count < 0) |
12583 | return - orig_count + count; | |
12584 | return orig_count - count; | |
aa6d10fa | 12585 | |
12adba34 | 12586 | } |
a2889657 | 12587 | |
a2889657 | 12588 | |
5f5c8ee5 GM |
12589 | \f |
12590 | /*********************************************************************** | |
12591 | Displaying strings | |
12592 | ***********************************************************************/ | |
278feba9 | 12593 | |
5f5c8ee5 | 12594 | /* Display a NUL-terminated string, starting with index START. |
a3788d53 | 12595 | |
5f5c8ee5 GM |
12596 | If STRING is non-null, display that C string. Otherwise, the Lisp |
12597 | string LISP_STRING is displayed. | |
a2889657 | 12598 | |
5f5c8ee5 GM |
12599 | If FACE_STRING is not nil, FACE_STRING_POS is a position in |
12600 | FACE_STRING. Display STRING or LISP_STRING with the face at | |
12601 | FACE_STRING_POS in FACE_STRING: | |
a2889657 | 12602 | |
5f5c8ee5 GM |
12603 | Display the string in the environment given by IT, but use the |
12604 | standard display table, temporarily. | |
a3788d53 | 12605 | |
5f5c8ee5 GM |
12606 | FIELD_WIDTH is the minimum number of output glyphs to produce. |
12607 | If STRING has fewer characters than FIELD_WIDTH, pad to the right | |
12608 | with spaces. If STRING has more characters, more than FIELD_WIDTH | |
12609 | glyphs will be produced. FIELD_WIDTH <= 0 means don't pad. | |
12610 | ||
12611 | PRECISION is the maximum number of characters to output from | |
12612 | STRING. PRECISION < 0 means don't truncate the string. | |
a2889657 | 12613 | |
5f5c8ee5 | 12614 | This is roughly equivalent to printf format specifiers: |
a2889657 | 12615 | |
5f5c8ee5 GM |
12616 | FIELD_WIDTH PRECISION PRINTF |
12617 | ---------------------------------------- | |
12618 | -1 -1 %s | |
12619 | -1 10 %.10s | |
12620 | 10 -1 %10s | |
12621 | 20 10 %20.10s | |
a2889657 | 12622 | |
5f5c8ee5 GM |
12623 | MULTIBYTE zero means do not display multibyte chars, > 0 means do |
12624 | display them, and < 0 means obey the current buffer's value of | |
12625 | enable_multibyte_characters. | |
278feba9 | 12626 | |
5f5c8ee5 | 12627 | Value is the number of glyphs produced. */ |
b1d1124b | 12628 | |
5f5c8ee5 GM |
12629 | static int |
12630 | display_string (string, lisp_string, face_string, face_string_pos, | |
12631 | start, it, field_width, precision, max_x, multibyte) | |
12632 | unsigned char *string; | |
12633 | Lisp_Object lisp_string; | |
68c45bf0 PE |
12634 | Lisp_Object face_string; |
12635 | int face_string_pos; | |
5f5c8ee5 GM |
12636 | int start; |
12637 | struct it *it; | |
12638 | int field_width, precision, max_x; | |
12639 | int multibyte; | |
12640 | { | |
12641 | int hpos_at_start = it->hpos; | |
12642 | int saved_face_id = it->face_id; | |
12643 | struct glyph_row *row = it->glyph_row; | |
12644 | ||
12645 | /* Initialize the iterator IT for iteration over STRING beginning | |
12646 | with index START. We assume that IT may be modified here (which | |
12647 | means that display_line has to do something when displaying a | |
12648 | mini-buffer prompt, which it does). */ | |
12649 | reseat_to_string (it, string, lisp_string, start, | |
12650 | precision, field_width, multibyte); | |
12651 | ||
12652 | /* If displaying STRING, set up the face of the iterator | |
12653 | from LISP_STRING, if that's given. */ | |
12654 | if (STRINGP (face_string)) | |
12655 | { | |
12656 | int endptr; | |
12657 | struct face *face; | |
12658 | ||
12659 | it->face_id | |
12660 | = face_at_string_position (it->w, face_string, face_string_pos, | |
12661 | 0, it->region_beg_charpos, | |
12662 | it->region_end_charpos, | |
12663 | &endptr, it->base_face_id); | |
12664 | face = FACE_FROM_ID (it->f, it->face_id); | |
12665 | it->face_box_p = face->box != FACE_NO_BOX; | |
b1d1124b | 12666 | } |
a2889657 | 12667 | |
5f5c8ee5 GM |
12668 | /* Set max_x to the maximum allowed X position. Don't let it go |
12669 | beyond the right edge of the window. */ | |
12670 | if (max_x <= 0) | |
12671 | max_x = it->last_visible_x; | |
12672 | else | |
12673 | max_x = min (max_x, it->last_visible_x); | |
efc63ef0 | 12674 | |
5f5c8ee5 GM |
12675 | /* Skip over display elements that are not visible. because IT->w is |
12676 | hscrolled. */ | |
12677 | if (it->current_x < it->first_visible_x) | |
12678 | move_it_in_display_line_to (it, 100000, it->first_visible_x, | |
12679 | MOVE_TO_POS | MOVE_TO_X); | |
a2889657 | 12680 | |
5f5c8ee5 GM |
12681 | row->ascent = it->max_ascent; |
12682 | row->height = it->max_ascent + it->max_descent; | |
312246d1 GM |
12683 | row->phys_ascent = it->max_phys_ascent; |
12684 | row->phys_height = it->max_phys_ascent + it->max_phys_descent; | |
1c9241f5 | 12685 | |
5f5c8ee5 GM |
12686 | /* This condition is for the case that we are called with current_x |
12687 | past last_visible_x. */ | |
12688 | while (it->current_x < max_x) | |
a2889657 | 12689 | { |
5f5c8ee5 | 12690 | int x_before, x, n_glyphs_before, i, nglyphs; |
1c9241f5 | 12691 | |
5f5c8ee5 GM |
12692 | /* Get the next display element. */ |
12693 | if (!get_next_display_element (it)) | |
90adcf20 | 12694 | break; |
1c9241f5 | 12695 | |
5f5c8ee5 GM |
12696 | /* Produce glyphs. */ |
12697 | x_before = it->current_x; | |
12698 | n_glyphs_before = it->glyph_row->used[TEXT_AREA]; | |
12699 | PRODUCE_GLYPHS (it); | |
90adcf20 | 12700 | |
5f5c8ee5 GM |
12701 | nglyphs = it->glyph_row->used[TEXT_AREA] - n_glyphs_before; |
12702 | i = 0; | |
12703 | x = x_before; | |
12704 | while (i < nglyphs) | |
a2889657 | 12705 | { |
5f5c8ee5 GM |
12706 | struct glyph *glyph = row->glyphs[TEXT_AREA] + n_glyphs_before + i; |
12707 | ||
12708 | if (!it->truncate_lines_p | |
12709 | && x + glyph->pixel_width > max_x) | |
12710 | { | |
12711 | /* End of continued line or max_x reached. */ | |
12712 | it->glyph_row->used[TEXT_AREA] = n_glyphs_before + i; | |
12713 | it->current_x = x; | |
12714 | break; | |
12715 | } | |
12716 | else if (x + glyph->pixel_width > it->first_visible_x) | |
12717 | { | |
12718 | /* Glyph is at least partially visible. */ | |
12719 | ++it->hpos; | |
12720 | if (x < it->first_visible_x) | |
12721 | it->glyph_row->x = x - it->first_visible_x; | |
12722 | } | |
12723 | else | |
a2889657 | 12724 | { |
5f5c8ee5 GM |
12725 | /* Glyph is off the left margin of the display area. |
12726 | Should not happen. */ | |
12727 | abort (); | |
a2889657 | 12728 | } |
5f5c8ee5 GM |
12729 | |
12730 | row->ascent = max (row->ascent, it->max_ascent); | |
12731 | row->height = max (row->height, it->max_ascent + it->max_descent); | |
312246d1 GM |
12732 | row->phys_ascent = max (row->phys_ascent, it->max_phys_ascent); |
12733 | row->phys_height = max (row->phys_height, | |
12734 | it->max_phys_ascent + it->max_phys_descent); | |
5f5c8ee5 GM |
12735 | x += glyph->pixel_width; |
12736 | ++i; | |
a2889657 | 12737 | } |
5f5c8ee5 GM |
12738 | |
12739 | /* Stop if max_x reached. */ | |
12740 | if (i < nglyphs) | |
12741 | break; | |
12742 | ||
12743 | /* Stop at line ends. */ | |
12744 | if (ITERATOR_AT_END_OF_LINE_P (it)) | |
a2889657 | 12745 | { |
5f5c8ee5 GM |
12746 | it->continuation_lines_width = 0; |
12747 | break; | |
a2889657 | 12748 | } |
1c9241f5 | 12749 | |
5f5c8ee5 | 12750 | set_iterator_to_next (it); |
a688bb24 | 12751 | |
5f5c8ee5 GM |
12752 | /* Stop if truncating at the right edge. */ |
12753 | if (it->truncate_lines_p | |
12754 | && it->current_x >= it->last_visible_x) | |
12755 | { | |
12756 | /* Add truncation mark, but don't do it if the line is | |
12757 | truncated at a padding space. */ | |
12758 | if (IT_CHARPOS (*it) < it->string_nchars) | |
1c9241f5 | 12759 | { |
5f5c8ee5 GM |
12760 | if (!FRAME_WINDOW_P (it->f)) |
12761 | produce_special_glyphs (it, IT_TRUNCATION); | |
12762 | it->glyph_row->truncated_on_right_p = 1; | |
1c9241f5 | 12763 | } |
5f5c8ee5 | 12764 | break; |
1c9241f5 | 12765 | } |
a2889657 JB |
12766 | } |
12767 | ||
5f5c8ee5 GM |
12768 | /* Maybe insert a truncation at the left. */ |
12769 | if (it->first_visible_x | |
12770 | && IT_CHARPOS (*it) > 0) | |
a2889657 | 12771 | { |
5f5c8ee5 GM |
12772 | if (!FRAME_WINDOW_P (it->f)) |
12773 | insert_left_trunc_glyphs (it); | |
12774 | it->glyph_row->truncated_on_left_p = 1; | |
a2889657 JB |
12775 | } |
12776 | ||
5f5c8ee5 GM |
12777 | it->face_id = saved_face_id; |
12778 | ||
12779 | /* Value is number of columns displayed. */ | |
12780 | return it->hpos - hpos_at_start; | |
12781 | } | |
a2889657 | 12782 | |
a2889657 | 12783 | |
a2889657 | 12784 | \f |
5f5c8ee5 GM |
12785 | /* This is like a combination of memq and assq. Return 1 if PROPVAL |
12786 | appears as an element of LIST or as the car of an element of LIST. | |
12787 | If PROPVAL is a list, compare each element against LIST in that | |
12788 | way, and return 1 if any element of PROPVAL is found in LIST. | |
12789 | Otherwise return 0. This function cannot quit. */ | |
642eefc6 RS |
12790 | |
12791 | int | |
12792 | invisible_p (propval, list) | |
12793 | register Lisp_Object propval; | |
12794 | Lisp_Object list; | |
12795 | { | |
af460d46 | 12796 | register Lisp_Object tail, proptail; |
9472f927 | 12797 | for (tail = list; CONSP (tail); tail = XCDR (tail)) |
642eefc6 RS |
12798 | { |
12799 | register Lisp_Object tem; | |
9472f927 | 12800 | tem = XCAR (tail); |
642eefc6 RS |
12801 | if (EQ (propval, tem)) |
12802 | return 1; | |
9472f927 | 12803 | if (CONSP (tem) && EQ (propval, XCAR (tem))) |
642eefc6 RS |
12804 | return 1; |
12805 | } | |
af460d46 RS |
12806 | if (CONSP (propval)) |
12807 | for (proptail = propval; CONSP (proptail); | |
9472f927 | 12808 | proptail = XCDR (proptail)) |
af460d46 RS |
12809 | { |
12810 | Lisp_Object propelt; | |
9472f927 GM |
12811 | propelt = XCAR (proptail); |
12812 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
af460d46 RS |
12813 | { |
12814 | register Lisp_Object tem; | |
9472f927 | 12815 | tem = XCAR (tail); |
af460d46 RS |
12816 | if (EQ (propelt, tem)) |
12817 | return 1; | |
9472f927 | 12818 | if (CONSP (tem) && EQ (propelt, XCAR (tem))) |
af460d46 RS |
12819 | return 1; |
12820 | } | |
12821 | } | |
642eefc6 RS |
12822 | return 0; |
12823 | } | |
12824 | ||
5f5c8ee5 GM |
12825 | |
12826 | /* Return 1 if PROPVAL appears as the car of an element of LIST and | |
12827 | the cdr of that element is non-nil. If PROPVAL is a list, check | |
12828 | each element of PROPVAL in that way, and the first time some | |
12829 | element is found, return 1 if the cdr of that element is non-nil. | |
12830 | Otherwise return 0. This function cannot quit. */ | |
642eefc6 RS |
12831 | |
12832 | int | |
12833 | invisible_ellipsis_p (propval, list) | |
12834 | register Lisp_Object propval; | |
12835 | Lisp_Object list; | |
12836 | { | |
af460d46 | 12837 | register Lisp_Object tail, proptail; |
9472f927 GM |
12838 | |
12839 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
642eefc6 RS |
12840 | { |
12841 | register Lisp_Object tem; | |
9472f927 GM |
12842 | tem = XCAR (tail); |
12843 | if (CONSP (tem) && EQ (propval, XCAR (tem))) | |
12844 | return ! NILP (XCDR (tem)); | |
642eefc6 | 12845 | } |
9472f927 | 12846 | |
af460d46 | 12847 | if (CONSP (propval)) |
9472f927 | 12848 | for (proptail = propval; CONSP (proptail); proptail = XCDR (proptail)) |
af460d46 RS |
12849 | { |
12850 | Lisp_Object propelt; | |
9472f927 GM |
12851 | propelt = XCAR (proptail); |
12852 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
af460d46 RS |
12853 | { |
12854 | register Lisp_Object tem; | |
9472f927 GM |
12855 | tem = XCAR (tail); |
12856 | if (CONSP (tem) && EQ (propelt, XCAR (tem))) | |
12857 | return ! NILP (XCDR (tem)); | |
af460d46 RS |
12858 | } |
12859 | } | |
9472f927 | 12860 | |
642eefc6 RS |
12861 | return 0; |
12862 | } | |
5f5c8ee5 GM |
12863 | |
12864 | ||
642eefc6 | 12865 | \f |
5f5c8ee5 GM |
12866 | /*********************************************************************** |
12867 | Initialization | |
12868 | ***********************************************************************/ | |
12869 | ||
a2889657 JB |
12870 | void |
12871 | syms_of_xdisp () | |
12872 | { | |
c6e89d6c GM |
12873 | Vwith_echo_area_save_vector = Qnil; |
12874 | staticpro (&Vwith_echo_area_save_vector); | |
5f5c8ee5 | 12875 | |
c6e89d6c GM |
12876 | Vmessage_stack = Qnil; |
12877 | staticpro (&Vmessage_stack); | |
12878 | ||
735c094c | 12879 | Qinhibit_redisplay = intern ("inhibit-redisplay"); |
c6e89d6c | 12880 | staticpro (&Qinhibit_redisplay); |
735c094c | 12881 | |
5f5c8ee5 GM |
12882 | #if GLYPH_DEBUG |
12883 | defsubr (&Sdump_glyph_matrix); | |
12884 | defsubr (&Sdump_glyph_row); | |
e037b9ec | 12885 | defsubr (&Sdump_tool_bar_row); |
5f5c8ee5 | 12886 | defsubr (&Strace_redisplay_toggle); |
bf9249e3 | 12887 | defsubr (&Strace_to_stderr); |
5f5c8ee5 GM |
12888 | #endif |
12889 | ||
cf074754 RS |
12890 | staticpro (&Qmenu_bar_update_hook); |
12891 | Qmenu_bar_update_hook = intern ("menu-bar-update-hook"); | |
12892 | ||
d46fb96a | 12893 | staticpro (&Qoverriding_terminal_local_map); |
7079aefa | 12894 | Qoverriding_terminal_local_map = intern ("overriding-terminal-local-map"); |
d46fb96a | 12895 | |
399164b4 KH |
12896 | staticpro (&Qoverriding_local_map); |
12897 | Qoverriding_local_map = intern ("overriding-local-map"); | |
12898 | ||
75c43375 RS |
12899 | staticpro (&Qwindow_scroll_functions); |
12900 | Qwindow_scroll_functions = intern ("window-scroll-functions"); | |
12901 | ||
e0bfbde6 RS |
12902 | staticpro (&Qredisplay_end_trigger_functions); |
12903 | Qredisplay_end_trigger_functions = intern ("redisplay-end-trigger-functions"); | |
5f5c8ee5 | 12904 | |
2e54982e RS |
12905 | staticpro (&Qinhibit_point_motion_hooks); |
12906 | Qinhibit_point_motion_hooks = intern ("inhibit-point-motion-hooks"); | |
12907 | ||
9499d71b GM |
12908 | QCdata = intern (":data"); |
12909 | staticpro (&QCdata); | |
5f5c8ee5 | 12910 | Qdisplay = intern ("display"); |
f3751a65 | 12911 | staticpro (&Qdisplay); |
5f5c8ee5 GM |
12912 | Qspace_width = intern ("space-width"); |
12913 | staticpro (&Qspace_width); | |
5f5c8ee5 GM |
12914 | Qraise = intern ("raise"); |
12915 | staticpro (&Qraise); | |
12916 | Qspace = intern ("space"); | |
12917 | staticpro (&Qspace); | |
f3751a65 GM |
12918 | Qmargin = intern ("margin"); |
12919 | staticpro (&Qmargin); | |
5f5c8ee5 | 12920 | Qleft_margin = intern ("left-margin"); |
f3751a65 | 12921 | staticpro (&Qleft_margin); |
5f5c8ee5 | 12922 | Qright_margin = intern ("right-margin"); |
f3751a65 | 12923 | staticpro (&Qright_margin); |
5f5c8ee5 GM |
12924 | Qalign_to = intern ("align-to"); |
12925 | staticpro (&Qalign_to); | |
12926 | QCalign_to = intern (":align-to"); | |
12927 | staticpro (&QCalign_to); | |
5f5c8ee5 GM |
12928 | Qrelative_width = intern ("relative-width"); |
12929 | staticpro (&Qrelative_width); | |
12930 | QCrelative_width = intern (":relative-width"); | |
12931 | staticpro (&QCrelative_width); | |
12932 | QCrelative_height = intern (":relative-height"); | |
12933 | staticpro (&QCrelative_height); | |
12934 | QCeval = intern (":eval"); | |
12935 | staticpro (&QCeval); | |
d3acf96b | 12936 | Qwhen = intern ("when"); |
f3751a65 | 12937 | staticpro (&Qwhen); |
886bd6f2 GM |
12938 | QCfile = intern (":file"); |
12939 | staticpro (&QCfile); | |
5f5c8ee5 GM |
12940 | Qfontified = intern ("fontified"); |
12941 | staticpro (&Qfontified); | |
12942 | Qfontification_functions = intern ("fontification-functions"); | |
12943 | staticpro (&Qfontification_functions); | |
5f5c8ee5 GM |
12944 | Qtrailing_whitespace = intern ("trailing-whitespace"); |
12945 | staticpro (&Qtrailing_whitespace); | |
12946 | Qimage = intern ("image"); | |
12947 | staticpro (&Qimage); | |
12948 | ||
a2889657 JB |
12949 | last_arrow_position = Qnil; |
12950 | last_arrow_string = Qnil; | |
f3751a65 GM |
12951 | staticpro (&last_arrow_position); |
12952 | staticpro (&last_arrow_string); | |
c6e89d6c GM |
12953 | |
12954 | echo_buffer[0] = echo_buffer[1] = Qnil; | |
12955 | staticpro (&echo_buffer[0]); | |
12956 | staticpro (&echo_buffer[1]); | |
12957 | ||
12958 | echo_area_buffer[0] = echo_area_buffer[1] = Qnil; | |
12959 | staticpro (&echo_area_buffer[0]); | |
12960 | staticpro (&echo_area_buffer[1]); | |
a2889657 | 12961 | |
8f897821 GM |
12962 | DEFVAR_LISP ("show-trailing-whitespace", &Vshow_trailing_whitespace, |
12963 | "Non-nil means highlight trailing whitespace.\n\ | |
12964 | The face used for trailing whitespace is `trailing-whitespace'."); | |
12965 | Vshow_trailing_whitespace = Qnil; | |
12966 | ||
735c094c KH |
12967 | DEFVAR_LISP ("inhibit-redisplay", &Vinhibit_redisplay, |
12968 | "Non-nil means don't actually do any redisplay.\n\ | |
12969 | This is used for internal purposes."); | |
12970 | Vinhibit_redisplay = Qnil; | |
12971 | ||
a2889657 | 12972 | DEFVAR_LISP ("global-mode-string", &Vglobal_mode_string, |
8c45d522 | 12973 | "String (or mode line construct) included (normally) in `mode-line-format'."); |
a2889657 JB |
12974 | Vglobal_mode_string = Qnil; |
12975 | ||
12976 | DEFVAR_LISP ("overlay-arrow-position", &Voverlay_arrow_position, | |
12977 | "Marker for where to display an arrow on top of the buffer text.\n\ | |
12978 | This must be the beginning of a line in order to work.\n\ | |
12979 | See also `overlay-arrow-string'."); | |
12980 | Voverlay_arrow_position = Qnil; | |
12981 | ||
12982 | DEFVAR_LISP ("overlay-arrow-string", &Voverlay_arrow_string, | |
12983 | "String to display as an arrow. See also `overlay-arrow-position'."); | |
12984 | Voverlay_arrow_string = Qnil; | |
12985 | ||
12986 | DEFVAR_INT ("scroll-step", &scroll_step, | |
12987 | "*The number of lines to try scrolling a window by when point moves out.\n\ | |
44fa5b1e JB |
12988 | If that fails to bring point back on frame, point is centered instead.\n\ |
12989 | If this is zero, point is always centered after it moves off frame."); | |
a2889657 | 12990 | |
0789adb2 | 12991 | DEFVAR_INT ("scroll-conservatively", &scroll_conservatively, |
090f7baa GM |
12992 | "*Scroll up to this many lines, to bring point back on screen.\n\ |
12993 | A value of zero means to scroll the text to center point vertically\n\ | |
12994 | in the window."); | |
0789adb2 RS |
12995 | scroll_conservatively = 0; |
12996 | ||
9afd2168 RS |
12997 | DEFVAR_INT ("scroll-margin", &scroll_margin, |
12998 | "*Number of lines of margin at the top and bottom of a window.\n\ | |
12999 | Recenter the window whenever point gets within this many lines\n\ | |
13000 | of the top or bottom of the window."); | |
13001 | scroll_margin = 0; | |
13002 | ||
5f5c8ee5 | 13003 | #if GLYPH_DEBUG |
a2889657 | 13004 | DEFVAR_INT ("debug-end-pos", &debug_end_pos, "Don't ask"); |
5f5c8ee5 | 13005 | #endif |
a2889657 JB |
13006 | |
13007 | DEFVAR_BOOL ("truncate-partial-width-windows", | |
13008 | &truncate_partial_width_windows, | |
44fa5b1e | 13009 | "*Non-nil means truncate lines in all windows less than full frame wide."); |
a2889657 JB |
13010 | truncate_partial_width_windows = 1; |
13011 | ||
13012 | DEFVAR_BOOL ("mode-line-inverse-video", &mode_line_inverse_video, | |
13013 | "*Non-nil means use inverse video for the mode line."); | |
13014 | mode_line_inverse_video = 1; | |
aa6d10fa RS |
13015 | |
13016 | DEFVAR_INT ("line-number-display-limit", &line_number_display_limit, | |
5f5c8ee5 | 13017 | "*Maximum buffer size for which line number should be displayed.\n\ |
db4f2bfa | 13018 | If the buffer is bigger than this, the line number does not appear\n\ |
9f027393 | 13019 | in the mode line."); |
aa6d10fa | 13020 | line_number_display_limit = 1000000; |
fba9ce76 | 13021 | |
5d121aec KH |
13022 | DEFVAR_INT ("line-number-display-limit-width", &line_number_display_limit_width, |
13023 | "*Maximum line width (in characters) for line number display.\n\ | |
13024 | If the average length of the lines near point is bigger than this, then the\n\ | |
13025 | line number may be omitted from the mode line."); | |
13026 | line_number_display_limit_width = 200; | |
13027 | ||
fba9ce76 RS |
13028 | DEFVAR_BOOL ("highlight-nonselected-windows", &highlight_nonselected_windows, |
13029 | "*Non-nil means highlight region even in nonselected windows."); | |
293a54ce | 13030 | highlight_nonselected_windows = 0; |
d39b6696 KH |
13031 | |
13032 | DEFVAR_BOOL ("multiple-frames", &multiple_frames, | |
3450d04c KH |
13033 | "Non-nil if more than one frame is visible on this display.\n\ |
13034 | Minibuffer-only frames don't count, but iconified frames do.\n\ | |
4c2eb242 RS |
13035 | This variable is not guaranteed to be accurate except while processing\n\ |
13036 | `frame-title-format' and `icon-title-format'."); | |
d39b6696 KH |
13037 | |
13038 | DEFVAR_LISP ("frame-title-format", &Vframe_title_format, | |
5f5c8ee5 | 13039 | "Template for displaying the title bar of visible frames.\n\ |
d39b6696 KH |
13040 | \(Assuming the window manager supports this feature.)\n\ |
13041 | This variable has the same structure as `mode-line-format' (which see),\n\ | |
13042 | and is used only on frames for which no explicit name has been set\n\ | |
13043 | \(see `modify-frame-parameters')."); | |
13044 | DEFVAR_LISP ("icon-title-format", &Vicon_title_format, | |
5f5c8ee5 | 13045 | "Template for displaying the title bar of an iconified frame.\n\ |
d39b6696 KH |
13046 | \(Assuming the window manager supports this feature.)\n\ |
13047 | This variable has the same structure as `mode-line-format' (which see),\n\ | |
13048 | and is used only on frames for which no explicit name has been set\n\ | |
13049 | \(see `modify-frame-parameters')."); | |
13050 | Vicon_title_format | |
13051 | = Vframe_title_format | |
13052 | = Fcons (intern ("multiple-frames"), | |
13053 | Fcons (build_string ("%b"), | |
13054 | Fcons (Fcons (build_string (""), | |
13055 | Fcons (intern ("invocation-name"), | |
13056 | Fcons (build_string ("@"), | |
13057 | Fcons (intern ("system-name"), | |
13058 | Qnil)))), | |
13059 | Qnil))); | |
5992c4f7 KH |
13060 | |
13061 | DEFVAR_LISP ("message-log-max", &Vmessage_log_max, | |
13062 | "Maximum number of lines to keep in the message log buffer.\n\ | |
13063 | If nil, disable message logging. If t, log messages but don't truncate\n\ | |
13064 | the buffer when it becomes large."); | |
13065 | XSETFASTINT (Vmessage_log_max, 50); | |
08b610e4 RS |
13066 | |
13067 | DEFVAR_LISP ("window-size-change-functions", &Vwindow_size_change_functions, | |
13068 | "Functions called before redisplay, if window sizes have changed.\n\ | |
13069 | The value should be a list of functions that take one argument.\n\ | |
13070 | Just before redisplay, for each frame, if any of its windows have changed\n\ | |
13071 | size since the last redisplay, or have been split or deleted,\n\ | |
13072 | all the functions in the list are called, with the frame as argument."); | |
13073 | Vwindow_size_change_functions = Qnil; | |
75c43375 RS |
13074 | |
13075 | DEFVAR_LISP ("window-scroll-functions", &Vwindow_scroll_functions, | |
5f5c8ee5 | 13076 | "List of Functions to call before redisplaying a window with scrolling.\n\ |
75c43375 | 13077 | Each function is called with two arguments, the window\n\ |
8d9583b0 RS |
13078 | and its new display-start position. Note that the value of `window-end'\n\ |
13079 | is not valid when these functions are called."); | |
75c43375 | 13080 | Vwindow_scroll_functions = Qnil; |
5f5c8ee5 | 13081 | |
e037b9ec GM |
13082 | DEFVAR_BOOL ("auto-resize-tool-bars", &auto_resize_tool_bars_p, |
13083 | "*Non-nil means automatically resize tool-bars.\n\ | |
13084 | This increases a tool-bar's height if not all tool-bar items are visible.\n\ | |
13085 | It decreases a tool-bar's height when it would display blank lines\n\ | |
5f5c8ee5 | 13086 | otherwise."); |
e037b9ec | 13087 | auto_resize_tool_bars_p = 1; |
5f5c8ee5 | 13088 | |
e037b9ec GM |
13089 | DEFVAR_BOOL ("auto-raise-tool-bar-buttons", &auto_raise_tool_bar_buttons_p, |
13090 | "*Non-nil means raise tool-bar buttons when the mouse moves over them."); | |
13091 | auto_raise_tool_bar_buttons_p = 1; | |
5f5c8ee5 | 13092 | |
e037b9ec GM |
13093 | DEFVAR_INT ("tool-bar-button-margin", &tool_bar_button_margin, |
13094 | "*Margin around tool-bar buttons in pixels."); | |
13095 | tool_bar_button_margin = 1; | |
5f5c8ee5 | 13096 | |
e037b9ec GM |
13097 | DEFVAR_INT ("tool-bar-button-relief", &tool_bar_button_relief, |
13098 | "Relief thickness of tool-bar buttons."); | |
13099 | tool_bar_button_relief = 3; | |
5f5c8ee5 GM |
13100 | |
13101 | DEFVAR_LISP ("fontification-functions", &Vfontification_functions, | |
13102 | "List of functions to call to fontify regions of text.\n\ | |
13103 | Each function is called with one argument POS. Functions must\n\ | |
13104 | fontify a region starting at POS in the current buffer, and give\n\ | |
13105 | fontified regions the property `fontified'.\n\ | |
13106 | This variable automatically becomes buffer-local when set."); | |
13107 | Vfontification_functions = Qnil; | |
13108 | Fmake_local_variable (Qfontification_functions); | |
7bbe686f AI |
13109 | |
13110 | DEFVAR_BOOL ("unibyte-display-via-language-environment", | |
5f5c8ee5 GM |
13111 | &unibyte_display_via_language_environment, |
13112 | "*Non-nil means display unibyte text according to language environment.\n\ | |
7bbe686f AI |
13113 | Specifically this means that unibyte non-ASCII characters\n\ |
13114 | are displayed by converting them to the equivalent multibyte characters\n\ | |
13115 | according to the current language environment. As a result, they are\n\ | |
13116 | displayed according to the current fontset."); | |
13117 | unibyte_display_via_language_environment = 0; | |
c6e89d6c GM |
13118 | |
13119 | DEFVAR_LISP ("max-mini-window-height", &Vmax_mini_window_height, | |
13120 | "*Maximum height for resizing mini-windows.\n\ | |
13121 | If a float, it specifies a fraction of the mini-window frame's height.\n\ | |
97cafc0f GM |
13122 | If an integer, it specifies a number of lines.\n\ |
13123 | If nil, don't resize."); | |
c6e89d6c | 13124 | Vmax_mini_window_height = make_float (0.25); |
d6d26ed3 GM |
13125 | |
13126 | DEFVAR_BOOL ("cursor-in-non-selected-windows", | |
13127 | &cursor_in_non_selected_windows, | |
13128 | "*Non-nil means display a hollow cursor in non-selected windows.\n\ | |
13129 | Nil means don't display a cursor there."); | |
13130 | cursor_in_non_selected_windows = 1; | |
d475bcb8 GM |
13131 | |
13132 | DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p, | |
13133 | "*Non-nil means scroll the display automatically to make point visible."); | |
13134 | automatic_hscrolling_p = 1; | |
e00daaa0 GM |
13135 | |
13136 | DEFVAR_LISP ("image-types", &Vimage_types, | |
13137 | "List of supported image types.\n\ | |
13138 | Each element of the list is a symbol for a supported image type."); | |
13139 | Vimage_types = Qnil; | |
a2889657 JB |
13140 | } |
13141 | ||
5f5c8ee5 GM |
13142 | |
13143 | /* Initialize this module when Emacs starts. */ | |
13144 | ||
dfcf069d | 13145 | void |
a2889657 JB |
13146 | init_xdisp () |
13147 | { | |
13148 | Lisp_Object root_window; | |
5f5c8ee5 | 13149 | struct window *mini_w; |
a2889657 | 13150 | |
5f5c8ee5 | 13151 | CHARPOS (this_line_start_pos) = 0; |
a2889657 JB |
13152 | |
13153 | mini_w = XWINDOW (minibuf_window); | |
11e82b76 | 13154 | root_window = FRAME_ROOT_WINDOW (XFRAME (WINDOW_FRAME (mini_w))); |
a2889657 | 13155 | |
a2889657 JB |
13156 | if (!noninteractive) |
13157 | { | |
5f5c8ee5 GM |
13158 | struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (root_window))); |
13159 | int i; | |
13160 | ||
13161 | XSETFASTINT (XWINDOW (root_window)->top, FRAME_TOP_MARGIN (f)); | |
12c226c5 | 13162 | set_window_height (root_window, |
5f5c8ee5 | 13163 | FRAME_HEIGHT (f) - 1 - FRAME_TOP_MARGIN (f), |
12c226c5 | 13164 | 0); |
c2213350 | 13165 | XSETFASTINT (mini_w->top, FRAME_HEIGHT (f) - 1); |
a2889657 JB |
13166 | set_window_height (minibuf_window, 1, 0); |
13167 | ||
c2213350 KH |
13168 | XSETFASTINT (XWINDOW (root_window)->width, FRAME_WIDTH (f)); |
13169 | XSETFASTINT (mini_w->width, FRAME_WIDTH (f)); | |
5f5c8ee5 GM |
13170 | |
13171 | scratch_glyph_row.glyphs[TEXT_AREA] = scratch_glyphs; | |
13172 | scratch_glyph_row.glyphs[TEXT_AREA + 1] | |
13173 | = scratch_glyphs + MAX_SCRATCH_GLYPHS; | |
13174 | ||
13175 | /* The default ellipsis glyphs `...'. */ | |
13176 | for (i = 0; i < 3; ++i) | |
13177 | XSETFASTINT (default_invis_vector[i], '.'); | |
a2889657 | 13178 | } |
5f5c8ee5 GM |
13179 | |
13180 | #ifdef HAVE_WINDOW_SYSTEM | |
13181 | { | |
13182 | /* Allocate the buffer for frame titles. */ | |
13183 | int size = 100; | |
13184 | frame_title_buf = (char *) xmalloc (size); | |
13185 | frame_title_buf_end = frame_title_buf + size; | |
13186 | frame_title_ptr = NULL; | |
13187 | } | |
13188 | #endif /* HAVE_WINDOW_SYSTEM */ | |
a2889657 | 13189 | } |
5f5c8ee5 GM |
13190 | |
13191 |