blob: 7e18ced3caa190843ab342d5f5577d135a3f20d5 [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
1128 if (wp->w_p_spell
1129 && *wp->w_s->b_p_spl != NUL
1130 && wp->w_s->b_langp.ga_len > 0
1131 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
1132 {
1133 // Prepare for spell checking.
1134 has_spell = TRUE;
1135 extra_check = TRUE;
1136
1137 // Get the start of the next line, so that words that wrap to the
1138 // next line are found too: "et<line-break>al.".
1139 // Trick: skip a few chars for C/shell/Vim comments
1140 nextline[SPWORDLEN] = NUL;
1141 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1142 {
1143 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1144 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1145 }
1146
1147 // When a word wrapped from the previous line the start of the
1148 // current line is valid.
1149 if (lnum == checked_lnum)
1150 cur_checked_col = checked_col;
1151 checked_lnum = 0;
1152
1153 // When there was a sentence end in the previous line may require a
1154 // word starting with capital in this line. In line 1 always check
1155 // the first word.
1156 if (lnum != capcol_lnum)
1157 cap_col = -1;
1158 if (lnum == 1)
1159 cap_col = 0;
1160 capcol_lnum = 0;
1161 }
1162#endif
1163
1164 // handle Visual active in this window
1165 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1166 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001167 pos_T *top, *bot;
1168
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1170 {
1171 // Visual is after curwin->w_cursor
1172 top = &curwin->w_cursor;
1173 bot = &VIsual;
1174 }
1175 else
1176 {
1177 // Visual is before curwin->w_cursor
1178 top = &VIsual;
1179 bot = &curwin->w_cursor;
1180 }
1181 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1182 if (VIsual_mode == Ctrl_V)
1183 {
1184 // block mode
1185 if (lnum_in_visual_area)
1186 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001187 wlv.fromcol = wp->w_old_cursor_fcol;
1188 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 }
1190 }
1191 else
1192 {
1193 // non-block mode
1194 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001195 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 else if (lnum == top->lnum)
1197 {
1198 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001199 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 else
1201 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001202 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001204 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 }
1206 }
1207 if (VIsual_mode != 'V' && lnum == bot->lnum)
1208 {
1209 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1210 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001211 wlv.fromcol = -10;
1212 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 }
1214 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001215 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 else
1217 {
1218 pos = *bot;
1219 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001220 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1221 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 else
1223 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001224 getvvcol(wp, &pos, NULL, NULL,
1225 (colnr_T *)&wlv.tocol);
1226 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 }
1228 }
1229 }
1230 }
1231
1232 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001233 if (!highlight_match && lnum == curwin->w_cursor.lnum
1234 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235#ifdef FEAT_GUI
1236 && !gui.in_use
1237#endif
1238 )
1239 noinvcur = TRUE;
1240
1241 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001242 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 {
1244 area_highlighting = TRUE;
1245 vi_attr = HL_ATTR(HLF_V);
1246#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1247 if ((clip_star.available && !clip_star.owned
1248 && clip_isautosel_star())
1249 || (clip_plus.available && !clip_plus.owned
1250 && clip_isautosel_plus()))
1251 vi_attr = HL_ATTR(HLF_VNC);
1252#endif
1253 }
1254 }
1255
1256 // handle 'incsearch' and ":s///c" highlighting
1257 else if (highlight_match
1258 && wp == curwin
1259 && lnum >= curwin->w_cursor.lnum
1260 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1261 {
1262 if (lnum == curwin->w_cursor.lnum)
1263 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001264 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001266 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1268 {
1269 pos.lnum = lnum;
1270 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001271 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001272 }
1273 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001274 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1277 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 area_highlighting = TRUE;
1279 vi_attr = HL_ATTR(HLF_I);
1280 }
1281 }
1282
1283#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001284 wlv.filler_lines = diff_check(wp, lnum);
1285 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001287 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 {
1289 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001290 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001292 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001294 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 }
1296 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001297 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001298 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 area_highlighting = TRUE;
1300 }
1301 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001302 wlv.filler_lines = wp->w_topfill;
1303 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001304#endif
1305
1306#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001307 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001308 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001309 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310#endif
1311
1312#ifdef LINE_ATTR
1313# ifdef FEAT_SIGNS
1314 // If this line has a sign with line highlighting set line_attr.
1315 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001316 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317# endif
1318# if defined(FEAT_QUICKFIX)
1319 // Highlight the current line in the quickfix window.
1320 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1321 line_attr = HL_ATTR(HLF_QFL);
1322# endif
1323 if (line_attr != 0)
1324 area_highlighting = TRUE;
1325#endif
1326
1327 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1328 ptr = line;
1329
1330#ifdef FEAT_SPELL
1331 if (has_spell && !number_only)
1332 {
1333 // For checking first word with a capital skip white space.
1334 if (cap_col == 0)
1335 cap_col = getwhitecols(line);
1336
1337 // To be able to spell-check over line boundaries copy the end of the
1338 // current line into nextline[]. Above the start of the next line was
1339 // copied to nextline[SPWORDLEN].
1340 if (nextline[SPWORDLEN] == NUL)
1341 {
1342 // No next line or it is empty.
1343 nextlinecol = MAXCOL;
1344 nextline_idx = 0;
1345 }
1346 else
1347 {
1348 v = (long)STRLEN(line);
1349 if (v < SPWORDLEN)
1350 {
1351 // Short line, use it completely and append the start of the
1352 // next line.
1353 nextlinecol = 0;
1354 mch_memmove(nextline, line, (size_t)v);
1355 STRMOVE(nextline + v, nextline + SPWORDLEN);
1356 nextline_idx = v + 1;
1357 }
1358 else
1359 {
1360 // Long line, use only the last SPWORDLEN bytes.
1361 nextlinecol = v - SPWORDLEN;
1362 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1363 nextline_idx = SPWORDLEN + 1;
1364 }
1365 }
1366 }
1367#endif
1368
1369 if (wp->w_p_list)
1370 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001371 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001372 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001373 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001374 || wp->w_lcs_chars.trail
1375 || wp->w_lcs_chars.lead
1376 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001378
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001380 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381 {
1382 trailcol = (colnr_T)STRLEN(ptr);
1383 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1384 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001385 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001387 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001388 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001389 {
1390 leadcol = 0;
1391 while (VIM_ISWHITE(ptr[leadcol]))
1392 ++leadcol;
1393 if (ptr[leadcol] == NUL)
1394 // in a line full of spaces all of them are treated as trailing
1395 leadcol = (colnr_T)0;
1396 else
1397 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001398 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001399 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 }
1401
Bram Moolenaard7657e92022-09-20 18:59:30 +01001402 wlv.wcr_attr = get_wcr_attr(wp);
1403 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001405 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 area_highlighting = TRUE;
1407 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001408
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001409#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001411 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412#endif
1413
1414 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1415 // first character to be displayed.
1416 if (wp->w_p_wrap)
1417 v = wp->w_skipcol;
1418 else
1419 v = wp->w_leftcol;
1420 if (v > 0 && !number_only)
1421 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001422 char_u *prev_ptr = ptr;
1423 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001424 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001426 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001427 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001429 charsize = win_lbr_chartabsize(&cts, NULL);
1430 cts.cts_vcol += charsize;
1431 prev_ptr = cts.cts_ptr;
1432 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001434 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001435 ptr = cts.cts_ptr;
1436 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437
1438 // When:
1439 // - 'cuc' is set, or
1440 // - 'colorcolumn' is set, or
1441 // - 'virtualedit' is set, or
1442 // - the visual mode is active,
1443 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001444 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001446 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447#endif
1448 virtual_active() ||
1449 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001450 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451
1452 // Handle a character that's not completely on the screen: Put ptr at
1453 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001454 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001456 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457 ptr = prev_ptr;
1458 // If the character fits on the screen, don't need to skip it.
1459 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001460 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1461 && wlv.col == 0)
1462 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 }
1464
1465 // Adjust for when the inverted text is before the screen,
1466 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001467 if (wlv.tocol <= wlv.vcol)
1468 wlv.fromcol = 0;
1469 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1470 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
1472#ifdef FEAT_LINEBREAK
1473 // When w_skipcol is non-zero, first line needs 'showbreak'
1474 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001475 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476#endif
1477#ifdef FEAT_SPELL
1478 // When spell checking a word we need to figure out the start of the
1479 // word and if it's badly spelled or not.
1480 if (has_spell)
1481 {
1482 int len;
1483 colnr_T linecol = (colnr_T)(ptr - line);
1484 hlf_T spell_hlf = HLF_COUNT;
1485
1486 pos = wp->w_cursor;
1487 wp->w_cursor.lnum = lnum;
1488 wp->w_cursor.col = linecol;
1489 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1490
1491 // spell_move_to() may call ml_get() and make "line" invalid
1492 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1493 ptr = line + linecol;
1494
1495 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1496 {
1497 // no bad word found at line start, don't check until end of a
1498 // word
1499 spell_hlf = HLF_COUNT;
1500 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1501 }
1502 else
1503 {
1504 // bad word found, use attributes until end of word
1505 word_end = wp->w_cursor.col + len + 1;
1506
1507 // Turn index into actual attributes.
1508 if (spell_hlf != HLF_COUNT)
1509 spell_attr = highlight_attr[spell_hlf];
1510 }
1511 wp->w_cursor = pos;
1512
1513# ifdef FEAT_SYN_HL
1514 // Need to restart syntax highlighting for this line.
1515 if (has_syntax)
1516 syntax_start(wp, lnum);
1517# endif
1518 }
1519#endif
1520 }
1521
1522 // Correct highlighting for cursor that can't be disabled.
1523 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001524 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525 {
1526 if (noinvcur)
1527 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001528 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 {
1530 // highlighting starts at cursor, let it start just after the
1531 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001532 fromcol_prev = wlv.fromcol;
1533 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001535 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001536 // restart highlighting after the cursor
1537 fromcol_prev = wp->w_virtcol;
1538 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001539 if (wlv.fromcol >= wlv.tocol)
1540 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 }
1542
1543#ifdef FEAT_SEARCH_EXTRA
1544 if (!number_only)
1545 {
1546 v = (long)(ptr - line);
1547 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1548 &line, &screen_search_hl,
1549 &search_attr);
1550 ptr = line + v; // "line" may have been updated
1551 }
1552#endif
1553
1554#ifdef FEAT_SYN_HL
1555 // Cursor line highlighting for 'cursorline' in the current window.
1556 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1557 {
1558 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001559 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 if (!(wp == curwin && VIsual_active)
1561 && wp->w_p_culopt_flags != CULOPT_NBR)
1562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001563 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1565
1566 // Only set line_attr here when "screenline" is not present in
1567 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001568 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001570 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001571# ifdef FEAT_SIGNS
1572 // Combine the 'cursorline' and sign highlighting, depending on
1573 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001574 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001575 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001576 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001577 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001578 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001579 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001580 }
1581 else
1582# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001583# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001584 // let the line attribute overrule 'cursorline', otherwise
1585 // it disappears when both have background set;
1586 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001587 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001588# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001589 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001590# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 }
1592 else
1593 {
1594 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1596 }
1597 area_highlighting = TRUE;
1598 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 }
1600#endif
1601
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001602#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 {
1604 char_u *prop_start;
1605
1606 text_prop_count = get_text_props(wp->w_buffer, lnum,
1607 &prop_start, FALSE);
1608 if (text_prop_count > 0)
1609 {
1610 // Make a copy of the properties, so that they are properly
1611 // aligned.
1612 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1613 if (text_props != NULL)
1614 mch_memmove(text_props, prop_start,
1615 text_prop_count * sizeof(textprop_T));
1616
1617 // Allocate an array for the indexes.
1618 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001619 if (text_prop_idxs == NULL)
1620 VIM_CLEAR(text_props);
1621
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001622 if (text_props != NULL)
1623 {
1624 area_highlighting = TRUE;
1625 extra_check = TRUE;
1626 for (int i = 0; i < text_prop_count; ++i)
1627 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1628 ++wlv.text_prop_above_count;
1629 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 }
1631 }
1632#endif
1633
Bram Moolenaar1306b362022-08-06 15:59:06 +01001634 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635
1636 // Repeat for the whole displayed line.
1637 for (;;)
1638 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001639 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001640#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001641 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642#endif
1643#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001644 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001646
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001647 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001648 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001650#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001651 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001652 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001653 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001654 line_attr = line_attr_save;
1655 }
1656#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001657#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001658 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001660 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 if (cmdwin_type != 0 && wp == curwin)
1662 {
1663 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001664 wlv.n_extra = 1;
1665 wlv.c_extra = cmdwin_type;
1666 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001667 wlv.char_attr =
1668 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 }
1670 }
1671#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001673 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001675 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001676 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 }
1678#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001680 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001682 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001685 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001686 }
1687#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001688 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001690 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001692 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001695 // Check if 'breakindent' applies and show it.
1696 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1697 if (wlv.n_extra == 0)
1698 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001701 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001703 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001704 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705 }
1706#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001709 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001710 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 }
1712 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001713
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001715 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001716 && wlv.vcol >= left_curline_col
1717 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001719 wlv.cul_attr = HL_ATTR(HLF_CUL);
1720 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 }
1722#endif
1723
1724 // When still displaying '$' of change command, stop at cursor.
1725 // When only displaying the (relative) line number and that's done,
1726 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001727 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001728 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001729 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001731 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732#endif
1733 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001735 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1736 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 // Pretend we have finished updating the window. Except when
1738 // 'cursorcolumn' is set.
1739#ifdef FEAT_SYN_HL
1740 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001741 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 else
1743#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001744 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 break;
1746 }
1747
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 {
1750 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001751 if (wlv.vcol == wlv.fromcol
1752 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1753 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 && (*mb_ptr2cells)(ptr) > 1)
1755 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001756 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 area_attr = vi_attr; // start highlighting
1759 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001760 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001761 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 area_attr = 0; // stop highlighting
1763
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001764#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 if (text_props != NULL)
1766 {
1767 int pi;
1768 int bcol = (int)(ptr - line);
1769
Bram Moolenaar1306b362022-08-06 15:59:06 +01001770 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001771# ifdef FEAT_LINEBREAK
1772 && !in_linebreak
1773# endif
1774 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 --bcol; // still working on the previous char, e.g. Tab
1776
1777 // Check if any active property ends.
1778 for (pi = 0; pi < text_props_active; ++pi)
1779 {
1780 int tpi = text_prop_idxs[pi];
1781
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001782 if (text_props[tpi].tp_col != MAXCOL
1783 && bcol >= text_props[tpi].tp_col - 1
1784 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 {
1786 if (pi + 1 < text_props_active)
1787 mch_memmove(text_prop_idxs + pi,
1788 text_prop_idxs + pi + 1,
1789 sizeof(int)
1790 * (text_props_active - (pi + 1)));
1791 --text_props_active;
1792 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001793# ifdef FEAT_LINEBREAK
1794 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001795 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001796 syntax_attr = 0;
1797# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 }
1799 }
1800
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001801# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001802 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001803 // not on the next char yet, don't start another prop
1804 --bcol;
1805# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001807 // With 'nowrap' and not in the first screen line only "below"
1808 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001810 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001811 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001812 && (wp->w_p_wrap
1813 || wlv.row == startrow
1814 || (text_props[text_prop_next].tp_flags
1815 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001816 || (bcol == 0 &&
1817 (text_props[text_prop_next].tp_flags
1818 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001819 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001820 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001821 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001822 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1823 {
1824 // first display the '$' after the line
1825 text_prop_follows = TRUE;
1826 break;
1827 }
1828 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001829 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001830 + text_props[text_prop_next].tp_len)
1831 text_prop_idxs[text_props_active++] = text_prop_next;
1832 ++text_prop_next;
1833 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001835 if (wlv.n_extra == 0 || !extra_for_textprop)
1836 {
1837 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001838 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001839 text_prop_flags = 0;
1840 text_prop_type = NULL;
1841 text_prop_id = 0;
1842 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001845 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001846 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001847 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001848
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 // Sort the properties on priority and/or starting last.
1850 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001851 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001852 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001853 sort_text_props(wp->w_buffer, text_props,
1854 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855
1856 for (pi = 0; pi < text_props_active; ++pi)
1857 {
1858 int tpi = text_prop_idxs[pi];
1859 proptype_T *pt = text_prop_type_by_id(
1860 wp->w_buffer, text_props[tpi].tp_type);
1861
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001862 if (pt != NULL && (pt->pt_hl_id > 0
1863 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001864 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001866 if (pt->pt_hl_id > 0)
1867 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 text_prop_type = pt;
1869 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001870 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001871 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001872 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001873 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001874 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 }
1876 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001877 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001878 && -text_prop_id
1879 <= wp->w_buffer->b_textprop_text.ga_len)
1880 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001881 textprop_T *tp = &text_props[used_tpi];
1882 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001883 ->b_textprop_text.ga_data)[
1884 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001885 int above = (tp->tp_flags
1886 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001887
1888 // reset the ID in the copy to avoid it being used
1889 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001890 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001892 if (p != NULL)
1893 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001894 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001895 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001896 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001897 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001898 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1899 int padding = tp->tp_col == MAXCOL
1900 && tp->tp_len > 1
1901 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001902
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001903 // Insert virtual text before the current
1904 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905 wlv.p_extra = p;
1906 wlv.c_extra = NUL;
1907 wlv.c_final = NUL;
1908 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001909 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001910 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001911 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001912 // restore search_attr and area_attr when n_extra
1913 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001914 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001915 saved_area_attr = area_attr;
1916 search_attr = 0;
1917 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001918 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001919 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001920 if (*ptr == NUL)
1921 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001922 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001923#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001924 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001925 {
1926 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001927 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001928 wlv.need_showbreak = FALSE;
1929 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001930 }
1931#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001932 if ((right || above || below || !wrap
1933 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001934 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001935 char_u *prev_p_extra = wlv.p_extra;
1936 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001937
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001938 // Take care of padding, right-align and
1939 // truncation.
1940 // Shared with win_lbr_chartabsize(), must do
1941 // exactly the same.
1942 start_line = text_prop_position(wp, tp,
1943 wlv.col,
1944 &wlv.n_extra, &wlv.p_extra,
1945 &n_attr, &n_attr_skip);
1946 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001947 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001948 // wlv.p_extra was allocated
1949 vim_free(p_extra_free2);
1950 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001951 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001952
Bram Moolenaara4abe512022-09-15 19:44:09 +01001953 if (lcs_eol_one < 0 && wlv.col
1954 + wlv.n_extra - 2 > wp->w_width)
1955 // don't bail out at end of line
1956 lcs_eol_one = 0;
1957
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001958 // When 'wrap' is off then for "below" we need
1959 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001960 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001961 {
1962 draw_screen_line(wp, &wlv);
1963
1964 // When line got too long for screen break
1965 // here.
1966 if (wlv.row == endrow)
1967 {
1968 ++wlv.row;
1969 break;
1970 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001971 win_line_start(wp, &wlv, TRUE);
1972 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001973 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001974 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001975 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001976
1977 // If another text prop follows the condition below at
1978 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001979 // If this is an "above" text prop and 'nowrap' the we
1980 // must wrap anyway.
1981 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001982 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001983 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001984 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001985 else if (text_prop_next < text_prop_count
1986 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001987 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1988 || (!wp->w_p_wrap
1989 && wlv.col == wp->w_width - 1
1990 && (text_props[text_prop_next].tp_flags
1991 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001992 // When at last-but-one character and a text property
1993 // follows after it, we may need to flush the line after
1994 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001995 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001996 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 }
1998#endif
1999
Bram Moolenaare38fc862022-08-11 17:24:50 +01002000#ifdef FEAT_SEARCH_EXTRA
2001 if (wlv.n_extra == 0)
2002 {
2003 // Check for start/end of 'hlsearch' and other matches.
2004 // After end, check for start/end of next match.
2005 // When another match, have to check for start again.
2006 v = (long)(ptr - line);
2007 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2008 &screen_search_hl, &has_match_conc,
2009 &match_conc, did_line_attr, lcs_eol_one,
2010 &on_last_col);
2011 ptr = line + v; // "line" may have been changed
2012 prev_ptr = ptr;
2013
2014 // Do not allow a conceal over EOL otherwise EOL will be missed
2015 // and bad things happen.
2016 if (*ptr == NUL)
2017 has_match_conc = 0;
2018 }
2019#endif
2020
2021#ifdef FEAT_DIFF
2022 if (wlv.diff_hlf != (hlf_T)0)
2023 {
2024 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2025 && wlv.n_extra == 0)
2026 wlv.diff_hlf = HLF_TXD; // changed text
2027 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2028 && wlv.n_extra == 0)
2029 wlv.diff_hlf = HLF_CHD; // changed line
2030 line_attr = HL_ATTR(wlv.diff_hlf);
2031 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2032 && wp->w_p_culopt_flags != CULOPT_NBR
2033 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2034 && wlv.vcol <= right_curline_col)))
2035 line_attr = hl_combine_attr(
2036 line_attr, HL_ATTR(HLF_CUL));
2037 }
2038#endif
2039
Bram Moolenaara74fda62019-10-19 17:38:03 +02002040#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002041 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002042 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002043 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002044# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002045 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002046 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002047# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002048 // Get syntax attribute.
2049 if (has_syntax)
2050 {
2051 // Get the syntax attribute for the character. If there
2052 // is an error, disable syntax highlighting.
2053 save_did_emsg = did_emsg;
2054 did_emsg = FALSE;
2055
2056 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002057 if (v == prev_syntax_col)
2058 // at same column again
2059 syntax_attr = prev_syntax_attr;
2060 else
2061 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002062# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002063 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002064# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002065 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002066# ifdef FEAT_SPELL
2067 has_spell ? &can_spell :
2068# endif
2069 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002070 prev_syntax_col = v;
2071 prev_syntax_attr = syntax_attr;
2072 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002073
Bram Moolenaar34390282019-10-16 14:38:26 +02002074 if (did_emsg)
2075 {
2076 wp->w_s->b_syn_error = TRUE;
2077 has_syntax = FALSE;
2078 syntax_attr = 0;
2079 }
2080 else
2081 did_emsg = save_did_emsg;
2082# ifdef SYN_TIME_LIMIT
2083 if (wp->w_s->b_syn_slow)
2084 has_syntax = FALSE;
2085# endif
2086
2087 // Need to get the line again, a multi-line regexp may
2088 // have made it invalid.
2089 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2090 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002091 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002092# ifdef FEAT_CONCEAL
2093 // no concealing past the end of the line, it interferes
2094 // with line highlighting
2095 if (*ptr == NUL)
2096 syntax_flags = 0;
2097 else
2098 syntax_flags = get_syntax_info(&syntax_seqnr);
2099# endif
2100 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002101 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002102# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002103 // Combine text property highlight into syntax highlight.
2104 if (text_prop_type != NULL)
2105 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002106 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002107 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2108 else
2109 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002110 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002111 }
2112# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002113#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002114
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002115 // Decide which of the highlight attributes to use.
2116 attr_pri = TRUE;
2117#ifdef LINE_ATTR
2118 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002119 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002121 if (!highlight_match)
2122 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002123 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002124# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002126# endif
2127 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002129 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002131# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002132 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002133# endif
2134 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002135 else if (line_attr != 0
2136 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2137 || wlv.vcol < wlv.fromcol
2138 || vcol_prev < fromcol_prev
2139 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002140 {
2141 // Use line_attr when not in the Visual or 'incsearch' area
2142 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002143# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002145# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002147# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 attr_pri = FALSE;
2149 }
2150#else
2151 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002154 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155#endif
2156 else
2157 {
2158 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002161#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002163#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002165#ifdef FEAT_PROP_POPUP
2166 // override with text property highlight when "override" is TRUE
2167 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002168 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002169#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002171
2172 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002173 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002174 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002175 if (wlv.char_attr == 0)
2176 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002177 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002179 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180
2181 // Get the next character to put on the screen.
2182
2183 // The "p_extra" points to the extra stuff that is inserted to
2184 // represent special characters (non-printable stuff) and other
2185 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2188 // "p_extra[n_extra]".
2189 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002190 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2195 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2197 if (enc_utf8 && utf_char2len(c) > 1)
2198 {
2199 mb_utf8 = TRUE;
2200 u8cc[0] = 0;
2201 c = 0xc0;
2202 }
2203 else
2204 mb_utf8 = FALSE;
2205 }
2206 else
2207 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 if (has_mbyte)
2210 {
2211 mb_c = c;
2212 if (enc_utf8)
2213 {
2214 // If the UTF-8 character is more than one byte:
2215 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 mb_l = 1;
2220 else if (mb_l > 1)
2221 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 mb_utf8 = TRUE;
2224 c = 0xc0;
2225 }
2226 }
2227 else
2228 {
2229 // if this is a DBCS character, put it in "mb_c"
2230 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232 mb_l = 1;
2233 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002234 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 }
2236 if (mb_l == 0) // at the NUL at end-of-line
2237 mb_l = 1;
2238
2239 // If a double-width char doesn't fit display a '>' in the
2240 // last column.
2241 if ((
2242# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002243 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002245 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 && (*mb_char2cells)(mb_c) == 2)
2247 {
2248 c = '>';
2249 mb_c = c;
2250 mb_l = 1;
2251 mb_utf8 = FALSE;
2252 multi_attr = HL_ATTR(HLF_AT);
2253#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002254 if (wlv.cul_attr)
2255 multi_attr = hl_combine_attr(
2256 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002257#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002258 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002259
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260 // put the pointer back to output the double-width
2261 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002262 ++wlv.n_extra;
2263 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 }
2265 else
2266 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002267 wlv.n_extra -= mb_l - 1;
2268 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 }
2270 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002271 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002272 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002274#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002276 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002277 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002278 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002279 if (search_attr == 0)
2280 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002281 if (area_attr == 0 && *ptr != NUL)
2282 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002283 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002284#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285 }
2286 else
2287 {
2288#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002289 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002291 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002293 // Get a character from the line itself.
2294 c = *ptr;
2295#ifdef FEAT_LINEBREAK
2296 c0 = *ptr;
2297#endif
2298 if (has_mbyte)
2299 {
2300 mb_c = c;
2301 if (enc_utf8)
2302 {
2303 // If the UTF-8 character is more than one byte: Decode it
2304 // into "mb_c".
2305 mb_l = utfc_ptr2len(ptr);
2306 mb_utf8 = FALSE;
2307 if (mb_l > 1)
2308 {
2309 mb_c = utfc_ptr2char(ptr, u8cc);
2310 // Overlong encoded ASCII or ASCII with composing char
2311 // is displayed normally, except a NUL.
2312 if (mb_c < 0x80)
2313 {
2314 c = mb_c;
2315#ifdef FEAT_LINEBREAK
2316 c0 = mb_c;
2317#endif
2318 }
2319 mb_utf8 = TRUE;
2320
2321 // At start of the line we can have a composing char.
2322 // Draw it as a space with a composing char.
2323 if (utf_iscomposing(mb_c))
2324 {
2325 int i;
2326
2327 for (i = Screen_mco - 1; i > 0; --i)
2328 u8cc[i] = u8cc[i - 1];
2329 u8cc[0] = mb_c;
2330 mb_c = ' ';
2331 }
2332 }
2333
2334 if ((mb_l == 1 && c >= 0x80)
2335 || (mb_l >= 1 && mb_c == 0)
2336 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2337 {
2338 // Illegal UTF-8 byte: display as <xx>.
2339 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002340 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341# ifdef FEAT_RIGHTLEFT
2342 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002343 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002344# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002345 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 c = *wlv.p_extra;
2347 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002349 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2350 wlv.c_extra = NUL;
2351 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 if (area_attr == 0 && search_attr == 0)
2353 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002354 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002355 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002356 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002357 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 }
2359 }
2360 else if (mb_l == 0) // at the NUL at end-of-line
2361 mb_l = 1;
2362#ifdef FEAT_ARABIC
2363 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2364 {
2365 // Do Arabic shaping.
2366 int pc, pc1, nc;
2367 int pcc[MAX_MCO];
2368
2369 // The idea of what is the previous and next
2370 // character depends on 'rightleft'.
2371 if (wp->w_p_rl)
2372 {
2373 pc = prev_c;
2374 pc1 = prev_c1;
2375 nc = utf_ptr2char(ptr + mb_l);
2376 prev_c1 = u8cc[0];
2377 }
2378 else
2379 {
2380 pc = utfc_ptr2char(ptr + mb_l, pcc);
2381 nc = prev_c;
2382 pc1 = pcc[0];
2383 }
2384 prev_c = mb_c;
2385
2386 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2387 }
2388 else
2389 prev_c = mb_c;
2390#endif
2391 }
2392 else // enc_dbcs
2393 {
2394 mb_l = MB_BYTE2LEN(c);
2395 if (mb_l == 0) // at the NUL at end-of-line
2396 mb_l = 1;
2397 else if (mb_l > 1)
2398 {
2399 // We assume a second byte below 32 is illegal.
2400 // Hopefully this is OK for all double-byte encodings!
2401 if (ptr[1] >= 32)
2402 mb_c = (c << 8) + ptr[1];
2403 else
2404 {
2405 if (ptr[1] == NUL)
2406 {
2407 // head byte at end of line
2408 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002409 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 }
2411 else
2412 {
2413 // illegal tail byte
2414 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002415 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002417 wlv.p_extra = wlv.extra;
2418 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 wlv.c_extra = NUL;
2420 wlv.c_final = NUL;
2421 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422 if (area_attr == 0 && search_attr == 0)
2423 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002425 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002426 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002427 // save current attr
2428 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 }
2430 mb_c = c;
2431 }
2432 }
2433 }
2434 // If a double-width char doesn't fit display a '>' in the
2435 // last column; the character is displayed at the start of the
2436 // next line.
2437 if ((
2438# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002439 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002441 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 && (*mb_char2cells)(mb_c) == 2)
2443 {
2444 c = '>';
2445 mb_c = c;
2446 mb_utf8 = FALSE;
2447 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002448 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 // Put pointer back so that the character will be
2450 // displayed at the start of the next line.
2451 --ptr;
2452#ifdef FEAT_CONCEAL
2453 did_decrement_ptr = TRUE;
2454#endif
2455 }
2456 else if (*ptr != NUL)
2457 ptr += mb_l - 1;
2458
2459 // If a double-width char doesn't fit at the left side display
2460 // a '<' in the first column. Don't do this for unprintable
2461 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 wlv.n_extra = 1;
2465 wlv.c_extra = MB_FILLER_CHAR;
2466 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 c = ' ';
2468 if (area_attr == 0 && search_attr == 0)
2469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002471 extra_attr = hl_combine_attr(
2472 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 }
2475 mb_c = c;
2476 mb_utf8 = FALSE;
2477 mb_l = 1;
2478 }
2479
2480 }
2481 ++ptr;
2482
2483 if (extra_check)
2484 {
2485#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 // Check spelling (unless at the end of the line).
2487 // Only do this when there is no syntax highlighting, the
2488 // @Spell cluster is not used or the current syntax item
2489 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002490 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 if (has_spell && v >= word_end && v > cur_checked_col)
2492 {
2493 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002494 // do not calculate cap_col at the end of the line or when
2495 // only white space is following
2496 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497# ifdef FEAT_SYN_HL
2498 !has_syntax ||
2499# endif
2500 can_spell))
2501 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002502 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 int len;
2504 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002505
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508
2509 // Use nextline[] if possible, it has the start of the
2510 // next line concatenated.
2511 if ((prev_ptr - line) - nextlinecol >= 0)
2512 p = nextline + (prev_ptr - line) - nextlinecol;
2513 else
2514 p = prev_ptr;
2515 cap_col -= (int)(prev_ptr - line);
2516 len = spell_check(wp, p, &spell_hlf, &cap_col,
2517 nochange);
2518 word_end = v + len;
2519
2520 // In Insert mode only highlight a word that
2521 // doesn't touch the cursor.
2522 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002523 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 && wp->w_cursor.lnum == lnum
2525 && wp->w_cursor.col >=
2526 (colnr_T)(prev_ptr - line)
2527 && wp->w_cursor.col < (colnr_T)word_end)
2528 {
2529 spell_hlf = HLF_COUNT;
2530 spell_redraw_lnum = lnum;
2531 }
2532
2533 if (spell_hlf == HLF_COUNT && p != prev_ptr
2534 && (p - nextline) + len > nextline_idx)
2535 {
2536 // Remember that the good word continues at the
2537 // start of the next line.
2538 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002539 checked_col = (int)((p - nextline)
2540 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 }
2542
2543 // Turn index into actual attributes.
2544 if (spell_hlf != HLF_COUNT)
2545 spell_attr = highlight_attr[spell_hlf];
2546
2547 if (cap_col > 0)
2548 {
2549 if (p != prev_ptr
2550 && (p - nextline) + cap_col >= nextline_idx)
2551 {
2552 // Remember that the word in the next line
2553 // must start with a capital.
2554 capcol_lnum = lnum + 1;
2555 cap_col = (int)((p - nextline) + cap_col
2556 - nextline_idx);
2557 }
2558 else
2559 // Compute the actual column.
2560 cap_col += (int)(prev_ptr - line);
2561 }
2562 }
2563 }
2564 if (spell_attr != 0)
2565 {
2566 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2568 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002570 wlv.char_attr = hl_combine_attr(spell_attr,
2571 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 }
2573#endif
2574#ifdef FEAT_LINEBREAK
2575 // Found last space before word: check for line break.
2576 if (wp->w_p_lbr && c0 == c
2577 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2578 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002579 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2580 : 0;
2581 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002582 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002584 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002585# ifdef FEAT_PROP_POPUP
2586 // do not want virtual text counted here
2587 cts.cts_has_prop_with_text = FALSE;
2588# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002590 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002591
2592 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002593 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002594 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002595 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002596 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2597 if (wlv.n_extra < 0)
2598 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002599 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002600 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002601 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002602 // line break, but for TABs the highlighting should
2603 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002604 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002605
Bram Moolenaar1306b362022-08-06 15:59:06 +01002606 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002609 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 wp->w_buffer->b_p_vts_array) - 1;
2611# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002612 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002613 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614# endif
2615
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2617 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002618# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002620 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002621# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 if (VIM_ISWHITE(c))
2623 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002624# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625 if (c == TAB)
2626 // See "Tab alignment" below.
2627 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002628# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629 if (!wp->w_p_list)
2630 c = ' ';
2631 }
2632 }
2633#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002634 in_multispace = c == ' '
2635 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2636 if (!in_multispace)
2637 multispace_pos = 0;
2638
Bram Moolenaareed9d462021-02-15 20:38:25 +01002639 // 'list': Change char 160 to 'nbsp' and space to 'space'
2640 // setting in 'listchars'. But not when the character is
2641 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 if (wp->w_p_list
2643 && ((((c == 160 && mb_l == 1)
2644 || (mb_utf8
2645 && ((mb_c == 160 && mb_l == 2)
2646 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002647 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 || (c == ' '
2649 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002650 && (wp->w_lcs_chars.space
2651 || (in_multispace
2652 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002653 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 && ptr - line <= trailcol)))
2655 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002656 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2657 {
2658 c = wp->w_lcs_chars.multispace[multispace_pos++];
2659 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2660 multispace_pos = 0;
2661 }
2662 else
2663 c = (c == ' ') ? wp->w_lcs_chars.space
2664 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 if (area_attr == 0 && search_attr == 0)
2666 {
2667 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002668 extra_attr = hl_combine_attr(wlv.win_attr,
2669 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002670 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 }
2672 mb_c = c;
2673 if (enc_utf8 && utf_char2len(c) > 1)
2674 {
2675 mb_utf8 = TRUE;
2676 u8cc[0] = 0;
2677 c = 0xc0;
2678 }
2679 else
2680 mb_utf8 = FALSE;
2681 }
2682
zeertzjq2e7cba32022-06-10 15:30:32 +01002683 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2684 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002686 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2687 && wp->w_lcs_chars.leadmultispace != NULL)
2688 {
2689 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002690 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2691 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002692 multispace_pos = 0;
2693 }
2694
2695 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2696 c = wp->w_lcs_chars.trail;
2697
2698 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2699 c = wp->w_lcs_chars.lead;
2700
zeertzjq2e7cba32022-06-10 15:30:32 +01002701 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002702 c = wp->w_lcs_chars.space;
2703
2704
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 if (!attr_pri)
2706 {
2707 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 extra_attr = hl_combine_attr(wlv.win_attr,
2709 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 }
2712 mb_c = c;
2713 if (enc_utf8 && utf_char2len(c) > 1)
2714 {
2715 mb_utf8 = TRUE;
2716 u8cc[0] = 0;
2717 c = 0xc0;
2718 }
2719 else
2720 mb_utf8 = FALSE;
2721 }
2722 }
2723
2724 // Handling of non-printable characters.
2725 if (!vim_isprintc(c))
2726 {
2727 // when getting a character from the file, we may have to
2728 // turn it into something else on the way to putting it
2729 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002730 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 {
2732 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002733 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002735 char_u *sbr = get_showbreak_value(wp);
2736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 // only adjust the tab_len, when at the first column
2738 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002739 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002740 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741#endif
2742 // tab amount depends on current column
2743#ifdef FEAT_VARTABS
2744 tab_len = tabstop_padding(vcol_adjusted,
2745 wp->w_buffer->b_p_ts,
2746 wp->w_buffer->b_p_vts_array) - 1;
2747#else
2748 tab_len = (int)wp->w_buffer->b_p_ts
2749 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2750#endif
2751
2752#ifdef FEAT_LINEBREAK
2753 if (!wp->w_p_lbr || !wp->w_p_list)
2754#endif
2755 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757#ifdef FEAT_LINEBREAK
2758 else
2759 {
2760 char_u *p;
2761 int len;
2762 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002763 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002765# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002766 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002768 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002769
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002771 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002772 && old_boguscols > 0
2773 && wlv.n_extra > tab_len)
2774 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002775# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002776 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002778 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002779 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002780 if (wp->w_lcs_chars.tab3)
2781 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 if (wlv.n_extra > 0)
2783 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002784 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002786 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002788 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002790 vim_memset(p, ' ', len);
2791 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002792 vim_free(wlv.p_extra_free);
2793 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002794 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002796 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002798 if (*p == NUL)
2799 {
2800 tab_len = i;
2801 break;
2802 }
2803
2804 // if tab3 is given, use it for the last char
2805 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2806 lcs = wp->w_lcs_chars.tab3;
2807 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002808 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002810 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002811 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812# ifdef FEAT_CONCEAL
2813 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2814 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002815 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002817# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002818 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 }
2820#endif
2821#ifdef FEAT_CONCEAL
2822 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002823 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824
2825 // Tab alignment should be identical regardless of
2826 // 'conceallevel' value. So tab compensates of all
2827 // previous concealed characters, and thus resets
2828 // vcol_off and boguscols accumulated so far in the
2829 // line. Note that the tab can be longer than
2830 // 'tabstop' when there are concealed characters.
2831 FIX_FOR_BOGUSCOLS;
2832
2833 // Make sure, the highlighting for the tab char will be
2834 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002835 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002836 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002837 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838 tab_len += vc_saved;
2839 }
2840#endif
2841 mb_utf8 = FALSE; // don't draw as UTF-8
2842 if (wp->w_p_list)
2843 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002844 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002845 ? wp->w_lcs_chars.tab3
2846 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847#ifdef FEAT_LINEBREAK
2848 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002849 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850 else
2851#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002852 wlv.c_extra = wp->w_lcs_chars.tab2;
2853 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002855 extra_attr = hl_combine_attr(wlv.win_attr,
2856 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002857 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 mb_c = c;
2859 if (enc_utf8 && utf_char2len(c) > 1)
2860 {
2861 mb_utf8 = TRUE;
2862 u8cc[0] = 0;
2863 c = 0xc0;
2864 }
2865 }
2866 else
2867 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 wlv.c_final = NUL;
2869 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 c = ' ';
2871 }
2872 }
2873 else if (c == NUL
2874 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002875 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2876 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 && VIsual_mode != Ctrl_V
2878 && (
2879# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002880 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002881# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002882 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 && !(noinvcur
2884 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002885 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 && lcs_eol_one > 0)
2887 {
2888 // Display a '$' after the line or highlight an extra
2889 // character if the line break is included.
2890#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2891 // For a diff line the highlighting continues after the
2892 // "$".
2893 if (
2894# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896# ifdef LINE_ATTR
2897 &&
2898# endif
2899# endif
2900# ifdef LINE_ATTR
2901 line_attr == 0
2902# endif
2903 )
2904#endif
2905 {
2906 // In virtualedit, visual selections may extend
2907 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002908 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002909 && wlv.tocol != MAXCOL
2910 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002911 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002912 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002914 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2915 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 else
2917 c = ' ';
2918 lcs_eol_one = -1;
2919 --ptr; // put it back at the NUL
2920 if (!attr_pri)
2921 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002922 extra_attr = hl_combine_attr(wlv.win_attr,
2923 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924 n_attr = 1;
2925 }
2926 mb_c = c;
2927 if (enc_utf8 && utf_char2len(c) > 1)
2928 {
2929 mb_utf8 = TRUE;
2930 u8cc[0] = 0;
2931 c = 0xc0;
2932 }
2933 else
2934 mb_utf8 = FALSE; // don't draw as UTF-8
2935 }
2936 else if (c != NUL)
2937 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002938 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2939 if (wlv.n_extra == 0)
2940 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941#ifdef FEAT_RIGHTLEFT
2942 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 wlv.c_extra = NUL;
2946 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002947#ifdef FEAT_LINEBREAK
2948 if (wp->w_p_lbr)
2949 {
2950 char_u *p;
2951
Bram Moolenaar1306b362022-08-06 15:59:06 +01002952 c = *wlv.p_extra;
2953 p = alloc(wlv.n_extra + 1);
2954 vim_memset(p, ' ', wlv.n_extra);
2955 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2956 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002957 vim_free(wlv.p_extra_free);
2958 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959 }
2960 else
2961#endif
2962 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.n_extra = byte2cells(c) - 1;
2964 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 }
2966 if (!attr_pri)
2967 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002968 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002969 extra_attr = hl_combine_attr(wlv.win_attr,
2970 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002971 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973 mb_utf8 = FALSE; // don't draw as UTF-8
2974 }
2975 else if (VIsual_active
2976 && (VIsual_mode == Ctrl_V
2977 || VIsual_mode == 'v')
2978 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002979 && wlv.tocol != MAXCOL
2980 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 && (
2982#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002983 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002985 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 {
2987 c = ' ';
2988 --ptr; // put it back at the NUL
2989 }
2990#if defined(LINE_ATTR)
2991 else if ((
2992# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002993 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994# endif
2995# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002996 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997# endif
2998 line_attr != 0
2999 ) && (
3000# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003001 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003003 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003005 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003006# endif
3007 < wp->w_width)))
3008 {
3009 // Highlight until the right side of the window
3010 c = ' ';
3011 --ptr; // put it back at the NUL
3012
3013 // Remember we do the char for line highlighting.
3014 ++did_line_attr;
3015
3016 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003017 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003019 || (wp->w_p_list &&
3020 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 wlv.diff_hlf = HLF_CHD;
3026 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3030 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003031 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003032 || (wlv.vcol >= left_curline_col
3033 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 wlv.char_attr = hl_combine_attr(
3035 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 }
3037 }
3038# endif
3039# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003040 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003043 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3044 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 if (!wlv.cul_screenline
3047 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003048 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 wlv.char_attr = hl_combine_attr(
3050 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 }
3052 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003053 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3054 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 }
3056# endif
3057 }
3058#endif
3059 }
3060
3061#ifdef FEAT_CONCEAL
3062 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003063 && (wp != curwin || lnum != wp->w_cursor.lnum
3064 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3066 && !(lnum_in_visual_area
3067 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3068 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003069 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003070 if (((prev_syntax_id != syntax_seqnr
3071 && (syntax_flags & HL_CONCEAL) != 0)
3072 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003073 && (syn_get_sub_char() != NUL
3074 || (has_match_conc && match_conc)
3075 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 && wp->w_p_cole != 3)
3077 {
3078 // First time at this concealed item: display one
3079 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003080 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 c = match_conc;
3082 else if (syn_get_sub_char() != NUL)
3083 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003084 else if (wp->w_lcs_chars.conceal != NUL)
3085 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 else
3087 c = ' ';
3088
3089 prev_syntax_id = syntax_seqnr;
3090
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 if (wlv.n_extra > 0)
3092 wlv.vcol_off += wlv.n_extra;
3093 wlv.vcol += wlv.n_extra;
3094 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 {
3096# ifdef FEAT_RIGHTLEFT
3097 if (wp->w_p_rl)
3098 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003099 wlv.col -= wlv.n_extra;
3100 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 }
3102 else
3103# endif
3104 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 wlv.boguscols += wlv.n_extra;
3106 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 }
3108 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 n_attr = 0;
3111 }
3112 else if (n_skip == 0)
3113 {
3114 is_concealing = TRUE;
3115 n_skip = 1;
3116 }
3117 mb_c = c;
3118 if (enc_utf8 && utf_char2len(c) > 1)
3119 {
3120 mb_utf8 = TRUE;
3121 u8cc[0] = 0;
3122 c = 0xc0;
3123 }
3124 else
3125 mb_utf8 = FALSE; // don't draw as UTF-8
3126 }
3127 else
3128 {
3129 prev_syntax_id = 0;
3130 is_concealing = FALSE;
3131 }
3132
3133 if (n_skip > 0 && did_decrement_ptr)
3134 // not showing the '>', put pointer back to avoid getting stuck
3135 ++ptr;
3136
3137#endif // FEAT_CONCEAL
3138 }
3139
3140#ifdef FEAT_CONCEAL
3141 // In the cursor line and we may be concealing characters: correct
3142 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 && wp == curwin && lnum == wp->w_cursor.lnum
3145 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003146 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003148# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003150 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003152# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003153 wp->w_wcol = wlv.col - wlv.boguscols;
3154 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 did_wcol = TRUE;
3156 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003157# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003158 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003159# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160 }
3161#endif
3162
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003163 // Use "extra_attr", but don't override visual selection highlighting,
3164 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003165 // Don't use "extra_attr" until n_attr_skip is zero.
3166 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003168 && (!attr_pri
3169#ifdef FEAT_PROP_POPUP
3170 || (text_prop_flags & PT_FLAG_OVERRIDE)
3171#endif
3172 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 {
3174#ifdef LINE_ATTR
3175 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003176 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 else
3178#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003179 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180 }
3181
3182#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3183 // XIM don't send preedit_start and preedit_end, but they send
3184 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3185 // im_is_preediting() here.
3186 if (p_imst == IM_ON_THE_SPOT
3187 && xic != NULL
3188 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003189 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 && !p_imdisable
3191 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003192 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 {
3194 colnr_T tcol;
3195
3196 if (preedit_end_col == MAXCOL)
3197 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3198 else
3199 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003200 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 {
3202 if (feedback_old_attr < 0)
3203 {
3204 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 wlv.char_attr = im_get_feedback_attr(feedback_col);
3208 if (wlv.char_attr < 0)
3209 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 feedback_col++;
3211 }
3212 else if (feedback_old_attr >= 0)
3213 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003214 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215 feedback_old_attr = -1;
3216 feedback_col = 0;
3217 }
3218 }
3219#endif
3220 // Handle the case where we are in column 0 but not on the first
3221 // character of the line and the user wants us to show us a
3222 // special character (via 'listchars' option "precedes:<char>".
3223 if (lcs_prec_todo != NUL
3224 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003225 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003226 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003227 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003229 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 && c != NUL)
3233 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003234 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 lcs_prec_todo = NUL;
3236 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3237 {
3238 // Double-width character being overwritten by the "precedes"
3239 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 wlv.c_extra = MB_FILLER_CHAR;
3241 wlv.c_final = NUL;
3242 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003244 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 }
3246 mb_c = c;
3247 if (enc_utf8 && utf_char2len(c) > 1)
3248 {
3249 mb_utf8 = TRUE;
3250 u8cc[0] = 0;
3251 c = 0xc0;
3252 }
3253 else
3254 mb_utf8 = FALSE; // don't draw as UTF-8
3255 if (!attr_pri)
3256 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 saved_attr3 = wlv.char_attr; // save current attr
3258 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 n_attr3 = 1;
3260 }
3261 }
3262
3263 // At end of the text line or just after the last character.
3264 if ((c == NUL
3265#if defined(LINE_ATTR)
3266 || did_line_attr == 1
3267#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 {
3270#ifdef FEAT_SEARCH_EXTRA
3271 // flag to indicate whether prevcol equals startcol of search_hl or
3272 // one of the matches
3273 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3274 (long)(ptr - line) - (c == NUL));
3275#endif
3276 // Invert at least one char, used for Visual and empty line or
3277 // highlight match at end of line. If it's beyond the last
3278 // char on the screen, just overwrite that one (tricky!) Not
3279 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003280 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003281 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 && (VIsual_mode != Ctrl_V
3283 || lnum == VIsual.lnum
3284 || lnum == curwin->w_cursor.lnum)
3285 && c == NUL)
3286#ifdef FEAT_SEARCH_EXTRA
3287 // highlight 'hlsearch' match at end of line
3288 || (prevcol_hl_flag
3289# ifdef FEAT_SYN_HL
3290 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3291 && !(wp == curwin && VIsual_active))
3292# endif
3293# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003294 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295# endif
3296# if defined(LINE_ATTR)
3297 && did_line_attr <= 1
3298# endif
3299 )
3300#endif
3301 ))
3302 {
3303 int n = 0;
3304
3305#ifdef FEAT_RIGHTLEFT
3306 if (wp->w_p_rl)
3307 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003308 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 n = 1;
3310 }
3311 else
3312#endif
3313 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 n = -1;
3316 }
3317 if (n != 0)
3318 {
3319 // At the window boundary, highlight the last character
3320 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 wlv.off += n;
3322 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 }
3324 else
3325 {
3326 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003327 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003329 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
3331#ifdef FEAT_SEARCH_EXTRA
3332 if (area_attr == 0)
3333 {
3334 // Use attributes from match with highest priority among
3335 // 'search_hl' and the match list.
3336 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
3339#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003340 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342#ifdef FEAT_RIGHTLEFT
3343 if (wp->w_p_rl)
3344 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003345 --wlv.col;
3346 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348 else
3349#endif
3350 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003351 ++wlv.col;
3352 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003354 ++wlv.vcol;
3355 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 }
3357 }
3358
3359 // At end of the text line.
3360 if (c == NUL)
3361 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363
3364 // Update w_cline_height and w_cline_folded if the cursor line was
3365 // updated (saves a call to plines() later).
3366 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3367 {
3368 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003369 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370#ifdef FEAT_FOLDING
3371 curwin->w_cline_folded = FALSE;
3372#endif
3373 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3374 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 break;
3376 }
3377
3378 // Show "extends" character from 'listchars' if beyond the line end and
3379 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003380 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 && wp->w_p_list
3383 && !wp->w_p_wrap
3384#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003385 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386#endif
3387 && (
3388#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003389 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003390#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003393 || lcs_eol_one > 0
3394 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003397 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003398 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 mb_c = c;
3400 if (enc_utf8 && utf_char2len(c) > 1)
3401 {
3402 mb_utf8 = TRUE;
3403 u8cc[0] = 0;
3404 c = 0xc0;
3405 }
3406 else
3407 mb_utf8 = FALSE;
3408 }
3409
3410#ifdef FEAT_SYN_HL
3411 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 if (wlv.draw_color_col)
3413 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414
3415 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3416 // highlight the cursor position itself.
3417 // Also highlight the 'colorcolumn' if it is different than
3418 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003419 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3420 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003422 if (((wlv.draw_state == WL_LINE
3423 || wlv.draw_state == WL_BRI
3424 || wlv.draw_state == WL_SBR)
3425 && !lnum_in_visual_area
3426 && search_attr == 0
3427 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003428# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003429 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003430# endif
3431 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 {
3433 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3434 && lnum != wp->w_cursor.lnum)
3435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 vcol_save_attr = wlv.char_attr;
3437 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3438 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003442 vcol_save_attr = wlv.char_attr;
3443 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 }
3445 }
3446#endif
3447
3448 // Store character to be displayed.
3449 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
3453 // Store the character.
3454#if defined(FEAT_RIGHTLEFT)
3455 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3456 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003457 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 --wlv.off;
3459 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 }
3461#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 if (enc_dbcs == DBCS_JPNU)
3464 {
3465 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 ScreenLines[wlv.off] = 0x8e;
3467 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 }
3469 else if (enc_utf8)
3470 {
3471 if (mb_utf8)
3472 {
3473 int i;
3474
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 for (i = 0; i < Screen_mco; ++i)
3479 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003480 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 if (u8cc[i] == 0)
3482 break;
3483 }
3484 }
3485 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 }
3488 if (multi_attr)
3489 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003490 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 multi_attr = 0;
3492 }
3493 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003497
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3499 {
3500 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ++wlv.off;
3502 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 if (enc_utf8)
3504 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 else
3507 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003509 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003511 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512#endif
3513 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003515 // When "wlv.tocol" is halfway a character, set it to the end
3516 // of the character, otherwise highlighting won't stop.
3517 if (wlv.tocol == wlv.vcol)
3518 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003519
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003520 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003521
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522#ifdef FEAT_RIGHTLEFT
3523 if (wp->w_p_rl)
3524 {
3525 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003526 --wlv.off;
3527 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528 }
3529#endif
3530 }
3531#ifdef FEAT_RIGHTLEFT
3532 if (wp->w_p_rl)
3533 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 --wlv.off;
3535 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003536 }
3537 else
3538#endif
3539 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 ++wlv.off;
3541 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 }
3543 }
3544#ifdef FEAT_CONCEAL
3545 else if (wp->w_p_cole > 0 && is_concealing)
3546 {
3547 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 if (wlv.n_extra > 0)
3550 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 if (wp->w_p_wrap)
3552 {
3553 // Special voodoo required if 'wrap' is on.
3554 //
3555 // Advance the column indicator to force the line
3556 // drawing to wrap early. This will make the line
3557 // take up the same screen space when parts are concealed,
3558 // so that cursor line computations aren't messed up.
3559 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 // trailing junk to be written out of the screen line
3562 // we are building, 'boguscols' keeps track of the number
3563 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003564 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003566 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567# ifdef FEAT_RIGHTLEFT
3568 if (wp->w_p_rl)
3569 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 wlv.col -= wlv.n_extra;
3571 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573 else
3574# endif
3575 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 wlv.col += wlv.n_extra;
3577 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003579 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 n_attr = 0;
3581 }
3582
3583
3584 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3585 {
3586 // Need to fill two screen columns.
3587# ifdef FEAT_RIGHTLEFT
3588 if (wp->w_p_rl)
3589 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 --wlv.boguscols;
3591 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 }
3593 else
3594# endif
3595 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 ++wlv.boguscols;
3597 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 }
3599 }
3600
3601# ifdef FEAT_RIGHTLEFT
3602 if (wp->w_p_rl)
3603 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003604 --wlv.boguscols;
3605 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 }
3607 else
3608# endif
3609 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 ++wlv.boguscols;
3611 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 }
3613 }
3614 else
3615 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003616 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003618 wlv.vcol += wlv.n_extra;
3619 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 n_attr = 0;
3621 }
3622 }
3623
3624 }
3625#endif // FEAT_CONCEAL
3626 else
3627 --n_skip;
3628
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003629 // Only advance the "wlv.vcol" when after the 'number' or
3630 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003633 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634#endif
3635 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637
3638#ifdef FEAT_SYN_HL
3639 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003640 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#endif
3642
3643 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3645 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646
3647 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003648 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003649 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003650 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003651 if (n_attr_skip > 0)
3652 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653
3654 // At end of screen line and there is more to come: Display the line
3655 // so far. If there is no more to display it is caught above.
3656 if ((
3657#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003660 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003661 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003662 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003664 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003666#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003667 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003668#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003669 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 && wlv.p_extra != at_end_str)
3671 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3672 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673 )
3674 {
3675#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003676 screen_line(wp, wlv.screen_row, wp->w_wincol,
3677 wlv.col - wlv.boguscols,
3678 wp->w_width, wlv.screen_line_flags);
3679 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003681 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3682 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 ++wlv.row;
3685 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686
3687 // When not wrapping and finished diff lines, or when displayed
3688 // '$' and highlighting until last column, break here.
3689 if ((!wp->w_p_wrap
3690#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003691 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003692#endif
3693#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003694 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695#endif
3696 ) || lcs_eol_one == -1)
3697 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003698#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003699 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003700 {
3701 // do not output more of the line, only the "below" prop
3702 ptr += STRLEN(ptr);
3703# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003704 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003705# endif
3706 }
3707#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708
3709 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003710 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003712 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003713#endif
3714 )
3715 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3717 draw_vsep_win(wp, wlv.row);
3718 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719 }
3720
3721 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003724 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003725 break;
3726 }
3727
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003730 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003732#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003733 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003734#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 && wp->w_width == Columns)
3736 {
3737 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739
3740 // Special trick to make copy/paste of wrapped lines work with
3741 // xterm/screen: write an extra character beyond the end of
3742 // the line. This will work with all terminal types
3743 // (regardless of the xn,am settings).
3744 // Only do this on a fast tty.
3745 // Only do this if the cursor is on the current line
3746 // (something has been written in it).
3747 // Don't do this for the GUI.
3748 // Don't do this for double-width characters.
3749 // Don't do this for a window not at the right screen border.
3750 if (p_tf
3751#ifdef FEAT_GUI
3752 && !gui.in_use
3753#endif
3754 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003755 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3756 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003758 || (*mb_off2cells)(
3759 LineOffset[wlv.screen_row - 1]
3760 + (int)Columns - 2,
3761 LineOffset[wlv.screen_row]
3762 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 {
3764 // First make sure we are at the end of the screen line,
3765 // then output the same character again to let the
3766 // terminal know about the wrap. If the terminal doesn't
3767 // auto-wrap, we overwrite the character.
3768 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 screen_char(LineOffset[wlv.screen_row - 1]
3770 + (unsigned)Columns - 1,
3771 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772
3773 // When there is a multi-byte character, just output a
3774 // space to keep it simple.
3775 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 out_char(' ');
3778 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 + (Columns - 1)]);
3781 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003782 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783 screen_start(); // don't know where cursor is now
3784 }
3785 }
3786
Bram Moolenaar1306b362022-08-06 15:59:06 +01003787 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788
Bram Moolenaareed9d462021-02-15 20:38:25 +01003789 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003791 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003793 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003795 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003796 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797#endif
3798#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003799 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 // When the filler lines are actually below the last line of the
3801 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003802 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803 break;
3804#endif
3805 }
3806
3807 } // for every character in the line
3808
3809#ifdef FEAT_SPELL
3810 // After an empty line check first word for capital.
3811 if (*skipwhite(line) == NUL)
3812 {
3813 capcol_lnum = lnum + 1;
3814 cap_col = 0;
3815 }
3816#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003817#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 vim_free(text_props);
3819 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003820 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821#endif
3822
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003823 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003824 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825}