blob: 5cfec8407759025e4db87fbd29d5fede5b168e24 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
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 * drawline.c: Functions for drawing window lines on the screen.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
78#ifdef FEAT_SIGNS
79/*
80 * Get information needed to display the sign in line 'lnum' in window 'wp'.
81 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
82 * Otherwise the sign is going to be displayed in the sign column.
83 */
84 static void
85get_sign_display_info(
86 int nrcol,
87 win_T *wp,
88 linenr_T lnum UNUSED,
89 sign_attrs_T *sattr,
90 int wcr_attr,
91 int row,
92 int startrow,
93 int filler_lines UNUSED,
94 int filler_todo UNUSED,
95 int *c_extrap,
96 int *c_finalp,
97 char_u *extra,
98 char_u **pp_extra,
99 int *n_extrap,
100 int *char_attrp)
101{
102 int text_sign;
103# ifdef FEAT_SIGN_ICONS
104 int icon_sign;
105# endif
106
107 // Draw two cells with the sign value or blank.
108 *c_extrap = ' ';
109 *c_finalp = NUL;
110 if (nrcol)
111 *n_extrap = number_width(wp) + 1;
112 else
113 {
114 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
115 *n_extrap = 2;
116 }
117
118 if (row == startrow
119#ifdef FEAT_DIFF
120 + filler_lines && filler_todo <= 0
121#endif
122 )
123 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200124 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200125# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200126 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200127 if (gui.in_use && icon_sign != 0)
128 {
129 // Use the image in this position.
130 if (nrcol)
131 {
132 *c_extrap = NUL;
133 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
134 *pp_extra = extra;
135 *n_extrap = (int)STRLEN(*pp_extra);
136 }
137 else
138 *c_extrap = SIGN_BYTE;
139# ifdef FEAT_NETBEANS_INTG
140 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
141 {
142 if (nrcol)
143 {
144 *c_extrap = NUL;
145 sprintf((char *)extra, "%-*c ", number_width(wp),
146 MULTISIGN_BYTE);
147 *pp_extra = extra;
148 *n_extrap = (int)STRLEN(*pp_extra);
149 }
150 else
151 *c_extrap = MULTISIGN_BYTE;
152 }
153# endif
154 *c_finalp = NUL;
155 *char_attrp = icon_sign;
156 }
157 else
158# endif
159 if (text_sign != 0)
160 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200161 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200162 if (*pp_extra != NULL)
163 {
164 if (nrcol)
165 {
166 int n, width = number_width(wp) - 2;
167
168 for (n = 0; n < width; n++)
169 extra[n] = ' ';
170 extra[n] = 0;
171 STRCAT(extra, *pp_extra);
172 STRCAT(extra, " ");
173 *pp_extra = extra;
174 }
175 *c_extrap = NUL;
176 *c_finalp = NUL;
177 *n_extrap = (int)STRLEN(*pp_extra);
178 }
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200179 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200180 }
181 }
182}
183#endif
184
185#ifdef FEAT_TEXT_PROP
186static textprop_T *current_text_props = NULL;
187static buf_T *current_buf = NULL;
188
189 static int
190text_prop_compare(const void *s1, const void *s2)
191{
192 int idx1, idx2;
193 proptype_T *pt1, *pt2;
194 colnr_T col1, col2;
195
196 idx1 = *(int *)s1;
197 idx2 = *(int *)s2;
198 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
199 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
200 if (pt1 == pt2)
201 return 0;
202 if (pt1 == NULL)
203 return -1;
204 if (pt2 == NULL)
205 return 1;
206 if (pt1->pt_priority != pt2->pt_priority)
207 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
208 col1 = current_text_props[idx1].tp_col;
209 col2 = current_text_props[idx2].tp_col;
210 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
211}
212#endif
213
214/*
215 * Display line "lnum" of window 'wp' on the screen.
216 * Start at row "startrow", stop when "endrow" is reached.
217 * wp->w_virtcol needs to be valid.
218 *
219 * Return the number of last row the line occupies.
220 */
221 int
222win_line(
223 win_T *wp,
224 linenr_T lnum,
225 int startrow,
226 int endrow,
227 int nochange UNUSED, // not updating for changed text
228 int number_only) // only update the number column
229{
230 int col = 0; // visual column on screen
231 unsigned off; // offset in ScreenLines/ScreenAttrs
232 int c = 0; // init for GCC
233 long vcol = 0; // virtual column (for tabs)
234#ifdef FEAT_LINEBREAK
235 long vcol_sbr = -1; // virtual column after showbreak
236#endif
237 long vcol_prev = -1; // "vcol" of previous character
238 char_u *line; // current line
239 char_u *ptr; // current position in "line"
240 int row; // row in the window, excl w_winrow
241 int screen_row; // row on the screen, incl w_winrow
242
243 char_u extra[21]; // "%ld " and 'fdc' must fit in here
244 int n_extra = 0; // number of extra chars
245 char_u *p_extra = NULL; // string of extra chars, plus NUL
246 char_u *p_extra_free = NULL; // p_extra needs to be freed
247 int c_extra = NUL; // extra chars, all the same
248 int c_final = NUL; // final char, mandatory if set
249 int extra_attr = 0; // attributes when n_extra != 0
250 static char_u *at_end_str = (char_u *)""; // used for p_extra when
251 // displaying lcs_eol at end-of-line
252 int lcs_eol_one = lcs_eol; // lcs_eol until it's been used
253 int lcs_prec_todo = lcs_prec; // lcs_prec until it's been used
254
255 // saved "extra" items for when draw_state becomes WL_LINE (again)
256 int saved_n_extra = 0;
257 char_u *saved_p_extra = NULL;
258 int saved_c_extra = 0;
259 int saved_c_final = 0;
260 int saved_char_attr = 0;
261
262 int n_attr = 0; // chars with special attr
263 int saved_attr2 = 0; // char_attr saved for n_attr
264 int n_attr3 = 0; // chars with overruling special attr
265 int saved_attr3 = 0; // char_attr saved for n_attr3
266
267 int n_skip = 0; // nr of chars to skip for 'nowrap'
268
269 int fromcol = -10; // start of inverting
270 int tocol = MAXCOL; // end of inverting
271 int fromcol_prev = -2; // start of inverting after cursor
272 int noinvcur = FALSE; // don't invert the cursor
273 pos_T *top, *bot;
274 int lnum_in_visual_area = FALSE;
275 pos_T pos;
276 long v;
277
278 int char_attr = 0; // attributes for next character
279 int attr_pri = FALSE; // char_attr has priority
280 int area_highlighting = FALSE; // Visual or incsearch highlighting
281 // in this line
282 int vi_attr = 0; // attributes for Visual and incsearch
283 // highlighting
284 int wcr_attr = 0; // attributes from 'wincolor'
285 int win_attr = 0; // background for whole window, except
286 // margins and "~" lines.
287 int area_attr = 0; // attributes desired by highlighting
288 int search_attr = 0; // attributes desired by 'hlsearch'
289#ifdef FEAT_SYN_HL
290 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
291 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200292 int prev_syntax_col = -1; // column of prev_syntax_attr
293 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 int has_syntax = FALSE; // this buffer has syntax highl.
295 int save_did_emsg;
296 int draw_color_col = FALSE; // highlight colorcolumn
297 int *color_cols = NULL; // pointer to according columns array
298#endif
299 int eol_hl_off = 0; // 1 if highlighted char after EOL
300#ifdef FEAT_TEXT_PROP
301 int text_prop_count;
302 int text_prop_next = 0; // next text property to use
303 textprop_T *text_props = NULL;
304 int *text_prop_idxs = NULL;
305 int text_props_active = 0;
306 proptype_T *text_prop_type = NULL;
307 int text_prop_attr = 0;
308 int text_prop_combine = FALSE;
309#endif
310#ifdef FEAT_SPELL
311 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200312 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313# define SPWORDLEN 150
314 char_u nextline[SPWORDLEN * 2];// text with start of the next line
315 int nextlinecol = 0; // column where nextline[] starts
316 int nextline_idx = 0; // index in nextline[] where next line
317 // starts
318 int spell_attr = 0; // attributes desired by spelling
319 int word_end = 0; // last byte with same spell_attr
320 static linenr_T checked_lnum = 0; // line number for "checked_col"
321 static int checked_col = 0; // column in "checked_lnum" up to which
322 // there are no spell errors
323 static int cap_col = -1; // column to check for Cap word
324 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
325 int cur_checked_col = 0; // checked column for current line
326#endif
327 int extra_check = 0; // has extra highlighting
328 int multi_attr = 0; // attributes desired by multibyte
329 int mb_l = 1; // multi-byte byte length
330 int mb_c = 0; // decoded multi-byte character
331 int mb_utf8 = FALSE; // screen char is UTF-8 char
332 int u8cc[MAX_MCO]; // composing UTF-8 chars
333#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
334 int filler_lines = 0; // nr of filler lines to be drawn
335 int filler_todo = 0; // nr of filler lines still to do + 1
336#endif
337#ifdef FEAT_DIFF
338 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
339 int change_start = MAXCOL; // first col of changed area
340 int change_end = -1; // last col of changed area
341#endif
342 colnr_T trailcol = MAXCOL; // start of trailing spaces
343#ifdef FEAT_LINEBREAK
344 int need_showbreak = FALSE; // overlong line, skipping first x
345 // chars
346#endif
347#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
348 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
349# define LINE_ATTR
350 int line_attr = 0; // attribute for the whole line
351 int line_attr_save;
352#endif
353#ifdef FEAT_SIGNS
354 int sign_present = FALSE;
355 sign_attrs_T sattr;
356#endif
357#ifdef FEAT_ARABIC
358 int prev_c = 0; // previous Arabic character
359 int prev_c1 = 0; // first composing char for prev_c
360#endif
361#if defined(LINE_ATTR)
362 int did_line_attr = 0;
363#endif
364#ifdef FEAT_TERMINAL
365 int get_term_attr = FALSE;
366#endif
367#ifdef FEAT_SYN_HL
368 int cul_attr = 0; // set when 'cursorline' active
369
370 // 'cursorlineopt' has "screenline" and cursor is in this line
371 int cul_screenline = FALSE;
372
373 // margin columns for the screen line, needed for when 'cursorlineopt'
374 // contains "screenline"
375 int left_curline_col = 0;
376 int right_curline_col = 0;
377#endif
378
379 // draw_state: items that are drawn in sequence:
380#define WL_START 0 // nothing done yet
381#ifdef FEAT_CMDWIN
382# define WL_CMDLINE WL_START + 1 // cmdline window column
383#else
384# define WL_CMDLINE WL_START
385#endif
386#ifdef FEAT_FOLDING
387# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
388#else
389# define WL_FOLD WL_CMDLINE
390#endif
391#ifdef FEAT_SIGNS
392# define WL_SIGN WL_FOLD + 1 // column for signs
393#else
394# define WL_SIGN WL_FOLD // column for signs
395#endif
396#define WL_NR WL_SIGN + 1 // line number
397#ifdef FEAT_LINEBREAK
398# define WL_BRI WL_NR + 1 // 'breakindent'
399#else
400# define WL_BRI WL_NR
401#endif
402#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
403# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
404#else
405# define WL_SBR WL_BRI
406#endif
407#define WL_LINE WL_SBR + 1 // text in the line
408 int draw_state = WL_START; // what to draw next
409#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
410 int feedback_col = 0;
411 int feedback_old_attr = -1;
412#endif
413 int screen_line_flags = 0;
414
415#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
416 int match_conc = 0; // cchar for match functions
417#endif
418#ifdef FEAT_CONCEAL
419 int syntax_flags = 0;
420 int syntax_seqnr = 0;
421 int prev_syntax_id = 0;
422 int conceal_attr = HL_ATTR(HLF_CONCEAL);
423 int is_concealing = FALSE;
424 int boguscols = 0; // nonexistent columns added to force
425 // wrapping
426 int vcol_off = 0; // offset for concealed characters
427 int did_wcol = FALSE;
428 int old_boguscols = 0;
429# define VCOL_HLC (vcol - vcol_off)
430# define FIX_FOR_BOGUSCOLS \
431 { \
432 n_extra += vcol_off; \
433 vcol -= vcol_off; \
434 vcol_off = 0; \
435 col -= boguscols; \
436 old_boguscols = boguscols; \
437 boguscols = 0; \
438 }
439#else
440# define VCOL_HLC (vcol)
441#endif
442
443 if (startrow > endrow) // past the end already!
444 return startrow;
445
446 row = startrow;
447 screen_row = row + W_WINROW(wp);
448
449 if (!number_only)
450 {
451 // To speed up the loop below, set extra_check when there is linebreak,
452 // trailing white space and/or syntax processing to be done.
453#ifdef FEAT_LINEBREAK
454 extra_check = wp->w_p_lbr;
455#endif
456#ifdef FEAT_SYN_HL
457 if (syntax_present(wp) && !wp->w_s->b_syn_error
458# ifdef SYN_TIME_LIMIT
459 && !wp->w_s->b_syn_slow
460# endif
461 )
462 {
463 // Prepare for syntax highlighting in this line. When there is an
464 // error, stop syntax highlighting.
465 save_did_emsg = did_emsg;
466 did_emsg = FALSE;
467 syntax_start(wp, lnum);
468 if (did_emsg)
469 wp->w_s->b_syn_error = TRUE;
470 else
471 {
472 did_emsg = save_did_emsg;
473#ifdef SYN_TIME_LIMIT
474 if (!wp->w_s->b_syn_slow)
475#endif
476 {
477 has_syntax = TRUE;
478 extra_check = TRUE;
479 }
480 }
481 }
482
483 // Check for columns to display for 'colorcolumn'.
484 color_cols = wp->w_p_cc_cols;
485 if (color_cols != NULL)
486 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
487#endif
488
489#ifdef FEAT_TERMINAL
490 if (term_show_buffer(wp->w_buffer))
491 {
492 extra_check = TRUE;
493 get_term_attr = TRUE;
494 win_attr = term_get_attr(wp->w_buffer, lnum, -1);
495 }
496#endif
497
498#ifdef FEAT_SPELL
499 if (wp->w_p_spell
500 && *wp->w_s->b_p_spl != NUL
501 && wp->w_s->b_langp.ga_len > 0
502 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
503 {
504 // Prepare for spell checking.
505 has_spell = TRUE;
506 extra_check = TRUE;
507
508 // Get the start of the next line, so that words that wrap to the
509 // next line are found too: "et<line-break>al.".
510 // Trick: skip a few chars for C/shell/Vim comments
511 nextline[SPWORDLEN] = NUL;
512 if (lnum < wp->w_buffer->b_ml.ml_line_count)
513 {
514 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
515 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
516 }
517
518 // When a word wrapped from the previous line the start of the
519 // current line is valid.
520 if (lnum == checked_lnum)
521 cur_checked_col = checked_col;
522 checked_lnum = 0;
523
524 // When there was a sentence end in the previous line may require a
525 // word starting with capital in this line. In line 1 always check
526 // the first word.
527 if (lnum != capcol_lnum)
528 cap_col = -1;
529 if (lnum == 1)
530 cap_col = 0;
531 capcol_lnum = 0;
532 }
533#endif
534
535 // handle Visual active in this window
536 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
537 {
538 if (LTOREQ_POS(curwin->w_cursor, VIsual))
539 {
540 // Visual is after curwin->w_cursor
541 top = &curwin->w_cursor;
542 bot = &VIsual;
543 }
544 else
545 {
546 // Visual is before curwin->w_cursor
547 top = &VIsual;
548 bot = &curwin->w_cursor;
549 }
550 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
551 if (VIsual_mode == Ctrl_V)
552 {
553 // block mode
554 if (lnum_in_visual_area)
555 {
556 fromcol = wp->w_old_cursor_fcol;
557 tocol = wp->w_old_cursor_lcol;
558 }
559 }
560 else
561 {
562 // non-block mode
563 if (lnum > top->lnum && lnum <= bot->lnum)
564 fromcol = 0;
565 else if (lnum == top->lnum)
566 {
567 if (VIsual_mode == 'V') // linewise
568 fromcol = 0;
569 else
570 {
571 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
572 if (gchar_pos(top) == NUL)
573 tocol = fromcol + 1;
574 }
575 }
576 if (VIsual_mode != 'V' && lnum == bot->lnum)
577 {
578 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
579 {
580 fromcol = -10;
581 tocol = MAXCOL;
582 }
583 else if (bot->col == MAXCOL)
584 tocol = MAXCOL;
585 else
586 {
587 pos = *bot;
588 if (*p_sel == 'e')
589 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
590 else
591 {
592 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
593 ++tocol;
594 }
595 }
596 }
597 }
598
599 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200600 if (!highlight_match && lnum == curwin->w_cursor.lnum
601 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200602#ifdef FEAT_GUI
603 && !gui.in_use
604#endif
605 )
606 noinvcur = TRUE;
607
608 // if inverting in this line set area_highlighting
609 if (fromcol >= 0)
610 {
611 area_highlighting = TRUE;
612 vi_attr = HL_ATTR(HLF_V);
613#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
614 if ((clip_star.available && !clip_star.owned
615 && clip_isautosel_star())
616 || (clip_plus.available && !clip_plus.owned
617 && clip_isautosel_plus()))
618 vi_attr = HL_ATTR(HLF_VNC);
619#endif
620 }
621 }
622
623 // handle 'incsearch' and ":s///c" highlighting
624 else if (highlight_match
625 && wp == curwin
626 && lnum >= curwin->w_cursor.lnum
627 && lnum <= curwin->w_cursor.lnum + search_match_lines)
628 {
629 if (lnum == curwin->w_cursor.lnum)
630 getvcol(curwin, &(curwin->w_cursor),
631 (colnr_T *)&fromcol, NULL, NULL);
632 else
633 fromcol = 0;
634 if (lnum == curwin->w_cursor.lnum + search_match_lines)
635 {
636 pos.lnum = lnum;
637 pos.col = search_match_endcol;
638 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
639 }
640 else
641 tocol = MAXCOL;
642 // do at least one character; happens when past end of line
643 if (fromcol == tocol)
644 tocol = fromcol + 1;
645 area_highlighting = TRUE;
646 vi_attr = HL_ATTR(HLF_I);
647 }
648 }
649
650#ifdef FEAT_DIFF
651 filler_lines = diff_check(wp, lnum);
652 if (filler_lines < 0)
653 {
654 if (filler_lines == -1)
655 {
656 if (diff_find_change(wp, lnum, &change_start, &change_end))
657 diff_hlf = HLF_ADD; // added line
658 else if (change_start == 0)
659 diff_hlf = HLF_TXD; // changed text
660 else
661 diff_hlf = HLF_CHD; // changed line
662 }
663 else
664 diff_hlf = HLF_ADD; // added line
665 filler_lines = 0;
666 area_highlighting = TRUE;
667 }
668 if (lnum == wp->w_topline)
669 filler_lines = wp->w_topfill;
670 filler_todo = filler_lines;
671#endif
672
673#ifdef FEAT_SIGNS
674 sign_present = buf_get_signattrs(wp->w_buffer, lnum, &sattr);
675#endif
676
677#ifdef LINE_ATTR
678# ifdef FEAT_SIGNS
679 // If this line has a sign with line highlighting set line_attr.
680 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200681 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200682# endif
683# if defined(FEAT_QUICKFIX)
684 // Highlight the current line in the quickfix window.
685 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
686 line_attr = HL_ATTR(HLF_QFL);
687# endif
688 if (line_attr != 0)
689 area_highlighting = TRUE;
690#endif
691
692 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
693 ptr = line;
694
695#ifdef FEAT_SPELL
696 if (has_spell && !number_only)
697 {
698 // For checking first word with a capital skip white space.
699 if (cap_col == 0)
700 cap_col = getwhitecols(line);
701
702 // To be able to spell-check over line boundaries copy the end of the
703 // current line into nextline[]. Above the start of the next line was
704 // copied to nextline[SPWORDLEN].
705 if (nextline[SPWORDLEN] == NUL)
706 {
707 // No next line or it is empty.
708 nextlinecol = MAXCOL;
709 nextline_idx = 0;
710 }
711 else
712 {
713 v = (long)STRLEN(line);
714 if (v < SPWORDLEN)
715 {
716 // Short line, use it completely and append the start of the
717 // next line.
718 nextlinecol = 0;
719 mch_memmove(nextline, line, (size_t)v);
720 STRMOVE(nextline + v, nextline + SPWORDLEN);
721 nextline_idx = v + 1;
722 }
723 else
724 {
725 // Long line, use only the last SPWORDLEN bytes.
726 nextlinecol = v - SPWORDLEN;
727 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
728 nextline_idx = SPWORDLEN + 1;
729 }
730 }
731 }
732#endif
733
734 if (wp->w_p_list)
735 {
736 if (lcs_space || lcs_trail || lcs_nbsp)
737 extra_check = TRUE;
738 // find start of trailing whitespace
739 if (lcs_trail)
740 {
741 trailcol = (colnr_T)STRLEN(ptr);
742 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
743 --trailcol;
744 trailcol += (colnr_T) (ptr - line);
745 }
746 }
747
748 wcr_attr = get_wcr_attr(wp);
749 if (wcr_attr != 0)
750 {
751 win_attr = wcr_attr;
752 area_highlighting = TRUE;
753 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200754
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200755#ifdef FEAT_TEXT_PROP
756 if (WIN_IS_POPUP(wp))
757 screen_line_flags |= SLF_POPUP;
758#endif
759
760 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
761 // first character to be displayed.
762 if (wp->w_p_wrap)
763 v = wp->w_skipcol;
764 else
765 v = wp->w_leftcol;
766 if (v > 0 && !number_only)
767 {
768 char_u *prev_ptr = ptr;
769
770 while (vcol < v && *ptr != NUL)
771 {
772 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
773 vcol += c;
774 prev_ptr = ptr;
775 MB_PTR_ADV(ptr);
776 }
777
778 // When:
779 // - 'cuc' is set, or
780 // - 'colorcolumn' is set, or
781 // - 'virtualedit' is set, or
782 // - the visual mode is active,
783 // the end of the line may be before the start of the displayed part.
784 if (vcol < v && (
785#ifdef FEAT_SYN_HL
786 wp->w_p_cuc || draw_color_col ||
787#endif
788 virtual_active() ||
789 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
790 vcol = v;
791
792 // Handle a character that's not completely on the screen: Put ptr at
793 // that character but skip the first few screen characters.
794 if (vcol > v)
795 {
796 vcol -= c;
797 ptr = prev_ptr;
798 // If the character fits on the screen, don't need to skip it.
799 // Except for a TAB.
800 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
801 n_skip = v - vcol;
802 }
803
804 // Adjust for when the inverted text is before the screen,
805 // and when the start of the inverted text is before the screen.
806 if (tocol <= vcol)
807 fromcol = 0;
808 else if (fromcol >= 0 && fromcol < vcol)
809 fromcol = vcol;
810
811#ifdef FEAT_LINEBREAK
812 // When w_skipcol is non-zero, first line needs 'showbreak'
813 if (wp->w_p_wrap)
814 need_showbreak = TRUE;
815#endif
816#ifdef FEAT_SPELL
817 // When spell checking a word we need to figure out the start of the
818 // word and if it's badly spelled or not.
819 if (has_spell)
820 {
821 int len;
822 colnr_T linecol = (colnr_T)(ptr - line);
823 hlf_T spell_hlf = HLF_COUNT;
824
825 pos = wp->w_cursor;
826 wp->w_cursor.lnum = lnum;
827 wp->w_cursor.col = linecol;
828 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
829
830 // spell_move_to() may call ml_get() and make "line" invalid
831 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
832 ptr = line + linecol;
833
834 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
835 {
836 // no bad word found at line start, don't check until end of a
837 // word
838 spell_hlf = HLF_COUNT;
839 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
840 }
841 else
842 {
843 // bad word found, use attributes until end of word
844 word_end = wp->w_cursor.col + len + 1;
845
846 // Turn index into actual attributes.
847 if (spell_hlf != HLF_COUNT)
848 spell_attr = highlight_attr[spell_hlf];
849 }
850 wp->w_cursor = pos;
851
852# ifdef FEAT_SYN_HL
853 // Need to restart syntax highlighting for this line.
854 if (has_syntax)
855 syntax_start(wp, lnum);
856# endif
857 }
858#endif
859 }
860
861 // Correct highlighting for cursor that can't be disabled.
862 // Avoids having to check this for each character.
863 if (fromcol >= 0)
864 {
865 if (noinvcur)
866 {
867 if ((colnr_T)fromcol == wp->w_virtcol)
868 {
869 // highlighting starts at cursor, let it start just after the
870 // cursor
871 fromcol_prev = fromcol;
872 fromcol = -1;
873 }
874 else if ((colnr_T)fromcol < wp->w_virtcol)
875 // restart highlighting after the cursor
876 fromcol_prev = wp->w_virtcol;
877 }
878 if (fromcol >= tocol)
879 fromcol = -1;
880 }
881
882#ifdef FEAT_SEARCH_EXTRA
883 if (!number_only)
884 {
885 v = (long)(ptr - line);
886 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
887 &line, &screen_search_hl,
888 &search_attr);
889 ptr = line + v; // "line" may have been updated
890 }
891#endif
892
893#ifdef FEAT_SYN_HL
894 // Cursor line highlighting for 'cursorline' in the current window.
895 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
896 {
897 // Do not show the cursor line in the text when Visual mode is active,
898 // because it's not clear what is selected then. Do update
899 // w_last_cursorline.
900 if (!(wp == curwin && VIsual_active)
901 && wp->w_p_culopt_flags != CULOPT_NBR)
902 {
903 cul_screenline = (wp->w_p_wrap
904 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
905
906 // Only set line_attr here when "screenline" is not present in
907 // 'cursorlineopt'. Otherwise it's done later.
908 if (!cul_screenline)
909 {
910 cul_attr = HL_ATTR(HLF_CUL);
911 line_attr = cul_attr;
912 wp->w_last_cursorline = wp->w_cursor.lnum;
913 }
914 else
915 {
916 line_attr_save = line_attr;
917 wp->w_last_cursorline = 0;
918 margin_columns_win(wp, &left_curline_col, &right_curline_col);
919 }
920 area_highlighting = TRUE;
921 }
922 else
923 wp->w_last_cursorline = wp->w_cursor.lnum;
924 }
925#endif
926
927#ifdef FEAT_TEXT_PROP
928 {
929 char_u *prop_start;
930
931 text_prop_count = get_text_props(wp->w_buffer, lnum,
932 &prop_start, FALSE);
933 if (text_prop_count > 0)
934 {
935 // Make a copy of the properties, so that they are properly
936 // aligned.
937 text_props = ALLOC_MULT(textprop_T, text_prop_count);
938 if (text_props != NULL)
939 mch_memmove(text_props, prop_start,
940 text_prop_count * sizeof(textprop_T));
941
942 // Allocate an array for the indexes.
943 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
944 area_highlighting = TRUE;
945 extra_check = TRUE;
946 }
947 }
948#endif
949
950 off = (unsigned)(current_ScreenLine - ScreenLines);
951 col = 0;
952
953#ifdef FEAT_RIGHTLEFT
954 if (wp->w_p_rl)
955 {
956 // Rightleft window: process the text in the normal direction, but put
957 // it in current_ScreenLine[] from right to left. Start at the
958 // rightmost column of the window.
959 col = wp->w_width - 1;
960 off += col;
961 screen_line_flags |= SLF_RIGHTLEFT;
962 }
963#endif
964
965 // Repeat for the whole displayed line.
966 for (;;)
967 {
968#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
969 int has_match_conc = 0; // match wants to conceal
970#endif
971#ifdef FEAT_CONCEAL
972 int did_decrement_ptr = FALSE;
973#endif
974 // Skip this quickly when working on the text.
975 if (draw_state != WL_LINE)
976 {
977#ifdef FEAT_CMDWIN
978 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
979 {
980 draw_state = WL_CMDLINE;
981 if (cmdwin_type != 0 && wp == curwin)
982 {
983 // Draw the cmdline character.
984 n_extra = 1;
985 c_extra = cmdwin_type;
986 c_final = NUL;
987 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
988 }
989 }
990#endif
991
992#ifdef FEAT_FOLDING
993 if (draw_state == WL_FOLD - 1 && n_extra == 0)
994 {
995 int fdc = compute_foldcolumn(wp, 0);
996
997 draw_state = WL_FOLD;
998 if (fdc > 0)
999 {
1000 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1001 // already be in use.
1002 vim_free(p_extra_free);
1003 p_extra_free = alloc(12 + 1);
1004
1005 if (p_extra_free != NULL)
1006 {
1007 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
1008 n_extra = fdc;
1009 p_extra_free[n_extra] = NUL;
1010 p_extra = p_extra_free;
1011 c_extra = NUL;
1012 c_final = NUL;
1013 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
1014 }
1015 }
1016 }
1017#endif
1018
1019#ifdef FEAT_SIGNS
1020 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1021 {
1022 draw_state = WL_SIGN;
1023 // Show the sign column when there are any signs in this
1024 // buffer or when using Netbeans.
1025 if (signcolumn_on(wp))
1026 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1027 row, startrow, filler_lines, filler_todo, &c_extra,
1028 &c_final, extra, &p_extra, &n_extra, &char_attr);
1029 }
1030#endif
1031
1032 if (draw_state == WL_NR - 1 && n_extra == 0)
1033 {
1034 draw_state = WL_NR;
1035 // Display the absolute or relative line number. After the
1036 // first fill with blanks when the 'n' flag isn't in 'cpo'
1037 if ((wp->w_p_nu || wp->w_p_rnu)
1038 && (row == startrow
1039#ifdef FEAT_DIFF
1040 + filler_lines
1041#endif
1042 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1043 {
1044#ifdef FEAT_SIGNS
1045 // If 'signcolumn' is set to 'number' and a sign is present
1046 // in 'lnum', then display the sign instead of the line
1047 // number.
1048 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1049 && sign_present)
1050 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1051 row, startrow, filler_lines, filler_todo,
1052 &c_extra, &c_final, extra, &p_extra, &n_extra,
1053 &char_attr);
1054 else
1055#endif
1056 {
1057 // Draw the line number (empty space after wrapping).
1058 if (row == startrow
1059#ifdef FEAT_DIFF
1060 + filler_lines
1061#endif
1062 )
1063 {
1064 long num;
1065 char *fmt = "%*ld ";
1066
1067 if (wp->w_p_nu && !wp->w_p_rnu)
1068 // 'number' + 'norelativenumber'
1069 num = (long)lnum;
1070 else
1071 {
1072 // 'relativenumber', don't use negative numbers
1073 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1074 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1075 {
1076 // 'number' + 'relativenumber'
1077 num = lnum;
1078 fmt = "%-*ld ";
1079 }
1080 }
1081
1082 sprintf((char *)extra, fmt,
1083 number_width(wp), num);
1084 if (wp->w_skipcol > 0)
1085 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1086 *p_extra = '-';
1087#ifdef FEAT_RIGHTLEFT
1088 if (wp->w_p_rl) // reverse line numbers
1089 {
1090 char_u *p1, *p2;
1091 int t;
1092
1093 // like rl_mirror(), but keep the space at the end
1094 p2 = skiptowhite(extra) - 1;
1095 for (p1 = extra; p1 < p2; ++p1, --p2)
1096 {
1097 t = *p1;
1098 *p1 = *p2;
1099 *p2 = t;
1100 }
1101 }
1102#endif
1103 p_extra = extra;
1104 c_extra = NUL;
1105 c_final = NUL;
1106 }
1107 else
1108 {
1109 c_extra = ' ';
1110 c_final = NUL;
1111 }
1112 n_extra = number_width(wp) + 1;
1113 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1114#ifdef FEAT_SYN_HL
1115 // When 'cursorline' is set highlight the line number of
1116 // the current line differently.
1117 // When 'cursorlineopt' has "screenline" only highlight
1118 // the line number itself.
1119 // TODO: Can we use CursorLine instead of CursorLineNr
1120 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001121 if (wp->w_p_cul
1122 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 && (wp->w_p_culopt_flags & CULOPT_NBR)
1124 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001125 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1127#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001128 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1129 && HL_ATTR(HLF_LNA) != 0)
1130 // Use LineNrAbove
1131 char_attr = hl_combine_attr(wcr_attr,
1132 HL_ATTR(HLF_LNA));
1133 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1134 && HL_ATTR(HLF_LNB) != 0)
1135 // Use LineNrBelow
1136 char_attr = hl_combine_attr(wcr_attr,
1137 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 }
1139 }
1140 }
1141
1142#ifdef FEAT_LINEBREAK
1143 if (wp->w_p_brisbr && draw_state == WL_BRI - 1
1144 && n_extra == 0 && *p_sbr != NUL)
1145 // draw indent after showbreak value
1146 draw_state = WL_BRI;
1147 else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0)
1148 // After the showbreak, draw the breakindent
1149 draw_state = WL_BRI - 1;
1150
1151 // draw 'breakindent': indent wrapped text accordingly
1152 if (draw_state == WL_BRI - 1 && n_extra == 0)
1153 {
1154 draw_state = WL_BRI;
1155 // if need_showbreak is set, breakindent also applies
1156 if (wp->w_p_bri && n_extra == 0
1157 && (row != startrow || need_showbreak)
1158# ifdef FEAT_DIFF
1159 && filler_lines == 0
1160# endif
1161 )
1162 {
1163 char_attr = 0;
1164# ifdef FEAT_DIFF
1165 if (diff_hlf != (hlf_T)0)
1166 {
1167 char_attr = HL_ATTR(diff_hlf);
1168# ifdef FEAT_SYN_HL
1169 if (cul_attr != 0)
1170 char_attr = hl_combine_attr(char_attr, cul_attr);
1171# endif
1172 }
1173# endif
1174 p_extra = NULL;
1175 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001176 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 n_extra = get_breakindent_win(wp,
1178 ml_get_buf(wp->w_buffer, lnum, FALSE));
1179 // Correct end of highlighted area for 'breakindent',
1180 // required when 'linebreak' is also set.
1181 if (tocol == vcol)
1182 tocol += n_extra;
1183 }
1184 }
1185#endif
1186
1187#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1188 if (draw_state == WL_SBR - 1 && n_extra == 0)
1189 {
1190 draw_state = WL_SBR;
1191# ifdef FEAT_DIFF
1192 if (filler_todo > 0)
1193 {
1194 // Draw "deleted" diff line(s).
1195 if (char2cells(fill_diff) > 1)
1196 {
1197 c_extra = '-';
1198 c_final = NUL;
1199 }
1200 else
1201 {
1202 c_extra = fill_diff;
1203 c_final = NUL;
1204 }
1205# ifdef FEAT_RIGHTLEFT
1206 if (wp->w_p_rl)
1207 n_extra = col + 1;
1208 else
1209# endif
1210 n_extra = wp->w_width - col;
1211 char_attr = HL_ATTR(HLF_DED);
1212 }
1213# endif
1214# ifdef FEAT_LINEBREAK
1215 if (*p_sbr != NUL && need_showbreak)
1216 {
1217 // Draw 'showbreak' at the start of each broken line.
1218 p_extra = p_sbr;
1219 c_extra = NUL;
1220 c_final = NUL;
1221 n_extra = (int)STRLEN(p_sbr);
1222 char_attr = HL_ATTR(HLF_AT);
1223 need_showbreak = FALSE;
1224 vcol_sbr = vcol + MB_CHARLEN(p_sbr);
1225 // Correct end of highlighted area for 'showbreak',
1226 // required when 'linebreak' is also set.
1227 if (tocol == vcol)
1228 tocol += n_extra;
1229 // combine 'showbreak' with 'wincolor'
1230 if (win_attr != 0)
1231 char_attr = hl_combine_attr(win_attr, char_attr);
1232# ifdef FEAT_SYN_HL
1233 // combine 'showbreak' with 'cursorline'
1234 if (cul_attr != 0)
1235 char_attr = hl_combine_attr(char_attr, cul_attr);
1236# endif
1237 }
1238# endif
1239 }
1240#endif
1241
1242 if (draw_state == WL_LINE - 1 && n_extra == 0)
1243 {
1244 draw_state = WL_LINE;
1245 if (saved_n_extra)
1246 {
1247 // Continue item from end of wrapped line.
1248 n_extra = saved_n_extra;
1249 c_extra = saved_c_extra;
1250 c_final = saved_c_final;
1251 p_extra = saved_p_extra;
1252 char_attr = saved_char_attr;
1253 }
1254 else
1255 char_attr = win_attr;
1256 }
1257 }
1258#ifdef FEAT_SYN_HL
1259 if (cul_screenline)
1260 {
1261 if (draw_state == WL_LINE
1262 && vcol >= left_curline_col
1263 && vcol < right_curline_col)
1264 {
1265 cul_attr = HL_ATTR(HLF_CUL);
1266 line_attr = cul_attr;
1267 }
1268 else
1269 {
1270 cul_attr = 0;
1271 line_attr = line_attr_save;
1272 }
1273 }
1274#endif
1275
1276 // When still displaying '$' of change command, stop at cursor.
1277 // When only displaying the (relative) line number and that's done,
1278 // stop here.
1279 if ((dollar_vcol >= 0 && wp == curwin
1280 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
1281#ifdef FEAT_DIFF
1282 && filler_todo <= 0
1283#endif
1284 )
1285 || (number_only && draw_state > WL_NR))
1286 {
1287 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1288 screen_line_flags);
1289 // Pretend we have finished updating the window. Except when
1290 // 'cursorcolumn' is set.
1291#ifdef FEAT_SYN_HL
1292 if (wp->w_p_cuc)
1293 row = wp->w_cline_row + wp->w_cline_height;
1294 else
1295#endif
1296 row = wp->w_height;
1297 break;
1298 }
1299
Bram Moolenaar34390282019-10-16 14:38:26 +02001300 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 {
1302 // handle Visual or match highlighting in this line
1303 if (vcol == fromcol
1304 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1305 && (*mb_ptr2cells)(ptr) > 1)
1306 || ((int)vcol_prev == fromcol_prev
1307 && vcol_prev < vcol // not at margin
1308 && vcol < tocol))
1309 area_attr = vi_attr; // start highlighting
1310 else if (area_attr != 0
1311 && (vcol == tocol
1312 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1313 area_attr = 0; // stop highlighting
1314
1315#ifdef FEAT_SEARCH_EXTRA
1316 if (!n_extra)
1317 {
1318 // Check for start/end of 'hlsearch' and other matches.
1319 // After end, check for start/end of next match.
1320 // When another match, have to check for start again.
1321 v = (long)(ptr - line);
1322 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1323 &screen_search_hl, &has_match_conc,
1324 &match_conc, did_line_attr, lcs_eol_one);
1325 ptr = line + v; // "line" may have been changed
1326 }
1327#endif
1328
1329#ifdef FEAT_DIFF
1330 if (diff_hlf != (hlf_T)0)
1331 {
1332 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1333 && n_extra == 0)
1334 diff_hlf = HLF_TXD; // changed text
1335 if (diff_hlf == HLF_TXD && ptr - line > change_end
1336 && n_extra == 0)
1337 diff_hlf = HLF_CHD; // changed line
1338 line_attr = HL_ATTR(diff_hlf);
1339 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1340 && wp->w_p_culopt_flags != CULOPT_NBR
1341 && (!cul_screenline || (vcol >= left_curline_col
1342 && vcol <= right_curline_col)))
1343 line_attr = hl_combine_attr(
1344 line_attr, HL_ATTR(HLF_CUL));
1345 }
1346#endif
1347
1348#ifdef FEAT_TEXT_PROP
1349 if (text_props != NULL)
1350 {
1351 int pi;
1352 int bcol = (int)(ptr - line);
1353
1354 if (n_extra > 0)
1355 --bcol; // still working on the previous char, e.g. Tab
1356
1357 // Check if any active property ends.
1358 for (pi = 0; pi < text_props_active; ++pi)
1359 {
1360 int tpi = text_prop_idxs[pi];
1361
1362 if (bcol >= text_props[tpi].tp_col - 1
1363 + text_props[tpi].tp_len)
1364 {
1365 if (pi + 1 < text_props_active)
1366 mch_memmove(text_prop_idxs + pi,
1367 text_prop_idxs + pi + 1,
1368 sizeof(int)
1369 * (text_props_active - (pi + 1)));
1370 --text_props_active;
1371 --pi;
1372 }
1373 }
1374
1375 // Add any text property that starts in this column.
1376 while (text_prop_next < text_prop_count
1377 && bcol >= text_props[text_prop_next].tp_col - 1)
1378 text_prop_idxs[text_props_active++] = text_prop_next++;
1379
1380 text_prop_attr = 0;
1381 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001382 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 if (text_props_active > 0)
1384 {
1385 // Sort the properties on priority and/or starting last.
1386 // Then combine the attributes, highest priority last.
1387 current_text_props = text_props;
1388 current_buf = wp->w_buffer;
1389 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1390 sizeof(int), text_prop_compare);
1391
1392 for (pi = 0; pi < text_props_active; ++pi)
1393 {
1394 int tpi = text_prop_idxs[pi];
1395 proptype_T *pt = text_prop_type_by_id(
1396 wp->w_buffer, text_props[tpi].tp_type);
1397
1398 if (pt != NULL && pt->pt_hl_id > 0)
1399 {
1400 int pt_attr = syn_id2attr(pt->pt_hl_id);
1401
1402 text_prop_type = pt;
1403 text_prop_attr =
1404 hl_combine_attr(text_prop_attr, pt_attr);
1405 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1406 }
1407 }
1408 }
1409 }
1410#endif
1411
Bram Moolenaara74fda62019-10-19 17:38:03 +02001412#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001413 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001414 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001415 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001416# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001417 if (get_term_attr)
Bram Moolenaar34390282019-10-16 14:38:26 +02001418 syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001419# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001420 // Get syntax attribute.
1421 if (has_syntax)
1422 {
1423 // Get the syntax attribute for the character. If there
1424 // is an error, disable syntax highlighting.
1425 save_did_emsg = did_emsg;
1426 did_emsg = FALSE;
1427
1428 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001429 if (v == prev_syntax_col)
1430 // at same column again
1431 syntax_attr = prev_syntax_attr;
1432 else
1433 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001434# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001435 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001436# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001437 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001438# ifdef FEAT_SPELL
1439 has_spell ? &can_spell :
1440# endif
1441 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001442 prev_syntax_col = v;
1443 prev_syntax_attr = syntax_attr;
1444 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001445
Bram Moolenaar34390282019-10-16 14:38:26 +02001446 if (did_emsg)
1447 {
1448 wp->w_s->b_syn_error = TRUE;
1449 has_syntax = FALSE;
1450 syntax_attr = 0;
1451 }
1452 else
1453 did_emsg = save_did_emsg;
1454# ifdef SYN_TIME_LIMIT
1455 if (wp->w_s->b_syn_slow)
1456 has_syntax = FALSE;
1457# endif
1458
1459 // Need to get the line again, a multi-line regexp may
1460 // have made it invalid.
1461 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1462 ptr = line + v;
1463# ifdef FEAT_CONCEAL
1464 // no concealing past the end of the line, it interferes
1465 // with line highlighting
1466 if (*ptr == NUL)
1467 syntax_flags = 0;
1468 else
1469 syntax_flags = get_syntax_info(&syntax_seqnr);
1470# endif
1471 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001472 }
Bram Moolenaardbd43162019-11-09 21:28:14 +01001473# ifdef FEAT_TEXT_PROP
1474 // Combine text property highlight into syntax highlight.
1475 if (text_prop_type != NULL)
1476 {
1477 if (text_prop_combine)
1478 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1479 else
1480 syntax_attr = text_prop_attr;
1481 }
1482# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001483#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001484
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 // Decide which of the highlight attributes to use.
1486 attr_pri = TRUE;
1487#ifdef LINE_ATTR
1488 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001489 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001491# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001492 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001493# endif
1494 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001496 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001498# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001499 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001500# endif
1501 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1503 || vcol < fromcol || vcol_prev < fromcol_prev
1504 || vcol >= tocol))
1505 {
1506 // Use line_attr when not in the Visual or 'incsearch' area
1507 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001508# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001509 char_attr = hl_combine_attr(syntax_attr, line_attr);
1510# else
1511 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001512# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 attr_pri = FALSE;
1514 }
1515#else
1516 if (area_attr != 0)
1517 char_attr = area_attr;
1518 else if (search_attr != 0)
1519 char_attr = search_attr;
1520#endif
1521 else
1522 {
1523 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001525 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001526#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001527 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001528#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 }
1530 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001531
1532 // combine attribute with 'wincolor'
1533 if (win_attr != 0)
1534 {
1535 if (char_attr == 0)
1536 char_attr = win_attr;
1537 else
1538 char_attr = hl_combine_attr(win_attr, char_attr);
1539 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540
1541 // Get the next character to put on the screen.
1542
1543 // The "p_extra" points to the extra stuff that is inserted to
1544 // represent special characters (non-printable stuff) and other
1545 // things. When all characters are the same, c_extra is used.
1546 // If c_final is set, it will compulsorily be used at the end.
1547 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1548 // "p_extra[n_extra]".
1549 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1550 if (n_extra > 0)
1551 {
1552 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1553 {
1554 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1555 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1556 if (enc_utf8 && utf_char2len(c) > 1)
1557 {
1558 mb_utf8 = TRUE;
1559 u8cc[0] = 0;
1560 c = 0xc0;
1561 }
1562 else
1563 mb_utf8 = FALSE;
1564 }
1565 else
1566 {
1567 c = *p_extra;
1568 if (has_mbyte)
1569 {
1570 mb_c = c;
1571 if (enc_utf8)
1572 {
1573 // If the UTF-8 character is more than one byte:
1574 // Decode it into "mb_c".
1575 mb_l = utfc_ptr2len(p_extra);
1576 mb_utf8 = FALSE;
1577 if (mb_l > n_extra)
1578 mb_l = 1;
1579 else if (mb_l > 1)
1580 {
1581 mb_c = utfc_ptr2char(p_extra, u8cc);
1582 mb_utf8 = TRUE;
1583 c = 0xc0;
1584 }
1585 }
1586 else
1587 {
1588 // if this is a DBCS character, put it in "mb_c"
1589 mb_l = MB_BYTE2LEN(c);
1590 if (mb_l >= n_extra)
1591 mb_l = 1;
1592 else if (mb_l > 1)
1593 mb_c = (c << 8) + p_extra[1];
1594 }
1595 if (mb_l == 0) // at the NUL at end-of-line
1596 mb_l = 1;
1597
1598 // If a double-width char doesn't fit display a '>' in the
1599 // last column.
1600 if ((
1601# ifdef FEAT_RIGHTLEFT
1602 wp->w_p_rl ? (col <= 0) :
1603# endif
1604 (col >= wp->w_width - 1))
1605 && (*mb_char2cells)(mb_c) == 2)
1606 {
1607 c = '>';
1608 mb_c = c;
1609 mb_l = 1;
1610 mb_utf8 = FALSE;
1611 multi_attr = HL_ATTR(HLF_AT);
1612#ifdef FEAT_SYN_HL
1613 if (cul_attr)
1614 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1615#endif
1616 // put the pointer back to output the double-width
1617 // character at the start of the next line.
1618 ++n_extra;
1619 --p_extra;
1620 }
1621 else
1622 {
1623 n_extra -= mb_l - 1;
1624 p_extra += mb_l - 1;
1625 }
1626 }
1627 ++p_extra;
1628 }
1629 --n_extra;
1630 }
1631 else
1632 {
1633#ifdef FEAT_LINEBREAK
1634 int c0;
1635#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001636 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 // Get a character from the line itself.
1639 c = *ptr;
1640#ifdef FEAT_LINEBREAK
1641 c0 = *ptr;
1642#endif
1643 if (has_mbyte)
1644 {
1645 mb_c = c;
1646 if (enc_utf8)
1647 {
1648 // If the UTF-8 character is more than one byte: Decode it
1649 // into "mb_c".
1650 mb_l = utfc_ptr2len(ptr);
1651 mb_utf8 = FALSE;
1652 if (mb_l > 1)
1653 {
1654 mb_c = utfc_ptr2char(ptr, u8cc);
1655 // Overlong encoded ASCII or ASCII with composing char
1656 // is displayed normally, except a NUL.
1657 if (mb_c < 0x80)
1658 {
1659 c = mb_c;
1660#ifdef FEAT_LINEBREAK
1661 c0 = mb_c;
1662#endif
1663 }
1664 mb_utf8 = TRUE;
1665
1666 // At start of the line we can have a composing char.
1667 // Draw it as a space with a composing char.
1668 if (utf_iscomposing(mb_c))
1669 {
1670 int i;
1671
1672 for (i = Screen_mco - 1; i > 0; --i)
1673 u8cc[i] = u8cc[i - 1];
1674 u8cc[0] = mb_c;
1675 mb_c = ' ';
1676 }
1677 }
1678
1679 if ((mb_l == 1 && c >= 0x80)
1680 || (mb_l >= 1 && mb_c == 0)
1681 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1682 {
1683 // Illegal UTF-8 byte: display as <xx>.
1684 // Non-BMP character : display as ? or fullwidth ?.
1685 transchar_hex(extra, mb_c);
1686# ifdef FEAT_RIGHTLEFT
1687 if (wp->w_p_rl) // reverse
1688 rl_mirror(extra);
1689# endif
1690 p_extra = extra;
1691 c = *p_extra;
1692 mb_c = mb_ptr2char_adv(&p_extra);
1693 mb_utf8 = (c >= 0x80);
1694 n_extra = (int)STRLEN(p_extra);
1695 c_extra = NUL;
1696 c_final = NUL;
1697 if (area_attr == 0 && search_attr == 0)
1698 {
1699 n_attr = n_extra + 1;
1700 extra_attr = HL_ATTR(HLF_8);
1701 saved_attr2 = char_attr; // save current attr
1702 }
1703 }
1704 else if (mb_l == 0) // at the NUL at end-of-line
1705 mb_l = 1;
1706#ifdef FEAT_ARABIC
1707 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1708 {
1709 // Do Arabic shaping.
1710 int pc, pc1, nc;
1711 int pcc[MAX_MCO];
1712
1713 // The idea of what is the previous and next
1714 // character depends on 'rightleft'.
1715 if (wp->w_p_rl)
1716 {
1717 pc = prev_c;
1718 pc1 = prev_c1;
1719 nc = utf_ptr2char(ptr + mb_l);
1720 prev_c1 = u8cc[0];
1721 }
1722 else
1723 {
1724 pc = utfc_ptr2char(ptr + mb_l, pcc);
1725 nc = prev_c;
1726 pc1 = pcc[0];
1727 }
1728 prev_c = mb_c;
1729
1730 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1731 }
1732 else
1733 prev_c = mb_c;
1734#endif
1735 }
1736 else // enc_dbcs
1737 {
1738 mb_l = MB_BYTE2LEN(c);
1739 if (mb_l == 0) // at the NUL at end-of-line
1740 mb_l = 1;
1741 else if (mb_l > 1)
1742 {
1743 // We assume a second byte below 32 is illegal.
1744 // Hopefully this is OK for all double-byte encodings!
1745 if (ptr[1] >= 32)
1746 mb_c = (c << 8) + ptr[1];
1747 else
1748 {
1749 if (ptr[1] == NUL)
1750 {
1751 // head byte at end of line
1752 mb_l = 1;
1753 transchar_nonprint(extra, c);
1754 }
1755 else
1756 {
1757 // illegal tail byte
1758 mb_l = 2;
1759 STRCPY(extra, "XX");
1760 }
1761 p_extra = extra;
1762 n_extra = (int)STRLEN(extra) - 1;
1763 c_extra = NUL;
1764 c_final = NUL;
1765 c = *p_extra++;
1766 if (area_attr == 0 && search_attr == 0)
1767 {
1768 n_attr = n_extra + 1;
1769 extra_attr = HL_ATTR(HLF_8);
1770 saved_attr2 = char_attr; // save current attr
1771 }
1772 mb_c = c;
1773 }
1774 }
1775 }
1776 // If a double-width char doesn't fit display a '>' in the
1777 // last column; the character is displayed at the start of the
1778 // next line.
1779 if ((
1780# ifdef FEAT_RIGHTLEFT
1781 wp->w_p_rl ? (col <= 0) :
1782# endif
1783 (col >= wp->w_width - 1))
1784 && (*mb_char2cells)(mb_c) == 2)
1785 {
1786 c = '>';
1787 mb_c = c;
1788 mb_utf8 = FALSE;
1789 mb_l = 1;
1790 multi_attr = HL_ATTR(HLF_AT);
1791 // Put pointer back so that the character will be
1792 // displayed at the start of the next line.
1793 --ptr;
1794#ifdef FEAT_CONCEAL
1795 did_decrement_ptr = TRUE;
1796#endif
1797 }
1798 else if (*ptr != NUL)
1799 ptr += mb_l - 1;
1800
1801 // If a double-width char doesn't fit at the left side display
1802 // a '<' in the first column. Don't do this for unprintable
1803 // characters.
1804 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1805 {
1806 n_extra = 1;
1807 c_extra = MB_FILLER_CHAR;
1808 c_final = NUL;
1809 c = ' ';
1810 if (area_attr == 0 && search_attr == 0)
1811 {
1812 n_attr = n_extra + 1;
1813 extra_attr = HL_ATTR(HLF_AT);
1814 saved_attr2 = char_attr; // save current attr
1815 }
1816 mb_c = c;
1817 mb_utf8 = FALSE;
1818 mb_l = 1;
1819 }
1820
1821 }
1822 ++ptr;
1823
1824 if (extra_check)
1825 {
1826#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 // Check spelling (unless at the end of the line).
1828 // Only do this when there is no syntax highlighting, the
1829 // @Spell cluster is not used or the current syntax item
1830 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001831 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 if (has_spell && v >= word_end && v > cur_checked_col)
1833 {
1834 spell_attr = 0;
1835 if (c != 0 && (
1836# ifdef FEAT_SYN_HL
1837 !has_syntax ||
1838# endif
1839 can_spell))
1840 {
1841 char_u *prev_ptr, *p;
1842 int len;
1843 hlf_T spell_hlf = HLF_COUNT;
1844 if (has_mbyte)
1845 {
1846 prev_ptr = ptr - mb_l;
1847 v -= mb_l - 1;
1848 }
1849 else
1850 prev_ptr = ptr - 1;
1851
1852 // Use nextline[] if possible, it has the start of the
1853 // next line concatenated.
1854 if ((prev_ptr - line) - nextlinecol >= 0)
1855 p = nextline + (prev_ptr - line) - nextlinecol;
1856 else
1857 p = prev_ptr;
1858 cap_col -= (int)(prev_ptr - line);
1859 len = spell_check(wp, p, &spell_hlf, &cap_col,
1860 nochange);
1861 word_end = v + len;
1862
1863 // In Insert mode only highlight a word that
1864 // doesn't touch the cursor.
1865 if (spell_hlf != HLF_COUNT
1866 && (State & INSERT) != 0
1867 && wp->w_cursor.lnum == lnum
1868 && wp->w_cursor.col >=
1869 (colnr_T)(prev_ptr - line)
1870 && wp->w_cursor.col < (colnr_T)word_end)
1871 {
1872 spell_hlf = HLF_COUNT;
1873 spell_redraw_lnum = lnum;
1874 }
1875
1876 if (spell_hlf == HLF_COUNT && p != prev_ptr
1877 && (p - nextline) + len > nextline_idx)
1878 {
1879 // Remember that the good word continues at the
1880 // start of the next line.
1881 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001882 checked_col = (int)((p - nextline)
1883 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 }
1885
1886 // Turn index into actual attributes.
1887 if (spell_hlf != HLF_COUNT)
1888 spell_attr = highlight_attr[spell_hlf];
1889
1890 if (cap_col > 0)
1891 {
1892 if (p != prev_ptr
1893 && (p - nextline) + cap_col >= nextline_idx)
1894 {
1895 // Remember that the word in the next line
1896 // must start with a capital.
1897 capcol_lnum = lnum + 1;
1898 cap_col = (int)((p - nextline) + cap_col
1899 - nextline_idx);
1900 }
1901 else
1902 // Compute the actual column.
1903 cap_col += (int)(prev_ptr - line);
1904 }
1905 }
1906 }
1907 if (spell_attr != 0)
1908 {
1909 if (!attr_pri)
1910 char_attr = hl_combine_attr(char_attr, spell_attr);
1911 else
1912 char_attr = hl_combine_attr(spell_attr, char_attr);
1913 }
1914#endif
1915#ifdef FEAT_LINEBREAK
1916 // Found last space before word: check for line break.
1917 if (wp->w_p_lbr && c0 == c
1918 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1919 {
1920 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1921 char_u *p = ptr - (mb_off + 1);
1922
1923 // TODO: is passing p for start of the line OK?
1924 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1925 NULL) - 1;
1926 if (c == TAB && n_extra + col > wp->w_width)
1927# ifdef FEAT_VARTABS
1928 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1929 wp->w_buffer->b_p_vts_array) - 1;
1930# else
1931 n_extra = (int)wp->w_buffer->b_p_ts
1932 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1933# endif
1934
1935 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1936 c_final = NUL;
1937 if (VIM_ISWHITE(c))
1938 {
1939#ifdef FEAT_CONCEAL
1940 if (c == TAB)
1941 // See "Tab alignment" below.
1942 FIX_FOR_BOGUSCOLS;
1943#endif
1944 if (!wp->w_p_list)
1945 c = ' ';
1946 }
1947 }
1948#endif
1949
1950 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
1951 // But not when the character is followed by a composing
1952 // character (use mb_l to check that).
1953 if (wp->w_p_list
1954 && ((((c == 160 && mb_l == 1)
1955 || (mb_utf8
1956 && ((mb_c == 160 && mb_l == 2)
1957 || (mb_c == 0x202f && mb_l == 3))))
1958 && lcs_nbsp)
1959 || (c == ' '
1960 && mb_l == 1
1961 && lcs_space
1962 && ptr - line <= trailcol)))
1963 {
1964 c = (c == ' ') ? lcs_space : lcs_nbsp;
1965 if (area_attr == 0 && search_attr == 0)
1966 {
1967 n_attr = 1;
1968 extra_attr = HL_ATTR(HLF_8);
1969 saved_attr2 = char_attr; // save current attr
1970 }
1971 mb_c = c;
1972 if (enc_utf8 && utf_char2len(c) > 1)
1973 {
1974 mb_utf8 = TRUE;
1975 u8cc[0] = 0;
1976 c = 0xc0;
1977 }
1978 else
1979 mb_utf8 = FALSE;
1980 }
1981
1982 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
1983 {
1984 c = lcs_trail;
1985 if (!attr_pri)
1986 {
1987 n_attr = 1;
1988 extra_attr = HL_ATTR(HLF_8);
1989 saved_attr2 = char_attr; // save current attr
1990 }
1991 mb_c = c;
1992 if (enc_utf8 && utf_char2len(c) > 1)
1993 {
1994 mb_utf8 = TRUE;
1995 u8cc[0] = 0;
1996 c = 0xc0;
1997 }
1998 else
1999 mb_utf8 = FALSE;
2000 }
2001 }
2002
2003 // Handling of non-printable characters.
2004 if (!vim_isprintc(c))
2005 {
2006 // when getting a character from the file, we may have to
2007 // turn it into something else on the way to putting it
2008 // into "ScreenLines".
2009 if (c == TAB && (!wp->w_p_list || lcs_tab1))
2010 {
2011 int tab_len = 0;
2012 long vcol_adjusted = vcol; // removed showbreak length
2013#ifdef FEAT_LINEBREAK
2014 // only adjust the tab_len, when at the first column
2015 // after the showbreak value was drawn
2016 if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2017 vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
2018#endif
2019 // tab amount depends on current column
2020#ifdef FEAT_VARTABS
2021 tab_len = tabstop_padding(vcol_adjusted,
2022 wp->w_buffer->b_p_ts,
2023 wp->w_buffer->b_p_vts_array) - 1;
2024#else
2025 tab_len = (int)wp->w_buffer->b_p_ts
2026 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2027#endif
2028
2029#ifdef FEAT_LINEBREAK
2030 if (!wp->w_p_lbr || !wp->w_p_list)
2031#endif
2032 // tab amount depends on current column
2033 n_extra = tab_len;
2034#ifdef FEAT_LINEBREAK
2035 else
2036 {
2037 char_u *p;
2038 int len;
2039 int i;
2040 int saved_nextra = n_extra;
2041
2042#ifdef FEAT_CONCEAL
2043 if (vcol_off > 0)
2044 // there are characters to conceal
2045 tab_len += vcol_off;
2046 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2047 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2048 && n_extra > tab_len)
2049 tab_len += n_extra - tab_len;
2050#endif
2051
2052 // if n_extra > 0, it gives the number of chars, to
2053 // use for a tab, else we need to calculate the width
2054 // for a tab
2055 len = (tab_len * mb_char2len(lcs_tab2));
2056 if (n_extra > 0)
2057 len += n_extra - tab_len;
2058 c = lcs_tab1;
2059 p = alloc(len + 1);
2060 vim_memset(p, ' ', len);
2061 p[len] = NUL;
2062 vim_free(p_extra_free);
2063 p_extra_free = p;
2064 for (i = 0; i < tab_len; i++)
2065 {
2066 int lcs = lcs_tab2;
2067
2068 if (*p == NUL)
2069 {
2070 tab_len = i;
2071 break;
2072 }
2073
2074 // if lcs_tab3 is given, need to change the char
2075 // for tab
2076 if (lcs_tab3 && i == tab_len - 1)
2077 lcs = lcs_tab3;
2078 mb_char2bytes(lcs, p);
2079 p += mb_char2len(lcs);
2080 n_extra += mb_char2len(lcs)
2081 - (saved_nextra > 0 ? 1 : 0);
2082 }
2083 p_extra = p_extra_free;
2084#ifdef FEAT_CONCEAL
2085 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2086 // macro below, so need to adjust for that here
2087 if (vcol_off > 0)
2088 n_extra -= vcol_off;
2089#endif
2090 }
2091#endif
2092#ifdef FEAT_CONCEAL
2093 {
2094 int vc_saved = vcol_off;
2095
2096 // Tab alignment should be identical regardless of
2097 // 'conceallevel' value. So tab compensates of all
2098 // previous concealed characters, and thus resets
2099 // vcol_off and boguscols accumulated so far in the
2100 // line. Note that the tab can be longer than
2101 // 'tabstop' when there are concealed characters.
2102 FIX_FOR_BOGUSCOLS;
2103
2104 // Make sure, the highlighting for the tab char will be
2105 // correctly set further below (effectively reverts the
2106 // FIX_FOR_BOGSUCOLS macro
2107 if (n_extra == tab_len + vc_saved && wp->w_p_list
2108 && lcs_tab1)
2109 tab_len += vc_saved;
2110 }
2111#endif
2112 mb_utf8 = FALSE; // don't draw as UTF-8
2113 if (wp->w_p_list)
2114 {
2115 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2116#ifdef FEAT_LINEBREAK
2117 if (wp->w_p_lbr)
2118 c_extra = NUL; // using p_extra from above
2119 else
2120#endif
2121 c_extra = lcs_tab2;
2122 c_final = lcs_tab3;
2123 n_attr = tab_len + 1;
2124 extra_attr = HL_ATTR(HLF_8);
2125 saved_attr2 = char_attr; // save current attr
2126 mb_c = c;
2127 if (enc_utf8 && utf_char2len(c) > 1)
2128 {
2129 mb_utf8 = TRUE;
2130 u8cc[0] = 0;
2131 c = 0xc0;
2132 }
2133 }
2134 else
2135 {
2136 c_final = NUL;
2137 c_extra = ' ';
2138 c = ' ';
2139 }
2140 }
2141 else if (c == NUL
2142 && (wp->w_p_list
2143 || ((fromcol >= 0 || fromcol_prev >= 0)
2144 && tocol > vcol
2145 && VIsual_mode != Ctrl_V
2146 && (
2147# ifdef FEAT_RIGHTLEFT
2148 wp->w_p_rl ? (col >= 0) :
2149# endif
2150 (col < wp->w_width))
2151 && !(noinvcur
2152 && lnum == wp->w_cursor.lnum
2153 && (colnr_T)vcol == wp->w_virtcol)))
2154 && lcs_eol_one > 0)
2155 {
2156 // Display a '$' after the line or highlight an extra
2157 // character if the line break is included.
2158#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2159 // For a diff line the highlighting continues after the
2160 // "$".
2161 if (
2162# ifdef FEAT_DIFF
2163 diff_hlf == (hlf_T)0
2164# ifdef LINE_ATTR
2165 &&
2166# endif
2167# endif
2168# ifdef LINE_ATTR
2169 line_attr == 0
2170# endif
2171 )
2172#endif
2173 {
2174 // In virtualedit, visual selections may extend
2175 // beyond end of line.
2176 if (area_highlighting && virtual_active()
2177 && tocol != MAXCOL && vcol < tocol)
2178 n_extra = 0;
2179 else
2180 {
2181 p_extra = at_end_str;
2182 n_extra = 1;
2183 c_extra = NUL;
2184 c_final = NUL;
2185 }
2186 }
2187 if (wp->w_p_list && lcs_eol > 0)
2188 c = lcs_eol;
2189 else
2190 c = ' ';
2191 lcs_eol_one = -1;
2192 --ptr; // put it back at the NUL
2193 if (!attr_pri)
2194 {
2195 extra_attr = HL_ATTR(HLF_AT);
2196 n_attr = 1;
2197 }
2198 mb_c = c;
2199 if (enc_utf8 && utf_char2len(c) > 1)
2200 {
2201 mb_utf8 = TRUE;
2202 u8cc[0] = 0;
2203 c = 0xc0;
2204 }
2205 else
2206 mb_utf8 = FALSE; // don't draw as UTF-8
2207 }
2208 else if (c != NUL)
2209 {
2210 p_extra = transchar(c);
2211 if (n_extra == 0)
2212 n_extra = byte2cells(c) - 1;
2213#ifdef FEAT_RIGHTLEFT
2214 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2215 rl_mirror(p_extra); // reverse "<12>"
2216#endif
2217 c_extra = NUL;
2218 c_final = NUL;
2219#ifdef FEAT_LINEBREAK
2220 if (wp->w_p_lbr)
2221 {
2222 char_u *p;
2223
2224 c = *p_extra;
2225 p = alloc(n_extra + 1);
2226 vim_memset(p, ' ', n_extra);
2227 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2228 p[n_extra] = NUL;
2229 vim_free(p_extra_free);
2230 p_extra_free = p_extra = p;
2231 }
2232 else
2233#endif
2234 {
2235 n_extra = byte2cells(c) - 1;
2236 c = *p_extra++;
2237 }
2238 if (!attr_pri)
2239 {
2240 n_attr = n_extra + 1;
2241 extra_attr = HL_ATTR(HLF_8);
2242 saved_attr2 = char_attr; // save current attr
2243 }
2244 mb_utf8 = FALSE; // don't draw as UTF-8
2245 }
2246 else if (VIsual_active
2247 && (VIsual_mode == Ctrl_V
2248 || VIsual_mode == 'v')
2249 && virtual_active()
2250 && tocol != MAXCOL
2251 && vcol < tocol
2252 && (
2253#ifdef FEAT_RIGHTLEFT
2254 wp->w_p_rl ? (col >= 0) :
2255#endif
2256 (col < wp->w_width)))
2257 {
2258 c = ' ';
2259 --ptr; // put it back at the NUL
2260 }
2261#if defined(LINE_ATTR)
2262 else if ((
2263# ifdef FEAT_DIFF
2264 diff_hlf != (hlf_T)0 ||
2265# endif
2266# ifdef FEAT_TERMINAL
2267 win_attr != 0 ||
2268# endif
2269 line_attr != 0
2270 ) && (
2271# ifdef FEAT_RIGHTLEFT
2272 wp->w_p_rl ? (col >= 0) :
2273# endif
2274 (col
2275# ifdef FEAT_CONCEAL
2276 - boguscols
2277# endif
2278 < wp->w_width)))
2279 {
2280 // Highlight until the right side of the window
2281 c = ' ';
2282 --ptr; // put it back at the NUL
2283
2284 // Remember we do the char for line highlighting.
2285 ++did_line_attr;
2286
2287 // don't do search HL for the rest of the line
2288 if (line_attr != 0 && char_attr == search_attr
2289 && (did_line_attr > 1
2290 || (wp->w_p_list && lcs_eol > 0)))
2291 char_attr = line_attr;
2292# ifdef FEAT_DIFF
2293 if (diff_hlf == HLF_TXD)
2294 {
2295 diff_hlf = HLF_CHD;
2296 if (vi_attr == 0 || char_attr != vi_attr)
2297 {
2298 char_attr = HL_ATTR(diff_hlf);
2299 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2300 && wp->w_p_culopt_flags != CULOPT_NBR
2301 && (!cul_screenline
2302 || (vcol >= left_curline_col
2303 && vcol <= right_curline_col)))
2304 char_attr = hl_combine_attr(
2305 char_attr, HL_ATTR(HLF_CUL));
2306 }
2307 }
2308# endif
2309# ifdef FEAT_TERMINAL
2310 if (win_attr != 0)
2311 {
2312 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002313 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2314 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 {
2316 if (!cul_screenline || (vcol >= left_curline_col
2317 && vcol <= right_curline_col))
2318 char_attr = hl_combine_attr(
2319 char_attr, HL_ATTR(HLF_CUL));
2320 }
2321 else if (line_attr)
2322 char_attr = hl_combine_attr(char_attr, line_attr);
2323 }
2324# endif
2325 }
2326#endif
2327 }
2328
2329#ifdef FEAT_CONCEAL
2330 if ( wp->w_p_cole > 0
2331 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2332 conceal_cursor_line(wp))
2333 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2334 && !(lnum_in_visual_area
2335 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2336 {
2337 char_attr = conceal_attr;
2338 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
2339 && (syn_get_sub_char() != NUL || match_conc
2340 || wp->w_p_cole == 1)
2341 && wp->w_p_cole != 3)
2342 {
2343 // First time at this concealed item: display one
2344 // character.
2345 if (match_conc)
2346 c = match_conc;
2347 else if (syn_get_sub_char() != NUL)
2348 c = syn_get_sub_char();
2349 else if (lcs_conceal != NUL)
2350 c = lcs_conceal;
2351 else
2352 c = ' ';
2353
2354 prev_syntax_id = syntax_seqnr;
2355
2356 if (n_extra > 0)
2357 vcol_off += n_extra;
2358 vcol += n_extra;
2359 if (wp->w_p_wrap && n_extra > 0)
2360 {
2361# ifdef FEAT_RIGHTLEFT
2362 if (wp->w_p_rl)
2363 {
2364 col -= n_extra;
2365 boguscols -= n_extra;
2366 }
2367 else
2368# endif
2369 {
2370 boguscols += n_extra;
2371 col += n_extra;
2372 }
2373 }
2374 n_extra = 0;
2375 n_attr = 0;
2376 }
2377 else if (n_skip == 0)
2378 {
2379 is_concealing = TRUE;
2380 n_skip = 1;
2381 }
2382 mb_c = c;
2383 if (enc_utf8 && utf_char2len(c) > 1)
2384 {
2385 mb_utf8 = TRUE;
2386 u8cc[0] = 0;
2387 c = 0xc0;
2388 }
2389 else
2390 mb_utf8 = FALSE; // don't draw as UTF-8
2391 }
2392 else
2393 {
2394 prev_syntax_id = 0;
2395 is_concealing = FALSE;
2396 }
2397
2398 if (n_skip > 0 && did_decrement_ptr)
2399 // not showing the '>', put pointer back to avoid getting stuck
2400 ++ptr;
2401
2402#endif // FEAT_CONCEAL
2403 }
2404
2405#ifdef FEAT_CONCEAL
2406 // In the cursor line and we may be concealing characters: correct
2407 // the cursor column when we reach its position.
2408 if (!did_wcol && draw_state == WL_LINE
2409 && wp == curwin && lnum == wp->w_cursor.lnum
2410 && conceal_cursor_line(wp)
2411 && (int)wp->w_virtcol <= vcol + n_skip)
2412 {
2413# ifdef FEAT_RIGHTLEFT
2414 if (wp->w_p_rl)
2415 wp->w_wcol = wp->w_width - col + boguscols - 1;
2416 else
2417# endif
2418 wp->w_wcol = col - boguscols;
2419 wp->w_wrow = row;
2420 did_wcol = TRUE;
2421 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
2422 }
2423#endif
2424
2425 // Don't override visual selection highlighting.
2426 if (n_attr > 0
2427 && draw_state == WL_LINE
2428 && !attr_pri)
2429 {
2430#ifdef LINE_ATTR
2431 if (line_attr)
2432 char_attr = hl_combine_attr(extra_attr, line_attr);
2433 else
2434#endif
2435 char_attr = extra_attr;
2436 }
2437
2438#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2439 // XIM don't send preedit_start and preedit_end, but they send
2440 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2441 // im_is_preediting() here.
2442 if (p_imst == IM_ON_THE_SPOT
2443 && xic != NULL
2444 && lnum == wp->w_cursor.lnum
2445 && (State & INSERT)
2446 && !p_imdisable
2447 && im_is_preediting()
2448 && draw_state == WL_LINE)
2449 {
2450 colnr_T tcol;
2451
2452 if (preedit_end_col == MAXCOL)
2453 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2454 else
2455 tcol = preedit_end_col;
2456 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2457 {
2458 if (feedback_old_attr < 0)
2459 {
2460 feedback_col = 0;
2461 feedback_old_attr = char_attr;
2462 }
2463 char_attr = im_get_feedback_attr(feedback_col);
2464 if (char_attr < 0)
2465 char_attr = feedback_old_attr;
2466 feedback_col++;
2467 }
2468 else if (feedback_old_attr >= 0)
2469 {
2470 char_attr = feedback_old_attr;
2471 feedback_old_attr = -1;
2472 feedback_col = 0;
2473 }
2474 }
2475#endif
2476 // Handle the case where we are in column 0 but not on the first
2477 // character of the line and the user wants us to show us a
2478 // special character (via 'listchars' option "precedes:<char>".
2479 if (lcs_prec_todo != NUL
2480 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002481 && (wp->w_p_wrap ?
2482 (wp->w_skipcol > 0 && row == 0) :
2483 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484#ifdef FEAT_DIFF
2485 && filler_todo <= 0
2486#endif
2487 && draw_state > WL_NR
2488 && c != NUL)
2489 {
2490 c = lcs_prec;
2491 lcs_prec_todo = NUL;
2492 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2493 {
2494 // Double-width character being overwritten by the "precedes"
2495 // character, need to fill up half the character.
2496 c_extra = MB_FILLER_CHAR;
2497 c_final = NUL;
2498 n_extra = 1;
2499 n_attr = 2;
2500 extra_attr = HL_ATTR(HLF_AT);
2501 }
2502 mb_c = c;
2503 if (enc_utf8 && utf_char2len(c) > 1)
2504 {
2505 mb_utf8 = TRUE;
2506 u8cc[0] = 0;
2507 c = 0xc0;
2508 }
2509 else
2510 mb_utf8 = FALSE; // don't draw as UTF-8
2511 if (!attr_pri)
2512 {
2513 saved_attr3 = char_attr; // save current attr
2514 char_attr = HL_ATTR(HLF_AT); // later copied to char_attr
2515 n_attr3 = 1;
2516 }
2517 }
2518
2519 // At end of the text line or just after the last character.
2520 if ((c == NUL
2521#if defined(LINE_ATTR)
2522 || did_line_attr == 1
2523#endif
2524 ) && eol_hl_off == 0)
2525 {
2526#ifdef FEAT_SEARCH_EXTRA
2527 // flag to indicate whether prevcol equals startcol of search_hl or
2528 // one of the matches
2529 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2530 (long)(ptr - line) - (c == NUL));
2531#endif
2532 // Invert at least one char, used for Visual and empty line or
2533 // highlight match at end of line. If it's beyond the last
2534 // char on the screen, just overwrite that one (tricky!) Not
2535 // needed when a '$' was displayed for 'list'.
2536 if (lcs_eol == lcs_eol_one
2537 && ((area_attr != 0 && vcol == fromcol
2538 && (VIsual_mode != Ctrl_V
2539 || lnum == VIsual.lnum
2540 || lnum == curwin->w_cursor.lnum)
2541 && c == NUL)
2542#ifdef FEAT_SEARCH_EXTRA
2543 // highlight 'hlsearch' match at end of line
2544 || (prevcol_hl_flag
2545# ifdef FEAT_SYN_HL
2546 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2547 && !(wp == curwin && VIsual_active))
2548# endif
2549# ifdef FEAT_DIFF
2550 && diff_hlf == (hlf_T)0
2551# endif
2552# if defined(LINE_ATTR)
2553 && did_line_attr <= 1
2554# endif
2555 )
2556#endif
2557 ))
2558 {
2559 int n = 0;
2560
2561#ifdef FEAT_RIGHTLEFT
2562 if (wp->w_p_rl)
2563 {
2564 if (col < 0)
2565 n = 1;
2566 }
2567 else
2568#endif
2569 {
2570 if (col >= wp->w_width)
2571 n = -1;
2572 }
2573 if (n != 0)
2574 {
2575 // At the window boundary, highlight the last character
2576 // instead (better than nothing).
2577 off += n;
2578 col += n;
2579 }
2580 else
2581 {
2582 // Add a blank character to highlight.
2583 ScreenLines[off] = ' ';
2584 if (enc_utf8)
2585 ScreenLinesUC[off] = 0;
2586 }
2587#ifdef FEAT_SEARCH_EXTRA
2588 if (area_attr == 0)
2589 {
2590 // Use attributes from match with highest priority among
2591 // 'search_hl' and the match list.
2592 get_search_match_hl(wp, &screen_search_hl,
2593 (long)(ptr - line), &char_attr);
2594 }
2595#endif
2596 ScreenAttrs[off] = char_attr;
2597#ifdef FEAT_RIGHTLEFT
2598 if (wp->w_p_rl)
2599 {
2600 --col;
2601 --off;
2602 }
2603 else
2604#endif
2605 {
2606 ++col;
2607 ++off;
2608 }
2609 ++vcol;
2610 eol_hl_off = 1;
2611 }
2612 }
2613
2614 // At end of the text line.
2615 if (c == NUL)
2616 {
2617#ifdef FEAT_SYN_HL
2618 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2619 if (wp->w_p_wrap)
2620 v = wp->w_skipcol;
2621 else
2622 v = wp->w_leftcol;
2623
2624 // check if line ends before left margin
2625 if (vcol < v + col - win_col_off(wp))
2626 vcol = v + col - win_col_off(wp);
2627#ifdef FEAT_CONCEAL
2628 // Get rid of the boguscols now, we want to draw until the right
2629 // edge for 'cursorcolumn'.
2630 col -= boguscols;
2631 boguscols = 0;
2632#endif
2633
2634 if (draw_color_col)
2635 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2636
2637 if (((wp->w_p_cuc
2638 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2639 && (int)wp->w_virtcol <
2640 wp->w_width * (row - startrow + 1) + v
2641 && lnum != wp->w_cursor.lnum)
2642 || draw_color_col
2643 || win_attr != 0)
2644# ifdef FEAT_RIGHTLEFT
2645 && !wp->w_p_rl
2646# endif
2647 )
2648 {
2649 int rightmost_vcol = 0;
2650 int i;
2651
2652 if (wp->w_p_cuc)
2653 rightmost_vcol = wp->w_virtcol;
2654 if (draw_color_col)
2655 // determine rightmost colorcolumn to possibly draw
2656 for (i = 0; color_cols[i] >= 0; ++i)
2657 if (rightmost_vcol < color_cols[i])
2658 rightmost_vcol = color_cols[i];
2659
2660 while (col < wp->w_width)
2661 {
2662 ScreenLines[off] = ' ';
2663 if (enc_utf8)
2664 ScreenLinesUC[off] = 0;
2665 ++col;
2666 if (draw_color_col)
2667 draw_color_col = advance_color_col(VCOL_HLC,
2668 &color_cols);
2669
2670 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2671 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2672 else if (draw_color_col && VCOL_HLC == *color_cols)
2673 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2674 else
2675 ScreenAttrs[off++] = win_attr;
2676
2677 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2678 break;
2679
2680 ++vcol;
2681 }
2682 }
2683#endif
2684
2685 screen_line(screen_row, wp->w_wincol, col,
2686 (int)wp->w_width, screen_line_flags);
2687 row++;
2688
2689 // Update w_cline_height and w_cline_folded if the cursor line was
2690 // updated (saves a call to plines() later).
2691 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2692 {
2693 curwin->w_cline_row = startrow;
2694 curwin->w_cline_height = row - startrow;
2695#ifdef FEAT_FOLDING
2696 curwin->w_cline_folded = FALSE;
2697#endif
2698 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2699 }
2700
2701 break;
2702 }
2703
2704 // Show "extends" character from 'listchars' if beyond the line end and
2705 // 'list' is set.
2706 if (lcs_ext != NUL
2707 && wp->w_p_list
2708 && !wp->w_p_wrap
2709#ifdef FEAT_DIFF
2710 && filler_todo <= 0
2711#endif
2712 && (
2713#ifdef FEAT_RIGHTLEFT
2714 wp->w_p_rl ? col == 0 :
2715#endif
2716 col == wp->w_width - 1)
2717 && (*ptr != NUL
2718 || (wp->w_p_list && lcs_eol_one > 0)
2719 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2720 {
2721 c = lcs_ext;
2722 char_attr = HL_ATTR(HLF_AT);
2723 mb_c = c;
2724 if (enc_utf8 && utf_char2len(c) > 1)
2725 {
2726 mb_utf8 = TRUE;
2727 u8cc[0] = 0;
2728 c = 0xc0;
2729 }
2730 else
2731 mb_utf8 = FALSE;
2732 }
2733
2734#ifdef FEAT_SYN_HL
2735 // advance to the next 'colorcolumn'
2736 if (draw_color_col)
2737 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2738
2739 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2740 // highlight the cursor position itself.
2741 // Also highlight the 'colorcolumn' if it is different than
2742 // 'cursorcolumn'
2743 vcol_save_attr = -1;
2744 if (draw_state == WL_LINE && !lnum_in_visual_area
2745 && search_attr == 0 && area_attr == 0)
2746 {
2747 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2748 && lnum != wp->w_cursor.lnum)
2749 {
2750 vcol_save_attr = char_attr;
2751 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2752 }
2753 else if (draw_color_col && VCOL_HLC == *color_cols)
2754 {
2755 vcol_save_attr = char_attr;
2756 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2757 }
2758 }
2759#endif
2760
2761 // Store character to be displayed.
2762 // Skip characters that are left of the screen for 'nowrap'.
2763 vcol_prev = vcol;
2764 if (draw_state < WL_LINE || n_skip <= 0)
2765 {
2766 // Store the character.
2767#if defined(FEAT_RIGHTLEFT)
2768 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2769 {
2770 // A double-wide character is: put first halve in left cell.
2771 --off;
2772 --col;
2773 }
2774#endif
2775 ScreenLines[off] = c;
2776 if (enc_dbcs == DBCS_JPNU)
2777 {
2778 if ((mb_c & 0xff00) == 0x8e00)
2779 ScreenLines[off] = 0x8e;
2780 ScreenLines2[off] = mb_c & 0xff;
2781 }
2782 else if (enc_utf8)
2783 {
2784 if (mb_utf8)
2785 {
2786 int i;
2787
2788 ScreenLinesUC[off] = mb_c;
2789 if ((c & 0xff) == 0)
2790 ScreenLines[off] = 0x80; // avoid storing zero
2791 for (i = 0; i < Screen_mco; ++i)
2792 {
2793 ScreenLinesC[i][off] = u8cc[i];
2794 if (u8cc[i] == 0)
2795 break;
2796 }
2797 }
2798 else
2799 ScreenLinesUC[off] = 0;
2800 }
2801 if (multi_attr)
2802 {
2803 ScreenAttrs[off] = multi_attr;
2804 multi_attr = 0;
2805 }
2806 else
2807 ScreenAttrs[off] = char_attr;
2808
2809 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2810 {
2811 // Need to fill two screen columns.
2812 ++off;
2813 ++col;
2814 if (enc_utf8)
2815 // UTF-8: Put a 0 in the second screen char.
2816 ScreenLines[off] = 0;
2817 else
2818 // DBCS: Put second byte in the second screen char.
2819 ScreenLines[off] = mb_c & 0xff;
2820 if (draw_state > WL_NR
2821#ifdef FEAT_DIFF
2822 && filler_todo <= 0
2823#endif
2824 )
2825 ++vcol;
2826 // When "tocol" is halfway a character, set it to the end of
2827 // the character, otherwise highlighting won't stop.
2828 if (tocol == vcol)
2829 ++tocol;
2830#ifdef FEAT_RIGHTLEFT
2831 if (wp->w_p_rl)
2832 {
2833 // now it's time to backup one cell
2834 --off;
2835 --col;
2836 }
2837#endif
2838 }
2839#ifdef FEAT_RIGHTLEFT
2840 if (wp->w_p_rl)
2841 {
2842 --off;
2843 --col;
2844 }
2845 else
2846#endif
2847 {
2848 ++off;
2849 ++col;
2850 }
2851 }
2852#ifdef FEAT_CONCEAL
2853 else if (wp->w_p_cole > 0 && is_concealing)
2854 {
2855 --n_skip;
2856 ++vcol_off;
2857 if (n_extra > 0)
2858 vcol_off += n_extra;
2859 if (wp->w_p_wrap)
2860 {
2861 // Special voodoo required if 'wrap' is on.
2862 //
2863 // Advance the column indicator to force the line
2864 // drawing to wrap early. This will make the line
2865 // take up the same screen space when parts are concealed,
2866 // so that cursor line computations aren't messed up.
2867 //
2868 // To avoid the fictitious advance of 'col' causing
2869 // trailing junk to be written out of the screen line
2870 // we are building, 'boguscols' keeps track of the number
2871 // of bad columns we have advanced.
2872 if (n_extra > 0)
2873 {
2874 vcol += n_extra;
2875# ifdef FEAT_RIGHTLEFT
2876 if (wp->w_p_rl)
2877 {
2878 col -= n_extra;
2879 boguscols -= n_extra;
2880 }
2881 else
2882# endif
2883 {
2884 col += n_extra;
2885 boguscols += n_extra;
2886 }
2887 n_extra = 0;
2888 n_attr = 0;
2889 }
2890
2891
2892 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2893 {
2894 // Need to fill two screen columns.
2895# ifdef FEAT_RIGHTLEFT
2896 if (wp->w_p_rl)
2897 {
2898 --boguscols;
2899 --col;
2900 }
2901 else
2902# endif
2903 {
2904 ++boguscols;
2905 ++col;
2906 }
2907 }
2908
2909# ifdef FEAT_RIGHTLEFT
2910 if (wp->w_p_rl)
2911 {
2912 --boguscols;
2913 --col;
2914 }
2915 else
2916# endif
2917 {
2918 ++boguscols;
2919 ++col;
2920 }
2921 }
2922 else
2923 {
2924 if (n_extra > 0)
2925 {
2926 vcol += n_extra;
2927 n_extra = 0;
2928 n_attr = 0;
2929 }
2930 }
2931
2932 }
2933#endif // FEAT_CONCEAL
2934 else
2935 --n_skip;
2936
2937 // Only advance the "vcol" when after the 'number' or 'relativenumber'
2938 // column.
2939 if (draw_state > WL_NR
2940#ifdef FEAT_DIFF
2941 && filler_todo <= 0
2942#endif
2943 )
2944 ++vcol;
2945
2946#ifdef FEAT_SYN_HL
2947 if (vcol_save_attr >= 0)
2948 char_attr = vcol_save_attr;
2949#endif
2950
2951 // restore attributes after "predeces" in 'listchars'
2952 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
2953 char_attr = saved_attr3;
2954
2955 // restore attributes after last 'listchars' or 'number' char
2956 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
2957 char_attr = saved_attr2;
2958
2959 // At end of screen line and there is more to come: Display the line
2960 // so far. If there is no more to display it is caught above.
2961 if ((
2962#ifdef FEAT_RIGHTLEFT
2963 wp->w_p_rl ? (col < 0) :
2964#endif
2965 (col >= wp->w_width))
2966 && (*ptr != NUL
2967#ifdef FEAT_DIFF
2968 || filler_todo > 0
2969#endif
2970 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
2971 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
2972 )
2973 {
2974#ifdef FEAT_CONCEAL
2975 screen_line(screen_row, wp->w_wincol, col - boguscols,
2976 (int)wp->w_width, screen_line_flags);
2977 boguscols = 0;
2978#else
2979 screen_line(screen_row, wp->w_wincol, col,
2980 (int)wp->w_width, screen_line_flags);
2981#endif
2982 ++row;
2983 ++screen_row;
2984
2985 // When not wrapping and finished diff lines, or when displayed
2986 // '$' and highlighting until last column, break here.
2987 if ((!wp->w_p_wrap
2988#ifdef FEAT_DIFF
2989 && filler_todo <= 0
2990#endif
2991 ) || lcs_eol_one == -1)
2992 break;
2993
2994 // When the window is too narrow draw all "@" lines.
2995 if (draw_state != WL_LINE
2996#ifdef FEAT_DIFF
2997 && filler_todo <= 0
2998#endif
2999 )
3000 {
3001 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3002 draw_vsep_win(wp, row);
3003 row = endrow;
3004 }
3005
3006 // When line got too long for screen break here.
3007 if (row == endrow)
3008 {
3009 ++row;
3010 break;
3011 }
3012
3013 if (screen_cur_row == screen_row - 1
3014#ifdef FEAT_DIFF
3015 && filler_todo <= 0
3016#endif
3017 && wp->w_width == Columns)
3018 {
3019 // Remember that the line wraps, used for modeless copy.
3020 LineWraps[screen_row - 1] = TRUE;
3021
3022 // Special trick to make copy/paste of wrapped lines work with
3023 // xterm/screen: write an extra character beyond the end of
3024 // the line. This will work with all terminal types
3025 // (regardless of the xn,am settings).
3026 // Only do this on a fast tty.
3027 // Only do this if the cursor is on the current line
3028 // (something has been written in it).
3029 // Don't do this for the GUI.
3030 // Don't do this for double-width characters.
3031 // Don't do this for a window not at the right screen border.
3032 if (p_tf
3033#ifdef FEAT_GUI
3034 && !gui.in_use
3035#endif
3036 && !(has_mbyte
3037 && ((*mb_off2cells)(LineOffset[screen_row],
3038 LineOffset[screen_row] + screen_Columns)
3039 == 2
3040 || (*mb_off2cells)(LineOffset[screen_row - 1]
3041 + (int)Columns - 2,
3042 LineOffset[screen_row] + screen_Columns)
3043 == 2)))
3044 {
3045 // First make sure we are at the end of the screen line,
3046 // then output the same character again to let the
3047 // terminal know about the wrap. If the terminal doesn't
3048 // auto-wrap, we overwrite the character.
3049 if (screen_cur_col != wp->w_width)
3050 screen_char(LineOffset[screen_row - 1]
3051 + (unsigned)Columns - 1,
3052 screen_row - 1, (int)(Columns - 1));
3053
3054 // When there is a multi-byte character, just output a
3055 // space to keep it simple.
3056 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3057 screen_row - 1] + (Columns - 1)]) > 1)
3058 out_char(' ');
3059 else
3060 out_char(ScreenLines[LineOffset[screen_row - 1]
3061 + (Columns - 1)]);
3062 // force a redraw of the first char on the next line
3063 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3064 screen_start(); // don't know where cursor is now
3065 }
3066 }
3067
3068 col = 0;
3069 off = (unsigned)(current_ScreenLine - ScreenLines);
3070#ifdef FEAT_RIGHTLEFT
3071 if (wp->w_p_rl)
3072 {
3073 col = wp->w_width - 1; // col is not used if breaking!
3074 off += col;
3075 }
3076#endif
3077
3078 // reset the drawing state for the start of a wrapped line
3079 draw_state = WL_START;
3080 saved_n_extra = n_extra;
3081 saved_p_extra = p_extra;
3082 saved_c_extra = c_extra;
3083 saved_c_final = c_final;
3084#ifdef FEAT_SYN_HL
3085 if (!(cul_screenline
3086# ifdef FEAT_DIFF
3087 && diff_hlf == (hlf_T)0)
3088# endif
3089 )
3090 saved_char_attr = char_attr;
3091 else
3092#endif
3093 saved_char_attr = 0;
3094 n_extra = 0;
3095 lcs_prec_todo = lcs_prec;
3096#ifdef FEAT_LINEBREAK
3097# ifdef FEAT_DIFF
3098 if (filler_todo <= 0)
3099# endif
3100 need_showbreak = TRUE;
3101#endif
3102#ifdef FEAT_DIFF
3103 --filler_todo;
3104 // When the filler lines are actually below the last line of the
3105 // file, don't draw the line itself, break here.
3106 if (filler_todo == 0 && wp->w_botfill)
3107 break;
3108#endif
3109 }
3110
3111 } // for every character in the line
3112
3113#ifdef FEAT_SPELL
3114 // After an empty line check first word for capital.
3115 if (*skipwhite(line) == NUL)
3116 {
3117 capcol_lnum = lnum + 1;
3118 cap_col = 0;
3119 }
3120#endif
3121#ifdef FEAT_TEXT_PROP
3122 vim_free(text_props);
3123 vim_free(text_prop_idxs);
3124#endif
3125
3126 vim_free(p_extra_free);
3127 return row;
3128}