blob: 871b09bfd2ca90b8d9f504774c7251544b6eea63 [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
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100280#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281static textprop_T *current_text_props = NULL;
282static buf_T *current_buf = NULL;
283
284 static int
285text_prop_compare(const void *s1, const void *s2)
286{
287 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100288 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 proptype_T *pt1, *pt2;
290 colnr_T col1, col2;
291
292 idx1 = *(int *)s1;
293 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100294 tp1 = &current_text_props[idx1];
295 tp2 = &current_text_props[idx2];
296 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
297 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 if (pt1 == pt2)
299 return 0;
300 if (pt1 == NULL)
301 return -1;
302 if (pt2 == NULL)
303 return 1;
304 if (pt1->pt_priority != pt2->pt_priority)
305 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100306 col1 = tp1->tp_col;
307 col2 = tp2->tp_col;
308 if (col1 == MAXCOL && col2 == MAXCOL)
309 {
310 int flags1 = 0;
311 int flags2 = 0;
312
313 // order on 0: after, 1: right, 2: below
314 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
315 flags1 = 1;
316 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
317 flags1 = 2;
318 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
319 flags2 = 1;
320 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
321 flags2 = 2;
322 if (flags1 != flags2)
323 return flags1 < flags2 ? 1 : -1;
324 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200325 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
326}
327#endif
328
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100329/*
330 * Called when finished with the line: draw the screen line and handle any
331 * highlighting until the right of the window.
332 */
333 static void
334draw_screen_line(win_T *wp, winlinevars_T *wlv)
335{
336#ifdef FEAT_SYN_HL
337 long v;
338
339 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
340 if (wp->w_p_wrap)
341 v = wp->w_skipcol;
342 else
343 v = wp->w_leftcol;
344
345 // check if line ends before left margin
346 if (wlv->vcol < v + wlv->col - win_col_off(wp))
347 wlv->vcol = v + wlv->col - win_col_off(wp);
348# ifdef FEAT_CONCEAL
349 // Get rid of the boguscols now, we want to draw until the right
350 // edge for 'cursorcolumn'.
351 wlv->col -= wlv->boguscols;
352 wlv->boguscols = 0;
353# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
354# else
355# define VCOL_HLC (wlv->vcol)
356# endif
357
358 if (wlv->draw_color_col)
359 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
360
361 if (((wp->w_p_cuc
362 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
363 && (int)wp->w_virtcol <
364 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
365 && wlv->lnum != wp->w_cursor.lnum)
366 || wlv->draw_color_col
367 || wlv->win_attr != 0)
368# ifdef FEAT_RIGHTLEFT
369 && !wp->w_p_rl
370# endif
371 )
372 {
373 int rightmost_vcol = 0;
374 int i;
375
376 if (wp->w_p_cuc)
377 rightmost_vcol = wp->w_virtcol;
378 if (wlv->draw_color_col)
379 // determine rightmost colorcolumn to possibly draw
380 for (i = 0; wlv->color_cols[i] >= 0; ++i)
381 if (rightmost_vcol < wlv->color_cols[i])
382 rightmost_vcol = wlv->color_cols[i];
383
384 while (wlv->col < wp->w_width)
385 {
386 ScreenLines[wlv->off] = ' ';
387 if (enc_utf8)
388 ScreenLinesUC[wlv->off] = 0;
389 ScreenCols[wlv->off] = MAXCOL;
390 ++wlv->col;
391 if (wlv->draw_color_col)
392 wlv->draw_color_col = advance_color_col(
393 VCOL_HLC, &wlv->color_cols);
394
395 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
396 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
397 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
398 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
399 else
400 ScreenAttrs[wlv->off++] = wlv->win_attr;
401
402 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
403 break;
404
405 ++wlv->vcol;
406 }
407 }
408#endif
409
410 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
411 wp->w_width, wlv->screen_line_flags);
412 ++wlv->row;
413 ++wlv->screen_row;
414}
415#undef VCOL_HLC
416
417/*
418 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100419 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100420 */
421 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100422win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100423{
424 wlv->col = 0;
425 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
426
427#ifdef FEAT_RIGHTLEFT
428 if (wp->w_p_rl)
429 {
430 // Rightleft window: process the text in the normal direction, but put
431 // it in current_ScreenLine[] from right to left. Start at the
432 // rightmost column of the window.
433 wlv->col = wp->w_width - 1;
434 wlv->off += wlv->col;
435 wlv->screen_line_flags |= SLF_RIGHTLEFT;
436 }
437#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100438 if (save_extra)
439 {
440 // reset the drawing state for the start of a wrapped line
441 wlv->draw_state = WL_START;
442 wlv->saved_n_extra = wlv->n_extra;
443 wlv->saved_p_extra = wlv->p_extra;
444 wlv->saved_c_extra = wlv->c_extra;
445 wlv->saved_c_final = wlv->c_final;
446#ifdef FEAT_SYN_HL
447 if (!(wlv->cul_screenline
448# ifdef FEAT_DIFF
449 && wlv->diff_hlf == (hlf_T)0
450# endif
451 ))
452 wlv->saved_char_attr = wlv->char_attr;
453 else
454#endif
455 wlv->saved_char_attr = 0;
456 wlv->n_extra = 0;
457 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100458}
459
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200460/*
461 * Display line "lnum" of window 'wp' on the screen.
462 * Start at row "startrow", stop when "endrow" is reached.
463 * wp->w_virtcol needs to be valid.
464 *
465 * Return the number of last row the line occupies.
466 */
467 int
468win_line(
469 win_T *wp,
470 linenr_T lnum,
471 int startrow,
472 int endrow,
473 int nochange UNUSED, // not updating for changed text
474 int number_only) // only update the number column
475{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100476 winlinevars_T wlv; // variables passed between functions
477
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200478 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200479#ifdef FEAT_LINEBREAK
480 long vcol_sbr = -1; // virtual column after showbreak
481#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100482 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200483 char_u *line; // current line
484 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200485
486 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200487 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100488#ifdef FEAT_PROP_POPUP
489 char_u *p_extra_free2 = NULL; // another p_extra to be freed
490#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200491 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000492#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000493 int in_linebreak = FALSE; // n_extra set for showing linebreak
494#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100496 // displaying eol at end-of-line
497 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000498 int lcs_prec_todo = wp->w_lcs_chars.prec;
499 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100501 int n_attr = 0; // chars with special attr
502 int n_attr_skip = 0; // chars to skip before using extra_attr
503 int saved_attr2 = 0; // char_attr saved for n_attr
504 int n_attr3 = 0; // chars with overruling special attr
505 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200506
507 int n_skip = 0; // nr of chars to skip for 'nowrap'
508
509 int fromcol = -10; // start of inverting
510 int tocol = MAXCOL; // end of inverting
511 int fromcol_prev = -2; // start of inverting after cursor
512 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200513 int lnum_in_visual_area = FALSE;
514 pos_T pos;
515 long v;
516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200517 int attr_pri = FALSE; // char_attr has priority
518 int area_highlighting = FALSE; // Visual or incsearch highlighting
519 // in this line
520 int vi_attr = 0; // attributes for Visual and incsearch
521 // highlighting
522 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523 int area_attr = 0; // attributes desired by highlighting
524 int search_attr = 0; // attributes desired by 'hlsearch'
525#ifdef FEAT_SYN_HL
526 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
527 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200528 int prev_syntax_col = -1; // column of prev_syntax_attr
529 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200530 int has_syntax = FALSE; // this buffer has syntax highl.
531 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200532#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100533#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200534 int text_prop_count;
535 int text_prop_next = 0; // next text property to use
536 textprop_T *text_props = NULL;
537 int *text_prop_idxs = NULL;
538 int text_props_active = 0;
539 proptype_T *text_prop_type = NULL;
540 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100541 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100542 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100543 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200544#endif
545#ifdef FEAT_SPELL
546 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000547 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200548# define SPWORDLEN 150
549 char_u nextline[SPWORDLEN * 2];// text with start of the next line
550 int nextlinecol = 0; // column where nextline[] starts
551 int nextline_idx = 0; // index in nextline[] where next line
552 // starts
553 int spell_attr = 0; // attributes desired by spelling
554 int word_end = 0; // last byte with same spell_attr
555 static linenr_T checked_lnum = 0; // line number for "checked_col"
556 static int checked_col = 0; // column in "checked_lnum" up to which
557 // there are no spell errors
558 static int cap_col = -1; // column to check for Cap word
559 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
560 int cur_checked_col = 0; // checked column for current line
561#endif
562 int extra_check = 0; // has extra highlighting
563 int multi_attr = 0; // attributes desired by multibyte
564 int mb_l = 1; // multi-byte byte length
565 int mb_c = 0; // decoded multi-byte character
566 int mb_utf8 = FALSE; // screen char is UTF-8 char
567 int u8cc[MAX_MCO]; // composing UTF-8 chars
568#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
569 int filler_lines = 0; // nr of filler lines to be drawn
570 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000571#else
572# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573#endif
574#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200575 int change_start = MAXCOL; // first col of changed area
576 int change_end = -1; // last col of changed area
577#endif
578 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100579 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200580 int in_multispace = FALSE; // in multiple consecutive spaces
581 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200582#ifdef FEAT_LINEBREAK
583 int need_showbreak = FALSE; // overlong line, skipping first x
584 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100585 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200586#endif
587#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
588 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
589# define LINE_ATTR
590 int line_attr = 0; // attribute for the whole line
591 int line_attr_save;
592#endif
593#ifdef FEAT_SIGNS
594 int sign_present = FALSE;
595 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000596 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200597#endif
598#ifdef FEAT_ARABIC
599 int prev_c = 0; // previous Arabic character
600 int prev_c1 = 0; // first composing char for prev_c
601#endif
602#if defined(LINE_ATTR)
603 int did_line_attr = 0;
604#endif
605#ifdef FEAT_TERMINAL
606 int get_term_attr = FALSE;
607#endif
608#ifdef FEAT_SYN_HL
609 int cul_attr = 0; // set when 'cursorline' active
610
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611 // margin columns for the screen line, needed for when 'cursorlineopt'
612 // contains "screenline"
613 int left_curline_col = 0;
614 int right_curline_col = 0;
615#endif
616
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
618 int feedback_col = 0;
619 int feedback_old_attr = -1;
620#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621
622#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
623 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000624 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200625#endif
626#ifdef FEAT_CONCEAL
627 int syntax_flags = 0;
628 int syntax_seqnr = 0;
629 int prev_syntax_id = 0;
630 int conceal_attr = HL_ATTR(HLF_CONCEAL);
631 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200632 int did_wcol = FALSE;
633 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100634# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200635# define FIX_FOR_BOGUSCOLS \
636 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100637 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100638 wlv.vcol -= wlv.vcol_off; \
639 wlv.vcol_off = 0; \
640 wlv.col -= wlv.boguscols; \
641 old_boguscols = wlv.boguscols; \
642 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643 }
644#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100645# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646#endif
647
648 if (startrow > endrow) // past the end already!
649 return startrow;
650
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100651 CLEAR_FIELD(wlv);
652
653 wlv.lnum = lnum;
654 wlv.startrow = startrow;
655 wlv.row = startrow;
656 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657
658 if (!number_only)
659 {
660 // To speed up the loop below, set extra_check when there is linebreak,
661 // trailing white space and/or syntax processing to be done.
662#ifdef FEAT_LINEBREAK
663 extra_check = wp->w_p_lbr;
664#endif
665#ifdef FEAT_SYN_HL
666 if (syntax_present(wp) && !wp->w_s->b_syn_error
667# ifdef SYN_TIME_LIMIT
668 && !wp->w_s->b_syn_slow
669# endif
670 )
671 {
672 // Prepare for syntax highlighting in this line. When there is an
673 // error, stop syntax highlighting.
674 save_did_emsg = did_emsg;
675 did_emsg = FALSE;
676 syntax_start(wp, lnum);
677 if (did_emsg)
678 wp->w_s->b_syn_error = TRUE;
679 else
680 {
681 did_emsg = save_did_emsg;
682#ifdef SYN_TIME_LIMIT
683 if (!wp->w_s->b_syn_slow)
684#endif
685 {
686 has_syntax = TRUE;
687 extra_check = TRUE;
688 }
689 }
690 }
691
692 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100693 wlv.color_cols = wp->w_p_cc_cols;
694 if (wlv.color_cols != NULL)
695 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200696#endif
697
698#ifdef FEAT_TERMINAL
699 if (term_show_buffer(wp->w_buffer))
700 {
701 extra_check = TRUE;
702 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100703 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200704 }
705#endif
706
707#ifdef FEAT_SPELL
708 if (wp->w_p_spell
709 && *wp->w_s->b_p_spl != NUL
710 && wp->w_s->b_langp.ga_len > 0
711 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
712 {
713 // Prepare for spell checking.
714 has_spell = TRUE;
715 extra_check = TRUE;
716
717 // Get the start of the next line, so that words that wrap to the
718 // next line are found too: "et<line-break>al.".
719 // Trick: skip a few chars for C/shell/Vim comments
720 nextline[SPWORDLEN] = NUL;
721 if (lnum < wp->w_buffer->b_ml.ml_line_count)
722 {
723 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
724 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
725 }
726
727 // When a word wrapped from the previous line the start of the
728 // current line is valid.
729 if (lnum == checked_lnum)
730 cur_checked_col = checked_col;
731 checked_lnum = 0;
732
733 // When there was a sentence end in the previous line may require a
734 // word starting with capital in this line. In line 1 always check
735 // the first word.
736 if (lnum != capcol_lnum)
737 cap_col = -1;
738 if (lnum == 1)
739 cap_col = 0;
740 capcol_lnum = 0;
741 }
742#endif
743
744 // handle Visual active in this window
745 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
746 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100747 pos_T *top, *bot;
748
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200749 if (LTOREQ_POS(curwin->w_cursor, VIsual))
750 {
751 // Visual is after curwin->w_cursor
752 top = &curwin->w_cursor;
753 bot = &VIsual;
754 }
755 else
756 {
757 // Visual is before curwin->w_cursor
758 top = &VIsual;
759 bot = &curwin->w_cursor;
760 }
761 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
762 if (VIsual_mode == Ctrl_V)
763 {
764 // block mode
765 if (lnum_in_visual_area)
766 {
767 fromcol = wp->w_old_cursor_fcol;
768 tocol = wp->w_old_cursor_lcol;
769 }
770 }
771 else
772 {
773 // non-block mode
774 if (lnum > top->lnum && lnum <= bot->lnum)
775 fromcol = 0;
776 else if (lnum == top->lnum)
777 {
778 if (VIsual_mode == 'V') // linewise
779 fromcol = 0;
780 else
781 {
782 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
783 if (gchar_pos(top) == NUL)
784 tocol = fromcol + 1;
785 }
786 }
787 if (VIsual_mode != 'V' && lnum == bot->lnum)
788 {
789 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
790 {
791 fromcol = -10;
792 tocol = MAXCOL;
793 }
794 else if (bot->col == MAXCOL)
795 tocol = MAXCOL;
796 else
797 {
798 pos = *bot;
799 if (*p_sel == 'e')
800 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
801 else
802 {
803 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
804 ++tocol;
805 }
806 }
807 }
808 }
809
810 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200811 if (!highlight_match && lnum == curwin->w_cursor.lnum
812 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200813#ifdef FEAT_GUI
814 && !gui.in_use
815#endif
816 )
817 noinvcur = TRUE;
818
819 // if inverting in this line set area_highlighting
820 if (fromcol >= 0)
821 {
822 area_highlighting = TRUE;
823 vi_attr = HL_ATTR(HLF_V);
824#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
825 if ((clip_star.available && !clip_star.owned
826 && clip_isautosel_star())
827 || (clip_plus.available && !clip_plus.owned
828 && clip_isautosel_plus()))
829 vi_attr = HL_ATTR(HLF_VNC);
830#endif
831 }
832 }
833
834 // handle 'incsearch' and ":s///c" highlighting
835 else if (highlight_match
836 && wp == curwin
837 && lnum >= curwin->w_cursor.lnum
838 && lnum <= curwin->w_cursor.lnum + search_match_lines)
839 {
840 if (lnum == curwin->w_cursor.lnum)
841 getvcol(curwin, &(curwin->w_cursor),
842 (colnr_T *)&fromcol, NULL, NULL);
843 else
844 fromcol = 0;
845 if (lnum == curwin->w_cursor.lnum + search_match_lines)
846 {
847 pos.lnum = lnum;
848 pos.col = search_match_endcol;
849 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
850 }
851 else
852 tocol = MAXCOL;
853 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100854 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200855 tocol = fromcol + 1;
856 area_highlighting = TRUE;
857 vi_attr = HL_ATTR(HLF_I);
858 }
859 }
860
861#ifdef FEAT_DIFF
862 filler_lines = diff_check(wp, lnum);
863 if (filler_lines < 0)
864 {
865 if (filler_lines == -1)
866 {
867 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100868 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200869 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100870 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200871 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100872 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200873 }
874 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100875 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200876 filler_lines = 0;
877 area_highlighting = TRUE;
878 }
879 if (lnum == wp->w_topline)
880 filler_lines = wp->w_topfill;
881 filler_todo = filler_lines;
882#endif
883
884#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100885 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000886 if (sign_present)
887 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888#endif
889
890#ifdef LINE_ATTR
891# ifdef FEAT_SIGNS
892 // If this line has a sign with line highlighting set line_attr.
893 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200894 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200895# endif
896# if defined(FEAT_QUICKFIX)
897 // Highlight the current line in the quickfix window.
898 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
899 line_attr = HL_ATTR(HLF_QFL);
900# endif
901 if (line_attr != 0)
902 area_highlighting = TRUE;
903#endif
904
905 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
906 ptr = line;
907
908#ifdef FEAT_SPELL
909 if (has_spell && !number_only)
910 {
911 // For checking first word with a capital skip white space.
912 if (cap_col == 0)
913 cap_col = getwhitecols(line);
914
915 // To be able to spell-check over line boundaries copy the end of the
916 // current line into nextline[]. Above the start of the next line was
917 // copied to nextline[SPWORDLEN].
918 if (nextline[SPWORDLEN] == NUL)
919 {
920 // No next line or it is empty.
921 nextlinecol = MAXCOL;
922 nextline_idx = 0;
923 }
924 else
925 {
926 v = (long)STRLEN(line);
927 if (v < SPWORDLEN)
928 {
929 // Short line, use it completely and append the start of the
930 // next line.
931 nextlinecol = 0;
932 mch_memmove(nextline, line, (size_t)v);
933 STRMOVE(nextline + v, nextline + SPWORDLEN);
934 nextline_idx = v + 1;
935 }
936 else
937 {
938 // Long line, use only the last SPWORDLEN bytes.
939 nextlinecol = v - SPWORDLEN;
940 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
941 nextline_idx = SPWORDLEN + 1;
942 }
943 }
944 }
945#endif
946
947 if (wp->w_p_list)
948 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100949 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200950 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100951 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100952 || wp->w_lcs_chars.trail
953 || wp->w_lcs_chars.lead
954 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100956
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100958 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959 {
960 trailcol = (colnr_T)STRLEN(ptr);
961 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
962 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100963 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100965 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100966 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100967 {
968 leadcol = 0;
969 while (VIM_ISWHITE(ptr[leadcol]))
970 ++leadcol;
971 if (ptr[leadcol] == NUL)
972 // in a line full of spaces all of them are treated as trailing
973 leadcol = (colnr_T)0;
974 else
975 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100976 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100977 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978 }
979
980 wcr_attr = get_wcr_attr(wp);
981 if (wcr_attr != 0)
982 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100983 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 area_highlighting = TRUE;
985 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200986
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100987#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100989 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990#endif
991
992 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
993 // first character to be displayed.
994 if (wp->w_p_wrap)
995 v = wp->w_skipcol;
996 else
997 v = wp->w_leftcol;
998 if (v > 0 && !number_only)
999 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001000 char_u *prev_ptr = ptr;
1001 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001002 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001005 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001007 charsize = win_lbr_chartabsize(&cts, NULL);
1008 cts.cts_vcol += charsize;
1009 prev_ptr = cts.cts_ptr;
1010 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001012 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001013 ptr = cts.cts_ptr;
1014 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015
1016 // When:
1017 // - 'cuc' is set, or
1018 // - 'colorcolumn' is set, or
1019 // - 'virtualedit' is set, or
1020 // - the visual mode is active,
1021 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001022 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001023#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001024 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001025#endif
1026 virtual_active() ||
1027 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001028 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029
1030 // Handle a character that's not completely on the screen: Put ptr at
1031 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001032 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001034 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 ptr = prev_ptr;
1036 // If the character fits on the screen, don't need to skip it.
1037 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001038 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1039 && wlv.col == 0)
1040 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001041 }
1042
1043 // Adjust for when the inverted text is before the screen,
1044 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001045 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001046 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001047 else if (fromcol >= 0 && fromcol < wlv.vcol)
1048 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049
1050#ifdef FEAT_LINEBREAK
1051 // When w_skipcol is non-zero, first line needs 'showbreak'
1052 if (wp->w_p_wrap)
1053 need_showbreak = TRUE;
1054#endif
1055#ifdef FEAT_SPELL
1056 // When spell checking a word we need to figure out the start of the
1057 // word and if it's badly spelled or not.
1058 if (has_spell)
1059 {
1060 int len;
1061 colnr_T linecol = (colnr_T)(ptr - line);
1062 hlf_T spell_hlf = HLF_COUNT;
1063
1064 pos = wp->w_cursor;
1065 wp->w_cursor.lnum = lnum;
1066 wp->w_cursor.col = linecol;
1067 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1068
1069 // spell_move_to() may call ml_get() and make "line" invalid
1070 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1071 ptr = line + linecol;
1072
1073 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1074 {
1075 // no bad word found at line start, don't check until end of a
1076 // word
1077 spell_hlf = HLF_COUNT;
1078 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1079 }
1080 else
1081 {
1082 // bad word found, use attributes until end of word
1083 word_end = wp->w_cursor.col + len + 1;
1084
1085 // Turn index into actual attributes.
1086 if (spell_hlf != HLF_COUNT)
1087 spell_attr = highlight_attr[spell_hlf];
1088 }
1089 wp->w_cursor = pos;
1090
1091# ifdef FEAT_SYN_HL
1092 // Need to restart syntax highlighting for this line.
1093 if (has_syntax)
1094 syntax_start(wp, lnum);
1095# endif
1096 }
1097#endif
1098 }
1099
1100 // Correct highlighting for cursor that can't be disabled.
1101 // Avoids having to check this for each character.
1102 if (fromcol >= 0)
1103 {
1104 if (noinvcur)
1105 {
1106 if ((colnr_T)fromcol == wp->w_virtcol)
1107 {
1108 // highlighting starts at cursor, let it start just after the
1109 // cursor
1110 fromcol_prev = fromcol;
1111 fromcol = -1;
1112 }
1113 else if ((colnr_T)fromcol < wp->w_virtcol)
1114 // restart highlighting after the cursor
1115 fromcol_prev = wp->w_virtcol;
1116 }
1117 if (fromcol >= tocol)
1118 fromcol = -1;
1119 }
1120
1121#ifdef FEAT_SEARCH_EXTRA
1122 if (!number_only)
1123 {
1124 v = (long)(ptr - line);
1125 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1126 &line, &screen_search_hl,
1127 &search_attr);
1128 ptr = line + v; // "line" may have been updated
1129 }
1130#endif
1131
1132#ifdef FEAT_SYN_HL
1133 // Cursor line highlighting for 'cursorline' in the current window.
1134 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1135 {
1136 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001137 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 if (!(wp == curwin && VIsual_active)
1139 && wp->w_p_culopt_flags != CULOPT_NBR)
1140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001141 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1143
1144 // Only set line_attr here when "screenline" is not present in
1145 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001146 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 {
1148 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001149# ifdef FEAT_SIGNS
1150 // Combine the 'cursorline' and sign highlighting, depending on
1151 // the sign priority.
1152 if (sign_present && sattr.sat_linehl > 0)
1153 {
1154 if (sattr.sat_priority >= 100)
1155 line_attr = hl_combine_attr(cul_attr, line_attr);
1156 else
1157 line_attr = hl_combine_attr(line_attr, cul_attr);
1158 }
1159 else
1160# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001161# if defined(FEAT_QUICKFIX)
1162 line_attr = hl_combine_attr(line_attr, cul_attr);
1163# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001164 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001165# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 }
1167 else
1168 {
1169 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1171 }
1172 area_highlighting = TRUE;
1173 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 }
1175#endif
1176
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001177#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 {
1179 char_u *prop_start;
1180
1181 text_prop_count = get_text_props(wp->w_buffer, lnum,
1182 &prop_start, FALSE);
1183 if (text_prop_count > 0)
1184 {
1185 // Make a copy of the properties, so that they are properly
1186 // aligned.
1187 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1188 if (text_props != NULL)
1189 mch_memmove(text_props, prop_start,
1190 text_prop_count * sizeof(textprop_T));
1191
1192 // Allocate an array for the indexes.
1193 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1194 area_highlighting = TRUE;
1195 extra_check = TRUE;
1196 }
1197 }
1198#endif
1199
Bram Moolenaar1306b362022-08-06 15:59:06 +01001200 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201
1202 // Repeat for the whole displayed line.
1203 for (;;)
1204 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001205 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001207 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208#endif
1209#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001210 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001212
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001214 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001216#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001217 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001218 {
1219 cul_attr = 0;
1220 line_attr = line_attr_save;
1221 }
1222#endif
1223
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001225 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001227 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 if (cmdwin_type != 0 && wp == curwin)
1229 {
1230 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001231 wlv.n_extra = 1;
1232 wlv.c_extra = cmdwin_type;
1233 wlv.c_final = NUL;
1234 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 }
1236 }
1237#endif
1238
1239#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001240 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 {
1242 int fdc = compute_foldcolumn(wp, 0);
1243
Bram Moolenaar1306b362022-08-06 15:59:06 +01001244 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 if (fdc > 0)
1246 {
1247 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1248 // already be in use.
1249 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001250 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 if (p_extra_free != NULL)
1252 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001253 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001254 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001255 p_extra_free[wlv.n_extra] = NUL;
1256 wlv.p_extra = p_extra_free;
1257 wlv.c_extra = NUL;
1258 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001259 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001260 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001261 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1262 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001263 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001264 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 }
1266 }
1267 }
1268#endif
1269
1270#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001271 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001273 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 // Show the sign column when there are any signs in this
1275 // buffer or when using Netbeans.
1276 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001277 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1278 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 }
1280#endif
1281
Bram Moolenaar1306b362022-08-06 15:59:06 +01001282 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001284 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 // Display the absolute or relative line number. After the
1286 // first fill with blanks when the 'n' flag isn't in 'cpo'
1287 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001288 && (wlv.row == startrow + filler_lines
1289 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 {
1291#ifdef FEAT_SIGNS
1292 // If 'signcolumn' is set to 'number' and a sign is present
1293 // in 'lnum', then display the sign instead of the line
1294 // number.
1295 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1296 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001297 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1298 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 else
1300#endif
1301 {
1302 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001303 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304 {
1305 long num;
1306 char *fmt = "%*ld ";
1307
1308 if (wp->w_p_nu && !wp->w_p_rnu)
1309 // 'number' + 'norelativenumber'
1310 num = (long)lnum;
1311 else
1312 {
1313 // 'relativenumber', don't use negative numbers
1314 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1315 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1316 {
1317 // 'number' + 'relativenumber'
1318 num = lnum;
1319 fmt = "%-*ld ";
1320 }
1321 }
1322
1323 sprintf((char *)extra, fmt,
1324 number_width(wp), num);
1325 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001326 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1327 ++wlv.p_extra)
1328 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329#ifdef FEAT_RIGHTLEFT
1330 if (wp->w_p_rl) // reverse line numbers
1331 {
1332 char_u *p1, *p2;
1333 int t;
1334
1335 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001336 p2 = skipwhite(extra);
1337 p2 = skiptowhite(p2) - 1;
1338 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 {
1340 t = *p1;
1341 *p1 = *p2;
1342 *p2 = t;
1343 }
1344 }
1345#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001346 wlv.p_extra = extra;
1347 wlv.c_extra = NUL;
1348 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 }
1350 else
1351 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001352 wlv.c_extra = ' ';
1353 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 wlv.n_extra = number_width(wp) + 1;
1356 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357#ifdef FEAT_SYN_HL
1358 // When 'cursorline' is set highlight the line number of
1359 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001360 // When 'cursorlineopt' does not have "line" only
1361 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 // TODO: Can we use CursorLine instead of CursorLineNr
1363 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001364 if (wp->w_p_cul
1365 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001367 && (wlv.row == startrow + filler_lines
1368 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001369 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001370 wlv.char_attr = hl_combine_attr(wcr_attr,
1371 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001373 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1374 && HL_ATTR(HLF_LNA) != 0)
1375 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001376 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001377 HL_ATTR(HLF_LNA));
1378 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1379 && HL_ATTR(HLF_LNB) != 0)
1380 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001381 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001382 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 }
James McCoya80aad72021-12-22 19:45:28 +00001384#ifdef FEAT_SIGNS
1385 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001386 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001387#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 }
1389 }
1390
1391#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001392 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1393 && wlv.n_extra == 0
1394 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001396 wlv.draw_state = WL_BRI;
1397 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1398 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001400 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401
1402 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001403 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001405 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001407 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408# ifdef FEAT_DIFF
1409 && filler_lines == 0
1410# endif
1411 )
1412 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001413 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001415 if (wlv.diff_hlf != (hlf_T)0)
1416 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 wlv.p_extra = NULL;
1419 wlv.c_extra = ' ';
1420 wlv.c_final = NUL;
1421 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001423 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001424 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001425 wlv.n_extra -= win_col_off2(wp);
1426 if (wlv.n_extra < 0)
1427 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001428 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001429 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001430 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 // Correct end of highlighted area for 'breakindent',
1432 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001433 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001434 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 }
1436 }
1437#endif
1438
1439#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001440 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001442 char_u *sbr;
1443
Bram Moolenaar1306b362022-08-06 15:59:06 +01001444 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445# ifdef FEAT_DIFF
1446 if (filler_todo > 0)
1447 {
1448 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001449 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001451 wlv.c_extra = '-';
1452 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 }
1454 else
1455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001456 wlv.c_extra = wp->w_fill_chars.diff;
1457 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 }
1459# ifdef FEAT_RIGHTLEFT
1460 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001461 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 else
1463# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001464 wlv.n_extra = wp->w_width - wlv.col;
1465 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 }
1467# endif
1468# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001469 sbr = get_showbreak_value(wp);
1470 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 {
1472 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001473 wlv.p_extra = sbr;
1474 wlv.c_extra = NUL;
1475 wlv.c_final = NUL;
1476 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001477 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1478 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001479 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 // Correct end of highlighted area for 'showbreak',
1481 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001482 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001483 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001485 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1486 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487# ifdef FEAT_SYN_HL
1488 // combine 'showbreak' with 'cursorline'
1489 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001490 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1491 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492# endif
1493 }
1494# endif
1495 }
1496#endif
1497
Bram Moolenaar1306b362022-08-06 15:59:06 +01001498 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001500 wlv.draw_state = WL_LINE;
1501 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 {
1503 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 wlv.n_extra = wlv.saved_n_extra;
1505 wlv.c_extra = wlv.saved_c_extra;
1506 wlv.c_final = wlv.saved_c_final;
1507 wlv.p_extra = wlv.saved_p_extra;
1508 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 }
1510 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001511 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 }
1513 }
1514#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001515 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001516 && wlv.vcol >= left_curline_col
1517 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001519 cul_attr = HL_ATTR(HLF_CUL);
1520 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521 }
1522#endif
1523
1524 // When still displaying '$' of change command, stop at cursor.
1525 // When only displaying the (relative) line number and that's done,
1526 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001527 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001528 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530#ifdef FEAT_DIFF
1531 && filler_todo <= 0
1532#endif
1533 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001535 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1536 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 // Pretend we have finished updating the window. Except when
1538 // 'cursorcolumn' is set.
1539#ifdef FEAT_SYN_HL
1540 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001541 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 else
1543#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001544 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 break;
1546 }
1547
Bram Moolenaar1306b362022-08-06 15:59:06 +01001548 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
1550 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001551 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001552 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 && (*mb_ptr2cells)(ptr) > 1)
1554 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001555 && vcol_prev < wlv.vcol // not at margin
1556 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 area_attr = vi_attr; // start highlighting
1558 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001559 && (wlv.vcol == tocol
1560 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 area_attr = 0; // stop highlighting
1562
1563#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaar1306b362022-08-06 15:59:06 +01001564 if (!wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 {
1566 // Check for start/end of 'hlsearch' and other matches.
1567 // After end, check for start/end of next match.
1568 // When another match, have to check for start again.
1569 v = (long)(ptr - line);
1570 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1571 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001572 &match_conc, did_line_attr, lcs_eol_one,
1573 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001575 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001576
1577 // Do not allow a conceal over EOL otherwise EOL will be missed
1578 // and bad things happen.
1579 if (*ptr == NUL)
1580 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001581 }
1582#endif
1583
1584#ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001585 if (wlv.diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001587 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1588 && wlv.n_extra == 0)
1589 wlv.diff_hlf = HLF_TXD; // changed text
1590 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1591 && wlv.n_extra == 0)
1592 wlv.diff_hlf = HLF_CHD; // changed line
1593 line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1595 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01001596 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001597 && wlv.vcol <= right_curline_col)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 line_attr = hl_combine_attr(
1599 line_attr, HL_ATTR(HLF_CUL));
1600 }
1601#endif
1602
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001603#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 if (text_props != NULL)
1605 {
1606 int pi;
1607 int bcol = (int)(ptr - line);
1608
Bram Moolenaar1306b362022-08-06 15:59:06 +01001609 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001610# ifdef FEAT_LINEBREAK
1611 && !in_linebreak
1612# endif
1613 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 --bcol; // still working on the previous char, e.g. Tab
1615
1616 // Check if any active property ends.
1617 for (pi = 0; pi < text_props_active; ++pi)
1618 {
1619 int tpi = text_prop_idxs[pi];
1620
1621 if (bcol >= text_props[tpi].tp_col - 1
1622 + text_props[tpi].tp_len)
1623 {
1624 if (pi + 1 < text_props_active)
1625 mch_memmove(text_prop_idxs + pi,
1626 text_prop_idxs + pi + 1,
1627 sizeof(int)
1628 * (text_props_active - (pi + 1)));
1629 --text_props_active;
1630 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001631# ifdef FEAT_LINEBREAK
1632 // not exactly right but should work in most cases
1633 if (in_linebreak && syntax_attr == text_prop_attr)
1634 syntax_attr = 0;
1635# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 }
1637 }
1638
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001639# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001640 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001641 // not on the next char yet, don't start another prop
1642 --bcol;
1643# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 // Add any text property that starts in this column.
1645 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001646 && (text_props[text_prop_next].tp_col == MAXCOL
1647 ? *ptr == NUL
1648 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001649 {
1650 if (bcol <= text_props[text_prop_next].tp_col - 1
1651 + text_props[text_prop_next].tp_len)
1652 text_prop_idxs[text_props_active++] = text_prop_next;
1653 ++text_prop_next;
1654 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655
1656 text_prop_attr = 0;
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001657 text_prop_flags = 0;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001658 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001659 text_prop_id = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001660 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001662 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001663 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001664 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001665
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 // Sort the properties on priority and/or starting last.
1667 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001668 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 current_text_props = text_props;
1670 current_buf = wp->w_buffer;
1671 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1672 sizeof(int), text_prop_compare);
1673
1674 for (pi = 0; pi < text_props_active; ++pi)
1675 {
1676 int tpi = text_prop_idxs[pi];
1677 proptype_T *pt = text_prop_type_by_id(
1678 wp->w_buffer, text_props[tpi].tp_type);
1679
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001680 if (pt != NULL && pt->pt_hl_id > 0
1681 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001683 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 text_prop_type = pt;
1685 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001686 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001687 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001688 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001689 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001690 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 }
1692 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001693 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001694 && -text_prop_id
1695 <= wp->w_buffer->b_textprop_text.ga_len)
1696 {
1697 char_u *p = ((char_u **)wp->w_buffer
1698 ->b_textprop_text.ga_data)[
1699 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700
1701 // reset the ID in the copy to avoid it being used
1702 // again
1703 text_props[used_tpi].tp_id = -MAXCOL;
1704
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001705 if (p != NULL)
1706 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001707 int right = (text_props[used_tpi].tp_flags
1708 & TP_FLAG_ALIGN_RIGHT);
1709 int below = (text_props[used_tpi].tp_flags
1710 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001711 int wrap = (text_props[used_tpi].tp_flags
1712 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001713
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 wlv.p_extra = p;
1715 wlv.c_extra = NUL;
1716 wlv.c_final = NUL;
1717 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001718 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001719 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001720 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001721 if (*ptr == NUL)
1722 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001723 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001724#ifdef FEAT_LINEBREAK
1725 if (below || right)
1726 {
1727 // no 'showbreak' before "below" text property
1728 // or after "right" text property
1729 need_showbreak = FALSE;
1730 dont_use_showbreak = TRUE;
1731 }
1732#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001733 // Keep in sync with where
1734 // textprop_size_after_trunc() is called in
1735 // win_lbr_chartabsize().
1736 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001737 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001738 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001739 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001740 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001741 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 ? vim_strsize(wlv.p_extra)
1743 : textprop_size_after_trunc(wp,
1744 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001745
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 if (wrap || right || below
1747 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001748 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001749 // Right-align: fill with spaces
1750 if (right)
1751 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001752 if (added < 0
1753 || (below
1754 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001755 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001756 added = 0;
1757 // add 1 for NUL, 2 for when '…' is used
1758 l = alloc(n_used + added + 3);
1759 if (l != NULL)
1760 {
1761 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762 vim_strncpy(l + added, wlv.p_extra,
1763 n_used);
1764 if (n_used < wlv.n_extra)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001765 {
1766 char_u *lp = l + added + n_used - 1;
1767
1768 if (has_mbyte)
1769 {
1770 // change last character to '…'
1771 lp -= (*mb_head_off)(l, lp);
1772 STRCPY(lp, "…");
1773 n_used = lp - l + 3;
1774 }
1775 else
1776 // change last character to '>'
1777 *lp = '>';
1778 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001779 vim_free(p_extra_free2);
1780 wlv.p_extra = p_extra_free2 = l;
1781 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001782 n_attr_skip = added;
1783 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001784 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001785
1786 // When 'wrap' is off then for "below" we need
1787 // to start a new line explictly.
1788 if (!wp->w_p_wrap)
1789 {
1790 draw_screen_line(wp, &wlv);
1791
1792 // When line got too long for screen break
1793 // here.
1794 if (wlv.row == endrow)
1795 {
1796 ++wlv.row;
1797 break;
1798 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 win_line_start(wp, &wlv, TRUE);
1800 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001801 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001802 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001803 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001804
1805 // If another text prop follows the condition below at
1806 // the last window column must know.
1807 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001808 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001810 else if (text_prop_next < text_prop_count
1811 && text_props[text_prop_next].tp_col == MAXCOL
1812 && *ptr != NUL
1813 && ptr[mb_ptr2len(ptr)] == NUL)
1814 // When at last-but-one character and a text property
1815 // follows after it, we may need to flush the line after
1816 // displaying that character.
1817 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 }
1819#endif
1820
Bram Moolenaara74fda62019-10-19 17:38:03 +02001821#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001823 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001824 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001825# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001826 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001827 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001828# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001829 // Get syntax attribute.
1830 if (has_syntax)
1831 {
1832 // Get the syntax attribute for the character. If there
1833 // is an error, disable syntax highlighting.
1834 save_did_emsg = did_emsg;
1835 did_emsg = FALSE;
1836
1837 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001838 if (v == prev_syntax_col)
1839 // at same column again
1840 syntax_attr = prev_syntax_attr;
1841 else
1842 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001843# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001844 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001845# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001846 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001847# ifdef FEAT_SPELL
1848 has_spell ? &can_spell :
1849# endif
1850 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001851 prev_syntax_col = v;
1852 prev_syntax_attr = syntax_attr;
1853 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001854
Bram Moolenaar34390282019-10-16 14:38:26 +02001855 if (did_emsg)
1856 {
1857 wp->w_s->b_syn_error = TRUE;
1858 has_syntax = FALSE;
1859 syntax_attr = 0;
1860 }
1861 else
1862 did_emsg = save_did_emsg;
1863# ifdef SYN_TIME_LIMIT
1864 if (wp->w_s->b_syn_slow)
1865 has_syntax = FALSE;
1866# endif
1867
1868 // Need to get the line again, a multi-line regexp may
1869 // have made it invalid.
1870 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1871 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001872 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001873# ifdef FEAT_CONCEAL
1874 // no concealing past the end of the line, it interferes
1875 // with line highlighting
1876 if (*ptr == NUL)
1877 syntax_flags = 0;
1878 else
1879 syntax_flags = get_syntax_info(&syntax_seqnr);
1880# endif
1881 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001882 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001883# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001884 // Combine text property highlight into syntax highlight.
1885 if (text_prop_type != NULL)
1886 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001887 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001888 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1889 else
1890 syntax_attr = text_prop_attr;
1891 }
1892# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001893#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001894
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 // Decide which of the highlight attributes to use.
1896 attr_pri = TRUE;
1897#ifdef LINE_ATTR
1898 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001899 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001900 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001901 if (!highlight_match)
1902 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001904# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001906# endif
1907 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001909 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001910 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001911# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001912 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001913# endif
1914 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001916 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1917 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 {
1919 // Use line_attr when not in the Visual or 'incsearch' area
1920 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001921# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001923# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001925# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 attr_pri = FALSE;
1927 }
1928#else
1929 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001930 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001932 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933#endif
1934 else
1935 {
1936 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001939#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001940 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001941#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001943#ifdef FEAT_PROP_POPUP
1944 // override with text property highlight when "override" is TRUE
1945 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001947#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001949
1950 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001951 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001952 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001953 if (wlv.char_attr == 0)
1954 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001955 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001956 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001957 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958
1959 // Get the next character to put on the screen.
1960
1961 // The "p_extra" points to the extra stuff that is inserted to
1962 // represent special characters (non-printable stuff) and other
1963 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001964 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1966 // "p_extra[n_extra]".
1967 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
1973 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001974 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1975 if (enc_utf8 && utf_char2len(c) > 1)
1976 {
1977 mb_utf8 = TRUE;
1978 u8cc[0] = 0;
1979 c = 0xc0;
1980 }
1981 else
1982 mb_utf8 = FALSE;
1983 }
1984 else
1985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 if (has_mbyte)
1988 {
1989 mb_c = c;
1990 if (enc_utf8)
1991 {
1992 // If the UTF-8 character is more than one byte:
1993 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 mb_l = 1;
1998 else if (mb_l > 1)
1999 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002000 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 mb_utf8 = TRUE;
2002 c = 0xc0;
2003 }
2004 }
2005 else
2006 {
2007 // if this is a DBCS character, put it in "mb_c"
2008 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002009 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010 mb_l = 1;
2011 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002012 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 }
2014 if (mb_l == 0) // at the NUL at end-of-line
2015 mb_l = 1;
2016
2017 // If a double-width char doesn't fit display a '>' in the
2018 // last column.
2019 if ((
2020# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002023 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024 && (*mb_char2cells)(mb_c) == 2)
2025 {
2026 c = '>';
2027 mb_c = c;
2028 mb_l = 1;
2029 mb_utf8 = FALSE;
2030 multi_attr = HL_ATTR(HLF_AT);
2031#ifdef FEAT_SYN_HL
2032 if (cul_attr)
2033 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2034#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002035 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 // put the pointer back to output the double-width
2038 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002039 ++wlv.n_extra;
2040 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041 }
2042 else
2043 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002044 wlv.n_extra -= mb_l - 1;
2045 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002046 }
2047 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002048 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 --wlv.n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002051#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002052 if (wlv.n_extra <= 0)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002053 in_linebreak = FALSE;
2054#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 }
2056 else
2057 {
2058#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002059 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002061 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002062
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002063 // Get a character from the line itself.
2064 c = *ptr;
2065#ifdef FEAT_LINEBREAK
2066 c0 = *ptr;
2067#endif
2068 if (has_mbyte)
2069 {
2070 mb_c = c;
2071 if (enc_utf8)
2072 {
2073 // If the UTF-8 character is more than one byte: Decode it
2074 // into "mb_c".
2075 mb_l = utfc_ptr2len(ptr);
2076 mb_utf8 = FALSE;
2077 if (mb_l > 1)
2078 {
2079 mb_c = utfc_ptr2char(ptr, u8cc);
2080 // Overlong encoded ASCII or ASCII with composing char
2081 // is displayed normally, except a NUL.
2082 if (mb_c < 0x80)
2083 {
2084 c = mb_c;
2085#ifdef FEAT_LINEBREAK
2086 c0 = mb_c;
2087#endif
2088 }
2089 mb_utf8 = TRUE;
2090
2091 // At start of the line we can have a composing char.
2092 // Draw it as a space with a composing char.
2093 if (utf_iscomposing(mb_c))
2094 {
2095 int i;
2096
2097 for (i = Screen_mco - 1; i > 0; --i)
2098 u8cc[i] = u8cc[i - 1];
2099 u8cc[0] = mb_c;
2100 mb_c = ' ';
2101 }
2102 }
2103
2104 if ((mb_l == 1 && c >= 0x80)
2105 || (mb_l >= 1 && mb_c == 0)
2106 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2107 {
2108 // Illegal UTF-8 byte: display as <xx>.
2109 // Non-BMP character : display as ? or fullwidth ?.
2110 transchar_hex(extra, mb_c);
2111# ifdef FEAT_RIGHTLEFT
2112 if (wp->w_p_rl) // reverse
2113 rl_mirror(extra);
2114# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002115 wlv.p_extra = extra;
2116 c = *wlv.p_extra;
2117 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002119 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2120 wlv.c_extra = NUL;
2121 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002122 if (area_attr == 0 && search_attr == 0)
2123 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002124 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002125 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002126 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 }
2129 }
2130 else if (mb_l == 0) // at the NUL at end-of-line
2131 mb_l = 1;
2132#ifdef FEAT_ARABIC
2133 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2134 {
2135 // Do Arabic shaping.
2136 int pc, pc1, nc;
2137 int pcc[MAX_MCO];
2138
2139 // The idea of what is the previous and next
2140 // character depends on 'rightleft'.
2141 if (wp->w_p_rl)
2142 {
2143 pc = prev_c;
2144 pc1 = prev_c1;
2145 nc = utf_ptr2char(ptr + mb_l);
2146 prev_c1 = u8cc[0];
2147 }
2148 else
2149 {
2150 pc = utfc_ptr2char(ptr + mb_l, pcc);
2151 nc = prev_c;
2152 pc1 = pcc[0];
2153 }
2154 prev_c = mb_c;
2155
2156 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2157 }
2158 else
2159 prev_c = mb_c;
2160#endif
2161 }
2162 else // enc_dbcs
2163 {
2164 mb_l = MB_BYTE2LEN(c);
2165 if (mb_l == 0) // at the NUL at end-of-line
2166 mb_l = 1;
2167 else if (mb_l > 1)
2168 {
2169 // We assume a second byte below 32 is illegal.
2170 // Hopefully this is OK for all double-byte encodings!
2171 if (ptr[1] >= 32)
2172 mb_c = (c << 8) + ptr[1];
2173 else
2174 {
2175 if (ptr[1] == NUL)
2176 {
2177 // head byte at end of line
2178 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002179 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 }
2181 else
2182 {
2183 // illegal tail byte
2184 mb_l = 2;
2185 STRCPY(extra, "XX");
2186 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 wlv.p_extra = extra;
2188 wlv.n_extra = (int)STRLEN(extra) - 1;
2189 wlv.c_extra = NUL;
2190 wlv.c_final = NUL;
2191 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 if (area_attr == 0 && search_attr == 0)
2193 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002195 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002196 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 // save current attr
2198 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 }
2200 mb_c = c;
2201 }
2202 }
2203 }
2204 // If a double-width char doesn't fit display a '>' in the
2205 // last column; the character is displayed at the start of the
2206 // next line.
2207 if ((
2208# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002209 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002211 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 && (*mb_char2cells)(mb_c) == 2)
2213 {
2214 c = '>';
2215 mb_c = c;
2216 mb_utf8 = FALSE;
2217 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002218 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 // Put pointer back so that the character will be
2220 // displayed at the start of the next line.
2221 --ptr;
2222#ifdef FEAT_CONCEAL
2223 did_decrement_ptr = TRUE;
2224#endif
2225 }
2226 else if (*ptr != NUL)
2227 ptr += mb_l - 1;
2228
2229 // If a double-width char doesn't fit at the left side display
2230 // a '<' in the first column. Don't do this for unprintable
2231 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002232 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 wlv.n_extra = 1;
2235 wlv.c_extra = MB_FILLER_CHAR;
2236 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002237 c = ' ';
2238 if (area_attr == 0 && search_attr == 0)
2239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002241 extra_attr = hl_combine_attr(
2242 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002243 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 }
2245 mb_c = c;
2246 mb_utf8 = FALSE;
2247 mb_l = 1;
2248 }
2249
2250 }
2251 ++ptr;
2252
2253 if (extra_check)
2254 {
2255#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 // Check spelling (unless at the end of the line).
2257 // Only do this when there is no syntax highlighting, the
2258 // @Spell cluster is not used or the current syntax item
2259 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002260 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 if (has_spell && v >= word_end && v > cur_checked_col)
2262 {
2263 spell_attr = 0;
2264 if (c != 0 && (
2265# ifdef FEAT_SYN_HL
2266 !has_syntax ||
2267# endif
2268 can_spell))
2269 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002270 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271 int len;
2272 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002273
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002275 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276
2277 // Use nextline[] if possible, it has the start of the
2278 // next line concatenated.
2279 if ((prev_ptr - line) - nextlinecol >= 0)
2280 p = nextline + (prev_ptr - line) - nextlinecol;
2281 else
2282 p = prev_ptr;
2283 cap_col -= (int)(prev_ptr - line);
2284 len = spell_check(wp, p, &spell_hlf, &cap_col,
2285 nochange);
2286 word_end = v + len;
2287
2288 // In Insert mode only highlight a word that
2289 // doesn't touch the cursor.
2290 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002291 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 && wp->w_cursor.lnum == lnum
2293 && wp->w_cursor.col >=
2294 (colnr_T)(prev_ptr - line)
2295 && wp->w_cursor.col < (colnr_T)word_end)
2296 {
2297 spell_hlf = HLF_COUNT;
2298 spell_redraw_lnum = lnum;
2299 }
2300
2301 if (spell_hlf == HLF_COUNT && p != prev_ptr
2302 && (p - nextline) + len > nextline_idx)
2303 {
2304 // Remember that the good word continues at the
2305 // start of the next line.
2306 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002307 checked_col = (int)((p - nextline)
2308 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 }
2310
2311 // Turn index into actual attributes.
2312 if (spell_hlf != HLF_COUNT)
2313 spell_attr = highlight_attr[spell_hlf];
2314
2315 if (cap_col > 0)
2316 {
2317 if (p != prev_ptr
2318 && (p - nextline) + cap_col >= nextline_idx)
2319 {
2320 // Remember that the word in the next line
2321 // must start with a capital.
2322 capcol_lnum = lnum + 1;
2323 cap_col = (int)((p - nextline) + cap_col
2324 - nextline_idx);
2325 }
2326 else
2327 // Compute the actual column.
2328 cap_col += (int)(prev_ptr - line);
2329 }
2330 }
2331 }
2332 if (spell_attr != 0)
2333 {
2334 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002335 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2336 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002338 wlv.char_attr = hl_combine_attr(spell_attr,
2339 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340 }
2341#endif
2342#ifdef FEAT_LINEBREAK
2343 // Found last space before word: check for line break.
2344 if (wp->w_p_lbr && c0 == c
2345 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2346 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002347 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2348 : 0;
2349 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002350 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002352 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002353 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002354
2355 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002356 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002357 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002359 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2360 if (wlv.n_extra < 0)
2361 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002362 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002363 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002364 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002365 // line break, but for TABs the highlighting should
2366 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002367 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002368
Bram Moolenaar1306b362022-08-06 15:59:06 +01002369 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002372 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 wp->w_buffer->b_p_vts_array) - 1;
2374# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002376 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377# endif
2378
Bram Moolenaar1306b362022-08-06 15:59:06 +01002379 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2380 wlv.c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002381# if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002382 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002383 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002384# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 if (VIM_ISWHITE(c))
2386 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002387# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002388 if (c == TAB)
2389 // See "Tab alignment" below.
2390 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002391# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 if (!wp->w_p_list)
2393 c = ' ';
2394 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002395 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 }
2397#endif
2398
zeertzjqf14b8ba2021-09-10 16:58:30 +02002399 in_multispace = c == ' '
2400 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2401 if (!in_multispace)
2402 multispace_pos = 0;
2403
Bram Moolenaareed9d462021-02-15 20:38:25 +01002404 // 'list': Change char 160 to 'nbsp' and space to 'space'
2405 // setting in 'listchars'. But not when the character is
2406 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 if (wp->w_p_list
2408 && ((((c == 160 && mb_l == 1)
2409 || (mb_utf8
2410 && ((mb_c == 160 && mb_l == 2)
2411 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002412 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 || (c == ' '
2414 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002415 && (wp->w_lcs_chars.space
2416 || (in_multispace
2417 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002418 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 && ptr - line <= trailcol)))
2420 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002421 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2422 {
2423 c = wp->w_lcs_chars.multispace[multispace_pos++];
2424 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2425 multispace_pos = 0;
2426 }
2427 else
2428 c = (c == ' ') ? wp->w_lcs_chars.space
2429 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 if (area_attr == 0 && search_attr == 0)
2431 {
2432 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002433 extra_attr = hl_combine_attr(wlv.win_attr,
2434 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002435 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002436 }
2437 mb_c = c;
2438 if (enc_utf8 && utf_char2len(c) > 1)
2439 {
2440 mb_utf8 = TRUE;
2441 u8cc[0] = 0;
2442 c = 0xc0;
2443 }
2444 else
2445 mb_utf8 = FALSE;
2446 }
2447
zeertzjq2e7cba32022-06-10 15:30:32 +01002448 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2449 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002451 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2452 && wp->w_lcs_chars.leadmultispace != NULL)
2453 {
2454 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002455 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2456 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002457 multispace_pos = 0;
2458 }
2459
2460 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2461 c = wp->w_lcs_chars.trail;
2462
2463 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2464 c = wp->w_lcs_chars.lead;
2465
zeertzjq2e7cba32022-06-10 15:30:32 +01002466 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002467 c = wp->w_lcs_chars.space;
2468
2469
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 if (!attr_pri)
2471 {
2472 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002473 extra_attr = hl_combine_attr(wlv.win_attr,
2474 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002475 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002476 }
2477 mb_c = c;
2478 if (enc_utf8 && utf_char2len(c) > 1)
2479 {
2480 mb_utf8 = TRUE;
2481 u8cc[0] = 0;
2482 c = 0xc0;
2483 }
2484 else
2485 mb_utf8 = FALSE;
2486 }
2487 }
2488
2489 // Handling of non-printable characters.
2490 if (!vim_isprintc(c))
2491 {
2492 // when getting a character from the file, we may have to
2493 // turn it into something else on the way to putting it
2494 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002495 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002496 {
2497 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002498 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002500 char_u *sbr = get_showbreak_value(wp);
2501
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 // only adjust the tab_len, when at the first column
2503 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002504 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2505 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506#endif
2507 // tab amount depends on current column
2508#ifdef FEAT_VARTABS
2509 tab_len = tabstop_padding(vcol_adjusted,
2510 wp->w_buffer->b_p_ts,
2511 wp->w_buffer->b_p_vts_array) - 1;
2512#else
2513 tab_len = (int)wp->w_buffer->b_p_ts
2514 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2515#endif
2516
2517#ifdef FEAT_LINEBREAK
2518 if (!wp->w_p_lbr || !wp->w_p_list)
2519#endif
2520 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002521 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522#ifdef FEAT_LINEBREAK
2523 else
2524 {
2525 char_u *p;
2526 int len;
2527 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002530# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002531 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002533 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002534
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002536 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 && old_boguscols > 0
2538 && wlv.n_extra > tab_len)
2539 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002540# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002542 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002543 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002544 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002545 if (wp->w_lcs_chars.tab3)
2546 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002547 if (wlv.n_extra > 0)
2548 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002549 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002551 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002553 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002554 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002555 vim_memset(p, ' ', len);
2556 p[len] = NUL;
2557 vim_free(p_extra_free);
2558 p_extra_free = p;
2559 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002561 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002563 if (*p == NUL)
2564 {
2565 tab_len = i;
2566 break;
2567 }
2568
2569 // if tab3 is given, use it for the last char
2570 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2571 lcs = wp->w_lcs_chars.tab3;
2572 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002573 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002575 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002576 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002577# ifdef FEAT_CONCEAL
2578 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2579 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002580 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002581 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002582# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 }
2585#endif
2586#ifdef FEAT_CONCEAL
2587 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002588 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589
2590 // Tab alignment should be identical regardless of
2591 // 'conceallevel' value. So tab compensates of all
2592 // previous concealed characters, and thus resets
2593 // vcol_off and boguscols accumulated so far in the
2594 // line. Note that the tab can be longer than
2595 // 'tabstop' when there are concealed characters.
2596 FIX_FOR_BOGUSCOLS;
2597
2598 // Make sure, the highlighting for the tab char will be
2599 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002600 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002602 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 tab_len += vc_saved;
2604 }
2605#endif
2606 mb_utf8 = FALSE; // don't draw as UTF-8
2607 if (wp->w_p_list)
2608 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002609 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002610 ? wp->w_lcs_chars.tab3
2611 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612#ifdef FEAT_LINEBREAK
2613 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002614 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 else
2616#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 wlv.c_extra = wp->w_lcs_chars.tab2;
2618 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002620 extra_attr = hl_combine_attr(wlv.win_attr,
2621 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002622 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 mb_c = c;
2624 if (enc_utf8 && utf_char2len(c) > 1)
2625 {
2626 mb_utf8 = TRUE;
2627 u8cc[0] = 0;
2628 c = 0xc0;
2629 }
2630 }
2631 else
2632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 wlv.c_final = NUL;
2634 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 c = ' ';
2636 }
2637 }
2638 else if (c == NUL
2639 && (wp->w_p_list
2640 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002641 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 && VIsual_mode != Ctrl_V
2643 && (
2644# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002645 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002647 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 && !(noinvcur
2649 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002650 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 && lcs_eol_one > 0)
2652 {
2653 // Display a '$' after the line or highlight an extra
2654 // character if the line break is included.
2655#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2656 // For a diff line the highlighting continues after the
2657 // "$".
2658 if (
2659# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002660 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661# ifdef LINE_ATTR
2662 &&
2663# endif
2664# endif
2665# ifdef LINE_ATTR
2666 line_attr == 0
2667# endif
2668 )
2669#endif
2670 {
2671 // In virtualedit, visual selections may extend
2672 // beyond end of line.
2673 if (area_highlighting && virtual_active()
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002674 && tocol != MAXCOL && wlv.vcol < tocol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002675 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676 else
2677 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002678 wlv.p_extra = at_end_str;
2679 wlv.n_extra = 1;
2680 wlv.c_extra = NUL;
2681 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 }
2683 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002684 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2685 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 else
2687 c = ' ';
2688 lcs_eol_one = -1;
2689 --ptr; // put it back at the NUL
2690 if (!attr_pri)
2691 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002692 extra_attr = hl_combine_attr(wlv.win_attr,
2693 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 n_attr = 1;
2695 }
2696 mb_c = c;
2697 if (enc_utf8 && utf_char2len(c) > 1)
2698 {
2699 mb_utf8 = TRUE;
2700 u8cc[0] = 0;
2701 c = 0xc0;
2702 }
2703 else
2704 mb_utf8 = FALSE; // don't draw as UTF-8
2705 }
2706 else if (c != NUL)
2707 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002708 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2709 if (wlv.n_extra == 0)
2710 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711#ifdef FEAT_RIGHTLEFT
2712 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002715 wlv.c_extra = NUL;
2716 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717#ifdef FEAT_LINEBREAK
2718 if (wp->w_p_lbr)
2719 {
2720 char_u *p;
2721
Bram Moolenaar1306b362022-08-06 15:59:06 +01002722 c = *wlv.p_extra;
2723 p = alloc(wlv.n_extra + 1);
2724 vim_memset(p, ' ', wlv.n_extra);
2725 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2726 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002727 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 }
2730 else
2731#endif
2732 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002733 wlv.n_extra = byte2cells(c) - 1;
2734 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 }
2736 if (!attr_pri)
2737 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002739 extra_attr = hl_combine_attr(wlv.win_attr,
2740 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 }
2743 mb_utf8 = FALSE; // don't draw as UTF-8
2744 }
2745 else if (VIsual_active
2746 && (VIsual_mode == Ctrl_V
2747 || VIsual_mode == 'v')
2748 && virtual_active()
2749 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002750 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 && (
2752#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002753 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002755 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 {
2757 c = ' ';
2758 --ptr; // put it back at the NUL
2759 }
2760#if defined(LINE_ATTR)
2761 else if ((
2762# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002763 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764# endif
2765# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002766 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767# endif
2768 line_attr != 0
2769 ) && (
2770# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002771 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002773 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002775 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776# endif
2777 < wp->w_width)))
2778 {
2779 // Highlight until the right side of the window
2780 c = ' ';
2781 --ptr; // put it back at the NUL
2782
2783 // Remember we do the char for line highlighting.
2784 ++did_line_attr;
2785
2786 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002789 || (wp->w_p_list &&
2790 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002791 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 wlv.diff_hlf = HLF_CHD;
2796 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2800 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002801 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002802 || (wlv.vcol >= left_curline_col
2803 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 wlv.char_attr = hl_combine_attr(
2805 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 }
2807 }
2808# endif
2809# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002810 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002813 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2814 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 if (!wlv.cul_screenline
2817 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 wlv.char_attr = hl_combine_attr(
2820 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 }
2822 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2824 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 }
2826# endif
2827 }
2828#endif
2829 }
2830
2831#ifdef FEAT_CONCEAL
2832 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002833 && (wp != curwin || lnum != wp->w_cursor.lnum
2834 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2836 && !(lnum_in_visual_area
2837 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2838 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002840 if (((prev_syntax_id != syntax_seqnr
2841 && (syntax_flags & HL_CONCEAL) != 0)
2842 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002843 && (syn_get_sub_char() != NUL
2844 || (has_match_conc && match_conc)
2845 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 && wp->w_p_cole != 3)
2847 {
2848 // First time at this concealed item: display one
2849 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002850 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 c = match_conc;
2852 else if (syn_get_sub_char() != NUL)
2853 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002854 else if (wp->w_lcs_chars.conceal != NUL)
2855 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856 else
2857 c = ' ';
2858
2859 prev_syntax_id = syntax_seqnr;
2860
Bram Moolenaar1306b362022-08-06 15:59:06 +01002861 if (wlv.n_extra > 0)
2862 wlv.vcol_off += wlv.n_extra;
2863 wlv.vcol += wlv.n_extra;
2864 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 {
2866# ifdef FEAT_RIGHTLEFT
2867 if (wp->w_p_rl)
2868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.col -= wlv.n_extra;
2870 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 }
2872 else
2873# endif
2874 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 wlv.boguscols += wlv.n_extra;
2876 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 }
2878 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 n_attr = 0;
2881 }
2882 else if (n_skip == 0)
2883 {
2884 is_concealing = TRUE;
2885 n_skip = 1;
2886 }
2887 mb_c = c;
2888 if (enc_utf8 && utf_char2len(c) > 1)
2889 {
2890 mb_utf8 = TRUE;
2891 u8cc[0] = 0;
2892 c = 0xc0;
2893 }
2894 else
2895 mb_utf8 = FALSE; // don't draw as UTF-8
2896 }
2897 else
2898 {
2899 prev_syntax_id = 0;
2900 is_concealing = FALSE;
2901 }
2902
2903 if (n_skip > 0 && did_decrement_ptr)
2904 // not showing the '>', put pointer back to avoid getting stuck
2905 ++ptr;
2906
2907#endif // FEAT_CONCEAL
2908 }
2909
2910#ifdef FEAT_CONCEAL
2911 // In the cursor line and we may be concealing characters: correct
2912 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 && wp == curwin && lnum == wp->w_cursor.lnum
2915 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002916 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002918# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002919 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002922# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002923 wp->w_wcol = wlv.col - wlv.boguscols;
2924 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 did_wcol = TRUE;
2926 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002927# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002928 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002929# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 }
2931#endif
2932
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002933 // Use "extra_attr", but don't override visual selection highlighting.
2934 // Don't use "extra_attr" until n_attr_skip is zero.
2935 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 && !attr_pri)
2938 {
2939#ifdef LINE_ATTR
2940 if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002941 wlv.char_attr = hl_combine_attr(extra_attr, line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 else
2943#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002944 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 }
2946
2947#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2948 // XIM don't send preedit_start and preedit_end, but they send
2949 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2950 // im_is_preediting() here.
2951 if (p_imst == IM_ON_THE_SPOT
2952 && xic != NULL
2953 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002954 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 && !p_imdisable
2956 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 {
2959 colnr_T tcol;
2960
2961 if (preedit_end_col == MAXCOL)
2962 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2963 else
2964 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002965 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966 {
2967 if (feedback_old_attr < 0)
2968 {
2969 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002972 wlv.char_attr = im_get_feedback_attr(feedback_col);
2973 if (wlv.char_attr < 0)
2974 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002975 feedback_col++;
2976 }
2977 else if (feedback_old_attr >= 0)
2978 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002979 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980 feedback_old_attr = -1;
2981 feedback_col = 0;
2982 }
2983 }
2984#endif
2985 // Handle the case where we are in column 0 but not on the first
2986 // character of the line and the user wants us to show us a
2987 // special character (via 'listchars' option "precedes:<char>".
2988 if (lcs_prec_todo != NUL
2989 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002990 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002991 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002992 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993#ifdef FEAT_DIFF
2994 && filler_todo <= 0
2995#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002996 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 && c != NUL)
2998 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002999 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003000 lcs_prec_todo = NUL;
3001 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3002 {
3003 // Double-width character being overwritten by the "precedes"
3004 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 wlv.c_extra = MB_FILLER_CHAR;
3006 wlv.c_final = NUL;
3007 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 }
3011 mb_c = c;
3012 if (enc_utf8 && utf_char2len(c) > 1)
3013 {
3014 mb_utf8 = TRUE;
3015 u8cc[0] = 0;
3016 c = 0xc0;
3017 }
3018 else
3019 mb_utf8 = FALSE; // don't draw as UTF-8
3020 if (!attr_pri)
3021 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 saved_attr3 = wlv.char_attr; // save current attr
3023 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 n_attr3 = 1;
3025 }
3026 }
3027
3028 // At end of the text line or just after the last character.
3029 if ((c == NUL
3030#if defined(LINE_ATTR)
3031 || did_line_attr == 1
3032#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 {
3035#ifdef FEAT_SEARCH_EXTRA
3036 // flag to indicate whether prevcol equals startcol of search_hl or
3037 // one of the matches
3038 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3039 (long)(ptr - line) - (c == NUL));
3040#endif
3041 // Invert at least one char, used for Visual and empty line or
3042 // highlight match at end of line. If it's beyond the last
3043 // char on the screen, just overwrite that one (tricky!) Not
3044 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003045 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003046 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 && (VIsual_mode != Ctrl_V
3048 || lnum == VIsual.lnum
3049 || lnum == curwin->w_cursor.lnum)
3050 && c == NUL)
3051#ifdef FEAT_SEARCH_EXTRA
3052 // highlight 'hlsearch' match at end of line
3053 || (prevcol_hl_flag
3054# ifdef FEAT_SYN_HL
3055 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3056 && !(wp == curwin && VIsual_active))
3057# endif
3058# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060# endif
3061# if defined(LINE_ATTR)
3062 && did_line_attr <= 1
3063# endif
3064 )
3065#endif
3066 ))
3067 {
3068 int n = 0;
3069
3070#ifdef FEAT_RIGHTLEFT
3071 if (wp->w_p_rl)
3072 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003073 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 n = 1;
3075 }
3076 else
3077#endif
3078 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003079 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 n = -1;
3081 }
3082 if (n != 0)
3083 {
3084 // At the window boundary, highlight the last character
3085 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003086 wlv.off += n;
3087 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 }
3089 else
3090 {
3091 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003092 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003094 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
3096#ifdef FEAT_SEARCH_EXTRA
3097 if (area_attr == 0)
3098 {
3099 // Use attributes from match with highest priority among
3100 // 'search_hl' and the match list.
3101 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003102 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 }
3104#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003106 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107#ifdef FEAT_RIGHTLEFT
3108 if (wp->w_p_rl)
3109 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003110 --wlv.col;
3111 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 }
3113 else
3114#endif
3115 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003116 ++wlv.col;
3117 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003119 ++wlv.vcol;
3120 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 }
3122 }
3123
3124 // At end of the text line.
3125 if (c == NUL)
3126 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003127 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128
3129 // Update w_cline_height and w_cline_folded if the cursor line was
3130 // updated (saves a call to plines() later).
3131 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3132 {
3133 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135#ifdef FEAT_FOLDING
3136 curwin->w_cline_folded = FALSE;
3137#endif
3138 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3139 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 break;
3141 }
3142
3143 // Show "extends" character from 'listchars' if beyond the line end and
3144 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003145 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 && wp->w_p_list
3148 && !wp->w_p_wrap
3149#ifdef FEAT_DIFF
3150 && filler_todo <= 0
3151#endif
3152 && (
3153#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003154 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003156 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 && (*ptr != NUL
3158 || (wp->w_p_list && lcs_eol_one > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 || (wlv.n_extra && (wlv.c_extra != NUL
3160 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003162 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 mb_c = c;
3165 if (enc_utf8 && utf_char2len(c) > 1)
3166 {
3167 mb_utf8 = TRUE;
3168 u8cc[0] = 0;
3169 c = 0xc0;
3170 }
3171 else
3172 mb_utf8 = FALSE;
3173 }
3174
3175#ifdef FEAT_SYN_HL
3176 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 if (wlv.draw_color_col)
3178 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179
3180 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3181 // highlight the cursor position itself.
3182 // Also highlight the 'colorcolumn' if it is different than
3183 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003184 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3185 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 if (((wlv.draw_state == WL_LINE
3188 || wlv.draw_state == WL_BRI
3189 || wlv.draw_state == WL_SBR)
3190 && !lnum_in_visual_area
3191 && search_attr == 0
3192 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003193# ifdef FEAT_DIFF
3194 && filler_todo <= 0
3195# endif
3196 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 {
3198 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3199 && lnum != wp->w_cursor.lnum)
3200 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003201 vcol_save_attr = wlv.char_attr;
3202 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3203 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003205 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 vcol_save_attr = wlv.char_attr;
3208 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 }
3210 }
3211#endif
3212
3213 // Store character to be displayed.
3214 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 {
3218 // Store the character.
3219#if defined(FEAT_RIGHTLEFT)
3220 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3221 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003222 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 --wlv.off;
3224 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 }
3226#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003227 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 if (enc_dbcs == DBCS_JPNU)
3229 {
3230 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003231 ScreenLines[wlv.off] = 0x8e;
3232 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 }
3234 else if (enc_utf8)
3235 {
3236 if (mb_utf8)
3237 {
3238 int i;
3239
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003240 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 for (i = 0; i < Screen_mco; ++i)
3244 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003245 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 if (u8cc[i] == 0)
3247 break;
3248 }
3249 }
3250 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 }
3253 if (multi_attr)
3254 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 multi_attr = 0;
3257 }
3258 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003261 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003262
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3264 {
3265 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 ++wlv.off;
3267 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 if (enc_utf8)
3269 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 else
3272 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275#ifdef FEAT_DIFF
3276 && filler_todo <= 0
3277#endif
3278 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 // When "tocol" is halfway a character, set it to the end of
3281 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003284
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003286
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287#ifdef FEAT_RIGHTLEFT
3288 if (wp->w_p_rl)
3289 {
3290 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 --wlv.off;
3292 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 }
3294#endif
3295 }
3296#ifdef FEAT_RIGHTLEFT
3297 if (wp->w_p_rl)
3298 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 --wlv.off;
3300 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 }
3302 else
3303#endif
3304 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 ++wlv.off;
3306 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 }
3308 }
3309#ifdef FEAT_CONCEAL
3310 else if (wp->w_p_cole > 0 && is_concealing)
3311 {
3312 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003313 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 if (wlv.n_extra > 0)
3315 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 if (wp->w_p_wrap)
3317 {
3318 // Special voodoo required if 'wrap' is on.
3319 //
3320 // Advance the column indicator to force the line
3321 // drawing to wrap early. This will make the line
3322 // take up the same screen space when parts are concealed,
3323 // so that cursor line computations aren't messed up.
3324 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 // trailing junk to be written out of the screen line
3327 // we are building, 'boguscols' keeps track of the number
3328 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003329 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332# ifdef FEAT_RIGHTLEFT
3333 if (wp->w_p_rl)
3334 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003335 wlv.col -= wlv.n_extra;
3336 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 }
3338 else
3339# endif
3340 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.col += wlv.n_extra;
3342 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003344 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 n_attr = 0;
3346 }
3347
3348
3349 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3350 {
3351 // Need to fill two screen columns.
3352# ifdef FEAT_RIGHTLEFT
3353 if (wp->w_p_rl)
3354 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 --wlv.boguscols;
3356 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 }
3358 else
3359# endif
3360 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 ++wlv.boguscols;
3362 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 }
3364 }
3365
3366# ifdef FEAT_RIGHTLEFT
3367 if (wp->w_p_rl)
3368 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003369 --wlv.boguscols;
3370 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 }
3372 else
3373# endif
3374 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003375 ++wlv.boguscols;
3376 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 }
3378 }
3379 else
3380 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 wlv.vcol += wlv.n_extra;
3384 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003385 n_attr = 0;
3386 }
3387 }
3388
3389 }
3390#endif // FEAT_CONCEAL
3391 else
3392 --n_skip;
3393
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003394 // Only advance the "wlv.vcol" when after the 'number' or
3395 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397#ifdef FEAT_DIFF
3398 && filler_todo <= 0
3399#endif
3400 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003401 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402
3403#ifdef FEAT_SYN_HL
3404 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003405 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406#endif
3407
3408 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3410 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411
3412 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003413 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003414 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003415 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003416 if (n_attr_skip > 0)
3417 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418
3419 // At end of screen line and there is more to come: Display the line
3420 // so far. If there is no more to display it is caught above.
3421 if ((
3422#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003427 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428#ifdef FEAT_DIFF
3429 || filler_todo > 0
3430#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003431#ifdef FEAT_PROP_POPUP
3432 || text_prop_follows
3433#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003434 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 && wlv.p_extra != at_end_str)
3436 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3437 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 )
3439 {
3440#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003441 screen_line(wp, wlv.screen_row, wp->w_wincol,
3442 wlv.col - wlv.boguscols,
3443 wp->w_width, wlv.screen_line_flags);
3444 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3447 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 ++wlv.row;
3450 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451
3452 // When not wrapping and finished diff lines, or when displayed
3453 // '$' and highlighting until last column, break here.
3454 if ((!wp->w_p_wrap
3455#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003456 && filler_todo <= 0
3457#endif
3458#ifdef FEAT_PROP_POPUP
3459 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460#endif
3461 ) || lcs_eol_one == -1)
3462 break;
3463
3464 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466#ifdef FEAT_DIFF
3467 && filler_todo <= 0
3468#endif
3469 )
3470 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3472 draw_vsep_win(wp, wlv.row);
3473 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 }
3475
3476 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 break;
3481 }
3482
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484#ifdef FEAT_DIFF
3485 && filler_todo <= 0
3486#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003487#ifdef FEAT_PROP_POPUP
3488 && !text_prop_follows
3489#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490 && wp->w_width == Columns)
3491 {
3492 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494
3495 // Special trick to make copy/paste of wrapped lines work with
3496 // xterm/screen: write an extra character beyond the end of
3497 // the line. This will work with all terminal types
3498 // (regardless of the xn,am settings).
3499 // Only do this on a fast tty.
3500 // Only do this if the cursor is on the current line
3501 // (something has been written in it).
3502 // Don't do this for the GUI.
3503 // Don't do this for double-width characters.
3504 // Don't do this for a window not at the right screen border.
3505 if (p_tf
3506#ifdef FEAT_GUI
3507 && !gui.in_use
3508#endif
3509 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3511 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003513 || (*mb_off2cells)(
3514 LineOffset[wlv.screen_row - 1]
3515 + (int)Columns - 2,
3516 LineOffset[wlv.screen_row]
3517 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 {
3519 // First make sure we are at the end of the screen line,
3520 // then output the same character again to let the
3521 // terminal know about the wrap. If the terminal doesn't
3522 // auto-wrap, we overwrite the character.
3523 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 screen_char(LineOffset[wlv.screen_row - 1]
3525 + (unsigned)Columns - 1,
3526 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527
3528 // When there is a multi-byte character, just output a
3529 // space to keep it simple.
3530 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 out_char(' ');
3533 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 + (Columns - 1)]);
3536 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 screen_start(); // don't know where cursor is now
3539 }
3540 }
3541
Bram Moolenaar1306b362022-08-06 15:59:06 +01003542 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543
Bram Moolenaareed9d462021-02-15 20:38:25 +01003544 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003546 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003548 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003550 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 need_showbreak = TRUE;
3552#endif
3553#ifdef FEAT_DIFF
3554 --filler_todo;
3555 // When the filler lines are actually below the last line of the
3556 // file, don't draw the line itself, break here.
3557 if (filler_todo == 0 && wp->w_botfill)
3558 break;
3559#endif
3560 }
3561
3562 } // for every character in the line
3563
3564#ifdef FEAT_SPELL
3565 // After an empty line check first word for capital.
3566 if (*skipwhite(line) == NUL)
3567 {
3568 capcol_lnum = lnum + 1;
3569 cap_col = 0;
3570 }
3571#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003572#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 vim_free(text_props);
3574 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003575 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576#endif
3577
3578 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580}