blob: c77f88848cd8fb6305e2bacfab8e575753cf04fe [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +0100106
107 int screen_line_flags; // flags for screen_line()
108
109 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
110 int cul_screenline;
111
112 int char_attr; // attributes for the next character
113
114 int n_extra; // number of extra bytes
115 char_u *p_extra; // string of extra chars, plus NUL, only used
116 // when c_extra and c_final are NUL
117 int c_extra; // extra chars, all the same
118 int c_final; // final char, mandatory if set
119
120 // saved "extra" items for when draw_state becomes WL_LINE (again)
121 int saved_n_extra;
122 char_u *saved_p_extra;
123 int saved_c_extra;
124 int saved_c_final;
125 int saved_char_attr;
126
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100127 char_u extra[NUMBUFLEN + MB_MAXBYTES];
128 // "%ld " and 'fdc' must fit in here, as well
129 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100130
Bram Moolenaar1306b362022-08-06 15:59:06 +0100131#ifdef FEAT_DIFF
132 hlf_T diff_hlf; // type of diff highlighting
133#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100134 int filler_lines; // nr of filler lines to be drawn
135 int filler_todo; // nr of filler lines still to do + 1
136#ifdef FEAT_SIGNS
137 sign_attrs_T sattr;
138#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100139} winlinevars_T;
140
141// draw_state values for items that are drawn in sequence:
142#define WL_START 0 // nothing done yet, must be zero
143#ifdef FEAT_CMDWIN
144# define WL_CMDLINE (WL_START + 1) // cmdline window column
145#else
146# define WL_CMDLINE WL_START
147#endif
148#ifdef FEAT_FOLDING
149# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
150#else
151# define WL_FOLD WL_CMDLINE
152#endif
153#ifdef FEAT_SIGNS
154# define WL_SIGN (WL_FOLD + 1) // column for signs
155#else
156# define WL_SIGN WL_FOLD // column for signs
157#endif
158#define WL_NR (WL_SIGN + 1) // line number
159#ifdef FEAT_LINEBREAK
160# define WL_BRI (WL_NR + 1) // 'breakindent'
161#else
162# define WL_BRI WL_NR
163#endif
164#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
165# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
166#else
167# define WL_SBR WL_BRI
168#endif
169#define WL_LINE (WL_SBR + 1) // text in the line
170
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200171#ifdef FEAT_SIGNS
172/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000173 * Return TRUE if CursorLineSign highlight is to be used.
174 */
175 static int
176use_cursor_line_sign(win_T *wp, linenr_T lnum)
177{
178 return wp->w_p_cul
179 && lnum == wp->w_cursor.lnum
180 && (wp->w_p_culopt_flags & CULOPT_NBR);
181}
182
183/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100184 * Get information needed to display the sign in line "wlv->lnum" in window
185 * "wp".
186 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200187 * Otherwise the sign is going to be displayed in the sign column.
188 */
189 static void
190get_sign_display_info(
191 int nrcol,
192 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100193 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200194{
195 int text_sign;
196# ifdef FEAT_SIGN_ICONS
197 int icon_sign;
198# endif
199
200 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100201 wlv->c_extra = ' ';
202 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200203 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100204 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200205 else
206 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100207 if (use_cursor_line_sign(wp, wlv->lnum))
208 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100210 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100211 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 }
213
Bram Moolenaar1306b362022-08-06 15:59:06 +0100214 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200215#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100216 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200217#endif
218 )
219 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100220 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100222 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200223 if (gui.in_use && icon_sign != 0)
224 {
225 // Use the image in this position.
226 if (nrcol)
227 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100228 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100229 sprintf((char *)wlv->extra, "%-*c ",
230 number_width(wp), SIGN_BYTE);
231 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100232 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 }
234 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100237 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
238 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200239 {
240 if (nrcol)
241 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100243 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200244 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100245 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100246 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100249 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200250 }
251# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->c_final = NUL;
253 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 }
255 else
256# endif
257 if (text_sign != 0)
258 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100259 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261 {
262 if (nrcol)
263 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100264 int width = number_width(wp) - 2;
265 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266
267 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100269 vim_snprintf((char *)wlv->extra + n,
270 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100273 wlv->c_extra = NUL;
274 wlv->c_final = NUL;
275 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000277
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 if (use_cursor_line_sign(wp, wlv->lnum)
279 && wlv->sattr.sat_culhl > 0)
280 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000281 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100282 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283 }
284 }
285}
286#endif
287
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288/*
289 * Display the absolute or relative line number. After the first row fill with
290 * blanks when the 'n' flag isn't in 'cpo'.
291 */
292 static void
293handle_lnum_col(
294 win_T *wp,
295 winlinevars_T *wlv,
296 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100297 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100298{
299 if ((wp->w_p_nu || wp->w_p_rnu)
300 && (wlv->row == wlv->startrow + wlv->filler_lines
301 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
302 {
303#ifdef FEAT_SIGNS
304 // If 'signcolumn' is set to 'number' and a sign is present
305 // in 'lnum', then display the sign instead of the line
306 // number.
307 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
308 get_sign_display_info(TRUE, wp, wlv);
309 else
310#endif
311 {
312 // Draw the line number (empty space after wrapping).
313 if (wlv->row == wlv->startrow + wlv->filler_lines)
314 {
315 long num;
316 char *fmt = "%*ld ";
317
318 if (wp->w_p_nu && !wp->w_p_rnu)
319 // 'number' + 'norelativenumber'
320 num = (long)wlv->lnum;
321 else
322 {
323 // 'relativenumber', don't use negative numbers
324 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
325 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
326 {
327 // 'number' + 'relativenumber'
328 num = wlv->lnum;
329 fmt = "%-*ld ";
330 }
331 }
332
333 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
334 if (wp->w_skipcol > 0)
335 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
336 ++wlv->p_extra)
337 *wlv->p_extra = '-';
338#ifdef FEAT_RIGHTLEFT
339 if (wp->w_p_rl) // reverse line numbers
340 {
341 char_u *p1, *p2;
342 int t;
343
344 // like rl_mirror(), but keep the space at the end
345 p2 = skipwhite(wlv->extra);
346 p2 = skiptowhite(p2) - 1;
347 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
348 {
349 t = *p1;
350 *p1 = *p2;
351 *p2 = t;
352 }
353 }
354#endif
355 wlv->p_extra = wlv->extra;
356 wlv->c_extra = NUL;
357 wlv->c_final = NUL;
358 }
359 else
360 {
361 wlv->c_extra = ' ';
362 wlv->c_final = NUL;
363 }
364 wlv->n_extra = number_width(wp) + 1;
365 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
366#ifdef FEAT_SYN_HL
367 // When 'cursorline' is set highlight the line number of
368 // the current line differently.
369 // When 'cursorlineopt' does not have "line" only
370 // highlight the line number itself.
371 // TODO: Can we use CursorLine instead of CursorLineNr
372 // when CursorLineNr isn't set?
373 if (wp->w_p_cul
374 && wlv->lnum == wp->w_cursor.lnum
375 && (wp->w_p_culopt_flags & CULOPT_NBR)
376 && (wlv->row == wlv->startrow + wlv->filler_lines
377 || (wlv->row > wlv->startrow + wlv->filler_lines
378 && (wp->w_p_culopt_flags & CULOPT_LINE))))
379 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
380#endif
381 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
382 && HL_ATTR(HLF_LNA) != 0)
383 // Use LineNrAbove
384 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
385 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
386 && HL_ATTR(HLF_LNB) != 0)
387 // Use LineNrBelow
388 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
389 }
390#ifdef FEAT_SIGNS
391 if (num_attr)
392 wlv->char_attr = num_attr;
393#endif
394 }
395}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100396
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100397#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100398/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100399 * Return the cell size of virtual text after truncation.
400 */
401 static int
402textprop_size_after_trunc(
403 win_T *wp,
404 int flags, // TP_FLAG_ALIGN_*
405 int added,
406 char_u *text,
407 int *n_used_ptr)
408{
409 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
410 ? wp->w_width : added;
411 int len = (int)STRLEN(text);
412 int strsize = 0;
413 int n_used;
414
415 // if the remaining size is to small wrap anyway and use the next line
416 if (space < PROP_TEXT_MIN_CELLS)
417 space += wp->w_width;
418 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
419 {
420 int clen = ptr2cells(text + n_used);
421
422 if (strsize + clen > space)
423 break;
424 strsize += clen;
425 }
426 *n_used_ptr = n_used;
427 return strsize;
428}
429
430/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100431 * Take care of padding, right-align and truncation of virtual text after a
432 * line.
433 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
434 * padding, right-align and truncation. Otherwise only the size is computed.
435 * When "n_attr" is NULL returns the number of screen cells used.
436 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100437 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100438 int
439text_prop_position(
440 win_T *wp,
441 textprop_T *tp,
442 int vcol, // current screen column
443 int *n_extra, // nr of bytes for virtual text
444 char_u **p_extra, // virtual text
445 int *n_attr, // attribute cells, NULL if not used
446 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200447{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100448 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100449 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100450 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
451 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
452 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
453 ? tp->tp_len - 1 : 0;
454 int col_with_padding = vcol + (below ? 0 : padding);
455 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100456 int before = room; // spaces before the text
457 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100458 int n_used = *n_extra;
459 char_u *l = NULL;
460 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100461 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
462 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200463
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100464 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100465 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100466 int col_off = win_col_off(wp) + win_col_off2(wp);
467 int skip_add = 0;
468
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100469 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100470 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100471 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100472 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100473 }
474 else
475 {
476 // Right-align: fill with before
477 if (right)
478 before -= cells;
479 if (before < 0
480 || !(right || below)
481 || (below
482 ? (col_with_padding == 0 || !wp->w_p_wrap)
483 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100484 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100485 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
486 {
487 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100488 before = wp->w_width - col_off - strsize + room;
489 if (before < 0)
490 before = 0;
491 else
492 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100493 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100494 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100495 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100496 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100497 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100498 else if (below && before > 0)
499 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100500 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100501 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100502
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100503 // With 'nowrap' add one to show the "extends" character if needed (it
504 // doesn't show if the text just fits).
505 if (!wp->w_p_wrap
506 && n_used < *n_extra
507 && wp->w_lcs_chars.ext != NUL
508 && wp->w_p_list)
509 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100510 if (!wp->w_p_wrap && below && padding > 0)
511 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100512
513 // add 1 for NUL, 2 for when '…' is used
514 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100515 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100516 if (n_attr == NULL || l != NULL)
517 {
518 int off = 0;
519
520 if (n_attr != NULL)
521 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100522 vim_memset(l, ' ', before);
523 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100524 if (padding > 0)
525 {
526 vim_memset(l + off, ' ', padding);
527 off += padding;
528 }
529 vim_strncpy(l + off, *p_extra, n_used);
530 off += n_used;
531 }
532 else
533 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100534 off = before + after + padding + n_used;
535 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100536 }
537 if (n_attr != NULL)
538 {
539 if (n_used < *n_extra && wp->w_p_wrap)
540 {
541 char_u *lp = l + off - 1;
542
543 if (has_mbyte)
544 {
545 // change last character to '…'
546 lp -= (*mb_head_off)(l, lp);
547 STRCPY(lp, "…");
548 n_used = lp - l + 3 - padding;
549 }
550 else
551 // change last character to '>'
552 *lp = '>';
553 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100554 else if (after > 0)
555 {
556 vim_memset(l + off, ' ', after);
557 l[off + after] = NUL;
558 }
559
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100560 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100561 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100562 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100563 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100564 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100565 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100566 }
567 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100568 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100569
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100570 if (n_attr == NULL)
571 return cells;
572 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573}
574#endif
575
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100576/*
577 * Called when finished with the line: draw the screen line and handle any
578 * highlighting until the right of the window.
579 */
580 static void
581draw_screen_line(win_T *wp, winlinevars_T *wlv)
582{
583#ifdef FEAT_SYN_HL
584 long v;
585
586 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
587 if (wp->w_p_wrap)
588 v = wp->w_skipcol;
589 else
590 v = wp->w_leftcol;
591
592 // check if line ends before left margin
593 if (wlv->vcol < v + wlv->col - win_col_off(wp))
594 wlv->vcol = v + wlv->col - win_col_off(wp);
595# ifdef FEAT_CONCEAL
596 // Get rid of the boguscols now, we want to draw until the right
597 // edge for 'cursorcolumn'.
598 wlv->col -= wlv->boguscols;
599 wlv->boguscols = 0;
600# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
601# else
602# define VCOL_HLC (wlv->vcol)
603# endif
604
605 if (wlv->draw_color_col)
606 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
607
608 if (((wp->w_p_cuc
609 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
610 && (int)wp->w_virtcol <
611 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
612 && wlv->lnum != wp->w_cursor.lnum)
613 || wlv->draw_color_col
614 || wlv->win_attr != 0)
615# ifdef FEAT_RIGHTLEFT
616 && !wp->w_p_rl
617# endif
618 )
619 {
620 int rightmost_vcol = 0;
621 int i;
622
623 if (wp->w_p_cuc)
624 rightmost_vcol = wp->w_virtcol;
625 if (wlv->draw_color_col)
626 // determine rightmost colorcolumn to possibly draw
627 for (i = 0; wlv->color_cols[i] >= 0; ++i)
628 if (rightmost_vcol < wlv->color_cols[i])
629 rightmost_vcol = wlv->color_cols[i];
630
631 while (wlv->col < wp->w_width)
632 {
633 ScreenLines[wlv->off] = ' ';
634 if (enc_utf8)
635 ScreenLinesUC[wlv->off] = 0;
636 ScreenCols[wlv->off] = MAXCOL;
637 ++wlv->col;
638 if (wlv->draw_color_col)
639 wlv->draw_color_col = advance_color_col(
640 VCOL_HLC, &wlv->color_cols);
641
642 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
643 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
644 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
645 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
646 else
647 ScreenAttrs[wlv->off++] = wlv->win_attr;
648
649 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
650 break;
651
652 ++wlv->vcol;
653 }
654 }
655#endif
656
657 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
658 wp->w_width, wlv->screen_line_flags);
659 ++wlv->row;
660 ++wlv->screen_row;
661}
662#undef VCOL_HLC
663
664/*
665 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100666 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100667 */
668 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100669win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100670{
671 wlv->col = 0;
672 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
673
674#ifdef FEAT_RIGHTLEFT
675 if (wp->w_p_rl)
676 {
677 // Rightleft window: process the text in the normal direction, but put
678 // it in current_ScreenLine[] from right to left. Start at the
679 // rightmost column of the window.
680 wlv->col = wp->w_width - 1;
681 wlv->off += wlv->col;
682 wlv->screen_line_flags |= SLF_RIGHTLEFT;
683 }
684#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100685 if (save_extra)
686 {
687 // reset the drawing state for the start of a wrapped line
688 wlv->draw_state = WL_START;
689 wlv->saved_n_extra = wlv->n_extra;
690 wlv->saved_p_extra = wlv->p_extra;
691 wlv->saved_c_extra = wlv->c_extra;
692 wlv->saved_c_final = wlv->c_final;
693#ifdef FEAT_SYN_HL
694 if (!(wlv->cul_screenline
695# ifdef FEAT_DIFF
696 && wlv->diff_hlf == (hlf_T)0
697# endif
698 ))
699 wlv->saved_char_attr = wlv->char_attr;
700 else
701#endif
702 wlv->saved_char_attr = 0;
703 wlv->n_extra = 0;
704 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100705}
706
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200707/*
708 * Display line "lnum" of window 'wp' on the screen.
709 * Start at row "startrow", stop when "endrow" is reached.
710 * wp->w_virtcol needs to be valid.
711 *
712 * Return the number of last row the line occupies.
713 */
714 int
715win_line(
716 win_T *wp,
717 linenr_T lnum,
718 int startrow,
719 int endrow,
720 int nochange UNUSED, // not updating for changed text
721 int number_only) // only update the number column
722{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100723 winlinevars_T wlv; // variables passed between functions
724
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200725 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200726#ifdef FEAT_LINEBREAK
727 long vcol_sbr = -1; // virtual column after showbreak
728#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100729 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730 char_u *line; // current line
731 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200732
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200733 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100734#ifdef FEAT_PROP_POPUP
735 char_u *p_extra_free2 = NULL; // another p_extra to be freed
736#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200737 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000738#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000739 int in_linebreak = FALSE; // n_extra set for showing linebreak
740#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200741 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100742 // displaying eol at end-of-line
743 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000744 int lcs_prec_todo = wp->w_lcs_chars.prec;
745 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200746
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100747 int n_attr = 0; // chars with special attr
748 int n_attr_skip = 0; // chars to skip before using extra_attr
749 int saved_attr2 = 0; // char_attr saved for n_attr
750 int n_attr3 = 0; // chars with overruling special attr
751 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200752
753 int n_skip = 0; // nr of chars to skip for 'nowrap'
754
755 int fromcol = -10; // start of inverting
756 int tocol = MAXCOL; // end of inverting
757 int fromcol_prev = -2; // start of inverting after cursor
758 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200759 int lnum_in_visual_area = FALSE;
760 pos_T pos;
761 long v;
762
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763 int attr_pri = FALSE; // char_attr has priority
764 int area_highlighting = FALSE; // Visual or incsearch highlighting
765 // in this line
766 int vi_attr = 0; // attributes for Visual and incsearch
767 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768 int area_attr = 0; // attributes desired by highlighting
769 int search_attr = 0; // attributes desired by 'hlsearch'
770#ifdef FEAT_SYN_HL
771 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
772 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200773 int prev_syntax_col = -1; // column of prev_syntax_attr
774 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 int has_syntax = FALSE; // this buffer has syntax highl.
776 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100778#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200779 int text_prop_count;
780 int text_prop_next = 0; // next text property to use
781 textprop_T *text_props = NULL;
782 int *text_prop_idxs = NULL;
783 int text_props_active = 0;
784 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100785 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200786 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100787 int text_prop_attr_comb = 0; // text_prop_attr combined with
788 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100789 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100790 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100791 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100792 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100793 int saved_search_attr = 0; // search_attr to be used when n_extra
794 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100795 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200796#endif
797#ifdef FEAT_SPELL
798 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000799 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200800# define SPWORDLEN 150
801 char_u nextline[SPWORDLEN * 2];// text with start of the next line
802 int nextlinecol = 0; // column where nextline[] starts
803 int nextline_idx = 0; // index in nextline[] where next line
804 // starts
805 int spell_attr = 0; // attributes desired by spelling
806 int word_end = 0; // last byte with same spell_attr
807 static linenr_T checked_lnum = 0; // line number for "checked_col"
808 static int checked_col = 0; // column in "checked_lnum" up to which
809 // there are no spell errors
810 static int cap_col = -1; // column to check for Cap word
811 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
812 int cur_checked_col = 0; // checked column for current line
813#endif
814 int extra_check = 0; // has extra highlighting
815 int multi_attr = 0; // attributes desired by multibyte
816 int mb_l = 1; // multi-byte byte length
817 int mb_c = 0; // decoded multi-byte character
818 int mb_utf8 = FALSE; // screen char is UTF-8 char
819 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200820#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200821 int change_start = MAXCOL; // first col of changed area
822 int change_end = -1; // last col of changed area
823#endif
824 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100825 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200826 int in_multispace = FALSE; // in multiple consecutive spaces
827 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828#ifdef FEAT_LINEBREAK
829 int need_showbreak = FALSE; // overlong line, skipping first x
830 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100831 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200832#endif
833#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
834 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
835# define LINE_ATTR
836 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100837 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200838#endif
839#ifdef FEAT_SIGNS
840 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +0000841 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200842#endif
843#ifdef FEAT_ARABIC
844 int prev_c = 0; // previous Arabic character
845 int prev_c1 = 0; // first composing char for prev_c
846#endif
847#if defined(LINE_ATTR)
848 int did_line_attr = 0;
849#endif
850#ifdef FEAT_TERMINAL
851 int get_term_attr = FALSE;
852#endif
853#ifdef FEAT_SYN_HL
854 int cul_attr = 0; // set when 'cursorline' active
855
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200856 // margin columns for the screen line, needed for when 'cursorlineopt'
857 // contains "screenline"
858 int left_curline_col = 0;
859 int right_curline_col = 0;
860#endif
861
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200862#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
863 int feedback_col = 0;
864 int feedback_old_attr = -1;
865#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200866
867#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
868 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000869 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200870#endif
871#ifdef FEAT_CONCEAL
872 int syntax_flags = 0;
873 int syntax_seqnr = 0;
874 int prev_syntax_id = 0;
875 int conceal_attr = HL_ATTR(HLF_CONCEAL);
876 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200877 int did_wcol = FALSE;
878 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100879# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200880# define FIX_FOR_BOGUSCOLS \
881 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100882 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100883 wlv.vcol -= wlv.vcol_off; \
884 wlv.vcol_off = 0; \
885 wlv.col -= wlv.boguscols; \
886 old_boguscols = wlv.boguscols; \
887 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200888 }
889#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200891#endif
892
893 if (startrow > endrow) // past the end already!
894 return startrow;
895
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896 CLEAR_FIELD(wlv);
897
898 wlv.lnum = lnum;
899 wlv.startrow = startrow;
900 wlv.row = startrow;
901 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200902
903 if (!number_only)
904 {
905 // To speed up the loop below, set extra_check when there is linebreak,
906 // trailing white space and/or syntax processing to be done.
907#ifdef FEAT_LINEBREAK
908 extra_check = wp->w_p_lbr;
909#endif
910#ifdef FEAT_SYN_HL
911 if (syntax_present(wp) && !wp->w_s->b_syn_error
912# ifdef SYN_TIME_LIMIT
913 && !wp->w_s->b_syn_slow
914# endif
915 )
916 {
917 // Prepare for syntax highlighting in this line. When there is an
918 // error, stop syntax highlighting.
919 save_did_emsg = did_emsg;
920 did_emsg = FALSE;
921 syntax_start(wp, lnum);
922 if (did_emsg)
923 wp->w_s->b_syn_error = TRUE;
924 else
925 {
926 did_emsg = save_did_emsg;
927#ifdef SYN_TIME_LIMIT
928 if (!wp->w_s->b_syn_slow)
929#endif
930 {
931 has_syntax = TRUE;
932 extra_check = TRUE;
933 }
934 }
935 }
936
937 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100938 wlv.color_cols = wp->w_p_cc_cols;
939 if (wlv.color_cols != NULL)
940 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941#endif
942
943#ifdef FEAT_TERMINAL
944 if (term_show_buffer(wp->w_buffer))
945 {
946 extra_check = TRUE;
947 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949 }
950#endif
951
952#ifdef FEAT_SPELL
953 if (wp->w_p_spell
954 && *wp->w_s->b_p_spl != NUL
955 && wp->w_s->b_langp.ga_len > 0
956 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
957 {
958 // Prepare for spell checking.
959 has_spell = TRUE;
960 extra_check = TRUE;
961
962 // Get the start of the next line, so that words that wrap to the
963 // next line are found too: "et<line-break>al.".
964 // Trick: skip a few chars for C/shell/Vim comments
965 nextline[SPWORDLEN] = NUL;
966 if (lnum < wp->w_buffer->b_ml.ml_line_count)
967 {
968 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
969 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
970 }
971
972 // When a word wrapped from the previous line the start of the
973 // current line is valid.
974 if (lnum == checked_lnum)
975 cur_checked_col = checked_col;
976 checked_lnum = 0;
977
978 // When there was a sentence end in the previous line may require a
979 // word starting with capital in this line. In line 1 always check
980 // the first word.
981 if (lnum != capcol_lnum)
982 cap_col = -1;
983 if (lnum == 1)
984 cap_col = 0;
985 capcol_lnum = 0;
986 }
987#endif
988
989 // handle Visual active in this window
990 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
991 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100992 pos_T *top, *bot;
993
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994 if (LTOREQ_POS(curwin->w_cursor, VIsual))
995 {
996 // Visual is after curwin->w_cursor
997 top = &curwin->w_cursor;
998 bot = &VIsual;
999 }
1000 else
1001 {
1002 // Visual is before curwin->w_cursor
1003 top = &VIsual;
1004 bot = &curwin->w_cursor;
1005 }
1006 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1007 if (VIsual_mode == Ctrl_V)
1008 {
1009 // block mode
1010 if (lnum_in_visual_area)
1011 {
1012 fromcol = wp->w_old_cursor_fcol;
1013 tocol = wp->w_old_cursor_lcol;
1014 }
1015 }
1016 else
1017 {
1018 // non-block mode
1019 if (lnum > top->lnum && lnum <= bot->lnum)
1020 fromcol = 0;
1021 else if (lnum == top->lnum)
1022 {
1023 if (VIsual_mode == 'V') // linewise
1024 fromcol = 0;
1025 else
1026 {
1027 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
1028 if (gchar_pos(top) == NUL)
1029 tocol = fromcol + 1;
1030 }
1031 }
1032 if (VIsual_mode != 'V' && lnum == bot->lnum)
1033 {
1034 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1035 {
1036 fromcol = -10;
1037 tocol = MAXCOL;
1038 }
1039 else if (bot->col == MAXCOL)
1040 tocol = MAXCOL;
1041 else
1042 {
1043 pos = *bot;
1044 if (*p_sel == 'e')
1045 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
1046 else
1047 {
1048 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
1049 ++tocol;
1050 }
1051 }
1052 }
1053 }
1054
1055 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001056 if (!highlight_match && lnum == curwin->w_cursor.lnum
1057 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058#ifdef FEAT_GUI
1059 && !gui.in_use
1060#endif
1061 )
1062 noinvcur = TRUE;
1063
1064 // if inverting in this line set area_highlighting
1065 if (fromcol >= 0)
1066 {
1067 area_highlighting = TRUE;
1068 vi_attr = HL_ATTR(HLF_V);
1069#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1070 if ((clip_star.available && !clip_star.owned
1071 && clip_isautosel_star())
1072 || (clip_plus.available && !clip_plus.owned
1073 && clip_isautosel_plus()))
1074 vi_attr = HL_ATTR(HLF_VNC);
1075#endif
1076 }
1077 }
1078
1079 // handle 'incsearch' and ":s///c" highlighting
1080 else if (highlight_match
1081 && wp == curwin
1082 && lnum >= curwin->w_cursor.lnum
1083 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1084 {
1085 if (lnum == curwin->w_cursor.lnum)
1086 getvcol(curwin, &(curwin->w_cursor),
1087 (colnr_T *)&fromcol, NULL, NULL);
1088 else
1089 fromcol = 0;
1090 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1091 {
1092 pos.lnum = lnum;
1093 pos.col = search_match_endcol;
1094 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
1095 }
1096 else
1097 tocol = MAXCOL;
1098 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +01001099 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100 tocol = fromcol + 1;
1101 area_highlighting = TRUE;
1102 vi_attr = HL_ATTR(HLF_I);
1103 }
1104 }
1105
1106#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001107 wlv.filler_lines = diff_check(wp, lnum);
1108 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001110 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 {
1112 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001113 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001115 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001117 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118 }
1119 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001120 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001121 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122 area_highlighting = TRUE;
1123 }
1124 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001125 wlv.filler_lines = wp->w_topfill;
1126 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127#endif
1128
1129#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001130 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001131 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001132 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133#endif
1134
1135#ifdef LINE_ATTR
1136# ifdef FEAT_SIGNS
1137 // If this line has a sign with line highlighting set line_attr.
1138 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001139 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140# endif
1141# if defined(FEAT_QUICKFIX)
1142 // Highlight the current line in the quickfix window.
1143 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1144 line_attr = HL_ATTR(HLF_QFL);
1145# endif
1146 if (line_attr != 0)
1147 area_highlighting = TRUE;
1148#endif
1149
1150 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1151 ptr = line;
1152
1153#ifdef FEAT_SPELL
1154 if (has_spell && !number_only)
1155 {
1156 // For checking first word with a capital skip white space.
1157 if (cap_col == 0)
1158 cap_col = getwhitecols(line);
1159
1160 // To be able to spell-check over line boundaries copy the end of the
1161 // current line into nextline[]. Above the start of the next line was
1162 // copied to nextline[SPWORDLEN].
1163 if (nextline[SPWORDLEN] == NUL)
1164 {
1165 // No next line or it is empty.
1166 nextlinecol = MAXCOL;
1167 nextline_idx = 0;
1168 }
1169 else
1170 {
1171 v = (long)STRLEN(line);
1172 if (v < SPWORDLEN)
1173 {
1174 // Short line, use it completely and append the start of the
1175 // next line.
1176 nextlinecol = 0;
1177 mch_memmove(nextline, line, (size_t)v);
1178 STRMOVE(nextline + v, nextline + SPWORDLEN);
1179 nextline_idx = v + 1;
1180 }
1181 else
1182 {
1183 // Long line, use only the last SPWORDLEN bytes.
1184 nextlinecol = v - SPWORDLEN;
1185 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1186 nextline_idx = SPWORDLEN + 1;
1187 }
1188 }
1189 }
1190#endif
1191
1192 if (wp->w_p_list)
1193 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001194 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001195 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001196 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001197 || wp->w_lcs_chars.trail
1198 || wp->w_lcs_chars.lead
1199 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001201
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001203 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 {
1205 trailcol = (colnr_T)STRLEN(ptr);
1206 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1207 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001208 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001210 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001211 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001212 {
1213 leadcol = 0;
1214 while (VIM_ISWHITE(ptr[leadcol]))
1215 ++leadcol;
1216 if (ptr[leadcol] == NUL)
1217 // in a line full of spaces all of them are treated as trailing
1218 leadcol = (colnr_T)0;
1219 else
1220 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001221 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001222 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 }
1224
Bram Moolenaard7657e92022-09-20 18:59:30 +01001225 wlv.wcr_attr = get_wcr_attr(wp);
1226 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001228 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229 area_highlighting = TRUE;
1230 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001231
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001232#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001234 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235#endif
1236
1237 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1238 // first character to be displayed.
1239 if (wp->w_p_wrap)
1240 v = wp->w_skipcol;
1241 else
1242 v = wp->w_leftcol;
1243 if (v > 0 && !number_only)
1244 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001245 char_u *prev_ptr = ptr;
1246 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001247 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001249 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001250 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001252 charsize = win_lbr_chartabsize(&cts, NULL);
1253 cts.cts_vcol += charsize;
1254 prev_ptr = cts.cts_ptr;
1255 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001257 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001258 ptr = cts.cts_ptr;
1259 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260
1261 // When:
1262 // - 'cuc' is set, or
1263 // - 'colorcolumn' is set, or
1264 // - 'virtualedit' is set, or
1265 // - the visual mode is active,
1266 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001267 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001269 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270#endif
1271 virtual_active() ||
1272 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001273 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274
1275 // Handle a character that's not completely on the screen: Put ptr at
1276 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001277 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001279 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001280 ptr = prev_ptr;
1281 // If the character fits on the screen, don't need to skip it.
1282 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001283 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1284 && wlv.col == 0)
1285 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287
1288 // Adjust for when the inverted text is before the screen,
1289 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001290 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001292 else if (fromcol >= 0 && fromcol < wlv.vcol)
1293 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294
1295#ifdef FEAT_LINEBREAK
1296 // When w_skipcol is non-zero, first line needs 'showbreak'
1297 if (wp->w_p_wrap)
1298 need_showbreak = TRUE;
1299#endif
1300#ifdef FEAT_SPELL
1301 // When spell checking a word we need to figure out the start of the
1302 // word and if it's badly spelled or not.
1303 if (has_spell)
1304 {
1305 int len;
1306 colnr_T linecol = (colnr_T)(ptr - line);
1307 hlf_T spell_hlf = HLF_COUNT;
1308
1309 pos = wp->w_cursor;
1310 wp->w_cursor.lnum = lnum;
1311 wp->w_cursor.col = linecol;
1312 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1313
1314 // spell_move_to() may call ml_get() and make "line" invalid
1315 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1316 ptr = line + linecol;
1317
1318 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1319 {
1320 // no bad word found at line start, don't check until end of a
1321 // word
1322 spell_hlf = HLF_COUNT;
1323 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1324 }
1325 else
1326 {
1327 // bad word found, use attributes until end of word
1328 word_end = wp->w_cursor.col + len + 1;
1329
1330 // Turn index into actual attributes.
1331 if (spell_hlf != HLF_COUNT)
1332 spell_attr = highlight_attr[spell_hlf];
1333 }
1334 wp->w_cursor = pos;
1335
1336# ifdef FEAT_SYN_HL
1337 // Need to restart syntax highlighting for this line.
1338 if (has_syntax)
1339 syntax_start(wp, lnum);
1340# endif
1341 }
1342#endif
1343 }
1344
1345 // Correct highlighting for cursor that can't be disabled.
1346 // Avoids having to check this for each character.
1347 if (fromcol >= 0)
1348 {
1349 if (noinvcur)
1350 {
1351 if ((colnr_T)fromcol == wp->w_virtcol)
1352 {
1353 // highlighting starts at cursor, let it start just after the
1354 // cursor
1355 fromcol_prev = fromcol;
1356 fromcol = -1;
1357 }
1358 else if ((colnr_T)fromcol < wp->w_virtcol)
1359 // restart highlighting after the cursor
1360 fromcol_prev = wp->w_virtcol;
1361 }
1362 if (fromcol >= tocol)
1363 fromcol = -1;
1364 }
1365
1366#ifdef FEAT_SEARCH_EXTRA
1367 if (!number_only)
1368 {
1369 v = (long)(ptr - line);
1370 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1371 &line, &screen_search_hl,
1372 &search_attr);
1373 ptr = line + v; // "line" may have been updated
1374 }
1375#endif
1376
1377#ifdef FEAT_SYN_HL
1378 // Cursor line highlighting for 'cursorline' in the current window.
1379 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1380 {
1381 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001382 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 if (!(wp == curwin && VIsual_active)
1384 && wp->w_p_culopt_flags != CULOPT_NBR)
1385 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001386 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1388
1389 // Only set line_attr here when "screenline" is not present in
1390 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001391 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 {
1393 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001394# ifdef FEAT_SIGNS
1395 // Combine the 'cursorline' and sign highlighting, depending on
1396 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001397 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001398 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001399 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001400 line_attr = hl_combine_attr(cul_attr, line_attr);
1401 else
1402 line_attr = hl_combine_attr(line_attr, cul_attr);
1403 }
1404 else
1405# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001406# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001407 // let the line attribute overrule 'cursorline', otherwise
1408 // it disappears when both have background set;
1409 // 'cursorline' can use underline or bold to make it show
1410 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001411# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001412 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001413# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 }
1415 else
1416 {
1417 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1419 }
1420 area_highlighting = TRUE;
1421 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 }
1423#endif
1424
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001425#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
1427 char_u *prop_start;
1428
1429 text_prop_count = get_text_props(wp->w_buffer, lnum,
1430 &prop_start, FALSE);
1431 if (text_prop_count > 0)
1432 {
1433 // Make a copy of the properties, so that they are properly
1434 // aligned.
1435 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1436 if (text_props != NULL)
1437 mch_memmove(text_props, prop_start,
1438 text_prop_count * sizeof(textprop_T));
1439
1440 // Allocate an array for the indexes.
1441 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001442 if (text_prop_idxs == NULL)
1443 VIM_CLEAR(text_props);
1444
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 area_highlighting = TRUE;
1446 extra_check = TRUE;
1447 }
1448 }
1449#endif
1450
Bram Moolenaar1306b362022-08-06 15:59:06 +01001451 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452
1453 // Repeat for the whole displayed line.
1454 for (;;)
1455 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001456 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001458 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459#endif
1460#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001461 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001463
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001467#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001468 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001469 {
1470 cul_attr = 0;
1471 line_attr = line_attr_save;
1472 }
1473#endif
1474
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001478 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 if (cmdwin_type != 0 && wp == curwin)
1480 {
1481 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.n_extra = 1;
1483 wlv.c_extra = cmdwin_type;
1484 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001485 wlv.char_attr =
1486 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 }
1488 }
1489#endif
1490
1491#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001492 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 {
1494 int fdc = compute_foldcolumn(wp, 0);
1495
Bram Moolenaar1306b362022-08-06 15:59:06 +01001496 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 if (fdc > 0)
1498 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001499 // Draw the 'foldcolumn'. Allocate a buffer, "wlv.extra"
1500 // may already be in use.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001502 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 if (p_extra_free != NULL)
1504 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001505 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001506 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001507 p_extra_free[wlv.n_extra] = NUL;
1508 wlv.p_extra = p_extra_free;
1509 wlv.c_extra = NUL;
1510 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001511 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001512 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001513 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_CLF));
Bram Moolenaare413ea02021-11-24 16:20:13 +00001514 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001515 wlv.char_attr =
Bram Moolenaard7657e92022-09-20 18:59:30 +01001516 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 }
1518 }
1519 }
1520#endif
1521
1522#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001523 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001525 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001526 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001528 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 }
1530#endif
1531
Bram Moolenaar1306b362022-08-06 15:59:06 +01001532 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001534 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 wlv.draw_state = WL_NR;
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +01001536 handle_lnum_col(wp, &wlv,
1537#ifdef FEAT_SIGNS
1538 sign_present, num_attr
1539#else
1540 0, 0
1541#endif
1542 );
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 }
1544
1545#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001546 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1547 && wlv.n_extra == 0
1548 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001550 wlv.draw_state = WL_BRI;
1551 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1552 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001553 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001554 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001555
1556 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001557 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001559 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001561 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001562# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001563 && wlv.filler_lines == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001565# ifdef FEAT_PROP_POPUP
1566 && !dont_use_showbreak
1567# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 )
1569 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001570 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001572 if (wlv.diff_hlf != (hlf_T)0)
1573 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001575 wlv.p_extra = NULL;
1576 wlv.c_extra = ' ';
1577 wlv.c_final = NUL;
1578 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001580 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001582 wlv.n_extra -= win_col_off2(wp);
1583 if (wlv.n_extra < 0)
1584 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001585 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001586 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001587 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 // Correct end of highlighted area for 'breakindent',
1589 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001590 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001591 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 }
1593 }
1594#endif
1595
1596#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001597 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001599 char_u *sbr;
1600
Bram Moolenaar1306b362022-08-06 15:59:06 +01001601 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001602# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001603 if (wlv.filler_todo > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 {
1605 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001606 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001607 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001608 wlv.c_extra = '-';
1609 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 }
1611 else
1612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001613 wlv.c_extra = wp->w_fill_chars.diff;
1614 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
1616# ifdef FEAT_RIGHTLEFT
1617 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001618 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 else
1620# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001621 wlv.n_extra = wp->w_width - wlv.col;
1622 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 }
1624# endif
1625# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001626 sbr = get_showbreak_value(wp);
1627 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 {
1629 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001630 wlv.p_extra = sbr;
1631 wlv.c_extra = NUL;
1632 wlv.c_final = NUL;
1633 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001634 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1635 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001636 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 // Correct end of highlighted area for 'showbreak',
1638 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001639 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001640 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001642 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1643 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644# ifdef FEAT_SYN_HL
1645 // combine 'showbreak' with 'cursorline'
1646 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001647 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1648 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649# endif
1650 }
1651# endif
1652 }
1653#endif
1654
Bram Moolenaar1306b362022-08-06 15:59:06 +01001655 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001656 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001657 wlv.draw_state = WL_LINE;
1658 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 {
1660 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001661 wlv.n_extra = wlv.saved_n_extra;
1662 wlv.c_extra = wlv.saved_c_extra;
1663 wlv.c_final = wlv.saved_c_final;
1664 wlv.p_extra = wlv.saved_p_extra;
1665 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 }
1667 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 }
1670 }
1671#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001672 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001673 && wlv.vcol >= left_curline_col
1674 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001676 cul_attr = HL_ATTR(HLF_CUL);
1677 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 }
1679#endif
1680
1681 // When still displaying '$' of change command, stop at cursor.
1682 // When only displaying the (relative) line number and that's done,
1683 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001684 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001685 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001688 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689#endif
1690 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001692 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1693 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 // Pretend we have finished updating the window. Except when
1695 // 'cursorcolumn' is set.
1696#ifdef FEAT_SYN_HL
1697 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001698 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 else
1700#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001701 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 break;
1703 }
1704
Bram Moolenaar1306b362022-08-06 15:59:06 +01001705 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 {
1707 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001708 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001709 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 && (*mb_ptr2cells)(ptr) > 1)
1711 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001712 && vcol_prev < wlv.vcol // not at margin
1713 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 area_attr = vi_attr; // start highlighting
1715 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001716 && (wlv.vcol == tocol
1717 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 area_attr = 0; // stop highlighting
1719
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001720#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 if (text_props != NULL)
1722 {
1723 int pi;
1724 int bcol = (int)(ptr - line);
1725
Bram Moolenaar1306b362022-08-06 15:59:06 +01001726 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001727# ifdef FEAT_LINEBREAK
1728 && !in_linebreak
1729# endif
1730 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 --bcol; // still working on the previous char, e.g. Tab
1732
1733 // Check if any active property ends.
1734 for (pi = 0; pi < text_props_active; ++pi)
1735 {
1736 int tpi = text_prop_idxs[pi];
1737
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001738 if (text_props[tpi].tp_col != MAXCOL
1739 && bcol >= text_props[tpi].tp_col - 1
1740 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
1742 if (pi + 1 < text_props_active)
1743 mch_memmove(text_prop_idxs + pi,
1744 text_prop_idxs + pi + 1,
1745 sizeof(int)
1746 * (text_props_active - (pi + 1)));
1747 --text_props_active;
1748 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001749# ifdef FEAT_LINEBREAK
1750 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001751 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001752 syntax_attr = 0;
1753# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
1755 }
1756
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001757# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001759 // not on the next char yet, don't start another prop
1760 --bcol;
1761# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001763 // With 'nowrap' and not in the first screen line only "below"
1764 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001766 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001767 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001768 && (wp->w_p_wrap
1769 || wlv.row == startrow
1770 || (text_props[text_prop_next].tp_flags
1771 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001772 || (bcol == 0 &&
1773 (text_props[text_prop_next].tp_flags
1774 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001775 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001776 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001777 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001778 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1779 {
1780 // first display the '$' after the line
1781 text_prop_follows = TRUE;
1782 break;
1783 }
1784 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001785 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001786 + text_props[text_prop_next].tp_len)
1787 text_prop_idxs[text_props_active++] = text_prop_next;
1788 ++text_prop_next;
1789 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001791 if (wlv.n_extra == 0 || !extra_for_textprop)
1792 {
1793 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001794 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001795 text_prop_flags = 0;
1796 text_prop_type = NULL;
1797 text_prop_id = 0;
1798 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001801 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001802 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001803 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001804
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 // Sort the properties on priority and/or starting last.
1806 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001807 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001808 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001809 sort_text_props(wp->w_buffer, text_props,
1810 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811
1812 for (pi = 0; pi < text_props_active; ++pi)
1813 {
1814 int tpi = text_prop_idxs[pi];
1815 proptype_T *pt = text_prop_type_by_id(
1816 wp->w_buffer, text_props[tpi].tp_type);
1817
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001818 if (pt != NULL && (pt->pt_hl_id > 0
1819 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001820 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001822 if (pt->pt_hl_id > 0)
1823 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 text_prop_type = pt;
1825 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001826 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001827 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001828 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001829 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001830 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 }
1832 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001833 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001834 && -text_prop_id
1835 <= wp->w_buffer->b_textprop_text.ga_len)
1836 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001837 textprop_T *tp = &text_props[used_tpi];
1838 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001839 ->b_textprop_text.ga_data)[
1840 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001841 int above = (tp->tp_flags
1842 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843
1844 // reset the ID in the copy to avoid it being used
1845 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001846 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001848 if (p != NULL)
1849 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001850 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001851 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001852 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001853 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001854 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1855 int padding = tp->tp_col == MAXCOL
1856 && tp->tp_len > 1
1857 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001858
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001859 // Insert virtual text before the current
1860 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001861 wlv.p_extra = p;
1862 wlv.c_extra = NUL;
1863 wlv.c_final = NUL;
1864 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001865 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001866 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001867 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001868 // restore search_attr and area_attr when n_extra
1869 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001870 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001871 saved_area_attr = area_attr;
1872 search_attr = 0;
1873 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001874 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001875 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001876 if (*ptr == NUL)
1877 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001878 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001879#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001880 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001881 {
1882 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001883 // or after "above" or "right" text property
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001884 need_showbreak = FALSE;
1885 dont_use_showbreak = TRUE;
1886 }
1887#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001888 if ((right || above || below || !wrap
1889 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001890 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001891 char_u *prev_p_extra = wlv.p_extra;
1892 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001893
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001894 // Take care of padding, right-align and
1895 // truncation.
1896 // Shared with win_lbr_chartabsize(), must do
1897 // exactly the same.
1898 start_line = text_prop_position(wp, tp,
1899 wlv.col,
1900 &wlv.n_extra, &wlv.p_extra,
1901 &n_attr, &n_attr_skip);
1902 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001903 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001904 // wlv.p_extra was allocated
1905 vim_free(p_extra_free2);
1906 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001907 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001908
Bram Moolenaara4abe512022-09-15 19:44:09 +01001909 if (lcs_eol_one < 0 && wlv.col
1910 + wlv.n_extra - 2 > wp->w_width)
1911 // don't bail out at end of line
1912 lcs_eol_one = 0;
1913
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001914 // When 'wrap' is off then for "below" we need
1915 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001916 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001917 {
1918 draw_screen_line(wp, &wlv);
1919
1920 // When line got too long for screen break
1921 // here.
1922 if (wlv.row == endrow)
1923 {
1924 ++wlv.row;
1925 break;
1926 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927 win_line_start(wp, &wlv, TRUE);
1928 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001929 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001930 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001931 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001932
1933 // If another text prop follows the condition below at
1934 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001935 // If this is an "above" text prop and 'nowrap' the we
1936 // must wrap anyway.
1937 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001938 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001939 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001941 else if (text_prop_next < text_prop_count
1942 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001943 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1944 || (!wp->w_p_wrap
1945 && wlv.col == wp->w_width - 1
1946 && (text_props[text_prop_next].tp_flags
1947 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001948 // When at last-but-one character and a text property
1949 // follows after it, we may need to flush the line after
1950 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001951 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001952 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 }
1954#endif
1955
Bram Moolenaare38fc862022-08-11 17:24:50 +01001956#ifdef FEAT_SEARCH_EXTRA
1957 if (wlv.n_extra == 0)
1958 {
1959 // Check for start/end of 'hlsearch' and other matches.
1960 // After end, check for start/end of next match.
1961 // When another match, have to check for start again.
1962 v = (long)(ptr - line);
1963 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1964 &screen_search_hl, &has_match_conc,
1965 &match_conc, did_line_attr, lcs_eol_one,
1966 &on_last_col);
1967 ptr = line + v; // "line" may have been changed
1968 prev_ptr = ptr;
1969
1970 // Do not allow a conceal over EOL otherwise EOL will be missed
1971 // and bad things happen.
1972 if (*ptr == NUL)
1973 has_match_conc = 0;
1974 }
1975#endif
1976
1977#ifdef FEAT_DIFF
1978 if (wlv.diff_hlf != (hlf_T)0)
1979 {
1980 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1981 && wlv.n_extra == 0)
1982 wlv.diff_hlf = HLF_TXD; // changed text
1983 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1984 && wlv.n_extra == 0)
1985 wlv.diff_hlf = HLF_CHD; // changed line
1986 line_attr = HL_ATTR(wlv.diff_hlf);
1987 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1988 && wp->w_p_culopt_flags != CULOPT_NBR
1989 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1990 && wlv.vcol <= right_curline_col)))
1991 line_attr = hl_combine_attr(
1992 line_attr, HL_ATTR(HLF_CUL));
1993 }
1994#endif
1995
Bram Moolenaara74fda62019-10-19 17:38:03 +02001996#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001997 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001998 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001999 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002000# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002001 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002002 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002003# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002004 // Get syntax attribute.
2005 if (has_syntax)
2006 {
2007 // Get the syntax attribute for the character. If there
2008 // is an error, disable syntax highlighting.
2009 save_did_emsg = did_emsg;
2010 did_emsg = FALSE;
2011
2012 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002013 if (v == prev_syntax_col)
2014 // at same column again
2015 syntax_attr = prev_syntax_attr;
2016 else
2017 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002018# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002019 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002020# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002021 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002022# ifdef FEAT_SPELL
2023 has_spell ? &can_spell :
2024# endif
2025 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002026 prev_syntax_col = v;
2027 prev_syntax_attr = syntax_attr;
2028 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002029
Bram Moolenaar34390282019-10-16 14:38:26 +02002030 if (did_emsg)
2031 {
2032 wp->w_s->b_syn_error = TRUE;
2033 has_syntax = FALSE;
2034 syntax_attr = 0;
2035 }
2036 else
2037 did_emsg = save_did_emsg;
2038# ifdef SYN_TIME_LIMIT
2039 if (wp->w_s->b_syn_slow)
2040 has_syntax = FALSE;
2041# endif
2042
2043 // Need to get the line again, a multi-line regexp may
2044 // have made it invalid.
2045 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2046 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002047 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002048# ifdef FEAT_CONCEAL
2049 // no concealing past the end of the line, it interferes
2050 // with line highlighting
2051 if (*ptr == NUL)
2052 syntax_flags = 0;
2053 else
2054 syntax_flags = get_syntax_info(&syntax_seqnr);
2055# endif
2056 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002057 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002058# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002059 // Combine text property highlight into syntax highlight.
2060 if (text_prop_type != NULL)
2061 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002062 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002063 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2064 else
2065 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002066 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002067 }
2068# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002069#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002070
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 // Decide which of the highlight attributes to use.
2072 attr_pri = TRUE;
2073#ifdef LINE_ATTR
2074 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002075 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002076 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002077 if (!highlight_match)
2078 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002079 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002080# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002081 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002082# endif
2083 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002087# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002088 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002089# endif
2090 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002091 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002092 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2093 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 {
2095 // Use line_attr when not in the Visual or 'incsearch' area
2096 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002097# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002099# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002100 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002101# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002102 attr_pri = FALSE;
2103 }
2104#else
2105 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002106 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002108 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002109#endif
2110 else
2111 {
2112 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002113#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002114 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002115#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002116 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002117#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002119#ifdef FEAT_PROP_POPUP
2120 // override with text property highlight when "override" is TRUE
2121 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002122 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002123#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002124 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002125
2126 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002127 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002128 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002129 if (wlv.char_attr == 0)
2130 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002131 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002132 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002133 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134
2135 // Get the next character to put on the screen.
2136
2137 // The "p_extra" points to the extra stuff that is inserted to
2138 // represent special characters (non-printable stuff) and other
2139 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002140 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002141 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2142 // "p_extra[n_extra]".
2143 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002144 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002148 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2149 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002150 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2151 if (enc_utf8 && utf_char2len(c) > 1)
2152 {
2153 mb_utf8 = TRUE;
2154 u8cc[0] = 0;
2155 c = 0xc0;
2156 }
2157 else
2158 mb_utf8 = FALSE;
2159 }
2160 else
2161 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 if (has_mbyte)
2164 {
2165 mb_c = c;
2166 if (enc_utf8)
2167 {
2168 // If the UTF-8 character is more than one byte:
2169 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002170 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002171 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002172 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002173 mb_l = 1;
2174 else if (mb_l > 1)
2175 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 mb_utf8 = TRUE;
2178 c = 0xc0;
2179 }
2180 }
2181 else
2182 {
2183 // if this is a DBCS character, put it in "mb_c"
2184 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002186 mb_l = 1;
2187 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002188 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 }
2190 if (mb_l == 0) // at the NUL at end-of-line
2191 mb_l = 1;
2192
2193 // If a double-width char doesn't fit display a '>' in the
2194 // last column.
2195 if ((
2196# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002197 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002198# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002199 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 && (*mb_char2cells)(mb_c) == 2)
2201 {
2202 c = '>';
2203 mb_c = c;
2204 mb_l = 1;
2205 mb_utf8 = FALSE;
2206 multi_attr = HL_ATTR(HLF_AT);
2207#ifdef FEAT_SYN_HL
2208 if (cul_attr)
2209 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2210#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002211 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002212
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 // put the pointer back to output the double-width
2214 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 ++wlv.n_extra;
2216 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217 }
2218 else
2219 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002220 wlv.n_extra -= mb_l - 1;
2221 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222 }
2223 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002226 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002227#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002228 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002229 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002230 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002231 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002232 if (search_attr == 0)
2233 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002234 if (area_attr == 0 && *ptr != NUL)
2235 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002236 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002237#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 }
2239 else
2240 {
2241#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002242 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002244 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 // Get a character from the line itself.
2247 c = *ptr;
2248#ifdef FEAT_LINEBREAK
2249 c0 = *ptr;
2250#endif
2251 if (has_mbyte)
2252 {
2253 mb_c = c;
2254 if (enc_utf8)
2255 {
2256 // If the UTF-8 character is more than one byte: Decode it
2257 // into "mb_c".
2258 mb_l = utfc_ptr2len(ptr);
2259 mb_utf8 = FALSE;
2260 if (mb_l > 1)
2261 {
2262 mb_c = utfc_ptr2char(ptr, u8cc);
2263 // Overlong encoded ASCII or ASCII with composing char
2264 // is displayed normally, except a NUL.
2265 if (mb_c < 0x80)
2266 {
2267 c = mb_c;
2268#ifdef FEAT_LINEBREAK
2269 c0 = mb_c;
2270#endif
2271 }
2272 mb_utf8 = TRUE;
2273
2274 // At start of the line we can have a composing char.
2275 // Draw it as a space with a composing char.
2276 if (utf_iscomposing(mb_c))
2277 {
2278 int i;
2279
2280 for (i = Screen_mco - 1; i > 0; --i)
2281 u8cc[i] = u8cc[i - 1];
2282 u8cc[0] = mb_c;
2283 mb_c = ' ';
2284 }
2285 }
2286
2287 if ((mb_l == 1 && c >= 0x80)
2288 || (mb_l >= 1 && mb_c == 0)
2289 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2290 {
2291 // Illegal UTF-8 byte: display as <xx>.
2292 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002293 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294# ifdef FEAT_RIGHTLEFT
2295 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002296 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002297# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002298 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 c = *wlv.p_extra;
2300 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2303 wlv.c_extra = NUL;
2304 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305 if (area_attr == 0 && search_attr == 0)
2306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002308 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002309 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311 }
2312 }
2313 else if (mb_l == 0) // at the NUL at end-of-line
2314 mb_l = 1;
2315#ifdef FEAT_ARABIC
2316 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2317 {
2318 // Do Arabic shaping.
2319 int pc, pc1, nc;
2320 int pcc[MAX_MCO];
2321
2322 // The idea of what is the previous and next
2323 // character depends on 'rightleft'.
2324 if (wp->w_p_rl)
2325 {
2326 pc = prev_c;
2327 pc1 = prev_c1;
2328 nc = utf_ptr2char(ptr + mb_l);
2329 prev_c1 = u8cc[0];
2330 }
2331 else
2332 {
2333 pc = utfc_ptr2char(ptr + mb_l, pcc);
2334 nc = prev_c;
2335 pc1 = pcc[0];
2336 }
2337 prev_c = mb_c;
2338
2339 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2340 }
2341 else
2342 prev_c = mb_c;
2343#endif
2344 }
2345 else // enc_dbcs
2346 {
2347 mb_l = MB_BYTE2LEN(c);
2348 if (mb_l == 0) // at the NUL at end-of-line
2349 mb_l = 1;
2350 else if (mb_l > 1)
2351 {
2352 // We assume a second byte below 32 is illegal.
2353 // Hopefully this is OK for all double-byte encodings!
2354 if (ptr[1] >= 32)
2355 mb_c = (c << 8) + ptr[1];
2356 else
2357 {
2358 if (ptr[1] == NUL)
2359 {
2360 // head byte at end of line
2361 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002362 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 }
2364 else
2365 {
2366 // illegal tail byte
2367 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002368 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002370 wlv.p_extra = wlv.extra;
2371 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 wlv.c_extra = NUL;
2373 wlv.c_final = NUL;
2374 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 if (area_attr == 0 && search_attr == 0)
2376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002378 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002379 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 // save current attr
2381 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 }
2383 mb_c = c;
2384 }
2385 }
2386 }
2387 // If a double-width char doesn't fit display a '>' in the
2388 // last column; the character is displayed at the start of the
2389 // next line.
2390 if ((
2391# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002392 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002394 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 && (*mb_char2cells)(mb_c) == 2)
2396 {
2397 c = '>';
2398 mb_c = c;
2399 mb_utf8 = FALSE;
2400 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002401 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 // Put pointer back so that the character will be
2403 // displayed at the start of the next line.
2404 --ptr;
2405#ifdef FEAT_CONCEAL
2406 did_decrement_ptr = TRUE;
2407#endif
2408 }
2409 else if (*ptr != NUL)
2410 ptr += mb_l - 1;
2411
2412 // If a double-width char doesn't fit at the left side display
2413 // a '<' in the first column. Don't do this for unprintable
2414 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 wlv.n_extra = 1;
2418 wlv.c_extra = MB_FILLER_CHAR;
2419 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 c = ' ';
2421 if (area_attr == 0 && search_attr == 0)
2422 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002424 extra_attr = hl_combine_attr(
2425 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002426 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 }
2428 mb_c = c;
2429 mb_utf8 = FALSE;
2430 mb_l = 1;
2431 }
2432
2433 }
2434 ++ptr;
2435
2436 if (extra_check)
2437 {
2438#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 // Check spelling (unless at the end of the line).
2440 // Only do this when there is no syntax highlighting, the
2441 // @Spell cluster is not used or the current syntax item
2442 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002443 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 if (has_spell && v >= word_end && v > cur_checked_col)
2445 {
2446 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002447 // do not calculate cap_col at the end of the line or when
2448 // only white space is following
2449 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450# ifdef FEAT_SYN_HL
2451 !has_syntax ||
2452# endif
2453 can_spell))
2454 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002455 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002456 int len;
2457 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002458
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461
2462 // Use nextline[] if possible, it has the start of the
2463 // next line concatenated.
2464 if ((prev_ptr - line) - nextlinecol >= 0)
2465 p = nextline + (prev_ptr - line) - nextlinecol;
2466 else
2467 p = prev_ptr;
2468 cap_col -= (int)(prev_ptr - line);
2469 len = spell_check(wp, p, &spell_hlf, &cap_col,
2470 nochange);
2471 word_end = v + len;
2472
2473 // In Insert mode only highlight a word that
2474 // doesn't touch the cursor.
2475 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002476 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 && wp->w_cursor.lnum == lnum
2478 && wp->w_cursor.col >=
2479 (colnr_T)(prev_ptr - line)
2480 && wp->w_cursor.col < (colnr_T)word_end)
2481 {
2482 spell_hlf = HLF_COUNT;
2483 spell_redraw_lnum = lnum;
2484 }
2485
2486 if (spell_hlf == HLF_COUNT && p != prev_ptr
2487 && (p - nextline) + len > nextline_idx)
2488 {
2489 // Remember that the good word continues at the
2490 // start of the next line.
2491 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002492 checked_col = (int)((p - nextline)
2493 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494 }
2495
2496 // Turn index into actual attributes.
2497 if (spell_hlf != HLF_COUNT)
2498 spell_attr = highlight_attr[spell_hlf];
2499
2500 if (cap_col > 0)
2501 {
2502 if (p != prev_ptr
2503 && (p - nextline) + cap_col >= nextline_idx)
2504 {
2505 // Remember that the word in the next line
2506 // must start with a capital.
2507 capcol_lnum = lnum + 1;
2508 cap_col = (int)((p - nextline) + cap_col
2509 - nextline_idx);
2510 }
2511 else
2512 // Compute the actual column.
2513 cap_col += (int)(prev_ptr - line);
2514 }
2515 }
2516 }
2517 if (spell_attr != 0)
2518 {
2519 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002520 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2521 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002523 wlv.char_attr = hl_combine_attr(spell_attr,
2524 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 }
2526#endif
2527#ifdef FEAT_LINEBREAK
2528 // Found last space before word: check for line break.
2529 if (wp->w_p_lbr && c0 == c
2530 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2531 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002532 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2533 : 0;
2534 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002535 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002537 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002538# ifdef FEAT_PROP_POPUP
2539 // do not want virtual text counted here
2540 cts.cts_has_prop_with_text = FALSE;
2541# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002542 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002543 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002544
2545 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002546 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002547 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002548 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2550 if (wlv.n_extra < 0)
2551 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002552 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002553 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002554 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002555 // line break, but for TABs the highlighting should
2556 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002557 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002558
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002562 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563 wp->w_buffer->b_p_vts_array) - 1;
2564# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002565 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002566 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567# endif
2568
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2570 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002571# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002573 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002574# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 if (VIM_ISWHITE(c))
2576 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002577# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 if (c == TAB)
2579 // See "Tab alignment" below.
2580 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002581# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 if (!wp->w_p_list)
2583 c = ' ';
2584 }
2585 }
2586#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002587 in_multispace = c == ' '
2588 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2589 if (!in_multispace)
2590 multispace_pos = 0;
2591
Bram Moolenaareed9d462021-02-15 20:38:25 +01002592 // 'list': Change char 160 to 'nbsp' and space to 'space'
2593 // setting in 'listchars'. But not when the character is
2594 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595 if (wp->w_p_list
2596 && ((((c == 160 && mb_l == 1)
2597 || (mb_utf8
2598 && ((mb_c == 160 && mb_l == 2)
2599 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002600 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 || (c == ' '
2602 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002603 && (wp->w_lcs_chars.space
2604 || (in_multispace
2605 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002606 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607 && ptr - line <= trailcol)))
2608 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002609 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2610 {
2611 c = wp->w_lcs_chars.multispace[multispace_pos++];
2612 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2613 multispace_pos = 0;
2614 }
2615 else
2616 c = (c == ' ') ? wp->w_lcs_chars.space
2617 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 if (area_attr == 0 && search_attr == 0)
2619 {
2620 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002621 extra_attr = hl_combine_attr(wlv.win_attr,
2622 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 }
2625 mb_c = c;
2626 if (enc_utf8 && utf_char2len(c) > 1)
2627 {
2628 mb_utf8 = TRUE;
2629 u8cc[0] = 0;
2630 c = 0xc0;
2631 }
2632 else
2633 mb_utf8 = FALSE;
2634 }
2635
zeertzjq2e7cba32022-06-10 15:30:32 +01002636 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2637 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002639 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2640 && wp->w_lcs_chars.leadmultispace != NULL)
2641 {
2642 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002643 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2644 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002645 multispace_pos = 0;
2646 }
2647
2648 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2649 c = wp->w_lcs_chars.trail;
2650
2651 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2652 c = wp->w_lcs_chars.lead;
2653
zeertzjq2e7cba32022-06-10 15:30:32 +01002654 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002655 c = wp->w_lcs_chars.space;
2656
2657
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658 if (!attr_pri)
2659 {
2660 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002661 extra_attr = hl_combine_attr(wlv.win_attr,
2662 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002663 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 }
2665 mb_c = c;
2666 if (enc_utf8 && utf_char2len(c) > 1)
2667 {
2668 mb_utf8 = TRUE;
2669 u8cc[0] = 0;
2670 c = 0xc0;
2671 }
2672 else
2673 mb_utf8 = FALSE;
2674 }
2675 }
2676
2677 // Handling of non-printable characters.
2678 if (!vim_isprintc(c))
2679 {
2680 // when getting a character from the file, we may have to
2681 // turn it into something else on the way to putting it
2682 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002683 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002684 {
2685 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002686 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002688 char_u *sbr = get_showbreak_value(wp);
2689
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 // only adjust the tab_len, when at the first column
2691 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002692 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2693 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694#endif
2695 // tab amount depends on current column
2696#ifdef FEAT_VARTABS
2697 tab_len = tabstop_padding(vcol_adjusted,
2698 wp->w_buffer->b_p_ts,
2699 wp->w_buffer->b_p_vts_array) - 1;
2700#else
2701 tab_len = (int)wp->w_buffer->b_p_ts
2702 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2703#endif
2704
2705#ifdef FEAT_LINEBREAK
2706 if (!wp->w_p_lbr || !wp->w_p_list)
2707#endif
2708 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002709 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002710#ifdef FEAT_LINEBREAK
2711 else
2712 {
2713 char_u *p;
2714 int len;
2715 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002718# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002719 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002721 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002722
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002724 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002725 && old_boguscols > 0
2726 && wlv.n_extra > tab_len)
2727 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002728# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002731 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002732 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002733 if (wp->w_lcs_chars.tab3)
2734 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002735 if (wlv.n_extra > 0)
2736 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002737 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002739 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002741 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002743 vim_memset(p, ' ', len);
2744 p[len] = NUL;
2745 vim_free(p_extra_free);
2746 p_extra_free = p;
2747 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002749 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002751 if (*p == NUL)
2752 {
2753 tab_len = i;
2754 break;
2755 }
2756
2757 // if tab3 is given, use it for the last char
2758 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2759 lcs = wp->w_lcs_chars.tab3;
2760 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002761 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002762 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002763 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002764 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002765# ifdef FEAT_CONCEAL
2766 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2767 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002768 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002770# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
2773#endif
2774#ifdef FEAT_CONCEAL
2775 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002776 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777
2778 // Tab alignment should be identical regardless of
2779 // 'conceallevel' value. So tab compensates of all
2780 // previous concealed characters, and thus resets
2781 // vcol_off and boguscols accumulated so far in the
2782 // line. Note that the tab can be longer than
2783 // 'tabstop' when there are concealed characters.
2784 FIX_FOR_BOGUSCOLS;
2785
2786 // Make sure, the highlighting for the tab char will be
2787 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002788 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002789 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002790 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 tab_len += vc_saved;
2792 }
2793#endif
2794 mb_utf8 = FALSE; // don't draw as UTF-8
2795 if (wp->w_p_list)
2796 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002797 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002798 ? wp->w_lcs_chars.tab3
2799 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800#ifdef FEAT_LINEBREAK
2801 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002802 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 else
2804#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 wlv.c_extra = wp->w_lcs_chars.tab2;
2806 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 extra_attr = hl_combine_attr(wlv.win_attr,
2809 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002810 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002811 mb_c = c;
2812 if (enc_utf8 && utf_char2len(c) > 1)
2813 {
2814 mb_utf8 = TRUE;
2815 u8cc[0] = 0;
2816 c = 0xc0;
2817 }
2818 }
2819 else
2820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 wlv.c_final = NUL;
2822 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 c = ' ';
2824 }
2825 }
2826 else if (c == NUL
2827 && (wp->w_p_list
2828 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 && VIsual_mode != Ctrl_V
2831 && (
2832# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002835 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 && !(noinvcur
2837 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002838 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002839 && lcs_eol_one > 0)
2840 {
2841 // Display a '$' after the line or highlight an extra
2842 // character if the line break is included.
2843#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2844 // For a diff line the highlighting continues after the
2845 // "$".
2846 if (
2847# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002848 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849# ifdef LINE_ATTR
2850 &&
2851# endif
2852# endif
2853# ifdef LINE_ATTR
2854 line_attr == 0
2855# endif
2856 )
2857#endif
2858 {
2859 // In virtualedit, visual selections may extend
2860 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002861 if (!(area_highlighting && virtual_active()
2862 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002863 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002864 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002866 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2867 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 else
2869 c = ' ';
2870 lcs_eol_one = -1;
2871 --ptr; // put it back at the NUL
2872 if (!attr_pri)
2873 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002874 extra_attr = hl_combine_attr(wlv.win_attr,
2875 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 n_attr = 1;
2877 }
2878 mb_c = c;
2879 if (enc_utf8 && utf_char2len(c) > 1)
2880 {
2881 mb_utf8 = TRUE;
2882 u8cc[0] = 0;
2883 c = 0xc0;
2884 }
2885 else
2886 mb_utf8 = FALSE; // don't draw as UTF-8
2887 }
2888 else if (c != NUL)
2889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2891 if (wlv.n_extra == 0)
2892 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002893#ifdef FEAT_RIGHTLEFT
2894 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.c_extra = NUL;
2898 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899#ifdef FEAT_LINEBREAK
2900 if (wp->w_p_lbr)
2901 {
2902 char_u *p;
2903
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 c = *wlv.p_extra;
2905 p = alloc(wlv.n_extra + 1);
2906 vim_memset(p, ' ', wlv.n_extra);
2907 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2908 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002910 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
2912 else
2913#endif
2914 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002915 wlv.n_extra = byte2cells(c) - 1;
2916 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 }
2918 if (!attr_pri)
2919 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002920 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002921 extra_attr = hl_combine_attr(wlv.win_attr,
2922 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002923 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002924 }
2925 mb_utf8 = FALSE; // don't draw as UTF-8
2926 }
2927 else if (VIsual_active
2928 && (VIsual_mode == Ctrl_V
2929 || VIsual_mode == 'v')
2930 && virtual_active()
2931 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002932 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 && (
2934#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002937 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 {
2939 c = ' ';
2940 --ptr; // put it back at the NUL
2941 }
2942#if defined(LINE_ATTR)
2943 else if ((
2944# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002945 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946# endif
2947# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002948 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949# endif
2950 line_attr != 0
2951 ) && (
2952# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002953 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002955 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002957 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958# endif
2959 < wp->w_width)))
2960 {
2961 // Highlight until the right side of the window
2962 c = ' ';
2963 --ptr; // put it back at the NUL
2964
2965 // Remember we do the char for line highlighting.
2966 ++did_line_attr;
2967
2968 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002971 || (wp->w_p_list &&
2972 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002974# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002977 wlv.diff_hlf = HLF_CHD;
2978 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2982 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002984 || (wlv.vcol >= left_curline_col
2985 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.char_attr = hl_combine_attr(
2987 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 }
2989 }
2990# endif
2991# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002992 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002994 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002995 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2996 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002997 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002998 if (!wlv.cul_screenline
2999 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003001 wlv.char_attr = hl_combine_attr(
3002 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 }
3004 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003005 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3006 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 }
3008# endif
3009 }
3010#endif
3011 }
3012
3013#ifdef FEAT_CONCEAL
3014 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003015 && (wp != curwin || lnum != wp->w_cursor.lnum
3016 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3018 && !(lnum_in_visual_area
3019 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3020 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003022 if (((prev_syntax_id != syntax_seqnr
3023 && (syntax_flags & HL_CONCEAL) != 0)
3024 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003025 && (syn_get_sub_char() != NUL
3026 || (has_match_conc && match_conc)
3027 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 && wp->w_p_cole != 3)
3029 {
3030 // First time at this concealed item: display one
3031 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003032 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 c = match_conc;
3034 else if (syn_get_sub_char() != NUL)
3035 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003036 else if (wp->w_lcs_chars.conceal != NUL)
3037 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003038 else
3039 c = ' ';
3040
3041 prev_syntax_id = syntax_seqnr;
3042
Bram Moolenaar1306b362022-08-06 15:59:06 +01003043 if (wlv.n_extra > 0)
3044 wlv.vcol_off += wlv.n_extra;
3045 wlv.vcol += wlv.n_extra;
3046 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 {
3048# ifdef FEAT_RIGHTLEFT
3049 if (wp->w_p_rl)
3050 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.col -= wlv.n_extra;
3052 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
3054 else
3055# endif
3056 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 wlv.boguscols += wlv.n_extra;
3058 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 }
3060 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003061 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 n_attr = 0;
3063 }
3064 else if (n_skip == 0)
3065 {
3066 is_concealing = TRUE;
3067 n_skip = 1;
3068 }
3069 mb_c = c;
3070 if (enc_utf8 && utf_char2len(c) > 1)
3071 {
3072 mb_utf8 = TRUE;
3073 u8cc[0] = 0;
3074 c = 0xc0;
3075 }
3076 else
3077 mb_utf8 = FALSE; // don't draw as UTF-8
3078 }
3079 else
3080 {
3081 prev_syntax_id = 0;
3082 is_concealing = FALSE;
3083 }
3084
3085 if (n_skip > 0 && did_decrement_ptr)
3086 // not showing the '>', put pointer back to avoid getting stuck
3087 ++ptr;
3088
3089#endif // FEAT_CONCEAL
3090 }
3091
3092#ifdef FEAT_CONCEAL
3093 // In the cursor line and we may be concealing characters: correct
3094 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003095 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 && wp == curwin && lnum == wp->w_cursor.lnum
3097 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003098 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003100# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003102 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003104# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003105 wp->w_wcol = wlv.col - wlv.boguscols;
3106 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 did_wcol = TRUE;
3108 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003109# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003110 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003111# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 }
3113#endif
3114
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003115 // Use "extra_attr", but don't override visual selection highlighting,
3116 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003117 // Don't use "extra_attr" until n_attr_skip is zero.
3118 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003120 && (!attr_pri
3121#ifdef FEAT_PROP_POPUP
3122 || (text_prop_flags & PT_FLAG_OVERRIDE)
3123#endif
3124 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 {
3126#ifdef LINE_ATTR
3127 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003128 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 else
3130#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 }
3133
3134#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3135 // XIM don't send preedit_start and preedit_end, but they send
3136 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3137 // im_is_preediting() here.
3138 if (p_imst == IM_ON_THE_SPOT
3139 && xic != NULL
3140 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003141 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 && !p_imdisable
3143 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 {
3146 colnr_T tcol;
3147
3148 if (preedit_end_col == MAXCOL)
3149 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3150 else
3151 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 {
3154 if (feedback_old_attr < 0)
3155 {
3156 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003157 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 wlv.char_attr = im_get_feedback_attr(feedback_col);
3160 if (wlv.char_attr < 0)
3161 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 feedback_col++;
3163 }
3164 else if (feedback_old_attr >= 0)
3165 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 feedback_old_attr = -1;
3168 feedback_col = 0;
3169 }
3170 }
3171#endif
3172 // Handle the case where we are in column 0 but not on the first
3173 // character of the line and the user wants us to show us a
3174 // special character (via 'listchars' option "precedes:<char>".
3175 if (lcs_prec_todo != NUL
3176 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003177 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003179 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003181 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 && c != NUL)
3185 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003186 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 lcs_prec_todo = NUL;
3188 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3189 {
3190 // Double-width character being overwritten by the "precedes"
3191 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003192 wlv.c_extra = MB_FILLER_CHAR;
3193 wlv.c_final = NUL;
3194 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003196 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 }
3198 mb_c = c;
3199 if (enc_utf8 && utf_char2len(c) > 1)
3200 {
3201 mb_utf8 = TRUE;
3202 u8cc[0] = 0;
3203 c = 0xc0;
3204 }
3205 else
3206 mb_utf8 = FALSE; // don't draw as UTF-8
3207 if (!attr_pri)
3208 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 saved_attr3 = wlv.char_attr; // save current attr
3210 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 n_attr3 = 1;
3212 }
3213 }
3214
3215 // At end of the text line or just after the last character.
3216 if ((c == NUL
3217#if defined(LINE_ATTR)
3218 || did_line_attr == 1
3219#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003220 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 {
3222#ifdef FEAT_SEARCH_EXTRA
3223 // flag to indicate whether prevcol equals startcol of search_hl or
3224 // one of the matches
3225 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3226 (long)(ptr - line) - (c == NUL));
3227#endif
3228 // Invert at least one char, used for Visual and empty line or
3229 // highlight match at end of line. If it's beyond the last
3230 // char on the screen, just overwrite that one (tricky!) Not
3231 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003232 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003233 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 && (VIsual_mode != Ctrl_V
3235 || lnum == VIsual.lnum
3236 || lnum == curwin->w_cursor.lnum)
3237 && c == NUL)
3238#ifdef FEAT_SEARCH_EXTRA
3239 // highlight 'hlsearch' match at end of line
3240 || (prevcol_hl_flag
3241# ifdef FEAT_SYN_HL
3242 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3243 && !(wp == curwin && VIsual_active))
3244# endif
3245# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003246 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247# endif
3248# if defined(LINE_ATTR)
3249 && did_line_attr <= 1
3250# endif
3251 )
3252#endif
3253 ))
3254 {
3255 int n = 0;
3256
3257#ifdef FEAT_RIGHTLEFT
3258 if (wp->w_p_rl)
3259 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003260 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 n = 1;
3262 }
3263 else
3264#endif
3265 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003266 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 n = -1;
3268 }
3269 if (n != 0)
3270 {
3271 // At the window boundary, highlight the last character
3272 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 wlv.off += n;
3274 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 }
3276 else
3277 {
3278 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003279 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 }
3283#ifdef FEAT_SEARCH_EXTRA
3284 if (area_attr == 0)
3285 {
3286 // Use attributes from match with highest priority among
3287 // 'search_hl' and the match list.
3288 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003289 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 }
3291#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003292 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294#ifdef FEAT_RIGHTLEFT
3295 if (wp->w_p_rl)
3296 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 --wlv.col;
3298 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 }
3300 else
3301#endif
3302 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 ++wlv.col;
3304 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 ++wlv.vcol;
3307 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 }
3309 }
3310
3311 // At end of the text line.
3312 if (c == NUL)
3313 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003314 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315
3316 // Update w_cline_height and w_cline_folded if the cursor line was
3317 // updated (saves a call to plines() later).
3318 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3319 {
3320 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322#ifdef FEAT_FOLDING
3323 curwin->w_cline_folded = FALSE;
3324#endif
3325 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3326 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 break;
3328 }
3329
3330 // Show "extends" character from 'listchars' if beyond the line end and
3331 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003332 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 && wp->w_p_list
3335 && !wp->w_p_wrap
3336#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003337 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338#endif
3339 && (
3340#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003341 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003345 || lcs_eol_one > 0
3346 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003347 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003349 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003350 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 mb_c = c;
3352 if (enc_utf8 && utf_char2len(c) > 1)
3353 {
3354 mb_utf8 = TRUE;
3355 u8cc[0] = 0;
3356 c = 0xc0;
3357 }
3358 else
3359 mb_utf8 = FALSE;
3360 }
3361
3362#ifdef FEAT_SYN_HL
3363 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 if (wlv.draw_color_col)
3365 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366
3367 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3368 // highlight the cursor position itself.
3369 // Also highlight the 'colorcolumn' if it is different than
3370 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003371 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3372 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 if (((wlv.draw_state == WL_LINE
3375 || wlv.draw_state == WL_BRI
3376 || wlv.draw_state == WL_SBR)
3377 && !lnum_in_visual_area
3378 && search_attr == 0
3379 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003380# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003381 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003382# endif
3383 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 {
3385 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3386 && lnum != wp->w_cursor.lnum)
3387 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003388 vcol_save_attr = wlv.char_attr;
3389 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3390 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 vcol_save_attr = wlv.char_attr;
3395 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 }
3397 }
3398#endif
3399
3400 // Store character to be displayed.
3401 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003402 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003403 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 {
3405 // Store the character.
3406#if defined(FEAT_RIGHTLEFT)
3407 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3408 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003409 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003410 --wlv.off;
3411 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 }
3413#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 if (enc_dbcs == DBCS_JPNU)
3416 {
3417 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003418 ScreenLines[wlv.off] = 0x8e;
3419 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 }
3421 else if (enc_utf8)
3422 {
3423 if (mb_utf8)
3424 {
3425 int i;
3426
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 for (i = 0; i < Screen_mco; ++i)
3431 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 if (u8cc[i] == 0)
3434 break;
3435 }
3436 }
3437 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003438 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 }
3440 if (multi_attr)
3441 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 multi_attr = 0;
3444 }
3445 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003446 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003449
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3451 {
3452 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003453 ++wlv.off;
3454 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 if (enc_utf8)
3456 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 else
3459 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003461 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003463 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464#endif
3465 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467 // When "tocol" is halfway a character, set it to the end of
3468 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003469 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003471
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003472 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003473
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474#ifdef FEAT_RIGHTLEFT
3475 if (wp->w_p_rl)
3476 {
3477 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003478 --wlv.off;
3479 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 }
3481#endif
3482 }
3483#ifdef FEAT_RIGHTLEFT
3484 if (wp->w_p_rl)
3485 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 --wlv.off;
3487 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 }
3489 else
3490#endif
3491 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 ++wlv.off;
3493 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 }
3495 }
3496#ifdef FEAT_CONCEAL
3497 else if (wp->w_p_cole > 0 && is_concealing)
3498 {
3499 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 if (wlv.n_extra > 0)
3502 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 if (wp->w_p_wrap)
3504 {
3505 // Special voodoo required if 'wrap' is on.
3506 //
3507 // Advance the column indicator to force the line
3508 // drawing to wrap early. This will make the line
3509 // take up the same screen space when parts are concealed,
3510 // so that cursor line computations aren't messed up.
3511 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 // trailing junk to be written out of the screen line
3514 // we are building, 'boguscols' keeps track of the number
3515 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003516 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519# ifdef FEAT_RIGHTLEFT
3520 if (wp->w_p_rl)
3521 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 wlv.col -= wlv.n_extra;
3523 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524 }
3525 else
3526# endif
3527 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003528 wlv.col += wlv.n_extra;
3529 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 n_attr = 0;
3533 }
3534
3535
3536 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3537 {
3538 // Need to fill two screen columns.
3539# ifdef FEAT_RIGHTLEFT
3540 if (wp->w_p_rl)
3541 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 --wlv.boguscols;
3543 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
3545 else
3546# endif
3547 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 ++wlv.boguscols;
3549 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551 }
3552
3553# ifdef FEAT_RIGHTLEFT
3554 if (wp->w_p_rl)
3555 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 --wlv.boguscols;
3557 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 }
3559 else
3560# endif
3561 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 ++wlv.boguscols;
3563 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 }
3565 }
3566 else
3567 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003568 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 wlv.vcol += wlv.n_extra;
3571 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 n_attr = 0;
3573 }
3574 }
3575
3576 }
3577#endif // FEAT_CONCEAL
3578 else
3579 --n_skip;
3580
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 // Only advance the "wlv.vcol" when after the 'number' or
3582 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003583 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003585 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586#endif
3587 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589
3590#ifdef FEAT_SYN_HL
3591 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593#endif
3594
3595 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3597 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598
3599 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003601 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003602 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003603 if (n_attr_skip > 0)
3604 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605
3606 // At end of screen line and there is more to come: Display the line
3607 // so far. If there is no more to display it is caught above.
3608 if ((
3609#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003610 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003613 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003614 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003616 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003618#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003619 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003620#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003621 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003622 && wlv.p_extra != at_end_str)
3623 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3624 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003625 )
3626 {
3627#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 screen_line(wp, wlv.screen_row, wp->w_wincol,
3629 wlv.col - wlv.boguscols,
3630 wp->w_width, wlv.screen_line_flags);
3631 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3634 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003635#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 ++wlv.row;
3637 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638
3639 // When not wrapping and finished diff lines, or when displayed
3640 // '$' and highlighting until last column, break here.
3641 if ((!wp->w_p_wrap
3642#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003643 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003644#endif
3645#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003646 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647#endif
3648 ) || lcs_eol_one == -1)
3649 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003650#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003651 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003652 {
3653 // do not output more of the line, only the "below" prop
3654 ptr += STRLEN(ptr);
3655# ifdef FEAT_LINEBREAK
3656 dont_use_showbreak = TRUE;
3657# endif
3658 }
3659#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660
3661 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 if (wlv.draw_state != WL_LINE
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
3666 )
3667 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3669 draw_vsep_win(wp, wlv.row);
3670 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671 }
3672
3673 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003676 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677 break;
3678 }
3679
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003682 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003684#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003685 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003686#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687 && wp->w_width == Columns)
3688 {
3689 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003690 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691
3692 // Special trick to make copy/paste of wrapped lines work with
3693 // xterm/screen: write an extra character beyond the end of
3694 // the line. This will work with all terminal types
3695 // (regardless of the xn,am settings).
3696 // Only do this on a fast tty.
3697 // Only do this if the cursor is on the current line
3698 // (something has been written in it).
3699 // Don't do this for the GUI.
3700 // Don't do this for double-width characters.
3701 // Don't do this for a window not at the right screen border.
3702 if (p_tf
3703#ifdef FEAT_GUI
3704 && !gui.in_use
3705#endif
3706 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3708 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 || (*mb_off2cells)(
3711 LineOffset[wlv.screen_row - 1]
3712 + (int)Columns - 2,
3713 LineOffset[wlv.screen_row]
3714 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 {
3716 // First make sure we are at the end of the screen line,
3717 // then output the same character again to let the
3718 // terminal know about the wrap. If the terminal doesn't
3719 // auto-wrap, we overwrite the character.
3720 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 screen_char(LineOffset[wlv.screen_row - 1]
3722 + (unsigned)Columns - 1,
3723 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724
3725 // When there is a multi-byte character, just output a
3726 // space to keep it simple.
3727 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 out_char(' ');
3730 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 + (Columns - 1)]);
3733 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003734 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 screen_start(); // don't know where cursor is now
3736 }
3737 }
3738
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740
Bram Moolenaareed9d462021-02-15 20:38:25 +01003741 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003743 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003745 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003747 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 need_showbreak = TRUE;
3749#endif
3750#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003751 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 // When the filler lines are actually below the last line of the
3753 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003754 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 break;
3756#endif
3757 }
3758
3759 } // for every character in the line
3760
3761#ifdef FEAT_SPELL
3762 // After an empty line check first word for capital.
3763 if (*skipwhite(line) == NUL)
3764 {
3765 capcol_lnum = lnum + 1;
3766 cap_col = 0;
3767 }
3768#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003769#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 vim_free(text_props);
3771 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003772 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773#endif
3774
3775 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777}