blob: 5413347b770c23baeda40a67d7e39524004e4fd6 [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 Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
159#ifdef FEAT_CMDWIN
160# define WL_CMDLINE (WL_START + 1) // cmdline window column
161#else
162# define WL_CMDLINE WL_START
163#endif
164#ifdef FEAT_FOLDING
165# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
166#else
167# define WL_FOLD WL_CMDLINE
168#endif
169#ifdef FEAT_SIGNS
170# define WL_SIGN (WL_FOLD + 1) // column for signs
171#else
172# define WL_SIGN WL_FOLD // column for signs
173#endif
174#define WL_NR (WL_SIGN + 1) // line number
175#ifdef FEAT_LINEBREAK
176# define WL_BRI (WL_NR + 1) // 'breakindent'
177#else
178# define WL_BRI WL_NR
179#endif
180#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
181# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
182#else
183# define WL_SBR WL_BRI
184#endif
185#define WL_LINE (WL_SBR + 1) // text in the line
186
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100187#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200188/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189 * Return TRUE if CursorLineSign highlight is to be used.
190 */
191 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100192use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193{
194 return wp->w_p_cul
195 && lnum == wp->w_cursor.lnum
196 && (wp->w_p_culopt_flags & CULOPT_NBR);
197}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100198#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200
201#ifdef FEAT_FOLDING
202/*
203 * Setup for drawing the 'foldcolumn', if there is one.
204 */
205 static void
206handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
207{
208 int fdc = compute_foldcolumn(wp, 0);
209
210 if (fdc <= 0)
211 return;
212
213 // Allocate a buffer, "wlv->extra[]" may already be in use.
214 vim_free(wlv->p_extra_free);
215 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
216 if (wlv->p_extra_free != NULL)
217 {
218 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
219 wp, FALSE, wlv->lnum);
220 wlv->p_extra_free[wlv->n_extra] = NUL;
221 wlv->p_extra = wlv->p_extra_free;
222 wlv->c_extra = NUL;
223 wlv->c_final = NUL;
224 if (use_cursor_line_highlight(wp, wlv->lnum))
225 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
226 else
227 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
228 }
229}
230#endif
231
232#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000233/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100234 * Get information needed to display the sign in line "wlv->lnum" in window
235 * "wp".
236 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200237 * Otherwise the sign is going to be displayed in the sign column.
238 */
239 static void
240get_sign_display_info(
241 int nrcol,
242 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100243 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200244{
245 int text_sign;
246# ifdef FEAT_SIGN_ICONS
247 int icon_sign;
248# endif
249
250 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100251 wlv->c_extra = ' ';
252 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200253 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100254 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200255 else
256 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100257 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100258 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000259 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100260 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100261 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200262 }
263
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267#endif
268 )
269 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100270 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (gui.in_use && icon_sign != 0)
274 {
275 // Use the image in this position.
276 if (nrcol)
277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 sprintf((char *)wlv->extra, "%-*c ",
280 number_width(wp), SIGN_BYTE);
281 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100282 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 }
284 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100285 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100287 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
288 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 {
290 if (nrcol)
291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100293 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100295 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->c_final = NUL;
303 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 }
305 else
306# endif
307 if (text_sign != 0)
308 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100309 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100310 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 {
312 if (nrcol)
313 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100314 int width = number_width(wp) - 2;
315 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316
317 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100318 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100319 vim_snprintf((char *)wlv->extra + n,
320 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100321 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 wlv->c_extra = NUL;
324 wlv->c_final = NUL;
325 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200326 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100328 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 && wlv->sattr.sat_culhl > 0)
330 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000331 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200333 }
334 }
335}
336#endif
337
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338/*
339 * Display the absolute or relative line number. After the first row fill with
340 * blanks when the 'n' flag isn't in 'cpo'.
341 */
342 static void
343handle_lnum_col(
344 win_T *wp,
345 winlinevars_T *wlv,
346 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100347 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100348{
349 if ((wp->w_p_nu || wp->w_p_rnu)
350 && (wlv->row == wlv->startrow + wlv->filler_lines
351 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
352 {
353#ifdef FEAT_SIGNS
354 // If 'signcolumn' is set to 'number' and a sign is present
355 // in 'lnum', then display the sign instead of the line
356 // number.
357 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
358 get_sign_display_info(TRUE, wp, wlv);
359 else
360#endif
361 {
362 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100363 // When there are text properties above the line put the line number
364 // below them.
365 if (wlv->row == wlv->startrow + wlv->filler_lines
366#ifdef FEAT_PROP_POPUP
367 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100369 )
370 {
371 long num;
372 char *fmt = "%*ld ";
373
374 if (wp->w_p_nu && !wp->w_p_rnu)
375 // 'number' + 'norelativenumber'
376 num = (long)wlv->lnum;
377 else
378 {
379 // 'relativenumber', don't use negative numbers
380 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
381 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
382 {
383 // 'number' + 'relativenumber'
384 num = wlv->lnum;
385 fmt = "%-*ld ";
386 }
387 }
388
389 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
390 if (wp->w_skipcol > 0)
391 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
392 ++wlv->p_extra)
393 *wlv->p_extra = '-';
394#ifdef FEAT_RIGHTLEFT
395 if (wp->w_p_rl) // reverse line numbers
396 {
397 char_u *p1, *p2;
398 int t;
399
400 // like rl_mirror(), but keep the space at the end
401 p2 = skipwhite(wlv->extra);
402 p2 = skiptowhite(p2) - 1;
403 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
404 {
405 t = *p1;
406 *p1 = *p2;
407 *p2 = t;
408 }
409 }
410#endif
411 wlv->p_extra = wlv->extra;
412 wlv->c_extra = NUL;
413 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100414 }
415 else
416 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100417 wlv->c_extra = ' ';
418 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100419 }
420 wlv->n_extra = number_width(wp) + 1;
421 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
422#ifdef FEAT_SYN_HL
423 // When 'cursorline' is set highlight the line number of
424 // the current line differently.
425 // When 'cursorlineopt' does not have "line" only
426 // highlight the line number itself.
427 // TODO: Can we use CursorLine instead of CursorLineNr
428 // when CursorLineNr isn't set?
429 if (wp->w_p_cul
430 && wlv->lnum == wp->w_cursor.lnum
431 && (wp->w_p_culopt_flags & CULOPT_NBR)
432 && (wlv->row == wlv->startrow + wlv->filler_lines
433 || (wlv->row > wlv->startrow + wlv->filler_lines
434 && (wp->w_p_culopt_flags & CULOPT_LINE))))
435 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
436#endif
437 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
438 && HL_ATTR(HLF_LNA) != 0)
439 // Use LineNrAbove
440 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
441 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNB) != 0)
443 // Use LineNrBelow
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
445 }
446#ifdef FEAT_SIGNS
447 if (num_attr)
448 wlv->char_attr = num_attr;
449#endif
450 }
451}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100452
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100453#ifdef FEAT_LINEBREAK
454 static void
455handle_breakindent(win_T *wp, winlinevars_T *wlv)
456{
457 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
458 && *get_showbreak_value(wp) != NUL)
459 // draw indent after showbreak value
460 wlv->draw_state = WL_BRI;
461 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
462 // After the showbreak, draw the breakindent
463 wlv->draw_state = WL_BRI - 1;
464
465 // draw 'breakindent': indent wrapped text accordingly
466 if (wlv->draw_state == WL_BRI - 1)
467 {
468 wlv->draw_state = WL_BRI;
469 // if wlv->need_showbreak is set, breakindent also applies
470 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
471# ifdef FEAT_DIFF
472 && wlv->filler_lines == 0
473# endif
474# ifdef FEAT_PROP_POPUP
475 && !wlv->dont_use_showbreak
476# endif
477 )
478 {
479 wlv->char_attr = 0;
480# ifdef FEAT_DIFF
481 if (wlv->diff_hlf != (hlf_T)0)
482 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
483# endif
484 wlv->p_extra = NULL;
485 wlv->c_extra = ' ';
486 wlv->c_final = NUL;
487 wlv->n_extra = get_breakindent_win(wp,
488 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
489 if (wlv->row == wlv->startrow)
490 {
491 wlv->n_extra -= win_col_off2(wp);
492 if (wlv->n_extra < 0)
493 wlv->n_extra = 0;
494 }
495 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
496 wlv->need_showbreak = FALSE;
497 // Correct end of highlighted area for 'breakindent',
498 // required when 'linebreak' is also set.
499 if (wlv->tocol == wlv->vcol)
500 wlv->tocol += wlv->n_extra;
501 }
502 }
503}
504#endif
505
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100506#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
507 static void
508handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
509{
510# ifdef FEAT_DIFF
511 if (wlv->filler_todo > 0)
512 {
513 // Draw "deleted" diff line(s).
514 if (char2cells(wp->w_fill_chars.diff) > 1)
515 {
516 wlv->c_extra = '-';
517 wlv->c_final = NUL;
518 }
519 else
520 {
521 wlv->c_extra = wp->w_fill_chars.diff;
522 wlv->c_final = NUL;
523 }
524# ifdef FEAT_RIGHTLEFT
525 if (wp->w_p_rl)
526 wlv->n_extra = wlv->col + 1;
527 else
528# endif
529 wlv->n_extra = wp->w_width - wlv->col;
530 wlv->char_attr = HL_ATTR(HLF_DED);
531 }
532# endif
533
534# ifdef FEAT_LINEBREAK
535 char_u *sbr = get_showbreak_value(wp);
536 if (*sbr != NUL && wlv->need_showbreak)
537 {
538 // Draw 'showbreak' at the start of each broken line.
539 wlv->p_extra = sbr;
540 wlv->c_extra = NUL;
541 wlv->c_final = NUL;
542 wlv->n_extra = (int)STRLEN(sbr);
543 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
544 wlv->need_showbreak = FALSE;
545 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
546 // Correct end of highlighted area for 'showbreak',
547 // required when 'linebreak' is also set.
548 if (wlv->tocol == wlv->vcol)
549 wlv->tocol += wlv->n_extra;
550 // combine 'showbreak' with 'wincolor'
551 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
552# ifdef FEAT_SYN_HL
553 // combine 'showbreak' with 'cursorline'
554 if (wlv->cul_attr != 0)
555 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
556# endif
557 }
558# endif
559}
560#endif
561
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100562#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100563/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100564 * Return the cell size of virtual text after truncation.
565 */
566 static int
567textprop_size_after_trunc(
568 win_T *wp,
569 int flags, // TP_FLAG_ALIGN_*
570 int added,
571 char_u *text,
572 int *n_used_ptr)
573{
574 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
575 ? wp->w_width : added;
576 int len = (int)STRLEN(text);
577 int strsize = 0;
578 int n_used;
579
580 // if the remaining size is to small wrap anyway and use the next line
581 if (space < PROP_TEXT_MIN_CELLS)
582 space += wp->w_width;
583 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
584 {
585 int clen = ptr2cells(text + n_used);
586
587 if (strsize + clen > space)
588 break;
589 strsize += clen;
590 }
591 *n_used_ptr = n_used;
592 return strsize;
593}
594
595/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100596 * Take care of padding, right-align and truncation of virtual text after a
597 * line.
598 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
599 * padding, right-align and truncation. Otherwise only the size is computed.
600 * When "n_attr" is NULL returns the number of screen cells used.
601 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100602 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100603 int
604text_prop_position(
605 win_T *wp,
606 textprop_T *tp,
607 int vcol, // current screen column
608 int *n_extra, // nr of bytes for virtual text
609 char_u **p_extra, // virtual text
610 int *n_attr, // attribute cells, NULL if not used
611 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200612{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100614 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100615 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
616 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
617 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
618 ? tp->tp_len - 1 : 0;
619 int col_with_padding = vcol + (below ? 0 : padding);
620 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100621 int before = room; // spaces before the text
622 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100623 int n_used = *n_extra;
624 char_u *l = NULL;
625 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100626 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
627 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200628
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100629 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100630 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100631 int col_off = win_col_off(wp) + win_col_off2(wp);
632 int skip_add = 0;
633
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100635 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100637 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638 }
639 else
640 {
641 // Right-align: fill with before
642 if (right)
643 before -= cells;
644 if (before < 0
645 || !(right || below)
646 || (below
647 ? (col_with_padding == 0 || !wp->w_p_wrap)
648 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100649 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
651 {
652 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100653 before = wp->w_width - col_off - strsize + room;
654 if (before < 0)
655 before = 0;
656 else
657 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100658 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100663 else if (below && before > 0)
664 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100665 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100667
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 // With 'nowrap' add one to show the "extends" character if needed (it
669 // doesn't show if the text just fits).
670 if (!wp->w_p_wrap
671 && n_used < *n_extra
672 && wp->w_lcs_chars.ext != NUL
673 && wp->w_p_list)
674 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100675 if (!wp->w_p_wrap && below && padding > 0)
676 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677
678 // add 1 for NUL, 2 for when '…' is used
679 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 if (n_attr == NULL || l != NULL)
682 {
683 int off = 0;
684
685 if (n_attr != NULL)
686 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 vim_memset(l, ' ', before);
688 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 if (padding > 0)
690 {
691 vim_memset(l + off, ' ', padding);
692 off += padding;
693 }
694 vim_strncpy(l + off, *p_extra, n_used);
695 off += n_used;
696 }
697 else
698 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100699 off = before + after + padding + n_used;
700 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100701 }
702 if (n_attr != NULL)
703 {
704 if (n_used < *n_extra && wp->w_p_wrap)
705 {
706 char_u *lp = l + off - 1;
707
708 if (has_mbyte)
709 {
710 // change last character to '…'
711 lp -= (*mb_head_off)(l, lp);
712 STRCPY(lp, "…");
713 n_used = lp - l + 3 - padding;
714 }
715 else
716 // change last character to '>'
717 *lp = '>';
718 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 else if (after > 0)
720 {
721 vim_memset(l + off, ' ', after);
722 l[off + after] = NUL;
723 }
724
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100728 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100729 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100730 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100731 }
732 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100733 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100734
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100735 if (n_attr == NULL)
736 return cells;
737 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200738}
739#endif
740
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100741/*
742 * Called when finished with the line: draw the screen line and handle any
743 * highlighting until the right of the window.
744 */
745 static void
746draw_screen_line(win_T *wp, winlinevars_T *wlv)
747{
748#ifdef FEAT_SYN_HL
749 long v;
750
751 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
752 if (wp->w_p_wrap)
753 v = wp->w_skipcol;
754 else
755 v = wp->w_leftcol;
756
757 // check if line ends before left margin
758 if (wlv->vcol < v + wlv->col - win_col_off(wp))
759 wlv->vcol = v + wlv->col - win_col_off(wp);
760# ifdef FEAT_CONCEAL
761 // Get rid of the boguscols now, we want to draw until the right
762 // edge for 'cursorcolumn'.
763 wlv->col -= wlv->boguscols;
764 wlv->boguscols = 0;
765# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
766# else
767# define VCOL_HLC (wlv->vcol)
768# endif
769
770 if (wlv->draw_color_col)
771 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
772
773 if (((wp->w_p_cuc
774 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
775 && (int)wp->w_virtcol <
776 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
777 && wlv->lnum != wp->w_cursor.lnum)
778 || wlv->draw_color_col
779 || wlv->win_attr != 0)
780# ifdef FEAT_RIGHTLEFT
781 && !wp->w_p_rl
782# endif
783 )
784 {
785 int rightmost_vcol = 0;
786 int i;
787
788 if (wp->w_p_cuc)
789 rightmost_vcol = wp->w_virtcol;
790 if (wlv->draw_color_col)
791 // determine rightmost colorcolumn to possibly draw
792 for (i = 0; wlv->color_cols[i] >= 0; ++i)
793 if (rightmost_vcol < wlv->color_cols[i])
794 rightmost_vcol = wlv->color_cols[i];
795
796 while (wlv->col < wp->w_width)
797 {
798 ScreenLines[wlv->off] = ' ';
799 if (enc_utf8)
800 ScreenLinesUC[wlv->off] = 0;
801 ScreenCols[wlv->off] = MAXCOL;
802 ++wlv->col;
803 if (wlv->draw_color_col)
804 wlv->draw_color_col = advance_color_col(
805 VCOL_HLC, &wlv->color_cols);
806
807 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
808 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
809 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
810 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
811 else
812 ScreenAttrs[wlv->off++] = wlv->win_attr;
813
814 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
815 break;
816
817 ++wlv->vcol;
818 }
819 }
820#endif
821
822 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
823 wp->w_width, wlv->screen_line_flags);
824 ++wlv->row;
825 ++wlv->screen_row;
826}
827#undef VCOL_HLC
828
829/*
830 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100831 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100832 */
833 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100834win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100835{
836 wlv->col = 0;
837 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
838
839#ifdef FEAT_RIGHTLEFT
840 if (wp->w_p_rl)
841 {
842 // Rightleft window: process the text in the normal direction, but put
843 // it in current_ScreenLine[] from right to left. Start at the
844 // rightmost column of the window.
845 wlv->col = wp->w_width - 1;
846 wlv->off += wlv->col;
847 wlv->screen_line_flags |= SLF_RIGHTLEFT;
848 }
849#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100850 if (save_extra)
851 {
852 // reset the drawing state for the start of a wrapped line
853 wlv->draw_state = WL_START;
854 wlv->saved_n_extra = wlv->n_extra;
855 wlv->saved_p_extra = wlv->p_extra;
856 wlv->saved_c_extra = wlv->c_extra;
857 wlv->saved_c_final = wlv->c_final;
858#ifdef FEAT_SYN_HL
859 if (!(wlv->cul_screenline
860# ifdef FEAT_DIFF
861 && wlv->diff_hlf == (hlf_T)0
862# endif
863 ))
864 wlv->saved_char_attr = wlv->char_attr;
865 else
866#endif
867 wlv->saved_char_attr = 0;
868 wlv->n_extra = 0;
869 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870}
871
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200872/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100873 * Called when wlv->draw_state is set to WL_LINE.
874 */
875 static void
876win_line_continue(winlinevars_T *wlv)
877{
878 if (wlv->saved_n_extra > 0)
879 {
880 // Continue item from end of wrapped line.
881 wlv->n_extra = wlv->saved_n_extra;
882 wlv->c_extra = wlv->saved_c_extra;
883 wlv->c_final = wlv->saved_c_final;
884 wlv->p_extra = wlv->saved_p_extra;
885 wlv->char_attr = wlv->saved_char_attr;
886 }
887 else
888 wlv->char_attr = wlv->win_attr;
889}
890
891/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200892 * Display line "lnum" of window 'wp' on the screen.
893 * Start at row "startrow", stop when "endrow" is reached.
894 * wp->w_virtcol needs to be valid.
895 *
896 * Return the number of last row the line occupies.
897 */
898 int
899win_line(
900 win_T *wp,
901 linenr_T lnum,
902 int startrow,
903 int endrow,
904 int nochange UNUSED, // not updating for changed text
905 int number_only) // only update the number column
906{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100907 winlinevars_T wlv; // variables passed between functions
908
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200909 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100910 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200911 char_u *line; // current line
912 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200913
Bram Moolenaar1306b362022-08-06 15:59:06 +0100914#ifdef FEAT_PROP_POPUP
915 char_u *p_extra_free2 = NULL; // another p_extra to be freed
916#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200917 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000918#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000919 int in_linebreak = FALSE; // n_extra set for showing linebreak
920#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200921 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100922 // displaying eol at end-of-line
923 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000924 int lcs_prec_todo = wp->w_lcs_chars.prec;
925 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200926
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100927 int n_attr = 0; // chars with special attr
928 int n_attr_skip = 0; // chars to skip before using extra_attr
929 int saved_attr2 = 0; // char_attr saved for n_attr
930 int n_attr3 = 0; // chars with overruling special attr
931 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200932
933 int n_skip = 0; // nr of chars to skip for 'nowrap'
934
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200935 int fromcol_prev = -2; // start of inverting after cursor
936 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200937 int lnum_in_visual_area = FALSE;
938 pos_T pos;
939 long v;
940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941 int attr_pri = FALSE; // char_attr has priority
942 int area_highlighting = FALSE; // Visual or incsearch highlighting
943 // in this line
944 int vi_attr = 0; // attributes for Visual and incsearch
945 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200946 int area_attr = 0; // attributes desired by highlighting
947 int search_attr = 0; // attributes desired by 'hlsearch'
948#ifdef FEAT_SYN_HL
949 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
950 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200951 int prev_syntax_col = -1; // column of prev_syntax_attr
952 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200953 int has_syntax = FALSE; // this buffer has syntax highl.
954 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100956#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 int text_prop_count;
958 int text_prop_next = 0; // next text property to use
959 textprop_T *text_props = NULL;
960 int *text_prop_idxs = NULL;
961 int text_props_active = 0;
962 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100963 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100965 int text_prop_attr_comb = 0; // text_prop_attr combined with
966 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100967 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100968 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100969 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100970 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100971 int saved_search_attr = 0; // search_attr to be used when n_extra
972 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100973 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974#endif
975#ifdef FEAT_SPELL
976 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000977 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978# define SPWORDLEN 150
979 char_u nextline[SPWORDLEN * 2];// text with start of the next line
980 int nextlinecol = 0; // column where nextline[] starts
981 int nextline_idx = 0; // index in nextline[] where next line
982 // starts
983 int spell_attr = 0; // attributes desired by spelling
984 int word_end = 0; // last byte with same spell_attr
985 static linenr_T checked_lnum = 0; // line number for "checked_col"
986 static int checked_col = 0; // column in "checked_lnum" up to which
987 // there are no spell errors
988 static int cap_col = -1; // column to check for Cap word
989 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
990 int cur_checked_col = 0; // checked column for current line
991#endif
992 int extra_check = 0; // has extra highlighting
993 int multi_attr = 0; // attributes desired by multibyte
994 int mb_l = 1; // multi-byte byte length
995 int mb_c = 0; // decoded multi-byte character
996 int mb_utf8 = FALSE; // screen char is UTF-8 char
997 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 int change_start = MAXCOL; // first col of changed area
1000 int change_end = -1; // last col of changed area
1001#endif
1002 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001003 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001004 int in_multispace = FALSE; // in multiple consecutive spaces
1005 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1007 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1008# define LINE_ATTR
1009 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001010 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001013 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014#ifdef FEAT_ARABIC
1015 int prev_c = 0; // previous Arabic character
1016 int prev_c1 = 0; // first composing char for prev_c
1017#endif
1018#if defined(LINE_ATTR)
1019 int did_line_attr = 0;
1020#endif
1021#ifdef FEAT_TERMINAL
1022 int get_term_attr = FALSE;
1023#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001024
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001025#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001026 // margin columns for the screen line, needed for when 'cursorlineopt'
1027 // contains "screenline"
1028 int left_curline_col = 0;
1029 int right_curline_col = 0;
1030#endif
1031
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1033 int feedback_col = 0;
1034 int feedback_old_attr = -1;
1035#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036
1037#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1038 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001039 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040#endif
1041#ifdef FEAT_CONCEAL
1042 int syntax_flags = 0;
1043 int syntax_seqnr = 0;
1044 int prev_syntax_id = 0;
1045 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1046 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047 int did_wcol = FALSE;
1048 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001049# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050# define FIX_FOR_BOGUSCOLS \
1051 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001052 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001053 wlv.vcol -= wlv.vcol_off; \
1054 wlv.vcol_off = 0; \
1055 wlv.col -= wlv.boguscols; \
1056 old_boguscols = wlv.boguscols; \
1057 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 }
1059#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001060# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001061#endif
1062
1063 if (startrow > endrow) // past the end already!
1064 return startrow;
1065
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001066 CLEAR_FIELD(wlv);
1067
1068 wlv.lnum = lnum;
1069 wlv.startrow = startrow;
1070 wlv.row = startrow;
1071 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001072 wlv.fromcol = -10;
1073 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001074#ifdef FEAT_LINEBREAK
1075 wlv.vcol_sbr = -1;
1076#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077
1078 if (!number_only)
1079 {
1080 // To speed up the loop below, set extra_check when there is linebreak,
1081 // trailing white space and/or syntax processing to be done.
1082#ifdef FEAT_LINEBREAK
1083 extra_check = wp->w_p_lbr;
1084#endif
1085#ifdef FEAT_SYN_HL
1086 if (syntax_present(wp) && !wp->w_s->b_syn_error
1087# ifdef SYN_TIME_LIMIT
1088 && !wp->w_s->b_syn_slow
1089# endif
1090 )
1091 {
1092 // Prepare for syntax highlighting in this line. When there is an
1093 // error, stop syntax highlighting.
1094 save_did_emsg = did_emsg;
1095 did_emsg = FALSE;
1096 syntax_start(wp, lnum);
1097 if (did_emsg)
1098 wp->w_s->b_syn_error = TRUE;
1099 else
1100 {
1101 did_emsg = save_did_emsg;
1102#ifdef SYN_TIME_LIMIT
1103 if (!wp->w_s->b_syn_slow)
1104#endif
1105 {
1106 has_syntax = TRUE;
1107 extra_check = TRUE;
1108 }
1109 }
1110 }
1111
1112 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001113 wlv.color_cols = wp->w_p_cc_cols;
1114 if (wlv.color_cols != NULL)
1115 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116#endif
1117
1118#ifdef FEAT_TERMINAL
1119 if (term_show_buffer(wp->w_buffer))
1120 {
1121 extra_check = TRUE;
1122 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001123 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 }
1125#endif
1126
1127#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001128 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129 {
1130 // Prepare for spell checking.
1131 has_spell = TRUE;
1132 extra_check = TRUE;
1133
1134 // Get the start of the next line, so that words that wrap to the
1135 // next line are found too: "et<line-break>al.".
1136 // Trick: skip a few chars for C/shell/Vim comments
1137 nextline[SPWORDLEN] = NUL;
1138 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1139 {
1140 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1141 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1142 }
1143
1144 // When a word wrapped from the previous line the start of the
1145 // current line is valid.
1146 if (lnum == checked_lnum)
1147 cur_checked_col = checked_col;
1148 checked_lnum = 0;
1149
1150 // When there was a sentence end in the previous line may require a
1151 // word starting with capital in this line. In line 1 always check
1152 // the first word.
1153 if (lnum != capcol_lnum)
1154 cap_col = -1;
1155 if (lnum == 1)
1156 cap_col = 0;
1157 capcol_lnum = 0;
1158 }
1159#endif
1160
1161 // handle Visual active in this window
1162 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1163 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001164 pos_T *top, *bot;
1165
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1167 {
1168 // Visual is after curwin->w_cursor
1169 top = &curwin->w_cursor;
1170 bot = &VIsual;
1171 }
1172 else
1173 {
1174 // Visual is before curwin->w_cursor
1175 top = &VIsual;
1176 bot = &curwin->w_cursor;
1177 }
1178 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1179 if (VIsual_mode == Ctrl_V)
1180 {
1181 // block mode
1182 if (lnum_in_visual_area)
1183 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001184 wlv.fromcol = wp->w_old_cursor_fcol;
1185 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186 }
1187 }
1188 else
1189 {
1190 // non-block mode
1191 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001192 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193 else if (lnum == top->lnum)
1194 {
1195 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001196 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197 else
1198 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001199 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001201 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202 }
1203 }
1204 if (VIsual_mode != 'V' && lnum == bot->lnum)
1205 {
1206 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1207 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001208 wlv.fromcol = -10;
1209 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210 }
1211 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001212 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 else
1214 {
1215 pos = *bot;
1216 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001217 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1218 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219 else
1220 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001221 getvvcol(wp, &pos, NULL, NULL,
1222 (colnr_T *)&wlv.tocol);
1223 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 }
1225 }
1226 }
1227 }
1228
1229 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001230 if (!highlight_match && lnum == curwin->w_cursor.lnum
1231 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232#ifdef FEAT_GUI
1233 && !gui.in_use
1234#endif
1235 )
1236 noinvcur = TRUE;
1237
1238 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 {
1241 area_highlighting = TRUE;
1242 vi_attr = HL_ATTR(HLF_V);
1243#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1244 if ((clip_star.available && !clip_star.owned
1245 && clip_isautosel_star())
1246 || (clip_plus.available && !clip_plus.owned
1247 && clip_isautosel_plus()))
1248 vi_attr = HL_ATTR(HLF_VNC);
1249#endif
1250 }
1251 }
1252
1253 // handle 'incsearch' and ":s///c" highlighting
1254 else if (highlight_match
1255 && wp == curwin
1256 && lnum >= curwin->w_cursor.lnum
1257 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1258 {
1259 if (lnum == curwin->w_cursor.lnum)
1260 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001263 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1265 {
1266 pos.lnum = lnum;
1267 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001268 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 }
1270 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001271 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001273 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1274 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 area_highlighting = TRUE;
1276 vi_attr = HL_ATTR(HLF_I);
1277 }
1278 }
1279
1280#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001281 wlv.filler_lines = diff_check(wp, lnum);
1282 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001284 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 {
1286 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001287 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001289 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001291 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 }
1293 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001294 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001295 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 area_highlighting = TRUE;
1297 }
1298 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001299 wlv.filler_lines = wp->w_topfill;
1300 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301#endif
1302
1303#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001304 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001305 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001306 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307#endif
1308
1309#ifdef LINE_ATTR
1310# ifdef FEAT_SIGNS
1311 // If this line has a sign with line highlighting set line_attr.
1312 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001313 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314# endif
1315# if defined(FEAT_QUICKFIX)
1316 // Highlight the current line in the quickfix window.
1317 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1318 line_attr = HL_ATTR(HLF_QFL);
1319# endif
1320 if (line_attr != 0)
1321 area_highlighting = TRUE;
1322#endif
1323
1324 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1325 ptr = line;
1326
1327#ifdef FEAT_SPELL
1328 if (has_spell && !number_only)
1329 {
1330 // For checking first word with a capital skip white space.
1331 if (cap_col == 0)
1332 cap_col = getwhitecols(line);
1333
1334 // To be able to spell-check over line boundaries copy the end of the
1335 // current line into nextline[]. Above the start of the next line was
1336 // copied to nextline[SPWORDLEN].
1337 if (nextline[SPWORDLEN] == NUL)
1338 {
1339 // No next line or it is empty.
1340 nextlinecol = MAXCOL;
1341 nextline_idx = 0;
1342 }
1343 else
1344 {
1345 v = (long)STRLEN(line);
1346 if (v < SPWORDLEN)
1347 {
1348 // Short line, use it completely and append the start of the
1349 // next line.
1350 nextlinecol = 0;
1351 mch_memmove(nextline, line, (size_t)v);
1352 STRMOVE(nextline + v, nextline + SPWORDLEN);
1353 nextline_idx = v + 1;
1354 }
1355 else
1356 {
1357 // Long line, use only the last SPWORDLEN bytes.
1358 nextlinecol = v - SPWORDLEN;
1359 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1360 nextline_idx = SPWORDLEN + 1;
1361 }
1362 }
1363 }
1364#endif
1365
1366 if (wp->w_p_list)
1367 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001368 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001369 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001370 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001371 || wp->w_lcs_chars.trail
1372 || wp->w_lcs_chars.lead
1373 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001375
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001377 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 {
1379 trailcol = (colnr_T)STRLEN(ptr);
1380 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1381 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001382 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001384 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001385 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001386 {
1387 leadcol = 0;
1388 while (VIM_ISWHITE(ptr[leadcol]))
1389 ++leadcol;
1390 if (ptr[leadcol] == NUL)
1391 // in a line full of spaces all of them are treated as trailing
1392 leadcol = (colnr_T)0;
1393 else
1394 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001395 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001396 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 }
1398
Bram Moolenaard7657e92022-09-20 18:59:30 +01001399 wlv.wcr_attr = get_wcr_attr(wp);
1400 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001402 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 area_highlighting = TRUE;
1404 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001405
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001406#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001408 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409#endif
1410
1411 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1412 // first character to be displayed.
1413 if (wp->w_p_wrap)
1414 v = wp->w_skipcol;
1415 else
1416 v = wp->w_leftcol;
1417 if (v > 0 && !number_only)
1418 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001419 char_u *prev_ptr = ptr;
1420 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001421 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001423 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001424 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001426 charsize = win_lbr_chartabsize(&cts, NULL);
1427 cts.cts_vcol += charsize;
1428 prev_ptr = cts.cts_ptr;
1429 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001431 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001432 ptr = cts.cts_ptr;
1433 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434
1435 // When:
1436 // - 'cuc' is set, or
1437 // - 'colorcolumn' is set, or
1438 // - 'virtualedit' is set, or
1439 // - the visual mode is active,
1440 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001441 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001443 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444#endif
1445 virtual_active() ||
1446 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001447 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448
1449 // Handle a character that's not completely on the screen: Put ptr at
1450 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001451 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001453 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 ptr = prev_ptr;
1455 // If the character fits on the screen, don't need to skip it.
1456 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001457 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1458 && wlv.col == 0)
1459 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
1461
1462 // Adjust for when the inverted text is before the screen,
1463 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001464 if (wlv.tocol <= wlv.vcol)
1465 wlv.fromcol = 0;
1466 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1467 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468
1469#ifdef FEAT_LINEBREAK
1470 // When w_skipcol is non-zero, first line needs 'showbreak'
1471 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001472 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473#endif
1474#ifdef FEAT_SPELL
1475 // When spell checking a word we need to figure out the start of the
1476 // word and if it's badly spelled or not.
1477 if (has_spell)
1478 {
1479 int len;
1480 colnr_T linecol = (colnr_T)(ptr - line);
1481 hlf_T spell_hlf = HLF_COUNT;
1482
1483 pos = wp->w_cursor;
1484 wp->w_cursor.lnum = lnum;
1485 wp->w_cursor.col = linecol;
1486 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1487
1488 // spell_move_to() may call ml_get() and make "line" invalid
1489 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1490 ptr = line + linecol;
1491
1492 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1493 {
1494 // no bad word found at line start, don't check until end of a
1495 // word
1496 spell_hlf = HLF_COUNT;
1497 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1498 }
1499 else
1500 {
1501 // bad word found, use attributes until end of word
1502 word_end = wp->w_cursor.col + len + 1;
1503
1504 // Turn index into actual attributes.
1505 if (spell_hlf != HLF_COUNT)
1506 spell_attr = highlight_attr[spell_hlf];
1507 }
1508 wp->w_cursor = pos;
1509
1510# ifdef FEAT_SYN_HL
1511 // Need to restart syntax highlighting for this line.
1512 if (has_syntax)
1513 syntax_start(wp, lnum);
1514# endif
1515 }
1516#endif
1517 }
1518
1519 // Correct highlighting for cursor that can't be disabled.
1520 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001521 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 {
1523 if (noinvcur)
1524 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001525 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 {
1527 // highlighting starts at cursor, let it start just after the
1528 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001529 fromcol_prev = wlv.fromcol;
1530 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001532 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 // restart highlighting after the cursor
1534 fromcol_prev = wp->w_virtcol;
1535 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001536 if (wlv.fromcol >= wlv.tocol)
1537 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 }
1539
1540#ifdef FEAT_SEARCH_EXTRA
1541 if (!number_only)
1542 {
1543 v = (long)(ptr - line);
1544 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1545 &line, &screen_search_hl,
1546 &search_attr);
1547 ptr = line + v; // "line" may have been updated
1548 }
1549#endif
1550
1551#ifdef FEAT_SYN_HL
1552 // Cursor line highlighting for 'cursorline' in the current window.
1553 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1554 {
1555 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001556 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 if (!(wp == curwin && VIsual_active)
1558 && wp->w_p_culopt_flags != CULOPT_NBR)
1559 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001560 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1562
1563 // Only set line_attr here when "screenline" is not present in
1564 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001565 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001567 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001568# ifdef FEAT_SIGNS
1569 // Combine the 'cursorline' and sign highlighting, depending on
1570 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001571 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001572 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001573 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001574 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001575 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001576 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001577 }
1578 else
1579# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001580# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001581 // let the line attribute overrule 'cursorline', otherwise
1582 // it disappears when both have background set;
1583 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001584 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001585# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001586 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001587# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 }
1589 else
1590 {
1591 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1593 }
1594 area_highlighting = TRUE;
1595 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 }
1597#endif
1598
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001599#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 {
1601 char_u *prop_start;
1602
1603 text_prop_count = get_text_props(wp->w_buffer, lnum,
1604 &prop_start, FALSE);
1605 if (text_prop_count > 0)
1606 {
1607 // Make a copy of the properties, so that they are properly
1608 // aligned.
1609 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1610 if (text_props != NULL)
1611 mch_memmove(text_props, prop_start,
1612 text_prop_count * sizeof(textprop_T));
1613
1614 // Allocate an array for the indexes.
1615 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001616 if (text_prop_idxs == NULL)
1617 VIM_CLEAR(text_props);
1618
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001619 if (text_props != NULL)
1620 {
1621 area_highlighting = TRUE;
1622 extra_check = TRUE;
1623 for (int i = 0; i < text_prop_count; ++i)
1624 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1625 ++wlv.text_prop_above_count;
1626 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 }
1628 }
1629#endif
1630
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632
1633 // Repeat for the whole displayed line.
1634 for (;;)
1635 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001636 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001638 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639#endif
1640#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001641 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001643
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001645 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001647#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001649 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001650 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001651 line_attr = line_attr_save;
1652 }
1653#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001655 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001657 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 if (cmdwin_type != 0 && wp == curwin)
1659 {
1660 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001661 wlv.n_extra = 1;
1662 wlv.c_extra = cmdwin_type;
1663 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001664 wlv.char_attr =
1665 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 }
1667 }
1668#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001670 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001672 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001673 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 }
1675#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001677 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001679 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001680 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001682 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 }
1684#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001685 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001687 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001688 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001689 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001692 // Check if 'breakindent' applies and show it.
1693 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1694 if (wlv.n_extra == 0)
1695 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001700 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001701 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 }
1703#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001704 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001707 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 }
1709 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001710
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001712 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001713 && wlv.vcol >= left_curline_col
1714 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001716 wlv.cul_attr = HL_ATTR(HLF_CUL);
1717 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 }
1719#endif
1720
1721 // When still displaying '$' of change command, stop at cursor.
1722 // When only displaying the (relative) line number and that's done,
1723 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001724 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001725 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001728 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729#endif
1730 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001732 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1733 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 // Pretend we have finished updating the window. Except when
1735 // 'cursorcolumn' is set.
1736#ifdef FEAT_SYN_HL
1737 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001738 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 else
1740#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 break;
1743 }
1744
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 {
1747 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001748 if (wlv.vcol == wlv.fromcol
1749 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1750 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 && (*mb_ptr2cells)(ptr) > 1)
1752 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001753 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001754 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 area_attr = vi_attr; // start highlighting
1756 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001758 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 area_attr = 0; // stop highlighting
1760
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001761#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 if (text_props != NULL)
1763 {
1764 int pi;
1765 int bcol = (int)(ptr - line);
1766
Bram Moolenaar1306b362022-08-06 15:59:06 +01001767 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001768# ifdef FEAT_LINEBREAK
1769 && !in_linebreak
1770# endif
1771 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 --bcol; // still working on the previous char, e.g. Tab
1773
1774 // Check if any active property ends.
1775 for (pi = 0; pi < text_props_active; ++pi)
1776 {
1777 int tpi = text_prop_idxs[pi];
1778
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001779 if (text_props[tpi].tp_col != MAXCOL
1780 && bcol >= text_props[tpi].tp_col - 1
1781 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
1783 if (pi + 1 < text_props_active)
1784 mch_memmove(text_prop_idxs + pi,
1785 text_prop_idxs + pi + 1,
1786 sizeof(int)
1787 * (text_props_active - (pi + 1)));
1788 --text_props_active;
1789 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001790# ifdef FEAT_LINEBREAK
1791 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001792 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001793 syntax_attr = 0;
1794# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795 }
1796 }
1797
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001798# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001800 // not on the next char yet, don't start another prop
1801 --bcol;
1802# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001804 // With 'nowrap' and not in the first screen line only "below"
1805 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001807 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001808 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001809 && (wp->w_p_wrap
1810 || wlv.row == startrow
1811 || (text_props[text_prop_next].tp_flags
1812 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001813 || (bcol == 0 &&
1814 (text_props[text_prop_next].tp_flags
1815 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001816 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001817 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001818 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001819 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1820 {
1821 // first display the '$' after the line
1822 text_prop_follows = TRUE;
1823 break;
1824 }
1825 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001826 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001827 + text_props[text_prop_next].tp_len)
1828 text_prop_idxs[text_props_active++] = text_prop_next;
1829 ++text_prop_next;
1830 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001832 if (wlv.n_extra == 0 || !extra_for_textprop)
1833 {
1834 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001835 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001836 text_prop_flags = 0;
1837 text_prop_type = NULL;
1838 text_prop_id = 0;
1839 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001840 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001842 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001843 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001844 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001845
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001846 // Sort the properties on priority and/or starting last.
1847 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001848 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001849 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001850 sort_text_props(wp->w_buffer, text_props,
1851 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852
1853 for (pi = 0; pi < text_props_active; ++pi)
1854 {
1855 int tpi = text_prop_idxs[pi];
1856 proptype_T *pt = text_prop_type_by_id(
1857 wp->w_buffer, text_props[tpi].tp_type);
1858
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001859 if (pt != NULL && (pt->pt_hl_id > 0
1860 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001861 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001863 if (pt->pt_hl_id > 0)
1864 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 text_prop_type = pt;
1866 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001867 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001868 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001869 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001870 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001871 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 }
1873 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001874 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001875 && -text_prop_id
1876 <= wp->w_buffer->b_textprop_text.ga_len)
1877 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001878 textprop_T *tp = &text_props[used_tpi];
1879 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001880 ->b_textprop_text.ga_data)[
1881 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001882 int above = (tp->tp_flags
1883 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884
1885 // reset the ID in the copy to avoid it being used
1886 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001887 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001888
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001889 if (p != NULL)
1890 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001891 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001892 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001893 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001894 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001895 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1896 int padding = tp->tp_col == MAXCOL
1897 && tp->tp_len > 1
1898 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001899
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001900 // Insert virtual text before the current
1901 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001902 wlv.p_extra = p;
1903 wlv.c_extra = NUL;
1904 wlv.c_final = NUL;
1905 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001906 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001907 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001908 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001909 // restore search_attr and area_attr when n_extra
1910 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001911 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001912 saved_area_attr = area_attr;
1913 search_attr = 0;
1914 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001915 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001916 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001917 if (*ptr == NUL)
1918 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001919 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001920#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001921 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001922 {
1923 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001924 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001925 wlv.need_showbreak = FALSE;
1926 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001927 }
1928#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001929 if ((right || above || below || !wrap
1930 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001931 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001932 char_u *prev_p_extra = wlv.p_extra;
1933 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001934
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001935 // Take care of padding, right-align and
1936 // truncation.
1937 // Shared with win_lbr_chartabsize(), must do
1938 // exactly the same.
1939 start_line = text_prop_position(wp, tp,
1940 wlv.col,
1941 &wlv.n_extra, &wlv.p_extra,
1942 &n_attr, &n_attr_skip);
1943 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001944 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001945 // wlv.p_extra was allocated
1946 vim_free(p_extra_free2);
1947 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001948 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001949
Bram Moolenaara4abe512022-09-15 19:44:09 +01001950 if (lcs_eol_one < 0 && wlv.col
1951 + wlv.n_extra - 2 > wp->w_width)
1952 // don't bail out at end of line
1953 lcs_eol_one = 0;
1954
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001955 // When 'wrap' is off then for "below" we need
1956 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001958 {
1959 draw_screen_line(wp, &wlv);
1960
1961 // When line got too long for screen break
1962 // here.
1963 if (wlv.row == endrow)
1964 {
1965 ++wlv.row;
1966 break;
1967 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001968 win_line_start(wp, &wlv, TRUE);
1969 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001970 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001971 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001972 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001973
1974 // If another text prop follows the condition below at
1975 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001976 // If this is an "above" text prop and 'nowrap' the we
1977 // must wrap anyway.
1978 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001979 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001980 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001982 else if (text_prop_next < text_prop_count
1983 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001984 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1985 || (!wp->w_p_wrap
1986 && wlv.col == wp->w_width - 1
1987 && (text_props[text_prop_next].tp_flags
1988 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001989 // When at last-but-one character and a text property
1990 // follows after it, we may need to flush the line after
1991 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001992 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001993 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 }
1995#endif
1996
Bram Moolenaare38fc862022-08-11 17:24:50 +01001997#ifdef FEAT_SEARCH_EXTRA
1998 if (wlv.n_extra == 0)
1999 {
2000 // Check for start/end of 'hlsearch' and other matches.
2001 // After end, check for start/end of next match.
2002 // When another match, have to check for start again.
2003 v = (long)(ptr - line);
2004 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2005 &screen_search_hl, &has_match_conc,
2006 &match_conc, did_line_attr, lcs_eol_one,
2007 &on_last_col);
2008 ptr = line + v; // "line" may have been changed
2009 prev_ptr = ptr;
2010
2011 // Do not allow a conceal over EOL otherwise EOL will be missed
2012 // and bad things happen.
2013 if (*ptr == NUL)
2014 has_match_conc = 0;
2015 }
2016#endif
2017
2018#ifdef FEAT_DIFF
2019 if (wlv.diff_hlf != (hlf_T)0)
2020 {
2021 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2022 && wlv.n_extra == 0)
2023 wlv.diff_hlf = HLF_TXD; // changed text
2024 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2025 && wlv.n_extra == 0)
2026 wlv.diff_hlf = HLF_CHD; // changed line
2027 line_attr = HL_ATTR(wlv.diff_hlf);
2028 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2029 && wp->w_p_culopt_flags != CULOPT_NBR
2030 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2031 && wlv.vcol <= right_curline_col)))
2032 line_attr = hl_combine_attr(
2033 line_attr, HL_ATTR(HLF_CUL));
2034 }
2035#endif
2036
Bram Moolenaara74fda62019-10-19 17:38:03 +02002037#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002038 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002039 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002040 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002041# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002042 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002043 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002044# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002045 // Get syntax attribute.
2046 if (has_syntax)
2047 {
2048 // Get the syntax attribute for the character. If there
2049 // is an error, disable syntax highlighting.
2050 save_did_emsg = did_emsg;
2051 did_emsg = FALSE;
2052
2053 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002054 if (v == prev_syntax_col)
2055 // at same column again
2056 syntax_attr = prev_syntax_attr;
2057 else
2058 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002059# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002060 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002061# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002062 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002063# ifdef FEAT_SPELL
2064 has_spell ? &can_spell :
2065# endif
2066 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002067 prev_syntax_col = v;
2068 prev_syntax_attr = syntax_attr;
2069 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002070
Bram Moolenaar34390282019-10-16 14:38:26 +02002071 if (did_emsg)
2072 {
2073 wp->w_s->b_syn_error = TRUE;
2074 has_syntax = FALSE;
2075 syntax_attr = 0;
2076 }
2077 else
2078 did_emsg = save_did_emsg;
2079# ifdef SYN_TIME_LIMIT
2080 if (wp->w_s->b_syn_slow)
2081 has_syntax = FALSE;
2082# endif
2083
2084 // Need to get the line again, a multi-line regexp may
2085 // have made it invalid.
2086 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2087 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002088 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002089# ifdef FEAT_CONCEAL
2090 // no concealing past the end of the line, it interferes
2091 // with line highlighting
2092 if (*ptr == NUL)
2093 syntax_flags = 0;
2094 else
2095 syntax_flags = get_syntax_info(&syntax_seqnr);
2096# endif
2097 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002098 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002099# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002100 // Combine text property highlight into syntax highlight.
2101 if (text_prop_type != NULL)
2102 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002103 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002104 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2105 else
2106 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002107 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002108 }
2109# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002110#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002111
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002112 // Decide which of the highlight attributes to use.
2113 attr_pri = TRUE;
2114#ifdef LINE_ATTR
2115 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002116 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002117 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002118 if (!highlight_match)
2119 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002121# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002122 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002123# endif
2124 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002127 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002128# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002130# endif
2131 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002132 else if (line_attr != 0
2133 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2134 || wlv.vcol < wlv.fromcol
2135 || vcol_prev < fromcol_prev
2136 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 {
2138 // Use line_attr when not in the Visual or 'incsearch' area
2139 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002140# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002141 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002142# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002144# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 attr_pri = FALSE;
2146 }
2147#else
2148 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002149 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002150 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002151 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152#endif
2153 else
2154 {
2155 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002156#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002158#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002159 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002160#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002161 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002162#ifdef FEAT_PROP_POPUP
2163 // override with text property highlight when "override" is TRUE
2164 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002166#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002168
2169 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002170 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002171 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002172 if (wlv.char_attr == 0)
2173 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002174 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002176 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177
2178 // Get the next character to put on the screen.
2179
2180 // The "p_extra" points to the extra stuff that is inserted to
2181 // represent special characters (non-printable stuff) and other
2182 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2185 // "p_extra[n_extra]".
2186 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2192 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2194 if (enc_utf8 && utf_char2len(c) > 1)
2195 {
2196 mb_utf8 = TRUE;
2197 u8cc[0] = 0;
2198 c = 0xc0;
2199 }
2200 else
2201 mb_utf8 = FALSE;
2202 }
2203 else
2204 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 if (has_mbyte)
2207 {
2208 mb_c = c;
2209 if (enc_utf8)
2210 {
2211 // If the UTF-8 character is more than one byte:
2212 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002213 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002216 mb_l = 1;
2217 else if (mb_l > 1)
2218 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002219 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220 mb_utf8 = TRUE;
2221 c = 0xc0;
2222 }
2223 }
2224 else
2225 {
2226 // if this is a DBCS character, put it in "mb_c"
2227 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002228 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002229 mb_l = 1;
2230 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232 }
2233 if (mb_l == 0) // at the NUL at end-of-line
2234 mb_l = 1;
2235
2236 // If a double-width char doesn't fit display a '>' in the
2237 // last column.
2238 if ((
2239# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002240 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002242 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 && (*mb_char2cells)(mb_c) == 2)
2244 {
2245 c = '>';
2246 mb_c = c;
2247 mb_l = 1;
2248 mb_utf8 = FALSE;
2249 multi_attr = HL_ATTR(HLF_AT);
2250#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002251 if (wlv.cul_attr)
2252 multi_attr = hl_combine_attr(
2253 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002255 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002256
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257 // put the pointer back to output the double-width
2258 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 ++wlv.n_extra;
2260 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 }
2262 else
2263 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 wlv.n_extra -= mb_l - 1;
2265 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 }
2267 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002271#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002273 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002274 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002275 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002276 if (search_attr == 0)
2277 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002278 if (area_attr == 0 && *ptr != NUL)
2279 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002280 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002281#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 }
2283 else
2284 {
2285#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002286 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002288 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 // Get a character from the line itself.
2291 c = *ptr;
2292#ifdef FEAT_LINEBREAK
2293 c0 = *ptr;
2294#endif
2295 if (has_mbyte)
2296 {
2297 mb_c = c;
2298 if (enc_utf8)
2299 {
2300 // If the UTF-8 character is more than one byte: Decode it
2301 // into "mb_c".
2302 mb_l = utfc_ptr2len(ptr);
2303 mb_utf8 = FALSE;
2304 if (mb_l > 1)
2305 {
2306 mb_c = utfc_ptr2char(ptr, u8cc);
2307 // Overlong encoded ASCII or ASCII with composing char
2308 // is displayed normally, except a NUL.
2309 if (mb_c < 0x80)
2310 {
2311 c = mb_c;
2312#ifdef FEAT_LINEBREAK
2313 c0 = mb_c;
2314#endif
2315 }
2316 mb_utf8 = TRUE;
2317
2318 // At start of the line we can have a composing char.
2319 // Draw it as a space with a composing char.
2320 if (utf_iscomposing(mb_c))
2321 {
2322 int i;
2323
2324 for (i = Screen_mco - 1; i > 0; --i)
2325 u8cc[i] = u8cc[i - 1];
2326 u8cc[0] = mb_c;
2327 mb_c = ' ';
2328 }
2329 }
2330
2331 if ((mb_l == 1 && c >= 0x80)
2332 || (mb_l >= 1 && mb_c == 0)
2333 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2334 {
2335 // Illegal UTF-8 byte: display as <xx>.
2336 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002337 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002338# ifdef FEAT_RIGHTLEFT
2339 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002340 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002342 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002343 c = *wlv.p_extra;
2344 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2347 wlv.c_extra = NUL;
2348 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349 if (area_attr == 0 && search_attr == 0)
2350 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002351 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002352 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002353 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002354 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 }
2356 }
2357 else if (mb_l == 0) // at the NUL at end-of-line
2358 mb_l = 1;
2359#ifdef FEAT_ARABIC
2360 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2361 {
2362 // Do Arabic shaping.
2363 int pc, pc1, nc;
2364 int pcc[MAX_MCO];
2365
2366 // The idea of what is the previous and next
2367 // character depends on 'rightleft'.
2368 if (wp->w_p_rl)
2369 {
2370 pc = prev_c;
2371 pc1 = prev_c1;
2372 nc = utf_ptr2char(ptr + mb_l);
2373 prev_c1 = u8cc[0];
2374 }
2375 else
2376 {
2377 pc = utfc_ptr2char(ptr + mb_l, pcc);
2378 nc = prev_c;
2379 pc1 = pcc[0];
2380 }
2381 prev_c = mb_c;
2382
2383 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2384 }
2385 else
2386 prev_c = mb_c;
2387#endif
2388 }
2389 else // enc_dbcs
2390 {
2391 mb_l = MB_BYTE2LEN(c);
2392 if (mb_l == 0) // at the NUL at end-of-line
2393 mb_l = 1;
2394 else if (mb_l > 1)
2395 {
2396 // We assume a second byte below 32 is illegal.
2397 // Hopefully this is OK for all double-byte encodings!
2398 if (ptr[1] >= 32)
2399 mb_c = (c << 8) + ptr[1];
2400 else
2401 {
2402 if (ptr[1] == NUL)
2403 {
2404 // head byte at end of line
2405 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002406 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 }
2408 else
2409 {
2410 // illegal tail byte
2411 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002412 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002414 wlv.p_extra = wlv.extra;
2415 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 wlv.c_extra = NUL;
2417 wlv.c_final = NUL;
2418 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 if (area_attr == 0 && search_attr == 0)
2420 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002421 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002422 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002423 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 // save current attr
2425 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 }
2427 mb_c = c;
2428 }
2429 }
2430 }
2431 // If a double-width char doesn't fit display a '>' in the
2432 // last column; the character is displayed at the start of the
2433 // next line.
2434 if ((
2435# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002436 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002438 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 && (*mb_char2cells)(mb_c) == 2)
2440 {
2441 c = '>';
2442 mb_c = c;
2443 mb_utf8 = FALSE;
2444 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002445 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 // Put pointer back so that the character will be
2447 // displayed at the start of the next line.
2448 --ptr;
2449#ifdef FEAT_CONCEAL
2450 did_decrement_ptr = TRUE;
2451#endif
2452 }
2453 else if (*ptr != NUL)
2454 ptr += mb_l - 1;
2455
2456 // If a double-width char doesn't fit at the left side display
2457 // a '<' in the first column. Don't do this for unprintable
2458 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002459 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 wlv.n_extra = 1;
2462 wlv.c_extra = MB_FILLER_CHAR;
2463 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 c = ' ';
2465 if (area_attr == 0 && search_attr == 0)
2466 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002468 extra_attr = hl_combine_attr(
2469 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 }
2472 mb_c = c;
2473 mb_utf8 = FALSE;
2474 mb_l = 1;
2475 }
2476
2477 }
2478 ++ptr;
2479
2480 if (extra_check)
2481 {
2482#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 // Check spelling (unless at the end of the line).
2484 // Only do this when there is no syntax highlighting, the
2485 // @Spell cluster is not used or the current syntax item
2486 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002487 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 if (has_spell && v >= word_end && v > cur_checked_col)
2489 {
2490 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002491 // do not calculate cap_col at the end of the line or when
2492 // only white space is following
2493 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494# ifdef FEAT_SYN_HL
2495 !has_syntax ||
2496# endif
2497 can_spell))
2498 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002499 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500 int len;
2501 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002502
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505
2506 // Use nextline[] if possible, it has the start of the
2507 // next line concatenated.
2508 if ((prev_ptr - line) - nextlinecol >= 0)
2509 p = nextline + (prev_ptr - line) - nextlinecol;
2510 else
2511 p = prev_ptr;
2512 cap_col -= (int)(prev_ptr - line);
2513 len = spell_check(wp, p, &spell_hlf, &cap_col,
2514 nochange);
2515 word_end = v + len;
2516
2517 // In Insert mode only highlight a word that
2518 // doesn't touch the cursor.
2519 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002520 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 && wp->w_cursor.lnum == lnum
2522 && wp->w_cursor.col >=
2523 (colnr_T)(prev_ptr - line)
2524 && wp->w_cursor.col < (colnr_T)word_end)
2525 {
2526 spell_hlf = HLF_COUNT;
2527 spell_redraw_lnum = lnum;
2528 }
2529
2530 if (spell_hlf == HLF_COUNT && p != prev_ptr
2531 && (p - nextline) + len > nextline_idx)
2532 {
2533 // Remember that the good word continues at the
2534 // start of the next line.
2535 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002536 checked_col = (int)((p - nextline)
2537 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 }
2539
2540 // Turn index into actual attributes.
2541 if (spell_hlf != HLF_COUNT)
2542 spell_attr = highlight_attr[spell_hlf];
2543
2544 if (cap_col > 0)
2545 {
2546 if (p != prev_ptr
2547 && (p - nextline) + cap_col >= nextline_idx)
2548 {
2549 // Remember that the word in the next line
2550 // must start with a capital.
2551 capcol_lnum = lnum + 1;
2552 cap_col = (int)((p - nextline) + cap_col
2553 - nextline_idx);
2554 }
2555 else
2556 // Compute the actual column.
2557 cap_col += (int)(prev_ptr - line);
2558 }
2559 }
2560 }
2561 if (spell_attr != 0)
2562 {
2563 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002564 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2565 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 wlv.char_attr = hl_combine_attr(spell_attr,
2568 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 }
2570#endif
2571#ifdef FEAT_LINEBREAK
2572 // Found last space before word: check for line break.
2573 if (wp->w_p_lbr && c0 == c
2574 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2575 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002576 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2577 : 0;
2578 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002579 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002581 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002582# ifdef FEAT_PROP_POPUP
2583 // do not want virtual text counted here
2584 cts.cts_has_prop_with_text = FALSE;
2585# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002586 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002587 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002588
2589 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002590 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002591 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2594 if (wlv.n_extra < 0)
2595 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002596 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002597 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002598 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002599 // line break, but for TABs the highlighting should
2600 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002601 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002602
Bram Moolenaar1306b362022-08-06 15:59:06 +01002603 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002606 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 wp->w_buffer->b_p_vts_array) - 1;
2608# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002609 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002610 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002611# endif
2612
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2614 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002615# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002617 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002618# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 if (VIM_ISWHITE(c))
2620 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002621# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 if (c == TAB)
2623 // See "Tab alignment" below.
2624 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002625# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 if (!wp->w_p_list)
2627 c = ' ';
2628 }
2629 }
2630#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002631 in_multispace = c == ' '
2632 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2633 if (!in_multispace)
2634 multispace_pos = 0;
2635
Bram Moolenaareed9d462021-02-15 20:38:25 +01002636 // 'list': Change char 160 to 'nbsp' and space to 'space'
2637 // setting in 'listchars'. But not when the character is
2638 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 if (wp->w_p_list
2640 && ((((c == 160 && mb_l == 1)
2641 || (mb_utf8
2642 && ((mb_c == 160 && mb_l == 2)
2643 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002644 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 || (c == ' '
2646 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002647 && (wp->w_lcs_chars.space
2648 || (in_multispace
2649 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002650 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 && ptr - line <= trailcol)))
2652 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002653 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2654 {
2655 c = wp->w_lcs_chars.multispace[multispace_pos++];
2656 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2657 multispace_pos = 0;
2658 }
2659 else
2660 c = (c == ' ') ? wp->w_lcs_chars.space
2661 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 if (area_attr == 0 && search_attr == 0)
2663 {
2664 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002665 extra_attr = hl_combine_attr(wlv.win_attr,
2666 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002667 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 }
2669 mb_c = c;
2670 if (enc_utf8 && utf_char2len(c) > 1)
2671 {
2672 mb_utf8 = TRUE;
2673 u8cc[0] = 0;
2674 c = 0xc0;
2675 }
2676 else
2677 mb_utf8 = FALSE;
2678 }
2679
zeertzjq2e7cba32022-06-10 15:30:32 +01002680 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2681 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002683 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2684 && wp->w_lcs_chars.leadmultispace != NULL)
2685 {
2686 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002687 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2688 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002689 multispace_pos = 0;
2690 }
2691
2692 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2693 c = wp->w_lcs_chars.trail;
2694
2695 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2696 c = wp->w_lcs_chars.lead;
2697
zeertzjq2e7cba32022-06-10 15:30:32 +01002698 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002699 c = wp->w_lcs_chars.space;
2700
2701
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 if (!attr_pri)
2703 {
2704 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002705 extra_attr = hl_combine_attr(wlv.win_attr,
2706 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 }
2709 mb_c = c;
2710 if (enc_utf8 && utf_char2len(c) > 1)
2711 {
2712 mb_utf8 = TRUE;
2713 u8cc[0] = 0;
2714 c = 0xc0;
2715 }
2716 else
2717 mb_utf8 = FALSE;
2718 }
2719 }
2720
2721 // Handling of non-printable characters.
2722 if (!vim_isprintc(c))
2723 {
2724 // when getting a character from the file, we may have to
2725 // turn it into something else on the way to putting it
2726 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002727 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 {
2729 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002730 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002732 char_u *sbr = get_showbreak_value(wp);
2733
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 // only adjust the tab_len, when at the first column
2735 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002736 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002737 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738#endif
2739 // tab amount depends on current column
2740#ifdef FEAT_VARTABS
2741 tab_len = tabstop_padding(vcol_adjusted,
2742 wp->w_buffer->b_p_ts,
2743 wp->w_buffer->b_p_vts_array) - 1;
2744#else
2745 tab_len = (int)wp->w_buffer->b_p_ts
2746 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2747#endif
2748
2749#ifdef FEAT_LINEBREAK
2750 if (!wp->w_p_lbr || !wp->w_p_list)
2751#endif
2752 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002753 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754#ifdef FEAT_LINEBREAK
2755 else
2756 {
2757 char_u *p;
2758 int len;
2759 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002760 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002762# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002763 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002765 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002766
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002768 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 && old_boguscols > 0
2770 && wlv.n_extra > tab_len)
2771 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002772# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002775 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002776 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002777 if (wp->w_lcs_chars.tab3)
2778 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 if (wlv.n_extra > 0)
2780 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002781 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002783 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002785 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002787 vim_memset(p, ' ', len);
2788 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002789 vim_free(wlv.p_extra_free);
2790 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002791 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002793 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002795 if (*p == NUL)
2796 {
2797 tab_len = i;
2798 break;
2799 }
2800
2801 // if tab3 is given, use it for the last char
2802 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2803 lcs = wp->w_lcs_chars.tab3;
2804 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002807 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002808 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002809# ifdef FEAT_CONCEAL
2810 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2811 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002812 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002813 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002814# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 }
2817#endif
2818#ifdef FEAT_CONCEAL
2819 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821
2822 // Tab alignment should be identical regardless of
2823 // 'conceallevel' value. So tab compensates of all
2824 // previous concealed characters, and thus resets
2825 // vcol_off and boguscols accumulated so far in the
2826 // line. Note that the tab can be longer than
2827 // 'tabstop' when there are concealed characters.
2828 FIX_FOR_BOGUSCOLS;
2829
2830 // Make sure, the highlighting for the tab char will be
2831 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002832 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002834 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 tab_len += vc_saved;
2836 }
2837#endif
2838 mb_utf8 = FALSE; // don't draw as UTF-8
2839 if (wp->w_p_list)
2840 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002841 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002842 ? wp->w_lcs_chars.tab3
2843 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844#ifdef FEAT_LINEBREAK
2845 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002846 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 else
2848#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002849 wlv.c_extra = wp->w_lcs_chars.tab2;
2850 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002852 extra_attr = hl_combine_attr(wlv.win_attr,
2853 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002854 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 mb_c = c;
2856 if (enc_utf8 && utf_char2len(c) > 1)
2857 {
2858 mb_utf8 = TRUE;
2859 u8cc[0] = 0;
2860 c = 0xc0;
2861 }
2862 }
2863 else
2864 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 wlv.c_final = NUL;
2866 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 c = ' ';
2868 }
2869 }
2870 else if (c == NUL
2871 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002872 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2873 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 && VIsual_mode != Ctrl_V
2875 && (
2876# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002877 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002879 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 && !(noinvcur
2881 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002882 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 && lcs_eol_one > 0)
2884 {
2885 // Display a '$' after the line or highlight an extra
2886 // character if the line break is included.
2887#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2888 // For a diff line the highlighting continues after the
2889 // "$".
2890 if (
2891# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893# ifdef LINE_ATTR
2894 &&
2895# endif
2896# endif
2897# ifdef LINE_ATTR
2898 line_attr == 0
2899# endif
2900 )
2901#endif
2902 {
2903 // In virtualedit, visual selections may extend
2904 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002905 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002906 && wlv.tocol != MAXCOL
2907 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002909 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002911 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2912 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 else
2914 c = ' ';
2915 lcs_eol_one = -1;
2916 --ptr; // put it back at the NUL
2917 if (!attr_pri)
2918 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002919 extra_attr = hl_combine_attr(wlv.win_attr,
2920 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 n_attr = 1;
2922 }
2923 mb_c = c;
2924 if (enc_utf8 && utf_char2len(c) > 1)
2925 {
2926 mb_utf8 = TRUE;
2927 u8cc[0] = 0;
2928 c = 0xc0;
2929 }
2930 else
2931 mb_utf8 = FALSE; // don't draw as UTF-8
2932 }
2933 else if (c != NUL)
2934 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2936 if (wlv.n_extra == 0)
2937 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938#ifdef FEAT_RIGHTLEFT
2939 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002940 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002942 wlv.c_extra = NUL;
2943 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944#ifdef FEAT_LINEBREAK
2945 if (wp->w_p_lbr)
2946 {
2947 char_u *p;
2948
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 c = *wlv.p_extra;
2950 p = alloc(wlv.n_extra + 1);
2951 vim_memset(p, ' ', wlv.n_extra);
2952 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2953 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002954 vim_free(wlv.p_extra_free);
2955 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 }
2957 else
2958#endif
2959 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 wlv.n_extra = byte2cells(c) - 1;
2961 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 }
2963 if (!attr_pri)
2964 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002966 extra_attr = hl_combine_attr(wlv.win_attr,
2967 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 }
2970 mb_utf8 = FALSE; // don't draw as UTF-8
2971 }
2972 else if (VIsual_active
2973 && (VIsual_mode == Ctrl_V
2974 || VIsual_mode == 'v')
2975 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002976 && wlv.tocol != MAXCOL
2977 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 && (
2979#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002980 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002982 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 {
2984 c = ' ';
2985 --ptr; // put it back at the NUL
2986 }
2987#if defined(LINE_ATTR)
2988 else if ((
2989# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991# endif
2992# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002993 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994# endif
2995 line_attr != 0
2996 ) && (
2997# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002998 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003002 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003# endif
3004 < wp->w_width)))
3005 {
3006 // Highlight until the right side of the window
3007 c = ' ';
3008 --ptr; // put it back at the NUL
3009
3010 // Remember we do the char for line highlighting.
3011 ++did_line_attr;
3012
3013 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003016 || (wp->w_p_list &&
3017 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003018 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003020 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 wlv.diff_hlf = HLF_CHD;
3023 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3027 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003029 || (wlv.vcol >= left_curline_col
3030 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 wlv.char_attr = hl_combine_attr(
3032 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 }
3034 }
3035# endif
3036# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003037 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003040 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3041 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 if (!wlv.cul_screenline
3044 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003045 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 wlv.char_attr = hl_combine_attr(
3047 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 }
3049 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3051 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 }
3053# endif
3054 }
3055#endif
3056 }
3057
3058#ifdef FEAT_CONCEAL
3059 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003060 && (wp != curwin || lnum != wp->w_cursor.lnum
3061 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3063 && !(lnum_in_visual_area
3064 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3065 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003067 if (((prev_syntax_id != syntax_seqnr
3068 && (syntax_flags & HL_CONCEAL) != 0)
3069 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003070 && (syn_get_sub_char() != NUL
3071 || (has_match_conc && match_conc)
3072 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073 && wp->w_p_cole != 3)
3074 {
3075 // First time at this concealed item: display one
3076 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003077 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003078 c = match_conc;
3079 else if (syn_get_sub_char() != NUL)
3080 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003081 else if (wp->w_lcs_chars.conceal != NUL)
3082 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 else
3084 c = ' ';
3085
3086 prev_syntax_id = syntax_seqnr;
3087
Bram Moolenaar1306b362022-08-06 15:59:06 +01003088 if (wlv.n_extra > 0)
3089 wlv.vcol_off += wlv.n_extra;
3090 wlv.vcol += wlv.n_extra;
3091 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 {
3093# ifdef FEAT_RIGHTLEFT
3094 if (wp->w_p_rl)
3095 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003096 wlv.col -= wlv.n_extra;
3097 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 }
3099 else
3100# endif
3101 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003102 wlv.boguscols += wlv.n_extra;
3103 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 }
3105 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003106 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 n_attr = 0;
3108 }
3109 else if (n_skip == 0)
3110 {
3111 is_concealing = TRUE;
3112 n_skip = 1;
3113 }
3114 mb_c = c;
3115 if (enc_utf8 && utf_char2len(c) > 1)
3116 {
3117 mb_utf8 = TRUE;
3118 u8cc[0] = 0;
3119 c = 0xc0;
3120 }
3121 else
3122 mb_utf8 = FALSE; // don't draw as UTF-8
3123 }
3124 else
3125 {
3126 prev_syntax_id = 0;
3127 is_concealing = FALSE;
3128 }
3129
3130 if (n_skip > 0 && did_decrement_ptr)
3131 // not showing the '>', put pointer back to avoid getting stuck
3132 ++ptr;
3133
3134#endif // FEAT_CONCEAL
3135 }
3136
3137#ifdef FEAT_CONCEAL
3138 // In the cursor line and we may be concealing characters: correct
3139 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003140 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 && wp == curwin && lnum == wp->w_cursor.lnum
3142 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003145# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003147 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003149# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003150 wp->w_wcol = wlv.col - wlv.boguscols;
3151 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 did_wcol = TRUE;
3153 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003154# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003155 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003156# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 }
3158#endif
3159
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003160 // Use "extra_attr", but don't override visual selection highlighting,
3161 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003162 // Don't use "extra_attr" until n_attr_skip is zero.
3163 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003165 && (!attr_pri
3166#ifdef FEAT_PROP_POPUP
3167 || (text_prop_flags & PT_FLAG_OVERRIDE)
3168#endif
3169 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 {
3171#ifdef LINE_ATTR
3172 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003173 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 else
3175#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003176 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 }
3178
3179#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3180 // XIM don't send preedit_start and preedit_end, but they send
3181 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3182 // im_is_preediting() here.
3183 if (p_imst == IM_ON_THE_SPOT
3184 && xic != NULL
3185 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003186 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 && !p_imdisable
3188 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 {
3191 colnr_T tcol;
3192
3193 if (preedit_end_col == MAXCOL)
3194 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3195 else
3196 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003197 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
3199 if (feedback_old_attr < 0)
3200 {
3201 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003204 wlv.char_attr = im_get_feedback_attr(feedback_col);
3205 if (wlv.char_attr < 0)
3206 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 feedback_col++;
3208 }
3209 else if (feedback_old_attr >= 0)
3210 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003211 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 feedback_old_attr = -1;
3213 feedback_col = 0;
3214 }
3215 }
3216#endif
3217 // Handle the case where we are in column 0 but not on the first
3218 // character of the line and the user wants us to show us a
3219 // special character (via 'listchars' option "precedes:<char>".
3220 if (lcs_prec_todo != NUL
3221 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003222 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003223 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003224 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003226 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 && c != NUL)
3230 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003231 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 lcs_prec_todo = NUL;
3233 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3234 {
3235 // Double-width character being overwritten by the "precedes"
3236 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.c_extra = MB_FILLER_CHAR;
3238 wlv.c_final = NUL;
3239 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003241 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242 }
3243 mb_c = c;
3244 if (enc_utf8 && utf_char2len(c) > 1)
3245 {
3246 mb_utf8 = TRUE;
3247 u8cc[0] = 0;
3248 c = 0xc0;
3249 }
3250 else
3251 mb_utf8 = FALSE; // don't draw as UTF-8
3252 if (!attr_pri)
3253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 saved_attr3 = wlv.char_attr; // save current attr
3255 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 n_attr3 = 1;
3257 }
3258 }
3259
3260 // At end of the text line or just after the last character.
3261 if ((c == NUL
3262#if defined(LINE_ATTR)
3263 || did_line_attr == 1
3264#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 {
3267#ifdef FEAT_SEARCH_EXTRA
3268 // flag to indicate whether prevcol equals startcol of search_hl or
3269 // one of the matches
3270 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3271 (long)(ptr - line) - (c == NUL));
3272#endif
3273 // Invert at least one char, used for Visual and empty line or
3274 // highlight match at end of line. If it's beyond the last
3275 // char on the screen, just overwrite that one (tricky!) Not
3276 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003277 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003278 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 && (VIsual_mode != Ctrl_V
3280 || lnum == VIsual.lnum
3281 || lnum == curwin->w_cursor.lnum)
3282 && c == NUL)
3283#ifdef FEAT_SEARCH_EXTRA
3284 // highlight 'hlsearch' match at end of line
3285 || (prevcol_hl_flag
3286# ifdef FEAT_SYN_HL
3287 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3288 && !(wp == curwin && VIsual_active))
3289# endif
3290# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003291 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292# endif
3293# if defined(LINE_ATTR)
3294 && did_line_attr <= 1
3295# endif
3296 )
3297#endif
3298 ))
3299 {
3300 int n = 0;
3301
3302#ifdef FEAT_RIGHTLEFT
3303 if (wp->w_p_rl)
3304 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003305 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003306 n = 1;
3307 }
3308 else
3309#endif
3310 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003311 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 n = -1;
3313 }
3314 if (n != 0)
3315 {
3316 // At the window boundary, highlight the last character
3317 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 wlv.off += n;
3319 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 }
3321 else
3322 {
3323 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 }
3328#ifdef FEAT_SEARCH_EXTRA
3329 if (area_attr == 0)
3330 {
3331 // Use attributes from match with highest priority among
3332 // 'search_hl' and the match list.
3333 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 }
3336#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339#ifdef FEAT_RIGHTLEFT
3340 if (wp->w_p_rl)
3341 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003342 --wlv.col;
3343 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 else
3346#endif
3347 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 ++wlv.col;
3349 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 ++wlv.vcol;
3352 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
3354 }
3355
3356 // At end of the text line.
3357 if (c == NUL)
3358 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003359 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360
3361 // Update w_cline_height and w_cline_folded if the cursor line was
3362 // updated (saves a call to plines() later).
3363 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3364 {
3365 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367#ifdef FEAT_FOLDING
3368 curwin->w_cline_folded = FALSE;
3369#endif
3370 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3371 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 break;
3373 }
3374
3375 // Show "extends" character from 'listchars' if beyond the line end and
3376 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003377 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 && wp->w_p_list
3380 && !wp->w_p_wrap
3381#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003382 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383#endif
3384 && (
3385#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003388 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003390 || lcs_eol_one > 0
3391 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003394 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 mb_c = c;
3397 if (enc_utf8 && utf_char2len(c) > 1)
3398 {
3399 mb_utf8 = TRUE;
3400 u8cc[0] = 0;
3401 c = 0xc0;
3402 }
3403 else
3404 mb_utf8 = FALSE;
3405 }
3406
3407#ifdef FEAT_SYN_HL
3408 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 if (wlv.draw_color_col)
3410 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411
3412 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3413 // highlight the cursor position itself.
3414 // Also highlight the 'colorcolumn' if it is different than
3415 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003416 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3417 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003419 if (((wlv.draw_state == WL_LINE
3420 || wlv.draw_state == WL_BRI
3421 || wlv.draw_state == WL_SBR)
3422 && !lnum_in_visual_area
3423 && search_attr == 0
3424 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003425# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003426 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003427# endif
3428 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 {
3430 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3431 && lnum != wp->w_cursor.lnum)
3432 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003433 vcol_save_attr = wlv.char_attr;
3434 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3435 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003437 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 vcol_save_attr = wlv.char_attr;
3440 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 }
3442 }
3443#endif
3444
3445 // Store character to be displayed.
3446 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449 {
3450 // Store the character.
3451#if defined(FEAT_RIGHTLEFT)
3452 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3453 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003454 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003455 --wlv.off;
3456 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 }
3458#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003459 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 if (enc_dbcs == DBCS_JPNU)
3461 {
3462 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003463 ScreenLines[wlv.off] = 0x8e;
3464 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 }
3466 else if (enc_utf8)
3467 {
3468 if (mb_utf8)
3469 {
3470 int i;
3471
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003472 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 for (i = 0; i < Screen_mco; ++i)
3476 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 if (u8cc[i] == 0)
3479 break;
3480 }
3481 }
3482 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 }
3485 if (multi_attr)
3486 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003487 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 multi_attr = 0;
3489 }
3490 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003494
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3496 {
3497 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003498 ++wlv.off;
3499 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 if (enc_utf8)
3501 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 else
3504 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003508 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509#endif
3510 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003511 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003512 // When "wlv.tocol" is halfway a character, set it to the end
3513 // of the character, otherwise highlighting won't stop.
3514 if (wlv.tocol == wlv.vcol)
3515 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003516
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003518
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#ifdef FEAT_RIGHTLEFT
3520 if (wp->w_p_rl)
3521 {
3522 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 --wlv.off;
3524 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 }
3526#endif
3527 }
3528#ifdef FEAT_RIGHTLEFT
3529 if (wp->w_p_rl)
3530 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 --wlv.off;
3532 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 }
3534 else
3535#endif
3536 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 ++wlv.off;
3538 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540 }
3541#ifdef FEAT_CONCEAL
3542 else if (wp->w_p_cole > 0 && is_concealing)
3543 {
3544 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 if (wlv.n_extra > 0)
3547 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 if (wp->w_p_wrap)
3549 {
3550 // Special voodoo required if 'wrap' is on.
3551 //
3552 // Advance the column indicator to force the line
3553 // drawing to wrap early. This will make the line
3554 // take up the same screen space when parts are concealed,
3555 // so that cursor line computations aren't messed up.
3556 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 // trailing junk to be written out of the screen line
3559 // we are building, 'boguscols' keeps track of the number
3560 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003561 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003563 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564# ifdef FEAT_RIGHTLEFT
3565 if (wp->w_p_rl)
3566 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003567 wlv.col -= wlv.n_extra;
3568 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 }
3570 else
3571# endif
3572 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003573 wlv.col += wlv.n_extra;
3574 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 n_attr = 0;
3578 }
3579
3580
3581 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3582 {
3583 // Need to fill two screen columns.
3584# ifdef FEAT_RIGHTLEFT
3585 if (wp->w_p_rl)
3586 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 --wlv.boguscols;
3588 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 }
3590 else
3591# endif
3592 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 ++wlv.boguscols;
3594 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 }
3596 }
3597
3598# ifdef FEAT_RIGHTLEFT
3599 if (wp->w_p_rl)
3600 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003601 --wlv.boguscols;
3602 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 }
3604 else
3605# endif
3606 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ++wlv.boguscols;
3608 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 }
3610 }
3611 else
3612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003615 wlv.vcol += wlv.n_extra;
3616 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 n_attr = 0;
3618 }
3619 }
3620
3621 }
3622#endif // FEAT_CONCEAL
3623 else
3624 --n_skip;
3625
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 // Only advance the "wlv.vcol" when after the 'number' or
3627 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003628 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003630 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631#endif
3632 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634
3635#ifdef FEAT_SYN_HL
3636 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003637 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638#endif
3639
3640 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003641 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3642 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643
3644 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003646 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003648 if (n_attr_skip > 0)
3649 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650
3651 // At end of screen line and there is more to come: Display the line
3652 // so far. If there is no more to display it is caught above.
3653 if ((
3654#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003658 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003659 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003661 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003663#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003664 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003665#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003666 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003667 && wlv.p_extra != at_end_str)
3668 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3669 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003670 )
3671 {
3672#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 screen_line(wp, wlv.screen_row, wp->w_wincol,
3674 wlv.col - wlv.boguscols,
3675 wp->w_width, wlv.screen_line_flags);
3676 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3679 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 ++wlv.row;
3682 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683
3684 // When not wrapping and finished diff lines, or when displayed
3685 // '$' and highlighting until last column, break here.
3686 if ((!wp->w_p_wrap
3687#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003688 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003689#endif
3690#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003691 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692#endif
3693 ) || lcs_eol_one == -1)
3694 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003695#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003696 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003697 {
3698 // do not output more of the line, only the "below" prop
3699 ptr += STRLEN(ptr);
3700# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003701 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003702# endif
3703 }
3704#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705
3706 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003707 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003709 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710#endif
3711 )
3712 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3714 draw_vsep_win(wp, wlv.row);
3715 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
3717
3718 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003719 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 break;
3723 }
3724
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003725 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003727 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003729#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003730 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003731#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 && wp->w_width == Columns)
3733 {
3734 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736
3737 // Special trick to make copy/paste of wrapped lines work with
3738 // xterm/screen: write an extra character beyond the end of
3739 // the line. This will work with all terminal types
3740 // (regardless of the xn,am settings).
3741 // Only do this on a fast tty.
3742 // Only do this if the cursor is on the current line
3743 // (something has been written in it).
3744 // Don't do this for the GUI.
3745 // Don't do this for double-width characters.
3746 // Don't do this for a window not at the right screen border.
3747 if (p_tf
3748#ifdef FEAT_GUI
3749 && !gui.in_use
3750#endif
3751 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3753 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 || (*mb_off2cells)(
3756 LineOffset[wlv.screen_row - 1]
3757 + (int)Columns - 2,
3758 LineOffset[wlv.screen_row]
3759 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 {
3761 // First make sure we are at the end of the screen line,
3762 // then output the same character again to let the
3763 // terminal know about the wrap. If the terminal doesn't
3764 // auto-wrap, we overwrite the character.
3765 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 screen_char(LineOffset[wlv.screen_row - 1]
3767 + (unsigned)Columns - 1,
3768 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769
3770 // When there is a multi-byte character, just output a
3771 // space to keep it simple.
3772 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 out_char(' ');
3775 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 + (Columns - 1)]);
3778 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 screen_start(); // don't know where cursor is now
3781 }
3782 }
3783
Bram Moolenaar1306b362022-08-06 15:59:06 +01003784 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003785
Bram Moolenaareed9d462021-02-15 20:38:25 +01003786 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003788 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003790 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003792 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003793 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794#endif
3795#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003796 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 // When the filler lines are actually below the last line of the
3798 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003799 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 break;
3801#endif
3802 }
3803
3804 } // for every character in the line
3805
3806#ifdef FEAT_SPELL
3807 // After an empty line check first word for capital.
3808 if (*skipwhite(line) == NUL)
3809 {
3810 capcol_lnum = lnum + 1;
3811 cap_col = 0;
3812 }
3813#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003814#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 vim_free(text_props);
3816 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003817 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#endif
3819
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003820 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822}