blob: 3e796d23e2b4731be1d61eab78639e0158dbef65 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 int c_extra; // extra chars, all the same
134 int c_final; // final char, mandatory if set
135
136 // saved "extra" items for when draw_state becomes WL_LINE (again)
137 int saved_n_extra;
138 char_u *saved_p_extra;
139 int saved_c_extra;
140 int saved_c_final;
141 int saved_char_attr;
142
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100143 char_u extra[NUMBUFLEN + MB_MAXBYTES];
144 // "%ld " and 'fdc' must fit in here, as well
145 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100146
Bram Moolenaar1306b362022-08-06 15:59:06 +0100147#ifdef FEAT_DIFF
148 hlf_T diff_hlf; // type of diff highlighting
149#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100150 int filler_lines; // nr of filler lines to be drawn
151 int filler_todo; // nr of filler lines still to do + 1
152#ifdef FEAT_SIGNS
153 sign_attrs_T sattr;
154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155} winlinevars_T;
156
157// draw_state values for items that are drawn in sequence:
158#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100159#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160#ifdef FEAT_FOLDING
161# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
162#else
163# define WL_FOLD WL_CMDLINE
164#endif
165#ifdef FEAT_SIGNS
166# define WL_SIGN (WL_FOLD + 1) // column for signs
167#else
168# define WL_SIGN WL_FOLD // column for signs
169#endif
170#define WL_NR (WL_SIGN + 1) // line number
171#ifdef FEAT_LINEBREAK
172# define WL_BRI (WL_NR + 1) // 'breakindent'
173#else
174# define WL_BRI WL_NR
175#endif
176#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
177# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
178#else
179# define WL_SBR WL_BRI
180#endif
181#define WL_LINE (WL_SBR + 1) // text in the line
182
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100183#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000185 * Return TRUE if CursorLineSign highlight is to be used.
186 */
187 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000189{
190 return wp->w_p_cul
191 && lnum == wp->w_cursor.lnum
192 && (wp->w_p_culopt_flags & CULOPT_NBR);
193}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100194#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000195
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100196
197#ifdef FEAT_FOLDING
198/*
199 * Setup for drawing the 'foldcolumn', if there is one.
200 */
201 static void
202handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
203{
204 int fdc = compute_foldcolumn(wp, 0);
205
206 if (fdc <= 0)
207 return;
208
209 // Allocate a buffer, "wlv->extra[]" may already be in use.
210 vim_free(wlv->p_extra_free);
211 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
212 if (wlv->p_extra_free != NULL)
213 {
214 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
215 wp, FALSE, wlv->lnum);
216 wlv->p_extra_free[wlv->n_extra] = NUL;
217 wlv->p_extra = wlv->p_extra_free;
218 wlv->c_extra = NUL;
219 wlv->c_final = NUL;
220 if (use_cursor_line_highlight(wp, wlv->lnum))
221 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
222 else
223 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
224 }
225}
226#endif
227
228#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000229/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100230 * Get information needed to display the sign in line "wlv->lnum" in window
231 * "wp".
232 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200233 * Otherwise the sign is going to be displayed in the sign column.
234 */
235 static void
236get_sign_display_info(
237 int nrcol,
238 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100239 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240{
241 int text_sign;
242# ifdef FEAT_SIGN_ICONS
243 int icon_sign;
244# endif
245
246 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100247 wlv->c_extra = ' ';
248 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100250 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 else
252 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100253 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100257 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258 }
259
Bram Moolenaar1306b362022-08-06 15:59:06 +0100260 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100262 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263#endif
264 )
265 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100266 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100268 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 if (gui.in_use && icon_sign != 0)
270 {
271 // Use the image in this position.
272 if (nrcol)
273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100275 sprintf((char *)wlv->extra, "%-*c ",
276 number_width(wp), SIGN_BYTE);
277 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279 }
280 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
284 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 {
286 if (nrcol)
287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100288 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100289 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 }
294 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_final = NUL;
299 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 }
301 else
302# endif
303 if (text_sign != 0)
304 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 {
308 if (nrcol)
309 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100310 int width = number_width(wp) - 2;
311 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312
313 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100314 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 vim_snprintf((char *)wlv->extra + n,
316 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100317 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = NUL;
320 wlv->c_final = NUL;
321 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000323
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100324 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100325 && wlv->sattr.sat_culhl > 0)
326 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000327 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100328 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329 }
330 }
331}
332#endif
333
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334/*
335 * Display the absolute or relative line number. After the first row fill with
336 * blanks when the 'n' flag isn't in 'cpo'.
337 */
338 static void
339handle_lnum_col(
340 win_T *wp,
341 winlinevars_T *wlv,
342 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100343 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344{
345 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb6aab8f2022-10-03 20:01:16 +0100346 && ((wlv->row == wlv->startrow + wlv->filler_lines
347 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
348 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349 {
350#ifdef FEAT_SIGNS
351 // If 'signcolumn' is set to 'number' and a sign is present
352 // in 'lnum', then display the sign instead of the line
353 // number.
354 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
355 get_sign_display_info(TRUE, wp, wlv);
356 else
357#endif
358 {
359 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100360 // When there are text properties above the line put the line number
361 // below them.
362 if (wlv->row == wlv->startrow + wlv->filler_lines
363#ifdef FEAT_PROP_POPUP
364 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100365#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100366 )
367 {
368 long num;
369 char *fmt = "%*ld ";
370
371 if (wp->w_p_nu && !wp->w_p_rnu)
372 // 'number' + 'norelativenumber'
373 num = (long)wlv->lnum;
374 else
375 {
376 // 'relativenumber', don't use negative numbers
377 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
378 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
379 {
380 // 'number' + 'relativenumber'
381 num = wlv->lnum;
382 fmt = "%-*ld ";
383 }
384 }
385
386 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100387 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100388 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
389 ++wlv->p_extra)
390 *wlv->p_extra = '-';
391#ifdef FEAT_RIGHTLEFT
392 if (wp->w_p_rl) // reverse line numbers
393 {
394 char_u *p1, *p2;
395 int t;
396
397 // like rl_mirror(), but keep the space at the end
398 p2 = skipwhite(wlv->extra);
399 p2 = skiptowhite(p2) - 1;
400 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
401 {
402 t = *p1;
403 *p1 = *p2;
404 *p2 = t;
405 }
406 }
407#endif
408 wlv->p_extra = wlv->extra;
409 wlv->c_extra = NUL;
410 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100411 }
412 else
413 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100414 wlv->c_extra = ' ';
415 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100416 }
417 wlv->n_extra = number_width(wp) + 1;
418 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
419#ifdef FEAT_SYN_HL
420 // When 'cursorline' is set highlight the line number of
421 // the current line differently.
422 // When 'cursorlineopt' does not have "line" only
423 // highlight the line number itself.
424 // TODO: Can we use CursorLine instead of CursorLineNr
425 // when CursorLineNr isn't set?
426 if (wp->w_p_cul
427 && wlv->lnum == wp->w_cursor.lnum
428 && (wp->w_p_culopt_flags & CULOPT_NBR)
429 && (wlv->row == wlv->startrow + wlv->filler_lines
430 || (wlv->row > wlv->startrow + wlv->filler_lines
431 && (wp->w_p_culopt_flags & CULOPT_LINE))))
432 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
433#endif
434 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
435 && HL_ATTR(HLF_LNA) != 0)
436 // Use LineNrAbove
437 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
438 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
439 && HL_ATTR(HLF_LNB) != 0)
440 // Use LineNrBelow
441 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
442 }
443#ifdef FEAT_SIGNS
444 if (num_attr)
445 wlv->char_attr = num_attr;
446#endif
447 }
448}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100449
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100450#ifdef FEAT_LINEBREAK
451 static void
452handle_breakindent(win_T *wp, winlinevars_T *wlv)
453{
454 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
455 && *get_showbreak_value(wp) != NUL)
456 // draw indent after showbreak value
457 wlv->draw_state = WL_BRI;
458 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
459 // After the showbreak, draw the breakindent
460 wlv->draw_state = WL_BRI - 1;
461
462 // draw 'breakindent': indent wrapped text accordingly
463 if (wlv->draw_state == WL_BRI - 1)
464 {
465 wlv->draw_state = WL_BRI;
466 // if wlv->need_showbreak is set, breakindent also applies
467 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
468# ifdef FEAT_DIFF
469 && wlv->filler_lines == 0
470# endif
471# ifdef FEAT_PROP_POPUP
472 && !wlv->dont_use_showbreak
473# endif
474 )
475 {
476 wlv->char_attr = 0;
477# ifdef FEAT_DIFF
478 if (wlv->diff_hlf != (hlf_T)0)
479 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
480# endif
481 wlv->p_extra = NULL;
482 wlv->c_extra = ' ';
483 wlv->c_final = NUL;
484 wlv->n_extra = get_breakindent_win(wp,
485 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
486 if (wlv->row == wlv->startrow)
487 {
488 wlv->n_extra -= win_col_off2(wp);
489 if (wlv->n_extra < 0)
490 wlv->n_extra = 0;
491 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100492 if (wp->w_skipcol > 0 && wlv->startrow == 0
493 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100494 wlv->need_showbreak = FALSE;
495 // Correct end of highlighted area for 'breakindent',
496 // required when 'linebreak' is also set.
497 if (wlv->tocol == wlv->vcol)
498 wlv->tocol += wlv->n_extra;
499 }
500 }
501}
502#endif
503
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100504#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
505 static void
506handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
507{
508# ifdef FEAT_DIFF
509 if (wlv->filler_todo > 0)
510 {
511 // Draw "deleted" diff line(s).
512 if (char2cells(wp->w_fill_chars.diff) > 1)
513 {
514 wlv->c_extra = '-';
515 wlv->c_final = NUL;
516 }
517 else
518 {
519 wlv->c_extra = wp->w_fill_chars.diff;
520 wlv->c_final = NUL;
521 }
522# ifdef FEAT_RIGHTLEFT
523 if (wp->w_p_rl)
524 wlv->n_extra = wlv->col + 1;
525 else
526# endif
527 wlv->n_extra = wp->w_width - wlv->col;
528 wlv->char_attr = HL_ATTR(HLF_DED);
529 }
530# endif
531
532# ifdef FEAT_LINEBREAK
533 char_u *sbr = get_showbreak_value(wp);
534 if (*sbr != NUL && wlv->need_showbreak)
535 {
536 // Draw 'showbreak' at the start of each broken line.
537 wlv->p_extra = sbr;
538 wlv->c_extra = NUL;
539 wlv->c_final = NUL;
540 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100541 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100542 wlv->need_showbreak = FALSE;
543 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
544 // Correct end of highlighted area for 'showbreak',
545 // required when 'linebreak' is also set.
546 if (wlv->tocol == wlv->vcol)
547 wlv->tocol += wlv->n_extra;
548 // combine 'showbreak' with 'wincolor'
549 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
550# ifdef FEAT_SYN_HL
551 // combine 'showbreak' with 'cursorline'
552 if (wlv->cul_attr != 0)
553 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
554# endif
555 }
556# endif
557}
558#endif
559
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100560#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100561/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100562 * Return the cell size of virtual text after truncation.
563 */
564 static int
565textprop_size_after_trunc(
566 win_T *wp,
567 int flags, // TP_FLAG_ALIGN_*
568 int added,
569 char_u *text,
570 int *n_used_ptr)
571{
572 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
573 ? wp->w_width : added;
574 int len = (int)STRLEN(text);
575 int strsize = 0;
576 int n_used;
577
578 // if the remaining size is to small wrap anyway and use the next line
579 if (space < PROP_TEXT_MIN_CELLS)
580 space += wp->w_width;
581 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
582 {
583 int clen = ptr2cells(text + n_used);
584
585 if (strsize + clen > space)
586 break;
587 strsize += clen;
588 }
589 *n_used_ptr = n_used;
590 return strsize;
591}
592
593/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100594 * Take care of padding, right-align and truncation of virtual text after a
595 * line.
596 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
597 * padding, right-align and truncation. Otherwise only the size is computed.
598 * When "n_attr" is NULL returns the number of screen cells used.
599 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100600 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100601 int
602text_prop_position(
603 win_T *wp,
604 textprop_T *tp,
605 int vcol, // current screen column
606 int *n_extra, // nr of bytes for virtual text
607 char_u **p_extra, // virtual text
608 int *n_attr, // attribute cells, NULL if not used
609 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200610{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100611 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
614 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
615 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
616 ? tp->tp_len - 1 : 0;
617 int col_with_padding = vcol + (below ? 0 : padding);
618 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 int before = room; // spaces before the text
620 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100621 int n_used = *n_extra;
622 char_u *l = NULL;
623 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
625 tp->tp_flags, before, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200626
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100628 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100629 int col_off = win_col_off(wp) + win_col_off2(wp);
630 int skip_add = 0;
631
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100635 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 }
637 else
638 {
639 // Right-align: fill with before
640 if (right)
641 before -= cells;
642 if (before < 0
643 || !(right || below)
644 || (below
645 ? (col_with_padding == 0 || !wp->w_p_wrap)
646 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100648 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
649 {
650 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 before = wp->w_width - col_off - strsize + room;
652 if (before < 0)
653 before = 0;
654 else
655 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100656 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100661 else if (below && before > 0)
662 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100665
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 // With 'nowrap' add one to show the "extends" character if needed (it
667 // doesn't show if the text just fits).
668 if (!wp->w_p_wrap
669 && n_used < *n_extra
670 && wp->w_lcs_chars.ext != NUL
671 && wp->w_p_list)
672 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100673 if (!wp->w_p_wrap && below && padding > 0)
674 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675
676 // add 1 for NUL, 2 for when '…' is used
677 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100678 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 if (n_attr == NULL || l != NULL)
680 {
681 int off = 0;
682
683 if (n_attr != NULL)
684 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 vim_memset(l, ' ', before);
686 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 if (padding > 0)
688 {
689 vim_memset(l + off, ' ', padding);
690 off += padding;
691 }
692 vim_strncpy(l + off, *p_extra, n_used);
693 off += n_used;
694 }
695 else
696 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100697 off = before + after + padding + n_used;
698 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100699 }
700 if (n_attr != NULL)
701 {
702 if (n_used < *n_extra && wp->w_p_wrap)
703 {
704 char_u *lp = l + off - 1;
705
706 if (has_mbyte)
707 {
708 // change last character to '…'
709 lp -= (*mb_head_off)(l, lp);
710 STRCPY(lp, "…");
711 n_used = lp - l + 3 - padding;
712 }
713 else
714 // change last character to '>'
715 *lp = '>';
716 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 else if (after > 0)
718 {
719 vim_memset(l + off, ' ', after);
720 l[off + after] = NUL;
721 }
722
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100723 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100724 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100726 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100727 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100728 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100729 }
730 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100731 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100732
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 if (n_attr == NULL)
734 return cells;
735 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200736}
737#endif
738
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100739/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100740 * Call screen_line() using values from "wlv".
741 * Also takes care of putting "<<<" on the first line for 'smoothscroll'.
742 */
743 static void
744wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
745{
746 if (wlv->row == 0 && wp->w_skipcol > 0)
747 {
748 int off = (int)(current_ScreenLine - ScreenLines);
749
750 for (int i = 0; i < 3; ++i)
751 {
752 ScreenLines[off] = '<';
753 if (enc_utf8)
754 ScreenLinesUC[off] = 0;
755 ScreenAttrs[off] = HL_ATTR(HLF_AT);
756 ++off;
757 }
758 }
759
760 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
761 negative_width ? -wp->w_width : wp->w_width,
762 wlv->screen_line_flags);
763}
764
765/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100766 * Called when finished with the line: draw the screen line and handle any
767 * highlighting until the right of the window.
768 */
769 static void
770draw_screen_line(win_T *wp, winlinevars_T *wlv)
771{
772#ifdef FEAT_SYN_HL
773 long v;
774
775 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
776 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100777 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100778 else
779 v = wp->w_leftcol;
780
781 // check if line ends before left margin
782 if (wlv->vcol < v + wlv->col - win_col_off(wp))
783 wlv->vcol = v + wlv->col - win_col_off(wp);
784# ifdef FEAT_CONCEAL
785 // Get rid of the boguscols now, we want to draw until the right
786 // edge for 'cursorcolumn'.
787 wlv->col -= wlv->boguscols;
788 wlv->boguscols = 0;
789# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
790# else
791# define VCOL_HLC (wlv->vcol)
792# endif
793
794 if (wlv->draw_color_col)
795 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
796
797 if (((wp->w_p_cuc
798 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
799 && (int)wp->w_virtcol <
800 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
801 && wlv->lnum != wp->w_cursor.lnum)
802 || wlv->draw_color_col
803 || wlv->win_attr != 0)
804# ifdef FEAT_RIGHTLEFT
805 && !wp->w_p_rl
806# endif
807 )
808 {
809 int rightmost_vcol = 0;
810 int i;
811
812 if (wp->w_p_cuc)
813 rightmost_vcol = wp->w_virtcol;
814 if (wlv->draw_color_col)
815 // determine rightmost colorcolumn to possibly draw
816 for (i = 0; wlv->color_cols[i] >= 0; ++i)
817 if (rightmost_vcol < wlv->color_cols[i])
818 rightmost_vcol = wlv->color_cols[i];
819
820 while (wlv->col < wp->w_width)
821 {
822 ScreenLines[wlv->off] = ' ';
823 if (enc_utf8)
824 ScreenLinesUC[wlv->off] = 0;
825 ScreenCols[wlv->off] = MAXCOL;
826 ++wlv->col;
827 if (wlv->draw_color_col)
828 wlv->draw_color_col = advance_color_col(
829 VCOL_HLC, &wlv->color_cols);
830
831 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
832 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
833 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
834 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
835 else
836 ScreenAttrs[wlv->off++] = wlv->win_attr;
837
838 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
839 break;
840
841 ++wlv->vcol;
842 }
843 }
844#endif
845
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100846 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100847 ++wlv->row;
848 ++wlv->screen_row;
849}
850#undef VCOL_HLC
851
852/*
853 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100854 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100855 */
856 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100857win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100858{
859 wlv->col = 0;
860 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
861
862#ifdef FEAT_RIGHTLEFT
863 if (wp->w_p_rl)
864 {
865 // Rightleft window: process the text in the normal direction, but put
866 // it in current_ScreenLine[] from right to left. Start at the
867 // rightmost column of the window.
868 wlv->col = wp->w_width - 1;
869 wlv->off += wlv->col;
870 wlv->screen_line_flags |= SLF_RIGHTLEFT;
871 }
872#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100873 if (save_extra)
874 {
875 // reset the drawing state for the start of a wrapped line
876 wlv->draw_state = WL_START;
877 wlv->saved_n_extra = wlv->n_extra;
878 wlv->saved_p_extra = wlv->p_extra;
879 wlv->saved_c_extra = wlv->c_extra;
880 wlv->saved_c_final = wlv->c_final;
881#ifdef FEAT_SYN_HL
882 if (!(wlv->cul_screenline
883# ifdef FEAT_DIFF
884 && wlv->diff_hlf == (hlf_T)0
885# endif
886 ))
887 wlv->saved_char_attr = wlv->char_attr;
888 else
889#endif
890 wlv->saved_char_attr = 0;
891 wlv->n_extra = 0;
892 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893}
894
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200895/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100896 * Called when wlv->draw_state is set to WL_LINE.
897 */
898 static void
899win_line_continue(winlinevars_T *wlv)
900{
901 if (wlv->saved_n_extra > 0)
902 {
903 // Continue item from end of wrapped line.
904 wlv->n_extra = wlv->saved_n_extra;
905 wlv->c_extra = wlv->saved_c_extra;
906 wlv->c_final = wlv->saved_c_final;
907 wlv->p_extra = wlv->saved_p_extra;
908 wlv->char_attr = wlv->saved_char_attr;
909 }
910 else
911 wlv->char_attr = wlv->win_attr;
912}
913
914/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200915 * Display line "lnum" of window 'wp' on the screen.
916 * Start at row "startrow", stop when "endrow" is reached.
917 * wp->w_virtcol needs to be valid.
918 *
919 * Return the number of last row the line occupies.
920 */
921 int
922win_line(
923 win_T *wp,
924 linenr_T lnum,
925 int startrow,
926 int endrow,
927 int nochange UNUSED, // not updating for changed text
928 int number_only) // only update the number column
929{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100930 winlinevars_T wlv; // variables passed between functions
931
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200932 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100933 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200934 char_u *line; // current line
935 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200936
Bram Moolenaar1306b362022-08-06 15:59:06 +0100937#ifdef FEAT_PROP_POPUP
938 char_u *p_extra_free2 = NULL; // another p_extra to be freed
939#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200940 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000941#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000942 int in_linebreak = FALSE; // n_extra set for showing linebreak
943#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200944 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100945 // displaying eol at end-of-line
946 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000947 int lcs_prec_todo = wp->w_lcs_chars.prec;
948 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100950 int n_attr = 0; // chars with special attr
951 int n_attr_skip = 0; // chars to skip before using extra_attr
952 int saved_attr2 = 0; // char_attr saved for n_attr
953 int n_attr3 = 0; // chars with overruling special attr
954 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955
956 int n_skip = 0; // nr of chars to skip for 'nowrap'
957
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958 int fromcol_prev = -2; // start of inverting after cursor
959 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200960 int lnum_in_visual_area = FALSE;
961 pos_T pos;
962 long v;
963
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int attr_pri = FALSE; // char_attr has priority
965 int area_highlighting = FALSE; // Visual or incsearch highlighting
966 // in this line
967 int vi_attr = 0; // attributes for Visual and incsearch
968 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969 int area_attr = 0; // attributes desired by highlighting
970 int search_attr = 0; // attributes desired by 'hlsearch'
971#ifdef FEAT_SYN_HL
972 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
973 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200974 int prev_syntax_col = -1; // column of prev_syntax_attr
975 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 int has_syntax = FALSE; // this buffer has syntax highl.
977 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200978#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100979#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int text_prop_count;
981 int text_prop_next = 0; // next text property to use
982 textprop_T *text_props = NULL;
983 int *text_prop_idxs = NULL;
984 int text_props_active = 0;
985 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100986 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200987 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +0100988 int text_prop_attr_comb = 0; // text_prop_attr combined with
989 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100990 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100991 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +0100992 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100993 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100994 int saved_search_attr = 0; // search_attr to be used when n_extra
995 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +0100996 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997#endif
998#ifdef FEAT_SPELL
999 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001000 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001# define SPWORDLEN 150
1002 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1003 int nextlinecol = 0; // column where nextline[] starts
1004 int nextline_idx = 0; // index in nextline[] where next line
1005 // starts
1006 int spell_attr = 0; // attributes desired by spelling
1007 int word_end = 0; // last byte with same spell_attr
1008 static linenr_T checked_lnum = 0; // line number for "checked_col"
1009 static int checked_col = 0; // column in "checked_lnum" up to which
1010 // there are no spell errors
1011 static int cap_col = -1; // column to check for Cap word
1012 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1013 int cur_checked_col = 0; // checked column for current line
1014#endif
1015 int extra_check = 0; // has extra highlighting
1016 int multi_attr = 0; // attributes desired by multibyte
1017 int mb_l = 1; // multi-byte byte length
1018 int mb_c = 0; // decoded multi-byte character
1019 int mb_utf8 = FALSE; // screen char is UTF-8 char
1020 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022 int change_start = MAXCOL; // first col of changed area
1023 int change_end = -1; // last col of changed area
1024#endif
1025 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001026 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001027 int in_multispace = FALSE; // in multiple consecutive spaces
1028 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1030 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1031# define LINE_ATTR
1032 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001033 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001034#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001036 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037#ifdef FEAT_ARABIC
1038 int prev_c = 0; // previous Arabic character
1039 int prev_c1 = 0; // first composing char for prev_c
1040#endif
1041#if defined(LINE_ATTR)
1042 int did_line_attr = 0;
1043#endif
1044#ifdef FEAT_TERMINAL
1045 int get_term_attr = FALSE;
1046#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001048#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049 // margin columns for the screen line, needed for when 'cursorlineopt'
1050 // contains "screenline"
1051 int left_curline_col = 0;
1052 int right_curline_col = 0;
1053#endif
1054
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1056 int feedback_col = 0;
1057 int feedback_old_attr = -1;
1058#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059
1060#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1061 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001062 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063#endif
1064#ifdef FEAT_CONCEAL
1065 int syntax_flags = 0;
1066 int syntax_seqnr = 0;
1067 int prev_syntax_id = 0;
1068 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1069 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070 int did_wcol = FALSE;
1071 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001072# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073# define FIX_FOR_BOGUSCOLS \
1074 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001075 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001076 wlv.vcol -= wlv.vcol_off; \
1077 wlv.vcol_off = 0; \
1078 wlv.col -= wlv.boguscols; \
1079 old_boguscols = wlv.boguscols; \
1080 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081 }
1082#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001083# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084#endif
1085
1086 if (startrow > endrow) // past the end already!
1087 return startrow;
1088
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001089 CLEAR_FIELD(wlv);
1090
1091 wlv.lnum = lnum;
1092 wlv.startrow = startrow;
1093 wlv.row = startrow;
1094 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001095 wlv.fromcol = -10;
1096 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001097#ifdef FEAT_LINEBREAK
1098 wlv.vcol_sbr = -1;
1099#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100
1101 if (!number_only)
1102 {
1103 // To speed up the loop below, set extra_check when there is linebreak,
1104 // trailing white space and/or syntax processing to be done.
1105#ifdef FEAT_LINEBREAK
1106 extra_check = wp->w_p_lbr;
1107#endif
1108#ifdef FEAT_SYN_HL
1109 if (syntax_present(wp) && !wp->w_s->b_syn_error
1110# ifdef SYN_TIME_LIMIT
1111 && !wp->w_s->b_syn_slow
1112# endif
1113 )
1114 {
1115 // Prepare for syntax highlighting in this line. When there is an
1116 // error, stop syntax highlighting.
1117 save_did_emsg = did_emsg;
1118 did_emsg = FALSE;
1119 syntax_start(wp, lnum);
1120 if (did_emsg)
1121 wp->w_s->b_syn_error = TRUE;
1122 else
1123 {
1124 did_emsg = save_did_emsg;
1125#ifdef SYN_TIME_LIMIT
1126 if (!wp->w_s->b_syn_slow)
1127#endif
1128 {
1129 has_syntax = TRUE;
1130 extra_check = TRUE;
1131 }
1132 }
1133 }
1134
1135 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001136 wlv.color_cols = wp->w_p_cc_cols;
1137 if (wlv.color_cols != NULL)
1138 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139#endif
1140
1141#ifdef FEAT_TERMINAL
1142 if (term_show_buffer(wp->w_buffer))
1143 {
1144 extra_check = TRUE;
1145 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001146 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 }
1148#endif
1149
1150#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001151 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001152 {
1153 // Prepare for spell checking.
1154 has_spell = TRUE;
1155 extra_check = TRUE;
1156
1157 // Get the start of the next line, so that words that wrap to the
1158 // next line are found too: "et<line-break>al.".
1159 // Trick: skip a few chars for C/shell/Vim comments
1160 nextline[SPWORDLEN] = NUL;
1161 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1162 {
1163 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1164 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1165 }
1166
1167 // When a word wrapped from the previous line the start of the
1168 // current line is valid.
1169 if (lnum == checked_lnum)
1170 cur_checked_col = checked_col;
1171 checked_lnum = 0;
1172
1173 // When there was a sentence end in the previous line may require a
1174 // word starting with capital in this line. In line 1 always check
1175 // the first word.
1176 if (lnum != capcol_lnum)
1177 cap_col = -1;
1178 if (lnum == 1)
1179 cap_col = 0;
1180 capcol_lnum = 0;
1181 }
1182#endif
1183
1184 // handle Visual active in this window
1185 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1186 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001187 pos_T *top, *bot;
1188
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1190 {
1191 // Visual is after curwin->w_cursor
1192 top = &curwin->w_cursor;
1193 bot = &VIsual;
1194 }
1195 else
1196 {
1197 // Visual is before curwin->w_cursor
1198 top = &VIsual;
1199 bot = &curwin->w_cursor;
1200 }
1201 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1202 if (VIsual_mode == Ctrl_V)
1203 {
1204 // block mode
1205 if (lnum_in_visual_area)
1206 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001207 wlv.fromcol = wp->w_old_cursor_fcol;
1208 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001209 }
1210 }
1211 else
1212 {
1213 // non-block mode
1214 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001215 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 else if (lnum == top->lnum)
1217 {
1218 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001219 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 else
1221 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001222 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001224 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 }
1226 }
1227 if (VIsual_mode != 'V' && lnum == bot->lnum)
1228 {
1229 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1230 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001231 wlv.fromcol = -10;
1232 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233 }
1234 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001235 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 else
1237 {
1238 pos = *bot;
1239 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001240 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1241 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242 else
1243 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001244 getvvcol(wp, &pos, NULL, NULL,
1245 (colnr_T *)&wlv.tocol);
1246 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 }
1248 }
1249 }
1250 }
1251
1252 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001253 if (!highlight_match && lnum == curwin->w_cursor.lnum
1254 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255#ifdef FEAT_GUI
1256 && !gui.in_use
1257#endif
1258 )
1259 noinvcur = TRUE;
1260
1261 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 {
1264 area_highlighting = TRUE;
1265 vi_attr = HL_ATTR(HLF_V);
1266#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1267 if ((clip_star.available && !clip_star.owned
1268 && clip_isautosel_star())
1269 || (clip_plus.available && !clip_plus.owned
1270 && clip_isautosel_plus()))
1271 vi_attr = HL_ATTR(HLF_VNC);
1272#endif
1273 }
1274 }
1275
1276 // handle 'incsearch' and ":s///c" highlighting
1277 else if (highlight_match
1278 && wp == curwin
1279 && lnum >= curwin->w_cursor.lnum
1280 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1281 {
1282 if (lnum == curwin->w_cursor.lnum)
1283 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001284 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001286 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1288 {
1289 pos.lnum = lnum;
1290 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001291 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 }
1293 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001294 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1297 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 area_highlighting = TRUE;
1299 vi_attr = HL_ATTR(HLF_I);
1300 }
1301 }
1302
1303#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001304 wlv.filler_lines = diff_check(wp, lnum);
1305 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001307 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 {
1309 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001310 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001312 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001314 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001315 }
1316 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001317 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001318 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 area_highlighting = TRUE;
1320 }
1321 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001322 wlv.filler_lines = wp->w_topfill;
1323 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324#endif
1325
1326#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001327 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001328 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001329 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330#endif
1331
1332#ifdef LINE_ATTR
1333# ifdef FEAT_SIGNS
1334 // If this line has a sign with line highlighting set line_attr.
1335 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001336 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337# endif
1338# if defined(FEAT_QUICKFIX)
1339 // Highlight the current line in the quickfix window.
1340 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1341 line_attr = HL_ATTR(HLF_QFL);
1342# endif
1343 if (line_attr != 0)
1344 area_highlighting = TRUE;
1345#endif
1346
1347 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1348 ptr = line;
1349
1350#ifdef FEAT_SPELL
1351 if (has_spell && !number_only)
1352 {
1353 // For checking first word with a capital skip white space.
1354 if (cap_col == 0)
1355 cap_col = getwhitecols(line);
1356
1357 // To be able to spell-check over line boundaries copy the end of the
1358 // current line into nextline[]. Above the start of the next line was
1359 // copied to nextline[SPWORDLEN].
1360 if (nextline[SPWORDLEN] == NUL)
1361 {
1362 // No next line or it is empty.
1363 nextlinecol = MAXCOL;
1364 nextline_idx = 0;
1365 }
1366 else
1367 {
1368 v = (long)STRLEN(line);
1369 if (v < SPWORDLEN)
1370 {
1371 // Short line, use it completely and append the start of the
1372 // next line.
1373 nextlinecol = 0;
1374 mch_memmove(nextline, line, (size_t)v);
1375 STRMOVE(nextline + v, nextline + SPWORDLEN);
1376 nextline_idx = v + 1;
1377 }
1378 else
1379 {
1380 // Long line, use only the last SPWORDLEN bytes.
1381 nextlinecol = v - SPWORDLEN;
1382 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1383 nextline_idx = SPWORDLEN + 1;
1384 }
1385 }
1386 }
1387#endif
1388
1389 if (wp->w_p_list)
1390 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001391 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001392 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001393 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001394 || wp->w_lcs_chars.trail
1395 || wp->w_lcs_chars.lead
1396 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001398
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001400 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 {
1402 trailcol = (colnr_T)STRLEN(ptr);
1403 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1404 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001405 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001407 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001408 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001409 {
1410 leadcol = 0;
1411 while (VIM_ISWHITE(ptr[leadcol]))
1412 ++leadcol;
1413 if (ptr[leadcol] == NUL)
1414 // in a line full of spaces all of them are treated as trailing
1415 leadcol = (colnr_T)0;
1416 else
1417 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001418 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001419 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 }
1421
Bram Moolenaard7657e92022-09-20 18:59:30 +01001422 wlv.wcr_attr = get_wcr_attr(wp);
1423 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001425 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 area_highlighting = TRUE;
1427 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001428
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001429#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001431 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432#endif
1433
1434 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1435 // first character to be displayed.
1436 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001437 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 else
1439 v = wp->w_leftcol;
1440 if (v > 0 && !number_only)
1441 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001442 char_u *prev_ptr = ptr;
1443 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001444 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001446 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001447 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001449 charsize = win_lbr_chartabsize(&cts, NULL);
1450 cts.cts_vcol += charsize;
1451 prev_ptr = cts.cts_ptr;
1452 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001454 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001455 ptr = cts.cts_ptr;
1456 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457
1458 // When:
1459 // - 'cuc' is set, or
1460 // - 'colorcolumn' is set, or
1461 // - 'virtualedit' is set, or
1462 // - the visual mode is active,
1463 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001464 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001466 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467#endif
1468 virtual_active() ||
1469 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001470 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471
1472 // Handle a character that's not completely on the screen: Put ptr at
1473 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001474 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001476 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 ptr = prev_ptr;
1478 // If the character fits on the screen, don't need to skip it.
1479 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001480 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1481 && wlv.col == 0)
1482 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
1484
1485 // Adjust for when the inverted text is before the screen,
1486 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001487 if (wlv.tocol <= wlv.vcol)
1488 wlv.fromcol = 0;
1489 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1490 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491
1492#ifdef FEAT_LINEBREAK
1493 // When w_skipcol is non-zero, first line needs 'showbreak'
1494 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001495 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496#endif
1497#ifdef FEAT_SPELL
1498 // When spell checking a word we need to figure out the start of the
1499 // word and if it's badly spelled or not.
1500 if (has_spell)
1501 {
1502 int len;
1503 colnr_T linecol = (colnr_T)(ptr - line);
1504 hlf_T spell_hlf = HLF_COUNT;
1505
1506 pos = wp->w_cursor;
1507 wp->w_cursor.lnum = lnum;
1508 wp->w_cursor.col = linecol;
1509 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1510
1511 // spell_move_to() may call ml_get() and make "line" invalid
1512 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1513 ptr = line + linecol;
1514
1515 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1516 {
1517 // no bad word found at line start, don't check until end of a
1518 // word
1519 spell_hlf = HLF_COUNT;
1520 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1521 }
1522 else
1523 {
1524 // bad word found, use attributes until end of word
1525 word_end = wp->w_cursor.col + len + 1;
1526
1527 // Turn index into actual attributes.
1528 if (spell_hlf != HLF_COUNT)
1529 spell_attr = highlight_attr[spell_hlf];
1530 }
1531 wp->w_cursor = pos;
1532
1533# ifdef FEAT_SYN_HL
1534 // Need to restart syntax highlighting for this line.
1535 if (has_syntax)
1536 syntax_start(wp, lnum);
1537# endif
1538 }
1539#endif
1540 }
1541
1542 // Correct highlighting for cursor that can't be disabled.
1543 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001544 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 {
1546 if (noinvcur)
1547 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001548 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
1550 // highlighting starts at cursor, let it start just after the
1551 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001552 fromcol_prev = wlv.fromcol;
1553 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001555 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 // restart highlighting after the cursor
1557 fromcol_prev = wp->w_virtcol;
1558 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001559 if (wlv.fromcol >= wlv.tocol)
1560 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 }
1562
1563#ifdef FEAT_SEARCH_EXTRA
1564 if (!number_only)
1565 {
1566 v = (long)(ptr - line);
1567 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1568 &line, &screen_search_hl,
1569 &search_attr);
1570 ptr = line + v; // "line" may have been updated
1571 }
1572#endif
1573
1574#ifdef FEAT_SYN_HL
1575 // Cursor line highlighting for 'cursorline' in the current window.
1576 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1577 {
1578 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001579 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 if (!(wp == curwin && VIsual_active)
1581 && wp->w_p_culopt_flags != CULOPT_NBR)
1582 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1585
1586 // Only set line_attr here when "screenline" is not present in
1587 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001588 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001589 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001590 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001591# ifdef FEAT_SIGNS
1592 // Combine the 'cursorline' and sign highlighting, depending on
1593 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001594 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001595 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001596 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001597 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001598 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001599 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001600 }
1601 else
1602# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001603# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001604 // let the line attribute overrule 'cursorline', otherwise
1605 // it disappears when both have background set;
1606 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001607 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001608# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001609 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001610# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001611 }
1612 else
1613 {
1614 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1616 }
1617 area_highlighting = TRUE;
1618 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 }
1620#endif
1621
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001622#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 {
1624 char_u *prop_start;
1625
1626 text_prop_count = get_text_props(wp->w_buffer, lnum,
1627 &prop_start, FALSE);
1628 if (text_prop_count > 0)
1629 {
1630 // Make a copy of the properties, so that they are properly
1631 // aligned.
1632 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1633 if (text_props != NULL)
1634 mch_memmove(text_props, prop_start,
1635 text_prop_count * sizeof(textprop_T));
1636
1637 // Allocate an array for the indexes.
1638 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001639 if (text_prop_idxs == NULL)
1640 VIM_CLEAR(text_props);
1641
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001642 if (text_props != NULL)
1643 {
1644 area_highlighting = TRUE;
1645 extra_check = TRUE;
1646 for (int i = 0; i < text_prop_count; ++i)
1647 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1648 ++wlv.text_prop_above_count;
1649 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
1651 }
1652#endif
1653
Bram Moolenaar1306b362022-08-06 15:59:06 +01001654 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655
1656 // Repeat for the whole displayed line.
1657 for (;;)
1658 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001659 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001661 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662#endif
1663#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001664 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001666
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001670#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001671 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001672 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001673 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001674 line_attr = line_attr_save;
1675 }
1676#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001677 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001679 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 if (cmdwin_type != 0 && wp == curwin)
1681 {
1682 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 wlv.n_extra = 1;
1684 wlv.c_extra = cmdwin_type;
1685 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001686 wlv.char_attr =
1687 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688 }
1689 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001691 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001693 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001694 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 }
1696#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001700 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001701 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001702 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001703 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 }
1705#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001708 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001709 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001710 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001713 // Check if 'breakindent' applies and show it.
1714 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1715 if (wlv.n_extra == 0)
1716 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001719 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001721 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001722 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 }
1724#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001725 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001727 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001728 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 }
1730 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001731
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001734 && wlv.vcol >= left_curline_col
1735 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001737 wlv.cul_attr = HL_ATTR(HLF_CUL);
1738 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 }
1740#endif
1741
1742 // When still displaying '$' of change command, stop at cursor.
1743 // When only displaying the (relative) line number and that's done,
1744 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001745 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001746 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001747 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001749 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750#endif
1751 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001753 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 // Pretend we have finished updating the window. Except when
1755 // 'cursorcolumn' is set.
1756#ifdef FEAT_SYN_HL
1757 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001758 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 else
1760#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001761 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 break;
1763 }
1764
Bram Moolenaar1306b362022-08-06 15:59:06 +01001765 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 {
1767 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001768 if (wlv.vcol == wlv.fromcol
1769 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1770 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 && (*mb_ptr2cells)(ptr) > 1)
1772 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001773 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001774 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 area_attr = vi_attr; // start highlighting
1776 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001777 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001778 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 area_attr = 0; // stop highlighting
1780
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001781#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 if (text_props != NULL)
1783 {
1784 int pi;
1785 int bcol = (int)(ptr - line);
1786
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001788# ifdef FEAT_LINEBREAK
1789 && !in_linebreak
1790# endif
1791 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 --bcol; // still working on the previous char, e.g. Tab
1793
1794 // Check if any active property ends.
1795 for (pi = 0; pi < text_props_active; ++pi)
1796 {
1797 int tpi = text_prop_idxs[pi];
1798
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001799 if (text_props[tpi].tp_col != MAXCOL
1800 && bcol >= text_props[tpi].tp_col - 1
1801 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 {
1803 if (pi + 1 < text_props_active)
1804 mch_memmove(text_prop_idxs + pi,
1805 text_prop_idxs + pi + 1,
1806 sizeof(int)
1807 * (text_props_active - (pi + 1)));
1808 --text_props_active;
1809 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001810# ifdef FEAT_LINEBREAK
1811 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001812 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001813 syntax_attr = 0;
1814# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 }
1816 }
1817
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001818# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001820 // not on the next char yet, don't start another prop
1821 --bcol;
1822# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001824 // With 'nowrap' and not in the first screen line only "below"
1825 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001827 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001828 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001829 && (wp->w_p_wrap
1830 || wlv.row == startrow
1831 || (text_props[text_prop_next].tp_flags
1832 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001833 || (bcol == 0 &&
1834 (text_props[text_prop_next].tp_flags
1835 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001836 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001837 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001838 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001839 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1840 {
1841 // first display the '$' after the line
1842 text_prop_follows = TRUE;
1843 break;
1844 }
1845 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001846 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001847 + text_props[text_prop_next].tp_len)
1848 text_prop_idxs[text_props_active++] = text_prop_next;
1849 ++text_prop_next;
1850 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001852 if (wlv.n_extra == 0 || !extra_for_textprop)
1853 {
1854 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001855 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001856 text_prop_flags = 0;
1857 text_prop_type = NULL;
1858 text_prop_id = 0;
1859 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001860 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001862 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001863 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001864 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001865
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 // Sort the properties on priority and/or starting last.
1867 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001868 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001869 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001870 sort_text_props(wp->w_buffer, text_props,
1871 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872
1873 for (pi = 0; pi < text_props_active; ++pi)
1874 {
1875 int tpi = text_prop_idxs[pi];
1876 proptype_T *pt = text_prop_type_by_id(
1877 wp->w_buffer, text_props[tpi].tp_type);
1878
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001879 if (pt != NULL && (pt->pt_hl_id > 0
1880 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001881 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001883 if (pt->pt_hl_id > 0)
1884 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 text_prop_type = pt;
1886 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001887 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001888 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001889 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001890 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001891 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 }
1893 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001894 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001895 && -text_prop_id
1896 <= wp->w_buffer->b_textprop_text.ga_len)
1897 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001898 textprop_T *tp = &text_props[used_tpi];
1899 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001900 ->b_textprop_text.ga_data)[
1901 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001902 int above = (tp->tp_flags
1903 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904
1905 // reset the ID in the copy to avoid it being used
1906 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001907 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001909 if (p != NULL)
1910 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001911 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001912 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001913 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001914 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001915 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1916 int padding = tp->tp_col == MAXCOL
1917 && tp->tp_len > 1
1918 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 // Insert virtual text before the current
1921 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001922 wlv.p_extra = p;
1923 wlv.c_extra = NUL;
1924 wlv.c_final = NUL;
1925 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001926 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001927 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001928 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001929 // restore search_attr and area_attr when n_extra
1930 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001931 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001932 saved_area_attr = area_attr;
1933 search_attr = 0;
1934 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001935 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001936 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001937 if (*ptr == NUL)
1938 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001939 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001940#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001941 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001942 {
1943 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001944 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001945 wlv.need_showbreak = FALSE;
1946 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001947 }
1948#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001949 if ((right || above || below || !wrap
1950 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001951 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001952 char_u *prev_p_extra = wlv.p_extra;
1953 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001954
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001955 // Take care of padding, right-align and
1956 // truncation.
1957 // Shared with win_lbr_chartabsize(), must do
1958 // exactly the same.
1959 start_line = text_prop_position(wp, tp,
1960 wlv.col,
1961 &wlv.n_extra, &wlv.p_extra,
1962 &n_attr, &n_attr_skip);
1963 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001964 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001965 // wlv.p_extra was allocated
1966 vim_free(p_extra_free2);
1967 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001968 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001969
Bram Moolenaara4abe512022-09-15 19:44:09 +01001970 if (lcs_eol_one < 0 && wlv.col
1971 + wlv.n_extra - 2 > wp->w_width)
1972 // don't bail out at end of line
1973 lcs_eol_one = 0;
1974
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001975 // When 'wrap' is off then for "below" we need
1976 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001977 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001978 {
1979 draw_screen_line(wp, &wlv);
1980
1981 // When line got too long for screen break
1982 // here.
1983 if (wlv.row == endrow)
1984 {
1985 ++wlv.row;
1986 break;
1987 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001988 win_line_start(wp, &wlv, TRUE);
1989 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001990 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001991 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001992 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001993
1994 // If another text prop follows the condition below at
1995 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001996 // If this is an "above" text prop and 'nowrap' the we
1997 // must wrap anyway.
1998 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001999 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002000 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002002 else if (text_prop_next < text_prop_count
2003 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002004 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2005 || (!wp->w_p_wrap
2006 && wlv.col == wp->w_width - 1
2007 && (text_props[text_prop_next].tp_flags
2008 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002009 // When at last-but-one character and a text property
2010 // follows after it, we may need to flush the line after
2011 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002012 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002013 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 }
2015#endif
2016
Bram Moolenaare38fc862022-08-11 17:24:50 +01002017#ifdef FEAT_SEARCH_EXTRA
2018 if (wlv.n_extra == 0)
2019 {
2020 // Check for start/end of 'hlsearch' and other matches.
2021 // After end, check for start/end of next match.
2022 // When another match, have to check for start again.
2023 v = (long)(ptr - line);
2024 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2025 &screen_search_hl, &has_match_conc,
2026 &match_conc, did_line_attr, lcs_eol_one,
2027 &on_last_col);
2028 ptr = line + v; // "line" may have been changed
2029 prev_ptr = ptr;
2030
2031 // Do not allow a conceal over EOL otherwise EOL will be missed
2032 // and bad things happen.
2033 if (*ptr == NUL)
2034 has_match_conc = 0;
2035 }
2036#endif
2037
2038#ifdef FEAT_DIFF
2039 if (wlv.diff_hlf != (hlf_T)0)
2040 {
2041 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2042 && wlv.n_extra == 0)
2043 wlv.diff_hlf = HLF_TXD; // changed text
2044 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2045 && wlv.n_extra == 0)
2046 wlv.diff_hlf = HLF_CHD; // changed line
2047 line_attr = HL_ATTR(wlv.diff_hlf);
2048 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2049 && wp->w_p_culopt_flags != CULOPT_NBR
2050 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2051 && wlv.vcol <= right_curline_col)))
2052 line_attr = hl_combine_attr(
2053 line_attr, HL_ATTR(HLF_CUL));
2054 }
2055#endif
2056
Bram Moolenaara74fda62019-10-19 17:38:03 +02002057#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002059 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002060 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002061# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002062 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002063 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002064# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002065 // Get syntax attribute.
2066 if (has_syntax)
2067 {
2068 // Get the syntax attribute for the character. If there
2069 // is an error, disable syntax highlighting.
2070 save_did_emsg = did_emsg;
2071 did_emsg = FALSE;
2072
2073 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002074 if (v == prev_syntax_col)
2075 // at same column again
2076 syntax_attr = prev_syntax_attr;
2077 else
2078 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002079# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002080 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002081# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002082 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002083# ifdef FEAT_SPELL
2084 has_spell ? &can_spell :
2085# endif
2086 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002087 prev_syntax_col = v;
2088 prev_syntax_attr = syntax_attr;
2089 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002090
Bram Moolenaar34390282019-10-16 14:38:26 +02002091 if (did_emsg)
2092 {
2093 wp->w_s->b_syn_error = TRUE;
2094 has_syntax = FALSE;
2095 syntax_attr = 0;
2096 }
2097 else
2098 did_emsg = save_did_emsg;
2099# ifdef SYN_TIME_LIMIT
2100 if (wp->w_s->b_syn_slow)
2101 has_syntax = FALSE;
2102# endif
2103
2104 // Need to get the line again, a multi-line regexp may
2105 // have made it invalid.
2106 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2107 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002108 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002109# ifdef FEAT_CONCEAL
2110 // no concealing past the end of the line, it interferes
2111 // with line highlighting
2112 if (*ptr == NUL)
2113 syntax_flags = 0;
2114 else
2115 syntax_flags = get_syntax_info(&syntax_seqnr);
2116# endif
2117 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002118 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002119# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002120 // Combine text property highlight into syntax highlight.
2121 if (text_prop_type != NULL)
2122 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002123 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002124 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2125 else
2126 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002127 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002128 }
2129# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002130#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002131
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 // Decide which of the highlight attributes to use.
2133 attr_pri = TRUE;
2134#ifdef LINE_ATTR
2135 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002136 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002137 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002138 if (!highlight_match)
2139 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002140 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002141# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002142 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002143# endif
2144 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002146 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002147 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002148# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002149 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002150# endif
2151 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002152 else if (line_attr != 0
2153 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2154 || wlv.vcol < wlv.fromcol
2155 || vcol_prev < fromcol_prev
2156 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 {
2158 // Use line_attr when not in the Visual or 'incsearch' area
2159 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002160# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002161 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002162# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002163 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002164# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 attr_pri = FALSE;
2166 }
2167#else
2168 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002169 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002171 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172#endif
2173 else
2174 {
2175 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002177 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002178#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002179 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002180#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002182#ifdef FEAT_PROP_POPUP
2183 // override with text property highlight when "override" is TRUE
2184 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002186#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002188
2189 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002190 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002191 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 if (wlv.char_attr == 0)
2193 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002194 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002195 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002196 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002197
2198 // Get the next character to put on the screen.
2199
2200 // The "p_extra" points to the extra stuff that is inserted to
2201 // represent special characters (non-printable stuff) and other
2202 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002203 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2205 // "p_extra[n_extra]".
2206 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002207 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002209 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002210 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002211 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2212 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2214 if (enc_utf8 && utf_char2len(c) > 1)
2215 {
2216 mb_utf8 = TRUE;
2217 u8cc[0] = 0;
2218 c = 0xc0;
2219 }
2220 else
2221 mb_utf8 = FALSE;
2222 }
2223 else
2224 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002225 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002226 if (has_mbyte)
2227 {
2228 mb_c = c;
2229 if (enc_utf8)
2230 {
2231 // If the UTF-8 character is more than one byte:
2232 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002233 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002235 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 mb_l = 1;
2237 else if (mb_l > 1)
2238 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002239 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002240 mb_utf8 = TRUE;
2241 c = 0xc0;
2242 }
2243 }
2244 else
2245 {
2246 // if this is a DBCS character, put it in "mb_c"
2247 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002248 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 mb_l = 1;
2250 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 }
2253 if (mb_l == 0) // at the NUL at end-of-line
2254 mb_l = 1;
2255
2256 // If a double-width char doesn't fit display a '>' in the
2257 // last column.
2258 if ((
2259# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002260 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002262 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 && (*mb_char2cells)(mb_c) == 2)
2264 {
2265 c = '>';
2266 mb_c = c;
2267 mb_l = 1;
2268 mb_utf8 = FALSE;
2269 multi_attr = HL_ATTR(HLF_AT);
2270#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002271 if (wlv.cul_attr)
2272 multi_attr = hl_combine_attr(
2273 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002275 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002276
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277 // put the pointer back to output the double-width
2278 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002279 ++wlv.n_extra;
2280 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281 }
2282 else
2283 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 wlv.n_extra -= mb_l - 1;
2285 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 }
2287 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002288 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002291#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002292 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002293 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002294 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002295 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002296 if (search_attr == 0)
2297 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002298 if (area_attr == 0 && *ptr != NUL)
2299 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002300 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002301#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002302 }
2303 else
2304 {
2305#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002306 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002308 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 // Get a character from the line itself.
2311 c = *ptr;
2312#ifdef FEAT_LINEBREAK
2313 c0 = *ptr;
2314#endif
2315 if (has_mbyte)
2316 {
2317 mb_c = c;
2318 if (enc_utf8)
2319 {
2320 // If the UTF-8 character is more than one byte: Decode it
2321 // into "mb_c".
2322 mb_l = utfc_ptr2len(ptr);
2323 mb_utf8 = FALSE;
2324 if (mb_l > 1)
2325 {
2326 mb_c = utfc_ptr2char(ptr, u8cc);
2327 // Overlong encoded ASCII or ASCII with composing char
2328 // is displayed normally, except a NUL.
2329 if (mb_c < 0x80)
2330 {
2331 c = mb_c;
2332#ifdef FEAT_LINEBREAK
2333 c0 = mb_c;
2334#endif
2335 }
2336 mb_utf8 = TRUE;
2337
2338 // At start of the line we can have a composing char.
2339 // Draw it as a space with a composing char.
2340 if (utf_iscomposing(mb_c))
2341 {
2342 int i;
2343
2344 for (i = Screen_mco - 1; i > 0; --i)
2345 u8cc[i] = u8cc[i - 1];
2346 u8cc[0] = mb_c;
2347 mb_c = ' ';
2348 }
2349 }
2350
2351 if ((mb_l == 1 && c >= 0x80)
2352 || (mb_l >= 1 && mb_c == 0)
2353 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2354 {
2355 // Illegal UTF-8 byte: display as <xx>.
2356 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002357 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358# ifdef FEAT_RIGHTLEFT
2359 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002360 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002362 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002363 c = *wlv.p_extra;
2364 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2367 wlv.c_extra = NUL;
2368 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 if (area_attr == 0 && search_attr == 0)
2370 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002372 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002373 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 }
2376 }
2377 else if (mb_l == 0) // at the NUL at end-of-line
2378 mb_l = 1;
2379#ifdef FEAT_ARABIC
2380 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2381 {
2382 // Do Arabic shaping.
2383 int pc, pc1, nc;
2384 int pcc[MAX_MCO];
2385
2386 // The idea of what is the previous and next
2387 // character depends on 'rightleft'.
2388 if (wp->w_p_rl)
2389 {
2390 pc = prev_c;
2391 pc1 = prev_c1;
2392 nc = utf_ptr2char(ptr + mb_l);
2393 prev_c1 = u8cc[0];
2394 }
2395 else
2396 {
2397 pc = utfc_ptr2char(ptr + mb_l, pcc);
2398 nc = prev_c;
2399 pc1 = pcc[0];
2400 }
2401 prev_c = mb_c;
2402
2403 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2404 }
2405 else
2406 prev_c = mb_c;
2407#endif
2408 }
2409 else // enc_dbcs
2410 {
2411 mb_l = MB_BYTE2LEN(c);
2412 if (mb_l == 0) // at the NUL at end-of-line
2413 mb_l = 1;
2414 else if (mb_l > 1)
2415 {
2416 // We assume a second byte below 32 is illegal.
2417 // Hopefully this is OK for all double-byte encodings!
2418 if (ptr[1] >= 32)
2419 mb_c = (c << 8) + ptr[1];
2420 else
2421 {
2422 if (ptr[1] == NUL)
2423 {
2424 // head byte at end of line
2425 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002426 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 }
2428 else
2429 {
2430 // illegal tail byte
2431 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002432 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002434 wlv.p_extra = wlv.extra;
2435 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002436 wlv.c_extra = NUL;
2437 wlv.c_final = NUL;
2438 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002439 if (area_attr == 0 && search_attr == 0)
2440 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002442 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002443 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002444 // save current attr
2445 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 }
2447 mb_c = c;
2448 }
2449 }
2450 }
2451 // If a double-width char doesn't fit display a '>' in the
2452 // last column; the character is displayed at the start of the
2453 // next line.
2454 if ((
2455# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002456 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002458 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 && (*mb_char2cells)(mb_c) == 2)
2460 {
2461 c = '>';
2462 mb_c = c;
2463 mb_utf8 = FALSE;
2464 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002465 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 // Put pointer back so that the character will be
2467 // displayed at the start of the next line.
2468 --ptr;
2469#ifdef FEAT_CONCEAL
2470 did_decrement_ptr = TRUE;
2471#endif
2472 }
2473 else if (*ptr != NUL)
2474 ptr += mb_l - 1;
2475
2476 // If a double-width char doesn't fit at the left side display
2477 // a '<' in the first column. Don't do this for unprintable
2478 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 wlv.n_extra = 1;
2482 wlv.c_extra = MB_FILLER_CHAR;
2483 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 c = ' ';
2485 if (area_attr == 0 && search_attr == 0)
2486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002488 extra_attr = hl_combine_attr(
2489 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002490 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491 }
2492 mb_c = c;
2493 mb_utf8 = FALSE;
2494 mb_l = 1;
2495 }
2496
2497 }
2498 ++ptr;
2499
2500 if (extra_check)
2501 {
2502#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 // Check spelling (unless at the end of the line).
2504 // Only do this when there is no syntax highlighting, the
2505 // @Spell cluster is not used or the current syntax item
2506 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002507 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 if (has_spell && v >= word_end && v > cur_checked_col)
2509 {
2510 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002511 // do not calculate cap_col at the end of the line or when
2512 // only white space is following
2513 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002514# ifdef FEAT_SYN_HL
2515 !has_syntax ||
2516# endif
2517 can_spell))
2518 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002519 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 int len;
2521 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002522
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525
2526 // Use nextline[] if possible, it has the start of the
2527 // next line concatenated.
2528 if ((prev_ptr - line) - nextlinecol >= 0)
2529 p = nextline + (prev_ptr - line) - nextlinecol;
2530 else
2531 p = prev_ptr;
2532 cap_col -= (int)(prev_ptr - line);
2533 len = spell_check(wp, p, &spell_hlf, &cap_col,
2534 nochange);
2535 word_end = v + len;
2536
2537 // In Insert mode only highlight a word that
2538 // doesn't touch the cursor.
2539 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002540 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 && wp->w_cursor.lnum == lnum
2542 && wp->w_cursor.col >=
2543 (colnr_T)(prev_ptr - line)
2544 && wp->w_cursor.col < (colnr_T)word_end)
2545 {
2546 spell_hlf = HLF_COUNT;
2547 spell_redraw_lnum = lnum;
2548 }
2549
2550 if (spell_hlf == HLF_COUNT && p != prev_ptr
2551 && (p - nextline) + len > nextline_idx)
2552 {
2553 // Remember that the good word continues at the
2554 // start of the next line.
2555 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002556 checked_col = (int)((p - nextline)
2557 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 }
2559
2560 // Turn index into actual attributes.
2561 if (spell_hlf != HLF_COUNT)
2562 spell_attr = highlight_attr[spell_hlf];
2563
2564 if (cap_col > 0)
2565 {
2566 if (p != prev_ptr
2567 && (p - nextline) + cap_col >= nextline_idx)
2568 {
2569 // Remember that the word in the next line
2570 // must start with a capital.
2571 capcol_lnum = lnum + 1;
2572 cap_col = (int)((p - nextline) + cap_col
2573 - nextline_idx);
2574 }
2575 else
2576 // Compute the actual column.
2577 cap_col += (int)(prev_ptr - line);
2578 }
2579 }
2580 }
2581 if (spell_attr != 0)
2582 {
2583 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2585 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002587 wlv.char_attr = hl_combine_attr(spell_attr,
2588 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589 }
2590#endif
2591#ifdef FEAT_LINEBREAK
2592 // Found last space before word: check for line break.
2593 if (wp->w_p_lbr && c0 == c
2594 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2595 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002596 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2597 : 0;
2598 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002599 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002601 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002602# ifdef FEAT_PROP_POPUP
2603 // do not want virtual text counted here
2604 cts.cts_has_prop_with_text = FALSE;
2605# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002606 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002607 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002608
2609 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002610 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002611 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002612 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002613 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2614 if (wlv.n_extra < 0)
2615 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002616 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002617 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002618 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002619 // line break, but for TABs the highlighting should
2620 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002621 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002622
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002626 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 wp->w_buffer->b_p_vts_array) - 1;
2628# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002630 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631# endif
2632
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2634 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002635# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002636 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002637 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002638# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 if (VIM_ISWHITE(c))
2640 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002641# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 if (c == TAB)
2643 // See "Tab alignment" below.
2644 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002645# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 if (!wp->w_p_list)
2647 c = ' ';
2648 }
2649 }
2650#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002651 in_multispace = c == ' '
2652 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2653 if (!in_multispace)
2654 multispace_pos = 0;
2655
Bram Moolenaareed9d462021-02-15 20:38:25 +01002656 // 'list': Change char 160 to 'nbsp' and space to 'space'
2657 // setting in 'listchars'. But not when the character is
2658 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 if (wp->w_p_list
2660 && ((((c == 160 && mb_l == 1)
2661 || (mb_utf8
2662 && ((mb_c == 160 && mb_l == 2)
2663 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002664 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 || (c == ' '
2666 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002667 && (wp->w_lcs_chars.space
2668 || (in_multispace
2669 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002670 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 && ptr - line <= trailcol)))
2672 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002673 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2674 {
2675 c = wp->w_lcs_chars.multispace[multispace_pos++];
2676 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2677 multispace_pos = 0;
2678 }
2679 else
2680 c = (c == ' ') ? wp->w_lcs_chars.space
2681 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 if (area_attr == 0 && search_attr == 0)
2683 {
2684 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002685 extra_attr = hl_combine_attr(wlv.win_attr,
2686 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002687 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 }
2689 mb_c = c;
2690 if (enc_utf8 && utf_char2len(c) > 1)
2691 {
2692 mb_utf8 = TRUE;
2693 u8cc[0] = 0;
2694 c = 0xc0;
2695 }
2696 else
2697 mb_utf8 = FALSE;
2698 }
2699
zeertzjq2e7cba32022-06-10 15:30:32 +01002700 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2701 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002703 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2704 && wp->w_lcs_chars.leadmultispace != NULL)
2705 {
2706 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002707 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2708 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002709 multispace_pos = 0;
2710 }
2711
2712 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2713 c = wp->w_lcs_chars.trail;
2714
2715 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2716 c = wp->w_lcs_chars.lead;
2717
zeertzjq2e7cba32022-06-10 15:30:32 +01002718 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002719 c = wp->w_lcs_chars.space;
2720
2721
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 if (!attr_pri)
2723 {
2724 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 extra_attr = hl_combine_attr(wlv.win_attr,
2726 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002727 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 }
2729 mb_c = c;
2730 if (enc_utf8 && utf_char2len(c) > 1)
2731 {
2732 mb_utf8 = TRUE;
2733 u8cc[0] = 0;
2734 c = 0xc0;
2735 }
2736 else
2737 mb_utf8 = FALSE;
2738 }
2739 }
2740
2741 // Handling of non-printable characters.
2742 if (!vim_isprintc(c))
2743 {
2744 // when getting a character from the file, we may have to
2745 // turn it into something else on the way to putting it
2746 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002747 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 {
2749 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002750 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002751#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002752 char_u *sbr = get_showbreak_value(wp);
2753
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002754 // only adjust the tab_len, when at the first column
2755 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002756 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002757 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758#endif
2759 // tab amount depends on current column
2760#ifdef FEAT_VARTABS
2761 tab_len = tabstop_padding(vcol_adjusted,
2762 wp->w_buffer->b_p_ts,
2763 wp->w_buffer->b_p_vts_array) - 1;
2764#else
2765 tab_len = (int)wp->w_buffer->b_p_ts
2766 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2767#endif
2768
2769#ifdef FEAT_LINEBREAK
2770 if (!wp->w_p_lbr || !wp->w_p_list)
2771#endif
2772 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774#ifdef FEAT_LINEBREAK
2775 else
2776 {
2777 char_u *p;
2778 int len;
2779 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002782# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002783 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002785 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002786
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002788 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002789 && old_boguscols > 0
2790 && wlv.n_extra > tab_len)
2791 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002792# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002795 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002796 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002797 if (wp->w_lcs_chars.tab3)
2798 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002799 if (wlv.n_extra > 0)
2800 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002801 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002803 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002805 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002807 vim_memset(p, ' ', len);
2808 p[len] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002809 vim_free(wlv.p_extra_free);
2810 wlv.p_extra_free = p;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002811 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002812 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002813 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002815 if (*p == NUL)
2816 {
2817 tab_len = i;
2818 break;
2819 }
2820
2821 // if tab3 is given, use it for the last char
2822 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2823 lcs = wp->w_lcs_chars.tab3;
2824 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002825 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002827 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002828 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002829# ifdef FEAT_CONCEAL
2830 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2831 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002832 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002833 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002834# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 }
2837#endif
2838#ifdef FEAT_CONCEAL
2839 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841
2842 // Tab alignment should be identical regardless of
2843 // 'conceallevel' value. So tab compensates of all
2844 // previous concealed characters, and thus resets
2845 // vcol_off and boguscols accumulated so far in the
2846 // line. Note that the tab can be longer than
2847 // 'tabstop' when there are concealed characters.
2848 FIX_FOR_BOGUSCOLS;
2849
2850 // Make sure, the highlighting for the tab char will be
2851 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002852 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002854 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 tab_len += vc_saved;
2856 }
2857#endif
2858 mb_utf8 = FALSE; // don't draw as UTF-8
2859 if (wp->w_p_list)
2860 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002861 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002862 ? wp->w_lcs_chars.tab3
2863 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864#ifdef FEAT_LINEBREAK
2865 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 else
2868#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.c_extra = wp->w_lcs_chars.tab2;
2870 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002872 extra_attr = hl_combine_attr(wlv.win_attr,
2873 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002874 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002875 mb_c = c;
2876 if (enc_utf8 && utf_char2len(c) > 1)
2877 {
2878 mb_utf8 = TRUE;
2879 u8cc[0] = 0;
2880 c = 0xc0;
2881 }
2882 }
2883 else
2884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 wlv.c_final = NUL;
2886 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 c = ' ';
2888 }
2889 }
2890 else if (c == NUL
2891 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002892 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2893 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 && VIsual_mode != Ctrl_V
2895 && (
2896# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002897 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002899 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 && !(noinvcur
2901 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002902 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 && lcs_eol_one > 0)
2904 {
2905 // Display a '$' after the line or highlight an extra
2906 // character if the line break is included.
2907#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2908 // For a diff line the highlighting continues after the
2909 // "$".
2910 if (
2911# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002912 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002913# ifdef LINE_ATTR
2914 &&
2915# endif
2916# endif
2917# ifdef LINE_ATTR
2918 line_attr == 0
2919# endif
2920 )
2921#endif
2922 {
2923 // In virtualedit, visual selections may extend
2924 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002925 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002926 && wlv.tocol != MAXCOL
2927 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002928 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002929 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002931 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2932 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 else
2934 c = ' ';
2935 lcs_eol_one = -1;
2936 --ptr; // put it back at the NUL
2937 if (!attr_pri)
2938 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002939 extra_attr = hl_combine_attr(wlv.win_attr,
2940 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 n_attr = 1;
2942 }
2943 mb_c = c;
2944 if (enc_utf8 && utf_char2len(c) > 1)
2945 {
2946 mb_utf8 = TRUE;
2947 u8cc[0] = 0;
2948 c = 0xc0;
2949 }
2950 else
2951 mb_utf8 = FALSE; // don't draw as UTF-8
2952 }
2953 else if (c != NUL)
2954 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002955 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2956 if (wlv.n_extra == 0)
2957 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958#ifdef FEAT_RIGHTLEFT
2959 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.c_extra = NUL;
2963 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964#ifdef FEAT_LINEBREAK
2965 if (wp->w_p_lbr)
2966 {
2967 char_u *p;
2968
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 c = *wlv.p_extra;
2970 p = alloc(wlv.n_extra + 1);
2971 vim_memset(p, ' ', wlv.n_extra);
2972 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2973 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002974 vim_free(wlv.p_extra_free);
2975 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 }
2977 else
2978#endif
2979 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 wlv.n_extra = byte2cells(c) - 1;
2981 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 }
2983 if (!attr_pri)
2984 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002986 extra_attr = hl_combine_attr(wlv.win_attr,
2987 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
2990 mb_utf8 = FALSE; // don't draw as UTF-8
2991 }
2992 else if (VIsual_active
2993 && (VIsual_mode == Ctrl_V
2994 || VIsual_mode == 'v')
2995 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002996 && wlv.tocol != MAXCOL
2997 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 && (
2999#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003002 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003 {
3004 c = ' ';
3005 --ptr; // put it back at the NUL
3006 }
3007#if defined(LINE_ATTR)
3008 else if ((
3009# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011# endif
3012# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003013 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014# endif
3015 line_attr != 0
3016 ) && (
3017# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003018 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003020 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003022 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023# endif
3024 < wp->w_width)))
3025 {
3026 // Highlight until the right side of the window
3027 c = ' ';
3028 --ptr; // put it back at the NUL
3029
3030 // Remember we do the char for line highlighting.
3031 ++did_line_attr;
3032
3033 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003034 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003036 || (wp->w_p_list &&
3037 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003040 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003042 wlv.diff_hlf = HLF_CHD;
3043 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3047 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003048 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003049 || (wlv.vcol >= left_curline_col
3050 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.char_attr = hl_combine_attr(
3052 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 }
3054 }
3055# endif
3056# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003057 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003060 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3061 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 if (!wlv.cul_screenline
3064 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003065 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.char_attr = hl_combine_attr(
3067 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 }
3069 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3071 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 }
3073# endif
3074 }
3075#endif
3076 }
3077
3078#ifdef FEAT_CONCEAL
3079 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003080 && (wp != curwin || lnum != wp->w_cursor.lnum
3081 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003082 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3083 && !(lnum_in_visual_area
3084 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003087 if (((prev_syntax_id != syntax_seqnr
3088 && (syntax_flags & HL_CONCEAL) != 0)
3089 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003090 && (syn_get_sub_char() != NUL
3091 || (has_match_conc && match_conc)
3092 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 && wp->w_p_cole != 3)
3094 {
3095 // First time at this concealed item: display one
3096 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003097 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 c = match_conc;
3099 else if (syn_get_sub_char() != NUL)
3100 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003101 else if (wp->w_lcs_chars.conceal != NUL)
3102 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 else
3104 c = ' ';
3105
3106 prev_syntax_id = syntax_seqnr;
3107
Bram Moolenaar1306b362022-08-06 15:59:06 +01003108 if (wlv.n_extra > 0)
3109 wlv.vcol_off += wlv.n_extra;
3110 wlv.vcol += wlv.n_extra;
3111 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 {
3113# ifdef FEAT_RIGHTLEFT
3114 if (wp->w_p_rl)
3115 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 wlv.col -= wlv.n_extra;
3117 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 }
3119 else
3120# endif
3121 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003122 wlv.boguscols += wlv.n_extra;
3123 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 }
3125 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 n_attr = 0;
3128 }
3129 else if (n_skip == 0)
3130 {
3131 is_concealing = TRUE;
3132 n_skip = 1;
3133 }
3134 mb_c = c;
3135 if (enc_utf8 && utf_char2len(c) > 1)
3136 {
3137 mb_utf8 = TRUE;
3138 u8cc[0] = 0;
3139 c = 0xc0;
3140 }
3141 else
3142 mb_utf8 = FALSE; // don't draw as UTF-8
3143 }
3144 else
3145 {
3146 prev_syntax_id = 0;
3147 is_concealing = FALSE;
3148 }
3149
3150 if (n_skip > 0 && did_decrement_ptr)
3151 // not showing the '>', put pointer back to avoid getting stuck
3152 ++ptr;
3153
3154#endif // FEAT_CONCEAL
3155 }
3156
3157#ifdef FEAT_CONCEAL
3158 // In the cursor line and we may be concealing characters: correct
3159 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 && wp == curwin && lnum == wp->w_cursor.lnum
3162 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003163 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003165# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003167 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003169# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003170 wp->w_wcol = wlv.col - wlv.boguscols;
3171 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 did_wcol = TRUE;
3173 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003174# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003175 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003176# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 }
3178#endif
3179
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003180 // Use "extra_attr", but don't override visual selection highlighting,
3181 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003182 // Don't use "extra_attr" until n_attr_skip is zero.
3183 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003184 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003185 && (!attr_pri
3186#ifdef FEAT_PROP_POPUP
3187 || (text_prop_flags & PT_FLAG_OVERRIDE)
3188#endif
3189 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 {
3191#ifdef LINE_ATTR
3192 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003193 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194 else
3195#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003196 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 }
3198
3199#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3200 // XIM don't send preedit_start and preedit_end, but they send
3201 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3202 // im_is_preediting() here.
3203 if (p_imst == IM_ON_THE_SPOT
3204 && xic != NULL
3205 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003206 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 && !p_imdisable
3208 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003210 {
3211 colnr_T tcol;
3212
3213 if (preedit_end_col == MAXCOL)
3214 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3215 else
3216 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003217 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 {
3219 if (feedback_old_attr < 0)
3220 {
3221 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003222 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 wlv.char_attr = im_get_feedback_attr(feedback_col);
3225 if (wlv.char_attr < 0)
3226 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 feedback_col++;
3228 }
3229 else if (feedback_old_attr >= 0)
3230 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003231 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 feedback_old_attr = -1;
3233 feedback_col = 0;
3234 }
3235 }
3236#endif
3237 // Handle the case where we are in column 0 but not on the first
3238 // character of the line and the user wants us to show us a
3239 // special character (via 'listchars' option "precedes:<char>".
3240 if (lcs_prec_todo != NUL
3241 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003242 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3243 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003245 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 && c != NUL)
3249 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003250 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 lcs_prec_todo = NUL;
3252 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3253 {
3254 // Double-width character being overwritten by the "precedes"
3255 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 wlv.c_extra = MB_FILLER_CHAR;
3257 wlv.c_final = NUL;
3258 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003260 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 }
3262 mb_c = c;
3263 if (enc_utf8 && utf_char2len(c) > 1)
3264 {
3265 mb_utf8 = TRUE;
3266 u8cc[0] = 0;
3267 c = 0xc0;
3268 }
3269 else
3270 mb_utf8 = FALSE; // don't draw as UTF-8
3271 if (!attr_pri)
3272 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003273 saved_attr3 = wlv.char_attr; // save current attr
3274 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 n_attr3 = 1;
3276 }
3277 }
3278
3279 // At end of the text line or just after the last character.
3280 if ((c == NUL
3281#if defined(LINE_ATTR)
3282 || did_line_attr == 1
3283#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 {
3286#ifdef FEAT_SEARCH_EXTRA
3287 // flag to indicate whether prevcol equals startcol of search_hl or
3288 // one of the matches
3289 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3290 (long)(ptr - line) - (c == NUL));
3291#endif
3292 // Invert at least one char, used for Visual and empty line or
3293 // highlight match at end of line. If it's beyond the last
3294 // char on the screen, just overwrite that one (tricky!) Not
3295 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003296 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003297 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 && (VIsual_mode != Ctrl_V
3299 || lnum == VIsual.lnum
3300 || lnum == curwin->w_cursor.lnum)
3301 && c == NUL)
3302#ifdef FEAT_SEARCH_EXTRA
3303 // highlight 'hlsearch' match at end of line
3304 || (prevcol_hl_flag
3305# ifdef FEAT_SYN_HL
3306 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3307 && !(wp == curwin && VIsual_active))
3308# endif
3309# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311# endif
3312# if defined(LINE_ATTR)
3313 && did_line_attr <= 1
3314# endif
3315 )
3316#endif
3317 ))
3318 {
3319 int n = 0;
3320
3321#ifdef FEAT_RIGHTLEFT
3322 if (wp->w_p_rl)
3323 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 n = 1;
3326 }
3327 else
3328#endif
3329 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 n = -1;
3332 }
3333 if (n != 0)
3334 {
3335 // At the window boundary, highlight the last character
3336 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 wlv.off += n;
3338 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 }
3340 else
3341 {
3342 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003343 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003345 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 }
3347#ifdef FEAT_SEARCH_EXTRA
3348 if (area_attr == 0)
3349 {
3350 // Use attributes from match with highest priority among
3351 // 'search_hl' and the match list.
3352 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 }
3355#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003356 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003357 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358#ifdef FEAT_RIGHTLEFT
3359 if (wp->w_p_rl)
3360 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 --wlv.col;
3362 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 }
3364 else
3365#endif
3366 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003367 ++wlv.col;
3368 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 ++wlv.vcol;
3371 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 }
3373 }
3374
3375 // At end of the text line.
3376 if (c == NUL)
3377 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003378 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379
3380 // Update w_cline_height and w_cline_folded if the cursor line was
3381 // updated (saves a call to plines() later).
3382 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3383 {
3384 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386#ifdef FEAT_FOLDING
3387 curwin->w_cline_folded = FALSE;
3388#endif
3389 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3390 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 break;
3392 }
3393
3394 // Show "extends" character from 'listchars' if beyond the line end and
3395 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003396 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398 && wp->w_p_list
3399 && !wp->w_p_wrap
3400#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003401 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402#endif
3403 && (
3404#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003405 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003407 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003409 || lcs_eol_one > 0
3410 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003411 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003413 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 mb_c = c;
3416 if (enc_utf8 && utf_char2len(c) > 1)
3417 {
3418 mb_utf8 = TRUE;
3419 u8cc[0] = 0;
3420 c = 0xc0;
3421 }
3422 else
3423 mb_utf8 = FALSE;
3424 }
3425
3426#ifdef FEAT_SYN_HL
3427 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 if (wlv.draw_color_col)
3429 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430
3431 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3432 // highlight the cursor position itself.
3433 // Also highlight the 'colorcolumn' if it is different than
3434 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003435 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3436 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003438 if (((wlv.draw_state == WL_LINE
3439 || wlv.draw_state == WL_BRI
3440 || wlv.draw_state == WL_SBR)
3441 && !lnum_in_visual_area
3442 && search_attr == 0
3443 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003444# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003445 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003446# endif
3447 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 {
3449 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3450 && lnum != wp->w_cursor.lnum)
3451 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003452 vcol_save_attr = wlv.char_attr;
3453 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3454 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 vcol_save_attr = wlv.char_attr;
3459 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 }
3461 }
3462#endif
3463
3464 // Store character to be displayed.
3465 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003467 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 {
3469 // Store the character.
3470#if defined(FEAT_RIGHTLEFT)
3471 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3472 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003473 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 --wlv.off;
3475 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 }
3477#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003478 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 if (enc_dbcs == DBCS_JPNU)
3480 {
3481 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 ScreenLines[wlv.off] = 0x8e;
3483 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003484 }
3485 else if (enc_utf8)
3486 {
3487 if (mb_utf8)
3488 {
3489 int i;
3490
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003491 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003493 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 for (i = 0; i < Screen_mco; ++i)
3495 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497 if (u8cc[i] == 0)
3498 break;
3499 }
3500 }
3501 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 }
3504 if (multi_attr)
3505 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 multi_attr = 0;
3508 }
3509 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003513
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3515 {
3516 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 ++wlv.off;
3518 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519 if (enc_utf8)
3520 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003521 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 else
3523 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003525 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003527 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528#endif
3529 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003531 // When "wlv.tocol" is halfway a character, set it to the end
3532 // of the character, otherwise highlighting won't stop.
3533 if (wlv.tocol == wlv.vcol)
3534 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003535
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003537
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538#ifdef FEAT_RIGHTLEFT
3539 if (wp->w_p_rl)
3540 {
3541 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003542 --wlv.off;
3543 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
3545#endif
3546 }
3547#ifdef FEAT_RIGHTLEFT
3548 if (wp->w_p_rl)
3549 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003550 --wlv.off;
3551 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 }
3553 else
3554#endif
3555 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 ++wlv.off;
3557 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 }
3559 }
3560#ifdef FEAT_CONCEAL
3561 else if (wp->w_p_cole > 0 && is_concealing)
3562 {
3563 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003565 if (wlv.n_extra > 0)
3566 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 if (wp->w_p_wrap)
3568 {
3569 // Special voodoo required if 'wrap' is on.
3570 //
3571 // Advance the column indicator to force the line
3572 // drawing to wrap early. This will make the line
3573 // take up the same screen space when parts are concealed,
3574 // so that cursor line computations aren't messed up.
3575 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 // trailing junk to be written out of the screen line
3578 // we are building, 'boguscols' keeps track of the number
3579 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003582 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583# ifdef FEAT_RIGHTLEFT
3584 if (wp->w_p_rl)
3585 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003586 wlv.col -= wlv.n_extra;
3587 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 }
3589 else
3590# endif
3591 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 wlv.col += wlv.n_extra;
3593 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003595 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 n_attr = 0;
3597 }
3598
3599
3600 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3601 {
3602 // Need to fill two screen columns.
3603# ifdef FEAT_RIGHTLEFT
3604 if (wp->w_p_rl)
3605 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 --wlv.boguscols;
3607 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 }
3609 else
3610# endif
3611 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003612 ++wlv.boguscols;
3613 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 }
3615 }
3616
3617# ifdef FEAT_RIGHTLEFT
3618 if (wp->w_p_rl)
3619 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 --wlv.boguscols;
3621 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
3623 else
3624# endif
3625 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ++wlv.boguscols;
3627 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 }
3629 }
3630 else
3631 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003634 wlv.vcol += wlv.n_extra;
3635 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 n_attr = 0;
3637 }
3638 }
3639
3640 }
3641#endif // FEAT_CONCEAL
3642 else
3643 --n_skip;
3644
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003645 // Only advance the "wlv.vcol" when after the 'number' or
3646 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003649 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#endif
3651 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003652 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653
3654#ifdef FEAT_SYN_HL
3655 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003656 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657#endif
3658
3659 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3661 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662
3663 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003664 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003665 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003666 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003667 if (n_attr_skip > 0)
3668 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669
3670 // At end of screen line and there is more to come: Display the line
3671 // so far. If there is no more to display it is caught above.
3672 if ((
3673#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003676 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003677 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003678 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003680 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003682#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003683 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003684#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003685 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003686 && wlv.p_extra != at_end_str)
3687 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3688 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689 )
3690 {
3691#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003692 wlv.col += wlv.boguscols;
3693 wlv_screen_line(wp, &wlv, FALSE);
3694 wlv.col -= wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003695 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003697 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 ++wlv.row;
3700 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003701
3702 // When not wrapping and finished diff lines, or when displayed
3703 // '$' and highlighting until last column, break here.
3704 if ((!wp->w_p_wrap
3705#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003706 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003707#endif
3708#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003709 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710#endif
3711 ) || lcs_eol_one == -1)
3712 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003713#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003714 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003715 {
3716 // do not output more of the line, only the "below" prop
3717 ptr += STRLEN(ptr);
3718# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003719 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003720# endif
3721 }
3722#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723
3724 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003727 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728#endif
3729 )
3730 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3732 draw_vsep_win(wp, wlv.row);
3733 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 }
3735
3736 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003739 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740 break;
3741 }
3742
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 if (screen_cur_row == wlv.screen_row - 1
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 Moolenaarb7963df2022-07-31 17:12:43 +01003747#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003748 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003749#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 && wp->w_width == Columns)
3751 {
3752 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754
3755 // Special trick to make copy/paste of wrapped lines work with
3756 // xterm/screen: write an extra character beyond the end of
3757 // the line. This will work with all terminal types
3758 // (regardless of the xn,am settings).
3759 // Only do this on a fast tty.
3760 // Only do this if the cursor is on the current line
3761 // (something has been written in it).
3762 // Don't do this for the GUI.
3763 // Don't do this for double-width characters.
3764 // Don't do this for a window not at the right screen border.
3765 if (p_tf
3766#ifdef FEAT_GUI
3767 && !gui.in_use
3768#endif
3769 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003770 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3771 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 || (*mb_off2cells)(
3774 LineOffset[wlv.screen_row - 1]
3775 + (int)Columns - 2,
3776 LineOffset[wlv.screen_row]
3777 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 {
3779 // First make sure we are at the end of the screen line,
3780 // then output the same character again to let the
3781 // terminal know about the wrap. If the terminal doesn't
3782 // auto-wrap, we overwrite the character.
3783 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003784 screen_char(LineOffset[wlv.screen_row - 1]
3785 + (unsigned)Columns - 1,
3786 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787
3788 // When there is a multi-byte character, just output a
3789 // space to keep it simple.
3790 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003792 out_char(' ');
3793 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003794 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 + (Columns - 1)]);
3796 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 screen_start(); // don't know where cursor is now
3799 }
3800 }
3801
Bram Moolenaar1306b362022-08-06 15:59:06 +01003802 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803
Bram Moolenaareed9d462021-02-15 20:38:25 +01003804 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003806 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003808 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003810 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003811 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#endif
3813#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003814 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 // When the filler lines are actually below the last line of the
3816 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003817 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 break;
3819#endif
3820 }
3821
3822 } // for every character in the line
3823
3824#ifdef FEAT_SPELL
3825 // After an empty line check first word for capital.
3826 if (*skipwhite(line) == NUL)
3827 {
3828 capcol_lnum = lnum + 1;
3829 cap_col = 0;
3830 }
3831#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003832#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 vim_free(text_props);
3834 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003835 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836#endif
3837
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003838 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003839 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840}