blob: 17637559cf6710e56f789a395d3f015be17d8d00 [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.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * 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.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +0100106
107 int screen_line_flags; // flags for screen_line()
108
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100109 int fromcol; // start of inverting
110 int tocol; // end of inverting
111
112#ifdef FEAT_LINEBREAK
113 int need_showbreak; // overlong line, skipping first x chars
114 int dont_use_showbreak; // do not use 'showbreak'
115#endif
116
Bram Moolenaar1306b362022-08-06 15:59:06 +0100117 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
118 int cul_screenline;
119
120 int char_attr; // attributes for the next character
121
122 int n_extra; // number of extra bytes
123 char_u *p_extra; // string of extra chars, plus NUL, only used
124 // when c_extra and c_final are NUL
125 int c_extra; // extra chars, all the same
126 int c_final; // final char, mandatory if set
127
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100128 char_u *p_extra_free; // p_extra buffer that needs to be freed
129
Bram Moolenaar1306b362022-08-06 15:59:06 +0100130 // saved "extra" items for when draw_state becomes WL_LINE (again)
131 int saved_n_extra;
132 char_u *saved_p_extra;
133 int saved_c_extra;
134 int saved_c_final;
135 int saved_char_attr;
136
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100137 char_u extra[NUMBUFLEN + MB_MAXBYTES];
138 // "%ld " and 'fdc' must fit in here, as well
139 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100140
Bram Moolenaar1306b362022-08-06 15:59:06 +0100141#ifdef FEAT_DIFF
142 hlf_T diff_hlf; // type of diff highlighting
143#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100144 int filler_lines; // nr of filler lines to be drawn
145 int filler_todo; // nr of filler lines still to do + 1
146#ifdef FEAT_SIGNS
147 sign_attrs_T sattr;
148#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100149} winlinevars_T;
150
151// draw_state values for items that are drawn in sequence:
152#define WL_START 0 // nothing done yet, must be zero
153#ifdef FEAT_CMDWIN
154# define WL_CMDLINE (WL_START + 1) // cmdline window column
155#else
156# define WL_CMDLINE WL_START
157#endif
158#ifdef FEAT_FOLDING
159# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
160#else
161# define WL_FOLD WL_CMDLINE
162#endif
163#ifdef FEAT_SIGNS
164# define WL_SIGN (WL_FOLD + 1) // column for signs
165#else
166# define WL_SIGN WL_FOLD // column for signs
167#endif
168#define WL_NR (WL_SIGN + 1) // line number
169#ifdef FEAT_LINEBREAK
170# define WL_BRI (WL_NR + 1) // 'breakindent'
171#else
172# define WL_BRI WL_NR
173#endif
174#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
175# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
176#else
177# define WL_SBR WL_BRI
178#endif
179#define WL_LINE (WL_SBR + 1) // text in the line
180
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100181#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200182/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000183 * Return TRUE if CursorLineSign highlight is to be used.
184 */
185 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100186use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000187{
188 return wp->w_p_cul
189 && lnum == wp->w_cursor.lnum
190 && (wp->w_p_culopt_flags & CULOPT_NBR);
191}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100192#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194
195#ifdef FEAT_FOLDING
196/*
197 * Setup for drawing the 'foldcolumn', if there is one.
198 */
199 static void
200handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
201{
202 int fdc = compute_foldcolumn(wp, 0);
203
204 if (fdc <= 0)
205 return;
206
207 // Allocate a buffer, "wlv->extra[]" may already be in use.
208 vim_free(wlv->p_extra_free);
209 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
210 if (wlv->p_extra_free != NULL)
211 {
212 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
213 wp, FALSE, wlv->lnum);
214 wlv->p_extra_free[wlv->n_extra] = NUL;
215 wlv->p_extra = wlv->p_extra_free;
216 wlv->c_extra = NUL;
217 wlv->c_final = NUL;
218 if (use_cursor_line_highlight(wp, wlv->lnum))
219 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
220 else
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
222 }
223}
224#endif
225
226#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000227/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100228 * Get information needed to display the sign in line "wlv->lnum" in window
229 * "wp".
230 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200231 * Otherwise the sign is going to be displayed in the sign column.
232 */
233 static void
234get_sign_display_info(
235 int nrcol,
236 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100237 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200238{
239 int text_sign;
240# ifdef FEAT_SIGN_ICONS
241 int icon_sign;
242# endif
243
244 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_extra = ' ';
246 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100248 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 else
250 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100251 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100252 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000253 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100255 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 }
257
Bram Moolenaar1306b362022-08-06 15:59:06 +0100258 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100260 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#endif
262 )
263 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100264 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267 if (gui.in_use && icon_sign != 0)
268 {
269 // Use the image in this position.
270 if (nrcol)
271 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 sprintf((char *)wlv->extra, "%-*c ",
274 number_width(wp), SIGN_BYTE);
275 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277 }
278 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100281 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
282 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 {
284 if (nrcol)
285 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200288 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100290 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 }
292 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 }
295# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->c_final = NUL;
297 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
300# endif
301 if (text_sign != 0)
302 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100303 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100304 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200305 {
306 if (nrcol)
307 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100308 int width = number_width(wp) - 2;
309 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310
311 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100312 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100313 vim_snprintf((char *)wlv->extra + n,
314 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100317 wlv->c_extra = NUL;
318 wlv->c_final = NUL;
319 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000321
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100322 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100323 && wlv->sattr.sat_culhl > 0)
324 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000325 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100326 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200327 }
328 }
329}
330#endif
331
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332/*
333 * Display the absolute or relative line number. After the first row fill with
334 * blanks when the 'n' flag isn't in 'cpo'.
335 */
336 static void
337handle_lnum_col(
338 win_T *wp,
339 winlinevars_T *wlv,
340 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100341 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100342{
343 if ((wp->w_p_nu || wp->w_p_rnu)
344 && (wlv->row == wlv->startrow + wlv->filler_lines
345 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
346 {
347#ifdef FEAT_SIGNS
348 // If 'signcolumn' is set to 'number' and a sign is present
349 // in 'lnum', then display the sign instead of the line
350 // number.
351 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
352 get_sign_display_info(TRUE, wp, wlv);
353 else
354#endif
355 {
356 // Draw the line number (empty space after wrapping).
357 if (wlv->row == wlv->startrow + wlv->filler_lines)
358 {
359 long num;
360 char *fmt = "%*ld ";
361
362 if (wp->w_p_nu && !wp->w_p_rnu)
363 // 'number' + 'norelativenumber'
364 num = (long)wlv->lnum;
365 else
366 {
367 // 'relativenumber', don't use negative numbers
368 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
369 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
370 {
371 // 'number' + 'relativenumber'
372 num = wlv->lnum;
373 fmt = "%-*ld ";
374 }
375 }
376
377 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
378 if (wp->w_skipcol > 0)
379 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
380 ++wlv->p_extra)
381 *wlv->p_extra = '-';
382#ifdef FEAT_RIGHTLEFT
383 if (wp->w_p_rl) // reverse line numbers
384 {
385 char_u *p1, *p2;
386 int t;
387
388 // like rl_mirror(), but keep the space at the end
389 p2 = skipwhite(wlv->extra);
390 p2 = skiptowhite(p2) - 1;
391 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
392 {
393 t = *p1;
394 *p1 = *p2;
395 *p2 = t;
396 }
397 }
398#endif
399 wlv->p_extra = wlv->extra;
400 wlv->c_extra = NUL;
401 wlv->c_final = NUL;
402 }
403 else
404 {
405 wlv->c_extra = ' ';
406 wlv->c_final = NUL;
407 }
408 wlv->n_extra = number_width(wp) + 1;
409 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
410#ifdef FEAT_SYN_HL
411 // When 'cursorline' is set highlight the line number of
412 // the current line differently.
413 // When 'cursorlineopt' does not have "line" only
414 // highlight the line number itself.
415 // TODO: Can we use CursorLine instead of CursorLineNr
416 // when CursorLineNr isn't set?
417 if (wp->w_p_cul
418 && wlv->lnum == wp->w_cursor.lnum
419 && (wp->w_p_culopt_flags & CULOPT_NBR)
420 && (wlv->row == wlv->startrow + wlv->filler_lines
421 || (wlv->row > wlv->startrow + wlv->filler_lines
422 && (wp->w_p_culopt_flags & CULOPT_LINE))))
423 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
424#endif
425 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
426 && HL_ATTR(HLF_LNA) != 0)
427 // Use LineNrAbove
428 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
429 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
430 && HL_ATTR(HLF_LNB) != 0)
431 // Use LineNrBelow
432 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
433 }
434#ifdef FEAT_SIGNS
435 if (num_attr)
436 wlv->char_attr = num_attr;
437#endif
438 }
439}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100440
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100441#ifdef FEAT_LINEBREAK
442 static void
443handle_breakindent(win_T *wp, winlinevars_T *wlv)
444{
445 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
446 && *get_showbreak_value(wp) != NUL)
447 // draw indent after showbreak value
448 wlv->draw_state = WL_BRI;
449 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
450 // After the showbreak, draw the breakindent
451 wlv->draw_state = WL_BRI - 1;
452
453 // draw 'breakindent': indent wrapped text accordingly
454 if (wlv->draw_state == WL_BRI - 1)
455 {
456 wlv->draw_state = WL_BRI;
457 // if wlv->need_showbreak is set, breakindent also applies
458 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
459# ifdef FEAT_DIFF
460 && wlv->filler_lines == 0
461# endif
462# ifdef FEAT_PROP_POPUP
463 && !wlv->dont_use_showbreak
464# endif
465 )
466 {
467 wlv->char_attr = 0;
468# ifdef FEAT_DIFF
469 if (wlv->diff_hlf != (hlf_T)0)
470 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
471# endif
472 wlv->p_extra = NULL;
473 wlv->c_extra = ' ';
474 wlv->c_final = NUL;
475 wlv->n_extra = get_breakindent_win(wp,
476 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
477 if (wlv->row == wlv->startrow)
478 {
479 wlv->n_extra -= win_col_off2(wp);
480 if (wlv->n_extra < 0)
481 wlv->n_extra = 0;
482 }
483 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
484 wlv->need_showbreak = FALSE;
485 // Correct end of highlighted area for 'breakindent',
486 // required when 'linebreak' is also set.
487 if (wlv->tocol == wlv->vcol)
488 wlv->tocol += wlv->n_extra;
489 }
490 }
491}
492#endif
493
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100494#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100495/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100496 * Return the cell size of virtual text after truncation.
497 */
498 static int
499textprop_size_after_trunc(
500 win_T *wp,
501 int flags, // TP_FLAG_ALIGN_*
502 int added,
503 char_u *text,
504 int *n_used_ptr)
505{
506 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
507 ? wp->w_width : added;
508 int len = (int)STRLEN(text);
509 int strsize = 0;
510 int n_used;
511
512 // if the remaining size is to small wrap anyway and use the next line
513 if (space < PROP_TEXT_MIN_CELLS)
514 space += wp->w_width;
515 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
516 {
517 int clen = ptr2cells(text + n_used);
518
519 if (strsize + clen > space)
520 break;
521 strsize += clen;
522 }
523 *n_used_ptr = n_used;
524 return strsize;
525}
526
527/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100528 * Take care of padding, right-align and truncation of virtual text after a
529 * line.
530 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
531 * padding, right-align and truncation. Otherwise only the size is computed.
532 * When "n_attr" is NULL returns the number of screen cells used.
533 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100534 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100535 int
536text_prop_position(
537 win_T *wp,
538 textprop_T *tp,
539 int vcol, // current screen column
540 int *n_extra, // nr of bytes for virtual text
541 char_u **p_extra, // virtual text
542 int *n_attr, // attribute cells, NULL if not used
543 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200544{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100545 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100546 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100547 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
548 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
549 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
550 ? tp->tp_len - 1 : 0;
551 int col_with_padding = vcol + (below ? 0 : padding);
552 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100553 int before = room; // spaces before the text
554 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100555 int n_used = *n_extra;
556 char_u *l = NULL;
557 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100558 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
559 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200560
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100561 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100562 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100563 int col_off = win_col_off(wp) + win_col_off2(wp);
564 int skip_add = 0;
565
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100566 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100568 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100569 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100570 }
571 else
572 {
573 // Right-align: fill with before
574 if (right)
575 before -= cells;
576 if (before < 0
577 || !(right || below)
578 || (below
579 ? (col_with_padding == 0 || !wp->w_p_wrap)
580 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100581 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100582 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
583 {
584 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 before = wp->w_width - col_off - strsize + room;
586 if (before < 0)
587 before = 0;
588 else
589 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100590 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100591 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100592 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100593 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100594 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100595 else if (below && before > 0)
596 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100597 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100598 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100599
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100600 // With 'nowrap' add one to show the "extends" character if needed (it
601 // doesn't show if the text just fits).
602 if (!wp->w_p_wrap
603 && n_used < *n_extra
604 && wp->w_lcs_chars.ext != NUL
605 && wp->w_p_list)
606 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100607 if (!wp->w_p_wrap && below && padding > 0)
608 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100609
610 // add 1 for NUL, 2 for when '…' is used
611 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 if (n_attr == NULL || l != NULL)
614 {
615 int off = 0;
616
617 if (n_attr != NULL)
618 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 vim_memset(l, ' ', before);
620 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100621 if (padding > 0)
622 {
623 vim_memset(l + off, ' ', padding);
624 off += padding;
625 }
626 vim_strncpy(l + off, *p_extra, n_used);
627 off += n_used;
628 }
629 else
630 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 off = before + after + padding + n_used;
632 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 }
634 if (n_attr != NULL)
635 {
636 if (n_used < *n_extra && wp->w_p_wrap)
637 {
638 char_u *lp = l + off - 1;
639
640 if (has_mbyte)
641 {
642 // change last character to '…'
643 lp -= (*mb_head_off)(l, lp);
644 STRCPY(lp, "…");
645 n_used = lp - l + 3 - padding;
646 }
647 else
648 // change last character to '>'
649 *lp = '>';
650 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 else if (after > 0)
652 {
653 vim_memset(l + off, ' ', after);
654 l[off + after] = NUL;
655 }
656
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100659 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100660 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100661 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100662 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 }
664 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100665 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100666
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100667 if (n_attr == NULL)
668 return cells;
669 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200670}
671#endif
672
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100673/*
674 * Called when finished with the line: draw the screen line and handle any
675 * highlighting until the right of the window.
676 */
677 static void
678draw_screen_line(win_T *wp, winlinevars_T *wlv)
679{
680#ifdef FEAT_SYN_HL
681 long v;
682
683 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
684 if (wp->w_p_wrap)
685 v = wp->w_skipcol;
686 else
687 v = wp->w_leftcol;
688
689 // check if line ends before left margin
690 if (wlv->vcol < v + wlv->col - win_col_off(wp))
691 wlv->vcol = v + wlv->col - win_col_off(wp);
692# ifdef FEAT_CONCEAL
693 // Get rid of the boguscols now, we want to draw until the right
694 // edge for 'cursorcolumn'.
695 wlv->col -= wlv->boguscols;
696 wlv->boguscols = 0;
697# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
698# else
699# define VCOL_HLC (wlv->vcol)
700# endif
701
702 if (wlv->draw_color_col)
703 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
704
705 if (((wp->w_p_cuc
706 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
707 && (int)wp->w_virtcol <
708 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
709 && wlv->lnum != wp->w_cursor.lnum)
710 || wlv->draw_color_col
711 || wlv->win_attr != 0)
712# ifdef FEAT_RIGHTLEFT
713 && !wp->w_p_rl
714# endif
715 )
716 {
717 int rightmost_vcol = 0;
718 int i;
719
720 if (wp->w_p_cuc)
721 rightmost_vcol = wp->w_virtcol;
722 if (wlv->draw_color_col)
723 // determine rightmost colorcolumn to possibly draw
724 for (i = 0; wlv->color_cols[i] >= 0; ++i)
725 if (rightmost_vcol < wlv->color_cols[i])
726 rightmost_vcol = wlv->color_cols[i];
727
728 while (wlv->col < wp->w_width)
729 {
730 ScreenLines[wlv->off] = ' ';
731 if (enc_utf8)
732 ScreenLinesUC[wlv->off] = 0;
733 ScreenCols[wlv->off] = MAXCOL;
734 ++wlv->col;
735 if (wlv->draw_color_col)
736 wlv->draw_color_col = advance_color_col(
737 VCOL_HLC, &wlv->color_cols);
738
739 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
740 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
741 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
742 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
743 else
744 ScreenAttrs[wlv->off++] = wlv->win_attr;
745
746 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
747 break;
748
749 ++wlv->vcol;
750 }
751 }
752#endif
753
754 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
755 wp->w_width, wlv->screen_line_flags);
756 ++wlv->row;
757 ++wlv->screen_row;
758}
759#undef VCOL_HLC
760
761/*
762 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100763 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100764 */
765 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100766win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100767{
768 wlv->col = 0;
769 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
770
771#ifdef FEAT_RIGHTLEFT
772 if (wp->w_p_rl)
773 {
774 // Rightleft window: process the text in the normal direction, but put
775 // it in current_ScreenLine[] from right to left. Start at the
776 // rightmost column of the window.
777 wlv->col = wp->w_width - 1;
778 wlv->off += wlv->col;
779 wlv->screen_line_flags |= SLF_RIGHTLEFT;
780 }
781#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100782 if (save_extra)
783 {
784 // reset the drawing state for the start of a wrapped line
785 wlv->draw_state = WL_START;
786 wlv->saved_n_extra = wlv->n_extra;
787 wlv->saved_p_extra = wlv->p_extra;
788 wlv->saved_c_extra = wlv->c_extra;
789 wlv->saved_c_final = wlv->c_final;
790#ifdef FEAT_SYN_HL
791 if (!(wlv->cul_screenline
792# ifdef FEAT_DIFF
793 && wlv->diff_hlf == (hlf_T)0
794# endif
795 ))
796 wlv->saved_char_attr = wlv->char_attr;
797 else
798#endif
799 wlv->saved_char_attr = 0;
800 wlv->n_extra = 0;
801 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100802}
803
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200804/*
805 * Display line "lnum" of window 'wp' on the screen.
806 * Start at row "startrow", stop when "endrow" is reached.
807 * wp->w_virtcol needs to be valid.
808 *
809 * Return the number of last row the line occupies.
810 */
811 int
812win_line(
813 win_T *wp,
814 linenr_T lnum,
815 int startrow,
816 int endrow,
817 int nochange UNUSED, // not updating for changed text
818 int number_only) // only update the number column
819{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100820 winlinevars_T wlv; // variables passed between functions
821
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200822 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200823#ifdef FEAT_LINEBREAK
824 long vcol_sbr = -1; // virtual column after showbreak
825#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100826 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200827 char_u *line; // current line
828 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200829
Bram Moolenaar1306b362022-08-06 15:59:06 +0100830#ifdef FEAT_PROP_POPUP
831 char_u *p_extra_free2 = NULL; // another p_extra to be freed
832#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200833 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000834#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000835 int in_linebreak = FALSE; // n_extra set for showing linebreak
836#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200837 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100838 // displaying eol at end-of-line
839 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000840 int lcs_prec_todo = wp->w_lcs_chars.prec;
841 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200842
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100843 int n_attr = 0; // chars with special attr
844 int n_attr_skip = 0; // chars to skip before using extra_attr
845 int saved_attr2 = 0; // char_attr saved for n_attr
846 int n_attr3 = 0; // chars with overruling special attr
847 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200848
849 int n_skip = 0; // nr of chars to skip for 'nowrap'
850
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200851 int fromcol_prev = -2; // start of inverting after cursor
852 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200853 int lnum_in_visual_area = FALSE;
854 pos_T pos;
855 long v;
856
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200857 int attr_pri = FALSE; // char_attr has priority
858 int area_highlighting = FALSE; // Visual or incsearch highlighting
859 // in this line
860 int vi_attr = 0; // attributes for Visual and incsearch
861 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200862 int area_attr = 0; // attributes desired by highlighting
863 int search_attr = 0; // attributes desired by 'hlsearch'
864#ifdef FEAT_SYN_HL
865 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
866 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200867 int prev_syntax_col = -1; // column of prev_syntax_attr
868 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200869 int has_syntax = FALSE; // this buffer has syntax highl.
870 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200871#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100872#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200873 int text_prop_count;
874 int text_prop_next = 0; // next text property to use
875 textprop_T *text_props = NULL;
876 int *text_prop_idxs = NULL;
877 int text_props_active = 0;
878 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100879 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200880 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100881 int text_prop_attr_comb = 0; // text_prop_attr combined with
882 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100883 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100884 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100885 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100886 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100887 int saved_search_attr = 0; // search_attr to be used when n_extra
888 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100889 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200890#endif
891#ifdef FEAT_SPELL
892 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000893 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200894# define SPWORDLEN 150
895 char_u nextline[SPWORDLEN * 2];// text with start of the next line
896 int nextlinecol = 0; // column where nextline[] starts
897 int nextline_idx = 0; // index in nextline[] where next line
898 // starts
899 int spell_attr = 0; // attributes desired by spelling
900 int word_end = 0; // last byte with same spell_attr
901 static linenr_T checked_lnum = 0; // line number for "checked_col"
902 static int checked_col = 0; // column in "checked_lnum" up to which
903 // there are no spell errors
904 static int cap_col = -1; // column to check for Cap word
905 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
906 int cur_checked_col = 0; // checked column for current line
907#endif
908 int extra_check = 0; // has extra highlighting
909 int multi_attr = 0; // attributes desired by multibyte
910 int mb_l = 1; // multi-byte byte length
911 int mb_c = 0; // decoded multi-byte character
912 int mb_utf8 = FALSE; // screen char is UTF-8 char
913 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200914#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200915 int change_start = MAXCOL; // first col of changed area
916 int change_end = -1; // last col of changed area
917#endif
918 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100919 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200920 int in_multispace = FALSE; // in multiple consecutive spaces
921 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200922#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
923 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
924# define LINE_ATTR
925 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100926 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200927#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200928 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +0000929 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200930#ifdef FEAT_ARABIC
931 int prev_c = 0; // previous Arabic character
932 int prev_c1 = 0; // first composing char for prev_c
933#endif
934#if defined(LINE_ATTR)
935 int did_line_attr = 0;
936#endif
937#ifdef FEAT_TERMINAL
938 int get_term_attr = FALSE;
939#endif
940#ifdef FEAT_SYN_HL
941 int cul_attr = 0; // set when 'cursorline' active
942
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200943 // margin columns for the screen line, needed for when 'cursorlineopt'
944 // contains "screenline"
945 int left_curline_col = 0;
946 int right_curline_col = 0;
947#endif
948
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
950 int feedback_col = 0;
951 int feedback_old_attr = -1;
952#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200953
954#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
955 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000956 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957#endif
958#ifdef FEAT_CONCEAL
959 int syntax_flags = 0;
960 int syntax_seqnr = 0;
961 int prev_syntax_id = 0;
962 int conceal_attr = HL_ATTR(HLF_CONCEAL);
963 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int did_wcol = FALSE;
965 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100966# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200967# define FIX_FOR_BOGUSCOLS \
968 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100969 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100970 wlv.vcol -= wlv.vcol_off; \
971 wlv.vcol_off = 0; \
972 wlv.col -= wlv.boguscols; \
973 old_boguscols = wlv.boguscols; \
974 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975 }
976#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100977# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978#endif
979
980 if (startrow > endrow) // past the end already!
981 return startrow;
982
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100983 CLEAR_FIELD(wlv);
984
985 wlv.lnum = lnum;
986 wlv.startrow = startrow;
987 wlv.row = startrow;
988 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100989 wlv.fromcol = -10;
990 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991
992 if (!number_only)
993 {
994 // To speed up the loop below, set extra_check when there is linebreak,
995 // trailing white space and/or syntax processing to be done.
996#ifdef FEAT_LINEBREAK
997 extra_check = wp->w_p_lbr;
998#endif
999#ifdef FEAT_SYN_HL
1000 if (syntax_present(wp) && !wp->w_s->b_syn_error
1001# ifdef SYN_TIME_LIMIT
1002 && !wp->w_s->b_syn_slow
1003# endif
1004 )
1005 {
1006 // Prepare for syntax highlighting in this line. When there is an
1007 // error, stop syntax highlighting.
1008 save_did_emsg = did_emsg;
1009 did_emsg = FALSE;
1010 syntax_start(wp, lnum);
1011 if (did_emsg)
1012 wp->w_s->b_syn_error = TRUE;
1013 else
1014 {
1015 did_emsg = save_did_emsg;
1016#ifdef SYN_TIME_LIMIT
1017 if (!wp->w_s->b_syn_slow)
1018#endif
1019 {
1020 has_syntax = TRUE;
1021 extra_check = TRUE;
1022 }
1023 }
1024 }
1025
1026 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001027 wlv.color_cols = wp->w_p_cc_cols;
1028 if (wlv.color_cols != NULL)
1029 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#endif
1031
1032#ifdef FEAT_TERMINAL
1033 if (term_show_buffer(wp->w_buffer))
1034 {
1035 extra_check = TRUE;
1036 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001037 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 }
1039#endif
1040
1041#ifdef FEAT_SPELL
1042 if (wp->w_p_spell
1043 && *wp->w_s->b_p_spl != NUL
1044 && wp->w_s->b_langp.ga_len > 0
1045 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
1046 {
1047 // Prepare for spell checking.
1048 has_spell = TRUE;
1049 extra_check = TRUE;
1050
1051 // Get the start of the next line, so that words that wrap to the
1052 // next line are found too: "et<line-break>al.".
1053 // Trick: skip a few chars for C/shell/Vim comments
1054 nextline[SPWORDLEN] = NUL;
1055 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1056 {
1057 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1058 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1059 }
1060
1061 // When a word wrapped from the previous line the start of the
1062 // current line is valid.
1063 if (lnum == checked_lnum)
1064 cur_checked_col = checked_col;
1065 checked_lnum = 0;
1066
1067 // When there was a sentence end in the previous line may require a
1068 // word starting with capital in this line. In line 1 always check
1069 // the first word.
1070 if (lnum != capcol_lnum)
1071 cap_col = -1;
1072 if (lnum == 1)
1073 cap_col = 0;
1074 capcol_lnum = 0;
1075 }
1076#endif
1077
1078 // handle Visual active in this window
1079 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1080 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001081 pos_T *top, *bot;
1082
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1084 {
1085 // Visual is after curwin->w_cursor
1086 top = &curwin->w_cursor;
1087 bot = &VIsual;
1088 }
1089 else
1090 {
1091 // Visual is before curwin->w_cursor
1092 top = &VIsual;
1093 bot = &curwin->w_cursor;
1094 }
1095 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1096 if (VIsual_mode == Ctrl_V)
1097 {
1098 // block mode
1099 if (lnum_in_visual_area)
1100 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001101 wlv.fromcol = wp->w_old_cursor_fcol;
1102 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001103 }
1104 }
1105 else
1106 {
1107 // non-block mode
1108 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001109 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110 else if (lnum == top->lnum)
1111 {
1112 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001113 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 else
1115 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001116 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001118 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 }
1120 }
1121 if (VIsual_mode != 'V' && lnum == bot->lnum)
1122 {
1123 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1124 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001125 wlv.fromcol = -10;
1126 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127 }
1128 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001129 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 else
1131 {
1132 pos = *bot;
1133 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001134 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1135 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136 else
1137 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001138 getvvcol(wp, &pos, NULL, NULL,
1139 (colnr_T *)&wlv.tocol);
1140 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 }
1142 }
1143 }
1144 }
1145
1146 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001147 if (!highlight_match && lnum == curwin->w_cursor.lnum
1148 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001149#ifdef FEAT_GUI
1150 && !gui.in_use
1151#endif
1152 )
1153 noinvcur = TRUE;
1154
1155 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001156 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001157 {
1158 area_highlighting = TRUE;
1159 vi_attr = HL_ATTR(HLF_V);
1160#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1161 if ((clip_star.available && !clip_star.owned
1162 && clip_isautosel_star())
1163 || (clip_plus.available && !clip_plus.owned
1164 && clip_isautosel_plus()))
1165 vi_attr = HL_ATTR(HLF_VNC);
1166#endif
1167 }
1168 }
1169
1170 // handle 'incsearch' and ":s///c" highlighting
1171 else if (highlight_match
1172 && wp == curwin
1173 && lnum >= curwin->w_cursor.lnum
1174 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1175 {
1176 if (lnum == curwin->w_cursor.lnum)
1177 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001178 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001180 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1182 {
1183 pos.lnum = lnum;
1184 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001185 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 }
1187 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001188 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001190 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1191 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192 area_highlighting = TRUE;
1193 vi_attr = HL_ATTR(HLF_I);
1194 }
1195 }
1196
1197#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001198 wlv.filler_lines = diff_check(wp, lnum);
1199 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001201 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202 {
1203 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001204 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001206 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001208 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209 }
1210 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001211 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001212 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 area_highlighting = TRUE;
1214 }
1215 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001216 wlv.filler_lines = wp->w_topfill;
1217 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218#endif
1219
1220#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001221 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001222 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001223 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224#endif
1225
1226#ifdef LINE_ATTR
1227# ifdef FEAT_SIGNS
1228 // If this line has a sign with line highlighting set line_attr.
1229 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001230 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231# endif
1232# if defined(FEAT_QUICKFIX)
1233 // Highlight the current line in the quickfix window.
1234 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1235 line_attr = HL_ATTR(HLF_QFL);
1236# endif
1237 if (line_attr != 0)
1238 area_highlighting = TRUE;
1239#endif
1240
1241 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1242 ptr = line;
1243
1244#ifdef FEAT_SPELL
1245 if (has_spell && !number_only)
1246 {
1247 // For checking first word with a capital skip white space.
1248 if (cap_col == 0)
1249 cap_col = getwhitecols(line);
1250
1251 // To be able to spell-check over line boundaries copy the end of the
1252 // current line into nextline[]. Above the start of the next line was
1253 // copied to nextline[SPWORDLEN].
1254 if (nextline[SPWORDLEN] == NUL)
1255 {
1256 // No next line or it is empty.
1257 nextlinecol = MAXCOL;
1258 nextline_idx = 0;
1259 }
1260 else
1261 {
1262 v = (long)STRLEN(line);
1263 if (v < SPWORDLEN)
1264 {
1265 // Short line, use it completely and append the start of the
1266 // next line.
1267 nextlinecol = 0;
1268 mch_memmove(nextline, line, (size_t)v);
1269 STRMOVE(nextline + v, nextline + SPWORDLEN);
1270 nextline_idx = v + 1;
1271 }
1272 else
1273 {
1274 // Long line, use only the last SPWORDLEN bytes.
1275 nextlinecol = v - SPWORDLEN;
1276 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1277 nextline_idx = SPWORDLEN + 1;
1278 }
1279 }
1280 }
1281#endif
1282
1283 if (wp->w_p_list)
1284 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001285 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001286 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001287 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001288 || wp->w_lcs_chars.trail
1289 || wp->w_lcs_chars.lead
1290 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001292
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001294 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 {
1296 trailcol = (colnr_T)STRLEN(ptr);
1297 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1298 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001299 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001301 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001302 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001303 {
1304 leadcol = 0;
1305 while (VIM_ISWHITE(ptr[leadcol]))
1306 ++leadcol;
1307 if (ptr[leadcol] == NUL)
1308 // in a line full of spaces all of them are treated as trailing
1309 leadcol = (colnr_T)0;
1310 else
1311 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001312 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001313 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 }
1315
Bram Moolenaard7657e92022-09-20 18:59:30 +01001316 wlv.wcr_attr = get_wcr_attr(wp);
1317 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001319 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320 area_highlighting = TRUE;
1321 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001322
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001323#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001325 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326#endif
1327
1328 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1329 // first character to be displayed.
1330 if (wp->w_p_wrap)
1331 v = wp->w_skipcol;
1332 else
1333 v = wp->w_leftcol;
1334 if (v > 0 && !number_only)
1335 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001336 char_u *prev_ptr = ptr;
1337 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001338 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001340 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001341 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001343 charsize = win_lbr_chartabsize(&cts, NULL);
1344 cts.cts_vcol += charsize;
1345 prev_ptr = cts.cts_ptr;
1346 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001348 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001349 ptr = cts.cts_ptr;
1350 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351
1352 // When:
1353 // - 'cuc' is set, or
1354 // - 'colorcolumn' is set, or
1355 // - 'virtualedit' is set, or
1356 // - the visual mode is active,
1357 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001358 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001360 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361#endif
1362 virtual_active() ||
1363 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001364 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365
1366 // Handle a character that's not completely on the screen: Put ptr at
1367 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001368 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001370 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 ptr = prev_ptr;
1372 // If the character fits on the screen, don't need to skip it.
1373 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001374 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1375 && wlv.col == 0)
1376 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 }
1378
1379 // Adjust for when the inverted text is before the screen,
1380 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001381 if (wlv.tocol <= wlv.vcol)
1382 wlv.fromcol = 0;
1383 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1384 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385
1386#ifdef FEAT_LINEBREAK
1387 // When w_skipcol is non-zero, first line needs 'showbreak'
1388 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001389 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390#endif
1391#ifdef FEAT_SPELL
1392 // When spell checking a word we need to figure out the start of the
1393 // word and if it's badly spelled or not.
1394 if (has_spell)
1395 {
1396 int len;
1397 colnr_T linecol = (colnr_T)(ptr - line);
1398 hlf_T spell_hlf = HLF_COUNT;
1399
1400 pos = wp->w_cursor;
1401 wp->w_cursor.lnum = lnum;
1402 wp->w_cursor.col = linecol;
1403 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1404
1405 // spell_move_to() may call ml_get() and make "line" invalid
1406 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1407 ptr = line + linecol;
1408
1409 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1410 {
1411 // no bad word found at line start, don't check until end of a
1412 // word
1413 spell_hlf = HLF_COUNT;
1414 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1415 }
1416 else
1417 {
1418 // bad word found, use attributes until end of word
1419 word_end = wp->w_cursor.col + len + 1;
1420
1421 // Turn index into actual attributes.
1422 if (spell_hlf != HLF_COUNT)
1423 spell_attr = highlight_attr[spell_hlf];
1424 }
1425 wp->w_cursor = pos;
1426
1427# ifdef FEAT_SYN_HL
1428 // Need to restart syntax highlighting for this line.
1429 if (has_syntax)
1430 syntax_start(wp, lnum);
1431# endif
1432 }
1433#endif
1434 }
1435
1436 // Correct highlighting for cursor that can't be disabled.
1437 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001438 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 {
1440 if (noinvcur)
1441 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001442 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 {
1444 // highlighting starts at cursor, let it start just after the
1445 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001446 fromcol_prev = wlv.fromcol;
1447 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001449 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 // restart highlighting after the cursor
1451 fromcol_prev = wp->w_virtcol;
1452 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001453 if (wlv.fromcol >= wlv.tocol)
1454 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 }
1456
1457#ifdef FEAT_SEARCH_EXTRA
1458 if (!number_only)
1459 {
1460 v = (long)(ptr - line);
1461 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1462 &line, &screen_search_hl,
1463 &search_attr);
1464 ptr = line + v; // "line" may have been updated
1465 }
1466#endif
1467
1468#ifdef FEAT_SYN_HL
1469 // Cursor line highlighting for 'cursorline' in the current window.
1470 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1471 {
1472 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001473 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 if (!(wp == curwin && VIsual_active)
1475 && wp->w_p_culopt_flags != CULOPT_NBR)
1476 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001477 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1479
1480 // Only set line_attr here when "screenline" is not present in
1481 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 {
1484 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001485# ifdef FEAT_SIGNS
1486 // Combine the 'cursorline' and sign highlighting, depending on
1487 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001488 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001489 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001490 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001491 line_attr = hl_combine_attr(cul_attr, line_attr);
1492 else
1493 line_attr = hl_combine_attr(line_attr, cul_attr);
1494 }
1495 else
1496# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001497# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001498 // let the line attribute overrule 'cursorline', otherwise
1499 // it disappears when both have background set;
1500 // 'cursorline' can use underline or bold to make it show
1501 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001502# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001503 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001504# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 }
1506 else
1507 {
1508 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1510 }
1511 area_highlighting = TRUE;
1512 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 }
1514#endif
1515
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001516#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 {
1518 char_u *prop_start;
1519
1520 text_prop_count = get_text_props(wp->w_buffer, lnum,
1521 &prop_start, FALSE);
1522 if (text_prop_count > 0)
1523 {
1524 // Make a copy of the properties, so that they are properly
1525 // aligned.
1526 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1527 if (text_props != NULL)
1528 mch_memmove(text_props, prop_start,
1529 text_prop_count * sizeof(textprop_T));
1530
1531 // Allocate an array for the indexes.
1532 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001533 if (text_prop_idxs == NULL)
1534 VIM_CLEAR(text_props);
1535
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 area_highlighting = TRUE;
1537 extra_check = TRUE;
1538 }
1539 }
1540#endif
1541
Bram Moolenaar1306b362022-08-06 15:59:06 +01001542 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543
1544 // Repeat for the whole displayed line.
1545 for (;;)
1546 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001547 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001548#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001549 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001550#endif
1551#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001552 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001554
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001556 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001558#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001559 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001560 {
1561 cul_attr = 0;
1562 line_attr = line_attr_save;
1563 }
1564#endif
1565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001567 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001569 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 if (cmdwin_type != 0 && wp == curwin)
1571 {
1572 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001573 wlv.n_extra = 1;
1574 wlv.c_extra = cmdwin_type;
1575 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001576 wlv.char_attr =
1577 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001578 }
1579 }
1580#endif
1581
1582#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001585 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001586 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 }
1588#endif
1589
1590#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001593 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001594 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001596 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598#endif
1599
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001602 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001603 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001604 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 }
1606
1607#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001608 // Check if 'breakindent' applies and show it.
1609 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1610 if (wlv.n_extra == 0)
1611 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612#endif
1613
1614#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001615 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001617 char_u *sbr;
1618
Bram Moolenaar1306b362022-08-06 15:59:06 +01001619 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001621 if (wlv.filler_todo > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 {
1623 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001624 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001626 wlv.c_extra = '-';
1627 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 }
1629 else
1630 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 wlv.c_extra = wp->w_fill_chars.diff;
1632 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633 }
1634# ifdef FEAT_RIGHTLEFT
1635 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001636 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 else
1638# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001639 wlv.n_extra = wp->w_width - wlv.col;
1640 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 }
1642# endif
1643# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001644 sbr = get_showbreak_value(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001645 if (*sbr != NUL && wlv.need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 {
1647 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 wlv.p_extra = sbr;
1649 wlv.c_extra = NUL;
1650 wlv.c_final = NUL;
1651 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001652 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001653 wlv.need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001654 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 // Correct end of highlighted area for 'showbreak',
1656 // required when 'linebreak' is also set.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001657 if (wlv.tocol == wlv.vcol)
1658 wlv.tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001660 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1661 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662# ifdef FEAT_SYN_HL
1663 // combine 'showbreak' with 'cursorline'
1664 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001665 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1666 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667# endif
1668 }
1669# endif
1670 }
1671#endif
1672
Bram Moolenaar1306b362022-08-06 15:59:06 +01001673 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001675 wlv.draw_state = WL_LINE;
1676 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 {
1678 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001679 wlv.n_extra = wlv.saved_n_extra;
1680 wlv.c_extra = wlv.saved_c_extra;
1681 wlv.c_final = wlv.saved_c_final;
1682 wlv.p_extra = wlv.saved_p_extra;
1683 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 }
1685 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 }
1688 }
1689#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001690 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001691 && wlv.vcol >= left_curline_col
1692 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001694 cul_attr = HL_ATTR(HLF_CUL);
1695 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 }
1697#endif
1698
1699 // When still displaying '$' of change command, stop at cursor.
1700 // When only displaying the (relative) line number and that's done,
1701 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001702 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001703 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001704 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001706 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707#endif
1708 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001710 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1711 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 // Pretend we have finished updating the window. Except when
1713 // 'cursorcolumn' is set.
1714#ifdef FEAT_SYN_HL
1715 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001716 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 else
1718#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001719 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 break;
1721 }
1722
Bram Moolenaar1306b362022-08-06 15:59:06 +01001723 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 {
1725 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001726 if (wlv.vcol == wlv.fromcol
1727 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1728 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 && (*mb_ptr2cells)(ptr) > 1)
1730 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001731 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001732 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 area_attr = vi_attr; // start highlighting
1734 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001735 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001736 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 area_attr = 0; // stop highlighting
1738
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001739#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740 if (text_props != NULL)
1741 {
1742 int pi;
1743 int bcol = (int)(ptr - line);
1744
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001746# ifdef FEAT_LINEBREAK
1747 && !in_linebreak
1748# endif
1749 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 --bcol; // still working on the previous char, e.g. Tab
1751
1752 // Check if any active property ends.
1753 for (pi = 0; pi < text_props_active; ++pi)
1754 {
1755 int tpi = text_prop_idxs[pi];
1756
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001757 if (text_props[tpi].tp_col != MAXCOL
1758 && bcol >= text_props[tpi].tp_col - 1
1759 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 {
1761 if (pi + 1 < text_props_active)
1762 mch_memmove(text_prop_idxs + pi,
1763 text_prop_idxs + pi + 1,
1764 sizeof(int)
1765 * (text_props_active - (pi + 1)));
1766 --text_props_active;
1767 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001768# ifdef FEAT_LINEBREAK
1769 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001770 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001771 syntax_attr = 0;
1772# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
1774 }
1775
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001776# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001778 // not on the next char yet, don't start another prop
1779 --bcol;
1780# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001782 // With 'nowrap' and not in the first screen line only "below"
1783 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001785 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001786 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001787 && (wp->w_p_wrap
1788 || wlv.row == startrow
1789 || (text_props[text_prop_next].tp_flags
1790 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001791 || (bcol == 0 &&
1792 (text_props[text_prop_next].tp_flags
1793 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001794 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001795 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001796 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001797 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1798 {
1799 // first display the '$' after the line
1800 text_prop_follows = TRUE;
1801 break;
1802 }
1803 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001804 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001805 + text_props[text_prop_next].tp_len)
1806 text_prop_idxs[text_props_active++] = text_prop_next;
1807 ++text_prop_next;
1808 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001810 if (wlv.n_extra == 0 || !extra_for_textprop)
1811 {
1812 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001813 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001814 text_prop_flags = 0;
1815 text_prop_type = NULL;
1816 text_prop_id = 0;
1817 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001820 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001821 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001822 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001823
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 // Sort the properties on priority and/or starting last.
1825 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001826 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001827 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001828 sort_text_props(wp->w_buffer, text_props,
1829 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830
1831 for (pi = 0; pi < text_props_active; ++pi)
1832 {
1833 int tpi = text_prop_idxs[pi];
1834 proptype_T *pt = text_prop_type_by_id(
1835 wp->w_buffer, text_props[tpi].tp_type);
1836
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001837 if (pt != NULL && (pt->pt_hl_id > 0
1838 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001839 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001841 if (pt->pt_hl_id > 0)
1842 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 text_prop_type = pt;
1844 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001845 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001846 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001847 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001848 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001849 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 }
1851 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001852 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001853 && -text_prop_id
1854 <= wp->w_buffer->b_textprop_text.ga_len)
1855 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001856 textprop_T *tp = &text_props[used_tpi];
1857 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001858 ->b_textprop_text.ga_data)[
1859 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001860 int above = (tp->tp_flags
1861 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862
1863 // reset the ID in the copy to avoid it being used
1864 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001865 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001866
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001867 if (p != NULL)
1868 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001869 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001870 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001871 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001872 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001873 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1874 int padding = tp->tp_col == MAXCOL
1875 && tp->tp_len > 1
1876 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001877
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001878 // Insert virtual text before the current
1879 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001880 wlv.p_extra = p;
1881 wlv.c_extra = NUL;
1882 wlv.c_final = NUL;
1883 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001884 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001885 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001886 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001887 // restore search_attr and area_attr when n_extra
1888 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001889 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001890 saved_area_attr = area_attr;
1891 search_attr = 0;
1892 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001893 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001894 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 if (*ptr == NUL)
1896 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001897 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001898#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001899 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001900 {
1901 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001902 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001903 wlv.need_showbreak = FALSE;
1904 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001905 }
1906#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001907 if ((right || above || below || !wrap
1908 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001909 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001910 char_u *prev_p_extra = wlv.p_extra;
1911 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001912
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001913 // Take care of padding, right-align and
1914 // truncation.
1915 // Shared with win_lbr_chartabsize(), must do
1916 // exactly the same.
1917 start_line = text_prop_position(wp, tp,
1918 wlv.col,
1919 &wlv.n_extra, &wlv.p_extra,
1920 &n_attr, &n_attr_skip);
1921 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001922 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001923 // wlv.p_extra was allocated
1924 vim_free(p_extra_free2);
1925 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001926 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001927
Bram Moolenaara4abe512022-09-15 19:44:09 +01001928 if (lcs_eol_one < 0 && wlv.col
1929 + wlv.n_extra - 2 > wp->w_width)
1930 // don't bail out at end of line
1931 lcs_eol_one = 0;
1932
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001933 // When 'wrap' is off then for "below" we need
1934 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001935 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001936 {
1937 draw_screen_line(wp, &wlv);
1938
1939 // When line got too long for screen break
1940 // here.
1941 if (wlv.row == endrow)
1942 {
1943 ++wlv.row;
1944 break;
1945 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 win_line_start(wp, &wlv, TRUE);
1947 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001948 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001949 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001950 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001951
1952 // If another text prop follows the condition below at
1953 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001954 // If this is an "above" text prop and 'nowrap' the we
1955 // must wrap anyway.
1956 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001957 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001958 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001960 else if (text_prop_next < text_prop_count
1961 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001962 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1963 || (!wp->w_p_wrap
1964 && wlv.col == wp->w_width - 1
1965 && (text_props[text_prop_next].tp_flags
1966 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001967 // When at last-but-one character and a text property
1968 // follows after it, we may need to flush the line after
1969 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001970 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001971 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001972 }
1973#endif
1974
Bram Moolenaare38fc862022-08-11 17:24:50 +01001975#ifdef FEAT_SEARCH_EXTRA
1976 if (wlv.n_extra == 0)
1977 {
1978 // Check for start/end of 'hlsearch' and other matches.
1979 // After end, check for start/end of next match.
1980 // When another match, have to check for start again.
1981 v = (long)(ptr - line);
1982 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1983 &screen_search_hl, &has_match_conc,
1984 &match_conc, did_line_attr, lcs_eol_one,
1985 &on_last_col);
1986 ptr = line + v; // "line" may have been changed
1987 prev_ptr = ptr;
1988
1989 // Do not allow a conceal over EOL otherwise EOL will be missed
1990 // and bad things happen.
1991 if (*ptr == NUL)
1992 has_match_conc = 0;
1993 }
1994#endif
1995
1996#ifdef FEAT_DIFF
1997 if (wlv.diff_hlf != (hlf_T)0)
1998 {
1999 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2000 && wlv.n_extra == 0)
2001 wlv.diff_hlf = HLF_TXD; // changed text
2002 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2003 && wlv.n_extra == 0)
2004 wlv.diff_hlf = HLF_CHD; // changed line
2005 line_attr = HL_ATTR(wlv.diff_hlf);
2006 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2007 && wp->w_p_culopt_flags != CULOPT_NBR
2008 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2009 && wlv.vcol <= right_curline_col)))
2010 line_attr = hl_combine_attr(
2011 line_attr, HL_ATTR(HLF_CUL));
2012 }
2013#endif
2014
Bram Moolenaara74fda62019-10-19 17:38:03 +02002015#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002017 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002018 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002019# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002020 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002022# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002023 // Get syntax attribute.
2024 if (has_syntax)
2025 {
2026 // Get the syntax attribute for the character. If there
2027 // is an error, disable syntax highlighting.
2028 save_did_emsg = did_emsg;
2029 did_emsg = FALSE;
2030
2031 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002032 if (v == prev_syntax_col)
2033 // at same column again
2034 syntax_attr = prev_syntax_attr;
2035 else
2036 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002037# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002038 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002039# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002040 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002041# ifdef FEAT_SPELL
2042 has_spell ? &can_spell :
2043# endif
2044 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002045 prev_syntax_col = v;
2046 prev_syntax_attr = syntax_attr;
2047 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002048
Bram Moolenaar34390282019-10-16 14:38:26 +02002049 if (did_emsg)
2050 {
2051 wp->w_s->b_syn_error = TRUE;
2052 has_syntax = FALSE;
2053 syntax_attr = 0;
2054 }
2055 else
2056 did_emsg = save_did_emsg;
2057# ifdef SYN_TIME_LIMIT
2058 if (wp->w_s->b_syn_slow)
2059 has_syntax = FALSE;
2060# endif
2061
2062 // Need to get the line again, a multi-line regexp may
2063 // have made it invalid.
2064 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2065 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002066 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002067# ifdef FEAT_CONCEAL
2068 // no concealing past the end of the line, it interferes
2069 // with line highlighting
2070 if (*ptr == NUL)
2071 syntax_flags = 0;
2072 else
2073 syntax_flags = get_syntax_info(&syntax_seqnr);
2074# endif
2075 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002076 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002077# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002078 // Combine text property highlight into syntax highlight.
2079 if (text_prop_type != NULL)
2080 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002081 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002082 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2083 else
2084 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002085 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002086 }
2087# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002088#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002089
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 // Decide which of the highlight attributes to use.
2091 attr_pri = TRUE;
2092#ifdef LINE_ATTR
2093 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002094 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002095 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002096 if (!highlight_match)
2097 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002099# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002100 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002101# endif
2102 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002104 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002105 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002106# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002108# endif
2109 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002110 else if (line_attr != 0
2111 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2112 || wlv.vcol < wlv.fromcol
2113 || vcol_prev < fromcol_prev
2114 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 {
2116 // Use line_attr when not in the Visual or 'incsearch' area
2117 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002118# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002119 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002120# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002121 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002122# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123 attr_pri = FALSE;
2124 }
2125#else
2126 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130#endif
2131 else
2132 {
2133 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002135 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002136#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002138#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002139 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002140#ifdef FEAT_PROP_POPUP
2141 // override with text property highlight when "override" is TRUE
2142 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002144#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002146
2147 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002148 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002149 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002150 if (wlv.char_attr == 0)
2151 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002152 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002153 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002154 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155
2156 // Get the next character to put on the screen.
2157
2158 // The "p_extra" points to the extra stuff that is inserted to
2159 // represent special characters (non-printable stuff) and other
2160 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2163 // "p_extra[n_extra]".
2164 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002168 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002169 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2170 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2172 if (enc_utf8 && utf_char2len(c) > 1)
2173 {
2174 mb_utf8 = TRUE;
2175 u8cc[0] = 0;
2176 c = 0xc0;
2177 }
2178 else
2179 mb_utf8 = FALSE;
2180 }
2181 else
2182 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 if (has_mbyte)
2185 {
2186 mb_c = c;
2187 if (enc_utf8)
2188 {
2189 // If the UTF-8 character is more than one byte:
2190 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002194 mb_l = 1;
2195 else if (mb_l > 1)
2196 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198 mb_utf8 = TRUE;
2199 c = 0xc0;
2200 }
2201 }
2202 else
2203 {
2204 // if this is a DBCS character, put it in "mb_c"
2205 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 mb_l = 1;
2208 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002209 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 }
2211 if (mb_l == 0) // at the NUL at end-of-line
2212 mb_l = 1;
2213
2214 // If a double-width char doesn't fit display a '>' in the
2215 // last column.
2216 if ((
2217# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002218 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002220 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002221 && (*mb_char2cells)(mb_c) == 2)
2222 {
2223 c = '>';
2224 mb_c = c;
2225 mb_l = 1;
2226 mb_utf8 = FALSE;
2227 multi_attr = HL_ATTR(HLF_AT);
2228#ifdef FEAT_SYN_HL
2229 if (cul_attr)
2230 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2231#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002232 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002233
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234 // put the pointer back to output the double-width
2235 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002236 ++wlv.n_extra;
2237 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 }
2239 else
2240 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002241 wlv.n_extra -= mb_l - 1;
2242 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 }
2244 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002248#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002250 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002251 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002252 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002253 if (search_attr == 0)
2254 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002255 if (area_attr == 0 && *ptr != NUL)
2256 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002257 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002258#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 }
2260 else
2261 {
2262#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002263 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002265 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 // Get a character from the line itself.
2268 c = *ptr;
2269#ifdef FEAT_LINEBREAK
2270 c0 = *ptr;
2271#endif
2272 if (has_mbyte)
2273 {
2274 mb_c = c;
2275 if (enc_utf8)
2276 {
2277 // If the UTF-8 character is more than one byte: Decode it
2278 // into "mb_c".
2279 mb_l = utfc_ptr2len(ptr);
2280 mb_utf8 = FALSE;
2281 if (mb_l > 1)
2282 {
2283 mb_c = utfc_ptr2char(ptr, u8cc);
2284 // Overlong encoded ASCII or ASCII with composing char
2285 // is displayed normally, except a NUL.
2286 if (mb_c < 0x80)
2287 {
2288 c = mb_c;
2289#ifdef FEAT_LINEBREAK
2290 c0 = mb_c;
2291#endif
2292 }
2293 mb_utf8 = TRUE;
2294
2295 // At start of the line we can have a composing char.
2296 // Draw it as a space with a composing char.
2297 if (utf_iscomposing(mb_c))
2298 {
2299 int i;
2300
2301 for (i = Screen_mco - 1; i > 0; --i)
2302 u8cc[i] = u8cc[i - 1];
2303 u8cc[0] = mb_c;
2304 mb_c = ' ';
2305 }
2306 }
2307
2308 if ((mb_l == 1 && c >= 0x80)
2309 || (mb_l >= 1 && mb_c == 0)
2310 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2311 {
2312 // Illegal UTF-8 byte: display as <xx>.
2313 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002314 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315# ifdef FEAT_RIGHTLEFT
2316 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002317 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002319 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 c = *wlv.p_extra;
2321 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2324 wlv.c_extra = NUL;
2325 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 if (area_attr == 0 && search_attr == 0)
2327 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002329 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002330 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002331 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002332 }
2333 }
2334 else if (mb_l == 0) // at the NUL at end-of-line
2335 mb_l = 1;
2336#ifdef FEAT_ARABIC
2337 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2338 {
2339 // Do Arabic shaping.
2340 int pc, pc1, nc;
2341 int pcc[MAX_MCO];
2342
2343 // The idea of what is the previous and next
2344 // character depends on 'rightleft'.
2345 if (wp->w_p_rl)
2346 {
2347 pc = prev_c;
2348 pc1 = prev_c1;
2349 nc = utf_ptr2char(ptr + mb_l);
2350 prev_c1 = u8cc[0];
2351 }
2352 else
2353 {
2354 pc = utfc_ptr2char(ptr + mb_l, pcc);
2355 nc = prev_c;
2356 pc1 = pcc[0];
2357 }
2358 prev_c = mb_c;
2359
2360 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2361 }
2362 else
2363 prev_c = mb_c;
2364#endif
2365 }
2366 else // enc_dbcs
2367 {
2368 mb_l = MB_BYTE2LEN(c);
2369 if (mb_l == 0) // at the NUL at end-of-line
2370 mb_l = 1;
2371 else if (mb_l > 1)
2372 {
2373 // We assume a second byte below 32 is illegal.
2374 // Hopefully this is OK for all double-byte encodings!
2375 if (ptr[1] >= 32)
2376 mb_c = (c << 8) + ptr[1];
2377 else
2378 {
2379 if (ptr[1] == NUL)
2380 {
2381 // head byte at end of line
2382 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002383 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 }
2385 else
2386 {
2387 // illegal tail byte
2388 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002389 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002391 wlv.p_extra = wlv.extra;
2392 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002393 wlv.c_extra = NUL;
2394 wlv.c_final = NUL;
2395 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 if (area_attr == 0 && search_attr == 0)
2397 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002398 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002399 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002400 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 // save current attr
2402 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403 }
2404 mb_c = c;
2405 }
2406 }
2407 }
2408 // If a double-width char doesn't fit display a '>' in the
2409 // last column; the character is displayed at the start of the
2410 // next line.
2411 if ((
2412# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002413 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002415 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 && (*mb_char2cells)(mb_c) == 2)
2417 {
2418 c = '>';
2419 mb_c = c;
2420 mb_utf8 = FALSE;
2421 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002422 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 // Put pointer back so that the character will be
2424 // displayed at the start of the next line.
2425 --ptr;
2426#ifdef FEAT_CONCEAL
2427 did_decrement_ptr = TRUE;
2428#endif
2429 }
2430 else if (*ptr != NUL)
2431 ptr += mb_l - 1;
2432
2433 // If a double-width char doesn't fit at the left side display
2434 // a '<' in the first column. Don't do this for unprintable
2435 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002438 wlv.n_extra = 1;
2439 wlv.c_extra = MB_FILLER_CHAR;
2440 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 c = ' ';
2442 if (area_attr == 0 && search_attr == 0)
2443 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002444 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002445 extra_attr = hl_combine_attr(
2446 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 }
2449 mb_c = c;
2450 mb_utf8 = FALSE;
2451 mb_l = 1;
2452 }
2453
2454 }
2455 ++ptr;
2456
2457 if (extra_check)
2458 {
2459#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 // Check spelling (unless at the end of the line).
2461 // Only do this when there is no syntax highlighting, the
2462 // @Spell cluster is not used or the current syntax item
2463 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002464 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002465 if (has_spell && v >= word_end && v > cur_checked_col)
2466 {
2467 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002468 // do not calculate cap_col at the end of the line or when
2469 // only white space is following
2470 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471# ifdef FEAT_SYN_HL
2472 !has_syntax ||
2473# endif
2474 can_spell))
2475 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002476 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 int len;
2478 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002479
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482
2483 // Use nextline[] if possible, it has the start of the
2484 // next line concatenated.
2485 if ((prev_ptr - line) - nextlinecol >= 0)
2486 p = nextline + (prev_ptr - line) - nextlinecol;
2487 else
2488 p = prev_ptr;
2489 cap_col -= (int)(prev_ptr - line);
2490 len = spell_check(wp, p, &spell_hlf, &cap_col,
2491 nochange);
2492 word_end = v + len;
2493
2494 // In Insert mode only highlight a word that
2495 // doesn't touch the cursor.
2496 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002497 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 && wp->w_cursor.lnum == lnum
2499 && wp->w_cursor.col >=
2500 (colnr_T)(prev_ptr - line)
2501 && wp->w_cursor.col < (colnr_T)word_end)
2502 {
2503 spell_hlf = HLF_COUNT;
2504 spell_redraw_lnum = lnum;
2505 }
2506
2507 if (spell_hlf == HLF_COUNT && p != prev_ptr
2508 && (p - nextline) + len > nextline_idx)
2509 {
2510 // Remember that the good word continues at the
2511 // start of the next line.
2512 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002513 checked_col = (int)((p - nextline)
2514 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 }
2516
2517 // Turn index into actual attributes.
2518 if (spell_hlf != HLF_COUNT)
2519 spell_attr = highlight_attr[spell_hlf];
2520
2521 if (cap_col > 0)
2522 {
2523 if (p != prev_ptr
2524 && (p - nextline) + cap_col >= nextline_idx)
2525 {
2526 // Remember that the word in the next line
2527 // must start with a capital.
2528 capcol_lnum = lnum + 1;
2529 cap_col = (int)((p - nextline) + cap_col
2530 - nextline_idx);
2531 }
2532 else
2533 // Compute the actual column.
2534 cap_col += (int)(prev_ptr - line);
2535 }
2536 }
2537 }
2538 if (spell_attr != 0)
2539 {
2540 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2542 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002544 wlv.char_attr = hl_combine_attr(spell_attr,
2545 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
2547#endif
2548#ifdef FEAT_LINEBREAK
2549 // Found last space before word: check for line break.
2550 if (wp->w_p_lbr && c0 == c
2551 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2552 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002553 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2554 : 0;
2555 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002556 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002558 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002559# ifdef FEAT_PROP_POPUP
2560 // do not want virtual text counted here
2561 cts.cts_has_prop_with_text = FALSE;
2562# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002564 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002565
2566 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002567 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002568 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002569 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2571 if (wlv.n_extra < 0)
2572 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002573 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002574 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002575 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002576 // line break, but for TABs the highlighting should
2577 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002578 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002579
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002582 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002583 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 wp->w_buffer->b_p_vts_array) - 1;
2585# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002587 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588# endif
2589
Bram Moolenaar1306b362022-08-06 15:59:06 +01002590 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2591 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002592# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002594 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002595# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 if (VIM_ISWHITE(c))
2597 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002598# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002599 if (c == TAB)
2600 // See "Tab alignment" below.
2601 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002602# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 if (!wp->w_p_list)
2604 c = ' ';
2605 }
2606 }
2607#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002608 in_multispace = c == ' '
2609 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2610 if (!in_multispace)
2611 multispace_pos = 0;
2612
Bram Moolenaareed9d462021-02-15 20:38:25 +01002613 // 'list': Change char 160 to 'nbsp' and space to 'space'
2614 // setting in 'listchars'. But not when the character is
2615 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 if (wp->w_p_list
2617 && ((((c == 160 && mb_l == 1)
2618 || (mb_utf8
2619 && ((mb_c == 160 && mb_l == 2)
2620 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002621 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 || (c == ' '
2623 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002624 && (wp->w_lcs_chars.space
2625 || (in_multispace
2626 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002627 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 && ptr - line <= trailcol)))
2629 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002630 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2631 {
2632 c = wp->w_lcs_chars.multispace[multispace_pos++];
2633 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2634 multispace_pos = 0;
2635 }
2636 else
2637 c = (c == ' ') ? wp->w_lcs_chars.space
2638 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 if (area_attr == 0 && search_attr == 0)
2640 {
2641 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002642 extra_attr = hl_combine_attr(wlv.win_attr,
2643 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 }
2646 mb_c = c;
2647 if (enc_utf8 && utf_char2len(c) > 1)
2648 {
2649 mb_utf8 = TRUE;
2650 u8cc[0] = 0;
2651 c = 0xc0;
2652 }
2653 else
2654 mb_utf8 = FALSE;
2655 }
2656
zeertzjq2e7cba32022-06-10 15:30:32 +01002657 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2658 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002660 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2661 && wp->w_lcs_chars.leadmultispace != NULL)
2662 {
2663 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002664 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2665 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002666 multispace_pos = 0;
2667 }
2668
2669 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2670 c = wp->w_lcs_chars.trail;
2671
2672 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2673 c = wp->w_lcs_chars.lead;
2674
zeertzjq2e7cba32022-06-10 15:30:32 +01002675 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002676 c = wp->w_lcs_chars.space;
2677
2678
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 if (!attr_pri)
2680 {
2681 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002682 extra_attr = hl_combine_attr(wlv.win_attr,
2683 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002684 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 }
2686 mb_c = c;
2687 if (enc_utf8 && utf_char2len(c) > 1)
2688 {
2689 mb_utf8 = TRUE;
2690 u8cc[0] = 0;
2691 c = 0xc0;
2692 }
2693 else
2694 mb_utf8 = FALSE;
2695 }
2696 }
2697
2698 // Handling of non-printable characters.
2699 if (!vim_isprintc(c))
2700 {
2701 // when getting a character from the file, we may have to
2702 // turn it into something else on the way to putting it
2703 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002704 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 {
2706 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002707 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002709 char_u *sbr = get_showbreak_value(wp);
2710
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 // only adjust the tab_len, when at the first column
2712 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002713 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2714 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715#endif
2716 // tab amount depends on current column
2717#ifdef FEAT_VARTABS
2718 tab_len = tabstop_padding(vcol_adjusted,
2719 wp->w_buffer->b_p_ts,
2720 wp->w_buffer->b_p_vts_array) - 1;
2721#else
2722 tab_len = (int)wp->w_buffer->b_p_ts
2723 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2724#endif
2725
2726#ifdef FEAT_LINEBREAK
2727 if (!wp->w_p_lbr || !wp->w_p_list)
2728#endif
2729 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002730 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731#ifdef FEAT_LINEBREAK
2732 else
2733 {
2734 char_u *p;
2735 int len;
2736 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002737 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002739# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002740 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002742 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002743
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002745 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 && old_boguscols > 0
2747 && wlv.n_extra > tab_len)
2748 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002749# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002750 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002752 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002753 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002754 if (wp->w_lcs_chars.tab3)
2755 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 if (wlv.n_extra > 0)
2757 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002758 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002760 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002762 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002764 vim_memset(p, ' ', len);
2765 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002766 vim_free(wlv.p_extra_free);
2767 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002768 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002770 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002772 if (*p == NUL)
2773 {
2774 tab_len = i;
2775 break;
2776 }
2777
2778 // if tab3 is given, use it for the last char
2779 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2780 lcs = wp->w_lcs_chars.tab3;
2781 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002784 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002785 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002786# ifdef FEAT_CONCEAL
2787 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2788 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002789 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002791# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002793 }
2794#endif
2795#ifdef FEAT_CONCEAL
2796 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002797 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798
2799 // Tab alignment should be identical regardless of
2800 // 'conceallevel' value. So tab compensates of all
2801 // previous concealed characters, and thus resets
2802 // vcol_off and boguscols accumulated so far in the
2803 // line. Note that the tab can be longer than
2804 // 'tabstop' when there are concealed characters.
2805 FIX_FOR_BOGUSCOLS;
2806
2807 // Make sure, the highlighting for the tab char will be
2808 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002809 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002811 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 tab_len += vc_saved;
2813 }
2814#endif
2815 mb_utf8 = FALSE; // don't draw as UTF-8
2816 if (wp->w_p_list)
2817 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002819 ? wp->w_lcs_chars.tab3
2820 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821#ifdef FEAT_LINEBREAK
2822 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 else
2825#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002826 wlv.c_extra = wp->w_lcs_chars.tab2;
2827 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 extra_attr = hl_combine_attr(wlv.win_attr,
2830 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002831 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 mb_c = c;
2833 if (enc_utf8 && utf_char2len(c) > 1)
2834 {
2835 mb_utf8 = TRUE;
2836 u8cc[0] = 0;
2837 c = 0xc0;
2838 }
2839 }
2840 else
2841 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 wlv.c_final = NUL;
2843 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844 c = ' ';
2845 }
2846 }
2847 else if (c == NUL
2848 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002849 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2850 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 && VIsual_mode != Ctrl_V
2852 && (
2853# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002854 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002856 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 && !(noinvcur
2858 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002859 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002860 && lcs_eol_one > 0)
2861 {
2862 // Display a '$' after the line or highlight an extra
2863 // character if the line break is included.
2864#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2865 // For a diff line the highlighting continues after the
2866 // "$".
2867 if (
2868# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870# ifdef LINE_ATTR
2871 &&
2872# endif
2873# endif
2874# ifdef LINE_ATTR
2875 line_attr == 0
2876# endif
2877 )
2878#endif
2879 {
2880 // In virtualedit, visual selections may extend
2881 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002882 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002883 && wlv.tocol != MAXCOL
2884 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002886 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002888 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2889 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 else
2891 c = ' ';
2892 lcs_eol_one = -1;
2893 --ptr; // put it back at the NUL
2894 if (!attr_pri)
2895 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002896 extra_attr = hl_combine_attr(wlv.win_attr,
2897 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 n_attr = 1;
2899 }
2900 mb_c = c;
2901 if (enc_utf8 && utf_char2len(c) > 1)
2902 {
2903 mb_utf8 = TRUE;
2904 u8cc[0] = 0;
2905 c = 0xc0;
2906 }
2907 else
2908 mb_utf8 = FALSE; // don't draw as UTF-8
2909 }
2910 else if (c != NUL)
2911 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002912 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2913 if (wlv.n_extra == 0)
2914 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915#ifdef FEAT_RIGHTLEFT
2916 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002917 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002919 wlv.c_extra = NUL;
2920 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921#ifdef FEAT_LINEBREAK
2922 if (wp->w_p_lbr)
2923 {
2924 char_u *p;
2925
Bram Moolenaar1306b362022-08-06 15:59:06 +01002926 c = *wlv.p_extra;
2927 p = alloc(wlv.n_extra + 1);
2928 vim_memset(p, ' ', wlv.n_extra);
2929 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2930 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002931 vim_free(wlv.p_extra_free);
2932 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 }
2934 else
2935#endif
2936 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002937 wlv.n_extra = byte2cells(c) - 1;
2938 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 }
2940 if (!attr_pri)
2941 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002942 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002943 extra_attr = hl_combine_attr(wlv.win_attr,
2944 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 }
2947 mb_utf8 = FALSE; // don't draw as UTF-8
2948 }
2949 else if (VIsual_active
2950 && (VIsual_mode == Ctrl_V
2951 || VIsual_mode == 'v')
2952 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002953 && wlv.tocol != MAXCOL
2954 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 && (
2956#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002957 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002959 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 {
2961 c = ' ';
2962 --ptr; // put it back at the NUL
2963 }
2964#if defined(LINE_ATTR)
2965 else if ((
2966# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968# endif
2969# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971# endif
2972 line_attr != 0
2973 ) && (
2974# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002975 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002977 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002979 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002980# endif
2981 < wp->w_width)))
2982 {
2983 // Highlight until the right side of the window
2984 c = ' ';
2985 --ptr; // put it back at the NUL
2986
2987 // Remember we do the char for line highlighting.
2988 ++did_line_attr;
2989
2990 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002993 || (wp->w_p_list &&
2994 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 wlv.diff_hlf = HLF_CHD;
3000 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3004 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003006 || (wlv.vcol >= left_curline_col
3007 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 wlv.char_attr = hl_combine_attr(
3009 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 }
3011 }
3012# endif
3013# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003014 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003017 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3018 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003020 if (!wlv.cul_screenline
3021 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003022 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 wlv.char_attr = hl_combine_attr(
3024 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 }
3026 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3028 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 }
3030# endif
3031 }
3032#endif
3033 }
3034
3035#ifdef FEAT_CONCEAL
3036 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003037 && (wp != curwin || lnum != wp->w_cursor.lnum
3038 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3040 && !(lnum_in_visual_area
3041 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003044 if (((prev_syntax_id != syntax_seqnr
3045 && (syntax_flags & HL_CONCEAL) != 0)
3046 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003047 && (syn_get_sub_char() != NUL
3048 || (has_match_conc && match_conc)
3049 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 && wp->w_p_cole != 3)
3051 {
3052 // First time at this concealed item: display one
3053 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003054 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 c = match_conc;
3056 else if (syn_get_sub_char() != NUL)
3057 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003058 else if (wp->w_lcs_chars.conceal != NUL)
3059 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 else
3061 c = ' ';
3062
3063 prev_syntax_id = syntax_seqnr;
3064
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 if (wlv.n_extra > 0)
3066 wlv.vcol_off += wlv.n_extra;
3067 wlv.vcol += wlv.n_extra;
3068 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
3070# ifdef FEAT_RIGHTLEFT
3071 if (wp->w_p_rl)
3072 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 wlv.col -= wlv.n_extra;
3074 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 }
3076 else
3077# endif
3078 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 wlv.boguscols += wlv.n_extra;
3080 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 }
3082 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003083 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 n_attr = 0;
3085 }
3086 else if (n_skip == 0)
3087 {
3088 is_concealing = TRUE;
3089 n_skip = 1;
3090 }
3091 mb_c = c;
3092 if (enc_utf8 && utf_char2len(c) > 1)
3093 {
3094 mb_utf8 = TRUE;
3095 u8cc[0] = 0;
3096 c = 0xc0;
3097 }
3098 else
3099 mb_utf8 = FALSE; // don't draw as UTF-8
3100 }
3101 else
3102 {
3103 prev_syntax_id = 0;
3104 is_concealing = FALSE;
3105 }
3106
3107 if (n_skip > 0 && did_decrement_ptr)
3108 // not showing the '>', put pointer back to avoid getting stuck
3109 ++ptr;
3110
3111#endif // FEAT_CONCEAL
3112 }
3113
3114#ifdef FEAT_CONCEAL
3115 // In the cursor line and we may be concealing characters: correct
3116 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 && wp == curwin && lnum == wp->w_cursor.lnum
3119 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003120 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003122# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003124 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003126# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003127 wp->w_wcol = wlv.col - wlv.boguscols;
3128 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 did_wcol = TRUE;
3130 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003131# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003132 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003133# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 }
3135#endif
3136
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003137 // Use "extra_attr", but don't override visual selection highlighting,
3138 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003139 // Don't use "extra_attr" until n_attr_skip is zero.
3140 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003142 && (!attr_pri
3143#ifdef FEAT_PROP_POPUP
3144 || (text_prop_flags & PT_FLAG_OVERRIDE)
3145#endif
3146 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 {
3148#ifdef LINE_ATTR
3149 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003150 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 else
3152#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155
3156#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3157 // XIM don't send preedit_start and preedit_end, but they send
3158 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3159 // im_is_preediting() here.
3160 if (p_imst == IM_ON_THE_SPOT
3161 && xic != NULL
3162 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003163 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 && !p_imdisable
3165 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 {
3168 colnr_T tcol;
3169
3170 if (preedit_end_col == MAXCOL)
3171 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3172 else
3173 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 {
3176 if (feedback_old_attr < 0)
3177 {
3178 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003179 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 wlv.char_attr = im_get_feedback_attr(feedback_col);
3182 if (wlv.char_attr < 0)
3183 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 feedback_col++;
3185 }
3186 else if (feedback_old_attr >= 0)
3187 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003188 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 feedback_old_attr = -1;
3190 feedback_col = 0;
3191 }
3192 }
3193#endif
3194 // Handle the case where we are in column 0 but not on the first
3195 // character of the line and the user wants us to show us a
3196 // special character (via 'listchars' option "precedes:<char>".
3197 if (lcs_prec_todo != NUL
3198 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003199 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003200 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003201 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003203 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 && c != NUL)
3207 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003208 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 lcs_prec_todo = NUL;
3210 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3211 {
3212 // Double-width character being overwritten by the "precedes"
3213 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 wlv.c_extra = MB_FILLER_CHAR;
3215 wlv.c_final = NUL;
3216 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 }
3220 mb_c = c;
3221 if (enc_utf8 && utf_char2len(c) > 1)
3222 {
3223 mb_utf8 = TRUE;
3224 u8cc[0] = 0;
3225 c = 0xc0;
3226 }
3227 else
3228 mb_utf8 = FALSE; // don't draw as UTF-8
3229 if (!attr_pri)
3230 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 saved_attr3 = wlv.char_attr; // save current attr
3232 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 n_attr3 = 1;
3234 }
3235 }
3236
3237 // At end of the text line or just after the last character.
3238 if ((c == NUL
3239#if defined(LINE_ATTR)
3240 || did_line_attr == 1
3241#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 {
3244#ifdef FEAT_SEARCH_EXTRA
3245 // flag to indicate whether prevcol equals startcol of search_hl or
3246 // one of the matches
3247 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3248 (long)(ptr - line) - (c == NUL));
3249#endif
3250 // Invert at least one char, used for Visual and empty line or
3251 // highlight match at end of line. If it's beyond the last
3252 // char on the screen, just overwrite that one (tricky!) Not
3253 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003254 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003255 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 && (VIsual_mode != Ctrl_V
3257 || lnum == VIsual.lnum
3258 || lnum == curwin->w_cursor.lnum)
3259 && c == NUL)
3260#ifdef FEAT_SEARCH_EXTRA
3261 // highlight 'hlsearch' match at end of line
3262 || (prevcol_hl_flag
3263# ifdef FEAT_SYN_HL
3264 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3265 && !(wp == curwin && VIsual_active))
3266# endif
3267# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269# endif
3270# if defined(LINE_ATTR)
3271 && did_line_attr <= 1
3272# endif
3273 )
3274#endif
3275 ))
3276 {
3277 int n = 0;
3278
3279#ifdef FEAT_RIGHTLEFT
3280 if (wp->w_p_rl)
3281 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003282 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 n = 1;
3284 }
3285 else
3286#endif
3287 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 n = -1;
3290 }
3291 if (n != 0)
3292 {
3293 // At the window boundary, highlight the last character
3294 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 wlv.off += n;
3296 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 }
3298 else
3299 {
3300 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
3305#ifdef FEAT_SEARCH_EXTRA
3306 if (area_attr == 0)
3307 {
3308 // Use attributes from match with highest priority among
3309 // 'search_hl' and the match list.
3310 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 }
3313#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003315 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316#ifdef FEAT_RIGHTLEFT
3317 if (wp->w_p_rl)
3318 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003319 --wlv.col;
3320 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 }
3322 else
3323#endif
3324 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 ++wlv.col;
3326 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003328 ++wlv.vcol;
3329 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
3331 }
3332
3333 // At end of the text line.
3334 if (c == NUL)
3335 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337
3338 // Update w_cline_height and w_cline_folded if the cursor line was
3339 // updated (saves a call to plines() later).
3340 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3341 {
3342 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344#ifdef FEAT_FOLDING
3345 curwin->w_cline_folded = FALSE;
3346#endif
3347 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3348 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 break;
3350 }
3351
3352 // Show "extends" character from 'listchars' if beyond the line end and
3353 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003354 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003355 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 && wp->w_p_list
3357 && !wp->w_p_wrap
3358#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003359 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360#endif
3361 && (
3362#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003367 || lcs_eol_one > 0
3368 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003371 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003372 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 mb_c = c;
3374 if (enc_utf8 && utf_char2len(c) > 1)
3375 {
3376 mb_utf8 = TRUE;
3377 u8cc[0] = 0;
3378 c = 0xc0;
3379 }
3380 else
3381 mb_utf8 = FALSE;
3382 }
3383
3384#ifdef FEAT_SYN_HL
3385 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 if (wlv.draw_color_col)
3387 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388
3389 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3390 // highlight the cursor position itself.
3391 // Also highlight the 'colorcolumn' if it is different than
3392 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003393 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3394 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003396 if (((wlv.draw_state == WL_LINE
3397 || wlv.draw_state == WL_BRI
3398 || wlv.draw_state == WL_SBR)
3399 && !lnum_in_visual_area
3400 && search_attr == 0
3401 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003402# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003403 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003404# endif
3405 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 {
3407 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3408 && lnum != wp->w_cursor.lnum)
3409 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 vcol_save_attr = wlv.char_attr;
3411 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3412 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 vcol_save_attr = wlv.char_attr;
3417 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 }
3419 }
3420#endif
3421
3422 // Store character to be displayed.
3423 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003425 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 {
3427 // Store the character.
3428#if defined(FEAT_RIGHTLEFT)
3429 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3430 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003431 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 --wlv.off;
3433 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 }
3435#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003436 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 if (enc_dbcs == DBCS_JPNU)
3438 {
3439 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 ScreenLines[wlv.off] = 0x8e;
3441 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 }
3443 else if (enc_utf8)
3444 {
3445 if (mb_utf8)
3446 {
3447 int i;
3448
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003449 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 for (i = 0; i < Screen_mco; ++i)
3453 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 if (u8cc[i] == 0)
3456 break;
3457 }
3458 }
3459 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
3462 if (multi_attr)
3463 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 multi_attr = 0;
3466 }
3467 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003468 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003471
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3473 {
3474 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 ++wlv.off;
3476 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 if (enc_utf8)
3478 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 else
3481 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003485 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486#endif
3487 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003488 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003489 // When "wlv.tocol" is halfway a character, set it to the end
3490 // of the character, otherwise highlighting won't stop.
3491 if (wlv.tocol == wlv.vcol)
3492 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003493
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003495
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496#ifdef FEAT_RIGHTLEFT
3497 if (wp->w_p_rl)
3498 {
3499 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 --wlv.off;
3501 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 }
3503#endif
3504 }
3505#ifdef FEAT_RIGHTLEFT
3506 if (wp->w_p_rl)
3507 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 --wlv.off;
3509 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 }
3511 else
3512#endif
3513 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 ++wlv.off;
3515 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 }
3517 }
3518#ifdef FEAT_CONCEAL
3519 else if (wp->w_p_cole > 0 && is_concealing)
3520 {
3521 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003522 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003523 if (wlv.n_extra > 0)
3524 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 if (wp->w_p_wrap)
3526 {
3527 // Special voodoo required if 'wrap' is on.
3528 //
3529 // Advance the column indicator to force the line
3530 // drawing to wrap early. This will make the line
3531 // take up the same screen space when parts are concealed,
3532 // so that cursor line computations aren't messed up.
3533 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 // trailing junk to be written out of the screen line
3536 // we are building, 'boguscols' keeps track of the number
3537 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003540 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541# ifdef FEAT_RIGHTLEFT
3542 if (wp->w_p_rl)
3543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003544 wlv.col -= wlv.n_extra;
3545 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547 else
3548# endif
3549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003550 wlv.col += wlv.n_extra;
3551 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 n_attr = 0;
3555 }
3556
3557
3558 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3559 {
3560 // Need to fill two screen columns.
3561# ifdef FEAT_RIGHTLEFT
3562 if (wp->w_p_rl)
3563 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 --wlv.boguscols;
3565 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 }
3567 else
3568# endif
3569 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ++wlv.boguscols;
3571 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573 }
3574
3575# ifdef FEAT_RIGHTLEFT
3576 if (wp->w_p_rl)
3577 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 --wlv.boguscols;
3579 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 }
3581 else
3582# endif
3583 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 ++wlv.boguscols;
3585 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 }
3587 }
3588 else
3589 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003590 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 wlv.vcol += wlv.n_extra;
3593 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 n_attr = 0;
3595 }
3596 }
3597
3598 }
3599#endif // FEAT_CONCEAL
3600 else
3601 --n_skip;
3602
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 // Only advance the "wlv.vcol" when after the 'number' or
3604 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003605 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003607 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608#endif
3609 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611
3612#ifdef FEAT_SYN_HL
3613 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003614 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615#endif
3616
3617 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003618 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3619 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620
3621 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003622 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003623 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003624 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003625 if (n_attr_skip > 0)
3626 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627
3628 // At end of screen line and there is more to come: Display the line
3629 // so far. If there is no more to display it is caught above.
3630 if ((
3631#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003635 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003636 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003638 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003640#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003641 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003642#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003643 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 && wlv.p_extra != at_end_str)
3645 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3646 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 )
3648 {
3649#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 screen_line(wp, wlv.screen_row, wp->w_wincol,
3651 wlv.col - wlv.boguscols,
3652 wp->w_width, wlv.screen_line_flags);
3653 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3656 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ++wlv.row;
3659 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660
3661 // When not wrapping and finished diff lines, or when displayed
3662 // '$' and highlighting until last column, break here.
3663 if ((!wp->w_p_wrap
3664#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003665 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003666#endif
3667#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003668 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669#endif
3670 ) || lcs_eol_one == -1)
3671 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003672#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003673 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003674 {
3675 // do not output more of the line, only the "below" prop
3676 ptr += STRLEN(ptr);
3677# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003678 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003679# endif
3680 }
3681#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682
3683 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003684 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003686 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687#endif
3688 )
3689 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003690 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3691 draw_vsep_win(wp, wlv.row);
3692 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693 }
3694
3695 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 break;
3700 }
3701
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003704 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003706#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003707 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003708#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 && wp->w_width == Columns)
3710 {
3711 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713
3714 // Special trick to make copy/paste of wrapped lines work with
3715 // xterm/screen: write an extra character beyond the end of
3716 // the line. This will work with all terminal types
3717 // (regardless of the xn,am settings).
3718 // Only do this on a fast tty.
3719 // Only do this if the cursor is on the current line
3720 // (something has been written in it).
3721 // Don't do this for the GUI.
3722 // Don't do this for double-width characters.
3723 // Don't do this for a window not at the right screen border.
3724 if (p_tf
3725#ifdef FEAT_GUI
3726 && !gui.in_use
3727#endif
3728 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003729 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3730 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 || (*mb_off2cells)(
3733 LineOffset[wlv.screen_row - 1]
3734 + (int)Columns - 2,
3735 LineOffset[wlv.screen_row]
3736 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 {
3738 // First make sure we are at the end of the screen line,
3739 // then output the same character again to let the
3740 // terminal know about the wrap. If the terminal doesn't
3741 // auto-wrap, we overwrite the character.
3742 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 screen_char(LineOffset[wlv.screen_row - 1]
3744 + (unsigned)Columns - 1,
3745 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746
3747 // When there is a multi-byte character, just output a
3748 // space to keep it simple.
3749 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 out_char(' ');
3752 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 + (Columns - 1)]);
3755 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 screen_start(); // don't know where cursor is now
3758 }
3759 }
3760
Bram Moolenaar1306b362022-08-06 15:59:06 +01003761 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762
Bram Moolenaareed9d462021-02-15 20:38:25 +01003763 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003764#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003765 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003767 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003769 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003770 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771#endif
3772#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003773 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 // When the filler lines are actually below the last line of the
3775 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003776 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 break;
3778#endif
3779 }
3780
3781 } // for every character in the line
3782
3783#ifdef FEAT_SPELL
3784 // After an empty line check first word for capital.
3785 if (*skipwhite(line) == NUL)
3786 {
3787 capcol_lnum = lnum + 1;
3788 cap_col = 0;
3789 }
3790#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003791#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 vim_free(text_props);
3793 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003794 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795#endif
3796
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003797 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799}