blob: 0d7c5b49646b1133b571f0b711665a436886632c [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;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100211 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 proptype_T *pt1, *pt2;
213 colnr_T col1, col2;
214
215 idx1 = *(int *)s1;
216 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100217 tp1 = &current_text_props[idx1];
218 tp2 = &current_text_props[idx2];
219 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
220 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221 if (pt1 == pt2)
222 return 0;
223 if (pt1 == NULL)
224 return -1;
225 if (pt2 == NULL)
226 return 1;
227 if (pt1->pt_priority != pt2->pt_priority)
228 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100229 col1 = tp1->tp_col;
230 col2 = tp2->tp_col;
231 if (col1 == MAXCOL && col2 == MAXCOL)
232 {
233 int flags1 = 0;
234 int flags2 = 0;
235
236 // order on 0: after, 1: right, 2: below
237 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
238 flags1 = 1;
239 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
240 flags1 = 2;
241 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
242 flags2 = 1;
243 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
244 flags2 = 2;
245 if (flags1 != flags2)
246 return flags1 < flags2 ? 1 : -1;
247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200248 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
249}
250#endif
251
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100252// structure with variables passed between win_line() and other functions
253typedef struct {
254 linenr_T lnum; // line number to be drawn
255
256 int startrow; // first row in the window to be drawn
257 int row; // row in the window, excl w_winrow
258 int screen_row; // row on the screen, incl w_winrow
259
260 long vcol; // virtual column, before wrapping
261 int col; // visual column on screen, after wrapping
262#ifdef FEAT_CONCEAL
263 int boguscols; // nonexistent columns added to "col" to force
264 // wrapping
265 int vcol_off; // offset for concealed characters
266#endif
267#ifdef FEAT_SYN_HL
268 int draw_color_col; // highlight colorcolumn
269 int *color_cols; // pointer to according columns array
270#endif
271 int eol_hl_off; // 1 if highlighted char after EOL
272
273 unsigned off; // offset in ScreenLines/ScreenAttrs
274
275 int win_attr; // background for the whole window, except
276 // margins and "~" lines.
277 int screen_line_flags;
278} winlinevars_T;
279
280/*
281 * Called when finished with the line: draw the screen line and handle any
282 * highlighting until the right of the window.
283 */
284 static void
285draw_screen_line(win_T *wp, winlinevars_T *wlv)
286{
287#ifdef FEAT_SYN_HL
288 long v;
289
290 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
291 if (wp->w_p_wrap)
292 v = wp->w_skipcol;
293 else
294 v = wp->w_leftcol;
295
296 // check if line ends before left margin
297 if (wlv->vcol < v + wlv->col - win_col_off(wp))
298 wlv->vcol = v + wlv->col - win_col_off(wp);
299# ifdef FEAT_CONCEAL
300 // Get rid of the boguscols now, we want to draw until the right
301 // edge for 'cursorcolumn'.
302 wlv->col -= wlv->boguscols;
303 wlv->boguscols = 0;
304# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
305# else
306# define VCOL_HLC (wlv->vcol)
307# endif
308
309 if (wlv->draw_color_col)
310 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
311
312 if (((wp->w_p_cuc
313 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
314 && (int)wp->w_virtcol <
315 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
316 && wlv->lnum != wp->w_cursor.lnum)
317 || wlv->draw_color_col
318 || wlv->win_attr != 0)
319# ifdef FEAT_RIGHTLEFT
320 && !wp->w_p_rl
321# endif
322 )
323 {
324 int rightmost_vcol = 0;
325 int i;
326
327 if (wp->w_p_cuc)
328 rightmost_vcol = wp->w_virtcol;
329 if (wlv->draw_color_col)
330 // determine rightmost colorcolumn to possibly draw
331 for (i = 0; wlv->color_cols[i] >= 0; ++i)
332 if (rightmost_vcol < wlv->color_cols[i])
333 rightmost_vcol = wlv->color_cols[i];
334
335 while (wlv->col < wp->w_width)
336 {
337 ScreenLines[wlv->off] = ' ';
338 if (enc_utf8)
339 ScreenLinesUC[wlv->off] = 0;
340 ScreenCols[wlv->off] = MAXCOL;
341 ++wlv->col;
342 if (wlv->draw_color_col)
343 wlv->draw_color_col = advance_color_col(
344 VCOL_HLC, &wlv->color_cols);
345
346 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
347 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
348 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
349 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
350 else
351 ScreenAttrs[wlv->off++] = wlv->win_attr;
352
353 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
354 break;
355
356 ++wlv->vcol;
357 }
358 }
359#endif
360
361 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
362 wp->w_width, wlv->screen_line_flags);
363 ++wlv->row;
364 ++wlv->screen_row;
365}
366#undef VCOL_HLC
367
368/*
369 * Start a screen line at column zero.
370 */
371 static void
372win_line_start(win_T *wp, winlinevars_T *wlv)
373{
374 wlv->col = 0;
375 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
376
377#ifdef FEAT_RIGHTLEFT
378 if (wp->w_p_rl)
379 {
380 // Rightleft window: process the text in the normal direction, but put
381 // it in current_ScreenLine[] from right to left. Start at the
382 // rightmost column of the window.
383 wlv->col = wp->w_width - 1;
384 wlv->off += wlv->col;
385 wlv->screen_line_flags |= SLF_RIGHTLEFT;
386 }
387#endif
388}
389
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200390/*
391 * Display line "lnum" of window 'wp' on the screen.
392 * Start at row "startrow", stop when "endrow" is reached.
393 * wp->w_virtcol needs to be valid.
394 *
395 * Return the number of last row the line occupies.
396 */
397 int
398win_line(
399 win_T *wp,
400 linenr_T lnum,
401 int startrow,
402 int endrow,
403 int nochange UNUSED, // not updating for changed text
404 int number_only) // only update the number column
405{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100406 winlinevars_T wlv; // variables passed between functions
407
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200408 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200409#ifdef FEAT_LINEBREAK
410 long vcol_sbr = -1; // virtual column after showbreak
411#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100412 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200413 char_u *line; // current line
414 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200415
416 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar09ff4b52022-08-01 16:51:02 +0100417 int n_extra = 0; // number of extra bytes
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200418 char_u *p_extra = NULL; // string of extra chars, plus NUL
419 char_u *p_extra_free = NULL; // p_extra needs to be freed
420 int c_extra = NUL; // extra chars, all the same
421 int c_final = NUL; // final char, mandatory if set
422 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000423#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000424 int in_linebreak = FALSE; // n_extra set for showing linebreak
425#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200426 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100427 // displaying eol at end-of-line
428 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000429 int lcs_prec_todo = wp->w_lcs_chars.prec;
430 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200431
432 // saved "extra" items for when draw_state becomes WL_LINE (again)
433 int saved_n_extra = 0;
434 char_u *saved_p_extra = NULL;
435 int saved_c_extra = 0;
436 int saved_c_final = 0;
437 int saved_char_attr = 0;
438
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100439 int n_attr = 0; // chars with special attr
440 int n_attr_skip = 0; // chars to skip before using extra_attr
441 int saved_attr2 = 0; // char_attr saved for n_attr
442 int n_attr3 = 0; // chars with overruling special attr
443 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200444
445 int n_skip = 0; // nr of chars to skip for 'nowrap'
446
447 int fromcol = -10; // start of inverting
448 int tocol = MAXCOL; // end of inverting
449 int fromcol_prev = -2; // start of inverting after cursor
450 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200451 int lnum_in_visual_area = FALSE;
452 pos_T pos;
453 long v;
454
455 int char_attr = 0; // attributes for next character
456 int attr_pri = FALSE; // char_attr has priority
457 int area_highlighting = FALSE; // Visual or incsearch highlighting
458 // in this line
459 int vi_attr = 0; // attributes for Visual and incsearch
460 // highlighting
461 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200462 int area_attr = 0; // attributes desired by highlighting
463 int search_attr = 0; // attributes desired by 'hlsearch'
464#ifdef FEAT_SYN_HL
465 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
466 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200467 int prev_syntax_col = -1; // column of prev_syntax_attr
468 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200469 int has_syntax = FALSE; // this buffer has syntax highl.
470 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200471#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100472#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200473 int text_prop_count;
474 int text_prop_next = 0; // next text property to use
475 textprop_T *text_props = NULL;
476 int *text_prop_idxs = NULL;
477 int text_props_active = 0;
478 proptype_T *text_prop_type = NULL;
479 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100480 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100481 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100482 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200483#endif
484#ifdef FEAT_SPELL
485 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000486 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200487# define SPWORDLEN 150
488 char_u nextline[SPWORDLEN * 2];// text with start of the next line
489 int nextlinecol = 0; // column where nextline[] starts
490 int nextline_idx = 0; // index in nextline[] where next line
491 // starts
492 int spell_attr = 0; // attributes desired by spelling
493 int word_end = 0; // last byte with same spell_attr
494 static linenr_T checked_lnum = 0; // line number for "checked_col"
495 static int checked_col = 0; // column in "checked_lnum" up to which
496 // there are no spell errors
497 static int cap_col = -1; // column to check for Cap word
498 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
499 int cur_checked_col = 0; // checked column for current line
500#endif
501 int extra_check = 0; // has extra highlighting
502 int multi_attr = 0; // attributes desired by multibyte
503 int mb_l = 1; // multi-byte byte length
504 int mb_c = 0; // decoded multi-byte character
505 int mb_utf8 = FALSE; // screen char is UTF-8 char
506 int u8cc[MAX_MCO]; // composing UTF-8 chars
507#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
508 int filler_lines = 0; // nr of filler lines to be drawn
509 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000510#else
511# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200512#endif
513#ifdef FEAT_DIFF
514 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
515 int change_start = MAXCOL; // first col of changed area
516 int change_end = -1; // last col of changed area
517#endif
518 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100519 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200520 int in_multispace = FALSE; // in multiple consecutive spaces
521 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200522#ifdef FEAT_LINEBREAK
523 int need_showbreak = FALSE; // overlong line, skipping first x
524 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100525 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200526#endif
527#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
528 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
529# define LINE_ATTR
530 int line_attr = 0; // attribute for the whole line
531 int line_attr_save;
532#endif
533#ifdef FEAT_SIGNS
534 int sign_present = FALSE;
535 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000536 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200537#endif
538#ifdef FEAT_ARABIC
539 int prev_c = 0; // previous Arabic character
540 int prev_c1 = 0; // first composing char for prev_c
541#endif
542#if defined(LINE_ATTR)
543 int did_line_attr = 0;
544#endif
545#ifdef FEAT_TERMINAL
546 int get_term_attr = FALSE;
547#endif
548#ifdef FEAT_SYN_HL
549 int cul_attr = 0; // set when 'cursorline' active
550
551 // 'cursorlineopt' has "screenline" and cursor is in this line
552 int cul_screenline = FALSE;
553
554 // margin columns for the screen line, needed for when 'cursorlineopt'
555 // contains "screenline"
556 int left_curline_col = 0;
557 int right_curline_col = 0;
558#endif
559
560 // draw_state: items that are drawn in sequence:
561#define WL_START 0 // nothing done yet
562#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000563# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200564#else
565# define WL_CMDLINE WL_START
566#endif
567#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000568# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200569#else
570# define WL_FOLD WL_CMDLINE
571#endif
572#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000573# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200574#else
575# define WL_SIGN WL_FOLD // column for signs
576#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000577#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200578#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000579# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200580#else
581# define WL_BRI WL_NR
582#endif
583#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000584# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200585#else
586# define WL_SBR WL_BRI
587#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000588#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200589 int draw_state = WL_START; // what to draw next
590#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
591 int feedback_col = 0;
592 int feedback_old_attr = -1;
593#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200594
595#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
596 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000597 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200598#endif
599#ifdef FEAT_CONCEAL
600 int syntax_flags = 0;
601 int syntax_seqnr = 0;
602 int prev_syntax_id = 0;
603 int conceal_attr = HL_ATTR(HLF_CONCEAL);
604 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605 int did_wcol = FALSE;
606 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100607# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200608# define FIX_FOR_BOGUSCOLS \
609 { \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100610 n_extra += wlv.vcol_off; \
611 wlv.vcol -= wlv.vcol_off; \
612 wlv.vcol_off = 0; \
613 wlv.col -= wlv.boguscols; \
614 old_boguscols = wlv.boguscols; \
615 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200616 }
617#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100618# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200619#endif
620
621 if (startrow > endrow) // past the end already!
622 return startrow;
623
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100624 CLEAR_FIELD(wlv);
625
626 wlv.lnum = lnum;
627 wlv.startrow = startrow;
628 wlv.row = startrow;
629 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630
631 if (!number_only)
632 {
633 // To speed up the loop below, set extra_check when there is linebreak,
634 // trailing white space and/or syntax processing to be done.
635#ifdef FEAT_LINEBREAK
636 extra_check = wp->w_p_lbr;
637#endif
638#ifdef FEAT_SYN_HL
639 if (syntax_present(wp) && !wp->w_s->b_syn_error
640# ifdef SYN_TIME_LIMIT
641 && !wp->w_s->b_syn_slow
642# endif
643 )
644 {
645 // Prepare for syntax highlighting in this line. When there is an
646 // error, stop syntax highlighting.
647 save_did_emsg = did_emsg;
648 did_emsg = FALSE;
649 syntax_start(wp, lnum);
650 if (did_emsg)
651 wp->w_s->b_syn_error = TRUE;
652 else
653 {
654 did_emsg = save_did_emsg;
655#ifdef SYN_TIME_LIMIT
656 if (!wp->w_s->b_syn_slow)
657#endif
658 {
659 has_syntax = TRUE;
660 extra_check = TRUE;
661 }
662 }
663 }
664
665 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100666 wlv.color_cols = wp->w_p_cc_cols;
667 if (wlv.color_cols != NULL)
668 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200669#endif
670
671#ifdef FEAT_TERMINAL
672 if (term_show_buffer(wp->w_buffer))
673 {
674 extra_check = TRUE;
675 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100676 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677 }
678#endif
679
680#ifdef FEAT_SPELL
681 if (wp->w_p_spell
682 && *wp->w_s->b_p_spl != NUL
683 && wp->w_s->b_langp.ga_len > 0
684 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
685 {
686 // Prepare for spell checking.
687 has_spell = TRUE;
688 extra_check = TRUE;
689
690 // Get the start of the next line, so that words that wrap to the
691 // next line are found too: "et<line-break>al.".
692 // Trick: skip a few chars for C/shell/Vim comments
693 nextline[SPWORDLEN] = NUL;
694 if (lnum < wp->w_buffer->b_ml.ml_line_count)
695 {
696 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
697 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
698 }
699
700 // When a word wrapped from the previous line the start of the
701 // current line is valid.
702 if (lnum == checked_lnum)
703 cur_checked_col = checked_col;
704 checked_lnum = 0;
705
706 // When there was a sentence end in the previous line may require a
707 // word starting with capital in this line. In line 1 always check
708 // the first word.
709 if (lnum != capcol_lnum)
710 cap_col = -1;
711 if (lnum == 1)
712 cap_col = 0;
713 capcol_lnum = 0;
714 }
715#endif
716
717 // handle Visual active in this window
718 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
719 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100720 pos_T *top, *bot;
721
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200722 if (LTOREQ_POS(curwin->w_cursor, VIsual))
723 {
724 // Visual is after curwin->w_cursor
725 top = &curwin->w_cursor;
726 bot = &VIsual;
727 }
728 else
729 {
730 // Visual is before curwin->w_cursor
731 top = &VIsual;
732 bot = &curwin->w_cursor;
733 }
734 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
735 if (VIsual_mode == Ctrl_V)
736 {
737 // block mode
738 if (lnum_in_visual_area)
739 {
740 fromcol = wp->w_old_cursor_fcol;
741 tocol = wp->w_old_cursor_lcol;
742 }
743 }
744 else
745 {
746 // non-block mode
747 if (lnum > top->lnum && lnum <= bot->lnum)
748 fromcol = 0;
749 else if (lnum == top->lnum)
750 {
751 if (VIsual_mode == 'V') // linewise
752 fromcol = 0;
753 else
754 {
755 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
756 if (gchar_pos(top) == NUL)
757 tocol = fromcol + 1;
758 }
759 }
760 if (VIsual_mode != 'V' && lnum == bot->lnum)
761 {
762 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
763 {
764 fromcol = -10;
765 tocol = MAXCOL;
766 }
767 else if (bot->col == MAXCOL)
768 tocol = MAXCOL;
769 else
770 {
771 pos = *bot;
772 if (*p_sel == 'e')
773 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
774 else
775 {
776 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
777 ++tocol;
778 }
779 }
780 }
781 }
782
783 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200784 if (!highlight_match && lnum == curwin->w_cursor.lnum
785 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200786#ifdef FEAT_GUI
787 && !gui.in_use
788#endif
789 )
790 noinvcur = TRUE;
791
792 // if inverting in this line set area_highlighting
793 if (fromcol >= 0)
794 {
795 area_highlighting = TRUE;
796 vi_attr = HL_ATTR(HLF_V);
797#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
798 if ((clip_star.available && !clip_star.owned
799 && clip_isautosel_star())
800 || (clip_plus.available && !clip_plus.owned
801 && clip_isautosel_plus()))
802 vi_attr = HL_ATTR(HLF_VNC);
803#endif
804 }
805 }
806
807 // handle 'incsearch' and ":s///c" highlighting
808 else if (highlight_match
809 && wp == curwin
810 && lnum >= curwin->w_cursor.lnum
811 && lnum <= curwin->w_cursor.lnum + search_match_lines)
812 {
813 if (lnum == curwin->w_cursor.lnum)
814 getvcol(curwin, &(curwin->w_cursor),
815 (colnr_T *)&fromcol, NULL, NULL);
816 else
817 fromcol = 0;
818 if (lnum == curwin->w_cursor.lnum + search_match_lines)
819 {
820 pos.lnum = lnum;
821 pos.col = search_match_endcol;
822 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
823 }
824 else
825 tocol = MAXCOL;
826 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100827 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828 tocol = fromcol + 1;
829 area_highlighting = TRUE;
830 vi_attr = HL_ATTR(HLF_I);
831 }
832 }
833
834#ifdef FEAT_DIFF
835 filler_lines = diff_check(wp, lnum);
836 if (filler_lines < 0)
837 {
838 if (filler_lines == -1)
839 {
840 if (diff_find_change(wp, lnum, &change_start, &change_end))
841 diff_hlf = HLF_ADD; // added line
842 else if (change_start == 0)
843 diff_hlf = HLF_TXD; // changed text
844 else
845 diff_hlf = HLF_CHD; // changed line
846 }
847 else
848 diff_hlf = HLF_ADD; // added line
849 filler_lines = 0;
850 area_highlighting = TRUE;
851 }
852 if (lnum == wp->w_topline)
853 filler_lines = wp->w_topfill;
854 filler_todo = filler_lines;
855#endif
856
857#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100858 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000859 if (sign_present)
860 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200861#endif
862
863#ifdef LINE_ATTR
864# ifdef FEAT_SIGNS
865 // If this line has a sign with line highlighting set line_attr.
866 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200867 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200868# endif
869# if defined(FEAT_QUICKFIX)
870 // Highlight the current line in the quickfix window.
871 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
872 line_attr = HL_ATTR(HLF_QFL);
873# endif
874 if (line_attr != 0)
875 area_highlighting = TRUE;
876#endif
877
878 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
879 ptr = line;
880
881#ifdef FEAT_SPELL
882 if (has_spell && !number_only)
883 {
884 // For checking first word with a capital skip white space.
885 if (cap_col == 0)
886 cap_col = getwhitecols(line);
887
888 // To be able to spell-check over line boundaries copy the end of the
889 // current line into nextline[]. Above the start of the next line was
890 // copied to nextline[SPWORDLEN].
891 if (nextline[SPWORDLEN] == NUL)
892 {
893 // No next line or it is empty.
894 nextlinecol = MAXCOL;
895 nextline_idx = 0;
896 }
897 else
898 {
899 v = (long)STRLEN(line);
900 if (v < SPWORDLEN)
901 {
902 // Short line, use it completely and append the start of the
903 // next line.
904 nextlinecol = 0;
905 mch_memmove(nextline, line, (size_t)v);
906 STRMOVE(nextline + v, nextline + SPWORDLEN);
907 nextline_idx = v + 1;
908 }
909 else
910 {
911 // Long line, use only the last SPWORDLEN bytes.
912 nextlinecol = v - SPWORDLEN;
913 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
914 nextline_idx = SPWORDLEN + 1;
915 }
916 }
917 }
918#endif
919
920 if (wp->w_p_list)
921 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100922 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200923 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100924 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100925 || wp->w_lcs_chars.trail
926 || wp->w_lcs_chars.lead
927 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200928 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100929
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200930 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100931 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200932 {
933 trailcol = (colnr_T)STRLEN(ptr);
934 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
935 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100936 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100938 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100939 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100940 {
941 leadcol = 0;
942 while (VIM_ISWHITE(ptr[leadcol]))
943 ++leadcol;
944 if (ptr[leadcol] == NUL)
945 // in a line full of spaces all of them are treated as trailing
946 leadcol = (colnr_T)0;
947 else
948 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100949 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100950 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200951 }
952
953 wcr_attr = get_wcr_attr(wp);
954 if (wcr_attr != 0)
955 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100956 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 area_highlighting = TRUE;
958 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200959
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100960#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200961 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100962 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200963#endif
964
965 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
966 // first character to be displayed.
967 if (wp->w_p_wrap)
968 v = wp->w_skipcol;
969 else
970 v = wp->w_leftcol;
971 if (v > 0 && !number_only)
972 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100973 char_u *prev_ptr = ptr;
974 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +0100975 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100977 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100978 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100980 charsize = win_lbr_chartabsize(&cts, NULL);
981 cts.cts_vcol += charsize;
982 prev_ptr = cts.cts_ptr;
983 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100985 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100986 ptr = cts.cts_ptr;
987 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988
989 // When:
990 // - 'cuc' is set, or
991 // - 'colorcolumn' is set, or
992 // - 'virtualedit' is set, or
993 // - the visual mode is active,
994 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100995 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200996#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100997 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998#endif
999 virtual_active() ||
1000 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001001 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002
1003 // Handle a character that's not completely on the screen: Put ptr at
1004 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001005 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001007 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 ptr = prev_ptr;
1009 // If the character fits on the screen, don't need to skip it.
1010 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001011 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1012 && wlv.col == 0)
1013 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014 }
1015
1016 // Adjust for when the inverted text is before the screen,
1017 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001018 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001020 else if (fromcol >= 0 && fromcol < wlv.vcol)
1021 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022
1023#ifdef FEAT_LINEBREAK
1024 // When w_skipcol is non-zero, first line needs 'showbreak'
1025 if (wp->w_p_wrap)
1026 need_showbreak = TRUE;
1027#endif
1028#ifdef FEAT_SPELL
1029 // When spell checking a word we need to figure out the start of the
1030 // word and if it's badly spelled or not.
1031 if (has_spell)
1032 {
1033 int len;
1034 colnr_T linecol = (colnr_T)(ptr - line);
1035 hlf_T spell_hlf = HLF_COUNT;
1036
1037 pos = wp->w_cursor;
1038 wp->w_cursor.lnum = lnum;
1039 wp->w_cursor.col = linecol;
1040 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1041
1042 // spell_move_to() may call ml_get() and make "line" invalid
1043 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1044 ptr = line + linecol;
1045
1046 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1047 {
1048 // no bad word found at line start, don't check until end of a
1049 // word
1050 spell_hlf = HLF_COUNT;
1051 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1052 }
1053 else
1054 {
1055 // bad word found, use attributes until end of word
1056 word_end = wp->w_cursor.col + len + 1;
1057
1058 // Turn index into actual attributes.
1059 if (spell_hlf != HLF_COUNT)
1060 spell_attr = highlight_attr[spell_hlf];
1061 }
1062 wp->w_cursor = pos;
1063
1064# ifdef FEAT_SYN_HL
1065 // Need to restart syntax highlighting for this line.
1066 if (has_syntax)
1067 syntax_start(wp, lnum);
1068# endif
1069 }
1070#endif
1071 }
1072
1073 // Correct highlighting for cursor that can't be disabled.
1074 // Avoids having to check this for each character.
1075 if (fromcol >= 0)
1076 {
1077 if (noinvcur)
1078 {
1079 if ((colnr_T)fromcol == wp->w_virtcol)
1080 {
1081 // highlighting starts at cursor, let it start just after the
1082 // cursor
1083 fromcol_prev = fromcol;
1084 fromcol = -1;
1085 }
1086 else if ((colnr_T)fromcol < wp->w_virtcol)
1087 // restart highlighting after the cursor
1088 fromcol_prev = wp->w_virtcol;
1089 }
1090 if (fromcol >= tocol)
1091 fromcol = -1;
1092 }
1093
1094#ifdef FEAT_SEARCH_EXTRA
1095 if (!number_only)
1096 {
1097 v = (long)(ptr - line);
1098 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1099 &line, &screen_search_hl,
1100 &search_attr);
1101 ptr = line + v; // "line" may have been updated
1102 }
1103#endif
1104
1105#ifdef FEAT_SYN_HL
1106 // Cursor line highlighting for 'cursorline' in the current window.
1107 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1108 {
1109 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001110 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 if (!(wp == curwin && VIsual_active)
1112 && wp->w_p_culopt_flags != CULOPT_NBR)
1113 {
1114 cul_screenline = (wp->w_p_wrap
1115 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1116
1117 // Only set line_attr here when "screenline" is not present in
1118 // 'cursorlineopt'. Otherwise it's done later.
1119 if (!cul_screenline)
1120 {
1121 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001122# ifdef FEAT_SIGNS
1123 // Combine the 'cursorline' and sign highlighting, depending on
1124 // the sign priority.
1125 if (sign_present && sattr.sat_linehl > 0)
1126 {
1127 if (sattr.sat_priority >= 100)
1128 line_attr = hl_combine_attr(cul_attr, line_attr);
1129 else
1130 line_attr = hl_combine_attr(line_attr, cul_attr);
1131 }
1132 else
1133# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001134# if defined(FEAT_QUICKFIX)
1135 line_attr = hl_combine_attr(line_attr, cul_attr);
1136# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001137 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001138# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 }
1140 else
1141 {
1142 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1144 }
1145 area_highlighting = TRUE;
1146 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 }
1148#endif
1149
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001150#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 {
1152 char_u *prop_start;
1153
1154 text_prop_count = get_text_props(wp->w_buffer, lnum,
1155 &prop_start, FALSE);
1156 if (text_prop_count > 0)
1157 {
1158 // Make a copy of the properties, so that they are properly
1159 // aligned.
1160 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1161 if (text_props != NULL)
1162 mch_memmove(text_props, prop_start,
1163 text_prop_count * sizeof(textprop_T));
1164
1165 // Allocate an array for the indexes.
1166 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1167 area_highlighting = TRUE;
1168 extra_check = TRUE;
1169 }
1170 }
1171#endif
1172
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001173 win_line_start(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174
1175 // Repeat for the whole displayed line.
1176 for (;;)
1177 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001178 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001180 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181#endif
1182#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001183 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001185
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 // Skip this quickly when working on the text.
1187 if (draw_state != WL_LINE)
1188 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001189#ifdef FEAT_SYN_HL
1190 if (cul_screenline)
1191 {
1192 cul_attr = 0;
1193 line_attr = line_attr_save;
1194 }
1195#endif
1196
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197#ifdef FEAT_CMDWIN
1198 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1199 {
1200 draw_state = WL_CMDLINE;
1201 if (cmdwin_type != 0 && wp == curwin)
1202 {
1203 // Draw the cmdline character.
1204 n_extra = 1;
1205 c_extra = cmdwin_type;
1206 c_final = NUL;
1207 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1208 }
1209 }
1210#endif
1211
1212#ifdef FEAT_FOLDING
1213 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1214 {
1215 int fdc = compute_foldcolumn(wp, 0);
1216
1217 draw_state = WL_FOLD;
1218 if (fdc > 0)
1219 {
1220 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1221 // already be in use.
1222 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001223 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 if (p_extra_free != NULL)
1225 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001226 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001227 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 p_extra_free[n_extra] = NUL;
1229 p_extra = p_extra_free;
1230 c_extra = NUL;
1231 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001232 if (use_cursor_line_sign(wp, lnum))
1233 char_attr =
1234 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1235 else
1236 char_attr =
1237 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 }
1239 }
1240 }
1241#endif
1242
1243#ifdef FEAT_SIGNS
1244 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1245 {
1246 draw_state = WL_SIGN;
1247 // Show the sign column when there are any signs in this
1248 // buffer or when using Netbeans.
1249 if (signcolumn_on(wp))
1250 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001251 wlv.row, startrow, filler_lines, filler_todo,
1252 &c_extra, &c_final, extra, &p_extra, &n_extra,
1253 &char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 }
1255#endif
1256
1257 if (draw_state == WL_NR - 1 && n_extra == 0)
1258 {
1259 draw_state = WL_NR;
1260 // Display the absolute or relative line number. After the
1261 // first fill with blanks when the 'n' flag isn't in 'cpo'
1262 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001263 && (wlv.row == startrow + filler_lines
1264 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 {
1266#ifdef FEAT_SIGNS
1267 // If 'signcolumn' is set to 'number' and a sign is present
1268 // in 'lnum', then display the sign instead of the line
1269 // number.
1270 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1271 && sign_present)
1272 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001273 wlv.row, startrow, filler_lines, filler_todo,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 &c_extra, &c_final, extra, &p_extra, &n_extra,
1275 &char_attr);
1276 else
1277#endif
1278 {
1279 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001280 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281 {
1282 long num;
1283 char *fmt = "%*ld ";
1284
1285 if (wp->w_p_nu && !wp->w_p_rnu)
1286 // 'number' + 'norelativenumber'
1287 num = (long)lnum;
1288 else
1289 {
1290 // 'relativenumber', don't use negative numbers
1291 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1292 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1293 {
1294 // 'number' + 'relativenumber'
1295 num = lnum;
1296 fmt = "%-*ld ";
1297 }
1298 }
1299
1300 sprintf((char *)extra, fmt,
1301 number_width(wp), num);
1302 if (wp->w_skipcol > 0)
1303 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1304 *p_extra = '-';
1305#ifdef FEAT_RIGHTLEFT
1306 if (wp->w_p_rl) // reverse line numbers
1307 {
1308 char_u *p1, *p2;
1309 int t;
1310
1311 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001312 p2 = skipwhite(extra);
1313 p2 = skiptowhite(p2) - 1;
1314 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 {
1316 t = *p1;
1317 *p1 = *p2;
1318 *p2 = t;
1319 }
1320 }
1321#endif
1322 p_extra = extra;
1323 c_extra = NUL;
1324 c_final = NUL;
1325 }
1326 else
1327 {
1328 c_extra = ' ';
1329 c_final = NUL;
1330 }
1331 n_extra = number_width(wp) + 1;
1332 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1333#ifdef FEAT_SYN_HL
1334 // When 'cursorline' is set highlight the line number of
1335 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001336 // When 'cursorlineopt' does not have "line" only
1337 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 // TODO: Can we use CursorLine instead of CursorLineNr
1339 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001340 if (wp->w_p_cul
1341 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001343 && (wlv.row == startrow + filler_lines
1344 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001345 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1347#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001348 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1349 && HL_ATTR(HLF_LNA) != 0)
1350 // Use LineNrAbove
1351 char_attr = hl_combine_attr(wcr_attr,
1352 HL_ATTR(HLF_LNA));
1353 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1354 && HL_ATTR(HLF_LNB) != 0)
1355 // Use LineNrBelow
1356 char_attr = hl_combine_attr(wcr_attr,
1357 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 }
James McCoya80aad72021-12-22 19:45:28 +00001359#ifdef FEAT_SIGNS
1360 if (num_attr)
1361 char_attr = num_attr;
1362#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 }
1364 }
1365
1366#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001367 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001368 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 // draw indent after showbreak value
1370 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001371 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 // After the showbreak, draw the breakindent
1373 draw_state = WL_BRI - 1;
1374
1375 // draw 'breakindent': indent wrapped text accordingly
1376 if (draw_state == WL_BRI - 1 && n_extra == 0)
1377 {
1378 draw_state = WL_BRI;
1379 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001380 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381# ifdef FEAT_DIFF
1382 && filler_lines == 0
1383# endif
1384 )
1385 {
1386 char_attr = 0;
1387# ifdef FEAT_DIFF
1388 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390# endif
1391 p_extra = NULL;
1392 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001393 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 n_extra = get_breakindent_win(wp,
1395 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001396 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001397 {
1398 n_extra -= win_col_off2(wp);
1399 if (n_extra < 0)
1400 n_extra = 0;
1401 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001402 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001403 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 // Correct end of highlighted area for 'breakindent',
1405 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001406 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 tocol += n_extra;
1408 }
1409 }
1410#endif
1411
1412#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1413 if (draw_state == WL_SBR - 1 && n_extra == 0)
1414 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001415 char_u *sbr;
1416
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 draw_state = WL_SBR;
1418# ifdef FEAT_DIFF
1419 if (filler_todo > 0)
1420 {
1421 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001422 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
1424 c_extra = '-';
1425 c_final = NUL;
1426 }
1427 else
1428 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001429 c_extra = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 c_final = NUL;
1431 }
1432# ifdef FEAT_RIGHTLEFT
1433 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001434 n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 else
1436# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001437 n_extra = wp->w_width - wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 char_attr = HL_ATTR(HLF_DED);
1439 }
1440# endif
1441# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001442 sbr = get_showbreak_value(wp);
1443 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 {
1445 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001446 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447 c_extra = NUL;
1448 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001449 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001450 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1451 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001452 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 // Correct end of highlighted area for 'showbreak',
1454 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001455 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 tocol += n_extra;
1457 // combine 'showbreak' with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001458 char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459# ifdef FEAT_SYN_HL
1460 // combine 'showbreak' with 'cursorline'
1461 if (cul_attr != 0)
1462 char_attr = hl_combine_attr(char_attr, cul_attr);
1463# endif
1464 }
1465# endif
1466 }
1467#endif
1468
1469 if (draw_state == WL_LINE - 1 && n_extra == 0)
1470 {
1471 draw_state = WL_LINE;
1472 if (saved_n_extra)
1473 {
1474 // Continue item from end of wrapped line.
1475 n_extra = saved_n_extra;
1476 c_extra = saved_c_extra;
1477 c_final = saved_c_final;
1478 p_extra = saved_p_extra;
1479 char_attr = saved_char_attr;
1480 }
1481 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001482 char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
1484 }
1485#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001486 if (cul_screenline && draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001487 && wlv.vcol >= left_curline_col
1488 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001490 cul_attr = HL_ATTR(HLF_CUL);
1491 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 }
1493#endif
1494
1495 // When still displaying '$' of change command, stop at cursor.
1496 // When only displaying the (relative) line number and that's done,
1497 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001498 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001499 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar511feec2020-06-18 19:15:27 +02001500 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501#ifdef FEAT_DIFF
1502 && filler_todo <= 0
1503#endif
1504 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1507 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 // Pretend we have finished updating the window. Except when
1509 // 'cursorcolumn' is set.
1510#ifdef FEAT_SYN_HL
1511 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001512 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 else
1514#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001515 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516 break;
1517 }
1518
Bram Moolenaar34390282019-10-16 14:38:26 +02001519 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 {
1521 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001522 if (wlv.vcol == fromcol
1523 || (has_mbyte && wlv.vcol + 1 == fromcol && n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 && (*mb_ptr2cells)(ptr) > 1)
1525 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001526 && vcol_prev < wlv.vcol // not at margin
1527 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 area_attr = vi_attr; // start highlighting
1529 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001530 && (wlv.vcol == tocol
1531 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 area_attr = 0; // stop highlighting
1533
1534#ifdef FEAT_SEARCH_EXTRA
1535 if (!n_extra)
1536 {
1537 // Check for start/end of 'hlsearch' and other matches.
1538 // After end, check for start/end of next match.
1539 // When another match, have to check for start again.
1540 v = (long)(ptr - line);
1541 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1542 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001543 &match_conc, did_line_attr, lcs_eol_one,
1544 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001546 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001547
1548 // Do not allow a conceal over EOL otherwise EOL will be missed
1549 // and bad things happen.
1550 if (*ptr == NUL)
1551 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 }
1553#endif
1554
1555#ifdef FEAT_DIFF
1556 if (diff_hlf != (hlf_T)0)
1557 {
1558 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1559 && n_extra == 0)
1560 diff_hlf = HLF_TXD; // changed text
1561 if (diff_hlf == HLF_TXD && ptr - line > change_end
1562 && n_extra == 0)
1563 diff_hlf = HLF_CHD; // changed line
1564 line_attr = HL_ATTR(diff_hlf);
1565 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1566 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001567 && (!cul_screenline || (wlv.vcol >= left_curline_col
1568 && wlv.vcol <= right_curline_col)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 line_attr = hl_combine_attr(
1570 line_attr, HL_ATTR(HLF_CUL));
1571 }
1572#endif
1573
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001574#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 if (text_props != NULL)
1576 {
1577 int pi;
1578 int bcol = (int)(ptr - line);
1579
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001580 if (n_extra > 0
1581# ifdef FEAT_LINEBREAK
1582 && !in_linebreak
1583# endif
1584 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 --bcol; // still working on the previous char, e.g. Tab
1586
1587 // Check if any active property ends.
1588 for (pi = 0; pi < text_props_active; ++pi)
1589 {
1590 int tpi = text_prop_idxs[pi];
1591
1592 if (bcol >= text_props[tpi].tp_col - 1
1593 + text_props[tpi].tp_len)
1594 {
1595 if (pi + 1 < text_props_active)
1596 mch_memmove(text_prop_idxs + pi,
1597 text_prop_idxs + pi + 1,
1598 sizeof(int)
1599 * (text_props_active - (pi + 1)));
1600 --text_props_active;
1601 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001602# ifdef FEAT_LINEBREAK
1603 // not exactly right but should work in most cases
1604 if (in_linebreak && syntax_attr == text_prop_attr)
1605 syntax_attr = 0;
1606# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001607 }
1608 }
1609
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001610# ifdef FEAT_LINEBREAK
1611 if (n_extra > 0 && in_linebreak)
1612 // not on the next char yet, don't start another prop
1613 --bcol;
1614# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 // Add any text property that starts in this column.
1616 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001617 && (text_props[text_prop_next].tp_col == MAXCOL
1618 ? *ptr == NUL
1619 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001620 {
1621 if (bcol <= text_props[text_prop_next].tp_col - 1
1622 + text_props[text_prop_next].tp_len)
1623 text_prop_idxs[text_props_active++] = text_prop_next;
1624 ++text_prop_next;
1625 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626
1627 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001628 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001629 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001630 text_prop_id = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001631 if (text_props_active > 0 && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001633 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001634 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001635 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001636
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 // Sort the properties on priority and/or starting last.
1638 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001639 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640 current_text_props = text_props;
1641 current_buf = wp->w_buffer;
1642 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1643 sizeof(int), text_prop_compare);
1644
1645 for (pi = 0; pi < text_props_active; ++pi)
1646 {
1647 int tpi = text_prop_idxs[pi];
1648 proptype_T *pt = text_prop_type_by_id(
1649 wp->w_buffer, text_props[tpi].tp_type);
1650
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001651 if (pt != NULL && pt->pt_hl_id > 0
1652 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001653 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001654 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 text_prop_type = pt;
1656 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001657 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001658 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001659 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001660 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001661 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 }
1663 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001664 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001665 && -text_prop_id
1666 <= wp->w_buffer->b_textprop_text.ga_len)
1667 {
1668 char_u *p = ((char_u **)wp->w_buffer
1669 ->b_textprop_text.ga_data)[
1670 -text_prop_id - 1];
1671 if (p != NULL)
1672 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001673 int right = (text_props[used_tpi].tp_flags
1674 & TP_FLAG_ALIGN_RIGHT);
1675 int below = (text_props[used_tpi].tp_flags
1676 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001677 int wrap = (text_props[used_tpi].tp_flags
1678 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001679
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001680 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001681 c_extra = NUL;
1682 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001683 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001684 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001685 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001686 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001687 if (*ptr == NUL)
1688 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001689 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001690#ifdef FEAT_LINEBREAK
1691 if (below || right)
1692 {
1693 // no 'showbreak' before "below" text property
1694 // or after "right" text property
1695 need_showbreak = FALSE;
1696 dont_use_showbreak = TRUE;
1697 }
1698#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001699 // Keep in sync with where
1700 // textprop_size_after_trunc() is called in
1701 // win_lbr_chartabsize().
1702 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001703 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001704 int added = wp->w_width - wlv.col;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001705 int n_used = n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001706 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001707 int strsize = wrap
1708 ? vim_strsize(p_extra)
1709 : textprop_size_after_trunc(wp,
1710 below, added, p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001711
Bram Moolenaar398649e2022-08-04 15:03:48 +01001712 if (wrap || right || below || n_used < n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001713 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001714 // Right-align: fill with spaces
1715 if (right)
1716 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001717 if (added < 0
1718 || (below
1719 ? wlv.col == 0 || !wp->w_p_wrap
1720 : n_used < n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001721 added = 0;
1722 // add 1 for NUL, 2 for when '…' is used
1723 l = alloc(n_used + added + 3);
1724 if (l != NULL)
1725 {
1726 vim_memset(l, ' ', added);
1727 vim_strncpy(l + added, p_extra, n_used);
1728 if (n_used < n_extra)
1729 {
1730 char_u *lp = l + added + n_used - 1;
1731
1732 if (has_mbyte)
1733 {
1734 // change last character to '…'
1735 lp -= (*mb_head_off)(l, lp);
1736 STRCPY(lp, "…");
1737 n_used = lp - l + 3;
1738 }
1739 else
1740 // change last character to '>'
1741 *lp = '>';
1742 }
1743 vim_free(p_extra_free);
1744 p_extra = p_extra_free = l;
1745 n_extra = n_used + added;
1746 n_attr_skip = added;
1747 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001748 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749
1750 // When 'wrap' is off then for "below" we need
1751 // to start a new line explictly.
1752 if (!wp->w_p_wrap)
1753 {
1754 draw_screen_line(wp, &wlv);
1755
1756 // When line got too long for screen break
1757 // here.
1758 if (wlv.row == endrow)
1759 {
1760 ++wlv.row;
1761 break;
1762 }
1763 win_line_start(wp, &wlv);
1764 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001765 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001766 }
1767 // reset the ID in the copy to avoid it being used
1768 // again
1769 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001770
1771 // If another text prop follows the condition below at
1772 // the last window column must know.
1773 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001774 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001776 else if (text_prop_next < text_prop_count
1777 && text_props[text_prop_next].tp_col == MAXCOL
1778 && *ptr != NUL
1779 && ptr[mb_ptr2len(ptr)] == NUL)
1780 // When at last-but-one character and a text property
1781 // follows after it, we may need to flush the line after
1782 // displaying that character.
1783 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784 }
1785#endif
1786
Bram Moolenaara74fda62019-10-19 17:38:03 +02001787#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001788 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001789 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001790 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001791# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001792 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001793 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001794# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001795 // Get syntax attribute.
1796 if (has_syntax)
1797 {
1798 // Get the syntax attribute for the character. If there
1799 // is an error, disable syntax highlighting.
1800 save_did_emsg = did_emsg;
1801 did_emsg = FALSE;
1802
1803 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001804 if (v == prev_syntax_col)
1805 // at same column again
1806 syntax_attr = prev_syntax_attr;
1807 else
1808 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001809# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001810 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001811# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001812 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001813# ifdef FEAT_SPELL
1814 has_spell ? &can_spell :
1815# endif
1816 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001817 prev_syntax_col = v;
1818 prev_syntax_attr = syntax_attr;
1819 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001820
Bram Moolenaar34390282019-10-16 14:38:26 +02001821 if (did_emsg)
1822 {
1823 wp->w_s->b_syn_error = TRUE;
1824 has_syntax = FALSE;
1825 syntax_attr = 0;
1826 }
1827 else
1828 did_emsg = save_did_emsg;
1829# ifdef SYN_TIME_LIMIT
1830 if (wp->w_s->b_syn_slow)
1831 has_syntax = FALSE;
1832# endif
1833
1834 // Need to get the line again, a multi-line regexp may
1835 // have made it invalid.
1836 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1837 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001838 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001839# ifdef FEAT_CONCEAL
1840 // no concealing past the end of the line, it interferes
1841 // with line highlighting
1842 if (*ptr == NUL)
1843 syntax_flags = 0;
1844 else
1845 syntax_flags = get_syntax_info(&syntax_seqnr);
1846# endif
1847 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001848 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001849# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001850 // Combine text property highlight into syntax highlight.
1851 if (text_prop_type != NULL)
1852 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001853 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001854 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1855 else
1856 syntax_attr = text_prop_attr;
1857 }
1858# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001859#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001860
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 // Decide which of the highlight attributes to use.
1862 attr_pri = TRUE;
1863#ifdef LINE_ATTR
1864 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001865 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001867 if (!highlight_match)
1868 // let search highlight show in Visual area if possible
1869 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001870# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001871 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001872# endif
1873 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001875 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001877# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001878 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001879# endif
1880 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001882 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1883 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
1885 // Use line_attr when not in the Visual or 'incsearch' area
1886 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001887# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001888 char_attr = hl_combine_attr(syntax_attr, line_attr);
1889# else
1890 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001891# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 attr_pri = FALSE;
1893 }
1894#else
1895 if (area_attr != 0)
1896 char_attr = area_attr;
1897 else if (search_attr != 0)
1898 char_attr = search_attr;
1899#endif
1900 else
1901 {
1902 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001904 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001905#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001906 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001907#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001909#ifdef FEAT_PROP_POPUP
1910 // override with text property highlight when "override" is TRUE
1911 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
1912 char_attr = hl_combine_attr(char_attr, text_prop_attr);
1913#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001915
1916 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001917 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001918 {
1919 if (char_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001920 char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001921 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001922 char_attr = hl_combine_attr(wlv.win_attr, char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001923 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924
1925 // Get the next character to put on the screen.
1926
1927 // The "p_extra" points to the extra stuff that is inserted to
1928 // represent special characters (non-printable stuff) and other
1929 // things. When all characters are the same, c_extra is used.
1930 // If c_final is set, it will compulsorily be used at the end.
1931 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1932 // "p_extra[n_extra]".
1933 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1934 if (n_extra > 0)
1935 {
1936 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1937 {
1938 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1939 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1940 if (enc_utf8 && utf_char2len(c) > 1)
1941 {
1942 mb_utf8 = TRUE;
1943 u8cc[0] = 0;
1944 c = 0xc0;
1945 }
1946 else
1947 mb_utf8 = FALSE;
1948 }
1949 else
1950 {
1951 c = *p_extra;
1952 if (has_mbyte)
1953 {
1954 mb_c = c;
1955 if (enc_utf8)
1956 {
1957 // If the UTF-8 character is more than one byte:
1958 // Decode it into "mb_c".
1959 mb_l = utfc_ptr2len(p_extra);
1960 mb_utf8 = FALSE;
1961 if (mb_l > n_extra)
1962 mb_l = 1;
1963 else if (mb_l > 1)
1964 {
1965 mb_c = utfc_ptr2char(p_extra, u8cc);
1966 mb_utf8 = TRUE;
1967 c = 0xc0;
1968 }
1969 }
1970 else
1971 {
1972 // if this is a DBCS character, put it in "mb_c"
1973 mb_l = MB_BYTE2LEN(c);
1974 if (mb_l >= n_extra)
1975 mb_l = 1;
1976 else if (mb_l > 1)
1977 mb_c = (c << 8) + p_extra[1];
1978 }
1979 if (mb_l == 0) // at the NUL at end-of-line
1980 mb_l = 1;
1981
1982 // If a double-width char doesn't fit display a '>' in the
1983 // last column.
1984 if ((
1985# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001986 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001988 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 && (*mb_char2cells)(mb_c) == 2)
1990 {
1991 c = '>';
1992 mb_c = c;
1993 mb_l = 1;
1994 mb_utf8 = FALSE;
1995 multi_attr = HL_ATTR(HLF_AT);
1996#ifdef FEAT_SYN_HL
1997 if (cul_attr)
1998 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1999#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002000 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002001
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 // put the pointer back to output the double-width
2003 // character at the start of the next line.
2004 ++n_extra;
2005 --p_extra;
2006 }
2007 else
2008 {
2009 n_extra -= mb_l - 1;
2010 p_extra += mb_l - 1;
2011 }
2012 }
2013 ++p_extra;
2014 }
2015 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002016#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002017 if (n_extra <= 0)
2018 in_linebreak = FALSE;
2019#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020 }
2021 else
2022 {
2023#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002024 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01002026 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01002027 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 // Get a character from the line itself.
2030 c = *ptr;
2031#ifdef FEAT_LINEBREAK
2032 c0 = *ptr;
2033#endif
2034 if (has_mbyte)
2035 {
2036 mb_c = c;
2037 if (enc_utf8)
2038 {
2039 // If the UTF-8 character is more than one byte: Decode it
2040 // into "mb_c".
2041 mb_l = utfc_ptr2len(ptr);
2042 mb_utf8 = FALSE;
2043 if (mb_l > 1)
2044 {
2045 mb_c = utfc_ptr2char(ptr, u8cc);
2046 // Overlong encoded ASCII or ASCII with composing char
2047 // is displayed normally, except a NUL.
2048 if (mb_c < 0x80)
2049 {
2050 c = mb_c;
2051#ifdef FEAT_LINEBREAK
2052 c0 = mb_c;
2053#endif
2054 }
2055 mb_utf8 = TRUE;
2056
2057 // At start of the line we can have a composing char.
2058 // Draw it as a space with a composing char.
2059 if (utf_iscomposing(mb_c))
2060 {
2061 int i;
2062
2063 for (i = Screen_mco - 1; i > 0; --i)
2064 u8cc[i] = u8cc[i - 1];
2065 u8cc[0] = mb_c;
2066 mb_c = ' ';
2067 }
2068 }
2069
2070 if ((mb_l == 1 && c >= 0x80)
2071 || (mb_l >= 1 && mb_c == 0)
2072 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2073 {
2074 // Illegal UTF-8 byte: display as <xx>.
2075 // Non-BMP character : display as ? or fullwidth ?.
2076 transchar_hex(extra, mb_c);
2077# ifdef FEAT_RIGHTLEFT
2078 if (wp->w_p_rl) // reverse
2079 rl_mirror(extra);
2080# endif
2081 p_extra = extra;
2082 c = *p_extra;
2083 mb_c = mb_ptr2char_adv(&p_extra);
2084 mb_utf8 = (c >= 0x80);
2085 n_extra = (int)STRLEN(p_extra);
2086 c_extra = NUL;
2087 c_final = NUL;
2088 if (area_attr == 0 && search_attr == 0)
2089 {
2090 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002091 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002092 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 saved_attr2 = char_attr; // save current attr
2094 }
2095 }
2096 else if (mb_l == 0) // at the NUL at end-of-line
2097 mb_l = 1;
2098#ifdef FEAT_ARABIC
2099 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2100 {
2101 // Do Arabic shaping.
2102 int pc, pc1, nc;
2103 int pcc[MAX_MCO];
2104
2105 // The idea of what is the previous and next
2106 // character depends on 'rightleft'.
2107 if (wp->w_p_rl)
2108 {
2109 pc = prev_c;
2110 pc1 = prev_c1;
2111 nc = utf_ptr2char(ptr + mb_l);
2112 prev_c1 = u8cc[0];
2113 }
2114 else
2115 {
2116 pc = utfc_ptr2char(ptr + mb_l, pcc);
2117 nc = prev_c;
2118 pc1 = pcc[0];
2119 }
2120 prev_c = mb_c;
2121
2122 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2123 }
2124 else
2125 prev_c = mb_c;
2126#endif
2127 }
2128 else // enc_dbcs
2129 {
2130 mb_l = MB_BYTE2LEN(c);
2131 if (mb_l == 0) // at the NUL at end-of-line
2132 mb_l = 1;
2133 else if (mb_l > 1)
2134 {
2135 // We assume a second byte below 32 is illegal.
2136 // Hopefully this is OK for all double-byte encodings!
2137 if (ptr[1] >= 32)
2138 mb_c = (c << 8) + ptr[1];
2139 else
2140 {
2141 if (ptr[1] == NUL)
2142 {
2143 // head byte at end of line
2144 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002145 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 }
2147 else
2148 {
2149 // illegal tail byte
2150 mb_l = 2;
2151 STRCPY(extra, "XX");
2152 }
2153 p_extra = extra;
2154 n_extra = (int)STRLEN(extra) - 1;
2155 c_extra = NUL;
2156 c_final = NUL;
2157 c = *p_extra++;
2158 if (area_attr == 0 && search_attr == 0)
2159 {
2160 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002161 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002162 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 saved_attr2 = char_attr; // save current attr
2164 }
2165 mb_c = c;
2166 }
2167 }
2168 }
2169 // If a double-width char doesn't fit display a '>' in the
2170 // last column; the character is displayed at the start of the
2171 // next line.
2172 if ((
2173# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002174 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002175# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002176 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 && (*mb_char2cells)(mb_c) == 2)
2178 {
2179 c = '>';
2180 mb_c = c;
2181 mb_utf8 = FALSE;
2182 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002183 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 // Put pointer back so that the character will be
2185 // displayed at the start of the next line.
2186 --ptr;
2187#ifdef FEAT_CONCEAL
2188 did_decrement_ptr = TRUE;
2189#endif
2190 }
2191 else if (*ptr != NUL)
2192 ptr += mb_l - 1;
2193
2194 // If a double-width char doesn't fit at the left side display
2195 // a '<' in the first column. Don't do this for unprintable
2196 // characters.
2197 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2198 {
2199 n_extra = 1;
2200 c_extra = MB_FILLER_CHAR;
2201 c_final = NUL;
2202 c = ' ';
2203 if (area_attr == 0 && search_attr == 0)
2204 {
2205 n_attr = n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002206 extra_attr = hl_combine_attr(
2207 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 saved_attr2 = char_attr; // save current attr
2209 }
2210 mb_c = c;
2211 mb_utf8 = FALSE;
2212 mb_l = 1;
2213 }
2214
2215 }
2216 ++ptr;
2217
2218 if (extra_check)
2219 {
2220#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002221 // Check spelling (unless at the end of the line).
2222 // Only do this when there is no syntax highlighting, the
2223 // @Spell cluster is not used or the current syntax item
2224 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002225 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002226 if (has_spell && v >= word_end && v > cur_checked_col)
2227 {
2228 spell_attr = 0;
2229 if (c != 0 && (
2230# ifdef FEAT_SYN_HL
2231 !has_syntax ||
2232# endif
2233 can_spell))
2234 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002235 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 int len;
2237 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002238
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241
2242 // Use nextline[] if possible, it has the start of the
2243 // next line concatenated.
2244 if ((prev_ptr - line) - nextlinecol >= 0)
2245 p = nextline + (prev_ptr - line) - nextlinecol;
2246 else
2247 p = prev_ptr;
2248 cap_col -= (int)(prev_ptr - line);
2249 len = spell_check(wp, p, &spell_hlf, &cap_col,
2250 nochange);
2251 word_end = v + len;
2252
2253 // In Insert mode only highlight a word that
2254 // doesn't touch the cursor.
2255 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002256 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 && wp->w_cursor.lnum == lnum
2258 && wp->w_cursor.col >=
2259 (colnr_T)(prev_ptr - line)
2260 && wp->w_cursor.col < (colnr_T)word_end)
2261 {
2262 spell_hlf = HLF_COUNT;
2263 spell_redraw_lnum = lnum;
2264 }
2265
2266 if (spell_hlf == HLF_COUNT && p != prev_ptr
2267 && (p - nextline) + len > nextline_idx)
2268 {
2269 // Remember that the good word continues at the
2270 // start of the next line.
2271 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002272 checked_col = (int)((p - nextline)
2273 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 }
2275
2276 // Turn index into actual attributes.
2277 if (spell_hlf != HLF_COUNT)
2278 spell_attr = highlight_attr[spell_hlf];
2279
2280 if (cap_col > 0)
2281 {
2282 if (p != prev_ptr
2283 && (p - nextline) + cap_col >= nextline_idx)
2284 {
2285 // Remember that the word in the next line
2286 // must start with a capital.
2287 capcol_lnum = lnum + 1;
2288 cap_col = (int)((p - nextline) + cap_col
2289 - nextline_idx);
2290 }
2291 else
2292 // Compute the actual column.
2293 cap_col += (int)(prev_ptr - line);
2294 }
2295 }
2296 }
2297 if (spell_attr != 0)
2298 {
2299 if (!attr_pri)
2300 char_attr = hl_combine_attr(char_attr, spell_attr);
2301 else
2302 char_attr = hl_combine_attr(spell_attr, char_attr);
2303 }
2304#endif
2305#ifdef FEAT_LINEBREAK
2306 // Found last space before word: check for line break.
2307 if (wp->w_p_lbr && c0 == c
2308 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2309 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002310 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2311 : 0;
2312 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002313 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002315 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002316 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002317
2318 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002319 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002320 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002321 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002322 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002323 if (n_extra < 0)
2324 n_extra = 0;
2325 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002326 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002327 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002328 // line break, but for TABs the highlighting should
2329 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002330 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002331
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002332 if (c == TAB && n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333# ifdef FEAT_VARTABS
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002334 n_extra = tabstop_padding(wlv.vcol,
2335 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002336 wp->w_buffer->b_p_vts_array) - 1;
2337# else
2338 n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002339 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340# endif
2341
2342 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2343 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002344# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002345 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002346 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002347# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 if (VIM_ISWHITE(c))
2349 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002350# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 if (c == TAB)
2352 // See "Tab alignment" below.
2353 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002354# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 if (!wp->w_p_list)
2356 c = ' ';
2357 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002358 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 }
2360#endif
2361
zeertzjqf14b8ba2021-09-10 16:58:30 +02002362 in_multispace = c == ' '
2363 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2364 if (!in_multispace)
2365 multispace_pos = 0;
2366
Bram Moolenaareed9d462021-02-15 20:38:25 +01002367 // 'list': Change char 160 to 'nbsp' and space to 'space'
2368 // setting in 'listchars'. But not when the character is
2369 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 if (wp->w_p_list
2371 && ((((c == 160 && mb_l == 1)
2372 || (mb_utf8
2373 && ((mb_c == 160 && mb_l == 2)
2374 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002375 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 || (c == ' '
2377 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002378 && (wp->w_lcs_chars.space
2379 || (in_multispace
2380 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002381 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 && ptr - line <= trailcol)))
2383 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002384 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2385 {
2386 c = wp->w_lcs_chars.multispace[multispace_pos++];
2387 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2388 multispace_pos = 0;
2389 }
2390 else
2391 c = (c == ' ') ? wp->w_lcs_chars.space
2392 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 if (area_attr == 0 && search_attr == 0)
2394 {
2395 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002396 extra_attr = hl_combine_attr(wlv.win_attr,
2397 HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 saved_attr2 = char_attr; // save current attr
2399 }
2400 mb_c = c;
2401 if (enc_utf8 && utf_char2len(c) > 1)
2402 {
2403 mb_utf8 = TRUE;
2404 u8cc[0] = 0;
2405 c = 0xc0;
2406 }
2407 else
2408 mb_utf8 = FALSE;
2409 }
2410
zeertzjq2e7cba32022-06-10 15:30:32 +01002411 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2412 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002414 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2415 && wp->w_lcs_chars.leadmultispace != NULL)
2416 {
2417 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002418 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2419 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002420 multispace_pos = 0;
2421 }
2422
2423 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2424 c = wp->w_lcs_chars.trail;
2425
2426 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2427 c = wp->w_lcs_chars.lead;
2428
zeertzjq2e7cba32022-06-10 15:30:32 +01002429 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002430 c = wp->w_lcs_chars.space;
2431
2432
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 if (!attr_pri)
2434 {
2435 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002436 extra_attr = hl_combine_attr(wlv.win_attr,
2437 HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 saved_attr2 = char_attr; // save current attr
2439 }
2440 mb_c = c;
2441 if (enc_utf8 && utf_char2len(c) > 1)
2442 {
2443 mb_utf8 = TRUE;
2444 u8cc[0] = 0;
2445 c = 0xc0;
2446 }
2447 else
2448 mb_utf8 = FALSE;
2449 }
2450 }
2451
2452 // Handling of non-printable characters.
2453 if (!vim_isprintc(c))
2454 {
2455 // when getting a character from the file, we may have to
2456 // turn it into something else on the way to putting it
2457 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002458 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 {
2460 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002461 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002463 char_u *sbr = get_showbreak_value(wp);
2464
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 // only adjust the tab_len, when at the first column
2466 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002467 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2468 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469#endif
2470 // tab amount depends on current column
2471#ifdef FEAT_VARTABS
2472 tab_len = tabstop_padding(vcol_adjusted,
2473 wp->w_buffer->b_p_ts,
2474 wp->w_buffer->b_p_vts_array) - 1;
2475#else
2476 tab_len = (int)wp->w_buffer->b_p_ts
2477 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2478#endif
2479
2480#ifdef FEAT_LINEBREAK
2481 if (!wp->w_p_lbr || !wp->w_p_list)
2482#endif
2483 // tab amount depends on current column
2484 n_extra = tab_len;
2485#ifdef FEAT_LINEBREAK
2486 else
2487 {
2488 char_u *p;
2489 int len;
2490 int i;
2491 int saved_nextra = n_extra;
2492
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002493# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002494 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002496 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002497
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002499 if (wp->w_p_list && wp->w_lcs_chars.tab1
2500 && old_boguscols > 0
2501 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002503# endif
2504 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002506 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002507 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002508 if (wp->w_lcs_chars.tab3)
2509 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 if (n_extra > 0)
2511 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002512 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002514 if (p == NULL)
2515 n_extra = 0;
2516 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002518 vim_memset(p, ' ', len);
2519 p[len] = NUL;
2520 vim_free(p_extra_free);
2521 p_extra_free = p;
2522 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002524 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002526 if (*p == NUL)
2527 {
2528 tab_len = i;
2529 break;
2530 }
2531
2532 // if tab3 is given, use it for the last char
2533 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2534 lcs = wp->w_lcs_chars.tab3;
2535 p += mb_char2bytes(lcs, p);
2536 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002538 }
2539 p_extra = p_extra_free;
2540# ifdef FEAT_CONCEAL
2541 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2542 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002543 if (wlv.vcol_off > 0)
2544 n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002545# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 }
2548#endif
2549#ifdef FEAT_CONCEAL
2550 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552
2553 // Tab alignment should be identical regardless of
2554 // 'conceallevel' value. So tab compensates of all
2555 // previous concealed characters, and thus resets
2556 // vcol_off and boguscols accumulated so far in the
2557 // line. Note that the tab can be longer than
2558 // 'tabstop' when there are concealed characters.
2559 FIX_FOR_BOGUSCOLS;
2560
2561 // Make sure, the highlighting for the tab char will be
2562 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002563 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002565 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 tab_len += vc_saved;
2567 }
2568#endif
2569 mb_utf8 = FALSE; // don't draw as UTF-8
2570 if (wp->w_p_list)
2571 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002572 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2573 ? wp->w_lcs_chars.tab3
2574 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575#ifdef FEAT_LINEBREAK
2576 if (wp->w_p_lbr)
2577 c_extra = NUL; // using p_extra from above
2578 else
2579#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002580 c_extra = wp->w_lcs_chars.tab2;
2581 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002583 extra_attr = hl_combine_attr(wlv.win_attr,
2584 HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 saved_attr2 = char_attr; // save current attr
2586 mb_c = c;
2587 if (enc_utf8 && utf_char2len(c) > 1)
2588 {
2589 mb_utf8 = TRUE;
2590 u8cc[0] = 0;
2591 c = 0xc0;
2592 }
2593 }
2594 else
2595 {
2596 c_final = NUL;
2597 c_extra = ' ';
2598 c = ' ';
2599 }
2600 }
2601 else if (c == NUL
2602 && (wp->w_p_list
2603 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002604 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 && VIsual_mode != Ctrl_V
2606 && (
2607# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002608 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002610 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002611 && !(noinvcur
2612 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002613 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 && lcs_eol_one > 0)
2615 {
2616 // Display a '$' after the line or highlight an extra
2617 // character if the line break is included.
2618#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2619 // For a diff line the highlighting continues after the
2620 // "$".
2621 if (
2622# ifdef FEAT_DIFF
2623 diff_hlf == (hlf_T)0
2624# ifdef LINE_ATTR
2625 &&
2626# endif
2627# endif
2628# ifdef LINE_ATTR
2629 line_attr == 0
2630# endif
2631 )
2632#endif
2633 {
2634 // In virtualedit, visual selections may extend
2635 // beyond end of line.
2636 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002637 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 n_extra = 0;
2639 else
2640 {
2641 p_extra = at_end_str;
2642 n_extra = 1;
2643 c_extra = NUL;
2644 c_final = NUL;
2645 }
2646 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002647 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2648 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 else
2650 c = ' ';
2651 lcs_eol_one = -1;
2652 --ptr; // put it back at the NUL
2653 if (!attr_pri)
2654 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002655 extra_attr = hl_combine_attr(wlv.win_attr,
2656 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657 n_attr = 1;
2658 }
2659 mb_c = c;
2660 if (enc_utf8 && utf_char2len(c) > 1)
2661 {
2662 mb_utf8 = TRUE;
2663 u8cc[0] = 0;
2664 c = 0xc0;
2665 }
2666 else
2667 mb_utf8 = FALSE; // don't draw as UTF-8
2668 }
2669 else if (c != NUL)
2670 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002671 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 if (n_extra == 0)
2673 n_extra = byte2cells(c) - 1;
2674#ifdef FEAT_RIGHTLEFT
2675 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2676 rl_mirror(p_extra); // reverse "<12>"
2677#endif
2678 c_extra = NUL;
2679 c_final = NUL;
2680#ifdef FEAT_LINEBREAK
2681 if (wp->w_p_lbr)
2682 {
2683 char_u *p;
2684
2685 c = *p_extra;
2686 p = alloc(n_extra + 1);
2687 vim_memset(p, ' ', n_extra);
2688 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2689 p[n_extra] = NUL;
2690 vim_free(p_extra_free);
2691 p_extra_free = p_extra = p;
2692 }
2693 else
2694#endif
2695 {
2696 n_extra = byte2cells(c) - 1;
2697 c = *p_extra++;
2698 }
2699 if (!attr_pri)
2700 {
2701 n_attr = n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002702 extra_attr = hl_combine_attr(wlv.win_attr,
2703 HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002704 saved_attr2 = char_attr; // save current attr
2705 }
2706 mb_utf8 = FALSE; // don't draw as UTF-8
2707 }
2708 else if (VIsual_active
2709 && (VIsual_mode == Ctrl_V
2710 || VIsual_mode == 'v')
2711 && virtual_active()
2712 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002713 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 && (
2715#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002718 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 {
2720 c = ' ';
2721 --ptr; // put it back at the NUL
2722 }
2723#if defined(LINE_ATTR)
2724 else if ((
2725# ifdef FEAT_DIFF
2726 diff_hlf != (hlf_T)0 ||
2727# endif
2728# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002729 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730# endif
2731 line_attr != 0
2732 ) && (
2733# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002734 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002736 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002738 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739# endif
2740 < wp->w_width)))
2741 {
2742 // Highlight until the right side of the window
2743 c = ' ';
2744 --ptr; // put it back at the NUL
2745
2746 // Remember we do the char for line highlighting.
2747 ++did_line_attr;
2748
2749 // don't do search HL for the rest of the line
2750 if (line_attr != 0 && char_attr == search_attr
2751 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002752 || (wp->w_p_list &&
2753 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 char_attr = line_attr;
2755# ifdef FEAT_DIFF
2756 if (diff_hlf == HLF_TXD)
2757 {
2758 diff_hlf = HLF_CHD;
2759 if (vi_attr == 0 || char_attr != vi_attr)
2760 {
2761 char_attr = HL_ATTR(diff_hlf);
2762 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2763 && wp->w_p_culopt_flags != CULOPT_NBR
2764 && (!cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002765 || (wlv.vcol >= left_curline_col
2766 && wlv.vcol <= right_curline_col)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 char_attr = hl_combine_attr(
2768 char_attr, HL_ATTR(HLF_CUL));
2769 }
2770 }
2771# endif
2772# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002773 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002775 char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002776 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2777 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002779 if (!cul_screenline || (wlv.vcol >= left_curline_col
2780 && wlv.vcol <= right_curline_col))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 char_attr = hl_combine_attr(
2782 char_attr, HL_ATTR(HLF_CUL));
2783 }
2784 else if (line_attr)
2785 char_attr = hl_combine_attr(char_attr, line_attr);
2786 }
2787# endif
2788 }
2789#endif
2790 }
2791
2792#ifdef FEAT_CONCEAL
2793 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002794 && (wp != curwin || lnum != wp->w_cursor.lnum
2795 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2797 && !(lnum_in_visual_area
2798 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2799 {
2800 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002801 if (((prev_syntax_id != syntax_seqnr
2802 && (syntax_flags & HL_CONCEAL) != 0)
2803 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002804 && (syn_get_sub_char() != NUL
2805 || (has_match_conc && match_conc)
2806 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 && wp->w_p_cole != 3)
2808 {
2809 // First time at this concealed item: display one
2810 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002811 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 c = match_conc;
2813 else if (syn_get_sub_char() != NUL)
2814 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002815 else if (wp->w_lcs_chars.conceal != NUL)
2816 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 else
2818 c = ' ';
2819
2820 prev_syntax_id = syntax_seqnr;
2821
2822 if (n_extra > 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002823 wlv.vcol_off += n_extra;
2824 wlv.vcol += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 if (wp->w_p_wrap && n_extra > 0)
2826 {
2827# ifdef FEAT_RIGHTLEFT
2828 if (wp->w_p_rl)
2829 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002830 wlv.col -= n_extra;
2831 wlv.boguscols -= n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 }
2833 else
2834# endif
2835 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002836 wlv.boguscols += n_extra;
2837 wlv.col += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 }
2839 }
2840 n_extra = 0;
2841 n_attr = 0;
2842 }
2843 else if (n_skip == 0)
2844 {
2845 is_concealing = TRUE;
2846 n_skip = 1;
2847 }
2848 mb_c = c;
2849 if (enc_utf8 && utf_char2len(c) > 1)
2850 {
2851 mb_utf8 = TRUE;
2852 u8cc[0] = 0;
2853 c = 0xc0;
2854 }
2855 else
2856 mb_utf8 = FALSE; // don't draw as UTF-8
2857 }
2858 else
2859 {
2860 prev_syntax_id = 0;
2861 is_concealing = FALSE;
2862 }
2863
2864 if (n_skip > 0 && did_decrement_ptr)
2865 // not showing the '>', put pointer back to avoid getting stuck
2866 ++ptr;
2867
2868#endif // FEAT_CONCEAL
2869 }
2870
2871#ifdef FEAT_CONCEAL
2872 // In the cursor line and we may be concealing characters: correct
2873 // the cursor column when we reach its position.
2874 if (!did_wcol && draw_state == WL_LINE
2875 && wp == curwin && lnum == wp->w_cursor.lnum
2876 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002877 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002879# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002881 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002883# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002884 wp->w_wcol = wlv.col - wlv.boguscols;
2885 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 did_wcol = TRUE;
2887 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002888# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002889 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002890# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 }
2892#endif
2893
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002894 // Use "extra_attr", but don't override visual selection highlighting.
2895 // Don't use "extra_attr" until n_attr_skip is zero.
2896 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 && draw_state == WL_LINE
2898 && !attr_pri)
2899 {
2900#ifdef LINE_ATTR
2901 if (line_attr)
2902 char_attr = hl_combine_attr(extra_attr, line_attr);
2903 else
2904#endif
2905 char_attr = extra_attr;
2906 }
2907
2908#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2909 // XIM don't send preedit_start and preedit_end, but they send
2910 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2911 // im_is_preediting() here.
2912 if (p_imst == IM_ON_THE_SPOT
2913 && xic != NULL
2914 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002915 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 && !p_imdisable
2917 && im_is_preediting()
2918 && draw_state == WL_LINE)
2919 {
2920 colnr_T tcol;
2921
2922 if (preedit_end_col == MAXCOL)
2923 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2924 else
2925 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002926 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 {
2928 if (feedback_old_attr < 0)
2929 {
2930 feedback_col = 0;
2931 feedback_old_attr = char_attr;
2932 }
2933 char_attr = im_get_feedback_attr(feedback_col);
2934 if (char_attr < 0)
2935 char_attr = feedback_old_attr;
2936 feedback_col++;
2937 }
2938 else if (feedback_old_attr >= 0)
2939 {
2940 char_attr = feedback_old_attr;
2941 feedback_old_attr = -1;
2942 feedback_col = 0;
2943 }
2944 }
2945#endif
2946 // Handle the case where we are in column 0 but not on the first
2947 // character of the line and the user wants us to show us a
2948 // special character (via 'listchars' option "precedes:<char>".
2949 if (lcs_prec_todo != NUL
2950 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002951 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002952 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002953 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954#ifdef FEAT_DIFF
2955 && filler_todo <= 0
2956#endif
2957 && draw_state > WL_NR
2958 && c != NUL)
2959 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002960 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 lcs_prec_todo = NUL;
2962 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2963 {
2964 // Double-width character being overwritten by the "precedes"
2965 // character, need to fill up half the character.
2966 c_extra = MB_FILLER_CHAR;
2967 c_final = NUL;
2968 n_extra = 1;
2969 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 }
2972 mb_c = c;
2973 if (enc_utf8 && utf_char2len(c) > 1)
2974 {
2975 mb_utf8 = TRUE;
2976 u8cc[0] = 0;
2977 c = 0xc0;
2978 }
2979 else
2980 mb_utf8 = FALSE; // don't draw as UTF-8
2981 if (!attr_pri)
2982 {
2983 saved_attr3 = char_attr; // save current attr
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002984 char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 n_attr3 = 1;
2986 }
2987 }
2988
2989 // At end of the text line or just after the last character.
2990 if ((c == NUL
2991#if defined(LINE_ATTR)
2992 || did_line_attr == 1
2993#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 {
2996#ifdef FEAT_SEARCH_EXTRA
2997 // flag to indicate whether prevcol equals startcol of search_hl or
2998 // one of the matches
2999 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3000 (long)(ptr - line) - (c == NUL));
3001#endif
3002 // Invert at least one char, used for Visual and empty line or
3003 // highlight match at end of line. If it's beyond the last
3004 // char on the screen, just overwrite that one (tricky!) Not
3005 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003006 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003007 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 && (VIsual_mode != Ctrl_V
3009 || lnum == VIsual.lnum
3010 || lnum == curwin->w_cursor.lnum)
3011 && c == NUL)
3012#ifdef FEAT_SEARCH_EXTRA
3013 // highlight 'hlsearch' match at end of line
3014 || (prevcol_hl_flag
3015# ifdef FEAT_SYN_HL
3016 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3017 && !(wp == curwin && VIsual_active))
3018# endif
3019# ifdef FEAT_DIFF
3020 && diff_hlf == (hlf_T)0
3021# endif
3022# if defined(LINE_ATTR)
3023 && did_line_attr <= 1
3024# endif
3025 )
3026#endif
3027 ))
3028 {
3029 int n = 0;
3030
3031#ifdef FEAT_RIGHTLEFT
3032 if (wp->w_p_rl)
3033 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003034 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 n = 1;
3036 }
3037 else
3038#endif
3039 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003040 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 n = -1;
3042 }
3043 if (n != 0)
3044 {
3045 // At the window boundary, highlight the last character
3046 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003047 wlv.off += n;
3048 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 }
3050 else
3051 {
3052 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003053 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003055 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056 }
3057#ifdef FEAT_SEARCH_EXTRA
3058 if (area_attr == 0)
3059 {
3060 // Use attributes from match with highest priority among
3061 // 'search_hl' and the match list.
3062 get_search_match_hl(wp, &screen_search_hl,
3063 (long)(ptr - line), &char_attr);
3064 }
3065#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003066 ScreenAttrs[wlv.off] = char_attr;
3067 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068#ifdef FEAT_RIGHTLEFT
3069 if (wp->w_p_rl)
3070 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003071 --wlv.col;
3072 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 }
3074 else
3075#endif
3076 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003077 ++wlv.col;
3078 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003080 ++wlv.vcol;
3081 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003082 }
3083 }
3084
3085 // At end of the text line.
3086 if (c == NUL)
3087 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089
3090 // Update w_cline_height and w_cline_folded if the cursor line was
3091 // updated (saves a call to plines() later).
3092 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3093 {
3094 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003095 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096#ifdef FEAT_FOLDING
3097 curwin->w_cline_folded = FALSE;
3098#endif
3099 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3100 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 break;
3102 }
3103
3104 // Show "extends" character from 'listchars' if beyond the line end and
3105 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003106 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003107 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 && wp->w_p_list
3109 && !wp->w_p_wrap
3110#ifdef FEAT_DIFF
3111 && filler_todo <= 0
3112#endif
3113 && (
3114#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003117 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 && (*ptr != NUL
3119 || (wp->w_p_list && lcs_eol_one > 0)
3120 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
3121 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003122 c = wp->w_lcs_chars.ext;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 mb_c = c;
3125 if (enc_utf8 && utf_char2len(c) > 1)
3126 {
3127 mb_utf8 = TRUE;
3128 u8cc[0] = 0;
3129 c = 0xc0;
3130 }
3131 else
3132 mb_utf8 = FALSE;
3133 }
3134
3135#ifdef FEAT_SYN_HL
3136 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003137 if (wlv.draw_color_col)
3138 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139
3140 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3141 // highlight the cursor position itself.
3142 // Also highlight the 'colorcolumn' if it is different than
3143 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003144 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3145 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003147 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003148 draw_state == WL_BRI ||
3149 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003151# ifdef FEAT_DIFF
3152 && filler_todo <= 0
3153# endif
3154 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 {
3156 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3157 && lnum != wp->w_cursor.lnum)
3158 {
3159 vcol_save_attr = char_attr;
3160 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3161 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003162 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 {
3164 vcol_save_attr = char_attr;
3165 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3166 }
3167 }
3168#endif
3169
3170 // Store character to be displayed.
3171 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 vcol_prev = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 if (draw_state < WL_LINE || n_skip <= 0)
3174 {
3175 // Store the character.
3176#if defined(FEAT_RIGHTLEFT)
3177 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3178 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003179 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 --wlv.off;
3181 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
3183#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003184 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003185 if (enc_dbcs == DBCS_JPNU)
3186 {
3187 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003188 ScreenLines[wlv.off] = 0x8e;
3189 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 }
3191 else if (enc_utf8)
3192 {
3193 if (mb_utf8)
3194 {
3195 int i;
3196
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003197 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003199 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 for (i = 0; i < Screen_mco; ++i)
3201 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003202 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 if (u8cc[i] == 0)
3204 break;
3205 }
3206 }
3207 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003208 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 }
3210 if (multi_attr)
3211 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003212 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 multi_attr = 0;
3214 }
3215 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003216 ScreenAttrs[wlv.off] = char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003219
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3221 {
3222 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 ++wlv.off;
3224 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 if (enc_utf8)
3226 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 else
3229 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003230 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 if (draw_state > WL_NR
3232#ifdef FEAT_DIFF
3233 && filler_todo <= 0
3234#endif
3235 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003236 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 // When "tocol" is halfway a character, set it to the end of
3238 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003239 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003241
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003243
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244#ifdef FEAT_RIGHTLEFT
3245 if (wp->w_p_rl)
3246 {
3247 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003248 --wlv.off;
3249 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 }
3251#endif
3252 }
3253#ifdef FEAT_RIGHTLEFT
3254 if (wp->w_p_rl)
3255 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 --wlv.off;
3257 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 }
3259 else
3260#endif
3261 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 ++wlv.off;
3263 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265 }
3266#ifdef FEAT_CONCEAL
3267 else if (wp->w_p_cole > 0 && is_concealing)
3268 {
3269 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ++wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 if (n_extra > 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003272 wlv.vcol_off += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 if (wp->w_p_wrap)
3274 {
3275 // Special voodoo required if 'wrap' is on.
3276 //
3277 // Advance the column indicator to force the line
3278 // drawing to wrap early. This will make the line
3279 // take up the same screen space when parts are concealed,
3280 // so that cursor line computations aren't messed up.
3281 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 // trailing junk to be written out of the screen line
3284 // we are building, 'boguscols' keeps track of the number
3285 // of bad columns we have advanced.
3286 if (n_extra > 0)
3287 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 wlv.vcol += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289# ifdef FEAT_RIGHTLEFT
3290 if (wp->w_p_rl)
3291 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003292 wlv.col -= n_extra;
3293 wlv.boguscols -= n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 }
3295 else
3296# endif
3297 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003298 wlv.col += n_extra;
3299 wlv.boguscols += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 }
3301 n_extra = 0;
3302 n_attr = 0;
3303 }
3304
3305
3306 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3307 {
3308 // Need to fill two screen columns.
3309# ifdef FEAT_RIGHTLEFT
3310 if (wp->w_p_rl)
3311 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 --wlv.boguscols;
3313 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 }
3315 else
3316# endif
3317 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 ++wlv.boguscols;
3319 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 }
3321 }
3322
3323# ifdef FEAT_RIGHTLEFT
3324 if (wp->w_p_rl)
3325 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 --wlv.boguscols;
3327 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 }
3329 else
3330# endif
3331 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003332 ++wlv.boguscols;
3333 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 }
3335 }
3336 else
3337 {
3338 if (n_extra > 0)
3339 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 wlv.vcol += n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 n_extra = 0;
3342 n_attr = 0;
3343 }
3344 }
3345
3346 }
3347#endif // FEAT_CONCEAL
3348 else
3349 --n_skip;
3350
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 // Only advance the "wlv.vcol" when after the 'number' or
3352 // 'relativenumber' column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 if (draw_state > WL_NR
3354#ifdef FEAT_DIFF
3355 && filler_todo <= 0
3356#endif
3357 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359
3360#ifdef FEAT_SYN_HL
3361 if (vcol_save_attr >= 0)
3362 char_attr = vcol_save_attr;
3363#endif
3364
3365 // restore attributes after "predeces" in 'listchars'
3366 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3367 char_attr = saved_attr3;
3368
3369 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003370 if (n_attr > 0 && draw_state == WL_LINE
3371 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003373 if (n_attr_skip > 0)
3374 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375
3376 // At end of screen line and there is more to come: Display the line
3377 // so far. If there is no more to display it is caught above.
3378 if ((
3379#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003382 (wlv.col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003383 && (draw_state != WL_LINE
3384 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385#ifdef FEAT_DIFF
3386 || filler_todo > 0
3387#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003388#ifdef FEAT_PROP_POPUP
3389 || text_prop_follows
3390#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003391 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3392 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3394 )
3395 {
3396#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003397 screen_line(wp, wlv.screen_row, wp->w_wincol,
3398 wlv.col - wlv.boguscols,
3399 wp->w_width, wlv.screen_line_flags);
3400 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003402 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3403 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 ++wlv.row;
3406 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407
3408 // When not wrapping and finished diff lines, or when displayed
3409 // '$' and highlighting until last column, break here.
3410 if ((!wp->w_p_wrap
3411#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003412 && filler_todo <= 0
3413#endif
3414#ifdef FEAT_PROP_POPUP
3415 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416#endif
3417 ) || lcs_eol_one == -1)
3418 break;
3419
3420 // When the window is too narrow draw all "@" lines.
3421 if (draw_state != WL_LINE
3422#ifdef FEAT_DIFF
3423 && filler_todo <= 0
3424#endif
3425 )
3426 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3428 draw_vsep_win(wp, wlv.row);
3429 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 }
3431
3432 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 break;
3437 }
3438
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003439 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440#ifdef FEAT_DIFF
3441 && filler_todo <= 0
3442#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003443#ifdef FEAT_PROP_POPUP
3444 && !text_prop_follows
3445#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 && wp->w_width == Columns)
3447 {
3448 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450
3451 // Special trick to make copy/paste of wrapped lines work with
3452 // xterm/screen: write an extra character beyond the end of
3453 // the line. This will work with all terminal types
3454 // (regardless of the xn,am settings).
3455 // Only do this on a fast tty.
3456 // Only do this if the cursor is on the current line
3457 // (something has been written in it).
3458 // Don't do this for the GUI.
3459 // Don't do this for double-width characters.
3460 // Don't do this for a window not at the right screen border.
3461 if (p_tf
3462#ifdef FEAT_GUI
3463 && !gui.in_use
3464#endif
3465 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3467 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 || (*mb_off2cells)(
3470 LineOffset[wlv.screen_row - 1]
3471 + (int)Columns - 2,
3472 LineOffset[wlv.screen_row]
3473 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 {
3475 // First make sure we are at the end of the screen line,
3476 // then output the same character again to let the
3477 // terminal know about the wrap. If the terminal doesn't
3478 // auto-wrap, we overwrite the character.
3479 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003480 screen_char(LineOffset[wlv.screen_row - 1]
3481 + (unsigned)Columns - 1,
3482 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483
3484 // When there is a multi-byte character, just output a
3485 // space to keep it simple.
3486 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 out_char(' ');
3489 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 + (Columns - 1)]);
3492 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 screen_start(); // don't know where cursor is now
3495 }
3496 }
3497
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 win_line_start(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499
3500 // reset the drawing state for the start of a wrapped line
3501 draw_state = WL_START;
3502 saved_n_extra = n_extra;
3503 saved_p_extra = p_extra;
3504 saved_c_extra = c_extra;
3505 saved_c_final = c_final;
3506#ifdef FEAT_SYN_HL
3507 if (!(cul_screenline
3508# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003509 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003511 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 saved_char_attr = char_attr;
3513 else
3514#endif
3515 saved_char_attr = 0;
3516 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003517 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003519 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003521 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003523 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524 need_showbreak = TRUE;
3525#endif
3526#ifdef FEAT_DIFF
3527 --filler_todo;
3528 // When the filler lines are actually below the last line of the
3529 // file, don't draw the line itself, break here.
3530 if (filler_todo == 0 && wp->w_botfill)
3531 break;
3532#endif
3533 }
3534
3535 } // for every character in the line
3536
3537#ifdef FEAT_SPELL
3538 // After an empty line check first word for capital.
3539 if (*skipwhite(line) == NUL)
3540 {
3541 capcol_lnum = lnum + 1;
3542 cap_col = 0;
3543 }
3544#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003545#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 vim_free(text_props);
3547 vim_free(text_prop_idxs);
3548#endif
3549
3550 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003551 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552}