blob: 5fcdc4945712a6bccc45436b21a5421ffdf17780 [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/*
Bram Moolenaare413ea02021-11-24 16:20:13 +000080 * Return TRUE if CursorLineSign highlight is to be used.
81 */
82 static int
83use_cursor_line_sign(win_T *wp, linenr_T lnum)
84{
85 return wp->w_p_cul
86 && lnum == wp->w_cursor.lnum
87 && (wp->w_p_culopt_flags & CULOPT_NBR);
88}
89
90/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020091 * Get information needed to display the sign in line 'lnum' in window 'wp'.
92 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
93 * Otherwise the sign is going to be displayed in the sign column.
94 */
95 static void
96get_sign_display_info(
97 int nrcol,
98 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +000099 linenr_T lnum,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200100 sign_attrs_T *sattr,
101 int wcr_attr,
102 int row,
103 int startrow,
104 int filler_lines UNUSED,
105 int filler_todo UNUSED,
106 int *c_extrap,
107 int *c_finalp,
108 char_u *extra,
109 char_u **pp_extra,
110 int *n_extrap,
111 int *char_attrp)
112{
113 int text_sign;
114# ifdef FEAT_SIGN_ICONS
115 int icon_sign;
116# endif
117
118 // Draw two cells with the sign value or blank.
119 *c_extrap = ' ';
120 *c_finalp = NUL;
121 if (nrcol)
122 *n_extrap = number_width(wp) + 1;
123 else
124 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000125 if (use_cursor_line_sign(wp, lnum))
126 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
127 else
128 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200129 *n_extrap = 2;
130 }
131
132 if (row == startrow
133#ifdef FEAT_DIFF
134 + filler_lines && filler_todo <= 0
135#endif
136 )
137 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200138 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200139# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200140 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141 if (gui.in_use && icon_sign != 0)
142 {
143 // Use the image in this position.
144 if (nrcol)
145 {
146 *c_extrap = NUL;
147 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
148 *pp_extra = extra;
149 *n_extrap = (int)STRLEN(*pp_extra);
150 }
151 else
152 *c_extrap = SIGN_BYTE;
153# ifdef FEAT_NETBEANS_INTG
154 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
155 {
156 if (nrcol)
157 {
158 *c_extrap = NUL;
159 sprintf((char *)extra, "%-*c ", number_width(wp),
160 MULTISIGN_BYTE);
161 *pp_extra = extra;
162 *n_extrap = (int)STRLEN(*pp_extra);
163 }
164 else
165 *c_extrap = MULTISIGN_BYTE;
166 }
167# endif
168 *c_finalp = NUL;
169 *char_attrp = icon_sign;
170 }
171 else
172# endif
173 if (text_sign != 0)
174 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200175 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200176 if (*pp_extra != NULL)
177 {
178 if (nrcol)
179 {
180 int n, width = number_width(wp) - 2;
181
182 for (n = 0; n < width; n++)
183 extra[n] = ' ';
184 extra[n] = 0;
185 STRCAT(extra, *pp_extra);
186 STRCAT(extra, " ");
187 *pp_extra = extra;
188 }
189 *c_extrap = NUL;
190 *c_finalp = NUL;
191 *n_extrap = (int)STRLEN(*pp_extra);
192 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
194 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
195 *char_attrp = sattr->sat_culhl;
196 else
197 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 }
199 }
200}
201#endif
202
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100203#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200204static textprop_T *current_text_props = NULL;
205static buf_T *current_buf = NULL;
206
207 static int
208text_prop_compare(const void *s1, const void *s2)
209{
210 int idx1, idx2;
211 proptype_T *pt1, *pt2;
212 colnr_T col1, col2;
213
214 idx1 = *(int *)s1;
215 idx2 = *(int *)s2;
216 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
217 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
218 if (pt1 == pt2)
219 return 0;
220 if (pt1 == NULL)
221 return -1;
222 if (pt2 == NULL)
223 return 1;
224 if (pt1->pt_priority != pt2->pt_priority)
225 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
226 col1 = current_text_props[idx1].tp_col;
227 col2 = current_text_props[idx2].tp_col;
228 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
229}
230#endif
231
232/*
233 * Display line "lnum" of window 'wp' on the screen.
234 * Start at row "startrow", stop when "endrow" is reached.
235 * wp->w_virtcol needs to be valid.
236 *
237 * Return the number of last row the line occupies.
238 */
239 int
240win_line(
241 win_T *wp,
242 linenr_T lnum,
243 int startrow,
244 int endrow,
245 int nochange UNUSED, // not updating for changed text
246 int number_only) // only update the number column
247{
248 int col = 0; // visual column on screen
249 unsigned off; // offset in ScreenLines/ScreenAttrs
250 int c = 0; // init for GCC
251 long vcol = 0; // virtual column (for tabs)
252#ifdef FEAT_LINEBREAK
253 long vcol_sbr = -1; // virtual column after showbreak
254#endif
255 long vcol_prev = -1; // "vcol" of previous character
256 char_u *line; // current line
257 char_u *ptr; // current position in "line"
258 int row; // row in the window, excl w_winrow
259 int screen_row; // row on the screen, incl w_winrow
260
261 char_u extra[21]; // "%ld " and 'fdc' must fit in here
262 int n_extra = 0; // number of extra chars
263 char_u *p_extra = NULL; // string of extra chars, plus NUL
264 char_u *p_extra_free = NULL; // p_extra needs to be freed
265 int c_extra = NUL; // extra chars, all the same
266 int c_final = NUL; // final char, mandatory if set
267 int extra_attr = 0; // attributes when n_extra != 0
268 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100269 // displaying eol at end-of-line
270 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
271 int lcs_prec_todo = wp->w_lcs_chars.prec; // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272
273 // saved "extra" items for when draw_state becomes WL_LINE (again)
274 int saved_n_extra = 0;
275 char_u *saved_p_extra = NULL;
276 int saved_c_extra = 0;
277 int saved_c_final = 0;
278 int saved_char_attr = 0;
279
280 int n_attr = 0; // chars with special attr
281 int saved_attr2 = 0; // char_attr saved for n_attr
282 int n_attr3 = 0; // chars with overruling special attr
283 int saved_attr3 = 0; // char_attr saved for n_attr3
284
285 int n_skip = 0; // nr of chars to skip for 'nowrap'
286
287 int fromcol = -10; // start of inverting
288 int tocol = MAXCOL; // end of inverting
289 int fromcol_prev = -2; // start of inverting after cursor
290 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 int lnum_in_visual_area = FALSE;
292 pos_T pos;
293 long v;
294
295 int char_attr = 0; // attributes for next character
296 int attr_pri = FALSE; // char_attr has priority
297 int area_highlighting = FALSE; // Visual or incsearch highlighting
298 // in this line
299 int vi_attr = 0; // attributes for Visual and incsearch
300 // highlighting
301 int wcr_attr = 0; // attributes from 'wincolor'
302 int win_attr = 0; // background for whole window, except
303 // margins and "~" lines.
304 int area_attr = 0; // attributes desired by highlighting
305 int search_attr = 0; // attributes desired by 'hlsearch'
306#ifdef FEAT_SYN_HL
307 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
308 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200309 int prev_syntax_col = -1; // column of prev_syntax_attr
310 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 int has_syntax = FALSE; // this buffer has syntax highl.
312 int save_did_emsg;
313 int draw_color_col = FALSE; // highlight colorcolumn
314 int *color_cols = NULL; // pointer to according columns array
315#endif
316 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100317#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 int text_prop_count;
319 int text_prop_next = 0; // next text property to use
320 textprop_T *text_props = NULL;
321 int *text_prop_idxs = NULL;
322 int text_props_active = 0;
323 proptype_T *text_prop_type = NULL;
324 int text_prop_attr = 0;
325 int text_prop_combine = FALSE;
326#endif
327#ifdef FEAT_SPELL
328 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200329 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330# define SPWORDLEN 150
331 char_u nextline[SPWORDLEN * 2];// text with start of the next line
332 int nextlinecol = 0; // column where nextline[] starts
333 int nextline_idx = 0; // index in nextline[] where next line
334 // starts
335 int spell_attr = 0; // attributes desired by spelling
336 int word_end = 0; // last byte with same spell_attr
337 static linenr_T checked_lnum = 0; // line number for "checked_col"
338 static int checked_col = 0; // column in "checked_lnum" up to which
339 // there are no spell errors
340 static int cap_col = -1; // column to check for Cap word
341 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
342 int cur_checked_col = 0; // checked column for current line
343#endif
344 int extra_check = 0; // has extra highlighting
345 int multi_attr = 0; // attributes desired by multibyte
346 int mb_l = 1; // multi-byte byte length
347 int mb_c = 0; // decoded multi-byte character
348 int mb_utf8 = FALSE; // screen char is UTF-8 char
349 int u8cc[MAX_MCO]; // composing UTF-8 chars
350#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
351 int filler_lines = 0; // nr of filler lines to be drawn
352 int filler_todo = 0; // nr of filler lines still to do + 1
353#endif
354#ifdef FEAT_DIFF
355 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
356 int change_start = MAXCOL; // first col of changed area
357 int change_end = -1; // last col of changed area
358#endif
359 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100360 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200361 int in_multispace = FALSE; // in multiple consecutive spaces
362 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200363#ifdef FEAT_LINEBREAK
364 int need_showbreak = FALSE; // overlong line, skipping first x
365 // chars
366#endif
367#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
368 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
369# define LINE_ATTR
370 int line_attr = 0; // attribute for the whole line
371 int line_attr_save;
372#endif
373#ifdef FEAT_SIGNS
374 int sign_present = FALSE;
375 sign_attrs_T sattr;
376#endif
377#ifdef FEAT_ARABIC
378 int prev_c = 0; // previous Arabic character
379 int prev_c1 = 0; // first composing char for prev_c
380#endif
381#if defined(LINE_ATTR)
382 int did_line_attr = 0;
383#endif
384#ifdef FEAT_TERMINAL
385 int get_term_attr = FALSE;
386#endif
387#ifdef FEAT_SYN_HL
388 int cul_attr = 0; // set when 'cursorline' active
389
390 // 'cursorlineopt' has "screenline" and cursor is in this line
391 int cul_screenline = FALSE;
392
393 // margin columns for the screen line, needed for when 'cursorlineopt'
394 // contains "screenline"
395 int left_curline_col = 0;
396 int right_curline_col = 0;
397#endif
398
399 // draw_state: items that are drawn in sequence:
400#define WL_START 0 // nothing done yet
401#ifdef FEAT_CMDWIN
402# define WL_CMDLINE WL_START + 1 // cmdline window column
403#else
404# define WL_CMDLINE WL_START
405#endif
406#ifdef FEAT_FOLDING
407# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
408#else
409# define WL_FOLD WL_CMDLINE
410#endif
411#ifdef FEAT_SIGNS
412# define WL_SIGN WL_FOLD + 1 // column for signs
413#else
414# define WL_SIGN WL_FOLD // column for signs
415#endif
416#define WL_NR WL_SIGN + 1 // line number
417#ifdef FEAT_LINEBREAK
418# define WL_BRI WL_NR + 1 // 'breakindent'
419#else
420# define WL_BRI WL_NR
421#endif
422#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
423# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
424#else
425# define WL_SBR WL_BRI
426#endif
427#define WL_LINE WL_SBR + 1 // text in the line
428 int draw_state = WL_START; // what to draw next
429#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
430 int feedback_col = 0;
431 int feedback_old_attr = -1;
432#endif
433 int screen_line_flags = 0;
434
435#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
436 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000437 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200438#endif
439#ifdef FEAT_CONCEAL
440 int syntax_flags = 0;
441 int syntax_seqnr = 0;
442 int prev_syntax_id = 0;
443 int conceal_attr = HL_ATTR(HLF_CONCEAL);
444 int is_concealing = FALSE;
445 int boguscols = 0; // nonexistent columns added to force
446 // wrapping
447 int vcol_off = 0; // offset for concealed characters
448 int did_wcol = FALSE;
449 int old_boguscols = 0;
450# define VCOL_HLC (vcol - vcol_off)
451# define FIX_FOR_BOGUSCOLS \
452 { \
453 n_extra += vcol_off; \
454 vcol -= vcol_off; \
455 vcol_off = 0; \
456 col -= boguscols; \
457 old_boguscols = boguscols; \
458 boguscols = 0; \
459 }
460#else
461# define VCOL_HLC (vcol)
462#endif
463
464 if (startrow > endrow) // past the end already!
465 return startrow;
466
467 row = startrow;
468 screen_row = row + W_WINROW(wp);
469
470 if (!number_only)
471 {
472 // To speed up the loop below, set extra_check when there is linebreak,
473 // trailing white space and/or syntax processing to be done.
474#ifdef FEAT_LINEBREAK
475 extra_check = wp->w_p_lbr;
476#endif
477#ifdef FEAT_SYN_HL
478 if (syntax_present(wp) && !wp->w_s->b_syn_error
479# ifdef SYN_TIME_LIMIT
480 && !wp->w_s->b_syn_slow
481# endif
482 )
483 {
484 // Prepare for syntax highlighting in this line. When there is an
485 // error, stop syntax highlighting.
486 save_did_emsg = did_emsg;
487 did_emsg = FALSE;
488 syntax_start(wp, lnum);
489 if (did_emsg)
490 wp->w_s->b_syn_error = TRUE;
491 else
492 {
493 did_emsg = save_did_emsg;
494#ifdef SYN_TIME_LIMIT
495 if (!wp->w_s->b_syn_slow)
496#endif
497 {
498 has_syntax = TRUE;
499 extra_check = TRUE;
500 }
501 }
502 }
503
504 // Check for columns to display for 'colorcolumn'.
505 color_cols = wp->w_p_cc_cols;
506 if (color_cols != NULL)
507 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
508#endif
509
510#ifdef FEAT_TERMINAL
511 if (term_show_buffer(wp->w_buffer))
512 {
513 extra_check = TRUE;
514 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100515 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200516 }
517#endif
518
519#ifdef FEAT_SPELL
520 if (wp->w_p_spell
521 && *wp->w_s->b_p_spl != NUL
522 && wp->w_s->b_langp.ga_len > 0
523 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
524 {
525 // Prepare for spell checking.
526 has_spell = TRUE;
527 extra_check = TRUE;
528
529 // Get the start of the next line, so that words that wrap to the
530 // next line are found too: "et<line-break>al.".
531 // Trick: skip a few chars for C/shell/Vim comments
532 nextline[SPWORDLEN] = NUL;
533 if (lnum < wp->w_buffer->b_ml.ml_line_count)
534 {
535 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
536 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
537 }
538
539 // When a word wrapped from the previous line the start of the
540 // current line is valid.
541 if (lnum == checked_lnum)
542 cur_checked_col = checked_col;
543 checked_lnum = 0;
544
545 // When there was a sentence end in the previous line may require a
546 // word starting with capital in this line. In line 1 always check
547 // the first word.
548 if (lnum != capcol_lnum)
549 cap_col = -1;
550 if (lnum == 1)
551 cap_col = 0;
552 capcol_lnum = 0;
553 }
554#endif
555
556 // handle Visual active in this window
557 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
558 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100559 pos_T *top, *bot;
560
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200561 if (LTOREQ_POS(curwin->w_cursor, VIsual))
562 {
563 // Visual is after curwin->w_cursor
564 top = &curwin->w_cursor;
565 bot = &VIsual;
566 }
567 else
568 {
569 // Visual is before curwin->w_cursor
570 top = &VIsual;
571 bot = &curwin->w_cursor;
572 }
573 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
574 if (VIsual_mode == Ctrl_V)
575 {
576 // block mode
577 if (lnum_in_visual_area)
578 {
579 fromcol = wp->w_old_cursor_fcol;
580 tocol = wp->w_old_cursor_lcol;
581 }
582 }
583 else
584 {
585 // non-block mode
586 if (lnum > top->lnum && lnum <= bot->lnum)
587 fromcol = 0;
588 else if (lnum == top->lnum)
589 {
590 if (VIsual_mode == 'V') // linewise
591 fromcol = 0;
592 else
593 {
594 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
595 if (gchar_pos(top) == NUL)
596 tocol = fromcol + 1;
597 }
598 }
599 if (VIsual_mode != 'V' && lnum == bot->lnum)
600 {
601 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
602 {
603 fromcol = -10;
604 tocol = MAXCOL;
605 }
606 else if (bot->col == MAXCOL)
607 tocol = MAXCOL;
608 else
609 {
610 pos = *bot;
611 if (*p_sel == 'e')
612 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
613 else
614 {
615 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
616 ++tocol;
617 }
618 }
619 }
620 }
621
622 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200623 if (!highlight_match && lnum == curwin->w_cursor.lnum
624 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625#ifdef FEAT_GUI
626 && !gui.in_use
627#endif
628 )
629 noinvcur = TRUE;
630
631 // if inverting in this line set area_highlighting
632 if (fromcol >= 0)
633 {
634 area_highlighting = TRUE;
635 vi_attr = HL_ATTR(HLF_V);
636#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
637 if ((clip_star.available && !clip_star.owned
638 && clip_isautosel_star())
639 || (clip_plus.available && !clip_plus.owned
640 && clip_isautosel_plus()))
641 vi_attr = HL_ATTR(HLF_VNC);
642#endif
643 }
644 }
645
646 // handle 'incsearch' and ":s///c" highlighting
647 else if (highlight_match
648 && wp == curwin
649 && lnum >= curwin->w_cursor.lnum
650 && lnum <= curwin->w_cursor.lnum + search_match_lines)
651 {
652 if (lnum == curwin->w_cursor.lnum)
653 getvcol(curwin, &(curwin->w_cursor),
654 (colnr_T *)&fromcol, NULL, NULL);
655 else
656 fromcol = 0;
657 if (lnum == curwin->w_cursor.lnum + search_match_lines)
658 {
659 pos.lnum = lnum;
660 pos.col = search_match_endcol;
661 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
662 }
663 else
664 tocol = MAXCOL;
665 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100666 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200667 tocol = fromcol + 1;
668 area_highlighting = TRUE;
669 vi_attr = HL_ATTR(HLF_I);
670 }
671 }
672
673#ifdef FEAT_DIFF
674 filler_lines = diff_check(wp, lnum);
675 if (filler_lines < 0)
676 {
677 if (filler_lines == -1)
678 {
679 if (diff_find_change(wp, lnum, &change_start, &change_end))
680 diff_hlf = HLF_ADD; // added line
681 else if (change_start == 0)
682 diff_hlf = HLF_TXD; // changed text
683 else
684 diff_hlf = HLF_CHD; // changed line
685 }
686 else
687 diff_hlf = HLF_ADD; // added line
688 filler_lines = 0;
689 area_highlighting = TRUE;
690 }
691 if (lnum == wp->w_topline)
692 filler_lines = wp->w_topfill;
693 filler_todo = filler_lines;
694#endif
695
696#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100697 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200698#endif
699
700#ifdef LINE_ATTR
701# ifdef FEAT_SIGNS
702 // If this line has a sign with line highlighting set line_attr.
703 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200704 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705# endif
706# if defined(FEAT_QUICKFIX)
707 // Highlight the current line in the quickfix window.
708 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
709 line_attr = HL_ATTR(HLF_QFL);
710# endif
711 if (line_attr != 0)
712 area_highlighting = TRUE;
713#endif
714
715 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
716 ptr = line;
717
718#ifdef FEAT_SPELL
719 if (has_spell && !number_only)
720 {
721 // For checking first word with a capital skip white space.
722 if (cap_col == 0)
723 cap_col = getwhitecols(line);
724
725 // To be able to spell-check over line boundaries copy the end of the
726 // current line into nextline[]. Above the start of the next line was
727 // copied to nextline[SPWORDLEN].
728 if (nextline[SPWORDLEN] == NUL)
729 {
730 // No next line or it is empty.
731 nextlinecol = MAXCOL;
732 nextline_idx = 0;
733 }
734 else
735 {
736 v = (long)STRLEN(line);
737 if (v < SPWORDLEN)
738 {
739 // Short line, use it completely and append the start of the
740 // next line.
741 nextlinecol = 0;
742 mch_memmove(nextline, line, (size_t)v);
743 STRMOVE(nextline + v, nextline + SPWORDLEN);
744 nextline_idx = v + 1;
745 }
746 else
747 {
748 // Long line, use only the last SPWORDLEN bytes.
749 nextlinecol = v - SPWORDLEN;
750 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
751 nextline_idx = SPWORDLEN + 1;
752 }
753 }
754 }
755#endif
756
757 if (wp->w_p_list)
758 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100759 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200760 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100761 || wp->w_lcs_chars.trail
762 || wp->w_lcs_chars.lead
763 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200764 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100765
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200766 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100767 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768 {
769 trailcol = (colnr_T)STRLEN(ptr);
770 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
771 --trailcol;
772 trailcol += (colnr_T) (ptr - line);
773 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100774 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100775 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100776 {
777 leadcol = 0;
778 while (VIM_ISWHITE(ptr[leadcol]))
779 ++leadcol;
780 if (ptr[leadcol] == NUL)
781 // in a line full of spaces all of them are treated as trailing
782 leadcol = (colnr_T)0;
783 else
784 // keep track of the first column not filled with spaces
785 leadcol += (colnr_T) (ptr - line) + 1;
786 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200787 }
788
789 wcr_attr = get_wcr_attr(wp);
790 if (wcr_attr != 0)
791 {
792 win_attr = wcr_attr;
793 area_highlighting = TRUE;
794 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200795
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100796#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200797 if (WIN_IS_POPUP(wp))
798 screen_line_flags |= SLF_POPUP;
799#endif
800
801 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
802 // first character to be displayed.
803 if (wp->w_p_wrap)
804 v = wp->w_skipcol;
805 else
806 v = wp->w_leftcol;
807 if (v > 0 && !number_only)
808 {
809 char_u *prev_ptr = ptr;
810
811 while (vcol < v && *ptr != NUL)
812 {
813 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
814 vcol += c;
815 prev_ptr = ptr;
816 MB_PTR_ADV(ptr);
817 }
818
819 // When:
820 // - 'cuc' is set, or
821 // - 'colorcolumn' is set, or
822 // - 'virtualedit' is set, or
823 // - the visual mode is active,
824 // the end of the line may be before the start of the displayed part.
825 if (vcol < v && (
826#ifdef FEAT_SYN_HL
827 wp->w_p_cuc || draw_color_col ||
828#endif
829 virtual_active() ||
830 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
831 vcol = v;
832
833 // Handle a character that's not completely on the screen: Put ptr at
834 // that character but skip the first few screen characters.
835 if (vcol > v)
836 {
837 vcol -= c;
838 ptr = prev_ptr;
839 // If the character fits on the screen, don't need to skip it.
840 // Except for a TAB.
841 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
842 n_skip = v - vcol;
843 }
844
845 // Adjust for when the inverted text is before the screen,
846 // and when the start of the inverted text is before the screen.
847 if (tocol <= vcol)
848 fromcol = 0;
849 else if (fromcol >= 0 && fromcol < vcol)
850 fromcol = vcol;
851
852#ifdef FEAT_LINEBREAK
853 // When w_skipcol is non-zero, first line needs 'showbreak'
854 if (wp->w_p_wrap)
855 need_showbreak = TRUE;
856#endif
857#ifdef FEAT_SPELL
858 // When spell checking a word we need to figure out the start of the
859 // word and if it's badly spelled or not.
860 if (has_spell)
861 {
862 int len;
863 colnr_T linecol = (colnr_T)(ptr - line);
864 hlf_T spell_hlf = HLF_COUNT;
865
866 pos = wp->w_cursor;
867 wp->w_cursor.lnum = lnum;
868 wp->w_cursor.col = linecol;
869 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
870
871 // spell_move_to() may call ml_get() and make "line" invalid
872 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
873 ptr = line + linecol;
874
875 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
876 {
877 // no bad word found at line start, don't check until end of a
878 // word
879 spell_hlf = HLF_COUNT;
880 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
881 }
882 else
883 {
884 // bad word found, use attributes until end of word
885 word_end = wp->w_cursor.col + len + 1;
886
887 // Turn index into actual attributes.
888 if (spell_hlf != HLF_COUNT)
889 spell_attr = highlight_attr[spell_hlf];
890 }
891 wp->w_cursor = pos;
892
893# ifdef FEAT_SYN_HL
894 // Need to restart syntax highlighting for this line.
895 if (has_syntax)
896 syntax_start(wp, lnum);
897# endif
898 }
899#endif
900 }
901
902 // Correct highlighting for cursor that can't be disabled.
903 // Avoids having to check this for each character.
904 if (fromcol >= 0)
905 {
906 if (noinvcur)
907 {
908 if ((colnr_T)fromcol == wp->w_virtcol)
909 {
910 // highlighting starts at cursor, let it start just after the
911 // cursor
912 fromcol_prev = fromcol;
913 fromcol = -1;
914 }
915 else if ((colnr_T)fromcol < wp->w_virtcol)
916 // restart highlighting after the cursor
917 fromcol_prev = wp->w_virtcol;
918 }
919 if (fromcol >= tocol)
920 fromcol = -1;
921 }
922
923#ifdef FEAT_SEARCH_EXTRA
924 if (!number_only)
925 {
926 v = (long)(ptr - line);
927 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
928 &line, &screen_search_hl,
929 &search_attr);
930 ptr = line + v; // "line" may have been updated
931 }
932#endif
933
934#ifdef FEAT_SYN_HL
935 // Cursor line highlighting for 'cursorline' in the current window.
936 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
937 {
938 // Do not show the cursor line in the text when Visual mode is active,
939 // because it's not clear what is selected then. Do update
940 // w_last_cursorline.
941 if (!(wp == curwin && VIsual_active)
942 && wp->w_p_culopt_flags != CULOPT_NBR)
943 {
944 cul_screenline = (wp->w_p_wrap
945 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
946
947 // Only set line_attr here when "screenline" is not present in
948 // 'cursorlineopt'. Otherwise it's done later.
949 if (!cul_screenline)
950 {
951 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200952# ifdef FEAT_SIGNS
953 // Combine the 'cursorline' and sign highlighting, depending on
954 // the sign priority.
955 if (sign_present && sattr.sat_linehl > 0)
956 {
957 if (sattr.sat_priority >= 100)
958 line_attr = hl_combine_attr(cul_attr, line_attr);
959 else
960 line_attr = hl_combine_attr(line_attr, cul_attr);
961 }
962 else
963# endif
964 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965 wp->w_last_cursorline = wp->w_cursor.lnum;
966 }
967 else
968 {
969 line_attr_save = line_attr;
970 wp->w_last_cursorline = 0;
971 margin_columns_win(wp, &left_curline_col, &right_curline_col);
972 }
973 area_highlighting = TRUE;
974 }
975 else
976 wp->w_last_cursorline = wp->w_cursor.lnum;
977 }
978#endif
979
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100980#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200981 {
982 char_u *prop_start;
983
984 text_prop_count = get_text_props(wp->w_buffer, lnum,
985 &prop_start, FALSE);
986 if (text_prop_count > 0)
987 {
988 // Make a copy of the properties, so that they are properly
989 // aligned.
990 text_props = ALLOC_MULT(textprop_T, text_prop_count);
991 if (text_props != NULL)
992 mch_memmove(text_props, prop_start,
993 text_prop_count * sizeof(textprop_T));
994
995 // Allocate an array for the indexes.
996 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
997 area_highlighting = TRUE;
998 extra_check = TRUE;
999 }
1000 }
1001#endif
1002
1003 off = (unsigned)(current_ScreenLine - ScreenLines);
1004 col = 0;
1005
1006#ifdef FEAT_RIGHTLEFT
1007 if (wp->w_p_rl)
1008 {
1009 // Rightleft window: process the text in the normal direction, but put
1010 // it in current_ScreenLine[] from right to left. Start at the
1011 // rightmost column of the window.
1012 col = wp->w_width - 1;
1013 off += col;
1014 screen_line_flags |= SLF_RIGHTLEFT;
1015 }
1016#endif
1017
1018 // Repeat for the whole displayed line.
1019 for (;;)
1020 {
1021#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001022 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#endif
1024#ifdef FEAT_CONCEAL
1025 int did_decrement_ptr = FALSE;
1026#endif
1027 // Skip this quickly when working on the text.
1028 if (draw_state != WL_LINE)
1029 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001030#ifdef FEAT_SYN_HL
1031 if (cul_screenline)
1032 {
1033 cul_attr = 0;
1034 line_attr = line_attr_save;
1035 }
1036#endif
1037
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038#ifdef FEAT_CMDWIN
1039 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1040 {
1041 draw_state = WL_CMDLINE;
1042 if (cmdwin_type != 0 && wp == curwin)
1043 {
1044 // Draw the cmdline character.
1045 n_extra = 1;
1046 c_extra = cmdwin_type;
1047 c_final = NUL;
1048 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1049 }
1050 }
1051#endif
1052
1053#ifdef FEAT_FOLDING
1054 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1055 {
1056 int fdc = compute_foldcolumn(wp, 0);
1057
1058 draw_state = WL_FOLD;
1059 if (fdc > 0)
1060 {
1061 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1062 // already be in use.
1063 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001064 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 if (p_extra_free != NULL)
1066 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001067 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001068 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069 p_extra_free[n_extra] = NUL;
1070 p_extra = p_extra_free;
1071 c_extra = NUL;
1072 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001073 if (use_cursor_line_sign(wp, lnum))
1074 char_attr =
1075 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1076 else
1077 char_attr =
1078 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079 }
1080 }
1081 }
1082#endif
1083
1084#ifdef FEAT_SIGNS
1085 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1086 {
1087 draw_state = WL_SIGN;
1088 // Show the sign column when there are any signs in this
1089 // buffer or when using Netbeans.
1090 if (signcolumn_on(wp))
1091 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1092 row, startrow, filler_lines, filler_todo, &c_extra,
1093 &c_final, extra, &p_extra, &n_extra, &char_attr);
1094 }
1095#endif
1096
1097 if (draw_state == WL_NR - 1 && n_extra == 0)
1098 {
1099 draw_state = WL_NR;
1100 // Display the absolute or relative line number. After the
1101 // first fill with blanks when the 'n' flag isn't in 'cpo'
1102 if ((wp->w_p_nu || wp->w_p_rnu)
1103 && (row == startrow
1104#ifdef FEAT_DIFF
1105 + filler_lines
1106#endif
1107 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1108 {
1109#ifdef FEAT_SIGNS
1110 // If 'signcolumn' is set to 'number' and a sign is present
1111 // in 'lnum', then display the sign instead of the line
1112 // number.
1113 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1114 && sign_present)
1115 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1116 row, startrow, filler_lines, filler_todo,
1117 &c_extra, &c_final, extra, &p_extra, &n_extra,
1118 &char_attr);
1119 else
1120#endif
1121 {
1122 // Draw the line number (empty space after wrapping).
1123 if (row == startrow
1124#ifdef FEAT_DIFF
1125 + filler_lines
1126#endif
1127 )
1128 {
1129 long num;
1130 char *fmt = "%*ld ";
1131
1132 if (wp->w_p_nu && !wp->w_p_rnu)
1133 // 'number' + 'norelativenumber'
1134 num = (long)lnum;
1135 else
1136 {
1137 // 'relativenumber', don't use negative numbers
1138 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1139 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1140 {
1141 // 'number' + 'relativenumber'
1142 num = lnum;
1143 fmt = "%-*ld ";
1144 }
1145 }
1146
1147 sprintf((char *)extra, fmt,
1148 number_width(wp), num);
1149 if (wp->w_skipcol > 0)
1150 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1151 *p_extra = '-';
1152#ifdef FEAT_RIGHTLEFT
1153 if (wp->w_p_rl) // reverse line numbers
1154 {
1155 char_u *p1, *p2;
1156 int t;
1157
1158 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001159 p2 = skipwhite(extra);
1160 p2 = skiptowhite(p2) - 1;
1161 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 {
1163 t = *p1;
1164 *p1 = *p2;
1165 *p2 = t;
1166 }
1167 }
1168#endif
1169 p_extra = extra;
1170 c_extra = NUL;
1171 c_final = NUL;
1172 }
1173 else
1174 {
1175 c_extra = ' ';
1176 c_final = NUL;
1177 }
1178 n_extra = number_width(wp) + 1;
1179 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1180#ifdef FEAT_SYN_HL
1181 // When 'cursorline' is set highlight the line number of
1182 // the current line differently.
1183 // When 'cursorlineopt' has "screenline" only highlight
1184 // the line number itself.
1185 // TODO: Can we use CursorLine instead of CursorLineNr
1186 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001187 if (wp->w_p_cul
1188 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 && (wp->w_p_culopt_flags & CULOPT_NBR)
1190 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001191 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1193#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001194 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1195 && HL_ATTR(HLF_LNA) != 0)
1196 // Use LineNrAbove
1197 char_attr = hl_combine_attr(wcr_attr,
1198 HL_ATTR(HLF_LNA));
1199 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1200 && HL_ATTR(HLF_LNB) != 0)
1201 // Use LineNrBelow
1202 char_attr = hl_combine_attr(wcr_attr,
1203 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 }
1205 }
1206 }
1207
1208#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001209 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001210 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 // draw indent after showbreak value
1212 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001213 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214 // After the showbreak, draw the breakindent
1215 draw_state = WL_BRI - 1;
1216
1217 // draw 'breakindent': indent wrapped text accordingly
1218 if (draw_state == WL_BRI - 1 && n_extra == 0)
1219 {
1220 draw_state = WL_BRI;
1221 // if need_showbreak is set, breakindent also applies
1222 if (wp->w_p_bri && n_extra == 0
1223 && (row != startrow || need_showbreak)
1224# ifdef FEAT_DIFF
1225 && filler_lines == 0
1226# endif
1227 )
1228 {
1229 char_attr = 0;
1230# ifdef FEAT_DIFF
1231 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233# endif
1234 p_extra = NULL;
1235 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001236 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237 n_extra = get_breakindent_win(wp,
1238 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001239 if (row == startrow)
1240 {
1241 n_extra -= win_col_off2(wp);
1242 if (n_extra < 0)
1243 n_extra = 0;
1244 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001245 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001246 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 // Correct end of highlighted area for 'breakindent',
1248 // required when 'linebreak' is also set.
1249 if (tocol == vcol)
1250 tocol += n_extra;
1251 }
1252 }
1253#endif
1254
1255#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1256 if (draw_state == WL_SBR - 1 && n_extra == 0)
1257 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001258 char_u *sbr;
1259
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260 draw_state = WL_SBR;
1261# ifdef FEAT_DIFF
1262 if (filler_todo > 0)
1263 {
1264 // Draw "deleted" diff line(s).
1265 if (char2cells(fill_diff) > 1)
1266 {
1267 c_extra = '-';
1268 c_final = NUL;
1269 }
1270 else
1271 {
1272 c_extra = fill_diff;
1273 c_final = NUL;
1274 }
1275# ifdef FEAT_RIGHTLEFT
1276 if (wp->w_p_rl)
1277 n_extra = col + 1;
1278 else
1279# endif
1280 n_extra = wp->w_width - col;
1281 char_attr = HL_ATTR(HLF_DED);
1282 }
1283# endif
1284# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001285 sbr = get_showbreak_value(wp);
1286 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 {
1288 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001289 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 c_extra = NUL;
1291 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001292 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001293 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1294 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001295 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 // Correct end of highlighted area for 'showbreak',
1297 // required when 'linebreak' is also set.
1298 if (tocol == vcol)
1299 tocol += n_extra;
1300 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001301 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302# ifdef FEAT_SYN_HL
1303 // combine 'showbreak' with 'cursorline'
1304 if (cul_attr != 0)
1305 char_attr = hl_combine_attr(char_attr, cul_attr);
1306# endif
1307 }
1308# endif
1309 }
1310#endif
1311
1312 if (draw_state == WL_LINE - 1 && n_extra == 0)
1313 {
1314 draw_state = WL_LINE;
1315 if (saved_n_extra)
1316 {
1317 // Continue item from end of wrapped line.
1318 n_extra = saved_n_extra;
1319 c_extra = saved_c_extra;
1320 c_final = saved_c_final;
1321 p_extra = saved_p_extra;
1322 char_attr = saved_char_attr;
1323 }
1324 else
1325 char_attr = win_attr;
1326 }
1327 }
1328#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001329 if (cul_screenline && draw_state == WL_LINE
1330 && vcol >= left_curline_col
1331 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001333 cul_attr = HL_ATTR(HLF_CUL);
1334 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 }
1336#endif
1337
1338 // When still displaying '$' of change command, stop at cursor.
1339 // When only displaying the (relative) line number and that's done,
1340 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001341 if (((dollar_vcol >= 0 && wp == curwin
1342 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1343 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344#ifdef FEAT_DIFF
1345 && filler_todo <= 0
1346#endif
1347 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 {
1349 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1350 screen_line_flags);
1351 // Pretend we have finished updating the window. Except when
1352 // 'cursorcolumn' is set.
1353#ifdef FEAT_SYN_HL
1354 if (wp->w_p_cuc)
1355 row = wp->w_cline_row + wp->w_cline_height;
1356 else
1357#endif
1358 row = wp->w_height;
1359 break;
1360 }
1361
Bram Moolenaar34390282019-10-16 14:38:26 +02001362 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 {
1364 // handle Visual or match highlighting in this line
1365 if (vcol == fromcol
1366 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1367 && (*mb_ptr2cells)(ptr) > 1)
1368 || ((int)vcol_prev == fromcol_prev
1369 && vcol_prev < vcol // not at margin
1370 && vcol < tocol))
1371 area_attr = vi_attr; // start highlighting
1372 else if (area_attr != 0
1373 && (vcol == tocol
1374 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1375 area_attr = 0; // stop highlighting
1376
1377#ifdef FEAT_SEARCH_EXTRA
1378 if (!n_extra)
1379 {
1380 // Check for start/end of 'hlsearch' and other matches.
1381 // After end, check for start/end of next match.
1382 // When another match, have to check for start again.
1383 v = (long)(ptr - line);
1384 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1385 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001386 &match_conc, did_line_attr, lcs_eol_one,
1387 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001389
1390 // Do not allow a conceal over EOL otherwise EOL will be missed
1391 // and bad things happen.
1392 if (*ptr == NUL)
1393 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 }
1395#endif
1396
1397#ifdef FEAT_DIFF
1398 if (diff_hlf != (hlf_T)0)
1399 {
1400 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1401 && n_extra == 0)
1402 diff_hlf = HLF_TXD; // changed text
1403 if (diff_hlf == HLF_TXD && ptr - line > change_end
1404 && n_extra == 0)
1405 diff_hlf = HLF_CHD; // changed line
1406 line_attr = HL_ATTR(diff_hlf);
1407 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1408 && wp->w_p_culopt_flags != CULOPT_NBR
1409 && (!cul_screenline || (vcol >= left_curline_col
1410 && vcol <= right_curline_col)))
1411 line_attr = hl_combine_attr(
1412 line_attr, HL_ATTR(HLF_CUL));
1413 }
1414#endif
1415
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001416#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 if (text_props != NULL)
1418 {
1419 int pi;
1420 int bcol = (int)(ptr - line);
1421
1422 if (n_extra > 0)
1423 --bcol; // still working on the previous char, e.g. Tab
1424
1425 // Check if any active property ends.
1426 for (pi = 0; pi < text_props_active; ++pi)
1427 {
1428 int tpi = text_prop_idxs[pi];
1429
1430 if (bcol >= text_props[tpi].tp_col - 1
1431 + text_props[tpi].tp_len)
1432 {
1433 if (pi + 1 < text_props_active)
1434 mch_memmove(text_prop_idxs + pi,
1435 text_prop_idxs + pi + 1,
1436 sizeof(int)
1437 * (text_props_active - (pi + 1)));
1438 --text_props_active;
1439 --pi;
1440 }
1441 }
1442
1443 // Add any text property that starts in this column.
1444 while (text_prop_next < text_prop_count
1445 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001446 {
1447 if (bcol <= text_props[text_prop_next].tp_col - 1
1448 + text_props[text_prop_next].tp_len)
1449 text_prop_idxs[text_props_active++] = text_prop_next;
1450 ++text_prop_next;
1451 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452
1453 text_prop_attr = 0;
1454 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001455 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 if (text_props_active > 0)
1457 {
1458 // Sort the properties on priority and/or starting last.
1459 // Then combine the attributes, highest priority last.
1460 current_text_props = text_props;
1461 current_buf = wp->w_buffer;
1462 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1463 sizeof(int), text_prop_compare);
1464
1465 for (pi = 0; pi < text_props_active; ++pi)
1466 {
1467 int tpi = text_prop_idxs[pi];
1468 proptype_T *pt = text_prop_type_by_id(
1469 wp->w_buffer, text_props[tpi].tp_type);
1470
1471 if (pt != NULL && pt->pt_hl_id > 0)
1472 {
1473 int pt_attr = syn_id2attr(pt->pt_hl_id);
1474
1475 text_prop_type = pt;
1476 text_prop_attr =
1477 hl_combine_attr(text_prop_attr, pt_attr);
1478 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1479 }
1480 }
1481 }
1482 }
1483#endif
1484
Bram Moolenaara74fda62019-10-19 17:38:03 +02001485#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001486 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001487 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001488 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001489# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001490 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001491 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001492# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001493 // Get syntax attribute.
1494 if (has_syntax)
1495 {
1496 // Get the syntax attribute for the character. If there
1497 // is an error, disable syntax highlighting.
1498 save_did_emsg = did_emsg;
1499 did_emsg = FALSE;
1500
1501 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001502 if (v == prev_syntax_col)
1503 // at same column again
1504 syntax_attr = prev_syntax_attr;
1505 else
1506 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001507# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001508 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001509# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001510 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001511# ifdef FEAT_SPELL
1512 has_spell ? &can_spell :
1513# endif
1514 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001515 prev_syntax_col = v;
1516 prev_syntax_attr = syntax_attr;
1517 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001518
Bram Moolenaar34390282019-10-16 14:38:26 +02001519 if (did_emsg)
1520 {
1521 wp->w_s->b_syn_error = TRUE;
1522 has_syntax = FALSE;
1523 syntax_attr = 0;
1524 }
1525 else
1526 did_emsg = save_did_emsg;
1527# ifdef SYN_TIME_LIMIT
1528 if (wp->w_s->b_syn_slow)
1529 has_syntax = FALSE;
1530# endif
1531
1532 // Need to get the line again, a multi-line regexp may
1533 // have made it invalid.
1534 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1535 ptr = line + v;
1536# ifdef FEAT_CONCEAL
1537 // no concealing past the end of the line, it interferes
1538 // with line highlighting
1539 if (*ptr == NUL)
1540 syntax_flags = 0;
1541 else
1542 syntax_flags = get_syntax_info(&syntax_seqnr);
1543# endif
1544 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001545 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001546# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001547 // Combine text property highlight into syntax highlight.
1548 if (text_prop_type != NULL)
1549 {
1550 if (text_prop_combine)
1551 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1552 else
1553 syntax_attr = text_prop_attr;
1554 }
1555# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001556#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001557
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 // Decide which of the highlight attributes to use.
1559 attr_pri = TRUE;
1560#ifdef LINE_ATTR
1561 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001562 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001564 if (!highlight_match)
1565 // let search highlight show in Visual area if possible
1566 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001567# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001568 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001569# endif
1570 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001572 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001574# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001575 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001576# endif
1577 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1579 || vcol < fromcol || vcol_prev < fromcol_prev
1580 || vcol >= tocol))
1581 {
1582 // Use line_attr when not in the Visual or 'incsearch' area
1583 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001584# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001585 char_attr = hl_combine_attr(syntax_attr, line_attr);
1586# else
1587 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001588# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 attr_pri = FALSE;
1590 }
1591#else
1592 if (area_attr != 0)
1593 char_attr = area_attr;
1594 else if (search_attr != 0)
1595 char_attr = search_attr;
1596#endif
1597 else
1598 {
1599 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001601 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001602#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001603 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001604#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 }
1606 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001607
1608 // combine attribute with 'wincolor'
1609 if (win_attr != 0)
1610 {
1611 if (char_attr == 0)
1612 char_attr = win_attr;
1613 else
1614 char_attr = hl_combine_attr(win_attr, char_attr);
1615 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616
1617 // Get the next character to put on the screen.
1618
1619 // The "p_extra" points to the extra stuff that is inserted to
1620 // represent special characters (non-printable stuff) and other
1621 // things. When all characters are the same, c_extra is used.
1622 // If c_final is set, it will compulsorily be used at the end.
1623 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1624 // "p_extra[n_extra]".
1625 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1626 if (n_extra > 0)
1627 {
1628 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1629 {
1630 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1631 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1632 if (enc_utf8 && utf_char2len(c) > 1)
1633 {
1634 mb_utf8 = TRUE;
1635 u8cc[0] = 0;
1636 c = 0xc0;
1637 }
1638 else
1639 mb_utf8 = FALSE;
1640 }
1641 else
1642 {
1643 c = *p_extra;
1644 if (has_mbyte)
1645 {
1646 mb_c = c;
1647 if (enc_utf8)
1648 {
1649 // If the UTF-8 character is more than one byte:
1650 // Decode it into "mb_c".
1651 mb_l = utfc_ptr2len(p_extra);
1652 mb_utf8 = FALSE;
1653 if (mb_l > n_extra)
1654 mb_l = 1;
1655 else if (mb_l > 1)
1656 {
1657 mb_c = utfc_ptr2char(p_extra, u8cc);
1658 mb_utf8 = TRUE;
1659 c = 0xc0;
1660 }
1661 }
1662 else
1663 {
1664 // if this is a DBCS character, put it in "mb_c"
1665 mb_l = MB_BYTE2LEN(c);
1666 if (mb_l >= n_extra)
1667 mb_l = 1;
1668 else if (mb_l > 1)
1669 mb_c = (c << 8) + p_extra[1];
1670 }
1671 if (mb_l == 0) // at the NUL at end-of-line
1672 mb_l = 1;
1673
1674 // If a double-width char doesn't fit display a '>' in the
1675 // last column.
1676 if ((
1677# ifdef FEAT_RIGHTLEFT
1678 wp->w_p_rl ? (col <= 0) :
1679# endif
1680 (col >= wp->w_width - 1))
1681 && (*mb_char2cells)(mb_c) == 2)
1682 {
1683 c = '>';
1684 mb_c = c;
1685 mb_l = 1;
1686 mb_utf8 = FALSE;
1687 multi_attr = HL_ATTR(HLF_AT);
1688#ifdef FEAT_SYN_HL
1689 if (cul_attr)
1690 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1691#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001692 multi_attr = hl_combine_attr(win_attr, multi_attr);
1693
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 // put the pointer back to output the double-width
1695 // character at the start of the next line.
1696 ++n_extra;
1697 --p_extra;
1698 }
1699 else
1700 {
1701 n_extra -= mb_l - 1;
1702 p_extra += mb_l - 1;
1703 }
1704 }
1705 ++p_extra;
1706 }
1707 --n_extra;
1708 }
1709 else
1710 {
1711#ifdef FEAT_LINEBREAK
1712 int c0;
1713#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001714 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716 // Get a character from the line itself.
1717 c = *ptr;
1718#ifdef FEAT_LINEBREAK
1719 c0 = *ptr;
1720#endif
1721 if (has_mbyte)
1722 {
1723 mb_c = c;
1724 if (enc_utf8)
1725 {
1726 // If the UTF-8 character is more than one byte: Decode it
1727 // into "mb_c".
1728 mb_l = utfc_ptr2len(ptr);
1729 mb_utf8 = FALSE;
1730 if (mb_l > 1)
1731 {
1732 mb_c = utfc_ptr2char(ptr, u8cc);
1733 // Overlong encoded ASCII or ASCII with composing char
1734 // is displayed normally, except a NUL.
1735 if (mb_c < 0x80)
1736 {
1737 c = mb_c;
1738#ifdef FEAT_LINEBREAK
1739 c0 = mb_c;
1740#endif
1741 }
1742 mb_utf8 = TRUE;
1743
1744 // At start of the line we can have a composing char.
1745 // Draw it as a space with a composing char.
1746 if (utf_iscomposing(mb_c))
1747 {
1748 int i;
1749
1750 for (i = Screen_mco - 1; i > 0; --i)
1751 u8cc[i] = u8cc[i - 1];
1752 u8cc[0] = mb_c;
1753 mb_c = ' ';
1754 }
1755 }
1756
1757 if ((mb_l == 1 && c >= 0x80)
1758 || (mb_l >= 1 && mb_c == 0)
1759 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1760 {
1761 // Illegal UTF-8 byte: display as <xx>.
1762 // Non-BMP character : display as ? or fullwidth ?.
1763 transchar_hex(extra, mb_c);
1764# ifdef FEAT_RIGHTLEFT
1765 if (wp->w_p_rl) // reverse
1766 rl_mirror(extra);
1767# endif
1768 p_extra = extra;
1769 c = *p_extra;
1770 mb_c = mb_ptr2char_adv(&p_extra);
1771 mb_utf8 = (c >= 0x80);
1772 n_extra = (int)STRLEN(p_extra);
1773 c_extra = NUL;
1774 c_final = NUL;
1775 if (area_attr == 0 && search_attr == 0)
1776 {
1777 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001778 extra_attr = hl_combine_attr(
1779 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 saved_attr2 = char_attr; // save current attr
1781 }
1782 }
1783 else if (mb_l == 0) // at the NUL at end-of-line
1784 mb_l = 1;
1785#ifdef FEAT_ARABIC
1786 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1787 {
1788 // Do Arabic shaping.
1789 int pc, pc1, nc;
1790 int pcc[MAX_MCO];
1791
1792 // The idea of what is the previous and next
1793 // character depends on 'rightleft'.
1794 if (wp->w_p_rl)
1795 {
1796 pc = prev_c;
1797 pc1 = prev_c1;
1798 nc = utf_ptr2char(ptr + mb_l);
1799 prev_c1 = u8cc[0];
1800 }
1801 else
1802 {
1803 pc = utfc_ptr2char(ptr + mb_l, pcc);
1804 nc = prev_c;
1805 pc1 = pcc[0];
1806 }
1807 prev_c = mb_c;
1808
1809 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1810 }
1811 else
1812 prev_c = mb_c;
1813#endif
1814 }
1815 else // enc_dbcs
1816 {
1817 mb_l = MB_BYTE2LEN(c);
1818 if (mb_l == 0) // at the NUL at end-of-line
1819 mb_l = 1;
1820 else if (mb_l > 1)
1821 {
1822 // We assume a second byte below 32 is illegal.
1823 // Hopefully this is OK for all double-byte encodings!
1824 if (ptr[1] >= 32)
1825 mb_c = (c << 8) + ptr[1];
1826 else
1827 {
1828 if (ptr[1] == NUL)
1829 {
1830 // head byte at end of line
1831 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001832 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 }
1834 else
1835 {
1836 // illegal tail byte
1837 mb_l = 2;
1838 STRCPY(extra, "XX");
1839 }
1840 p_extra = extra;
1841 n_extra = (int)STRLEN(extra) - 1;
1842 c_extra = NUL;
1843 c_final = NUL;
1844 c = *p_extra++;
1845 if (area_attr == 0 && search_attr == 0)
1846 {
1847 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001848 extra_attr = hl_combine_attr(
1849 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 saved_attr2 = char_attr; // save current attr
1851 }
1852 mb_c = c;
1853 }
1854 }
1855 }
1856 // If a double-width char doesn't fit display a '>' in the
1857 // last column; the character is displayed at the start of the
1858 // next line.
1859 if ((
1860# ifdef FEAT_RIGHTLEFT
1861 wp->w_p_rl ? (col <= 0) :
1862# endif
1863 (col >= wp->w_width - 1))
1864 && (*mb_char2cells)(mb_c) == 2)
1865 {
1866 c = '>';
1867 mb_c = c;
1868 mb_utf8 = FALSE;
1869 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001870 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 // Put pointer back so that the character will be
1872 // displayed at the start of the next line.
1873 --ptr;
1874#ifdef FEAT_CONCEAL
1875 did_decrement_ptr = TRUE;
1876#endif
1877 }
1878 else if (*ptr != NUL)
1879 ptr += mb_l - 1;
1880
1881 // If a double-width char doesn't fit at the left side display
1882 // a '<' in the first column. Don't do this for unprintable
1883 // characters.
1884 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1885 {
1886 n_extra = 1;
1887 c_extra = MB_FILLER_CHAR;
1888 c_final = NUL;
1889 c = ' ';
1890 if (area_attr == 0 && search_attr == 0)
1891 {
1892 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001893 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 saved_attr2 = char_attr; // save current attr
1895 }
1896 mb_c = c;
1897 mb_utf8 = FALSE;
1898 mb_l = 1;
1899 }
1900
1901 }
1902 ++ptr;
1903
1904 if (extra_check)
1905 {
1906#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 // Check spelling (unless at the end of the line).
1908 // Only do this when there is no syntax highlighting, the
1909 // @Spell cluster is not used or the current syntax item
1910 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001911 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 if (has_spell && v >= word_end && v > cur_checked_col)
1913 {
1914 spell_attr = 0;
1915 if (c != 0 && (
1916# ifdef FEAT_SYN_HL
1917 !has_syntax ||
1918# endif
1919 can_spell))
1920 {
1921 char_u *prev_ptr, *p;
1922 int len;
1923 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001924
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 if (has_mbyte)
1926 {
1927 prev_ptr = ptr - mb_l;
1928 v -= mb_l - 1;
1929 }
1930 else
1931 prev_ptr = ptr - 1;
1932
1933 // Use nextline[] if possible, it has the start of the
1934 // next line concatenated.
1935 if ((prev_ptr - line) - nextlinecol >= 0)
1936 p = nextline + (prev_ptr - line) - nextlinecol;
1937 else
1938 p = prev_ptr;
1939 cap_col -= (int)(prev_ptr - line);
1940 len = spell_check(wp, p, &spell_hlf, &cap_col,
1941 nochange);
1942 word_end = v + len;
1943
1944 // In Insert mode only highlight a word that
1945 // doesn't touch the cursor.
1946 if (spell_hlf != HLF_COUNT
1947 && (State & INSERT) != 0
1948 && wp->w_cursor.lnum == lnum
1949 && wp->w_cursor.col >=
1950 (colnr_T)(prev_ptr - line)
1951 && wp->w_cursor.col < (colnr_T)word_end)
1952 {
1953 spell_hlf = HLF_COUNT;
1954 spell_redraw_lnum = lnum;
1955 }
1956
1957 if (spell_hlf == HLF_COUNT && p != prev_ptr
1958 && (p - nextline) + len > nextline_idx)
1959 {
1960 // Remember that the good word continues at the
1961 // start of the next line.
1962 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001963 checked_col = (int)((p - nextline)
1964 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 }
1966
1967 // Turn index into actual attributes.
1968 if (spell_hlf != HLF_COUNT)
1969 spell_attr = highlight_attr[spell_hlf];
1970
1971 if (cap_col > 0)
1972 {
1973 if (p != prev_ptr
1974 && (p - nextline) + cap_col >= nextline_idx)
1975 {
1976 // Remember that the word in the next line
1977 // must start with a capital.
1978 capcol_lnum = lnum + 1;
1979 cap_col = (int)((p - nextline) + cap_col
1980 - nextline_idx);
1981 }
1982 else
1983 // Compute the actual column.
1984 cap_col += (int)(prev_ptr - line);
1985 }
1986 }
1987 }
1988 if (spell_attr != 0)
1989 {
1990 if (!attr_pri)
1991 char_attr = hl_combine_attr(char_attr, spell_attr);
1992 else
1993 char_attr = hl_combine_attr(spell_attr, char_attr);
1994 }
1995#endif
1996#ifdef FEAT_LINEBREAK
1997 // Found last space before word: check for line break.
1998 if (wp->w_p_lbr && c0 == c
1999 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2000 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002001 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2002 : 0;
2003 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004
2005 // TODO: is passing p for start of the line OK?
2006 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2007 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002008
2009 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002010 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002011 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002012 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002013 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002014 if (n_extra < 0)
2015 n_extra = 0;
2016 }
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002017 if (on_last_col)
2018 // Do not continue search/match highlighting over the
2019 // line break.
2020 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002021
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 if (c == TAB && n_extra + col > wp->w_width)
2023# ifdef FEAT_VARTABS
2024 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2025 wp->w_buffer->b_p_vts_array) - 1;
2026# else
2027 n_extra = (int)wp->w_buffer->b_p_ts
2028 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2029# endif
2030
2031 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2032 c_final = NUL;
2033 if (VIM_ISWHITE(c))
2034 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002035# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002036 if (c == TAB)
2037 // See "Tab alignment" below.
2038 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002039# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002040 if (!wp->w_p_list)
2041 c = ' ';
2042 }
2043 }
2044#endif
2045
zeertzjqf14b8ba2021-09-10 16:58:30 +02002046 in_multispace = c == ' '
2047 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2048 if (!in_multispace)
2049 multispace_pos = 0;
2050
Bram Moolenaareed9d462021-02-15 20:38:25 +01002051 // 'list': Change char 160 to 'nbsp' and space to 'space'
2052 // setting in 'listchars'. But not when the character is
2053 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 if (wp->w_p_list
2055 && ((((c == 160 && mb_l == 1)
2056 || (mb_utf8
2057 && ((mb_c == 160 && mb_l == 2)
2058 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002059 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 || (c == ' '
2061 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002062 && (wp->w_lcs_chars.space
2063 || (in_multispace
2064 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002065 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 && ptr - line <= trailcol)))
2067 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002068 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2069 {
2070 c = wp->w_lcs_chars.multispace[multispace_pos++];
2071 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2072 multispace_pos = 0;
2073 }
2074 else
2075 c = (c == ' ') ? wp->w_lcs_chars.space
2076 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077 if (area_attr == 0 && search_attr == 0)
2078 {
2079 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002080 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 saved_attr2 = char_attr; // save current attr
2082 }
2083 mb_c = c;
2084 if (enc_utf8 && utf_char2len(c) > 1)
2085 {
2086 mb_utf8 = TRUE;
2087 u8cc[0] = 0;
2088 c = 0xc0;
2089 }
2090 else
2091 mb_utf8 = FALSE;
2092 }
2093
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002094 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2095 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002097 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2098 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 if (!attr_pri)
2100 {
2101 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002102 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103 saved_attr2 = char_attr; // save current attr
2104 }
2105 mb_c = c;
2106 if (enc_utf8 && utf_char2len(c) > 1)
2107 {
2108 mb_utf8 = TRUE;
2109 u8cc[0] = 0;
2110 c = 0xc0;
2111 }
2112 else
2113 mb_utf8 = FALSE;
2114 }
2115 }
2116
2117 // Handling of non-printable characters.
2118 if (!vim_isprintc(c))
2119 {
2120 // when getting a character from the file, we may have to
2121 // turn it into something else on the way to putting it
2122 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002123 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002124 {
2125 int tab_len = 0;
2126 long vcol_adjusted = vcol; // removed showbreak length
2127#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002128 char_u *sbr = get_showbreak_value(wp);
2129
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 // only adjust the tab_len, when at the first column
2131 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002132 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2133 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134#endif
2135 // tab amount depends on current column
2136#ifdef FEAT_VARTABS
2137 tab_len = tabstop_padding(vcol_adjusted,
2138 wp->w_buffer->b_p_ts,
2139 wp->w_buffer->b_p_vts_array) - 1;
2140#else
2141 tab_len = (int)wp->w_buffer->b_p_ts
2142 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2143#endif
2144
2145#ifdef FEAT_LINEBREAK
2146 if (!wp->w_p_lbr || !wp->w_p_list)
2147#endif
2148 // tab amount depends on current column
2149 n_extra = tab_len;
2150#ifdef FEAT_LINEBREAK
2151 else
2152 {
2153 char_u *p;
2154 int len;
2155 int i;
2156 int saved_nextra = n_extra;
2157
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002158# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 if (vcol_off > 0)
2160 // there are characters to conceal
2161 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002162
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002164 if (wp->w_p_list && wp->w_lcs_chars.tab1
2165 && old_boguscols > 0
2166 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002168# endif
2169 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002171 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002172 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002173 if (wp->w_lcs_chars.tab3)
2174 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175 if (n_extra > 0)
2176 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002177 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002179 if (p == NULL)
2180 n_extra = 0;
2181 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002183 vim_memset(p, ' ', len);
2184 p[len] = NUL;
2185 vim_free(p_extra_free);
2186 p_extra_free = p;
2187 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002189 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002191 if (*p == NUL)
2192 {
2193 tab_len = i;
2194 break;
2195 }
2196
2197 // if tab3 is given, use it for the last char
2198 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2199 lcs = wp->w_lcs_chars.tab3;
2200 p += mb_char2bytes(lcs, p);
2201 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002203 }
2204 p_extra = p_extra_free;
2205# ifdef FEAT_CONCEAL
2206 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2207 // macro below, so need to adjust for that here
2208 if (vcol_off > 0)
2209 n_extra -= vcol_off;
2210# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 }
2213#endif
2214#ifdef FEAT_CONCEAL
2215 {
2216 int vc_saved = vcol_off;
2217
2218 // Tab alignment should be identical regardless of
2219 // 'conceallevel' value. So tab compensates of all
2220 // previous concealed characters, and thus resets
2221 // vcol_off and boguscols accumulated so far in the
2222 // line. Note that the tab can be longer than
2223 // 'tabstop' when there are concealed characters.
2224 FIX_FOR_BOGUSCOLS;
2225
2226 // Make sure, the highlighting for the tab char will be
2227 // correctly set further below (effectively reverts the
2228 // FIX_FOR_BOGSUCOLS macro
2229 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002230 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002231 tab_len += vc_saved;
2232 }
2233#endif
2234 mb_utf8 = FALSE; // don't draw as UTF-8
2235 if (wp->w_p_list)
2236 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002237 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2238 ? wp->w_lcs_chars.tab3
2239 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240#ifdef FEAT_LINEBREAK
2241 if (wp->w_p_lbr)
2242 c_extra = NUL; // using p_extra from above
2243 else
2244#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002245 c_extra = wp->w_lcs_chars.tab2;
2246 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002248 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 saved_attr2 = char_attr; // save current attr
2250 mb_c = c;
2251 if (enc_utf8 && utf_char2len(c) > 1)
2252 {
2253 mb_utf8 = TRUE;
2254 u8cc[0] = 0;
2255 c = 0xc0;
2256 }
2257 }
2258 else
2259 {
2260 c_final = NUL;
2261 c_extra = ' ';
2262 c = ' ';
2263 }
2264 }
2265 else if (c == NUL
2266 && (wp->w_p_list
2267 || ((fromcol >= 0 || fromcol_prev >= 0)
2268 && tocol > vcol
2269 && VIsual_mode != Ctrl_V
2270 && (
2271# ifdef FEAT_RIGHTLEFT
2272 wp->w_p_rl ? (col >= 0) :
2273# endif
2274 (col < wp->w_width))
2275 && !(noinvcur
2276 && lnum == wp->w_cursor.lnum
2277 && (colnr_T)vcol == wp->w_virtcol)))
2278 && lcs_eol_one > 0)
2279 {
2280 // Display a '$' after the line or highlight an extra
2281 // character if the line break is included.
2282#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2283 // For a diff line the highlighting continues after the
2284 // "$".
2285 if (
2286# ifdef FEAT_DIFF
2287 diff_hlf == (hlf_T)0
2288# ifdef LINE_ATTR
2289 &&
2290# endif
2291# endif
2292# ifdef LINE_ATTR
2293 line_attr == 0
2294# endif
2295 )
2296#endif
2297 {
2298 // In virtualedit, visual selections may extend
2299 // beyond end of line.
2300 if (area_highlighting && virtual_active()
2301 && tocol != MAXCOL && vcol < tocol)
2302 n_extra = 0;
2303 else
2304 {
2305 p_extra = at_end_str;
2306 n_extra = 1;
2307 c_extra = NUL;
2308 c_final = NUL;
2309 }
2310 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002311 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2312 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002313 else
2314 c = ' ';
2315 lcs_eol_one = -1;
2316 --ptr; // put it back at the NUL
2317 if (!attr_pri)
2318 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002319 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 n_attr = 1;
2321 }
2322 mb_c = c;
2323 if (enc_utf8 && utf_char2len(c) > 1)
2324 {
2325 mb_utf8 = TRUE;
2326 u8cc[0] = 0;
2327 c = 0xc0;
2328 }
2329 else
2330 mb_utf8 = FALSE; // don't draw as UTF-8
2331 }
2332 else if (c != NUL)
2333 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002334 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 if (n_extra == 0)
2336 n_extra = byte2cells(c) - 1;
2337#ifdef FEAT_RIGHTLEFT
2338 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2339 rl_mirror(p_extra); // reverse "<12>"
2340#endif
2341 c_extra = NUL;
2342 c_final = NUL;
2343#ifdef FEAT_LINEBREAK
2344 if (wp->w_p_lbr)
2345 {
2346 char_u *p;
2347
2348 c = *p_extra;
2349 p = alloc(n_extra + 1);
2350 vim_memset(p, ' ', n_extra);
2351 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2352 p[n_extra] = NUL;
2353 vim_free(p_extra_free);
2354 p_extra_free = p_extra = p;
2355 }
2356 else
2357#endif
2358 {
2359 n_extra = byte2cells(c) - 1;
2360 c = *p_extra++;
2361 }
2362 if (!attr_pri)
2363 {
2364 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002365 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002366 saved_attr2 = char_attr; // save current attr
2367 }
2368 mb_utf8 = FALSE; // don't draw as UTF-8
2369 }
2370 else if (VIsual_active
2371 && (VIsual_mode == Ctrl_V
2372 || VIsual_mode == 'v')
2373 && virtual_active()
2374 && tocol != MAXCOL
2375 && vcol < tocol
2376 && (
2377#ifdef FEAT_RIGHTLEFT
2378 wp->w_p_rl ? (col >= 0) :
2379#endif
2380 (col < wp->w_width)))
2381 {
2382 c = ' ';
2383 --ptr; // put it back at the NUL
2384 }
2385#if defined(LINE_ATTR)
2386 else if ((
2387# ifdef FEAT_DIFF
2388 diff_hlf != (hlf_T)0 ||
2389# endif
2390# ifdef FEAT_TERMINAL
2391 win_attr != 0 ||
2392# endif
2393 line_attr != 0
2394 ) && (
2395# ifdef FEAT_RIGHTLEFT
2396 wp->w_p_rl ? (col >= 0) :
2397# endif
2398 (col
2399# ifdef FEAT_CONCEAL
2400 - boguscols
2401# endif
2402 < wp->w_width)))
2403 {
2404 // Highlight until the right side of the window
2405 c = ' ';
2406 --ptr; // put it back at the NUL
2407
2408 // Remember we do the char for line highlighting.
2409 ++did_line_attr;
2410
2411 // don't do search HL for the rest of the line
2412 if (line_attr != 0 && char_attr == search_attr
2413 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002414 || (wp->w_p_list &&
2415 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 char_attr = line_attr;
2417# ifdef FEAT_DIFF
2418 if (diff_hlf == HLF_TXD)
2419 {
2420 diff_hlf = HLF_CHD;
2421 if (vi_attr == 0 || char_attr != vi_attr)
2422 {
2423 char_attr = HL_ATTR(diff_hlf);
2424 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2425 && wp->w_p_culopt_flags != CULOPT_NBR
2426 && (!cul_screenline
2427 || (vcol >= left_curline_col
2428 && vcol <= right_curline_col)))
2429 char_attr = hl_combine_attr(
2430 char_attr, HL_ATTR(HLF_CUL));
2431 }
2432 }
2433# endif
2434# ifdef FEAT_TERMINAL
2435 if (win_attr != 0)
2436 {
2437 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002438 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2439 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440 {
2441 if (!cul_screenline || (vcol >= left_curline_col
2442 && vcol <= right_curline_col))
2443 char_attr = hl_combine_attr(
2444 char_attr, HL_ATTR(HLF_CUL));
2445 }
2446 else if (line_attr)
2447 char_attr = hl_combine_attr(char_attr, line_attr);
2448 }
2449# endif
2450 }
2451#endif
2452 }
2453
2454#ifdef FEAT_CONCEAL
2455 if ( wp->w_p_cole > 0
2456 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2457 conceal_cursor_line(wp))
2458 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2459 && !(lnum_in_visual_area
2460 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2461 {
2462 char_attr = conceal_attr;
2463 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002464 && (syn_get_sub_char() != NUL
2465 || (has_match_conc && match_conc)
2466 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 && wp->w_p_cole != 3)
2468 {
2469 // First time at this concealed item: display one
2470 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002471 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 c = match_conc;
2473 else if (syn_get_sub_char() != NUL)
2474 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002475 else if (wp->w_lcs_chars.conceal != NUL)
2476 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 else
2478 c = ' ';
2479
2480 prev_syntax_id = syntax_seqnr;
2481
2482 if (n_extra > 0)
2483 vcol_off += n_extra;
2484 vcol += n_extra;
2485 if (wp->w_p_wrap && n_extra > 0)
2486 {
2487# ifdef FEAT_RIGHTLEFT
2488 if (wp->w_p_rl)
2489 {
2490 col -= n_extra;
2491 boguscols -= n_extra;
2492 }
2493 else
2494# endif
2495 {
2496 boguscols += n_extra;
2497 col += n_extra;
2498 }
2499 }
2500 n_extra = 0;
2501 n_attr = 0;
2502 }
2503 else if (n_skip == 0)
2504 {
2505 is_concealing = TRUE;
2506 n_skip = 1;
2507 }
2508 mb_c = c;
2509 if (enc_utf8 && utf_char2len(c) > 1)
2510 {
2511 mb_utf8 = TRUE;
2512 u8cc[0] = 0;
2513 c = 0xc0;
2514 }
2515 else
2516 mb_utf8 = FALSE; // don't draw as UTF-8
2517 }
2518 else
2519 {
2520 prev_syntax_id = 0;
2521 is_concealing = FALSE;
2522 }
2523
2524 if (n_skip > 0 && did_decrement_ptr)
2525 // not showing the '>', put pointer back to avoid getting stuck
2526 ++ptr;
2527
2528#endif // FEAT_CONCEAL
2529 }
2530
2531#ifdef FEAT_CONCEAL
2532 // In the cursor line and we may be concealing characters: correct
2533 // the cursor column when we reach its position.
2534 if (!did_wcol && draw_state == WL_LINE
2535 && wp == curwin && lnum == wp->w_cursor.lnum
2536 && conceal_cursor_line(wp)
2537 && (int)wp->w_virtcol <= vcol + n_skip)
2538 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002539# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 if (wp->w_p_rl)
2541 wp->w_wcol = wp->w_width - col + boguscols - 1;
2542 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002543# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 wp->w_wcol = col - boguscols;
2545 wp->w_wrow = row;
2546 did_wcol = TRUE;
2547 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002548# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002549 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002550# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 }
2552#endif
2553
2554 // Don't override visual selection highlighting.
2555 if (n_attr > 0
2556 && draw_state == WL_LINE
2557 && !attr_pri)
2558 {
2559#ifdef LINE_ATTR
2560 if (line_attr)
2561 char_attr = hl_combine_attr(extra_attr, line_attr);
2562 else
2563#endif
2564 char_attr = extra_attr;
2565 }
2566
2567#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2568 // XIM don't send preedit_start and preedit_end, but they send
2569 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2570 // im_is_preediting() here.
2571 if (p_imst == IM_ON_THE_SPOT
2572 && xic != NULL
2573 && lnum == wp->w_cursor.lnum
2574 && (State & INSERT)
2575 && !p_imdisable
2576 && im_is_preediting()
2577 && draw_state == WL_LINE)
2578 {
2579 colnr_T tcol;
2580
2581 if (preedit_end_col == MAXCOL)
2582 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2583 else
2584 tcol = preedit_end_col;
2585 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2586 {
2587 if (feedback_old_attr < 0)
2588 {
2589 feedback_col = 0;
2590 feedback_old_attr = char_attr;
2591 }
2592 char_attr = im_get_feedback_attr(feedback_col);
2593 if (char_attr < 0)
2594 char_attr = feedback_old_attr;
2595 feedback_col++;
2596 }
2597 else if (feedback_old_attr >= 0)
2598 {
2599 char_attr = feedback_old_attr;
2600 feedback_old_attr = -1;
2601 feedback_col = 0;
2602 }
2603 }
2604#endif
2605 // Handle the case where we are in column 0 but not on the first
2606 // character of the line and the user wants us to show us a
2607 // special character (via 'listchars' option "precedes:<char>".
2608 if (lcs_prec_todo != NUL
2609 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002610 && (wp->w_p_wrap ?
2611 (wp->w_skipcol > 0 && row == 0) :
2612 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613#ifdef FEAT_DIFF
2614 && filler_todo <= 0
2615#endif
2616 && draw_state > WL_NR
2617 && c != NUL)
2618 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002619 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 lcs_prec_todo = NUL;
2621 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2622 {
2623 // Double-width character being overwritten by the "precedes"
2624 // character, need to fill up half the character.
2625 c_extra = MB_FILLER_CHAR;
2626 c_final = NUL;
2627 n_extra = 1;
2628 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002629 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 }
2631 mb_c = c;
2632 if (enc_utf8 && utf_char2len(c) > 1)
2633 {
2634 mb_utf8 = TRUE;
2635 u8cc[0] = 0;
2636 c = 0xc0;
2637 }
2638 else
2639 mb_utf8 = FALSE; // don't draw as UTF-8
2640 if (!attr_pri)
2641 {
2642 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002643 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 n_attr3 = 1;
2645 }
2646 }
2647
2648 // At end of the text line or just after the last character.
2649 if ((c == NUL
2650#if defined(LINE_ATTR)
2651 || did_line_attr == 1
2652#endif
2653 ) && eol_hl_off == 0)
2654 {
2655#ifdef FEAT_SEARCH_EXTRA
2656 // flag to indicate whether prevcol equals startcol of search_hl or
2657 // one of the matches
2658 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2659 (long)(ptr - line) - (c == NUL));
2660#endif
2661 // Invert at least one char, used for Visual and empty line or
2662 // highlight match at end of line. If it's beyond the last
2663 // char on the screen, just overwrite that one (tricky!) Not
2664 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002665 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 && ((area_attr != 0 && vcol == fromcol
2667 && (VIsual_mode != Ctrl_V
2668 || lnum == VIsual.lnum
2669 || lnum == curwin->w_cursor.lnum)
2670 && c == NUL)
2671#ifdef FEAT_SEARCH_EXTRA
2672 // highlight 'hlsearch' match at end of line
2673 || (prevcol_hl_flag
2674# ifdef FEAT_SYN_HL
2675 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2676 && !(wp == curwin && VIsual_active))
2677# endif
2678# ifdef FEAT_DIFF
2679 && diff_hlf == (hlf_T)0
2680# endif
2681# if defined(LINE_ATTR)
2682 && did_line_attr <= 1
2683# endif
2684 )
2685#endif
2686 ))
2687 {
2688 int n = 0;
2689
2690#ifdef FEAT_RIGHTLEFT
2691 if (wp->w_p_rl)
2692 {
2693 if (col < 0)
2694 n = 1;
2695 }
2696 else
2697#endif
2698 {
2699 if (col >= wp->w_width)
2700 n = -1;
2701 }
2702 if (n != 0)
2703 {
2704 // At the window boundary, highlight the last character
2705 // instead (better than nothing).
2706 off += n;
2707 col += n;
2708 }
2709 else
2710 {
2711 // Add a blank character to highlight.
2712 ScreenLines[off] = ' ';
2713 if (enc_utf8)
2714 ScreenLinesUC[off] = 0;
2715 }
2716#ifdef FEAT_SEARCH_EXTRA
2717 if (area_attr == 0)
2718 {
2719 // Use attributes from match with highest priority among
2720 // 'search_hl' and the match list.
2721 get_search_match_hl(wp, &screen_search_hl,
2722 (long)(ptr - line), &char_attr);
2723 }
2724#endif
2725 ScreenAttrs[off] = char_attr;
2726#ifdef FEAT_RIGHTLEFT
2727 if (wp->w_p_rl)
2728 {
2729 --col;
2730 --off;
2731 }
2732 else
2733#endif
2734 {
2735 ++col;
2736 ++off;
2737 }
2738 ++vcol;
2739 eol_hl_off = 1;
2740 }
2741 }
2742
2743 // At end of the text line.
2744 if (c == NUL)
2745 {
2746#ifdef FEAT_SYN_HL
2747 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2748 if (wp->w_p_wrap)
2749 v = wp->w_skipcol;
2750 else
2751 v = wp->w_leftcol;
2752
2753 // check if line ends before left margin
2754 if (vcol < v + col - win_col_off(wp))
2755 vcol = v + col - win_col_off(wp);
2756#ifdef FEAT_CONCEAL
2757 // Get rid of the boguscols now, we want to draw until the right
2758 // edge for 'cursorcolumn'.
2759 col -= boguscols;
2760 boguscols = 0;
2761#endif
2762
2763 if (draw_color_col)
2764 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2765
2766 if (((wp->w_p_cuc
2767 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2768 && (int)wp->w_virtcol <
2769 wp->w_width * (row - startrow + 1) + v
2770 && lnum != wp->w_cursor.lnum)
2771 || draw_color_col
2772 || win_attr != 0)
2773# ifdef FEAT_RIGHTLEFT
2774 && !wp->w_p_rl
2775# endif
2776 )
2777 {
2778 int rightmost_vcol = 0;
2779 int i;
2780
2781 if (wp->w_p_cuc)
2782 rightmost_vcol = wp->w_virtcol;
2783 if (draw_color_col)
2784 // determine rightmost colorcolumn to possibly draw
2785 for (i = 0; color_cols[i] >= 0; ++i)
2786 if (rightmost_vcol < color_cols[i])
2787 rightmost_vcol = color_cols[i];
2788
2789 while (col < wp->w_width)
2790 {
2791 ScreenLines[off] = ' ';
2792 if (enc_utf8)
2793 ScreenLinesUC[off] = 0;
2794 ++col;
2795 if (draw_color_col)
2796 draw_color_col = advance_color_col(VCOL_HLC,
2797 &color_cols);
2798
2799 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2800 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2801 else if (draw_color_col && VCOL_HLC == *color_cols)
2802 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2803 else
2804 ScreenAttrs[off++] = win_attr;
2805
2806 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2807 break;
2808
2809 ++vcol;
2810 }
2811 }
2812#endif
2813
2814 screen_line(screen_row, wp->w_wincol, col,
2815 (int)wp->w_width, screen_line_flags);
2816 row++;
2817
2818 // Update w_cline_height and w_cline_folded if the cursor line was
2819 // updated (saves a call to plines() later).
2820 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2821 {
2822 curwin->w_cline_row = startrow;
2823 curwin->w_cline_height = row - startrow;
2824#ifdef FEAT_FOLDING
2825 curwin->w_cline_folded = FALSE;
2826#endif
2827 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2828 }
2829
2830 break;
2831 }
2832
2833 // Show "extends" character from 'listchars' if beyond the line end and
2834 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002835 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002836 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 && wp->w_p_list
2838 && !wp->w_p_wrap
2839#ifdef FEAT_DIFF
2840 && filler_todo <= 0
2841#endif
2842 && (
2843#ifdef FEAT_RIGHTLEFT
2844 wp->w_p_rl ? col == 0 :
2845#endif
2846 col == wp->w_width - 1)
2847 && (*ptr != NUL
2848 || (wp->w_p_list && lcs_eol_one > 0)
2849 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2850 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002851 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002852 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 mb_c = c;
2854 if (enc_utf8 && utf_char2len(c) > 1)
2855 {
2856 mb_utf8 = TRUE;
2857 u8cc[0] = 0;
2858 c = 0xc0;
2859 }
2860 else
2861 mb_utf8 = FALSE;
2862 }
2863
2864#ifdef FEAT_SYN_HL
2865 // advance to the next 'colorcolumn'
2866 if (draw_color_col)
2867 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2868
2869 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2870 // highlight the cursor position itself.
2871 // Also highlight the 'colorcolumn' if it is different than
2872 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002873 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2874 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002875 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002876 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002877 draw_state == WL_BRI ||
2878 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002879 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002880# ifdef FEAT_DIFF
2881 && filler_todo <= 0
2882# endif
2883 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
2885 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2886 && lnum != wp->w_cursor.lnum)
2887 {
2888 vcol_save_attr = char_attr;
2889 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2890 }
2891 else if (draw_color_col && VCOL_HLC == *color_cols)
2892 {
2893 vcol_save_attr = char_attr;
2894 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2895 }
2896 }
2897#endif
2898
2899 // Store character to be displayed.
2900 // Skip characters that are left of the screen for 'nowrap'.
2901 vcol_prev = vcol;
2902 if (draw_state < WL_LINE || n_skip <= 0)
2903 {
2904 // Store the character.
2905#if defined(FEAT_RIGHTLEFT)
2906 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2907 {
2908 // A double-wide character is: put first halve in left cell.
2909 --off;
2910 --col;
2911 }
2912#endif
2913 ScreenLines[off] = c;
2914 if (enc_dbcs == DBCS_JPNU)
2915 {
2916 if ((mb_c & 0xff00) == 0x8e00)
2917 ScreenLines[off] = 0x8e;
2918 ScreenLines2[off] = mb_c & 0xff;
2919 }
2920 else if (enc_utf8)
2921 {
2922 if (mb_utf8)
2923 {
2924 int i;
2925
2926 ScreenLinesUC[off] = mb_c;
2927 if ((c & 0xff) == 0)
2928 ScreenLines[off] = 0x80; // avoid storing zero
2929 for (i = 0; i < Screen_mco; ++i)
2930 {
2931 ScreenLinesC[i][off] = u8cc[i];
2932 if (u8cc[i] == 0)
2933 break;
2934 }
2935 }
2936 else
2937 ScreenLinesUC[off] = 0;
2938 }
2939 if (multi_attr)
2940 {
2941 ScreenAttrs[off] = multi_attr;
2942 multi_attr = 0;
2943 }
2944 else
2945 ScreenAttrs[off] = char_attr;
2946
2947 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2948 {
2949 // Need to fill two screen columns.
2950 ++off;
2951 ++col;
2952 if (enc_utf8)
2953 // UTF-8: Put a 0 in the second screen char.
2954 ScreenLines[off] = 0;
2955 else
2956 // DBCS: Put second byte in the second screen char.
2957 ScreenLines[off] = mb_c & 0xff;
2958 if (draw_state > WL_NR
2959#ifdef FEAT_DIFF
2960 && filler_todo <= 0
2961#endif
2962 )
2963 ++vcol;
2964 // When "tocol" is halfway a character, set it to the end of
2965 // the character, otherwise highlighting won't stop.
2966 if (tocol == vcol)
2967 ++tocol;
2968#ifdef FEAT_RIGHTLEFT
2969 if (wp->w_p_rl)
2970 {
2971 // now it's time to backup one cell
2972 --off;
2973 --col;
2974 }
2975#endif
2976 }
2977#ifdef FEAT_RIGHTLEFT
2978 if (wp->w_p_rl)
2979 {
2980 --off;
2981 --col;
2982 }
2983 else
2984#endif
2985 {
2986 ++off;
2987 ++col;
2988 }
2989 }
2990#ifdef FEAT_CONCEAL
2991 else if (wp->w_p_cole > 0 && is_concealing)
2992 {
2993 --n_skip;
2994 ++vcol_off;
2995 if (n_extra > 0)
2996 vcol_off += n_extra;
2997 if (wp->w_p_wrap)
2998 {
2999 // Special voodoo required if 'wrap' is on.
3000 //
3001 // Advance the column indicator to force the line
3002 // drawing to wrap early. This will make the line
3003 // take up the same screen space when parts are concealed,
3004 // so that cursor line computations aren't messed up.
3005 //
3006 // To avoid the fictitious advance of 'col' causing
3007 // trailing junk to be written out of the screen line
3008 // we are building, 'boguscols' keeps track of the number
3009 // of bad columns we have advanced.
3010 if (n_extra > 0)
3011 {
3012 vcol += n_extra;
3013# ifdef FEAT_RIGHTLEFT
3014 if (wp->w_p_rl)
3015 {
3016 col -= n_extra;
3017 boguscols -= n_extra;
3018 }
3019 else
3020# endif
3021 {
3022 col += n_extra;
3023 boguscols += n_extra;
3024 }
3025 n_extra = 0;
3026 n_attr = 0;
3027 }
3028
3029
3030 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3031 {
3032 // Need to fill two screen columns.
3033# ifdef FEAT_RIGHTLEFT
3034 if (wp->w_p_rl)
3035 {
3036 --boguscols;
3037 --col;
3038 }
3039 else
3040# endif
3041 {
3042 ++boguscols;
3043 ++col;
3044 }
3045 }
3046
3047# ifdef FEAT_RIGHTLEFT
3048 if (wp->w_p_rl)
3049 {
3050 --boguscols;
3051 --col;
3052 }
3053 else
3054# endif
3055 {
3056 ++boguscols;
3057 ++col;
3058 }
3059 }
3060 else
3061 {
3062 if (n_extra > 0)
3063 {
3064 vcol += n_extra;
3065 n_extra = 0;
3066 n_attr = 0;
3067 }
3068 }
3069
3070 }
3071#endif // FEAT_CONCEAL
3072 else
3073 --n_skip;
3074
3075 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3076 // column.
3077 if (draw_state > WL_NR
3078#ifdef FEAT_DIFF
3079 && filler_todo <= 0
3080#endif
3081 )
3082 ++vcol;
3083
3084#ifdef FEAT_SYN_HL
3085 if (vcol_save_attr >= 0)
3086 char_attr = vcol_save_attr;
3087#endif
3088
3089 // restore attributes after "predeces" in 'listchars'
3090 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3091 char_attr = saved_attr3;
3092
3093 // restore attributes after last 'listchars' or 'number' char
3094 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3095 char_attr = saved_attr2;
3096
3097 // At end of screen line and there is more to come: Display the line
3098 // so far. If there is no more to display it is caught above.
3099 if ((
3100#ifdef FEAT_RIGHTLEFT
3101 wp->w_p_rl ? (col < 0) :
3102#endif
3103 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003104 && (draw_state != WL_LINE
3105 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106#ifdef FEAT_DIFF
3107 || filler_todo > 0
3108#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003109 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3110 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3112 )
3113 {
3114#ifdef FEAT_CONCEAL
3115 screen_line(screen_row, wp->w_wincol, col - boguscols,
3116 (int)wp->w_width, screen_line_flags);
3117 boguscols = 0;
3118#else
3119 screen_line(screen_row, wp->w_wincol, col,
3120 (int)wp->w_width, screen_line_flags);
3121#endif
3122 ++row;
3123 ++screen_row;
3124
3125 // When not wrapping and finished diff lines, or when displayed
3126 // '$' and highlighting until last column, break here.
3127 if ((!wp->w_p_wrap
3128#ifdef FEAT_DIFF
3129 && filler_todo <= 0
3130#endif
3131 ) || lcs_eol_one == -1)
3132 break;
3133
3134 // When the window is too narrow draw all "@" lines.
3135 if (draw_state != WL_LINE
3136#ifdef FEAT_DIFF
3137 && filler_todo <= 0
3138#endif
3139 )
3140 {
3141 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3142 draw_vsep_win(wp, row);
3143 row = endrow;
3144 }
3145
3146 // When line got too long for screen break here.
3147 if (row == endrow)
3148 {
3149 ++row;
3150 break;
3151 }
3152
3153 if (screen_cur_row == screen_row - 1
3154#ifdef FEAT_DIFF
3155 && filler_todo <= 0
3156#endif
3157 && wp->w_width == Columns)
3158 {
3159 // Remember that the line wraps, used for modeless copy.
3160 LineWraps[screen_row - 1] = TRUE;
3161
3162 // Special trick to make copy/paste of wrapped lines work with
3163 // xterm/screen: write an extra character beyond the end of
3164 // the line. This will work with all terminal types
3165 // (regardless of the xn,am settings).
3166 // Only do this on a fast tty.
3167 // Only do this if the cursor is on the current line
3168 // (something has been written in it).
3169 // Don't do this for the GUI.
3170 // Don't do this for double-width characters.
3171 // Don't do this for a window not at the right screen border.
3172 if (p_tf
3173#ifdef FEAT_GUI
3174 && !gui.in_use
3175#endif
3176 && !(has_mbyte
3177 && ((*mb_off2cells)(LineOffset[screen_row],
3178 LineOffset[screen_row] + screen_Columns)
3179 == 2
3180 || (*mb_off2cells)(LineOffset[screen_row - 1]
3181 + (int)Columns - 2,
3182 LineOffset[screen_row] + screen_Columns)
3183 == 2)))
3184 {
3185 // First make sure we are at the end of the screen line,
3186 // then output the same character again to let the
3187 // terminal know about the wrap. If the terminal doesn't
3188 // auto-wrap, we overwrite the character.
3189 if (screen_cur_col != wp->w_width)
3190 screen_char(LineOffset[screen_row - 1]
3191 + (unsigned)Columns - 1,
3192 screen_row - 1, (int)(Columns - 1));
3193
3194 // When there is a multi-byte character, just output a
3195 // space to keep it simple.
3196 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3197 screen_row - 1] + (Columns - 1)]) > 1)
3198 out_char(' ');
3199 else
3200 out_char(ScreenLines[LineOffset[screen_row - 1]
3201 + (Columns - 1)]);
3202 // force a redraw of the first char on the next line
3203 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3204 screen_start(); // don't know where cursor is now
3205 }
3206 }
3207
3208 col = 0;
3209 off = (unsigned)(current_ScreenLine - ScreenLines);
3210#ifdef FEAT_RIGHTLEFT
3211 if (wp->w_p_rl)
3212 {
3213 col = wp->w_width - 1; // col is not used if breaking!
3214 off += col;
3215 }
3216#endif
3217
3218 // reset the drawing state for the start of a wrapped line
3219 draw_state = WL_START;
3220 saved_n_extra = n_extra;
3221 saved_p_extra = p_extra;
3222 saved_c_extra = c_extra;
3223 saved_c_final = c_final;
3224#ifdef FEAT_SYN_HL
3225 if (!(cul_screenline
3226# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003227 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003229 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 saved_char_attr = char_attr;
3231 else
3232#endif
3233 saved_char_attr = 0;
3234 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003235 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236#ifdef FEAT_LINEBREAK
3237# ifdef FEAT_DIFF
3238 if (filler_todo <= 0)
3239# endif
3240 need_showbreak = TRUE;
3241#endif
3242#ifdef FEAT_DIFF
3243 --filler_todo;
3244 // When the filler lines are actually below the last line of the
3245 // file, don't draw the line itself, break here.
3246 if (filler_todo == 0 && wp->w_botfill)
3247 break;
3248#endif
3249 }
3250
3251 } // for every character in the line
3252
3253#ifdef FEAT_SPELL
3254 // After an empty line check first word for capital.
3255 if (*skipwhite(line) == NUL)
3256 {
3257 capcol_lnum = lnum + 1;
3258 cap_col = 0;
3259 }
3260#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003261#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 vim_free(text_props);
3263 vim_free(text_prop_idxs);
3264#endif
3265
3266 vim_free(p_extra_free);
3267 return row;
3268}