blob: 109b8b35ca8d546ca5b0049f30dc470d6b2d4788 [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
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000268#ifdef FEAT_LINEBREAK
269 int in_linebreak = FALSE; // n_extra set for showing linebreak
270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100272 // displaying eol at end-of-line
273 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
274 int lcs_prec_todo = wp->w_lcs_chars.prec; // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275
276 // saved "extra" items for when draw_state becomes WL_LINE (again)
277 int saved_n_extra = 0;
278 char_u *saved_p_extra = NULL;
279 int saved_c_extra = 0;
280 int saved_c_final = 0;
281 int saved_char_attr = 0;
282
283 int n_attr = 0; // chars with special attr
284 int saved_attr2 = 0; // char_attr saved for n_attr
285 int n_attr3 = 0; // chars with overruling special attr
286 int saved_attr3 = 0; // char_attr saved for n_attr3
287
288 int n_skip = 0; // nr of chars to skip for 'nowrap'
289
290 int fromcol = -10; // start of inverting
291 int tocol = MAXCOL; // end of inverting
292 int fromcol_prev = -2; // start of inverting after cursor
293 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 int lnum_in_visual_area = FALSE;
295 pos_T pos;
296 long v;
297
298 int char_attr = 0; // attributes for next character
299 int attr_pri = FALSE; // char_attr has priority
300 int area_highlighting = FALSE; // Visual or incsearch highlighting
301 // in this line
302 int vi_attr = 0; // attributes for Visual and incsearch
303 // highlighting
304 int wcr_attr = 0; // attributes from 'wincolor'
305 int win_attr = 0; // background for whole window, except
306 // margins and "~" lines.
307 int area_attr = 0; // attributes desired by highlighting
308 int search_attr = 0; // attributes desired by 'hlsearch'
309#ifdef FEAT_SYN_HL
310 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
311 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200312 int prev_syntax_col = -1; // column of prev_syntax_attr
313 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 int has_syntax = FALSE; // this buffer has syntax highl.
315 int save_did_emsg;
316 int draw_color_col = FALSE; // highlight colorcolumn
317 int *color_cols = NULL; // pointer to according columns array
318#endif
319 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100320#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200321 int text_prop_count;
322 int text_prop_next = 0; // next text property to use
323 textprop_T *text_props = NULL;
324 int *text_prop_idxs = NULL;
325 int text_props_active = 0;
326 proptype_T *text_prop_type = NULL;
327 int text_prop_attr = 0;
328 int text_prop_combine = FALSE;
329#endif
330#ifdef FEAT_SPELL
331 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200332 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200333# define SPWORDLEN 150
334 char_u nextline[SPWORDLEN * 2];// text with start of the next line
335 int nextlinecol = 0; // column where nextline[] starts
336 int nextline_idx = 0; // index in nextline[] where next line
337 // starts
338 int spell_attr = 0; // attributes desired by spelling
339 int word_end = 0; // last byte with same spell_attr
340 static linenr_T checked_lnum = 0; // line number for "checked_col"
341 static int checked_col = 0; // column in "checked_lnum" up to which
342 // there are no spell errors
343 static int cap_col = -1; // column to check for Cap word
344 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
345 int cur_checked_col = 0; // checked column for current line
346#endif
347 int extra_check = 0; // has extra highlighting
348 int multi_attr = 0; // attributes desired by multibyte
349 int mb_l = 1; // multi-byte byte length
350 int mb_c = 0; // decoded multi-byte character
351 int mb_utf8 = FALSE; // screen char is UTF-8 char
352 int u8cc[MAX_MCO]; // composing UTF-8 chars
353#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
354 int filler_lines = 0; // nr of filler lines to be drawn
355 int filler_todo = 0; // nr of filler lines still to do + 1
356#endif
357#ifdef FEAT_DIFF
358 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
359 int change_start = MAXCOL; // first col of changed area
360 int change_end = -1; // last col of changed area
361#endif
362 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100363 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200364 int in_multispace = FALSE; // in multiple consecutive spaces
365 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200366#ifdef FEAT_LINEBREAK
367 int need_showbreak = FALSE; // overlong line, skipping first x
368 // chars
369#endif
370#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
371 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
372# define LINE_ATTR
373 int line_attr = 0; // attribute for the whole line
374 int line_attr_save;
375#endif
376#ifdef FEAT_SIGNS
377 int sign_present = FALSE;
378 sign_attrs_T sattr;
379#endif
380#ifdef FEAT_ARABIC
381 int prev_c = 0; // previous Arabic character
382 int prev_c1 = 0; // first composing char for prev_c
383#endif
384#if defined(LINE_ATTR)
385 int did_line_attr = 0;
386#endif
387#ifdef FEAT_TERMINAL
388 int get_term_attr = FALSE;
389#endif
390#ifdef FEAT_SYN_HL
391 int cul_attr = 0; // set when 'cursorline' active
392
393 // 'cursorlineopt' has "screenline" and cursor is in this line
394 int cul_screenline = FALSE;
395
396 // margin columns for the screen line, needed for when 'cursorlineopt'
397 // contains "screenline"
398 int left_curline_col = 0;
399 int right_curline_col = 0;
400#endif
401
402 // draw_state: items that are drawn in sequence:
403#define WL_START 0 // nothing done yet
404#ifdef FEAT_CMDWIN
405# define WL_CMDLINE WL_START + 1 // cmdline window column
406#else
407# define WL_CMDLINE WL_START
408#endif
409#ifdef FEAT_FOLDING
410# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
411#else
412# define WL_FOLD WL_CMDLINE
413#endif
414#ifdef FEAT_SIGNS
415# define WL_SIGN WL_FOLD + 1 // column for signs
416#else
417# define WL_SIGN WL_FOLD // column for signs
418#endif
419#define WL_NR WL_SIGN + 1 // line number
420#ifdef FEAT_LINEBREAK
421# define WL_BRI WL_NR + 1 // 'breakindent'
422#else
423# define WL_BRI WL_NR
424#endif
425#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
426# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
427#else
428# define WL_SBR WL_BRI
429#endif
430#define WL_LINE WL_SBR + 1 // text in the line
431 int draw_state = WL_START; // what to draw next
432#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
433 int feedback_col = 0;
434 int feedback_old_attr = -1;
435#endif
436 int screen_line_flags = 0;
437
438#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
439 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000440 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200441#endif
442#ifdef FEAT_CONCEAL
443 int syntax_flags = 0;
444 int syntax_seqnr = 0;
445 int prev_syntax_id = 0;
446 int conceal_attr = HL_ATTR(HLF_CONCEAL);
447 int is_concealing = FALSE;
448 int boguscols = 0; // nonexistent columns added to force
449 // wrapping
450 int vcol_off = 0; // offset for concealed characters
451 int did_wcol = FALSE;
452 int old_boguscols = 0;
453# define VCOL_HLC (vcol - vcol_off)
454# define FIX_FOR_BOGUSCOLS \
455 { \
456 n_extra += vcol_off; \
457 vcol -= vcol_off; \
458 vcol_off = 0; \
459 col -= boguscols; \
460 old_boguscols = boguscols; \
461 boguscols = 0; \
462 }
463#else
464# define VCOL_HLC (vcol)
465#endif
466
467 if (startrow > endrow) // past the end already!
468 return startrow;
469
470 row = startrow;
471 screen_row = row + W_WINROW(wp);
472
473 if (!number_only)
474 {
475 // To speed up the loop below, set extra_check when there is linebreak,
476 // trailing white space and/or syntax processing to be done.
477#ifdef FEAT_LINEBREAK
478 extra_check = wp->w_p_lbr;
479#endif
480#ifdef FEAT_SYN_HL
481 if (syntax_present(wp) && !wp->w_s->b_syn_error
482# ifdef SYN_TIME_LIMIT
483 && !wp->w_s->b_syn_slow
484# endif
485 )
486 {
487 // Prepare for syntax highlighting in this line. When there is an
488 // error, stop syntax highlighting.
489 save_did_emsg = did_emsg;
490 did_emsg = FALSE;
491 syntax_start(wp, lnum);
492 if (did_emsg)
493 wp->w_s->b_syn_error = TRUE;
494 else
495 {
496 did_emsg = save_did_emsg;
497#ifdef SYN_TIME_LIMIT
498 if (!wp->w_s->b_syn_slow)
499#endif
500 {
501 has_syntax = TRUE;
502 extra_check = TRUE;
503 }
504 }
505 }
506
507 // Check for columns to display for 'colorcolumn'.
508 color_cols = wp->w_p_cc_cols;
509 if (color_cols != NULL)
510 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
511#endif
512
513#ifdef FEAT_TERMINAL
514 if (term_show_buffer(wp->w_buffer))
515 {
516 extra_check = TRUE;
517 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100518 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200519 }
520#endif
521
522#ifdef FEAT_SPELL
523 if (wp->w_p_spell
524 && *wp->w_s->b_p_spl != NUL
525 && wp->w_s->b_langp.ga_len > 0
526 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
527 {
528 // Prepare for spell checking.
529 has_spell = TRUE;
530 extra_check = TRUE;
531
532 // Get the start of the next line, so that words that wrap to the
533 // next line are found too: "et<line-break>al.".
534 // Trick: skip a few chars for C/shell/Vim comments
535 nextline[SPWORDLEN] = NUL;
536 if (lnum < wp->w_buffer->b_ml.ml_line_count)
537 {
538 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
539 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
540 }
541
542 // When a word wrapped from the previous line the start of the
543 // current line is valid.
544 if (lnum == checked_lnum)
545 cur_checked_col = checked_col;
546 checked_lnum = 0;
547
548 // When there was a sentence end in the previous line may require a
549 // word starting with capital in this line. In line 1 always check
550 // the first word.
551 if (lnum != capcol_lnum)
552 cap_col = -1;
553 if (lnum == 1)
554 cap_col = 0;
555 capcol_lnum = 0;
556 }
557#endif
558
559 // handle Visual active in this window
560 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
561 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100562 pos_T *top, *bot;
563
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200564 if (LTOREQ_POS(curwin->w_cursor, VIsual))
565 {
566 // Visual is after curwin->w_cursor
567 top = &curwin->w_cursor;
568 bot = &VIsual;
569 }
570 else
571 {
572 // Visual is before curwin->w_cursor
573 top = &VIsual;
574 bot = &curwin->w_cursor;
575 }
576 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
577 if (VIsual_mode == Ctrl_V)
578 {
579 // block mode
580 if (lnum_in_visual_area)
581 {
582 fromcol = wp->w_old_cursor_fcol;
583 tocol = wp->w_old_cursor_lcol;
584 }
585 }
586 else
587 {
588 // non-block mode
589 if (lnum > top->lnum && lnum <= bot->lnum)
590 fromcol = 0;
591 else if (lnum == top->lnum)
592 {
593 if (VIsual_mode == 'V') // linewise
594 fromcol = 0;
595 else
596 {
597 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
598 if (gchar_pos(top) == NUL)
599 tocol = fromcol + 1;
600 }
601 }
602 if (VIsual_mode != 'V' && lnum == bot->lnum)
603 {
604 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
605 {
606 fromcol = -10;
607 tocol = MAXCOL;
608 }
609 else if (bot->col == MAXCOL)
610 tocol = MAXCOL;
611 else
612 {
613 pos = *bot;
614 if (*p_sel == 'e')
615 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
616 else
617 {
618 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
619 ++tocol;
620 }
621 }
622 }
623 }
624
625 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200626 if (!highlight_match && lnum == curwin->w_cursor.lnum
627 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200628#ifdef FEAT_GUI
629 && !gui.in_use
630#endif
631 )
632 noinvcur = TRUE;
633
634 // if inverting in this line set area_highlighting
635 if (fromcol >= 0)
636 {
637 area_highlighting = TRUE;
638 vi_attr = HL_ATTR(HLF_V);
639#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
640 if ((clip_star.available && !clip_star.owned
641 && clip_isautosel_star())
642 || (clip_plus.available && !clip_plus.owned
643 && clip_isautosel_plus()))
644 vi_attr = HL_ATTR(HLF_VNC);
645#endif
646 }
647 }
648
649 // handle 'incsearch' and ":s///c" highlighting
650 else if (highlight_match
651 && wp == curwin
652 && lnum >= curwin->w_cursor.lnum
653 && lnum <= curwin->w_cursor.lnum + search_match_lines)
654 {
655 if (lnum == curwin->w_cursor.lnum)
656 getvcol(curwin, &(curwin->w_cursor),
657 (colnr_T *)&fromcol, NULL, NULL);
658 else
659 fromcol = 0;
660 if (lnum == curwin->w_cursor.lnum + search_match_lines)
661 {
662 pos.lnum = lnum;
663 pos.col = search_match_endcol;
664 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
665 }
666 else
667 tocol = MAXCOL;
668 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100669 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200670 tocol = fromcol + 1;
671 area_highlighting = TRUE;
672 vi_attr = HL_ATTR(HLF_I);
673 }
674 }
675
676#ifdef FEAT_DIFF
677 filler_lines = diff_check(wp, lnum);
678 if (filler_lines < 0)
679 {
680 if (filler_lines == -1)
681 {
682 if (diff_find_change(wp, lnum, &change_start, &change_end))
683 diff_hlf = HLF_ADD; // added line
684 else if (change_start == 0)
685 diff_hlf = HLF_TXD; // changed text
686 else
687 diff_hlf = HLF_CHD; // changed line
688 }
689 else
690 diff_hlf = HLF_ADD; // added line
691 filler_lines = 0;
692 area_highlighting = TRUE;
693 }
694 if (lnum == wp->w_topline)
695 filler_lines = wp->w_topfill;
696 filler_todo = filler_lines;
697#endif
698
699#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100700 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200701#endif
702
703#ifdef LINE_ATTR
704# ifdef FEAT_SIGNS
705 // If this line has a sign with line highlighting set line_attr.
706 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200707 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200708# endif
709# if defined(FEAT_QUICKFIX)
710 // Highlight the current line in the quickfix window.
711 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
712 line_attr = HL_ATTR(HLF_QFL);
713# endif
714 if (line_attr != 0)
715 area_highlighting = TRUE;
716#endif
717
718 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
719 ptr = line;
720
721#ifdef FEAT_SPELL
722 if (has_spell && !number_only)
723 {
724 // For checking first word with a capital skip white space.
725 if (cap_col == 0)
726 cap_col = getwhitecols(line);
727
728 // To be able to spell-check over line boundaries copy the end of the
729 // current line into nextline[]. Above the start of the next line was
730 // copied to nextline[SPWORDLEN].
731 if (nextline[SPWORDLEN] == NUL)
732 {
733 // No next line or it is empty.
734 nextlinecol = MAXCOL;
735 nextline_idx = 0;
736 }
737 else
738 {
739 v = (long)STRLEN(line);
740 if (v < SPWORDLEN)
741 {
742 // Short line, use it completely and append the start of the
743 // next line.
744 nextlinecol = 0;
745 mch_memmove(nextline, line, (size_t)v);
746 STRMOVE(nextline + v, nextline + SPWORDLEN);
747 nextline_idx = v + 1;
748 }
749 else
750 {
751 // Long line, use only the last SPWORDLEN bytes.
752 nextlinecol = v - SPWORDLEN;
753 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
754 nextline_idx = SPWORDLEN + 1;
755 }
756 }
757 }
758#endif
759
760 if (wp->w_p_list)
761 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100762 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200763 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100764 || wp->w_lcs_chars.trail
765 || wp->w_lcs_chars.lead
766 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200767 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100768
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200769 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100770 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200771 {
772 trailcol = (colnr_T)STRLEN(ptr);
773 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
774 --trailcol;
775 trailcol += (colnr_T) (ptr - line);
776 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100777 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100778 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100779 {
780 leadcol = 0;
781 while (VIM_ISWHITE(ptr[leadcol]))
782 ++leadcol;
783 if (ptr[leadcol] == NUL)
784 // in a line full of spaces all of them are treated as trailing
785 leadcol = (colnr_T)0;
786 else
787 // keep track of the first column not filled with spaces
788 leadcol += (colnr_T) (ptr - line) + 1;
789 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200790 }
791
792 wcr_attr = get_wcr_attr(wp);
793 if (wcr_attr != 0)
794 {
795 win_attr = wcr_attr;
796 area_highlighting = TRUE;
797 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200798
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100799#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200800 if (WIN_IS_POPUP(wp))
801 screen_line_flags |= SLF_POPUP;
802#endif
803
804 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
805 // first character to be displayed.
806 if (wp->w_p_wrap)
807 v = wp->w_skipcol;
808 else
809 v = wp->w_leftcol;
810 if (v > 0 && !number_only)
811 {
812 char_u *prev_ptr = ptr;
813
814 while (vcol < v && *ptr != NUL)
815 {
816 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
817 vcol += c;
818 prev_ptr = ptr;
819 MB_PTR_ADV(ptr);
820 }
821
822 // When:
823 // - 'cuc' is set, or
824 // - 'colorcolumn' is set, or
825 // - 'virtualedit' is set, or
826 // - the visual mode is active,
827 // the end of the line may be before the start of the displayed part.
828 if (vcol < v && (
829#ifdef FEAT_SYN_HL
830 wp->w_p_cuc || draw_color_col ||
831#endif
832 virtual_active() ||
833 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
834 vcol = v;
835
836 // Handle a character that's not completely on the screen: Put ptr at
837 // that character but skip the first few screen characters.
838 if (vcol > v)
839 {
840 vcol -= c;
841 ptr = prev_ptr;
842 // If the character fits on the screen, don't need to skip it.
843 // Except for a TAB.
844 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
845 n_skip = v - vcol;
846 }
847
848 // Adjust for when the inverted text is before the screen,
849 // and when the start of the inverted text is before the screen.
850 if (tocol <= vcol)
851 fromcol = 0;
852 else if (fromcol >= 0 && fromcol < vcol)
853 fromcol = vcol;
854
855#ifdef FEAT_LINEBREAK
856 // When w_skipcol is non-zero, first line needs 'showbreak'
857 if (wp->w_p_wrap)
858 need_showbreak = TRUE;
859#endif
860#ifdef FEAT_SPELL
861 // When spell checking a word we need to figure out the start of the
862 // word and if it's badly spelled or not.
863 if (has_spell)
864 {
865 int len;
866 colnr_T linecol = (colnr_T)(ptr - line);
867 hlf_T spell_hlf = HLF_COUNT;
868
869 pos = wp->w_cursor;
870 wp->w_cursor.lnum = lnum;
871 wp->w_cursor.col = linecol;
872 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
873
874 // spell_move_to() may call ml_get() and make "line" invalid
875 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
876 ptr = line + linecol;
877
878 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
879 {
880 // no bad word found at line start, don't check until end of a
881 // word
882 spell_hlf = HLF_COUNT;
883 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
884 }
885 else
886 {
887 // bad word found, use attributes until end of word
888 word_end = wp->w_cursor.col + len + 1;
889
890 // Turn index into actual attributes.
891 if (spell_hlf != HLF_COUNT)
892 spell_attr = highlight_attr[spell_hlf];
893 }
894 wp->w_cursor = pos;
895
896# ifdef FEAT_SYN_HL
897 // Need to restart syntax highlighting for this line.
898 if (has_syntax)
899 syntax_start(wp, lnum);
900# endif
901 }
902#endif
903 }
904
905 // Correct highlighting for cursor that can't be disabled.
906 // Avoids having to check this for each character.
907 if (fromcol >= 0)
908 {
909 if (noinvcur)
910 {
911 if ((colnr_T)fromcol == wp->w_virtcol)
912 {
913 // highlighting starts at cursor, let it start just after the
914 // cursor
915 fromcol_prev = fromcol;
916 fromcol = -1;
917 }
918 else if ((colnr_T)fromcol < wp->w_virtcol)
919 // restart highlighting after the cursor
920 fromcol_prev = wp->w_virtcol;
921 }
922 if (fromcol >= tocol)
923 fromcol = -1;
924 }
925
926#ifdef FEAT_SEARCH_EXTRA
927 if (!number_only)
928 {
929 v = (long)(ptr - line);
930 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
931 &line, &screen_search_hl,
932 &search_attr);
933 ptr = line + v; // "line" may have been updated
934 }
935#endif
936
937#ifdef FEAT_SYN_HL
938 // Cursor line highlighting for 'cursorline' in the current window.
939 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
940 {
941 // Do not show the cursor line in the text when Visual mode is active,
942 // because it's not clear what is selected then. Do update
943 // w_last_cursorline.
944 if (!(wp == curwin && VIsual_active)
945 && wp->w_p_culopt_flags != CULOPT_NBR)
946 {
947 cul_screenline = (wp->w_p_wrap
948 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
949
950 // Only set line_attr here when "screenline" is not present in
951 // 'cursorlineopt'. Otherwise it's done later.
952 if (!cul_screenline)
953 {
954 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200955# ifdef FEAT_SIGNS
956 // Combine the 'cursorline' and sign highlighting, depending on
957 // the sign priority.
958 if (sign_present && sattr.sat_linehl > 0)
959 {
960 if (sattr.sat_priority >= 100)
961 line_attr = hl_combine_attr(cul_attr, line_attr);
962 else
963 line_attr = hl_combine_attr(line_attr, cul_attr);
964 }
965 else
966# endif
967 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200968 wp->w_last_cursorline = wp->w_cursor.lnum;
969 }
970 else
971 {
972 line_attr_save = line_attr;
973 wp->w_last_cursorline = 0;
974 margin_columns_win(wp, &left_curline_col, &right_curline_col);
975 }
976 area_highlighting = TRUE;
977 }
978 else
979 wp->w_last_cursorline = wp->w_cursor.lnum;
980 }
981#endif
982
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100983#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 {
985 char_u *prop_start;
986
987 text_prop_count = get_text_props(wp->w_buffer, lnum,
988 &prop_start, FALSE);
989 if (text_prop_count > 0)
990 {
991 // Make a copy of the properties, so that they are properly
992 // aligned.
993 text_props = ALLOC_MULT(textprop_T, text_prop_count);
994 if (text_props != NULL)
995 mch_memmove(text_props, prop_start,
996 text_prop_count * sizeof(textprop_T));
997
998 // Allocate an array for the indexes.
999 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1000 area_highlighting = TRUE;
1001 extra_check = TRUE;
1002 }
1003 }
1004#endif
1005
1006 off = (unsigned)(current_ScreenLine - ScreenLines);
1007 col = 0;
1008
1009#ifdef FEAT_RIGHTLEFT
1010 if (wp->w_p_rl)
1011 {
1012 // Rightleft window: process the text in the normal direction, but put
1013 // it in current_ScreenLine[] from right to left. Start at the
1014 // rightmost column of the window.
1015 col = wp->w_width - 1;
1016 off += col;
1017 screen_line_flags |= SLF_RIGHTLEFT;
1018 }
1019#endif
1020
1021 // Repeat for the whole displayed line.
1022 for (;;)
1023 {
1024#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001025 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001026#endif
1027#ifdef FEAT_CONCEAL
1028 int did_decrement_ptr = FALSE;
1029#endif
1030 // Skip this quickly when working on the text.
1031 if (draw_state != WL_LINE)
1032 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001033#ifdef FEAT_SYN_HL
1034 if (cul_screenline)
1035 {
1036 cul_attr = 0;
1037 line_attr = line_attr_save;
1038 }
1039#endif
1040
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041#ifdef FEAT_CMDWIN
1042 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1043 {
1044 draw_state = WL_CMDLINE;
1045 if (cmdwin_type != 0 && wp == curwin)
1046 {
1047 // Draw the cmdline character.
1048 n_extra = 1;
1049 c_extra = cmdwin_type;
1050 c_final = NUL;
1051 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1052 }
1053 }
1054#endif
1055
1056#ifdef FEAT_FOLDING
1057 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1058 {
1059 int fdc = compute_foldcolumn(wp, 0);
1060
1061 draw_state = WL_FOLD;
1062 if (fdc > 0)
1063 {
1064 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1065 // already be in use.
1066 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001067 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068 if (p_extra_free != NULL)
1069 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001070 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001071 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 p_extra_free[n_extra] = NUL;
1073 p_extra = p_extra_free;
1074 c_extra = NUL;
1075 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001076 if (use_cursor_line_sign(wp, lnum))
1077 char_attr =
1078 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1079 else
1080 char_attr =
1081 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082 }
1083 }
1084 }
1085#endif
1086
1087#ifdef FEAT_SIGNS
1088 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1089 {
1090 draw_state = WL_SIGN;
1091 // Show the sign column when there are any signs in this
1092 // buffer or when using Netbeans.
1093 if (signcolumn_on(wp))
1094 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1095 row, startrow, filler_lines, filler_todo, &c_extra,
1096 &c_final, extra, &p_extra, &n_extra, &char_attr);
1097 }
1098#endif
1099
1100 if (draw_state == WL_NR - 1 && n_extra == 0)
1101 {
1102 draw_state = WL_NR;
1103 // Display the absolute or relative line number. After the
1104 // first fill with blanks when the 'n' flag isn't in 'cpo'
1105 if ((wp->w_p_nu || wp->w_p_rnu)
1106 && (row == startrow
1107#ifdef FEAT_DIFF
1108 + filler_lines
1109#endif
1110 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1111 {
1112#ifdef FEAT_SIGNS
1113 // If 'signcolumn' is set to 'number' and a sign is present
1114 // in 'lnum', then display the sign instead of the line
1115 // number.
1116 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1117 && sign_present)
1118 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1119 row, startrow, filler_lines, filler_todo,
1120 &c_extra, &c_final, extra, &p_extra, &n_extra,
1121 &char_attr);
1122 else
1123#endif
1124 {
1125 // Draw the line number (empty space after wrapping).
1126 if (row == startrow
1127#ifdef FEAT_DIFF
1128 + filler_lines
1129#endif
1130 )
1131 {
1132 long num;
1133 char *fmt = "%*ld ";
1134
1135 if (wp->w_p_nu && !wp->w_p_rnu)
1136 // 'number' + 'norelativenumber'
1137 num = (long)lnum;
1138 else
1139 {
1140 // 'relativenumber', don't use negative numbers
1141 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1142 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1143 {
1144 // 'number' + 'relativenumber'
1145 num = lnum;
1146 fmt = "%-*ld ";
1147 }
1148 }
1149
1150 sprintf((char *)extra, fmt,
1151 number_width(wp), num);
1152 if (wp->w_skipcol > 0)
1153 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1154 *p_extra = '-';
1155#ifdef FEAT_RIGHTLEFT
1156 if (wp->w_p_rl) // reverse line numbers
1157 {
1158 char_u *p1, *p2;
1159 int t;
1160
1161 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001162 p2 = skipwhite(extra);
1163 p2 = skiptowhite(p2) - 1;
1164 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 {
1166 t = *p1;
1167 *p1 = *p2;
1168 *p2 = t;
1169 }
1170 }
1171#endif
1172 p_extra = extra;
1173 c_extra = NUL;
1174 c_final = NUL;
1175 }
1176 else
1177 {
1178 c_extra = ' ';
1179 c_final = NUL;
1180 }
1181 n_extra = number_width(wp) + 1;
1182 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1183#ifdef FEAT_SYN_HL
1184 // When 'cursorline' is set highlight the line number of
1185 // the current line differently.
1186 // When 'cursorlineopt' has "screenline" only highlight
1187 // the line number itself.
1188 // TODO: Can we use CursorLine instead of CursorLineNr
1189 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001190 if (wp->w_p_cul
1191 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 && (wp->w_p_culopt_flags & CULOPT_NBR)
1193 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001194 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1196#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001197 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1198 && HL_ATTR(HLF_LNA) != 0)
1199 // Use LineNrAbove
1200 char_attr = hl_combine_attr(wcr_attr,
1201 HL_ATTR(HLF_LNA));
1202 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1203 && HL_ATTR(HLF_LNB) != 0)
1204 // Use LineNrBelow
1205 char_attr = hl_combine_attr(wcr_attr,
1206 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 }
1208 }
1209 }
1210
1211#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001212 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001213 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214 // draw indent after showbreak value
1215 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001216 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217 // After the showbreak, draw the breakindent
1218 draw_state = WL_BRI - 1;
1219
1220 // draw 'breakindent': indent wrapped text accordingly
1221 if (draw_state == WL_BRI - 1 && n_extra == 0)
1222 {
1223 draw_state = WL_BRI;
1224 // if need_showbreak is set, breakindent also applies
1225 if (wp->w_p_bri && n_extra == 0
1226 && (row != startrow || need_showbreak)
1227# ifdef FEAT_DIFF
1228 && filler_lines == 0
1229# endif
1230 )
1231 {
1232 char_attr = 0;
1233# ifdef FEAT_DIFF
1234 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236# endif
1237 p_extra = NULL;
1238 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001239 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 n_extra = get_breakindent_win(wp,
1241 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001242 if (row == startrow)
1243 {
1244 n_extra -= win_col_off2(wp);
1245 if (n_extra < 0)
1246 n_extra = 0;
1247 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001248 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001249 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250 // Correct end of highlighted area for 'breakindent',
1251 // required when 'linebreak' is also set.
1252 if (tocol == vcol)
1253 tocol += n_extra;
1254 }
1255 }
1256#endif
1257
1258#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1259 if (draw_state == WL_SBR - 1 && n_extra == 0)
1260 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001261 char_u *sbr;
1262
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 draw_state = WL_SBR;
1264# ifdef FEAT_DIFF
1265 if (filler_todo > 0)
1266 {
1267 // Draw "deleted" diff line(s).
1268 if (char2cells(fill_diff) > 1)
1269 {
1270 c_extra = '-';
1271 c_final = NUL;
1272 }
1273 else
1274 {
1275 c_extra = fill_diff;
1276 c_final = NUL;
1277 }
1278# ifdef FEAT_RIGHTLEFT
1279 if (wp->w_p_rl)
1280 n_extra = col + 1;
1281 else
1282# endif
1283 n_extra = wp->w_width - col;
1284 char_attr = HL_ATTR(HLF_DED);
1285 }
1286# endif
1287# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001288 sbr = get_showbreak_value(wp);
1289 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 {
1291 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001292 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 c_extra = NUL;
1294 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001295 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001296 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1297 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001298 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 // Correct end of highlighted area for 'showbreak',
1300 // required when 'linebreak' is also set.
1301 if (tocol == vcol)
1302 tocol += n_extra;
1303 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001304 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305# ifdef FEAT_SYN_HL
1306 // combine 'showbreak' with 'cursorline'
1307 if (cul_attr != 0)
1308 char_attr = hl_combine_attr(char_attr, cul_attr);
1309# endif
1310 }
1311# endif
1312 }
1313#endif
1314
1315 if (draw_state == WL_LINE - 1 && n_extra == 0)
1316 {
1317 draw_state = WL_LINE;
1318 if (saved_n_extra)
1319 {
1320 // Continue item from end of wrapped line.
1321 n_extra = saved_n_extra;
1322 c_extra = saved_c_extra;
1323 c_final = saved_c_final;
1324 p_extra = saved_p_extra;
1325 char_attr = saved_char_attr;
1326 }
1327 else
1328 char_attr = win_attr;
1329 }
1330 }
1331#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001332 if (cul_screenline && draw_state == WL_LINE
1333 && vcol >= left_curline_col
1334 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001336 cul_attr = HL_ATTR(HLF_CUL);
1337 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 }
1339#endif
1340
1341 // When still displaying '$' of change command, stop at cursor.
1342 // When only displaying the (relative) line number and that's done,
1343 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001344 if (((dollar_vcol >= 0 && wp == curwin
1345 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1346 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347#ifdef FEAT_DIFF
1348 && filler_todo <= 0
1349#endif
1350 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 {
1352 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1353 screen_line_flags);
1354 // Pretend we have finished updating the window. Except when
1355 // 'cursorcolumn' is set.
1356#ifdef FEAT_SYN_HL
1357 if (wp->w_p_cuc)
1358 row = wp->w_cline_row + wp->w_cline_height;
1359 else
1360#endif
1361 row = wp->w_height;
1362 break;
1363 }
1364
Bram Moolenaar34390282019-10-16 14:38:26 +02001365 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 {
1367 // handle Visual or match highlighting in this line
1368 if (vcol == fromcol
1369 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1370 && (*mb_ptr2cells)(ptr) > 1)
1371 || ((int)vcol_prev == fromcol_prev
1372 && vcol_prev < vcol // not at margin
1373 && vcol < tocol))
1374 area_attr = vi_attr; // start highlighting
1375 else if (area_attr != 0
1376 && (vcol == tocol
1377 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1378 area_attr = 0; // stop highlighting
1379
1380#ifdef FEAT_SEARCH_EXTRA
1381 if (!n_extra)
1382 {
1383 // Check for start/end of 'hlsearch' and other matches.
1384 // After end, check for start/end of next match.
1385 // When another match, have to check for start again.
1386 v = (long)(ptr - line);
1387 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1388 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001389 &match_conc, did_line_attr, lcs_eol_one,
1390 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001392
1393 // Do not allow a conceal over EOL otherwise EOL will be missed
1394 // and bad things happen.
1395 if (*ptr == NUL)
1396 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 }
1398#endif
1399
1400#ifdef FEAT_DIFF
1401 if (diff_hlf != (hlf_T)0)
1402 {
1403 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1404 && n_extra == 0)
1405 diff_hlf = HLF_TXD; // changed text
1406 if (diff_hlf == HLF_TXD && ptr - line > change_end
1407 && n_extra == 0)
1408 diff_hlf = HLF_CHD; // changed line
1409 line_attr = HL_ATTR(diff_hlf);
1410 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1411 && wp->w_p_culopt_flags != CULOPT_NBR
1412 && (!cul_screenline || (vcol >= left_curline_col
1413 && vcol <= right_curline_col)))
1414 line_attr = hl_combine_attr(
1415 line_attr, HL_ATTR(HLF_CUL));
1416 }
1417#endif
1418
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001419#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 if (text_props != NULL)
1421 {
1422 int pi;
1423 int bcol = (int)(ptr - line);
1424
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001425 if (n_extra > 0
1426# ifdef FEAT_LINEBREAK
1427 && !in_linebreak
1428# endif
1429 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 --bcol; // still working on the previous char, e.g. Tab
1431
1432 // Check if any active property ends.
1433 for (pi = 0; pi < text_props_active; ++pi)
1434 {
1435 int tpi = text_prop_idxs[pi];
1436
1437 if (bcol >= text_props[tpi].tp_col - 1
1438 + text_props[tpi].tp_len)
1439 {
1440 if (pi + 1 < text_props_active)
1441 mch_memmove(text_prop_idxs + pi,
1442 text_prop_idxs + pi + 1,
1443 sizeof(int)
1444 * (text_props_active - (pi + 1)));
1445 --text_props_active;
1446 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001447# ifdef FEAT_LINEBREAK
1448 // not exactly right but should work in most cases
1449 if (in_linebreak && syntax_attr == text_prop_attr)
1450 syntax_attr = 0;
1451# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 }
1453 }
1454
1455 // Add any text property that starts in this column.
1456 while (text_prop_next < text_prop_count
1457 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001458 {
1459 if (bcol <= text_props[text_prop_next].tp_col - 1
1460 + text_props[text_prop_next].tp_len)
1461 text_prop_idxs[text_props_active++] = text_prop_next;
1462 ++text_prop_next;
1463 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464
1465 text_prop_attr = 0;
1466 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001467 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 if (text_props_active > 0)
1469 {
1470 // Sort the properties on priority and/or starting last.
1471 // Then combine the attributes, highest priority last.
1472 current_text_props = text_props;
1473 current_buf = wp->w_buffer;
1474 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1475 sizeof(int), text_prop_compare);
1476
1477 for (pi = 0; pi < text_props_active; ++pi)
1478 {
1479 int tpi = text_prop_idxs[pi];
1480 proptype_T *pt = text_prop_type_by_id(
1481 wp->w_buffer, text_props[tpi].tp_type);
1482
1483 if (pt != NULL && pt->pt_hl_id > 0)
1484 {
1485 int pt_attr = syn_id2attr(pt->pt_hl_id);
1486
1487 text_prop_type = pt;
1488 text_prop_attr =
1489 hl_combine_attr(text_prop_attr, pt_attr);
1490 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1491 }
1492 }
1493 }
1494 }
1495#endif
1496
Bram Moolenaara74fda62019-10-19 17:38:03 +02001497#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001498 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001499 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001500 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001501# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001502 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001503 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001504# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001505 // Get syntax attribute.
1506 if (has_syntax)
1507 {
1508 // Get the syntax attribute for the character. If there
1509 // is an error, disable syntax highlighting.
1510 save_did_emsg = did_emsg;
1511 did_emsg = FALSE;
1512
1513 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001514 if (v == prev_syntax_col)
1515 // at same column again
1516 syntax_attr = prev_syntax_attr;
1517 else
1518 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001519# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001520 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001521# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001522 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001523# ifdef FEAT_SPELL
1524 has_spell ? &can_spell :
1525# endif
1526 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001527 prev_syntax_col = v;
1528 prev_syntax_attr = syntax_attr;
1529 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001530
Bram Moolenaar34390282019-10-16 14:38:26 +02001531 if (did_emsg)
1532 {
1533 wp->w_s->b_syn_error = TRUE;
1534 has_syntax = FALSE;
1535 syntax_attr = 0;
1536 }
1537 else
1538 did_emsg = save_did_emsg;
1539# ifdef SYN_TIME_LIMIT
1540 if (wp->w_s->b_syn_slow)
1541 has_syntax = FALSE;
1542# endif
1543
1544 // Need to get the line again, a multi-line regexp may
1545 // have made it invalid.
1546 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1547 ptr = line + v;
1548# ifdef FEAT_CONCEAL
1549 // no concealing past the end of the line, it interferes
1550 // with line highlighting
1551 if (*ptr == NUL)
1552 syntax_flags = 0;
1553 else
1554 syntax_flags = get_syntax_info(&syntax_seqnr);
1555# endif
1556 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001557 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001558# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001559 // Combine text property highlight into syntax highlight.
1560 if (text_prop_type != NULL)
1561 {
1562 if (text_prop_combine)
1563 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1564 else
1565 syntax_attr = text_prop_attr;
1566 }
1567# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001568#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001569
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 // Decide which of the highlight attributes to use.
1571 attr_pri = TRUE;
1572#ifdef LINE_ATTR
1573 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001574 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001576 if (!highlight_match)
1577 // let search highlight show in Visual area if possible
1578 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001579# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001580 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001581# endif
1582 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001584 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001586# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001587 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001588# endif
1589 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1591 || vcol < fromcol || vcol_prev < fromcol_prev
1592 || vcol >= tocol))
1593 {
1594 // Use line_attr when not in the Visual or 'incsearch' area
1595 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001596# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001597 char_attr = hl_combine_attr(syntax_attr, line_attr);
1598# else
1599 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001600# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 attr_pri = FALSE;
1602 }
1603#else
1604 if (area_attr != 0)
1605 char_attr = area_attr;
1606 else if (search_attr != 0)
1607 char_attr = search_attr;
1608#endif
1609 else
1610 {
1611 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001613 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001614#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001615 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001616#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 }
1618 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001619
1620 // combine attribute with 'wincolor'
1621 if (win_attr != 0)
1622 {
1623 if (char_attr == 0)
1624 char_attr = win_attr;
1625 else
1626 char_attr = hl_combine_attr(win_attr, char_attr);
1627 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628
1629 // Get the next character to put on the screen.
1630
1631 // The "p_extra" points to the extra stuff that is inserted to
1632 // represent special characters (non-printable stuff) and other
1633 // things. When all characters are the same, c_extra is used.
1634 // If c_final is set, it will compulsorily be used at the end.
1635 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1636 // "p_extra[n_extra]".
1637 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1638 if (n_extra > 0)
1639 {
1640 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1641 {
1642 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1643 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1644 if (enc_utf8 && utf_char2len(c) > 1)
1645 {
1646 mb_utf8 = TRUE;
1647 u8cc[0] = 0;
1648 c = 0xc0;
1649 }
1650 else
1651 mb_utf8 = FALSE;
1652 }
1653 else
1654 {
1655 c = *p_extra;
1656 if (has_mbyte)
1657 {
1658 mb_c = c;
1659 if (enc_utf8)
1660 {
1661 // If the UTF-8 character is more than one byte:
1662 // Decode it into "mb_c".
1663 mb_l = utfc_ptr2len(p_extra);
1664 mb_utf8 = FALSE;
1665 if (mb_l > n_extra)
1666 mb_l = 1;
1667 else if (mb_l > 1)
1668 {
1669 mb_c = utfc_ptr2char(p_extra, u8cc);
1670 mb_utf8 = TRUE;
1671 c = 0xc0;
1672 }
1673 }
1674 else
1675 {
1676 // if this is a DBCS character, put it in "mb_c"
1677 mb_l = MB_BYTE2LEN(c);
1678 if (mb_l >= n_extra)
1679 mb_l = 1;
1680 else if (mb_l > 1)
1681 mb_c = (c << 8) + p_extra[1];
1682 }
1683 if (mb_l == 0) // at the NUL at end-of-line
1684 mb_l = 1;
1685
1686 // If a double-width char doesn't fit display a '>' in the
1687 // last column.
1688 if ((
1689# ifdef FEAT_RIGHTLEFT
1690 wp->w_p_rl ? (col <= 0) :
1691# endif
1692 (col >= wp->w_width - 1))
1693 && (*mb_char2cells)(mb_c) == 2)
1694 {
1695 c = '>';
1696 mb_c = c;
1697 mb_l = 1;
1698 mb_utf8 = FALSE;
1699 multi_attr = HL_ATTR(HLF_AT);
1700#ifdef FEAT_SYN_HL
1701 if (cul_attr)
1702 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1703#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001704 multi_attr = hl_combine_attr(win_attr, multi_attr);
1705
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 // put the pointer back to output the double-width
1707 // character at the start of the next line.
1708 ++n_extra;
1709 --p_extra;
1710 }
1711 else
1712 {
1713 n_extra -= mb_l - 1;
1714 p_extra += mb_l - 1;
1715 }
1716 }
1717 ++p_extra;
1718 }
1719 --n_extra;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001720#ifdef FEAT_LINEBREAK
1721 if (n_extra <= 0)
1722 in_linebreak = FALSE;
1723#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 }
1725 else
1726 {
1727#ifdef FEAT_LINEBREAK
1728 int c0;
1729#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001730 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 // Get a character from the line itself.
1733 c = *ptr;
1734#ifdef FEAT_LINEBREAK
1735 c0 = *ptr;
1736#endif
1737 if (has_mbyte)
1738 {
1739 mb_c = c;
1740 if (enc_utf8)
1741 {
1742 // If the UTF-8 character is more than one byte: Decode it
1743 // into "mb_c".
1744 mb_l = utfc_ptr2len(ptr);
1745 mb_utf8 = FALSE;
1746 if (mb_l > 1)
1747 {
1748 mb_c = utfc_ptr2char(ptr, u8cc);
1749 // Overlong encoded ASCII or ASCII with composing char
1750 // is displayed normally, except a NUL.
1751 if (mb_c < 0x80)
1752 {
1753 c = mb_c;
1754#ifdef FEAT_LINEBREAK
1755 c0 = mb_c;
1756#endif
1757 }
1758 mb_utf8 = TRUE;
1759
1760 // At start of the line we can have a composing char.
1761 // Draw it as a space with a composing char.
1762 if (utf_iscomposing(mb_c))
1763 {
1764 int i;
1765
1766 for (i = Screen_mco - 1; i > 0; --i)
1767 u8cc[i] = u8cc[i - 1];
1768 u8cc[0] = mb_c;
1769 mb_c = ' ';
1770 }
1771 }
1772
1773 if ((mb_l == 1 && c >= 0x80)
1774 || (mb_l >= 1 && mb_c == 0)
1775 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1776 {
1777 // Illegal UTF-8 byte: display as <xx>.
1778 // Non-BMP character : display as ? or fullwidth ?.
1779 transchar_hex(extra, mb_c);
1780# ifdef FEAT_RIGHTLEFT
1781 if (wp->w_p_rl) // reverse
1782 rl_mirror(extra);
1783# endif
1784 p_extra = extra;
1785 c = *p_extra;
1786 mb_c = mb_ptr2char_adv(&p_extra);
1787 mb_utf8 = (c >= 0x80);
1788 n_extra = (int)STRLEN(p_extra);
1789 c_extra = NUL;
1790 c_final = NUL;
1791 if (area_attr == 0 && search_attr == 0)
1792 {
1793 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001794 extra_attr = hl_combine_attr(
1795 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 saved_attr2 = char_attr; // save current attr
1797 }
1798 }
1799 else if (mb_l == 0) // at the NUL at end-of-line
1800 mb_l = 1;
1801#ifdef FEAT_ARABIC
1802 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1803 {
1804 // Do Arabic shaping.
1805 int pc, pc1, nc;
1806 int pcc[MAX_MCO];
1807
1808 // The idea of what is the previous and next
1809 // character depends on 'rightleft'.
1810 if (wp->w_p_rl)
1811 {
1812 pc = prev_c;
1813 pc1 = prev_c1;
1814 nc = utf_ptr2char(ptr + mb_l);
1815 prev_c1 = u8cc[0];
1816 }
1817 else
1818 {
1819 pc = utfc_ptr2char(ptr + mb_l, pcc);
1820 nc = prev_c;
1821 pc1 = pcc[0];
1822 }
1823 prev_c = mb_c;
1824
1825 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1826 }
1827 else
1828 prev_c = mb_c;
1829#endif
1830 }
1831 else // enc_dbcs
1832 {
1833 mb_l = MB_BYTE2LEN(c);
1834 if (mb_l == 0) // at the NUL at end-of-line
1835 mb_l = 1;
1836 else if (mb_l > 1)
1837 {
1838 // We assume a second byte below 32 is illegal.
1839 // Hopefully this is OK for all double-byte encodings!
1840 if (ptr[1] >= 32)
1841 mb_c = (c << 8) + ptr[1];
1842 else
1843 {
1844 if (ptr[1] == NUL)
1845 {
1846 // head byte at end of line
1847 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001848 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 }
1850 else
1851 {
1852 // illegal tail byte
1853 mb_l = 2;
1854 STRCPY(extra, "XX");
1855 }
1856 p_extra = extra;
1857 n_extra = (int)STRLEN(extra) - 1;
1858 c_extra = NUL;
1859 c_final = NUL;
1860 c = *p_extra++;
1861 if (area_attr == 0 && search_attr == 0)
1862 {
1863 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001864 extra_attr = hl_combine_attr(
1865 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 saved_attr2 = char_attr; // save current attr
1867 }
1868 mb_c = c;
1869 }
1870 }
1871 }
1872 // If a double-width char doesn't fit display a '>' in the
1873 // last column; the character is displayed at the start of the
1874 // next line.
1875 if ((
1876# ifdef FEAT_RIGHTLEFT
1877 wp->w_p_rl ? (col <= 0) :
1878# endif
1879 (col >= wp->w_width - 1))
1880 && (*mb_char2cells)(mb_c) == 2)
1881 {
1882 c = '>';
1883 mb_c = c;
1884 mb_utf8 = FALSE;
1885 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001886 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 // Put pointer back so that the character will be
1888 // displayed at the start of the next line.
1889 --ptr;
1890#ifdef FEAT_CONCEAL
1891 did_decrement_ptr = TRUE;
1892#endif
1893 }
1894 else if (*ptr != NUL)
1895 ptr += mb_l - 1;
1896
1897 // If a double-width char doesn't fit at the left side display
1898 // a '<' in the first column. Don't do this for unprintable
1899 // characters.
1900 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1901 {
1902 n_extra = 1;
1903 c_extra = MB_FILLER_CHAR;
1904 c_final = NUL;
1905 c = ' ';
1906 if (area_attr == 0 && search_attr == 0)
1907 {
1908 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001909 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 saved_attr2 = char_attr; // save current attr
1911 }
1912 mb_c = c;
1913 mb_utf8 = FALSE;
1914 mb_l = 1;
1915 }
1916
1917 }
1918 ++ptr;
1919
1920 if (extra_check)
1921 {
1922#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 // Check spelling (unless at the end of the line).
1924 // Only do this when there is no syntax highlighting, the
1925 // @Spell cluster is not used or the current syntax item
1926 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001927 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 if (has_spell && v >= word_end && v > cur_checked_col)
1929 {
1930 spell_attr = 0;
1931 if (c != 0 && (
1932# ifdef FEAT_SYN_HL
1933 !has_syntax ||
1934# endif
1935 can_spell))
1936 {
1937 char_u *prev_ptr, *p;
1938 int len;
1939 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 if (has_mbyte)
1942 {
1943 prev_ptr = ptr - mb_l;
1944 v -= mb_l - 1;
1945 }
1946 else
1947 prev_ptr = ptr - 1;
1948
1949 // Use nextline[] if possible, it has the start of the
1950 // next line concatenated.
1951 if ((prev_ptr - line) - nextlinecol >= 0)
1952 p = nextline + (prev_ptr - line) - nextlinecol;
1953 else
1954 p = prev_ptr;
1955 cap_col -= (int)(prev_ptr - line);
1956 len = spell_check(wp, p, &spell_hlf, &cap_col,
1957 nochange);
1958 word_end = v + len;
1959
1960 // In Insert mode only highlight a word that
1961 // doesn't touch the cursor.
1962 if (spell_hlf != HLF_COUNT
1963 && (State & INSERT) != 0
1964 && wp->w_cursor.lnum == lnum
1965 && wp->w_cursor.col >=
1966 (colnr_T)(prev_ptr - line)
1967 && wp->w_cursor.col < (colnr_T)word_end)
1968 {
1969 spell_hlf = HLF_COUNT;
1970 spell_redraw_lnum = lnum;
1971 }
1972
1973 if (spell_hlf == HLF_COUNT && p != prev_ptr
1974 && (p - nextline) + len > nextline_idx)
1975 {
1976 // Remember that the good word continues at the
1977 // start of the next line.
1978 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001979 checked_col = (int)((p - nextline)
1980 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 }
1982
1983 // Turn index into actual attributes.
1984 if (spell_hlf != HLF_COUNT)
1985 spell_attr = highlight_attr[spell_hlf];
1986
1987 if (cap_col > 0)
1988 {
1989 if (p != prev_ptr
1990 && (p - nextline) + cap_col >= nextline_idx)
1991 {
1992 // Remember that the word in the next line
1993 // must start with a capital.
1994 capcol_lnum = lnum + 1;
1995 cap_col = (int)((p - nextline) + cap_col
1996 - nextline_idx);
1997 }
1998 else
1999 // Compute the actual column.
2000 cap_col += (int)(prev_ptr - line);
2001 }
2002 }
2003 }
2004 if (spell_attr != 0)
2005 {
2006 if (!attr_pri)
2007 char_attr = hl_combine_attr(char_attr, spell_attr);
2008 else
2009 char_attr = hl_combine_attr(spell_attr, char_attr);
2010 }
2011#endif
2012#ifdef FEAT_LINEBREAK
2013 // Found last space before word: check for line break.
2014 if (wp->w_p_lbr && c0 == c
2015 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2016 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002017 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2018 : 0;
2019 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020
2021 // TODO: is passing p for start of the line OK?
2022 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2023 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002024
2025 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002026 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002027 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002028 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002029 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002030 if (n_extra < 0)
2031 n_extra = 0;
2032 }
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002033 if (on_last_col)
2034 // Do not continue search/match highlighting over the
2035 // line break.
2036 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002037
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 if (c == TAB && n_extra + col > wp->w_width)
2039# ifdef FEAT_VARTABS
2040 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2041 wp->w_buffer->b_p_vts_array) - 1;
2042# else
2043 n_extra = (int)wp->w_buffer->b_p_ts
2044 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2045# endif
2046
2047 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2048 c_final = NUL;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002049 if (n_extra > 0)
2050 in_linebreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 if (VIM_ISWHITE(c))
2052 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002053# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 if (c == TAB)
2055 // See "Tab alignment" below.
2056 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002057# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 if (!wp->w_p_list)
2059 c = ' ';
2060 }
2061 }
2062#endif
2063
zeertzjqf14b8ba2021-09-10 16:58:30 +02002064 in_multispace = c == ' '
2065 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2066 if (!in_multispace)
2067 multispace_pos = 0;
2068
Bram Moolenaareed9d462021-02-15 20:38:25 +01002069 // 'list': Change char 160 to 'nbsp' and space to 'space'
2070 // setting in 'listchars'. But not when the character is
2071 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002072 if (wp->w_p_list
2073 && ((((c == 160 && mb_l == 1)
2074 || (mb_utf8
2075 && ((mb_c == 160 && mb_l == 2)
2076 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002077 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 || (c == ' '
2079 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002080 && (wp->w_lcs_chars.space
2081 || (in_multispace
2082 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002083 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 && ptr - line <= trailcol)))
2085 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002086 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2087 {
2088 c = wp->w_lcs_chars.multispace[multispace_pos++];
2089 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2090 multispace_pos = 0;
2091 }
2092 else
2093 c = (c == ' ') ? wp->w_lcs_chars.space
2094 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002095 if (area_attr == 0 && search_attr == 0)
2096 {
2097 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002098 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 saved_attr2 = char_attr; // save current attr
2100 }
2101 mb_c = c;
2102 if (enc_utf8 && utf_char2len(c) > 1)
2103 {
2104 mb_utf8 = TRUE;
2105 u8cc[0] = 0;
2106 c = 0xc0;
2107 }
2108 else
2109 mb_utf8 = FALSE;
2110 }
2111
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002112 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2113 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002114 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002115 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2116 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002117 if (!attr_pri)
2118 {
2119 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002120 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002121 saved_attr2 = char_attr; // save current attr
2122 }
2123 mb_c = c;
2124 if (enc_utf8 && utf_char2len(c) > 1)
2125 {
2126 mb_utf8 = TRUE;
2127 u8cc[0] = 0;
2128 c = 0xc0;
2129 }
2130 else
2131 mb_utf8 = FALSE;
2132 }
2133 }
2134
2135 // Handling of non-printable characters.
2136 if (!vim_isprintc(c))
2137 {
2138 // when getting a character from the file, we may have to
2139 // turn it into something else on the way to putting it
2140 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002141 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142 {
2143 int tab_len = 0;
2144 long vcol_adjusted = vcol; // removed showbreak length
2145#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002146 char_u *sbr = get_showbreak_value(wp);
2147
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 // only adjust the tab_len, when at the first column
2149 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002150 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2151 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152#endif
2153 // tab amount depends on current column
2154#ifdef FEAT_VARTABS
2155 tab_len = tabstop_padding(vcol_adjusted,
2156 wp->w_buffer->b_p_ts,
2157 wp->w_buffer->b_p_vts_array) - 1;
2158#else
2159 tab_len = (int)wp->w_buffer->b_p_ts
2160 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2161#endif
2162
2163#ifdef FEAT_LINEBREAK
2164 if (!wp->w_p_lbr || !wp->w_p_list)
2165#endif
2166 // tab amount depends on current column
2167 n_extra = tab_len;
2168#ifdef FEAT_LINEBREAK
2169 else
2170 {
2171 char_u *p;
2172 int len;
2173 int i;
2174 int saved_nextra = n_extra;
2175
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002176# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 if (vcol_off > 0)
2178 // there are characters to conceal
2179 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002180
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002182 if (wp->w_p_list && wp->w_lcs_chars.tab1
2183 && old_boguscols > 0
2184 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002186# endif
2187 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002189 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002190 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002191 if (wp->w_lcs_chars.tab3)
2192 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 if (n_extra > 0)
2194 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002195 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002197 if (p == NULL)
2198 n_extra = 0;
2199 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002201 vim_memset(p, ' ', len);
2202 p[len] = NUL;
2203 vim_free(p_extra_free);
2204 p_extra_free = p;
2205 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002207 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002209 if (*p == NUL)
2210 {
2211 tab_len = i;
2212 break;
2213 }
2214
2215 // if tab3 is given, use it for the last char
2216 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2217 lcs = wp->w_lcs_chars.tab3;
2218 p += mb_char2bytes(lcs, p);
2219 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002221 }
2222 p_extra = p_extra_free;
2223# ifdef FEAT_CONCEAL
2224 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2225 // macro below, so need to adjust for that here
2226 if (vcol_off > 0)
2227 n_extra -= vcol_off;
2228# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 }
2231#endif
2232#ifdef FEAT_CONCEAL
2233 {
2234 int vc_saved = vcol_off;
2235
2236 // Tab alignment should be identical regardless of
2237 // 'conceallevel' value. So tab compensates of all
2238 // previous concealed characters, and thus resets
2239 // vcol_off and boguscols accumulated so far in the
2240 // line. Note that the tab can be longer than
2241 // 'tabstop' when there are concealed characters.
2242 FIX_FOR_BOGUSCOLS;
2243
2244 // Make sure, the highlighting for the tab char will be
2245 // correctly set further below (effectively reverts the
2246 // FIX_FOR_BOGSUCOLS macro
2247 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002248 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 tab_len += vc_saved;
2250 }
2251#endif
2252 mb_utf8 = FALSE; // don't draw as UTF-8
2253 if (wp->w_p_list)
2254 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002255 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2256 ? wp->w_lcs_chars.tab3
2257 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258#ifdef FEAT_LINEBREAK
2259 if (wp->w_p_lbr)
2260 c_extra = NUL; // using p_extra from above
2261 else
2262#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002263 c_extra = wp->w_lcs_chars.tab2;
2264 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002266 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 saved_attr2 = char_attr; // save current attr
2268 mb_c = c;
2269 if (enc_utf8 && utf_char2len(c) > 1)
2270 {
2271 mb_utf8 = TRUE;
2272 u8cc[0] = 0;
2273 c = 0xc0;
2274 }
2275 }
2276 else
2277 {
2278 c_final = NUL;
2279 c_extra = ' ';
2280 c = ' ';
2281 }
2282 }
2283 else if (c == NUL
2284 && (wp->w_p_list
2285 || ((fromcol >= 0 || fromcol_prev >= 0)
2286 && tocol > vcol
2287 && VIsual_mode != Ctrl_V
2288 && (
2289# ifdef FEAT_RIGHTLEFT
2290 wp->w_p_rl ? (col >= 0) :
2291# endif
2292 (col < wp->w_width))
2293 && !(noinvcur
2294 && lnum == wp->w_cursor.lnum
2295 && (colnr_T)vcol == wp->w_virtcol)))
2296 && lcs_eol_one > 0)
2297 {
2298 // Display a '$' after the line or highlight an extra
2299 // character if the line break is included.
2300#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2301 // For a diff line the highlighting continues after the
2302 // "$".
2303 if (
2304# ifdef FEAT_DIFF
2305 diff_hlf == (hlf_T)0
2306# ifdef LINE_ATTR
2307 &&
2308# endif
2309# endif
2310# ifdef LINE_ATTR
2311 line_attr == 0
2312# endif
2313 )
2314#endif
2315 {
2316 // In virtualedit, visual selections may extend
2317 // beyond end of line.
2318 if (area_highlighting && virtual_active()
2319 && tocol != MAXCOL && vcol < tocol)
2320 n_extra = 0;
2321 else
2322 {
2323 p_extra = at_end_str;
2324 n_extra = 1;
2325 c_extra = NUL;
2326 c_final = NUL;
2327 }
2328 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002329 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2330 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 else
2332 c = ' ';
2333 lcs_eol_one = -1;
2334 --ptr; // put it back at the NUL
2335 if (!attr_pri)
2336 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002337 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338 n_attr = 1;
2339 }
2340 mb_c = c;
2341 if (enc_utf8 && utf_char2len(c) > 1)
2342 {
2343 mb_utf8 = TRUE;
2344 u8cc[0] = 0;
2345 c = 0xc0;
2346 }
2347 else
2348 mb_utf8 = FALSE; // don't draw as UTF-8
2349 }
2350 else if (c != NUL)
2351 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002352 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 if (n_extra == 0)
2354 n_extra = byte2cells(c) - 1;
2355#ifdef FEAT_RIGHTLEFT
2356 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2357 rl_mirror(p_extra); // reverse "<12>"
2358#endif
2359 c_extra = NUL;
2360 c_final = NUL;
2361#ifdef FEAT_LINEBREAK
2362 if (wp->w_p_lbr)
2363 {
2364 char_u *p;
2365
2366 c = *p_extra;
2367 p = alloc(n_extra + 1);
2368 vim_memset(p, ' ', n_extra);
2369 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2370 p[n_extra] = NUL;
2371 vim_free(p_extra_free);
2372 p_extra_free = p_extra = p;
2373 }
2374 else
2375#endif
2376 {
2377 n_extra = byte2cells(c) - 1;
2378 c = *p_extra++;
2379 }
2380 if (!attr_pri)
2381 {
2382 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002383 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 saved_attr2 = char_attr; // save current attr
2385 }
2386 mb_utf8 = FALSE; // don't draw as UTF-8
2387 }
2388 else if (VIsual_active
2389 && (VIsual_mode == Ctrl_V
2390 || VIsual_mode == 'v')
2391 && virtual_active()
2392 && tocol != MAXCOL
2393 && vcol < tocol
2394 && (
2395#ifdef FEAT_RIGHTLEFT
2396 wp->w_p_rl ? (col >= 0) :
2397#endif
2398 (col < wp->w_width)))
2399 {
2400 c = ' ';
2401 --ptr; // put it back at the NUL
2402 }
2403#if defined(LINE_ATTR)
2404 else if ((
2405# ifdef FEAT_DIFF
2406 diff_hlf != (hlf_T)0 ||
2407# endif
2408# ifdef FEAT_TERMINAL
2409 win_attr != 0 ||
2410# endif
2411 line_attr != 0
2412 ) && (
2413# ifdef FEAT_RIGHTLEFT
2414 wp->w_p_rl ? (col >= 0) :
2415# endif
2416 (col
2417# ifdef FEAT_CONCEAL
2418 - boguscols
2419# endif
2420 < wp->w_width)))
2421 {
2422 // Highlight until the right side of the window
2423 c = ' ';
2424 --ptr; // put it back at the NUL
2425
2426 // Remember we do the char for line highlighting.
2427 ++did_line_attr;
2428
2429 // don't do search HL for the rest of the line
2430 if (line_attr != 0 && char_attr == search_attr
2431 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002432 || (wp->w_p_list &&
2433 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 char_attr = line_attr;
2435# ifdef FEAT_DIFF
2436 if (diff_hlf == HLF_TXD)
2437 {
2438 diff_hlf = HLF_CHD;
2439 if (vi_attr == 0 || char_attr != vi_attr)
2440 {
2441 char_attr = HL_ATTR(diff_hlf);
2442 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2443 && wp->w_p_culopt_flags != CULOPT_NBR
2444 && (!cul_screenline
2445 || (vcol >= left_curline_col
2446 && vcol <= right_curline_col)))
2447 char_attr = hl_combine_attr(
2448 char_attr, HL_ATTR(HLF_CUL));
2449 }
2450 }
2451# endif
2452# ifdef FEAT_TERMINAL
2453 if (win_attr != 0)
2454 {
2455 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002456 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2457 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 {
2459 if (!cul_screenline || (vcol >= left_curline_col
2460 && vcol <= right_curline_col))
2461 char_attr = hl_combine_attr(
2462 char_attr, HL_ATTR(HLF_CUL));
2463 }
2464 else if (line_attr)
2465 char_attr = hl_combine_attr(char_attr, line_attr);
2466 }
2467# endif
2468 }
2469#endif
2470 }
2471
2472#ifdef FEAT_CONCEAL
2473 if ( wp->w_p_cole > 0
2474 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2475 conceal_cursor_line(wp))
2476 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2477 && !(lnum_in_visual_area
2478 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2479 {
2480 char_attr = conceal_attr;
2481 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002482 && (syn_get_sub_char() != NUL
2483 || (has_match_conc && match_conc)
2484 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 && wp->w_p_cole != 3)
2486 {
2487 // First time at this concealed item: display one
2488 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002489 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 c = match_conc;
2491 else if (syn_get_sub_char() != NUL)
2492 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002493 else if (wp->w_lcs_chars.conceal != NUL)
2494 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 else
2496 c = ' ';
2497
2498 prev_syntax_id = syntax_seqnr;
2499
2500 if (n_extra > 0)
2501 vcol_off += n_extra;
2502 vcol += n_extra;
2503 if (wp->w_p_wrap && n_extra > 0)
2504 {
2505# ifdef FEAT_RIGHTLEFT
2506 if (wp->w_p_rl)
2507 {
2508 col -= n_extra;
2509 boguscols -= n_extra;
2510 }
2511 else
2512# endif
2513 {
2514 boguscols += n_extra;
2515 col += n_extra;
2516 }
2517 }
2518 n_extra = 0;
2519 n_attr = 0;
2520 }
2521 else if (n_skip == 0)
2522 {
2523 is_concealing = TRUE;
2524 n_skip = 1;
2525 }
2526 mb_c = c;
2527 if (enc_utf8 && utf_char2len(c) > 1)
2528 {
2529 mb_utf8 = TRUE;
2530 u8cc[0] = 0;
2531 c = 0xc0;
2532 }
2533 else
2534 mb_utf8 = FALSE; // don't draw as UTF-8
2535 }
2536 else
2537 {
2538 prev_syntax_id = 0;
2539 is_concealing = FALSE;
2540 }
2541
2542 if (n_skip > 0 && did_decrement_ptr)
2543 // not showing the '>', put pointer back to avoid getting stuck
2544 ++ptr;
2545
2546#endif // FEAT_CONCEAL
2547 }
2548
2549#ifdef FEAT_CONCEAL
2550 // In the cursor line and we may be concealing characters: correct
2551 // the cursor column when we reach its position.
2552 if (!did_wcol && draw_state == WL_LINE
2553 && wp == curwin && lnum == wp->w_cursor.lnum
2554 && conceal_cursor_line(wp)
2555 && (int)wp->w_virtcol <= vcol + n_skip)
2556 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002557# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 if (wp->w_p_rl)
2559 wp->w_wcol = wp->w_width - col + boguscols - 1;
2560 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002561# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 wp->w_wcol = col - boguscols;
2563 wp->w_wrow = row;
2564 did_wcol = TRUE;
2565 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002566# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002567 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002568# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 }
2570#endif
2571
2572 // Don't override visual selection highlighting.
2573 if (n_attr > 0
2574 && draw_state == WL_LINE
2575 && !attr_pri)
2576 {
2577#ifdef LINE_ATTR
2578 if (line_attr)
2579 char_attr = hl_combine_attr(extra_attr, line_attr);
2580 else
2581#endif
2582 char_attr = extra_attr;
2583 }
2584
2585#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2586 // XIM don't send preedit_start and preedit_end, but they send
2587 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2588 // im_is_preediting() here.
2589 if (p_imst == IM_ON_THE_SPOT
2590 && xic != NULL
2591 && lnum == wp->w_cursor.lnum
2592 && (State & INSERT)
2593 && !p_imdisable
2594 && im_is_preediting()
2595 && draw_state == WL_LINE)
2596 {
2597 colnr_T tcol;
2598
2599 if (preedit_end_col == MAXCOL)
2600 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2601 else
2602 tcol = preedit_end_col;
2603 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2604 {
2605 if (feedback_old_attr < 0)
2606 {
2607 feedback_col = 0;
2608 feedback_old_attr = char_attr;
2609 }
2610 char_attr = im_get_feedback_attr(feedback_col);
2611 if (char_attr < 0)
2612 char_attr = feedback_old_attr;
2613 feedback_col++;
2614 }
2615 else if (feedback_old_attr >= 0)
2616 {
2617 char_attr = feedback_old_attr;
2618 feedback_old_attr = -1;
2619 feedback_col = 0;
2620 }
2621 }
2622#endif
2623 // Handle the case where we are in column 0 but not on the first
2624 // character of the line and the user wants us to show us a
2625 // special character (via 'listchars' option "precedes:<char>".
2626 if (lcs_prec_todo != NUL
2627 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002628 && (wp->w_p_wrap ?
2629 (wp->w_skipcol > 0 && row == 0) :
2630 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631#ifdef FEAT_DIFF
2632 && filler_todo <= 0
2633#endif
2634 && draw_state > WL_NR
2635 && c != NUL)
2636 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002637 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 lcs_prec_todo = NUL;
2639 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2640 {
2641 // Double-width character being overwritten by the "precedes"
2642 // character, need to fill up half the character.
2643 c_extra = MB_FILLER_CHAR;
2644 c_final = NUL;
2645 n_extra = 1;
2646 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002647 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 }
2649 mb_c = c;
2650 if (enc_utf8 && utf_char2len(c) > 1)
2651 {
2652 mb_utf8 = TRUE;
2653 u8cc[0] = 0;
2654 c = 0xc0;
2655 }
2656 else
2657 mb_utf8 = FALSE; // don't draw as UTF-8
2658 if (!attr_pri)
2659 {
2660 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002661 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 n_attr3 = 1;
2663 }
2664 }
2665
2666 // At end of the text line or just after the last character.
2667 if ((c == NUL
2668#if defined(LINE_ATTR)
2669 || did_line_attr == 1
2670#endif
2671 ) && eol_hl_off == 0)
2672 {
2673#ifdef FEAT_SEARCH_EXTRA
2674 // flag to indicate whether prevcol equals startcol of search_hl or
2675 // one of the matches
2676 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2677 (long)(ptr - line) - (c == NUL));
2678#endif
2679 // Invert at least one char, used for Visual and empty line or
2680 // highlight match at end of line. If it's beyond the last
2681 // char on the screen, just overwrite that one (tricky!) Not
2682 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002683 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 && ((area_attr != 0 && vcol == fromcol
2685 && (VIsual_mode != Ctrl_V
2686 || lnum == VIsual.lnum
2687 || lnum == curwin->w_cursor.lnum)
2688 && c == NUL)
2689#ifdef FEAT_SEARCH_EXTRA
2690 // highlight 'hlsearch' match at end of line
2691 || (prevcol_hl_flag
2692# ifdef FEAT_SYN_HL
2693 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2694 && !(wp == curwin && VIsual_active))
2695# endif
2696# ifdef FEAT_DIFF
2697 && diff_hlf == (hlf_T)0
2698# endif
2699# if defined(LINE_ATTR)
2700 && did_line_attr <= 1
2701# endif
2702 )
2703#endif
2704 ))
2705 {
2706 int n = 0;
2707
2708#ifdef FEAT_RIGHTLEFT
2709 if (wp->w_p_rl)
2710 {
2711 if (col < 0)
2712 n = 1;
2713 }
2714 else
2715#endif
2716 {
2717 if (col >= wp->w_width)
2718 n = -1;
2719 }
2720 if (n != 0)
2721 {
2722 // At the window boundary, highlight the last character
2723 // instead (better than nothing).
2724 off += n;
2725 col += n;
2726 }
2727 else
2728 {
2729 // Add a blank character to highlight.
2730 ScreenLines[off] = ' ';
2731 if (enc_utf8)
2732 ScreenLinesUC[off] = 0;
2733 }
2734#ifdef FEAT_SEARCH_EXTRA
2735 if (area_attr == 0)
2736 {
2737 // Use attributes from match with highest priority among
2738 // 'search_hl' and the match list.
2739 get_search_match_hl(wp, &screen_search_hl,
2740 (long)(ptr - line), &char_attr);
2741 }
2742#endif
2743 ScreenAttrs[off] = char_attr;
2744#ifdef FEAT_RIGHTLEFT
2745 if (wp->w_p_rl)
2746 {
2747 --col;
2748 --off;
2749 }
2750 else
2751#endif
2752 {
2753 ++col;
2754 ++off;
2755 }
2756 ++vcol;
2757 eol_hl_off = 1;
2758 }
2759 }
2760
2761 // At end of the text line.
2762 if (c == NUL)
2763 {
2764#ifdef FEAT_SYN_HL
2765 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2766 if (wp->w_p_wrap)
2767 v = wp->w_skipcol;
2768 else
2769 v = wp->w_leftcol;
2770
2771 // check if line ends before left margin
2772 if (vcol < v + col - win_col_off(wp))
2773 vcol = v + col - win_col_off(wp);
2774#ifdef FEAT_CONCEAL
2775 // Get rid of the boguscols now, we want to draw until the right
2776 // edge for 'cursorcolumn'.
2777 col -= boguscols;
2778 boguscols = 0;
2779#endif
2780
2781 if (draw_color_col)
2782 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2783
2784 if (((wp->w_p_cuc
2785 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2786 && (int)wp->w_virtcol <
2787 wp->w_width * (row - startrow + 1) + v
2788 && lnum != wp->w_cursor.lnum)
2789 || draw_color_col
2790 || win_attr != 0)
2791# ifdef FEAT_RIGHTLEFT
2792 && !wp->w_p_rl
2793# endif
2794 )
2795 {
2796 int rightmost_vcol = 0;
2797 int i;
2798
2799 if (wp->w_p_cuc)
2800 rightmost_vcol = wp->w_virtcol;
2801 if (draw_color_col)
2802 // determine rightmost colorcolumn to possibly draw
2803 for (i = 0; color_cols[i] >= 0; ++i)
2804 if (rightmost_vcol < color_cols[i])
2805 rightmost_vcol = color_cols[i];
2806
2807 while (col < wp->w_width)
2808 {
2809 ScreenLines[off] = ' ';
2810 if (enc_utf8)
2811 ScreenLinesUC[off] = 0;
2812 ++col;
2813 if (draw_color_col)
2814 draw_color_col = advance_color_col(VCOL_HLC,
2815 &color_cols);
2816
2817 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2818 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2819 else if (draw_color_col && VCOL_HLC == *color_cols)
2820 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2821 else
2822 ScreenAttrs[off++] = win_attr;
2823
2824 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2825 break;
2826
2827 ++vcol;
2828 }
2829 }
2830#endif
2831
2832 screen_line(screen_row, wp->w_wincol, col,
2833 (int)wp->w_width, screen_line_flags);
2834 row++;
2835
2836 // Update w_cline_height and w_cline_folded if the cursor line was
2837 // updated (saves a call to plines() later).
2838 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2839 {
2840 curwin->w_cline_row = startrow;
2841 curwin->w_cline_height = row - startrow;
2842#ifdef FEAT_FOLDING
2843 curwin->w_cline_folded = FALSE;
2844#endif
2845 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2846 }
2847
2848 break;
2849 }
2850
2851 // Show "extends" character from 'listchars' if beyond the line end and
2852 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002853 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002854 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 && wp->w_p_list
2856 && !wp->w_p_wrap
2857#ifdef FEAT_DIFF
2858 && filler_todo <= 0
2859#endif
2860 && (
2861#ifdef FEAT_RIGHTLEFT
2862 wp->w_p_rl ? col == 0 :
2863#endif
2864 col == wp->w_width - 1)
2865 && (*ptr != NUL
2866 || (wp->w_p_list && lcs_eol_one > 0)
2867 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2868 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002869 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002870 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 mb_c = c;
2872 if (enc_utf8 && utf_char2len(c) > 1)
2873 {
2874 mb_utf8 = TRUE;
2875 u8cc[0] = 0;
2876 c = 0xc0;
2877 }
2878 else
2879 mb_utf8 = FALSE;
2880 }
2881
2882#ifdef FEAT_SYN_HL
2883 // advance to the next 'colorcolumn'
2884 if (draw_color_col)
2885 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2886
2887 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2888 // highlight the cursor position itself.
2889 // Also highlight the 'colorcolumn' if it is different than
2890 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002891 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2892 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002894 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002895 draw_state == WL_BRI ||
2896 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002898# ifdef FEAT_DIFF
2899 && filler_todo <= 0
2900# endif
2901 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 {
2903 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2904 && lnum != wp->w_cursor.lnum)
2905 {
2906 vcol_save_attr = char_attr;
2907 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2908 }
2909 else if (draw_color_col && VCOL_HLC == *color_cols)
2910 {
2911 vcol_save_attr = char_attr;
2912 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2913 }
2914 }
2915#endif
2916
2917 // Store character to be displayed.
2918 // Skip characters that are left of the screen for 'nowrap'.
2919 vcol_prev = vcol;
2920 if (draw_state < WL_LINE || n_skip <= 0)
2921 {
2922 // Store the character.
2923#if defined(FEAT_RIGHTLEFT)
2924 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2925 {
2926 // A double-wide character is: put first halve in left cell.
2927 --off;
2928 --col;
2929 }
2930#endif
2931 ScreenLines[off] = c;
2932 if (enc_dbcs == DBCS_JPNU)
2933 {
2934 if ((mb_c & 0xff00) == 0x8e00)
2935 ScreenLines[off] = 0x8e;
2936 ScreenLines2[off] = mb_c & 0xff;
2937 }
2938 else if (enc_utf8)
2939 {
2940 if (mb_utf8)
2941 {
2942 int i;
2943
2944 ScreenLinesUC[off] = mb_c;
2945 if ((c & 0xff) == 0)
2946 ScreenLines[off] = 0x80; // avoid storing zero
2947 for (i = 0; i < Screen_mco; ++i)
2948 {
2949 ScreenLinesC[i][off] = u8cc[i];
2950 if (u8cc[i] == 0)
2951 break;
2952 }
2953 }
2954 else
2955 ScreenLinesUC[off] = 0;
2956 }
2957 if (multi_attr)
2958 {
2959 ScreenAttrs[off] = multi_attr;
2960 multi_attr = 0;
2961 }
2962 else
2963 ScreenAttrs[off] = char_attr;
2964
2965 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2966 {
2967 // Need to fill two screen columns.
2968 ++off;
2969 ++col;
2970 if (enc_utf8)
2971 // UTF-8: Put a 0 in the second screen char.
2972 ScreenLines[off] = 0;
2973 else
2974 // DBCS: Put second byte in the second screen char.
2975 ScreenLines[off] = mb_c & 0xff;
2976 if (draw_state > WL_NR
2977#ifdef FEAT_DIFF
2978 && filler_todo <= 0
2979#endif
2980 )
2981 ++vcol;
2982 // When "tocol" is halfway a character, set it to the end of
2983 // the character, otherwise highlighting won't stop.
2984 if (tocol == vcol)
2985 ++tocol;
2986#ifdef FEAT_RIGHTLEFT
2987 if (wp->w_p_rl)
2988 {
2989 // now it's time to backup one cell
2990 --off;
2991 --col;
2992 }
2993#endif
2994 }
2995#ifdef FEAT_RIGHTLEFT
2996 if (wp->w_p_rl)
2997 {
2998 --off;
2999 --col;
3000 }
3001 else
3002#endif
3003 {
3004 ++off;
3005 ++col;
3006 }
3007 }
3008#ifdef FEAT_CONCEAL
3009 else if (wp->w_p_cole > 0 && is_concealing)
3010 {
3011 --n_skip;
3012 ++vcol_off;
3013 if (n_extra > 0)
3014 vcol_off += n_extra;
3015 if (wp->w_p_wrap)
3016 {
3017 // Special voodoo required if 'wrap' is on.
3018 //
3019 // Advance the column indicator to force the line
3020 // drawing to wrap early. This will make the line
3021 // take up the same screen space when parts are concealed,
3022 // so that cursor line computations aren't messed up.
3023 //
3024 // To avoid the fictitious advance of 'col' causing
3025 // trailing junk to be written out of the screen line
3026 // we are building, 'boguscols' keeps track of the number
3027 // of bad columns we have advanced.
3028 if (n_extra > 0)
3029 {
3030 vcol += n_extra;
3031# ifdef FEAT_RIGHTLEFT
3032 if (wp->w_p_rl)
3033 {
3034 col -= n_extra;
3035 boguscols -= n_extra;
3036 }
3037 else
3038# endif
3039 {
3040 col += n_extra;
3041 boguscols += n_extra;
3042 }
3043 n_extra = 0;
3044 n_attr = 0;
3045 }
3046
3047
3048 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3049 {
3050 // Need to fill two screen columns.
3051# ifdef FEAT_RIGHTLEFT
3052 if (wp->w_p_rl)
3053 {
3054 --boguscols;
3055 --col;
3056 }
3057 else
3058# endif
3059 {
3060 ++boguscols;
3061 ++col;
3062 }
3063 }
3064
3065# ifdef FEAT_RIGHTLEFT
3066 if (wp->w_p_rl)
3067 {
3068 --boguscols;
3069 --col;
3070 }
3071 else
3072# endif
3073 {
3074 ++boguscols;
3075 ++col;
3076 }
3077 }
3078 else
3079 {
3080 if (n_extra > 0)
3081 {
3082 vcol += n_extra;
3083 n_extra = 0;
3084 n_attr = 0;
3085 }
3086 }
3087
3088 }
3089#endif // FEAT_CONCEAL
3090 else
3091 --n_skip;
3092
3093 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3094 // column.
3095 if (draw_state > WL_NR
3096#ifdef FEAT_DIFF
3097 && filler_todo <= 0
3098#endif
3099 )
3100 ++vcol;
3101
3102#ifdef FEAT_SYN_HL
3103 if (vcol_save_attr >= 0)
3104 char_attr = vcol_save_attr;
3105#endif
3106
3107 // restore attributes after "predeces" in 'listchars'
3108 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3109 char_attr = saved_attr3;
3110
3111 // restore attributes after last 'listchars' or 'number' char
3112 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3113 char_attr = saved_attr2;
3114
3115 // At end of screen line and there is more to come: Display the line
3116 // so far. If there is no more to display it is caught above.
3117 if ((
3118#ifdef FEAT_RIGHTLEFT
3119 wp->w_p_rl ? (col < 0) :
3120#endif
3121 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003122 && (draw_state != WL_LINE
3123 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124#ifdef FEAT_DIFF
3125 || filler_todo > 0
3126#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003127 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3128 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3130 )
3131 {
3132#ifdef FEAT_CONCEAL
3133 screen_line(screen_row, wp->w_wincol, col - boguscols,
3134 (int)wp->w_width, screen_line_flags);
3135 boguscols = 0;
3136#else
3137 screen_line(screen_row, wp->w_wincol, col,
3138 (int)wp->w_width, screen_line_flags);
3139#endif
3140 ++row;
3141 ++screen_row;
3142
3143 // When not wrapping and finished diff lines, or when displayed
3144 // '$' and highlighting until last column, break here.
3145 if ((!wp->w_p_wrap
3146#ifdef FEAT_DIFF
3147 && filler_todo <= 0
3148#endif
3149 ) || lcs_eol_one == -1)
3150 break;
3151
3152 // When the window is too narrow draw all "@" lines.
3153 if (draw_state != WL_LINE
3154#ifdef FEAT_DIFF
3155 && filler_todo <= 0
3156#endif
3157 )
3158 {
3159 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3160 draw_vsep_win(wp, row);
3161 row = endrow;
3162 }
3163
3164 // When line got too long for screen break here.
3165 if (row == endrow)
3166 {
3167 ++row;
3168 break;
3169 }
3170
3171 if (screen_cur_row == screen_row - 1
3172#ifdef FEAT_DIFF
3173 && filler_todo <= 0
3174#endif
3175 && wp->w_width == Columns)
3176 {
3177 // Remember that the line wraps, used for modeless copy.
3178 LineWraps[screen_row - 1] = TRUE;
3179
3180 // Special trick to make copy/paste of wrapped lines work with
3181 // xterm/screen: write an extra character beyond the end of
3182 // the line. This will work with all terminal types
3183 // (regardless of the xn,am settings).
3184 // Only do this on a fast tty.
3185 // Only do this if the cursor is on the current line
3186 // (something has been written in it).
3187 // Don't do this for the GUI.
3188 // Don't do this for double-width characters.
3189 // Don't do this for a window not at the right screen border.
3190 if (p_tf
3191#ifdef FEAT_GUI
3192 && !gui.in_use
3193#endif
3194 && !(has_mbyte
3195 && ((*mb_off2cells)(LineOffset[screen_row],
3196 LineOffset[screen_row] + screen_Columns)
3197 == 2
3198 || (*mb_off2cells)(LineOffset[screen_row - 1]
3199 + (int)Columns - 2,
3200 LineOffset[screen_row] + screen_Columns)
3201 == 2)))
3202 {
3203 // First make sure we are at the end of the screen line,
3204 // then output the same character again to let the
3205 // terminal know about the wrap. If the terminal doesn't
3206 // auto-wrap, we overwrite the character.
3207 if (screen_cur_col != wp->w_width)
3208 screen_char(LineOffset[screen_row - 1]
3209 + (unsigned)Columns - 1,
3210 screen_row - 1, (int)(Columns - 1));
3211
3212 // When there is a multi-byte character, just output a
3213 // space to keep it simple.
3214 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3215 screen_row - 1] + (Columns - 1)]) > 1)
3216 out_char(' ');
3217 else
3218 out_char(ScreenLines[LineOffset[screen_row - 1]
3219 + (Columns - 1)]);
3220 // force a redraw of the first char on the next line
3221 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3222 screen_start(); // don't know where cursor is now
3223 }
3224 }
3225
3226 col = 0;
3227 off = (unsigned)(current_ScreenLine - ScreenLines);
3228#ifdef FEAT_RIGHTLEFT
3229 if (wp->w_p_rl)
3230 {
3231 col = wp->w_width - 1; // col is not used if breaking!
3232 off += col;
3233 }
3234#endif
3235
3236 // reset the drawing state for the start of a wrapped line
3237 draw_state = WL_START;
3238 saved_n_extra = n_extra;
3239 saved_p_extra = p_extra;
3240 saved_c_extra = c_extra;
3241 saved_c_final = c_final;
3242#ifdef FEAT_SYN_HL
3243 if (!(cul_screenline
3244# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003245 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003247 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 saved_char_attr = char_attr;
3249 else
3250#endif
3251 saved_char_attr = 0;
3252 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003253 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254#ifdef FEAT_LINEBREAK
3255# ifdef FEAT_DIFF
3256 if (filler_todo <= 0)
3257# endif
3258 need_showbreak = TRUE;
3259#endif
3260#ifdef FEAT_DIFF
3261 --filler_todo;
3262 // When the filler lines are actually below the last line of the
3263 // file, don't draw the line itself, break here.
3264 if (filler_todo == 0 && wp->w_botfill)
3265 break;
3266#endif
3267 }
3268
3269 } // for every character in the line
3270
3271#ifdef FEAT_SPELL
3272 // After an empty line check first word for capital.
3273 if (*skipwhite(line) == NUL)
3274 {
3275 capcol_lnum = lnum + 1;
3276 cap_col = 0;
3277 }
3278#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003279#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 vim_free(text_props);
3281 vim_free(text_prop_idxs);
3282#endif
3283
3284 vim_free(p_extra_free);
3285 return row;
3286}