Mercurial > vim
annotate src/screen.c @ 2103:89dc68c0ab6f v7.2.386
updated for version 7.2.386
Problem: Focus hack for KDE 3.1 causes problems for other window managers.
Solution: Remove the hack. (forwarded by Joel Bradshaw)
author | Bram Moolenaar <bram@zimbu.org> |
---|---|
date | Wed, 10 Mar 2010 12:25:03 +0100 |
parents | 63613d8d7e4d |
children | 476336a5ae95 |
rev | line source |
---|---|
7 | 1 /* vi:set ts=8 sts=4 sw=4: |
2 * | |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * screen.c: code for displaying on the screen | |
12 * | |
13 * Output to the screen (console, terminal emulator or GUI window) is minimized | |
14 * by remembering what is already on the screen, and only updating the parts | |
15 * that changed. | |
16 * | |
17 * ScreenLines[off] Contains a copy of the whole screen, as it is currently | |
18 * displayed (excluding text written by external commands). | |
19 * ScreenAttrs[off] Contains the associated attributes. | |
20 * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] | |
21 * for each line. | |
22 * LineWraps[row] Flag for each line whether it wraps to the next line. | |
23 * | |
24 * For double-byte characters, two consecutive bytes in ScreenLines[] can form | |
25 * one character which occupies two display cells. | |
26 * For UTF-8 a multi-byte character is converted to Unicode and stored in | |
27 * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII | |
28 * character without composing chars ScreenLinesUC[] will be 0. When the | |
29 * character occupies two display cells the next byte in ScreenLines[] is 0. | |
714 | 30 * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
7 | 31 * (drawn on top of the first character). They are 0 when not used. |
32 * ScreenLines2[] is only used for euc-jp to store the second byte if the | |
33 * first byte is 0x8e (single-width character). | |
34 * | |
35 * The screen_*() functions write to the screen and handle updating | |
36 * ScreenLines[]. | |
37 * | |
38 * update_screen() is the function that updates all windows and status lines. | |
39 * It is called form the main loop when must_redraw is non-zero. It may be | |
1213 | 40 * called from other places when an immediate screen update is needed. |
7 | 41 * |
42 * The part of the buffer that is displayed in a window is set with: | |
43 * - w_topline (first buffer line in window) | |
44 * - w_topfill (filler line above the first line) | |
45 * - w_leftcol (leftmost window cell in window), | |
46 * - w_skipcol (skipped window cells of first line) | |
47 * | |
48 * Commands that only move the cursor around in a window, do not need to take | |
49 * action to update the display. The main loop will check if w_topline is | |
50 * valid and update it (scroll the window) when needed. | |
51 * | |
52 * Commands that scroll a window change w_topline and must call | |
53 * check_cursor() to move the cursor into the visible part of the window, and | |
54 * call redraw_later(VALID) to have the window displayed by update_screen() | |
55 * later. | |
56 * | |
57 * Commands that change text in the buffer must call changed_bytes() or | |
58 * changed_lines() to mark the area that changed and will require updating | |
59 * later. The main loop will call update_screen(), which will update each | |
60 * window that shows the changed buffer. This assumes text above the change | |
61 * can remain displayed as it is. Text after the change may need updating for | |
62 * scrolling, folding and syntax highlighting. | |
63 * | |
64 * Commands that change how a window is displayed (e.g., setting 'list') or | |
65 * invalidate the contents of a window in another way (e.g., change fold | |
66 * settings), must call redraw_later(NOT_VALID) to have the whole window | |
67 * redisplayed by update_screen() later. | |
68 * | |
69 * Commands that change how a buffer is displayed (e.g., setting 'tabstop') | |
70 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the | |
71 * buffer redisplayed by update_screen() later. | |
72 * | |
743 | 73 * Commands that change highlighting and possibly cause a scroll too must call |
74 * redraw_later(SOME_VALID) to update the whole window but still use scrolling | |
75 * to avoid redrawing everything. But the length of displayed lines must not | |
76 * change, use NOT_VALID then. | |
77 * | |
7 | 78 * Commands that move the window position must call redraw_later(NOT_VALID). |
79 * TODO: should minimize redrawing by scrolling when possible. | |
80 * | |
81 * Commands that change everything (e.g., resizing the screen) must call | |
82 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). | |
83 * | |
84 * Things that are handled indirectly: | |
85 * - When messages scroll the screen up, msg_scrolled will be set and | |
86 * update_screen() called to redraw. | |
87 */ | |
88 | |
89 #include "vim.h" | |
90 | |
91 /* | |
92 * The attributes that are actually active for writing to the screen. | |
93 */ | |
94 static int screen_attr = 0; | |
95 | |
96 /* | |
97 * Positioning the cursor is reduced by remembering the last position. | |
98 * Mostly used by windgoto() and screen_char(). | |
99 */ | |
100 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
101 | |
102 #ifdef FEAT_SEARCH_EXTRA | |
103 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
104 #endif | |
105 | |
106 #ifdef FEAT_FOLDING | |
107 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
108 #endif | |
109 | |
110 /* | |
111 * Buffer for one screen line (characters and attributes). | |
112 */ | |
113 static schar_T *current_ScreenLine; | |
114 | |
115 static void win_update __ARGS((win_T *wp)); | |
534 | 116 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 117 #ifdef FEAT_FOLDING |
118 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
119 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
120 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
121 #endif | |
625 | 122 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 123 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
124 #ifdef FEAT_RIGHTLEFT | |
125 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
126 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
127 #else | |
128 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
129 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
130 #endif | |
131 #ifdef FEAT_VERTSPLIT | |
132 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
133 #endif | |
680 | 134 #ifdef FEAT_STL_OPT |
1983 | 135 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 136 #endif |
7 | 137 #ifdef FEAT_SEARCH_EXTRA |
1326 | 138 #define SEARCH_HL_PRIORITY 0 |
7 | 139 static void start_search_hl __ARGS((void)); |
140 static void end_search_hl __ARGS((void)); | |
141 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); | |
142 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
143 #endif | |
144 static void screen_start_highlight __ARGS((int attr)); | |
145 static void screen_char __ARGS((unsigned off, int row, int col)); | |
146 #ifdef FEAT_MBYTE | |
147 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
148 #endif | |
149 static void screenclear2 __ARGS((void)); | |
150 static void lineclear __ARGS((unsigned off, int width)); | |
151 static void lineinvalid __ARGS((unsigned off, int width)); | |
152 #ifdef FEAT_VERTSPLIT | |
153 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
154 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
155 #endif | |
156 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
157 static void win_rest_invalid __ARGS((win_T *wp)); | |
158 static void msg_pos_mode __ARGS((void)); | |
667 | 159 #if defined(FEAT_WINDOWS) |
677 | 160 static void draw_tabline __ARGS((void)); |
667 | 161 #endif |
7 | 162 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
163 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
164 #endif | |
165 #ifdef FEAT_VERTSPLIT | |
166 static int fillchar_vsep __ARGS((int *attr)); | |
167 #endif | |
168 #ifdef FEAT_STL_OPT | |
574 | 169 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 170 #endif |
171 #ifdef FEAT_CMDL_INFO | |
172 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
173 #endif | |
174 | |
175 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
176 /* Ugly global: overrule attribute used by screen_char() */ | |
177 static int screen_char_attr = 0; | |
178 #endif | |
179 | |
180 /* | |
181 * Redraw the current window later, with update_screen(type). | |
182 * Set must_redraw only if not already set to a higher value. | |
183 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
184 */ | |
185 void | |
186 redraw_later(type) | |
187 int type; | |
188 { | |
189 redraw_win_later(curwin, type); | |
190 } | |
191 | |
192 void | |
193 redraw_win_later(wp, type) | |
194 win_T *wp; | |
195 int type; | |
196 { | |
197 if (wp->w_redr_type < type) | |
198 { | |
199 wp->w_redr_type = type; | |
200 if (type >= NOT_VALID) | |
201 wp->w_lines_valid = 0; | |
202 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
203 must_redraw = type; | |
204 } | |
205 } | |
206 | |
207 /* | |
208 * Force a complete redraw later. Also resets the highlighting. To be used | |
209 * after executing a shell command that messes up the screen. | |
210 */ | |
211 void | |
212 redraw_later_clear() | |
213 { | |
214 redraw_all_later(CLEAR); | |
826 | 215 #ifdef FEAT_GUI |
216 if (gui.in_use) | |
217 /* Use a code that will reset gui.highlight_mask in | |
218 * gui_stop_highlight(). */ | |
219 screen_attr = HL_ALL + 1; | |
220 else | |
221 #endif | |
222 /* Use attributes that is very unlikely to appear in text. */ | |
223 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 224 } |
225 | |
226 /* | |
227 * Mark all windows to be redrawn later. | |
228 */ | |
229 void | |
230 redraw_all_later(type) | |
231 int type; | |
232 { | |
233 win_T *wp; | |
234 | |
235 FOR_ALL_WINDOWS(wp) | |
236 { | |
237 redraw_win_later(wp, type); | |
238 } | |
239 } | |
240 | |
241 /* | |
301 | 242 * Mark all windows that are editing the current buffer to be updated later. |
7 | 243 */ |
244 void | |
245 redraw_curbuf_later(type) | |
246 int type; | |
247 { | |
248 redraw_buf_later(curbuf, type); | |
249 } | |
250 | |
251 void | |
252 redraw_buf_later(buf, type) | |
253 buf_T *buf; | |
254 int type; | |
255 { | |
256 win_T *wp; | |
257 | |
258 FOR_ALL_WINDOWS(wp) | |
259 { | |
260 if (wp->w_buffer == buf) | |
261 redraw_win_later(wp, type); | |
262 } | |
263 } | |
264 | |
265 /* | |
266 * Changed something in the current window, at buffer line "lnum", that | |
267 * requires that line and possibly other lines to be redrawn. | |
268 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
269 * Used to remove the "$" from a change command. | |
270 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
271 * may become invalid and the whole window will have to be redrawn. | |
272 */ | |
273 void | |
274 redrawWinline(lnum, invalid) | |
275 linenr_T lnum; | |
1883 | 276 int invalid UNUSED; /* window line height is invalid now */ |
7 | 277 { |
278 #ifdef FEAT_FOLDING | |
279 int i; | |
280 #endif | |
281 | |
282 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
283 curwin->w_redraw_top = lnum; | |
284 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
285 curwin->w_redraw_bot = lnum; | |
286 redraw_later(VALID); | |
287 | |
288 #ifdef FEAT_FOLDING | |
289 if (invalid) | |
290 { | |
291 /* A w_lines[] entry for this lnum has become invalid. */ | |
292 i = find_wl_entry(curwin, lnum); | |
293 if (i >= 0) | |
294 curwin->w_lines[i].wl_valid = FALSE; | |
295 } | |
296 #endif | |
297 } | |
298 | |
299 /* | |
300 * update all windows that are editing the current buffer | |
301 */ | |
302 void | |
303 update_curbuf(type) | |
304 int type; | |
305 { | |
306 redraw_curbuf_later(type); | |
307 update_screen(type); | |
308 } | |
309 | |
310 /* | |
311 * update_screen() | |
312 * | |
313 * Based on the current value of curwin->w_topline, transfer a screenfull | |
314 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
315 */ | |
316 void | |
317 update_screen(type) | |
318 int type; | |
319 { | |
320 win_T *wp; | |
321 static int did_intro = FALSE; | |
322 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
323 int did_one; | |
324 #endif | |
325 | |
2008 | 326 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 327 if (!screen_valid(TRUE)) |
328 return; | |
329 | |
330 if (must_redraw) | |
331 { | |
332 if (type < must_redraw) /* use maximal type */ | |
333 type = must_redraw; | |
1331 | 334 |
335 /* must_redraw is reset here, so that when we run into some weird | |
336 * reason to redraw while busy redrawing (e.g., asynchronous | |
337 * scrolling), or update_topline() in win_update() will cause a | |
338 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 339 must_redraw = 0; |
340 } | |
341 | |
342 /* Need to update w_lines[]. */ | |
343 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
344 type = NOT_VALID; | |
345 | |
2008 | 346 /* Postpone the redrawing when it's not needed and when being called |
347 * recursively. */ | |
348 if (!redrawing() || updating_screen) | |
7 | 349 { |
350 redraw_later(type); /* remember type for next time */ | |
351 must_redraw = type; | |
352 if (type > INVERTED_ALL) | |
353 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
354 return; | |
355 } | |
356 | |
357 updating_screen = TRUE; | |
358 #ifdef FEAT_SYN_HL | |
359 ++display_tick; /* let syntax code know we're in a next round of | |
360 * display updating */ | |
361 #endif | |
362 | |
363 /* | |
364 * if the screen was scrolled up when displaying a message, scroll it down | |
365 */ | |
366 if (msg_scrolled) | |
367 { | |
368 clear_cmdline = TRUE; | |
369 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
370 type = CLEAR; | |
371 else if (type != CLEAR) | |
372 { | |
373 check_for_delay(FALSE); | |
374 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
375 type = CLEAR; | |
376 FOR_ALL_WINDOWS(wp) | |
377 { | |
378 if (W_WINROW(wp) < msg_scrolled) | |
379 { | |
380 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
381 && wp->w_redr_type < REDRAW_TOP | |
382 && wp->w_lines_valid > 0 | |
383 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
384 { | |
385 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
386 wp->w_redr_type = REDRAW_TOP; | |
387 } | |
388 else | |
389 { | |
390 wp->w_redr_type = NOT_VALID; | |
391 #ifdef FEAT_WINDOWS | |
392 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
393 <= msg_scrolled) | |
394 wp->w_redr_status = TRUE; | |
395 #endif | |
396 } | |
397 } | |
398 } | |
399 redraw_cmdline = TRUE; | |
667 | 400 #ifdef FEAT_WINDOWS |
673 | 401 redraw_tabline = TRUE; |
667 | 402 #endif |
7 | 403 } |
404 msg_scrolled = 0; | |
405 need_wait_return = FALSE; | |
406 } | |
407 | |
408 /* reset cmdline_row now (may have been changed temporarily) */ | |
409 compute_cmdrow(); | |
410 | |
411 /* Check for changed highlighting */ | |
412 if (need_highlight_changed) | |
413 highlight_changed(); | |
414 | |
415 if (type == CLEAR) /* first clear screen */ | |
416 { | |
417 screenclear(); /* will reset clear_cmdline */ | |
418 type = NOT_VALID; | |
419 } | |
420 | |
421 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
422 check_for_delay(FALSE); | |
423 | |
13 | 424 #ifdef FEAT_LINEBREAK |
425 /* Force redraw when width of 'number' column changes. */ | |
426 if (curwin->w_redr_type < NOT_VALID | |
677 | 427 && curwin->w_nrwidth != (curwin->w_p_nu ? number_width(curwin) : 0)) |
13 | 428 curwin->w_redr_type = NOT_VALID; |
429 #endif | |
430 | |
7 | 431 /* |
432 * Only start redrawing if there is really something to do. | |
433 */ | |
434 if (type == INVERTED) | |
435 update_curswant(); | |
436 if (curwin->w_redr_type < type | |
437 && !((type == VALID | |
438 && curwin->w_lines[0].wl_valid | |
439 #ifdef FEAT_DIFF | |
440 && curwin->w_topfill == curwin->w_old_topfill | |
441 && curwin->w_botfill == curwin->w_old_botfill | |
442 #endif | |
443 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
444 #ifdef FEAT_VISUAL | |
445 || (type == INVERTED | |
1043 | 446 && VIsual_active |
7 | 447 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
448 && curwin->w_old_visual_mode == VIsual_mode | |
449 && (curwin->w_valid & VALID_VIRTCOL) | |
450 && curwin->w_old_curswant == curwin->w_curswant) | |
451 #endif | |
452 )) | |
453 curwin->w_redr_type = type; | |
454 | |
849 | 455 #ifdef FEAT_WINDOWS |
456 /* Redraw the tab pages line if needed. */ | |
457 if (redraw_tabline || type >= NOT_VALID) | |
458 draw_tabline(); | |
459 #endif | |
460 | |
7 | 461 #ifdef FEAT_SYN_HL |
462 /* | |
463 * Correct stored syntax highlighting info for changes in each displayed | |
464 * buffer. Each buffer must only be done once. | |
465 */ | |
466 FOR_ALL_WINDOWS(wp) | |
467 { | |
468 if (wp->w_buffer->b_mod_set) | |
469 { | |
470 # ifdef FEAT_WINDOWS | |
471 win_T *wwp; | |
472 | |
473 /* Check if we already did this buffer. */ | |
474 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
475 if (wwp->w_buffer == wp->w_buffer) | |
476 break; | |
477 # endif | |
478 if ( | |
479 # ifdef FEAT_WINDOWS | |
480 wwp == wp && | |
481 # endif | |
482 syntax_present(wp->w_buffer)) | |
483 syn_stack_apply_changes(wp->w_buffer); | |
484 } | |
485 } | |
486 #endif | |
487 | |
488 /* | |
489 * Go from top to bottom through the windows, redrawing the ones that need | |
490 * it. | |
491 */ | |
492 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
493 did_one = FALSE; | |
494 #endif | |
495 #ifdef FEAT_SEARCH_EXTRA | |
496 search_hl.rm.regprog = NULL; | |
497 #endif | |
498 FOR_ALL_WINDOWS(wp) | |
499 { | |
500 if (wp->w_redr_type != 0) | |
501 { | |
502 cursor_off(); | |
503 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
504 if (!did_one) | |
505 { | |
506 did_one = TRUE; | |
507 # ifdef FEAT_SEARCH_EXTRA | |
508 start_search_hl(); | |
509 # endif | |
510 # ifdef FEAT_CLIPBOARD | |
511 /* When Visual area changed, may have to update selection. */ | |
512 if (clip_star.available && clip_isautosel()) | |
513 clip_update_selection(); | |
514 # endif | |
515 #ifdef FEAT_GUI | |
516 /* Remove the cursor before starting to do anything, because | |
517 * scrolling may make it difficult to redraw the text under | |
518 * it. */ | |
519 if (gui.in_use) | |
520 gui_undraw_cursor(); | |
521 #endif | |
522 } | |
523 #endif | |
524 win_update(wp); | |
525 } | |
526 | |
527 #ifdef FEAT_WINDOWS | |
528 /* redraw status line after the window to minimize cursor movement */ | |
529 if (wp->w_redr_status) | |
530 { | |
531 cursor_off(); | |
532 win_redr_status(wp); | |
533 } | |
534 #endif | |
535 } | |
536 #if defined(FEAT_SEARCH_EXTRA) | |
537 end_search_hl(); | |
538 #endif | |
539 | |
540 #ifdef FEAT_WINDOWS | |
541 /* Reset b_mod_set flags. Going through all windows is probably faster | |
542 * than going through all buffers (there could be many buffers). */ | |
543 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
544 wp->w_buffer->b_mod_set = FALSE; | |
545 #else | |
546 curbuf->b_mod_set = FALSE; | |
547 #endif | |
548 | |
549 updating_screen = FALSE; | |
550 #ifdef FEAT_GUI | |
551 gui_may_resize_shell(); | |
552 #endif | |
553 | |
554 /* Clear or redraw the command line. Done last, because scrolling may | |
555 * mess up the command line. */ | |
556 if (clear_cmdline || redraw_cmdline) | |
557 showmode(); | |
558 | |
559 /* May put up an introductory message when not editing a file */ | |
560 if (!did_intro && bufempty() | |
561 && curbuf->b_fname == NULL | |
562 #ifdef FEAT_WINDOWS | |
563 && firstwin->w_next == NULL | |
564 #endif | |
565 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
566 intro_message(FALSE); | |
567 did_intro = TRUE; | |
568 | |
569 #ifdef FEAT_GUI | |
570 /* Redraw the cursor and update the scrollbars when all screen updating is | |
571 * done. */ | |
572 if (gui.in_use) | |
573 { | |
574 out_flush(); /* required before updating the cursor */ | |
575 if (did_one) | |
576 gui_update_cursor(FALSE, FALSE); | |
577 gui_update_scrollbars(FALSE); | |
578 } | |
579 #endif | |
580 } | |
581 | |
582 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) | |
583 static void update_prepare __ARGS((void)); | |
584 static void update_finish __ARGS((void)); | |
585 | |
586 /* | |
587 * Prepare for updating one or more windows. | |
2008 | 588 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 589 */ |
590 static void | |
591 update_prepare() | |
592 { | |
593 cursor_off(); | |
594 updating_screen = TRUE; | |
595 #ifdef FEAT_GUI | |
596 /* Remove the cursor before starting to do anything, because scrolling may | |
597 * make it difficult to redraw the text under it. */ | |
598 if (gui.in_use) | |
599 gui_undraw_cursor(); | |
600 #endif | |
601 #ifdef FEAT_SEARCH_EXTRA | |
602 start_search_hl(); | |
603 #endif | |
604 } | |
605 | |
606 /* | |
607 * Finish updating one or more windows. | |
608 */ | |
609 static void | |
610 update_finish() | |
611 { | |
612 if (redraw_cmdline) | |
613 showmode(); | |
614 | |
615 # ifdef FEAT_SEARCH_EXTRA | |
616 end_search_hl(); | |
617 # endif | |
618 | |
619 updating_screen = FALSE; | |
620 | |
621 # ifdef FEAT_GUI | |
622 gui_may_resize_shell(); | |
623 | |
624 /* Redraw the cursor and update the scrollbars when all screen updating is | |
625 * done. */ | |
626 if (gui.in_use) | |
627 { | |
628 out_flush(); /* required before updating the cursor */ | |
629 gui_update_cursor(FALSE, FALSE); | |
630 gui_update_scrollbars(FALSE); | |
631 } | |
632 # endif | |
633 } | |
634 #endif | |
635 | |
636 #if defined(FEAT_SIGNS) || defined(PROTO) | |
637 void | |
638 update_debug_sign(buf, lnum) | |
639 buf_T *buf; | |
640 linenr_T lnum; | |
641 { | |
642 win_T *wp; | |
643 int doit = FALSE; | |
644 | |
645 # ifdef FEAT_FOLDING | |
646 win_foldinfo.fi_level = 0; | |
647 # endif | |
648 | |
649 /* update/delete a specific mark */ | |
650 FOR_ALL_WINDOWS(wp) | |
651 { | |
652 if (buf != NULL && lnum > 0) | |
653 { | |
654 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
655 && lnum < wp->w_botline) | |
656 { | |
657 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
658 wp->w_redraw_top = lnum; | |
659 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
660 wp->w_redraw_bot = lnum; | |
661 redraw_win_later(wp, VALID); | |
662 } | |
663 } | |
664 else | |
665 redraw_win_later(wp, VALID); | |
666 if (wp->w_redr_type != 0) | |
667 doit = TRUE; | |
668 } | |
669 | |
2008 | 670 /* Return when there is nothing to do or screen updating already |
671 * happening. */ | |
672 if (!doit || updating_screen) | |
7 | 673 return; |
674 | |
675 /* update all windows that need updating */ | |
676 update_prepare(); | |
677 | |
678 # ifdef FEAT_WINDOWS | |
679 for (wp = firstwin; wp; wp = wp->w_next) | |
680 { | |
681 if (wp->w_redr_type != 0) | |
682 win_update(wp); | |
683 if (wp->w_redr_status) | |
684 win_redr_status(wp); | |
685 } | |
686 # else | |
687 if (curwin->w_redr_type != 0) | |
688 win_update(curwin); | |
689 # endif | |
690 | |
691 update_finish(); | |
692 } | |
693 #endif | |
694 | |
695 | |
696 #if defined(FEAT_GUI) || defined(PROTO) | |
697 /* | |
698 * Update a single window, its status line and maybe the command line msg. | |
699 * Used for the GUI scrollbar. | |
700 */ | |
701 void | |
702 updateWindow(wp) | |
703 win_T *wp; | |
704 { | |
2008 | 705 /* return if already busy updating */ |
706 if (updating_screen) | |
707 return; | |
708 | |
7 | 709 update_prepare(); |
710 | |
711 #ifdef FEAT_CLIPBOARD | |
712 /* When Visual area changed, may have to update selection. */ | |
713 if (clip_star.available && clip_isautosel()) | |
714 clip_update_selection(); | |
715 #endif | |
670 | 716 |
7 | 717 win_update(wp); |
670 | 718 |
7 | 719 #ifdef FEAT_WINDOWS |
670 | 720 /* When the screen was cleared redraw the tab pages line. */ |
673 | 721 if (redraw_tabline) |
677 | 722 draw_tabline(); |
670 | 723 |
7 | 724 if (wp->w_redr_status |
725 # ifdef FEAT_CMDL_INFO | |
726 || p_ru | |
727 # endif | |
728 # ifdef FEAT_STL_OPT | |
40 | 729 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 730 # endif |
731 ) | |
732 win_redr_status(wp); | |
733 #endif | |
734 | |
735 update_finish(); | |
736 } | |
737 #endif | |
738 | |
739 /* | |
740 * Update a single window. | |
741 * | |
742 * This may cause the windows below it also to be redrawn (when clearing the | |
743 * screen or scrolling lines). | |
744 * | |
745 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
746 * implies the one below it. | |
747 * NOT_VALID redraw the whole window | |
743 | 748 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 749 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
750 * INVERTED redraw the changed part of the Visual area | |
751 * INVERTED_ALL redraw the whole Visual area | |
752 * VALID 1. scroll up/down to adjust for a changed w_topline | |
753 * 2. update lines at the top when scrolled down | |
754 * 3. redraw changed text: | |
301 | 755 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 756 * b_mod_top and b_mod_bot. |
757 * - if wp->w_redraw_top non-zero, redraw lines between | |
758 * wp->w_redraw_top and wp->w_redr_bot. | |
759 * - continue redrawing when syntax status is invalid. | |
760 * 4. if scrolled up, update lines at the bottom. | |
761 * This results in three areas that may need updating: | |
762 * top: from first row to top_end (when scrolled down) | |
763 * mid: from mid_start to mid_end (update inversion or changed text) | |
764 * bot: from bot_start to last row (when scrolled up) | |
765 */ | |
766 static void | |
767 win_update(wp) | |
768 win_T *wp; | |
769 { | |
770 buf_T *buf = wp->w_buffer; | |
771 int type; | |
772 int top_end = 0; /* Below last row of the top area that needs | |
773 updating. 0 when no top area updating. */ | |
774 int mid_start = 999;/* first row of the mid area that needs | |
775 updating. 999 when no mid area updating. */ | |
776 int mid_end = 0; /* Below last row of the mid area that needs | |
777 updating. 0 when no mid area updating. */ | |
778 int bot_start = 999;/* first row of the bot area that needs | |
779 updating. 999 when no bot area updating */ | |
780 #ifdef FEAT_VISUAL | |
781 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
782 w_topline got smaller a bit */ | |
783 #endif | |
784 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 785 matchitem_T *cur; /* points to the match list */ |
7 | 786 int top_to_mod = FALSE; /* redraw above mod_top */ |
787 #endif | |
788 | |
789 int row; /* current window row to display */ | |
790 linenr_T lnum; /* current buffer lnum to display */ | |
791 int idx; /* current index in w_lines[] */ | |
792 int srow; /* starting row of the current line */ | |
793 | |
794 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
795 int didline = FALSE; /* if TRUE, we finished the last line */ | |
796 int i; | |
797 long j; | |
798 static int recursive = FALSE; /* being called recursively */ | |
799 int old_botline = wp->w_botline; | |
800 #ifdef FEAT_FOLDING | |
801 long fold_count; | |
802 #endif | |
803 #ifdef FEAT_SYN_HL | |
804 /* remember what happened to the previous line, to know if | |
805 * check_visual_highlight() can be used */ | |
806 #define DID_NONE 1 /* didn't update a line */ | |
807 #define DID_LINE 2 /* updated a normal line */ | |
808 #define DID_FOLD 3 /* updated a folded line */ | |
809 int did_update = DID_NONE; | |
810 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
811 #endif | |
812 linenr_T mod_top = 0; | |
813 linenr_T mod_bot = 0; | |
814 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
815 int save_got_int; | |
816 #endif | |
817 | |
818 type = wp->w_redr_type; | |
819 | |
820 if (type == NOT_VALID) | |
821 { | |
822 #ifdef FEAT_WINDOWS | |
823 wp->w_redr_status = TRUE; | |
824 #endif | |
825 wp->w_lines_valid = 0; | |
826 } | |
827 | |
828 /* Window is zero-height: nothing to draw. */ | |
829 if (wp->w_height == 0) | |
830 { | |
831 wp->w_redr_type = 0; | |
832 return; | |
833 } | |
834 | |
835 #ifdef FEAT_VERTSPLIT | |
836 /* Window is zero-width: Only need to draw the separator. */ | |
837 if (wp->w_width == 0) | |
838 { | |
839 /* draw the vertical separator right of this window */ | |
840 draw_vsep_win(wp, 0); | |
841 wp->w_redr_type = 0; | |
842 return; | |
843 } | |
844 #endif | |
845 | |
846 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 847 /* Setup for match and 'hlsearch' highlighting. Disable any previous |
699 | 848 * match */ |
1326 | 849 cur = wp->w_match_head; |
850 while (cur != NULL) | |
851 { | |
852 cur->hl.rm = cur->match; | |
853 if (cur->hlg_id == 0) | |
854 cur->hl.attr = 0; | |
699 | 855 else |
1326 | 856 cur->hl.attr = syn_id2attr(cur->hlg_id); |
857 cur->hl.buf = buf; | |
858 cur->hl.lnum = 0; | |
859 cur->hl.first_lnum = 0; | |
1521 | 860 # ifdef FEAT_RELTIME |
861 /* Set the time limit to 'redrawtime'. */ | |
862 profile_setlimit(p_rdt, &(cur->hl.tm)); | |
863 # endif | |
1326 | 864 cur = cur->next; |
699 | 865 } |
7 | 866 search_hl.buf = buf; |
867 search_hl.lnum = 0; | |
868 search_hl.first_lnum = 0; | |
1521 | 869 /* time limit is set at the toplevel, for all windows */ |
7 | 870 #endif |
871 | |
13 | 872 #ifdef FEAT_LINEBREAK |
873 /* Force redraw when width of 'number' column changes. */ | |
677 | 874 i = wp->w_p_nu ? number_width(wp) : 0; |
875 if (wp->w_nrwidth != i) | |
13 | 876 { |
877 type = NOT_VALID; | |
677 | 878 wp->w_nrwidth = i; |
13 | 879 } |
880 else | |
881 #endif | |
882 | |
7 | 883 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
884 { | |
885 /* | |
886 * When there are both inserted/deleted lines and specific lines to be | |
887 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
888 * everything (only happens when redrawing is off for while). | |
889 */ | |
890 type = NOT_VALID; | |
891 } | |
892 else | |
893 { | |
894 /* | |
895 * Set mod_top to the first line that needs displaying because of | |
896 * changes. Set mod_bot to the first line after the changes. | |
897 */ | |
898 mod_top = wp->w_redraw_top; | |
899 if (wp->w_redraw_bot != 0) | |
900 mod_bot = wp->w_redraw_bot + 1; | |
901 else | |
902 mod_bot = 0; | |
903 wp->w_redraw_top = 0; /* reset for next time */ | |
904 wp->w_redraw_bot = 0; | |
905 if (buf->b_mod_set) | |
906 { | |
907 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
908 { | |
909 mod_top = buf->b_mod_top; | |
910 #ifdef FEAT_SYN_HL | |
911 /* Need to redraw lines above the change that may be included | |
912 * in a pattern match. */ | |
913 if (syntax_present(buf)) | |
914 { | |
915 mod_top -= buf->b_syn_sync_linebreaks; | |
916 if (mod_top < 1) | |
917 mod_top = 1; | |
918 } | |
919 #endif | |
920 } | |
921 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
922 mod_bot = buf->b_mod_bot; | |
923 | |
924 #ifdef FEAT_SEARCH_EXTRA | |
925 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
926 * change in one line may make the Search highlighting in a | |
927 * previous line invalid. Simple solution: redraw all visible | |
928 * lines above the change. | |
1326 | 929 * Same for a match pattern. |
7 | 930 */ |
699 | 931 if (search_hl.rm.regprog != NULL |
932 && re_multiline(search_hl.rm.regprog)) | |
7 | 933 top_to_mod = TRUE; |
699 | 934 else |
1326 | 935 { |
936 cur = wp->w_match_head; | |
937 while (cur != NULL) | |
938 { | |
939 if (cur->match.regprog != NULL | |
940 && re_multiline(cur->match.regprog)) | |
699 | 941 { |
942 top_to_mod = TRUE; | |
943 break; | |
944 } | |
1326 | 945 cur = cur->next; |
946 } | |
947 } | |
7 | 948 #endif |
949 } | |
950 #ifdef FEAT_FOLDING | |
951 if (mod_top != 0 && hasAnyFolding(wp)) | |
952 { | |
953 linenr_T lnumt, lnumb; | |
954 | |
955 /* | |
956 * A change in a line can cause lines above it to become folded or | |
957 * unfolded. Find the top most buffer line that may be affected. | |
958 * If the line was previously folded and displayed, get the first | |
959 * line of that fold. If the line is folded now, get the first | |
960 * folded line. Use the minimum of these two. | |
961 */ | |
962 | |
963 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
964 * the line below it. If there is no valid entry, use w_topline. | |
965 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
966 * to this line. If there is no valid entry, use MAXLNUM. */ | |
967 lnumt = wp->w_topline; | |
968 lnumb = MAXLNUM; | |
969 for (i = 0; i < wp->w_lines_valid; ++i) | |
970 if (wp->w_lines[i].wl_valid) | |
971 { | |
972 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
973 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
974 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
975 { | |
976 lnumb = wp->w_lines[i].wl_lnum; | |
977 /* When there is a fold column it might need updating | |
978 * in the next line ("J" just above an open fold). */ | |
979 if (wp->w_p_fdc > 0) | |
980 ++lnumb; | |
981 } | |
982 } | |
983 | |
984 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
985 if (mod_top > lnumt) | |
986 mod_top = lnumt; | |
987 | |
988 /* Now do the same for the bottom line (one above mod_bot). */ | |
989 --mod_bot; | |
990 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
991 ++mod_bot; | |
992 if (mod_bot < lnumb) | |
993 mod_bot = lnumb; | |
994 } | |
995 #endif | |
996 | |
997 /* When a change starts above w_topline and the end is below | |
998 * w_topline, start redrawing at w_topline. | |
36 | 999 * If the end of the change is above w_topline: do like no change was |
1000 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1001 if (mod_top != 0 && mod_top < wp->w_topline) |
1002 { | |
1003 if (mod_bot > wp->w_topline) | |
1004 mod_top = wp->w_topline; | |
1005 #ifdef FEAT_SYN_HL | |
1006 else if (syntax_present(buf)) | |
1007 top_end = 1; | |
1008 #endif | |
1009 } | |
36 | 1010 |
1011 /* When line numbers are displayed need to redraw all lines below | |
1012 * inserted/deleted lines. */ | |
1013 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1014 mod_bot = MAXLNUM; | |
7 | 1015 } |
1016 | |
1017 /* | |
1018 * When only displaying the lines at the top, set top_end. Used when | |
1019 * window has scrolled down for msg_scrolled. | |
1020 */ | |
1021 if (type == REDRAW_TOP) | |
1022 { | |
1023 j = 0; | |
1024 for (i = 0; i < wp->w_lines_valid; ++i) | |
1025 { | |
1026 j += wp->w_lines[i].wl_size; | |
1027 if (j >= wp->w_upd_rows) | |
1028 { | |
1029 top_end = j; | |
1030 break; | |
1031 } | |
1032 } | |
1033 if (top_end == 0) | |
1034 /* not found (cannot happen?): redraw everything */ | |
1035 type = NOT_VALID; | |
1036 else | |
1037 /* top area defined, the rest is VALID */ | |
1038 type = VALID; | |
1039 } | |
1040 | |
1378 | 1041 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1042 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1043 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1044 * called. */ | |
1045 if (screen_cleared) | |
1046 screen_cleared = MAYBE; | |
1047 | |
7 | 1048 /* |
1049 * If there are no changes on the screen that require a complete redraw, | |
1050 * handle three cases: | |
1051 * 1: we are off the top of the screen by a few lines: scroll down | |
1052 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1053 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1054 * w_lines[] that needs updating. | |
1055 */ | |
743 | 1056 if ((type == VALID || type == SOME_VALID |
1057 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1058 #ifdef FEAT_DIFF |
1059 && !wp->w_botfill && !wp->w_old_botfill | |
1060 #endif | |
1061 ) | |
1062 { | |
1063 if (mod_top != 0 && wp->w_topline == mod_top) | |
1064 { | |
1065 /* | |
1066 * w_topline is the first changed line, the scrolling will be done | |
1067 * further down. | |
1068 */ | |
1069 } | |
1070 else if (wp->w_lines[0].wl_valid | |
1071 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1072 #ifdef FEAT_DIFF | |
1073 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1074 && wp->w_topfill > wp->w_old_topfill) | |
1075 #endif | |
1076 )) | |
1077 { | |
1078 /* | |
1079 * New topline is above old topline: May scroll down. | |
1080 */ | |
1081 #ifdef FEAT_FOLDING | |
1082 if (hasAnyFolding(wp)) | |
1083 { | |
1084 linenr_T ln; | |
1085 | |
1086 /* count the number of lines we are off, counting a sequence | |
1087 * of folded lines as one */ | |
1088 j = 0; | |
1089 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1090 { | |
1091 ++j; | |
1092 if (j >= wp->w_height - 2) | |
1093 break; | |
1094 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1095 } | |
1096 } | |
1097 else | |
1098 #endif | |
1099 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1100 if (j < wp->w_height - 2) /* not too far off */ | |
1101 { | |
1102 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1103 #ifdef FEAT_DIFF | |
1104 /* insert extra lines for previously invisible filler lines */ | |
1105 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1106 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1107 - wp->w_old_topfill; | |
1108 #endif | |
1109 if (i < wp->w_height - 2) /* less than a screen off */ | |
1110 { | |
1111 /* | |
1112 * Try to insert the correct number of lines. | |
1113 * If not the last window, delete the lines at the bottom. | |
1114 * win_ins_lines may fail when the terminal can't do it. | |
1115 */ | |
1116 if (i > 0) | |
1117 check_for_delay(FALSE); | |
1118 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1119 { | |
1120 if (wp->w_lines_valid != 0) | |
1121 { | |
1122 /* Need to update rows that are new, stop at the | |
1123 * first one that scrolled down. */ | |
1124 top_end = i; | |
1125 #ifdef FEAT_VISUAL | |
1126 scrolled_down = TRUE; | |
1127 #endif | |
1128 | |
1129 /* Move the entries that were scrolled, disable | |
1130 * the entries for the lines to be redrawn. */ | |
1131 if ((wp->w_lines_valid += j) > wp->w_height) | |
1132 wp->w_lines_valid = wp->w_height; | |
1133 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1134 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1135 while (idx >= 0) | |
1136 wp->w_lines[idx--].wl_valid = FALSE; | |
1137 } | |
1138 } | |
1139 else | |
1140 mid_start = 0; /* redraw all lines */ | |
1141 } | |
1142 else | |
1143 mid_start = 0; /* redraw all lines */ | |
1144 } | |
1145 else | |
1146 mid_start = 0; /* redraw all lines */ | |
1147 } | |
1148 else | |
1149 { | |
1150 /* | |
1151 * New topline is at or below old topline: May scroll up. | |
1152 * When topline didn't change, find first entry in w_lines[] that | |
1153 * needs updating. | |
1154 */ | |
1155 | |
1156 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1157 j = -1; | |
1158 row = 0; | |
1159 for (i = 0; i < wp->w_lines_valid; i++) | |
1160 { | |
1161 if (wp->w_lines[i].wl_valid | |
1162 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1163 { | |
1164 j = i; | |
1165 break; | |
1166 } | |
1167 row += wp->w_lines[i].wl_size; | |
1168 } | |
1169 if (j == -1) | |
1170 { | |
1171 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1172 * lines */ | |
1173 mid_start = 0; | |
1174 } | |
1175 else | |
1176 { | |
1177 /* | |
1178 * Try to delete the correct number of lines. | |
1179 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1180 */ | |
1181 #ifdef FEAT_DIFF | |
1182 /* If the topline didn't change, delete old filler lines, | |
1183 * otherwise delete filler lines of the new topline... */ | |
1184 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1185 row += wp->w_old_topfill; | |
1186 else | |
1187 row += diff_check_fill(wp, wp->w_topline); | |
1188 /* ... but don't delete new filler lines. */ | |
1189 row -= wp->w_topfill; | |
1190 #endif | |
1191 if (row > 0) | |
1192 { | |
1193 check_for_delay(FALSE); | |
1194 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1195 bot_start = wp->w_height - row; | |
1196 else | |
1197 mid_start = 0; /* redraw all lines */ | |
1198 } | |
1199 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1200 { | |
1201 /* | |
1202 * Skip the lines (below the deleted lines) that are still | |
1203 * valid and don't need redrawing. Copy their info | |
1204 * upwards, to compensate for the deleted lines. Set | |
1205 * bot_start to the first row that needs redrawing. | |
1206 */ | |
1207 bot_start = 0; | |
1208 idx = 0; | |
1209 for (;;) | |
1210 { | |
1211 wp->w_lines[idx] = wp->w_lines[j]; | |
1212 /* stop at line that didn't fit, unless it is still | |
1213 * valid (no lines deleted) */ | |
1214 if (row > 0 && bot_start + row | |
1215 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1216 { | |
1217 wp->w_lines_valid = idx + 1; | |
1218 break; | |
1219 } | |
1220 bot_start += wp->w_lines[idx++].wl_size; | |
1221 | |
1222 /* stop at the last valid entry in w_lines[].wl_size */ | |
1223 if (++j >= wp->w_lines_valid) | |
1224 { | |
1225 wp->w_lines_valid = idx; | |
1226 break; | |
1227 } | |
1228 } | |
1229 #ifdef FEAT_DIFF | |
1230 /* Correct the first entry for filler lines at the top | |
1231 * when it won't get updated below. */ | |
1232 if (wp->w_p_diff && bot_start > 0) | |
1233 wp->w_lines[0].wl_size = | |
1234 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1235 + wp->w_topfill; | |
1236 #endif | |
1237 } | |
1238 } | |
1239 } | |
1240 | |
1241 /* When starting redraw in the first line, redraw all lines. When | |
1242 * there is only one window it's probably faster to clear the screen | |
1243 * first. */ | |
1244 if (mid_start == 0) | |
1245 { | |
1246 mid_end = wp->w_height; | |
1247 if (lastwin == firstwin) | |
981 | 1248 { |
1331 | 1249 /* Clear the screen when it was not done by win_del_lines() or |
1250 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1251 * then. */ | |
1252 if (screen_cleared != TRUE) | |
1253 screenclear(); | |
981 | 1254 #ifdef FEAT_WINDOWS |
1255 /* The screen was cleared, redraw the tab pages line. */ | |
1256 if (redraw_tabline) | |
1257 draw_tabline(); | |
1258 #endif | |
1259 } | |
7 | 1260 } |
1331 | 1261 |
1262 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1263 * cleared (only happens for the first window) or when screenclear() | |
1264 * was called directly above, "must_redraw" will have been set to | |
1265 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1266 if (screen_cleared == TRUE) | |
1267 must_redraw = 0; | |
7 | 1268 } |
1269 else | |
1270 { | |
1271 /* Not VALID or INVERTED: redraw all lines. */ | |
1272 mid_start = 0; | |
1273 mid_end = wp->w_height; | |
1274 } | |
1275 | |
743 | 1276 if (type == SOME_VALID) |
1277 { | |
1278 /* SOME_VALID: redraw all lines. */ | |
1279 mid_start = 0; | |
1280 mid_end = wp->w_height; | |
1281 type = NOT_VALID; | |
1282 } | |
1283 | |
7 | 1284 #ifdef FEAT_VISUAL |
1285 /* check if we are updating or removing the inverted part */ | |
1286 if ((VIsual_active && buf == curwin->w_buffer) | |
1287 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1288 { | |
1289 linenr_T from, to; | |
1290 | |
1291 if (VIsual_active) | |
1292 { | |
1293 if (VIsual_active | |
1294 && (VIsual_mode != wp->w_old_visual_mode | |
1295 || type == INVERTED_ALL)) | |
1296 { | |
1297 /* | |
1298 * If the type of Visual selection changed, redraw the whole | |
1299 * selection. Also when the ownership of the X selection is | |
1300 * gained or lost. | |
1301 */ | |
1302 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1303 { | |
1304 from = curwin->w_cursor.lnum; | |
1305 to = VIsual.lnum; | |
1306 } | |
1307 else | |
1308 { | |
1309 from = VIsual.lnum; | |
1310 to = curwin->w_cursor.lnum; | |
1311 } | |
1312 /* redraw more when the cursor moved as well */ | |
1313 if (wp->w_old_cursor_lnum < from) | |
1314 from = wp->w_old_cursor_lnum; | |
1315 if (wp->w_old_cursor_lnum > to) | |
1316 to = wp->w_old_cursor_lnum; | |
1317 if (wp->w_old_visual_lnum < from) | |
1318 from = wp->w_old_visual_lnum; | |
1319 if (wp->w_old_visual_lnum > to) | |
1320 to = wp->w_old_visual_lnum; | |
1321 } | |
1322 else | |
1323 { | |
1324 /* | |
1325 * Find the line numbers that need to be updated: The lines | |
1326 * between the old cursor position and the current cursor | |
1327 * position. Also check if the Visual position changed. | |
1328 */ | |
1329 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1330 { | |
1331 from = curwin->w_cursor.lnum; | |
1332 to = wp->w_old_cursor_lnum; | |
1333 } | |
1334 else | |
1335 { | |
1336 from = wp->w_old_cursor_lnum; | |
1337 to = curwin->w_cursor.lnum; | |
1338 if (from == 0) /* Visual mode just started */ | |
1339 from = to; | |
1340 } | |
1341 | |
422 | 1342 if (VIsual.lnum != wp->w_old_visual_lnum |
1343 || VIsual.col != wp->w_old_visual_col) | |
7 | 1344 { |
1345 if (wp->w_old_visual_lnum < from | |
1346 && wp->w_old_visual_lnum != 0) | |
1347 from = wp->w_old_visual_lnum; | |
1348 if (wp->w_old_visual_lnum > to) | |
1349 to = wp->w_old_visual_lnum; | |
1350 if (VIsual.lnum < from) | |
1351 from = VIsual.lnum; | |
1352 if (VIsual.lnum > to) | |
1353 to = VIsual.lnum; | |
1354 } | |
1355 } | |
1356 | |
1357 /* | |
1358 * If in block mode and changed column or curwin->w_curswant: | |
1359 * update all lines. | |
1360 * First compute the actual start and end column. | |
1361 */ | |
1362 if (VIsual_mode == Ctrl_V) | |
1363 { | |
1364 colnr_T fromc, toc; | |
1365 | |
1366 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1367 ++toc; | |
1368 if (curwin->w_curswant == MAXCOL) | |
1369 toc = MAXCOL; | |
1370 | |
1371 if (fromc != wp->w_old_cursor_fcol | |
1372 || toc != wp->w_old_cursor_lcol) | |
1373 { | |
1374 if (from > VIsual.lnum) | |
1375 from = VIsual.lnum; | |
1376 if (to < VIsual.lnum) | |
1377 to = VIsual.lnum; | |
1378 } | |
1379 wp->w_old_cursor_fcol = fromc; | |
1380 wp->w_old_cursor_lcol = toc; | |
1381 } | |
1382 } | |
1383 else | |
1384 { | |
1385 /* Use the line numbers of the old Visual area. */ | |
1386 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1387 { | |
1388 from = wp->w_old_cursor_lnum; | |
1389 to = wp->w_old_visual_lnum; | |
1390 } | |
1391 else | |
1392 { | |
1393 from = wp->w_old_visual_lnum; | |
1394 to = wp->w_old_cursor_lnum; | |
1395 } | |
1396 } | |
1397 | |
1398 /* | |
1399 * There is no need to update lines above the top of the window. | |
1400 */ | |
1401 if (from < wp->w_topline) | |
1402 from = wp->w_topline; | |
1403 | |
1404 /* | |
1405 * If we know the value of w_botline, use it to restrict the update to | |
1406 * the lines that are visible in the window. | |
1407 */ | |
1408 if (wp->w_valid & VALID_BOTLINE) | |
1409 { | |
1410 if (from >= wp->w_botline) | |
1411 from = wp->w_botline - 1; | |
1412 if (to >= wp->w_botline) | |
1413 to = wp->w_botline - 1; | |
1414 } | |
1415 | |
1416 /* | |
1417 * Find the minimal part to be updated. | |
1418 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1419 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1420 * top_end; need to redraw from top_end to the "to" line. | |
1421 * A middle mouse click with a Visual selection may change the text | |
1422 * above the Visual area and reset wl_valid, do count these for | |
1423 * mid_end (in srow). | |
1424 */ | |
1425 if (mid_start > 0) | |
1426 { | |
1427 lnum = wp->w_topline; | |
1428 idx = 0; | |
1429 srow = 0; | |
1430 if (scrolled_down) | |
1431 mid_start = top_end; | |
1432 else | |
1433 mid_start = 0; | |
1434 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1435 { | |
1436 if (wp->w_lines[idx].wl_valid) | |
1437 mid_start += wp->w_lines[idx].wl_size; | |
1438 else if (!scrolled_down) | |
1439 srow += wp->w_lines[idx].wl_size; | |
1440 ++idx; | |
1441 # ifdef FEAT_FOLDING | |
1442 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1443 lnum = wp->w_lines[idx].wl_lnum; | |
1444 else | |
1445 # endif | |
1446 ++lnum; | |
1447 } | |
1448 srow += mid_start; | |
1449 mid_end = wp->w_height; | |
1450 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1451 { | |
1452 if (wp->w_lines[idx].wl_valid | |
1453 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1454 { | |
1455 /* Only update until first row of this line */ | |
1456 mid_end = srow; | |
1457 break; | |
1458 } | |
1459 srow += wp->w_lines[idx].wl_size; | |
1460 } | |
1461 } | |
1462 } | |
1463 | |
1464 if (VIsual_active && buf == curwin->w_buffer) | |
1465 { | |
1466 wp->w_old_visual_mode = VIsual_mode; | |
1467 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1468 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1469 wp->w_old_visual_col = VIsual.col; |
7 | 1470 wp->w_old_curswant = curwin->w_curswant; |
1471 } | |
1472 else | |
1473 { | |
1474 wp->w_old_visual_mode = 0; | |
1475 wp->w_old_cursor_lnum = 0; | |
1476 wp->w_old_visual_lnum = 0; | |
422 | 1477 wp->w_old_visual_col = 0; |
7 | 1478 } |
1479 #endif /* FEAT_VISUAL */ | |
1480 | |
1481 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1482 /* reset got_int, otherwise regexp won't work */ | |
1483 save_got_int = got_int; | |
1484 got_int = 0; | |
1485 #endif | |
1486 #ifdef FEAT_FOLDING | |
1487 win_foldinfo.fi_level = 0; | |
1488 #endif | |
1489 | |
1490 /* | |
1491 * Update all the window rows. | |
1492 */ | |
1493 idx = 0; /* first entry in w_lines[].wl_size */ | |
1494 row = 0; | |
1495 srow = 0; | |
1496 lnum = wp->w_topline; /* first line shown in window */ | |
1497 for (;;) | |
1498 { | |
1499 /* stop updating when reached the end of the window (check for _past_ | |
1500 * the end of the window is at the end of the loop) */ | |
1501 if (row == wp->w_height) | |
1502 { | |
1503 didline = TRUE; | |
1504 break; | |
1505 } | |
1506 | |
1507 /* stop updating when hit the end of the file */ | |
1508 if (lnum > buf->b_ml.ml_line_count) | |
1509 { | |
1510 eof = TRUE; | |
1511 break; | |
1512 } | |
1513 | |
1514 /* Remember the starting row of the line that is going to be dealt | |
1515 * with. It is used further down when the line doesn't fit. */ | |
1516 srow = row; | |
1517 | |
1518 /* | |
1519 * Update a line when it is in an area that needs updating, when it | |
1520 * has changes or w_lines[idx] is invalid. | |
1521 * bot_start may be halfway a wrapped line after using | |
1522 * win_del_lines(), check if the current line includes it. | |
1523 * When syntax folding is being used, the saved syntax states will | |
1524 * already have been updated, we can't see where the syntax state is | |
1525 * the same again, just update until the end of the window. | |
1526 */ | |
1527 if (row < top_end | |
1528 || (row >= mid_start && row < mid_end) | |
1529 #ifdef FEAT_SEARCH_EXTRA | |
1530 || top_to_mod | |
1531 #endif | |
1532 || idx >= wp->w_lines_valid | |
1533 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1534 || (mod_top != 0 | |
1535 && (lnum == mod_top | |
1536 || (lnum >= mod_top | |
1537 && (lnum < mod_bot | |
1538 #ifdef FEAT_SYN_HL | |
1539 || did_update == DID_FOLD | |
1540 || (did_update == DID_LINE | |
1541 && syntax_present(buf) | |
1542 && ( | |
1543 # ifdef FEAT_FOLDING | |
1544 (foldmethodIsSyntax(wp) | |
1545 && hasAnyFolding(wp)) || | |
1546 # endif | |
1547 syntax_check_changed(lnum))) | |
1548 #endif | |
1549 ))))) | |
1550 { | |
1551 #ifdef FEAT_SEARCH_EXTRA | |
1552 if (lnum == mod_top) | |
1553 top_to_mod = FALSE; | |
1554 #endif | |
1555 | |
1556 /* | |
1557 * When at start of changed lines: May scroll following lines | |
1558 * up or down to minimize redrawing. | |
1559 * Don't do this when the change continues until the end. | |
1560 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1561 */ | |
1562 if (lnum == mod_top | |
1563 && mod_bot != MAXLNUM | |
1564 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1565 { | |
1566 int old_rows = 0; | |
1567 int new_rows = 0; | |
1568 int xtra_rows; | |
1569 linenr_T l; | |
1570 | |
1571 /* Count the old number of window rows, using w_lines[], which | |
1572 * should still contain the sizes for the lines as they are | |
1573 * currently displayed. */ | |
1574 for (i = idx; i < wp->w_lines_valid; ++i) | |
1575 { | |
1576 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1577 * lines are part of the changed area. */ | |
1578 if (wp->w_lines[i].wl_valid | |
1579 && wp->w_lines[i].wl_lnum == mod_bot) | |
1580 break; | |
1581 old_rows += wp->w_lines[i].wl_size; | |
1582 #ifdef FEAT_FOLDING | |
1583 if (wp->w_lines[i].wl_valid | |
1584 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1585 { | |
1586 /* Must have found the last valid entry above mod_bot. | |
1587 * Add following invalid entries. */ | |
1588 ++i; | |
1589 while (i < wp->w_lines_valid | |
1590 && !wp->w_lines[i].wl_valid) | |
1591 old_rows += wp->w_lines[i++].wl_size; | |
1592 break; | |
1593 } | |
1594 #endif | |
1595 } | |
1596 | |
1597 if (i >= wp->w_lines_valid) | |
1598 { | |
1599 /* We can't find a valid line below the changed lines, | |
1600 * need to redraw until the end of the window. | |
1601 * Inserting/deleting lines has no use. */ | |
1602 bot_start = 0; | |
1603 } | |
1604 else | |
1605 { | |
1606 /* Able to count old number of rows: Count new window | |
1607 * rows, and may insert/delete lines */ | |
1608 j = idx; | |
1609 for (l = lnum; l < mod_bot; ++l) | |
1610 { | |
1611 #ifdef FEAT_FOLDING | |
1612 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1613 ++new_rows; | |
1614 else | |
1615 #endif | |
1616 #ifdef FEAT_DIFF | |
1617 if (l == wp->w_topline) | |
1618 new_rows += plines_win_nofill(wp, l, TRUE) | |
1619 + wp->w_topfill; | |
1620 else | |
1621 #endif | |
1622 new_rows += plines_win(wp, l, TRUE); | |
1623 ++j; | |
1624 if (new_rows > wp->w_height - row - 2) | |
1625 { | |
1626 /* it's getting too much, must redraw the rest */ | |
1627 new_rows = 9999; | |
1628 break; | |
1629 } | |
1630 } | |
1631 xtra_rows = new_rows - old_rows; | |
1632 if (xtra_rows < 0) | |
1633 { | |
1634 /* May scroll text up. If there is not enough | |
1635 * remaining text or scrolling fails, must redraw the | |
1636 * rest. If scrolling works, must redraw the text | |
1637 * below the scrolled text. */ | |
1638 if (row - xtra_rows >= wp->w_height - 2) | |
1639 mod_bot = MAXLNUM; | |
1640 else | |
1641 { | |
1642 check_for_delay(FALSE); | |
1643 if (win_del_lines(wp, row, | |
1644 -xtra_rows, FALSE, FALSE) == FAIL) | |
1645 mod_bot = MAXLNUM; | |
1646 else | |
1647 bot_start = wp->w_height + xtra_rows; | |
1648 } | |
1649 } | |
1650 else if (xtra_rows > 0) | |
1651 { | |
1652 /* May scroll text down. If there is not enough | |
1653 * remaining text of scrolling fails, must redraw the | |
1654 * rest. */ | |
1655 if (row + xtra_rows >= wp->w_height - 2) | |
1656 mod_bot = MAXLNUM; | |
1657 else | |
1658 { | |
1659 check_for_delay(FALSE); | |
1660 if (win_ins_lines(wp, row + old_rows, | |
1661 xtra_rows, FALSE, FALSE) == FAIL) | |
1662 mod_bot = MAXLNUM; | |
1663 else if (top_end > row + old_rows) | |
1664 /* Scrolled the part at the top that requires | |
1665 * updating down. */ | |
1666 top_end += xtra_rows; | |
1667 } | |
1668 } | |
1669 | |
1670 /* When not updating the rest, may need to move w_lines[] | |
1671 * entries. */ | |
1672 if (mod_bot != MAXLNUM && i != j) | |
1673 { | |
1674 if (j < i) | |
1675 { | |
1676 int x = row + new_rows; | |
1677 | |
1678 /* move entries in w_lines[] upwards */ | |
1679 for (;;) | |
1680 { | |
1681 /* stop at last valid entry in w_lines[] */ | |
1682 if (i >= wp->w_lines_valid) | |
1683 { | |
1684 wp->w_lines_valid = j; | |
1685 break; | |
1686 } | |
1687 wp->w_lines[j] = wp->w_lines[i]; | |
1688 /* stop at a line that won't fit */ | |
1689 if (x + (int)wp->w_lines[j].wl_size | |
1690 > wp->w_height) | |
1691 { | |
1692 wp->w_lines_valid = j + 1; | |
1693 break; | |
1694 } | |
1695 x += wp->w_lines[j++].wl_size; | |
1696 ++i; | |
1697 } | |
1698 if (bot_start > x) | |
1699 bot_start = x; | |
1700 } | |
1701 else /* j > i */ | |
1702 { | |
1703 /* move entries in w_lines[] downwards */ | |
1704 j -= i; | |
1705 wp->w_lines_valid += j; | |
1706 if (wp->w_lines_valid > wp->w_height) | |
1707 wp->w_lines_valid = wp->w_height; | |
1708 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1709 wp->w_lines[i] = wp->w_lines[i - j]; | |
1710 | |
1711 /* The w_lines[] entries for inserted lines are | |
1712 * now invalid, but wl_size may be used above. | |
1713 * Reset to zero. */ | |
1714 while (i >= idx) | |
1715 { | |
1716 wp->w_lines[i].wl_size = 0; | |
1717 wp->w_lines[i--].wl_valid = FALSE; | |
1718 } | |
1719 } | |
1720 } | |
1721 } | |
1722 } | |
1723 | |
1724 #ifdef FEAT_FOLDING | |
1725 /* | |
1726 * When lines are folded, display one line for all of them. | |
1727 * Otherwise, display normally (can be several display lines when | |
1728 * 'wrap' is on). | |
1729 */ | |
1730 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1731 if (fold_count != 0) | |
1732 { | |
1733 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1734 ++row; | |
1735 --fold_count; | |
1736 wp->w_lines[idx].wl_folded = TRUE; | |
1737 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1738 # ifdef FEAT_SYN_HL | |
1739 did_update = DID_FOLD; | |
1740 # endif | |
1741 } | |
1742 else | |
1743 #endif | |
1744 if (idx < wp->w_lines_valid | |
1745 && wp->w_lines[idx].wl_valid | |
1746 && wp->w_lines[idx].wl_lnum == lnum | |
1747 && lnum > wp->w_topline | |
1748 && !(dy_flags & DY_LASTLINE) | |
1749 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1750 #ifdef FEAT_DIFF | |
1751 && diff_check_fill(wp, lnum) == 0 | |
1752 #endif | |
1753 ) | |
1754 { | |
1755 /* This line is not going to fit. Don't draw anything here, | |
1756 * will draw "@ " lines below. */ | |
1757 row = wp->w_height + 1; | |
1758 } | |
1759 else | |
1760 { | |
1761 #ifdef FEAT_SEARCH_EXTRA | |
1762 prepare_search_hl(wp, lnum); | |
1763 #endif | |
1764 #ifdef FEAT_SYN_HL | |
1765 /* Let the syntax stuff know we skipped a few lines. */ | |
1766 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum | |
1767 && syntax_present(buf)) | |
1768 syntax_end_parsing(syntax_last_parsed + 1); | |
1769 #endif | |
1770 | |
1771 /* | |
1772 * Display one line. | |
1773 */ | |
625 | 1774 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1775 |
1776 #ifdef FEAT_FOLDING | |
1777 wp->w_lines[idx].wl_folded = FALSE; | |
1778 wp->w_lines[idx].wl_lastlnum = lnum; | |
1779 #endif | |
1780 #ifdef FEAT_SYN_HL | |
1781 did_update = DID_LINE; | |
1782 syntax_last_parsed = lnum; | |
1783 #endif | |
1784 } | |
1785 | |
1786 wp->w_lines[idx].wl_lnum = lnum; | |
1787 wp->w_lines[idx].wl_valid = TRUE; | |
1788 if (row > wp->w_height) /* past end of screen */ | |
1789 { | |
1790 /* we may need the size of that too long line later on */ | |
1791 if (dollar_vcol == 0) | |
1792 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1793 ++idx; | |
1794 break; | |
1795 } | |
1796 if (dollar_vcol == 0) | |
1797 wp->w_lines[idx].wl_size = row - srow; | |
1798 ++idx; | |
1799 #ifdef FEAT_FOLDING | |
1800 lnum += fold_count + 1; | |
1801 #else | |
1802 ++lnum; | |
1803 #endif | |
1804 } | |
1805 else | |
1806 { | |
1807 /* This line does not need updating, advance to the next one */ | |
1808 row += wp->w_lines[idx++].wl_size; | |
1809 if (row > wp->w_height) /* past end of screen */ | |
1810 break; | |
1811 #ifdef FEAT_FOLDING | |
1812 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1813 #else | |
1814 ++lnum; | |
1815 #endif | |
1816 #ifdef FEAT_SYN_HL | |
1817 did_update = DID_NONE; | |
1818 #endif | |
1819 } | |
1820 | |
1821 if (lnum > buf->b_ml.ml_line_count) | |
1822 { | |
1823 eof = TRUE; | |
1824 break; | |
1825 } | |
1826 } | |
1827 /* | |
1828 * End of loop over all window lines. | |
1829 */ | |
1830 | |
1831 | |
1832 if (idx > wp->w_lines_valid) | |
1833 wp->w_lines_valid = idx; | |
1834 | |
1835 #ifdef FEAT_SYN_HL | |
1836 /* | |
1837 * Let the syntax stuff know we stop parsing here. | |
1838 */ | |
1839 if (syntax_last_parsed != 0 && syntax_present(buf)) | |
1840 syntax_end_parsing(syntax_last_parsed + 1); | |
1841 #endif | |
1842 | |
1843 /* | |
1844 * If we didn't hit the end of the file, and we didn't finish the last | |
1845 * line we were working on, then the line didn't fit. | |
1846 */ | |
1847 wp->w_empty_rows = 0; | |
1848 #ifdef FEAT_DIFF | |
1849 wp->w_filler_rows = 0; | |
1850 #endif | |
1851 if (!eof && !didline) | |
1852 { | |
1853 if (lnum == wp->w_topline) | |
1854 { | |
1855 /* | |
1856 * Single line that does not fit! | |
1857 * Don't overwrite it, it can be edited. | |
1858 */ | |
1859 wp->w_botline = lnum + 1; | |
1860 } | |
1861 #ifdef FEAT_DIFF | |
1862 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1863 { | |
1864 /* Window ends in filler lines. */ | |
1865 wp->w_botline = lnum; | |
1866 wp->w_filler_rows = wp->w_height - srow; | |
1867 } | |
1868 #endif | |
1869 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1870 { | |
1871 /* | |
1872 * Last line isn't finished: Display "@@@" at the end. | |
1873 */ | |
1874 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1875 W_WINROW(wp) + wp->w_height, | |
1876 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1877 '@', '@', hl_attr(HLF_AT)); | |
1878 set_empty_rows(wp, srow); | |
1879 wp->w_botline = lnum; | |
1880 } | |
1881 else | |
1882 { | |
1883 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1884 wp->w_botline = lnum; | |
1885 } | |
1886 } | |
1887 else | |
1888 { | |
1889 #ifdef FEAT_VERTSPLIT | |
1890 draw_vsep_win(wp, row); | |
1891 #endif | |
1892 if (eof) /* we hit the end of the file */ | |
1893 { | |
1894 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1895 #ifdef FEAT_DIFF | |
1896 j = diff_check_fill(wp, wp->w_botline); | |
1897 if (j > 0 && !wp->w_botfill) | |
1898 { | |
1899 /* | |
1900 * Display filler lines at the end of the file | |
1901 */ | |
1902 if (char2cells(fill_diff) > 1) | |
1903 i = '-'; | |
1904 else | |
1905 i = fill_diff; | |
1906 if (row + j > wp->w_height) | |
1907 j = wp->w_height - row; | |
1908 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1909 row += j; | |
1910 } | |
1911 #endif | |
1912 } | |
1913 else if (dollar_vcol == 0) | |
1914 wp->w_botline = lnum; | |
1915 | |
1916 /* make sure the rest of the screen is blank */ | |
1917 /* put '~'s on rows that aren't part of the file. */ | |
1918 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1919 } | |
1920 | |
1921 /* Reset the type of redrawing required, the window has been updated. */ | |
1922 wp->w_redr_type = 0; | |
1923 #ifdef FEAT_DIFF | |
1924 wp->w_old_topfill = wp->w_topfill; | |
1925 wp->w_old_botfill = wp->w_botfill; | |
1926 #endif | |
1927 | |
1928 if (dollar_vcol == 0) | |
1929 { | |
1930 /* | |
1931 * There is a trick with w_botline. If we invalidate it on each | |
1932 * change that might modify it, this will cause a lot of expensive | |
1933 * calls to plines() in update_topline() each time. Therefore the | |
1934 * value of w_botline is often approximated, and this value is used to | |
1935 * compute the value of w_topline. If the value of w_botline was | |
1936 * wrong, check that the value of w_topline is correct (cursor is on | |
1937 * the visible part of the text). If it's not, we need to redraw | |
1938 * again. Mostly this just means scrolling up a few lines, so it | |
1939 * doesn't look too bad. Only do this for the current window (where | |
1940 * changes are relevant). | |
1941 */ | |
1942 wp->w_valid |= VALID_BOTLINE; | |
1943 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
1944 { | |
1945 recursive = TRUE; | |
1946 curwin->w_valid &= ~VALID_TOPLINE; | |
1947 update_topline(); /* may invalidate w_botline again */ | |
1948 if (must_redraw != 0) | |
1949 { | |
1950 /* Don't update for changes in buffer again. */ | |
1951 i = curbuf->b_mod_set; | |
1952 curbuf->b_mod_set = FALSE; | |
1953 win_update(curwin); | |
1954 must_redraw = 0; | |
1955 curbuf->b_mod_set = i; | |
1956 } | |
1957 recursive = FALSE; | |
1958 } | |
1959 } | |
1960 | |
1961 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1962 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
1963 if (!got_int) | |
1964 got_int = save_got_int; | |
1965 #endif | |
1966 } | |
1967 | |
1968 #ifdef FEAT_SIGNS | |
1969 static int draw_signcolumn __ARGS((win_T *wp)); | |
1970 | |
1971 /* | |
1972 * Return TRUE when window "wp" has a column to draw signs in. | |
1973 */ | |
1974 static int | |
1975 draw_signcolumn(wp) | |
1976 win_T *wp; | |
1977 { | |
1978 return (wp->w_buffer->b_signlist != NULL | |
1979 # ifdef FEAT_NETBEANS_INTG | |
1980 || usingNetbeans | |
1981 # endif | |
1982 ); | |
1983 } | |
1984 #endif | |
1985 | |
1986 /* | |
1987 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
1988 * as the filler character. | |
1989 */ | |
1990 static void | |
1991 win_draw_end(wp, c1, c2, row, endrow, hl) | |
1992 win_T *wp; | |
1993 int c1; | |
1994 int c2; | |
1995 int row; | |
1996 int endrow; | |
534 | 1997 hlf_T hl; |
7 | 1998 { |
1999 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2000 int n = 0; | |
2001 # define FDC_OFF n | |
2002 #else | |
2003 # define FDC_OFF 0 | |
2004 #endif | |
2005 | |
2006 #ifdef FEAT_RIGHTLEFT | |
2007 if (wp->w_p_rl) | |
2008 { | |
2009 /* No check for cmdline window: should never be right-left. */ | |
2010 # ifdef FEAT_FOLDING | |
2011 n = wp->w_p_fdc; | |
2012 | |
2013 if (n > 0) | |
2014 { | |
2015 /* draw the fold column at the right */ | |
119 | 2016 if (n > W_WIDTH(wp)) |
2017 n = W_WIDTH(wp); | |
7 | 2018 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2019 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2020 ' ', ' ', hl_attr(HLF_FC)); | |
2021 } | |
2022 # endif | |
2023 # ifdef FEAT_SIGNS | |
2024 if (draw_signcolumn(wp)) | |
2025 { | |
2026 int nn = n + 2; | |
2027 | |
2028 /* draw the sign column left of the fold column */ | |
119 | 2029 if (nn > W_WIDTH(wp)) |
2030 nn = W_WIDTH(wp); | |
7 | 2031 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2032 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2033 ' ', ' ', hl_attr(HLF_SC)); | |
2034 n = nn; | |
2035 } | |
2036 # endif | |
2037 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2038 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2039 c2, c2, hl_attr(hl)); | |
2040 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2041 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2042 c1, c2, hl_attr(hl)); | |
2043 } | |
2044 else | |
2045 #endif | |
2046 { | |
2047 #ifdef FEAT_CMDWIN | |
2048 if (cmdwin_type != 0 && wp == curwin) | |
2049 { | |
2050 /* draw the cmdline character in the leftmost column */ | |
2051 n = 1; | |
2052 if (n > wp->w_width) | |
2053 n = wp->w_width; | |
2054 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2055 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2056 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2057 } | |
2058 #endif | |
2059 #ifdef FEAT_FOLDING | |
2060 if (wp->w_p_fdc > 0) | |
2061 { | |
2062 int nn = n + wp->w_p_fdc; | |
2063 | |
2064 /* draw the fold column at the left */ | |
2065 if (nn > W_WIDTH(wp)) | |
2066 nn = W_WIDTH(wp); | |
2067 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2068 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2069 ' ', ' ', hl_attr(HLF_FC)); | |
2070 n = nn; | |
2071 } | |
2072 #endif | |
2073 #ifdef FEAT_SIGNS | |
2074 if (draw_signcolumn(wp)) | |
2075 { | |
2076 int nn = n + 2; | |
2077 | |
2078 /* draw the sign column after the fold column */ | |
2079 if (nn > W_WIDTH(wp)) | |
2080 nn = W_WIDTH(wp); | |
2081 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2082 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2083 ' ', ' ', hl_attr(HLF_SC)); | |
2084 n = nn; | |
2085 } | |
2086 #endif | |
2087 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2088 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2089 c1, c2, hl_attr(hl)); | |
2090 } | |
2091 set_empty_rows(wp, row); | |
2092 } | |
2093 | |
2094 #ifdef FEAT_FOLDING | |
2095 /* | |
2096 * Display one folded line. | |
2097 */ | |
2098 static void | |
2099 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2100 win_T *wp; | |
2101 long fold_count; | |
2102 foldinfo_T *foldinfo; | |
2103 linenr_T lnum; | |
2104 int row; | |
2105 { | |
2106 char_u buf[51]; | |
2107 pos_T *top, *bot; | |
2108 linenr_T lnume = lnum + fold_count - 1; | |
2109 int len; | |
29 | 2110 char_u *text; |
7 | 2111 int fdc; |
2112 int col; | |
2113 int txtcol; | |
2114 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2115 int ri; |
7 | 2116 |
2117 /* Build the fold line: | |
2118 * 1. Add the cmdwin_type for the command-line window | |
2119 * 2. Add the 'foldcolumn' | |
2120 * 3. Add the 'number' column | |
2121 * 4. Compose the text | |
2122 * 5. Add the text | |
2123 * 6. set highlighting for the Visual area an other text | |
2124 */ | |
2125 col = 0; | |
2126 | |
2127 /* | |
2128 * 1. Add the cmdwin_type for the command-line window | |
2129 * Ignores 'rightleft', this window is never right-left. | |
2130 */ | |
2131 #ifdef FEAT_CMDWIN | |
2132 if (cmdwin_type != 0 && wp == curwin) | |
2133 { | |
2134 ScreenLines[off] = cmdwin_type; | |
2135 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2136 #ifdef FEAT_MBYTE | |
2137 if (enc_utf8) | |
2138 ScreenLinesUC[off] = 0; | |
2139 #endif | |
2140 ++col; | |
2141 } | |
2142 #endif | |
2143 | |
2144 /* | |
2145 * 2. Add the 'foldcolumn' | |
2146 */ | |
2147 fdc = wp->w_p_fdc; | |
2148 if (fdc > W_WIDTH(wp) - col) | |
2149 fdc = W_WIDTH(wp) - col; | |
2150 if (fdc > 0) | |
2151 { | |
2152 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2153 #ifdef FEAT_RIGHTLEFT | |
2154 if (wp->w_p_rl) | |
2155 { | |
2156 int i; | |
2157 | |
2158 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2159 hl_attr(HLF_FC)); | |
2160 /* reverse the fold column */ | |
2161 for (i = 0; i < fdc; ++i) | |
2162 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2163 } | |
2164 else | |
2165 #endif | |
2166 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2167 col += fdc; | |
2168 } | |
2169 | |
2170 #ifdef FEAT_RIGHTLEFT | |
216 | 2171 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2172 for (ri = 0; ri < l; ++ri) \ | |
2173 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2174 else \ | |
2175 for (ri = 0; ri < l; ++ri) \ | |
2176 ScreenAttrs[off + (p) + ri] = v | |
7 | 2177 #else |
216 | 2178 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2179 ScreenAttrs[off + (p) + ri] = v | |
7 | 2180 #endif |
2181 | |
2182 /* Set all attributes of the 'number' column and the text */ | |
216 | 2183 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2184 |
2185 #ifdef FEAT_SIGNS | |
2186 /* If signs are being displayed, add two spaces. */ | |
2187 if (draw_signcolumn(wp)) | |
2188 { | |
2189 len = W_WIDTH(wp) - col; | |
2190 if (len > 0) | |
2191 { | |
2192 if (len > 2) | |
2193 len = 2; | |
2194 # ifdef FEAT_RIGHTLEFT | |
2195 if (wp->w_p_rl) | |
2196 /* the line number isn't reversed */ | |
2197 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2198 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2199 else | |
2200 # endif | |
2201 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2202 col += len; | |
2203 } | |
2204 } | |
2205 #endif | |
2206 | |
2207 /* | |
2208 * 3. Add the 'number' column | |
2209 */ | |
2210 if (wp->w_p_nu) | |
2211 { | |
2212 len = W_WIDTH(wp) - col; | |
2213 if (len > 0) | |
2214 { | |
13 | 2215 int w = number_width(wp); |
2216 | |
2217 if (len > w + 1) | |
2218 len = w + 1; | |
2219 sprintf((char *)buf, "%*ld ", w, (long)lnum); | |
7 | 2220 #ifdef FEAT_RIGHTLEFT |
2221 if (wp->w_p_rl) | |
2222 /* the line number isn't reversed */ | |
2223 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2224 hl_attr(HLF_FL)); | |
2225 else | |
2226 #endif | |
2227 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2228 col += len; | |
2229 } | |
2230 } | |
2231 | |
2232 /* | |
2233 * 4. Compose the folded-line string with 'foldtext', if set. | |
2234 */ | |
29 | 2235 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2236 |
2237 txtcol = col; /* remember where text starts */ | |
2238 | |
2239 /* | |
2240 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2241 * Right-left text is put in columns 0 - number-col, normal text is put | |
2242 * in columns number-col - window-width. | |
2243 */ | |
2244 #ifdef FEAT_MBYTE | |
2245 if (has_mbyte) | |
2246 { | |
2247 int cells; | |
714 | 2248 int u8c, u8cc[MAX_MCO]; |
2249 int i; | |
7 | 2250 int idx; |
2251 int c_len; | |
33 | 2252 char_u *p; |
7 | 2253 # ifdef FEAT_ARABIC |
2254 int prev_c = 0; /* previous Arabic character */ | |
2255 int prev_c1 = 0; /* first composing char for prev_c */ | |
2256 # endif | |
2257 | |
2258 # ifdef FEAT_RIGHTLEFT | |
2259 if (wp->w_p_rl) | |
2260 idx = off; | |
2261 else | |
2262 # endif | |
2263 idx = off + col; | |
2264 | |
2265 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2266 for (p = text; *p != NUL; ) | |
2267 { | |
2268 cells = (*mb_ptr2cells)(p); | |
474 | 2269 c_len = (*mb_ptr2len)(p); |
7 | 2270 if (col + cells > W_WIDTH(wp) |
2271 # ifdef FEAT_RIGHTLEFT | |
2272 - (wp->w_p_rl ? col : 0) | |
2273 # endif | |
2274 ) | |
2275 break; | |
2276 ScreenLines[idx] = *p; | |
2277 if (enc_utf8) | |
2278 { | |
714 | 2279 u8c = utfc_ptr2char(p, u8cc); |
2280 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2281 { |
2282 ScreenLinesUC[idx] = 0; | |
2283 #ifdef FEAT_ARABIC | |
2284 prev_c = u8c; | |
2285 #endif | |
2286 } | |
2287 else | |
2288 { | |
2289 #ifdef FEAT_ARABIC | |
2290 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2291 { | |
2292 /* Do Arabic shaping. */ | |
714 | 2293 int pc, pc1, nc; |
2294 int pcc[MAX_MCO]; | |
7 | 2295 int firstbyte = *p; |
2296 | |
2297 /* The idea of what is the previous and next | |
2298 * character depends on 'rightleft'. */ | |
2299 if (wp->w_p_rl) | |
2300 { | |
2301 pc = prev_c; | |
2302 pc1 = prev_c1; | |
2303 nc = utf_ptr2char(p + c_len); | |
714 | 2304 prev_c1 = u8cc[0]; |
7 | 2305 } |
2306 else | |
2307 { | |
714 | 2308 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2309 nc = prev_c; |
714 | 2310 pc1 = pcc[0]; |
7 | 2311 } |
2312 prev_c = u8c; | |
2313 | |
714 | 2314 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2315 pc, pc1, nc); |
2316 ScreenLines[idx] = firstbyte; | |
2317 } | |
2318 else | |
2319 prev_c = u8c; | |
2320 #endif | |
2321 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2322 #ifdef UNICODE16 |
7 | 2323 if (u8c >= 0x10000) |
2324 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2325 else | |
1401 | 2326 #endif |
7 | 2327 ScreenLinesUC[idx] = u8c; |
714 | 2328 for (i = 0; i < Screen_mco; ++i) |
2329 { | |
2330 ScreenLinesC[i][idx] = u8cc[i]; | |
2331 if (u8cc[i] == 0) | |
2332 break; | |
2333 } | |
7 | 2334 } |
2335 if (cells > 1) | |
2336 ScreenLines[idx + 1] = 0; | |
2337 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2338 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2339 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2340 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2341 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2342 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2343 ScreenLines[idx + 1] = p[1]; |
7 | 2344 col += cells; |
2345 idx += cells; | |
2346 p += c_len; | |
2347 } | |
2348 } | |
2349 else | |
2350 #endif | |
2351 { | |
2352 len = (int)STRLEN(text); | |
2353 if (len > W_WIDTH(wp) - col) | |
2354 len = W_WIDTH(wp) - col; | |
2355 if (len > 0) | |
2356 { | |
2357 #ifdef FEAT_RIGHTLEFT | |
2358 if (wp->w_p_rl) | |
2359 STRNCPY(current_ScreenLine, text, len); | |
2360 else | |
2361 #endif | |
2362 STRNCPY(current_ScreenLine + col, text, len); | |
2363 col += len; | |
2364 } | |
2365 } | |
2366 | |
2367 /* Fill the rest of the line with the fold filler */ | |
2368 #ifdef FEAT_RIGHTLEFT | |
2369 if (wp->w_p_rl) | |
2370 col -= txtcol; | |
2371 #endif | |
2372 while (col < W_WIDTH(wp) | |
2373 #ifdef FEAT_RIGHTLEFT | |
2374 - (wp->w_p_rl ? txtcol : 0) | |
2375 #endif | |
2376 ) | |
2377 { | |
2378 #ifdef FEAT_MBYTE | |
2379 if (enc_utf8) | |
2380 { | |
2381 if (fill_fold >= 0x80) | |
2382 { | |
2383 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2384 ScreenLinesC[0][off + col] = 0; |
7 | 2385 } |
2386 else | |
2387 ScreenLinesUC[off + col] = 0; | |
2388 } | |
2389 #endif | |
2390 ScreenLines[off + col++] = fill_fold; | |
2391 } | |
2392 | |
2393 if (text != buf) | |
2394 vim_free(text); | |
2395 | |
2396 /* | |
2397 * 6. set highlighting for the Visual area an other text. | |
2398 * If all folded lines are in the Visual area, highlight the line. | |
2399 */ | |
2400 #ifdef FEAT_VISUAL | |
2401 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2402 { | |
2403 if (ltoreq(curwin->w_cursor, VIsual)) | |
2404 { | |
2405 /* Visual is after curwin->w_cursor */ | |
2406 top = &curwin->w_cursor; | |
2407 bot = &VIsual; | |
2408 } | |
2409 else | |
2410 { | |
2411 /* Visual is before curwin->w_cursor */ | |
2412 top = &VIsual; | |
2413 bot = &curwin->w_cursor; | |
2414 } | |
2415 if (lnum >= top->lnum | |
2416 && lnume <= bot->lnum | |
2417 && (VIsual_mode != 'v' | |
2418 || ((lnum > top->lnum | |
2419 || (lnum == top->lnum | |
2420 && top->col == 0)) | |
2421 && (lnume < bot->lnum | |
2422 || (lnume == bot->lnum | |
2423 && (bot->col - (*p_sel == 'e')) | |
1883 | 2424 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2425 { |
2426 if (VIsual_mode == Ctrl_V) | |
2427 { | |
2428 /* Visual block mode: highlight the chars part of the block */ | |
2429 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2430 { | |
2431 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2432 len = wp->w_old_cursor_lcol; | |
2433 else | |
2434 len = W_WIDTH(wp) - txtcol; | |
2435 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2436 len - (int)wp->w_old_cursor_fcol); |
7 | 2437 } |
2438 } | |
2439 else | |
216 | 2440 { |
7 | 2441 /* Set all attributes of the text */ |
216 | 2442 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2443 } | |
7 | 2444 } |
2445 } | |
2446 #endif | |
2447 | |
743 | 2448 #ifdef FEAT_SYN_HL |
2449 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2450 if (wp->w_p_cuc) |
2451 { | |
2452 txtcol += wp->w_virtcol; | |
2453 if (wp->w_p_wrap) | |
2454 txtcol -= wp->w_skipcol; | |
2455 else | |
2456 txtcol -= wp->w_leftcol; | |
2457 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2458 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2459 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2460 } | |
743 | 2461 #endif |
7 | 2462 |
2463 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2464 (int)W_WIDTH(wp), FALSE); | |
2465 | |
2466 /* | |
2467 * Update w_cline_height and w_cline_folded if the cursor line was | |
2468 * updated (saves a call to plines() later). | |
2469 */ | |
2470 if (wp == curwin | |
2471 && lnum <= curwin->w_cursor.lnum | |
2472 && lnume >= curwin->w_cursor.lnum) | |
2473 { | |
2474 curwin->w_cline_row = row; | |
2475 curwin->w_cline_height = 1; | |
2476 curwin->w_cline_folded = TRUE; | |
2477 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2478 } | |
2479 } | |
2480 | |
2481 /* | |
2482 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2483 */ | |
2484 static void | |
2485 copy_text_attr(off, buf, len, attr) | |
2486 int off; | |
2487 char_u *buf; | |
2488 int len; | |
2489 int attr; | |
2490 { | |
216 | 2491 int i; |
2492 | |
7 | 2493 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2494 # ifdef FEAT_MBYTE | |
2495 if (enc_utf8) | |
2496 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2497 # endif | |
216 | 2498 for (i = 0; i < len; ++i) |
2499 ScreenAttrs[off + i] = attr; | |
7 | 2500 } |
2501 | |
2502 /* | |
2503 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2504 * Only to be called when 'foldcolumn' > 0. |
7 | 2505 */ |
2506 static void | |
2507 fill_foldcolumn(p, wp, closed, lnum) | |
2508 char_u *p; | |
2509 win_T *wp; | |
2510 int closed; /* TRUE of FALSE */ | |
2511 linenr_T lnum; /* current line number */ | |
2512 { | |
2513 int i = 0; | |
2514 int level; | |
2515 int first_level; | |
519 | 2516 int empty; |
7 | 2517 |
2518 /* Init to all spaces. */ | |
2519 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2520 | |
2521 level = win_foldinfo.fi_level; | |
2522 if (level > 0) | |
2523 { | |
519 | 2524 /* If there is only one column put more info in it. */ |
2525 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2526 | |
7 | 2527 /* If the column is too narrow, we start at the lowest level that |
2528 * fits and use numbers to indicated the depth. */ | |
519 | 2529 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2530 if (first_level < 1) |
2531 first_level = 1; | |
2532 | |
519 | 2533 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2534 { |
2535 if (win_foldinfo.fi_lnum == lnum | |
2536 && first_level + i >= win_foldinfo.fi_low_level) | |
2537 p[i] = '-'; | |
2538 else if (first_level == 1) | |
2539 p[i] = '|'; | |
2540 else if (first_level + i <= 9) | |
2541 p[i] = '0' + first_level + i; | |
2542 else | |
2543 p[i] = '>'; | |
2544 if (first_level + i == level) | |
2545 break; | |
2546 } | |
2547 } | |
2548 if (closed) | |
548 | 2549 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2550 } |
2551 #endif /* FEAT_FOLDING */ | |
2552 | |
2553 /* | |
2554 * Display line "lnum" of window 'wp' on the screen. | |
2555 * Start at row "startrow", stop when "endrow" is reached. | |
2556 * wp->w_virtcol needs to be valid. | |
2557 * | |
2558 * Return the number of last row the line occupies. | |
2559 */ | |
2560 static int | |
625 | 2561 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2562 win_T *wp; |
2563 linenr_T lnum; | |
2564 int startrow; | |
2565 int endrow; | |
1883 | 2566 int nochange UNUSED; /* not updating for changed text */ |
7 | 2567 { |
2568 int col; /* visual column on screen */ | |
2569 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2570 int c = 0; /* init for GCC */ | |
2571 long vcol = 0; /* virtual column (for tabs) */ | |
2572 long vcol_prev = -1; /* "vcol" of previous character */ | |
2573 char_u *line; /* current line */ | |
2574 char_u *ptr; /* current position in "line" */ | |
2575 int row; /* row in the window, excl w_winrow */ | |
2576 int screen_row; /* row on the screen, incl w_winrow */ | |
2577 | |
2578 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2579 int n_extra = 0; /* number of extra chars */ | |
1340 | 2580 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2581 int c_extra = NUL; /* extra chars, all the same */ |
2582 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2583 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2584 displaying lcs_eol at end-of-line */ | |
2585 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2586 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2587 | |
2588 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2589 int saved_n_extra = 0; | |
2590 char_u *saved_p_extra = NULL; | |
2591 int saved_c_extra = 0; | |
2592 int saved_char_attr = 0; | |
2593 | |
2594 int n_attr = 0; /* chars with special attr */ | |
2595 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2596 int n_attr3 = 0; /* chars with overruling special attr */ | |
2597 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2598 | |
2599 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2600 | |
2601 int fromcol, tocol; /* start/end of inverting */ | |
2602 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2603 int noinvcur = FALSE; /* don't invert the cursor */ | |
2604 #ifdef FEAT_VISUAL | |
2605 pos_T *top, *bot; | |
1813 | 2606 int lnum_in_visual_area = FALSE; |
7 | 2607 #endif |
2608 pos_T pos; | |
2609 long v; | |
2610 | |
2611 int char_attr = 0; /* attributes for next character */ | |
674 | 2612 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2613 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2614 in this line */ | |
2615 int attr = 0; /* attributes for area highlighting */ | |
2616 int area_attr = 0; /* attributes desired by highlighting */ | |
2617 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2618 #ifdef FEAT_SYN_HL | |
743 | 2619 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2620 int syntax_attr = 0; /* attributes desired by syntax */ |
2621 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2622 int save_did_emsg; | |
1437 | 2623 int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
743 | 2624 #endif |
2625 #ifdef FEAT_SPELL | |
221 | 2626 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2627 # define SPWORDLEN 150 |
2628 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2629 int nextlinecol = 0; /* column where nextline[] starts */ |
2630 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2631 starts */ |
221 | 2632 int spell_attr = 0; /* attributes desired by spelling */ |
2633 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2634 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2635 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2636 * there are no spell errors */ |
386 | 2637 static int cap_col = -1; /* column to check for Cap word */ |
2638 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2639 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2640 #endif |
2641 int extra_check; /* has syntax or linebreak */ | |
2642 #ifdef FEAT_MBYTE | |
2643 int multi_attr = 0; /* attributes desired by multibyte */ | |
2644 int mb_l = 1; /* multi-byte byte length */ | |
2645 int mb_c = 0; /* decoded multi-byte character */ | |
2646 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2647 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2648 #endif |
2649 #ifdef FEAT_DIFF | |
2650 int filler_lines; /* nr of filler lines to be drawn */ | |
2651 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2652 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2653 int change_start = MAXCOL; /* first col of changed area */ |
2654 int change_end = -1; /* last col of changed area */ | |
2655 #endif | |
2656 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2657 #ifdef FEAT_LINEBREAK | |
2658 int need_showbreak = FALSE; | |
2659 #endif | |
910 | 2660 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2661 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2662 # define LINE_ATTR |
1536 | 2663 int line_attr = 0; /* attribute for the whole line */ |
7 | 2664 #endif |
2665 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2666 matchitem_T *cur; /* points to the match list */ |
2667 match_T *shl; /* points to search_hl or a match */ | |
2668 int shl_flag; /* flag to indicate whether search_hl | |
2669 has been processed or not */ | |
2670 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2671 equals startcol of search_hl or one | |
2672 of the matches */ | |
7 | 2673 #endif |
2674 #ifdef FEAT_ARABIC | |
2675 int prev_c = 0; /* previous Arabic character */ | |
2676 int prev_c1 = 0; /* first composing char for prev_c */ | |
2677 #endif | |
910 | 2678 #if defined(LINE_ATTR) |
867 | 2679 int did_line_attr = 0; |
2680 #endif | |
7 | 2681 |
2682 /* draw_state: items that are drawn in sequence: */ | |
2683 #define WL_START 0 /* nothing done yet */ | |
2684 #ifdef FEAT_CMDWIN | |
2685 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2686 #else | |
2687 # define WL_CMDLINE WL_START | |
2688 #endif | |
2689 #ifdef FEAT_FOLDING | |
2690 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2691 #else | |
2692 # define WL_FOLD WL_CMDLINE | |
2693 #endif | |
2694 #ifdef FEAT_SIGNS | |
2695 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2696 #else | |
2697 # define WL_SIGN WL_FOLD /* column for signs */ | |
2698 #endif | |
2699 #define WL_NR WL_SIGN + 1 /* line number */ | |
2700 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2701 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2702 #else | |
2703 # define WL_SBR WL_NR | |
2704 #endif | |
2705 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2706 int draw_state = WL_START; /* what to draw next */ | |
574 | 2707 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2708 int feedback_col = 0; |
2709 int feedback_old_attr = -1; | |
2710 #endif | |
2711 | |
2712 | |
2713 if (startrow > endrow) /* past the end already! */ | |
2714 return startrow; | |
2715 | |
2716 row = startrow; | |
2717 screen_row = row + W_WINROW(wp); | |
2718 | |
2719 /* | |
2720 * To speed up the loop below, set extra_check when there is linebreak, | |
2721 * trailing white space and/or syntax processing to be done. | |
2722 */ | |
2723 #ifdef FEAT_LINEBREAK | |
2724 extra_check = wp->w_p_lbr; | |
2725 #else | |
2726 extra_check = 0; | |
2727 #endif | |
2728 #ifdef FEAT_SYN_HL | |
482 | 2729 if (syntax_present(wp->w_buffer) && !wp->w_buffer->b_syn_error) |
7 | 2730 { |
2731 /* Prepare for syntax highlighting in this line. When there is an | |
2732 * error, stop syntax highlighting. */ | |
2733 save_did_emsg = did_emsg; | |
2734 did_emsg = FALSE; | |
2735 syntax_start(wp, lnum); | |
2736 if (did_emsg) | |
482 | 2737 wp->w_buffer->b_syn_error = TRUE; |
7 | 2738 else |
2739 { | |
2740 did_emsg = save_did_emsg; | |
2741 has_syntax = TRUE; | |
2742 extra_check = TRUE; | |
2743 } | |
2744 } | |
743 | 2745 #endif |
2746 | |
2747 #ifdef FEAT_SPELL | |
258 | 2748 if (wp->w_p_spell |
2749 && *wp->w_buffer->b_p_spl != NUL | |
2750 && wp->w_buffer->b_langp.ga_len > 0 | |
2751 && *(char **)(wp->w_buffer->b_langp.ga_data) != NULL) | |
221 | 2752 { |
2753 /* Prepare for spell checking. */ | |
2754 has_spell = TRUE; | |
2755 extra_check = TRUE; | |
348 | 2756 |
2757 /* Get the start of the next line, so that words that wrap to the next | |
2758 * line are found too: "et<line-break>al.". | |
2759 * Trick: skip a few chars for C/shell/Vim comments */ | |
2760 nextline[SPWORDLEN] = NUL; | |
2761 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2762 { | |
2763 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2764 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2765 } | |
2766 | |
2767 /* When a word wrapped from the previous line the start of the current | |
2768 * line is valid. */ | |
2769 if (lnum == checked_lnum) | |
2770 cur_checked_col = checked_col; | |
2771 checked_lnum = 0; | |
386 | 2772 |
2773 /* When there was a sentence end in the previous line may require a | |
2774 * word starting with capital in this line. In line 1 always check | |
2775 * the first word. */ | |
2776 if (lnum != capcol_lnum) | |
2777 cap_col = -1; | |
2778 if (lnum == 1) | |
2779 cap_col = 0; | |
2780 capcol_lnum = 0; | |
221 | 2781 } |
7 | 2782 #endif |
2783 | |
2784 /* | |
2785 * handle visual active in this window | |
2786 */ | |
2787 fromcol = -10; | |
2788 tocol = MAXCOL; | |
2789 #ifdef FEAT_VISUAL | |
2790 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2791 { | |
2792 /* Visual is after curwin->w_cursor */ | |
2793 if (ltoreq(curwin->w_cursor, VIsual)) | |
2794 { | |
2795 top = &curwin->w_cursor; | |
2796 bot = &VIsual; | |
2797 } | |
2798 else /* Visual is before curwin->w_cursor */ | |
2799 { | |
2800 top = &VIsual; | |
2801 bot = &curwin->w_cursor; | |
2802 } | |
1813 | 2803 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2804 if (VIsual_mode == Ctrl_V) /* block mode */ |
2805 { | |
1813 | 2806 if (lnum_in_visual_area) |
7 | 2807 { |
2808 fromcol = wp->w_old_cursor_fcol; | |
2809 tocol = wp->w_old_cursor_lcol; | |
2810 } | |
2811 } | |
2812 else /* non-block mode */ | |
2813 { | |
2814 if (lnum > top->lnum && lnum <= bot->lnum) | |
2815 fromcol = 0; | |
2816 else if (lnum == top->lnum) | |
2817 { | |
2818 if (VIsual_mode == 'V') /* linewise */ | |
2819 fromcol = 0; | |
2820 else | |
2821 { | |
2822 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2823 if (gchar_pos(top) == NUL) | |
2824 tocol = fromcol + 1; | |
2825 } | |
2826 } | |
2827 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2828 { | |
2829 if (*p_sel == 'e' && bot->col == 0 | |
2830 #ifdef FEAT_VIRTUALEDIT | |
2831 && bot->coladd == 0 | |
2832 #endif | |
2833 ) | |
2834 { | |
2835 fromcol = -10; | |
2836 tocol = MAXCOL; | |
2837 } | |
36 | 2838 else if (bot->col == MAXCOL) |
2839 tocol = MAXCOL; | |
7 | 2840 else |
2841 { | |
2842 pos = *bot; | |
2843 if (*p_sel == 'e') | |
2844 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2845 else | |
2846 { | |
2847 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2848 ++tocol; | |
2849 } | |
2850 } | |
2851 } | |
2852 } | |
2853 | |
2854 #ifndef MSDOS | |
2855 /* Check if the character under the cursor should not be inverted */ | |
2856 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2857 # ifdef FEAT_GUI | |
2858 && !gui.in_use | |
2859 # endif | |
2860 ) | |
2861 noinvcur = TRUE; | |
2862 #endif | |
2863 | |
2864 /* if inverting in this line set area_highlighting */ | |
2865 if (fromcol >= 0) | |
2866 { | |
2867 area_highlighting = TRUE; | |
2868 attr = hl_attr(HLF_V); | |
2869 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2870 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2871 attr = hl_attr(HLF_VNC); | |
2872 #endif | |
2873 } | |
2874 } | |
2875 | |
2876 /* | |
674 | 2877 * handle 'incsearch' and ":s///c" highlighting |
7 | 2878 */ |
2879 else | |
2880 #endif /* FEAT_VISUAL */ | |
2881 if (highlight_match | |
2882 && wp == curwin | |
2883 && lnum >= curwin->w_cursor.lnum | |
2884 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
2885 { | |
2886 if (lnum == curwin->w_cursor.lnum) | |
2887 getvcol(curwin, &(curwin->w_cursor), | |
2888 (colnr_T *)&fromcol, NULL, NULL); | |
2889 else | |
2890 fromcol = 0; | |
2891 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
2892 { | |
2893 pos.lnum = lnum; | |
2894 pos.col = search_match_endcol; | |
2895 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2896 } | |
2897 else | |
2898 tocol = MAXCOL; | |
1850 | 2899 /* do at least one character; happens when past end of line */ |
2900 if (fromcol == tocol) | |
2901 tocol = fromcol + 1; | |
7 | 2902 area_highlighting = TRUE; |
2903 attr = hl_attr(HLF_I); | |
2904 } | |
2905 | |
2906 #ifdef FEAT_DIFF | |
2907 filler_lines = diff_check(wp, lnum); | |
2908 if (filler_lines < 0) | |
2909 { | |
2910 if (filler_lines == -1) | |
2911 { | |
2912 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
2913 diff_hlf = HLF_ADD; /* added line */ | |
2914 else if (change_start == 0) | |
2915 diff_hlf = HLF_TXD; /* changed text */ | |
2916 else | |
2917 diff_hlf = HLF_CHD; /* changed line */ | |
2918 } | |
2919 else | |
2920 diff_hlf = HLF_ADD; /* added line */ | |
2921 filler_lines = 0; | |
2922 area_highlighting = TRUE; | |
2923 } | |
2924 if (lnum == wp->w_topline) | |
2925 filler_lines = wp->w_topfill; | |
2926 filler_todo = filler_lines; | |
2927 #endif | |
2928 | |
2929 #ifdef LINE_ATTR | |
2930 # ifdef FEAT_SIGNS | |
2931 /* If this line has a sign with line highlighting set line_attr. */ | |
2932 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
2933 if (v != 0) | |
2934 line_attr = sign_get_attr((int)v, TRUE); | |
2935 # endif | |
2936 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
2937 /* Highlight the current line in the quickfix window. */ | |
644 | 2938 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 2939 line_attr = hl_attr(HLF_L); |
2940 # endif | |
2941 if (line_attr != 0) | |
2942 area_highlighting = TRUE; | |
2943 #endif | |
2944 | |
2945 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
2946 ptr = line; | |
2947 | |
743 | 2948 #ifdef FEAT_SPELL |
348 | 2949 if (has_spell) |
2950 { | |
386 | 2951 /* For checking first word with a capital skip white space. */ |
2952 if (cap_col == 0) | |
835 | 2953 cap_col = (int)(skipwhite(line) - line); |
386 | 2954 |
348 | 2955 /* To be able to spell-check over line boundaries copy the end of the |
2956 * current line into nextline[]. Above the start of the next line was | |
2957 * copied to nextline[SPWORDLEN]. */ | |
2958 if (nextline[SPWORDLEN] == NUL) | |
2959 { | |
2960 /* No next line or it is empty. */ | |
2961 nextlinecol = MAXCOL; | |
2962 nextline_idx = 0; | |
2963 } | |
2964 else | |
2965 { | |
835 | 2966 v = (long)STRLEN(line); |
348 | 2967 if (v < SPWORDLEN) |
2968 { | |
2969 /* Short line, use it completely and append the start of the | |
2970 * next line. */ | |
2971 nextlinecol = 0; | |
2972 mch_memmove(nextline, line, (size_t)v); | |
1621 | 2973 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 2974 nextline_idx = v + 1; |
2975 } | |
2976 else | |
2977 { | |
2978 /* Long line, use only the last SPWORDLEN bytes. */ | |
2979 nextlinecol = v - SPWORDLEN; | |
2980 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
2981 nextline_idx = SPWORDLEN + 1; | |
2982 } | |
2983 } | |
2984 } | |
2985 #endif | |
2986 | |
7 | 2987 /* find start of trailing whitespace */ |
2988 if (wp->w_p_list && lcs_trail) | |
2989 { | |
2990 trailcol = (colnr_T)STRLEN(ptr); | |
2991 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
2992 --trailcol; | |
2993 trailcol += (colnr_T) (ptr - line); | |
2994 extra_check = TRUE; | |
2995 } | |
2996 | |
2997 /* | |
2998 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
2999 * first character to be displayed. | |
3000 */ | |
3001 if (wp->w_p_wrap) | |
3002 v = wp->w_skipcol; | |
3003 else | |
3004 v = wp->w_leftcol; | |
3005 if (v > 0) | |
3006 { | |
3007 #ifdef FEAT_MBYTE | |
3008 char_u *prev_ptr = ptr; | |
3009 #endif | |
3010 while (vcol < v && *ptr != NUL) | |
3011 { | |
3012 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3013 vcol += c; | |
3014 #ifdef FEAT_MBYTE | |
3015 prev_ptr = ptr; | |
39 | 3016 #endif |
3017 mb_ptr_adv(ptr); | |
7 | 3018 } |
3019 | |
1984 | 3020 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3021 /* When: | |
3022 * - 'cuc' is set, or | |
3023 * - 'virtualedit' is set, or | |
3024 * - the visual mode is active, | |
3025 * the end of the line may be before the start of the displayed part. | |
3026 */ | |
3027 if (vcol < v && ( | |
3028 # ifdef FEAT_SYN_HL | |
3029 wp->w_p_cuc | |
3030 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) | |
3031 || | |
3032 # endif | |
3033 # endif | |
3034 # ifdef FEAT_VIRTUALEDIT | |
3035 virtual_active() | |
3036 # ifdef FEAT_VISUAL | |
3037 || | |
3038 # endif | |
3039 # endif | |
3040 # ifdef FEAT_VISUAL | |
3041 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3042 # endif | |
3043 )) | |
3044 { | |
7 | 3045 vcol = v; |
1984 | 3046 } |
7 | 3047 #endif |
3048 | |
3049 /* Handle a character that's not completely on the screen: Put ptr at | |
3050 * that character but skip the first few screen characters. */ | |
3051 if (vcol > v) | |
3052 { | |
3053 vcol -= c; | |
3054 #ifdef FEAT_MBYTE | |
3055 ptr = prev_ptr; | |
3056 #else | |
3057 --ptr; | |
3058 #endif | |
3059 n_skip = v - vcol; | |
3060 } | |
3061 | |
3062 /* | |
3063 * Adjust for when the inverted text is before the screen, | |
3064 * and when the start of the inverted text is before the screen. | |
3065 */ | |
3066 if (tocol <= vcol) | |
3067 fromcol = 0; | |
3068 else if (fromcol >= 0 && fromcol < vcol) | |
3069 fromcol = vcol; | |
3070 | |
3071 #ifdef FEAT_LINEBREAK | |
3072 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3073 if (wp->w_p_wrap) | |
3074 need_showbreak = TRUE; | |
3075 #endif | |
743 | 3076 #ifdef FEAT_SPELL |
499 | 3077 /* When spell checking a word we need to figure out the start of the |
3078 * word and if it's badly spelled or not. */ | |
3079 if (has_spell) | |
3080 { | |
3081 int len; | |
1536 | 3082 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3083 hlf_T spell_hlf = HLF_COUNT; |
499 | 3084 |
3085 pos = wp->w_cursor; | |
3086 wp->w_cursor.lnum = lnum; | |
1536 | 3087 wp->w_cursor.col = linecol; |
534 | 3088 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3089 |
3090 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3091 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3092 ptr = line + linecol; | |
3093 | |
530 | 3094 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3095 { |
3096 /* no bad word found at line start, don't check until end of a | |
3097 * word */ | |
534 | 3098 spell_hlf = HLF_COUNT; |
1536 | 3099 word_end = (int)(spell_to_word_end(ptr, wp->w_buffer) |
3100 - line + 1); | |
499 | 3101 } |
3102 else | |
534 | 3103 { |
499 | 3104 /* bad word found, use attributes until end of word */ |
3105 word_end = wp->w_cursor.col + len + 1; | |
3106 | |
534 | 3107 /* Turn index into actual attributes. */ |
3108 if (spell_hlf != HLF_COUNT) | |
3109 spell_attr = highlight_attr[spell_hlf]; | |
3110 } | |
499 | 3111 wp->w_cursor = pos; |
501 | 3112 |
743 | 3113 # ifdef FEAT_SYN_HL |
501 | 3114 /* Need to restart syntax highlighting for this line. */ |
3115 if (has_syntax) | |
3116 syntax_start(wp, lnum); | |
743 | 3117 # endif |
499 | 3118 } |
3119 #endif | |
7 | 3120 } |
3121 | |
3122 /* | |
3123 * Correct highlighting for cursor that can't be disabled. | |
3124 * Avoids having to check this for each character. | |
3125 */ | |
3126 if (fromcol >= 0) | |
3127 { | |
3128 if (noinvcur) | |
3129 { | |
3130 if ((colnr_T)fromcol == wp->w_virtcol) | |
3131 { | |
3132 /* highlighting starts at cursor, let it start just after the | |
3133 * cursor */ | |
3134 fromcol_prev = fromcol; | |
3135 fromcol = -1; | |
3136 } | |
3137 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3138 /* restart highlighting after the cursor */ | |
3139 fromcol_prev = wp->w_virtcol; | |
3140 } | |
3141 if (fromcol >= tocol) | |
3142 fromcol = -1; | |
3143 } | |
3144 | |
3145 #ifdef FEAT_SEARCH_EXTRA | |
3146 /* | |
1326 | 3147 * Handle highlighting the last used search pattern and matches. |
3148 * Do this for both search_hl and the match list. | |
7 | 3149 */ |
1326 | 3150 cur = wp->w_match_head; |
3151 shl_flag = FALSE; | |
3152 while (cur != NULL || shl_flag == FALSE) | |
3153 { | |
3154 if (shl_flag == FALSE) | |
3155 { | |
3156 shl = &search_hl; | |
3157 shl_flag = TRUE; | |
3158 } | |
3159 else | |
3160 shl = &cur->hl; | |
36 | 3161 shl->startcol = MAXCOL; |
3162 shl->endcol = MAXCOL; | |
7 | 3163 shl->attr_cur = 0; |
3164 if (shl->rm.regprog != NULL) | |
3165 { | |
3166 v = (long)(ptr - line); | |
3167 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3168 | |
3169 /* Need to get the line again, a multi-line regexp may have made it | |
3170 * invalid. */ | |
3171 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3172 ptr = line + v; | |
3173 | |
3174 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3175 { | |
3176 if (shl->lnum == lnum) | |
36 | 3177 shl->startcol = shl->rm.startpos[0].col; |
7 | 3178 else |
36 | 3179 shl->startcol = 0; |
7 | 3180 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3181 - shl->rm.startpos[0].lnum) | |
36 | 3182 shl->endcol = shl->rm.endpos[0].col; |
7 | 3183 else |
36 | 3184 shl->endcol = MAXCOL; |
7 | 3185 /* Highlight one character for an empty match. */ |
36 | 3186 if (shl->startcol == shl->endcol) |
7 | 3187 { |
3188 #ifdef FEAT_MBYTE | |
36 | 3189 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3190 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3191 else |
3192 #endif | |
36 | 3193 ++shl->endcol; |
7 | 3194 } |
36 | 3195 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3196 { |
3197 shl->attr_cur = shl->attr; | |
3198 search_attr = shl->attr; | |
3199 } | |
3200 area_highlighting = TRUE; | |
3201 } | |
3202 } | |
1326 | 3203 if (shl != &search_hl && cur != NULL) |
3204 cur = cur->next; | |
7 | 3205 } |
3206 #endif | |
3207 | |
743 | 3208 #ifdef FEAT_SYN_HL |
818 | 3209 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3210 * active, because it's not clear what is selected then. */ | |
3211 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3212 { |
3213 line_attr = hl_attr(HLF_CUL); | |
3214 area_highlighting = TRUE; | |
3215 } | |
3216 #endif | |
3217 | |
504 | 3218 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3219 col = 0; |
3220 #ifdef FEAT_RIGHTLEFT | |
3221 if (wp->w_p_rl) | |
3222 { | |
3223 /* Rightleft window: process the text in the normal direction, but put | |
3224 * it in current_ScreenLine[] from right to left. Start at the | |
3225 * rightmost column of the window. */ | |
3226 col = W_WIDTH(wp) - 1; | |
3227 off += col; | |
3228 } | |
3229 #endif | |
3230 | |
3231 /* | |
3232 * Repeat for the whole displayed line. | |
3233 */ | |
3234 for (;;) | |
3235 { | |
3236 /* Skip this quickly when working on the text. */ | |
3237 if (draw_state != WL_LINE) | |
3238 { | |
3239 #ifdef FEAT_CMDWIN | |
3240 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3241 { | |
3242 draw_state = WL_CMDLINE; | |
3243 if (cmdwin_type != 0 && wp == curwin) | |
3244 { | |
3245 /* Draw the cmdline character. */ | |
3246 n_extra = 1; | |
1340 | 3247 c_extra = cmdwin_type; |
7 | 3248 char_attr = hl_attr(HLF_AT); |
3249 } | |
3250 } | |
3251 #endif | |
3252 | |
3253 #ifdef FEAT_FOLDING | |
3254 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3255 { | |
3256 draw_state = WL_FOLD; | |
3257 if (wp->w_p_fdc > 0) | |
3258 { | |
3259 /* Draw the 'foldcolumn'. */ | |
3260 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3261 n_extra = wp->w_p_fdc; | |
3262 p_extra = extra; | |
1340 | 3263 p_extra[n_extra] = NUL; |
7 | 3264 c_extra = NUL; |
3265 char_attr = hl_attr(HLF_FC); | |
3266 } | |
3267 } | |
3268 #endif | |
3269 | |
3270 #ifdef FEAT_SIGNS | |
3271 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3272 { | |
3273 draw_state = WL_SIGN; | |
3274 /* Show the sign column when there are any signs in this | |
3275 * buffer or when using Netbeans. */ | |
3276 if (draw_signcolumn(wp) | |
3277 # ifdef FEAT_DIFF | |
3278 && filler_todo <= 0 | |
3279 # endif | |
3280 ) | |
3281 { | |
3282 int_u text_sign; | |
3283 # ifdef FEAT_SIGN_ICONS | |
3284 int_u icon_sign; | |
3285 # endif | |
3286 | |
3287 /* Draw two cells with the sign value or blank. */ | |
3288 c_extra = ' '; | |
3289 char_attr = hl_attr(HLF_SC); | |
3290 n_extra = 2; | |
3291 | |
3292 if (row == startrow) | |
3293 { | |
3294 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3295 SIGN_TEXT); | |
3296 # ifdef FEAT_SIGN_ICONS | |
3297 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3298 SIGN_ICON); | |
3299 if (gui.in_use && icon_sign != 0) | |
3300 { | |
3301 /* Use the image in this position. */ | |
3302 c_extra = SIGN_BYTE; | |
3303 # ifdef FEAT_NETBEANS_INTG | |
3304 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3305 c_extra = MULTISIGN_BYTE; | |
3306 # endif | |
3307 char_attr = icon_sign; | |
3308 } | |
3309 else | |
3310 # endif | |
3311 if (text_sign != 0) | |
3312 { | |
3313 p_extra = sign_get_text(text_sign); | |
3314 if (p_extra != NULL) | |
3315 { | |
3316 c_extra = NUL; | |
835 | 3317 n_extra = (int)STRLEN(p_extra); |
7 | 3318 } |
3319 char_attr = sign_get_attr(text_sign, FALSE); | |
3320 } | |
3321 } | |
3322 } | |
3323 } | |
3324 #endif | |
3325 | |
3326 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3327 { | |
3328 draw_state = WL_NR; | |
3329 /* Display the line number. After the first fill with blanks | |
3330 * when the 'n' flag isn't in 'cpo' */ | |
3331 if (wp->w_p_nu | |
3332 && (row == startrow | |
3333 #ifdef FEAT_DIFF | |
3334 + filler_lines | |
3335 #endif | |
3336 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3337 { | |
3338 /* Draw the line number (empty space after wrapping). */ | |
3339 if (row == startrow | |
3340 #ifdef FEAT_DIFF | |
3341 + filler_lines | |
3342 #endif | |
3343 ) | |
3344 { | |
13 | 3345 sprintf((char *)extra, "%*ld ", |
3346 number_width(wp), (long)lnum); | |
7 | 3347 if (wp->w_skipcol > 0) |
3348 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3349 *p_extra = '-'; | |
3350 #ifdef FEAT_RIGHTLEFT | |
3351 if (wp->w_p_rl) /* reverse line numbers */ | |
3352 rl_mirror(extra); | |
3353 #endif | |
3354 p_extra = extra; | |
3355 c_extra = NUL; | |
3356 } | |
3357 else | |
3358 c_extra = ' '; | |
13 | 3359 n_extra = number_width(wp) + 1; |
7 | 3360 char_attr = hl_attr(HLF_N); |
743 | 3361 #ifdef FEAT_SYN_HL |
3362 /* When 'cursorline' is set highlight the line number of | |
3363 * the current line differently. */ | |
3364 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3365 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3366 #endif | |
7 | 3367 } |
3368 } | |
3369 | |
3370 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3371 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3372 { | |
3373 draw_state = WL_SBR; | |
3374 # ifdef FEAT_DIFF | |
3375 if (filler_todo > 0) | |
3376 { | |
3377 /* Draw "deleted" diff line(s). */ | |
3378 if (char2cells(fill_diff) > 1) | |
3379 c_extra = '-'; | |
3380 else | |
3381 c_extra = fill_diff; | |
3382 # ifdef FEAT_RIGHTLEFT | |
3383 if (wp->w_p_rl) | |
3384 n_extra = col + 1; | |
3385 else | |
3386 # endif | |
3387 n_extra = W_WIDTH(wp) - col; | |
3388 char_attr = hl_attr(HLF_DED); | |
3389 } | |
3390 # endif | |
3391 # ifdef FEAT_LINEBREAK | |
3392 if (*p_sbr != NUL && need_showbreak) | |
3393 { | |
3394 /* Draw 'showbreak' at the start of each broken line. */ | |
3395 p_extra = p_sbr; | |
3396 c_extra = NUL; | |
3397 n_extra = (int)STRLEN(p_sbr); | |
3398 char_attr = hl_attr(HLF_AT); | |
3399 need_showbreak = FALSE; | |
3400 /* Correct end of highlighted area for 'showbreak', | |
3401 * required when 'linebreak' is also set. */ | |
3402 if (tocol == vcol) | |
3403 tocol += n_extra; | |
3404 } | |
3405 # endif | |
3406 } | |
3407 #endif | |
3408 | |
3409 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3410 { | |
3411 draw_state = WL_LINE; | |
3412 if (saved_n_extra) | |
3413 { | |
3414 /* Continue item from end of wrapped line. */ | |
3415 n_extra = saved_n_extra; | |
3416 c_extra = saved_c_extra; | |
3417 p_extra = saved_p_extra; | |
3418 char_attr = saved_char_attr; | |
3419 } | |
3420 else | |
3421 char_attr = 0; | |
3422 } | |
3423 } | |
3424 | |
3425 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3426 if (dollar_vcol != 0 && wp == curwin |
3427 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3428 #ifdef FEAT_DIFF |
3429 && filler_todo <= 0 | |
3430 #endif | |
3431 ) | |
3432 { | |
3433 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3434 wp->w_p_rl); | |
819 | 3435 /* Pretend we have finished updating the window. Except when |
3436 * 'cursorcolumn' is set. */ | |
3437 #ifdef FEAT_SYN_HL | |
3438 if (wp->w_p_cuc) | |
3439 row = wp->w_cline_row + wp->w_cline_height; | |
3440 else | |
3441 #endif | |
3442 row = wp->w_height; | |
7 | 3443 break; |
3444 } | |
3445 | |
3446 if (draw_state == WL_LINE && area_highlighting) | |
3447 { | |
3448 /* handle Visual or match highlighting in this line */ | |
3449 if (vcol == fromcol | |
3450 #ifdef FEAT_MBYTE | |
3451 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3452 && (*mb_ptr2cells)(ptr) > 1) | |
3453 #endif | |
3454 || ((int)vcol_prev == fromcol_prev | |
1814 | 3455 && vcol_prev < vcol /* not at margin */ |
7 | 3456 && vcol < tocol)) |
3457 area_attr = attr; /* start highlighting */ | |
3458 else if (area_attr != 0 | |
3459 && (vcol == tocol | |
3460 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3461 area_attr = 0; /* stop highlighting */ | |
3462 | |
3463 #ifdef FEAT_SEARCH_EXTRA | |
3464 if (!n_extra) | |
3465 { | |
3466 /* | |
3467 * Check for start/end of search pattern match. | |
3468 * After end, check for start/end of next match. | |
3469 * When another match, have to check for start again. | |
3470 * Watch out for matching an empty string! | |
1326 | 3471 * Do this for 'search_hl' and the match list (ordered by |
3472 * priority). | |
7 | 3473 */ |
36 | 3474 v = (long)(ptr - line); |
1326 | 3475 cur = wp->w_match_head; |
3476 shl_flag = FALSE; | |
3477 while (cur != NULL || shl_flag == FALSE) | |
3478 { | |
3479 if (shl_flag == FALSE | |
3480 && ((cur != NULL | |
3481 && cur->priority > SEARCH_HL_PRIORITY) | |
3482 || cur == NULL)) | |
3483 { | |
3484 shl = &search_hl; | |
3485 shl_flag = TRUE; | |
3486 } | |
3487 else | |
3488 shl = &cur->hl; | |
7 | 3489 while (shl->rm.regprog != NULL) |
3490 { | |
36 | 3491 if (shl->startcol != MAXCOL |
3492 && v >= (long)shl->startcol | |
3493 && v < (long)shl->endcol) | |
7 | 3494 { |
3495 shl->attr_cur = shl->attr; | |
3496 } | |
36 | 3497 else if (v == (long)shl->endcol) |
7 | 3498 { |
3499 shl->attr_cur = 0; | |
3500 | |
3501 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3502 | |
3503 /* Need to get the line again, a multi-line regexp | |
3504 * may have made it invalid. */ | |
3505 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3506 ptr = line + v; | |
3507 | |
3508 if (shl->lnum == lnum) | |
3509 { | |
36 | 3510 shl->startcol = shl->rm.startpos[0].col; |
7 | 3511 if (shl->rm.endpos[0].lnum == 0) |
36 | 3512 shl->endcol = shl->rm.endpos[0].col; |
7 | 3513 else |
36 | 3514 shl->endcol = MAXCOL; |
3515 | |
3516 if (shl->startcol == shl->endcol) | |
7 | 3517 { |
3518 /* highlight empty match, try again after | |
3519 * it */ | |
3520 #ifdef FEAT_MBYTE | |
3521 if (has_mbyte) | |
474 | 3522 shl->endcol += (*mb_ptr2len)(line |
36 | 3523 + shl->endcol); |
7 | 3524 else |
3525 #endif | |
36 | 3526 ++shl->endcol; |
7 | 3527 } |
3528 | |
3529 /* Loop to check if the match starts at the | |
3530 * current position */ | |
3531 continue; | |
3532 } | |
3533 } | |
3534 break; | |
3535 } | |
1326 | 3536 if (shl != &search_hl && cur != NULL) |
3537 cur = cur->next; | |
3538 } | |
3539 | |
3540 /* Use attributes from match with highest priority among | |
3541 * 'search_hl' and the match list. */ | |
3542 search_attr = search_hl.attr_cur; | |
3543 cur = wp->w_match_head; | |
3544 shl_flag = FALSE; | |
3545 while (cur != NULL || shl_flag == FALSE) | |
3546 { | |
3547 if (shl_flag == FALSE | |
3548 && ((cur != NULL | |
3549 && cur->priority > SEARCH_HL_PRIORITY) | |
3550 || cur == NULL)) | |
699 | 3551 { |
1326 | 3552 shl = &search_hl; |
3553 shl_flag = TRUE; | |
699 | 3554 } |
1326 | 3555 else |
3556 shl = &cur->hl; | |
3557 if (shl->attr_cur != 0) | |
3558 search_attr = shl->attr_cur; | |
3559 if (shl != &search_hl && cur != NULL) | |
3560 cur = cur->next; | |
3561 } | |
7 | 3562 } |
3563 #endif | |
3564 | |
3565 #ifdef FEAT_DIFF | |
674 | 3566 if (diff_hlf != (hlf_T)0) |
7 | 3567 { |
1295 | 3568 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3569 && n_extra == 0) | |
7 | 3570 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3571 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3572 && n_extra == 0) | |
7 | 3573 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3574 line_attr = hl_attr(diff_hlf); |
3575 } | |
3576 #endif | |
3577 | |
3578 /* Decide which of the highlight attributes to use. */ | |
3579 attr_pri = TRUE; | |
3580 if (area_attr != 0) | |
3581 char_attr = area_attr; | |
3582 else if (search_attr != 0) | |
3583 char_attr = search_attr; | |
3584 #ifdef LINE_ATTR | |
3585 /* Use line_attr when not in the Visual or 'incsearch' area | |
3586 * (area_attr may be 0 when "noinvcur" is set). */ | |
3587 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3588 || vcol < fromcol || vcol_prev < fromcol_prev |
3589 || vcol >= tocol)) | |
674 | 3590 char_attr = line_attr; |
3591 #endif | |
3592 else | |
3593 { | |
3594 attr_pri = FALSE; | |
3595 #ifdef FEAT_SYN_HL | |
3596 if (has_syntax) | |
3597 char_attr = syntax_attr; | |
3598 else | |
3599 #endif | |
3600 char_attr = 0; | |
3601 } | |
7 | 3602 } |
3603 | |
3604 /* | |
3605 * Get the next character to put on the screen. | |
3606 */ | |
3607 /* | |
1340 | 3608 * The "p_extra" points to the extra stuff that is inserted to |
3609 * represent special characters (non-printable stuff) and other | |
3610 * things. When all characters are the same, c_extra is used. | |
3611 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3612 * "p_extra[n_extra]". | |
7 | 3613 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3614 */ | |
3615 if (n_extra > 0) | |
3616 { | |
3617 if (c_extra != NUL) | |
3618 { | |
3619 c = c_extra; | |
3620 #ifdef FEAT_MBYTE | |
3621 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3622 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3623 { | |
3624 mb_utf8 = TRUE; | |
714 | 3625 u8cc[0] = 0; |
819 | 3626 c = 0xc0; |
7 | 3627 } |
3628 else | |
3629 mb_utf8 = FALSE; | |
3630 #endif | |
3631 } | |
3632 else | |
3633 { | |
3634 c = *p_extra; | |
3635 #ifdef FEAT_MBYTE | |
3636 if (has_mbyte) | |
3637 { | |
3638 mb_c = c; | |
3639 if (enc_utf8) | |
3640 { | |
3641 /* If the UTF-8 character is more than one byte: | |
3642 * Decode it into "mb_c". */ | |
474 | 3643 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3644 mb_utf8 = FALSE; |
3645 if (mb_l > n_extra) | |
3646 mb_l = 1; | |
3647 else if (mb_l > 1) | |
3648 { | |
714 | 3649 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3650 mb_utf8 = TRUE; |
819 | 3651 c = 0xc0; |
7 | 3652 } |
3653 } | |
3654 else | |
3655 { | |
3656 /* if this is a DBCS character, put it in "mb_c" */ | |
3657 mb_l = MB_BYTE2LEN(c); | |
3658 if (mb_l >= n_extra) | |
3659 mb_l = 1; | |
3660 else if (mb_l > 1) | |
3661 mb_c = (c << 8) + p_extra[1]; | |
3662 } | |
504 | 3663 if (mb_l == 0) /* at the NUL at end-of-line */ |
3664 mb_l = 1; | |
3665 | |
7 | 3666 /* If a double-width char doesn't fit display a '>' in the |
3667 * last column. */ | |
504 | 3668 if (( |
7 | 3669 # ifdef FEAT_RIGHTLEFT |
3670 wp->w_p_rl ? (col <= 0) : | |
3671 # endif | |
504 | 3672 (col >= W_WIDTH(wp) - 1)) |
7 | 3673 && (*mb_char2cells)(mb_c) == 2) |
3674 { | |
3675 c = '>'; | |
3676 mb_c = c; | |
3677 mb_l = 1; | |
3678 mb_utf8 = FALSE; | |
3679 multi_attr = hl_attr(HLF_AT); | |
3680 /* put the pointer back to output the double-width | |
3681 * character at the start of the next line. */ | |
3682 ++n_extra; | |
3683 --p_extra; | |
3684 } | |
3685 else | |
3686 { | |
3687 n_extra -= mb_l - 1; | |
3688 p_extra += mb_l - 1; | |
3689 } | |
3690 } | |
3691 #endif | |
3692 ++p_extra; | |
3693 } | |
3694 --n_extra; | |
3695 } | |
3696 else | |
3697 { | |
3698 /* | |
3699 * Get a character from the line itself. | |
3700 */ | |
3701 c = *ptr; | |
3702 #ifdef FEAT_MBYTE | |
3703 if (has_mbyte) | |
3704 { | |
3705 mb_c = c; | |
3706 if (enc_utf8) | |
3707 { | |
3708 /* If the UTF-8 character is more than one byte: Decode it | |
3709 * into "mb_c". */ | |
474 | 3710 mb_l = (*mb_ptr2len)(ptr); |
7 | 3711 mb_utf8 = FALSE; |
3712 if (mb_l > 1) | |
3713 { | |
714 | 3714 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3715 /* Overlong encoded ASCII or ASCII with composing char |
3716 * is displayed normally, except a NUL. */ | |
3717 if (mb_c < 0x80) | |
3718 c = mb_c; | |
3719 mb_utf8 = TRUE; | |
507 | 3720 |
3721 /* At start of the line we can have a composing char. | |
3722 * Draw it as a space with a composing char. */ | |
3723 if (utf_iscomposing(mb_c)) | |
3724 { | |
1326 | 3725 int i; |
3726 | |
714 | 3727 for (i = Screen_mco - 1; i > 0; --i) |
3728 u8cc[i] = u8cc[i - 1]; | |
3729 u8cc[0] = mb_c; | |
507 | 3730 mb_c = ' '; |
3731 } | |
7 | 3732 } |
3733 | |
3734 if ((mb_l == 1 && c >= 0x80) | |
3735 || (mb_l >= 1 && mb_c == 0) | |
3736 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3737 # ifdef UNICODE16 |
3738 || mb_c >= 0x10000 | |
3739 # endif | |
3740 ))) | |
7 | 3741 { |
3742 /* | |
3743 * Illegal UTF-8 byte: display as <xx>. | |
3744 * Non-BMP character : display as ? or fullwidth ?. | |
3745 */ | |
1401 | 3746 # ifdef UNICODE16 |
7 | 3747 if (mb_c < 0x10000) |
1401 | 3748 # endif |
7 | 3749 { |
3750 transchar_hex(extra, mb_c); | |
714 | 3751 # ifdef FEAT_RIGHTLEFT |
7 | 3752 if (wp->w_p_rl) /* reverse */ |
3753 rl_mirror(extra); | |
714 | 3754 # endif |
7 | 3755 } |
1401 | 3756 # ifdef UNICODE16 |
7 | 3757 else if (utf_char2cells(mb_c) != 2) |
3758 STRCPY(extra, "?"); | |
3759 else | |
3760 /* 0xff1f in UTF-8: full-width '?' */ | |
3761 STRCPY(extra, "\357\274\237"); | |
1401 | 3762 # endif |
7 | 3763 |
3764 p_extra = extra; | |
3765 c = *p_extra; | |
3766 mb_c = mb_ptr2char_adv(&p_extra); | |
3767 mb_utf8 = (c >= 0x80); | |
3768 n_extra = (int)STRLEN(p_extra); | |
3769 c_extra = NUL; | |
3770 if (area_attr == 0 && search_attr == 0) | |
3771 { | |
3772 n_attr = n_extra + 1; | |
3773 extra_attr = hl_attr(HLF_8); | |
3774 saved_attr2 = char_attr; /* save current attr */ | |
3775 } | |
3776 } | |
3777 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3778 mb_l = 1; | |
3779 #ifdef FEAT_ARABIC | |
3780 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3781 { | |
3782 /* Do Arabic shaping. */ | |
714 | 3783 int pc, pc1, nc; |
3784 int pcc[MAX_MCO]; | |
7 | 3785 |
3786 /* The idea of what is the previous and next | |
3787 * character depends on 'rightleft'. */ | |
3788 if (wp->w_p_rl) | |
3789 { | |
3790 pc = prev_c; | |
3791 pc1 = prev_c1; | |
3792 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3793 prev_c1 = u8cc[0]; |
7 | 3794 } |
3795 else | |
3796 { | |
714 | 3797 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3798 nc = prev_c; |
714 | 3799 pc1 = pcc[0]; |
7 | 3800 } |
3801 prev_c = mb_c; | |
3802 | |
714 | 3803 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3804 } |
3805 else | |
3806 prev_c = mb_c; | |
3807 #endif | |
3808 } | |
3809 else /* enc_dbcs */ | |
3810 { | |
3811 mb_l = MB_BYTE2LEN(c); | |
3812 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3813 mb_l = 1; | |
3814 else if (mb_l > 1) | |
3815 { | |
3816 /* We assume a second byte below 32 is illegal. | |
3817 * Hopefully this is OK for all double-byte encodings! | |
3818 */ | |
3819 if (ptr[1] >= 32) | |
3820 mb_c = (c << 8) + ptr[1]; | |
3821 else | |
3822 { | |
3823 if (ptr[1] == NUL) | |
3824 { | |
3825 /* head byte at end of line */ | |
3826 mb_l = 1; | |
3827 transchar_nonprint(extra, c); | |
3828 } | |
3829 else | |
3830 { | |
3831 /* illegal tail byte */ | |
3832 mb_l = 2; | |
3833 STRCPY(extra, "XX"); | |
3834 } | |
3835 p_extra = extra; | |
3836 n_extra = (int)STRLEN(extra) - 1; | |
3837 c_extra = NUL; | |
3838 c = *p_extra++; | |
3839 if (area_attr == 0 && search_attr == 0) | |
3840 { | |
3841 n_attr = n_extra + 1; | |
3842 extra_attr = hl_attr(HLF_8); | |
3843 saved_attr2 = char_attr; /* save current attr */ | |
3844 } | |
3845 mb_c = c; | |
3846 } | |
3847 } | |
3848 } | |
3849 /* If a double-width char doesn't fit display a '>' in the | |
3850 * last column; the character is displayed at the start of the | |
3851 * next line. */ | |
3852 if (( | |
3853 # ifdef FEAT_RIGHTLEFT | |
3854 wp->w_p_rl ? (col <= 0) : | |
3855 # endif | |
3856 (col >= W_WIDTH(wp) - 1)) | |
3857 && (*mb_char2cells)(mb_c) == 2) | |
3858 { | |
3859 c = '>'; | |
3860 mb_c = c; | |
3861 mb_utf8 = FALSE; | |
3862 mb_l = 1; | |
3863 multi_attr = hl_attr(HLF_AT); | |
3864 /* Put pointer back so that the character will be | |
3865 * displayed at the start of the next line. */ | |
3866 --ptr; | |
3867 } | |
3868 else if (*ptr != NUL) | |
3869 ptr += mb_l - 1; | |
3870 | |
3871 /* If a double-width char doesn't fit at the left side display | |
3872 * a '<' in the first column. */ | |
3873 if (n_skip > 0 && mb_l > 1) | |
3874 { | |
3875 n_extra = 1; | |
1340 | 3876 c_extra = '<'; |
7 | 3877 c = ' '; |
3878 if (area_attr == 0 && search_attr == 0) | |
3879 { | |
3880 n_attr = n_extra + 1; | |
3881 extra_attr = hl_attr(HLF_AT); | |
3882 saved_attr2 = char_attr; /* save current attr */ | |
3883 } | |
3884 mb_c = c; | |
3885 mb_utf8 = FALSE; | |
3886 mb_l = 1; | |
3887 } | |
3888 | |
3889 } | |
3890 #endif | |
3891 ++ptr; | |
3892 | |
12 | 3893 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 3894 if (wp->w_p_list && (c == 160 |
3895 #ifdef FEAT_MBYTE | |
3896 || (mb_utf8 && mb_c == 160) | |
3897 #endif | |
3898 ) && lcs_nbsp) | |
12 | 3899 { |
3900 c = lcs_nbsp; | |
3901 if (area_attr == 0 && search_attr == 0) | |
3902 { | |
3903 n_attr = 1; | |
3904 extra_attr = hl_attr(HLF_8); | |
3905 saved_attr2 = char_attr; /* save current attr */ | |
3906 } | |
3907 #ifdef FEAT_MBYTE | |
3908 mb_c = c; | |
3909 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3910 { | |
3911 mb_utf8 = TRUE; | |
714 | 3912 u8cc[0] = 0; |
819 | 3913 c = 0xc0; |
12 | 3914 } |
3915 else | |
3916 mb_utf8 = FALSE; | |
3917 #endif | |
3918 } | |
3919 | |
7 | 3920 if (extra_check) |
3921 { | |
743 | 3922 #ifdef FEAT_SPELL |
221 | 3923 int can_spell = TRUE; |
743 | 3924 #endif |
3925 | |
3926 #ifdef FEAT_SYN_HL | |
7 | 3927 /* Get syntax attribute, unless still at the start of the line |
3928 * (double-wide char that doesn't fit). */ | |
221 | 3929 v = (long)(ptr - line); |
3930 if (has_syntax && v > 0) | |
7 | 3931 { |
3932 /* Get the syntax attribute for the character. If there | |
3933 * is an error, disable syntax highlighting. */ | |
3934 save_did_emsg = did_emsg; | |
3935 did_emsg = FALSE; | |
3936 | |
221 | 3937 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
743 | 3938 # ifdef FEAT_SPELL |
3939 has_spell ? &can_spell : | |
3940 # endif | |
1504 | 3941 NULL, FALSE); |
7 | 3942 |
3943 if (did_emsg) | |
482 | 3944 { |
3945 wp->w_buffer->b_syn_error = TRUE; | |
3946 has_syntax = FALSE; | |
3947 } | |
7 | 3948 else |
3949 did_emsg = save_did_emsg; | |
3950 | |
3951 /* Need to get the line again, a multi-line regexp may | |
3952 * have made it invalid. */ | |
3953 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3954 ptr = line + v; | |
3955 | |
674 | 3956 if (!attr_pri) |
7 | 3957 char_attr = syntax_attr; |
301 | 3958 else |
303 | 3959 char_attr = hl_combine_attr(syntax_attr, char_attr); |
7 | 3960 } |
743 | 3961 #endif |
3962 | |
3963 #ifdef FEAT_SPELL | |
301 | 3964 /* Check spelling (unless at the end of the line). |
319 | 3965 * Only do this when there is no syntax highlighting, the |
3966 * @Spell cluster is not used or the current syntax item | |
3967 * contains the @Spell cluster. */ | |
348 | 3968 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 3969 { |
230 | 3970 spell_attr = 0; |
743 | 3971 # ifdef FEAT_SYN_HL |
674 | 3972 if (!attr_pri) |
230 | 3973 char_attr = syntax_attr; |
743 | 3974 # endif |
3975 if (c != 0 && ( | |
3976 # ifdef FEAT_SYN_HL | |
3977 !has_syntax || | |
3978 # endif | |
3979 can_spell)) | |
221 | 3980 { |
348 | 3981 char_u *prev_ptr, *p; |
3982 int len; | |
534 | 3983 hlf_T spell_hlf = HLF_COUNT; |
221 | 3984 # ifdef FEAT_MBYTE |
336 | 3985 if (has_mbyte) |
3986 { | |
3987 prev_ptr = ptr - mb_l; | |
3988 v -= mb_l - 1; | |
3989 } | |
3990 else | |
221 | 3991 # endif |
336 | 3992 prev_ptr = ptr - 1; |
348 | 3993 |
3994 /* Use nextline[] if possible, it has the start of the | |
3995 * next line concatenated. */ | |
3996 if ((prev_ptr - line) - nextlinecol >= 0) | |
3997 p = nextline + (prev_ptr - line) - nextlinecol; | |
3998 else | |
3999 p = prev_ptr; | |
835 | 4000 cap_col -= (int)(prev_ptr - line); |
625 | 4001 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4002 nochange); | |
348 | 4003 word_end = v + len; |
301 | 4004 |
4005 /* In Insert mode only highlight a word that | |
4006 * doesn't touch the cursor. */ | |
534 | 4007 if (spell_hlf != HLF_COUNT |
301 | 4008 && (State & INSERT) != 0 |
4009 && wp->w_cursor.lnum == lnum | |
4010 && wp->w_cursor.col >= | |
4011 (colnr_T)(prev_ptr - line) | |
4012 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4013 { |
534 | 4014 spell_hlf = HLF_COUNT; |
301 | 4015 spell_redraw_lnum = lnum; |
221 | 4016 } |
348 | 4017 |
534 | 4018 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4019 && (p - nextline) + len > nextline_idx) |
4020 { | |
4021 /* Remember that the good word continues at the | |
4022 * start of the next line. */ | |
4023 checked_lnum = lnum + 1; | |
835 | 4024 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4025 } |
386 | 4026 |
534 | 4027 /* Turn index into actual attributes. */ |
4028 if (spell_hlf != HLF_COUNT) | |
4029 spell_attr = highlight_attr[spell_hlf]; | |
4030 | |
386 | 4031 if (cap_col > 0) |
4032 { | |
4033 if (p != prev_ptr | |
4034 && (p - nextline) + cap_col >= nextline_idx) | |
4035 { | |
4036 /* Remember that the word in the next line | |
4037 * must start with a capital. */ | |
4038 capcol_lnum = lnum + 1; | |
835 | 4039 cap_col = (int)((p - nextline) + cap_col |
4040 - nextline_idx); | |
386 | 4041 } |
4042 else | |
4043 /* Compute the actual column. */ | |
835 | 4044 cap_col += (int)(prev_ptr - line); |
386 | 4045 } |
221 | 4046 } |
4047 } | |
4048 if (spell_attr != 0) | |
348 | 4049 { |
674 | 4050 if (!attr_pri) |
348 | 4051 char_attr = hl_combine_attr(char_attr, spell_attr); |
4052 else | |
4053 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4054 } | |
7 | 4055 #endif |
4056 #ifdef FEAT_LINEBREAK | |
4057 /* | |
221 | 4058 * Found last space before word: check for line break. |
7 | 4059 */ |
4060 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4061 && !wp->w_p_list) |
7 | 4062 { |
4063 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4064 # ifdef FEAT_MBYTE | |
4065 has_mbyte ? mb_l : | |
4066 # endif | |
4067 1), (colnr_T)vcol, NULL) - 1; | |
4068 c_extra = ' '; | |
4069 if (vim_iswhite(c)) | |
4070 c = ' '; | |
4071 } | |
4072 #endif | |
4073 | |
4074 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4075 { | |
4076 c = lcs_trail; | |
674 | 4077 if (!attr_pri) |
7 | 4078 { |
4079 n_attr = 1; | |
4080 extra_attr = hl_attr(HLF_8); | |
4081 saved_attr2 = char_attr; /* save current attr */ | |
4082 } | |
4083 #ifdef FEAT_MBYTE | |
4084 mb_c = c; | |
4085 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4086 { | |
4087 mb_utf8 = TRUE; | |
714 | 4088 u8cc[0] = 0; |
819 | 4089 c = 0xc0; |
7 | 4090 } |
4091 else | |
4092 mb_utf8 = FALSE; | |
4093 #endif | |
4094 } | |
4095 } | |
4096 | |
4097 /* | |
4098 * Handling of non-printable characters. | |
4099 */ | |
819 | 4100 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4101 { |
4102 /* | |
4103 * when getting a character from the file, we may have to | |
4104 * turn it into something else on the way to putting it | |
4105 * into "ScreenLines". | |
4106 */ | |
4107 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4108 { | |
4109 /* tab amount depends on current column */ | |
4110 n_extra = (int)wp->w_buffer->b_p_ts | |
4111 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4112 #ifdef FEAT_MBYTE | |
4113 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4114 #endif | |
4115 if (wp->w_p_list) | |
4116 { | |
4117 c = lcs_tab1; | |
4118 c_extra = lcs_tab2; | |
4119 n_attr = n_extra + 1; | |
4120 extra_attr = hl_attr(HLF_8); | |
4121 saved_attr2 = char_attr; /* save current attr */ | |
4122 #ifdef FEAT_MBYTE | |
4123 mb_c = c; | |
4124 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4125 { | |
4126 mb_utf8 = TRUE; | |
714 | 4127 u8cc[0] = 0; |
819 | 4128 c = 0xc0; |
7 | 4129 } |
4130 #endif | |
4131 } | |
4132 else | |
4133 { | |
4134 c_extra = ' '; | |
4135 c = ' '; | |
4136 } | |
4137 } | |
36 | 4138 else if (c == NUL |
4139 && ((wp->w_p_list && lcs_eol > 0) | |
4140 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4141 && tocol > vcol | |
39 | 4142 #ifdef FEAT_VISUAL |
36 | 4143 && VIsual_mode != Ctrl_V |
39 | 4144 #endif |
36 | 4145 && ( |
4146 # ifdef FEAT_RIGHTLEFT | |
4147 wp->w_p_rl ? (col >= 0) : | |
4148 # endif | |
4149 (col < W_WIDTH(wp))) | |
4150 && !(noinvcur | |
1850 | 4151 && lnum == wp->w_cursor.lnum |
36 | 4152 && (colnr_T)vcol == wp->w_virtcol))) |
4153 && lcs_eol_one >= 0) | |
7 | 4154 { |
36 | 4155 /* Display a '$' after the line or highlight an extra |
4156 * character if the line break is included. */ | |
7 | 4157 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4158 /* For a diff line the highlighting continues after the | |
4159 * "$". */ | |
4160 if ( | |
4161 # ifdef FEAT_DIFF | |
534 | 4162 diff_hlf == (hlf_T)0 |
7 | 4163 # ifdef LINE_ATTR |
4164 && | |
4165 # endif | |
4166 # endif | |
4167 # ifdef LINE_ATTR | |
4168 line_attr == 0 | |
4169 # endif | |
4170 ) | |
4171 #endif | |
4172 { | |
4173 #ifdef FEAT_VIRTUALEDIT | |
4174 /* In virtualedit, visual selections may extend | |
4175 * beyond end of line. */ | |
4176 if (area_highlighting && virtual_active() | |
4177 && tocol != MAXCOL && vcol < tocol) | |
4178 n_extra = 0; | |
4179 else | |
4180 #endif | |
4181 { | |
4182 p_extra = at_end_str; | |
4183 n_extra = 1; | |
4184 c_extra = NUL; | |
4185 } | |
4186 } | |
36 | 4187 if (wp->w_p_list) |
4188 c = lcs_eol; | |
4189 else | |
4190 c = ' '; | |
7 | 4191 lcs_eol_one = -1; |
4192 --ptr; /* put it back at the NUL */ | |
674 | 4193 if (!attr_pri) |
7 | 4194 { |
4195 extra_attr = hl_attr(HLF_AT); | |
4196 n_attr = 1; | |
4197 } | |
4198 #ifdef FEAT_MBYTE | |
4199 mb_c = c; | |
4200 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4201 { | |
4202 mb_utf8 = TRUE; | |
714 | 4203 u8cc[0] = 0; |
819 | 4204 c = 0xc0; |
7 | 4205 } |
4206 else | |
4207 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4208 #endif | |
4209 } | |
4210 else if (c != NUL) | |
4211 { | |
4212 p_extra = transchar(c); | |
4213 #ifdef FEAT_RIGHTLEFT | |
4214 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4215 rl_mirror(p_extra); /* reverse "<12>" */ | |
4216 #endif | |
4217 n_extra = byte2cells(c) - 1; | |
4218 c_extra = NUL; | |
4219 c = *p_extra++; | |
674 | 4220 if (!attr_pri) |
7 | 4221 { |
4222 n_attr = n_extra + 1; | |
4223 extra_attr = hl_attr(HLF_8); | |
4224 saved_attr2 = char_attr; /* save current attr */ | |
4225 } | |
4226 #ifdef FEAT_MBYTE | |
4227 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4228 #endif | |
4229 } | |
4230 #ifdef FEAT_VIRTUALEDIT | |
4231 else if (VIsual_active | |
4232 && (VIsual_mode == Ctrl_V | |
4233 || VIsual_mode == 'v') | |
4234 && virtual_active() | |
4235 && tocol != MAXCOL | |
4236 && vcol < tocol | |
4237 && ( | |
4238 # ifdef FEAT_RIGHTLEFT | |
4239 wp->w_p_rl ? (col >= 0) : | |
4240 # endif | |
4241 (col < W_WIDTH(wp)))) | |
4242 { | |
4243 c = ' '; | |
4244 --ptr; /* put it back at the NUL */ | |
4245 } | |
4246 #endif | |
910 | 4247 #if defined(LINE_ATTR) |
7 | 4248 else if (( |
4249 # ifdef FEAT_DIFF | |
910 | 4250 diff_hlf != (hlf_T)0 || |
7 | 4251 # endif |
4252 line_attr != 0 | |
4253 ) && ( | |
4254 # ifdef FEAT_RIGHTLEFT | |
4255 wp->w_p_rl ? (col >= 0) : | |
4256 # endif | |
4257 (col < W_WIDTH(wp)))) | |
4258 { | |
4259 /* Highlight until the right side of the window */ | |
4260 c = ' '; | |
4261 --ptr; /* put it back at the NUL */ | |
867 | 4262 |
4263 /* Remember we do the char for line highlighting. */ | |
4264 ++did_line_attr; | |
4265 | |
4266 /* don't do search HL for the rest of the line */ | |
4267 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4268 char_attr = line_attr; | |
7 | 4269 # ifdef FEAT_DIFF |
4270 if (diff_hlf == HLF_TXD) | |
4271 { | |
4272 diff_hlf = HLF_CHD; | |
4273 if (attr == 0 || char_attr != attr) | |
4274 char_attr = hl_attr(diff_hlf); | |
4275 } | |
4276 # endif | |
4277 } | |
4278 #endif | |
4279 } | |
4280 } | |
4281 | |
4282 /* Don't override visual selection highlighting. */ | |
4283 if (n_attr > 0 | |
4284 && draw_state == WL_LINE | |
674 | 4285 && !attr_pri) |
7 | 4286 char_attr = extra_attr; |
4287 | |
42 | 4288 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4289 /* XIM don't send preedit_start and preedit_end, but they send |
4290 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4291 * im_is_preediting() here. */ | |
4292 if (xic != NULL | |
1850 | 4293 && lnum == wp->w_cursor.lnum |
7 | 4294 && (State & INSERT) |
4295 && !p_imdisable | |
4296 && im_is_preediting() | |
4297 && draw_state == WL_LINE) | |
4298 { | |
4299 colnr_T tcol; | |
4300 | |
4301 if (preedit_end_col == MAXCOL) | |
1850 | 4302 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4303 else |
4304 tcol = preedit_end_col; | |
4305 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4306 { | |
4307 if (feedback_old_attr < 0) | |
4308 { | |
4309 feedback_col = 0; | |
4310 feedback_old_attr = char_attr; | |
4311 } | |
4312 char_attr = im_get_feedback_attr(feedback_col); | |
4313 if (char_attr < 0) | |
4314 char_attr = feedback_old_attr; | |
4315 feedback_col++; | |
4316 } | |
4317 else if (feedback_old_attr >= 0) | |
4318 { | |
4319 char_attr = feedback_old_attr; | |
4320 feedback_old_attr = -1; | |
4321 feedback_col = 0; | |
4322 } | |
4323 } | |
4324 #endif | |
4325 /* | |
4326 * Handle the case where we are in column 0 but not on the first | |
4327 * character of the line and the user wants us to show us a | |
4328 * special character (via 'listchars' option "precedes:<char>". | |
4329 */ | |
4330 if (lcs_prec_todo != NUL | |
4331 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4332 #ifdef FEAT_DIFF | |
4333 && filler_todo <= 0 | |
4334 #endif | |
4335 && draw_state > WL_NR | |
4336 && c != NUL) | |
4337 { | |
4338 c = lcs_prec; | |
4339 lcs_prec_todo = NUL; | |
4340 #ifdef FEAT_MBYTE | |
4341 mb_c = c; | |
4342 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4343 { | |
4344 mb_utf8 = TRUE; | |
714 | 4345 u8cc[0] = 0; |
819 | 4346 c = 0xc0; |
7 | 4347 } |
4348 else | |
4349 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4350 #endif | |
674 | 4351 if (!attr_pri) |
7 | 4352 { |
4353 saved_attr3 = char_attr; /* save current attr */ | |
4354 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4355 n_attr3 = 1; | |
4356 } | |
4357 } | |
4358 | |
4359 /* | |
867 | 4360 * At end of the text line or just after the last character. |
7 | 4361 */ |
867 | 4362 if (c == NUL |
910 | 4363 #if defined(LINE_ATTR) |
867 | 4364 || did_line_attr == 1 |
4365 #endif | |
4366 ) | |
4367 { | |
4368 #ifdef FEAT_SEARCH_EXTRA | |
4369 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4370 |
4371 /* we're not really at that column when skipping some text */ | |
1439 | 4372 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4373 ++prevcol; |
867 | 4374 #endif |
4375 | |
7 | 4376 /* invert at least one char, used for Visual and empty line or |
4377 * highlight match at end of line. If it's beyond the last | |
4378 * char on the screen, just overwrite that one (tricky!) Not | |
4379 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4380 #ifdef FEAT_SEARCH_EXTRA |
4381 prevcol_hl_flag = FALSE; | |
4382 if (prevcol == (long)search_hl.startcol) | |
4383 prevcol_hl_flag = TRUE; | |
4384 else | |
4385 { | |
4386 cur = wp->w_match_head; | |
4387 while (cur != NULL) | |
4388 { | |
4389 if (prevcol == (long)cur->hl.startcol) | |
4390 { | |
4391 prevcol_hl_flag = TRUE; | |
4392 break; | |
4393 } | |
4394 cur = cur->next; | |
4395 } | |
4396 } | |
4397 #endif | |
7 | 4398 if (lcs_eol == lcs_eol_one |
1850 | 4399 && ((area_attr != 0 && vcol == fromcol |
4400 #ifdef FEAT_VISUAL | |
4401 && (VIsual_mode != Ctrl_V | |
4402 || lnum == VIsual.lnum | |
4403 || lnum == curwin->w_cursor.lnum) | |
4404 #endif | |
4405 && c == NUL) | |
7 | 4406 #ifdef FEAT_SEARCH_EXTRA |
4407 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4408 || (prevcol_hl_flag == TRUE |
910 | 4409 # if defined(LINE_ATTR) |
867 | 4410 && did_line_attr <= 1 |
4411 # endif | |
4412 ) | |
7 | 4413 #endif |
4414 )) | |
4415 { | |
4416 int n = 0; | |
4417 | |
4418 #ifdef FEAT_RIGHTLEFT | |
4419 if (wp->w_p_rl) | |
4420 { | |
4421 if (col < 0) | |
4422 n = 1; | |
4423 } | |
4424 else | |
4425 #endif | |
4426 { | |
4427 if (col >= W_WIDTH(wp)) | |
4428 n = -1; | |
4429 } | |
4430 if (n != 0) | |
4431 { | |
4432 /* At the window boundary, highlight the last character | |
4433 * instead (better than nothing). */ | |
4434 off += n; | |
4435 col += n; | |
4436 } | |
4437 else | |
4438 { | |
4439 /* Add a blank character to highlight. */ | |
4440 ScreenLines[off] = ' '; | |
4441 #ifdef FEAT_MBYTE | |
4442 if (enc_utf8) | |
4443 ScreenLinesUC[off] = 0; | |
4444 #endif | |
4445 } | |
4446 #ifdef FEAT_SEARCH_EXTRA | |
4447 if (area_attr == 0) | |
4448 { | |
1326 | 4449 /* Use attributes from match with highest priority among |
4450 * 'search_hl' and the match list. */ | |
4451 char_attr = search_hl.attr; | |
4452 cur = wp->w_match_head; | |
4453 shl_flag = FALSE; | |
4454 while (cur != NULL || shl_flag == FALSE) | |
699 | 4455 { |
1326 | 4456 if (shl_flag == FALSE |
4457 && ((cur != NULL | |
4458 && cur->priority > SEARCH_HL_PRIORITY) | |
4459 || cur == NULL)) | |
699 | 4460 { |
1326 | 4461 shl = &search_hl; |
4462 shl_flag = TRUE; | |
699 | 4463 } |
1326 | 4464 else |
4465 shl = &cur->hl; | |
4466 if ((ptr - line) - 1 == (long)shl->startcol) | |
4467 char_attr = shl->attr; | |
4468 if (shl != &search_hl && cur != NULL) | |
4469 cur = cur->next; | |
699 | 4470 } |
7 | 4471 } |
4472 #endif | |
4473 ScreenAttrs[off] = char_attr; | |
4474 #ifdef FEAT_RIGHTLEFT | |
4475 if (wp->w_p_rl) | |
1437 | 4476 { |
7 | 4477 --col; |
1437 | 4478 --off; |
4479 } | |
7 | 4480 else |
4481 #endif | |
1437 | 4482 { |
7 | 4483 ++col; |
1437 | 4484 ++off; |
4485 } | |
743 | 4486 ++vcol; |
1437 | 4487 #ifdef FEAT_SYN_HL |
4488 eol_hl_off = 1; | |
4489 #endif | |
743 | 4490 } |
867 | 4491 } |
4492 | |
4493 /* | |
4494 * At end of the text line. | |
4495 */ | |
4496 if (c == NUL) | |
4497 { | |
743 | 4498 #ifdef FEAT_SYN_HL |
1850 | 4499 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4500 && lnum == wp->w_cursor.lnum) | |
1437 | 4501 { |
4502 /* highlight last char after line */ | |
4503 --col; | |
4504 --off; | |
4505 --vcol; | |
4506 } | |
4507 | |
743 | 4508 /* Highlight 'cursorcolumn' past end of the line. */ |
758 | 4509 if (wp->w_p_wrap) |
4510 v = wp->w_skipcol; | |
4511 else | |
4512 v = wp->w_leftcol; | |
820 | 4513 /* check if line ends before left margin */ |
4514 if (vcol < v + col - win_col_off(wp)) | |
4515 | |
4516 vcol = v + col - win_col_off(wp); | |
743 | 4517 if (wp->w_p_cuc |
1437 | 4518 && (int)wp->w_virtcol >= vcol - eol_hl_off |
819 | 4519 && (int)wp->w_virtcol < W_WIDTH(wp) * (row - startrow + 1) |
4520 + v | |
743 | 4521 && lnum != wp->w_cursor.lnum |
4522 # ifdef FEAT_RIGHTLEFT | |
4523 && !wp->w_p_rl | |
4524 # endif | |
4525 ) | |
4526 { | |
4527 while (col < W_WIDTH(wp)) | |
4528 { | |
4529 ScreenLines[off] = ' '; | |
4530 #ifdef FEAT_MBYTE | |
4531 if (enc_utf8) | |
4532 ScreenLinesUC[off] = 0; | |
4533 #endif | |
4534 ++col; | |
777 | 4535 if (vcol == (long)wp->w_virtcol) |
743 | 4536 { |
4537 ScreenAttrs[off] = hl_attr(HLF_CUC); | |
4538 break; | |
4539 } | |
4540 ScreenAttrs[off++] = 0; | |
4541 ++vcol; | |
4542 } | |
4543 } | |
4544 #endif | |
7 | 4545 |
4546 SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), | |
4547 wp->w_p_rl); | |
4548 row++; | |
4549 | |
4550 /* | |
4551 * Update w_cline_height and w_cline_folded if the cursor line was | |
4552 * updated (saves a call to plines() later). | |
4553 */ | |
4554 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4555 { | |
4556 curwin->w_cline_row = startrow; | |
4557 curwin->w_cline_height = row - startrow; | |
4558 #ifdef FEAT_FOLDING | |
4559 curwin->w_cline_folded = FALSE; | |
4560 #endif | |
4561 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4562 } | |
4563 | |
4564 break; | |
4565 } | |
4566 | |
4567 /* line continues beyond line end */ | |
4568 if (lcs_ext | |
4569 && !wp->w_p_wrap | |
4570 #ifdef FEAT_DIFF | |
4571 && filler_todo <= 0 | |
4572 #endif | |
4573 && ( | |
4574 #ifdef FEAT_RIGHTLEFT | |
4575 wp->w_p_rl ? col == 0 : | |
4576 #endif | |
4577 col == W_WIDTH(wp) - 1) | |
4578 && (*ptr != NUL | |
1555 | 4579 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4580 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4581 { | |
4582 c = lcs_ext; | |
4583 char_attr = hl_attr(HLF_AT); | |
4584 #ifdef FEAT_MBYTE | |
4585 mb_c = c; | |
4586 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4587 { | |
4588 mb_utf8 = TRUE; | |
714 | 4589 u8cc[0] = 0; |
819 | 4590 c = 0xc0; |
7 | 4591 } |
4592 else | |
4593 mb_utf8 = FALSE; | |
4594 #endif | |
4595 } | |
4596 | |
743 | 4597 #ifdef FEAT_SYN_HL |
4598 /* Highlight the cursor column if 'cursorcolumn' is set. But don't | |
4599 * highlight the cursor position itself. */ | |
777 | 4600 if (wp->w_p_cuc && vcol == (long)wp->w_virtcol |
743 | 4601 && lnum != wp->w_cursor.lnum |
1813 | 4602 && draw_state == WL_LINE |
4603 && !lnum_in_visual_area) | |
743 | 4604 { |
4605 vcol_save_attr = char_attr; | |
4606 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); | |
4607 } | |
4608 else | |
4609 vcol_save_attr = -1; | |
4610 #endif | |
4611 | |
7 | 4612 /* |
4613 * Store character to be displayed. | |
4614 * Skip characters that are left of the screen for 'nowrap'. | |
4615 */ | |
4616 vcol_prev = vcol; | |
4617 if (draw_state < WL_LINE || n_skip <= 0) | |
4618 { | |
4619 /* | |
4620 * Store the character. | |
4621 */ | |
4622 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4623 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4624 { | |
4625 /* A double-wide character is: put first halve in left cell. */ | |
4626 --off; | |
4627 --col; | |
4628 } | |
4629 #endif | |
4630 ScreenLines[off] = c; | |
4631 #ifdef FEAT_MBYTE | |
4632 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4633 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4634 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4635 ScreenLines[off] = 0x8e; |
7 | 4636 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4637 } |
7 | 4638 else if (enc_utf8) |
4639 { | |
4640 if (mb_utf8) | |
4641 { | |
1326 | 4642 int i; |
4643 | |
7 | 4644 ScreenLinesUC[off] = mb_c; |
819 | 4645 if ((c & 0xff) == 0) |
4646 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4647 for (i = 0; i < Screen_mco; ++i) |
4648 { | |
4649 ScreenLinesC[i][off] = u8cc[i]; | |
4650 if (u8cc[i] == 0) | |
4651 break; | |
4652 } | |
7 | 4653 } |
4654 else | |
4655 ScreenLinesUC[off] = 0; | |
4656 } | |
4657 if (multi_attr) | |
4658 { | |
4659 ScreenAttrs[off] = multi_attr; | |
4660 multi_attr = 0; | |
4661 } | |
4662 else | |
4663 #endif | |
4664 ScreenAttrs[off] = char_attr; | |
4665 | |
4666 #ifdef FEAT_MBYTE | |
4667 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4668 { | |
4669 /* Need to fill two screen columns. */ | |
4670 ++off; | |
4671 ++col; | |
4672 if (enc_utf8) | |
4673 /* UTF-8: Put a 0 in the second screen char. */ | |
4674 ScreenLines[off] = 0; | |
4675 else | |
4676 /* DBCS: Put second byte in the second screen char. */ | |
4677 ScreenLines[off] = mb_c & 0xff; | |
4678 ++vcol; | |
4679 /* When "tocol" is halfway a character, set it to the end of | |
4680 * the character, otherwise highlighting won't stop. */ | |
4681 if (tocol == vcol) | |
4682 ++tocol; | |
4683 #ifdef FEAT_RIGHTLEFT | |
4684 if (wp->w_p_rl) | |
4685 { | |
4686 /* now it's time to backup one cell */ | |
4687 --off; | |
4688 --col; | |
4689 } | |
4690 #endif | |
4691 } | |
4692 #endif | |
4693 #ifdef FEAT_RIGHTLEFT | |
4694 if (wp->w_p_rl) | |
4695 { | |
4696 --off; | |
4697 --col; | |
4698 } | |
4699 else | |
4700 #endif | |
4701 { | |
4702 ++off; | |
4703 ++col; | |
4704 } | |
4705 } | |
4706 else | |
4707 --n_skip; | |
4708 | |
4709 /* Only advance the "vcol" when after the 'number' column. */ | |
1849 | 4710 if (draw_state > WL_NR |
7 | 4711 #ifdef FEAT_DIFF |
4712 && filler_todo <= 0 | |
4713 #endif | |
4714 ) | |
4715 ++vcol; | |
4716 | |
743 | 4717 #ifdef FEAT_SYN_HL |
4718 if (vcol_save_attr >= 0) | |
4719 char_attr = vcol_save_attr; | |
4720 #endif | |
4721 | |
7 | 4722 /* restore attributes after "predeces" in 'listchars' */ |
4723 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
4724 char_attr = saved_attr3; | |
4725 | |
4726 /* restore attributes after last 'listchars' or 'number' char */ | |
4727 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
4728 char_attr = saved_attr2; | |
4729 | |
4730 /* | |
4731 * At end of screen line and there is more to come: Display the line | |
1378 | 4732 * so far. If there is no more to display it is caught above. |
7 | 4733 */ |
4734 if (( | |
4735 #ifdef FEAT_RIGHTLEFT | |
4736 wp->w_p_rl ? (col < 0) : | |
4737 #endif | |
4738 (col >= W_WIDTH(wp))) | |
4739 && (*ptr != NUL | |
4740 #ifdef FEAT_DIFF | |
4741 || filler_todo > 0 | |
4742 #endif | |
4743 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
4744 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
4745 ) | |
4746 { | |
4747 SCREEN_LINE(screen_row, W_WINCOL(wp), col, (int)W_WIDTH(wp), | |
4748 wp->w_p_rl); | |
4749 ++row; | |
4750 ++screen_row; | |
4751 | |
4752 /* When not wrapping and finished diff lines, or when displayed | |
4753 * '$' and highlighting until last column, break here. */ | |
4754 if ((!wp->w_p_wrap | |
4755 #ifdef FEAT_DIFF | |
4756 && filler_todo <= 0 | |
4757 #endif | |
4758 ) || lcs_eol_one == -1) | |
4759 break; | |
4760 | |
4761 /* When the window is too narrow draw all "@" lines. */ | |
4762 if (draw_state != WL_LINE | |
4763 #ifdef FEAT_DIFF | |
4764 && filler_todo <= 0 | |
4765 #endif | |
4766 ) | |
4767 { | |
4768 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
4769 #ifdef FEAT_VERTSPLIT | |
4770 draw_vsep_win(wp, row); | |
4771 #endif | |
4772 row = endrow; | |
4773 } | |
4774 | |
4775 /* When line got too long for screen break here. */ | |
4776 if (row == endrow) | |
4777 { | |
4778 ++row; | |
4779 break; | |
4780 } | |
4781 | |
4782 if (screen_cur_row == screen_row - 1 | |
4783 #ifdef FEAT_DIFF | |
4784 && filler_todo <= 0 | |
4785 #endif | |
4786 && W_WIDTH(wp) == Columns) | |
4787 { | |
4788 /* Remember that the line wraps, used for modeless copy. */ | |
4789 LineWraps[screen_row - 1] = TRUE; | |
4790 | |
4791 /* | |
4792 * Special trick to make copy/paste of wrapped lines work with | |
4793 * xterm/screen: write an extra character beyond the end of | |
4794 * the line. This will work with all terminal types | |
4795 * (regardless of the xn,am settings). | |
4796 * Only do this on a fast tty. | |
4797 * Only do this if the cursor is on the current line | |
4798 * (something has been written in it). | |
4799 * Don't do this for the GUI. | |
4800 * Don't do this for double-width characters. | |
4801 * Don't do this for a window not at the right screen border. | |
4802 */ | |
4803 if (p_tf | |
4804 #ifdef FEAT_GUI | |
4805 && !gui.in_use | |
4806 #endif | |
4807 #ifdef FEAT_MBYTE | |
4808 && !(has_mbyte | |
1378 | 4809 && ((*mb_off2cells)(LineOffset[screen_row], |
4810 LineOffset[screen_row] + screen_Columns) | |
4811 == 2 | |
7 | 4812 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 4813 + (int)Columns - 2, |
4814 LineOffset[screen_row] + screen_Columns) | |
4815 == 2)) | |
7 | 4816 #endif |
4817 ) | |
4818 { | |
4819 /* First make sure we are at the end of the screen line, | |
4820 * then output the same character again to let the | |
4821 * terminal know about the wrap. If the terminal doesn't | |
4822 * auto-wrap, we overwrite the character. */ | |
4823 if (screen_cur_col != W_WIDTH(wp)) | |
4824 screen_char(LineOffset[screen_row - 1] | |
4825 + (unsigned)Columns - 1, | |
4826 screen_row - 1, (int)(Columns - 1)); | |
4827 | |
4828 #ifdef FEAT_MBYTE | |
4829 /* When there is a multi-byte character, just output a | |
4830 * space to keep it simple. */ | |
148 | 4831 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
4832 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 4833 out_char(' '); |
4834 else | |
4835 #endif | |
4836 out_char(ScreenLines[LineOffset[screen_row - 1] | |
4837 + (Columns - 1)]); | |
4838 /* force a redraw of the first char on the next line */ | |
4839 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
4840 screen_start(); /* don't know where cursor is now */ | |
4841 } | |
4842 } | |
4843 | |
4844 col = 0; | |
4845 off = (unsigned)(current_ScreenLine - ScreenLines); | |
4846 #ifdef FEAT_RIGHTLEFT | |
4847 if (wp->w_p_rl) | |
4848 { | |
4849 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
4850 off += col; | |
4851 } | |
4852 #endif | |
4853 | |
4854 /* reset the drawing state for the start of a wrapped line */ | |
4855 draw_state = WL_START; | |
4856 saved_n_extra = n_extra; | |
4857 saved_p_extra = p_extra; | |
4858 saved_c_extra = c_extra; | |
4859 saved_char_attr = char_attr; | |
4860 n_extra = 0; | |
4861 lcs_prec_todo = lcs_prec; | |
4862 #ifdef FEAT_LINEBREAK | |
4863 # ifdef FEAT_DIFF | |
4864 if (filler_todo <= 0) | |
4865 # endif | |
4866 need_showbreak = TRUE; | |
4867 #endif | |
4868 #ifdef FEAT_DIFF | |
4869 --filler_todo; | |
4870 /* When the filler lines are actually below the last line of the | |
4871 * file, don't draw the line itself, break here. */ | |
4872 if (filler_todo == 0 && wp->w_botfill) | |
4873 break; | |
4874 #endif | |
4875 } | |
4876 | |
4877 } /* for every character in the line */ | |
4878 | |
743 | 4879 #ifdef FEAT_SPELL |
386 | 4880 /* After an empty line check first word for capital. */ |
4881 if (*skipwhite(line) == NUL) | |
4882 { | |
4883 capcol_lnum = lnum + 1; | |
4884 cap_col = 0; | |
4885 } | |
4886 #endif | |
4887 | |
7 | 4888 return row; |
4889 } | |
4890 | |
714 | 4891 #ifdef FEAT_MBYTE |
4892 static int comp_char_differs __ARGS((int, int)); | |
4893 | |
4894 /* | |
4895 * Return if the composing characters at "off_from" and "off_to" differ. | |
4896 */ | |
4897 static int | |
4898 comp_char_differs(off_from, off_to) | |
4899 int off_from; | |
4900 int off_to; | |
4901 { | |
4902 int i; | |
4903 | |
4904 for (i = 0; i < Screen_mco; ++i) | |
4905 { | |
4906 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
4907 return TRUE; | |
4908 if (ScreenLinesC[i][off_from] == 0) | |
4909 break; | |
4910 } | |
4911 return FALSE; | |
4912 } | |
4913 #endif | |
4914 | |
7 | 4915 /* |
4916 * Check whether the given character needs redrawing: | |
4917 * - the (first byte of the) character is different | |
4918 * - the attributes are different | |
4919 * - the character is multi-byte and the next byte is different | |
1616 | 4920 * - the character is two cells wide and the second cell differs. |
7 | 4921 */ |
4922 static int | |
4923 char_needs_redraw(off_from, off_to, cols) | |
4924 int off_from; | |
4925 int off_to; | |
4926 int cols; | |
4927 { | |
4928 if (cols > 0 | |
4929 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
4930 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
4931 | |
4932 #ifdef FEAT_MBYTE | |
4933 || (enc_dbcs != 0 | |
4934 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
4935 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
4936 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
4937 : (cols > 1 && ScreenLines[off_from + 1] | |
4938 != ScreenLines[off_to + 1]))) | |
4939 || (enc_utf8 | |
4940 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
4941 || (ScreenLinesUC[off_from] != 0 | |
1616 | 4942 && comp_char_differs(off_from, off_to)) |
4943 || (cols > 1 && ScreenLines[off_from + 1] | |
4944 != ScreenLines[off_to + 1]))) | |
7 | 4945 #endif |
4946 )) | |
4947 return TRUE; | |
4948 return FALSE; | |
4949 } | |
4950 | |
4951 /* | |
4952 * Move one "cooked" screen line to the screen, but only the characters that | |
4953 * have actually changed. Handle insert/delete character. | |
4954 * "coloff" gives the first column on the screen for this line. | |
4955 * "endcol" gives the columns where valid characters are. | |
4956 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
4957 * needs to be cleared, negative otherwise. | |
4958 * "rlflag" is TRUE in a rightleft window: | |
4959 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
4960 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
4961 */ | |
4962 static void | |
4963 screen_line(row, coloff, endcol, clear_width | |
4964 #ifdef FEAT_RIGHTLEFT | |
4965 , rlflag | |
4966 #endif | |
4967 ) | |
4968 int row; | |
4969 int coloff; | |
4970 int endcol; | |
4971 int clear_width; | |
4972 #ifdef FEAT_RIGHTLEFT | |
4973 int rlflag; | |
4974 #endif | |
4975 { | |
4976 unsigned off_from; | |
4977 unsigned off_to; | |
1378 | 4978 #ifdef FEAT_MBYTE |
4979 unsigned max_off_from; | |
4980 unsigned max_off_to; | |
4981 #endif | |
7 | 4982 int col = 0; |
4983 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
4984 int hl; | |
4985 #endif | |
4986 int force = FALSE; /* force update rest of the line */ | |
4987 int redraw_this /* bool: does character need redraw? */ | |
4988 #ifdef FEAT_GUI | |
4989 = TRUE /* For GUI when while-loop empty */ | |
4990 #endif | |
4991 ; | |
4992 int redraw_next; /* redraw_this for next character */ | |
4993 #ifdef FEAT_MBYTE | |
4994 int clear_next = FALSE; | |
4995 int char_cells; /* 1: normal char */ | |
4996 /* 2: occupies two display cells */ | |
4997 # define CHAR_CELLS char_cells | |
4998 #else | |
4999 # define CHAR_CELLS 1 | |
5000 #endif | |
5001 | |
5002 # ifdef FEAT_CLIPBOARD | |
5003 clip_may_clear_selection(row, row); | |
5004 # endif | |
5005 | |
5006 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5007 off_to = LineOffset[row] + coloff; | |
1378 | 5008 #ifdef FEAT_MBYTE |
5009 max_off_from = off_from + screen_Columns; | |
5010 max_off_to = LineOffset[row] + screen_Columns; | |
5011 #endif | |
7 | 5012 |
5013 #ifdef FEAT_RIGHTLEFT | |
5014 if (rlflag) | |
5015 { | |
5016 /* Clear rest first, because it's left of the text. */ | |
5017 if (clear_width > 0) | |
5018 { | |
5019 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5020 && ScreenAttrs[off_to] == 0 | |
5021 # ifdef FEAT_MBYTE | |
5022 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5023 # endif | |
5024 ) | |
5025 { | |
5026 ++off_to; | |
5027 ++col; | |
5028 } | |
5029 if (col <= endcol) | |
5030 screen_fill(row, row + 1, col + coloff, | |
5031 endcol + coloff + 1, ' ', ' ', 0); | |
5032 } | |
5033 col = endcol + 1; | |
5034 off_to = LineOffset[row] + col + coloff; | |
5035 off_from += col; | |
5036 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5037 } | |
5038 #endif /* FEAT_RIGHTLEFT */ | |
5039 | |
5040 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5041 | |
5042 while (col < endcol) | |
5043 { | |
5044 #ifdef FEAT_MBYTE | |
5045 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5046 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5047 else |
5048 char_cells = 1; | |
5049 #endif | |
5050 | |
5051 redraw_this = redraw_next; | |
5052 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5053 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5054 | |
5055 #ifdef FEAT_GUI | |
5056 /* If the next character was bold, then redraw the current character to | |
5057 * remove any pixels that might have spilt over into us. This only | |
5058 * happens in the GUI. | |
5059 */ | |
5060 if (redraw_next && gui.in_use) | |
5061 { | |
5062 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5063 if (hl > HL_ALL) |
5064 hl = syn_attr2attr(hl); | |
5065 if (hl & HL_BOLD) | |
7 | 5066 redraw_this = TRUE; |
5067 } | |
5068 #endif | |
5069 | |
5070 if (redraw_this) | |
5071 { | |
5072 /* | |
5073 * Special handling when 'xs' termcap flag set (hpterm): | |
5074 * Attributes for characters are stored at the position where the | |
5075 * cursor is when writing the highlighting code. The | |
5076 * start-highlighting code must be written with the cursor on the | |
5077 * first highlighted character. The stop-highlighting code must | |
5078 * be written with the cursor just after the last highlighted | |
5079 * character. | |
5080 * Overwriting a character doesn't remove it's highlighting. Need | |
5081 * to clear the rest of the line, and force redrawing it | |
5082 * completely. | |
5083 */ | |
5084 if ( p_wiv | |
5085 && !force | |
5086 #ifdef FEAT_GUI | |
5087 && !gui.in_use | |
5088 #endif | |
5089 && ScreenAttrs[off_to] != 0 | |
5090 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5091 { | |
5092 /* | |
5093 * Need to remove highlighting attributes here. | |
5094 */ | |
5095 windgoto(row, col + coloff); | |
5096 out_str(T_CE); /* clear rest of this screen line */ | |
5097 screen_start(); /* don't know where cursor is now */ | |
5098 force = TRUE; /* force redraw of rest of the line */ | |
5099 redraw_next = TRUE; /* or else next char would miss out */ | |
5100 | |
5101 /* | |
5102 * If the previous character was highlighted, need to stop | |
5103 * highlighting at this character. | |
5104 */ | |
5105 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5106 { | |
5107 screen_attr = ScreenAttrs[off_to - 1]; | |
5108 term_windgoto(row, col + coloff); | |
5109 screen_stop_highlight(); | |
5110 } | |
5111 else | |
5112 screen_attr = 0; /* highlighting has stopped */ | |
5113 } | |
5114 #ifdef FEAT_MBYTE | |
5115 if (enc_dbcs != 0) | |
5116 { | |
5117 /* Check if overwriting a double-byte with a single-byte or | |
5118 * the other way around requires another character to be | |
5119 * redrawn. For UTF-8 this isn't needed, because comparing | |
5120 * ScreenLinesUC[] is sufficient. */ | |
5121 if (char_cells == 1 | |
5122 && col + 1 < endcol | |
1378 | 5123 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5124 { |
5125 /* Writing a single-cell character over a double-cell | |
5126 * character: need to redraw the next cell. */ | |
5127 ScreenLines[off_to + 1] = 0; | |
5128 redraw_next = TRUE; | |
5129 } | |
5130 else if (char_cells == 2 | |
5131 && col + 2 < endcol | |
1378 | 5132 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5133 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5134 { |
5135 /* Writing the second half of a double-cell character over | |
5136 * a double-cell character: need to redraw the second | |
5137 * cell. */ | |
5138 ScreenLines[off_to + 2] = 0; | |
5139 redraw_next = TRUE; | |
5140 } | |
5141 | |
5142 if (enc_dbcs == DBCS_JPNU) | |
5143 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5144 } | |
5145 /* When writing a single-width character over a double-width | |
5146 * character and at the end of the redrawn text, need to clear out | |
5147 * the right halve of the old character. | |
5148 * Also required when writing the right halve of a double-width | |
5149 * char over the left halve of an existing one. */ | |
5150 if (has_mbyte && col + char_cells == endcol | |
5151 && ((char_cells == 1 | |
1378 | 5152 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5153 || (char_cells == 2 |
1378 | 5154 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5155 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5156 clear_next = TRUE; |
5157 #endif | |
5158 | |
5159 ScreenLines[off_to] = ScreenLines[off_from]; | |
5160 #ifdef FEAT_MBYTE | |
5161 if (enc_utf8) | |
5162 { | |
5163 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5164 if (ScreenLinesUC[off_from] != 0) | |
5165 { | |
714 | 5166 int i; |
5167 | |
5168 for (i = 0; i < Screen_mco; ++i) | |
5169 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5170 } |
5171 } | |
5172 if (char_cells == 2) | |
5173 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5174 #endif | |
5175 | |
5176 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5177 /* The bold trick makes a single column of pixels appear in the |
5178 * next character. When a bold character is removed, the next | |
7 | 5179 * character should be redrawn too. This happens for our own GUI |
5180 * and for some xterms. */ | |
5181 if ( | |
5182 # ifdef FEAT_GUI | |
5183 gui.in_use | |
5184 # endif | |
5185 # if defined(FEAT_GUI) && defined(UNIX) | |
5186 || | |
5187 # endif | |
5188 # ifdef UNIX | |
5189 term_is_xterm | |
5190 # endif | |
5191 ) | |
5192 { | |
5193 hl = ScreenAttrs[off_to]; | |
743 | 5194 if (hl > HL_ALL) |
5195 hl = syn_attr2attr(hl); | |
5196 if (hl & HL_BOLD) | |
7 | 5197 redraw_next = TRUE; |
5198 } | |
5199 #endif | |
5200 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5201 #ifdef FEAT_MBYTE | |
819 | 5202 /* For simplicity set the attributes of second half of a |
5203 * double-wide character equal to the first half. */ | |
5204 if (char_cells == 2) | |
5205 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5206 | |
7 | 5207 if (enc_dbcs != 0 && char_cells == 2) |
5208 screen_char_2(off_to, row, col + coloff); | |
5209 else | |
5210 #endif | |
5211 screen_char(off_to, row, col + coloff); | |
5212 } | |
5213 else if ( p_wiv | |
5214 #ifdef FEAT_GUI | |
5215 && !gui.in_use | |
5216 #endif | |
5217 && col + coloff > 0) | |
5218 { | |
5219 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5220 { | |
5221 /* | |
5222 * Don't output stop-highlight when moving the cursor, it will | |
5223 * stop the highlighting when it should continue. | |
5224 */ | |
5225 screen_attr = 0; | |
5226 } | |
5227 else if (screen_attr != 0) | |
5228 screen_stop_highlight(); | |
5229 } | |
5230 | |
5231 off_to += CHAR_CELLS; | |
5232 off_from += CHAR_CELLS; | |
5233 col += CHAR_CELLS; | |
5234 } | |
5235 | |
5236 #ifdef FEAT_MBYTE | |
5237 if (clear_next) | |
5238 { | |
5239 /* Clear the second half of a double-wide character of which the left | |
5240 * half was overwritten with a single-wide character. */ | |
5241 ScreenLines[off_to] = ' '; | |
5242 if (enc_utf8) | |
5243 ScreenLinesUC[off_to] = 0; | |
5244 screen_char(off_to, row, col + coloff); | |
5245 } | |
5246 #endif | |
5247 | |
5248 if (clear_width > 0 | |
5249 #ifdef FEAT_RIGHTLEFT | |
5250 && !rlflag | |
5251 #endif | |
5252 ) | |
5253 { | |
5254 #ifdef FEAT_GUI | |
5255 int startCol = col; | |
5256 #endif | |
5257 | |
5258 /* blank out the rest of the line */ | |
5259 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5260 && ScreenAttrs[off_to] == 0 | |
5261 #ifdef FEAT_MBYTE | |
5262 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5263 #endif | |
5264 ) | |
5265 { | |
5266 ++off_to; | |
5267 ++col; | |
5268 } | |
5269 if (col < clear_width) | |
5270 { | |
5271 #ifdef FEAT_GUI | |
5272 /* | |
5273 * In the GUI, clearing the rest of the line may leave pixels | |
5274 * behind if the first character cleared was bold. Some bold | |
5275 * fonts spill over the left. In this case we redraw the previous | |
5276 * character too. If we didn't skip any blanks above, then we | |
5277 * only redraw if the character wasn't already redrawn anyway. | |
5278 */ | |
996 | 5279 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5280 { |
5281 hl = ScreenAttrs[off_to]; | |
5282 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5283 { |
5284 int prev_cells = 1; | |
5285 # ifdef FEAT_MBYTE | |
5286 if (enc_utf8) | |
5287 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5288 * that its width is 2. */ | |
5289 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5290 else if (enc_dbcs != 0) | |
5291 { | |
5292 /* find previous character by counting from first | |
5293 * column and get its width. */ | |
5294 unsigned off = LineOffset[row]; | |
1378 | 5295 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5296 |
5297 while (off < off_to) | |
5298 { | |
1378 | 5299 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5300 off += prev_cells; |
5301 } | |
5302 } | |
5303 | |
5304 if (enc_dbcs != 0 && prev_cells > 1) | |
5305 screen_char_2(off_to - prev_cells, row, | |
5306 col + coloff - prev_cells); | |
5307 else | |
5308 # endif | |
5309 screen_char(off_to - prev_cells, row, | |
5310 col + coloff - prev_cells); | |
5311 } | |
7 | 5312 } |
5313 #endif | |
5314 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5315 ' ', ' ', 0); | |
5316 #ifdef FEAT_VERTSPLIT | |
5317 off_to += clear_width - col; | |
5318 col = clear_width; | |
5319 #endif | |
5320 } | |
5321 } | |
5322 | |
5323 if (clear_width > 0) | |
5324 { | |
5325 #ifdef FEAT_VERTSPLIT | |
5326 /* For a window that's left of another, draw the separator char. */ | |
5327 if (col + coloff < Columns) | |
5328 { | |
5329 int c; | |
5330 | |
5331 c = fillchar_vsep(&hl); | |
5332 if (ScreenLines[off_to] != c | |
5333 # ifdef FEAT_MBYTE | |
714 | 5334 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5335 != (c >= 0x80 ? c : 0)) | |
7 | 5336 # endif |
5337 || ScreenAttrs[off_to] != hl) | |
5338 { | |
5339 ScreenLines[off_to] = c; | |
5340 ScreenAttrs[off_to] = hl; | |
5341 # ifdef FEAT_MBYTE | |
5342 if (enc_utf8) | |
5343 { | |
5344 if (c >= 0x80) | |
5345 { | |
5346 ScreenLinesUC[off_to] = c; | |
714 | 5347 ScreenLinesC[0][off_to] = 0; |
7 | 5348 } |
5349 else | |
5350 ScreenLinesUC[off_to] = 0; | |
5351 } | |
5352 # endif | |
5353 screen_char(off_to, row, col + coloff); | |
5354 } | |
5355 } | |
5356 else | |
5357 #endif | |
5358 LineWraps[row] = FALSE; | |
5359 } | |
5360 } | |
5361 | |
474 | 5362 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5363 /* |
474 | 5364 * Mirror text "str" for right-left displaying. |
5365 * Only works for single-byte characters (e.g., numbers). | |
7 | 5366 */ |
474 | 5367 void |
7 | 5368 rl_mirror(str) |
5369 char_u *str; | |
5370 { | |
5371 char_u *p1, *p2; | |
5372 int t; | |
5373 | |
5374 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5375 { | |
5376 t = *p1; | |
5377 *p1 = *p2; | |
5378 *p2 = t; | |
5379 } | |
5380 } | |
5381 #endif | |
5382 | |
5383 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5384 /* | |
5385 * mark all status lines for redraw; used after first :cd | |
5386 */ | |
5387 void | |
5388 status_redraw_all() | |
5389 { | |
5390 win_T *wp; | |
5391 | |
5392 for (wp = firstwin; wp; wp = wp->w_next) | |
5393 if (wp->w_status_height) | |
5394 { | |
5395 wp->w_redr_status = TRUE; | |
5396 redraw_later(VALID); | |
5397 } | |
5398 } | |
5399 | |
5400 /* | |
5401 * mark all status lines of the current buffer for redraw | |
5402 */ | |
5403 void | |
5404 status_redraw_curbuf() | |
5405 { | |
5406 win_T *wp; | |
5407 | |
5408 for (wp = firstwin; wp; wp = wp->w_next) | |
5409 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5410 { | |
5411 wp->w_redr_status = TRUE; | |
5412 redraw_later(VALID); | |
5413 } | |
5414 } | |
5415 | |
5416 /* | |
5417 * Redraw all status lines that need to be redrawn. | |
5418 */ | |
5419 void | |
5420 redraw_statuslines() | |
5421 { | |
5422 win_T *wp; | |
5423 | |
5424 for (wp = firstwin; wp; wp = wp->w_next) | |
5425 if (wp->w_redr_status) | |
5426 win_redr_status(wp); | |
673 | 5427 if (redraw_tabline) |
677 | 5428 draw_tabline(); |
7 | 5429 } |
5430 #endif | |
5431 | |
5432 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5433 /* | |
5434 * Redraw all status lines at the bottom of frame "frp". | |
5435 */ | |
5436 void | |
5437 win_redraw_last_status(frp) | |
5438 frame_T *frp; | |
5439 { | |
5440 if (frp->fr_layout == FR_LEAF) | |
5441 frp->fr_win->w_redr_status = TRUE; | |
5442 else if (frp->fr_layout == FR_ROW) | |
5443 { | |
5444 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5445 win_redraw_last_status(frp); | |
5446 } | |
5447 else /* frp->fr_layout == FR_COL */ | |
5448 { | |
5449 frp = frp->fr_child; | |
5450 while (frp->fr_next != NULL) | |
5451 frp = frp->fr_next; | |
5452 win_redraw_last_status(frp); | |
5453 } | |
5454 } | |
5455 #endif | |
5456 | |
5457 #ifdef FEAT_VERTSPLIT | |
5458 /* | |
5459 * Draw the verticap separator right of window "wp" starting with line "row". | |
5460 */ | |
5461 static void | |
5462 draw_vsep_win(wp, row) | |
5463 win_T *wp; | |
5464 int row; | |
5465 { | |
5466 int hl; | |
5467 int c; | |
5468 | |
5469 if (wp->w_vsep_width) | |
5470 { | |
5471 /* draw the vertical separator right of this window */ | |
5472 c = fillchar_vsep(&hl); | |
5473 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5474 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5475 c, ' ', hl); | |
5476 } | |
5477 } | |
5478 #endif | |
5479 | |
5480 #ifdef FEAT_WILDMENU | |
5481 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5482 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5483 |
5484 /* | |
1378 | 5485 * Get the length of an item as it will be shown in the status line. |
7 | 5486 */ |
5487 static int | |
5488 status_match_len(xp, s) | |
5489 expand_T *xp; | |
5490 char_u *s; | |
5491 { | |
5492 int len = 0; | |
5493 | |
5494 #ifdef FEAT_MENU | |
5495 int emenu = (xp->xp_context == EXPAND_MENUS | |
5496 || xp->xp_context == EXPAND_MENUNAMES); | |
5497 | |
5498 /* Check for menu separators - replace with '|'. */ | |
5499 if (emenu && menu_is_separator(s)) | |
5500 return 1; | |
5501 #endif | |
5502 | |
5503 while (*s != NUL) | |
5504 { | |
1685 | 5505 s += skip_status_match_char(xp, s); |
42 | 5506 len += ptr2cells(s); |
39 | 5507 mb_ptr_adv(s); |
7 | 5508 } |
5509 | |
5510 return len; | |
5511 } | |
5512 | |
5513 /* | |
1685 | 5514 * Return the number of characters that should be skipped in a status match. |
277 | 5515 * These are backslashes used for escaping. Do show backslashes in help tags. |
5516 */ | |
5517 static int | |
5518 skip_status_match_char(xp, s) | |
5519 expand_T *xp; | |
5520 char_u *s; | |
5521 { | |
1685 | 5522 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5523 #ifdef FEAT_MENU |
5524 || ((xp->xp_context == EXPAND_MENUS | |
5525 || xp->xp_context == EXPAND_MENUNAMES) | |
5526 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5527 #endif | |
1685 | 5528 ) |
5529 { | |
5530 #ifndef BACKSLASH_IN_FILENAME | |
5531 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5532 return 2; | |
5533 #endif | |
5534 return 1; | |
5535 } | |
5536 return 0; | |
277 | 5537 } |
5538 | |
5539 /* | |
7 | 5540 * Show wildchar matches in the status line. |
5541 * Show at least the "match" item. | |
5542 * We start at item 'first_match' in the list and show all matches that fit. | |
5543 * | |
5544 * If inversion is possible we use it. Else '=' characters are used. | |
5545 */ | |
5546 void | |
5547 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5548 expand_T *xp; | |
5549 int num_matches; | |
5550 char_u **matches; /* list of matches */ | |
5551 int match; | |
5552 int showtail; | |
5553 { | |
5554 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5555 int row; | |
5556 char_u *buf; | |
5557 int len; | |
1378 | 5558 int clen; /* length in screen cells */ |
7 | 5559 int fillchar; |
5560 int attr; | |
5561 int i; | |
5562 int highlight = TRUE; | |
5563 char_u *selstart = NULL; | |
5564 int selstart_col = 0; | |
5565 char_u *selend = NULL; | |
5566 static int first_match = 0; | |
5567 int add_left = FALSE; | |
5568 char_u *s; | |
5569 #ifdef FEAT_MENU | |
5570 int emenu; | |
5571 #endif | |
5572 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5573 int l; | |
5574 #endif | |
5575 | |
5576 if (matches == NULL) /* interrupted completion? */ | |
5577 return; | |
5578 | |
39 | 5579 #ifdef FEAT_MBYTE |
5580 if (has_mbyte) | |
5581 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5582 else | |
5583 #endif | |
5584 buf = alloc((unsigned)Columns + 1); | |
7 | 5585 if (buf == NULL) |
5586 return; | |
5587 | |
5588 if (match == -1) /* don't show match but original text */ | |
5589 { | |
5590 match = 0; | |
5591 highlight = FALSE; | |
5592 } | |
5593 /* count 1 for the ending ">" */ | |
5594 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5595 if (match == 0) | |
5596 first_match = 0; | |
5597 else if (match < first_match) | |
5598 { | |
5599 /* jumping left, as far as we can go */ | |
5600 first_match = match; | |
5601 add_left = TRUE; | |
5602 } | |
5603 else | |
5604 { | |
5605 /* check if match fits on the screen */ | |
5606 for (i = first_match; i < match; ++i) | |
5607 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5608 if (first_match > 0) | |
5609 clen += 2; | |
5610 /* jumping right, put match at the left */ | |
5611 if ((long)clen > Columns) | |
5612 { | |
5613 first_match = match; | |
5614 /* if showing the last match, we can add some on the left */ | |
5615 clen = 2; | |
5616 for (i = match; i < num_matches; ++i) | |
5617 { | |
5618 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5619 if ((long)clen >= Columns) | |
5620 break; | |
5621 } | |
5622 if (i == num_matches) | |
5623 add_left = TRUE; | |
5624 } | |
5625 } | |
5626 if (add_left) | |
5627 while (first_match > 0) | |
5628 { | |
5629 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5630 if ((long)clen >= Columns) | |
5631 break; | |
5632 --first_match; | |
5633 } | |
5634 | |
5635 fillchar = fillchar_status(&attr, TRUE); | |
5636 | |
5637 if (first_match == 0) | |
5638 { | |
5639 *buf = NUL; | |
5640 len = 0; | |
5641 } | |
5642 else | |
5643 { | |
5644 STRCPY(buf, "< "); | |
5645 len = 2; | |
5646 } | |
5647 clen = len; | |
5648 | |
5649 i = first_match; | |
5650 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
5651 { | |
5652 if (i == match) | |
5653 { | |
5654 selstart = buf + len; | |
5655 selstart_col = clen; | |
5656 } | |
5657 | |
5658 s = L_MATCH(i); | |
5659 /* Check for menu separators - replace with '|' */ | |
5660 #ifdef FEAT_MENU | |
5661 emenu = (xp->xp_context == EXPAND_MENUS | |
5662 || xp->xp_context == EXPAND_MENUNAMES); | |
5663 if (emenu && menu_is_separator(s)) | |
5664 { | |
5665 STRCPY(buf + len, transchar('|')); | |
5666 l = (int)STRLEN(buf + len); | |
5667 len += l; | |
5668 clen += l; | |
5669 } | |
5670 else | |
5671 #endif | |
5672 for ( ; *s != NUL; ++s) | |
5673 { | |
1685 | 5674 s += skip_status_match_char(xp, s); |
7 | 5675 clen += ptr2cells(s); |
5676 #ifdef FEAT_MBYTE | |
474 | 5677 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 5678 { |
5679 STRNCPY(buf + len, s, l); | |
5680 s += l - 1; | |
5681 len += l; | |
5682 } | |
5683 else | |
5684 #endif | |
5685 { | |
5686 STRCPY(buf + len, transchar_byte(*s)); | |
5687 len += (int)STRLEN(buf + len); | |
5688 } | |
5689 } | |
5690 if (i == match) | |
5691 selend = buf + len; | |
5692 | |
5693 *(buf + len++) = ' '; | |
5694 *(buf + len++) = ' '; | |
5695 clen += 2; | |
5696 if (++i == num_matches) | |
5697 break; | |
5698 } | |
5699 | |
5700 if (i != num_matches) | |
5701 { | |
5702 *(buf + len++) = '>'; | |
5703 ++clen; | |
5704 } | |
5705 | |
5706 buf[len] = NUL; | |
5707 | |
5708 row = cmdline_row - 1; | |
5709 if (row >= 0) | |
5710 { | |
5711 if (wild_menu_showing == 0) | |
5712 { | |
5713 if (msg_scrolled > 0) | |
5714 { | |
5715 /* Put the wildmenu just above the command line. If there is | |
5716 * no room, scroll the screen one line up. */ | |
5717 if (cmdline_row == Rows - 1) | |
5718 { | |
5719 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
5720 ++msg_scrolled; | |
5721 } | |
5722 else | |
5723 { | |
5724 ++cmdline_row; | |
5725 ++row; | |
5726 } | |
5727 wild_menu_showing = WM_SCROLLED; | |
5728 } | |
5729 else | |
5730 { | |
5731 /* Create status line if needed by setting 'laststatus' to 2. | |
5732 * Set 'winminheight' to zero to avoid that the window is | |
5733 * resized. */ | |
5734 if (lastwin->w_status_height == 0) | |
5735 { | |
5736 save_p_ls = p_ls; | |
5737 save_p_wmh = p_wmh; | |
5738 p_ls = 2; | |
5739 p_wmh = 0; | |
5740 last_status(FALSE); | |
5741 } | |
5742 wild_menu_showing = WM_SHOWN; | |
5743 } | |
5744 } | |
5745 | |
5746 screen_puts(buf, row, 0, attr); | |
5747 if (selstart != NULL && highlight) | |
5748 { | |
5749 *selend = NUL; | |
5750 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
5751 } | |
5752 | |
5753 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
5754 } | |
5755 | |
5756 #ifdef FEAT_VERTSPLIT | |
5757 win_redraw_last_status(topframe); | |
5758 #else | |
5759 lastwin->w_redr_status = TRUE; | |
5760 #endif | |
5761 vim_free(buf); | |
5762 } | |
5763 #endif | |
5764 | |
5765 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5766 /* | |
5767 * Redraw the status line of window wp. | |
5768 * | |
5769 * If inversion is possible we use it. Else '=' characters are used. | |
5770 */ | |
5771 void | |
5772 win_redr_status(wp) | |
5773 win_T *wp; | |
5774 { | |
5775 int row; | |
5776 char_u *p; | |
5777 int len; | |
5778 int fillchar; | |
5779 int attr; | |
5780 int this_ru_col; | |
1910 | 5781 static int busy = FALSE; |
5782 | |
5783 /* It's possible to get here recursively when 'statusline' (indirectly) | |
5784 * invokes ":redrawstatus". Simply ignore the call then. */ | |
5785 if (busy) | |
5786 return; | |
5787 busy = TRUE; | |
7 | 5788 |
5789 wp->w_redr_status = FALSE; | |
5790 if (wp->w_status_height == 0) | |
5791 { | |
5792 /* no status line, can only be last window */ | |
5793 redraw_cmdline = TRUE; | |
5794 } | |
540 | 5795 else if (!redrawing() |
5796 #ifdef FEAT_INS_EXPAND | |
5797 /* don't update status line when popup menu is visible and may be | |
5798 * drawn over it */ | |
5799 || pum_visible() | |
5800 #endif | |
5801 ) | |
7 | 5802 { |
5803 /* Don't redraw right now, do it later. */ | |
5804 wp->w_redr_status = TRUE; | |
5805 } | |
5806 #ifdef FEAT_STL_OPT | |
40 | 5807 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 5808 { |
5809 /* redraw custom status line */ | |
1983 | 5810 redraw_custom_statusline(wp); |
7 | 5811 } |
5812 #endif | |
5813 else | |
5814 { | |
5815 fillchar = fillchar_status(&attr, wp == curwin); | |
5816 | |
685 | 5817 get_trans_bufname(wp->w_buffer); |
7 | 5818 p = NameBuff; |
5819 len = (int)STRLEN(p); | |
5820 | |
5821 if (wp->w_buffer->b_help | |
5822 #ifdef FEAT_QUICKFIX | |
5823 || wp->w_p_pvw | |
5824 #endif | |
5825 || bufIsChanged(wp->w_buffer) | |
5826 || wp->w_buffer->b_p_ro) | |
5827 *(p + len++) = ' '; | |
5828 if (wp->w_buffer->b_help) | |
5829 { | |
809 | 5830 STRCPY(p + len, _("[Help]")); |
7 | 5831 len += (int)STRLEN(p + len); |
5832 } | |
5833 #ifdef FEAT_QUICKFIX | |
5834 if (wp->w_p_pvw) | |
5835 { | |
5836 STRCPY(p + len, _("[Preview]")); | |
5837 len += (int)STRLEN(p + len); | |
5838 } | |
5839 #endif | |
5840 if (bufIsChanged(wp->w_buffer)) | |
5841 { | |
5842 STRCPY(p + len, "[+]"); | |
5843 len += 3; | |
5844 } | |
5845 if (wp->w_buffer->b_p_ro) | |
5846 { | |
5847 STRCPY(p + len, "[RO]"); | |
5848 len += 4; | |
5849 } | |
5850 | |
5851 #ifndef FEAT_VERTSPLIT | |
5852 this_ru_col = ru_col; | |
5853 if (this_ru_col < (Columns + 1) / 2) | |
5854 this_ru_col = (Columns + 1) / 2; | |
5855 #else | |
5856 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
5857 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
5858 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
5859 if (this_ru_col <= 1) | |
5860 { | |
5861 p = (char_u *)"<"; /* No room for file name! */ | |
5862 len = 1; | |
5863 } | |
5864 else | |
5865 #endif | |
5866 #ifdef FEAT_MBYTE | |
5867 if (has_mbyte) | |
5868 { | |
5869 int clen = 0, i; | |
5870 | |
5871 /* Count total number of display cells. */ | |
474 | 5872 for (i = 0; p[i] != NUL; i += (*mb_ptr2len)(p + i)) |
7 | 5873 clen += (*mb_ptr2cells)(p + i); |
5874 /* Find first character that will fit. | |
5875 * Going from start to end is much faster for DBCS. */ | |
5876 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 5877 i += (*mb_ptr2len)(p + i)) |
7 | 5878 clen -= (*mb_ptr2cells)(p + i); |
5879 len = clen; | |
5880 if (i > 0) | |
5881 { | |
5882 p = p + i - 1; | |
5883 *p = '<'; | |
5884 ++len; | |
5885 } | |
5886 | |
5887 } | |
5888 else | |
5889 #endif | |
5890 if (len > this_ru_col - 1) | |
5891 { | |
5892 p += len - (this_ru_col - 1); | |
5893 *p = '<'; | |
5894 len = this_ru_col - 1; | |
5895 } | |
5896 | |
5897 row = W_WINROW(wp) + wp->w_height; | |
5898 screen_puts(p, row, W_WINCOL(wp), attr); | |
5899 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
5900 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
5901 | |
5902 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
5903 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
5904 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
5905 - 1 + W_WINCOL(wp)), attr); | |
5906 | |
5907 #ifdef FEAT_CMDL_INFO | |
5908 win_redr_ruler(wp, TRUE); | |
5909 #endif | |
5910 } | |
5911 | |
5912 #ifdef FEAT_VERTSPLIT | |
5913 /* | |
5914 * May need to draw the character below the vertical separator. | |
5915 */ | |
5916 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
5917 { | |
5918 if (stl_connected(wp)) | |
5919 fillchar = fillchar_status(&attr, wp == curwin); | |
5920 else | |
5921 fillchar = fillchar_vsep(&attr); | |
5922 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
5923 attr); | |
5924 } | |
5925 #endif | |
1910 | 5926 busy = FALSE; |
7 | 5927 } |
5928 | |
680 | 5929 #ifdef FEAT_STL_OPT |
5930 /* | |
5931 * Redraw the status line according to 'statusline' and take care of any | |
5932 * errors encountered. | |
5933 */ | |
5934 static void | |
1983 | 5935 redraw_custom_statusline(wp) |
680 | 5936 win_T *wp; |
5937 { | |
1983 | 5938 static int entered = FALSE; |
5939 int save_called_emsg = called_emsg; | |
5940 | |
5941 /* When called recursively return. This can happen when the statusline | |
5942 * contains an expression that triggers a redraw. */ | |
5943 if (entered) | |
5944 return; | |
5945 entered = TRUE; | |
680 | 5946 |
5947 called_emsg = FALSE; | |
5948 win_redr_custom(wp, FALSE); | |
5949 if (called_emsg) | |
1983 | 5950 { |
5951 /* When there is an error disable the statusline, otherwise the | |
5952 * display is messed up with errors and a redraw triggers the problem | |
5953 * again and again. */ | |
680 | 5954 set_string_option_direct((char_u *)"statusline", -1, |
5955 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 5956 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 5957 } |
680 | 5958 called_emsg |= save_called_emsg; |
1983 | 5959 entered = FALSE; |
680 | 5960 } |
5961 #endif | |
5962 | |
7 | 5963 # ifdef FEAT_VERTSPLIT |
5964 /* | |
5965 * Return TRUE if the status line of window "wp" is connected to the status | |
5966 * line of the window right of it. If not, then it's a vertical separator. | |
5967 * Only call if (wp->w_vsep_width != 0). | |
5968 */ | |
5969 int | |
5970 stl_connected(wp) | |
5971 win_T *wp; | |
5972 { | |
5973 frame_T *fr; | |
5974 | |
5975 fr = wp->w_frame; | |
5976 while (fr->fr_parent != NULL) | |
5977 { | |
5978 if (fr->fr_parent->fr_layout == FR_COL) | |
5979 { | |
5980 if (fr->fr_next != NULL) | |
5981 break; | |
5982 } | |
5983 else | |
5984 { | |
5985 if (fr->fr_next != NULL) | |
5986 return TRUE; | |
5987 } | |
5988 fr = fr->fr_parent; | |
5989 } | |
5990 return FALSE; | |
5991 } | |
5992 # endif | |
5993 | |
5994 #endif /* FEAT_WINDOWS */ | |
5995 | |
5996 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
5997 /* | |
5998 * Get the value to show for the language mappings, active 'keymap'. | |
5999 */ | |
6000 int | |
6001 get_keymap_str(wp, buf, len) | |
6002 win_T *wp; | |
6003 char_u *buf; /* buffer for the result */ | |
6004 int len; /* length of buffer */ | |
6005 { | |
6006 char_u *p; | |
6007 | |
6008 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6009 return FALSE; | |
6010 | |
6011 { | |
6012 #ifdef FEAT_EVAL | |
6013 buf_T *old_curbuf = curbuf; | |
6014 win_T *old_curwin = curwin; | |
6015 char_u *s; | |
6016 | |
6017 curbuf = wp->w_buffer; | |
6018 curwin = wp; | |
6019 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6020 ++emsg_skip; | |
714 | 6021 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6022 --emsg_skip; |
6023 curbuf = old_curbuf; | |
6024 curwin = old_curwin; | |
6025 if (p == NULL || *p == NUL) | |
6026 #endif | |
6027 { | |
6028 #ifdef FEAT_KEYMAP | |
6029 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6030 p = wp->w_buffer->b_p_keymap; | |
6031 else | |
6032 #endif | |
6033 p = (char_u *)"lang"; | |
6034 } | |
6035 if ((int)(STRLEN(p) + 3) < len) | |
6036 sprintf((char *)buf, "<%s>", p); | |
6037 else | |
6038 buf[0] = NUL; | |
6039 #ifdef FEAT_EVAL | |
6040 vim_free(s); | |
6041 #endif | |
6042 } | |
6043 return buf[0] != NUL; | |
6044 } | |
6045 #endif | |
6046 | |
6047 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6048 /* | |
677 | 6049 * Redraw the status line or ruler of window "wp". |
6050 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6051 */ |
6052 static void | |
574 | 6053 win_redr_custom(wp, draw_ruler) |
7 | 6054 win_T *wp; |
574 | 6055 int draw_ruler; /* TRUE or FALSE */ |
7 | 6056 { |
6057 int attr; | |
6058 int curattr; | |
6059 int row; | |
6060 int col = 0; | |
6061 int maxwidth; | |
6062 int width; | |
6063 int n; | |
6064 int len; | |
6065 int fillchar; | |
6066 char_u buf[MAXPATHL]; | |
1983 | 6067 char_u *stl; |
7 | 6068 char_u *p; |
681 | 6069 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6070 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6071 int use_sandbox = FALSE; |
7 | 6072 |
6073 /* setup environment for the task at hand */ | |
677 | 6074 if (wp == NULL) |
6075 { | |
6076 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6077 stl = p_tal; |
677 | 6078 row = 0; |
707 | 6079 fillchar = ' '; |
677 | 6080 attr = hl_attr(HLF_TPF); |
6081 maxwidth = Columns; | |
6082 # ifdef FEAT_EVAL | |
681 | 6083 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6084 # endif |
6085 } | |
40 | 6086 else |
677 | 6087 { |
6088 row = W_WINROW(wp) + wp->w_height; | |
6089 fillchar = fillchar_status(&attr, wp == curwin); | |
6090 maxwidth = W_WIDTH(wp); | |
6091 | |
6092 if (draw_ruler) | |
6093 { | |
1983 | 6094 stl = p_ruf; |
677 | 6095 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6096 if (*stl == '%') |
6097 { | |
6098 if (*++stl == '-') | |
6099 stl++; | |
6100 if (atoi((char *)stl)) | |
6101 while (VIM_ISDIGIT(*stl)) | |
6102 stl++; | |
6103 if (*stl++ != '(') | |
6104 stl = p_ruf; | |
677 | 6105 } |
7 | 6106 #ifdef FEAT_VERTSPLIT |
677 | 6107 col = ru_col - (Columns - W_WIDTH(wp)); |
6108 if (col < (W_WIDTH(wp) + 1) / 2) | |
6109 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6110 #else |
677 | 6111 col = ru_col; |
6112 if (col > (Columns + 1) / 2) | |
6113 col = (Columns + 1) / 2; | |
6114 #endif | |
6115 maxwidth = W_WIDTH(wp) - col; | |
7 | 6116 #ifdef FEAT_WINDOWS |
677 | 6117 if (!wp->w_status_height) |
6118 #endif | |
6119 { | |
6120 row = Rows - 1; | |
6121 --maxwidth; /* writing in last column may cause scrolling */ | |
6122 fillchar = ' '; | |
6123 attr = 0; | |
6124 } | |
6125 | |
6126 # ifdef FEAT_EVAL | |
681 | 6127 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6128 # endif |
6129 } | |
6130 else | |
6131 { | |
6132 if (*wp->w_p_stl != NUL) | |
1983 | 6133 stl = wp->w_p_stl; |
677 | 6134 else |
1983 | 6135 stl = p_stl; |
677 | 6136 # ifdef FEAT_EVAL |
681 | 6137 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6138 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6139 # endif |
6140 } | |
6141 | |
6142 #ifdef FEAT_VERTSPLIT | |
6143 col += W_WINCOL(wp); | |
6144 #endif | |
6145 } | |
6146 | |
7 | 6147 if (maxwidth <= 0) |
6148 return; | |
677 | 6149 |
1983 | 6150 /* Make a copy, because the statusline may include a function call that |
6151 * might change the option value and free the memory. */ | |
6152 stl = vim_strsave(stl); | |
677 | 6153 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6154 buf, sizeof(buf), | |
1983 | 6155 stl, use_sandbox, |
681 | 6156 fillchar, maxwidth, hltab, tabtab); |
1983 | 6157 vim_free(stl); |
835 | 6158 len = (int)STRLEN(buf); |
7 | 6159 |
1883 | 6160 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6161 { |
6162 #ifdef FEAT_MBYTE | |
6163 len += (*mb_char2bytes)(fillchar, buf + len); | |
6164 #else | |
6165 buf[len++] = fillchar; | |
6166 #endif | |
6167 ++width; | |
6168 } | |
6169 buf[len] = NUL; | |
6170 | |
681 | 6171 /* |
6172 * Draw each snippet with the specified highlighting. | |
6173 */ | |
7 | 6174 curattr = attr; |
6175 p = buf; | |
681 | 6176 for (n = 0; hltab[n].start != NULL; n++) |
6177 { | |
6178 len = (int)(hltab[n].start - p); | |
7 | 6179 screen_puts_len(p, len, row, col, curattr); |
6180 col += vim_strnsize(p, len); | |
681 | 6181 p = hltab[n].start; |
6182 | |
6183 if (hltab[n].userhl == 0) | |
7 | 6184 curattr = attr; |
681 | 6185 else if (hltab[n].userhl < 0) |
6186 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6187 #ifdef FEAT_WINDOWS |
680 | 6188 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6189 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6190 #endif |
6191 else | |
681 | 6192 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6193 } |
6194 screen_puts(p, row, col, curattr); | |
681 | 6195 |
6196 if (wp == NULL) | |
6197 { | |
6198 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6199 col = 0; | |
6200 len = 0; | |
6201 p = buf; | |
6202 fillchar = 0; | |
6203 for (n = 0; tabtab[n].start != NULL; n++) | |
6204 { | |
6205 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6206 while (col < len) | |
6207 TabPageIdxs[col++] = fillchar; | |
6208 p = tabtab[n].start; | |
6209 fillchar = tabtab[n].userhl; | |
6210 } | |
6211 while (col < Columns) | |
6212 TabPageIdxs[col++] = fillchar; | |
6213 } | |
7 | 6214 } |
6215 | |
6216 #endif /* FEAT_STL_OPT */ | |
6217 | |
6218 /* | |
6219 * Output a single character directly to the screen and update ScreenLines. | |
6220 */ | |
6221 void | |
6222 screen_putchar(c, row, col, attr) | |
6223 int c; | |
6224 int row, col; | |
6225 int attr; | |
6226 { | |
6227 #ifdef FEAT_MBYTE | |
6228 char_u buf[MB_MAXBYTES + 1]; | |
6229 | |
6230 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6231 #else | |
6232 char_u buf[2]; | |
6233 | |
6234 buf[0] = c; | |
6235 buf[1] = NUL; | |
6236 #endif | |
6237 screen_puts(buf, row, col, attr); | |
6238 } | |
6239 | |
6240 /* | |
6241 * Get a single character directly from ScreenLines into "bytes[]". | |
6242 * Also return its attribute in *attrp; | |
6243 */ | |
6244 void | |
6245 screen_getbytes(row, col, bytes, attrp) | |
6246 int row, col; | |
6247 char_u *bytes; | |
6248 int *attrp; | |
6249 { | |
6250 unsigned off; | |
6251 | |
6252 /* safety check */ | |
6253 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6254 { | |
6255 off = LineOffset[row] + col; | |
6256 *attrp = ScreenAttrs[off]; | |
6257 bytes[0] = ScreenLines[off]; | |
6258 bytes[1] = NUL; | |
6259 | |
6260 #ifdef FEAT_MBYTE | |
6261 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6262 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6263 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6264 { | |
6265 bytes[0] = ScreenLines[off]; | |
6266 bytes[1] = ScreenLines2[off]; | |
6267 bytes[2] = NUL; | |
6268 } | |
6269 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6270 { | |
6271 bytes[1] = ScreenLines[off + 1]; | |
6272 bytes[2] = NUL; | |
6273 } | |
6274 #endif | |
6275 } | |
6276 } | |
6277 | |
714 | 6278 #ifdef FEAT_MBYTE |
6279 static int screen_comp_differs __ARGS((int, int*)); | |
6280 | |
6281 /* | |
6282 * Return TRUE if composing characters for screen posn "off" differs from | |
6283 * composing characters in "u8cc". | |
6284 */ | |
6285 static int | |
6286 screen_comp_differs(off, u8cc) | |
6287 int off; | |
6288 int *u8cc; | |
6289 { | |
6290 int i; | |
6291 | |
6292 for (i = 0; i < Screen_mco; ++i) | |
6293 { | |
6294 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6295 return TRUE; | |
6296 if (u8cc[i] == 0) | |
6297 break; | |
6298 } | |
6299 return FALSE; | |
6300 } | |
6301 #endif | |
6302 | |
7 | 6303 /* |
6304 * Put string '*text' on the screen at position 'row' and 'col', with | |
6305 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6306 * Note: only outputs within one row, message is truncated at screen boundary! | |
6307 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6308 */ | |
6309 void | |
6310 screen_puts(text, row, col, attr) | |
6311 char_u *text; | |
6312 int row; | |
6313 int col; | |
6314 int attr; | |
6315 { | |
6316 screen_puts_len(text, -1, row, col, attr); | |
6317 } | |
6318 | |
6319 /* | |
6320 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6321 * a NUL. | |
6322 */ | |
6323 void | |
6324 screen_puts_len(text, len, row, col, attr) | |
6325 char_u *text; | |
6326 int len; | |
6327 int row; | |
6328 int col; | |
6329 int attr; | |
6330 { | |
6331 unsigned off; | |
6332 char_u *ptr = text; | |
6333 int c; | |
6334 #ifdef FEAT_MBYTE | |
1378 | 6335 unsigned max_off; |
7 | 6336 int mbyte_blen = 1; |
6337 int mbyte_cells = 1; | |
6338 int u8c = 0; | |
714 | 6339 int u8cc[MAX_MCO]; |
7 | 6340 int clear_next_cell = FALSE; |
6341 # ifdef FEAT_ARABIC | |
6342 int prev_c = 0; /* previous Arabic character */ | |
714 | 6343 int pc, nc, nc1; |
6344 int pcc[MAX_MCO]; | |
7 | 6345 # endif |
6346 #endif | |
1843 | 6347 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6348 int force_redraw_this; | |
6349 int force_redraw_next = FALSE; | |
6350 #endif | |
6351 int need_redraw; | |
7 | 6352 |
6353 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6354 return; | |
1843 | 6355 off = LineOffset[row] + col; |
7 | 6356 |
1668 | 6357 #ifdef FEAT_MBYTE |
6358 /* When drawing over the right halve of a double-wide char clear out the | |
6359 * left halve. Only needed in a terminal. */ | |
1685 | 6360 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6361 # ifdef FEAT_GUI |
6362 && !gui.in_use | |
6363 # endif | |
6364 && mb_fix_col(col, row) != col) | |
1843 | 6365 { |
6366 ScreenLines[off - 1] = ' '; | |
6367 ScreenAttrs[off - 1] = 0; | |
6368 if (enc_utf8) | |
6369 { | |
6370 ScreenLinesUC[off - 1] = 0; | |
6371 ScreenLinesC[0][off - 1] = 0; | |
6372 } | |
6373 /* redraw the previous cell, make it empty */ | |
6374 screen_char(off - 1, row, col - 1); | |
6375 /* force the cell at "col" to be redrawn */ | |
6376 force_redraw_next = TRUE; | |
6377 } | |
6378 #endif | |
6379 | |
1378 | 6380 #ifdef FEAT_MBYTE |
6381 max_off = LineOffset[row] + screen_Columns; | |
6382 #endif | |
1340 | 6383 while (col < screen_Columns |
6384 && (len < 0 || (int)(ptr - text) < len) | |
6385 && *ptr != NUL) | |
7 | 6386 { |
6387 c = *ptr; | |
6388 #ifdef FEAT_MBYTE | |
6389 /* check if this is the first byte of a multibyte */ | |
6390 if (has_mbyte) | |
6391 { | |
6392 if (enc_utf8 && len > 0) | |
474 | 6393 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6394 else |
474 | 6395 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6396 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6397 mbyte_cells = 1; | |
6398 else if (enc_dbcs != 0) | |
6399 mbyte_cells = mbyte_blen; | |
6400 else /* enc_utf8 */ | |
6401 { | |
6402 if (len >= 0) | |
714 | 6403 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6404 (int)((text + len) - ptr)); |
6405 else | |
714 | 6406 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6407 mbyte_cells = utf_char2cells(u8c); |
1401 | 6408 # ifdef UNICODE16 |
7 | 6409 /* Non-BMP character: display as ? or fullwidth ?. */ |
6410 if (u8c >= 0x10000) | |
6411 { | |
6412 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6413 if (attr == 0) | |
6414 attr = hl_attr(HLF_8); | |
6415 } | |
1401 | 6416 # endif |
7 | 6417 # ifdef FEAT_ARABIC |
6418 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6419 { | |
6420 /* Do Arabic shaping. */ | |
6421 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6422 { | |
6423 /* Past end of string to be displayed. */ | |
6424 nc = NUL; | |
6425 nc1 = NUL; | |
6426 } | |
6427 else | |
714 | 6428 { |
1994 | 6429 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6430 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6431 nc1 = pcc[0]; |
6432 } | |
7 | 6433 pc = prev_c; |
6434 prev_c = u8c; | |
714 | 6435 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6436 } |
6437 else | |
6438 prev_c = u8c; | |
6439 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6440 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6441 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6442 /* Only 1 cell left, but character requires 2 cells: |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6443 * display a '>' in the last column to avoid wrapping. */ |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6444 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6445 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6446 } |
7 | 6447 } |
6448 } | |
6449 #endif | |
6450 | |
1843 | 6451 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6452 force_redraw_this = force_redraw_next; | |
6453 force_redraw_next = FALSE; | |
6454 #endif | |
6455 | |
6456 need_redraw = ScreenLines[off] != c | |
7 | 6457 #ifdef FEAT_MBYTE |
6458 || (mbyte_cells == 2 | |
6459 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6460 || (enc_dbcs == DBCS_JPNU | |
6461 && c == 0x8e | |
6462 && ScreenLines2[off] != ptr[1]) | |
6463 || (enc_utf8 | |
1821 | 6464 && (ScreenLinesUC[off] != (u8char_T)(c >= 0x80 ? u8c : 0) |
714 | 6465 || screen_comp_differs(off, u8cc))) |
7 | 6466 #endif |
6467 || ScreenAttrs[off] != attr | |
1843 | 6468 || exmode_active; |
6469 | |
6470 if (need_redraw | |
6471 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6472 || force_redraw_this | |
6473 #endif | |
7 | 6474 ) |
6475 { | |
6476 #if defined(FEAT_GUI) || defined(UNIX) | |
6477 /* The bold trick makes a single row of pixels appear in the next | |
6478 * character. When a bold character is removed, the next | |
6479 * character should be redrawn too. This happens for our own GUI | |
1843 | 6480 * and for some xterms. */ |
6481 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6482 # ifdef FEAT_GUI |
6483 gui.in_use | |
6484 # endif | |
6485 # if defined(FEAT_GUI) && defined(UNIX) | |
6486 || | |
6487 # endif | |
6488 # ifdef UNIX | |
6489 term_is_xterm | |
6490 # endif | |
1843 | 6491 )) |
6492 { | |
6493 int n = ScreenAttrs[off]; | |
6494 | |
6495 if (n > HL_ALL) | |
6496 n = syn_attr2attr(n); | |
6497 if (n & HL_BOLD) | |
6498 force_redraw_next = TRUE; | |
7 | 6499 } |
6500 #endif | |
6501 #ifdef FEAT_MBYTE | |
6502 /* When at the end of the text and overwriting a two-cell | |
6503 * character with a one-cell character, need to clear the next | |
6504 * cell. Also when overwriting the left halve of a two-cell char | |
6505 * with the right halve of a two-cell char. Do this only once | |
6506 * (mb_off2cells() may return 2 on the right halve). */ | |
6507 if (clear_next_cell) | |
6508 clear_next_cell = FALSE; | |
6509 else if (has_mbyte | |
6510 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6511 : ptr + mbyte_blen >= text + len) | |
1378 | 6512 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6513 || (mbyte_cells == 2 |
1378 | 6514 && (*mb_off2cells)(off, max_off) == 1 |
6515 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6516 clear_next_cell = TRUE; |
6517 | |
6518 /* Make sure we never leave a second byte of a double-byte behind, | |
6519 * it confuses mb_off2cells(). */ | |
6520 if (enc_dbcs | |
1378 | 6521 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6522 || (mbyte_cells == 2 |
1378 | 6523 && (*mb_off2cells)(off, max_off) == 1 |
6524 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6525 ScreenLines[off + mbyte_blen] = 0; |
6526 #endif | |
6527 ScreenLines[off] = c; | |
6528 ScreenAttrs[off] = attr; | |
6529 #ifdef FEAT_MBYTE | |
6530 if (enc_utf8) | |
6531 { | |
714 | 6532 if (c < 0x80 && u8cc[0] == 0) |
7 | 6533 ScreenLinesUC[off] = 0; |
6534 else | |
6535 { | |
714 | 6536 int i; |
6537 | |
7 | 6538 ScreenLinesUC[off] = u8c; |
714 | 6539 for (i = 0; i < Screen_mco; ++i) |
6540 { | |
6541 ScreenLinesC[i][off] = u8cc[i]; | |
6542 if (u8cc[i] == 0) | |
6543 break; | |
6544 } | |
7 | 6545 } |
6546 if (mbyte_cells == 2) | |
6547 { | |
6548 ScreenLines[off + 1] = 0; | |
6549 ScreenAttrs[off + 1] = attr; | |
6550 } | |
6551 screen_char(off, row, col); | |
6552 } | |
6553 else if (mbyte_cells == 2) | |
6554 { | |
6555 ScreenLines[off + 1] = ptr[1]; | |
6556 ScreenAttrs[off + 1] = attr; | |
6557 screen_char_2(off, row, col); | |
6558 } | |
6559 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6560 { | |
6561 ScreenLines2[off] = ptr[1]; | |
6562 screen_char(off, row, col); | |
6563 } | |
6564 else | |
6565 #endif | |
6566 screen_char(off, row, col); | |
6567 } | |
6568 #ifdef FEAT_MBYTE | |
6569 if (has_mbyte) | |
6570 { | |
6571 off += mbyte_cells; | |
6572 col += mbyte_cells; | |
6573 ptr += mbyte_blen; | |
6574 if (clear_next_cell) | |
6575 ptr = (char_u *)" "; | |
6576 } | |
6577 else | |
6578 #endif | |
6579 { | |
6580 ++off; | |
6581 ++col; | |
6582 ++ptr; | |
6583 } | |
6584 } | |
1843 | 6585 |
6586 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6587 /* If we detected the next character needs to be redrawn, but the text | |
6588 * doesn't extend up to there, update the character here. */ | |
6589 if (force_redraw_next && col < screen_Columns) | |
6590 { | |
6591 # ifdef FEAT_MBYTE | |
6592 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6593 screen_char_2(off, row, col); | |
6594 else | |
6595 # endif | |
6596 screen_char(off, row, col); | |
6597 } | |
6598 #endif | |
7 | 6599 } |
6600 | |
6601 #ifdef FEAT_SEARCH_EXTRA | |
6602 /* | |
1326 | 6603 * Prepare for 'hlsearch' highlighting. |
7 | 6604 */ |
6605 static void | |
6606 start_search_hl() | |
6607 { | |
6608 if (p_hls && !no_hlsearch) | |
6609 { | |
6610 last_pat_prog(&search_hl.rm); | |
6611 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6612 # ifdef FEAT_RELTIME |
6613 /* Set the time limit to 'redrawtime'. */ | |
6614 profile_setlimit(p_rdt, &search_hl.tm); | |
6615 # endif | |
7 | 6616 } |
6617 } | |
6618 | |
6619 /* | |
1326 | 6620 * Clean up for 'hlsearch' highlighting. |
7 | 6621 */ |
6622 static void | |
6623 end_search_hl() | |
6624 { | |
6625 if (search_hl.rm.regprog != NULL) | |
6626 { | |
6627 vim_free(search_hl.rm.regprog); | |
6628 search_hl.rm.regprog = NULL; | |
6629 } | |
6630 } | |
6631 | |
6632 /* | |
6633 * Advance to the match in window "wp" line "lnum" or past it. | |
6634 */ | |
6635 static void | |
6636 prepare_search_hl(wp, lnum) | |
6637 win_T *wp; | |
6638 linenr_T lnum; | |
6639 { | |
1326 | 6640 matchitem_T *cur; /* points to the match list */ |
6641 match_T *shl; /* points to search_hl or a match */ | |
6642 int shl_flag; /* flag to indicate whether search_hl | |
6643 has been processed or not */ | |
7 | 6644 int n; |
6645 | |
6646 /* | |
6647 * When using a multi-line pattern, start searching at the top | |
6648 * of the window or just after a closed fold. | |
1326 | 6649 * Do this both for search_hl and the match list. |
7 | 6650 */ |
1326 | 6651 cur = wp->w_match_head; |
6652 shl_flag = FALSE; | |
6653 while (cur != NULL || shl_flag == FALSE) | |
6654 { | |
6655 if (shl_flag == FALSE) | |
6656 { | |
6657 shl = &search_hl; | |
6658 shl_flag = TRUE; | |
6659 } | |
6660 else | |
6661 shl = &cur->hl; | |
7 | 6662 if (shl->rm.regprog != NULL |
6663 && shl->lnum == 0 | |
6664 && re_multiline(shl->rm.regprog)) | |
6665 { | |
6666 if (shl->first_lnum == 0) | |
6667 { | |
6668 # ifdef FEAT_FOLDING | |
6669 for (shl->first_lnum = lnum; | |
6670 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
6671 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
6672 NULL, NULL, TRUE, NULL)) | |
6673 break; | |
6674 # else | |
6675 shl->first_lnum = wp->w_topline; | |
6676 # endif | |
6677 } | |
6678 n = 0; | |
6679 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
6680 { | |
6681 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
6682 if (shl->lnum != 0) | |
6683 { | |
6684 shl->first_lnum = shl->lnum | |
6685 + shl->rm.endpos[0].lnum | |
6686 - shl->rm.startpos[0].lnum; | |
6687 n = shl->rm.endpos[0].col; | |
6688 } | |
6689 else | |
6690 { | |
6691 ++shl->first_lnum; | |
6692 n = 0; | |
6693 } | |
6694 } | |
6695 } | |
1326 | 6696 if (shl != &search_hl && cur != NULL) |
6697 cur = cur->next; | |
7 | 6698 } |
6699 } | |
6700 | |
6701 /* | |
1326 | 6702 * Search for a next 'hlsearch' or match. |
7 | 6703 * Uses shl->buf. |
6704 * Sets shl->lnum and shl->rm contents. | |
6705 * Note: Assumes a previous match is always before "lnum", unless | |
6706 * shl->lnum is zero. | |
6707 * Careful: Any pointers for buffer lines will become invalid. | |
6708 */ | |
6709 static void | |
6710 next_search_hl(win, shl, lnum, mincol) | |
6711 win_T *win; | |
1326 | 6712 match_T *shl; /* points to search_hl or a match */ |
7 | 6713 linenr_T lnum; |
6714 colnr_T mincol; /* minimal column for a match */ | |
6715 { | |
6716 linenr_T l; | |
6717 colnr_T matchcol; | |
6718 long nmatched; | |
6719 | |
6720 if (shl->lnum != 0) | |
6721 { | |
6722 /* Check for three situations: | |
6723 * 1. If the "lnum" is below a previous match, start a new search. | |
6724 * 2. If the previous match includes "mincol", use it. | |
6725 * 3. Continue after the previous match. | |
6726 */ | |
6727 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
6728 if (lnum > l) | |
6729 shl->lnum = 0; | |
6730 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
6731 return; | |
6732 } | |
6733 | |
6734 /* | |
6735 * Repeat searching for a match until one is found that includes "mincol" | |
6736 * or none is found in this line. | |
6737 */ | |
6738 called_emsg = FALSE; | |
6739 for (;;) | |
6740 { | |
1521 | 6741 #ifdef FEAT_RELTIME |
6742 /* Stop searching after passing the time limit. */ | |
6743 if (profile_passed_limit(&(shl->tm))) | |
6744 { | |
6745 shl->lnum = 0; /* no match found in time */ | |
6746 break; | |
6747 } | |
6748 #endif | |
7 | 6749 /* Three situations: |
6750 * 1. No useful previous match: search from start of line. | |
6751 * 2. Not Vi compatible or empty match: continue at next character. | |
6752 * Break the loop if this is beyond the end of the line. | |
6753 * 3. Vi compatible searching: continue at end of previous match. | |
6754 */ | |
6755 if (shl->lnum == 0) | |
6756 matchcol = 0; | |
6757 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
6758 || (shl->rm.endpos[0].lnum == 0 | |
685 | 6759 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
6760 { | |
688 | 6761 char_u *ml; |
685 | 6762 |
6763 matchcol = shl->rm.startpos[0].col; | |
688 | 6764 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 6765 if (*ml == NUL) |
6766 { | |
6767 ++matchcol; | |
7 | 6768 shl->lnum = 0; |
6769 break; | |
6770 } | |
685 | 6771 #ifdef FEAT_MBYTE |
6772 if (has_mbyte) | |
6773 matchcol += mb_ptr2len(ml); | |
6774 else | |
6775 #endif | |
6776 ++matchcol; | |
7 | 6777 } |
6778 else | |
6779 matchcol = shl->rm.endpos[0].col; | |
6780 | |
6781 shl->lnum = lnum; | |
1521 | 6782 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
6783 #ifdef FEAT_RELTIME | |
6784 &(shl->tm) | |
6785 #else | |
6786 NULL | |
6787 #endif | |
6788 ); | |
7 | 6789 if (called_emsg) |
6790 { | |
6791 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 6792 if (shl == &search_hl) |
6793 { | |
1326 | 6794 /* don't free regprog in the match list, it's a copy */ |
1112 | 6795 vim_free(shl->rm.regprog); |
6796 no_hlsearch = TRUE; | |
6797 } | |
7 | 6798 shl->rm.regprog = NULL; |
1112 | 6799 shl->lnum = 0; |
6800 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 6801 break; |
6802 } | |
6803 if (nmatched == 0) | |
6804 { | |
6805 shl->lnum = 0; /* no match found */ | |
6806 break; | |
6807 } | |
6808 if (shl->rm.startpos[0].lnum > 0 | |
6809 || shl->rm.startpos[0].col >= mincol | |
6810 || nmatched > 1 | |
6811 || shl->rm.endpos[0].col > mincol) | |
6812 { | |
6813 shl->lnum += shl->rm.startpos[0].lnum; | |
6814 break; /* useful match found */ | |
6815 } | |
6816 } | |
6817 } | |
6818 #endif | |
6819 | |
6820 static void | |
6821 screen_start_highlight(attr) | |
6822 int attr; | |
6823 { | |
6824 attrentry_T *aep = NULL; | |
6825 | |
6826 screen_attr = attr; | |
6827 if (full_screen | |
6828 #ifdef WIN3264 | |
6829 && termcap_active | |
6830 #endif | |
6831 ) | |
6832 { | |
6833 #ifdef FEAT_GUI | |
6834 if (gui.in_use) | |
6835 { | |
6836 char buf[20]; | |
6837 | |
681 | 6838 /* The GUI handles this internally. */ |
6839 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 6840 OUT_STR(buf); |
6841 } | |
6842 else | |
6843 #endif | |
6844 { | |
6845 if (attr > HL_ALL) /* special HL attr. */ | |
6846 { | |
6847 if (t_colors > 1) | |
6848 aep = syn_cterm_attr2entry(attr); | |
6849 else | |
6850 aep = syn_term_attr2entry(attr); | |
6851 if (aep == NULL) /* did ":syntax clear" */ | |
6852 attr = 0; | |
6853 else | |
6854 attr = aep->ae_attr; | |
6855 } | |
6856 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
6857 out_str(T_MD); | |
681 | 6858 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
6859 && cterm_normal_fg_bold) | |
6860 /* If the Normal FG color has BOLD attribute and the new HL | |
6861 * has a FG color defined, clear BOLD. */ | |
6862 out_str(T_ME); | |
7 | 6863 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
6864 out_str(T_SO); | |
205 | 6865 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
6866 /* underline or undercurl */ | |
7 | 6867 out_str(T_US); |
6868 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
6869 out_str(T_CZH); | |
6870 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
6871 out_str(T_MR); | |
6872 | |
6873 /* | |
6874 * Output the color or start string after bold etc., in case the | |
6875 * bold etc. override the color setting. | |
6876 */ | |
6877 if (aep != NULL) | |
6878 { | |
6879 if (t_colors > 1) | |
6880 { | |
6881 if (aep->ae_u.cterm.fg_color) | |
6882 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
6883 if (aep->ae_u.cterm.bg_color) | |
6884 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
6885 } | |
6886 else | |
6887 { | |
6888 if (aep->ae_u.term.start != NULL) | |
6889 out_str(aep->ae_u.term.start); | |
6890 } | |
6891 } | |
6892 } | |
6893 } | |
6894 } | |
6895 | |
6896 void | |
6897 screen_stop_highlight() | |
6898 { | |
6899 int do_ME = FALSE; /* output T_ME code */ | |
6900 | |
6901 if (screen_attr != 0 | |
6902 #ifdef WIN3264 | |
6903 && termcap_active | |
6904 #endif | |
6905 ) | |
6906 { | |
6907 #ifdef FEAT_GUI | |
6908 if (gui.in_use) | |
6909 { | |
6910 char buf[20]; | |
6911 | |
6912 /* use internal GUI code */ | |
6913 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
6914 OUT_STR(buf); | |
6915 } | |
6916 else | |
6917 #endif | |
6918 { | |
6919 if (screen_attr > HL_ALL) /* special HL attr. */ | |
6920 { | |
6921 attrentry_T *aep; | |
6922 | |
6923 if (t_colors > 1) | |
6924 { | |
6925 /* | |
6926 * Assume that t_me restores the original colors! | |
6927 */ | |
6928 aep = syn_cterm_attr2entry(screen_attr); | |
6929 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
6930 || aep->ae_u.cterm.bg_color)) | |
6931 do_ME = TRUE; | |
6932 } | |
6933 else | |
6934 { | |
6935 aep = syn_term_attr2entry(screen_attr); | |
6936 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
6937 { | |
6938 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
6939 do_ME = TRUE; | |
6940 else | |
6941 out_str(aep->ae_u.term.stop); | |
6942 } | |
6943 } | |
6944 if (aep == NULL) /* did ":syntax clear" */ | |
6945 screen_attr = 0; | |
6946 else | |
6947 screen_attr = aep->ae_attr; | |
6948 } | |
6949 | |
6950 /* | |
6951 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
6952 * same sequence several times. | |
6953 */ | |
6954 if (screen_attr & HL_STANDOUT) | |
6955 { | |
6956 if (STRCMP(T_SE, T_ME) == 0) | |
6957 do_ME = TRUE; | |
6958 else | |
6959 out_str(T_SE); | |
6960 } | |
205 | 6961 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 6962 { |
6963 if (STRCMP(T_UE, T_ME) == 0) | |
6964 do_ME = TRUE; | |
6965 else | |
6966 out_str(T_UE); | |
6967 } | |
6968 if (screen_attr & HL_ITALIC) | |
6969 { | |
6970 if (STRCMP(T_CZR, T_ME) == 0) | |
6971 do_ME = TRUE; | |
6972 else | |
6973 out_str(T_CZR); | |
6974 } | |
6975 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
6976 out_str(T_ME); | |
6977 | |
6978 if (t_colors > 1) | |
6979 { | |
6980 /* set Normal cterm colors */ | |
6981 if (cterm_normal_fg_color != 0) | |
6982 term_fg_color(cterm_normal_fg_color - 1); | |
6983 if (cterm_normal_bg_color != 0) | |
6984 term_bg_color(cterm_normal_bg_color - 1); | |
6985 if (cterm_normal_fg_bold) | |
6986 out_str(T_MD); | |
6987 } | |
6988 } | |
6989 } | |
6990 screen_attr = 0; | |
6991 } | |
6992 | |
6993 /* | |
6994 * Reset the colors for a cterm. Used when leaving Vim. | |
6995 * The machine specific code may override this again. | |
6996 */ | |
6997 void | |
6998 reset_cterm_colors() | |
6999 { | |
7000 if (t_colors > 1) | |
7001 { | |
7002 /* set Normal cterm colors */ | |
7003 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7004 { | |
7005 out_str(T_OP); | |
7006 screen_attr = -1; | |
7007 } | |
7008 if (cterm_normal_fg_bold) | |
7009 { | |
7010 out_str(T_ME); | |
7011 screen_attr = -1; | |
7012 } | |
7013 } | |
7014 } | |
7015 | |
7016 /* | |
7017 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7018 * using the attributes from ScreenAttrs["off"]. | |
7019 */ | |
7020 static void | |
7021 screen_char(off, row, col) | |
7022 unsigned off; | |
7023 int row; | |
7024 int col; | |
7025 { | |
7026 int attr; | |
7027 | |
7028 /* Check for illegal values, just in case (could happen just after | |
7029 * resizing). */ | |
7030 if (row >= screen_Rows || col >= screen_Columns) | |
7031 return; | |
7032 | |
7033 /* Outputting the last character on the screen may scrollup the screen. | |
7034 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7035 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7036 #ifdef FEAT_RIGHTLEFT | |
7037 /* account for first command-line character in rightleft mode */ | |
7038 && !cmdmsg_rl | |
7039 #endif | |
7040 ) | |
7041 { | |
7042 ScreenAttrs[off] = (sattr_T)-1; | |
7043 return; | |
7044 } | |
7045 | |
7046 /* | |
7047 * Stop highlighting first, so it's easier to move the cursor. | |
7048 */ | |
7049 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7050 if (screen_char_attr != 0) | |
7051 attr = screen_char_attr; | |
7052 else | |
7053 #endif | |
7054 attr = ScreenAttrs[off]; | |
7055 if (screen_attr != attr) | |
7056 screen_stop_highlight(); | |
7057 | |
7058 windgoto(row, col); | |
7059 | |
7060 if (screen_attr != attr) | |
7061 screen_start_highlight(attr); | |
7062 | |
7063 #ifdef FEAT_MBYTE | |
7064 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7065 { | |
7066 char_u buf[MB_MAXBYTES + 1]; | |
7067 | |
7068 /* Convert UTF-8 character to bytes and write it. */ | |
7069 | |
7070 buf[utfc_char2bytes(off, buf)] = NUL; | |
7071 | |
7072 out_str(buf); | |
7073 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7074 ++screen_cur_col; | |
7075 } | |
7076 else | |
7077 #endif | |
7078 { | |
7079 #ifdef FEAT_MBYTE | |
7080 out_flush_check(); | |
7081 #endif | |
7082 out_char(ScreenLines[off]); | |
7083 #ifdef FEAT_MBYTE | |
7084 /* double-byte character in single-width cell */ | |
7085 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7086 out_char(ScreenLines2[off]); | |
7087 #endif | |
7088 } | |
7089 | |
7090 screen_cur_col++; | |
7091 } | |
7092 | |
7093 #ifdef FEAT_MBYTE | |
7094 | |
7095 /* | |
7096 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7097 * on the screen at position 'row' and 'col'. | |
7098 * The attributes of the first byte is used for all. This is required to | |
7099 * output the two bytes of a double-byte character with nothing in between. | |
7100 */ | |
7101 static void | |
7102 screen_char_2(off, row, col) | |
7103 unsigned off; | |
7104 int row; | |
7105 int col; | |
7106 { | |
7107 /* Check for illegal values (could be wrong when screen was resized). */ | |
7108 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7109 return; | |
7110 | |
7111 /* Outputting the last character on the screen may scrollup the screen. | |
7112 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7113 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7114 { | |
7115 ScreenAttrs[off] = (sattr_T)-1; | |
7116 return; | |
7117 } | |
7118 | |
7119 /* Output the first byte normally (positions the cursor), then write the | |
7120 * second byte directly. */ | |
7121 screen_char(off, row, col); | |
7122 out_char(ScreenLines[off + 1]); | |
7123 ++screen_cur_col; | |
7124 } | |
7125 #endif | |
7126 | |
7127 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7128 /* | |
7129 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7130 * This uses the contents of ScreenLines[] and doesn't change it. | |
7131 */ | |
7132 void | |
7133 screen_draw_rectangle(row, col, height, width, invert) | |
7134 int row; | |
7135 int col; | |
7136 int height; | |
7137 int width; | |
7138 int invert; | |
7139 { | |
7140 int r, c; | |
7141 int off; | |
1378 | 7142 #ifdef FEAT_MBYTE |
7143 int max_off; | |
7144 #endif | |
7 | 7145 |
534 | 7146 /* Can't use ScreenLines unless initialized */ |
7147 if (ScreenLines == NULL) | |
7148 return; | |
7149 | |
7 | 7150 if (invert) |
7151 screen_char_attr = HL_INVERSE; | |
7152 for (r = row; r < row + height; ++r) | |
7153 { | |
7154 off = LineOffset[r]; | |
1378 | 7155 #ifdef FEAT_MBYTE |
7156 max_off = off + screen_Columns; | |
7157 #endif | |
7 | 7158 for (c = col; c < col + width; ++c) |
7159 { | |
7160 #ifdef FEAT_MBYTE | |
1378 | 7161 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7162 { |
7163 screen_char_2(off + c, r, c); | |
7164 ++c; | |
7165 } | |
7166 else | |
7167 #endif | |
7168 { | |
7169 screen_char(off + c, r, c); | |
7170 #ifdef FEAT_MBYTE | |
1378 | 7171 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7172 ++c; |
7173 #endif | |
7174 } | |
7175 } | |
7176 } | |
7177 screen_char_attr = 0; | |
7178 } | |
7179 #endif | |
7180 | |
7181 #ifdef FEAT_VERTSPLIT | |
7182 /* | |
7183 * Redraw the characters for a vertically split window. | |
7184 */ | |
7185 static void | |
7186 redraw_block(row, end, wp) | |
7187 int row; | |
7188 int end; | |
7189 win_T *wp; | |
7190 { | |
7191 int col; | |
7192 int width; | |
7193 | |
7194 # ifdef FEAT_CLIPBOARD | |
7195 clip_may_clear_selection(row, end - 1); | |
7196 # endif | |
7197 | |
7198 if (wp == NULL) | |
7199 { | |
7200 col = 0; | |
7201 width = Columns; | |
7202 } | |
7203 else | |
7204 { | |
7205 col = wp->w_wincol; | |
7206 width = wp->w_width; | |
7207 } | |
7208 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7209 } | |
7210 #endif | |
7211 | |
7212 /* | |
7213 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7214 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7215 * Use attributes 'attr'. | |
7216 */ | |
7217 void | |
7218 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7219 int start_row, end_row; | |
7220 int start_col, end_col; | |
7221 int c1, c2; | |
7222 int attr; | |
7223 { | |
7224 int row; | |
7225 int col; | |
7226 int off; | |
7227 int end_off; | |
7228 int did_delete; | |
7229 int c; | |
7230 int norm_term; | |
7231 #if defined(FEAT_GUI) || defined(UNIX) | |
7232 int force_next = FALSE; | |
7233 #endif | |
7234 | |
7235 if (end_row > screen_Rows) /* safety check */ | |
7236 end_row = screen_Rows; | |
7237 if (end_col > screen_Columns) /* safety check */ | |
7238 end_col = screen_Columns; | |
7239 if (ScreenLines == NULL | |
7240 || start_row >= end_row | |
7241 || start_col >= end_col) /* nothing to do */ | |
7242 return; | |
7243 | |
7244 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7245 norm_term = ( | |
7246 #ifdef FEAT_GUI | |
7247 !gui.in_use && | |
7248 #endif | |
7249 t_colors <= 1); | |
7250 for (row = start_row; row < end_row; ++row) | |
7251 { | |
1668 | 7252 #ifdef FEAT_MBYTE |
7253 if (has_mbyte | |
7254 # ifdef FEAT_GUI | |
7255 && !gui.in_use | |
7256 # endif | |
7257 ) | |
7258 { | |
7259 /* When drawing over the right halve of a double-wide char clear | |
7260 * out the left halve. When drawing over the left halve of a | |
7261 * double wide-char clear out the right halve. Only needed in a | |
7262 * terminal. */ | |
1685 | 7263 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7264 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7265 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7266 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7267 } |
7268 #endif | |
7 | 7269 /* |
7270 * Try to use delete-line termcap code, when no attributes or in a | |
7271 * "normal" terminal, where a bold/italic space is just a | |
7272 * space. | |
7273 */ | |
7274 did_delete = FALSE; | |
7275 if (c2 == ' ' | |
7276 && end_col == Columns | |
7277 && can_clear(T_CE) | |
7278 && (attr == 0 | |
7279 || (norm_term | |
7280 && attr <= HL_ALL | |
7281 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7282 { | |
7283 /* | |
7284 * check if we really need to clear something | |
7285 */ | |
7286 col = start_col; | |
7287 if (c1 != ' ') /* don't clear first char */ | |
7288 ++col; | |
7289 | |
7290 off = LineOffset[row] + col; | |
7291 end_off = LineOffset[row] + end_col; | |
7292 | |
7293 /* skip blanks (used often, keep it fast!) */ | |
7294 #ifdef FEAT_MBYTE | |
7295 if (enc_utf8) | |
7296 while (off < end_off && ScreenLines[off] == ' ' | |
7297 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7298 ++off; | |
7299 else | |
7300 #endif | |
7301 while (off < end_off && ScreenLines[off] == ' ' | |
7302 && ScreenAttrs[off] == 0) | |
7303 ++off; | |
7304 if (off < end_off) /* something to be cleared */ | |
7305 { | |
7306 col = off - LineOffset[row]; | |
7307 screen_stop_highlight(); | |
7308 term_windgoto(row, col);/* clear rest of this screen line */ | |
7309 out_str(T_CE); | |
7310 screen_start(); /* don't know where cursor is now */ | |
7311 col = end_col - col; | |
7312 while (col--) /* clear chars in ScreenLines */ | |
7313 { | |
7314 ScreenLines[off] = ' '; | |
7315 #ifdef FEAT_MBYTE | |
7316 if (enc_utf8) | |
7317 ScreenLinesUC[off] = 0; | |
7318 #endif | |
7319 ScreenAttrs[off] = 0; | |
7320 ++off; | |
7321 } | |
7322 } | |
7323 did_delete = TRUE; /* the chars are cleared now */ | |
7324 } | |
7325 | |
7326 off = LineOffset[row] + start_col; | |
7327 c = c1; | |
7328 for (col = start_col; col < end_col; ++col) | |
7329 { | |
7330 if (ScreenLines[off] != c | |
7331 #ifdef FEAT_MBYTE | |
714 | 7332 || (enc_utf8 && (int)ScreenLinesUC[off] |
7333 != (c >= 0x80 ? c : 0)) | |
7 | 7334 #endif |
7335 || ScreenAttrs[off] != attr | |
7336 #if defined(FEAT_GUI) || defined(UNIX) | |
7337 || force_next | |
7338 #endif | |
7339 ) | |
7340 { | |
7341 #if defined(FEAT_GUI) || defined(UNIX) | |
7342 /* The bold trick may make a single row of pixels appear in | |
7343 * the next character. When a bold character is removed, the | |
7344 * next character should be redrawn too. This happens for our | |
7345 * own GUI and for some xterms. */ | |
7346 if ( | |
7347 # ifdef FEAT_GUI | |
7348 gui.in_use | |
7349 # endif | |
7350 # if defined(FEAT_GUI) && defined(UNIX) | |
7351 || | |
7352 # endif | |
7353 # ifdef UNIX | |
7354 term_is_xterm | |
7355 # endif | |
7356 ) | |
7357 { | |
7358 if (ScreenLines[off] != ' ' | |
7359 && (ScreenAttrs[off] > HL_ALL | |
7360 || ScreenAttrs[off] & HL_BOLD)) | |
7361 force_next = TRUE; | |
7362 else | |
7363 force_next = FALSE; | |
7364 } | |
7365 #endif | |
7366 ScreenLines[off] = c; | |
7367 #ifdef FEAT_MBYTE | |
7368 if (enc_utf8) | |
7369 { | |
7370 if (c >= 0x80) | |
7371 { | |
7372 ScreenLinesUC[off] = c; | |
714 | 7373 ScreenLinesC[0][off] = 0; |
7 | 7374 } |
7375 else | |
7376 ScreenLinesUC[off] = 0; | |
7377 } | |
7378 #endif | |
7379 ScreenAttrs[off] = attr; | |
7380 if (!did_delete || c != ' ') | |
7381 screen_char(off, row, col); | |
7382 } | |
7383 ++off; | |
7384 if (col == start_col) | |
7385 { | |
7386 if (did_delete) | |
7387 break; | |
7388 c = c2; | |
7389 } | |
7390 } | |
7391 if (end_col == Columns) | |
7392 LineWraps[row] = FALSE; | |
7393 if (row == Rows - 1) /* overwritten the command line */ | |
7394 { | |
7395 redraw_cmdline = TRUE; | |
7396 if (c1 == ' ' && c2 == ' ') | |
7397 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7398 if (start_col == 0) |
7399 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7400 } |
7401 } | |
7402 } | |
7403 | |
7404 /* | |
7405 * Check if there should be a delay. Used before clearing or redrawing the | |
7406 * screen or the command line. | |
7407 */ | |
7408 void | |
7409 check_for_delay(check_msg_scroll) | |
7410 int check_msg_scroll; | |
7411 { | |
7412 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7413 && !did_wait_return | |
7414 && emsg_silent == 0) | |
7415 { | |
7416 out_flush(); | |
7417 ui_delay(1000L, TRUE); | |
7418 emsg_on_display = FALSE; | |
7419 if (check_msg_scroll) | |
7420 msg_scroll = FALSE; | |
7421 } | |
7422 } | |
7423 | |
7424 /* | |
7425 * screen_valid - allocate screen buffers if size changed | |
7426 * If "clear" is TRUE: clear screen if it has been resized. | |
7427 * Returns TRUE if there is a valid screen to write to. | |
7428 * Returns FALSE when starting up and screen not initialized yet. | |
7429 */ | |
7430 int | |
7431 screen_valid(clear) | |
7432 int clear; | |
7433 { | |
7434 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7435 return (ScreenLines != NULL); | |
7436 } | |
7437 | |
7438 /* | |
7439 * Resize the shell to Rows and Columns. | |
7440 * Allocate ScreenLines[] and associated items. | |
7441 * | |
7442 * There may be some time between setting Rows and Columns and (re)allocating | |
7443 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7444 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7445 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7446 * final size of the shell is needed. | |
7447 */ | |
7448 void | |
7449 screenalloc(clear) | |
7450 int clear; | |
7451 { | |
7452 int new_row, old_row; | |
7453 #ifdef FEAT_GUI | |
7454 int old_Rows; | |
7455 #endif | |
7456 win_T *wp; | |
7457 int outofmem = FALSE; | |
7458 int len; | |
7459 schar_T *new_ScreenLines; | |
7460 #ifdef FEAT_MBYTE | |
7461 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7462 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7463 schar_T *new_ScreenLines2 = NULL; |
714 | 7464 int i; |
7 | 7465 #endif |
7466 sattr_T *new_ScreenAttrs; | |
7467 unsigned *new_LineOffset; | |
7468 char_u *new_LineWraps; | |
671 | 7469 #ifdef FEAT_WINDOWS |
681 | 7470 short *new_TabPageIdxs; |
671 | 7471 tabpage_T *tp; |
7472 #endif | |
7 | 7473 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7474 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7475 #ifdef FEAT_AUTOCMD |
7476 int retry_count = 0; | |
7477 | |
7478 retry: | |
7479 #endif | |
7 | 7480 /* |
7481 * Allocation of the screen buffers is done only when the size changes and | |
7482 * when Rows and Columns have been set and we have started doing full | |
7483 * screen stuff. | |
7484 */ | |
7485 if ((ScreenLines != NULL | |
7486 && Rows == screen_Rows | |
7487 && Columns == screen_Columns | |
7488 #ifdef FEAT_MBYTE | |
7489 && enc_utf8 == (ScreenLinesUC != NULL) | |
7490 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7491 && p_mco == Screen_mco |
7 | 7492 #endif |
7493 ) | |
7494 || Rows == 0 | |
7495 || Columns == 0 | |
7496 || (!full_screen && ScreenLines == NULL)) | |
7497 return; | |
7498 | |
7499 /* | |
7500 * It's possible that we produce an out-of-memory message below, which | |
7501 * will cause this function to be called again. To break the loop, just | |
7502 * return here. | |
7503 */ | |
7504 if (entered) | |
7505 return; | |
7506 entered = TRUE; | |
7507 | |
911 | 7508 /* |
7509 * Note that the window sizes are updated before reallocating the arrays, | |
7510 * thus we must not redraw here! | |
7511 */ | |
7512 ++RedrawingDisabled; | |
7513 | |
7 | 7514 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7515 | |
7516 comp_col(); /* recompute columns for shown command and ruler */ | |
7517 | |
7518 /* | |
7519 * We're changing the size of the screen. | |
7520 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7521 * - Move lines from the old arrays into the new arrays, clear extra | |
7522 * lines (unless the screen is going to be cleared). | |
7523 * - Free the old arrays. | |
7524 * | |
7525 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7526 * Continuing with the old ScreenLines may result in a crash, because the | |
7527 * size is wrong. | |
7528 */ | |
671 | 7529 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7530 win_free_lsize(wp); |
1946 | 7531 #ifdef FEAT_AUTOCMD |
7532 if (aucmd_win != NULL) | |
7533 win_free_lsize(aucmd_win); | |
7534 #endif | |
7 | 7535 |
7536 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7537 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7538 #ifdef FEAT_MBYTE | |
714 | 7539 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T) * MAX_MCO); |
7 | 7540 if (enc_utf8) |
7541 { | |
7542 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7543 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7544 for (i = 0; i < p_mco; ++i) |
7545 new_ScreenLinesC[i] = (u8char_T *)lalloc((long_u)( | |
7 | 7546 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7547 } | |
7548 if (enc_dbcs == DBCS_JPNU) | |
7549 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7550 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7551 #endif | |
7552 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7553 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7554 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7555 Rows * sizeof(unsigned)), FALSE); | |
7556 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7557 #ifdef FEAT_WINDOWS |
681 | 7558 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7559 #endif |
7 | 7560 |
677 | 7561 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7562 { |
7563 if (win_alloc_lines(wp) == FAIL) | |
7564 { | |
7565 outofmem = TRUE; | |
7566 #ifdef FEAT_WINDOWS | |
1819 | 7567 goto give_up; |
7568 #endif | |
7569 } | |
7570 } | |
1906 | 7571 #ifdef FEAT_AUTOCMD |
1946 | 7572 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7573 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7574 outofmem = TRUE; |
7575 #endif | |
1819 | 7576 #ifdef FEAT_WINDOWS |
7577 give_up: | |
7578 #endif | |
7 | 7579 |
714 | 7580 #ifdef FEAT_MBYTE |
7581 for (i = 0; i < p_mco; ++i) | |
7582 if (new_ScreenLinesC[i] == NULL) | |
7583 break; | |
7584 #endif | |
7 | 7585 if (new_ScreenLines == NULL |
7586 #ifdef FEAT_MBYTE | |
714 | 7587 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7588 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7589 #endif | |
7590 || new_ScreenAttrs == NULL | |
7591 || new_LineOffset == NULL | |
7592 || new_LineWraps == NULL | |
671 | 7593 #ifdef FEAT_WINDOWS |
7594 || new_TabPageIdxs == NULL | |
7595 #endif | |
7 | 7596 || outofmem) |
7597 { | |
944 | 7598 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7599 { |
7600 /* guess the size */ | |
7601 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
7602 | |
7603 /* Remember we did this to avoid getting outofmem messages over | |
7604 * and over again. */ | |
944 | 7605 done_outofmem_msg = TRUE; |
534 | 7606 } |
7 | 7607 vim_free(new_ScreenLines); |
7608 new_ScreenLines = NULL; | |
7609 #ifdef FEAT_MBYTE | |
7610 vim_free(new_ScreenLinesUC); | |
7611 new_ScreenLinesUC = NULL; | |
714 | 7612 for (i = 0; i < p_mco; ++i) |
7613 { | |
7614 vim_free(new_ScreenLinesC[i]); | |
7615 new_ScreenLinesC[i] = NULL; | |
7616 } | |
7 | 7617 vim_free(new_ScreenLines2); |
7618 new_ScreenLines2 = NULL; | |
7619 #endif | |
7620 vim_free(new_ScreenAttrs); | |
7621 new_ScreenAttrs = NULL; | |
7622 vim_free(new_LineOffset); | |
7623 new_LineOffset = NULL; | |
7624 vim_free(new_LineWraps); | |
7625 new_LineWraps = NULL; | |
671 | 7626 #ifdef FEAT_WINDOWS |
7627 vim_free(new_TabPageIdxs); | |
7628 new_TabPageIdxs = NULL; | |
7629 #endif | |
7 | 7630 } |
7631 else | |
7632 { | |
944 | 7633 done_outofmem_msg = FALSE; |
534 | 7634 |
7 | 7635 for (new_row = 0; new_row < Rows; ++new_row) |
7636 { | |
7637 new_LineOffset[new_row] = new_row * Columns; | |
7638 new_LineWraps[new_row] = FALSE; | |
7639 | |
7640 /* | |
7641 * If the screen is not going to be cleared, copy as much as | |
7642 * possible from the old screen to the new one and clear the rest | |
7643 * (used when resizing the window at the "--more--" prompt or when | |
7644 * executing an external command, for the GUI). | |
7645 */ | |
7646 if (!clear) | |
7647 { | |
7648 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
7649 ' ', (size_t)Columns * sizeof(schar_T)); | |
7650 #ifdef FEAT_MBYTE | |
7651 if (enc_utf8) | |
7652 { | |
7653 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
7654 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 7655 for (i = 0; i < p_mco; ++i) |
7656 (void)vim_memset(new_ScreenLinesC[i] | |
7657 + new_row * Columns, | |
7 | 7658 0, (size_t)Columns * sizeof(u8char_T)); |
7659 } | |
7660 if (enc_dbcs == DBCS_JPNU) | |
7661 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
7662 0, (size_t)Columns * sizeof(schar_T)); | |
7663 #endif | |
7664 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
7665 0, (size_t)Columns * sizeof(sattr_T)); | |
7666 old_row = new_row + (screen_Rows - Rows); | |
534 | 7667 if (old_row >= 0 && ScreenLines != NULL) |
7 | 7668 { |
7669 if (screen_Columns < Columns) | |
7670 len = screen_Columns; | |
7671 else | |
7672 len = Columns; | |
26 | 7673 #ifdef FEAT_MBYTE |
571 | 7674 /* When switching to utf-8 don't copy characters, they |
714 | 7675 * may be invalid now. Also when p_mco changes. */ |
7676 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
7677 && p_mco == Screen_mco) | |
26 | 7678 #endif |
7679 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
7680 ScreenLines + LineOffset[old_row], | |
7681 (size_t)len * sizeof(schar_T)); | |
7 | 7682 #ifdef FEAT_MBYTE |
714 | 7683 if (enc_utf8 && ScreenLinesUC != NULL |
7684 && p_mco == Screen_mco) | |
7 | 7685 { |
7686 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
7687 ScreenLinesUC + LineOffset[old_row], | |
7688 (size_t)len * sizeof(u8char_T)); | |
714 | 7689 for (i = 0; i < p_mco; ++i) |
7690 mch_memmove(new_ScreenLinesC[i] | |
7691 + new_LineOffset[new_row], | |
7692 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 7693 (size_t)len * sizeof(u8char_T)); |
7694 } | |
7695 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
7696 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
7697 ScreenLines2 + LineOffset[old_row], | |
7698 (size_t)len * sizeof(schar_T)); | |
7699 #endif | |
7700 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
7701 ScreenAttrs + LineOffset[old_row], | |
7702 (size_t)len * sizeof(sattr_T)); | |
7703 } | |
7704 } | |
7705 } | |
7706 /* Use the last line of the screen for the current line. */ | |
7707 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
7708 } | |
7709 | |
356 | 7710 free_screenlines(); |
7711 | |
7 | 7712 ScreenLines = new_ScreenLines; |
7713 #ifdef FEAT_MBYTE | |
7714 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 7715 for (i = 0; i < p_mco; ++i) |
7716 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
7717 Screen_mco = p_mco; | |
7 | 7718 ScreenLines2 = new_ScreenLines2; |
7719 #endif | |
7720 ScreenAttrs = new_ScreenAttrs; | |
7721 LineOffset = new_LineOffset; | |
7722 LineWraps = new_LineWraps; | |
671 | 7723 #ifdef FEAT_WINDOWS |
7724 TabPageIdxs = new_TabPageIdxs; | |
7725 #endif | |
7 | 7726 |
7727 /* It's important that screen_Rows and screen_Columns reflect the actual | |
7728 * size of ScreenLines[]. Set them before calling anything. */ | |
7729 #ifdef FEAT_GUI | |
7730 old_Rows = screen_Rows; | |
7731 #endif | |
7732 screen_Rows = Rows; | |
7733 screen_Columns = Columns; | |
7734 | |
7735 must_redraw = CLEAR; /* need to clear the screen later */ | |
7736 if (clear) | |
7737 screenclear2(); | |
7738 | |
7739 #ifdef FEAT_GUI | |
7740 else if (gui.in_use | |
7741 && !gui.starting | |
7742 && ScreenLines != NULL | |
7743 && old_Rows != Rows) | |
7744 { | |
7745 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
7746 /* | |
7747 * Adjust the position of the cursor, for when executing an external | |
7748 * command. | |
7749 */ | |
7750 if (msg_row >= Rows) /* Rows got smaller */ | |
7751 msg_row = Rows - 1; /* put cursor at last row */ | |
7752 else if (Rows > old_Rows) /* Rows got bigger */ | |
7753 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
7754 if (msg_col >= Columns) /* Columns got smaller */ | |
7755 msg_col = Columns - 1; /* put cursor at last column */ | |
7756 } | |
7757 #endif | |
7758 | |
7759 entered = FALSE; | |
911 | 7760 --RedrawingDisabled; |
766 | 7761 |
7762 #ifdef FEAT_AUTOCMD | |
1824 | 7763 /* |
7764 * Do not apply autocommands more than 3 times to avoid an endless loop | |
7765 * in case applying autocommands always changes Rows or Columns. | |
7766 */ | |
7767 if (starting == 0 && ++retry_count <= 3) | |
7768 { | |
766 | 7769 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 7770 /* In rare cases, autocommands may have altered Rows or Columns, |
7771 * jump back to check if we need to allocate the screen again. */ | |
7772 goto retry; | |
7773 } | |
766 | 7774 #endif |
7 | 7775 } |
7776 | |
7777 void | |
356 | 7778 free_screenlines() |
7779 { | |
7780 #ifdef FEAT_MBYTE | |
714 | 7781 int i; |
7782 | |
356 | 7783 vim_free(ScreenLinesUC); |
714 | 7784 for (i = 0; i < Screen_mco; ++i) |
7785 vim_free(ScreenLinesC[i]); | |
356 | 7786 vim_free(ScreenLines2); |
7787 #endif | |
714 | 7788 vim_free(ScreenLines); |
356 | 7789 vim_free(ScreenAttrs); |
7790 vim_free(LineOffset); | |
7791 vim_free(LineWraps); | |
671 | 7792 #ifdef FEAT_WINDOWS |
7793 vim_free(TabPageIdxs); | |
7794 #endif | |
356 | 7795 } |
7796 | |
7797 void | |
7 | 7798 screenclear() |
7799 { | |
7800 check_for_delay(FALSE); | |
7801 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
7802 screenclear2(); /* clear the screen */ | |
7803 } | |
7804 | |
7805 static void | |
7806 screenclear2() | |
7807 { | |
7808 int i; | |
7809 | |
7810 if (starting == NO_SCREEN || ScreenLines == NULL | |
7811 #ifdef FEAT_GUI | |
7812 || (gui.in_use && gui.starting) | |
7813 #endif | |
7814 ) | |
7815 return; | |
7816 | |
7817 #ifdef FEAT_GUI | |
7818 if (!gui.in_use) | |
7819 #endif | |
7820 screen_attr = -1; /* force setting the Normal colors */ | |
7821 screen_stop_highlight(); /* don't want highlighting here */ | |
7822 | |
7823 #ifdef FEAT_CLIPBOARD | |
7824 /* disable selection without redrawing it */ | |
7825 clip_scroll_selection(9999); | |
7826 #endif | |
7827 | |
7828 /* blank out ScreenLines */ | |
7829 for (i = 0; i < Rows; ++i) | |
7830 { | |
7831 lineclear(LineOffset[i], (int)Columns); | |
7832 LineWraps[i] = FALSE; | |
7833 } | |
7834 | |
7835 if (can_clear(T_CL)) | |
7836 { | |
7837 out_str(T_CL); /* clear the display */ | |
7838 clear_cmdline = FALSE; | |
644 | 7839 mode_displayed = FALSE; |
7 | 7840 } |
7841 else | |
7842 { | |
7843 /* can't clear the screen, mark all chars with invalid attributes */ | |
7844 for (i = 0; i < Rows; ++i) | |
7845 lineinvalid(LineOffset[i], (int)Columns); | |
7846 clear_cmdline = TRUE; | |
7847 } | |
7848 | |
7849 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
7850 | |
7851 win_rest_invalid(firstwin); | |
7852 redraw_cmdline = TRUE; | |
670 | 7853 #ifdef FEAT_WINDOWS |
673 | 7854 redraw_tabline = TRUE; |
670 | 7855 #endif |
7 | 7856 if (must_redraw == CLEAR) /* no need to clear again */ |
7857 must_redraw = NOT_VALID; | |
7858 compute_cmdrow(); | |
7859 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
7860 msg_col = 0; | |
7861 screen_start(); /* don't know where cursor is now */ | |
7862 msg_scrolled = 0; /* can't scroll back */ | |
7863 msg_didany = FALSE; | |
7864 msg_didout = FALSE; | |
7865 } | |
7866 | |
7867 /* | |
7868 * Clear one line in ScreenLines. | |
7869 */ | |
7870 static void | |
7871 lineclear(off, width) | |
7872 unsigned off; | |
7873 int width; | |
7874 { | |
7875 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
7876 #ifdef FEAT_MBYTE | |
7877 if (enc_utf8) | |
7878 (void)vim_memset(ScreenLinesUC + off, 0, | |
7879 (size_t)width * sizeof(u8char_T)); | |
7880 #endif | |
7881 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
7882 } | |
7883 | |
7884 /* | |
7885 * Mark one line in ScreenLines invalid by setting the attributes to an | |
7886 * invalid value. | |
7887 */ | |
7888 static void | |
7889 lineinvalid(off, width) | |
7890 unsigned off; | |
7891 int width; | |
7892 { | |
7893 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
7894 } | |
7895 | |
7896 #ifdef FEAT_VERTSPLIT | |
7897 /* | |
7898 * Copy part of a Screenline for vertically split window "wp". | |
7899 */ | |
7900 static void | |
7901 linecopy(to, from, wp) | |
7902 int to; | |
7903 int from; | |
7904 win_T *wp; | |
7905 { | |
7906 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
7907 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
7908 | |
7909 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
7910 wp->w_width * sizeof(schar_T)); | |
7911 # ifdef FEAT_MBYTE | |
7912 if (enc_utf8) | |
7913 { | |
714 | 7914 int i; |
7915 | |
7 | 7916 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
7917 wp->w_width * sizeof(u8char_T)); | |
714 | 7918 for (i = 0; i < p_mco; ++i) |
7919 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
7920 wp->w_width * sizeof(u8char_T)); | |
7 | 7921 } |
7922 if (enc_dbcs == DBCS_JPNU) | |
7923 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
7924 wp->w_width * sizeof(schar_T)); | |
7925 # endif | |
7926 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
7927 wp->w_width * sizeof(sattr_T)); | |
7928 } | |
7929 #endif | |
7930 | |
7931 /* | |
7932 * Return TRUE if clearing with term string "p" would work. | |
7933 * It can't work when the string is empty or it won't set the right background. | |
7934 */ | |
7935 int | |
7936 can_clear(p) | |
7937 char_u *p; | |
7938 { | |
7939 return (*p != NUL && (t_colors <= 1 | |
7940 #ifdef FEAT_GUI | |
7941 || gui.in_use | |
7942 #endif | |
7943 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
7944 } | |
7945 | |
7946 /* | |
7947 * Reset cursor position. Use whenever cursor was moved because of outputting | |
7948 * something directly to the screen (shell commands) or a terminal control | |
7949 * code. | |
7950 */ | |
7951 void | |
7952 screen_start() | |
7953 { | |
7954 screen_cur_row = screen_cur_col = 9999; | |
7955 } | |
7956 | |
7957 /* | |
7958 * Move the cursor to position "row","col" in the screen. | |
7959 * This tries to find the most efficient way to move, minimizing the number of | |
7960 * characters sent to the terminal. | |
7961 */ | |
7962 void | |
7963 windgoto(row, col) | |
7964 int row; | |
7965 int col; | |
7966 { | |
205 | 7967 sattr_T *p; |
7 | 7968 int i; |
7969 int plan; | |
7970 int cost; | |
7971 int wouldbe_col; | |
7972 int noinvcurs; | |
7973 char_u *bs; | |
7974 int goto_cost; | |
7975 int attr; | |
7976 | |
1213 | 7977 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 7978 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
7979 | |
7980 #define PLAN_LE 1 | |
7981 #define PLAN_CR 2 | |
7982 #define PLAN_NL 3 | |
7983 #define PLAN_WRITE 4 | |
7984 /* Can't use ScreenLines unless initialized */ | |
7985 if (ScreenLines == NULL) | |
7986 return; | |
7987 | |
7988 if (col != screen_cur_col || row != screen_cur_row) | |
7989 { | |
7990 /* Check for valid position. */ | |
7991 if (row < 0) /* window without text lines? */ | |
7992 row = 0; | |
7993 if (row >= screen_Rows) | |
7994 row = screen_Rows - 1; | |
7995 if (col >= screen_Columns) | |
7996 col = screen_Columns - 1; | |
7997 | |
7998 /* check if no cursor movement is allowed in highlight mode */ | |
7999 if (screen_attr && *T_MS == NUL) | |
8000 noinvcurs = HIGHL_COST; | |
8001 else | |
8002 noinvcurs = 0; | |
8003 goto_cost = GOTO_COST + noinvcurs; | |
8004 | |
8005 /* | |
8006 * Plan how to do the positioning: | |
8007 * 1. Use CR to move it to column 0, same row. | |
8008 * 2. Use T_LE to move it a few columns to the left. | |
8009 * 3. Use NL to move a few lines down, column 0. | |
8010 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8011 * | |
8012 * Don't do this if the cursor went beyond the last column, the cursor | |
8013 * position is unknown then (some terminals wrap, some don't ) | |
8014 * | |
1213 | 8015 * First check if the highlighting attributes allow us to write |
7 | 8016 * characters to move the cursor to the right. |
8017 */ | |
8018 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8019 { | |
8020 /* | |
8021 * If the cursor is in the same row, bigger col, we can use CR | |
8022 * or T_LE. | |
8023 */ | |
8024 bs = NULL; /* init for GCC */ | |
8025 attr = screen_attr; | |
8026 if (row == screen_cur_row && col < screen_cur_col) | |
8027 { | |
8028 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8029 if (*T_LE) | |
8030 bs = T_LE; /* "cursor left" */ | |
8031 else | |
8032 bs = T_BC; /* "backspace character (old) */ | |
8033 if (*bs) | |
8034 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8035 else | |
8036 cost = 999; | |
8037 if (col + 1 < cost) /* using CR is less characters */ | |
8038 { | |
8039 plan = PLAN_CR; | |
8040 wouldbe_col = 0; | |
8041 cost = 1; /* CR is just one character */ | |
8042 } | |
8043 else | |
8044 { | |
8045 plan = PLAN_LE; | |
8046 wouldbe_col = col; | |
8047 } | |
8048 if (noinvcurs) /* will stop highlighting */ | |
8049 { | |
8050 cost += noinvcurs; | |
8051 attr = 0; | |
8052 } | |
8053 } | |
8054 | |
8055 /* | |
8056 * If the cursor is above where we want to be, we can use CR LF. | |
8057 */ | |
8058 else if (row > screen_cur_row) | |
8059 { | |
8060 plan = PLAN_NL; | |
8061 wouldbe_col = 0; | |
8062 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8063 if (noinvcurs) /* will stop highlighting */ | |
8064 { | |
8065 cost += noinvcurs; | |
8066 attr = 0; | |
8067 } | |
8068 } | |
8069 | |
8070 /* | |
8071 * If the cursor is in the same row, smaller col, just use write. | |
8072 */ | |
8073 else | |
8074 { | |
8075 plan = PLAN_WRITE; | |
8076 wouldbe_col = screen_cur_col; | |
8077 cost = 0; | |
8078 } | |
8079 | |
8080 /* | |
8081 * Check if any characters that need to be written have the | |
8082 * correct attributes. Also avoid UTF-8 characters. | |
8083 */ | |
8084 i = col - wouldbe_col; | |
8085 if (i > 0) | |
8086 cost += i; | |
8087 if (cost < goto_cost && i > 0) | |
8088 { | |
8089 /* | |
8090 * Check if the attributes are correct without additionally | |
8091 * stopping highlighting. | |
8092 */ | |
8093 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8094 while (i && *p++ == attr) | |
8095 --i; | |
8096 if (i != 0) | |
8097 { | |
8098 /* | |
8099 * Try if it works when highlighting is stopped here. | |
8100 */ | |
8101 if (*--p == 0) | |
8102 { | |
8103 cost += noinvcurs; | |
8104 while (i && *p++ == 0) | |
8105 --i; | |
8106 } | |
8107 if (i != 0) | |
8108 cost = 999; /* different attributes, don't do it */ | |
8109 } | |
8110 #ifdef FEAT_MBYTE | |
8111 if (enc_utf8) | |
8112 { | |
8113 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8114 for (i = wouldbe_col; i < col; ++i) | |
8115 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8116 { | |
8117 cost = 999; | |
8118 break; | |
8119 } | |
8120 } | |
8121 #endif | |
8122 } | |
8123 | |
8124 /* | |
8125 * We can do it without term_windgoto()! | |
8126 */ | |
8127 if (cost < goto_cost) | |
8128 { | |
8129 if (plan == PLAN_LE) | |
8130 { | |
8131 if (noinvcurs) | |
8132 screen_stop_highlight(); | |
8133 while (screen_cur_col > col) | |
8134 { | |
8135 out_str(bs); | |
8136 --screen_cur_col; | |
8137 } | |
8138 } | |
8139 else if (plan == PLAN_CR) | |
8140 { | |
8141 if (noinvcurs) | |
8142 screen_stop_highlight(); | |
8143 out_char('\r'); | |
8144 screen_cur_col = 0; | |
8145 } | |
8146 else if (plan == PLAN_NL) | |
8147 { | |
8148 if (noinvcurs) | |
8149 screen_stop_highlight(); | |
8150 while (screen_cur_row < row) | |
8151 { | |
8152 out_char('\n'); | |
8153 ++screen_cur_row; | |
8154 } | |
8155 screen_cur_col = 0; | |
8156 } | |
8157 | |
8158 i = col - screen_cur_col; | |
8159 if (i > 0) | |
8160 { | |
8161 /* | |
8162 * Use cursor-right if it's one character only. Avoids | |
8163 * removing a line of pixels from the last bold char, when | |
8164 * using the bold trick in the GUI. | |
8165 */ | |
8166 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8167 { | |
8168 while (i-- > 0) | |
8169 out_char(*T_ND); | |
8170 } | |
8171 else | |
8172 { | |
8173 int off; | |
8174 | |
8175 off = LineOffset[row] + screen_cur_col; | |
8176 while (i-- > 0) | |
8177 { | |
8178 if (ScreenAttrs[off] != screen_attr) | |
8179 screen_stop_highlight(); | |
8180 #ifdef FEAT_MBYTE | |
8181 out_flush_check(); | |
8182 #endif | |
8183 out_char(ScreenLines[off]); | |
8184 #ifdef FEAT_MBYTE | |
8185 if (enc_dbcs == DBCS_JPNU | |
8186 && ScreenLines[off] == 0x8e) | |
8187 out_char(ScreenLines2[off]); | |
8188 #endif | |
8189 ++off; | |
8190 } | |
8191 } | |
8192 } | |
8193 } | |
8194 } | |
8195 else | |
8196 cost = 999; | |
8197 | |
8198 if (cost >= goto_cost) | |
8199 { | |
8200 if (noinvcurs) | |
8201 screen_stop_highlight(); | |
8202 if (row == screen_cur_row && (col > screen_cur_col) && | |
8203 *T_CRI != NUL) | |
8204 term_cursor_right(col - screen_cur_col); | |
8205 else | |
8206 term_windgoto(row, col); | |
8207 } | |
8208 screen_cur_row = row; | |
8209 screen_cur_col = col; | |
8210 } | |
8211 } | |
8212 | |
8213 /* | |
8214 * Set cursor to its position in the current window. | |
8215 */ | |
8216 void | |
8217 setcursor() | |
8218 { | |
8219 if (redrawing()) | |
8220 { | |
8221 validate_cursor(); | |
8222 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8223 W_WINCOL(curwin) + ( | |
8224 #ifdef FEAT_RIGHTLEFT | |
1545 | 8225 /* With 'rightleft' set and the cursor on a double-wide |
8226 * character, position it on the leftmost column. */ | |
7 | 8227 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8228 # ifdef FEAT_MBYTE | |
1545 | 8229 (has_mbyte |
8230 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8231 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8232 # endif |
8233 1)) : | |
8234 #endif | |
8235 curwin->w_wcol)); | |
8236 } | |
8237 } | |
8238 | |
8239 | |
8240 /* | |
8241 * insert 'line_count' lines at 'row' in window 'wp' | |
8242 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8243 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8244 * scrolling. | |
8245 * Returns FAIL if the lines are not inserted, OK for success. | |
8246 */ | |
8247 int | |
8248 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8249 win_T *wp; | |
8250 int row; | |
8251 int line_count; | |
8252 int invalid; | |
8253 int mayclear; | |
8254 { | |
8255 int did_delete; | |
8256 int nextrow; | |
8257 int lastrow; | |
8258 int retval; | |
8259 | |
8260 if (invalid) | |
8261 wp->w_lines_valid = 0; | |
8262 | |
8263 if (wp->w_height < 5) | |
8264 return FAIL; | |
8265 | |
8266 if (line_count > wp->w_height - row) | |
8267 line_count = wp->w_height - row; | |
8268 | |
8269 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8270 if (retval != MAYBE) | |
8271 return retval; | |
8272 | |
8273 /* | |
8274 * If there is a next window or a status line, we first try to delete the | |
8275 * lines at the bottom to avoid messing what is after the window. | |
8276 * If this fails and there are following windows, don't do anything to avoid | |
8277 * messing up those windows, better just redraw. | |
8278 */ | |
8279 did_delete = FALSE; | |
8280 #ifdef FEAT_WINDOWS | |
8281 if (wp->w_next != NULL || wp->w_status_height) | |
8282 { | |
8283 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8284 line_count, (int)Rows, FALSE, NULL) == OK) | |
8285 did_delete = TRUE; | |
8286 else if (wp->w_next) | |
8287 return FAIL; | |
8288 } | |
8289 #endif | |
8290 /* | |
8291 * if no lines deleted, blank the lines that will end up below the window | |
8292 */ | |
8293 if (!did_delete) | |
8294 { | |
8295 #ifdef FEAT_WINDOWS | |
8296 wp->w_redr_status = TRUE; | |
8297 #endif | |
8298 redraw_cmdline = TRUE; | |
8299 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8300 lastrow = nextrow + line_count; | |
8301 if (lastrow > Rows) | |
8302 lastrow = Rows; | |
8303 screen_fill(nextrow - line_count, lastrow - line_count, | |
8304 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8305 ' ', ' ', 0); | |
8306 } | |
8307 | |
8308 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8309 == FAIL) | |
8310 { | |
8311 /* deletion will have messed up other windows */ | |
8312 if (did_delete) | |
8313 { | |
8314 #ifdef FEAT_WINDOWS | |
8315 wp->w_redr_status = TRUE; | |
8316 #endif | |
8317 win_rest_invalid(W_NEXT(wp)); | |
8318 } | |
8319 return FAIL; | |
8320 } | |
8321 | |
8322 return OK; | |
8323 } | |
8324 | |
8325 /* | |
8326 * delete "line_count" window lines at "row" in window "wp" | |
8327 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8328 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8329 * scrolling | |
8330 * Return OK for success, FAIL if the lines are not deleted. | |
8331 */ | |
8332 int | |
8333 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8334 win_T *wp; | |
8335 int row; | |
8336 int line_count; | |
8337 int invalid; | |
8338 int mayclear; | |
8339 { | |
8340 int retval; | |
8341 | |
8342 if (invalid) | |
8343 wp->w_lines_valid = 0; | |
8344 | |
8345 if (line_count > wp->w_height - row) | |
8346 line_count = wp->w_height - row; | |
8347 | |
8348 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8349 if (retval != MAYBE) | |
8350 return retval; | |
8351 | |
8352 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8353 (int)Rows, FALSE, NULL) == FAIL) | |
8354 return FAIL; | |
8355 | |
8356 #ifdef FEAT_WINDOWS | |
8357 /* | |
8358 * If there are windows or status lines below, try to put them at the | |
8359 * correct place. If we can't do that, they have to be redrawn. | |
8360 */ | |
8361 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8362 { | |
8363 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8364 line_count, (int)Rows, NULL) == FAIL) | |
8365 { | |
8366 wp->w_redr_status = TRUE; | |
8367 win_rest_invalid(wp->w_next); | |
8368 } | |
8369 } | |
8370 /* | |
8371 * If this is the last window and there is no status line, redraw the | |
8372 * command line later. | |
8373 */ | |
8374 else | |
8375 #endif | |
8376 redraw_cmdline = TRUE; | |
8377 return OK; | |
8378 } | |
8379 | |
8380 /* | |
8381 * Common code for win_ins_lines() and win_del_lines(). | |
8382 * Returns OK or FAIL when the work has been done. | |
8383 * Returns MAYBE when not finished yet. | |
8384 */ | |
8385 static int | |
8386 win_do_lines(wp, row, line_count, mayclear, del) | |
8387 win_T *wp; | |
8388 int row; | |
8389 int line_count; | |
8390 int mayclear; | |
8391 int del; | |
8392 { | |
8393 int retval; | |
8394 | |
8395 if (!redrawing() || line_count <= 0) | |
8396 return FAIL; | |
8397 | |
8398 /* only a few lines left: redraw is faster */ | |
8399 if (mayclear && Rows - line_count < 5 | |
8400 #ifdef FEAT_VERTSPLIT | |
8401 && wp->w_width == Columns | |
8402 #endif | |
8403 ) | |
8404 { | |
8405 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8406 return FAIL; | |
8407 } | |
8408 | |
8409 /* | |
8410 * Delete all remaining lines | |
8411 */ | |
8412 if (row + line_count >= wp->w_height) | |
8413 { | |
8414 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8415 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8416 ' ', ' ', 0); | |
8417 return OK; | |
8418 } | |
8419 | |
8420 /* | |
8421 * when scrolling, the message on the command line should be cleared, | |
8422 * otherwise it will stay there forever. | |
8423 */ | |
8424 clear_cmdline = TRUE; | |
8425 | |
8426 /* | |
8427 * If the terminal can set a scroll region, use that. | |
8428 * Always do this in a vertically split window. This will redraw from | |
8429 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8430 * win_line(). | |
8431 * Don't use a scroll region when we are going to redraw the text, writing | |
8432 * a character in the lower right corner of the scroll region causes a | |
8433 * scroll-up in the DJGPP version. | |
8434 */ | |
8435 if (scroll_region | |
8436 #ifdef FEAT_VERTSPLIT | |
8437 || W_WIDTH(wp) != Columns | |
8438 #endif | |
8439 ) | |
8440 { | |
8441 #ifdef FEAT_VERTSPLIT | |
8442 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8443 #endif | |
8444 scroll_region_set(wp, row); | |
8445 if (del) | |
8446 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8447 wp->w_height - row, FALSE, wp); | |
8448 else | |
8449 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8450 wp->w_height - row, wp); | |
8451 #ifdef FEAT_VERTSPLIT | |
8452 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8453 #endif | |
8454 scroll_region_reset(); | |
8455 return retval; | |
8456 } | |
8457 | |
8458 #ifdef FEAT_WINDOWS | |
8459 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8460 return FAIL; | |
8461 #endif | |
8462 | |
8463 return MAYBE; | |
8464 } | |
8465 | |
8466 /* | |
8467 * window 'wp' and everything after it is messed up, mark it for redraw | |
8468 */ | |
8469 static void | |
8470 win_rest_invalid(wp) | |
8471 win_T *wp; | |
8472 { | |
8473 #ifdef FEAT_WINDOWS | |
8474 while (wp != NULL) | |
8475 #else | |
8476 if (wp != NULL) | |
8477 #endif | |
8478 { | |
8479 redraw_win_later(wp, NOT_VALID); | |
8480 #ifdef FEAT_WINDOWS | |
8481 wp->w_redr_status = TRUE; | |
8482 wp = wp->w_next; | |
8483 #endif | |
8484 } | |
8485 redraw_cmdline = TRUE; | |
8486 } | |
8487 | |
8488 /* | |
8489 * The rest of the routines in this file perform screen manipulations. The | |
8490 * given operation is performed physically on the screen. The corresponding | |
8491 * change is also made to the internal screen image. In this way, the editor | |
8492 * anticipates the effect of editing changes on the appearance of the screen. | |
8493 * That way, when we call screenupdate a complete redraw isn't usually | |
8494 * necessary. Another advantage is that we can keep adding code to anticipate | |
8495 * screen changes, and in the meantime, everything still works. | |
8496 */ | |
8497 | |
8498 /* | |
8499 * types for inserting or deleting lines | |
8500 */ | |
8501 #define USE_T_CAL 1 | |
8502 #define USE_T_CDL 2 | |
8503 #define USE_T_AL 3 | |
8504 #define USE_T_CE 4 | |
8505 #define USE_T_DL 5 | |
8506 #define USE_T_SR 6 | |
8507 #define USE_NL 7 | |
8508 #define USE_T_CD 8 | |
8509 #define USE_REDRAW 9 | |
8510 | |
8511 /* | |
8512 * insert lines on the screen and update ScreenLines[] | |
8513 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8514 * When scrolling region used 'off' is the offset from the top for the region. | |
8515 * 'row' and 'end' are relative to the start of the region. | |
8516 * | |
8517 * return FAIL for failure, OK for success. | |
8518 */ | |
446 | 8519 int |
7 | 8520 screen_ins_lines(off, row, line_count, end, wp) |
8521 int off; | |
8522 int row; | |
8523 int line_count; | |
8524 int end; | |
8525 win_T *wp; /* NULL or window to use width from */ | |
8526 { | |
8527 int i; | |
8528 int j; | |
8529 unsigned temp; | |
8530 int cursor_row; | |
8531 int type; | |
8532 int result_empty; | |
8533 int can_ce = can_clear(T_CE); | |
8534 | |
8535 /* | |
8536 * FAIL if | |
8537 * - there is no valid screen | |
8538 * - the screen has to be redrawn completely | |
8539 * - the line count is less than one | |
8540 * - the line count is more than 'ttyscroll' | |
8541 */ | |
8542 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8543 return FAIL; | |
8544 | |
8545 /* | |
8546 * There are seven ways to insert lines: | |
8547 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8548 * characters from ScreenLines[]. | |
8549 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8550 * the insert is just empty lines | |
8551 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8552 * present or line_count > 1. It looks better if we do all the inserts | |
8553 * at once. | |
8554 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8555 * insert is just empty lines and T_CE is not present or line_count > | |
8556 * 1. | |
8557 * 4. Use T_AL (insert line) if it exists. | |
8558 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8559 * just empty lines. | |
8560 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8561 * just empty lines. | |
8562 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8563 * the 'da' flag is not set or we have clear line capability. | |
8564 * 8. redraw the characters from ScreenLines[]. | |
8565 * | |
8566 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8567 * the scrollbar for the window. It does have insert line, use that if it | |
8568 * exists. | |
8569 */ | |
8570 result_empty = (row + line_count >= end); | |
8571 #ifdef FEAT_VERTSPLIT | |
8572 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8573 type = USE_REDRAW; | |
8574 else | |
8575 #endif | |
8576 if (can_clear(T_CD) && result_empty) | |
8577 type = USE_T_CD; | |
8578 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8579 type = USE_T_CAL; | |
8580 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8581 type = USE_T_CDL; | |
8582 else if (*T_AL != NUL) | |
8583 type = USE_T_AL; | |
8584 else if (can_ce && result_empty) | |
8585 type = USE_T_CE; | |
8586 else if (*T_DL != NUL && result_empty) | |
8587 type = USE_T_DL; | |
8588 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8589 type = USE_T_SR; | |
8590 else | |
8591 return FAIL; | |
8592 | |
8593 /* | |
8594 * For clearing the lines screen_del_lines() is used. This will also take | |
8595 * care of t_db if necessary. | |
8596 */ | |
8597 if (type == USE_T_CD || type == USE_T_CDL || | |
8598 type == USE_T_CE || type == USE_T_DL) | |
8599 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8600 | |
8601 /* | |
8602 * If text is retained below the screen, first clear or delete as many | |
8603 * lines at the bottom of the window as are about to be inserted so that | |
8604 * the deleted lines won't later surface during a screen_del_lines. | |
8605 */ | |
8606 if (*T_DB) | |
8607 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
8608 | |
8609 #ifdef FEAT_CLIPBOARD | |
8610 /* Remove a modeless selection when inserting lines halfway the screen | |
8611 * or not the full width of the screen. */ | |
8612 if (off + row > 0 | |
8613 # ifdef FEAT_VERTSPLIT | |
8614 || (wp != NULL && wp->w_width != Columns) | |
8615 # endif | |
8616 ) | |
8617 clip_clear_selection(); | |
8618 else | |
8619 clip_scroll_selection(-line_count); | |
8620 #endif | |
8621 | |
8622 #ifdef FEAT_GUI | |
8623 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
8624 * scrolling is actually carried out. */ | |
8625 gui_dont_update_cursor(); | |
8626 #endif | |
8627 | |
8628 if (*T_CCS != NUL) /* cursor relative to region */ | |
8629 cursor_row = row; | |
8630 else | |
8631 cursor_row = row + off; | |
8632 | |
8633 /* | |
8634 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
8635 * Clear the inserted lines in ScreenLines[]. | |
8636 */ | |
8637 row += off; | |
8638 end += off; | |
8639 for (i = 0; i < line_count; ++i) | |
8640 { | |
8641 #ifdef FEAT_VERTSPLIT | |
8642 if (wp != NULL && wp->w_width != Columns) | |
8643 { | |
8644 /* need to copy part of a line */ | |
8645 j = end - 1 - i; | |
8646 while ((j -= line_count) >= row) | |
8647 linecopy(j + line_count, j, wp); | |
8648 j += line_count; | |
8649 if (can_clear((char_u *)" ")) | |
8650 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8651 else | |
8652 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8653 LineWraps[j] = FALSE; | |
8654 } | |
8655 else | |
8656 #endif | |
8657 { | |
8658 j = end - 1 - i; | |
8659 temp = LineOffset[j]; | |
8660 while ((j -= line_count) >= row) | |
8661 { | |
8662 LineOffset[j + line_count] = LineOffset[j]; | |
8663 LineWraps[j + line_count] = LineWraps[j]; | |
8664 } | |
8665 LineOffset[j + line_count] = temp; | |
8666 LineWraps[j + line_count] = FALSE; | |
8667 if (can_clear((char_u *)" ")) | |
8668 lineclear(temp, (int)Columns); | |
8669 else | |
8670 lineinvalid(temp, (int)Columns); | |
8671 } | |
8672 } | |
8673 | |
8674 screen_stop_highlight(); | |
8675 windgoto(cursor_row, 0); | |
8676 | |
8677 #ifdef FEAT_VERTSPLIT | |
8678 /* redraw the characters */ | |
8679 if (type == USE_REDRAW) | |
8680 redraw_block(row, end, wp); | |
8681 else | |
8682 #endif | |
8683 if (type == USE_T_CAL) | |
8684 { | |
8685 term_append_lines(line_count); | |
8686 screen_start(); /* don't know where cursor is now */ | |
8687 } | |
8688 else | |
8689 { | |
8690 for (i = 0; i < line_count; i++) | |
8691 { | |
8692 if (type == USE_T_AL) | |
8693 { | |
8694 if (i && cursor_row != 0) | |
8695 windgoto(cursor_row, 0); | |
8696 out_str(T_AL); | |
8697 } | |
8698 else /* type == USE_T_SR */ | |
8699 out_str(T_SR); | |
8700 screen_start(); /* don't know where cursor is now */ | |
8701 } | |
8702 } | |
8703 | |
8704 /* | |
8705 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
8706 * have been scrolled down into the region. | |
8707 */ | |
8708 if (type == USE_T_SR && *T_DA) | |
8709 { | |
8710 for (i = 0; i < line_count; ++i) | |
8711 { | |
8712 windgoto(off + i, 0); | |
8713 out_str(T_CE); | |
8714 screen_start(); /* don't know where cursor is now */ | |
8715 } | |
8716 } | |
8717 | |
8718 #ifdef FEAT_GUI | |
8719 gui_can_update_cursor(); | |
8720 if (gui.in_use) | |
8721 out_flush(); /* always flush after a scroll */ | |
8722 #endif | |
8723 return OK; | |
8724 } | |
8725 | |
8726 /* | |
8727 * delete lines on the screen and update ScreenLines[] | |
8728 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8729 * When scrolling region used 'off' is the offset from the top for the region. | |
8730 * 'row' and 'end' are relative to the start of the region. | |
8731 * | |
8732 * Return OK for success, FAIL if the lines are not deleted. | |
8733 */ | |
8734 int | |
8735 screen_del_lines(off, row, line_count, end, force, wp) | |
8736 int off; | |
8737 int row; | |
8738 int line_count; | |
8739 int end; | |
8740 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 8741 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 8742 { |
8743 int j; | |
8744 int i; | |
8745 unsigned temp; | |
8746 int cursor_row; | |
8747 int cursor_end; | |
8748 int result_empty; /* result is empty until end of region */ | |
8749 int can_delete; /* deleting line codes can be used */ | |
8750 int type; | |
8751 | |
8752 /* | |
8753 * FAIL if | |
8754 * - there is no valid screen | |
8755 * - the screen has to be redrawn completely | |
8756 * - the line count is less than one | |
8757 * - the line count is more than 'ttyscroll' | |
8758 */ | |
8759 if (!screen_valid(TRUE) || line_count <= 0 || | |
8760 (!force && line_count > p_ttyscroll)) | |
8761 return FAIL; | |
8762 | |
8763 /* | |
8764 * Check if the rest of the current region will become empty. | |
8765 */ | |
8766 result_empty = row + line_count >= end; | |
8767 | |
8768 /* | |
8769 * We can delete lines only when 'db' flag not set or when 'ce' option | |
8770 * available. | |
8771 */ | |
8772 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
8773 | |
8774 /* | |
8775 * There are six ways to delete lines: | |
8776 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8777 * characters from ScreenLines[]. | |
8778 * 1. Use T_CD if it exists and the result is empty. | |
8779 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
8780 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
8781 * none of the other ways work. | |
8782 * 4. Use T_CE (erase line) if the result is empty. | |
8783 * 5. Use T_DL (delete line) if it exists. | |
8784 * 6. redraw the characters from ScreenLines[]. | |
8785 */ | |
8786 #ifdef FEAT_VERTSPLIT | |
8787 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8788 type = USE_REDRAW; | |
8789 else | |
8790 #endif | |
8791 if (can_clear(T_CD) && result_empty) | |
8792 type = USE_T_CD; | |
8793 #if defined(__BEOS__) && defined(BEOS_DR8) | |
8794 /* | |
8795 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
8796 * its internal termcap... this works okay for tests which test *T_DB != | |
8797 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
8798 * command to get T_DB (back) to empty_option, only :set term=... will do | |
8799 * the trick... | |
8800 * Anyway, this hack will hopefully go away with the next OS release. | |
8801 * (Olaf Seibert) | |
8802 */ | |
8803 else if (row == 0 && T_DB == empty_option | |
8804 && (line_count == 1 || *T_CDL == NUL)) | |
8805 #else | |
8806 else if (row == 0 && ( | |
8807 #ifndef AMIGA | |
8808 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
8809 * up, so use delete-line command */ | |
8810 line_count == 1 || | |
8811 #endif | |
8812 *T_CDL == NUL)) | |
8813 #endif | |
8814 type = USE_NL; | |
8815 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
8816 type = USE_T_CDL; | |
8817 else if (can_clear(T_CE) && result_empty | |
8818 #ifdef FEAT_VERTSPLIT | |
8819 && (wp == NULL || wp->w_width == Columns) | |
8820 #endif | |
8821 ) | |
8822 type = USE_T_CE; | |
8823 else if (*T_DL != NUL && can_delete) | |
8824 type = USE_T_DL; | |
8825 else if (*T_CDL != NUL && can_delete) | |
8826 type = USE_T_CDL; | |
8827 else | |
8828 return FAIL; | |
8829 | |
8830 #ifdef FEAT_CLIPBOARD | |
8831 /* Remove a modeless selection when deleting lines halfway the screen or | |
8832 * not the full width of the screen. */ | |
8833 if (off + row > 0 | |
8834 # ifdef FEAT_VERTSPLIT | |
8835 || (wp != NULL && wp->w_width != Columns) | |
8836 # endif | |
8837 ) | |
8838 clip_clear_selection(); | |
8839 else | |
8840 clip_scroll_selection(line_count); | |
8841 #endif | |
8842 | |
8843 #ifdef FEAT_GUI | |
8844 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
8845 * scrolling is actually carried out. */ | |
8846 gui_dont_update_cursor(); | |
8847 #endif | |
8848 | |
8849 if (*T_CCS != NUL) /* cursor relative to region */ | |
8850 { | |
8851 cursor_row = row; | |
8852 cursor_end = end; | |
8853 } | |
8854 else | |
8855 { | |
8856 cursor_row = row + off; | |
8857 cursor_end = end + off; | |
8858 } | |
8859 | |
8860 /* | |
8861 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
8862 * Clear the inserted lines in ScreenLines[]. | |
8863 */ | |
8864 row += off; | |
8865 end += off; | |
8866 for (i = 0; i < line_count; ++i) | |
8867 { | |
8868 #ifdef FEAT_VERTSPLIT | |
8869 if (wp != NULL && wp->w_width != Columns) | |
8870 { | |
8871 /* need to copy part of a line */ | |
8872 j = row + i; | |
8873 while ((j += line_count) <= end - 1) | |
8874 linecopy(j - line_count, j, wp); | |
8875 j -= line_count; | |
8876 if (can_clear((char_u *)" ")) | |
8877 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8878 else | |
8879 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8880 LineWraps[j] = FALSE; | |
8881 } | |
8882 else | |
8883 #endif | |
8884 { | |
8885 /* whole width, moving the line pointers is faster */ | |
8886 j = row + i; | |
8887 temp = LineOffset[j]; | |
8888 while ((j += line_count) <= end - 1) | |
8889 { | |
8890 LineOffset[j - line_count] = LineOffset[j]; | |
8891 LineWraps[j - line_count] = LineWraps[j]; | |
8892 } | |
8893 LineOffset[j - line_count] = temp; | |
8894 LineWraps[j - line_count] = FALSE; | |
8895 if (can_clear((char_u *)" ")) | |
8896 lineclear(temp, (int)Columns); | |
8897 else | |
8898 lineinvalid(temp, (int)Columns); | |
8899 } | |
8900 } | |
8901 | |
8902 screen_stop_highlight(); | |
8903 | |
8904 #ifdef FEAT_VERTSPLIT | |
8905 /* redraw the characters */ | |
8906 if (type == USE_REDRAW) | |
8907 redraw_block(row, end, wp); | |
8908 else | |
8909 #endif | |
8910 if (type == USE_T_CD) /* delete the lines */ | |
8911 { | |
8912 windgoto(cursor_row, 0); | |
8913 out_str(T_CD); | |
8914 screen_start(); /* don't know where cursor is now */ | |
8915 } | |
8916 else if (type == USE_T_CDL) | |
8917 { | |
8918 windgoto(cursor_row, 0); | |
8919 term_delete_lines(line_count); | |
8920 screen_start(); /* don't know where cursor is now */ | |
8921 } | |
8922 /* | |
8923 * Deleting lines at top of the screen or scroll region: Just scroll | |
8924 * the whole screen (scroll region) up by outputting newlines on the | |
8925 * last line. | |
8926 */ | |
8927 else if (type == USE_NL) | |
8928 { | |
8929 windgoto(cursor_end - 1, 0); | |
8930 for (i = line_count; --i >= 0; ) | |
8931 out_char('\n'); /* cursor will remain on same line */ | |
8932 } | |
8933 else | |
8934 { | |
8935 for (i = line_count; --i >= 0; ) | |
8936 { | |
8937 if (type == USE_T_DL) | |
8938 { | |
8939 windgoto(cursor_row, 0); | |
8940 out_str(T_DL); /* delete a line */ | |
8941 } | |
8942 else /* type == USE_T_CE */ | |
8943 { | |
8944 windgoto(cursor_row + i, 0); | |
8945 out_str(T_CE); /* erase a line */ | |
8946 } | |
8947 screen_start(); /* don't know where cursor is now */ | |
8948 } | |
8949 } | |
8950 | |
8951 /* | |
8952 * If the 'db' flag is set, we need to clear the lines that have been | |
8953 * scrolled up at the bottom of the region. | |
8954 */ | |
8955 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
8956 { | |
8957 for (i = line_count; i > 0; --i) | |
8958 { | |
8959 windgoto(cursor_end - i, 0); | |
8960 out_str(T_CE); /* erase a line */ | |
8961 screen_start(); /* don't know where cursor is now */ | |
8962 } | |
8963 } | |
8964 | |
8965 #ifdef FEAT_GUI | |
8966 gui_can_update_cursor(); | |
8967 if (gui.in_use) | |
8968 out_flush(); /* always flush after a scroll */ | |
8969 #endif | |
8970 | |
8971 return OK; | |
8972 } | |
8973 | |
8974 /* | |
8975 * show the current mode and ruler | |
8976 * | |
8977 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
8978 * If clear_cmdline is FALSE there may be a message there that needs to be | |
8979 * cleared only if a mode is shown. | |
8980 * Return the length of the message (0 if no message). | |
8981 */ | |
8982 int | |
8983 showmode() | |
8984 { | |
8985 int need_clear; | |
8986 int length = 0; | |
8987 int do_mode; | |
8988 int attr; | |
8989 int nwr_save; | |
8990 #ifdef FEAT_INS_EXPAND | |
8991 int sub_attr; | |
8992 #endif | |
8993 | |
642 | 8994 do_mode = ((p_smd && msg_silent == 0) |
8995 && ((State & INSERT) | |
8996 || restart_edit | |
7 | 8997 #ifdef FEAT_VISUAL |
8998 || VIsual_active | |
8999 #endif | |
9000 )); | |
9001 if (do_mode || Recording) | |
9002 { | |
9003 /* | |
9004 * Don't show mode right now, when not redrawing or inside a mapping. | |
9005 * Call char_avail() only when we are going to show something, because | |
9006 * it takes a bit of time. | |
9007 */ | |
9008 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9009 { | |
9010 redraw_cmdline = TRUE; /* show mode later */ | |
9011 return 0; | |
9012 } | |
9013 | |
9014 nwr_save = need_wait_return; | |
9015 | |
9016 /* wait a bit before overwriting an important message */ | |
9017 check_for_delay(FALSE); | |
9018 | |
9019 /* if the cmdline is more than one line high, erase top lines */ | |
9020 need_clear = clear_cmdline; | |
9021 if (clear_cmdline && cmdline_row < Rows - 1) | |
9022 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9023 | |
9024 /* Position on the last line in the window, column 0 */ | |
9025 msg_pos_mode(); | |
9026 cursor_off(); | |
9027 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9028 if (do_mode) | |
9029 { | |
9030 MSG_PUTS_ATTR("--", attr); | |
9031 #if defined(FEAT_XIM) | |
1668 | 9032 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9033 if (xic != NULL && im_get_status() && !p_imdisable |
9034 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9035 # else |
9036 if ( | |
9037 # ifdef HAVE_GTK2 | |
9038 preedit_get_status() | |
9039 # else | |
9040 im_get_status() | |
9041 # endif | |
9042 ) | |
9043 # endif | |
7 | 9044 # ifdef HAVE_GTK2 /* most of the time, it's not XIM being used */ |
9045 MSG_PUTS_ATTR(" IM", attr); | |
9046 # else | |
9047 MSG_PUTS_ATTR(" XIM", attr); | |
9048 # endif | |
9049 #endif | |
9050 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9051 if (gui.in_use) | |
9052 { | |
9053 if (hangul_input_state_get()) | |
236 | 9054 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9055 } |
9056 #endif | |
9057 #ifdef FEAT_INS_EXPAND | |
9058 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9059 { | |
9060 /* These messages can get long, avoid a wrap in a narrow | |
9061 * window. Prefer showing edit_submode_extra. */ | |
9062 length = (Rows - msg_row) * Columns - 3; | |
9063 if (edit_submode_extra != NULL) | |
9064 length -= vim_strsize(edit_submode_extra); | |
9065 if (length > 0) | |
9066 { | |
9067 if (edit_submode_pre != NULL) | |
9068 length -= vim_strsize(edit_submode_pre); | |
9069 if (length - vim_strsize(edit_submode) > 0) | |
9070 { | |
9071 if (edit_submode_pre != NULL) | |
9072 msg_puts_attr(edit_submode_pre, attr); | |
9073 msg_puts_attr(edit_submode, attr); | |
9074 } | |
9075 if (edit_submode_extra != NULL) | |
9076 { | |
9077 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9078 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9079 sub_attr = hl_attr(edit_submode_highl); | |
9080 else | |
9081 sub_attr = attr; | |
9082 msg_puts_attr(edit_submode_extra, sub_attr); | |
9083 } | |
9084 } | |
9085 length = 0; | |
9086 } | |
9087 else | |
9088 #endif | |
9089 { | |
9090 #ifdef FEAT_VREPLACE | |
9091 if (State & VREPLACE_FLAG) | |
9092 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9093 else | |
9094 #endif | |
9095 if (State & REPLACE_FLAG) | |
9096 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9097 else if (State & INSERT) | |
9098 { | |
9099 #ifdef FEAT_RIGHTLEFT | |
9100 if (p_ri) | |
9101 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9102 #endif | |
9103 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9104 } | |
9105 else if (restart_edit == 'I') | |
9106 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9107 else if (restart_edit == 'R') | |
9108 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9109 else if (restart_edit == 'V') | |
9110 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9111 #ifdef FEAT_RIGHTLEFT | |
9112 if (p_hkmap) | |
9113 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9114 # ifdef FEAT_FKMAP | |
9115 if (p_fkmap) | |
9116 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9117 # endif | |
9118 #endif | |
9119 #ifdef FEAT_KEYMAP | |
9120 if (State & LANGMAP) | |
9121 { | |
9122 # ifdef FEAT_ARABIC | |
9123 if (curwin->w_p_arab) | |
9124 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9125 else | |
9126 # endif | |
9127 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9128 } | |
9129 #endif | |
9130 if ((State & INSERT) && p_paste) | |
9131 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9132 | |
9133 #ifdef FEAT_VISUAL | |
9134 if (VIsual_active) | |
9135 { | |
9136 char *p; | |
9137 | |
9138 /* Don't concatenate separate words to avoid translation | |
9139 * problems. */ | |
9140 switch ((VIsual_select ? 4 : 0) | |
9141 + (VIsual_mode == Ctrl_V) * 2 | |
9142 + (VIsual_mode == 'V')) | |
9143 { | |
9144 case 0: p = N_(" VISUAL"); break; | |
9145 case 1: p = N_(" VISUAL LINE"); break; | |
9146 case 2: p = N_(" VISUAL BLOCK"); break; | |
9147 case 4: p = N_(" SELECT"); break; | |
9148 case 5: p = N_(" SELECT LINE"); break; | |
9149 default: p = N_(" SELECT BLOCK"); break; | |
9150 } | |
9151 MSG_PUTS_ATTR(_(p), attr); | |
9152 } | |
9153 #endif | |
9154 MSG_PUTS_ATTR(" --", attr); | |
9155 } | |
644 | 9156 |
7 | 9157 need_clear = TRUE; |
9158 } | |
9159 if (Recording | |
9160 #ifdef FEAT_INS_EXPAND | |
9161 && edit_submode == NULL /* otherwise it gets too long */ | |
9162 #endif | |
9163 ) | |
9164 { | |
9165 MSG_PUTS_ATTR(_("recording"), attr); | |
9166 need_clear = TRUE; | |
9167 } | |
644 | 9168 |
9169 mode_displayed = TRUE; | |
7 | 9170 if (need_clear || clear_cmdline) |
9171 msg_clr_eos(); | |
9172 msg_didout = FALSE; /* overwrite this message */ | |
9173 length = msg_col; | |
9174 msg_col = 0; | |
9175 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9176 } | |
9177 else if (clear_cmdline && msg_silent == 0) | |
9178 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9179 msg_clr_cmdline(); | |
9180 | |
9181 #ifdef FEAT_CMDL_INFO | |
9182 # ifdef FEAT_VISUAL | |
9183 /* In Visual mode the size of the selected area must be redrawn. */ | |
9184 if (VIsual_active) | |
9185 clear_showcmd(); | |
9186 # endif | |
9187 | |
9188 /* If the last window has no status line, the ruler is after the mode | |
9189 * message and must be redrawn */ | |
9190 if (redrawing() | |
9191 # ifdef FEAT_WINDOWS | |
9192 && lastwin->w_status_height == 0 | |
9193 # endif | |
9194 ) | |
9195 win_redr_ruler(lastwin, TRUE); | |
9196 #endif | |
9197 redraw_cmdline = FALSE; | |
9198 clear_cmdline = FALSE; | |
9199 | |
9200 return length; | |
9201 } | |
9202 | |
9203 /* | |
9204 * Position for a mode message. | |
9205 */ | |
9206 static void | |
9207 msg_pos_mode() | |
9208 { | |
9209 msg_col = 0; | |
9210 msg_row = Rows - 1; | |
9211 } | |
9212 | |
9213 /* | |
9214 * Delete mode message. Used when ESC is typed which is expected to end | |
9215 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9216 * Caller should check "mode_displayed". |
7 | 9217 */ |
9218 void | |
9219 unshowmode(force) | |
9220 int force; | |
9221 { | |
9222 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9223 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9224 */ |
9225 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9226 redraw_cmdline = TRUE; /* delete mode later */ | |
9227 else | |
9228 { | |
9229 msg_pos_mode(); | |
9230 if (Recording) | |
9231 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9232 msg_clr_eos(); | |
9233 } | |
9234 } | |
9235 | |
667 | 9236 #if defined(FEAT_WINDOWS) |
9237 /* | |
9238 * Draw the tab pages line at the top of the Vim window. | |
9239 */ | |
9240 static void | |
677 | 9241 draw_tabline() |
667 | 9242 { |
9243 int tabcount = 0; | |
9244 tabpage_T *tp; | |
9245 int tabwidth; | |
9246 int col = 0; | |
673 | 9247 int scol = 0; |
667 | 9248 int attr; |
9249 win_T *wp; | |
671 | 9250 win_T *cwp; |
9251 int wincount; | |
9252 int modified; | |
667 | 9253 int c; |
9254 int len; | |
9255 int attr_sel = hl_attr(HLF_TPS); | |
9256 int attr_nosel = hl_attr(HLF_TP); | |
9257 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9258 char_u *p; |
677 | 9259 int room; |
9260 int use_sep_chars = (t_colors < 8 | |
9261 #ifdef FEAT_GUI | |
9262 && !gui.in_use | |
9263 #endif | |
9264 ); | |
673 | 9265 |
9266 redraw_tabline = FALSE; | |
667 | 9267 |
685 | 9268 #ifdef FEAT_GUI_TABLINE |
798 | 9269 /* Take care of a GUI tabline. */ |
685 | 9270 if (gui_use_tabline()) |
9271 { | |
9272 gui_update_tabline(); | |
9273 return; | |
9274 } | |
9275 #endif | |
9276 | |
9277 if (tabline_height() < 1) | |
667 | 9278 return; |
9279 | |
677 | 9280 #if defined(FEAT_STL_OPT) |
681 | 9281 |
9282 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9283 for (scol = 0; scol < Columns; ++scol) | |
9284 TabPageIdxs[scol] = 0; | |
9285 | |
677 | 9286 /* Use the 'tabline' option if it's set. */ |
9287 if (*p_tal != NUL) | |
9288 { | |
680 | 9289 int save_called_emsg = called_emsg; |
9290 | |
9291 /* Check for an error. If there is one we would loop in redrawing the | |
9292 * screen. Avoid that by making 'tabline' empty. */ | |
9293 called_emsg = FALSE; | |
677 | 9294 win_redr_custom(NULL, FALSE); |
680 | 9295 if (called_emsg) |
9296 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9297 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9298 called_emsg |= save_called_emsg; |
9299 } | |
9300 else | |
9301 #endif | |
9302 { | |
9303 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9304 ++tabcount; | |
9305 | |
9306 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9307 if (tabwidth < 6) | |
9308 tabwidth = 6; | |
9309 | |
9310 attr = attr_nosel; | |
9311 tabcount = 0; | |
681 | 9312 scol = 0; |
699 | 9313 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9314 tp = tp->tp_next) | |
680 | 9315 { |
9316 scol = col; | |
9317 | |
9318 if (tp->tp_topframe == topframe) | |
9319 attr = attr_sel; | |
9320 if (use_sep_chars && col > 0) | |
9321 screen_putchar('|', 0, col++, attr); | |
9322 | |
9323 if (tp->tp_topframe != topframe) | |
9324 attr = attr_nosel; | |
9325 | |
9326 screen_putchar(' ', 0, col++, attr); | |
9327 | |
9328 if (tp == curtab) | |
9329 { | |
9330 cwp = curwin; | |
9331 wp = firstwin; | |
9332 } | |
9333 else | |
9334 { | |
9335 cwp = tp->tp_curwin; | |
9336 wp = tp->tp_firstwin; | |
9337 } | |
9338 | |
9339 modified = FALSE; | |
9340 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9341 if (bufIsChanged(wp->w_buffer)) | |
9342 modified = TRUE; | |
9343 if (modified || wincount > 1) | |
9344 { | |
9345 if (wincount > 1) | |
9346 { | |
9347 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9348 len = (int)STRLEN(NameBuff); |
699 | 9349 if (col + len >= Columns - 3) |
9350 break; | |
680 | 9351 screen_puts_len(NameBuff, len, 0, col, |
677 | 9352 #if defined(FEAT_SYN_HL) |
680 | 9353 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9354 #else |
680 | 9355 attr |
9356 #endif | |
9357 ); | |
9358 col += len; | |
9359 } | |
9360 if (modified) | |
9361 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9362 screen_putchar(' ', 0, col++, attr); | |
9363 } | |
9364 | |
9365 room = scol - col + tabwidth - 1; | |
9366 if (room > 0) | |
9367 { | |
685 | 9368 /* Get buffer name in NameBuff[] */ |
9369 get_trans_bufname(cwp->w_buffer); | |
819 | 9370 shorten_dir(NameBuff); |
680 | 9371 len = vim_strsize(NameBuff); |
9372 p = NameBuff; | |
677 | 9373 #ifdef FEAT_MBYTE |
680 | 9374 if (has_mbyte) |
9375 while (len > room) | |
9376 { | |
9377 len -= ptr2cells(p); | |
9378 mb_ptr_adv(p); | |
9379 } | |
9380 else | |
9381 #endif | |
9382 if (len > room) | |
677 | 9383 { |
680 | 9384 p += len - room; |
9385 len = room; | |
677 | 9386 } |
699 | 9387 if (len > Columns - col - 1) |
9388 len = Columns - col - 1; | |
680 | 9389 |
835 | 9390 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9391 col += len; |
9392 } | |
9393 screen_putchar(' ', 0, col++, attr); | |
9394 | |
9395 /* Store the tab page number in TabPageIdxs[], so that | |
9396 * jump_to_mouse() knows where each one is. */ | |
9397 ++tabcount; | |
9398 while (scol < col) | |
9399 TabPageIdxs[scol++] = tabcount; | |
9400 } | |
9401 | |
9402 if (use_sep_chars) | |
9403 c = '_'; | |
9404 else | |
9405 c = ' '; | |
9406 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9407 |
9408 /* Put an "X" for closing the current tab if there are several. */ | |
9409 if (first_tabpage->tp_next != NULL) | |
9410 { | |
9411 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9412 TabPageIdxs[Columns - 1] = -999; | |
9413 } | |
9414 } | |
834 | 9415 |
9416 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9417 * set. */ | |
9418 redraw_tabline = FALSE; | |
667 | 9419 } |
685 | 9420 |
9421 /* | |
9422 * Get buffer name for "buf" into NameBuff[]. | |
9423 * Takes care of special buffer names and translates special characters. | |
9424 */ | |
9425 void | |
9426 get_trans_bufname(buf) | |
9427 buf_T *buf; | |
9428 { | |
9429 if (buf_spname(buf) != NULL) | |
9430 STRCPY(NameBuff, buf_spname(buf)); | |
9431 else | |
9432 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9433 trans_characters(NameBuff, MAXPATHL); | |
9434 } | |
667 | 9435 #endif |
9436 | |
7 | 9437 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9438 /* | |
9439 * Get the character to use in a status line. Get its attributes in "*attr". | |
9440 */ | |
9441 static int | |
9442 fillchar_status(attr, is_curwin) | |
9443 int *attr; | |
9444 int is_curwin; | |
9445 { | |
9446 int fill; | |
9447 if (is_curwin) | |
9448 { | |
9449 *attr = hl_attr(HLF_S); | |
9450 fill = fill_stl; | |
9451 } | |
9452 else | |
9453 { | |
9454 *attr = hl_attr(HLF_SNC); | |
9455 fill = fill_stlnc; | |
9456 } | |
9457 /* Use fill when there is highlighting, and highlighting of current | |
9458 * window differs, or the fillchars differ, or this is not the | |
9459 * current window */ | |
9460 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9461 || !is_curwin || firstwin == lastwin) | |
9462 || (fill_stl != fill_stlnc))) | |
9463 return fill; | |
9464 if (is_curwin) | |
9465 return '^'; | |
9466 return '='; | |
9467 } | |
9468 #endif | |
9469 | |
9470 #ifdef FEAT_VERTSPLIT | |
9471 /* | |
9472 * Get the character to use in a separator between vertically split windows. | |
9473 * Get its attributes in "*attr". | |
9474 */ | |
9475 static int | |
9476 fillchar_vsep(attr) | |
9477 int *attr; | |
9478 { | |
9479 *attr = hl_attr(HLF_C); | |
9480 if (*attr == 0 && fill_vert == ' ') | |
9481 return '|'; | |
9482 else | |
9483 return fill_vert; | |
9484 } | |
9485 #endif | |
9486 | |
9487 /* | |
9488 * Return TRUE if redrawing should currently be done. | |
9489 */ | |
9490 int | |
9491 redrawing() | |
9492 { | |
9493 return (!RedrawingDisabled | |
9494 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9495 } | |
9496 | |
9497 /* | |
9498 * Return TRUE if printing messages should currently be done. | |
9499 */ | |
9500 int | |
9501 messaging() | |
9502 { | |
9503 return (!(p_lz && char_avail() && !KeyTyped)); | |
9504 } | |
9505 | |
9506 /* | |
9507 * Show current status info in ruler and various other places | |
9508 * If always is FALSE, only show ruler if position has changed. | |
9509 */ | |
9510 void | |
9511 showruler(always) | |
9512 int always; | |
9513 { | |
9514 if (!always && !redrawing()) | |
9515 return; | |
574 | 9516 #ifdef FEAT_INS_EXPAND |
9517 if (pum_visible()) | |
9518 { | |
639 | 9519 # ifdef FEAT_WINDOWS |
574 | 9520 /* Don't redraw right now, do it later. */ |
9521 curwin->w_redr_status = TRUE; | |
639 | 9522 # endif |
574 | 9523 return; |
9524 } | |
9525 #endif | |
7 | 9526 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9527 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9528 { |
1983 | 9529 redraw_custom_statusline(curwin); |
680 | 9530 } |
7 | 9531 else |
9532 #endif | |
9533 #ifdef FEAT_CMDL_INFO | |
9534 win_redr_ruler(curwin, always); | |
9535 #endif | |
9536 | |
9537 #ifdef FEAT_TITLE | |
9538 if (need_maketitle | |
9539 # ifdef FEAT_STL_OPT | |
9540 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9541 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9542 # endif | |
9543 ) | |
9544 maketitle(); | |
9545 #endif | |
1588 | 9546 #ifdef FEAT_WINDOWS |
9547 /* Redraw the tab pages line if needed. */ | |
9548 if (redraw_tabline) | |
9549 draw_tabline(); | |
9550 #endif | |
7 | 9551 } |
9552 | |
9553 #ifdef FEAT_CMDL_INFO | |
9554 static void | |
9555 win_redr_ruler(wp, always) | |
9556 win_T *wp; | |
9557 int always; | |
9558 { | |
1869 | 9559 #define RULER_BUF_LEN 70 |
9560 char_u buffer[RULER_BUF_LEN]; | |
7 | 9561 int row; |
9562 int fillchar; | |
9563 int attr; | |
9564 int empty_line = FALSE; | |
9565 colnr_T virtcol; | |
9566 int i; | |
1869 | 9567 size_t len; |
7 | 9568 int o; |
9569 #ifdef FEAT_VERTSPLIT | |
9570 int this_ru_col; | |
9571 int off = 0; | |
9572 int width = Columns; | |
9573 # define WITH_OFF(x) x | |
9574 # define WITH_WIDTH(x) x | |
9575 #else | |
9576 # define WITH_OFF(x) 0 | |
9577 # define WITH_WIDTH(x) Columns | |
9578 # define this_ru_col ru_col | |
9579 #endif | |
9580 | |
9581 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9582 if (!p_ru) | |
9583 return; | |
9584 | |
9585 /* | |
9586 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9587 * after deleting lines, before cursor.lnum is corrected. | |
9588 */ | |
9589 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9590 return; | |
9591 | |
9592 #ifdef FEAT_INS_EXPAND | |
9593 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9594 * the (long) mode message. */ | |
9595 # ifdef FEAT_WINDOWS | |
9596 if (wp == lastwin && lastwin->w_status_height == 0) | |
9597 # endif | |
9598 if (edit_submode != NULL) | |
9599 return; | |
540 | 9600 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
9601 if (pum_visible()) | |
9602 return; | |
7 | 9603 #endif |
9604 | |
9605 #ifdef FEAT_STL_OPT | |
9606 if (*p_ruf) | |
9607 { | |
680 | 9608 int save_called_emsg = called_emsg; |
9609 | |
9610 called_emsg = FALSE; | |
7 | 9611 win_redr_custom(wp, TRUE); |
680 | 9612 if (called_emsg) |
9613 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 9614 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9615 called_emsg |= save_called_emsg; |
7 | 9616 return; |
9617 } | |
9618 #endif | |
9619 | |
9620 /* | |
9621 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
9622 */ | |
9623 if (!(State & INSERT) | |
9624 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
9625 empty_line = TRUE; | |
9626 | |
9627 /* | |
9628 * Only draw the ruler when something changed. | |
9629 */ | |
9630 validate_virtcol_win(wp); | |
9631 if ( redraw_cmdline | |
9632 || always | |
9633 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
9634 || wp->w_cursor.col != wp->w_ru_cursor.col | |
9635 || wp->w_virtcol != wp->w_ru_virtcol | |
9636 #ifdef FEAT_VIRTUALEDIT | |
9637 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
9638 #endif | |
9639 || wp->w_topline != wp->w_ru_topline | |
9640 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
9641 #ifdef FEAT_DIFF | |
9642 || wp->w_topfill != wp->w_ru_topfill | |
9643 #endif | |
9644 || empty_line != wp->w_ru_empty) | |
9645 { | |
9646 cursor_off(); | |
9647 #ifdef FEAT_WINDOWS | |
9648 if (wp->w_status_height) | |
9649 { | |
9650 row = W_WINROW(wp) + wp->w_height; | |
9651 fillchar = fillchar_status(&attr, wp == curwin); | |
9652 # ifdef FEAT_VERTSPLIT | |
9653 off = W_WINCOL(wp); | |
9654 width = W_WIDTH(wp); | |
9655 # endif | |
9656 } | |
9657 else | |
9658 #endif | |
9659 { | |
9660 row = Rows - 1; | |
9661 fillchar = ' '; | |
9662 attr = 0; | |
9663 #ifdef FEAT_VERTSPLIT | |
9664 width = Columns; | |
9665 off = 0; | |
9666 #endif | |
9667 } | |
9668 | |
9669 /* In list mode virtcol needs to be recomputed */ | |
9670 virtcol = wp->w_virtcol; | |
9671 if (wp->w_p_list && lcs_tab1 == NUL) | |
9672 { | |
9673 wp->w_p_list = FALSE; | |
9674 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
9675 wp->w_p_list = TRUE; | |
9676 } | |
9677 | |
9678 /* | |
9679 * Some sprintfs return the length, some return a pointer. | |
9680 * To avoid portability problems we use strlen() here. | |
9681 */ | |
1869 | 9682 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 9683 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
9684 ? 0L | |
9685 : (long)(wp->w_cursor.lnum)); | |
1869 | 9686 len = STRLEN(buffer); |
9687 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 9688 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
9689 (int)virtcol + 1); | |
9690 | |
9691 /* | |
9692 * Add a "50%" if there is room for it. | |
9693 * On the last line, don't print in the last column (scrolls the | |
9694 * screen up on some terminals). | |
9695 */ | |
9696 i = (int)STRLEN(buffer); | |
1869 | 9697 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 9698 o = i + vim_strsize(buffer + i + 1); |
9699 #ifdef FEAT_WINDOWS | |
9700 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
9701 #endif | |
9702 ++o; | |
9703 #ifdef FEAT_VERTSPLIT | |
9704 this_ru_col = ru_col - (Columns - width); | |
9705 if (this_ru_col < 0) | |
9706 this_ru_col = 0; | |
9707 #endif | |
9708 /* Never use more than half the window/screen width, leave the other | |
9709 * half for the filename. */ | |
9710 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
9711 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
9712 if (this_ru_col + o < WITH_WIDTH(width)) | |
9713 { | |
9714 while (this_ru_col + o < WITH_WIDTH(width)) | |
9715 { | |
9716 #ifdef FEAT_MBYTE | |
9717 if (has_mbyte) | |
9718 i += (*mb_char2bytes)(fillchar, buffer + i); | |
9719 else | |
9720 #endif | |
9721 buffer[i++] = fillchar; | |
9722 ++o; | |
9723 } | |
1869 | 9724 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 9725 } |
9726 /* Truncate at window boundary. */ | |
9727 #ifdef FEAT_MBYTE | |
9728 if (has_mbyte) | |
9729 { | |
9730 o = 0; | |
474 | 9731 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 9732 { |
9733 o += (*mb_ptr2cells)(buffer + i); | |
9734 if (this_ru_col + o > WITH_WIDTH(width)) | |
9735 { | |
9736 buffer[i] = NUL; | |
9737 break; | |
9738 } | |
9739 } | |
9740 } | |
9741 else | |
9742 #endif | |
9743 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
9744 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
9745 | |
9746 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
9747 i = redraw_cmdline; | |
9748 screen_fill(row, row + 1, | |
9749 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
9750 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
9751 fillchar, fillchar, attr); | |
9752 /* don't redraw the cmdline because of showing the ruler */ | |
9753 redraw_cmdline = i; | |
9754 wp->w_ru_cursor = wp->w_cursor; | |
9755 wp->w_ru_virtcol = wp->w_virtcol; | |
9756 wp->w_ru_empty = empty_line; | |
9757 wp->w_ru_topline = wp->w_topline; | |
9758 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
9759 #ifdef FEAT_DIFF | |
9760 wp->w_ru_topfill = wp->w_topfill; | |
9761 #endif | |
9762 } | |
9763 } | |
9764 #endif | |
13 | 9765 |
9766 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
9767 /* | |
9768 * Return the width of the 'number' column. | |
677 | 9769 * Caller may need to check if 'number' is set. |
13 | 9770 * Otherwise it depends on 'numberwidth' and the line count. |
9771 */ | |
9772 int | |
9773 number_width(wp) | |
9774 win_T *wp; | |
9775 { | |
9776 int n; | |
9777 linenr_T lnum; | |
9778 | |
9779 lnum = wp->w_buffer->b_ml.ml_line_count; | |
9780 if (lnum == wp->w_nrwidth_line_count) | |
9781 return wp->w_nrwidth_width; | |
9782 wp->w_nrwidth_line_count = lnum; | |
9783 | |
9784 n = 0; | |
9785 do | |
9786 { | |
856 | 9787 lnum /= 10; |
9788 ++n; | |
13 | 9789 } while (lnum > 0); |
9790 | |
9791 /* 'numberwidth' gives the minimal width plus one */ | |
9792 if (n < wp->w_p_nuw - 1) | |
9793 n = wp->w_p_nuw - 1; | |
9794 | |
9795 wp->w_nrwidth_width = n; | |
9796 return n; | |
9797 } | |
9798 #endif |