Mercurial > vim
annotate src/screen.c @ 2314:233eb4412f5d vim73
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 14 Jul 2010 19:53:30 +0200 |
parents | 69064995302a |
children | b13079093ae1 |
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 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
28 * character without composing chars ScreenLinesUC[] will be 0 and |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
29 * ScreenLinesC[][] is not used. When the character occupies two display |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
30 * cells the next byte in ScreenLines[] is 0. |
714 | 31 * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
32 * (drawn on top of the first character). There is 0 after the last one used. |
7 | 33 * ScreenLines2[] is only used for euc-jp to store the second byte if the |
34 * first byte is 0x8e (single-width character). | |
35 * | |
36 * The screen_*() functions write to the screen and handle updating | |
37 * ScreenLines[]. | |
38 * | |
39 * update_screen() is the function that updates all windows and status lines. | |
40 * It is called form the main loop when must_redraw is non-zero. It may be | |
1213 | 41 * called from other places when an immediate screen update is needed. |
7 | 42 * |
43 * The part of the buffer that is displayed in a window is set with: | |
44 * - w_topline (first buffer line in window) | |
45 * - w_topfill (filler line above the first line) | |
46 * - w_leftcol (leftmost window cell in window), | |
47 * - w_skipcol (skipped window cells of first line) | |
48 * | |
49 * Commands that only move the cursor around in a window, do not need to take | |
50 * action to update the display. The main loop will check if w_topline is | |
51 * valid and update it (scroll the window) when needed. | |
52 * | |
53 * Commands that scroll a window change w_topline and must call | |
54 * check_cursor() to move the cursor into the visible part of the window, and | |
55 * call redraw_later(VALID) to have the window displayed by update_screen() | |
56 * later. | |
57 * | |
58 * Commands that change text in the buffer must call changed_bytes() or | |
59 * changed_lines() to mark the area that changed and will require updating | |
60 * later. The main loop will call update_screen(), which will update each | |
61 * window that shows the changed buffer. This assumes text above the change | |
62 * can remain displayed as it is. Text after the change may need updating for | |
63 * scrolling, folding and syntax highlighting. | |
64 * | |
65 * Commands that change how a window is displayed (e.g., setting 'list') or | |
66 * invalidate the contents of a window in another way (e.g., change fold | |
67 * settings), must call redraw_later(NOT_VALID) to have the whole window | |
68 * redisplayed by update_screen() later. | |
69 * | |
70 * Commands that change how a buffer is displayed (e.g., setting 'tabstop') | |
71 * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the | |
72 * buffer redisplayed by update_screen() later. | |
73 * | |
743 | 74 * Commands that change highlighting and possibly cause a scroll too must call |
75 * redraw_later(SOME_VALID) to update the whole window but still use scrolling | |
76 * to avoid redrawing everything. But the length of displayed lines must not | |
77 * change, use NOT_VALID then. | |
78 * | |
7 | 79 * Commands that move the window position must call redraw_later(NOT_VALID). |
80 * TODO: should minimize redrawing by scrolling when possible. | |
81 * | |
82 * Commands that change everything (e.g., resizing the screen) must call | |
83 * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). | |
84 * | |
85 * Things that are handled indirectly: | |
86 * - When messages scroll the screen up, msg_scrolled will be set and | |
87 * update_screen() called to redraw. | |
88 */ | |
89 | |
90 #include "vim.h" | |
91 | |
92 /* | |
93 * The attributes that are actually active for writing to the screen. | |
94 */ | |
95 static int screen_attr = 0; | |
96 | |
97 /* | |
98 * Positioning the cursor is reduced by remembering the last position. | |
99 * Mostly used by windgoto() and screen_char(). | |
100 */ | |
101 static int screen_cur_row, screen_cur_col; /* last known cursor position */ | |
102 | |
103 #ifdef FEAT_SEARCH_EXTRA | |
104 static match_T search_hl; /* used for 'hlsearch' highlight matching */ | |
105 #endif | |
106 | |
107 #ifdef FEAT_FOLDING | |
108 static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ | |
109 #endif | |
110 | |
111 /* | |
112 * Buffer for one screen line (characters and attributes). | |
113 */ | |
114 static schar_T *current_ScreenLine; | |
115 | |
116 static void win_update __ARGS((win_T *wp)); | |
534 | 117 static void win_draw_end __ARGS((win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl)); |
7 | 118 #ifdef FEAT_FOLDING |
119 static void fold_line __ARGS((win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row)); | |
120 static void fill_foldcolumn __ARGS((char_u *p, win_T *wp, int closed, linenr_T lnum)); | |
121 static void copy_text_attr __ARGS((int off, char_u *buf, int len, int attr)); | |
122 #endif | |
625 | 123 static int win_line __ARGS((win_T *, linenr_T, int, int, int nochange)); |
7 | 124 static int char_needs_redraw __ARGS((int off_from, int off_to, int cols)); |
125 #ifdef FEAT_RIGHTLEFT | |
126 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width, int rlflag)); | |
127 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) | |
128 #else | |
129 static void screen_line __ARGS((int row, int coloff, int endcol, int clear_width)); | |
130 # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) | |
131 #endif | |
132 #ifdef FEAT_VERTSPLIT | |
133 static void draw_vsep_win __ARGS((win_T *wp, int row)); | |
134 #endif | |
680 | 135 #ifdef FEAT_STL_OPT |
1983 | 136 static void redraw_custom_statusline __ARGS((win_T *wp)); |
680 | 137 #endif |
7 | 138 #ifdef FEAT_SEARCH_EXTRA |
1326 | 139 #define SEARCH_HL_PRIORITY 0 |
7 | 140 static void start_search_hl __ARGS((void)); |
141 static void end_search_hl __ARGS((void)); | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
142 static void init_search_hl __ARGS((win_T *wp)); |
7 | 143 static void prepare_search_hl __ARGS((win_T *wp, linenr_T lnum)); |
144 static void next_search_hl __ARGS((win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol)); | |
145 #endif | |
146 static void screen_start_highlight __ARGS((int attr)); | |
147 static void screen_char __ARGS((unsigned off, int row, int col)); | |
148 #ifdef FEAT_MBYTE | |
149 static void screen_char_2 __ARGS((unsigned off, int row, int col)); | |
150 #endif | |
151 static void screenclear2 __ARGS((void)); | |
152 static void lineclear __ARGS((unsigned off, int width)); | |
153 static void lineinvalid __ARGS((unsigned off, int width)); | |
154 #ifdef FEAT_VERTSPLIT | |
155 static void linecopy __ARGS((int to, int from, win_T *wp)); | |
156 static void redraw_block __ARGS((int row, int end, win_T *wp)); | |
157 #endif | |
158 static int win_do_lines __ARGS((win_T *wp, int row, int line_count, int mayclear, int del)); | |
159 static void win_rest_invalid __ARGS((win_T *wp)); | |
160 static void msg_pos_mode __ARGS((void)); | |
667 | 161 #if defined(FEAT_WINDOWS) |
677 | 162 static void draw_tabline __ARGS((void)); |
667 | 163 #endif |
7 | 164 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
165 static int fillchar_status __ARGS((int *attr, int is_curwin)); | |
166 #endif | |
167 #ifdef FEAT_VERTSPLIT | |
168 static int fillchar_vsep __ARGS((int *attr)); | |
169 #endif | |
170 #ifdef FEAT_STL_OPT | |
574 | 171 static void win_redr_custom __ARGS((win_T *wp, int draw_ruler)); |
7 | 172 #endif |
173 #ifdef FEAT_CMDL_INFO | |
174 static void win_redr_ruler __ARGS((win_T *wp, int always)); | |
175 #endif | |
176 | |
177 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
178 /* Ugly global: overrule attribute used by screen_char() */ | |
179 static int screen_char_attr = 0; | |
180 #endif | |
181 | |
182 /* | |
183 * Redraw the current window later, with update_screen(type). | |
184 * Set must_redraw only if not already set to a higher value. | |
185 * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. | |
186 */ | |
187 void | |
188 redraw_later(type) | |
189 int type; | |
190 { | |
191 redraw_win_later(curwin, type); | |
192 } | |
193 | |
194 void | |
195 redraw_win_later(wp, type) | |
196 win_T *wp; | |
197 int type; | |
198 { | |
199 if (wp->w_redr_type < type) | |
200 { | |
201 wp->w_redr_type = type; | |
202 if (type >= NOT_VALID) | |
203 wp->w_lines_valid = 0; | |
204 if (must_redraw < type) /* must_redraw is the maximum of all windows */ | |
205 must_redraw = type; | |
206 } | |
207 } | |
208 | |
209 /* | |
210 * Force a complete redraw later. Also resets the highlighting. To be used | |
211 * after executing a shell command that messes up the screen. | |
212 */ | |
213 void | |
214 redraw_later_clear() | |
215 { | |
216 redraw_all_later(CLEAR); | |
826 | 217 #ifdef FEAT_GUI |
218 if (gui.in_use) | |
219 /* Use a code that will reset gui.highlight_mask in | |
220 * gui_stop_highlight(). */ | |
221 screen_attr = HL_ALL + 1; | |
222 else | |
223 #endif | |
224 /* Use attributes that is very unlikely to appear in text. */ | |
225 screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; | |
7 | 226 } |
227 | |
228 /* | |
229 * Mark all windows to be redrawn later. | |
230 */ | |
231 void | |
232 redraw_all_later(type) | |
233 int type; | |
234 { | |
235 win_T *wp; | |
236 | |
237 FOR_ALL_WINDOWS(wp) | |
238 { | |
239 redraw_win_later(wp, type); | |
240 } | |
241 } | |
242 | |
243 /* | |
301 | 244 * Mark all windows that are editing the current buffer to be updated later. |
7 | 245 */ |
246 void | |
247 redraw_curbuf_later(type) | |
248 int type; | |
249 { | |
250 redraw_buf_later(curbuf, type); | |
251 } | |
252 | |
253 void | |
254 redraw_buf_later(buf, type) | |
255 buf_T *buf; | |
256 int type; | |
257 { | |
258 win_T *wp; | |
259 | |
260 FOR_ALL_WINDOWS(wp) | |
261 { | |
262 if (wp->w_buffer == buf) | |
263 redraw_win_later(wp, type); | |
264 } | |
265 } | |
266 | |
267 /* | |
268 * Changed something in the current window, at buffer line "lnum", that | |
269 * requires that line and possibly other lines to be redrawn. | |
270 * Used when entering/leaving Insert mode with the cursor on a folded line. | |
271 * Used to remove the "$" from a change command. | |
272 * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot | |
273 * may become invalid and the whole window will have to be redrawn. | |
274 */ | |
275 void | |
276 redrawWinline(lnum, invalid) | |
277 linenr_T lnum; | |
1883 | 278 int invalid UNUSED; /* window line height is invalid now */ |
7 | 279 { |
280 #ifdef FEAT_FOLDING | |
281 int i; | |
282 #endif | |
283 | |
284 if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) | |
285 curwin->w_redraw_top = lnum; | |
286 if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) | |
287 curwin->w_redraw_bot = lnum; | |
288 redraw_later(VALID); | |
289 | |
290 #ifdef FEAT_FOLDING | |
291 if (invalid) | |
292 { | |
293 /* A w_lines[] entry for this lnum has become invalid. */ | |
294 i = find_wl_entry(curwin, lnum); | |
295 if (i >= 0) | |
296 curwin->w_lines[i].wl_valid = FALSE; | |
297 } | |
298 #endif | |
299 } | |
300 | |
2255 | 301 #if defined(FEAT_RUBY) || defined(FEAT_PERL) || defined(FEAT_VISUAL) || \ |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
302 (defined(FEAT_CLIPBOARD) && defined(FEAT_X11)) || defined(PROTO) |
7 | 303 /* |
304 * update all windows that are editing the current buffer | |
305 */ | |
306 void | |
307 update_curbuf(type) | |
308 int type; | |
309 { | |
310 redraw_curbuf_later(type); | |
311 update_screen(type); | |
312 } | |
2237
770485470e59
Add a few #ifdefs to exclude functions that are not used. (Domnique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
313 #endif |
7 | 314 |
315 /* | |
316 * update_screen() | |
317 * | |
318 * Based on the current value of curwin->w_topline, transfer a screenfull | |
319 * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. | |
320 */ | |
321 void | |
322 update_screen(type) | |
323 int type; | |
324 { | |
325 win_T *wp; | |
326 static int did_intro = FALSE; | |
327 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
328 int did_one; | |
329 #endif | |
330 | |
2008 | 331 /* Don't do anything if the screen structures are (not yet) valid. */ |
7 | 332 if (!screen_valid(TRUE)) |
333 return; | |
334 | |
335 if (must_redraw) | |
336 { | |
337 if (type < must_redraw) /* use maximal type */ | |
338 type = must_redraw; | |
1331 | 339 |
340 /* must_redraw is reset here, so that when we run into some weird | |
341 * reason to redraw while busy redrawing (e.g., asynchronous | |
342 * scrolling), or update_topline() in win_update() will cause a | |
343 * scroll, the screen will be redrawn later or in win_update(). */ | |
7 | 344 must_redraw = 0; |
345 } | |
346 | |
347 /* Need to update w_lines[]. */ | |
348 if (curwin->w_lines_valid == 0 && type < NOT_VALID) | |
349 type = NOT_VALID; | |
350 | |
2008 | 351 /* Postpone the redrawing when it's not needed and when being called |
352 * recursively. */ | |
353 if (!redrawing() || updating_screen) | |
7 | 354 { |
355 redraw_later(type); /* remember type for next time */ | |
356 must_redraw = type; | |
357 if (type > INVERTED_ALL) | |
358 curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ | |
359 return; | |
360 } | |
361 | |
362 updating_screen = TRUE; | |
363 #ifdef FEAT_SYN_HL | |
364 ++display_tick; /* let syntax code know we're in a next round of | |
365 * display updating */ | |
366 #endif | |
367 | |
368 /* | |
369 * if the screen was scrolled up when displaying a message, scroll it down | |
370 */ | |
371 if (msg_scrolled) | |
372 { | |
373 clear_cmdline = TRUE; | |
374 if (msg_scrolled > Rows - 5) /* clearing is faster */ | |
375 type = CLEAR; | |
376 else if (type != CLEAR) | |
377 { | |
378 check_for_delay(FALSE); | |
379 if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) | |
380 type = CLEAR; | |
381 FOR_ALL_WINDOWS(wp) | |
382 { | |
383 if (W_WINROW(wp) < msg_scrolled) | |
384 { | |
385 if (W_WINROW(wp) + wp->w_height > msg_scrolled | |
386 && wp->w_redr_type < REDRAW_TOP | |
387 && wp->w_lines_valid > 0 | |
388 && wp->w_topline == wp->w_lines[0].wl_lnum) | |
389 { | |
390 wp->w_upd_rows = msg_scrolled - W_WINROW(wp); | |
391 wp->w_redr_type = REDRAW_TOP; | |
392 } | |
393 else | |
394 { | |
395 wp->w_redr_type = NOT_VALID; | |
396 #ifdef FEAT_WINDOWS | |
397 if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) | |
398 <= msg_scrolled) | |
399 wp->w_redr_status = TRUE; | |
400 #endif | |
401 } | |
402 } | |
403 } | |
404 redraw_cmdline = TRUE; | |
667 | 405 #ifdef FEAT_WINDOWS |
673 | 406 redraw_tabline = TRUE; |
667 | 407 #endif |
7 | 408 } |
409 msg_scrolled = 0; | |
410 need_wait_return = FALSE; | |
411 } | |
412 | |
413 /* reset cmdline_row now (may have been changed temporarily) */ | |
414 compute_cmdrow(); | |
415 | |
416 /* Check for changed highlighting */ | |
417 if (need_highlight_changed) | |
418 highlight_changed(); | |
419 | |
420 if (type == CLEAR) /* first clear screen */ | |
421 { | |
422 screenclear(); /* will reset clear_cmdline */ | |
423 type = NOT_VALID; | |
424 } | |
425 | |
426 if (clear_cmdline) /* going to clear cmdline (done below) */ | |
427 check_for_delay(FALSE); | |
428 | |
13 | 429 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
430 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
431 * changes. */ |
13 | 432 if (curwin->w_redr_type < NOT_VALID |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
433 && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
434 ? number_width(curwin) : 0)) |
13 | 435 curwin->w_redr_type = NOT_VALID; |
436 #endif | |
437 | |
7 | 438 /* |
439 * Only start redrawing if there is really something to do. | |
440 */ | |
441 if (type == INVERTED) | |
442 update_curswant(); | |
443 if (curwin->w_redr_type < type | |
444 && !((type == VALID | |
445 && curwin->w_lines[0].wl_valid | |
446 #ifdef FEAT_DIFF | |
447 && curwin->w_topfill == curwin->w_old_topfill | |
448 && curwin->w_botfill == curwin->w_old_botfill | |
449 #endif | |
450 && curwin->w_topline == curwin->w_lines[0].wl_lnum) | |
451 #ifdef FEAT_VISUAL | |
452 || (type == INVERTED | |
1043 | 453 && VIsual_active |
7 | 454 && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
455 && curwin->w_old_visual_mode == VIsual_mode | |
456 && (curwin->w_valid & VALID_VIRTCOL) | |
457 && curwin->w_old_curswant == curwin->w_curswant) | |
458 #endif | |
459 )) | |
460 curwin->w_redr_type = type; | |
461 | |
849 | 462 #ifdef FEAT_WINDOWS |
463 /* Redraw the tab pages line if needed. */ | |
464 if (redraw_tabline || type >= NOT_VALID) | |
465 draw_tabline(); | |
466 #endif | |
467 | |
7 | 468 #ifdef FEAT_SYN_HL |
469 /* | |
470 * Correct stored syntax highlighting info for changes in each displayed | |
471 * buffer. Each buffer must only be done once. | |
472 */ | |
473 FOR_ALL_WINDOWS(wp) | |
474 { | |
475 if (wp->w_buffer->b_mod_set) | |
476 { | |
477 # ifdef FEAT_WINDOWS | |
478 win_T *wwp; | |
479 | |
480 /* Check if we already did this buffer. */ | |
481 for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) | |
482 if (wwp->w_buffer == wp->w_buffer) | |
483 break; | |
484 # endif | |
485 if ( | |
486 # ifdef FEAT_WINDOWS | |
487 wwp == wp && | |
488 # endif | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
489 syntax_present(wp)) |
7 | 490 syn_stack_apply_changes(wp->w_buffer); |
491 } | |
492 } | |
493 #endif | |
494 | |
495 /* | |
496 * Go from top to bottom through the windows, redrawing the ones that need | |
497 * it. | |
498 */ | |
499 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
500 did_one = FALSE; | |
501 #endif | |
502 #ifdef FEAT_SEARCH_EXTRA | |
503 search_hl.rm.regprog = NULL; | |
504 #endif | |
505 FOR_ALL_WINDOWS(wp) | |
506 { | |
507 if (wp->w_redr_type != 0) | |
508 { | |
509 cursor_off(); | |
510 #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) | |
511 if (!did_one) | |
512 { | |
513 did_one = TRUE; | |
514 # ifdef FEAT_SEARCH_EXTRA | |
515 start_search_hl(); | |
516 # endif | |
517 # ifdef FEAT_CLIPBOARD | |
518 /* When Visual area changed, may have to update selection. */ | |
519 if (clip_star.available && clip_isautosel()) | |
520 clip_update_selection(); | |
521 # endif | |
522 #ifdef FEAT_GUI | |
523 /* Remove the cursor before starting to do anything, because | |
524 * scrolling may make it difficult to redraw the text under | |
525 * it. */ | |
526 if (gui.in_use) | |
527 gui_undraw_cursor(); | |
528 #endif | |
529 } | |
530 #endif | |
531 win_update(wp); | |
532 } | |
533 | |
534 #ifdef FEAT_WINDOWS | |
535 /* redraw status line after the window to minimize cursor movement */ | |
536 if (wp->w_redr_status) | |
537 { | |
538 cursor_off(); | |
539 win_redr_status(wp); | |
540 } | |
541 #endif | |
542 } | |
543 #if defined(FEAT_SEARCH_EXTRA) | |
544 end_search_hl(); | |
545 #endif | |
546 | |
547 #ifdef FEAT_WINDOWS | |
548 /* Reset b_mod_set flags. Going through all windows is probably faster | |
549 * than going through all buffers (there could be many buffers). */ | |
550 for (wp = firstwin; wp != NULL; wp = wp->w_next) | |
551 wp->w_buffer->b_mod_set = FALSE; | |
552 #else | |
553 curbuf->b_mod_set = FALSE; | |
554 #endif | |
555 | |
556 updating_screen = FALSE; | |
557 #ifdef FEAT_GUI | |
558 gui_may_resize_shell(); | |
559 #endif | |
560 | |
561 /* Clear or redraw the command line. Done last, because scrolling may | |
562 * mess up the command line. */ | |
563 if (clear_cmdline || redraw_cmdline) | |
564 showmode(); | |
565 | |
566 /* May put up an introductory message when not editing a file */ | |
567 if (!did_intro && bufempty() | |
568 && curbuf->b_fname == NULL | |
569 #ifdef FEAT_WINDOWS | |
570 && firstwin->w_next == NULL | |
571 #endif | |
572 && vim_strchr(p_shm, SHM_INTRO) == NULL) | |
573 intro_message(FALSE); | |
574 did_intro = TRUE; | |
575 | |
576 #ifdef FEAT_GUI | |
577 /* Redraw the cursor and update the scrollbars when all screen updating is | |
578 * done. */ | |
579 if (gui.in_use) | |
580 { | |
581 out_flush(); /* required before updating the cursor */ | |
582 if (did_one) | |
583 gui_update_cursor(FALSE, FALSE); | |
584 gui_update_scrollbars(FALSE); | |
585 } | |
586 #endif | |
587 } | |
588 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
589 #if defined(FEAT_CONCEAL) || defined(PROTO) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
590 void |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
591 update_single_line(wp, lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
592 win_T *wp; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
593 linenr_T lnum; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
594 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
595 int row; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
596 int j; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
597 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
598 if (lnum >= wp->w_topline && lnum < wp->w_botline |
2269
fb627e94e6c6
Couple of small fixes for conceal feature. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2255
diff
changeset
|
599 && foldedCount(wp, lnum, &win_foldinfo) == 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
600 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
601 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
602 /* Remove the cursor before starting to do anything, because scrolling |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
603 * may make it difficult to redraw the text under it. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
604 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
605 gui_undraw_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
606 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
607 row = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
608 for (j = 0; j < wp->w_lines_valid; ++j) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
609 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
610 if (lnum == wp->w_lines[j].wl_lnum) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
611 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
612 screen_start(); /* not sure of screen cursor */ |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
613 # ifdef FEAT_SEARCH_EXTRA |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
614 init_search_hl(wp); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
615 start_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
616 prepare_search_hl(wp, lnum); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
617 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
618 win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
619 # if defined(FEAT_SEARCH_EXTRA) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
620 end_search_hl(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
621 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
622 break; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
623 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
624 row += wp->w_lines[j].wl_size; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
625 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
626 # ifdef FEAT_GUI |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
627 /* Redraw the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
628 if (gui.in_use) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
629 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
630 out_flush(); /* required before updating the cursor */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
631 gui_update_cursor(FALSE, FALSE); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
632 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
633 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
634 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
635 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
636 #endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
637 |
7 | 638 #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
639 static void update_prepare __ARGS((void)); | |
640 static void update_finish __ARGS((void)); | |
641 | |
642 /* | |
643 * Prepare for updating one or more windows. | |
2008 | 644 * Caller must check for "updating_screen" already set to avoid recursiveness. |
7 | 645 */ |
646 static void | |
647 update_prepare() | |
648 { | |
649 cursor_off(); | |
650 updating_screen = TRUE; | |
651 #ifdef FEAT_GUI | |
652 /* Remove the cursor before starting to do anything, because scrolling may | |
653 * make it difficult to redraw the text under it. */ | |
654 if (gui.in_use) | |
655 gui_undraw_cursor(); | |
656 #endif | |
657 #ifdef FEAT_SEARCH_EXTRA | |
658 start_search_hl(); | |
659 #endif | |
660 } | |
661 | |
662 /* | |
663 * Finish updating one or more windows. | |
664 */ | |
665 static void | |
666 update_finish() | |
667 { | |
668 if (redraw_cmdline) | |
669 showmode(); | |
670 | |
671 # ifdef FEAT_SEARCH_EXTRA | |
672 end_search_hl(); | |
673 # endif | |
674 | |
675 updating_screen = FALSE; | |
676 | |
677 # ifdef FEAT_GUI | |
678 gui_may_resize_shell(); | |
679 | |
680 /* Redraw the cursor and update the scrollbars when all screen updating is | |
681 * done. */ | |
682 if (gui.in_use) | |
683 { | |
684 out_flush(); /* required before updating the cursor */ | |
685 gui_update_cursor(FALSE, FALSE); | |
686 gui_update_scrollbars(FALSE); | |
687 } | |
688 # endif | |
689 } | |
690 #endif | |
691 | |
692 #if defined(FEAT_SIGNS) || defined(PROTO) | |
693 void | |
694 update_debug_sign(buf, lnum) | |
695 buf_T *buf; | |
696 linenr_T lnum; | |
697 { | |
698 win_T *wp; | |
699 int doit = FALSE; | |
700 | |
701 # ifdef FEAT_FOLDING | |
702 win_foldinfo.fi_level = 0; | |
703 # endif | |
704 | |
705 /* update/delete a specific mark */ | |
706 FOR_ALL_WINDOWS(wp) | |
707 { | |
708 if (buf != NULL && lnum > 0) | |
709 { | |
710 if (wp->w_buffer == buf && lnum >= wp->w_topline | |
711 && lnum < wp->w_botline) | |
712 { | |
713 if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) | |
714 wp->w_redraw_top = lnum; | |
715 if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) | |
716 wp->w_redraw_bot = lnum; | |
717 redraw_win_later(wp, VALID); | |
718 } | |
719 } | |
720 else | |
721 redraw_win_later(wp, VALID); | |
722 if (wp->w_redr_type != 0) | |
723 doit = TRUE; | |
724 } | |
725 | |
2008 | 726 /* Return when there is nothing to do or screen updating already |
727 * happening. */ | |
728 if (!doit || updating_screen) | |
7 | 729 return; |
730 | |
731 /* update all windows that need updating */ | |
732 update_prepare(); | |
733 | |
734 # ifdef FEAT_WINDOWS | |
735 for (wp = firstwin; wp; wp = wp->w_next) | |
736 { | |
737 if (wp->w_redr_type != 0) | |
738 win_update(wp); | |
739 if (wp->w_redr_status) | |
740 win_redr_status(wp); | |
741 } | |
742 # else | |
743 if (curwin->w_redr_type != 0) | |
744 win_update(curwin); | |
745 # endif | |
746 | |
747 update_finish(); | |
748 } | |
749 #endif | |
750 | |
751 | |
752 #if defined(FEAT_GUI) || defined(PROTO) | |
753 /* | |
754 * Update a single window, its status line and maybe the command line msg. | |
755 * Used for the GUI scrollbar. | |
756 */ | |
757 void | |
758 updateWindow(wp) | |
759 win_T *wp; | |
760 { | |
2008 | 761 /* return if already busy updating */ |
762 if (updating_screen) | |
763 return; | |
764 | |
7 | 765 update_prepare(); |
766 | |
767 #ifdef FEAT_CLIPBOARD | |
768 /* When Visual area changed, may have to update selection. */ | |
769 if (clip_star.available && clip_isautosel()) | |
770 clip_update_selection(); | |
771 #endif | |
670 | 772 |
7 | 773 win_update(wp); |
670 | 774 |
7 | 775 #ifdef FEAT_WINDOWS |
670 | 776 /* When the screen was cleared redraw the tab pages line. */ |
673 | 777 if (redraw_tabline) |
677 | 778 draw_tabline(); |
670 | 779 |
7 | 780 if (wp->w_redr_status |
781 # ifdef FEAT_CMDL_INFO | |
782 || p_ru | |
783 # endif | |
784 # ifdef FEAT_STL_OPT | |
40 | 785 || *p_stl != NUL || *wp->w_p_stl != NUL |
7 | 786 # endif |
787 ) | |
788 win_redr_status(wp); | |
789 #endif | |
790 | |
791 update_finish(); | |
792 } | |
793 #endif | |
794 | |
795 /* | |
796 * Update a single window. | |
797 * | |
798 * This may cause the windows below it also to be redrawn (when clearing the | |
799 * screen or scrolling lines). | |
800 * | |
801 * How the window is redrawn depends on wp->w_redr_type. Each type also | |
802 * implies the one below it. | |
803 * NOT_VALID redraw the whole window | |
743 | 804 * SOME_VALID redraw the whole window but do scroll when possible |
7 | 805 * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
806 * INVERTED redraw the changed part of the Visual area | |
807 * INVERTED_ALL redraw the whole Visual area | |
808 * VALID 1. scroll up/down to adjust for a changed w_topline | |
809 * 2. update lines at the top when scrolled down | |
810 * 3. redraw changed text: | |
301 | 811 * - if wp->w_buffer->b_mod_set set, update lines between |
7 | 812 * b_mod_top and b_mod_bot. |
813 * - if wp->w_redraw_top non-zero, redraw lines between | |
814 * wp->w_redraw_top and wp->w_redr_bot. | |
815 * - continue redrawing when syntax status is invalid. | |
816 * 4. if scrolled up, update lines at the bottom. | |
817 * This results in three areas that may need updating: | |
818 * top: from first row to top_end (when scrolled down) | |
819 * mid: from mid_start to mid_end (update inversion or changed text) | |
820 * bot: from bot_start to last row (when scrolled up) | |
821 */ | |
822 static void | |
823 win_update(wp) | |
824 win_T *wp; | |
825 { | |
826 buf_T *buf = wp->w_buffer; | |
827 int type; | |
828 int top_end = 0; /* Below last row of the top area that needs | |
829 updating. 0 when no top area updating. */ | |
830 int mid_start = 999;/* first row of the mid area that needs | |
831 updating. 999 when no mid area updating. */ | |
832 int mid_end = 0; /* Below last row of the mid area that needs | |
833 updating. 0 when no mid area updating. */ | |
834 int bot_start = 999;/* first row of the bot area that needs | |
835 updating. 999 when no bot area updating */ | |
836 #ifdef FEAT_VISUAL | |
837 int scrolled_down = FALSE; /* TRUE when scrolled down when | |
838 w_topline got smaller a bit */ | |
839 #endif | |
840 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 841 matchitem_T *cur; /* points to the match list */ |
7 | 842 int top_to_mod = FALSE; /* redraw above mod_top */ |
843 #endif | |
844 | |
845 int row; /* current window row to display */ | |
846 linenr_T lnum; /* current buffer lnum to display */ | |
847 int idx; /* current index in w_lines[] */ | |
848 int srow; /* starting row of the current line */ | |
849 | |
850 int eof = FALSE; /* if TRUE, we hit the end of the file */ | |
851 int didline = FALSE; /* if TRUE, we finished the last line */ | |
852 int i; | |
853 long j; | |
854 static int recursive = FALSE; /* being called recursively */ | |
855 int old_botline = wp->w_botline; | |
856 #ifdef FEAT_FOLDING | |
857 long fold_count; | |
858 #endif | |
859 #ifdef FEAT_SYN_HL | |
860 /* remember what happened to the previous line, to know if | |
861 * check_visual_highlight() can be used */ | |
862 #define DID_NONE 1 /* didn't update a line */ | |
863 #define DID_LINE 2 /* updated a normal line */ | |
864 #define DID_FOLD 3 /* updated a folded line */ | |
865 int did_update = DID_NONE; | |
866 linenr_T syntax_last_parsed = 0; /* last parsed text line */ | |
867 #endif | |
868 linenr_T mod_top = 0; | |
869 linenr_T mod_bot = 0; | |
870 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
871 int save_got_int; | |
872 #endif | |
873 | |
874 type = wp->w_redr_type; | |
875 | |
876 if (type == NOT_VALID) | |
877 { | |
878 #ifdef FEAT_WINDOWS | |
879 wp->w_redr_status = TRUE; | |
880 #endif | |
881 wp->w_lines_valid = 0; | |
882 } | |
883 | |
884 /* Window is zero-height: nothing to draw. */ | |
885 if (wp->w_height == 0) | |
886 { | |
887 wp->w_redr_type = 0; | |
888 return; | |
889 } | |
890 | |
891 #ifdef FEAT_VERTSPLIT | |
892 /* Window is zero-width: Only need to draw the separator. */ | |
893 if (wp->w_width == 0) | |
894 { | |
895 /* draw the vertical separator right of this window */ | |
896 draw_vsep_win(wp, 0); | |
897 wp->w_redr_type = 0; | |
898 return; | |
899 } | |
900 #endif | |
901 | |
902 #ifdef FEAT_SEARCH_EXTRA | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
903 init_search_hl(wp); |
7 | 904 #endif |
905 | |
13 | 906 #ifdef FEAT_LINEBREAK |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
907 /* Force redraw when width of 'number' or 'relativenumber' column |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
908 * changes. */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
909 i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
677 | 910 if (wp->w_nrwidth != i) |
13 | 911 { |
912 type = NOT_VALID; | |
677 | 913 wp->w_nrwidth = i; |
13 | 914 } |
915 else | |
916 #endif | |
917 | |
7 | 918 if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
919 { | |
920 /* | |
921 * When there are both inserted/deleted lines and specific lines to be | |
922 * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw | |
923 * everything (only happens when redrawing is off for while). | |
924 */ | |
925 type = NOT_VALID; | |
926 } | |
927 else | |
928 { | |
929 /* | |
930 * Set mod_top to the first line that needs displaying because of | |
931 * changes. Set mod_bot to the first line after the changes. | |
932 */ | |
933 mod_top = wp->w_redraw_top; | |
934 if (wp->w_redraw_bot != 0) | |
935 mod_bot = wp->w_redraw_bot + 1; | |
936 else | |
937 mod_bot = 0; | |
938 wp->w_redraw_top = 0; /* reset for next time */ | |
939 wp->w_redraw_bot = 0; | |
940 if (buf->b_mod_set) | |
941 { | |
942 if (mod_top == 0 || mod_top > buf->b_mod_top) | |
943 { | |
944 mod_top = buf->b_mod_top; | |
945 #ifdef FEAT_SYN_HL | |
946 /* Need to redraw lines above the change that may be included | |
947 * in a pattern match. */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
948 if (syntax_present(wp)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
949 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
950 mod_top -= buf->b_s.b_syn_sync_linebreaks; |
7 | 951 if (mod_top < 1) |
952 mod_top = 1; | |
953 } | |
954 #endif | |
955 } | |
956 if (mod_bot == 0 || mod_bot < buf->b_mod_bot) | |
957 mod_bot = buf->b_mod_bot; | |
958 | |
959 #ifdef FEAT_SEARCH_EXTRA | |
960 /* When 'hlsearch' is on and using a multi-line search pattern, a | |
961 * change in one line may make the Search highlighting in a | |
962 * previous line invalid. Simple solution: redraw all visible | |
963 * lines above the change. | |
1326 | 964 * Same for a match pattern. |
7 | 965 */ |
699 | 966 if (search_hl.rm.regprog != NULL |
967 && re_multiline(search_hl.rm.regprog)) | |
7 | 968 top_to_mod = TRUE; |
699 | 969 else |
1326 | 970 { |
971 cur = wp->w_match_head; | |
972 while (cur != NULL) | |
973 { | |
974 if (cur->match.regprog != NULL | |
975 && re_multiline(cur->match.regprog)) | |
699 | 976 { |
977 top_to_mod = TRUE; | |
978 break; | |
979 } | |
1326 | 980 cur = cur->next; |
981 } | |
982 } | |
7 | 983 #endif |
984 } | |
985 #ifdef FEAT_FOLDING | |
986 if (mod_top != 0 && hasAnyFolding(wp)) | |
987 { | |
988 linenr_T lnumt, lnumb; | |
989 | |
990 /* | |
991 * A change in a line can cause lines above it to become folded or | |
992 * unfolded. Find the top most buffer line that may be affected. | |
993 * If the line was previously folded and displayed, get the first | |
994 * line of that fold. If the line is folded now, get the first | |
995 * folded line. Use the minimum of these two. | |
996 */ | |
997 | |
998 /* Find last valid w_lines[] entry above mod_top. Set lnumt to | |
999 * the line below it. If there is no valid entry, use w_topline. | |
1000 * Find the first valid w_lines[] entry below mod_bot. Set lnumb | |
1001 * to this line. If there is no valid entry, use MAXLNUM. */ | |
1002 lnumt = wp->w_topline; | |
1003 lnumb = MAXLNUM; | |
1004 for (i = 0; i < wp->w_lines_valid; ++i) | |
1005 if (wp->w_lines[i].wl_valid) | |
1006 { | |
1007 if (wp->w_lines[i].wl_lastlnum < mod_top) | |
1008 lnumt = wp->w_lines[i].wl_lastlnum + 1; | |
1009 if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) | |
1010 { | |
1011 lnumb = wp->w_lines[i].wl_lnum; | |
1012 /* When there is a fold column it might need updating | |
1013 * in the next line ("J" just above an open fold). */ | |
1014 if (wp->w_p_fdc > 0) | |
1015 ++lnumb; | |
1016 } | |
1017 } | |
1018 | |
1019 (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); | |
1020 if (mod_top > lnumt) | |
1021 mod_top = lnumt; | |
1022 | |
1023 /* Now do the same for the bottom line (one above mod_bot). */ | |
1024 --mod_bot; | |
1025 (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); | |
1026 ++mod_bot; | |
1027 if (mod_bot < lnumb) | |
1028 mod_bot = lnumb; | |
1029 } | |
1030 #endif | |
1031 | |
1032 /* When a change starts above w_topline and the end is below | |
1033 * w_topline, start redrawing at w_topline. | |
36 | 1034 * If the end of the change is above w_topline: do like no change was |
1035 * made, but redraw the first line to find changes in syntax. */ | |
7 | 1036 if (mod_top != 0 && mod_top < wp->w_topline) |
1037 { | |
1038 if (mod_bot > wp->w_topline) | |
1039 mod_top = wp->w_topline; | |
1040 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1041 else if (syntax_present(wp)) |
7 | 1042 top_end = 1; |
1043 #endif | |
1044 } | |
36 | 1045 |
1046 /* When line numbers are displayed need to redraw all lines below | |
1047 * inserted/deleted lines. */ | |
1048 if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) | |
1049 mod_bot = MAXLNUM; | |
7 | 1050 } |
1051 | |
1052 /* | |
1053 * When only displaying the lines at the top, set top_end. Used when | |
1054 * window has scrolled down for msg_scrolled. | |
1055 */ | |
1056 if (type == REDRAW_TOP) | |
1057 { | |
1058 j = 0; | |
1059 for (i = 0; i < wp->w_lines_valid; ++i) | |
1060 { | |
1061 j += wp->w_lines[i].wl_size; | |
1062 if (j >= wp->w_upd_rows) | |
1063 { | |
1064 top_end = j; | |
1065 break; | |
1066 } | |
1067 } | |
1068 if (top_end == 0) | |
1069 /* not found (cannot happen?): redraw everything */ | |
1070 type = NOT_VALID; | |
1071 else | |
1072 /* top area defined, the rest is VALID */ | |
1073 type = VALID; | |
1074 } | |
1075 | |
1378 | 1076 /* Trick: we want to avoid clearing the screen twice. screenclear() will |
1331 | 1077 * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
1078 * non-zero and thus not FALSE) will indicate that screenclear() was not | |
1079 * called. */ | |
1080 if (screen_cleared) | |
1081 screen_cleared = MAYBE; | |
1082 | |
7 | 1083 /* |
1084 * If there are no changes on the screen that require a complete redraw, | |
1085 * handle three cases: | |
1086 * 1: we are off the top of the screen by a few lines: scroll down | |
1087 * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up | |
1088 * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in | |
1089 * w_lines[] that needs updating. | |
1090 */ | |
743 | 1091 if ((type == VALID || type == SOME_VALID |
1092 || type == INVERTED || type == INVERTED_ALL) | |
7 | 1093 #ifdef FEAT_DIFF |
1094 && !wp->w_botfill && !wp->w_old_botfill | |
1095 #endif | |
1096 ) | |
1097 { | |
1098 if (mod_top != 0 && wp->w_topline == mod_top) | |
1099 { | |
1100 /* | |
1101 * w_topline is the first changed line, the scrolling will be done | |
1102 * further down. | |
1103 */ | |
1104 } | |
1105 else if (wp->w_lines[0].wl_valid | |
1106 && (wp->w_topline < wp->w_lines[0].wl_lnum | |
1107 #ifdef FEAT_DIFF | |
1108 || (wp->w_topline == wp->w_lines[0].wl_lnum | |
1109 && wp->w_topfill > wp->w_old_topfill) | |
1110 #endif | |
1111 )) | |
1112 { | |
1113 /* | |
1114 * New topline is above old topline: May scroll down. | |
1115 */ | |
1116 #ifdef FEAT_FOLDING | |
1117 if (hasAnyFolding(wp)) | |
1118 { | |
1119 linenr_T ln; | |
1120 | |
1121 /* count the number of lines we are off, counting a sequence | |
1122 * of folded lines as one */ | |
1123 j = 0; | |
1124 for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) | |
1125 { | |
1126 ++j; | |
1127 if (j >= wp->w_height - 2) | |
1128 break; | |
1129 (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); | |
1130 } | |
1131 } | |
1132 else | |
1133 #endif | |
1134 j = wp->w_lines[0].wl_lnum - wp->w_topline; | |
1135 if (j < wp->w_height - 2) /* not too far off */ | |
1136 { | |
1137 i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); | |
1138 #ifdef FEAT_DIFF | |
1139 /* insert extra lines for previously invisible filler lines */ | |
1140 if (wp->w_lines[0].wl_lnum != wp->w_topline) | |
1141 i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) | |
1142 - wp->w_old_topfill; | |
1143 #endif | |
1144 if (i < wp->w_height - 2) /* less than a screen off */ | |
1145 { | |
1146 /* | |
1147 * Try to insert the correct number of lines. | |
1148 * If not the last window, delete the lines at the bottom. | |
1149 * win_ins_lines may fail when the terminal can't do it. | |
1150 */ | |
1151 if (i > 0) | |
1152 check_for_delay(FALSE); | |
1153 if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) | |
1154 { | |
1155 if (wp->w_lines_valid != 0) | |
1156 { | |
1157 /* Need to update rows that are new, stop at the | |
1158 * first one that scrolled down. */ | |
1159 top_end = i; | |
1160 #ifdef FEAT_VISUAL | |
1161 scrolled_down = TRUE; | |
1162 #endif | |
1163 | |
1164 /* Move the entries that were scrolled, disable | |
1165 * the entries for the lines to be redrawn. */ | |
1166 if ((wp->w_lines_valid += j) > wp->w_height) | |
1167 wp->w_lines_valid = wp->w_height; | |
1168 for (idx = wp->w_lines_valid; idx - j >= 0; idx--) | |
1169 wp->w_lines[idx] = wp->w_lines[idx - j]; | |
1170 while (idx >= 0) | |
1171 wp->w_lines[idx--].wl_valid = FALSE; | |
1172 } | |
1173 } | |
1174 else | |
1175 mid_start = 0; /* redraw all lines */ | |
1176 } | |
1177 else | |
1178 mid_start = 0; /* redraw all lines */ | |
1179 } | |
1180 else | |
1181 mid_start = 0; /* redraw all lines */ | |
1182 } | |
1183 else | |
1184 { | |
1185 /* | |
1186 * New topline is at or below old topline: May scroll up. | |
1187 * When topline didn't change, find first entry in w_lines[] that | |
1188 * needs updating. | |
1189 */ | |
1190 | |
1191 /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ | |
1192 j = -1; | |
1193 row = 0; | |
1194 for (i = 0; i < wp->w_lines_valid; i++) | |
1195 { | |
1196 if (wp->w_lines[i].wl_valid | |
1197 && wp->w_lines[i].wl_lnum == wp->w_topline) | |
1198 { | |
1199 j = i; | |
1200 break; | |
1201 } | |
1202 row += wp->w_lines[i].wl_size; | |
1203 } | |
1204 if (j == -1) | |
1205 { | |
1206 /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all | |
1207 * lines */ | |
1208 mid_start = 0; | |
1209 } | |
1210 else | |
1211 { | |
1212 /* | |
1213 * Try to delete the correct number of lines. | |
1214 * wp->w_topline is at wp->w_lines[i].wl_lnum. | |
1215 */ | |
1216 #ifdef FEAT_DIFF | |
1217 /* If the topline didn't change, delete old filler lines, | |
1218 * otherwise delete filler lines of the new topline... */ | |
1219 if (wp->w_lines[0].wl_lnum == wp->w_topline) | |
1220 row += wp->w_old_topfill; | |
1221 else | |
1222 row += diff_check_fill(wp, wp->w_topline); | |
1223 /* ... but don't delete new filler lines. */ | |
1224 row -= wp->w_topfill; | |
1225 #endif | |
1226 if (row > 0) | |
1227 { | |
1228 check_for_delay(FALSE); | |
1229 if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) | |
1230 bot_start = wp->w_height - row; | |
1231 else | |
1232 mid_start = 0; /* redraw all lines */ | |
1233 } | |
1234 if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) | |
1235 { | |
1236 /* | |
1237 * Skip the lines (below the deleted lines) that are still | |
1238 * valid and don't need redrawing. Copy their info | |
1239 * upwards, to compensate for the deleted lines. Set | |
1240 * bot_start to the first row that needs redrawing. | |
1241 */ | |
1242 bot_start = 0; | |
1243 idx = 0; | |
1244 for (;;) | |
1245 { | |
1246 wp->w_lines[idx] = wp->w_lines[j]; | |
1247 /* stop at line that didn't fit, unless it is still | |
1248 * valid (no lines deleted) */ | |
1249 if (row > 0 && bot_start + row | |
1250 + (int)wp->w_lines[j].wl_size > wp->w_height) | |
1251 { | |
1252 wp->w_lines_valid = idx + 1; | |
1253 break; | |
1254 } | |
1255 bot_start += wp->w_lines[idx++].wl_size; | |
1256 | |
1257 /* stop at the last valid entry in w_lines[].wl_size */ | |
1258 if (++j >= wp->w_lines_valid) | |
1259 { | |
1260 wp->w_lines_valid = idx; | |
1261 break; | |
1262 } | |
1263 } | |
1264 #ifdef FEAT_DIFF | |
1265 /* Correct the first entry for filler lines at the top | |
1266 * when it won't get updated below. */ | |
1267 if (wp->w_p_diff && bot_start > 0) | |
1268 wp->w_lines[0].wl_size = | |
1269 plines_win_nofill(wp, wp->w_topline, TRUE) | |
1270 + wp->w_topfill; | |
1271 #endif | |
1272 } | |
1273 } | |
1274 } | |
1275 | |
1276 /* When starting redraw in the first line, redraw all lines. When | |
1277 * there is only one window it's probably faster to clear the screen | |
1278 * first. */ | |
1279 if (mid_start == 0) | |
1280 { | |
1281 mid_end = wp->w_height; | |
1282 if (lastwin == firstwin) | |
981 | 1283 { |
1331 | 1284 /* Clear the screen when it was not done by win_del_lines() or |
1285 * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE | |
1286 * then. */ | |
1287 if (screen_cleared != TRUE) | |
1288 screenclear(); | |
981 | 1289 #ifdef FEAT_WINDOWS |
1290 /* The screen was cleared, redraw the tab pages line. */ | |
1291 if (redraw_tabline) | |
1292 draw_tabline(); | |
1293 #endif | |
1294 } | |
7 | 1295 } |
1331 | 1296 |
1297 /* When win_del_lines() or win_ins_lines() caused the screen to be | |
1298 * cleared (only happens for the first window) or when screenclear() | |
1299 * was called directly above, "must_redraw" will have been set to | |
1300 * NOT_VALID, need to reset it here to avoid redrawing twice. */ | |
1301 if (screen_cleared == TRUE) | |
1302 must_redraw = 0; | |
7 | 1303 } |
1304 else | |
1305 { | |
1306 /* Not VALID or INVERTED: redraw all lines. */ | |
1307 mid_start = 0; | |
1308 mid_end = wp->w_height; | |
1309 } | |
1310 | |
743 | 1311 if (type == SOME_VALID) |
1312 { | |
1313 /* SOME_VALID: redraw all lines. */ | |
1314 mid_start = 0; | |
1315 mid_end = wp->w_height; | |
1316 type = NOT_VALID; | |
1317 } | |
1318 | |
7 | 1319 #ifdef FEAT_VISUAL |
1320 /* check if we are updating or removing the inverted part */ | |
1321 if ((VIsual_active && buf == curwin->w_buffer) | |
1322 || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) | |
1323 { | |
1324 linenr_T from, to; | |
1325 | |
1326 if (VIsual_active) | |
1327 { | |
1328 if (VIsual_active | |
1329 && (VIsual_mode != wp->w_old_visual_mode | |
1330 || type == INVERTED_ALL)) | |
1331 { | |
1332 /* | |
1333 * If the type of Visual selection changed, redraw the whole | |
1334 * selection. Also when the ownership of the X selection is | |
1335 * gained or lost. | |
1336 */ | |
1337 if (curwin->w_cursor.lnum < VIsual.lnum) | |
1338 { | |
1339 from = curwin->w_cursor.lnum; | |
1340 to = VIsual.lnum; | |
1341 } | |
1342 else | |
1343 { | |
1344 from = VIsual.lnum; | |
1345 to = curwin->w_cursor.lnum; | |
1346 } | |
1347 /* redraw more when the cursor moved as well */ | |
1348 if (wp->w_old_cursor_lnum < from) | |
1349 from = wp->w_old_cursor_lnum; | |
1350 if (wp->w_old_cursor_lnum > to) | |
1351 to = wp->w_old_cursor_lnum; | |
1352 if (wp->w_old_visual_lnum < from) | |
1353 from = wp->w_old_visual_lnum; | |
1354 if (wp->w_old_visual_lnum > to) | |
1355 to = wp->w_old_visual_lnum; | |
1356 } | |
1357 else | |
1358 { | |
1359 /* | |
1360 * Find the line numbers that need to be updated: The lines | |
1361 * between the old cursor position and the current cursor | |
1362 * position. Also check if the Visual position changed. | |
1363 */ | |
1364 if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) | |
1365 { | |
1366 from = curwin->w_cursor.lnum; | |
1367 to = wp->w_old_cursor_lnum; | |
1368 } | |
1369 else | |
1370 { | |
1371 from = wp->w_old_cursor_lnum; | |
1372 to = curwin->w_cursor.lnum; | |
1373 if (from == 0) /* Visual mode just started */ | |
1374 from = to; | |
1375 } | |
1376 | |
422 | 1377 if (VIsual.lnum != wp->w_old_visual_lnum |
1378 || VIsual.col != wp->w_old_visual_col) | |
7 | 1379 { |
1380 if (wp->w_old_visual_lnum < from | |
1381 && wp->w_old_visual_lnum != 0) | |
1382 from = wp->w_old_visual_lnum; | |
1383 if (wp->w_old_visual_lnum > to) | |
1384 to = wp->w_old_visual_lnum; | |
1385 if (VIsual.lnum < from) | |
1386 from = VIsual.lnum; | |
1387 if (VIsual.lnum > to) | |
1388 to = VIsual.lnum; | |
1389 } | |
1390 } | |
1391 | |
1392 /* | |
1393 * If in block mode and changed column or curwin->w_curswant: | |
1394 * update all lines. | |
1395 * First compute the actual start and end column. | |
1396 */ | |
1397 if (VIsual_mode == Ctrl_V) | |
1398 { | |
1399 colnr_T fromc, toc; | |
1400 | |
1401 getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); | |
1402 ++toc; | |
1403 if (curwin->w_curswant == MAXCOL) | |
1404 toc = MAXCOL; | |
1405 | |
1406 if (fromc != wp->w_old_cursor_fcol | |
1407 || toc != wp->w_old_cursor_lcol) | |
1408 { | |
1409 if (from > VIsual.lnum) | |
1410 from = VIsual.lnum; | |
1411 if (to < VIsual.lnum) | |
1412 to = VIsual.lnum; | |
1413 } | |
1414 wp->w_old_cursor_fcol = fromc; | |
1415 wp->w_old_cursor_lcol = toc; | |
1416 } | |
1417 } | |
1418 else | |
1419 { | |
1420 /* Use the line numbers of the old Visual area. */ | |
1421 if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) | |
1422 { | |
1423 from = wp->w_old_cursor_lnum; | |
1424 to = wp->w_old_visual_lnum; | |
1425 } | |
1426 else | |
1427 { | |
1428 from = wp->w_old_visual_lnum; | |
1429 to = wp->w_old_cursor_lnum; | |
1430 } | |
1431 } | |
1432 | |
1433 /* | |
1434 * There is no need to update lines above the top of the window. | |
1435 */ | |
1436 if (from < wp->w_topline) | |
1437 from = wp->w_topline; | |
1438 | |
1439 /* | |
1440 * If we know the value of w_botline, use it to restrict the update to | |
1441 * the lines that are visible in the window. | |
1442 */ | |
1443 if (wp->w_valid & VALID_BOTLINE) | |
1444 { | |
1445 if (from >= wp->w_botline) | |
1446 from = wp->w_botline - 1; | |
1447 if (to >= wp->w_botline) | |
1448 to = wp->w_botline - 1; | |
1449 } | |
1450 | |
1451 /* | |
1452 * Find the minimal part to be updated. | |
1453 * Watch out for scrolling that made entries in w_lines[] invalid. | |
1454 * E.g., CTRL-U makes the first half of w_lines[] invalid and sets | |
1455 * top_end; need to redraw from top_end to the "to" line. | |
1456 * A middle mouse click with a Visual selection may change the text | |
1457 * above the Visual area and reset wl_valid, do count these for | |
1458 * mid_end (in srow). | |
1459 */ | |
1460 if (mid_start > 0) | |
1461 { | |
1462 lnum = wp->w_topline; | |
1463 idx = 0; | |
1464 srow = 0; | |
1465 if (scrolled_down) | |
1466 mid_start = top_end; | |
1467 else | |
1468 mid_start = 0; | |
1469 while (lnum < from && idx < wp->w_lines_valid) /* find start */ | |
1470 { | |
1471 if (wp->w_lines[idx].wl_valid) | |
1472 mid_start += wp->w_lines[idx].wl_size; | |
1473 else if (!scrolled_down) | |
1474 srow += wp->w_lines[idx].wl_size; | |
1475 ++idx; | |
1476 # ifdef FEAT_FOLDING | |
1477 if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) | |
1478 lnum = wp->w_lines[idx].wl_lnum; | |
1479 else | |
1480 # endif | |
1481 ++lnum; | |
1482 } | |
1483 srow += mid_start; | |
1484 mid_end = wp->w_height; | |
1485 for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ | |
1486 { | |
1487 if (wp->w_lines[idx].wl_valid | |
1488 && wp->w_lines[idx].wl_lnum >= to + 1) | |
1489 { | |
1490 /* Only update until first row of this line */ | |
1491 mid_end = srow; | |
1492 break; | |
1493 } | |
1494 srow += wp->w_lines[idx].wl_size; | |
1495 } | |
1496 } | |
1497 } | |
1498 | |
1499 if (VIsual_active && buf == curwin->w_buffer) | |
1500 { | |
1501 wp->w_old_visual_mode = VIsual_mode; | |
1502 wp->w_old_cursor_lnum = curwin->w_cursor.lnum; | |
1503 wp->w_old_visual_lnum = VIsual.lnum; | |
422 | 1504 wp->w_old_visual_col = VIsual.col; |
7 | 1505 wp->w_old_curswant = curwin->w_curswant; |
1506 } | |
1507 else | |
1508 { | |
1509 wp->w_old_visual_mode = 0; | |
1510 wp->w_old_cursor_lnum = 0; | |
1511 wp->w_old_visual_lnum = 0; | |
422 | 1512 wp->w_old_visual_col = 0; |
7 | 1513 } |
1514 #endif /* FEAT_VISUAL */ | |
1515 | |
1516 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1517 /* reset got_int, otherwise regexp won't work */ | |
1518 save_got_int = got_int; | |
1519 got_int = 0; | |
1520 #endif | |
1521 #ifdef FEAT_FOLDING | |
1522 win_foldinfo.fi_level = 0; | |
1523 #endif | |
1524 | |
1525 /* | |
1526 * Update all the window rows. | |
1527 */ | |
1528 idx = 0; /* first entry in w_lines[].wl_size */ | |
1529 row = 0; | |
1530 srow = 0; | |
1531 lnum = wp->w_topline; /* first line shown in window */ | |
1532 for (;;) | |
1533 { | |
1534 /* stop updating when reached the end of the window (check for _past_ | |
1535 * the end of the window is at the end of the loop) */ | |
1536 if (row == wp->w_height) | |
1537 { | |
1538 didline = TRUE; | |
1539 break; | |
1540 } | |
1541 | |
1542 /* stop updating when hit the end of the file */ | |
1543 if (lnum > buf->b_ml.ml_line_count) | |
1544 { | |
1545 eof = TRUE; | |
1546 break; | |
1547 } | |
1548 | |
1549 /* Remember the starting row of the line that is going to be dealt | |
1550 * with. It is used further down when the line doesn't fit. */ | |
1551 srow = row; | |
1552 | |
1553 /* | |
1554 * Update a line when it is in an area that needs updating, when it | |
1555 * has changes or w_lines[idx] is invalid. | |
1556 * bot_start may be halfway a wrapped line after using | |
1557 * win_del_lines(), check if the current line includes it. | |
1558 * When syntax folding is being used, the saved syntax states will | |
1559 * already have been updated, we can't see where the syntax state is | |
1560 * the same again, just update until the end of the window. | |
1561 */ | |
1562 if (row < top_end | |
1563 || (row >= mid_start && row < mid_end) | |
1564 #ifdef FEAT_SEARCH_EXTRA | |
1565 || top_to_mod | |
1566 #endif | |
1567 || idx >= wp->w_lines_valid | |
1568 || (row + wp->w_lines[idx].wl_size > bot_start) | |
1569 || (mod_top != 0 | |
1570 && (lnum == mod_top | |
1571 || (lnum >= mod_top | |
1572 && (lnum < mod_bot | |
1573 #ifdef FEAT_SYN_HL | |
1574 || did_update == DID_FOLD | |
1575 || (did_update == DID_LINE | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1576 && syntax_present(wp) |
7 | 1577 && ( |
1578 # ifdef FEAT_FOLDING | |
1579 (foldmethodIsSyntax(wp) | |
1580 && hasAnyFolding(wp)) || | |
1581 # endif | |
1582 syntax_check_changed(lnum))) | |
1583 #endif | |
1584 ))))) | |
1585 { | |
1586 #ifdef FEAT_SEARCH_EXTRA | |
1587 if (lnum == mod_top) | |
1588 top_to_mod = FALSE; | |
1589 #endif | |
1590 | |
1591 /* | |
1592 * When at start of changed lines: May scroll following lines | |
1593 * up or down to minimize redrawing. | |
1594 * Don't do this when the change continues until the end. | |
1595 * Don't scroll when dollar_vcol is non-zero, keep the "$". | |
1596 */ | |
1597 if (lnum == mod_top | |
1598 && mod_bot != MAXLNUM | |
1599 && !(dollar_vcol != 0 && mod_bot == mod_top + 1)) | |
1600 { | |
1601 int old_rows = 0; | |
1602 int new_rows = 0; | |
1603 int xtra_rows; | |
1604 linenr_T l; | |
1605 | |
1606 /* Count the old number of window rows, using w_lines[], which | |
1607 * should still contain the sizes for the lines as they are | |
1608 * currently displayed. */ | |
1609 for (i = idx; i < wp->w_lines_valid; ++i) | |
1610 { | |
1611 /* Only valid lines have a meaningful wl_lnum. Invalid | |
1612 * lines are part of the changed area. */ | |
1613 if (wp->w_lines[i].wl_valid | |
1614 && wp->w_lines[i].wl_lnum == mod_bot) | |
1615 break; | |
1616 old_rows += wp->w_lines[i].wl_size; | |
1617 #ifdef FEAT_FOLDING | |
1618 if (wp->w_lines[i].wl_valid | |
1619 && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) | |
1620 { | |
1621 /* Must have found the last valid entry above mod_bot. | |
1622 * Add following invalid entries. */ | |
1623 ++i; | |
1624 while (i < wp->w_lines_valid | |
1625 && !wp->w_lines[i].wl_valid) | |
1626 old_rows += wp->w_lines[i++].wl_size; | |
1627 break; | |
1628 } | |
1629 #endif | |
1630 } | |
1631 | |
1632 if (i >= wp->w_lines_valid) | |
1633 { | |
1634 /* We can't find a valid line below the changed lines, | |
1635 * need to redraw until the end of the window. | |
1636 * Inserting/deleting lines has no use. */ | |
1637 bot_start = 0; | |
1638 } | |
1639 else | |
1640 { | |
1641 /* Able to count old number of rows: Count new window | |
1642 * rows, and may insert/delete lines */ | |
1643 j = idx; | |
1644 for (l = lnum; l < mod_bot; ++l) | |
1645 { | |
1646 #ifdef FEAT_FOLDING | |
1647 if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) | |
1648 ++new_rows; | |
1649 else | |
1650 #endif | |
1651 #ifdef FEAT_DIFF | |
1652 if (l == wp->w_topline) | |
1653 new_rows += plines_win_nofill(wp, l, TRUE) | |
1654 + wp->w_topfill; | |
1655 else | |
1656 #endif | |
1657 new_rows += plines_win(wp, l, TRUE); | |
1658 ++j; | |
1659 if (new_rows > wp->w_height - row - 2) | |
1660 { | |
1661 /* it's getting too much, must redraw the rest */ | |
1662 new_rows = 9999; | |
1663 break; | |
1664 } | |
1665 } | |
1666 xtra_rows = new_rows - old_rows; | |
1667 if (xtra_rows < 0) | |
1668 { | |
1669 /* May scroll text up. If there is not enough | |
1670 * remaining text or scrolling fails, must redraw the | |
1671 * rest. If scrolling works, must redraw the text | |
1672 * below the scrolled text. */ | |
1673 if (row - xtra_rows >= wp->w_height - 2) | |
1674 mod_bot = MAXLNUM; | |
1675 else | |
1676 { | |
1677 check_for_delay(FALSE); | |
1678 if (win_del_lines(wp, row, | |
1679 -xtra_rows, FALSE, FALSE) == FAIL) | |
1680 mod_bot = MAXLNUM; | |
1681 else | |
1682 bot_start = wp->w_height + xtra_rows; | |
1683 } | |
1684 } | |
1685 else if (xtra_rows > 0) | |
1686 { | |
1687 /* May scroll text down. If there is not enough | |
1688 * remaining text of scrolling fails, must redraw the | |
1689 * rest. */ | |
1690 if (row + xtra_rows >= wp->w_height - 2) | |
1691 mod_bot = MAXLNUM; | |
1692 else | |
1693 { | |
1694 check_for_delay(FALSE); | |
1695 if (win_ins_lines(wp, row + old_rows, | |
1696 xtra_rows, FALSE, FALSE) == FAIL) | |
1697 mod_bot = MAXLNUM; | |
1698 else if (top_end > row + old_rows) | |
1699 /* Scrolled the part at the top that requires | |
1700 * updating down. */ | |
1701 top_end += xtra_rows; | |
1702 } | |
1703 } | |
1704 | |
1705 /* When not updating the rest, may need to move w_lines[] | |
1706 * entries. */ | |
1707 if (mod_bot != MAXLNUM && i != j) | |
1708 { | |
1709 if (j < i) | |
1710 { | |
1711 int x = row + new_rows; | |
1712 | |
1713 /* move entries in w_lines[] upwards */ | |
1714 for (;;) | |
1715 { | |
1716 /* stop at last valid entry in w_lines[] */ | |
1717 if (i >= wp->w_lines_valid) | |
1718 { | |
1719 wp->w_lines_valid = j; | |
1720 break; | |
1721 } | |
1722 wp->w_lines[j] = wp->w_lines[i]; | |
1723 /* stop at a line that won't fit */ | |
1724 if (x + (int)wp->w_lines[j].wl_size | |
1725 > wp->w_height) | |
1726 { | |
1727 wp->w_lines_valid = j + 1; | |
1728 break; | |
1729 } | |
1730 x += wp->w_lines[j++].wl_size; | |
1731 ++i; | |
1732 } | |
1733 if (bot_start > x) | |
1734 bot_start = x; | |
1735 } | |
1736 else /* j > i */ | |
1737 { | |
1738 /* move entries in w_lines[] downwards */ | |
1739 j -= i; | |
1740 wp->w_lines_valid += j; | |
1741 if (wp->w_lines_valid > wp->w_height) | |
1742 wp->w_lines_valid = wp->w_height; | |
1743 for (i = wp->w_lines_valid; i - j >= idx; --i) | |
1744 wp->w_lines[i] = wp->w_lines[i - j]; | |
1745 | |
1746 /* The w_lines[] entries for inserted lines are | |
1747 * now invalid, but wl_size may be used above. | |
1748 * Reset to zero. */ | |
1749 while (i >= idx) | |
1750 { | |
1751 wp->w_lines[i].wl_size = 0; | |
1752 wp->w_lines[i--].wl_valid = FALSE; | |
1753 } | |
1754 } | |
1755 } | |
1756 } | |
1757 } | |
1758 | |
1759 #ifdef FEAT_FOLDING | |
1760 /* | |
1761 * When lines are folded, display one line for all of them. | |
1762 * Otherwise, display normally (can be several display lines when | |
1763 * 'wrap' is on). | |
1764 */ | |
1765 fold_count = foldedCount(wp, lnum, &win_foldinfo); | |
1766 if (fold_count != 0) | |
1767 { | |
1768 fold_line(wp, fold_count, &win_foldinfo, lnum, row); | |
1769 ++row; | |
1770 --fold_count; | |
1771 wp->w_lines[idx].wl_folded = TRUE; | |
1772 wp->w_lines[idx].wl_lastlnum = lnum + fold_count; | |
1773 # ifdef FEAT_SYN_HL | |
1774 did_update = DID_FOLD; | |
1775 # endif | |
1776 } | |
1777 else | |
1778 #endif | |
1779 if (idx < wp->w_lines_valid | |
1780 && wp->w_lines[idx].wl_valid | |
1781 && wp->w_lines[idx].wl_lnum == lnum | |
1782 && lnum > wp->w_topline | |
1783 && !(dy_flags & DY_LASTLINE) | |
1784 && srow + wp->w_lines[idx].wl_size > wp->w_height | |
1785 #ifdef FEAT_DIFF | |
1786 && diff_check_fill(wp, lnum) == 0 | |
1787 #endif | |
1788 ) | |
1789 { | |
1790 /* This line is not going to fit. Don't draw anything here, | |
1791 * will draw "@ " lines below. */ | |
1792 row = wp->w_height + 1; | |
1793 } | |
1794 else | |
1795 { | |
1796 #ifdef FEAT_SEARCH_EXTRA | |
1797 prepare_search_hl(wp, lnum); | |
1798 #endif | |
1799 #ifdef FEAT_SYN_HL | |
1800 /* Let the syntax stuff know we skipped a few lines. */ | |
1801 if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1802 && syntax_present(wp)) |
7 | 1803 syntax_end_parsing(syntax_last_parsed + 1); |
1804 #endif | |
1805 | |
1806 /* | |
1807 * Display one line. | |
1808 */ | |
625 | 1809 row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
7 | 1810 |
1811 #ifdef FEAT_FOLDING | |
1812 wp->w_lines[idx].wl_folded = FALSE; | |
1813 wp->w_lines[idx].wl_lastlnum = lnum; | |
1814 #endif | |
1815 #ifdef FEAT_SYN_HL | |
1816 did_update = DID_LINE; | |
1817 syntax_last_parsed = lnum; | |
1818 #endif | |
1819 } | |
1820 | |
1821 wp->w_lines[idx].wl_lnum = lnum; | |
1822 wp->w_lines[idx].wl_valid = TRUE; | |
1823 if (row > wp->w_height) /* past end of screen */ | |
1824 { | |
1825 /* we may need the size of that too long line later on */ | |
1826 if (dollar_vcol == 0) | |
1827 wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); | |
1828 ++idx; | |
1829 break; | |
1830 } | |
1831 if (dollar_vcol == 0) | |
1832 wp->w_lines[idx].wl_size = row - srow; | |
1833 ++idx; | |
1834 #ifdef FEAT_FOLDING | |
1835 lnum += fold_count + 1; | |
1836 #else | |
1837 ++lnum; | |
1838 #endif | |
1839 } | |
1840 else | |
1841 { | |
1842 /* This line does not need updating, advance to the next one */ | |
1843 row += wp->w_lines[idx++].wl_size; | |
1844 if (row > wp->w_height) /* past end of screen */ | |
1845 break; | |
1846 #ifdef FEAT_FOLDING | |
1847 lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; | |
1848 #else | |
1849 ++lnum; | |
1850 #endif | |
1851 #ifdef FEAT_SYN_HL | |
1852 did_update = DID_NONE; | |
1853 #endif | |
1854 } | |
1855 | |
1856 if (lnum > buf->b_ml.ml_line_count) | |
1857 { | |
1858 eof = TRUE; | |
1859 break; | |
1860 } | |
1861 } | |
1862 /* | |
1863 * End of loop over all window lines. | |
1864 */ | |
1865 | |
1866 | |
1867 if (idx > wp->w_lines_valid) | |
1868 wp->w_lines_valid = idx; | |
1869 | |
1870 #ifdef FEAT_SYN_HL | |
1871 /* | |
1872 * Let the syntax stuff know we stop parsing here. | |
1873 */ | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
1874 if (syntax_last_parsed != 0 && syntax_present(wp)) |
7 | 1875 syntax_end_parsing(syntax_last_parsed + 1); |
1876 #endif | |
1877 | |
1878 /* | |
1879 * If we didn't hit the end of the file, and we didn't finish the last | |
1880 * line we were working on, then the line didn't fit. | |
1881 */ | |
1882 wp->w_empty_rows = 0; | |
1883 #ifdef FEAT_DIFF | |
1884 wp->w_filler_rows = 0; | |
1885 #endif | |
1886 if (!eof && !didline) | |
1887 { | |
1888 if (lnum == wp->w_topline) | |
1889 { | |
1890 /* | |
1891 * Single line that does not fit! | |
1892 * Don't overwrite it, it can be edited. | |
1893 */ | |
1894 wp->w_botline = lnum + 1; | |
1895 } | |
1896 #ifdef FEAT_DIFF | |
1897 else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) | |
1898 { | |
1899 /* Window ends in filler lines. */ | |
1900 wp->w_botline = lnum; | |
1901 wp->w_filler_rows = wp->w_height - srow; | |
1902 } | |
1903 #endif | |
1904 else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ | |
1905 { | |
1906 /* | |
1907 * Last line isn't finished: Display "@@@" at the end. | |
1908 */ | |
1909 screen_fill(W_WINROW(wp) + wp->w_height - 1, | |
1910 W_WINROW(wp) + wp->w_height, | |
1911 (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), | |
1912 '@', '@', hl_attr(HLF_AT)); | |
1913 set_empty_rows(wp, srow); | |
1914 wp->w_botline = lnum; | |
1915 } | |
1916 else | |
1917 { | |
1918 win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); | |
1919 wp->w_botline = lnum; | |
1920 } | |
1921 } | |
1922 else | |
1923 { | |
1924 #ifdef FEAT_VERTSPLIT | |
1925 draw_vsep_win(wp, row); | |
1926 #endif | |
1927 if (eof) /* we hit the end of the file */ | |
1928 { | |
1929 wp->w_botline = buf->b_ml.ml_line_count + 1; | |
1930 #ifdef FEAT_DIFF | |
1931 j = diff_check_fill(wp, wp->w_botline); | |
1932 if (j > 0 && !wp->w_botfill) | |
1933 { | |
1934 /* | |
1935 * Display filler lines at the end of the file | |
1936 */ | |
1937 if (char2cells(fill_diff) > 1) | |
1938 i = '-'; | |
1939 else | |
1940 i = fill_diff; | |
1941 if (row + j > wp->w_height) | |
1942 j = wp->w_height - row; | |
1943 win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); | |
1944 row += j; | |
1945 } | |
1946 #endif | |
1947 } | |
1948 else if (dollar_vcol == 0) | |
1949 wp->w_botline = lnum; | |
1950 | |
1951 /* make sure the rest of the screen is blank */ | |
1952 /* put '~'s on rows that aren't part of the file. */ | |
1953 win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); | |
1954 } | |
1955 | |
1956 /* Reset the type of redrawing required, the window has been updated. */ | |
1957 wp->w_redr_type = 0; | |
1958 #ifdef FEAT_DIFF | |
1959 wp->w_old_topfill = wp->w_topfill; | |
1960 wp->w_old_botfill = wp->w_botfill; | |
1961 #endif | |
1962 | |
1963 if (dollar_vcol == 0) | |
1964 { | |
1965 /* | |
1966 * There is a trick with w_botline. If we invalidate it on each | |
1967 * change that might modify it, this will cause a lot of expensive | |
1968 * calls to plines() in update_topline() each time. Therefore the | |
1969 * value of w_botline is often approximated, and this value is used to | |
1970 * compute the value of w_topline. If the value of w_botline was | |
1971 * wrong, check that the value of w_topline is correct (cursor is on | |
1972 * the visible part of the text). If it's not, we need to redraw | |
1973 * again. Mostly this just means scrolling up a few lines, so it | |
1974 * doesn't look too bad. Only do this for the current window (where | |
1975 * changes are relevant). | |
1976 */ | |
1977 wp->w_valid |= VALID_BOTLINE; | |
1978 if (wp == curwin && wp->w_botline != old_botline && !recursive) | |
1979 { | |
1980 recursive = TRUE; | |
1981 curwin->w_valid &= ~VALID_TOPLINE; | |
1982 update_topline(); /* may invalidate w_botline again */ | |
1983 if (must_redraw != 0) | |
1984 { | |
1985 /* Don't update for changes in buffer again. */ | |
1986 i = curbuf->b_mod_set; | |
1987 curbuf->b_mod_set = FALSE; | |
1988 win_update(curwin); | |
1989 must_redraw = 0; | |
1990 curbuf->b_mod_set = i; | |
1991 } | |
1992 recursive = FALSE; | |
1993 } | |
1994 } | |
1995 | |
1996 #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) | |
1997 /* restore got_int, unless CTRL-C was hit while redrawing */ | |
1998 if (!got_int) | |
1999 got_int = save_got_int; | |
2000 #endif | |
2001 } | |
2002 | |
2003 #ifdef FEAT_SIGNS | |
2004 static int draw_signcolumn __ARGS((win_T *wp)); | |
2005 | |
2006 /* | |
2007 * Return TRUE when window "wp" has a column to draw signs in. | |
2008 */ | |
2009 static int | |
2010 draw_signcolumn(wp) | |
2011 win_T *wp; | |
2012 { | |
2013 return (wp->w_buffer->b_signlist != NULL | |
2014 # ifdef FEAT_NETBEANS_INTG | |
2210 | 2015 || netbeans_active() |
7 | 2016 # endif |
2017 ); | |
2018 } | |
2019 #endif | |
2020 | |
2021 /* | |
2022 * Clear the rest of the window and mark the unused lines with "c1". use "c2" | |
2023 * as the filler character. | |
2024 */ | |
2025 static void | |
2026 win_draw_end(wp, c1, c2, row, endrow, hl) | |
2027 win_T *wp; | |
2028 int c1; | |
2029 int c2; | |
2030 int row; | |
2031 int endrow; | |
534 | 2032 hlf_T hl; |
7 | 2033 { |
2034 #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) | |
2035 int n = 0; | |
2036 # define FDC_OFF n | |
2037 #else | |
2038 # define FDC_OFF 0 | |
2039 #endif | |
2040 | |
2041 #ifdef FEAT_RIGHTLEFT | |
2042 if (wp->w_p_rl) | |
2043 { | |
2044 /* No check for cmdline window: should never be right-left. */ | |
2045 # ifdef FEAT_FOLDING | |
2046 n = wp->w_p_fdc; | |
2047 | |
2048 if (n > 0) | |
2049 { | |
2050 /* draw the fold column at the right */ | |
119 | 2051 if (n > W_WIDTH(wp)) |
2052 n = W_WIDTH(wp); | |
7 | 2053 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2054 W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), | |
2055 ' ', ' ', hl_attr(HLF_FC)); | |
2056 } | |
2057 # endif | |
2058 # ifdef FEAT_SIGNS | |
2059 if (draw_signcolumn(wp)) | |
2060 { | |
2061 int nn = n + 2; | |
2062 | |
2063 /* draw the sign column left of the fold column */ | |
119 | 2064 if (nn > W_WIDTH(wp)) |
2065 nn = W_WIDTH(wp); | |
7 | 2066 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
2067 W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, | |
2068 ' ', ' ', hl_attr(HLF_SC)); | |
2069 n = nn; | |
2070 } | |
2071 # endif | |
2072 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2073 W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, | |
2074 c2, c2, hl_attr(hl)); | |
2075 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2076 W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, | |
2077 c1, c2, hl_attr(hl)); | |
2078 } | |
2079 else | |
2080 #endif | |
2081 { | |
2082 #ifdef FEAT_CMDWIN | |
2083 if (cmdwin_type != 0 && wp == curwin) | |
2084 { | |
2085 /* draw the cmdline character in the leftmost column */ | |
2086 n = 1; | |
2087 if (n > wp->w_width) | |
2088 n = wp->w_width; | |
2089 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2090 W_WINCOL(wp), (int)W_WINCOL(wp) + n, | |
2091 cmdwin_type, ' ', hl_attr(HLF_AT)); | |
2092 } | |
2093 #endif | |
2094 #ifdef FEAT_FOLDING | |
2095 if (wp->w_p_fdc > 0) | |
2096 { | |
2097 int nn = n + wp->w_p_fdc; | |
2098 | |
2099 /* draw the fold column at the left */ | |
2100 if (nn > W_WIDTH(wp)) | |
2101 nn = W_WIDTH(wp); | |
2102 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2103 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2104 ' ', ' ', hl_attr(HLF_FC)); | |
2105 n = nn; | |
2106 } | |
2107 #endif | |
2108 #ifdef FEAT_SIGNS | |
2109 if (draw_signcolumn(wp)) | |
2110 { | |
2111 int nn = n + 2; | |
2112 | |
2113 /* draw the sign column after the fold column */ | |
2114 if (nn > W_WIDTH(wp)) | |
2115 nn = W_WIDTH(wp); | |
2116 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2117 W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, | |
2118 ' ', ' ', hl_attr(HLF_SC)); | |
2119 n = nn; | |
2120 } | |
2121 #endif | |
2122 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, | |
2123 W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), | |
2124 c1, c2, hl_attr(hl)); | |
2125 } | |
2126 set_empty_rows(wp, row); | |
2127 } | |
2128 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2129 #ifdef FEAT_SYN_HL |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2130 static int advance_color_col __ARGS((int vcol, int **color_cols)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2131 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2132 /* |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2133 * Advance **color_cols and return TRUE when there are columns to draw. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2134 */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2135 static int |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2136 advance_color_col(vcol, color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2137 int vcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2138 int **color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2139 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2140 while (**color_cols >= 0 && vcol > **color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2141 ++*color_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2142 return (**color_cols >= 0); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2143 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2144 #endif |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2145 |
7 | 2146 #ifdef FEAT_FOLDING |
2147 /* | |
2148 * Display one folded line. | |
2149 */ | |
2150 static void | |
2151 fold_line(wp, fold_count, foldinfo, lnum, row) | |
2152 win_T *wp; | |
2153 long fold_count; | |
2154 foldinfo_T *foldinfo; | |
2155 linenr_T lnum; | |
2156 int row; | |
2157 { | |
2158 char_u buf[51]; | |
2159 pos_T *top, *bot; | |
2160 linenr_T lnume = lnum + fold_count - 1; | |
2161 int len; | |
29 | 2162 char_u *text; |
7 | 2163 int fdc; |
2164 int col; | |
2165 int txtcol; | |
2166 int off = (int)(current_ScreenLine - ScreenLines); | |
216 | 2167 int ri; |
7 | 2168 |
2169 /* Build the fold line: | |
2170 * 1. Add the cmdwin_type for the command-line window | |
2171 * 2. Add the 'foldcolumn' | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2172 * 3. Add the 'number' or 'relativenumber' column |
7 | 2173 * 4. Compose the text |
2174 * 5. Add the text | |
2175 * 6. set highlighting for the Visual area an other text | |
2176 */ | |
2177 col = 0; | |
2178 | |
2179 /* | |
2180 * 1. Add the cmdwin_type for the command-line window | |
2181 * Ignores 'rightleft', this window is never right-left. | |
2182 */ | |
2183 #ifdef FEAT_CMDWIN | |
2184 if (cmdwin_type != 0 && wp == curwin) | |
2185 { | |
2186 ScreenLines[off] = cmdwin_type; | |
2187 ScreenAttrs[off] = hl_attr(HLF_AT); | |
2188 #ifdef FEAT_MBYTE | |
2189 if (enc_utf8) | |
2190 ScreenLinesUC[off] = 0; | |
2191 #endif | |
2192 ++col; | |
2193 } | |
2194 #endif | |
2195 | |
2196 /* | |
2197 * 2. Add the 'foldcolumn' | |
2198 */ | |
2199 fdc = wp->w_p_fdc; | |
2200 if (fdc > W_WIDTH(wp) - col) | |
2201 fdc = W_WIDTH(wp) - col; | |
2202 if (fdc > 0) | |
2203 { | |
2204 fill_foldcolumn(buf, wp, TRUE, lnum); | |
2205 #ifdef FEAT_RIGHTLEFT | |
2206 if (wp->w_p_rl) | |
2207 { | |
2208 int i; | |
2209 | |
2210 copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, | |
2211 hl_attr(HLF_FC)); | |
2212 /* reverse the fold column */ | |
2213 for (i = 0; i < fdc; ++i) | |
2214 ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; | |
2215 } | |
2216 else | |
2217 #endif | |
2218 copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); | |
2219 col += fdc; | |
2220 } | |
2221 | |
2222 #ifdef FEAT_RIGHTLEFT | |
216 | 2223 # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
2224 for (ri = 0; ri < l; ++ri) \ | |
2225 ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ | |
2226 else \ | |
2227 for (ri = 0; ri < l; ++ri) \ | |
2228 ScreenAttrs[off + (p) + ri] = v | |
7 | 2229 #else |
216 | 2230 # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
2231 ScreenAttrs[off + (p) + ri] = v | |
7 | 2232 #endif |
2233 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2234 /* Set all attributes of the 'number' or 'relativenumber' column and the |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2235 * text */ |
216 | 2236 RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
7 | 2237 |
2238 #ifdef FEAT_SIGNS | |
2239 /* If signs are being displayed, add two spaces. */ | |
2240 if (draw_signcolumn(wp)) | |
2241 { | |
2242 len = W_WIDTH(wp) - col; | |
2243 if (len > 0) | |
2244 { | |
2245 if (len > 2) | |
2246 len = 2; | |
2247 # ifdef FEAT_RIGHTLEFT | |
2248 if (wp->w_p_rl) | |
2249 /* the line number isn't reversed */ | |
2250 copy_text_attr(off + W_WIDTH(wp) - len - col, | |
2251 (char_u *)" ", len, hl_attr(HLF_FL)); | |
2252 else | |
2253 # endif | |
2254 copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); | |
2255 col += len; | |
2256 } | |
2257 } | |
2258 #endif | |
2259 | |
2260 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2261 * 3. Add the 'number' or 'relativenumber' column |
7 | 2262 */ |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2263 if (wp->w_p_nu || wp->w_p_rnu) |
7 | 2264 { |
2265 len = W_WIDTH(wp) - col; | |
2266 if (len > 0) | |
2267 { | |
13 | 2268 int w = number_width(wp); |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2269 long num; |
13 | 2270 |
2271 if (len > w + 1) | |
2272 len = w + 1; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2273 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2274 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2275 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2276 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2277 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2278 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2279 num = (long)abs((int)get_cursor_rel_lnum(wp, lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2280 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
2281 sprintf((char *)buf, "%*ld ", w, num); |
7 | 2282 #ifdef FEAT_RIGHTLEFT |
2283 if (wp->w_p_rl) | |
2284 /* the line number isn't reversed */ | |
2285 copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, | |
2286 hl_attr(HLF_FL)); | |
2287 else | |
2288 #endif | |
2289 copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); | |
2290 col += len; | |
2291 } | |
2292 } | |
2293 | |
2294 /* | |
2295 * 4. Compose the folded-line string with 'foldtext', if set. | |
2296 */ | |
29 | 2297 text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
7 | 2298 |
2299 txtcol = col; /* remember where text starts */ | |
2300 | |
2301 /* | |
2302 * 5. move the text to current_ScreenLine. Fill up with "fill_fold". | |
2303 * Right-left text is put in columns 0 - number-col, normal text is put | |
2304 * in columns number-col - window-width. | |
2305 */ | |
2306 #ifdef FEAT_MBYTE | |
2307 if (has_mbyte) | |
2308 { | |
2309 int cells; | |
714 | 2310 int u8c, u8cc[MAX_MCO]; |
2311 int i; | |
7 | 2312 int idx; |
2313 int c_len; | |
33 | 2314 char_u *p; |
7 | 2315 # ifdef FEAT_ARABIC |
2316 int prev_c = 0; /* previous Arabic character */ | |
2317 int prev_c1 = 0; /* first composing char for prev_c */ | |
2318 # endif | |
2319 | |
2320 # ifdef FEAT_RIGHTLEFT | |
2321 if (wp->w_p_rl) | |
2322 idx = off; | |
2323 else | |
2324 # endif | |
2325 idx = off + col; | |
2326 | |
2327 /* Store multibyte characters in ScreenLines[] et al. correctly. */ | |
2328 for (p = text; *p != NUL; ) | |
2329 { | |
2330 cells = (*mb_ptr2cells)(p); | |
474 | 2331 c_len = (*mb_ptr2len)(p); |
7 | 2332 if (col + cells > W_WIDTH(wp) |
2333 # ifdef FEAT_RIGHTLEFT | |
2334 - (wp->w_p_rl ? col : 0) | |
2335 # endif | |
2336 ) | |
2337 break; | |
2338 ScreenLines[idx] = *p; | |
2339 if (enc_utf8) | |
2340 { | |
714 | 2341 u8c = utfc_ptr2char(p, u8cc); |
2342 if (*p < 0x80 && u8cc[0] == 0) | |
7 | 2343 { |
2344 ScreenLinesUC[idx] = 0; | |
2345 #ifdef FEAT_ARABIC | |
2346 prev_c = u8c; | |
2347 #endif | |
2348 } | |
2349 else | |
2350 { | |
2351 #ifdef FEAT_ARABIC | |
2352 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
2353 { | |
2354 /* Do Arabic shaping. */ | |
714 | 2355 int pc, pc1, nc; |
2356 int pcc[MAX_MCO]; | |
7 | 2357 int firstbyte = *p; |
2358 | |
2359 /* The idea of what is the previous and next | |
2360 * character depends on 'rightleft'. */ | |
2361 if (wp->w_p_rl) | |
2362 { | |
2363 pc = prev_c; | |
2364 pc1 = prev_c1; | |
2365 nc = utf_ptr2char(p + c_len); | |
714 | 2366 prev_c1 = u8cc[0]; |
7 | 2367 } |
2368 else | |
2369 { | |
714 | 2370 pc = utfc_ptr2char(p + c_len, pcc); |
7 | 2371 nc = prev_c; |
714 | 2372 pc1 = pcc[0]; |
7 | 2373 } |
2374 prev_c = u8c; | |
2375 | |
714 | 2376 u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
7 | 2377 pc, pc1, nc); |
2378 ScreenLines[idx] = firstbyte; | |
2379 } | |
2380 else | |
2381 prev_c = u8c; | |
2382 #endif | |
2383 /* Non-BMP character: display as ? or fullwidth ?. */ | |
1401 | 2384 #ifdef UNICODE16 |
7 | 2385 if (u8c >= 0x10000) |
2386 ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; | |
2387 else | |
1401 | 2388 #endif |
7 | 2389 ScreenLinesUC[idx] = u8c; |
714 | 2390 for (i = 0; i < Screen_mco; ++i) |
2391 { | |
2392 ScreenLinesC[i][idx] = u8cc[i]; | |
2393 if (u8cc[i] == 0) | |
2394 break; | |
2395 } | |
7 | 2396 } |
2397 if (cells > 1) | |
2398 ScreenLines[idx + 1] = 0; | |
2399 } | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2400 else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2401 /* double-byte single width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2402 ScreenLines2[idx] = p[1]; |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2403 else if (cells > 1) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2404 /* double-width character */ |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
2405 ScreenLines[idx + 1] = p[1]; |
7 | 2406 col += cells; |
2407 idx += cells; | |
2408 p += c_len; | |
2409 } | |
2410 } | |
2411 else | |
2412 #endif | |
2413 { | |
2414 len = (int)STRLEN(text); | |
2415 if (len > W_WIDTH(wp) - col) | |
2416 len = W_WIDTH(wp) - col; | |
2417 if (len > 0) | |
2418 { | |
2419 #ifdef FEAT_RIGHTLEFT | |
2420 if (wp->w_p_rl) | |
2421 STRNCPY(current_ScreenLine, text, len); | |
2422 else | |
2423 #endif | |
2424 STRNCPY(current_ScreenLine + col, text, len); | |
2425 col += len; | |
2426 } | |
2427 } | |
2428 | |
2429 /* Fill the rest of the line with the fold filler */ | |
2430 #ifdef FEAT_RIGHTLEFT | |
2431 if (wp->w_p_rl) | |
2432 col -= txtcol; | |
2433 #endif | |
2434 while (col < W_WIDTH(wp) | |
2435 #ifdef FEAT_RIGHTLEFT | |
2436 - (wp->w_p_rl ? txtcol : 0) | |
2437 #endif | |
2438 ) | |
2439 { | |
2440 #ifdef FEAT_MBYTE | |
2441 if (enc_utf8) | |
2442 { | |
2443 if (fill_fold >= 0x80) | |
2444 { | |
2445 ScreenLinesUC[off + col] = fill_fold; | |
714 | 2446 ScreenLinesC[0][off + col] = 0; |
7 | 2447 } |
2448 else | |
2449 ScreenLinesUC[off + col] = 0; | |
2450 } | |
2451 #endif | |
2452 ScreenLines[off + col++] = fill_fold; | |
2453 } | |
2454 | |
2455 if (text != buf) | |
2456 vim_free(text); | |
2457 | |
2458 /* | |
2459 * 6. set highlighting for the Visual area an other text. | |
2460 * If all folded lines are in the Visual area, highlight the line. | |
2461 */ | |
2462 #ifdef FEAT_VISUAL | |
2463 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2464 { | |
2465 if (ltoreq(curwin->w_cursor, VIsual)) | |
2466 { | |
2467 /* Visual is after curwin->w_cursor */ | |
2468 top = &curwin->w_cursor; | |
2469 bot = &VIsual; | |
2470 } | |
2471 else | |
2472 { | |
2473 /* Visual is before curwin->w_cursor */ | |
2474 top = &VIsual; | |
2475 bot = &curwin->w_cursor; | |
2476 } | |
2477 if (lnum >= top->lnum | |
2478 && lnume <= bot->lnum | |
2479 && (VIsual_mode != 'v' | |
2480 || ((lnum > top->lnum | |
2481 || (lnum == top->lnum | |
2482 && top->col == 0)) | |
2483 && (lnume < bot->lnum | |
2484 || (lnume == bot->lnum | |
2485 && (bot->col - (*p_sel == 'e')) | |
1883 | 2486 >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
7 | 2487 { |
2488 if (VIsual_mode == Ctrl_V) | |
2489 { | |
2490 /* Visual block mode: highlight the chars part of the block */ | |
2491 if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2492 { | |
2493 if (wp->w_old_cursor_lcol + txtcol < (colnr_T)W_WIDTH(wp)) | |
2494 len = wp->w_old_cursor_lcol; | |
2495 else | |
2496 len = W_WIDTH(wp) - txtcol; | |
2497 RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), | |
230 | 2498 len - (int)wp->w_old_cursor_fcol); |
7 | 2499 } |
2500 } | |
2501 else | |
216 | 2502 { |
7 | 2503 /* Set all attributes of the text */ |
216 | 2504 RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
2505 } | |
7 | 2506 } |
2507 } | |
2508 #endif | |
2509 | |
743 | 2510 #ifdef FEAT_SYN_HL |
2511 /* Show 'cursorcolumn' in the fold line. */ | |
1725 | 2512 if (wp->w_p_cuc) |
2513 { | |
2514 txtcol += wp->w_virtcol; | |
2515 if (wp->w_p_wrap) | |
2516 txtcol -= wp->w_skipcol; | |
2517 else | |
2518 txtcol -= wp->w_leftcol; | |
2519 if (txtcol >= 0 && txtcol < W_WIDTH(wp)) | |
2520 ScreenAttrs[off + txtcol] = hl_combine_attr( | |
2521 ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); | |
2522 } | |
743 | 2523 #endif |
7 | 2524 |
2525 SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), | |
2526 (int)W_WIDTH(wp), FALSE); | |
2527 | |
2528 /* | |
2529 * Update w_cline_height and w_cline_folded if the cursor line was | |
2530 * updated (saves a call to plines() later). | |
2531 */ | |
2532 if (wp == curwin | |
2533 && lnum <= curwin->w_cursor.lnum | |
2534 && lnume >= curwin->w_cursor.lnum) | |
2535 { | |
2536 curwin->w_cline_row = row; | |
2537 curwin->w_cline_height = 1; | |
2538 curwin->w_cline_folded = TRUE; | |
2539 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
2540 } | |
2541 } | |
2542 | |
2543 /* | |
2544 * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". | |
2545 */ | |
2546 static void | |
2547 copy_text_attr(off, buf, len, attr) | |
2548 int off; | |
2549 char_u *buf; | |
2550 int len; | |
2551 int attr; | |
2552 { | |
216 | 2553 int i; |
2554 | |
7 | 2555 mch_memmove(ScreenLines + off, buf, (size_t)len); |
2556 # ifdef FEAT_MBYTE | |
2557 if (enc_utf8) | |
2558 vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); | |
2559 # endif | |
216 | 2560 for (i = 0; i < len; ++i) |
2561 ScreenAttrs[off + i] = attr; | |
7 | 2562 } |
2563 | |
2564 /* | |
2565 * Fill the foldcolumn at "p" for window "wp". | |
548 | 2566 * Only to be called when 'foldcolumn' > 0. |
7 | 2567 */ |
2568 static void | |
2569 fill_foldcolumn(p, wp, closed, lnum) | |
2570 char_u *p; | |
2571 win_T *wp; | |
2572 int closed; /* TRUE of FALSE */ | |
2573 linenr_T lnum; /* current line number */ | |
2574 { | |
2575 int i = 0; | |
2576 int level; | |
2577 int first_level; | |
519 | 2578 int empty; |
7 | 2579 |
2580 /* Init to all spaces. */ | |
2581 copy_spaces(p, (size_t)wp->w_p_fdc); | |
2582 | |
2583 level = win_foldinfo.fi_level; | |
2584 if (level > 0) | |
2585 { | |
519 | 2586 /* If there is only one column put more info in it. */ |
2587 empty = (wp->w_p_fdc == 1) ? 0 : 1; | |
2588 | |
7 | 2589 /* If the column is too narrow, we start at the lowest level that |
2590 * fits and use numbers to indicated the depth. */ | |
519 | 2591 first_level = level - wp->w_p_fdc - closed + 1 + empty; |
7 | 2592 if (first_level < 1) |
2593 first_level = 1; | |
2594 | |
519 | 2595 for (i = 0; i + empty < wp->w_p_fdc; ++i) |
7 | 2596 { |
2597 if (win_foldinfo.fi_lnum == lnum | |
2598 && first_level + i >= win_foldinfo.fi_low_level) | |
2599 p[i] = '-'; | |
2600 else if (first_level == 1) | |
2601 p[i] = '|'; | |
2602 else if (first_level + i <= 9) | |
2603 p[i] = '0' + first_level + i; | |
2604 else | |
2605 p[i] = '>'; | |
2606 if (first_level + i == level) | |
2607 break; | |
2608 } | |
2609 } | |
2610 if (closed) | |
548 | 2611 p[i >= wp->w_p_fdc ? i - 1 : i] = '+'; |
7 | 2612 } |
2613 #endif /* FEAT_FOLDING */ | |
2614 | |
2615 /* | |
2616 * Display line "lnum" of window 'wp' on the screen. | |
2617 * Start at row "startrow", stop when "endrow" is reached. | |
2618 * wp->w_virtcol needs to be valid. | |
2619 * | |
2620 * Return the number of last row the line occupies. | |
2621 */ | |
2622 static int | |
625 | 2623 win_line(wp, lnum, startrow, endrow, nochange) |
7 | 2624 win_T *wp; |
2625 linenr_T lnum; | |
2626 int startrow; | |
2627 int endrow; | |
1883 | 2628 int nochange UNUSED; /* not updating for changed text */ |
7 | 2629 { |
2630 int col; /* visual column on screen */ | |
2631 unsigned off; /* offset in ScreenLines/ScreenAttrs */ | |
2632 int c = 0; /* init for GCC */ | |
2633 long vcol = 0; /* virtual column (for tabs) */ | |
2634 long vcol_prev = -1; /* "vcol" of previous character */ | |
2635 char_u *line; /* current line */ | |
2636 char_u *ptr; /* current position in "line" */ | |
2637 int row; /* row in the window, excl w_winrow */ | |
2638 int screen_row; /* row on the screen, incl w_winrow */ | |
2639 | |
2640 char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ | |
2641 int n_extra = 0; /* number of extra chars */ | |
1340 | 2642 char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
7 | 2643 int c_extra = NUL; /* extra chars, all the same */ |
2644 int extra_attr = 0; /* attributes when n_extra != 0 */ | |
2645 static char_u *at_end_str = (char_u *)""; /* used for p_extra when | |
2646 displaying lcs_eol at end-of-line */ | |
2647 int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ | |
2648 int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ | |
2649 | |
2650 /* saved "extra" items for when draw_state becomes WL_LINE (again) */ | |
2651 int saved_n_extra = 0; | |
2652 char_u *saved_p_extra = NULL; | |
2653 int saved_c_extra = 0; | |
2654 int saved_char_attr = 0; | |
2655 | |
2656 int n_attr = 0; /* chars with special attr */ | |
2657 int saved_attr2 = 0; /* char_attr saved for n_attr */ | |
2658 int n_attr3 = 0; /* chars with overruling special attr */ | |
2659 int saved_attr3 = 0; /* char_attr saved for n_attr3 */ | |
2660 | |
2661 int n_skip = 0; /* nr of chars to skip for 'nowrap' */ | |
2662 | |
2663 int fromcol, tocol; /* start/end of inverting */ | |
2664 int fromcol_prev = -2; /* start of inverting after cursor */ | |
2665 int noinvcur = FALSE; /* don't invert the cursor */ | |
2666 #ifdef FEAT_VISUAL | |
2667 pos_T *top, *bot; | |
1813 | 2668 int lnum_in_visual_area = FALSE; |
7 | 2669 #endif |
2670 pos_T pos; | |
2671 long v; | |
2672 | |
2673 int char_attr = 0; /* attributes for next character */ | |
674 | 2674 int attr_pri = FALSE; /* char_attr has priority */ |
7 | 2675 int area_highlighting = FALSE; /* Visual or incsearch highlighting |
2676 in this line */ | |
2677 int attr = 0; /* attributes for area highlighting */ | |
2678 int area_attr = 0; /* attributes desired by highlighting */ | |
2679 int search_attr = 0; /* attributes desired by 'hlsearch' */ | |
2680 #ifdef FEAT_SYN_HL | |
743 | 2681 int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
7 | 2682 int syntax_attr = 0; /* attributes desired by syntax */ |
2683 int has_syntax = FALSE; /* this buffer has syntax highl. */ | |
2684 int save_did_emsg; | |
1437 | 2685 int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2686 int draw_color_col = FALSE; /* highlight colorcolumn */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2687 int *color_cols = NULL; /* pointer to according columns array */ |
743 | 2688 #endif |
2689 #ifdef FEAT_SPELL | |
221 | 2690 int has_spell = FALSE; /* this buffer has spell checking */ |
348 | 2691 # define SPWORDLEN 150 |
2692 char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ | |
353 | 2693 int nextlinecol = 0; /* column where nextline[] starts */ |
2694 int nextline_idx = 0; /* index in nextline[] where next line | |
348 | 2695 starts */ |
221 | 2696 int spell_attr = 0; /* attributes desired by spelling */ |
2697 int word_end = 0; /* last byte with same spell_attr */ | |
378 | 2698 static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
2699 static int checked_col = 0; /* column in "checked_lnum" up to which | |
348 | 2700 * there are no spell errors */ |
386 | 2701 static int cap_col = -1; /* column to check for Cap word */ |
2702 static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ | |
348 | 2703 int cur_checked_col = 0; /* checked column for current line */ |
7 | 2704 #endif |
2705 int extra_check; /* has syntax or linebreak */ | |
2706 #ifdef FEAT_MBYTE | |
2707 int multi_attr = 0; /* attributes desired by multibyte */ | |
2708 int mb_l = 1; /* multi-byte byte length */ | |
2709 int mb_c = 0; /* decoded multi-byte character */ | |
2710 int mb_utf8 = FALSE; /* screen char is UTF-8 char */ | |
714 | 2711 int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
7 | 2712 #endif |
2713 #ifdef FEAT_DIFF | |
2714 int filler_lines; /* nr of filler lines to be drawn */ | |
2715 int filler_todo; /* nr of filler lines still to do + 1 */ | |
534 | 2716 hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
7 | 2717 int change_start = MAXCOL; /* first col of changed area */ |
2718 int change_end = -1; /* last col of changed area */ | |
2719 #endif | |
2720 colnr_T trailcol = MAXCOL; /* start of trailing spaces */ | |
2721 #ifdef FEAT_LINEBREAK | |
2722 int need_showbreak = FALSE; | |
2723 #endif | |
910 | 2724 #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
2725 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) | |
7 | 2726 # define LINE_ATTR |
1536 | 2727 int line_attr = 0; /* attribute for the whole line */ |
7 | 2728 #endif |
2729 #ifdef FEAT_SEARCH_EXTRA | |
1326 | 2730 matchitem_T *cur; /* points to the match list */ |
2731 match_T *shl; /* points to search_hl or a match */ | |
2732 int shl_flag; /* flag to indicate whether search_hl | |
2733 has been processed or not */ | |
2734 int prevcol_hl_flag; /* flag to indicate whether prevcol | |
2735 equals startcol of search_hl or one | |
2736 of the matches */ | |
7 | 2737 #endif |
2738 #ifdef FEAT_ARABIC | |
2739 int prev_c = 0; /* previous Arabic character */ | |
2740 int prev_c1 = 0; /* first composing char for prev_c */ | |
2741 #endif | |
910 | 2742 #if defined(LINE_ATTR) |
867 | 2743 int did_line_attr = 0; |
2744 #endif | |
7 | 2745 |
2746 /* draw_state: items that are drawn in sequence: */ | |
2747 #define WL_START 0 /* nothing done yet */ | |
2748 #ifdef FEAT_CMDWIN | |
2749 # define WL_CMDLINE WL_START + 1 /* cmdline window column */ | |
2750 #else | |
2751 # define WL_CMDLINE WL_START | |
2752 #endif | |
2753 #ifdef FEAT_FOLDING | |
2754 # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ | |
2755 #else | |
2756 # define WL_FOLD WL_CMDLINE | |
2757 #endif | |
2758 #ifdef FEAT_SIGNS | |
2759 # define WL_SIGN WL_FOLD + 1 /* column for signs */ | |
2760 #else | |
2761 # define WL_SIGN WL_FOLD /* column for signs */ | |
2762 #endif | |
2763 #define WL_NR WL_SIGN + 1 /* line number */ | |
2764 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
2765 # define WL_SBR WL_NR + 1 /* 'showbreak' or 'diff' */ | |
2766 #else | |
2767 # define WL_SBR WL_NR | |
2768 #endif | |
2769 #define WL_LINE WL_SBR + 1 /* text in the line */ | |
2770 int draw_state = WL_START; /* what to draw next */ | |
574 | 2771 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 2772 int feedback_col = 0; |
2773 int feedback_old_attr = -1; | |
2774 #endif | |
2775 | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2776 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2777 int syntax_flags = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2778 int conceal_attr = hl_attr(HLF_CONCEAL); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2779 int first_conceal = (wp->w_p_conceal != 3); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2780 int is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2781 int boguscols = 0; /* nonexistent columns added to force |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2782 wrapping */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2783 #endif |
7 | 2784 |
2785 if (startrow > endrow) /* past the end already! */ | |
2786 return startrow; | |
2787 | |
2788 row = startrow; | |
2789 screen_row = row + W_WINROW(wp); | |
2790 | |
2791 /* | |
2792 * To speed up the loop below, set extra_check when there is linebreak, | |
2793 * trailing white space and/or syntax processing to be done. | |
2794 */ | |
2795 #ifdef FEAT_LINEBREAK | |
2796 extra_check = wp->w_p_lbr; | |
2797 #else | |
2798 extra_check = 0; | |
2799 #endif | |
2800 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2801 if (syntax_present(wp) && !wp->w_s->b_syn_error) |
7 | 2802 { |
2803 /* Prepare for syntax highlighting in this line. When there is an | |
2804 * error, stop syntax highlighting. */ | |
2805 save_did_emsg = did_emsg; | |
2806 did_emsg = FALSE; | |
2807 syntax_start(wp, lnum); | |
2808 if (did_emsg) | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2809 wp->w_s->b_syn_error = TRUE; |
7 | 2810 else |
2811 { | |
2812 did_emsg = save_did_emsg; | |
2813 has_syntax = TRUE; | |
2814 extra_check = TRUE; | |
2815 } | |
2816 } | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2817 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2818 /* Check for columns to display for 'colorcolumn'. */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2819 color_cols = wp->w_p_cc_cols; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2820 if (color_cols != NULL) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
2821 draw_color_col = advance_color_col(vcol, &color_cols); |
743 | 2822 #endif |
2823 | |
2824 #ifdef FEAT_SPELL | |
258 | 2825 if (wp->w_p_spell |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2826 && *wp->w_s->b_p_spl != NUL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2827 && wp->w_s->b_langp.ga_len > 0 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
2828 && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
221 | 2829 { |
2830 /* Prepare for spell checking. */ | |
2831 has_spell = TRUE; | |
2832 extra_check = TRUE; | |
348 | 2833 |
2834 /* Get the start of the next line, so that words that wrap to the next | |
2835 * line are found too: "et<line-break>al.". | |
2836 * Trick: skip a few chars for C/shell/Vim comments */ | |
2837 nextline[SPWORDLEN] = NUL; | |
2838 if (lnum < wp->w_buffer->b_ml.ml_line_count) | |
2839 { | |
2840 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); | |
2841 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); | |
2842 } | |
2843 | |
2844 /* When a word wrapped from the previous line the start of the current | |
2845 * line is valid. */ | |
2846 if (lnum == checked_lnum) | |
2847 cur_checked_col = checked_col; | |
2848 checked_lnum = 0; | |
386 | 2849 |
2850 /* When there was a sentence end in the previous line may require a | |
2851 * word starting with capital in this line. In line 1 always check | |
2852 * the first word. */ | |
2853 if (lnum != capcol_lnum) | |
2854 cap_col = -1; | |
2855 if (lnum == 1) | |
2856 cap_col = 0; | |
2857 capcol_lnum = 0; | |
221 | 2858 } |
7 | 2859 #endif |
2860 | |
2861 /* | |
2862 * handle visual active in this window | |
2863 */ | |
2864 fromcol = -10; | |
2865 tocol = MAXCOL; | |
2866 #ifdef FEAT_VISUAL | |
2867 if (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
2868 { | |
2869 /* Visual is after curwin->w_cursor */ | |
2870 if (ltoreq(curwin->w_cursor, VIsual)) | |
2871 { | |
2872 top = &curwin->w_cursor; | |
2873 bot = &VIsual; | |
2874 } | |
2875 else /* Visual is before curwin->w_cursor */ | |
2876 { | |
2877 top = &VIsual; | |
2878 bot = &curwin->w_cursor; | |
2879 } | |
1813 | 2880 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
7 | 2881 if (VIsual_mode == Ctrl_V) /* block mode */ |
2882 { | |
1813 | 2883 if (lnum_in_visual_area) |
7 | 2884 { |
2885 fromcol = wp->w_old_cursor_fcol; | |
2886 tocol = wp->w_old_cursor_lcol; | |
2887 } | |
2888 } | |
2889 else /* non-block mode */ | |
2890 { | |
2891 if (lnum > top->lnum && lnum <= bot->lnum) | |
2892 fromcol = 0; | |
2893 else if (lnum == top->lnum) | |
2894 { | |
2895 if (VIsual_mode == 'V') /* linewise */ | |
2896 fromcol = 0; | |
2897 else | |
2898 { | |
2899 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); | |
2900 if (gchar_pos(top) == NUL) | |
2901 tocol = fromcol + 1; | |
2902 } | |
2903 } | |
2904 if (VIsual_mode != 'V' && lnum == bot->lnum) | |
2905 { | |
2906 if (*p_sel == 'e' && bot->col == 0 | |
2907 #ifdef FEAT_VIRTUALEDIT | |
2908 && bot->coladd == 0 | |
2909 #endif | |
2910 ) | |
2911 { | |
2912 fromcol = -10; | |
2913 tocol = MAXCOL; | |
2914 } | |
36 | 2915 else if (bot->col == MAXCOL) |
2916 tocol = MAXCOL; | |
7 | 2917 else |
2918 { | |
2919 pos = *bot; | |
2920 if (*p_sel == 'e') | |
2921 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2922 else | |
2923 { | |
2924 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); | |
2925 ++tocol; | |
2926 } | |
2927 } | |
2928 } | |
2929 } | |
2930 | |
2931 #ifndef MSDOS | |
2932 /* Check if the character under the cursor should not be inverted */ | |
2933 if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin | |
2934 # ifdef FEAT_GUI | |
2935 && !gui.in_use | |
2936 # endif | |
2937 ) | |
2938 noinvcur = TRUE; | |
2939 #endif | |
2940 | |
2941 /* if inverting in this line set area_highlighting */ | |
2942 if (fromcol >= 0) | |
2943 { | |
2944 area_highlighting = TRUE; | |
2945 attr = hl_attr(HLF_V); | |
2946 #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) | |
2947 if (clip_star.available && !clip_star.owned && clip_isautosel()) | |
2948 attr = hl_attr(HLF_VNC); | |
2949 #endif | |
2950 } | |
2951 } | |
2952 | |
2953 /* | |
674 | 2954 * handle 'incsearch' and ":s///c" highlighting |
7 | 2955 */ |
2956 else | |
2957 #endif /* FEAT_VISUAL */ | |
2958 if (highlight_match | |
2959 && wp == curwin | |
2960 && lnum >= curwin->w_cursor.lnum | |
2961 && lnum <= curwin->w_cursor.lnum + search_match_lines) | |
2962 { | |
2963 if (lnum == curwin->w_cursor.lnum) | |
2964 getvcol(curwin, &(curwin->w_cursor), | |
2965 (colnr_T *)&fromcol, NULL, NULL); | |
2966 else | |
2967 fromcol = 0; | |
2968 if (lnum == curwin->w_cursor.lnum + search_match_lines) | |
2969 { | |
2970 pos.lnum = lnum; | |
2971 pos.col = search_match_endcol; | |
2972 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); | |
2973 } | |
2974 else | |
2975 tocol = MAXCOL; | |
1850 | 2976 /* do at least one character; happens when past end of line */ |
2977 if (fromcol == tocol) | |
2978 tocol = fromcol + 1; | |
7 | 2979 area_highlighting = TRUE; |
2980 attr = hl_attr(HLF_I); | |
2981 } | |
2982 | |
2983 #ifdef FEAT_DIFF | |
2984 filler_lines = diff_check(wp, lnum); | |
2985 if (filler_lines < 0) | |
2986 { | |
2987 if (filler_lines == -1) | |
2988 { | |
2989 if (diff_find_change(wp, lnum, &change_start, &change_end)) | |
2990 diff_hlf = HLF_ADD; /* added line */ | |
2991 else if (change_start == 0) | |
2992 diff_hlf = HLF_TXD; /* changed text */ | |
2993 else | |
2994 diff_hlf = HLF_CHD; /* changed line */ | |
2995 } | |
2996 else | |
2997 diff_hlf = HLF_ADD; /* added line */ | |
2998 filler_lines = 0; | |
2999 area_highlighting = TRUE; | |
3000 } | |
3001 if (lnum == wp->w_topline) | |
3002 filler_lines = wp->w_topfill; | |
3003 filler_todo = filler_lines; | |
3004 #endif | |
3005 | |
3006 #ifdef LINE_ATTR | |
3007 # ifdef FEAT_SIGNS | |
3008 /* If this line has a sign with line highlighting set line_attr. */ | |
3009 v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); | |
3010 if (v != 0) | |
3011 line_attr = sign_get_attr((int)v, TRUE); | |
3012 # endif | |
3013 # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | |
3014 /* Highlight the current line in the quickfix window. */ | |
644 | 3015 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
7 | 3016 line_attr = hl_attr(HLF_L); |
3017 # endif | |
3018 if (line_attr != 0) | |
3019 area_highlighting = TRUE; | |
3020 #endif | |
3021 | |
3022 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3023 ptr = line; | |
3024 | |
743 | 3025 #ifdef FEAT_SPELL |
348 | 3026 if (has_spell) |
3027 { | |
386 | 3028 /* For checking first word with a capital skip white space. */ |
3029 if (cap_col == 0) | |
835 | 3030 cap_col = (int)(skipwhite(line) - line); |
386 | 3031 |
348 | 3032 /* To be able to spell-check over line boundaries copy the end of the |
3033 * current line into nextline[]. Above the start of the next line was | |
3034 * copied to nextline[SPWORDLEN]. */ | |
3035 if (nextline[SPWORDLEN] == NUL) | |
3036 { | |
3037 /* No next line or it is empty. */ | |
3038 nextlinecol = MAXCOL; | |
3039 nextline_idx = 0; | |
3040 } | |
3041 else | |
3042 { | |
835 | 3043 v = (long)STRLEN(line); |
348 | 3044 if (v < SPWORDLEN) |
3045 { | |
3046 /* Short line, use it completely and append the start of the | |
3047 * next line. */ | |
3048 nextlinecol = 0; | |
3049 mch_memmove(nextline, line, (size_t)v); | |
1621 | 3050 STRMOVE(nextline + v, nextline + SPWORDLEN); |
348 | 3051 nextline_idx = v + 1; |
3052 } | |
3053 else | |
3054 { | |
3055 /* Long line, use only the last SPWORDLEN bytes. */ | |
3056 nextlinecol = v - SPWORDLEN; | |
3057 mch_memmove(nextline, line + nextlinecol, SPWORDLEN); | |
3058 nextline_idx = SPWORDLEN + 1; | |
3059 } | |
3060 } | |
3061 } | |
3062 #endif | |
3063 | |
7 | 3064 /* find start of trailing whitespace */ |
3065 if (wp->w_p_list && lcs_trail) | |
3066 { | |
3067 trailcol = (colnr_T)STRLEN(ptr); | |
3068 while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) | |
3069 --trailcol; | |
3070 trailcol += (colnr_T) (ptr - line); | |
3071 extra_check = TRUE; | |
3072 } | |
3073 | |
3074 /* | |
3075 * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the | |
3076 * first character to be displayed. | |
3077 */ | |
3078 if (wp->w_p_wrap) | |
3079 v = wp->w_skipcol; | |
3080 else | |
3081 v = wp->w_leftcol; | |
3082 if (v > 0) | |
3083 { | |
3084 #ifdef FEAT_MBYTE | |
3085 char_u *prev_ptr = ptr; | |
3086 #endif | |
3087 while (vcol < v && *ptr != NUL) | |
3088 { | |
3089 c = win_lbr_chartabsize(wp, ptr, (colnr_T)vcol, NULL); | |
3090 vcol += c; | |
3091 #ifdef FEAT_MBYTE | |
3092 prev_ptr = ptr; | |
39 | 3093 #endif |
3094 mb_ptr_adv(ptr); | |
7 | 3095 } |
3096 | |
1984 | 3097 #if defined(FEAT_SYN_HL) || defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3098 /* When: | |
3099 * - 'cuc' is set, or | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3100 * - 'colorcolumn' is set, or |
1984 | 3101 * - 'virtualedit' is set, or |
3102 * - the visual mode is active, | |
3103 * the end of the line may be before the start of the displayed part. | |
3104 */ | |
3105 if (vcol < v && ( | |
3106 # ifdef FEAT_SYN_HL | |
3107 wp->w_p_cuc | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
3108 || draw_color_col |
1984 | 3109 # if defined(FEAT_VIRTUALEDIT) || defined(FEAT_VISUAL) |
3110 || | |
3111 # endif | |
3112 # endif | |
3113 # ifdef FEAT_VIRTUALEDIT | |
3114 virtual_active() | |
3115 # ifdef FEAT_VISUAL | |
3116 || | |
3117 # endif | |
3118 # endif | |
3119 # ifdef FEAT_VISUAL | |
3120 (VIsual_active && wp->w_buffer == curwin->w_buffer) | |
3121 # endif | |
3122 )) | |
3123 { | |
7 | 3124 vcol = v; |
1984 | 3125 } |
7 | 3126 #endif |
3127 | |
3128 /* Handle a character that's not completely on the screen: Put ptr at | |
3129 * that character but skip the first few screen characters. */ | |
3130 if (vcol > v) | |
3131 { | |
3132 vcol -= c; | |
3133 #ifdef FEAT_MBYTE | |
3134 ptr = prev_ptr; | |
3135 #else | |
3136 --ptr; | |
3137 #endif | |
3138 n_skip = v - vcol; | |
3139 } | |
3140 | |
3141 /* | |
3142 * Adjust for when the inverted text is before the screen, | |
3143 * and when the start of the inverted text is before the screen. | |
3144 */ | |
3145 if (tocol <= vcol) | |
3146 fromcol = 0; | |
3147 else if (fromcol >= 0 && fromcol < vcol) | |
3148 fromcol = vcol; | |
3149 | |
3150 #ifdef FEAT_LINEBREAK | |
3151 /* When w_skipcol is non-zero, first line needs 'showbreak' */ | |
3152 if (wp->w_p_wrap) | |
3153 need_showbreak = TRUE; | |
3154 #endif | |
743 | 3155 #ifdef FEAT_SPELL |
499 | 3156 /* When spell checking a word we need to figure out the start of the |
3157 * word and if it's badly spelled or not. */ | |
3158 if (has_spell) | |
3159 { | |
3160 int len; | |
1536 | 3161 colnr_T linecol = (colnr_T)(ptr - line); |
534 | 3162 hlf_T spell_hlf = HLF_COUNT; |
499 | 3163 |
3164 pos = wp->w_cursor; | |
3165 wp->w_cursor.lnum = lnum; | |
1536 | 3166 wp->w_cursor.col = linecol; |
534 | 3167 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
1536 | 3168 |
3169 /* spell_move_to() may call ml_get() and make "line" invalid */ | |
3170 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3171 ptr = line + linecol; | |
3172 | |
530 | 3173 if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
499 | 3174 { |
3175 /* no bad word found at line start, don't check until end of a | |
3176 * word */ | |
534 | 3177 spell_hlf = HLF_COUNT; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
3178 word_end = (int)(spell_to_word_end(ptr, wp) |
1536 | 3179 - line + 1); |
499 | 3180 } |
3181 else | |
534 | 3182 { |
499 | 3183 /* bad word found, use attributes until end of word */ |
3184 word_end = wp->w_cursor.col + len + 1; | |
3185 | |
534 | 3186 /* Turn index into actual attributes. */ |
3187 if (spell_hlf != HLF_COUNT) | |
3188 spell_attr = highlight_attr[spell_hlf]; | |
3189 } | |
499 | 3190 wp->w_cursor = pos; |
501 | 3191 |
743 | 3192 # ifdef FEAT_SYN_HL |
501 | 3193 /* Need to restart syntax highlighting for this line. */ |
3194 if (has_syntax) | |
3195 syntax_start(wp, lnum); | |
743 | 3196 # endif |
499 | 3197 } |
3198 #endif | |
7 | 3199 } |
3200 | |
3201 /* | |
3202 * Correct highlighting for cursor that can't be disabled. | |
3203 * Avoids having to check this for each character. | |
3204 */ | |
3205 if (fromcol >= 0) | |
3206 { | |
3207 if (noinvcur) | |
3208 { | |
3209 if ((colnr_T)fromcol == wp->w_virtcol) | |
3210 { | |
3211 /* highlighting starts at cursor, let it start just after the | |
3212 * cursor */ | |
3213 fromcol_prev = fromcol; | |
3214 fromcol = -1; | |
3215 } | |
3216 else if ((colnr_T)fromcol < wp->w_virtcol) | |
3217 /* restart highlighting after the cursor */ | |
3218 fromcol_prev = wp->w_virtcol; | |
3219 } | |
3220 if (fromcol >= tocol) | |
3221 fromcol = -1; | |
3222 } | |
3223 | |
3224 #ifdef FEAT_SEARCH_EXTRA | |
3225 /* | |
1326 | 3226 * Handle highlighting the last used search pattern and matches. |
3227 * Do this for both search_hl and the match list. | |
7 | 3228 */ |
1326 | 3229 cur = wp->w_match_head; |
3230 shl_flag = FALSE; | |
3231 while (cur != NULL || shl_flag == FALSE) | |
3232 { | |
3233 if (shl_flag == FALSE) | |
3234 { | |
3235 shl = &search_hl; | |
3236 shl_flag = TRUE; | |
3237 } | |
3238 else | |
3239 shl = &cur->hl; | |
36 | 3240 shl->startcol = MAXCOL; |
3241 shl->endcol = MAXCOL; | |
7 | 3242 shl->attr_cur = 0; |
3243 if (shl->rm.regprog != NULL) | |
3244 { | |
3245 v = (long)(ptr - line); | |
3246 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3247 | |
3248 /* Need to get the line again, a multi-line regexp may have made it | |
3249 * invalid. */ | |
3250 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3251 ptr = line + v; | |
3252 | |
3253 if (shl->lnum != 0 && shl->lnum <= lnum) | |
3254 { | |
3255 if (shl->lnum == lnum) | |
36 | 3256 shl->startcol = shl->rm.startpos[0].col; |
7 | 3257 else |
36 | 3258 shl->startcol = 0; |
7 | 3259 if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
3260 - shl->rm.startpos[0].lnum) | |
36 | 3261 shl->endcol = shl->rm.endpos[0].col; |
7 | 3262 else |
36 | 3263 shl->endcol = MAXCOL; |
7 | 3264 /* Highlight one character for an empty match. */ |
36 | 3265 if (shl->startcol == shl->endcol) |
7 | 3266 { |
3267 #ifdef FEAT_MBYTE | |
36 | 3268 if (has_mbyte && line[shl->endcol] != NUL) |
474 | 3269 shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
7 | 3270 else |
3271 #endif | |
36 | 3272 ++shl->endcol; |
7 | 3273 } |
36 | 3274 if ((long)shl->startcol < v) /* match at leftcol */ |
7 | 3275 { |
3276 shl->attr_cur = shl->attr; | |
3277 search_attr = shl->attr; | |
3278 } | |
3279 area_highlighting = TRUE; | |
3280 } | |
3281 } | |
1326 | 3282 if (shl != &search_hl && cur != NULL) |
3283 cur = cur->next; | |
7 | 3284 } |
3285 #endif | |
3286 | |
743 | 3287 #ifdef FEAT_SYN_HL |
818 | 3288 /* Cursor line highlighting for 'cursorline'. Not when Visual mode is |
3289 * active, because it's not clear what is selected then. */ | |
3290 if (wp->w_p_cul && lnum == wp->w_cursor.lnum && !VIsual_active) | |
743 | 3291 { |
3292 line_attr = hl_attr(HLF_CUL); | |
3293 area_highlighting = TRUE; | |
3294 } | |
3295 #endif | |
3296 | |
504 | 3297 off = (unsigned)(current_ScreenLine - ScreenLines); |
7 | 3298 col = 0; |
3299 #ifdef FEAT_RIGHTLEFT | |
3300 if (wp->w_p_rl) | |
3301 { | |
3302 /* Rightleft window: process the text in the normal direction, but put | |
3303 * it in current_ScreenLine[] from right to left. Start at the | |
3304 * rightmost column of the window. */ | |
3305 col = W_WIDTH(wp) - 1; | |
3306 off += col; | |
3307 } | |
3308 #endif | |
3309 | |
3310 /* | |
3311 * Repeat for the whole displayed line. | |
3312 */ | |
3313 for (;;) | |
3314 { | |
3315 /* Skip this quickly when working on the text. */ | |
3316 if (draw_state != WL_LINE) | |
3317 { | |
3318 #ifdef FEAT_CMDWIN | |
3319 if (draw_state == WL_CMDLINE - 1 && n_extra == 0) | |
3320 { | |
3321 draw_state = WL_CMDLINE; | |
3322 if (cmdwin_type != 0 && wp == curwin) | |
3323 { | |
3324 /* Draw the cmdline character. */ | |
3325 n_extra = 1; | |
1340 | 3326 c_extra = cmdwin_type; |
7 | 3327 char_attr = hl_attr(HLF_AT); |
3328 } | |
3329 } | |
3330 #endif | |
3331 | |
3332 #ifdef FEAT_FOLDING | |
3333 if (draw_state == WL_FOLD - 1 && n_extra == 0) | |
3334 { | |
3335 draw_state = WL_FOLD; | |
3336 if (wp->w_p_fdc > 0) | |
3337 { | |
3338 /* Draw the 'foldcolumn'. */ | |
3339 fill_foldcolumn(extra, wp, FALSE, lnum); | |
3340 n_extra = wp->w_p_fdc; | |
3341 p_extra = extra; | |
1340 | 3342 p_extra[n_extra] = NUL; |
7 | 3343 c_extra = NUL; |
3344 char_attr = hl_attr(HLF_FC); | |
3345 } | |
3346 } | |
3347 #endif | |
3348 | |
3349 #ifdef FEAT_SIGNS | |
3350 if (draw_state == WL_SIGN - 1 && n_extra == 0) | |
3351 { | |
3352 draw_state = WL_SIGN; | |
3353 /* Show the sign column when there are any signs in this | |
3354 * buffer or when using Netbeans. */ | |
3355 if (draw_signcolumn(wp) | |
3356 # ifdef FEAT_DIFF | |
3357 && filler_todo <= 0 | |
3358 # endif | |
3359 ) | |
3360 { | |
3361 int_u text_sign; | |
3362 # ifdef FEAT_SIGN_ICONS | |
3363 int_u icon_sign; | |
3364 # endif | |
3365 | |
3366 /* Draw two cells with the sign value or blank. */ | |
3367 c_extra = ' '; | |
3368 char_attr = hl_attr(HLF_SC); | |
3369 n_extra = 2; | |
3370 | |
3371 if (row == startrow) | |
3372 { | |
3373 text_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3374 SIGN_TEXT); | |
3375 # ifdef FEAT_SIGN_ICONS | |
3376 icon_sign = buf_getsigntype(wp->w_buffer, lnum, | |
3377 SIGN_ICON); | |
3378 if (gui.in_use && icon_sign != 0) | |
3379 { | |
3380 /* Use the image in this position. */ | |
3381 c_extra = SIGN_BYTE; | |
3382 # ifdef FEAT_NETBEANS_INTG | |
3383 if (buf_signcount(wp->w_buffer, lnum) > 1) | |
3384 c_extra = MULTISIGN_BYTE; | |
3385 # endif | |
3386 char_attr = icon_sign; | |
3387 } | |
3388 else | |
3389 # endif | |
3390 if (text_sign != 0) | |
3391 { | |
3392 p_extra = sign_get_text(text_sign); | |
3393 if (p_extra != NULL) | |
3394 { | |
3395 c_extra = NUL; | |
835 | 3396 n_extra = (int)STRLEN(p_extra); |
7 | 3397 } |
3398 char_attr = sign_get_attr(text_sign, FALSE); | |
3399 } | |
3400 } | |
3401 } | |
3402 } | |
3403 #endif | |
3404 | |
3405 if (draw_state == WL_NR - 1 && n_extra == 0) | |
3406 { | |
3407 draw_state = WL_NR; | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3408 /* Display the absolute or relative line number. After the |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3409 * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3410 if ((wp->w_p_nu || wp->w_p_rnu) |
7 | 3411 && (row == startrow |
3412 #ifdef FEAT_DIFF | |
3413 + filler_lines | |
3414 #endif | |
3415 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) | |
3416 { | |
3417 /* Draw the line number (empty space after wrapping). */ | |
3418 if (row == startrow | |
3419 #ifdef FEAT_DIFF | |
3420 + filler_lines | |
3421 #endif | |
3422 ) | |
3423 { | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3424 long num; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3425 |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3426 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3427 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3428 num = (long)lnum; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3429 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3430 /* 'relativenumber', don't use negative numbers */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3431 num = (long)abs((int)get_cursor_rel_lnum(wp, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3432 lnum)); |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3433 |
13 | 3434 sprintf((char *)extra, "%*ld ", |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
3435 number_width(wp), num); |
7 | 3436 if (wp->w_skipcol > 0) |
3437 for (p_extra = extra; *p_extra == ' '; ++p_extra) | |
3438 *p_extra = '-'; | |
3439 #ifdef FEAT_RIGHTLEFT | |
3440 if (wp->w_p_rl) /* reverse line numbers */ | |
3441 rl_mirror(extra); | |
3442 #endif | |
3443 p_extra = extra; | |
3444 c_extra = NUL; | |
3445 } | |
3446 else | |
3447 c_extra = ' '; | |
13 | 3448 n_extra = number_width(wp) + 1; |
7 | 3449 char_attr = hl_attr(HLF_N); |
743 | 3450 #ifdef FEAT_SYN_HL |
3451 /* When 'cursorline' is set highlight the line number of | |
3452 * the current line differently. */ | |
3453 if (wp->w_p_cul && lnum == wp->w_cursor.lnum) | |
3454 char_attr = hl_combine_attr(hl_attr(HLF_CUL), char_attr); | |
3455 #endif | |
7 | 3456 } |
3457 } | |
3458 | |
3459 #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) | |
3460 if (draw_state == WL_SBR - 1 && n_extra == 0) | |
3461 { | |
3462 draw_state = WL_SBR; | |
3463 # ifdef FEAT_DIFF | |
3464 if (filler_todo > 0) | |
3465 { | |
3466 /* Draw "deleted" diff line(s). */ | |
3467 if (char2cells(fill_diff) > 1) | |
3468 c_extra = '-'; | |
3469 else | |
3470 c_extra = fill_diff; | |
3471 # ifdef FEAT_RIGHTLEFT | |
3472 if (wp->w_p_rl) | |
3473 n_extra = col + 1; | |
3474 else | |
3475 # endif | |
3476 n_extra = W_WIDTH(wp) - col; | |
3477 char_attr = hl_attr(HLF_DED); | |
3478 } | |
3479 # endif | |
3480 # ifdef FEAT_LINEBREAK | |
3481 if (*p_sbr != NUL && need_showbreak) | |
3482 { | |
3483 /* Draw 'showbreak' at the start of each broken line. */ | |
3484 p_extra = p_sbr; | |
3485 c_extra = NUL; | |
3486 n_extra = (int)STRLEN(p_sbr); | |
3487 char_attr = hl_attr(HLF_AT); | |
3488 need_showbreak = FALSE; | |
3489 /* Correct end of highlighted area for 'showbreak', | |
3490 * required when 'linebreak' is also set. */ | |
3491 if (tocol == vcol) | |
3492 tocol += n_extra; | |
3493 } | |
3494 # endif | |
3495 } | |
3496 #endif | |
3497 | |
3498 if (draw_state == WL_LINE - 1 && n_extra == 0) | |
3499 { | |
3500 draw_state = WL_LINE; | |
3501 if (saved_n_extra) | |
3502 { | |
3503 /* Continue item from end of wrapped line. */ | |
3504 n_extra = saved_n_extra; | |
3505 c_extra = saved_c_extra; | |
3506 p_extra = saved_p_extra; | |
3507 char_attr = saved_char_attr; | |
3508 } | |
3509 else | |
3510 char_attr = 0; | |
3511 } | |
3512 } | |
3513 | |
3514 /* When still displaying '$' of change command, stop at cursor */ | |
819 | 3515 if (dollar_vcol != 0 && wp == curwin |
3516 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol | |
7 | 3517 #ifdef FEAT_DIFF |
3518 && filler_todo <= 0 | |
3519 #endif | |
3520 ) | |
3521 { | |
3522 SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), | |
3523 wp->w_p_rl); | |
819 | 3524 /* Pretend we have finished updating the window. Except when |
3525 * 'cursorcolumn' is set. */ | |
3526 #ifdef FEAT_SYN_HL | |
3527 if (wp->w_p_cuc) | |
3528 row = wp->w_cline_row + wp->w_cline_height; | |
3529 else | |
3530 #endif | |
3531 row = wp->w_height; | |
7 | 3532 break; |
3533 } | |
3534 | |
3535 if (draw_state == WL_LINE && area_highlighting) | |
3536 { | |
3537 /* handle Visual or match highlighting in this line */ | |
3538 if (vcol == fromcol | |
3539 #ifdef FEAT_MBYTE | |
3540 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 | |
3541 && (*mb_ptr2cells)(ptr) > 1) | |
3542 #endif | |
3543 || ((int)vcol_prev == fromcol_prev | |
1814 | 3544 && vcol_prev < vcol /* not at margin */ |
7 | 3545 && vcol < tocol)) |
3546 area_attr = attr; /* start highlighting */ | |
3547 else if (area_attr != 0 | |
3548 && (vcol == tocol | |
3549 || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) | |
3550 area_attr = 0; /* stop highlighting */ | |
3551 | |
3552 #ifdef FEAT_SEARCH_EXTRA | |
3553 if (!n_extra) | |
3554 { | |
3555 /* | |
3556 * Check for start/end of search pattern match. | |
3557 * After end, check for start/end of next match. | |
3558 * When another match, have to check for start again. | |
3559 * Watch out for matching an empty string! | |
1326 | 3560 * Do this for 'search_hl' and the match list (ordered by |
3561 * priority). | |
7 | 3562 */ |
36 | 3563 v = (long)(ptr - line); |
1326 | 3564 cur = wp->w_match_head; |
3565 shl_flag = FALSE; | |
3566 while (cur != NULL || shl_flag == FALSE) | |
3567 { | |
3568 if (shl_flag == FALSE | |
3569 && ((cur != NULL | |
3570 && cur->priority > SEARCH_HL_PRIORITY) | |
3571 || cur == NULL)) | |
3572 { | |
3573 shl = &search_hl; | |
3574 shl_flag = TRUE; | |
3575 } | |
3576 else | |
3577 shl = &cur->hl; | |
7 | 3578 while (shl->rm.regprog != NULL) |
3579 { | |
36 | 3580 if (shl->startcol != MAXCOL |
3581 && v >= (long)shl->startcol | |
3582 && v < (long)shl->endcol) | |
7 | 3583 { |
3584 shl->attr_cur = shl->attr; | |
3585 } | |
36 | 3586 else if (v == (long)shl->endcol) |
7 | 3587 { |
3588 shl->attr_cur = 0; | |
3589 | |
3590 next_search_hl(wp, shl, lnum, (colnr_T)v); | |
3591 | |
3592 /* Need to get the line again, a multi-line regexp | |
3593 * may have made it invalid. */ | |
3594 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
3595 ptr = line + v; | |
3596 | |
3597 if (shl->lnum == lnum) | |
3598 { | |
36 | 3599 shl->startcol = shl->rm.startpos[0].col; |
7 | 3600 if (shl->rm.endpos[0].lnum == 0) |
36 | 3601 shl->endcol = shl->rm.endpos[0].col; |
7 | 3602 else |
36 | 3603 shl->endcol = MAXCOL; |
3604 | |
3605 if (shl->startcol == shl->endcol) | |
7 | 3606 { |
3607 /* highlight empty match, try again after | |
3608 * it */ | |
3609 #ifdef FEAT_MBYTE | |
3610 if (has_mbyte) | |
474 | 3611 shl->endcol += (*mb_ptr2len)(line |
36 | 3612 + shl->endcol); |
7 | 3613 else |
3614 #endif | |
36 | 3615 ++shl->endcol; |
7 | 3616 } |
3617 | |
3618 /* Loop to check if the match starts at the | |
3619 * current position */ | |
3620 continue; | |
3621 } | |
3622 } | |
3623 break; | |
3624 } | |
1326 | 3625 if (shl != &search_hl && cur != NULL) |
3626 cur = cur->next; | |
3627 } | |
3628 | |
3629 /* Use attributes from match with highest priority among | |
3630 * 'search_hl' and the match list. */ | |
3631 search_attr = search_hl.attr_cur; | |
3632 cur = wp->w_match_head; | |
3633 shl_flag = FALSE; | |
3634 while (cur != NULL || shl_flag == FALSE) | |
3635 { | |
3636 if (shl_flag == FALSE | |
3637 && ((cur != NULL | |
3638 && cur->priority > SEARCH_HL_PRIORITY) | |
3639 || cur == NULL)) | |
699 | 3640 { |
1326 | 3641 shl = &search_hl; |
3642 shl_flag = TRUE; | |
699 | 3643 } |
1326 | 3644 else |
3645 shl = &cur->hl; | |
3646 if (shl->attr_cur != 0) | |
3647 search_attr = shl->attr_cur; | |
3648 if (shl != &search_hl && cur != NULL) | |
3649 cur = cur->next; | |
3650 } | |
7 | 3651 } |
3652 #endif | |
3653 | |
3654 #ifdef FEAT_DIFF | |
674 | 3655 if (diff_hlf != (hlf_T)0) |
7 | 3656 { |
1295 | 3657 if (diff_hlf == HLF_CHD && ptr - line >= change_start |
3658 && n_extra == 0) | |
7 | 3659 diff_hlf = HLF_TXD; /* changed text */ |
1295 | 3660 if (diff_hlf == HLF_TXD && ptr - line > change_end |
3661 && n_extra == 0) | |
7 | 3662 diff_hlf = HLF_CHD; /* changed line */ |
674 | 3663 line_attr = hl_attr(diff_hlf); |
3664 } | |
3665 #endif | |
3666 | |
3667 /* Decide which of the highlight attributes to use. */ | |
3668 attr_pri = TRUE; | |
3669 if (area_attr != 0) | |
3670 char_attr = area_attr; | |
3671 else if (search_attr != 0) | |
3672 char_attr = search_attr; | |
3673 #ifdef LINE_ATTR | |
3674 /* Use line_attr when not in the Visual or 'incsearch' area | |
3675 * (area_attr may be 0 when "noinvcur" is set). */ | |
3676 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) | |
1842 | 3677 || vcol < fromcol || vcol_prev < fromcol_prev |
3678 || vcol >= tocol)) | |
674 | 3679 char_attr = line_attr; |
3680 #endif | |
3681 else | |
3682 { | |
3683 attr_pri = FALSE; | |
3684 #ifdef FEAT_SYN_HL | |
3685 if (has_syntax) | |
3686 char_attr = syntax_attr; | |
3687 else | |
3688 #endif | |
3689 char_attr = 0; | |
3690 } | |
7 | 3691 } |
3692 | |
3693 /* | |
3694 * Get the next character to put on the screen. | |
3695 */ | |
3696 /* | |
1340 | 3697 * The "p_extra" points to the extra stuff that is inserted to |
3698 * represent special characters (non-printable stuff) and other | |
3699 * things. When all characters are the same, c_extra is used. | |
3700 * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past | |
3701 * "p_extra[n_extra]". | |
7 | 3702 * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
3703 */ | |
3704 if (n_extra > 0) | |
3705 { | |
3706 if (c_extra != NUL) | |
3707 { | |
3708 c = c_extra; | |
3709 #ifdef FEAT_MBYTE | |
3710 mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ | |
3711 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3712 { | |
3713 mb_utf8 = TRUE; | |
714 | 3714 u8cc[0] = 0; |
819 | 3715 c = 0xc0; |
7 | 3716 } |
3717 else | |
3718 mb_utf8 = FALSE; | |
3719 #endif | |
3720 } | |
3721 else | |
3722 { | |
3723 c = *p_extra; | |
3724 #ifdef FEAT_MBYTE | |
3725 if (has_mbyte) | |
3726 { | |
3727 mb_c = c; | |
3728 if (enc_utf8) | |
3729 { | |
3730 /* If the UTF-8 character is more than one byte: | |
3731 * Decode it into "mb_c". */ | |
474 | 3732 mb_l = (*mb_ptr2len)(p_extra); |
7 | 3733 mb_utf8 = FALSE; |
3734 if (mb_l > n_extra) | |
3735 mb_l = 1; | |
3736 else if (mb_l > 1) | |
3737 { | |
714 | 3738 mb_c = utfc_ptr2char(p_extra, u8cc); |
7 | 3739 mb_utf8 = TRUE; |
819 | 3740 c = 0xc0; |
7 | 3741 } |
3742 } | |
3743 else | |
3744 { | |
3745 /* if this is a DBCS character, put it in "mb_c" */ | |
3746 mb_l = MB_BYTE2LEN(c); | |
3747 if (mb_l >= n_extra) | |
3748 mb_l = 1; | |
3749 else if (mb_l > 1) | |
3750 mb_c = (c << 8) + p_extra[1]; | |
3751 } | |
504 | 3752 if (mb_l == 0) /* at the NUL at end-of-line */ |
3753 mb_l = 1; | |
3754 | |
7 | 3755 /* If a double-width char doesn't fit display a '>' in the |
3756 * last column. */ | |
504 | 3757 if (( |
7 | 3758 # ifdef FEAT_RIGHTLEFT |
3759 wp->w_p_rl ? (col <= 0) : | |
3760 # endif | |
504 | 3761 (col >= W_WIDTH(wp) - 1)) |
7 | 3762 && (*mb_char2cells)(mb_c) == 2) |
3763 { | |
3764 c = '>'; | |
3765 mb_c = c; | |
3766 mb_l = 1; | |
3767 mb_utf8 = FALSE; | |
3768 multi_attr = hl_attr(HLF_AT); | |
3769 /* put the pointer back to output the double-width | |
3770 * character at the start of the next line. */ | |
3771 ++n_extra; | |
3772 --p_extra; | |
3773 } | |
3774 else | |
3775 { | |
3776 n_extra -= mb_l - 1; | |
3777 p_extra += mb_l - 1; | |
3778 } | |
3779 } | |
3780 #endif | |
3781 ++p_extra; | |
3782 } | |
3783 --n_extra; | |
3784 } | |
3785 else | |
3786 { | |
3787 /* | |
3788 * Get a character from the line itself. | |
3789 */ | |
3790 c = *ptr; | |
3791 #ifdef FEAT_MBYTE | |
3792 if (has_mbyte) | |
3793 { | |
3794 mb_c = c; | |
3795 if (enc_utf8) | |
3796 { | |
3797 /* If the UTF-8 character is more than one byte: Decode it | |
3798 * into "mb_c". */ | |
474 | 3799 mb_l = (*mb_ptr2len)(ptr); |
7 | 3800 mb_utf8 = FALSE; |
3801 if (mb_l > 1) | |
3802 { | |
714 | 3803 mb_c = utfc_ptr2char(ptr, u8cc); |
7 | 3804 /* Overlong encoded ASCII or ASCII with composing char |
3805 * is displayed normally, except a NUL. */ | |
3806 if (mb_c < 0x80) | |
3807 c = mb_c; | |
3808 mb_utf8 = TRUE; | |
507 | 3809 |
3810 /* At start of the line we can have a composing char. | |
3811 * Draw it as a space with a composing char. */ | |
3812 if (utf_iscomposing(mb_c)) | |
3813 { | |
1326 | 3814 int i; |
3815 | |
714 | 3816 for (i = Screen_mco - 1; i > 0; --i) |
3817 u8cc[i] = u8cc[i - 1]; | |
3818 u8cc[0] = mb_c; | |
507 | 3819 mb_c = ' '; |
3820 } | |
7 | 3821 } |
3822 | |
3823 if ((mb_l == 1 && c >= 0x80) | |
3824 || (mb_l >= 1 && mb_c == 0) | |
3825 || (mb_l > 1 && (!vim_isprintc(mb_c) | |
1401 | 3826 # ifdef UNICODE16 |
3827 || mb_c >= 0x10000 | |
3828 # endif | |
3829 ))) | |
7 | 3830 { |
3831 /* | |
3832 * Illegal UTF-8 byte: display as <xx>. | |
3833 * Non-BMP character : display as ? or fullwidth ?. | |
3834 */ | |
1401 | 3835 # ifdef UNICODE16 |
7 | 3836 if (mb_c < 0x10000) |
1401 | 3837 # endif |
7 | 3838 { |
3839 transchar_hex(extra, mb_c); | |
714 | 3840 # ifdef FEAT_RIGHTLEFT |
7 | 3841 if (wp->w_p_rl) /* reverse */ |
3842 rl_mirror(extra); | |
714 | 3843 # endif |
7 | 3844 } |
1401 | 3845 # ifdef UNICODE16 |
7 | 3846 else if (utf_char2cells(mb_c) != 2) |
3847 STRCPY(extra, "?"); | |
3848 else | |
3849 /* 0xff1f in UTF-8: full-width '?' */ | |
3850 STRCPY(extra, "\357\274\237"); | |
1401 | 3851 # endif |
7 | 3852 |
3853 p_extra = extra; | |
3854 c = *p_extra; | |
3855 mb_c = mb_ptr2char_adv(&p_extra); | |
3856 mb_utf8 = (c >= 0x80); | |
3857 n_extra = (int)STRLEN(p_extra); | |
3858 c_extra = NUL; | |
3859 if (area_attr == 0 && search_attr == 0) | |
3860 { | |
3861 n_attr = n_extra + 1; | |
3862 extra_attr = hl_attr(HLF_8); | |
3863 saved_attr2 = char_attr; /* save current attr */ | |
3864 } | |
3865 } | |
3866 else if (mb_l == 0) /* at the NUL at end-of-line */ | |
3867 mb_l = 1; | |
3868 #ifdef FEAT_ARABIC | |
3869 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) | |
3870 { | |
3871 /* Do Arabic shaping. */ | |
714 | 3872 int pc, pc1, nc; |
3873 int pcc[MAX_MCO]; | |
7 | 3874 |
3875 /* The idea of what is the previous and next | |
3876 * character depends on 'rightleft'. */ | |
3877 if (wp->w_p_rl) | |
3878 { | |
3879 pc = prev_c; | |
3880 pc1 = prev_c1; | |
3881 nc = utf_ptr2char(ptr + mb_l); | |
714 | 3882 prev_c1 = u8cc[0]; |
7 | 3883 } |
3884 else | |
3885 { | |
714 | 3886 pc = utfc_ptr2char(ptr + mb_l, pcc); |
7 | 3887 nc = prev_c; |
714 | 3888 pc1 = pcc[0]; |
7 | 3889 } |
3890 prev_c = mb_c; | |
3891 | |
714 | 3892 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
7 | 3893 } |
3894 else | |
3895 prev_c = mb_c; | |
3896 #endif | |
3897 } | |
3898 else /* enc_dbcs */ | |
3899 { | |
3900 mb_l = MB_BYTE2LEN(c); | |
3901 if (mb_l == 0) /* at the NUL at end-of-line */ | |
3902 mb_l = 1; | |
3903 else if (mb_l > 1) | |
3904 { | |
3905 /* We assume a second byte below 32 is illegal. | |
3906 * Hopefully this is OK for all double-byte encodings! | |
3907 */ | |
3908 if (ptr[1] >= 32) | |
3909 mb_c = (c << 8) + ptr[1]; | |
3910 else | |
3911 { | |
3912 if (ptr[1] == NUL) | |
3913 { | |
3914 /* head byte at end of line */ | |
3915 mb_l = 1; | |
3916 transchar_nonprint(extra, c); | |
3917 } | |
3918 else | |
3919 { | |
3920 /* illegal tail byte */ | |
3921 mb_l = 2; | |
3922 STRCPY(extra, "XX"); | |
3923 } | |
3924 p_extra = extra; | |
3925 n_extra = (int)STRLEN(extra) - 1; | |
3926 c_extra = NUL; | |
3927 c = *p_extra++; | |
3928 if (area_attr == 0 && search_attr == 0) | |
3929 { | |
3930 n_attr = n_extra + 1; | |
3931 extra_attr = hl_attr(HLF_8); | |
3932 saved_attr2 = char_attr; /* save current attr */ | |
3933 } | |
3934 mb_c = c; | |
3935 } | |
3936 } | |
3937 } | |
3938 /* If a double-width char doesn't fit display a '>' in the | |
3939 * last column; the character is displayed at the start of the | |
3940 * next line. */ | |
3941 if (( | |
3942 # ifdef FEAT_RIGHTLEFT | |
3943 wp->w_p_rl ? (col <= 0) : | |
3944 # endif | |
3945 (col >= W_WIDTH(wp) - 1)) | |
3946 && (*mb_char2cells)(mb_c) == 2) | |
3947 { | |
3948 c = '>'; | |
3949 mb_c = c; | |
3950 mb_utf8 = FALSE; | |
3951 mb_l = 1; | |
3952 multi_attr = hl_attr(HLF_AT); | |
3953 /* Put pointer back so that the character will be | |
3954 * displayed at the start of the next line. */ | |
3955 --ptr; | |
3956 } | |
3957 else if (*ptr != NUL) | |
3958 ptr += mb_l - 1; | |
3959 | |
3960 /* If a double-width char doesn't fit at the left side display | |
3961 * a '<' in the first column. */ | |
3962 if (n_skip > 0 && mb_l > 1) | |
3963 { | |
3964 n_extra = 1; | |
1340 | 3965 c_extra = '<'; |
7 | 3966 c = ' '; |
3967 if (area_attr == 0 && search_attr == 0) | |
3968 { | |
3969 n_attr = n_extra + 1; | |
3970 extra_attr = hl_attr(HLF_AT); | |
3971 saved_attr2 = char_attr; /* save current attr */ | |
3972 } | |
3973 mb_c = c; | |
3974 mb_utf8 = FALSE; | |
3975 mb_l = 1; | |
3976 } | |
3977 | |
3978 } | |
3979 #endif | |
3980 ++ptr; | |
3981 | |
12 | 3982 /* 'list' : change char 160 to lcs_nbsp. */ |
819 | 3983 if (wp->w_p_list && (c == 160 |
3984 #ifdef FEAT_MBYTE | |
3985 || (mb_utf8 && mb_c == 160) | |
3986 #endif | |
3987 ) && lcs_nbsp) | |
12 | 3988 { |
3989 c = lcs_nbsp; | |
3990 if (area_attr == 0 && search_attr == 0) | |
3991 { | |
3992 n_attr = 1; | |
3993 extra_attr = hl_attr(HLF_8); | |
3994 saved_attr2 = char_attr; /* save current attr */ | |
3995 } | |
3996 #ifdef FEAT_MBYTE | |
3997 mb_c = c; | |
3998 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
3999 { | |
4000 mb_utf8 = TRUE; | |
714 | 4001 u8cc[0] = 0; |
819 | 4002 c = 0xc0; |
12 | 4003 } |
4004 else | |
4005 mb_utf8 = FALSE; | |
4006 #endif | |
4007 } | |
4008 | |
7 | 4009 if (extra_check) |
4010 { | |
743 | 4011 #ifdef FEAT_SPELL |
221 | 4012 int can_spell = TRUE; |
743 | 4013 #endif |
4014 | |
4015 #ifdef FEAT_SYN_HL | |
7 | 4016 /* Get syntax attribute, unless still at the start of the line |
4017 * (double-wide char that doesn't fit). */ | |
221 | 4018 v = (long)(ptr - line); |
4019 if (has_syntax && v > 0) | |
7 | 4020 { |
4021 /* Get the syntax attribute for the character. If there | |
4022 * is an error, disable syntax highlighting. */ | |
4023 save_did_emsg = did_emsg; | |
4024 did_emsg = FALSE; | |
4025 | |
221 | 4026 syntax_attr = get_syntax_attr((colnr_T)v - 1, |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4027 # ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4028 &syntax_flags, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4029 # else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4030 NULL, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4031 # endif |
743 | 4032 # ifdef FEAT_SPELL |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4033 has_spell ? &can_spell : |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4034 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4035 NULL, FALSE); |
7 | 4036 |
4037 if (did_emsg) | |
482 | 4038 { |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4039 wp->w_s->b_syn_error = TRUE; |
482 | 4040 has_syntax = FALSE; |
4041 } | |
7 | 4042 else |
4043 did_emsg = save_did_emsg; | |
4044 | |
4045 /* Need to get the line again, a multi-line regexp may | |
4046 * have made it invalid. */ | |
4047 line = ml_get_buf(wp->w_buffer, lnum, FALSE); | |
4048 ptr = line + v; | |
4049 | |
674 | 4050 if (!attr_pri) |
7 | 4051 char_attr = syntax_attr; |
301 | 4052 else |
303 | 4053 char_attr = hl_combine_attr(syntax_attr, char_attr); |
7 | 4054 } |
743 | 4055 #endif |
4056 | |
4057 #ifdef FEAT_SPELL | |
301 | 4058 /* Check spelling (unless at the end of the line). |
319 | 4059 * Only do this when there is no syntax highlighting, the |
4060 * @Spell cluster is not used or the current syntax item | |
4061 * contains the @Spell cluster. */ | |
348 | 4062 if (has_spell && v >= word_end && v > cur_checked_col) |
221 | 4063 { |
230 | 4064 spell_attr = 0; |
743 | 4065 # ifdef FEAT_SYN_HL |
674 | 4066 if (!attr_pri) |
230 | 4067 char_attr = syntax_attr; |
743 | 4068 # endif |
4069 if (c != 0 && ( | |
4070 # ifdef FEAT_SYN_HL | |
4071 !has_syntax || | |
4072 # endif | |
4073 can_spell)) | |
221 | 4074 { |
348 | 4075 char_u *prev_ptr, *p; |
4076 int len; | |
534 | 4077 hlf_T spell_hlf = HLF_COUNT; |
221 | 4078 # ifdef FEAT_MBYTE |
336 | 4079 if (has_mbyte) |
4080 { | |
4081 prev_ptr = ptr - mb_l; | |
4082 v -= mb_l - 1; | |
4083 } | |
4084 else | |
221 | 4085 # endif |
336 | 4086 prev_ptr = ptr - 1; |
348 | 4087 |
4088 /* Use nextline[] if possible, it has the start of the | |
4089 * next line concatenated. */ | |
4090 if ((prev_ptr - line) - nextlinecol >= 0) | |
4091 p = nextline + (prev_ptr - line) - nextlinecol; | |
4092 else | |
4093 p = prev_ptr; | |
835 | 4094 cap_col -= (int)(prev_ptr - line); |
625 | 4095 len = spell_check(wp, p, &spell_hlf, &cap_col, |
4096 nochange); | |
348 | 4097 word_end = v + len; |
301 | 4098 |
4099 /* In Insert mode only highlight a word that | |
4100 * doesn't touch the cursor. */ | |
534 | 4101 if (spell_hlf != HLF_COUNT |
301 | 4102 && (State & INSERT) != 0 |
4103 && wp->w_cursor.lnum == lnum | |
4104 && wp->w_cursor.col >= | |
4105 (colnr_T)(prev_ptr - line) | |
4106 && wp->w_cursor.col < (colnr_T)word_end) | |
221 | 4107 { |
534 | 4108 spell_hlf = HLF_COUNT; |
301 | 4109 spell_redraw_lnum = lnum; |
221 | 4110 } |
348 | 4111 |
534 | 4112 if (spell_hlf == HLF_COUNT && p != prev_ptr |
348 | 4113 && (p - nextline) + len > nextline_idx) |
4114 { | |
4115 /* Remember that the good word continues at the | |
4116 * start of the next line. */ | |
4117 checked_lnum = lnum + 1; | |
835 | 4118 checked_col = (int)((p - nextline) + len - nextline_idx); |
348 | 4119 } |
386 | 4120 |
534 | 4121 /* Turn index into actual attributes. */ |
4122 if (spell_hlf != HLF_COUNT) | |
4123 spell_attr = highlight_attr[spell_hlf]; | |
4124 | |
386 | 4125 if (cap_col > 0) |
4126 { | |
4127 if (p != prev_ptr | |
4128 && (p - nextline) + cap_col >= nextline_idx) | |
4129 { | |
4130 /* Remember that the word in the next line | |
4131 * must start with a capital. */ | |
4132 capcol_lnum = lnum + 1; | |
835 | 4133 cap_col = (int)((p - nextline) + cap_col |
4134 - nextline_idx); | |
386 | 4135 } |
4136 else | |
4137 /* Compute the actual column. */ | |
835 | 4138 cap_col += (int)(prev_ptr - line); |
386 | 4139 } |
221 | 4140 } |
4141 } | |
4142 if (spell_attr != 0) | |
348 | 4143 { |
674 | 4144 if (!attr_pri) |
348 | 4145 char_attr = hl_combine_attr(char_attr, spell_attr); |
4146 else | |
4147 char_attr = hl_combine_attr(spell_attr, char_attr); | |
4148 } | |
7 | 4149 #endif |
4150 #ifdef FEAT_LINEBREAK | |
4151 /* | |
221 | 4152 * Found last space before word: check for line break. |
7 | 4153 */ |
4154 if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr) | |
819 | 4155 && !wp->w_p_list) |
7 | 4156 { |
4157 n_extra = win_lbr_chartabsize(wp, ptr - ( | |
4158 # ifdef FEAT_MBYTE | |
4159 has_mbyte ? mb_l : | |
4160 # endif | |
4161 1), (colnr_T)vcol, NULL) - 1; | |
4162 c_extra = ' '; | |
4163 if (vim_iswhite(c)) | |
4164 c = ' '; | |
4165 } | |
4166 #endif | |
4167 | |
4168 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') | |
4169 { | |
4170 c = lcs_trail; | |
674 | 4171 if (!attr_pri) |
7 | 4172 { |
4173 n_attr = 1; | |
4174 extra_attr = hl_attr(HLF_8); | |
4175 saved_attr2 = char_attr; /* save current attr */ | |
4176 } | |
4177 #ifdef FEAT_MBYTE | |
4178 mb_c = c; | |
4179 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4180 { | |
4181 mb_utf8 = TRUE; | |
714 | 4182 u8cc[0] = 0; |
819 | 4183 c = 0xc0; |
7 | 4184 } |
4185 else | |
4186 mb_utf8 = FALSE; | |
4187 #endif | |
4188 } | |
4189 } | |
4190 | |
4191 /* | |
4192 * Handling of non-printable characters. | |
4193 */ | |
819 | 4194 if (!(chartab[c & 0xff] & CT_PRINT_CHAR)) |
7 | 4195 { |
4196 /* | |
4197 * when getting a character from the file, we may have to | |
4198 * turn it into something else on the way to putting it | |
4199 * into "ScreenLines". | |
4200 */ | |
4201 if (c == TAB && (!wp->w_p_list || lcs_tab1)) | |
4202 { | |
4203 /* tab amount depends on current column */ | |
4204 n_extra = (int)wp->w_buffer->b_p_ts | |
4205 - vcol % (int)wp->w_buffer->b_p_ts - 1; | |
4206 #ifdef FEAT_MBYTE | |
4207 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4208 #endif | |
4209 if (wp->w_p_list) | |
4210 { | |
4211 c = lcs_tab1; | |
4212 c_extra = lcs_tab2; | |
4213 n_attr = n_extra + 1; | |
4214 extra_attr = hl_attr(HLF_8); | |
4215 saved_attr2 = char_attr; /* save current attr */ | |
4216 #ifdef FEAT_MBYTE | |
4217 mb_c = c; | |
4218 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4219 { | |
4220 mb_utf8 = TRUE; | |
714 | 4221 u8cc[0] = 0; |
819 | 4222 c = 0xc0; |
7 | 4223 } |
4224 #endif | |
4225 } | |
4226 else | |
4227 { | |
4228 c_extra = ' '; | |
4229 c = ' '; | |
4230 } | |
4231 } | |
36 | 4232 else if (c == NUL |
4233 && ((wp->w_p_list && lcs_eol > 0) | |
4234 || ((fromcol >= 0 || fromcol_prev >= 0) | |
4235 && tocol > vcol | |
39 | 4236 #ifdef FEAT_VISUAL |
36 | 4237 && VIsual_mode != Ctrl_V |
39 | 4238 #endif |
36 | 4239 && ( |
4240 # ifdef FEAT_RIGHTLEFT | |
4241 wp->w_p_rl ? (col >= 0) : | |
4242 # endif | |
4243 (col < W_WIDTH(wp))) | |
4244 && !(noinvcur | |
1850 | 4245 && lnum == wp->w_cursor.lnum |
36 | 4246 && (colnr_T)vcol == wp->w_virtcol))) |
4247 && lcs_eol_one >= 0) | |
7 | 4248 { |
36 | 4249 /* Display a '$' after the line or highlight an extra |
4250 * character if the line break is included. */ | |
7 | 4251 #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
4252 /* For a diff line the highlighting continues after the | |
4253 * "$". */ | |
4254 if ( | |
4255 # ifdef FEAT_DIFF | |
534 | 4256 diff_hlf == (hlf_T)0 |
7 | 4257 # ifdef LINE_ATTR |
4258 && | |
4259 # endif | |
4260 # endif | |
4261 # ifdef LINE_ATTR | |
4262 line_attr == 0 | |
4263 # endif | |
4264 ) | |
4265 #endif | |
4266 { | |
4267 #ifdef FEAT_VIRTUALEDIT | |
4268 /* In virtualedit, visual selections may extend | |
4269 * beyond end of line. */ | |
4270 if (area_highlighting && virtual_active() | |
4271 && tocol != MAXCOL && vcol < tocol) | |
4272 n_extra = 0; | |
4273 else | |
4274 #endif | |
4275 { | |
4276 p_extra = at_end_str; | |
4277 n_extra = 1; | |
4278 c_extra = NUL; | |
4279 } | |
4280 } | |
36 | 4281 if (wp->w_p_list) |
4282 c = lcs_eol; | |
4283 else | |
4284 c = ' '; | |
7 | 4285 lcs_eol_one = -1; |
4286 --ptr; /* put it back at the NUL */ | |
674 | 4287 if (!attr_pri) |
7 | 4288 { |
4289 extra_attr = hl_attr(HLF_AT); | |
4290 n_attr = 1; | |
4291 } | |
4292 #ifdef FEAT_MBYTE | |
4293 mb_c = c; | |
4294 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4295 { | |
4296 mb_utf8 = TRUE; | |
714 | 4297 u8cc[0] = 0; |
819 | 4298 c = 0xc0; |
7 | 4299 } |
4300 else | |
4301 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4302 #endif | |
4303 } | |
4304 else if (c != NUL) | |
4305 { | |
4306 p_extra = transchar(c); | |
4307 #ifdef FEAT_RIGHTLEFT | |
4308 if ((dy_flags & DY_UHEX) && wp->w_p_rl) | |
4309 rl_mirror(p_extra); /* reverse "<12>" */ | |
4310 #endif | |
4311 n_extra = byte2cells(c) - 1; | |
4312 c_extra = NUL; | |
4313 c = *p_extra++; | |
674 | 4314 if (!attr_pri) |
7 | 4315 { |
4316 n_attr = n_extra + 1; | |
4317 extra_attr = hl_attr(HLF_8); | |
4318 saved_attr2 = char_attr; /* save current attr */ | |
4319 } | |
4320 #ifdef FEAT_MBYTE | |
4321 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4322 #endif | |
4323 } | |
4324 #ifdef FEAT_VIRTUALEDIT | |
4325 else if (VIsual_active | |
4326 && (VIsual_mode == Ctrl_V | |
4327 || VIsual_mode == 'v') | |
4328 && virtual_active() | |
4329 && tocol != MAXCOL | |
4330 && vcol < tocol | |
4331 && ( | |
4332 # ifdef FEAT_RIGHTLEFT | |
4333 wp->w_p_rl ? (col >= 0) : | |
4334 # endif | |
4335 (col < W_WIDTH(wp)))) | |
4336 { | |
4337 c = ' '; | |
4338 --ptr; /* put it back at the NUL */ | |
4339 } | |
4340 #endif | |
910 | 4341 #if defined(LINE_ATTR) |
7 | 4342 else if (( |
4343 # ifdef FEAT_DIFF | |
910 | 4344 diff_hlf != (hlf_T)0 || |
7 | 4345 # endif |
4346 line_attr != 0 | |
4347 ) && ( | |
4348 # ifdef FEAT_RIGHTLEFT | |
4349 wp->w_p_rl ? (col >= 0) : | |
4350 # endif | |
4351 (col < W_WIDTH(wp)))) | |
4352 { | |
4353 /* Highlight until the right side of the window */ | |
4354 c = ' '; | |
4355 --ptr; /* put it back at the NUL */ | |
867 | 4356 |
4357 /* Remember we do the char for line highlighting. */ | |
4358 ++did_line_attr; | |
4359 | |
4360 /* don't do search HL for the rest of the line */ | |
4361 if (line_attr != 0 && char_attr == search_attr && col > 0) | |
4362 char_attr = line_attr; | |
7 | 4363 # ifdef FEAT_DIFF |
4364 if (diff_hlf == HLF_TXD) | |
4365 { | |
4366 diff_hlf = HLF_CHD; | |
4367 if (attr == 0 || char_attr != attr) | |
4368 char_attr = hl_attr(diff_hlf); | |
4369 } | |
4370 # endif | |
4371 } | |
4372 #endif | |
4373 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4374 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4375 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4376 if ( wp->w_p_conceal |
2285
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4377 && !area_highlighting |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4378 && (lnum != wp->w_cursor.lnum |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4379 || curwin != wp || wp->w_buffer->b_p_ma == FALSE) |
69064995302a
Change SKIP_GTK to SKIP_GTK2 in configure.
Bram Moolenaar <bram@vim.org>
parents:
2284
diff
changeset
|
4380 && (syntax_flags & HL_CONCEAL) != 0) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4381 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4382 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4383 char_attr = conceal_attr; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4384 if (first_conceal |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4385 && (syn_get_sub_char() != NUL || wp->w_p_conceal == 1)) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4386 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4387 if (syn_get_sub_char() != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4388 c = syn_get_sub_char(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4389 else if (lcs_conceal != NUL) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4390 c = lcs_conceal; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4391 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4392 c = ' '; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4393 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4394 first_conceal = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4395 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4396 # ifdef FEAT_HLCOLUMN |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4397 if (hlc > 0 && n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4398 hlc += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4399 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4400 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4401 if (wp->w_p_wrap && n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4402 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4403 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4404 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4405 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4406 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4407 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4408 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4409 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4410 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4411 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4412 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4413 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4414 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4415 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4416 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4417 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4418 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4419 else if (n_skip == 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4420 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4421 is_concealing = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4422 n_skip = 1; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4423 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4424 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4425 mb_c = c; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4426 if (enc_utf8 && (*mb_char2len)(c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4427 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4428 mb_utf8 = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4429 u8cc[0] = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4430 c = 0xc0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4431 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4432 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4433 mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4434 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4435 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4436 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4437 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4438 first_conceal = (wp->w_p_conceal != 3); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4439 is_concealing = FALSE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4440 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4441 #endif /* FEAT_CONCEAL */ |
7 | 4442 } |
4443 | |
4444 /* Don't override visual selection highlighting. */ | |
4445 if (n_attr > 0 | |
4446 && draw_state == WL_LINE | |
674 | 4447 && !attr_pri) |
7 | 4448 char_attr = extra_attr; |
4449 | |
42 | 4450 #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
7 | 4451 /* XIM don't send preedit_start and preedit_end, but they send |
4452 * preedit_changed and commit. Thus Vim can't set "im_is_active", use | |
4453 * im_is_preediting() here. */ | |
4454 if (xic != NULL | |
1850 | 4455 && lnum == wp->w_cursor.lnum |
7 | 4456 && (State & INSERT) |
4457 && !p_imdisable | |
4458 && im_is_preediting() | |
4459 && draw_state == WL_LINE) | |
4460 { | |
4461 colnr_T tcol; | |
4462 | |
4463 if (preedit_end_col == MAXCOL) | |
1850 | 4464 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
7 | 4465 else |
4466 tcol = preedit_end_col; | |
4467 if ((long)preedit_start_col <= vcol && vcol < (long)tcol) | |
4468 { | |
4469 if (feedback_old_attr < 0) | |
4470 { | |
4471 feedback_col = 0; | |
4472 feedback_old_attr = char_attr; | |
4473 } | |
4474 char_attr = im_get_feedback_attr(feedback_col); | |
4475 if (char_attr < 0) | |
4476 char_attr = feedback_old_attr; | |
4477 feedback_col++; | |
4478 } | |
4479 else if (feedback_old_attr >= 0) | |
4480 { | |
4481 char_attr = feedback_old_attr; | |
4482 feedback_old_attr = -1; | |
4483 feedback_col = 0; | |
4484 } | |
4485 } | |
4486 #endif | |
4487 /* | |
4488 * Handle the case where we are in column 0 but not on the first | |
4489 * character of the line and the user wants us to show us a | |
4490 * special character (via 'listchars' option "precedes:<char>". | |
4491 */ | |
4492 if (lcs_prec_todo != NUL | |
4493 && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) | |
4494 #ifdef FEAT_DIFF | |
4495 && filler_todo <= 0 | |
4496 #endif | |
4497 && draw_state > WL_NR | |
4498 && c != NUL) | |
4499 { | |
4500 c = lcs_prec; | |
4501 lcs_prec_todo = NUL; | |
4502 #ifdef FEAT_MBYTE | |
4503 mb_c = c; | |
4504 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4505 { | |
4506 mb_utf8 = TRUE; | |
714 | 4507 u8cc[0] = 0; |
819 | 4508 c = 0xc0; |
7 | 4509 } |
4510 else | |
4511 mb_utf8 = FALSE; /* don't draw as UTF-8 */ | |
4512 #endif | |
674 | 4513 if (!attr_pri) |
7 | 4514 { |
4515 saved_attr3 = char_attr; /* save current attr */ | |
4516 char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ | |
4517 n_attr3 = 1; | |
4518 } | |
4519 } | |
4520 | |
4521 /* | |
867 | 4522 * At end of the text line or just after the last character. |
7 | 4523 */ |
867 | 4524 if (c == NUL |
910 | 4525 #if defined(LINE_ATTR) |
867 | 4526 || did_line_attr == 1 |
4527 #endif | |
4528 ) | |
4529 { | |
4530 #ifdef FEAT_SEARCH_EXTRA | |
4531 long prevcol = (long)(ptr - line) - (c == NUL); | |
1437 | 4532 |
4533 /* we're not really at that column when skipping some text */ | |
1439 | 4534 if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
1437 | 4535 ++prevcol; |
867 | 4536 #endif |
4537 | |
7 | 4538 /* invert at least one char, used for Visual and empty line or |
4539 * highlight match at end of line. If it's beyond the last | |
4540 * char on the screen, just overwrite that one (tricky!) Not | |
4541 * needed when a '$' was displayed for 'list'. */ | |
1326 | 4542 #ifdef FEAT_SEARCH_EXTRA |
4543 prevcol_hl_flag = FALSE; | |
4544 if (prevcol == (long)search_hl.startcol) | |
4545 prevcol_hl_flag = TRUE; | |
4546 else | |
4547 { | |
4548 cur = wp->w_match_head; | |
4549 while (cur != NULL) | |
4550 { | |
4551 if (prevcol == (long)cur->hl.startcol) | |
4552 { | |
4553 prevcol_hl_flag = TRUE; | |
4554 break; | |
4555 } | |
4556 cur = cur->next; | |
4557 } | |
4558 } | |
4559 #endif | |
7 | 4560 if (lcs_eol == lcs_eol_one |
1850 | 4561 && ((area_attr != 0 && vcol == fromcol |
4562 #ifdef FEAT_VISUAL | |
4563 && (VIsual_mode != Ctrl_V | |
4564 || lnum == VIsual.lnum | |
4565 || lnum == curwin->w_cursor.lnum) | |
4566 #endif | |
4567 && c == NUL) | |
7 | 4568 #ifdef FEAT_SEARCH_EXTRA |
4569 /* highlight 'hlsearch' match at end of line */ | |
1326 | 4570 || (prevcol_hl_flag == TRUE |
910 | 4571 # if defined(LINE_ATTR) |
867 | 4572 && did_line_attr <= 1 |
4573 # endif | |
4574 ) | |
7 | 4575 #endif |
4576 )) | |
4577 { | |
4578 int n = 0; | |
4579 | |
4580 #ifdef FEAT_RIGHTLEFT | |
4581 if (wp->w_p_rl) | |
4582 { | |
4583 if (col < 0) | |
4584 n = 1; | |
4585 } | |
4586 else | |
4587 #endif | |
4588 { | |
4589 if (col >= W_WIDTH(wp)) | |
4590 n = -1; | |
4591 } | |
4592 if (n != 0) | |
4593 { | |
4594 /* At the window boundary, highlight the last character | |
4595 * instead (better than nothing). */ | |
4596 off += n; | |
4597 col += n; | |
4598 } | |
4599 else | |
4600 { | |
4601 /* Add a blank character to highlight. */ | |
4602 ScreenLines[off] = ' '; | |
4603 #ifdef FEAT_MBYTE | |
4604 if (enc_utf8) | |
4605 ScreenLinesUC[off] = 0; | |
4606 #endif | |
4607 } | |
4608 #ifdef FEAT_SEARCH_EXTRA | |
4609 if (area_attr == 0) | |
4610 { | |
1326 | 4611 /* Use attributes from match with highest priority among |
4612 * 'search_hl' and the match list. */ | |
4613 char_attr = search_hl.attr; | |
4614 cur = wp->w_match_head; | |
4615 shl_flag = FALSE; | |
4616 while (cur != NULL || shl_flag == FALSE) | |
699 | 4617 { |
1326 | 4618 if (shl_flag == FALSE |
4619 && ((cur != NULL | |
4620 && cur->priority > SEARCH_HL_PRIORITY) | |
4621 || cur == NULL)) | |
699 | 4622 { |
1326 | 4623 shl = &search_hl; |
4624 shl_flag = TRUE; | |
699 | 4625 } |
1326 | 4626 else |
4627 shl = &cur->hl; | |
4628 if ((ptr - line) - 1 == (long)shl->startcol) | |
4629 char_attr = shl->attr; | |
4630 if (shl != &search_hl && cur != NULL) | |
4631 cur = cur->next; | |
699 | 4632 } |
7 | 4633 } |
4634 #endif | |
4635 ScreenAttrs[off] = char_attr; | |
4636 #ifdef FEAT_RIGHTLEFT | |
4637 if (wp->w_p_rl) | |
1437 | 4638 { |
7 | 4639 --col; |
1437 | 4640 --off; |
4641 } | |
7 | 4642 else |
4643 #endif | |
1437 | 4644 { |
7 | 4645 ++col; |
1437 | 4646 ++off; |
4647 } | |
743 | 4648 ++vcol; |
1437 | 4649 #ifdef FEAT_SYN_HL |
4650 eol_hl_off = 1; | |
4651 #endif | |
743 | 4652 } |
867 | 4653 } |
4654 | |
4655 /* | |
4656 * At end of the text line. | |
4657 */ | |
4658 if (c == NUL) | |
4659 { | |
743 | 4660 #ifdef FEAT_SYN_HL |
1850 | 4661 if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
4662 && lnum == wp->w_cursor.lnum) | |
1437 | 4663 { |
4664 /* highlight last char after line */ | |
4665 --col; | |
4666 --off; | |
4667 --vcol; | |
4668 } | |
4669 | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4670 /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
758 | 4671 if (wp->w_p_wrap) |
4672 v = wp->w_skipcol; | |
4673 else | |
4674 v = wp->w_leftcol; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4675 |
820 | 4676 /* check if line ends before left margin */ |
4677 if (vcol < v + col - win_col_off(wp)) | |
4678 vcol = v + col - win_col_off(wp); | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4679 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4680 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4681 draw_color_col = advance_color_col(vcol, &color_cols); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4682 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4683 if (((wp->w_p_cuc |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4684 && (int)wp->w_virtcol >= vcol - eol_hl_off |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4685 && (int)wp->w_virtcol < W_WIDTH(wp) * (row - startrow + 1) |
819 | 4686 + v |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4687 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4688 || draw_color_col) |
743 | 4689 # ifdef FEAT_RIGHTLEFT |
4690 && !wp->w_p_rl | |
4691 # endif | |
4692 ) | |
4693 { | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4694 int rightmost_vcol = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4695 int i; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4696 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4697 if (wp->w_p_cuc) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4698 rightmost_vcol = wp->w_virtcol; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4699 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4700 /* determine rightmost colorcolumn to possibly draw */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4701 for (i = 0; color_cols[i] >= 0; ++i) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4702 if (rightmost_vcol < color_cols[i]) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4703 rightmost_vcol = color_cols[i]; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4704 |
743 | 4705 while (col < W_WIDTH(wp)) |
4706 { | |
4707 ScreenLines[off] = ' '; | |
4708 #ifdef FEAT_MBYTE | |
4709 if (enc_utf8) | |
4710 ScreenLinesUC[off] = 0; | |
4711 #endif | |
4712 ++col; | |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4713 if (wp->w_p_cuc && vcol == (long)wp->w_virtcol) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4714 ScreenAttrs[off++] = hl_attr(HLF_CUC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4715 else if (draw_color_col && vcol == *color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4716 ScreenAttrs[off++] = hl_attr(HLF_MC); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4717 else |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4718 ScreenAttrs[off++] = 0; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4719 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4720 if (vcol >= rightmost_vcol) |
743 | 4721 break; |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4722 |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4723 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4724 draw_color_col = advance_color_col(vcol, &color_cols); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4725 |
743 | 4726 ++vcol; |
4727 } | |
4728 } | |
4729 #endif | |
7 | 4730 |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4731 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4732 SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4733 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4734 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4735 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4736 SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4737 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4738 #endif |
7 | 4739 row++; |
4740 | |
4741 /* | |
4742 * Update w_cline_height and w_cline_folded if the cursor line was | |
4743 * updated (saves a call to plines() later). | |
4744 */ | |
4745 if (wp == curwin && lnum == curwin->w_cursor.lnum) | |
4746 { | |
4747 curwin->w_cline_row = startrow; | |
4748 curwin->w_cline_height = row - startrow; | |
4749 #ifdef FEAT_FOLDING | |
4750 curwin->w_cline_folded = FALSE; | |
4751 #endif | |
4752 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); | |
4753 } | |
4754 | |
4755 break; | |
4756 } | |
4757 | |
4758 /* line continues beyond line end */ | |
4759 if (lcs_ext | |
4760 && !wp->w_p_wrap | |
4761 #ifdef FEAT_DIFF | |
4762 && filler_todo <= 0 | |
4763 #endif | |
4764 && ( | |
4765 #ifdef FEAT_RIGHTLEFT | |
4766 wp->w_p_rl ? col == 0 : | |
4767 #endif | |
4768 col == W_WIDTH(wp) - 1) | |
4769 && (*ptr != NUL | |
1555 | 4770 || (wp->w_p_list && lcs_eol_one > 0) |
7 | 4771 || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
4772 { | |
4773 c = lcs_ext; | |
4774 char_attr = hl_attr(HLF_AT); | |
4775 #ifdef FEAT_MBYTE | |
4776 mb_c = c; | |
4777 if (enc_utf8 && (*mb_char2len)(c) > 1) | |
4778 { | |
4779 mb_utf8 = TRUE; | |
714 | 4780 u8cc[0] = 0; |
819 | 4781 c = 0xc0; |
7 | 4782 } |
4783 else | |
4784 mb_utf8 = FALSE; | |
4785 #endif | |
4786 } | |
4787 | |
743 | 4788 #ifdef FEAT_SYN_HL |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4789 /* advance to the next 'colorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4790 if (draw_color_col) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4791 draw_color_col = advance_color_col(vcol, &color_cols); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4792 |
743 | 4793 /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
2314
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4794 * highlight the cursor position itself. |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4795 * Also highlight the 'colorcolumn' if it is different than |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4796 * 'cursorcolumn' */ |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4797 vcol_save_attr = -1; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4798 if (draw_state == WL_LINE && !lnum_in_visual_area) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4799 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4800 if (wp->w_p_cuc && vcol == (long)wp->w_virtcol |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4801 && lnum != wp->w_cursor.lnum) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4802 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4803 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4804 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4805 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4806 else if (draw_color_col && vcol == *color_cols) |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4807 { |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4808 vcol_save_attr = char_attr; |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4809 char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4810 } |
233eb4412f5d
Added 'colorcolumn' option. Partly by Gregor Uhlenheuer.
Bram Moolenaar <bram@vim.org>
parents:
2285
diff
changeset
|
4811 } |
743 | 4812 #endif |
4813 | |
7 | 4814 /* |
4815 * Store character to be displayed. | |
4816 * Skip characters that are left of the screen for 'nowrap'. | |
4817 */ | |
4818 vcol_prev = vcol; | |
4819 if (draw_state < WL_LINE || n_skip <= 0) | |
4820 { | |
4821 /* | |
4822 * Store the character. | |
4823 */ | |
4824 #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) | |
4825 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) | |
4826 { | |
4827 /* A double-wide character is: put first halve in left cell. */ | |
4828 --off; | |
4829 --col; | |
4830 } | |
4831 #endif | |
4832 ScreenLines[off] = c; | |
4833 #ifdef FEAT_MBYTE | |
4834 if (enc_dbcs == DBCS_JPNU) | |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4835 { |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4836 if ((mb_c & 0xff00) == 0x8e00) |
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4837 ScreenLines[off] = 0x8e; |
7 | 4838 ScreenLines2[off] = mb_c & 0xff; |
2069
63613d8d7e4d
updated for version 7.2.354
Bram Moolenaar <bram@zimbu.org>
parents:
2055
diff
changeset
|
4839 } |
7 | 4840 else if (enc_utf8) |
4841 { | |
4842 if (mb_utf8) | |
4843 { | |
1326 | 4844 int i; |
4845 | |
7 | 4846 ScreenLinesUC[off] = mb_c; |
819 | 4847 if ((c & 0xff) == 0) |
4848 ScreenLines[off] = 0x80; /* avoid storing zero */ | |
714 | 4849 for (i = 0; i < Screen_mco; ++i) |
4850 { | |
4851 ScreenLinesC[i][off] = u8cc[i]; | |
4852 if (u8cc[i] == 0) | |
4853 break; | |
4854 } | |
7 | 4855 } |
4856 else | |
4857 ScreenLinesUC[off] = 0; | |
4858 } | |
4859 if (multi_attr) | |
4860 { | |
4861 ScreenAttrs[off] = multi_attr; | |
4862 multi_attr = 0; | |
4863 } | |
4864 else | |
4865 #endif | |
4866 ScreenAttrs[off] = char_attr; | |
4867 | |
4868 #ifdef FEAT_MBYTE | |
4869 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) | |
4870 { | |
4871 /* Need to fill two screen columns. */ | |
4872 ++off; | |
4873 ++col; | |
4874 if (enc_utf8) | |
4875 /* UTF-8: Put a 0 in the second screen char. */ | |
4876 ScreenLines[off] = 0; | |
4877 else | |
4878 /* DBCS: Put second byte in the second screen char. */ | |
4879 ScreenLines[off] = mb_c & 0xff; | |
4880 ++vcol; | |
4881 /* When "tocol" is halfway a character, set it to the end of | |
4882 * the character, otherwise highlighting won't stop. */ | |
4883 if (tocol == vcol) | |
4884 ++tocol; | |
4885 #ifdef FEAT_RIGHTLEFT | |
4886 if (wp->w_p_rl) | |
4887 { | |
4888 /* now it's time to backup one cell */ | |
4889 --off; | |
4890 --col; | |
4891 } | |
4892 #endif | |
4893 } | |
4894 #endif | |
4895 #ifdef FEAT_RIGHTLEFT | |
4896 if (wp->w_p_rl) | |
4897 { | |
4898 --off; | |
4899 --col; | |
4900 } | |
4901 else | |
4902 #endif | |
4903 { | |
4904 ++off; | |
4905 ++col; | |
4906 } | |
4907 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4908 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4909 else if (wp->w_p_conceal && is_concealing) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4910 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4911 --n_skip; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4912 # ifdef FEAT_HLCOLUMN |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4913 if (hlc) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4914 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4915 ++hlc; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4916 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4917 hlc += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4918 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4919 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4920 if (wp->w_p_wrap) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4921 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4922 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4923 * Special voodoo required if 'wrap' is on. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4924 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4925 * Advance the column indicator to force the line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4926 * drawing to wrap early. This will make the line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4927 * take up the same screen space when parts are concealed, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4928 * so that cursor line computations aren't messed up. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4929 * |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4930 * To avoid the fictitious advance of 'col' causing |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4931 * trailing junk to be written out of the screen line |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4932 * we are building, 'boguscols' keeps track of the number |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4933 * of bad columns we have advanced. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4934 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4935 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4936 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4937 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4938 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4939 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4940 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4941 col -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4942 boguscols -= n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4943 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4944 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4945 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4946 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4947 col += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4948 boguscols += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4949 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4950 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4951 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4952 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4953 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4954 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4955 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4956 if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4957 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4958 /* Need to fill two screen columns. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4959 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4960 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4961 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4962 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4963 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4964 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4965 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4966 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4967 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4968 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4969 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4970 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4971 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4972 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4973 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4974 # ifdef FEAT_RIGHTLEFT |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4975 if (wp->w_p_rl) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4976 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4977 --boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4978 --col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4979 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4980 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4981 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4982 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4983 ++boguscols; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4984 ++col; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4985 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4986 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4987 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4988 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4989 if (n_extra > 0) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4990 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4991 vcol += n_extra; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4992 n_extra = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4993 n_attr = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4994 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4995 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4996 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4997 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
4998 #endif /* FEAT_CONCEAL */ |
7 | 4999 else |
5000 --n_skip; | |
5001 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5002 /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
5003 * column. */ |
1849 | 5004 if (draw_state > WL_NR |
7 | 5005 #ifdef FEAT_DIFF |
5006 && filler_todo <= 0 | |
5007 #endif | |
5008 ) | |
5009 ++vcol; | |
5010 | |
743 | 5011 #ifdef FEAT_SYN_HL |
5012 if (vcol_save_attr >= 0) | |
5013 char_attr = vcol_save_attr; | |
5014 #endif | |
5015 | |
7 | 5016 /* restore attributes after "predeces" in 'listchars' */ |
5017 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) | |
5018 char_attr = saved_attr3; | |
5019 | |
5020 /* restore attributes after last 'listchars' or 'number' char */ | |
5021 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) | |
5022 char_attr = saved_attr2; | |
5023 | |
5024 /* | |
5025 * At end of screen line and there is more to come: Display the line | |
1378 | 5026 * so far. If there is no more to display it is caught above. |
7 | 5027 */ |
5028 if (( | |
5029 #ifdef FEAT_RIGHTLEFT | |
5030 wp->w_p_rl ? (col < 0) : | |
5031 #endif | |
5032 (col >= W_WIDTH(wp))) | |
5033 && (*ptr != NUL | |
5034 #ifdef FEAT_DIFF | |
5035 || filler_todo > 0 | |
5036 #endif | |
5037 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) | |
5038 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) | |
5039 ) | |
5040 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5041 #ifdef FEAT_CONCEAL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5042 SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5043 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5044 boguscols = 0; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5045 #else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5046 SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5047 (int)W_WIDTH(wp), wp->w_p_rl); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2237
diff
changeset
|
5048 #endif |
7 | 5049 ++row; |
5050 ++screen_row; | |
5051 | |
5052 /* When not wrapping and finished diff lines, or when displayed | |
5053 * '$' and highlighting until last column, break here. */ | |
5054 if ((!wp->w_p_wrap | |
5055 #ifdef FEAT_DIFF | |
5056 && filler_todo <= 0 | |
5057 #endif | |
5058 ) || lcs_eol_one == -1) | |
5059 break; | |
5060 | |
5061 /* When the window is too narrow draw all "@" lines. */ | |
5062 if (draw_state != WL_LINE | |
5063 #ifdef FEAT_DIFF | |
5064 && filler_todo <= 0 | |
5065 #endif | |
5066 ) | |
5067 { | |
5068 win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); | |
5069 #ifdef FEAT_VERTSPLIT | |
5070 draw_vsep_win(wp, row); | |
5071 #endif | |
5072 row = endrow; | |
5073 } | |
5074 | |
5075 /* When line got too long for screen break here. */ | |
5076 if (row == endrow) | |
5077 { | |
5078 ++row; | |
5079 break; | |
5080 } | |
5081 | |
5082 if (screen_cur_row == screen_row - 1 | |
5083 #ifdef FEAT_DIFF | |
5084 && filler_todo <= 0 | |
5085 #endif | |
5086 && W_WIDTH(wp) == Columns) | |
5087 { | |
5088 /* Remember that the line wraps, used for modeless copy. */ | |
5089 LineWraps[screen_row - 1] = TRUE; | |
5090 | |
5091 /* | |
5092 * Special trick to make copy/paste of wrapped lines work with | |
5093 * xterm/screen: write an extra character beyond the end of | |
5094 * the line. This will work with all terminal types | |
5095 * (regardless of the xn,am settings). | |
5096 * Only do this on a fast tty. | |
5097 * Only do this if the cursor is on the current line | |
5098 * (something has been written in it). | |
5099 * Don't do this for the GUI. | |
5100 * Don't do this for double-width characters. | |
5101 * Don't do this for a window not at the right screen border. | |
5102 */ | |
5103 if (p_tf | |
5104 #ifdef FEAT_GUI | |
5105 && !gui.in_use | |
5106 #endif | |
5107 #ifdef FEAT_MBYTE | |
5108 && !(has_mbyte | |
1378 | 5109 && ((*mb_off2cells)(LineOffset[screen_row], |
5110 LineOffset[screen_row] + screen_Columns) | |
5111 == 2 | |
7 | 5112 || (*mb_off2cells)(LineOffset[screen_row - 1] |
1378 | 5113 + (int)Columns - 2, |
5114 LineOffset[screen_row] + screen_Columns) | |
5115 == 2)) | |
7 | 5116 #endif |
5117 ) | |
5118 { | |
5119 /* First make sure we are at the end of the screen line, | |
5120 * then output the same character again to let the | |
5121 * terminal know about the wrap. If the terminal doesn't | |
5122 * auto-wrap, we overwrite the character. */ | |
5123 if (screen_cur_col != W_WIDTH(wp)) | |
5124 screen_char(LineOffset[screen_row - 1] | |
5125 + (unsigned)Columns - 1, | |
5126 screen_row - 1, (int)(Columns - 1)); | |
5127 | |
5128 #ifdef FEAT_MBYTE | |
5129 /* When there is a multi-byte character, just output a | |
5130 * space to keep it simple. */ | |
148 | 5131 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
5132 screen_row - 1] + (Columns - 1)]) > 1) | |
7 | 5133 out_char(' '); |
5134 else | |
5135 #endif | |
5136 out_char(ScreenLines[LineOffset[screen_row - 1] | |
5137 + (Columns - 1)]); | |
5138 /* force a redraw of the first char on the next line */ | |
5139 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; | |
5140 screen_start(); /* don't know where cursor is now */ | |
5141 } | |
5142 } | |
5143 | |
5144 col = 0; | |
5145 off = (unsigned)(current_ScreenLine - ScreenLines); | |
5146 #ifdef FEAT_RIGHTLEFT | |
5147 if (wp->w_p_rl) | |
5148 { | |
5149 col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ | |
5150 off += col; | |
5151 } | |
5152 #endif | |
5153 | |
5154 /* reset the drawing state for the start of a wrapped line */ | |
5155 draw_state = WL_START; | |
5156 saved_n_extra = n_extra; | |
5157 saved_p_extra = p_extra; | |
5158 saved_c_extra = c_extra; | |
5159 saved_char_attr = char_attr; | |
5160 n_extra = 0; | |
5161 lcs_prec_todo = lcs_prec; | |
5162 #ifdef FEAT_LINEBREAK | |
5163 # ifdef FEAT_DIFF | |
5164 if (filler_todo <= 0) | |
5165 # endif | |
5166 need_showbreak = TRUE; | |
5167 #endif | |
5168 #ifdef FEAT_DIFF | |
5169 --filler_todo; | |
5170 /* When the filler lines are actually below the last line of the | |
5171 * file, don't draw the line itself, break here. */ | |
5172 if (filler_todo == 0 && wp->w_botfill) | |
5173 break; | |
5174 #endif | |
5175 } | |
5176 | |
5177 } /* for every character in the line */ | |
5178 | |
743 | 5179 #ifdef FEAT_SPELL |
386 | 5180 /* After an empty line check first word for capital. */ |
5181 if (*skipwhite(line) == NUL) | |
5182 { | |
5183 capcol_lnum = lnum + 1; | |
5184 cap_col = 0; | |
5185 } | |
5186 #endif | |
5187 | |
7 | 5188 return row; |
5189 } | |
5190 | |
714 | 5191 #ifdef FEAT_MBYTE |
5192 static int comp_char_differs __ARGS((int, int)); | |
5193 | |
5194 /* | |
5195 * Return if the composing characters at "off_from" and "off_to" differ. | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
5196 * Only to be used when ScreenLinesUC[off_from] != 0. |
714 | 5197 */ |
5198 static int | |
5199 comp_char_differs(off_from, off_to) | |
5200 int off_from; | |
5201 int off_to; | |
5202 { | |
5203 int i; | |
5204 | |
5205 for (i = 0; i < Screen_mco; ++i) | |
5206 { | |
5207 if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) | |
5208 return TRUE; | |
5209 if (ScreenLinesC[i][off_from] == 0) | |
5210 break; | |
5211 } | |
5212 return FALSE; | |
5213 } | |
5214 #endif | |
5215 | |
7 | 5216 /* |
5217 * Check whether the given character needs redrawing: | |
5218 * - the (first byte of the) character is different | |
5219 * - the attributes are different | |
5220 * - the character is multi-byte and the next byte is different | |
1616 | 5221 * - the character is two cells wide and the second cell differs. |
7 | 5222 */ |
5223 static int | |
5224 char_needs_redraw(off_from, off_to, cols) | |
5225 int off_from; | |
5226 int off_to; | |
5227 int cols; | |
5228 { | |
5229 if (cols > 0 | |
5230 && ((ScreenLines[off_from] != ScreenLines[off_to] | |
5231 || ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5232 | |
5233 #ifdef FEAT_MBYTE | |
5234 || (enc_dbcs != 0 | |
5235 && MB_BYTE2LEN(ScreenLines[off_from]) > 1 | |
5236 && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e | |
5237 ? ScreenLines2[off_from] != ScreenLines2[off_to] | |
5238 : (cols > 1 && ScreenLines[off_from + 1] | |
5239 != ScreenLines[off_to + 1]))) | |
5240 || (enc_utf8 | |
5241 && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] | |
5242 || (ScreenLinesUC[off_from] != 0 | |
1616 | 5243 && comp_char_differs(off_from, off_to)) |
5244 || (cols > 1 && ScreenLines[off_from + 1] | |
5245 != ScreenLines[off_to + 1]))) | |
7 | 5246 #endif |
5247 )) | |
5248 return TRUE; | |
5249 return FALSE; | |
5250 } | |
5251 | |
5252 /* | |
5253 * Move one "cooked" screen line to the screen, but only the characters that | |
5254 * have actually changed. Handle insert/delete character. | |
5255 * "coloff" gives the first column on the screen for this line. | |
5256 * "endcol" gives the columns where valid characters are. | |
5257 * "clear_width" is the width of the window. It's > 0 if the rest of the line | |
5258 * needs to be cleared, negative otherwise. | |
5259 * "rlflag" is TRUE in a rightleft window: | |
5260 * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" | |
5261 * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" | |
5262 */ | |
5263 static void | |
5264 screen_line(row, coloff, endcol, clear_width | |
5265 #ifdef FEAT_RIGHTLEFT | |
5266 , rlflag | |
5267 #endif | |
5268 ) | |
5269 int row; | |
5270 int coloff; | |
5271 int endcol; | |
5272 int clear_width; | |
5273 #ifdef FEAT_RIGHTLEFT | |
5274 int rlflag; | |
5275 #endif | |
5276 { | |
5277 unsigned off_from; | |
5278 unsigned off_to; | |
1378 | 5279 #ifdef FEAT_MBYTE |
5280 unsigned max_off_from; | |
5281 unsigned max_off_to; | |
5282 #endif | |
7 | 5283 int col = 0; |
5284 #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) | |
5285 int hl; | |
5286 #endif | |
5287 int force = FALSE; /* force update rest of the line */ | |
5288 int redraw_this /* bool: does character need redraw? */ | |
5289 #ifdef FEAT_GUI | |
5290 = TRUE /* For GUI when while-loop empty */ | |
5291 #endif | |
5292 ; | |
5293 int redraw_next; /* redraw_this for next character */ | |
5294 #ifdef FEAT_MBYTE | |
5295 int clear_next = FALSE; | |
5296 int char_cells; /* 1: normal char */ | |
5297 /* 2: occupies two display cells */ | |
5298 # define CHAR_CELLS char_cells | |
5299 #else | |
5300 # define CHAR_CELLS 1 | |
5301 #endif | |
5302 | |
5303 # ifdef FEAT_CLIPBOARD | |
5304 clip_may_clear_selection(row, row); | |
5305 # endif | |
5306 | |
5307 off_from = (unsigned)(current_ScreenLine - ScreenLines); | |
5308 off_to = LineOffset[row] + coloff; | |
1378 | 5309 #ifdef FEAT_MBYTE |
5310 max_off_from = off_from + screen_Columns; | |
5311 max_off_to = LineOffset[row] + screen_Columns; | |
5312 #endif | |
7 | 5313 |
5314 #ifdef FEAT_RIGHTLEFT | |
5315 if (rlflag) | |
5316 { | |
5317 /* Clear rest first, because it's left of the text. */ | |
5318 if (clear_width > 0) | |
5319 { | |
5320 while (col <= endcol && ScreenLines[off_to] == ' ' | |
5321 && ScreenAttrs[off_to] == 0 | |
5322 # ifdef FEAT_MBYTE | |
5323 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5324 # endif | |
5325 ) | |
5326 { | |
5327 ++off_to; | |
5328 ++col; | |
5329 } | |
5330 if (col <= endcol) | |
5331 screen_fill(row, row + 1, col + coloff, | |
5332 endcol + coloff + 1, ' ', ' ', 0); | |
5333 } | |
5334 col = endcol + 1; | |
5335 off_to = LineOffset[row] + col + coloff; | |
5336 off_from += col; | |
5337 endcol = (clear_width > 0 ? clear_width : -clear_width); | |
5338 } | |
5339 #endif /* FEAT_RIGHTLEFT */ | |
5340 | |
5341 redraw_next = char_needs_redraw(off_from, off_to, endcol - col); | |
5342 | |
5343 while (col < endcol) | |
5344 { | |
5345 #ifdef FEAT_MBYTE | |
5346 if (has_mbyte && (col + 1 < endcol)) | |
1378 | 5347 char_cells = (*mb_off2cells)(off_from, max_off_from); |
7 | 5348 else |
5349 char_cells = 1; | |
5350 #endif | |
5351 | |
5352 redraw_this = redraw_next; | |
5353 redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, | |
5354 off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); | |
5355 | |
5356 #ifdef FEAT_GUI | |
5357 /* If the next character was bold, then redraw the current character to | |
5358 * remove any pixels that might have spilt over into us. This only | |
5359 * happens in the GUI. | |
5360 */ | |
5361 if (redraw_next && gui.in_use) | |
5362 { | |
5363 hl = ScreenAttrs[off_to + CHAR_CELLS]; | |
743 | 5364 if (hl > HL_ALL) |
5365 hl = syn_attr2attr(hl); | |
5366 if (hl & HL_BOLD) | |
7 | 5367 redraw_this = TRUE; |
5368 } | |
5369 #endif | |
5370 | |
5371 if (redraw_this) | |
5372 { | |
5373 /* | |
5374 * Special handling when 'xs' termcap flag set (hpterm): | |
5375 * Attributes for characters are stored at the position where the | |
5376 * cursor is when writing the highlighting code. The | |
5377 * start-highlighting code must be written with the cursor on the | |
5378 * first highlighted character. The stop-highlighting code must | |
5379 * be written with the cursor just after the last highlighted | |
5380 * character. | |
5381 * Overwriting a character doesn't remove it's highlighting. Need | |
5382 * to clear the rest of the line, and force redrawing it | |
5383 * completely. | |
5384 */ | |
5385 if ( p_wiv | |
5386 && !force | |
5387 #ifdef FEAT_GUI | |
5388 && !gui.in_use | |
5389 #endif | |
5390 && ScreenAttrs[off_to] != 0 | |
5391 && ScreenAttrs[off_from] != ScreenAttrs[off_to]) | |
5392 { | |
5393 /* | |
5394 * Need to remove highlighting attributes here. | |
5395 */ | |
5396 windgoto(row, col + coloff); | |
5397 out_str(T_CE); /* clear rest of this screen line */ | |
5398 screen_start(); /* don't know where cursor is now */ | |
5399 force = TRUE; /* force redraw of rest of the line */ | |
5400 redraw_next = TRUE; /* or else next char would miss out */ | |
5401 | |
5402 /* | |
5403 * If the previous character was highlighted, need to stop | |
5404 * highlighting at this character. | |
5405 */ | |
5406 if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) | |
5407 { | |
5408 screen_attr = ScreenAttrs[off_to - 1]; | |
5409 term_windgoto(row, col + coloff); | |
5410 screen_stop_highlight(); | |
5411 } | |
5412 else | |
5413 screen_attr = 0; /* highlighting has stopped */ | |
5414 } | |
5415 #ifdef FEAT_MBYTE | |
5416 if (enc_dbcs != 0) | |
5417 { | |
5418 /* Check if overwriting a double-byte with a single-byte or | |
5419 * the other way around requires another character to be | |
5420 * redrawn. For UTF-8 this isn't needed, because comparing | |
5421 * ScreenLinesUC[] is sufficient. */ | |
5422 if (char_cells == 1 | |
5423 && col + 1 < endcol | |
1378 | 5424 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5425 { |
5426 /* Writing a single-cell character over a double-cell | |
5427 * character: need to redraw the next cell. */ | |
5428 ScreenLines[off_to + 1] = 0; | |
5429 redraw_next = TRUE; | |
5430 } | |
5431 else if (char_cells == 2 | |
5432 && col + 2 < endcol | |
1378 | 5433 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5434 && (*mb_off2cells)(off_to + 1, max_off_to) > 1) | |
7 | 5435 { |
5436 /* Writing the second half of a double-cell character over | |
5437 * a double-cell character: need to redraw the second | |
5438 * cell. */ | |
5439 ScreenLines[off_to + 2] = 0; | |
5440 redraw_next = TRUE; | |
5441 } | |
5442 | |
5443 if (enc_dbcs == DBCS_JPNU) | |
5444 ScreenLines2[off_to] = ScreenLines2[off_from]; | |
5445 } | |
5446 /* When writing a single-width character over a double-width | |
5447 * character and at the end of the redrawn text, need to clear out | |
5448 * the right halve of the old character. | |
5449 * Also required when writing the right halve of a double-width | |
5450 * char over the left halve of an existing one. */ | |
5451 if (has_mbyte && col + char_cells == endcol | |
5452 && ((char_cells == 1 | |
1378 | 5453 && (*mb_off2cells)(off_to, max_off_to) > 1) |
7 | 5454 || (char_cells == 2 |
1378 | 5455 && (*mb_off2cells)(off_to, max_off_to) == 1 |
5456 && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) | |
7 | 5457 clear_next = TRUE; |
5458 #endif | |
5459 | |
5460 ScreenLines[off_to] = ScreenLines[off_from]; | |
5461 #ifdef FEAT_MBYTE | |
5462 if (enc_utf8) | |
5463 { | |
5464 ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; | |
5465 if (ScreenLinesUC[off_from] != 0) | |
5466 { | |
714 | 5467 int i; |
5468 | |
5469 for (i = 0; i < Screen_mco; ++i) | |
5470 ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; | |
7 | 5471 } |
5472 } | |
5473 if (char_cells == 2) | |
5474 ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; | |
5475 #endif | |
5476 | |
5477 #if defined(FEAT_GUI) || defined(UNIX) | |
1843 | 5478 /* The bold trick makes a single column of pixels appear in the |
5479 * next character. When a bold character is removed, the next | |
7 | 5480 * character should be redrawn too. This happens for our own GUI |
5481 * and for some xterms. */ | |
5482 if ( | |
5483 # ifdef FEAT_GUI | |
5484 gui.in_use | |
5485 # endif | |
5486 # if defined(FEAT_GUI) && defined(UNIX) | |
5487 || | |
5488 # endif | |
5489 # ifdef UNIX | |
5490 term_is_xterm | |
5491 # endif | |
5492 ) | |
5493 { | |
5494 hl = ScreenAttrs[off_to]; | |
743 | 5495 if (hl > HL_ALL) |
5496 hl = syn_attr2attr(hl); | |
5497 if (hl & HL_BOLD) | |
7 | 5498 redraw_next = TRUE; |
5499 } | |
5500 #endif | |
5501 ScreenAttrs[off_to] = ScreenAttrs[off_from]; | |
5502 #ifdef FEAT_MBYTE | |
819 | 5503 /* For simplicity set the attributes of second half of a |
5504 * double-wide character equal to the first half. */ | |
5505 if (char_cells == 2) | |
5506 ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; | |
5507 | |
7 | 5508 if (enc_dbcs != 0 && char_cells == 2) |
5509 screen_char_2(off_to, row, col + coloff); | |
5510 else | |
5511 #endif | |
5512 screen_char(off_to, row, col + coloff); | |
5513 } | |
5514 else if ( p_wiv | |
5515 #ifdef FEAT_GUI | |
5516 && !gui.in_use | |
5517 #endif | |
5518 && col + coloff > 0) | |
5519 { | |
5520 if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) | |
5521 { | |
5522 /* | |
5523 * Don't output stop-highlight when moving the cursor, it will | |
5524 * stop the highlighting when it should continue. | |
5525 */ | |
5526 screen_attr = 0; | |
5527 } | |
5528 else if (screen_attr != 0) | |
5529 screen_stop_highlight(); | |
5530 } | |
5531 | |
5532 off_to += CHAR_CELLS; | |
5533 off_from += CHAR_CELLS; | |
5534 col += CHAR_CELLS; | |
5535 } | |
5536 | |
5537 #ifdef FEAT_MBYTE | |
5538 if (clear_next) | |
5539 { | |
5540 /* Clear the second half of a double-wide character of which the left | |
5541 * half was overwritten with a single-wide character. */ | |
5542 ScreenLines[off_to] = ' '; | |
5543 if (enc_utf8) | |
5544 ScreenLinesUC[off_to] = 0; | |
5545 screen_char(off_to, row, col + coloff); | |
5546 } | |
5547 #endif | |
5548 | |
5549 if (clear_width > 0 | |
5550 #ifdef FEAT_RIGHTLEFT | |
5551 && !rlflag | |
5552 #endif | |
5553 ) | |
5554 { | |
5555 #ifdef FEAT_GUI | |
5556 int startCol = col; | |
5557 #endif | |
5558 | |
5559 /* blank out the rest of the line */ | |
5560 while (col < clear_width && ScreenLines[off_to] == ' ' | |
5561 && ScreenAttrs[off_to] == 0 | |
5562 #ifdef FEAT_MBYTE | |
5563 && (!enc_utf8 || ScreenLinesUC[off_to] == 0) | |
5564 #endif | |
5565 ) | |
5566 { | |
5567 ++off_to; | |
5568 ++col; | |
5569 } | |
5570 if (col < clear_width) | |
5571 { | |
5572 #ifdef FEAT_GUI | |
5573 /* | |
5574 * In the GUI, clearing the rest of the line may leave pixels | |
5575 * behind if the first character cleared was bold. Some bold | |
5576 * fonts spill over the left. In this case we redraw the previous | |
5577 * character too. If we didn't skip any blanks above, then we | |
5578 * only redraw if the character wasn't already redrawn anyway. | |
5579 */ | |
996 | 5580 if (gui.in_use && (col > startCol || !redraw_this)) |
7 | 5581 { |
5582 hl = ScreenAttrs[off_to]; | |
5583 if (hl > HL_ALL || (hl & HL_BOLD)) | |
996 | 5584 { |
5585 int prev_cells = 1; | |
5586 # ifdef FEAT_MBYTE | |
5587 if (enc_utf8) | |
5588 /* for utf-8, ScreenLines[char_offset + 1] == 0 means | |
5589 * that its width is 2. */ | |
5590 prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; | |
5591 else if (enc_dbcs != 0) | |
5592 { | |
5593 /* find previous character by counting from first | |
5594 * column and get its width. */ | |
5595 unsigned off = LineOffset[row]; | |
1378 | 5596 unsigned max_off = LineOffset[row] + screen_Columns; |
996 | 5597 |
5598 while (off < off_to) | |
5599 { | |
1378 | 5600 prev_cells = (*mb_off2cells)(off, max_off); |
996 | 5601 off += prev_cells; |
5602 } | |
5603 } | |
5604 | |
5605 if (enc_dbcs != 0 && prev_cells > 1) | |
5606 screen_char_2(off_to - prev_cells, row, | |
5607 col + coloff - prev_cells); | |
5608 else | |
5609 # endif | |
5610 screen_char(off_to - prev_cells, row, | |
5611 col + coloff - prev_cells); | |
5612 } | |
7 | 5613 } |
5614 #endif | |
5615 screen_fill(row, row + 1, col + coloff, clear_width + coloff, | |
5616 ' ', ' ', 0); | |
5617 #ifdef FEAT_VERTSPLIT | |
5618 off_to += clear_width - col; | |
5619 col = clear_width; | |
5620 #endif | |
5621 } | |
5622 } | |
5623 | |
5624 if (clear_width > 0) | |
5625 { | |
5626 #ifdef FEAT_VERTSPLIT | |
5627 /* For a window that's left of another, draw the separator char. */ | |
5628 if (col + coloff < Columns) | |
5629 { | |
5630 int c; | |
5631 | |
5632 c = fillchar_vsep(&hl); | |
5633 if (ScreenLines[off_to] != c | |
5634 # ifdef FEAT_MBYTE | |
714 | 5635 || (enc_utf8 && (int)ScreenLinesUC[off_to] |
5636 != (c >= 0x80 ? c : 0)) | |
7 | 5637 # endif |
5638 || ScreenAttrs[off_to] != hl) | |
5639 { | |
5640 ScreenLines[off_to] = c; | |
5641 ScreenAttrs[off_to] = hl; | |
5642 # ifdef FEAT_MBYTE | |
5643 if (enc_utf8) | |
5644 { | |
5645 if (c >= 0x80) | |
5646 { | |
5647 ScreenLinesUC[off_to] = c; | |
714 | 5648 ScreenLinesC[0][off_to] = 0; |
7 | 5649 } |
5650 else | |
5651 ScreenLinesUC[off_to] = 0; | |
5652 } | |
5653 # endif | |
5654 screen_char(off_to, row, col + coloff); | |
5655 } | |
5656 } | |
5657 else | |
5658 #endif | |
5659 LineWraps[row] = FALSE; | |
5660 } | |
5661 } | |
5662 | |
474 | 5663 #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
7 | 5664 /* |
474 | 5665 * Mirror text "str" for right-left displaying. |
5666 * Only works for single-byte characters (e.g., numbers). | |
7 | 5667 */ |
474 | 5668 void |
7 | 5669 rl_mirror(str) |
5670 char_u *str; | |
5671 { | |
5672 char_u *p1, *p2; | |
5673 int t; | |
5674 | |
5675 for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) | |
5676 { | |
5677 t = *p1; | |
5678 *p1 = *p2; | |
5679 *p2 = t; | |
5680 } | |
5681 } | |
5682 #endif | |
5683 | |
5684 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
5685 /* | |
5686 * mark all status lines for redraw; used after first :cd | |
5687 */ | |
5688 void | |
5689 status_redraw_all() | |
5690 { | |
5691 win_T *wp; | |
5692 | |
5693 for (wp = firstwin; wp; wp = wp->w_next) | |
5694 if (wp->w_status_height) | |
5695 { | |
5696 wp->w_redr_status = TRUE; | |
5697 redraw_later(VALID); | |
5698 } | |
5699 } | |
5700 | |
5701 /* | |
5702 * mark all status lines of the current buffer for redraw | |
5703 */ | |
5704 void | |
5705 status_redraw_curbuf() | |
5706 { | |
5707 win_T *wp; | |
5708 | |
5709 for (wp = firstwin; wp; wp = wp->w_next) | |
5710 if (wp->w_status_height != 0 && wp->w_buffer == curbuf) | |
5711 { | |
5712 wp->w_redr_status = TRUE; | |
5713 redraw_later(VALID); | |
5714 } | |
5715 } | |
5716 | |
5717 /* | |
5718 * Redraw all status lines that need to be redrawn. | |
5719 */ | |
5720 void | |
5721 redraw_statuslines() | |
5722 { | |
5723 win_T *wp; | |
5724 | |
5725 for (wp = firstwin; wp; wp = wp->w_next) | |
5726 if (wp->w_redr_status) | |
5727 win_redr_status(wp); | |
673 | 5728 if (redraw_tabline) |
677 | 5729 draw_tabline(); |
7 | 5730 } |
5731 #endif | |
5732 | |
5733 #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) | |
5734 /* | |
5735 * Redraw all status lines at the bottom of frame "frp". | |
5736 */ | |
5737 void | |
5738 win_redraw_last_status(frp) | |
5739 frame_T *frp; | |
5740 { | |
5741 if (frp->fr_layout == FR_LEAF) | |
5742 frp->fr_win->w_redr_status = TRUE; | |
5743 else if (frp->fr_layout == FR_ROW) | |
5744 { | |
5745 for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) | |
5746 win_redraw_last_status(frp); | |
5747 } | |
5748 else /* frp->fr_layout == FR_COL */ | |
5749 { | |
5750 frp = frp->fr_child; | |
5751 while (frp->fr_next != NULL) | |
5752 frp = frp->fr_next; | |
5753 win_redraw_last_status(frp); | |
5754 } | |
5755 } | |
5756 #endif | |
5757 | |
5758 #ifdef FEAT_VERTSPLIT | |
5759 /* | |
5760 * Draw the verticap separator right of window "wp" starting with line "row". | |
5761 */ | |
5762 static void | |
5763 draw_vsep_win(wp, row) | |
5764 win_T *wp; | |
5765 int row; | |
5766 { | |
5767 int hl; | |
5768 int c; | |
5769 | |
5770 if (wp->w_vsep_width) | |
5771 { | |
5772 /* draw the vertical separator right of this window */ | |
5773 c = fillchar_vsep(&hl); | |
5774 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
5775 W_ENDCOL(wp), W_ENDCOL(wp) + 1, | |
5776 c, ' ', hl); | |
5777 } | |
5778 } | |
5779 #endif | |
5780 | |
5781 #ifdef FEAT_WILDMENU | |
5782 static int status_match_len __ARGS((expand_T *xp, char_u *s)); | |
277 | 5783 static int skip_status_match_char __ARGS((expand_T *xp, char_u *s)); |
7 | 5784 |
5785 /* | |
1378 | 5786 * Get the length of an item as it will be shown in the status line. |
7 | 5787 */ |
5788 static int | |
5789 status_match_len(xp, s) | |
5790 expand_T *xp; | |
5791 char_u *s; | |
5792 { | |
5793 int len = 0; | |
5794 | |
5795 #ifdef FEAT_MENU | |
5796 int emenu = (xp->xp_context == EXPAND_MENUS | |
5797 || xp->xp_context == EXPAND_MENUNAMES); | |
5798 | |
5799 /* Check for menu separators - replace with '|'. */ | |
5800 if (emenu && menu_is_separator(s)) | |
5801 return 1; | |
5802 #endif | |
5803 | |
5804 while (*s != NUL) | |
5805 { | |
1685 | 5806 s += skip_status_match_char(xp, s); |
42 | 5807 len += ptr2cells(s); |
39 | 5808 mb_ptr_adv(s); |
7 | 5809 } |
5810 | |
5811 return len; | |
5812 } | |
5813 | |
5814 /* | |
1685 | 5815 * Return the number of characters that should be skipped in a status match. |
277 | 5816 * These are backslashes used for escaping. Do show backslashes in help tags. |
5817 */ | |
5818 static int | |
5819 skip_status_match_char(xp, s) | |
5820 expand_T *xp; | |
5821 char_u *s; | |
5822 { | |
1685 | 5823 if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
277 | 5824 #ifdef FEAT_MENU |
5825 || ((xp->xp_context == EXPAND_MENUS | |
5826 || xp->xp_context == EXPAND_MENUNAMES) | |
5827 && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) | |
5828 #endif | |
1685 | 5829 ) |
5830 { | |
5831 #ifndef BACKSLASH_IN_FILENAME | |
5832 if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') | |
5833 return 2; | |
5834 #endif | |
5835 return 1; | |
5836 } | |
5837 return 0; | |
277 | 5838 } |
5839 | |
5840 /* | |
7 | 5841 * Show wildchar matches in the status line. |
5842 * Show at least the "match" item. | |
5843 * We start at item 'first_match' in the list and show all matches that fit. | |
5844 * | |
5845 * If inversion is possible we use it. Else '=' characters are used. | |
5846 */ | |
5847 void | |
5848 win_redr_status_matches(xp, num_matches, matches, match, showtail) | |
5849 expand_T *xp; | |
5850 int num_matches; | |
5851 char_u **matches; /* list of matches */ | |
5852 int match; | |
5853 int showtail; | |
5854 { | |
5855 #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) | |
5856 int row; | |
5857 char_u *buf; | |
5858 int len; | |
1378 | 5859 int clen; /* length in screen cells */ |
7 | 5860 int fillchar; |
5861 int attr; | |
5862 int i; | |
5863 int highlight = TRUE; | |
5864 char_u *selstart = NULL; | |
5865 int selstart_col = 0; | |
5866 char_u *selend = NULL; | |
5867 static int first_match = 0; | |
5868 int add_left = FALSE; | |
5869 char_u *s; | |
5870 #ifdef FEAT_MENU | |
5871 int emenu; | |
5872 #endif | |
5873 #if defined(FEAT_MBYTE) || defined(FEAT_MENU) | |
5874 int l; | |
5875 #endif | |
5876 | |
5877 if (matches == NULL) /* interrupted completion? */ | |
5878 return; | |
5879 | |
39 | 5880 #ifdef FEAT_MBYTE |
5881 if (has_mbyte) | |
5882 buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); | |
5883 else | |
5884 #endif | |
5885 buf = alloc((unsigned)Columns + 1); | |
7 | 5886 if (buf == NULL) |
5887 return; | |
5888 | |
5889 if (match == -1) /* don't show match but original text */ | |
5890 { | |
5891 match = 0; | |
5892 highlight = FALSE; | |
5893 } | |
5894 /* count 1 for the ending ">" */ | |
5895 clen = status_match_len(xp, L_MATCH(match)) + 3; | |
5896 if (match == 0) | |
5897 first_match = 0; | |
5898 else if (match < first_match) | |
5899 { | |
5900 /* jumping left, as far as we can go */ | |
5901 first_match = match; | |
5902 add_left = TRUE; | |
5903 } | |
5904 else | |
5905 { | |
5906 /* check if match fits on the screen */ | |
5907 for (i = first_match; i < match; ++i) | |
5908 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5909 if (first_match > 0) | |
5910 clen += 2; | |
5911 /* jumping right, put match at the left */ | |
5912 if ((long)clen > Columns) | |
5913 { | |
5914 first_match = match; | |
5915 /* if showing the last match, we can add some on the left */ | |
5916 clen = 2; | |
5917 for (i = match; i < num_matches; ++i) | |
5918 { | |
5919 clen += status_match_len(xp, L_MATCH(i)) + 2; | |
5920 if ((long)clen >= Columns) | |
5921 break; | |
5922 } | |
5923 if (i == num_matches) | |
5924 add_left = TRUE; | |
5925 } | |
5926 } | |
5927 if (add_left) | |
5928 while (first_match > 0) | |
5929 { | |
5930 clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; | |
5931 if ((long)clen >= Columns) | |
5932 break; | |
5933 --first_match; | |
5934 } | |
5935 | |
5936 fillchar = fillchar_status(&attr, TRUE); | |
5937 | |
5938 if (first_match == 0) | |
5939 { | |
5940 *buf = NUL; | |
5941 len = 0; | |
5942 } | |
5943 else | |
5944 { | |
5945 STRCPY(buf, "< "); | |
5946 len = 2; | |
5947 } | |
5948 clen = len; | |
5949 | |
5950 i = first_match; | |
5951 while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) | |
5952 { | |
5953 if (i == match) | |
5954 { | |
5955 selstart = buf + len; | |
5956 selstart_col = clen; | |
5957 } | |
5958 | |
5959 s = L_MATCH(i); | |
5960 /* Check for menu separators - replace with '|' */ | |
5961 #ifdef FEAT_MENU | |
5962 emenu = (xp->xp_context == EXPAND_MENUS | |
5963 || xp->xp_context == EXPAND_MENUNAMES); | |
5964 if (emenu && menu_is_separator(s)) | |
5965 { | |
5966 STRCPY(buf + len, transchar('|')); | |
5967 l = (int)STRLEN(buf + len); | |
5968 len += l; | |
5969 clen += l; | |
5970 } | |
5971 else | |
5972 #endif | |
5973 for ( ; *s != NUL; ++s) | |
5974 { | |
1685 | 5975 s += skip_status_match_char(xp, s); |
7 | 5976 clen += ptr2cells(s); |
5977 #ifdef FEAT_MBYTE | |
474 | 5978 if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
7 | 5979 { |
5980 STRNCPY(buf + len, s, l); | |
5981 s += l - 1; | |
5982 len += l; | |
5983 } | |
5984 else | |
5985 #endif | |
5986 { | |
5987 STRCPY(buf + len, transchar_byte(*s)); | |
5988 len += (int)STRLEN(buf + len); | |
5989 } | |
5990 } | |
5991 if (i == match) | |
5992 selend = buf + len; | |
5993 | |
5994 *(buf + len++) = ' '; | |
5995 *(buf + len++) = ' '; | |
5996 clen += 2; | |
5997 if (++i == num_matches) | |
5998 break; | |
5999 } | |
6000 | |
6001 if (i != num_matches) | |
6002 { | |
6003 *(buf + len++) = '>'; | |
6004 ++clen; | |
6005 } | |
6006 | |
6007 buf[len] = NUL; | |
6008 | |
6009 row = cmdline_row - 1; | |
6010 if (row >= 0) | |
6011 { | |
6012 if (wild_menu_showing == 0) | |
6013 { | |
6014 if (msg_scrolled > 0) | |
6015 { | |
6016 /* Put the wildmenu just above the command line. If there is | |
6017 * no room, scroll the screen one line up. */ | |
6018 if (cmdline_row == Rows - 1) | |
6019 { | |
6020 screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); | |
6021 ++msg_scrolled; | |
6022 } | |
6023 else | |
6024 { | |
6025 ++cmdline_row; | |
6026 ++row; | |
6027 } | |
6028 wild_menu_showing = WM_SCROLLED; | |
6029 } | |
6030 else | |
6031 { | |
6032 /* Create status line if needed by setting 'laststatus' to 2. | |
6033 * Set 'winminheight' to zero to avoid that the window is | |
6034 * resized. */ | |
6035 if (lastwin->w_status_height == 0) | |
6036 { | |
6037 save_p_ls = p_ls; | |
6038 save_p_wmh = p_wmh; | |
6039 p_ls = 2; | |
6040 p_wmh = 0; | |
6041 last_status(FALSE); | |
6042 } | |
6043 wild_menu_showing = WM_SHOWN; | |
6044 } | |
6045 } | |
6046 | |
6047 screen_puts(buf, row, 0, attr); | |
6048 if (selstart != NULL && highlight) | |
6049 { | |
6050 *selend = NUL; | |
6051 screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); | |
6052 } | |
6053 | |
6054 screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); | |
6055 } | |
6056 | |
6057 #ifdef FEAT_VERTSPLIT | |
6058 win_redraw_last_status(topframe); | |
6059 #else | |
6060 lastwin->w_redr_status = TRUE; | |
6061 #endif | |
6062 vim_free(buf); | |
6063 } | |
6064 #endif | |
6065 | |
6066 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
6067 /* | |
6068 * Redraw the status line of window wp. | |
6069 * | |
6070 * If inversion is possible we use it. Else '=' characters are used. | |
6071 */ | |
6072 void | |
6073 win_redr_status(wp) | |
6074 win_T *wp; | |
6075 { | |
6076 int row; | |
6077 char_u *p; | |
6078 int len; | |
6079 int fillchar; | |
6080 int attr; | |
6081 int this_ru_col; | |
1910 | 6082 static int busy = FALSE; |
6083 | |
6084 /* It's possible to get here recursively when 'statusline' (indirectly) | |
6085 * invokes ":redrawstatus". Simply ignore the call then. */ | |
6086 if (busy) | |
6087 return; | |
6088 busy = TRUE; | |
7 | 6089 |
6090 wp->w_redr_status = FALSE; | |
6091 if (wp->w_status_height == 0) | |
6092 { | |
6093 /* no status line, can only be last window */ | |
6094 redraw_cmdline = TRUE; | |
6095 } | |
540 | 6096 else if (!redrawing() |
6097 #ifdef FEAT_INS_EXPAND | |
6098 /* don't update status line when popup menu is visible and may be | |
6099 * drawn over it */ | |
6100 || pum_visible() | |
6101 #endif | |
6102 ) | |
7 | 6103 { |
6104 /* Don't redraw right now, do it later. */ | |
6105 wp->w_redr_status = TRUE; | |
6106 } | |
6107 #ifdef FEAT_STL_OPT | |
40 | 6108 else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
7 | 6109 { |
6110 /* redraw custom status line */ | |
1983 | 6111 redraw_custom_statusline(wp); |
7 | 6112 } |
6113 #endif | |
6114 else | |
6115 { | |
6116 fillchar = fillchar_status(&attr, wp == curwin); | |
6117 | |
685 | 6118 get_trans_bufname(wp->w_buffer); |
7 | 6119 p = NameBuff; |
6120 len = (int)STRLEN(p); | |
6121 | |
6122 if (wp->w_buffer->b_help | |
6123 #ifdef FEAT_QUICKFIX | |
6124 || wp->w_p_pvw | |
6125 #endif | |
6126 || bufIsChanged(wp->w_buffer) | |
6127 || wp->w_buffer->b_p_ro) | |
6128 *(p + len++) = ' '; | |
6129 if (wp->w_buffer->b_help) | |
6130 { | |
809 | 6131 STRCPY(p + len, _("[Help]")); |
7 | 6132 len += (int)STRLEN(p + len); |
6133 } | |
6134 #ifdef FEAT_QUICKFIX | |
6135 if (wp->w_p_pvw) | |
6136 { | |
6137 STRCPY(p + len, _("[Preview]")); | |
6138 len += (int)STRLEN(p + len); | |
6139 } | |
6140 #endif | |
6141 if (bufIsChanged(wp->w_buffer)) | |
6142 { | |
6143 STRCPY(p + len, "[+]"); | |
6144 len += 3; | |
6145 } | |
6146 if (wp->w_buffer->b_p_ro) | |
6147 { | |
6148 STRCPY(p + len, "[RO]"); | |
6149 len += 4; | |
6150 } | |
6151 | |
6152 #ifndef FEAT_VERTSPLIT | |
6153 this_ru_col = ru_col; | |
6154 if (this_ru_col < (Columns + 1) / 2) | |
6155 this_ru_col = (Columns + 1) / 2; | |
6156 #else | |
6157 this_ru_col = ru_col - (Columns - W_WIDTH(wp)); | |
6158 if (this_ru_col < (W_WIDTH(wp) + 1) / 2) | |
6159 this_ru_col = (W_WIDTH(wp) + 1) / 2; | |
6160 if (this_ru_col <= 1) | |
6161 { | |
6162 p = (char_u *)"<"; /* No room for file name! */ | |
6163 len = 1; | |
6164 } | |
6165 else | |
6166 #endif | |
6167 #ifdef FEAT_MBYTE | |
6168 if (has_mbyte) | |
6169 { | |
6170 int clen = 0, i; | |
6171 | |
6172 /* Count total number of display cells. */ | |
474 | 6173 for (i = 0; p[i] != NUL; i += (*mb_ptr2len)(p + i)) |
7 | 6174 clen += (*mb_ptr2cells)(p + i); |
6175 /* Find first character that will fit. | |
6176 * Going from start to end is much faster for DBCS. */ | |
6177 for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; | |
474 | 6178 i += (*mb_ptr2len)(p + i)) |
7 | 6179 clen -= (*mb_ptr2cells)(p + i); |
6180 len = clen; | |
6181 if (i > 0) | |
6182 { | |
6183 p = p + i - 1; | |
6184 *p = '<'; | |
6185 ++len; | |
6186 } | |
6187 | |
6188 } | |
6189 else | |
6190 #endif | |
6191 if (len > this_ru_col - 1) | |
6192 { | |
6193 p += len - (this_ru_col - 1); | |
6194 *p = '<'; | |
6195 len = this_ru_col - 1; | |
6196 } | |
6197 | |
6198 row = W_WINROW(wp) + wp->w_height; | |
6199 screen_puts(p, row, W_WINCOL(wp), attr); | |
6200 screen_fill(row, row + 1, len + W_WINCOL(wp), | |
6201 this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); | |
6202 | |
6203 if (get_keymap_str(wp, NameBuff, MAXPATHL) | |
6204 && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) | |
6205 screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) | |
6206 - 1 + W_WINCOL(wp)), attr); | |
6207 | |
6208 #ifdef FEAT_CMDL_INFO | |
6209 win_redr_ruler(wp, TRUE); | |
6210 #endif | |
6211 } | |
6212 | |
6213 #ifdef FEAT_VERTSPLIT | |
6214 /* | |
6215 * May need to draw the character below the vertical separator. | |
6216 */ | |
6217 if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) | |
6218 { | |
6219 if (stl_connected(wp)) | |
6220 fillchar = fillchar_status(&attr, wp == curwin); | |
6221 else | |
6222 fillchar = fillchar_vsep(&attr); | |
6223 screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), | |
6224 attr); | |
6225 } | |
6226 #endif | |
1910 | 6227 busy = FALSE; |
7 | 6228 } |
6229 | |
680 | 6230 #ifdef FEAT_STL_OPT |
6231 /* | |
6232 * Redraw the status line according to 'statusline' and take care of any | |
6233 * errors encountered. | |
6234 */ | |
6235 static void | |
1983 | 6236 redraw_custom_statusline(wp) |
680 | 6237 win_T *wp; |
6238 { | |
1983 | 6239 static int entered = FALSE; |
6240 int save_called_emsg = called_emsg; | |
6241 | |
6242 /* When called recursively return. This can happen when the statusline | |
6243 * contains an expression that triggers a redraw. */ | |
6244 if (entered) | |
6245 return; | |
6246 entered = TRUE; | |
680 | 6247 |
6248 called_emsg = FALSE; | |
6249 win_redr_custom(wp, FALSE); | |
6250 if (called_emsg) | |
1983 | 6251 { |
6252 /* When there is an error disable the statusline, otherwise the | |
6253 * display is messed up with errors and a redraw triggers the problem | |
6254 * again and again. */ | |
680 | 6255 set_string_option_direct((char_u *)"statusline", -1, |
6256 (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL | |
694 | 6257 ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
1983 | 6258 } |
680 | 6259 called_emsg |= save_called_emsg; |
1983 | 6260 entered = FALSE; |
680 | 6261 } |
6262 #endif | |
6263 | |
7 | 6264 # ifdef FEAT_VERTSPLIT |
6265 /* | |
6266 * Return TRUE if the status line of window "wp" is connected to the status | |
6267 * line of the window right of it. If not, then it's a vertical separator. | |
6268 * Only call if (wp->w_vsep_width != 0). | |
6269 */ | |
6270 int | |
6271 stl_connected(wp) | |
6272 win_T *wp; | |
6273 { | |
6274 frame_T *fr; | |
6275 | |
6276 fr = wp->w_frame; | |
6277 while (fr->fr_parent != NULL) | |
6278 { | |
6279 if (fr->fr_parent->fr_layout == FR_COL) | |
6280 { | |
6281 if (fr->fr_next != NULL) | |
6282 break; | |
6283 } | |
6284 else | |
6285 { | |
6286 if (fr->fr_next != NULL) | |
6287 return TRUE; | |
6288 } | |
6289 fr = fr->fr_parent; | |
6290 } | |
6291 return FALSE; | |
6292 } | |
6293 # endif | |
6294 | |
6295 #endif /* FEAT_WINDOWS */ | |
6296 | |
6297 #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) | |
6298 /* | |
6299 * Get the value to show for the language mappings, active 'keymap'. | |
6300 */ | |
6301 int | |
6302 get_keymap_str(wp, buf, len) | |
6303 win_T *wp; | |
6304 char_u *buf; /* buffer for the result */ | |
6305 int len; /* length of buffer */ | |
6306 { | |
6307 char_u *p; | |
6308 | |
6309 if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) | |
6310 return FALSE; | |
6311 | |
6312 { | |
6313 #ifdef FEAT_EVAL | |
6314 buf_T *old_curbuf = curbuf; | |
6315 win_T *old_curwin = curwin; | |
6316 char_u *s; | |
6317 | |
6318 curbuf = wp->w_buffer; | |
6319 curwin = wp; | |
6320 STRCPY(buf, "b:keymap_name"); /* must be writable */ | |
6321 ++emsg_skip; | |
714 | 6322 s = p = eval_to_string(buf, NULL, FALSE); |
7 | 6323 --emsg_skip; |
6324 curbuf = old_curbuf; | |
6325 curwin = old_curwin; | |
6326 if (p == NULL || *p == NUL) | |
6327 #endif | |
6328 { | |
6329 #ifdef FEAT_KEYMAP | |
6330 if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) | |
6331 p = wp->w_buffer->b_p_keymap; | |
6332 else | |
6333 #endif | |
6334 p = (char_u *)"lang"; | |
6335 } | |
6336 if ((int)(STRLEN(p) + 3) < len) | |
6337 sprintf((char *)buf, "<%s>", p); | |
6338 else | |
6339 buf[0] = NUL; | |
6340 #ifdef FEAT_EVAL | |
6341 vim_free(s); | |
6342 #endif | |
6343 } | |
6344 return buf[0] != NUL; | |
6345 } | |
6346 #endif | |
6347 | |
6348 #if defined(FEAT_STL_OPT) || defined(PROTO) | |
6349 /* | |
677 | 6350 * Redraw the status line or ruler of window "wp". |
6351 * When "wp" is NULL redraw the tab pages line from 'tabline'. | |
7 | 6352 */ |
6353 static void | |
574 | 6354 win_redr_custom(wp, draw_ruler) |
7 | 6355 win_T *wp; |
574 | 6356 int draw_ruler; /* TRUE or FALSE */ |
7 | 6357 { |
6358 int attr; | |
6359 int curattr; | |
6360 int row; | |
6361 int col = 0; | |
6362 int maxwidth; | |
6363 int width; | |
6364 int n; | |
6365 int len; | |
6366 int fillchar; | |
6367 char_u buf[MAXPATHL]; | |
1983 | 6368 char_u *stl; |
7 | 6369 char_u *p; |
681 | 6370 struct stl_hlrec hltab[STL_MAX_ITEM]; |
6371 struct stl_hlrec tabtab[STL_MAX_ITEM]; | |
677 | 6372 int use_sandbox = FALSE; |
7 | 6373 |
6374 /* setup environment for the task at hand */ | |
677 | 6375 if (wp == NULL) |
6376 { | |
6377 /* Use 'tabline'. Always at the first line of the screen. */ | |
1983 | 6378 stl = p_tal; |
677 | 6379 row = 0; |
707 | 6380 fillchar = ' '; |
677 | 6381 attr = hl_attr(HLF_TPF); |
6382 maxwidth = Columns; | |
6383 # ifdef FEAT_EVAL | |
681 | 6384 use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
677 | 6385 # endif |
6386 } | |
40 | 6387 else |
677 | 6388 { |
6389 row = W_WINROW(wp) + wp->w_height; | |
6390 fillchar = fillchar_status(&attr, wp == curwin); | |
6391 maxwidth = W_WIDTH(wp); | |
6392 | |
6393 if (draw_ruler) | |
6394 { | |
1983 | 6395 stl = p_ruf; |
677 | 6396 /* advance past any leading group spec - implicit in ru_col */ |
1983 | 6397 if (*stl == '%') |
6398 { | |
6399 if (*++stl == '-') | |
6400 stl++; | |
6401 if (atoi((char *)stl)) | |
6402 while (VIM_ISDIGIT(*stl)) | |
6403 stl++; | |
6404 if (*stl++ != '(') | |
6405 stl = p_ruf; | |
677 | 6406 } |
7 | 6407 #ifdef FEAT_VERTSPLIT |
677 | 6408 col = ru_col - (Columns - W_WIDTH(wp)); |
6409 if (col < (W_WIDTH(wp) + 1) / 2) | |
6410 col = (W_WIDTH(wp) + 1) / 2; | |
7 | 6411 #else |
677 | 6412 col = ru_col; |
6413 if (col > (Columns + 1) / 2) | |
6414 col = (Columns + 1) / 2; | |
6415 #endif | |
6416 maxwidth = W_WIDTH(wp) - col; | |
7 | 6417 #ifdef FEAT_WINDOWS |
677 | 6418 if (!wp->w_status_height) |
6419 #endif | |
6420 { | |
6421 row = Rows - 1; | |
6422 --maxwidth; /* writing in last column may cause scrolling */ | |
6423 fillchar = ' '; | |
6424 attr = 0; | |
6425 } | |
6426 | |
6427 # ifdef FEAT_EVAL | |
681 | 6428 use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
677 | 6429 # endif |
6430 } | |
6431 else | |
6432 { | |
6433 if (*wp->w_p_stl != NUL) | |
1983 | 6434 stl = wp->w_p_stl; |
677 | 6435 else |
1983 | 6436 stl = p_stl; |
677 | 6437 # ifdef FEAT_EVAL |
681 | 6438 use_sandbox = was_set_insecurely((char_u *)"statusline", |
6439 *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); | |
677 | 6440 # endif |
6441 } | |
6442 | |
6443 #ifdef FEAT_VERTSPLIT | |
6444 col += W_WINCOL(wp); | |
6445 #endif | |
6446 } | |
6447 | |
7 | 6448 if (maxwidth <= 0) |
6449 return; | |
677 | 6450 |
1983 | 6451 /* Make a copy, because the statusline may include a function call that |
6452 * might change the option value and free the memory. */ | |
6453 stl = vim_strsave(stl); | |
677 | 6454 width = build_stl_str_hl(wp == NULL ? curwin : wp, |
6455 buf, sizeof(buf), | |
1983 | 6456 stl, use_sandbox, |
681 | 6457 fillchar, maxwidth, hltab, tabtab); |
1983 | 6458 vim_free(stl); |
835 | 6459 len = (int)STRLEN(buf); |
7 | 6460 |
1883 | 6461 while (width < maxwidth && len < (int)sizeof(buf) - 1) |
7 | 6462 { |
6463 #ifdef FEAT_MBYTE | |
6464 len += (*mb_char2bytes)(fillchar, buf + len); | |
6465 #else | |
6466 buf[len++] = fillchar; | |
6467 #endif | |
6468 ++width; | |
6469 } | |
6470 buf[len] = NUL; | |
6471 | |
681 | 6472 /* |
6473 * Draw each snippet with the specified highlighting. | |
6474 */ | |
7 | 6475 curattr = attr; |
6476 p = buf; | |
681 | 6477 for (n = 0; hltab[n].start != NULL; n++) |
6478 { | |
6479 len = (int)(hltab[n].start - p); | |
7 | 6480 screen_puts_len(p, len, row, col, curattr); |
6481 col += vim_strnsize(p, len); | |
681 | 6482 p = hltab[n].start; |
6483 | |
6484 if (hltab[n].userhl == 0) | |
7 | 6485 curattr = attr; |
681 | 6486 else if (hltab[n].userhl < 0) |
6487 curattr = syn_id2attr(-hltab[n].userhl); | |
7 | 6488 #ifdef FEAT_WINDOWS |
680 | 6489 else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
681 | 6490 curattr = highlight_stlnc[hltab[n].userhl - 1]; |
7 | 6491 #endif |
6492 else | |
681 | 6493 curattr = highlight_user[hltab[n].userhl - 1]; |
7 | 6494 } |
6495 screen_puts(p, row, col, curattr); | |
681 | 6496 |
6497 if (wp == NULL) | |
6498 { | |
6499 /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ | |
6500 col = 0; | |
6501 len = 0; | |
6502 p = buf; | |
6503 fillchar = 0; | |
6504 for (n = 0; tabtab[n].start != NULL; n++) | |
6505 { | |
6506 len += vim_strnsize(p, (int)(tabtab[n].start - p)); | |
6507 while (col < len) | |
6508 TabPageIdxs[col++] = fillchar; | |
6509 p = tabtab[n].start; | |
6510 fillchar = tabtab[n].userhl; | |
6511 } | |
6512 while (col < Columns) | |
6513 TabPageIdxs[col++] = fillchar; | |
6514 } | |
7 | 6515 } |
6516 | |
6517 #endif /* FEAT_STL_OPT */ | |
6518 | |
6519 /* | |
6520 * Output a single character directly to the screen and update ScreenLines. | |
6521 */ | |
6522 void | |
6523 screen_putchar(c, row, col, attr) | |
6524 int c; | |
6525 int row, col; | |
6526 int attr; | |
6527 { | |
6528 #ifdef FEAT_MBYTE | |
6529 char_u buf[MB_MAXBYTES + 1]; | |
6530 | |
6531 buf[(*mb_char2bytes)(c, buf)] = NUL; | |
6532 #else | |
6533 char_u buf[2]; | |
6534 | |
6535 buf[0] = c; | |
6536 buf[1] = NUL; | |
6537 #endif | |
6538 screen_puts(buf, row, col, attr); | |
6539 } | |
6540 | |
6541 /* | |
6542 * Get a single character directly from ScreenLines into "bytes[]". | |
6543 * Also return its attribute in *attrp; | |
6544 */ | |
6545 void | |
6546 screen_getbytes(row, col, bytes, attrp) | |
6547 int row, col; | |
6548 char_u *bytes; | |
6549 int *attrp; | |
6550 { | |
6551 unsigned off; | |
6552 | |
6553 /* safety check */ | |
6554 if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) | |
6555 { | |
6556 off = LineOffset[row] + col; | |
6557 *attrp = ScreenAttrs[off]; | |
6558 bytes[0] = ScreenLines[off]; | |
6559 bytes[1] = NUL; | |
6560 | |
6561 #ifdef FEAT_MBYTE | |
6562 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
6563 bytes[utfc_char2bytes(off, bytes)] = NUL; | |
6564 else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
6565 { | |
6566 bytes[0] = ScreenLines[off]; | |
6567 bytes[1] = ScreenLines2[off]; | |
6568 bytes[2] = NUL; | |
6569 } | |
6570 else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) | |
6571 { | |
6572 bytes[1] = ScreenLines[off + 1]; | |
6573 bytes[2] = NUL; | |
6574 } | |
6575 #endif | |
6576 } | |
6577 } | |
6578 | |
714 | 6579 #ifdef FEAT_MBYTE |
6580 static int screen_comp_differs __ARGS((int, int*)); | |
6581 | |
6582 /* | |
6583 * Return TRUE if composing characters for screen posn "off" differs from | |
6584 * composing characters in "u8cc". | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6585 * Only to be used when ScreenLinesUC[off] != 0. |
714 | 6586 */ |
6587 static int | |
6588 screen_comp_differs(off, u8cc) | |
6589 int off; | |
6590 int *u8cc; | |
6591 { | |
6592 int i; | |
6593 | |
6594 for (i = 0; i < Screen_mco; ++i) | |
6595 { | |
6596 if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) | |
6597 return TRUE; | |
6598 if (u8cc[i] == 0) | |
6599 break; | |
6600 } | |
6601 return FALSE; | |
6602 } | |
6603 #endif | |
6604 | |
7 | 6605 /* |
6606 * Put string '*text' on the screen at position 'row' and 'col', with | |
6607 * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. | |
6608 * Note: only outputs within one row, message is truncated at screen boundary! | |
6609 * Note: if ScreenLines[], row and/or col is invalid, nothing is done. | |
6610 */ | |
6611 void | |
6612 screen_puts(text, row, col, attr) | |
6613 char_u *text; | |
6614 int row; | |
6615 int col; | |
6616 int attr; | |
6617 { | |
6618 screen_puts_len(text, -1, row, col, attr); | |
6619 } | |
6620 | |
6621 /* | |
6622 * Like screen_puts(), but output "text[len]". When "len" is -1 output up to | |
6623 * a NUL. | |
6624 */ | |
6625 void | |
6626 screen_puts_len(text, len, row, col, attr) | |
6627 char_u *text; | |
6628 int len; | |
6629 int row; | |
6630 int col; | |
6631 int attr; | |
6632 { | |
6633 unsigned off; | |
6634 char_u *ptr = text; | |
6635 int c; | |
6636 #ifdef FEAT_MBYTE | |
1378 | 6637 unsigned max_off; |
7 | 6638 int mbyte_blen = 1; |
6639 int mbyte_cells = 1; | |
6640 int u8c = 0; | |
714 | 6641 int u8cc[MAX_MCO]; |
7 | 6642 int clear_next_cell = FALSE; |
6643 # ifdef FEAT_ARABIC | |
6644 int prev_c = 0; /* previous Arabic character */ | |
714 | 6645 int pc, nc, nc1; |
6646 int pcc[MAX_MCO]; | |
7 | 6647 # endif |
6648 #endif | |
1843 | 6649 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6650 int force_redraw_this; | |
6651 int force_redraw_next = FALSE; | |
6652 #endif | |
6653 int need_redraw; | |
7 | 6654 |
6655 if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ | |
6656 return; | |
1843 | 6657 off = LineOffset[row] + col; |
7 | 6658 |
1668 | 6659 #ifdef FEAT_MBYTE |
6660 /* When drawing over the right halve of a double-wide char clear out the | |
6661 * left halve. Only needed in a terminal. */ | |
1685 | 6662 if (has_mbyte && col > 0 && col < screen_Columns |
1668 | 6663 # ifdef FEAT_GUI |
6664 && !gui.in_use | |
6665 # endif | |
6666 && mb_fix_col(col, row) != col) | |
1843 | 6667 { |
6668 ScreenLines[off - 1] = ' '; | |
6669 ScreenAttrs[off - 1] = 0; | |
6670 if (enc_utf8) | |
6671 { | |
6672 ScreenLinesUC[off - 1] = 0; | |
6673 ScreenLinesC[0][off - 1] = 0; | |
6674 } | |
6675 /* redraw the previous cell, make it empty */ | |
6676 screen_char(off - 1, row, col - 1); | |
6677 /* force the cell at "col" to be redrawn */ | |
6678 force_redraw_next = TRUE; | |
6679 } | |
6680 #endif | |
6681 | |
1378 | 6682 #ifdef FEAT_MBYTE |
6683 max_off = LineOffset[row] + screen_Columns; | |
6684 #endif | |
1340 | 6685 while (col < screen_Columns |
6686 && (len < 0 || (int)(ptr - text) < len) | |
6687 && *ptr != NUL) | |
7 | 6688 { |
6689 c = *ptr; | |
6690 #ifdef FEAT_MBYTE | |
6691 /* check if this is the first byte of a multibyte */ | |
6692 if (has_mbyte) | |
6693 { | |
6694 if (enc_utf8 && len > 0) | |
474 | 6695 mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
7 | 6696 else |
474 | 6697 mbyte_blen = (*mb_ptr2len)(ptr); |
7 | 6698 if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
6699 mbyte_cells = 1; | |
6700 else if (enc_dbcs != 0) | |
6701 mbyte_cells = mbyte_blen; | |
6702 else /* enc_utf8 */ | |
6703 { | |
6704 if (len >= 0) | |
714 | 6705 u8c = utfc_ptr2char_len(ptr, u8cc, |
7 | 6706 (int)((text + len) - ptr)); |
6707 else | |
714 | 6708 u8c = utfc_ptr2char(ptr, u8cc); |
7 | 6709 mbyte_cells = utf_char2cells(u8c); |
1401 | 6710 # ifdef UNICODE16 |
7 | 6711 /* Non-BMP character: display as ? or fullwidth ?. */ |
6712 if (u8c >= 0x10000) | |
6713 { | |
6714 u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; | |
6715 if (attr == 0) | |
6716 attr = hl_attr(HLF_8); | |
6717 } | |
1401 | 6718 # endif |
7 | 6719 # ifdef FEAT_ARABIC |
6720 if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) | |
6721 { | |
6722 /* Do Arabic shaping. */ | |
6723 if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) | |
6724 { | |
6725 /* Past end of string to be displayed. */ | |
6726 nc = NUL; | |
6727 nc1 = NUL; | |
6728 } | |
6729 else | |
714 | 6730 { |
1994 | 6731 nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
6732 (int)((text + len) - ptr - mbyte_blen)); | |
714 | 6733 nc1 = pcc[0]; |
6734 } | |
7 | 6735 pc = prev_c; |
6736 prev_c = u8c; | |
714 | 6737 u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
7 | 6738 } |
6739 else | |
6740 prev_c = u8c; | |
6741 # endif | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6742 if (col + mbyte_cells > screen_Columns) |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6743 { |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6744 /* 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
|
6745 * 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
|
6746 c = '>'; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6747 mbyte_cells = 1; |
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
6748 } |
7 | 6749 } |
6750 } | |
6751 #endif | |
6752 | |
1843 | 6753 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
6754 force_redraw_this = force_redraw_next; | |
6755 force_redraw_next = FALSE; | |
6756 #endif | |
6757 | |
6758 need_redraw = ScreenLines[off] != c | |
7 | 6759 #ifdef FEAT_MBYTE |
6760 || (mbyte_cells == 2 | |
6761 && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) | |
6762 || (enc_dbcs == DBCS_JPNU | |
6763 && c == 0x8e | |
6764 && ScreenLines2[off] != ptr[1]) | |
6765 || (enc_utf8 | |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6766 && (ScreenLinesUC[off] != |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6767 (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6768 || (ScreenLinesUC[off] != 0 |
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
6769 && screen_comp_differs(off, u8cc)))) |
7 | 6770 #endif |
6771 || ScreenAttrs[off] != attr | |
1843 | 6772 || exmode_active; |
6773 | |
6774 if (need_redraw | |
6775 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6776 || force_redraw_this | |
6777 #endif | |
7 | 6778 ) |
6779 { | |
6780 #if defined(FEAT_GUI) || defined(UNIX) | |
6781 /* The bold trick makes a single row of pixels appear in the next | |
6782 * character. When a bold character is removed, the next | |
6783 * character should be redrawn too. This happens for our own GUI | |
1843 | 6784 * and for some xterms. */ |
6785 if (need_redraw && ScreenLines[off] != ' ' && ( | |
7 | 6786 # ifdef FEAT_GUI |
6787 gui.in_use | |
6788 # endif | |
6789 # if defined(FEAT_GUI) && defined(UNIX) | |
6790 || | |
6791 # endif | |
6792 # ifdef UNIX | |
6793 term_is_xterm | |
6794 # endif | |
1843 | 6795 )) |
6796 { | |
6797 int n = ScreenAttrs[off]; | |
6798 | |
6799 if (n > HL_ALL) | |
6800 n = syn_attr2attr(n); | |
6801 if (n & HL_BOLD) | |
6802 force_redraw_next = TRUE; | |
7 | 6803 } |
6804 #endif | |
6805 #ifdef FEAT_MBYTE | |
6806 /* When at the end of the text and overwriting a two-cell | |
6807 * character with a one-cell character, need to clear the next | |
6808 * cell. Also when overwriting the left halve of a two-cell char | |
6809 * with the right halve of a two-cell char. Do this only once | |
6810 * (mb_off2cells() may return 2 on the right halve). */ | |
6811 if (clear_next_cell) | |
6812 clear_next_cell = FALSE; | |
6813 else if (has_mbyte | |
6814 && (len < 0 ? ptr[mbyte_blen] == NUL | |
6815 : ptr + mbyte_blen >= text + len) | |
1378 | 6816 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6817 || (mbyte_cells == 2 |
1378 | 6818 && (*mb_off2cells)(off, max_off) == 1 |
6819 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6820 clear_next_cell = TRUE; |
6821 | |
6822 /* Make sure we never leave a second byte of a double-byte behind, | |
6823 * it confuses mb_off2cells(). */ | |
6824 if (enc_dbcs | |
1378 | 6825 && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
7 | 6826 || (mbyte_cells == 2 |
1378 | 6827 && (*mb_off2cells)(off, max_off) == 1 |
6828 && (*mb_off2cells)(off + 1, max_off) > 1))) | |
7 | 6829 ScreenLines[off + mbyte_blen] = 0; |
6830 #endif | |
6831 ScreenLines[off] = c; | |
6832 ScreenAttrs[off] = attr; | |
6833 #ifdef FEAT_MBYTE | |
6834 if (enc_utf8) | |
6835 { | |
714 | 6836 if (c < 0x80 && u8cc[0] == 0) |
7 | 6837 ScreenLinesUC[off] = 0; |
6838 else | |
6839 { | |
714 | 6840 int i; |
6841 | |
7 | 6842 ScreenLinesUC[off] = u8c; |
714 | 6843 for (i = 0; i < Screen_mco; ++i) |
6844 { | |
6845 ScreenLinesC[i][off] = u8cc[i]; | |
6846 if (u8cc[i] == 0) | |
6847 break; | |
6848 } | |
7 | 6849 } |
6850 if (mbyte_cells == 2) | |
6851 { | |
6852 ScreenLines[off + 1] = 0; | |
6853 ScreenAttrs[off + 1] = attr; | |
6854 } | |
6855 screen_char(off, row, col); | |
6856 } | |
6857 else if (mbyte_cells == 2) | |
6858 { | |
6859 ScreenLines[off + 1] = ptr[1]; | |
6860 ScreenAttrs[off + 1] = attr; | |
6861 screen_char_2(off, row, col); | |
6862 } | |
6863 else if (enc_dbcs == DBCS_JPNU && c == 0x8e) | |
6864 { | |
6865 ScreenLines2[off] = ptr[1]; | |
6866 screen_char(off, row, col); | |
6867 } | |
6868 else | |
6869 #endif | |
6870 screen_char(off, row, col); | |
6871 } | |
6872 #ifdef FEAT_MBYTE | |
6873 if (has_mbyte) | |
6874 { | |
6875 off += mbyte_cells; | |
6876 col += mbyte_cells; | |
6877 ptr += mbyte_blen; | |
6878 if (clear_next_cell) | |
6879 ptr = (char_u *)" "; | |
6880 } | |
6881 else | |
6882 #endif | |
6883 { | |
6884 ++off; | |
6885 ++col; | |
6886 ++ptr; | |
6887 } | |
6888 } | |
1843 | 6889 |
6890 #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) | |
6891 /* If we detected the next character needs to be redrawn, but the text | |
6892 * doesn't extend up to there, update the character here. */ | |
6893 if (force_redraw_next && col < screen_Columns) | |
6894 { | |
6895 # ifdef FEAT_MBYTE | |
6896 if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) | |
6897 screen_char_2(off, row, col); | |
6898 else | |
6899 # endif | |
6900 screen_char(off, row, col); | |
6901 } | |
6902 #endif | |
7 | 6903 } |
6904 | |
6905 #ifdef FEAT_SEARCH_EXTRA | |
6906 /* | |
1326 | 6907 * Prepare for 'hlsearch' highlighting. |
7 | 6908 */ |
6909 static void | |
6910 start_search_hl() | |
6911 { | |
6912 if (p_hls && !no_hlsearch) | |
6913 { | |
6914 last_pat_prog(&search_hl.rm); | |
6915 search_hl.attr = hl_attr(HLF_L); | |
1521 | 6916 # ifdef FEAT_RELTIME |
6917 /* Set the time limit to 'redrawtime'. */ | |
6918 profile_setlimit(p_rdt, &search_hl.tm); | |
6919 # endif | |
7 | 6920 } |
6921 } | |
6922 | |
6923 /* | |
1326 | 6924 * Clean up for 'hlsearch' highlighting. |
7 | 6925 */ |
6926 static void | |
6927 end_search_hl() | |
6928 { | |
6929 if (search_hl.rm.regprog != NULL) | |
6930 { | |
6931 vim_free(search_hl.rm.regprog); | |
6932 search_hl.rm.regprog = NULL; | |
6933 } | |
6934 } | |
6935 | |
6936 /* | |
2284
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6937 * Init for calling prepare_search_hl(). |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6938 */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6939 static void |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6940 init_search_hl(wp) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6941 win_T *wp; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6942 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6943 matchitem_T *cur; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6944 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6945 /* Setup for match and 'hlsearch' highlighting. Disable any previous |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6946 * match */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6947 cur = wp->w_match_head; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6948 while (cur != NULL) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6949 { |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6950 cur->hl.rm = cur->match; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6951 if (cur->hlg_id == 0) |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6952 cur->hl.attr = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6953 else |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6954 cur->hl.attr = syn_id2attr(cur->hlg_id); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6955 cur->hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6956 cur->hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6957 cur->hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6958 # ifdef FEAT_RELTIME |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6959 /* Set the time limit to 'redrawtime'. */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6960 profile_setlimit(p_rdt, &(cur->hl.tm)); |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6961 # endif |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6962 cur = cur->next; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6963 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6964 search_hl.buf = wp->w_buffer; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6965 search_hl.lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6966 search_hl.first_lnum = 0; |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6967 /* time limit is set at the toplevel, for all windows */ |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6968 } |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6969 |
cca510a8b85b
Better init for match highlighting when using conceal feature.
Bram Moolenaar <bram@vim.org>
parents:
2277
diff
changeset
|
6970 /* |
7 | 6971 * Advance to the match in window "wp" line "lnum" or past it. |
6972 */ | |
6973 static void | |
6974 prepare_search_hl(wp, lnum) | |
6975 win_T *wp; | |
6976 linenr_T lnum; | |
6977 { | |
1326 | 6978 matchitem_T *cur; /* points to the match list */ |
6979 match_T *shl; /* points to search_hl or a match */ | |
6980 int shl_flag; /* flag to indicate whether search_hl | |
6981 has been processed or not */ | |
7 | 6982 int n; |
6983 | |
6984 /* | |
6985 * When using a multi-line pattern, start searching at the top | |
6986 * of the window or just after a closed fold. | |
1326 | 6987 * Do this both for search_hl and the match list. |
7 | 6988 */ |
1326 | 6989 cur = wp->w_match_head; |
6990 shl_flag = FALSE; | |
6991 while (cur != NULL || shl_flag == FALSE) | |
6992 { | |
6993 if (shl_flag == FALSE) | |
6994 { | |
6995 shl = &search_hl; | |
6996 shl_flag = TRUE; | |
6997 } | |
6998 else | |
6999 shl = &cur->hl; | |
7 | 7000 if (shl->rm.regprog != NULL |
7001 && shl->lnum == 0 | |
7002 && re_multiline(shl->rm.regprog)) | |
7003 { | |
7004 if (shl->first_lnum == 0) | |
7005 { | |
7006 # ifdef FEAT_FOLDING | |
7007 for (shl->first_lnum = lnum; | |
7008 shl->first_lnum > wp->w_topline; --shl->first_lnum) | |
7009 if (hasFoldingWin(wp, shl->first_lnum - 1, | |
7010 NULL, NULL, TRUE, NULL)) | |
7011 break; | |
7012 # else | |
7013 shl->first_lnum = wp->w_topline; | |
7014 # endif | |
7015 } | |
7016 n = 0; | |
7017 while (shl->first_lnum < lnum && shl->rm.regprog != NULL) | |
7018 { | |
7019 next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n); | |
7020 if (shl->lnum != 0) | |
7021 { | |
7022 shl->first_lnum = shl->lnum | |
7023 + shl->rm.endpos[0].lnum | |
7024 - shl->rm.startpos[0].lnum; | |
7025 n = shl->rm.endpos[0].col; | |
7026 } | |
7027 else | |
7028 { | |
7029 ++shl->first_lnum; | |
7030 n = 0; | |
7031 } | |
7032 } | |
7033 } | |
1326 | 7034 if (shl != &search_hl && cur != NULL) |
7035 cur = cur->next; | |
7 | 7036 } |
7037 } | |
7038 | |
7039 /* | |
1326 | 7040 * Search for a next 'hlsearch' or match. |
7 | 7041 * Uses shl->buf. |
7042 * Sets shl->lnum and shl->rm contents. | |
7043 * Note: Assumes a previous match is always before "lnum", unless | |
7044 * shl->lnum is zero. | |
7045 * Careful: Any pointers for buffer lines will become invalid. | |
7046 */ | |
7047 static void | |
7048 next_search_hl(win, shl, lnum, mincol) | |
7049 win_T *win; | |
1326 | 7050 match_T *shl; /* points to search_hl or a match */ |
7 | 7051 linenr_T lnum; |
7052 colnr_T mincol; /* minimal column for a match */ | |
7053 { | |
7054 linenr_T l; | |
7055 colnr_T matchcol; | |
7056 long nmatched; | |
7057 | |
7058 if (shl->lnum != 0) | |
7059 { | |
7060 /* Check for three situations: | |
7061 * 1. If the "lnum" is below a previous match, start a new search. | |
7062 * 2. If the previous match includes "mincol", use it. | |
7063 * 3. Continue after the previous match. | |
7064 */ | |
7065 l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; | |
7066 if (lnum > l) | |
7067 shl->lnum = 0; | |
7068 else if (lnum < l || shl->rm.endpos[0].col > mincol) | |
7069 return; | |
7070 } | |
7071 | |
7072 /* | |
7073 * Repeat searching for a match until one is found that includes "mincol" | |
7074 * or none is found in this line. | |
7075 */ | |
7076 called_emsg = FALSE; | |
7077 for (;;) | |
7078 { | |
1521 | 7079 #ifdef FEAT_RELTIME |
7080 /* Stop searching after passing the time limit. */ | |
7081 if (profile_passed_limit(&(shl->tm))) | |
7082 { | |
7083 shl->lnum = 0; /* no match found in time */ | |
7084 break; | |
7085 } | |
7086 #endif | |
7 | 7087 /* Three situations: |
7088 * 1. No useful previous match: search from start of line. | |
7089 * 2. Not Vi compatible or empty match: continue at next character. | |
7090 * Break the loop if this is beyond the end of the line. | |
7091 * 3. Vi compatible searching: continue at end of previous match. | |
7092 */ | |
7093 if (shl->lnum == 0) | |
7094 matchcol = 0; | |
7095 else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL | |
7096 || (shl->rm.endpos[0].lnum == 0 | |
685 | 7097 && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
7098 { | |
688 | 7099 char_u *ml; |
685 | 7100 |
7101 matchcol = shl->rm.startpos[0].col; | |
688 | 7102 ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
685 | 7103 if (*ml == NUL) |
7104 { | |
7105 ++matchcol; | |
7 | 7106 shl->lnum = 0; |
7107 break; | |
7108 } | |
685 | 7109 #ifdef FEAT_MBYTE |
7110 if (has_mbyte) | |
7111 matchcol += mb_ptr2len(ml); | |
7112 else | |
7113 #endif | |
7114 ++matchcol; | |
7 | 7115 } |
7116 else | |
7117 matchcol = shl->rm.endpos[0].col; | |
7118 | |
7119 shl->lnum = lnum; | |
1521 | 7120 nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, matchcol, |
7121 #ifdef FEAT_RELTIME | |
7122 &(shl->tm) | |
7123 #else | |
7124 NULL | |
7125 #endif | |
7126 ); | |
7 | 7127 if (called_emsg) |
7128 { | |
7129 /* Error while handling regexp: stop using this regexp. */ | |
1112 | 7130 if (shl == &search_hl) |
7131 { | |
1326 | 7132 /* don't free regprog in the match list, it's a copy */ |
1112 | 7133 vim_free(shl->rm.regprog); |
7134 no_hlsearch = TRUE; | |
7135 } | |
7 | 7136 shl->rm.regprog = NULL; |
1112 | 7137 shl->lnum = 0; |
7138 got_int = FALSE; /* avoid the "Type :quit to exit Vim" message */ | |
7 | 7139 break; |
7140 } | |
7141 if (nmatched == 0) | |
7142 { | |
7143 shl->lnum = 0; /* no match found */ | |
7144 break; | |
7145 } | |
7146 if (shl->rm.startpos[0].lnum > 0 | |
7147 || shl->rm.startpos[0].col >= mincol | |
7148 || nmatched > 1 | |
7149 || shl->rm.endpos[0].col > mincol) | |
7150 { | |
7151 shl->lnum += shl->rm.startpos[0].lnum; | |
7152 break; /* useful match found */ | |
7153 } | |
7154 } | |
7155 } | |
7156 #endif | |
7157 | |
7158 static void | |
7159 screen_start_highlight(attr) | |
7160 int attr; | |
7161 { | |
7162 attrentry_T *aep = NULL; | |
7163 | |
7164 screen_attr = attr; | |
7165 if (full_screen | |
7166 #ifdef WIN3264 | |
7167 && termcap_active | |
7168 #endif | |
7169 ) | |
7170 { | |
7171 #ifdef FEAT_GUI | |
7172 if (gui.in_use) | |
7173 { | |
7174 char buf[20]; | |
7175 | |
681 | 7176 /* The GUI handles this internally. */ |
7177 sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); | |
7 | 7178 OUT_STR(buf); |
7179 } | |
7180 else | |
7181 #endif | |
7182 { | |
7183 if (attr > HL_ALL) /* special HL attr. */ | |
7184 { | |
7185 if (t_colors > 1) | |
7186 aep = syn_cterm_attr2entry(attr); | |
7187 else | |
7188 aep = syn_term_attr2entry(attr); | |
7189 if (aep == NULL) /* did ":syntax clear" */ | |
7190 attr = 0; | |
7191 else | |
7192 attr = aep->ae_attr; | |
7193 } | |
7194 if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ | |
7195 out_str(T_MD); | |
681 | 7196 else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
7197 && cterm_normal_fg_bold) | |
7198 /* If the Normal FG color has BOLD attribute and the new HL | |
7199 * has a FG color defined, clear BOLD. */ | |
7200 out_str(T_ME); | |
7 | 7201 if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
7202 out_str(T_SO); | |
205 | 7203 if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
7204 /* underline or undercurl */ | |
7 | 7205 out_str(T_US); |
7206 if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ | |
7207 out_str(T_CZH); | |
7208 if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ | |
7209 out_str(T_MR); | |
7210 | |
7211 /* | |
7212 * Output the color or start string after bold etc., in case the | |
7213 * bold etc. override the color setting. | |
7214 */ | |
7215 if (aep != NULL) | |
7216 { | |
7217 if (t_colors > 1) | |
7218 { | |
7219 if (aep->ae_u.cterm.fg_color) | |
7220 term_fg_color(aep->ae_u.cterm.fg_color - 1); | |
7221 if (aep->ae_u.cterm.bg_color) | |
7222 term_bg_color(aep->ae_u.cterm.bg_color - 1); | |
7223 } | |
7224 else | |
7225 { | |
7226 if (aep->ae_u.term.start != NULL) | |
7227 out_str(aep->ae_u.term.start); | |
7228 } | |
7229 } | |
7230 } | |
7231 } | |
7232 } | |
7233 | |
7234 void | |
7235 screen_stop_highlight() | |
7236 { | |
7237 int do_ME = FALSE; /* output T_ME code */ | |
7238 | |
7239 if (screen_attr != 0 | |
7240 #ifdef WIN3264 | |
7241 && termcap_active | |
7242 #endif | |
7243 ) | |
7244 { | |
7245 #ifdef FEAT_GUI | |
7246 if (gui.in_use) | |
7247 { | |
7248 char buf[20]; | |
7249 | |
7250 /* use internal GUI code */ | |
7251 sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); | |
7252 OUT_STR(buf); | |
7253 } | |
7254 else | |
7255 #endif | |
7256 { | |
7257 if (screen_attr > HL_ALL) /* special HL attr. */ | |
7258 { | |
7259 attrentry_T *aep; | |
7260 | |
7261 if (t_colors > 1) | |
7262 { | |
7263 /* | |
7264 * Assume that t_me restores the original colors! | |
7265 */ | |
7266 aep = syn_cterm_attr2entry(screen_attr); | |
7267 if (aep != NULL && (aep->ae_u.cterm.fg_color | |
7268 || aep->ae_u.cterm.bg_color)) | |
7269 do_ME = TRUE; | |
7270 } | |
7271 else | |
7272 { | |
7273 aep = syn_term_attr2entry(screen_attr); | |
7274 if (aep != NULL && aep->ae_u.term.stop != NULL) | |
7275 { | |
7276 if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) | |
7277 do_ME = TRUE; | |
7278 else | |
7279 out_str(aep->ae_u.term.stop); | |
7280 } | |
7281 } | |
7282 if (aep == NULL) /* did ":syntax clear" */ | |
7283 screen_attr = 0; | |
7284 else | |
7285 screen_attr = aep->ae_attr; | |
7286 } | |
7287 | |
7288 /* | |
7289 * Often all ending-codes are equal to T_ME. Avoid outputting the | |
7290 * same sequence several times. | |
7291 */ | |
7292 if (screen_attr & HL_STANDOUT) | |
7293 { | |
7294 if (STRCMP(T_SE, T_ME) == 0) | |
7295 do_ME = TRUE; | |
7296 else | |
7297 out_str(T_SE); | |
7298 } | |
205 | 7299 if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
7 | 7300 { |
7301 if (STRCMP(T_UE, T_ME) == 0) | |
7302 do_ME = TRUE; | |
7303 else | |
7304 out_str(T_UE); | |
7305 } | |
7306 if (screen_attr & HL_ITALIC) | |
7307 { | |
7308 if (STRCMP(T_CZR, T_ME) == 0) | |
7309 do_ME = TRUE; | |
7310 else | |
7311 out_str(T_CZR); | |
7312 } | |
7313 if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) | |
7314 out_str(T_ME); | |
7315 | |
7316 if (t_colors > 1) | |
7317 { | |
7318 /* set Normal cterm colors */ | |
7319 if (cterm_normal_fg_color != 0) | |
7320 term_fg_color(cterm_normal_fg_color - 1); | |
7321 if (cterm_normal_bg_color != 0) | |
7322 term_bg_color(cterm_normal_bg_color - 1); | |
7323 if (cterm_normal_fg_bold) | |
7324 out_str(T_MD); | |
7325 } | |
7326 } | |
7327 } | |
7328 screen_attr = 0; | |
7329 } | |
7330 | |
7331 /* | |
7332 * Reset the colors for a cterm. Used when leaving Vim. | |
7333 * The machine specific code may override this again. | |
7334 */ | |
7335 void | |
7336 reset_cterm_colors() | |
7337 { | |
7338 if (t_colors > 1) | |
7339 { | |
7340 /* set Normal cterm colors */ | |
7341 if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) | |
7342 { | |
7343 out_str(T_OP); | |
7344 screen_attr = -1; | |
7345 } | |
7346 if (cterm_normal_fg_bold) | |
7347 { | |
7348 out_str(T_ME); | |
7349 screen_attr = -1; | |
7350 } | |
7351 } | |
7352 } | |
7353 | |
7354 /* | |
7355 * Put character ScreenLines["off"] on the screen at position "row" and "col", | |
7356 * using the attributes from ScreenAttrs["off"]. | |
7357 */ | |
7358 static void | |
7359 screen_char(off, row, col) | |
7360 unsigned off; | |
7361 int row; | |
7362 int col; | |
7363 { | |
7364 int attr; | |
7365 | |
7366 /* Check for illegal values, just in case (could happen just after | |
7367 * resizing). */ | |
7368 if (row >= screen_Rows || col >= screen_Columns) | |
7369 return; | |
7370 | |
7371 /* Outputting the last character on the screen may scrollup the screen. | |
7372 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7373 if (row == screen_Rows - 1 && col == screen_Columns - 1 | |
7374 #ifdef FEAT_RIGHTLEFT | |
7375 /* account for first command-line character in rightleft mode */ | |
7376 && !cmdmsg_rl | |
7377 #endif | |
7378 ) | |
7379 { | |
7380 ScreenAttrs[off] = (sattr_T)-1; | |
7381 return; | |
7382 } | |
7383 | |
7384 /* | |
7385 * Stop highlighting first, so it's easier to move the cursor. | |
7386 */ | |
7387 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) | |
7388 if (screen_char_attr != 0) | |
7389 attr = screen_char_attr; | |
7390 else | |
7391 #endif | |
7392 attr = ScreenAttrs[off]; | |
7393 if (screen_attr != attr) | |
7394 screen_stop_highlight(); | |
7395 | |
7396 windgoto(row, col); | |
7397 | |
7398 if (screen_attr != attr) | |
7399 screen_start_highlight(attr); | |
7400 | |
7401 #ifdef FEAT_MBYTE | |
7402 if (enc_utf8 && ScreenLinesUC[off] != 0) | |
7403 { | |
7404 char_u buf[MB_MAXBYTES + 1]; | |
7405 | |
7406 /* Convert UTF-8 character to bytes and write it. */ | |
7407 | |
7408 buf[utfc_char2bytes(off, buf)] = NUL; | |
7409 | |
7410 out_str(buf); | |
7411 if (utf_char2cells(ScreenLinesUC[off]) > 1) | |
7412 ++screen_cur_col; | |
7413 } | |
7414 else | |
7415 #endif | |
7416 { | |
7417 #ifdef FEAT_MBYTE | |
7418 out_flush_check(); | |
7419 #endif | |
7420 out_char(ScreenLines[off]); | |
7421 #ifdef FEAT_MBYTE | |
7422 /* double-byte character in single-width cell */ | |
7423 if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) | |
7424 out_char(ScreenLines2[off]); | |
7425 #endif | |
7426 } | |
7427 | |
7428 screen_cur_col++; | |
7429 } | |
7430 | |
7431 #ifdef FEAT_MBYTE | |
7432 | |
7433 /* | |
7434 * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] | |
7435 * on the screen at position 'row' and 'col'. | |
7436 * The attributes of the first byte is used for all. This is required to | |
7437 * output the two bytes of a double-byte character with nothing in between. | |
7438 */ | |
7439 static void | |
7440 screen_char_2(off, row, col) | |
7441 unsigned off; | |
7442 int row; | |
7443 int col; | |
7444 { | |
7445 /* Check for illegal values (could be wrong when screen was resized). */ | |
7446 if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) | |
7447 return; | |
7448 | |
7449 /* Outputting the last character on the screen may scrollup the screen. | |
7450 * Don't to it! Mark the character invalid (update it when scrolled up) */ | |
7451 if (row == screen_Rows - 1 && col >= screen_Columns - 2) | |
7452 { | |
7453 ScreenAttrs[off] = (sattr_T)-1; | |
7454 return; | |
7455 } | |
7456 | |
7457 /* Output the first byte normally (positions the cursor), then write the | |
7458 * second byte directly. */ | |
7459 screen_char(off, row, col); | |
7460 out_char(ScreenLines[off + 1]); | |
7461 ++screen_cur_col; | |
7462 } | |
7463 #endif | |
7464 | |
7465 #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) | |
7466 /* | |
7467 * Draw a rectangle of the screen, inverted when "invert" is TRUE. | |
7468 * This uses the contents of ScreenLines[] and doesn't change it. | |
7469 */ | |
7470 void | |
7471 screen_draw_rectangle(row, col, height, width, invert) | |
7472 int row; | |
7473 int col; | |
7474 int height; | |
7475 int width; | |
7476 int invert; | |
7477 { | |
7478 int r, c; | |
7479 int off; | |
1378 | 7480 #ifdef FEAT_MBYTE |
7481 int max_off; | |
7482 #endif | |
7 | 7483 |
534 | 7484 /* Can't use ScreenLines unless initialized */ |
7485 if (ScreenLines == NULL) | |
7486 return; | |
7487 | |
7 | 7488 if (invert) |
7489 screen_char_attr = HL_INVERSE; | |
7490 for (r = row; r < row + height; ++r) | |
7491 { | |
7492 off = LineOffset[r]; | |
1378 | 7493 #ifdef FEAT_MBYTE |
7494 max_off = off + screen_Columns; | |
7495 #endif | |
7 | 7496 for (c = col; c < col + width; ++c) |
7497 { | |
7498 #ifdef FEAT_MBYTE | |
1378 | 7499 if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
7 | 7500 { |
7501 screen_char_2(off + c, r, c); | |
7502 ++c; | |
7503 } | |
7504 else | |
7505 #endif | |
7506 { | |
7507 screen_char(off + c, r, c); | |
7508 #ifdef FEAT_MBYTE | |
1378 | 7509 if (utf_off2cells(off + c, max_off) > 1) |
7 | 7510 ++c; |
7511 #endif | |
7512 } | |
7513 } | |
7514 } | |
7515 screen_char_attr = 0; | |
7516 } | |
7517 #endif | |
7518 | |
7519 #ifdef FEAT_VERTSPLIT | |
7520 /* | |
7521 * Redraw the characters for a vertically split window. | |
7522 */ | |
7523 static void | |
7524 redraw_block(row, end, wp) | |
7525 int row; | |
7526 int end; | |
7527 win_T *wp; | |
7528 { | |
7529 int col; | |
7530 int width; | |
7531 | |
7532 # ifdef FEAT_CLIPBOARD | |
7533 clip_may_clear_selection(row, end - 1); | |
7534 # endif | |
7535 | |
7536 if (wp == NULL) | |
7537 { | |
7538 col = 0; | |
7539 width = Columns; | |
7540 } | |
7541 else | |
7542 { | |
7543 col = wp->w_wincol; | |
7544 width = wp->w_width; | |
7545 } | |
7546 screen_draw_rectangle(row, col, end - row, width, FALSE); | |
7547 } | |
7548 #endif | |
7549 | |
7550 /* | |
7551 * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' | |
7552 * with character 'c1' in first column followed by 'c2' in the other columns. | |
7553 * Use attributes 'attr'. | |
7554 */ | |
7555 void | |
7556 screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) | |
7557 int start_row, end_row; | |
7558 int start_col, end_col; | |
7559 int c1, c2; | |
7560 int attr; | |
7561 { | |
7562 int row; | |
7563 int col; | |
7564 int off; | |
7565 int end_off; | |
7566 int did_delete; | |
7567 int c; | |
7568 int norm_term; | |
7569 #if defined(FEAT_GUI) || defined(UNIX) | |
7570 int force_next = FALSE; | |
7571 #endif | |
7572 | |
7573 if (end_row > screen_Rows) /* safety check */ | |
7574 end_row = screen_Rows; | |
7575 if (end_col > screen_Columns) /* safety check */ | |
7576 end_col = screen_Columns; | |
7577 if (ScreenLines == NULL | |
7578 || start_row >= end_row | |
7579 || start_col >= end_col) /* nothing to do */ | |
7580 return; | |
7581 | |
7582 /* it's a "normal" terminal when not in a GUI or cterm */ | |
7583 norm_term = ( | |
7584 #ifdef FEAT_GUI | |
7585 !gui.in_use && | |
7586 #endif | |
7587 t_colors <= 1); | |
7588 for (row = start_row; row < end_row; ++row) | |
7589 { | |
1668 | 7590 #ifdef FEAT_MBYTE |
7591 if (has_mbyte | |
7592 # ifdef FEAT_GUI | |
7593 && !gui.in_use | |
7594 # endif | |
7595 ) | |
7596 { | |
7597 /* When drawing over the right halve of a double-wide char clear | |
7598 * out the left halve. When drawing over the left halve of a | |
7599 * double wide-char clear out the right halve. Only needed in a | |
7600 * terminal. */ | |
1685 | 7601 if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
1670 | 7602 screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
1677 | 7603 if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
1670 | 7604 screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
1668 | 7605 } |
7606 #endif | |
7 | 7607 /* |
7608 * Try to use delete-line termcap code, when no attributes or in a | |
7609 * "normal" terminal, where a bold/italic space is just a | |
7610 * space. | |
7611 */ | |
7612 did_delete = FALSE; | |
7613 if (c2 == ' ' | |
7614 && end_col == Columns | |
7615 && can_clear(T_CE) | |
7616 && (attr == 0 | |
7617 || (norm_term | |
7618 && attr <= HL_ALL | |
7619 && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) | |
7620 { | |
7621 /* | |
7622 * check if we really need to clear something | |
7623 */ | |
7624 col = start_col; | |
7625 if (c1 != ' ') /* don't clear first char */ | |
7626 ++col; | |
7627 | |
7628 off = LineOffset[row] + col; | |
7629 end_off = LineOffset[row] + end_col; | |
7630 | |
7631 /* skip blanks (used often, keep it fast!) */ | |
7632 #ifdef FEAT_MBYTE | |
7633 if (enc_utf8) | |
7634 while (off < end_off && ScreenLines[off] == ' ' | |
7635 && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) | |
7636 ++off; | |
7637 else | |
7638 #endif | |
7639 while (off < end_off && ScreenLines[off] == ' ' | |
7640 && ScreenAttrs[off] == 0) | |
7641 ++off; | |
7642 if (off < end_off) /* something to be cleared */ | |
7643 { | |
7644 col = off - LineOffset[row]; | |
7645 screen_stop_highlight(); | |
7646 term_windgoto(row, col);/* clear rest of this screen line */ | |
7647 out_str(T_CE); | |
7648 screen_start(); /* don't know where cursor is now */ | |
7649 col = end_col - col; | |
7650 while (col--) /* clear chars in ScreenLines */ | |
7651 { | |
7652 ScreenLines[off] = ' '; | |
7653 #ifdef FEAT_MBYTE | |
7654 if (enc_utf8) | |
7655 ScreenLinesUC[off] = 0; | |
7656 #endif | |
7657 ScreenAttrs[off] = 0; | |
7658 ++off; | |
7659 } | |
7660 } | |
7661 did_delete = TRUE; /* the chars are cleared now */ | |
7662 } | |
7663 | |
7664 off = LineOffset[row] + start_col; | |
7665 c = c1; | |
7666 for (col = start_col; col < end_col; ++col) | |
7667 { | |
7668 if (ScreenLines[off] != c | |
7669 #ifdef FEAT_MBYTE | |
714 | 7670 || (enc_utf8 && (int)ScreenLinesUC[off] |
7671 != (c >= 0x80 ? c : 0)) | |
7 | 7672 #endif |
7673 || ScreenAttrs[off] != attr | |
7674 #if defined(FEAT_GUI) || defined(UNIX) | |
7675 || force_next | |
7676 #endif | |
7677 ) | |
7678 { | |
7679 #if defined(FEAT_GUI) || defined(UNIX) | |
7680 /* The bold trick may make a single row of pixels appear in | |
7681 * the next character. When a bold character is removed, the | |
7682 * next character should be redrawn too. This happens for our | |
7683 * own GUI and for some xterms. */ | |
7684 if ( | |
7685 # ifdef FEAT_GUI | |
7686 gui.in_use | |
7687 # endif | |
7688 # if defined(FEAT_GUI) && defined(UNIX) | |
7689 || | |
7690 # endif | |
7691 # ifdef UNIX | |
7692 term_is_xterm | |
7693 # endif | |
7694 ) | |
7695 { | |
7696 if (ScreenLines[off] != ' ' | |
7697 && (ScreenAttrs[off] > HL_ALL | |
7698 || ScreenAttrs[off] & HL_BOLD)) | |
7699 force_next = TRUE; | |
7700 else | |
7701 force_next = FALSE; | |
7702 } | |
7703 #endif | |
7704 ScreenLines[off] = c; | |
7705 #ifdef FEAT_MBYTE | |
7706 if (enc_utf8) | |
7707 { | |
7708 if (c >= 0x80) | |
7709 { | |
7710 ScreenLinesUC[off] = c; | |
714 | 7711 ScreenLinesC[0][off] = 0; |
7 | 7712 } |
7713 else | |
7714 ScreenLinesUC[off] = 0; | |
7715 } | |
7716 #endif | |
7717 ScreenAttrs[off] = attr; | |
7718 if (!did_delete || c != ' ') | |
7719 screen_char(off, row, col); | |
7720 } | |
7721 ++off; | |
7722 if (col == start_col) | |
7723 { | |
7724 if (did_delete) | |
7725 break; | |
7726 c = c2; | |
7727 } | |
7728 } | |
7729 if (end_col == Columns) | |
7730 LineWraps[row] = FALSE; | |
7731 if (row == Rows - 1) /* overwritten the command line */ | |
7732 { | |
7733 redraw_cmdline = TRUE; | |
7734 if (c1 == ' ' && c2 == ' ') | |
7735 clear_cmdline = FALSE; /* command line has been cleared */ | |
644 | 7736 if (start_col == 0) |
7737 mode_displayed = FALSE; /* mode cleared or overwritten */ | |
7 | 7738 } |
7739 } | |
7740 } | |
7741 | |
7742 /* | |
7743 * Check if there should be a delay. Used before clearing or redrawing the | |
7744 * screen or the command line. | |
7745 */ | |
7746 void | |
7747 check_for_delay(check_msg_scroll) | |
7748 int check_msg_scroll; | |
7749 { | |
7750 if ((emsg_on_display || (check_msg_scroll && msg_scroll)) | |
7751 && !did_wait_return | |
7752 && emsg_silent == 0) | |
7753 { | |
7754 out_flush(); | |
7755 ui_delay(1000L, TRUE); | |
7756 emsg_on_display = FALSE; | |
7757 if (check_msg_scroll) | |
7758 msg_scroll = FALSE; | |
7759 } | |
7760 } | |
7761 | |
7762 /* | |
7763 * screen_valid - allocate screen buffers if size changed | |
7764 * If "clear" is TRUE: clear screen if it has been resized. | |
7765 * Returns TRUE if there is a valid screen to write to. | |
7766 * Returns FALSE when starting up and screen not initialized yet. | |
7767 */ | |
7768 int | |
7769 screen_valid(clear) | |
7770 int clear; | |
7771 { | |
7772 screenalloc(clear); /* allocate screen buffers if size changed */ | |
7773 return (ScreenLines != NULL); | |
7774 } | |
7775 | |
7776 /* | |
7777 * Resize the shell to Rows and Columns. | |
7778 * Allocate ScreenLines[] and associated items. | |
7779 * | |
7780 * There may be some time between setting Rows and Columns and (re)allocating | |
7781 * ScreenLines[]. This happens when starting up and when (manually) changing | |
7782 * the shell size. Always use screen_Rows and screen_Columns to access items | |
7783 * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the | |
7784 * final size of the shell is needed. | |
7785 */ | |
7786 void | |
7787 screenalloc(clear) | |
7788 int clear; | |
7789 { | |
7790 int new_row, old_row; | |
7791 #ifdef FEAT_GUI | |
7792 int old_Rows; | |
7793 #endif | |
7794 win_T *wp; | |
7795 int outofmem = FALSE; | |
7796 int len; | |
7797 schar_T *new_ScreenLines; | |
7798 #ifdef FEAT_MBYTE | |
7799 u8char_T *new_ScreenLinesUC = NULL; | |
714 | 7800 u8char_T *new_ScreenLinesC[MAX_MCO]; |
7 | 7801 schar_T *new_ScreenLines2 = NULL; |
714 | 7802 int i; |
7 | 7803 #endif |
7804 sattr_T *new_ScreenAttrs; | |
7805 unsigned *new_LineOffset; | |
7806 char_u *new_LineWraps; | |
671 | 7807 #ifdef FEAT_WINDOWS |
681 | 7808 short *new_TabPageIdxs; |
671 | 7809 tabpage_T *tp; |
7810 #endif | |
7 | 7811 static int entered = FALSE; /* avoid recursiveness */ |
944 | 7812 static int done_outofmem_msg = FALSE; /* did outofmem message */ |
1824 | 7813 #ifdef FEAT_AUTOCMD |
7814 int retry_count = 0; | |
7815 | |
7816 retry: | |
7817 #endif | |
7 | 7818 /* |
7819 * Allocation of the screen buffers is done only when the size changes and | |
7820 * when Rows and Columns have been set and we have started doing full | |
7821 * screen stuff. | |
7822 */ | |
7823 if ((ScreenLines != NULL | |
7824 && Rows == screen_Rows | |
7825 && Columns == screen_Columns | |
7826 #ifdef FEAT_MBYTE | |
7827 && enc_utf8 == (ScreenLinesUC != NULL) | |
7828 && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) | |
714 | 7829 && p_mco == Screen_mco |
7 | 7830 #endif |
7831 ) | |
7832 || Rows == 0 | |
7833 || Columns == 0 | |
7834 || (!full_screen && ScreenLines == NULL)) | |
7835 return; | |
7836 | |
7837 /* | |
7838 * It's possible that we produce an out-of-memory message below, which | |
7839 * will cause this function to be called again. To break the loop, just | |
7840 * return here. | |
7841 */ | |
7842 if (entered) | |
7843 return; | |
7844 entered = TRUE; | |
7845 | |
911 | 7846 /* |
7847 * Note that the window sizes are updated before reallocating the arrays, | |
7848 * thus we must not redraw here! | |
7849 */ | |
7850 ++RedrawingDisabled; | |
7851 | |
7 | 7852 win_new_shellsize(); /* fit the windows in the new sized shell */ |
7853 | |
7854 comp_col(); /* recompute columns for shown command and ruler */ | |
7855 | |
7856 /* | |
7857 * We're changing the size of the screen. | |
7858 * - Allocate new arrays for ScreenLines and ScreenAttrs. | |
7859 * - Move lines from the old arrays into the new arrays, clear extra | |
7860 * lines (unless the screen is going to be cleared). | |
7861 * - Free the old arrays. | |
7862 * | |
7863 * If anything fails, make ScreenLines NULL, so we don't do anything! | |
7864 * Continuing with the old ScreenLines may result in a crash, because the | |
7865 * size is wrong. | |
7866 */ | |
671 | 7867 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7868 win_free_lsize(wp); |
1946 | 7869 #ifdef FEAT_AUTOCMD |
7870 if (aucmd_win != NULL) | |
7871 win_free_lsize(aucmd_win); | |
7872 #endif | |
7 | 7873 |
7874 new_ScreenLines = (schar_T *)lalloc((long_u)( | |
7875 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7876 #ifdef FEAT_MBYTE | |
2122
476336a5ae95
updated for version 7.2.404
Bram Moolenaar <bram@zimbu.org>
parents:
2069
diff
changeset
|
7877 vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
7 | 7878 if (enc_utf8) |
7879 { | |
7880 new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( | |
7881 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); | |
714 | 7882 for (i = 0; i < p_mco; ++i) |
2124
dc8a5699253b
updated for version 7.2.406
Bram Moolenaar <bram@zimbu.org>
parents:
2122
diff
changeset
|
7883 new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
7 | 7884 (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
7885 } | |
7886 if (enc_dbcs == DBCS_JPNU) | |
7887 new_ScreenLines2 = (schar_T *)lalloc((long_u)( | |
7888 (Rows + 1) * Columns * sizeof(schar_T)), FALSE); | |
7889 #endif | |
7890 new_ScreenAttrs = (sattr_T *)lalloc((long_u)( | |
7891 (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); | |
7892 new_LineOffset = (unsigned *)lalloc((long_u)( | |
7893 Rows * sizeof(unsigned)), FALSE); | |
7894 new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); | |
671 | 7895 #ifdef FEAT_WINDOWS |
681 | 7896 new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
671 | 7897 #endif |
7 | 7898 |
677 | 7899 FOR_ALL_TAB_WINDOWS(tp, wp) |
7 | 7900 { |
7901 if (win_alloc_lines(wp) == FAIL) | |
7902 { | |
7903 outofmem = TRUE; | |
7904 #ifdef FEAT_WINDOWS | |
1819 | 7905 goto give_up; |
7906 #endif | |
7907 } | |
7908 } | |
1906 | 7909 #ifdef FEAT_AUTOCMD |
1946 | 7910 if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
7911 && win_alloc_lines(aucmd_win) == FAIL) | |
1906 | 7912 outofmem = TRUE; |
7913 #endif | |
1819 | 7914 #ifdef FEAT_WINDOWS |
7915 give_up: | |
7916 #endif | |
7 | 7917 |
714 | 7918 #ifdef FEAT_MBYTE |
7919 for (i = 0; i < p_mco; ++i) | |
7920 if (new_ScreenLinesC[i] == NULL) | |
7921 break; | |
7922 #endif | |
7 | 7923 if (new_ScreenLines == NULL |
7924 #ifdef FEAT_MBYTE | |
714 | 7925 || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
7 | 7926 || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
7927 #endif | |
7928 || new_ScreenAttrs == NULL | |
7929 || new_LineOffset == NULL | |
7930 || new_LineWraps == NULL | |
671 | 7931 #ifdef FEAT_WINDOWS |
7932 || new_TabPageIdxs == NULL | |
7933 #endif | |
7 | 7934 || outofmem) |
7935 { | |
944 | 7936 if (ScreenLines != NULL || !done_outofmem_msg) |
534 | 7937 { |
7938 /* guess the size */ | |
7939 do_outofmem_msg((long_u)((Rows + 1) * Columns)); | |
7940 | |
7941 /* Remember we did this to avoid getting outofmem messages over | |
7942 * and over again. */ | |
944 | 7943 done_outofmem_msg = TRUE; |
534 | 7944 } |
7 | 7945 vim_free(new_ScreenLines); |
7946 new_ScreenLines = NULL; | |
7947 #ifdef FEAT_MBYTE | |
7948 vim_free(new_ScreenLinesUC); | |
7949 new_ScreenLinesUC = NULL; | |
714 | 7950 for (i = 0; i < p_mco; ++i) |
7951 { | |
7952 vim_free(new_ScreenLinesC[i]); | |
7953 new_ScreenLinesC[i] = NULL; | |
7954 } | |
7 | 7955 vim_free(new_ScreenLines2); |
7956 new_ScreenLines2 = NULL; | |
7957 #endif | |
7958 vim_free(new_ScreenAttrs); | |
7959 new_ScreenAttrs = NULL; | |
7960 vim_free(new_LineOffset); | |
7961 new_LineOffset = NULL; | |
7962 vim_free(new_LineWraps); | |
7963 new_LineWraps = NULL; | |
671 | 7964 #ifdef FEAT_WINDOWS |
7965 vim_free(new_TabPageIdxs); | |
7966 new_TabPageIdxs = NULL; | |
7967 #endif | |
7 | 7968 } |
7969 else | |
7970 { | |
944 | 7971 done_outofmem_msg = FALSE; |
534 | 7972 |
7 | 7973 for (new_row = 0; new_row < Rows; ++new_row) |
7974 { | |
7975 new_LineOffset[new_row] = new_row * Columns; | |
7976 new_LineWraps[new_row] = FALSE; | |
7977 | |
7978 /* | |
7979 * If the screen is not going to be cleared, copy as much as | |
7980 * possible from the old screen to the new one and clear the rest | |
7981 * (used when resizing the window at the "--more--" prompt or when | |
7982 * executing an external command, for the GUI). | |
7983 */ | |
7984 if (!clear) | |
7985 { | |
7986 (void)vim_memset(new_ScreenLines + new_row * Columns, | |
7987 ' ', (size_t)Columns * sizeof(schar_T)); | |
7988 #ifdef FEAT_MBYTE | |
7989 if (enc_utf8) | |
7990 { | |
7991 (void)vim_memset(new_ScreenLinesUC + new_row * Columns, | |
7992 0, (size_t)Columns * sizeof(u8char_T)); | |
714 | 7993 for (i = 0; i < p_mco; ++i) |
7994 (void)vim_memset(new_ScreenLinesC[i] | |
7995 + new_row * Columns, | |
7 | 7996 0, (size_t)Columns * sizeof(u8char_T)); |
7997 } | |
7998 if (enc_dbcs == DBCS_JPNU) | |
7999 (void)vim_memset(new_ScreenLines2 + new_row * Columns, | |
8000 0, (size_t)Columns * sizeof(schar_T)); | |
8001 #endif | |
8002 (void)vim_memset(new_ScreenAttrs + new_row * Columns, | |
8003 0, (size_t)Columns * sizeof(sattr_T)); | |
8004 old_row = new_row + (screen_Rows - Rows); | |
534 | 8005 if (old_row >= 0 && ScreenLines != NULL) |
7 | 8006 { |
8007 if (screen_Columns < Columns) | |
8008 len = screen_Columns; | |
8009 else | |
8010 len = Columns; | |
26 | 8011 #ifdef FEAT_MBYTE |
571 | 8012 /* When switching to utf-8 don't copy characters, they |
714 | 8013 * may be invalid now. Also when p_mco changes. */ |
8014 if (!(enc_utf8 && ScreenLinesUC == NULL) | |
8015 && p_mco == Screen_mco) | |
26 | 8016 #endif |
8017 mch_memmove(new_ScreenLines + new_LineOffset[new_row], | |
8018 ScreenLines + LineOffset[old_row], | |
8019 (size_t)len * sizeof(schar_T)); | |
7 | 8020 #ifdef FEAT_MBYTE |
714 | 8021 if (enc_utf8 && ScreenLinesUC != NULL |
8022 && p_mco == Screen_mco) | |
7 | 8023 { |
8024 mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], | |
8025 ScreenLinesUC + LineOffset[old_row], | |
8026 (size_t)len * sizeof(u8char_T)); | |
714 | 8027 for (i = 0; i < p_mco; ++i) |
8028 mch_memmove(new_ScreenLinesC[i] | |
8029 + new_LineOffset[new_row], | |
8030 ScreenLinesC[i] + LineOffset[old_row], | |
7 | 8031 (size_t)len * sizeof(u8char_T)); |
8032 } | |
8033 if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) | |
8034 mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], | |
8035 ScreenLines2 + LineOffset[old_row], | |
8036 (size_t)len * sizeof(schar_T)); | |
8037 #endif | |
8038 mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], | |
8039 ScreenAttrs + LineOffset[old_row], | |
8040 (size_t)len * sizeof(sattr_T)); | |
8041 } | |
8042 } | |
8043 } | |
8044 /* Use the last line of the screen for the current line. */ | |
8045 current_ScreenLine = new_ScreenLines + Rows * Columns; | |
8046 } | |
8047 | |
356 | 8048 free_screenlines(); |
8049 | |
7 | 8050 ScreenLines = new_ScreenLines; |
8051 #ifdef FEAT_MBYTE | |
8052 ScreenLinesUC = new_ScreenLinesUC; | |
714 | 8053 for (i = 0; i < p_mco; ++i) |
8054 ScreenLinesC[i] = new_ScreenLinesC[i]; | |
8055 Screen_mco = p_mco; | |
7 | 8056 ScreenLines2 = new_ScreenLines2; |
8057 #endif | |
8058 ScreenAttrs = new_ScreenAttrs; | |
8059 LineOffset = new_LineOffset; | |
8060 LineWraps = new_LineWraps; | |
671 | 8061 #ifdef FEAT_WINDOWS |
8062 TabPageIdxs = new_TabPageIdxs; | |
8063 #endif | |
7 | 8064 |
8065 /* It's important that screen_Rows and screen_Columns reflect the actual | |
8066 * size of ScreenLines[]. Set them before calling anything. */ | |
8067 #ifdef FEAT_GUI | |
8068 old_Rows = screen_Rows; | |
8069 #endif | |
8070 screen_Rows = Rows; | |
8071 screen_Columns = Columns; | |
8072 | |
8073 must_redraw = CLEAR; /* need to clear the screen later */ | |
8074 if (clear) | |
8075 screenclear2(); | |
8076 | |
8077 #ifdef FEAT_GUI | |
8078 else if (gui.in_use | |
8079 && !gui.starting | |
8080 && ScreenLines != NULL | |
8081 && old_Rows != Rows) | |
8082 { | |
8083 (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); | |
8084 /* | |
8085 * Adjust the position of the cursor, for when executing an external | |
8086 * command. | |
8087 */ | |
8088 if (msg_row >= Rows) /* Rows got smaller */ | |
8089 msg_row = Rows - 1; /* put cursor at last row */ | |
8090 else if (Rows > old_Rows) /* Rows got bigger */ | |
8091 msg_row += Rows - old_Rows; /* put cursor in same place */ | |
8092 if (msg_col >= Columns) /* Columns got smaller */ | |
8093 msg_col = Columns - 1; /* put cursor at last column */ | |
8094 } | |
8095 #endif | |
8096 | |
8097 entered = FALSE; | |
911 | 8098 --RedrawingDisabled; |
766 | 8099 |
8100 #ifdef FEAT_AUTOCMD | |
1824 | 8101 /* |
8102 * Do not apply autocommands more than 3 times to avoid an endless loop | |
8103 * in case applying autocommands always changes Rows or Columns. | |
8104 */ | |
8105 if (starting == 0 && ++retry_count <= 3) | |
8106 { | |
766 | 8107 apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
1824 | 8108 /* In rare cases, autocommands may have altered Rows or Columns, |
8109 * jump back to check if we need to allocate the screen again. */ | |
8110 goto retry; | |
8111 } | |
766 | 8112 #endif |
7 | 8113 } |
8114 | |
8115 void | |
356 | 8116 free_screenlines() |
8117 { | |
8118 #ifdef FEAT_MBYTE | |
714 | 8119 int i; |
8120 | |
356 | 8121 vim_free(ScreenLinesUC); |
714 | 8122 for (i = 0; i < Screen_mco; ++i) |
8123 vim_free(ScreenLinesC[i]); | |
356 | 8124 vim_free(ScreenLines2); |
8125 #endif | |
714 | 8126 vim_free(ScreenLines); |
356 | 8127 vim_free(ScreenAttrs); |
8128 vim_free(LineOffset); | |
8129 vim_free(LineWraps); | |
671 | 8130 #ifdef FEAT_WINDOWS |
8131 vim_free(TabPageIdxs); | |
8132 #endif | |
356 | 8133 } |
8134 | |
8135 void | |
7 | 8136 screenclear() |
8137 { | |
8138 check_for_delay(FALSE); | |
8139 screenalloc(FALSE); /* allocate screen buffers if size changed */ | |
8140 screenclear2(); /* clear the screen */ | |
8141 } | |
8142 | |
8143 static void | |
8144 screenclear2() | |
8145 { | |
8146 int i; | |
8147 | |
8148 if (starting == NO_SCREEN || ScreenLines == NULL | |
8149 #ifdef FEAT_GUI | |
8150 || (gui.in_use && gui.starting) | |
8151 #endif | |
8152 ) | |
8153 return; | |
8154 | |
8155 #ifdef FEAT_GUI | |
8156 if (!gui.in_use) | |
8157 #endif | |
8158 screen_attr = -1; /* force setting the Normal colors */ | |
8159 screen_stop_highlight(); /* don't want highlighting here */ | |
8160 | |
8161 #ifdef FEAT_CLIPBOARD | |
8162 /* disable selection without redrawing it */ | |
8163 clip_scroll_selection(9999); | |
8164 #endif | |
8165 | |
8166 /* blank out ScreenLines */ | |
8167 for (i = 0; i < Rows; ++i) | |
8168 { | |
8169 lineclear(LineOffset[i], (int)Columns); | |
8170 LineWraps[i] = FALSE; | |
8171 } | |
8172 | |
8173 if (can_clear(T_CL)) | |
8174 { | |
8175 out_str(T_CL); /* clear the display */ | |
8176 clear_cmdline = FALSE; | |
644 | 8177 mode_displayed = FALSE; |
7 | 8178 } |
8179 else | |
8180 { | |
8181 /* can't clear the screen, mark all chars with invalid attributes */ | |
8182 for (i = 0; i < Rows; ++i) | |
8183 lineinvalid(LineOffset[i], (int)Columns); | |
8184 clear_cmdline = TRUE; | |
8185 } | |
8186 | |
8187 screen_cleared = TRUE; /* can use contents of ScreenLines now */ | |
8188 | |
8189 win_rest_invalid(firstwin); | |
8190 redraw_cmdline = TRUE; | |
670 | 8191 #ifdef FEAT_WINDOWS |
673 | 8192 redraw_tabline = TRUE; |
670 | 8193 #endif |
7 | 8194 if (must_redraw == CLEAR) /* no need to clear again */ |
8195 must_redraw = NOT_VALID; | |
8196 compute_cmdrow(); | |
8197 msg_row = cmdline_row; /* put cursor on last line for messages */ | |
8198 msg_col = 0; | |
8199 screen_start(); /* don't know where cursor is now */ | |
8200 msg_scrolled = 0; /* can't scroll back */ | |
8201 msg_didany = FALSE; | |
8202 msg_didout = FALSE; | |
8203 } | |
8204 | |
8205 /* | |
8206 * Clear one line in ScreenLines. | |
8207 */ | |
8208 static void | |
8209 lineclear(off, width) | |
8210 unsigned off; | |
8211 int width; | |
8212 { | |
8213 (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); | |
8214 #ifdef FEAT_MBYTE | |
8215 if (enc_utf8) | |
8216 (void)vim_memset(ScreenLinesUC + off, 0, | |
8217 (size_t)width * sizeof(u8char_T)); | |
8218 #endif | |
8219 (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); | |
8220 } | |
8221 | |
8222 /* | |
8223 * Mark one line in ScreenLines invalid by setting the attributes to an | |
8224 * invalid value. | |
8225 */ | |
8226 static void | |
8227 lineinvalid(off, width) | |
8228 unsigned off; | |
8229 int width; | |
8230 { | |
8231 (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); | |
8232 } | |
8233 | |
8234 #ifdef FEAT_VERTSPLIT | |
8235 /* | |
8236 * Copy part of a Screenline for vertically split window "wp". | |
8237 */ | |
8238 static void | |
8239 linecopy(to, from, wp) | |
8240 int to; | |
8241 int from; | |
8242 win_T *wp; | |
8243 { | |
8244 unsigned off_to = LineOffset[to] + wp->w_wincol; | |
8245 unsigned off_from = LineOffset[from] + wp->w_wincol; | |
8246 | |
8247 mch_memmove(ScreenLines + off_to, ScreenLines + off_from, | |
8248 wp->w_width * sizeof(schar_T)); | |
8249 # ifdef FEAT_MBYTE | |
8250 if (enc_utf8) | |
8251 { | |
714 | 8252 int i; |
8253 | |
7 | 8254 mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
8255 wp->w_width * sizeof(u8char_T)); | |
714 | 8256 for (i = 0; i < p_mco; ++i) |
8257 mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, | |
8258 wp->w_width * sizeof(u8char_T)); | |
7 | 8259 } |
8260 if (enc_dbcs == DBCS_JPNU) | |
8261 mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, | |
8262 wp->w_width * sizeof(schar_T)); | |
8263 # endif | |
8264 mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, | |
8265 wp->w_width * sizeof(sattr_T)); | |
8266 } | |
8267 #endif | |
8268 | |
8269 /* | |
8270 * Return TRUE if clearing with term string "p" would work. | |
8271 * It can't work when the string is empty or it won't set the right background. | |
8272 */ | |
8273 int | |
8274 can_clear(p) | |
8275 char_u *p; | |
8276 { | |
8277 return (*p != NUL && (t_colors <= 1 | |
8278 #ifdef FEAT_GUI | |
8279 || gui.in_use | |
8280 #endif | |
8281 || cterm_normal_bg_color == 0 || *T_UT != NUL)); | |
8282 } | |
8283 | |
8284 /* | |
8285 * Reset cursor position. Use whenever cursor was moved because of outputting | |
8286 * something directly to the screen (shell commands) or a terminal control | |
8287 * code. | |
8288 */ | |
8289 void | |
8290 screen_start() | |
8291 { | |
8292 screen_cur_row = screen_cur_col = 9999; | |
8293 } | |
8294 | |
8295 /* | |
8296 * Move the cursor to position "row","col" in the screen. | |
8297 * This tries to find the most efficient way to move, minimizing the number of | |
8298 * characters sent to the terminal. | |
8299 */ | |
8300 void | |
8301 windgoto(row, col) | |
8302 int row; | |
8303 int col; | |
8304 { | |
205 | 8305 sattr_T *p; |
7 | 8306 int i; |
8307 int plan; | |
8308 int cost; | |
8309 int wouldbe_col; | |
8310 int noinvcurs; | |
8311 char_u *bs; | |
8312 int goto_cost; | |
8313 int attr; | |
8314 | |
1213 | 8315 #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
7 | 8316 #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
8317 | |
8318 #define PLAN_LE 1 | |
8319 #define PLAN_CR 2 | |
8320 #define PLAN_NL 3 | |
8321 #define PLAN_WRITE 4 | |
8322 /* Can't use ScreenLines unless initialized */ | |
8323 if (ScreenLines == NULL) | |
8324 return; | |
8325 | |
8326 if (col != screen_cur_col || row != screen_cur_row) | |
8327 { | |
8328 /* Check for valid position. */ | |
8329 if (row < 0) /* window without text lines? */ | |
8330 row = 0; | |
8331 if (row >= screen_Rows) | |
8332 row = screen_Rows - 1; | |
8333 if (col >= screen_Columns) | |
8334 col = screen_Columns - 1; | |
8335 | |
8336 /* check if no cursor movement is allowed in highlight mode */ | |
8337 if (screen_attr && *T_MS == NUL) | |
8338 noinvcurs = HIGHL_COST; | |
8339 else | |
8340 noinvcurs = 0; | |
8341 goto_cost = GOTO_COST + noinvcurs; | |
8342 | |
8343 /* | |
8344 * Plan how to do the positioning: | |
8345 * 1. Use CR to move it to column 0, same row. | |
8346 * 2. Use T_LE to move it a few columns to the left. | |
8347 * 3. Use NL to move a few lines down, column 0. | |
8348 * 4. Move a few columns to the right with T_ND or by writing chars. | |
8349 * | |
8350 * Don't do this if the cursor went beyond the last column, the cursor | |
8351 * position is unknown then (some terminals wrap, some don't ) | |
8352 * | |
1213 | 8353 * First check if the highlighting attributes allow us to write |
7 | 8354 * characters to move the cursor to the right. |
8355 */ | |
8356 if (row >= screen_cur_row && screen_cur_col < Columns) | |
8357 { | |
8358 /* | |
8359 * If the cursor is in the same row, bigger col, we can use CR | |
8360 * or T_LE. | |
8361 */ | |
8362 bs = NULL; /* init for GCC */ | |
8363 attr = screen_attr; | |
8364 if (row == screen_cur_row && col < screen_cur_col) | |
8365 { | |
8366 /* "le" is preferred over "bc", because "bc" is obsolete */ | |
8367 if (*T_LE) | |
8368 bs = T_LE; /* "cursor left" */ | |
8369 else | |
8370 bs = T_BC; /* "backspace character (old) */ | |
8371 if (*bs) | |
8372 cost = (screen_cur_col - col) * (int)STRLEN(bs); | |
8373 else | |
8374 cost = 999; | |
8375 if (col + 1 < cost) /* using CR is less characters */ | |
8376 { | |
8377 plan = PLAN_CR; | |
8378 wouldbe_col = 0; | |
8379 cost = 1; /* CR is just one character */ | |
8380 } | |
8381 else | |
8382 { | |
8383 plan = PLAN_LE; | |
8384 wouldbe_col = col; | |
8385 } | |
8386 if (noinvcurs) /* will stop highlighting */ | |
8387 { | |
8388 cost += noinvcurs; | |
8389 attr = 0; | |
8390 } | |
8391 } | |
8392 | |
8393 /* | |
8394 * If the cursor is above where we want to be, we can use CR LF. | |
8395 */ | |
8396 else if (row > screen_cur_row) | |
8397 { | |
8398 plan = PLAN_NL; | |
8399 wouldbe_col = 0; | |
8400 cost = (row - screen_cur_row) * 2; /* CR LF */ | |
8401 if (noinvcurs) /* will stop highlighting */ | |
8402 { | |
8403 cost += noinvcurs; | |
8404 attr = 0; | |
8405 } | |
8406 } | |
8407 | |
8408 /* | |
8409 * If the cursor is in the same row, smaller col, just use write. | |
8410 */ | |
8411 else | |
8412 { | |
8413 plan = PLAN_WRITE; | |
8414 wouldbe_col = screen_cur_col; | |
8415 cost = 0; | |
8416 } | |
8417 | |
8418 /* | |
8419 * Check if any characters that need to be written have the | |
8420 * correct attributes. Also avoid UTF-8 characters. | |
8421 */ | |
8422 i = col - wouldbe_col; | |
8423 if (i > 0) | |
8424 cost += i; | |
8425 if (cost < goto_cost && i > 0) | |
8426 { | |
8427 /* | |
8428 * Check if the attributes are correct without additionally | |
8429 * stopping highlighting. | |
8430 */ | |
8431 p = ScreenAttrs + LineOffset[row] + wouldbe_col; | |
8432 while (i && *p++ == attr) | |
8433 --i; | |
8434 if (i != 0) | |
8435 { | |
8436 /* | |
8437 * Try if it works when highlighting is stopped here. | |
8438 */ | |
8439 if (*--p == 0) | |
8440 { | |
8441 cost += noinvcurs; | |
8442 while (i && *p++ == 0) | |
8443 --i; | |
8444 } | |
8445 if (i != 0) | |
8446 cost = 999; /* different attributes, don't do it */ | |
8447 } | |
8448 #ifdef FEAT_MBYTE | |
8449 if (enc_utf8) | |
8450 { | |
8451 /* Don't use an UTF-8 char for positioning, it's slow. */ | |
8452 for (i = wouldbe_col; i < col; ++i) | |
8453 if (ScreenLinesUC[LineOffset[row] + i] != 0) | |
8454 { | |
8455 cost = 999; | |
8456 break; | |
8457 } | |
8458 } | |
8459 #endif | |
8460 } | |
8461 | |
8462 /* | |
8463 * We can do it without term_windgoto()! | |
8464 */ | |
8465 if (cost < goto_cost) | |
8466 { | |
8467 if (plan == PLAN_LE) | |
8468 { | |
8469 if (noinvcurs) | |
8470 screen_stop_highlight(); | |
8471 while (screen_cur_col > col) | |
8472 { | |
8473 out_str(bs); | |
8474 --screen_cur_col; | |
8475 } | |
8476 } | |
8477 else if (plan == PLAN_CR) | |
8478 { | |
8479 if (noinvcurs) | |
8480 screen_stop_highlight(); | |
8481 out_char('\r'); | |
8482 screen_cur_col = 0; | |
8483 } | |
8484 else if (plan == PLAN_NL) | |
8485 { | |
8486 if (noinvcurs) | |
8487 screen_stop_highlight(); | |
8488 while (screen_cur_row < row) | |
8489 { | |
8490 out_char('\n'); | |
8491 ++screen_cur_row; | |
8492 } | |
8493 screen_cur_col = 0; | |
8494 } | |
8495 | |
8496 i = col - screen_cur_col; | |
8497 if (i > 0) | |
8498 { | |
8499 /* | |
8500 * Use cursor-right if it's one character only. Avoids | |
8501 * removing a line of pixels from the last bold char, when | |
8502 * using the bold trick in the GUI. | |
8503 */ | |
8504 if (T_ND[0] != NUL && T_ND[1] == NUL) | |
8505 { | |
8506 while (i-- > 0) | |
8507 out_char(*T_ND); | |
8508 } | |
8509 else | |
8510 { | |
8511 int off; | |
8512 | |
8513 off = LineOffset[row] + screen_cur_col; | |
8514 while (i-- > 0) | |
8515 { | |
8516 if (ScreenAttrs[off] != screen_attr) | |
8517 screen_stop_highlight(); | |
8518 #ifdef FEAT_MBYTE | |
8519 out_flush_check(); | |
8520 #endif | |
8521 out_char(ScreenLines[off]); | |
8522 #ifdef FEAT_MBYTE | |
8523 if (enc_dbcs == DBCS_JPNU | |
8524 && ScreenLines[off] == 0x8e) | |
8525 out_char(ScreenLines2[off]); | |
8526 #endif | |
8527 ++off; | |
8528 } | |
8529 } | |
8530 } | |
8531 } | |
8532 } | |
8533 else | |
8534 cost = 999; | |
8535 | |
8536 if (cost >= goto_cost) | |
8537 { | |
8538 if (noinvcurs) | |
8539 screen_stop_highlight(); | |
8540 if (row == screen_cur_row && (col > screen_cur_col) && | |
8541 *T_CRI != NUL) | |
8542 term_cursor_right(col - screen_cur_col); | |
8543 else | |
8544 term_windgoto(row, col); | |
8545 } | |
8546 screen_cur_row = row; | |
8547 screen_cur_col = col; | |
8548 } | |
8549 } | |
8550 | |
8551 /* | |
8552 * Set cursor to its position in the current window. | |
8553 */ | |
8554 void | |
8555 setcursor() | |
8556 { | |
8557 if (redrawing()) | |
8558 { | |
8559 validate_cursor(); | |
8560 windgoto(W_WINROW(curwin) + curwin->w_wrow, | |
8561 W_WINCOL(curwin) + ( | |
8562 #ifdef FEAT_RIGHTLEFT | |
1545 | 8563 /* With 'rightleft' set and the cursor on a double-wide |
8564 * character, position it on the leftmost column. */ | |
7 | 8565 curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
8566 # ifdef FEAT_MBYTE | |
1545 | 8567 (has_mbyte |
8568 && (*mb_ptr2cells)(ml_get_cursor()) == 2 | |
8569 && vim_isprintc(gchar_cursor())) ? 2 : | |
7 | 8570 # endif |
8571 1)) : | |
8572 #endif | |
8573 curwin->w_wcol)); | |
8574 } | |
8575 } | |
8576 | |
8577 | |
8578 /* | |
8579 * insert 'line_count' lines at 'row' in window 'wp' | |
8580 * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. | |
8581 * if 'mayclear' is TRUE the screen will be cleared if it is faster than | |
8582 * scrolling. | |
8583 * Returns FAIL if the lines are not inserted, OK for success. | |
8584 */ | |
8585 int | |
8586 win_ins_lines(wp, row, line_count, invalid, mayclear) | |
8587 win_T *wp; | |
8588 int row; | |
8589 int line_count; | |
8590 int invalid; | |
8591 int mayclear; | |
8592 { | |
8593 int did_delete; | |
8594 int nextrow; | |
8595 int lastrow; | |
8596 int retval; | |
8597 | |
8598 if (invalid) | |
8599 wp->w_lines_valid = 0; | |
8600 | |
8601 if (wp->w_height < 5) | |
8602 return FAIL; | |
8603 | |
8604 if (line_count > wp->w_height - row) | |
8605 line_count = wp->w_height - row; | |
8606 | |
8607 retval = win_do_lines(wp, row, line_count, mayclear, FALSE); | |
8608 if (retval != MAYBE) | |
8609 return retval; | |
8610 | |
8611 /* | |
8612 * If there is a next window or a status line, we first try to delete the | |
8613 * lines at the bottom to avoid messing what is after the window. | |
8614 * If this fails and there are following windows, don't do anything to avoid | |
8615 * messing up those windows, better just redraw. | |
8616 */ | |
8617 did_delete = FALSE; | |
8618 #ifdef FEAT_WINDOWS | |
8619 if (wp->w_next != NULL || wp->w_status_height) | |
8620 { | |
8621 if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8622 line_count, (int)Rows, FALSE, NULL) == OK) | |
8623 did_delete = TRUE; | |
8624 else if (wp->w_next) | |
8625 return FAIL; | |
8626 } | |
8627 #endif | |
8628 /* | |
8629 * if no lines deleted, blank the lines that will end up below the window | |
8630 */ | |
8631 if (!did_delete) | |
8632 { | |
8633 #ifdef FEAT_WINDOWS | |
8634 wp->w_redr_status = TRUE; | |
8635 #endif | |
8636 redraw_cmdline = TRUE; | |
8637 nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); | |
8638 lastrow = nextrow + line_count; | |
8639 if (lastrow > Rows) | |
8640 lastrow = Rows; | |
8641 screen_fill(nextrow - line_count, lastrow - line_count, | |
8642 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8643 ' ', ' ', 0); | |
8644 } | |
8645 | |
8646 if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) | |
8647 == FAIL) | |
8648 { | |
8649 /* deletion will have messed up other windows */ | |
8650 if (did_delete) | |
8651 { | |
8652 #ifdef FEAT_WINDOWS | |
8653 wp->w_redr_status = TRUE; | |
8654 #endif | |
8655 win_rest_invalid(W_NEXT(wp)); | |
8656 } | |
8657 return FAIL; | |
8658 } | |
8659 | |
8660 return OK; | |
8661 } | |
8662 | |
8663 /* | |
8664 * delete "line_count" window lines at "row" in window "wp" | |
8665 * If "invalid" is TRUE curwin->w_lines[] is invalidated. | |
8666 * If "mayclear" is TRUE the screen will be cleared if it is faster than | |
8667 * scrolling | |
8668 * Return OK for success, FAIL if the lines are not deleted. | |
8669 */ | |
8670 int | |
8671 win_del_lines(wp, row, line_count, invalid, mayclear) | |
8672 win_T *wp; | |
8673 int row; | |
8674 int line_count; | |
8675 int invalid; | |
8676 int mayclear; | |
8677 { | |
8678 int retval; | |
8679 | |
8680 if (invalid) | |
8681 wp->w_lines_valid = 0; | |
8682 | |
8683 if (line_count > wp->w_height - row) | |
8684 line_count = wp->w_height - row; | |
8685 | |
8686 retval = win_do_lines(wp, row, line_count, mayclear, TRUE); | |
8687 if (retval != MAYBE) | |
8688 return retval; | |
8689 | |
8690 if (screen_del_lines(0, W_WINROW(wp) + row, line_count, | |
8691 (int)Rows, FALSE, NULL) == FAIL) | |
8692 return FAIL; | |
8693 | |
8694 #ifdef FEAT_WINDOWS | |
8695 /* | |
8696 * If there are windows or status lines below, try to put them at the | |
8697 * correct place. If we can't do that, they have to be redrawn. | |
8698 */ | |
8699 if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) | |
8700 { | |
8701 if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, | |
8702 line_count, (int)Rows, NULL) == FAIL) | |
8703 { | |
8704 wp->w_redr_status = TRUE; | |
8705 win_rest_invalid(wp->w_next); | |
8706 } | |
8707 } | |
8708 /* | |
8709 * If this is the last window and there is no status line, redraw the | |
8710 * command line later. | |
8711 */ | |
8712 else | |
8713 #endif | |
8714 redraw_cmdline = TRUE; | |
8715 return OK; | |
8716 } | |
8717 | |
8718 /* | |
8719 * Common code for win_ins_lines() and win_del_lines(). | |
8720 * Returns OK or FAIL when the work has been done. | |
8721 * Returns MAYBE when not finished yet. | |
8722 */ | |
8723 static int | |
8724 win_do_lines(wp, row, line_count, mayclear, del) | |
8725 win_T *wp; | |
8726 int row; | |
8727 int line_count; | |
8728 int mayclear; | |
8729 int del; | |
8730 { | |
8731 int retval; | |
8732 | |
8733 if (!redrawing() || line_count <= 0) | |
8734 return FAIL; | |
8735 | |
8736 /* only a few lines left: redraw is faster */ | |
8737 if (mayclear && Rows - line_count < 5 | |
8738 #ifdef FEAT_VERTSPLIT | |
8739 && wp->w_width == Columns | |
8740 #endif | |
8741 ) | |
8742 { | |
8743 screenclear(); /* will set wp->w_lines_valid to 0 */ | |
8744 return FAIL; | |
8745 } | |
8746 | |
8747 /* | |
8748 * Delete all remaining lines | |
8749 */ | |
8750 if (row + line_count >= wp->w_height) | |
8751 { | |
8752 screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, | |
8753 W_WINCOL(wp), (int)W_ENDCOL(wp), | |
8754 ' ', ' ', 0); | |
8755 return OK; | |
8756 } | |
8757 | |
8758 /* | |
8759 * when scrolling, the message on the command line should be cleared, | |
8760 * otherwise it will stay there forever. | |
8761 */ | |
8762 clear_cmdline = TRUE; | |
8763 | |
8764 /* | |
8765 * If the terminal can set a scroll region, use that. | |
8766 * Always do this in a vertically split window. This will redraw from | |
8767 * ScreenLines[] when t_CV isn't defined. That's faster than using | |
8768 * win_line(). | |
8769 * Don't use a scroll region when we are going to redraw the text, writing | |
8770 * a character in the lower right corner of the scroll region causes a | |
8771 * scroll-up in the DJGPP version. | |
8772 */ | |
8773 if (scroll_region | |
8774 #ifdef FEAT_VERTSPLIT | |
8775 || W_WIDTH(wp) != Columns | |
8776 #endif | |
8777 ) | |
8778 { | |
8779 #ifdef FEAT_VERTSPLIT | |
8780 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8781 #endif | |
8782 scroll_region_set(wp, row); | |
8783 if (del) | |
8784 retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, | |
8785 wp->w_height - row, FALSE, wp); | |
8786 else | |
8787 retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, | |
8788 wp->w_height - row, wp); | |
8789 #ifdef FEAT_VERTSPLIT | |
8790 if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) | |
8791 #endif | |
8792 scroll_region_reset(); | |
8793 return retval; | |
8794 } | |
8795 | |
8796 #ifdef FEAT_WINDOWS | |
8797 if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ | |
8798 return FAIL; | |
8799 #endif | |
8800 | |
8801 return MAYBE; | |
8802 } | |
8803 | |
8804 /* | |
8805 * window 'wp' and everything after it is messed up, mark it for redraw | |
8806 */ | |
8807 static void | |
8808 win_rest_invalid(wp) | |
8809 win_T *wp; | |
8810 { | |
8811 #ifdef FEAT_WINDOWS | |
8812 while (wp != NULL) | |
8813 #else | |
8814 if (wp != NULL) | |
8815 #endif | |
8816 { | |
8817 redraw_win_later(wp, NOT_VALID); | |
8818 #ifdef FEAT_WINDOWS | |
8819 wp->w_redr_status = TRUE; | |
8820 wp = wp->w_next; | |
8821 #endif | |
8822 } | |
8823 redraw_cmdline = TRUE; | |
8824 } | |
8825 | |
8826 /* | |
8827 * The rest of the routines in this file perform screen manipulations. The | |
8828 * given operation is performed physically on the screen. The corresponding | |
8829 * change is also made to the internal screen image. In this way, the editor | |
8830 * anticipates the effect of editing changes on the appearance of the screen. | |
8831 * That way, when we call screenupdate a complete redraw isn't usually | |
8832 * necessary. Another advantage is that we can keep adding code to anticipate | |
8833 * screen changes, and in the meantime, everything still works. | |
8834 */ | |
8835 | |
8836 /* | |
8837 * types for inserting or deleting lines | |
8838 */ | |
8839 #define USE_T_CAL 1 | |
8840 #define USE_T_CDL 2 | |
8841 #define USE_T_AL 3 | |
8842 #define USE_T_CE 4 | |
8843 #define USE_T_DL 5 | |
8844 #define USE_T_SR 6 | |
8845 #define USE_NL 7 | |
8846 #define USE_T_CD 8 | |
8847 #define USE_REDRAW 9 | |
8848 | |
8849 /* | |
8850 * insert lines on the screen and update ScreenLines[] | |
8851 * 'end' is the line after the scrolled part. Normally it is Rows. | |
8852 * When scrolling region used 'off' is the offset from the top for the region. | |
8853 * 'row' and 'end' are relative to the start of the region. | |
8854 * | |
8855 * return FAIL for failure, OK for success. | |
8856 */ | |
446 | 8857 int |
7 | 8858 screen_ins_lines(off, row, line_count, end, wp) |
8859 int off; | |
8860 int row; | |
8861 int line_count; | |
8862 int end; | |
8863 win_T *wp; /* NULL or window to use width from */ | |
8864 { | |
8865 int i; | |
8866 int j; | |
8867 unsigned temp; | |
8868 int cursor_row; | |
8869 int type; | |
8870 int result_empty; | |
8871 int can_ce = can_clear(T_CE); | |
8872 | |
8873 /* | |
8874 * FAIL if | |
8875 * - there is no valid screen | |
8876 * - the screen has to be redrawn completely | |
8877 * - the line count is less than one | |
8878 * - the line count is more than 'ttyscroll' | |
8879 */ | |
8880 if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) | |
8881 return FAIL; | |
8882 | |
8883 /* | |
8884 * There are seven ways to insert lines: | |
8885 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
8886 * characters from ScreenLines[]. | |
8887 * 1. Use T_CD (clear to end of display) if it exists and the result of | |
8888 * the insert is just empty lines | |
8889 * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not | |
8890 * present or line_count > 1. It looks better if we do all the inserts | |
8891 * at once. | |
8892 * 3. Use T_CDL (delete multiple lines) if it exists and the result of the | |
8893 * insert is just empty lines and T_CE is not present or line_count > | |
8894 * 1. | |
8895 * 4. Use T_AL (insert line) if it exists. | |
8896 * 5. Use T_CE (erase line) if it exists and the result of the insert is | |
8897 * just empty lines. | |
8898 * 6. Use T_DL (delete line) if it exists and the result of the insert is | |
8899 * just empty lines. | |
8900 * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and | |
8901 * the 'da' flag is not set or we have clear line capability. | |
8902 * 8. redraw the characters from ScreenLines[]. | |
8903 * | |
8904 * Careful: In a hpterm scroll reverse doesn't work as expected, it moves | |
8905 * the scrollbar for the window. It does have insert line, use that if it | |
8906 * exists. | |
8907 */ | |
8908 result_empty = (row + line_count >= end); | |
8909 #ifdef FEAT_VERTSPLIT | |
8910 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
8911 type = USE_REDRAW; | |
8912 else | |
8913 #endif | |
8914 if (can_clear(T_CD) && result_empty) | |
8915 type = USE_T_CD; | |
8916 else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) | |
8917 type = USE_T_CAL; | |
8918 else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) | |
8919 type = USE_T_CDL; | |
8920 else if (*T_AL != NUL) | |
8921 type = USE_T_AL; | |
8922 else if (can_ce && result_empty) | |
8923 type = USE_T_CE; | |
8924 else if (*T_DL != NUL && result_empty) | |
8925 type = USE_T_DL; | |
8926 else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) | |
8927 type = USE_T_SR; | |
8928 else | |
8929 return FAIL; | |
8930 | |
8931 /* | |
8932 * For clearing the lines screen_del_lines() is used. This will also take | |
8933 * care of t_db if necessary. | |
8934 */ | |
8935 if (type == USE_T_CD || type == USE_T_CDL || | |
8936 type == USE_T_CE || type == USE_T_DL) | |
8937 return screen_del_lines(off, row, line_count, end, FALSE, wp); | |
8938 | |
8939 /* | |
8940 * If text is retained below the screen, first clear or delete as many | |
8941 * lines at the bottom of the window as are about to be inserted so that | |
8942 * the deleted lines won't later surface during a screen_del_lines. | |
8943 */ | |
8944 if (*T_DB) | |
8945 screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); | |
8946 | |
8947 #ifdef FEAT_CLIPBOARD | |
8948 /* Remove a modeless selection when inserting lines halfway the screen | |
8949 * or not the full width of the screen. */ | |
8950 if (off + row > 0 | |
8951 # ifdef FEAT_VERTSPLIT | |
8952 || (wp != NULL && wp->w_width != Columns) | |
8953 # endif | |
8954 ) | |
8955 clip_clear_selection(); | |
8956 else | |
8957 clip_scroll_selection(-line_count); | |
8958 #endif | |
8959 | |
8960 #ifdef FEAT_GUI | |
8961 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
8962 * scrolling is actually carried out. */ | |
8963 gui_dont_update_cursor(); | |
8964 #endif | |
8965 | |
8966 if (*T_CCS != NUL) /* cursor relative to region */ | |
8967 cursor_row = row; | |
8968 else | |
8969 cursor_row = row + off; | |
8970 | |
8971 /* | |
8972 * Shift LineOffset[] line_count down to reflect the inserted lines. | |
8973 * Clear the inserted lines in ScreenLines[]. | |
8974 */ | |
8975 row += off; | |
8976 end += off; | |
8977 for (i = 0; i < line_count; ++i) | |
8978 { | |
8979 #ifdef FEAT_VERTSPLIT | |
8980 if (wp != NULL && wp->w_width != Columns) | |
8981 { | |
8982 /* need to copy part of a line */ | |
8983 j = end - 1 - i; | |
8984 while ((j -= line_count) >= row) | |
8985 linecopy(j + line_count, j, wp); | |
8986 j += line_count; | |
8987 if (can_clear((char_u *)" ")) | |
8988 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8989 else | |
8990 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
8991 LineWraps[j] = FALSE; | |
8992 } | |
8993 else | |
8994 #endif | |
8995 { | |
8996 j = end - 1 - i; | |
8997 temp = LineOffset[j]; | |
8998 while ((j -= line_count) >= row) | |
8999 { | |
9000 LineOffset[j + line_count] = LineOffset[j]; | |
9001 LineWraps[j + line_count] = LineWraps[j]; | |
9002 } | |
9003 LineOffset[j + line_count] = temp; | |
9004 LineWraps[j + line_count] = FALSE; | |
9005 if (can_clear((char_u *)" ")) | |
9006 lineclear(temp, (int)Columns); | |
9007 else | |
9008 lineinvalid(temp, (int)Columns); | |
9009 } | |
9010 } | |
9011 | |
9012 screen_stop_highlight(); | |
9013 windgoto(cursor_row, 0); | |
9014 | |
9015 #ifdef FEAT_VERTSPLIT | |
9016 /* redraw the characters */ | |
9017 if (type == USE_REDRAW) | |
9018 redraw_block(row, end, wp); | |
9019 else | |
9020 #endif | |
9021 if (type == USE_T_CAL) | |
9022 { | |
9023 term_append_lines(line_count); | |
9024 screen_start(); /* don't know where cursor is now */ | |
9025 } | |
9026 else | |
9027 { | |
9028 for (i = 0; i < line_count; i++) | |
9029 { | |
9030 if (type == USE_T_AL) | |
9031 { | |
9032 if (i && cursor_row != 0) | |
9033 windgoto(cursor_row, 0); | |
9034 out_str(T_AL); | |
9035 } | |
9036 else /* type == USE_T_SR */ | |
9037 out_str(T_SR); | |
9038 screen_start(); /* don't know where cursor is now */ | |
9039 } | |
9040 } | |
9041 | |
9042 /* | |
9043 * With scroll-reverse and 'da' flag set we need to clear the lines that | |
9044 * have been scrolled down into the region. | |
9045 */ | |
9046 if (type == USE_T_SR && *T_DA) | |
9047 { | |
9048 for (i = 0; i < line_count; ++i) | |
9049 { | |
9050 windgoto(off + i, 0); | |
9051 out_str(T_CE); | |
9052 screen_start(); /* don't know where cursor is now */ | |
9053 } | |
9054 } | |
9055 | |
9056 #ifdef FEAT_GUI | |
9057 gui_can_update_cursor(); | |
9058 if (gui.in_use) | |
9059 out_flush(); /* always flush after a scroll */ | |
9060 #endif | |
9061 return OK; | |
9062 } | |
9063 | |
9064 /* | |
9065 * delete lines on the screen and update ScreenLines[] | |
9066 * 'end' is the line after the scrolled part. Normally it is Rows. | |
9067 * When scrolling region used 'off' is the offset from the top for the region. | |
9068 * 'row' and 'end' are relative to the start of the region. | |
9069 * | |
9070 * Return OK for success, FAIL if the lines are not deleted. | |
9071 */ | |
9072 int | |
9073 screen_del_lines(off, row, line_count, end, force, wp) | |
9074 int off; | |
9075 int row; | |
9076 int line_count; | |
9077 int end; | |
9078 int force; /* even when line_count > p_ttyscroll */ | |
1883 | 9079 win_T *wp UNUSED; /* NULL or window to use width from */ |
7 | 9080 { |
9081 int j; | |
9082 int i; | |
9083 unsigned temp; | |
9084 int cursor_row; | |
9085 int cursor_end; | |
9086 int result_empty; /* result is empty until end of region */ | |
9087 int can_delete; /* deleting line codes can be used */ | |
9088 int type; | |
9089 | |
9090 /* | |
9091 * FAIL if | |
9092 * - there is no valid screen | |
9093 * - the screen has to be redrawn completely | |
9094 * - the line count is less than one | |
9095 * - the line count is more than 'ttyscroll' | |
9096 */ | |
9097 if (!screen_valid(TRUE) || line_count <= 0 || | |
9098 (!force && line_count > p_ttyscroll)) | |
9099 return FAIL; | |
9100 | |
9101 /* | |
9102 * Check if the rest of the current region will become empty. | |
9103 */ | |
9104 result_empty = row + line_count >= end; | |
9105 | |
9106 /* | |
9107 * We can delete lines only when 'db' flag not set or when 'ce' option | |
9108 * available. | |
9109 */ | |
9110 can_delete = (*T_DB == NUL || can_clear(T_CE)); | |
9111 | |
9112 /* | |
9113 * There are six ways to delete lines: | |
9114 * 0. When in a vertically split window and t_CV isn't set, redraw the | |
9115 * characters from ScreenLines[]. | |
9116 * 1. Use T_CD if it exists and the result is empty. | |
9117 * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. | |
9118 * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or | |
9119 * none of the other ways work. | |
9120 * 4. Use T_CE (erase line) if the result is empty. | |
9121 * 5. Use T_DL (delete line) if it exists. | |
9122 * 6. redraw the characters from ScreenLines[]. | |
9123 */ | |
9124 #ifdef FEAT_VERTSPLIT | |
9125 if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) | |
9126 type = USE_REDRAW; | |
9127 else | |
9128 #endif | |
9129 if (can_clear(T_CD) && result_empty) | |
9130 type = USE_T_CD; | |
9131 #if defined(__BEOS__) && defined(BEOS_DR8) | |
9132 /* | |
9133 * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in | |
9134 * its internal termcap... this works okay for tests which test *T_DB != | |
9135 * NUL. It has the disadvantage that the user cannot use any :set t_* | |
9136 * command to get T_DB (back) to empty_option, only :set term=... will do | |
9137 * the trick... | |
9138 * Anyway, this hack will hopefully go away with the next OS release. | |
9139 * (Olaf Seibert) | |
9140 */ | |
9141 else if (row == 0 && T_DB == empty_option | |
9142 && (line_count == 1 || *T_CDL == NUL)) | |
9143 #else | |
9144 else if (row == 0 && ( | |
9145 #ifndef AMIGA | |
9146 /* On the Amiga, somehow '\n' on the last line doesn't always scroll | |
9147 * up, so use delete-line command */ | |
9148 line_count == 1 || | |
9149 #endif | |
9150 *T_CDL == NUL)) | |
9151 #endif | |
9152 type = USE_NL; | |
9153 else if (*T_CDL != NUL && line_count > 1 && can_delete) | |
9154 type = USE_T_CDL; | |
9155 else if (can_clear(T_CE) && result_empty | |
9156 #ifdef FEAT_VERTSPLIT | |
9157 && (wp == NULL || wp->w_width == Columns) | |
9158 #endif | |
9159 ) | |
9160 type = USE_T_CE; | |
9161 else if (*T_DL != NUL && can_delete) | |
9162 type = USE_T_DL; | |
9163 else if (*T_CDL != NUL && can_delete) | |
9164 type = USE_T_CDL; | |
9165 else | |
9166 return FAIL; | |
9167 | |
9168 #ifdef FEAT_CLIPBOARD | |
9169 /* Remove a modeless selection when deleting lines halfway the screen or | |
9170 * not the full width of the screen. */ | |
9171 if (off + row > 0 | |
9172 # ifdef FEAT_VERTSPLIT | |
9173 || (wp != NULL && wp->w_width != Columns) | |
9174 # endif | |
9175 ) | |
9176 clip_clear_selection(); | |
9177 else | |
9178 clip_scroll_selection(line_count); | |
9179 #endif | |
9180 | |
9181 #ifdef FEAT_GUI | |
9182 /* Don't update the GUI cursor here, ScreenLines[] is invalid until the | |
9183 * scrolling is actually carried out. */ | |
9184 gui_dont_update_cursor(); | |
9185 #endif | |
9186 | |
9187 if (*T_CCS != NUL) /* cursor relative to region */ | |
9188 { | |
9189 cursor_row = row; | |
9190 cursor_end = end; | |
9191 } | |
9192 else | |
9193 { | |
9194 cursor_row = row + off; | |
9195 cursor_end = end + off; | |
9196 } | |
9197 | |
9198 /* | |
9199 * Now shift LineOffset[] line_count up to reflect the deleted lines. | |
9200 * Clear the inserted lines in ScreenLines[]. | |
9201 */ | |
9202 row += off; | |
9203 end += off; | |
9204 for (i = 0; i < line_count; ++i) | |
9205 { | |
9206 #ifdef FEAT_VERTSPLIT | |
9207 if (wp != NULL && wp->w_width != Columns) | |
9208 { | |
9209 /* need to copy part of a line */ | |
9210 j = row + i; | |
9211 while ((j += line_count) <= end - 1) | |
9212 linecopy(j - line_count, j, wp); | |
9213 j -= line_count; | |
9214 if (can_clear((char_u *)" ")) | |
9215 lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9216 else | |
9217 lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); | |
9218 LineWraps[j] = FALSE; | |
9219 } | |
9220 else | |
9221 #endif | |
9222 { | |
9223 /* whole width, moving the line pointers is faster */ | |
9224 j = row + i; | |
9225 temp = LineOffset[j]; | |
9226 while ((j += line_count) <= end - 1) | |
9227 { | |
9228 LineOffset[j - line_count] = LineOffset[j]; | |
9229 LineWraps[j - line_count] = LineWraps[j]; | |
9230 } | |
9231 LineOffset[j - line_count] = temp; | |
9232 LineWraps[j - line_count] = FALSE; | |
9233 if (can_clear((char_u *)" ")) | |
9234 lineclear(temp, (int)Columns); | |
9235 else | |
9236 lineinvalid(temp, (int)Columns); | |
9237 } | |
9238 } | |
9239 | |
9240 screen_stop_highlight(); | |
9241 | |
9242 #ifdef FEAT_VERTSPLIT | |
9243 /* redraw the characters */ | |
9244 if (type == USE_REDRAW) | |
9245 redraw_block(row, end, wp); | |
9246 else | |
9247 #endif | |
9248 if (type == USE_T_CD) /* delete the lines */ | |
9249 { | |
9250 windgoto(cursor_row, 0); | |
9251 out_str(T_CD); | |
9252 screen_start(); /* don't know where cursor is now */ | |
9253 } | |
9254 else if (type == USE_T_CDL) | |
9255 { | |
9256 windgoto(cursor_row, 0); | |
9257 term_delete_lines(line_count); | |
9258 screen_start(); /* don't know where cursor is now */ | |
9259 } | |
9260 /* | |
9261 * Deleting lines at top of the screen or scroll region: Just scroll | |
9262 * the whole screen (scroll region) up by outputting newlines on the | |
9263 * last line. | |
9264 */ | |
9265 else if (type == USE_NL) | |
9266 { | |
9267 windgoto(cursor_end - 1, 0); | |
9268 for (i = line_count; --i >= 0; ) | |
9269 out_char('\n'); /* cursor will remain on same line */ | |
9270 } | |
9271 else | |
9272 { | |
9273 for (i = line_count; --i >= 0; ) | |
9274 { | |
9275 if (type == USE_T_DL) | |
9276 { | |
9277 windgoto(cursor_row, 0); | |
9278 out_str(T_DL); /* delete a line */ | |
9279 } | |
9280 else /* type == USE_T_CE */ | |
9281 { | |
9282 windgoto(cursor_row + i, 0); | |
9283 out_str(T_CE); /* erase a line */ | |
9284 } | |
9285 screen_start(); /* don't know where cursor is now */ | |
9286 } | |
9287 } | |
9288 | |
9289 /* | |
9290 * If the 'db' flag is set, we need to clear the lines that have been | |
9291 * scrolled up at the bottom of the region. | |
9292 */ | |
9293 if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) | |
9294 { | |
9295 for (i = line_count; i > 0; --i) | |
9296 { | |
9297 windgoto(cursor_end - i, 0); | |
9298 out_str(T_CE); /* erase a line */ | |
9299 screen_start(); /* don't know where cursor is now */ | |
9300 } | |
9301 } | |
9302 | |
9303 #ifdef FEAT_GUI | |
9304 gui_can_update_cursor(); | |
9305 if (gui.in_use) | |
9306 out_flush(); /* always flush after a scroll */ | |
9307 #endif | |
9308 | |
9309 return OK; | |
9310 } | |
9311 | |
9312 /* | |
9313 * show the current mode and ruler | |
9314 * | |
9315 * If clear_cmdline is TRUE, clear the rest of the cmdline. | |
9316 * If clear_cmdline is FALSE there may be a message there that needs to be | |
9317 * cleared only if a mode is shown. | |
9318 * Return the length of the message (0 if no message). | |
9319 */ | |
9320 int | |
9321 showmode() | |
9322 { | |
9323 int need_clear; | |
9324 int length = 0; | |
9325 int do_mode; | |
9326 int attr; | |
9327 int nwr_save; | |
9328 #ifdef FEAT_INS_EXPAND | |
9329 int sub_attr; | |
9330 #endif | |
9331 | |
642 | 9332 do_mode = ((p_smd && msg_silent == 0) |
9333 && ((State & INSERT) | |
9334 || restart_edit | |
7 | 9335 #ifdef FEAT_VISUAL |
9336 || VIsual_active | |
9337 #endif | |
9338 )); | |
9339 if (do_mode || Recording) | |
9340 { | |
9341 /* | |
9342 * Don't show mode right now, when not redrawing or inside a mapping. | |
9343 * Call char_avail() only when we are going to show something, because | |
9344 * it takes a bit of time. | |
9345 */ | |
9346 if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) | |
9347 { | |
9348 redraw_cmdline = TRUE; /* show mode later */ | |
9349 return 0; | |
9350 } | |
9351 | |
9352 nwr_save = need_wait_return; | |
9353 | |
9354 /* wait a bit before overwriting an important message */ | |
9355 check_for_delay(FALSE); | |
9356 | |
9357 /* if the cmdline is more than one line high, erase top lines */ | |
9358 need_clear = clear_cmdline; | |
9359 if (clear_cmdline && cmdline_row < Rows - 1) | |
9360 msg_clr_cmdline(); /* will reset clear_cmdline */ | |
9361 | |
9362 /* Position on the last line in the window, column 0 */ | |
9363 msg_pos_mode(); | |
9364 cursor_off(); | |
9365 attr = hl_attr(HLF_CM); /* Highlight mode */ | |
9366 if (do_mode) | |
9367 { | |
9368 MSG_PUTS_ATTR("--", attr); | |
9369 #if defined(FEAT_XIM) | |
1668 | 9370 # if 0 /* old version, changed by SungHyun Nam July 2008 */ |
7 | 9371 if (xic != NULL && im_get_status() && !p_imdisable |
9372 && curbuf->b_p_iminsert == B_IMODE_IM) | |
1668 | 9373 # else |
9374 if ( | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9375 # ifdef FEAT_GUI_GTK |
1668 | 9376 preedit_get_status() |
9377 # else | |
9378 im_get_status() | |
9379 # endif | |
9380 ) | |
9381 # endif | |
2277
f42e0b5ff9e9
Change remaining HAVE_GTK2 to FEAT_GUI_GTK.
Bram Moolenaar <bram@vim.org>
parents:
2269
diff
changeset
|
9382 # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
7 | 9383 MSG_PUTS_ATTR(" IM", attr); |
9384 # else | |
9385 MSG_PUTS_ATTR(" XIM", attr); | |
9386 # endif | |
9387 #endif | |
9388 #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) | |
9389 if (gui.in_use) | |
9390 { | |
9391 if (hangul_input_state_get()) | |
236 | 9392 MSG_PUTS_ATTR(" \307\321\261\333", attr); /* HANGUL */ |
7 | 9393 } |
9394 #endif | |
9395 #ifdef FEAT_INS_EXPAND | |
9396 if (edit_submode != NULL) /* CTRL-X in Insert mode */ | |
9397 { | |
9398 /* These messages can get long, avoid a wrap in a narrow | |
9399 * window. Prefer showing edit_submode_extra. */ | |
9400 length = (Rows - msg_row) * Columns - 3; | |
9401 if (edit_submode_extra != NULL) | |
9402 length -= vim_strsize(edit_submode_extra); | |
9403 if (length > 0) | |
9404 { | |
9405 if (edit_submode_pre != NULL) | |
9406 length -= vim_strsize(edit_submode_pre); | |
9407 if (length - vim_strsize(edit_submode) > 0) | |
9408 { | |
9409 if (edit_submode_pre != NULL) | |
9410 msg_puts_attr(edit_submode_pre, attr); | |
9411 msg_puts_attr(edit_submode, attr); | |
9412 } | |
9413 if (edit_submode_extra != NULL) | |
9414 { | |
9415 MSG_PUTS_ATTR(" ", attr); /* add a space in between */ | |
9416 if ((int)edit_submode_highl < (int)HLF_COUNT) | |
9417 sub_attr = hl_attr(edit_submode_highl); | |
9418 else | |
9419 sub_attr = attr; | |
9420 msg_puts_attr(edit_submode_extra, sub_attr); | |
9421 } | |
9422 } | |
9423 length = 0; | |
9424 } | |
9425 else | |
9426 #endif | |
9427 { | |
9428 #ifdef FEAT_VREPLACE | |
9429 if (State & VREPLACE_FLAG) | |
9430 MSG_PUTS_ATTR(_(" VREPLACE"), attr); | |
9431 else | |
9432 #endif | |
9433 if (State & REPLACE_FLAG) | |
9434 MSG_PUTS_ATTR(_(" REPLACE"), attr); | |
9435 else if (State & INSERT) | |
9436 { | |
9437 #ifdef FEAT_RIGHTLEFT | |
9438 if (p_ri) | |
9439 MSG_PUTS_ATTR(_(" REVERSE"), attr); | |
9440 #endif | |
9441 MSG_PUTS_ATTR(_(" INSERT"), attr); | |
9442 } | |
9443 else if (restart_edit == 'I') | |
9444 MSG_PUTS_ATTR(_(" (insert)"), attr); | |
9445 else if (restart_edit == 'R') | |
9446 MSG_PUTS_ATTR(_(" (replace)"), attr); | |
9447 else if (restart_edit == 'V') | |
9448 MSG_PUTS_ATTR(_(" (vreplace)"), attr); | |
9449 #ifdef FEAT_RIGHTLEFT | |
9450 if (p_hkmap) | |
9451 MSG_PUTS_ATTR(_(" Hebrew"), attr); | |
9452 # ifdef FEAT_FKMAP | |
9453 if (p_fkmap) | |
9454 MSG_PUTS_ATTR(farsi_text_5, attr); | |
9455 # endif | |
9456 #endif | |
9457 #ifdef FEAT_KEYMAP | |
9458 if (State & LANGMAP) | |
9459 { | |
9460 # ifdef FEAT_ARABIC | |
9461 if (curwin->w_p_arab) | |
9462 MSG_PUTS_ATTR(_(" Arabic"), attr); | |
9463 else | |
9464 # endif | |
9465 MSG_PUTS_ATTR(_(" (lang)"), attr); | |
9466 } | |
9467 #endif | |
9468 if ((State & INSERT) && p_paste) | |
9469 MSG_PUTS_ATTR(_(" (paste)"), attr); | |
9470 | |
9471 #ifdef FEAT_VISUAL | |
9472 if (VIsual_active) | |
9473 { | |
9474 char *p; | |
9475 | |
9476 /* Don't concatenate separate words to avoid translation | |
9477 * problems. */ | |
9478 switch ((VIsual_select ? 4 : 0) | |
9479 + (VIsual_mode == Ctrl_V) * 2 | |
9480 + (VIsual_mode == 'V')) | |
9481 { | |
9482 case 0: p = N_(" VISUAL"); break; | |
9483 case 1: p = N_(" VISUAL LINE"); break; | |
9484 case 2: p = N_(" VISUAL BLOCK"); break; | |
9485 case 4: p = N_(" SELECT"); break; | |
9486 case 5: p = N_(" SELECT LINE"); break; | |
9487 default: p = N_(" SELECT BLOCK"); break; | |
9488 } | |
9489 MSG_PUTS_ATTR(_(p), attr); | |
9490 } | |
9491 #endif | |
9492 MSG_PUTS_ATTR(" --", attr); | |
9493 } | |
644 | 9494 |
7 | 9495 need_clear = TRUE; |
9496 } | |
9497 if (Recording | |
9498 #ifdef FEAT_INS_EXPAND | |
9499 && edit_submode == NULL /* otherwise it gets too long */ | |
9500 #endif | |
9501 ) | |
9502 { | |
9503 MSG_PUTS_ATTR(_("recording"), attr); | |
9504 need_clear = TRUE; | |
9505 } | |
644 | 9506 |
9507 mode_displayed = TRUE; | |
7 | 9508 if (need_clear || clear_cmdline) |
9509 msg_clr_eos(); | |
9510 msg_didout = FALSE; /* overwrite this message */ | |
9511 length = msg_col; | |
9512 msg_col = 0; | |
9513 need_wait_return = nwr_save; /* never ask for hit-return for this */ | |
9514 } | |
9515 else if (clear_cmdline && msg_silent == 0) | |
9516 /* Clear the whole command line. Will reset "clear_cmdline". */ | |
9517 msg_clr_cmdline(); | |
9518 | |
9519 #ifdef FEAT_CMDL_INFO | |
9520 # ifdef FEAT_VISUAL | |
9521 /* In Visual mode the size of the selected area must be redrawn. */ | |
9522 if (VIsual_active) | |
9523 clear_showcmd(); | |
9524 # endif | |
9525 | |
9526 /* If the last window has no status line, the ruler is after the mode | |
9527 * message and must be redrawn */ | |
9528 if (redrawing() | |
9529 # ifdef FEAT_WINDOWS | |
9530 && lastwin->w_status_height == 0 | |
9531 # endif | |
9532 ) | |
9533 win_redr_ruler(lastwin, TRUE); | |
9534 #endif | |
9535 redraw_cmdline = FALSE; | |
9536 clear_cmdline = FALSE; | |
9537 | |
9538 return length; | |
9539 } | |
9540 | |
9541 /* | |
9542 * Position for a mode message. | |
9543 */ | |
9544 static void | |
9545 msg_pos_mode() | |
9546 { | |
9547 msg_col = 0; | |
9548 msg_row = Rows - 1; | |
9549 } | |
9550 | |
9551 /* | |
9552 * Delete mode message. Used when ESC is typed which is expected to end | |
9553 * Insert mode (but Insert mode didn't end yet!). | |
644 | 9554 * Caller should check "mode_displayed". |
7 | 9555 */ |
9556 void | |
9557 unshowmode(force) | |
9558 int force; | |
9559 { | |
9560 /* | |
2055
4aa4510d548c
updated for version 7.2.341
Bram Moolenaar <bram@zimbu.org>
parents:
2008
diff
changeset
|
9561 * Don't delete it right now, when not redrawing or inside a mapping. |
7 | 9562 */ |
9563 if (!redrawing() || (!force && char_avail() && !KeyTyped)) | |
9564 redraw_cmdline = TRUE; /* delete mode later */ | |
9565 else | |
9566 { | |
9567 msg_pos_mode(); | |
9568 if (Recording) | |
9569 MSG_PUTS_ATTR(_("recording"), hl_attr(HLF_CM)); | |
9570 msg_clr_eos(); | |
9571 } | |
9572 } | |
9573 | |
667 | 9574 #if defined(FEAT_WINDOWS) |
9575 /* | |
9576 * Draw the tab pages line at the top of the Vim window. | |
9577 */ | |
9578 static void | |
677 | 9579 draw_tabline() |
667 | 9580 { |
9581 int tabcount = 0; | |
9582 tabpage_T *tp; | |
9583 int tabwidth; | |
9584 int col = 0; | |
673 | 9585 int scol = 0; |
667 | 9586 int attr; |
9587 win_T *wp; | |
671 | 9588 win_T *cwp; |
9589 int wincount; | |
9590 int modified; | |
667 | 9591 int c; |
9592 int len; | |
9593 int attr_sel = hl_attr(HLF_TPS); | |
9594 int attr_nosel = hl_attr(HLF_TP); | |
9595 int attr_fill = hl_attr(HLF_TPF); | |
673 | 9596 char_u *p; |
677 | 9597 int room; |
9598 int use_sep_chars = (t_colors < 8 | |
9599 #ifdef FEAT_GUI | |
9600 && !gui.in_use | |
9601 #endif | |
9602 ); | |
673 | 9603 |
9604 redraw_tabline = FALSE; | |
667 | 9605 |
685 | 9606 #ifdef FEAT_GUI_TABLINE |
798 | 9607 /* Take care of a GUI tabline. */ |
685 | 9608 if (gui_use_tabline()) |
9609 { | |
9610 gui_update_tabline(); | |
9611 return; | |
9612 } | |
9613 #endif | |
9614 | |
9615 if (tabline_height() < 1) | |
667 | 9616 return; |
9617 | |
677 | 9618 #if defined(FEAT_STL_OPT) |
681 | 9619 |
9620 /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ | |
9621 for (scol = 0; scol < Columns; ++scol) | |
9622 TabPageIdxs[scol] = 0; | |
9623 | |
677 | 9624 /* Use the 'tabline' option if it's set. */ |
9625 if (*p_tal != NUL) | |
9626 { | |
680 | 9627 int save_called_emsg = called_emsg; |
9628 | |
9629 /* Check for an error. If there is one we would loop in redrawing the | |
9630 * screen. Avoid that by making 'tabline' empty. */ | |
9631 called_emsg = FALSE; | |
677 | 9632 win_redr_custom(NULL, FALSE); |
680 | 9633 if (called_emsg) |
9634 set_string_option_direct((char_u *)"tabline", -1, | |
694 | 9635 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9636 called_emsg |= save_called_emsg; |
9637 } | |
9638 else | |
9639 #endif | |
9640 { | |
9641 for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) | |
9642 ++tabcount; | |
9643 | |
9644 tabwidth = (Columns - 1 + tabcount / 2) / tabcount; | |
9645 if (tabwidth < 6) | |
9646 tabwidth = 6; | |
9647 | |
9648 attr = attr_nosel; | |
9649 tabcount = 0; | |
681 | 9650 scol = 0; |
699 | 9651 for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
9652 tp = tp->tp_next) | |
680 | 9653 { |
9654 scol = col; | |
9655 | |
9656 if (tp->tp_topframe == topframe) | |
9657 attr = attr_sel; | |
9658 if (use_sep_chars && col > 0) | |
9659 screen_putchar('|', 0, col++, attr); | |
9660 | |
9661 if (tp->tp_topframe != topframe) | |
9662 attr = attr_nosel; | |
9663 | |
9664 screen_putchar(' ', 0, col++, attr); | |
9665 | |
9666 if (tp == curtab) | |
9667 { | |
9668 cwp = curwin; | |
9669 wp = firstwin; | |
9670 } | |
9671 else | |
9672 { | |
9673 cwp = tp->tp_curwin; | |
9674 wp = tp->tp_firstwin; | |
9675 } | |
9676 | |
9677 modified = FALSE; | |
9678 for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) | |
9679 if (bufIsChanged(wp->w_buffer)) | |
9680 modified = TRUE; | |
9681 if (modified || wincount > 1) | |
9682 { | |
9683 if (wincount > 1) | |
9684 { | |
9685 vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); | |
835 | 9686 len = (int)STRLEN(NameBuff); |
699 | 9687 if (col + len >= Columns - 3) |
9688 break; | |
680 | 9689 screen_puts_len(NameBuff, len, 0, col, |
677 | 9690 #if defined(FEAT_SYN_HL) |
680 | 9691 hl_combine_attr(attr, hl_attr(HLF_T)) |
677 | 9692 #else |
680 | 9693 attr |
9694 #endif | |
9695 ); | |
9696 col += len; | |
9697 } | |
9698 if (modified) | |
9699 screen_puts_len((char_u *)"+", 1, 0, col++, attr); | |
9700 screen_putchar(' ', 0, col++, attr); | |
9701 } | |
9702 | |
9703 room = scol - col + tabwidth - 1; | |
9704 if (room > 0) | |
9705 { | |
685 | 9706 /* Get buffer name in NameBuff[] */ |
9707 get_trans_bufname(cwp->w_buffer); | |
819 | 9708 shorten_dir(NameBuff); |
680 | 9709 len = vim_strsize(NameBuff); |
9710 p = NameBuff; | |
677 | 9711 #ifdef FEAT_MBYTE |
680 | 9712 if (has_mbyte) |
9713 while (len > room) | |
9714 { | |
9715 len -= ptr2cells(p); | |
9716 mb_ptr_adv(p); | |
9717 } | |
9718 else | |
9719 #endif | |
9720 if (len > room) | |
677 | 9721 { |
680 | 9722 p += len - room; |
9723 len = room; | |
677 | 9724 } |
699 | 9725 if (len > Columns - col - 1) |
9726 len = Columns - col - 1; | |
680 | 9727 |
835 | 9728 screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
680 | 9729 col += len; |
9730 } | |
9731 screen_putchar(' ', 0, col++, attr); | |
9732 | |
9733 /* Store the tab page number in TabPageIdxs[], so that | |
9734 * jump_to_mouse() knows where each one is. */ | |
9735 ++tabcount; | |
9736 while (scol < col) | |
9737 TabPageIdxs[scol++] = tabcount; | |
9738 } | |
9739 | |
9740 if (use_sep_chars) | |
9741 c = '_'; | |
9742 else | |
9743 c = ' '; | |
9744 screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); | |
681 | 9745 |
9746 /* Put an "X" for closing the current tab if there are several. */ | |
9747 if (first_tabpage->tp_next != NULL) | |
9748 { | |
9749 screen_putchar('X', 0, (int)Columns - 1, attr_nosel); | |
9750 TabPageIdxs[Columns - 1] = -999; | |
9751 } | |
9752 } | |
834 | 9753 |
9754 /* Reset the flag here again, in case evaluating 'tabline' causes it to be | |
9755 * set. */ | |
9756 redraw_tabline = FALSE; | |
667 | 9757 } |
685 | 9758 |
9759 /* | |
9760 * Get buffer name for "buf" into NameBuff[]. | |
9761 * Takes care of special buffer names and translates special characters. | |
9762 */ | |
9763 void | |
9764 get_trans_bufname(buf) | |
9765 buf_T *buf; | |
9766 { | |
9767 if (buf_spname(buf) != NULL) | |
9768 STRCPY(NameBuff, buf_spname(buf)); | |
9769 else | |
9770 home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); | |
9771 trans_characters(NameBuff, MAXPATHL); | |
9772 } | |
667 | 9773 #endif |
9774 | |
7 | 9775 #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
9776 /* | |
9777 * Get the character to use in a status line. Get its attributes in "*attr". | |
9778 */ | |
9779 static int | |
9780 fillchar_status(attr, is_curwin) | |
9781 int *attr; | |
9782 int is_curwin; | |
9783 { | |
9784 int fill; | |
9785 if (is_curwin) | |
9786 { | |
9787 *attr = hl_attr(HLF_S); | |
9788 fill = fill_stl; | |
9789 } | |
9790 else | |
9791 { | |
9792 *attr = hl_attr(HLF_SNC); | |
9793 fill = fill_stlnc; | |
9794 } | |
9795 /* Use fill when there is highlighting, and highlighting of current | |
9796 * window differs, or the fillchars differ, or this is not the | |
9797 * current window */ | |
9798 if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) | |
9799 || !is_curwin || firstwin == lastwin) | |
9800 || (fill_stl != fill_stlnc))) | |
9801 return fill; | |
9802 if (is_curwin) | |
9803 return '^'; | |
9804 return '='; | |
9805 } | |
9806 #endif | |
9807 | |
9808 #ifdef FEAT_VERTSPLIT | |
9809 /* | |
9810 * Get the character to use in a separator between vertically split windows. | |
9811 * Get its attributes in "*attr". | |
9812 */ | |
9813 static int | |
9814 fillchar_vsep(attr) | |
9815 int *attr; | |
9816 { | |
9817 *attr = hl_attr(HLF_C); | |
9818 if (*attr == 0 && fill_vert == ' ') | |
9819 return '|'; | |
9820 else | |
9821 return fill_vert; | |
9822 } | |
9823 #endif | |
9824 | |
9825 /* | |
9826 * Return TRUE if redrawing should currently be done. | |
9827 */ | |
9828 int | |
9829 redrawing() | |
9830 { | |
9831 return (!RedrawingDisabled | |
9832 && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); | |
9833 } | |
9834 | |
9835 /* | |
9836 * Return TRUE if printing messages should currently be done. | |
9837 */ | |
9838 int | |
9839 messaging() | |
9840 { | |
9841 return (!(p_lz && char_avail() && !KeyTyped)); | |
9842 } | |
9843 | |
9844 /* | |
9845 * Show current status info in ruler and various other places | |
9846 * If always is FALSE, only show ruler if position has changed. | |
9847 */ | |
9848 void | |
9849 showruler(always) | |
9850 int always; | |
9851 { | |
9852 if (!always && !redrawing()) | |
9853 return; | |
574 | 9854 #ifdef FEAT_INS_EXPAND |
9855 if (pum_visible()) | |
9856 { | |
639 | 9857 # ifdef FEAT_WINDOWS |
574 | 9858 /* Don't redraw right now, do it later. */ |
9859 curwin->w_redr_status = TRUE; | |
639 | 9860 # endif |
574 | 9861 return; |
9862 } | |
9863 #endif | |
7 | 9864 #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
40 | 9865 if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
680 | 9866 { |
1983 | 9867 redraw_custom_statusline(curwin); |
680 | 9868 } |
7 | 9869 else |
9870 #endif | |
9871 #ifdef FEAT_CMDL_INFO | |
9872 win_redr_ruler(curwin, always); | |
9873 #endif | |
9874 | |
9875 #ifdef FEAT_TITLE | |
9876 if (need_maketitle | |
9877 # ifdef FEAT_STL_OPT | |
9878 || (p_icon && (stl_syntax & STL_IN_ICON)) | |
9879 || (p_title && (stl_syntax & STL_IN_TITLE)) | |
9880 # endif | |
9881 ) | |
9882 maketitle(); | |
9883 #endif | |
1588 | 9884 #ifdef FEAT_WINDOWS |
9885 /* Redraw the tab pages line if needed. */ | |
9886 if (redraw_tabline) | |
9887 draw_tabline(); | |
9888 #endif | |
7 | 9889 } |
9890 | |
9891 #ifdef FEAT_CMDL_INFO | |
9892 static void | |
9893 win_redr_ruler(wp, always) | |
9894 win_T *wp; | |
9895 int always; | |
9896 { | |
1869 | 9897 #define RULER_BUF_LEN 70 |
9898 char_u buffer[RULER_BUF_LEN]; | |
7 | 9899 int row; |
9900 int fillchar; | |
9901 int attr; | |
9902 int empty_line = FALSE; | |
9903 colnr_T virtcol; | |
9904 int i; | |
1869 | 9905 size_t len; |
7 | 9906 int o; |
9907 #ifdef FEAT_VERTSPLIT | |
9908 int this_ru_col; | |
9909 int off = 0; | |
9910 int width = Columns; | |
9911 # define WITH_OFF(x) x | |
9912 # define WITH_WIDTH(x) x | |
9913 #else | |
9914 # define WITH_OFF(x) 0 | |
9915 # define WITH_WIDTH(x) Columns | |
9916 # define this_ru_col ru_col | |
9917 #endif | |
9918 | |
9919 /* If 'ruler' off or redrawing disabled, don't do anything */ | |
9920 if (!p_ru) | |
9921 return; | |
9922 | |
9923 /* | |
9924 * Check if cursor.lnum is valid, since win_redr_ruler() may be called | |
9925 * after deleting lines, before cursor.lnum is corrected. | |
9926 */ | |
9927 if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) | |
9928 return; | |
9929 | |
9930 #ifdef FEAT_INS_EXPAND | |
9931 /* Don't draw the ruler while doing insert-completion, it might overwrite | |
9932 * the (long) mode message. */ | |
9933 # ifdef FEAT_WINDOWS | |
9934 if (wp == lastwin && lastwin->w_status_height == 0) | |
9935 # endif | |
9936 if (edit_submode != NULL) | |
9937 return; | |
540 | 9938 /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
9939 if (pum_visible()) | |
9940 return; | |
7 | 9941 #endif |
9942 | |
9943 #ifdef FEAT_STL_OPT | |
9944 if (*p_ruf) | |
9945 { | |
680 | 9946 int save_called_emsg = called_emsg; |
9947 | |
9948 called_emsg = FALSE; | |
7 | 9949 win_redr_custom(wp, TRUE); |
680 | 9950 if (called_emsg) |
9951 set_string_option_direct((char_u *)"rulerformat", -1, | |
694 | 9952 (char_u *)"", OPT_FREE, SID_ERROR); |
680 | 9953 called_emsg |= save_called_emsg; |
7 | 9954 return; |
9955 } | |
9956 #endif | |
9957 | |
9958 /* | |
9959 * Check if not in Insert mode and the line is empty (will show "0-1"). | |
9960 */ | |
9961 if (!(State & INSERT) | |
9962 && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) | |
9963 empty_line = TRUE; | |
9964 | |
9965 /* | |
9966 * Only draw the ruler when something changed. | |
9967 */ | |
9968 validate_virtcol_win(wp); | |
9969 if ( redraw_cmdline | |
9970 || always | |
9971 || wp->w_cursor.lnum != wp->w_ru_cursor.lnum | |
9972 || wp->w_cursor.col != wp->w_ru_cursor.col | |
9973 || wp->w_virtcol != wp->w_ru_virtcol | |
9974 #ifdef FEAT_VIRTUALEDIT | |
9975 || wp->w_cursor.coladd != wp->w_ru_cursor.coladd | |
9976 #endif | |
9977 || wp->w_topline != wp->w_ru_topline | |
9978 || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count | |
9979 #ifdef FEAT_DIFF | |
9980 || wp->w_topfill != wp->w_ru_topfill | |
9981 #endif | |
9982 || empty_line != wp->w_ru_empty) | |
9983 { | |
9984 cursor_off(); | |
9985 #ifdef FEAT_WINDOWS | |
9986 if (wp->w_status_height) | |
9987 { | |
9988 row = W_WINROW(wp) + wp->w_height; | |
9989 fillchar = fillchar_status(&attr, wp == curwin); | |
9990 # ifdef FEAT_VERTSPLIT | |
9991 off = W_WINCOL(wp); | |
9992 width = W_WIDTH(wp); | |
9993 # endif | |
9994 } | |
9995 else | |
9996 #endif | |
9997 { | |
9998 row = Rows - 1; | |
9999 fillchar = ' '; | |
10000 attr = 0; | |
10001 #ifdef FEAT_VERTSPLIT | |
10002 width = Columns; | |
10003 off = 0; | |
10004 #endif | |
10005 } | |
10006 | |
10007 /* In list mode virtcol needs to be recomputed */ | |
10008 virtcol = wp->w_virtcol; | |
10009 if (wp->w_p_list && lcs_tab1 == NUL) | |
10010 { | |
10011 wp->w_p_list = FALSE; | |
10012 getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); | |
10013 wp->w_p_list = TRUE; | |
10014 } | |
10015 | |
10016 /* | |
10017 * Some sprintfs return the length, some return a pointer. | |
10018 * To avoid portability problems we use strlen() here. | |
10019 */ | |
1869 | 10020 vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
7 | 10021 (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
10022 ? 0L | |
10023 : (long)(wp->w_cursor.lnum)); | |
1869 | 10024 len = STRLEN(buffer); |
10025 col_print(buffer + len, RULER_BUF_LEN - len, | |
7 | 10026 empty_line ? 0 : (int)wp->w_cursor.col + 1, |
10027 (int)virtcol + 1); | |
10028 | |
10029 /* | |
10030 * Add a "50%" if there is room for it. | |
10031 * On the last line, don't print in the last column (scrolls the | |
10032 * screen up on some terminals). | |
10033 */ | |
10034 i = (int)STRLEN(buffer); | |
1869 | 10035 get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
7 | 10036 o = i + vim_strsize(buffer + i + 1); |
10037 #ifdef FEAT_WINDOWS | |
10038 if (wp->w_status_height == 0) /* can't use last char of screen */ | |
10039 #endif | |
10040 ++o; | |
10041 #ifdef FEAT_VERTSPLIT | |
10042 this_ru_col = ru_col - (Columns - width); | |
10043 if (this_ru_col < 0) | |
10044 this_ru_col = 0; | |
10045 #endif | |
10046 /* Never use more than half the window/screen width, leave the other | |
10047 * half for the filename. */ | |
10048 if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) | |
10049 this_ru_col = (WITH_WIDTH(width) + 1) / 2; | |
10050 if (this_ru_col + o < WITH_WIDTH(width)) | |
10051 { | |
10052 while (this_ru_col + o < WITH_WIDTH(width)) | |
10053 { | |
10054 #ifdef FEAT_MBYTE | |
10055 if (has_mbyte) | |
10056 i += (*mb_char2bytes)(fillchar, buffer + i); | |
10057 else | |
10058 #endif | |
10059 buffer[i++] = fillchar; | |
10060 ++o; | |
10061 } | |
1869 | 10062 get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
7 | 10063 } |
10064 /* Truncate at window boundary. */ | |
10065 #ifdef FEAT_MBYTE | |
10066 if (has_mbyte) | |
10067 { | |
10068 o = 0; | |
474 | 10069 for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
7 | 10070 { |
10071 o += (*mb_ptr2cells)(buffer + i); | |
10072 if (this_ru_col + o > WITH_WIDTH(width)) | |
10073 { | |
10074 buffer[i] = NUL; | |
10075 break; | |
10076 } | |
10077 } | |
10078 } | |
10079 else | |
10080 #endif | |
10081 if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) | |
10082 buffer[WITH_WIDTH(width) - this_ru_col] = NUL; | |
10083 | |
10084 screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); | |
10085 i = redraw_cmdline; | |
10086 screen_fill(row, row + 1, | |
10087 this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), | |
10088 (int)(WITH_OFF(off) + WITH_WIDTH(width)), | |
10089 fillchar, fillchar, attr); | |
10090 /* don't redraw the cmdline because of showing the ruler */ | |
10091 redraw_cmdline = i; | |
10092 wp->w_ru_cursor = wp->w_cursor; | |
10093 wp->w_ru_virtcol = wp->w_virtcol; | |
10094 wp->w_ru_empty = empty_line; | |
10095 wp->w_ru_topline = wp->w_topline; | |
10096 wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; | |
10097 #ifdef FEAT_DIFF | |
10098 wp->w_ru_topfill = wp->w_topfill; | |
10099 #endif | |
10100 } | |
10101 } | |
10102 #endif | |
13 | 10103 |
10104 #if defined(FEAT_LINEBREAK) || defined(PROTO) | |
10105 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10106 * Return the width of the 'number' and 'relativenumber' column. |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10107 * Caller may need to check if 'number' or 'relativenumber' is set. |
13 | 10108 * Otherwise it depends on 'numberwidth' and the line count. |
10109 */ | |
10110 int | |
10111 number_width(wp) | |
10112 win_T *wp; | |
10113 { | |
10114 int n; | |
10115 linenr_T lnum; | |
10116 | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10117 if (wp->w_p_nu) |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10118 /* 'number' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10119 lnum = wp->w_buffer->b_ml.ml_line_count; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10120 else |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10121 /* 'relativenumber' */ |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10122 lnum = wp->w_height; |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2124
diff
changeset
|
10123 |
13 | 10124 if (lnum == wp->w_nrwidth_line_count) |
10125 return wp->w_nrwidth_width; | |
10126 wp->w_nrwidth_line_count = lnum; | |
10127 | |
10128 n = 0; | |
10129 do | |
10130 { | |
856 | 10131 lnum /= 10; |
10132 ++n; | |
13 | 10133 } while (lnum > 0); |
10134 | |
10135 /* 'numberwidth' gives the minimal width plus one */ | |
10136 if (n < wp->w_p_nuw - 1) | |
10137 n = wp->w_p_nuw - 1; | |
10138 | |
10139 wp->w_nrwidth_width = n; | |
10140 return n; | |
10141 } | |
10142 #endif |