blob: e6a785e408e212ec62a81b2c4e41656306f41fda [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{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100345 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
346
Bram Moolenaard7657e92022-09-20 18:59:30 +0100347 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100348 && (wlv->row == wlv->startrow + wlv->filler_lines || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100349 // there is no line number in a wrapped line when "n" is in
350 // 'cpoptions', but 'breakindent' assumes it anyway.
351 && !((has_cpo_n
352#ifdef FEAT_LINEBREAK
353 && !wp->w_p_bri
354#endif
355 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100356 {
357#ifdef FEAT_SIGNS
358 // If 'signcolumn' is set to 'number' and a sign is present
359 // in 'lnum', then display the sign instead of the line
360 // number.
361 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
362 get_sign_display_info(TRUE, wp, wlv);
363 else
364#endif
365 {
366 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100367 // When there are text properties above the line put the line number
368 // below them.
369 if (wlv->row == wlv->startrow + wlv->filler_lines
370#ifdef FEAT_PROP_POPUP
371 + wlv->text_prop_above_count
Bram Moolenaard7657e92022-09-20 18:59:30 +0100372#endif
Bram Moolenaar06618f92022-10-06 19:21:20 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100374 {
375 long num;
376 char *fmt = "%*ld ";
377
378 if (wp->w_p_nu && !wp->w_p_rnu)
379 // 'number' + 'norelativenumber'
380 num = (long)wlv->lnum;
381 else
382 {
383 // 'relativenumber', don't use negative numbers
384 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
385 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
386 {
387 // 'number' + 'relativenumber'
388 num = wlv->lnum;
389 fmt = "%-*ld ";
390 }
391 }
392
393 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100394 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
396 ++wlv->p_extra)
397 *wlv->p_extra = '-';
398#ifdef FEAT_RIGHTLEFT
399 if (wp->w_p_rl) // reverse line numbers
400 {
401 char_u *p1, *p2;
402 int t;
403
404 // like rl_mirror(), but keep the space at the end
405 p2 = skipwhite(wlv->extra);
406 p2 = skiptowhite(p2) - 1;
407 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
408 {
409 t = *p1;
410 *p1 = *p2;
411 *p2 = t;
412 }
413 }
414#endif
415 wlv->p_extra = wlv->extra;
416 wlv->c_extra = NUL;
417 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100418 }
419 else
420 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100421 wlv->c_extra = ' ';
422 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100423 }
424 wlv->n_extra = number_width(wp) + 1;
425 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
426#ifdef FEAT_SYN_HL
427 // When 'cursorline' is set highlight the line number of
428 // the current line differently.
429 // When 'cursorlineopt' does not have "line" only
430 // highlight the line number itself.
431 // TODO: Can we use CursorLine instead of CursorLineNr
432 // when CursorLineNr isn't set?
433 if (wp->w_p_cul
434 && wlv->lnum == wp->w_cursor.lnum
435 && (wp->w_p_culopt_flags & CULOPT_NBR)
436 && (wlv->row == wlv->startrow + wlv->filler_lines
437 || (wlv->row > wlv->startrow + wlv->filler_lines
438 && (wp->w_p_culopt_flags & CULOPT_LINE))))
439 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
440#endif
441 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
442 && HL_ATTR(HLF_LNA) != 0)
443 // Use LineNrAbove
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
445 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
446 && HL_ATTR(HLF_LNB) != 0)
447 // Use LineNrBelow
448 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
449 }
450#ifdef FEAT_SIGNS
451 if (num_attr)
452 wlv->char_attr = num_attr;
453#endif
454 }
455}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100456
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100457#ifdef FEAT_LINEBREAK
458 static void
459handle_breakindent(win_T *wp, winlinevars_T *wlv)
460{
461 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
462 && *get_showbreak_value(wp) != NUL)
463 // draw indent after showbreak value
464 wlv->draw_state = WL_BRI;
465 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
466 // After the showbreak, draw the breakindent
467 wlv->draw_state = WL_BRI - 1;
468
469 // draw 'breakindent': indent wrapped text accordingly
470 if (wlv->draw_state == WL_BRI - 1)
471 {
472 wlv->draw_state = WL_BRI;
473 // if wlv->need_showbreak is set, breakindent also applies
474 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
475# ifdef FEAT_DIFF
476 && wlv->filler_lines == 0
477# endif
478# ifdef FEAT_PROP_POPUP
479 && !wlv->dont_use_showbreak
480# endif
481 )
482 {
483 wlv->char_attr = 0;
484# ifdef FEAT_DIFF
485 if (wlv->diff_hlf != (hlf_T)0)
486 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
487# endif
488 wlv->p_extra = NULL;
489 wlv->c_extra = ' ';
490 wlv->c_final = NUL;
491 wlv->n_extra = get_breakindent_win(wp,
492 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
493 if (wlv->row == wlv->startrow)
494 {
495 wlv->n_extra -= win_col_off2(wp);
496 if (wlv->n_extra < 0)
497 wlv->n_extra = 0;
498 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100499 if (wp->w_skipcol > 0 && wlv->startrow == 0
500 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100501 wlv->need_showbreak = FALSE;
502 // Correct end of highlighted area for 'breakindent',
503 // required when 'linebreak' is also set.
504 if (wlv->tocol == wlv->vcol)
505 wlv->tocol += wlv->n_extra;
506 }
507 }
508}
509#endif
510
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100511#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
512 static void
513handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
514{
515# ifdef FEAT_DIFF
516 if (wlv->filler_todo > 0)
517 {
518 // Draw "deleted" diff line(s).
519 if (char2cells(wp->w_fill_chars.diff) > 1)
520 {
521 wlv->c_extra = '-';
522 wlv->c_final = NUL;
523 }
524 else
525 {
526 wlv->c_extra = wp->w_fill_chars.diff;
527 wlv->c_final = NUL;
528 }
529# ifdef FEAT_RIGHTLEFT
530 if (wp->w_p_rl)
531 wlv->n_extra = wlv->col + 1;
532 else
533# endif
534 wlv->n_extra = wp->w_width - wlv->col;
535 wlv->char_attr = HL_ATTR(HLF_DED);
536 }
537# endif
538
539# ifdef FEAT_LINEBREAK
540 char_u *sbr = get_showbreak_value(wp);
541 if (*sbr != NUL && wlv->need_showbreak)
542 {
543 // Draw 'showbreak' at the start of each broken line.
544 wlv->p_extra = sbr;
545 wlv->c_extra = NUL;
546 wlv->c_final = NUL;
547 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100548 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100549 wlv->need_showbreak = FALSE;
550 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
551 // Correct end of highlighted area for 'showbreak',
552 // required when 'linebreak' is also set.
553 if (wlv->tocol == wlv->vcol)
554 wlv->tocol += wlv->n_extra;
555 // combine 'showbreak' with 'wincolor'
556 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
557# ifdef FEAT_SYN_HL
558 // combine 'showbreak' with 'cursorline'
559 if (wlv->cul_attr != 0)
560 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
561# endif
562 }
563# endif
564}
565#endif
566
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100567#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100568/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100569 * Return the cell size of virtual text after truncation.
570 */
571 static int
572textprop_size_after_trunc(
573 win_T *wp,
574 int flags, // TP_FLAG_ALIGN_*
575 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100576 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 char_u *text,
578 int *n_used_ptr)
579{
580 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
581 ? wp->w_width : added;
582 int len = (int)STRLEN(text);
583 int strsize = 0;
584 int n_used;
585
586 // if the remaining size is to small wrap anyway and use the next line
587 if (space < PROP_TEXT_MIN_CELLS)
588 space += wp->w_width;
Bram Moolenaar13845c42022-10-09 15:26:03 +0100589 if (flags & TP_FLAG_ALIGN_BELOW)
590 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100591 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
592 {
593 int clen = ptr2cells(text + n_used);
594
595 if (strsize + clen > space)
596 break;
597 strsize += clen;
598 }
599 *n_used_ptr = n_used;
600 return strsize;
601}
602
603/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100604 * Take care of padding, right-align and truncation of virtual text after a
605 * line.
606 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
607 * padding, right-align and truncation. Otherwise only the size is computed.
608 * When "n_attr" is NULL returns the number of screen cells used.
609 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100611 int
612text_prop_position(
613 win_T *wp,
614 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100615 int vcol UNUSED, // current text column
616 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100617 int *n_extra, // nr of bytes for virtual text
618 char_u **p_extra, // virtual text
619 int *n_attr, // attribute cells, NULL if not used
620 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200621{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100622 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100623 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
625 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
626 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
627 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100628 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100629 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100630 int before = room; // spaces before the text
631 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int n_used = *n_extra;
633 char_u *l = NULL;
634 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100635 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100636 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200637
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100639 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100640 int col_off = win_col_off(wp) + win_col_off2(wp);
641 int skip_add = 0;
642
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100643 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100646 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 }
648 else
649 {
650 // Right-align: fill with before
651 if (right)
652 before -= cells;
653 if (before < 0
654 || !(right || below)
655 || (below
656 ? (col_with_padding == 0 || !wp->w_p_wrap)
657 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100658 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
660 {
661 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100662 before = wp->w_width - col_off - strsize + room;
663 if (before < 0)
664 before = 0;
665 else
666 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100667 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100668 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100670 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100671 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100672 else if (below && before > 0)
673 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100674 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100676
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100677 // With 'nowrap' add one to show the "extends" character if needed (it
678 // doesn't show if the text just fits).
679 if (!wp->w_p_wrap
680 && n_used < *n_extra
681 && wp->w_lcs_chars.ext != NUL
682 && wp->w_p_list)
683 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100684 if (!wp->w_p_wrap && below && padding > 0)
685 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100686
687 // add 1 for NUL, 2 for when '…' is used
688 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100689 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690 if (n_attr == NULL || l != NULL)
691 {
692 int off = 0;
693
694 if (n_attr != NULL)
695 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 vim_memset(l, ' ', before);
697 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698 if (padding > 0)
699 {
700 vim_memset(l + off, ' ', padding);
701 off += padding;
702 }
703 vim_strncpy(l + off, *p_extra, n_used);
704 off += n_used;
705 }
706 else
707 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 off = before + after + padding + n_used;
709 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 }
711 if (n_attr != NULL)
712 {
713 if (n_used < *n_extra && wp->w_p_wrap)
714 {
715 char_u *lp = l + off - 1;
716
717 if (has_mbyte)
718 {
719 // change last character to '…'
720 lp -= (*mb_head_off)(l, lp);
721 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100722 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100723 }
724 else
725 // change last character to '>'
726 *lp = '>';
727 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100728 else if (after > 0)
729 {
730 vim_memset(l + off, ' ', after);
731 l[off + after] = NUL;
732 }
733
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100734 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100735 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100736 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100737 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100738 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100739 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 }
741 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100742 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100743
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100744 if (n_attr == NULL)
745 return cells;
746 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200747}
748#endif
749
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100750/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100751 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100752 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
753 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100754 */
755 static void
756wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
757{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100758 if (wlv->row == 0 && wp->w_skipcol > 0
759#if defined(FEAT_LINEBREAK)
760 && *get_showbreak_value(wp) == NUL
761#endif
762 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100763 {
764 int off = (int)(current_ScreenLine - ScreenLines);
765
766 for (int i = 0; i < 3; ++i)
767 {
768 ScreenLines[off] = '<';
769 if (enc_utf8)
770 ScreenLinesUC[off] = 0;
771 ScreenAttrs[off] = HL_ATTR(HLF_AT);
772 ++off;
773 }
774 }
775
776 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
777 negative_width ? -wp->w_width : wp->w_width,
778 wlv->screen_line_flags);
779}
780
781/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100782 * Called when finished with the line: draw the screen line and handle any
783 * highlighting until the right of the window.
784 */
785 static void
786draw_screen_line(win_T *wp, winlinevars_T *wlv)
787{
788#ifdef FEAT_SYN_HL
789 long v;
790
791 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
792 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100793 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100794 else
795 v = wp->w_leftcol;
796
797 // check if line ends before left margin
798 if (wlv->vcol < v + wlv->col - win_col_off(wp))
799 wlv->vcol = v + wlv->col - win_col_off(wp);
800# ifdef FEAT_CONCEAL
801 // Get rid of the boguscols now, we want to draw until the right
802 // edge for 'cursorcolumn'.
803 wlv->col -= wlv->boguscols;
804 wlv->boguscols = 0;
805# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
806# else
807# define VCOL_HLC (wlv->vcol)
808# endif
809
810 if (wlv->draw_color_col)
811 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
812
813 if (((wp->w_p_cuc
814 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
815 && (int)wp->w_virtcol <
816 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
817 && wlv->lnum != wp->w_cursor.lnum)
818 || wlv->draw_color_col
819 || wlv->win_attr != 0)
820# ifdef FEAT_RIGHTLEFT
821 && !wp->w_p_rl
822# endif
823 )
824 {
825 int rightmost_vcol = 0;
826 int i;
827
828 if (wp->w_p_cuc)
829 rightmost_vcol = wp->w_virtcol;
830 if (wlv->draw_color_col)
831 // determine rightmost colorcolumn to possibly draw
832 for (i = 0; wlv->color_cols[i] >= 0; ++i)
833 if (rightmost_vcol < wlv->color_cols[i])
834 rightmost_vcol = wlv->color_cols[i];
835
836 while (wlv->col < wp->w_width)
837 {
838 ScreenLines[wlv->off] = ' ';
839 if (enc_utf8)
840 ScreenLinesUC[wlv->off] = 0;
841 ScreenCols[wlv->off] = MAXCOL;
842 ++wlv->col;
843 if (wlv->draw_color_col)
844 wlv->draw_color_col = advance_color_col(
845 VCOL_HLC, &wlv->color_cols);
846
847 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
848 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
849 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
850 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
851 else
852 ScreenAttrs[wlv->off++] = wlv->win_attr;
853
854 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
855 break;
856
857 ++wlv->vcol;
858 }
859 }
860#endif
861
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100862 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100863 ++wlv->row;
864 ++wlv->screen_row;
865}
866#undef VCOL_HLC
867
868/*
869 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100870 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871 */
872 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100873win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100874{
875 wlv->col = 0;
876 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
877
878#ifdef FEAT_RIGHTLEFT
879 if (wp->w_p_rl)
880 {
881 // Rightleft window: process the text in the normal direction, but put
882 // it in current_ScreenLine[] from right to left. Start at the
883 // rightmost column of the window.
884 wlv->col = wp->w_width - 1;
885 wlv->off += wlv->col;
886 wlv->screen_line_flags |= SLF_RIGHTLEFT;
887 }
888#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100889 if (save_extra)
890 {
891 // reset the drawing state for the start of a wrapped line
892 wlv->draw_state = WL_START;
893 wlv->saved_n_extra = wlv->n_extra;
894 wlv->saved_p_extra = wlv->p_extra;
895 wlv->saved_c_extra = wlv->c_extra;
896 wlv->saved_c_final = wlv->c_final;
897#ifdef FEAT_SYN_HL
898 if (!(wlv->cul_screenline
899# ifdef FEAT_DIFF
900 && wlv->diff_hlf == (hlf_T)0
901# endif
902 ))
903 wlv->saved_char_attr = wlv->char_attr;
904 else
905#endif
906 wlv->saved_char_attr = 0;
907 wlv->n_extra = 0;
908 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100909}
910
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200911/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100912 * Called when wlv->draw_state is set to WL_LINE.
913 */
914 static void
915win_line_continue(winlinevars_T *wlv)
916{
917 if (wlv->saved_n_extra > 0)
918 {
919 // Continue item from end of wrapped line.
920 wlv->n_extra = wlv->saved_n_extra;
921 wlv->c_extra = wlv->saved_c_extra;
922 wlv->c_final = wlv->saved_c_final;
923 wlv->p_extra = wlv->saved_p_extra;
924 wlv->char_attr = wlv->saved_char_attr;
925 }
926 else
927 wlv->char_attr = wlv->win_attr;
928}
929
930/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200931 * Display line "lnum" of window 'wp' on the screen.
932 * Start at row "startrow", stop when "endrow" is reached.
933 * wp->w_virtcol needs to be valid.
934 *
935 * Return the number of last row the line occupies.
936 */
937 int
938win_line(
939 win_T *wp,
940 linenr_T lnum,
941 int startrow,
942 int endrow,
943 int nochange UNUSED, // not updating for changed text
944 int number_only) // only update the number column
945{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100946 winlinevars_T wlv; // variables passed between functions
947
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200948 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100949 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200950 char_u *line; // current line
951 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200952
Bram Moolenaar1306b362022-08-06 15:59:06 +0100953#ifdef FEAT_PROP_POPUP
954 char_u *p_extra_free2 = NULL; // another p_extra to be freed
955#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000957#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000958 int in_linebreak = FALSE; // n_extra set for showing linebreak
959#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200960 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100961 // displaying eol at end-of-line
962 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000963 int lcs_prec_todo = wp->w_lcs_chars.prec;
964 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100966 int n_attr = 0; // chars with special attr
967 int n_attr_skip = 0; // chars to skip before using extra_attr
968 int saved_attr2 = 0; // char_attr saved for n_attr
969 int n_attr3 = 0; // chars with overruling special attr
970 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971
972 int n_skip = 0; // nr of chars to skip for 'nowrap'
973
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974 int fromcol_prev = -2; // start of inverting after cursor
975 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200976 int lnum_in_visual_area = FALSE;
977 pos_T pos;
978 long v;
979
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int attr_pri = FALSE; // char_attr has priority
981 int area_highlighting = FALSE; // Visual or incsearch highlighting
982 // in this line
983 int vi_attr = 0; // attributes for Visual and incsearch
984 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985 int area_attr = 0; // attributes desired by highlighting
986 int search_attr = 0; // attributes desired by 'hlsearch'
987#ifdef FEAT_SYN_HL
988 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
989 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200990 int prev_syntax_col = -1; // column of prev_syntax_attr
991 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200992 int has_syntax = FALSE; // this buffer has syntax highl.
993 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100995#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200996 int text_prop_count;
997 int text_prop_next = 0; // next text property to use
998 textprop_T *text_props = NULL;
999 int *text_prop_idxs = NULL;
1000 int text_props_active = 0;
1001 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001002 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001004 int text_prop_attr_comb = 0; // text_prop_attr combined with
1005 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001006 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001007 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001008 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001009 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001010 int saved_search_attr = 0; // search_attr to be used when n_extra
1011 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001012 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013#endif
1014#ifdef FEAT_SPELL
1015 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001016 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017# define SPWORDLEN 150
1018 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1019 int nextlinecol = 0; // column where nextline[] starts
1020 int nextline_idx = 0; // index in nextline[] where next line
1021 // starts
1022 int spell_attr = 0; // attributes desired by spelling
1023 int word_end = 0; // last byte with same spell_attr
1024 static linenr_T checked_lnum = 0; // line number for "checked_col"
1025 static int checked_col = 0; // column in "checked_lnum" up to which
1026 // there are no spell errors
1027 static int cap_col = -1; // column to check for Cap word
1028 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1029 int cur_checked_col = 0; // checked column for current line
1030#endif
1031 int extra_check = 0; // has extra highlighting
1032 int multi_attr = 0; // attributes desired by multibyte
1033 int mb_l = 1; // multi-byte byte length
1034 int mb_c = 0; // decoded multi-byte character
1035 int mb_utf8 = FALSE; // screen char is UTF-8 char
1036 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 int change_start = MAXCOL; // first col of changed area
1039 int change_end = -1; // last col of changed area
1040#endif
1041 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001042 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001043 int in_multispace = FALSE; // in multiple consecutive spaces
1044 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1046 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1047# define LINE_ATTR
1048 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001049 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001052 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053#ifdef FEAT_ARABIC
1054 int prev_c = 0; // previous Arabic character
1055 int prev_c1 = 0; // first composing char for prev_c
1056#endif
1057#if defined(LINE_ATTR)
1058 int did_line_attr = 0;
1059#endif
1060#ifdef FEAT_TERMINAL
1061 int get_term_attr = FALSE;
1062#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001064#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 // margin columns for the screen line, needed for when 'cursorlineopt'
1066 // contains "screenline"
1067 int left_curline_col = 0;
1068 int right_curline_col = 0;
1069#endif
1070
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1072 int feedback_col = 0;
1073 int feedback_old_attr = -1;
1074#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075
1076#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1077 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001078 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079#endif
1080#ifdef FEAT_CONCEAL
1081 int syntax_flags = 0;
1082 int syntax_seqnr = 0;
1083 int prev_syntax_id = 0;
1084 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1085 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 int did_wcol = FALSE;
1087 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001088# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089# define FIX_FOR_BOGUSCOLS \
1090 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001091 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001092 wlv.vcol -= wlv.vcol_off; \
1093 wlv.vcol_off = 0; \
1094 wlv.col -= wlv.boguscols; \
1095 old_boguscols = wlv.boguscols; \
1096 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 }
1098#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001099# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100#endif
1101
1102 if (startrow > endrow) // past the end already!
1103 return startrow;
1104
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001105 CLEAR_FIELD(wlv);
1106
1107 wlv.lnum = lnum;
1108 wlv.startrow = startrow;
1109 wlv.row = startrow;
1110 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001111 wlv.fromcol = -10;
1112 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001113#ifdef FEAT_LINEBREAK
1114 wlv.vcol_sbr = -1;
1115#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116
1117 if (!number_only)
1118 {
1119 // To speed up the loop below, set extra_check when there is linebreak,
1120 // trailing white space and/or syntax processing to be done.
1121#ifdef FEAT_LINEBREAK
1122 extra_check = wp->w_p_lbr;
1123#endif
1124#ifdef FEAT_SYN_HL
1125 if (syntax_present(wp) && !wp->w_s->b_syn_error
1126# ifdef SYN_TIME_LIMIT
1127 && !wp->w_s->b_syn_slow
1128# endif
1129 )
1130 {
1131 // Prepare for syntax highlighting in this line. When there is an
1132 // error, stop syntax highlighting.
1133 save_did_emsg = did_emsg;
1134 did_emsg = FALSE;
1135 syntax_start(wp, lnum);
1136 if (did_emsg)
1137 wp->w_s->b_syn_error = TRUE;
1138 else
1139 {
1140 did_emsg = save_did_emsg;
1141#ifdef SYN_TIME_LIMIT
1142 if (!wp->w_s->b_syn_slow)
1143#endif
1144 {
1145 has_syntax = TRUE;
1146 extra_check = TRUE;
1147 }
1148 }
1149 }
1150
1151 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001152 wlv.color_cols = wp->w_p_cc_cols;
1153 if (wlv.color_cols != NULL)
1154 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155#endif
1156
1157#ifdef FEAT_TERMINAL
1158 if (term_show_buffer(wp->w_buffer))
1159 {
1160 extra_check = TRUE;
1161 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001162 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 }
1164#endif
1165
1166#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001167 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001168 {
1169 // Prepare for spell checking.
1170 has_spell = TRUE;
1171 extra_check = TRUE;
1172
1173 // Get the start of the next line, so that words that wrap to the
1174 // next line are found too: "et<line-break>al.".
1175 // Trick: skip a few chars for C/shell/Vim comments
1176 nextline[SPWORDLEN] = NUL;
1177 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1178 {
1179 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1180 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1181 }
1182
1183 // When a word wrapped from the previous line the start of the
1184 // current line is valid.
1185 if (lnum == checked_lnum)
1186 cur_checked_col = checked_col;
1187 checked_lnum = 0;
1188
1189 // When there was a sentence end in the previous line may require a
1190 // word starting with capital in this line. In line 1 always check
1191 // the first word.
1192 if (lnum != capcol_lnum)
1193 cap_col = -1;
1194 if (lnum == 1)
1195 cap_col = 0;
1196 capcol_lnum = 0;
1197 }
1198#endif
1199
1200 // handle Visual active in this window
1201 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1202 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001203 pos_T *top, *bot;
1204
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1206 {
1207 // Visual is after curwin->w_cursor
1208 top = &curwin->w_cursor;
1209 bot = &VIsual;
1210 }
1211 else
1212 {
1213 // Visual is before curwin->w_cursor
1214 top = &VIsual;
1215 bot = &curwin->w_cursor;
1216 }
1217 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1218 if (VIsual_mode == Ctrl_V)
1219 {
1220 // block mode
1221 if (lnum_in_visual_area)
1222 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001223 wlv.fromcol = wp->w_old_cursor_fcol;
1224 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 }
1226 }
1227 else
1228 {
1229 // non-block mode
1230 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001231 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 else if (lnum == top->lnum)
1233 {
1234 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001235 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 else
1237 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001238 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001240 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 }
1242 }
1243 if (VIsual_mode != 'V' && lnum == bot->lnum)
1244 {
1245 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1246 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 wlv.fromcol = -10;
1248 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 }
1250 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001251 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 else
1253 {
1254 pos = *bot;
1255 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001256 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1257 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 else
1259 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001260 getvvcol(wp, &pos, NULL, NULL,
1261 (colnr_T *)&wlv.tocol);
1262 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 }
1265 }
1266 }
1267
1268 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001269 if (!highlight_match && lnum == curwin->w_cursor.lnum
1270 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271#ifdef FEAT_GUI
1272 && !gui.in_use
1273#endif
1274 )
1275 noinvcur = TRUE;
1276
1277 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 {
1280 area_highlighting = TRUE;
1281 vi_attr = HL_ATTR(HLF_V);
1282#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1283 if ((clip_star.available && !clip_star.owned
1284 && clip_isautosel_star())
1285 || (clip_plus.available && !clip_plus.owned
1286 && clip_isautosel_plus()))
1287 vi_attr = HL_ATTR(HLF_VNC);
1288#endif
1289 }
1290 }
1291
1292 // handle 'incsearch' and ":s///c" highlighting
1293 else if (highlight_match
1294 && wp == curwin
1295 && lnum >= curwin->w_cursor.lnum
1296 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1297 {
1298 if (lnum == curwin->w_cursor.lnum)
1299 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001300 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001302 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1304 {
1305 pos.lnum = lnum;
1306 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001307 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 }
1309 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001310 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001312 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1313 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001314 area_highlighting = TRUE;
1315 vi_attr = HL_ATTR(HLF_I);
1316 }
1317 }
1318
1319#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001320 wlv.filler_lines = diff_check(wp, lnum);
1321 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001322 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001323 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001326 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001328 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001330 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 }
1332 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001333 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001334 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 area_highlighting = TRUE;
1336 }
1337 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001338 wlv.filler_lines = wp->w_topfill;
1339 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340#endif
1341
1342#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001343 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001344 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001345 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346#endif
1347
1348#ifdef LINE_ATTR
1349# ifdef FEAT_SIGNS
1350 // If this line has a sign with line highlighting set line_attr.
1351 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001352 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353# endif
1354# if defined(FEAT_QUICKFIX)
1355 // Highlight the current line in the quickfix window.
1356 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1357 line_attr = HL_ATTR(HLF_QFL);
1358# endif
1359 if (line_attr != 0)
1360 area_highlighting = TRUE;
1361#endif
1362
1363 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1364 ptr = line;
1365
1366#ifdef FEAT_SPELL
1367 if (has_spell && !number_only)
1368 {
1369 // For checking first word with a capital skip white space.
1370 if (cap_col == 0)
1371 cap_col = getwhitecols(line);
1372
1373 // To be able to spell-check over line boundaries copy the end of the
1374 // current line into nextline[]. Above the start of the next line was
1375 // copied to nextline[SPWORDLEN].
1376 if (nextline[SPWORDLEN] == NUL)
1377 {
1378 // No next line or it is empty.
1379 nextlinecol = MAXCOL;
1380 nextline_idx = 0;
1381 }
1382 else
1383 {
1384 v = (long)STRLEN(line);
1385 if (v < SPWORDLEN)
1386 {
1387 // Short line, use it completely and append the start of the
1388 // next line.
1389 nextlinecol = 0;
1390 mch_memmove(nextline, line, (size_t)v);
1391 STRMOVE(nextline + v, nextline + SPWORDLEN);
1392 nextline_idx = v + 1;
1393 }
1394 else
1395 {
1396 // Long line, use only the last SPWORDLEN bytes.
1397 nextlinecol = v - SPWORDLEN;
1398 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1399 nextline_idx = SPWORDLEN + 1;
1400 }
1401 }
1402 }
1403#endif
1404
1405 if (wp->w_p_list)
1406 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001407 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001408 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001409 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001410 || wp->w_lcs_chars.trail
1411 || wp->w_lcs_chars.lead
1412 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001414
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001416 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001417 {
1418 trailcol = (colnr_T)STRLEN(ptr);
1419 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1420 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001421 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001423 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001424 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001425 {
1426 leadcol = 0;
1427 while (VIM_ISWHITE(ptr[leadcol]))
1428 ++leadcol;
1429 if (ptr[leadcol] == NUL)
1430 // in a line full of spaces all of them are treated as trailing
1431 leadcol = (colnr_T)0;
1432 else
1433 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001434 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001435 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 }
1437
Bram Moolenaard7657e92022-09-20 18:59:30 +01001438 wlv.wcr_attr = get_wcr_attr(wp);
1439 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001441 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 area_highlighting = TRUE;
1443 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001444
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001445#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001446 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001447 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448#endif
1449
1450 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1451 // first character to be displayed.
1452 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001453 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 else
1455 v = wp->w_leftcol;
1456 if (v > 0 && !number_only)
1457 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001458 char_u *prev_ptr = ptr;
1459 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001460 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001462 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001463 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001465 charsize = win_lbr_chartabsize(&cts, NULL);
1466 cts.cts_vcol += charsize;
1467 prev_ptr = cts.cts_ptr;
1468 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001470 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001471 ptr = cts.cts_ptr;
1472 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473
1474 // When:
1475 // - 'cuc' is set, or
1476 // - 'colorcolumn' is set, or
1477 // - 'virtualedit' is set, or
1478 // - the visual mode is active,
1479 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001480 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001482 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483#endif
1484 virtual_active() ||
1485 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001486 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487
1488 // Handle a character that's not completely on the screen: Put ptr at
1489 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001490 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001492 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 ptr = prev_ptr;
1494 // If the character fits on the screen, don't need to skip it.
1495 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001496 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1497 && wlv.col == 0)
1498 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 }
1500
1501 // Adjust for when the inverted text is before the screen,
1502 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001503 if (wlv.tocol <= wlv.vcol)
1504 wlv.fromcol = 0;
1505 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1506 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507
1508#ifdef FEAT_LINEBREAK
1509 // When w_skipcol is non-zero, first line needs 'showbreak'
1510 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001511 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512#endif
1513#ifdef FEAT_SPELL
1514 // When spell checking a word we need to figure out the start of the
1515 // word and if it's badly spelled or not.
1516 if (has_spell)
1517 {
1518 int len;
1519 colnr_T linecol = (colnr_T)(ptr - line);
1520 hlf_T spell_hlf = HLF_COUNT;
1521
1522 pos = wp->w_cursor;
1523 wp->w_cursor.lnum = lnum;
1524 wp->w_cursor.col = linecol;
1525 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1526
1527 // spell_move_to() may call ml_get() and make "line" invalid
1528 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1529 ptr = line + linecol;
1530
1531 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1532 {
1533 // no bad word found at line start, don't check until end of a
1534 // word
1535 spell_hlf = HLF_COUNT;
1536 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1537 }
1538 else
1539 {
1540 // bad word found, use attributes until end of word
1541 word_end = wp->w_cursor.col + len + 1;
1542
1543 // Turn index into actual attributes.
1544 if (spell_hlf != HLF_COUNT)
1545 spell_attr = highlight_attr[spell_hlf];
1546 }
1547 wp->w_cursor = pos;
1548
1549# ifdef FEAT_SYN_HL
1550 // Need to restart syntax highlighting for this line.
1551 if (has_syntax)
1552 syntax_start(wp, lnum);
1553# endif
1554 }
1555#endif
1556 }
1557
1558 // Correct highlighting for cursor that can't be disabled.
1559 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001560 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 {
1562 if (noinvcur)
1563 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001564 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 {
1566 // highlighting starts at cursor, let it start just after the
1567 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001568 fromcol_prev = wlv.fromcol;
1569 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001570 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001571 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 // restart highlighting after the cursor
1573 fromcol_prev = wp->w_virtcol;
1574 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001575 if (wlv.fromcol >= wlv.tocol)
1576 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577 }
1578
1579#ifdef FEAT_SEARCH_EXTRA
1580 if (!number_only)
1581 {
1582 v = (long)(ptr - line);
1583 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1584 &line, &screen_search_hl,
1585 &search_attr);
1586 ptr = line + v; // "line" may have been updated
1587 }
1588#endif
1589
1590#ifdef FEAT_SYN_HL
1591 // Cursor line highlighting for 'cursorline' in the current window.
1592 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1593 {
1594 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001595 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 if (!(wp == curwin && VIsual_active)
1597 && wp->w_p_culopt_flags != CULOPT_NBR)
1598 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001599 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1601
1602 // Only set line_attr here when "screenline" is not present in
1603 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001604 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001606 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001607# ifdef FEAT_SIGNS
1608 // Combine the 'cursorline' and sign highlighting, depending on
1609 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001610 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001611 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001612 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001613 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001614 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001615 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001616 }
1617 else
1618# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001619# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001620 // let the line attribute overrule 'cursorline', otherwise
1621 // it disappears when both have background set;
1622 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001623 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001624# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001625 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001626# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 }
1628 else
1629 {
1630 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1632 }
1633 area_highlighting = TRUE;
1634 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 }
1636#endif
1637
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001638#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639 {
1640 char_u *prop_start;
1641
1642 text_prop_count = get_text_props(wp->w_buffer, lnum,
1643 &prop_start, FALSE);
1644 if (text_prop_count > 0)
1645 {
1646 // Make a copy of the properties, so that they are properly
1647 // aligned.
1648 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1649 if (text_props != NULL)
1650 mch_memmove(text_props, prop_start,
1651 text_prop_count * sizeof(textprop_T));
1652
1653 // Allocate an array for the indexes.
1654 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001655 if (text_prop_idxs == NULL)
1656 VIM_CLEAR(text_props);
1657
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001658 if (text_props != NULL)
1659 {
1660 area_highlighting = TRUE;
1661 extra_check = TRUE;
1662 for (int i = 0; i < text_prop_count; ++i)
1663 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1664 ++wlv.text_prop_above_count;
1665 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666 }
1667 }
1668#endif
1669
Bram Moolenaar1306b362022-08-06 15:59:06 +01001670 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671
1672 // Repeat for the whole displayed line.
1673 for (;;)
1674 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001675 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001677 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001678#endif
1679#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001680 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001682
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001684 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001686#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001687 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001688 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001689 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001690 line_attr = line_attr_save;
1691 }
1692#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001693 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001695 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001696 if (cmdwin_type != 0 && wp == curwin)
1697 {
1698 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001699 wlv.n_extra = 1;
1700 wlv.c_extra = cmdwin_type;
1701 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001702 wlv.char_attr =
1703 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 }
1705 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001709 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001710 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 }
1712#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001714 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001716 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001717 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001719 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 }
1721#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001722 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001724 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001725 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001726 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001729 // Check if 'breakindent' applies and show it.
1730 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1731 if (wlv.n_extra == 0)
1732 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001735 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001737 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001738 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001739 }
1740#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001744 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 }
1746 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001747
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001749 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001750 && wlv.vcol >= left_curline_col
1751 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001753 wlv.cul_attr = HL_ATTR(HLF_CUL);
1754 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 }
1756#endif
1757
1758 // When still displaying '$' of change command, stop at cursor.
1759 // When only displaying the (relative) line number and that's done,
1760 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001761 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001762 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001765 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766#endif
1767 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001769 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 // Pretend we have finished updating the window. Except when
1771 // 'cursorcolumn' is set.
1772#ifdef FEAT_SYN_HL
1773 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001774 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 else
1776#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001777 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 break;
1779 }
1780
Bram Moolenaar1306b362022-08-06 15:59:06 +01001781 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782 {
1783 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001784 if (wlv.vcol == wlv.fromcol
1785 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1786 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787 && (*mb_ptr2cells)(ptr) > 1)
1788 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001789 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001790 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 area_attr = vi_attr; // start highlighting
1792 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001793 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001794 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795 area_attr = 0; // stop highlighting
1796
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001797#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 if (text_props != NULL)
1799 {
1800 int pi;
1801 int bcol = (int)(ptr - line);
1802
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001804# ifdef FEAT_LINEBREAK
1805 && !in_linebreak
1806# endif
1807 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 --bcol; // still working on the previous char, e.g. Tab
1809
1810 // Check if any active property ends.
1811 for (pi = 0; pi < text_props_active; ++pi)
1812 {
1813 int tpi = text_prop_idxs[pi];
1814
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001815 if (text_props[tpi].tp_col != MAXCOL
1816 && bcol >= text_props[tpi].tp_col - 1
1817 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 {
1819 if (pi + 1 < text_props_active)
1820 mch_memmove(text_prop_idxs + pi,
1821 text_prop_idxs + pi + 1,
1822 sizeof(int)
1823 * (text_props_active - (pi + 1)));
1824 --text_props_active;
1825 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001826# ifdef FEAT_LINEBREAK
1827 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001828 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001829 syntax_attr = 0;
1830# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 }
1832 }
1833
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001834# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001836 // not on the next char yet, don't start another prop
1837 --bcol;
1838# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001840 // With 'nowrap' and not in the first screen line only "below"
1841 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001843 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001844 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001845 && (wp->w_p_wrap
1846 || wlv.row == startrow
1847 || (text_props[text_prop_next].tp_flags
1848 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001849 || (bcol == 0 &&
1850 (text_props[text_prop_next].tp_flags
1851 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001852 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001853 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001854 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001855 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1856 {
1857 // first display the '$' after the line
1858 text_prop_follows = TRUE;
1859 break;
1860 }
1861 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001862 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001863 + text_props[text_prop_next].tp_len)
1864 text_prop_idxs[text_props_active++] = text_prop_next;
1865 ++text_prop_next;
1866 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001868 if (wlv.n_extra == 0 || !extra_for_textprop)
1869 {
1870 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001871 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001872 text_prop_flags = 0;
1873 text_prop_type = NULL;
1874 text_prop_id = 0;
1875 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001876 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001877 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001878 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001879 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001880 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001881
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 // Sort the properties on priority and/or starting last.
1883 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001884 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001885 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001886 sort_text_props(wp->w_buffer, text_props,
1887 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888
1889 for (pi = 0; pi < text_props_active; ++pi)
1890 {
1891 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001892 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001894 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001896 if (pt != NULL && (pt->pt_hl_id > 0
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001897 || tp->tp_id < 0) && tp->tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001899 if (pt->pt_hl_id > 0)
1900 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 text_prop_type = pt;
1902 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001903 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001904 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001905 text_prop_flags = pt->pt_flags;
1906 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001907 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 }
1909 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001910 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001911 && -text_prop_id
1912 <= wp->w_buffer->b_textprop_text.ga_len)
1913 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001914 textprop_T *tp = &text_props[used_tpi];
1915 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001916 ->b_textprop_text.ga_data)[
1917 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001918 int above = (tp->tp_flags
1919 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001920
1921 // reset the ID in the copy to avoid it being used
1922 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001923 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001924
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001925 if (p != NULL)
1926 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001927 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001928 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001929 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001930 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001931 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1932 int padding = tp->tp_col == MAXCOL
1933 && tp->tp_len > 1
1934 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001935
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001936 // Insert virtual text before the current
1937 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 wlv.p_extra = p;
1939 wlv.c_extra = NUL;
1940 wlv.c_final = NUL;
1941 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001942 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001943 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001944 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001945 // restore search_attr and area_attr when n_extra
1946 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001947 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001948 saved_area_attr = area_attr;
1949 search_attr = 0;
1950 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001951 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001952 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001953 if (*ptr == NUL)
1954 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001955 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001956#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001957 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001958 {
1959 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001960 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001961 wlv.need_showbreak = FALSE;
1962 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001963 }
1964#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001965 if ((right || above || below || !wrap
1966 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001968 char_u *prev_p_extra = wlv.p_extra;
1969 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001970
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001971 // Take care of padding, right-align and
1972 // truncation.
1973 // Shared with win_lbr_chartabsize(), must do
1974 // exactly the same.
1975 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001976 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001977 wlv.col,
1978 &wlv.n_extra, &wlv.p_extra,
1979 &n_attr, &n_attr_skip);
1980 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001981 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001982 // wlv.p_extra was allocated
1983 vim_free(p_extra_free2);
1984 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001985 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001986
Bram Moolenaara4abe512022-09-15 19:44:09 +01001987 if (lcs_eol_one < 0 && wlv.col
1988 + wlv.n_extra - 2 > wp->w_width)
1989 // don't bail out at end of line
1990 lcs_eol_one = 0;
1991
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001992 // When 'wrap' is off then for "below" we need
1993 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001994 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001995 {
1996 draw_screen_line(wp, &wlv);
1997
1998 // When line got too long for screen break
1999 // here.
2000 if (wlv.row == endrow)
2001 {
2002 ++wlv.row;
2003 break;
2004 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002005 win_line_start(wp, &wlv, TRUE);
2006 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002007 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002008 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002009 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002010
2011 // If another text prop follows the condition below at
2012 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002013 // If this is an "above" text prop and 'nowrap' the we
2014 // must wrap anyway.
2015 text_prop_above = above;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002016 text_prop_follows = other_tpi != -1
2017 && (wp->w_p_wrap
2018 || (text_props[other_tpi].tp_flags
2019 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002020 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002022 else if (text_prop_next < text_prop_count
2023 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002024 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2025 || (!wp->w_p_wrap
2026 && wlv.col == wp->w_width - 1
2027 && (text_props[text_prop_next].tp_flags
2028 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002029 // When at last-but-one character and a text property
2030 // follows after it, we may need to flush the line after
2031 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002032 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002033 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 }
2035#endif
2036
Bram Moolenaare38fc862022-08-11 17:24:50 +01002037#ifdef FEAT_SEARCH_EXTRA
2038 if (wlv.n_extra == 0)
2039 {
2040 // Check for start/end of 'hlsearch' and other matches.
2041 // After end, check for start/end of next match.
2042 // When another match, have to check for start again.
2043 v = (long)(ptr - line);
2044 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2045 &screen_search_hl, &has_match_conc,
2046 &match_conc, did_line_attr, lcs_eol_one,
2047 &on_last_col);
2048 ptr = line + v; // "line" may have been changed
2049 prev_ptr = ptr;
2050
2051 // Do not allow a conceal over EOL otherwise EOL will be missed
2052 // and bad things happen.
2053 if (*ptr == NUL)
2054 has_match_conc = 0;
2055 }
2056#endif
2057
2058#ifdef FEAT_DIFF
2059 if (wlv.diff_hlf != (hlf_T)0)
2060 {
2061 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2062 && wlv.n_extra == 0)
2063 wlv.diff_hlf = HLF_TXD; // changed text
2064 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2065 && wlv.n_extra == 0)
2066 wlv.diff_hlf = HLF_CHD; // changed line
2067 line_attr = HL_ATTR(wlv.diff_hlf);
2068 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2069 && wp->w_p_culopt_flags != CULOPT_NBR
2070 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2071 && wlv.vcol <= right_curline_col)))
2072 line_attr = hl_combine_attr(
2073 line_attr, HL_ATTR(HLF_CUL));
2074 }
2075#endif
2076
Bram Moolenaara74fda62019-10-19 17:38:03 +02002077#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002078 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002079 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002080 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002081# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002082 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002083 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002084# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002085 // Get syntax attribute.
2086 if (has_syntax)
2087 {
2088 // Get the syntax attribute for the character. If there
2089 // is an error, disable syntax highlighting.
2090 save_did_emsg = did_emsg;
2091 did_emsg = FALSE;
2092
2093 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002094 if (v == prev_syntax_col)
2095 // at same column again
2096 syntax_attr = prev_syntax_attr;
2097 else
2098 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002099# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002100 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002101# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002102 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002103# ifdef FEAT_SPELL
2104 has_spell ? &can_spell :
2105# endif
2106 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002107 prev_syntax_col = v;
2108 prev_syntax_attr = syntax_attr;
2109 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002110
Bram Moolenaar34390282019-10-16 14:38:26 +02002111 if (did_emsg)
2112 {
2113 wp->w_s->b_syn_error = TRUE;
2114 has_syntax = FALSE;
2115 syntax_attr = 0;
2116 }
2117 else
2118 did_emsg = save_did_emsg;
2119# ifdef SYN_TIME_LIMIT
2120 if (wp->w_s->b_syn_slow)
2121 has_syntax = FALSE;
2122# endif
2123
2124 // Need to get the line again, a multi-line regexp may
2125 // have made it invalid.
2126 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2127 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002128 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002129# ifdef FEAT_CONCEAL
2130 // no concealing past the end of the line, it interferes
2131 // with line highlighting
2132 if (*ptr == NUL)
2133 syntax_flags = 0;
2134 else
2135 syntax_flags = get_syntax_info(&syntax_seqnr);
2136# endif
2137 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002138 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002139# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002140 // Combine text property highlight into syntax highlight.
2141 if (text_prop_type != NULL)
2142 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002143 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002144 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2145 else
2146 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002147 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002148 }
2149# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002150#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002151
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152 // Decide which of the highlight attributes to use.
2153 attr_pri = TRUE;
2154#ifdef LINE_ATTR
2155 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002156 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002158 if (!highlight_match)
2159 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002160 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002161# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002163# endif
2164 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002166 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002167 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002168# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002169 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002170# endif
2171 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002172 else if (line_attr != 0
2173 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2174 || wlv.vcol < wlv.fromcol
2175 || vcol_prev < fromcol_prev
2176 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 {
2178 // Use line_attr when not in the Visual or 'incsearch' area
2179 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002180# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002181 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002182# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002184# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 attr_pri = FALSE;
2186 }
2187#else
2188 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192#endif
2193 else
2194 {
2195 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002198#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002199 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002200#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002201 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002202#ifdef FEAT_PROP_POPUP
2203 // override with text property highlight when "override" is TRUE
2204 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002205 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002206#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002207 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002208
2209 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002210 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002211 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002212 if (wlv.char_attr == 0)
2213 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002214 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002216 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002217
2218 // Get the next character to put on the screen.
2219
2220 // The "p_extra" points to the extra stuff that is inserted to
2221 // represent special characters (non-printable stuff) and other
2222 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002223 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002224 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2225 // "p_extra[n_extra]".
2226 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002227 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002230 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2232 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2234 if (enc_utf8 && utf_char2len(c) > 1)
2235 {
2236 mb_utf8 = TRUE;
2237 u8cc[0] = 0;
2238 c = 0xc0;
2239 }
2240 else
2241 mb_utf8 = FALSE;
2242 }
2243 else
2244 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002246 if (has_mbyte)
2247 {
2248 mb_c = c;
2249 if (enc_utf8)
2250 {
2251 // If the UTF-8 character is more than one byte:
2252 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002253 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002255 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 mb_l = 1;
2257 else if (mb_l > 1)
2258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002260 mb_utf8 = TRUE;
2261 c = 0xc0;
2262 }
2263 }
2264 else
2265 {
2266 // if this is a DBCS character, put it in "mb_c"
2267 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 mb_l = 1;
2270 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002271 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002272 }
2273 if (mb_l == 0) // at the NUL at end-of-line
2274 mb_l = 1;
2275
2276 // If a double-width char doesn't fit display a '>' in the
2277 // last column.
2278 if ((
2279# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002280 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002281# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002282 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 && (*mb_char2cells)(mb_c) == 2)
2284 {
2285 c = '>';
2286 mb_c = c;
2287 mb_l = 1;
2288 mb_utf8 = FALSE;
2289 multi_attr = HL_ATTR(HLF_AT);
2290#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002291 if (wlv.cul_attr)
2292 multi_attr = hl_combine_attr(
2293 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002295 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002296
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002297 // put the pointer back to output the double-width
2298 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 ++wlv.n_extra;
2300 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 }
2302 else
2303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 wlv.n_extra -= mb_l - 1;
2305 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306 }
2307 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002308 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002311#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002313 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002314 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002315 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002316 if (search_attr == 0)
2317 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002318 if (area_attr == 0 && *ptr != NUL)
2319 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002320 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002321#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 }
2323 else
2324 {
2325#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002326 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002327#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002328 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330 // Get a character from the line itself.
2331 c = *ptr;
2332#ifdef FEAT_LINEBREAK
2333 c0 = *ptr;
2334#endif
2335 if (has_mbyte)
2336 {
2337 mb_c = c;
2338 if (enc_utf8)
2339 {
2340 // If the UTF-8 character is more than one byte: Decode it
2341 // into "mb_c".
2342 mb_l = utfc_ptr2len(ptr);
2343 mb_utf8 = FALSE;
2344 if (mb_l > 1)
2345 {
2346 mb_c = utfc_ptr2char(ptr, u8cc);
2347 // Overlong encoded ASCII or ASCII with composing char
2348 // is displayed normally, except a NUL.
2349 if (mb_c < 0x80)
2350 {
2351 c = mb_c;
2352#ifdef FEAT_LINEBREAK
2353 c0 = mb_c;
2354#endif
2355 }
2356 mb_utf8 = TRUE;
2357
2358 // At start of the line we can have a composing char.
2359 // Draw it as a space with a composing char.
2360 if (utf_iscomposing(mb_c))
2361 {
2362 int i;
2363
2364 for (i = Screen_mco - 1; i > 0; --i)
2365 u8cc[i] = u8cc[i - 1];
2366 u8cc[0] = mb_c;
2367 mb_c = ' ';
2368 }
2369 }
2370
2371 if ((mb_l == 1 && c >= 0x80)
2372 || (mb_l >= 1 && mb_c == 0)
2373 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2374 {
2375 // Illegal UTF-8 byte: display as <xx>.
2376 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002377 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002378# ifdef FEAT_RIGHTLEFT
2379 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002380 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002382 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 c = *wlv.p_extra;
2384 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002386 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2387 wlv.c_extra = NUL;
2388 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389 if (area_attr == 0 && search_attr == 0)
2390 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002392 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002393 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 }
2396 }
2397 else if (mb_l == 0) // at the NUL at end-of-line
2398 mb_l = 1;
2399#ifdef FEAT_ARABIC
2400 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2401 {
2402 // Do Arabic shaping.
2403 int pc, pc1, nc;
2404 int pcc[MAX_MCO];
2405
2406 // The idea of what is the previous and next
2407 // character depends on 'rightleft'.
2408 if (wp->w_p_rl)
2409 {
2410 pc = prev_c;
2411 pc1 = prev_c1;
2412 nc = utf_ptr2char(ptr + mb_l);
2413 prev_c1 = u8cc[0];
2414 }
2415 else
2416 {
2417 pc = utfc_ptr2char(ptr + mb_l, pcc);
2418 nc = prev_c;
2419 pc1 = pcc[0];
2420 }
2421 prev_c = mb_c;
2422
2423 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2424 }
2425 else
2426 prev_c = mb_c;
2427#endif
2428 }
2429 else // enc_dbcs
2430 {
2431 mb_l = MB_BYTE2LEN(c);
2432 if (mb_l == 0) // at the NUL at end-of-line
2433 mb_l = 1;
2434 else if (mb_l > 1)
2435 {
2436 // We assume a second byte below 32 is illegal.
2437 // Hopefully this is OK for all double-byte encodings!
2438 if (ptr[1] >= 32)
2439 mb_c = (c << 8) + ptr[1];
2440 else
2441 {
2442 if (ptr[1] == NUL)
2443 {
2444 // head byte at end of line
2445 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002446 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 }
2448 else
2449 {
2450 // illegal tail byte
2451 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002452 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002454 wlv.p_extra = wlv.extra;
2455 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 wlv.c_extra = NUL;
2457 wlv.c_final = NUL;
2458 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459 if (area_attr == 0 && search_attr == 0)
2460 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002462 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002463 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 // save current attr
2465 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 }
2467 mb_c = c;
2468 }
2469 }
2470 }
2471 // If a double-width char doesn't fit display a '>' in the
2472 // last column; the character is displayed at the start of the
2473 // next line.
2474 if ((
2475# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002476 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002478 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 && (*mb_char2cells)(mb_c) == 2)
2480 {
2481 c = '>';
2482 mb_c = c;
2483 mb_utf8 = FALSE;
2484 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002485 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 // Put pointer back so that the character will be
2487 // displayed at the start of the next line.
2488 --ptr;
2489#ifdef FEAT_CONCEAL
2490 did_decrement_ptr = TRUE;
2491#endif
2492 }
2493 else if (*ptr != NUL)
2494 ptr += mb_l - 1;
2495
2496 // If a double-width char doesn't fit at the left side display
2497 // a '<' in the first column. Don't do this for unprintable
2498 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002499 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002501 wlv.n_extra = 1;
2502 wlv.c_extra = MB_FILLER_CHAR;
2503 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 c = ' ';
2505 if (area_attr == 0 && search_attr == 0)
2506 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002507 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002508 extra_attr = hl_combine_attr(
2509 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 }
2512 mb_c = c;
2513 mb_utf8 = FALSE;
2514 mb_l = 1;
2515 }
2516
2517 }
2518 ++ptr;
2519
2520 if (extra_check)
2521 {
2522#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 // Check spelling (unless at the end of the line).
2524 // Only do this when there is no syntax highlighting, the
2525 // @Spell cluster is not used or the current syntax item
2526 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002527 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 if (has_spell && v >= word_end && v > cur_checked_col)
2529 {
2530 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002531 // do not calculate cap_col at the end of the line or when
2532 // only white space is following
2533 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534# ifdef FEAT_SYN_HL
2535 !has_syntax ||
2536# endif
2537 can_spell))
2538 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002539 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 int len;
2541 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002542
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545
2546 // Use nextline[] if possible, it has the start of the
2547 // next line concatenated.
2548 if ((prev_ptr - line) - nextlinecol >= 0)
2549 p = nextline + (prev_ptr - line) - nextlinecol;
2550 else
2551 p = prev_ptr;
2552 cap_col -= (int)(prev_ptr - line);
2553 len = spell_check(wp, p, &spell_hlf, &cap_col,
2554 nochange);
2555 word_end = v + len;
2556
2557 // In Insert mode only highlight a word that
2558 // doesn't touch the cursor.
2559 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002560 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 && wp->w_cursor.lnum == lnum
2562 && wp->w_cursor.col >=
2563 (colnr_T)(prev_ptr - line)
2564 && wp->w_cursor.col < (colnr_T)word_end)
2565 {
2566 spell_hlf = HLF_COUNT;
2567 spell_redraw_lnum = lnum;
2568 }
2569
2570 if (spell_hlf == HLF_COUNT && p != prev_ptr
2571 && (p - nextline) + len > nextline_idx)
2572 {
2573 // Remember that the good word continues at the
2574 // start of the next line.
2575 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002576 checked_col = (int)((p - nextline)
2577 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 }
2579
2580 // Turn index into actual attributes.
2581 if (spell_hlf != HLF_COUNT)
2582 spell_attr = highlight_attr[spell_hlf];
2583
2584 if (cap_col > 0)
2585 {
2586 if (p != prev_ptr
2587 && (p - nextline) + cap_col >= nextline_idx)
2588 {
2589 // Remember that the word in the next line
2590 // must start with a capital.
2591 capcol_lnum = lnum + 1;
2592 cap_col = (int)((p - nextline) + cap_col
2593 - nextline_idx);
2594 }
2595 else
2596 // Compute the actual column.
2597 cap_col += (int)(prev_ptr - line);
2598 }
2599 }
2600 }
2601 if (spell_attr != 0)
2602 {
2603 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2605 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002607 wlv.char_attr = hl_combine_attr(spell_attr,
2608 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 }
2610#endif
2611#ifdef FEAT_LINEBREAK
2612 // Found last space before word: check for line break.
2613 if (wp->w_p_lbr && c0 == c
2614 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2615 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002616 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2617 : 0;
2618 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002619 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002621 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002622# ifdef FEAT_PROP_POPUP
2623 // do not want virtual text counted here
2624 cts.cts_has_prop_with_text = FALSE;
2625# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002627 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002628
2629 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002630 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002631 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2634 if (wlv.n_extra < 0)
2635 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002636 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002637 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002638 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002639 // line break, but for TABs the highlighting should
2640 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002641 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002642
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002646 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 wp->w_buffer->b_p_vts_array) - 1;
2648# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002649 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002650 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651# endif
2652
Bram Moolenaar1306b362022-08-06 15:59:06 +01002653 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2654 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002655# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002657 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002658# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 if (VIM_ISWHITE(c))
2660 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002661# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 if (c == TAB)
2663 // See "Tab alignment" below.
2664 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002665# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 if (!wp->w_p_list)
2667 c = ' ';
2668 }
2669 }
2670#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002671 in_multispace = c == ' '
2672 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2673 if (!in_multispace)
2674 multispace_pos = 0;
2675
Bram Moolenaareed9d462021-02-15 20:38:25 +01002676 // 'list': Change char 160 to 'nbsp' and space to 'space'
2677 // setting in 'listchars'. But not when the character is
2678 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 if (wp->w_p_list
2680 && ((((c == 160 && mb_l == 1)
2681 || (mb_utf8
2682 && ((mb_c == 160 && mb_l == 2)
2683 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002684 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 || (c == ' '
2686 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002687 && (wp->w_lcs_chars.space
2688 || (in_multispace
2689 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002690 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002691 && ptr - line <= trailcol)))
2692 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002693 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2694 {
2695 c = wp->w_lcs_chars.multispace[multispace_pos++];
2696 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2697 multispace_pos = 0;
2698 }
2699 else
2700 c = (c == ' ') ? wp->w_lcs_chars.space
2701 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 if (area_attr == 0 && search_attr == 0)
2703 {
2704 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002705 extra_attr = hl_combine_attr(wlv.win_attr,
2706 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 }
2709 mb_c = c;
2710 if (enc_utf8 && utf_char2len(c) > 1)
2711 {
2712 mb_utf8 = TRUE;
2713 u8cc[0] = 0;
2714 c = 0xc0;
2715 }
2716 else
2717 mb_utf8 = FALSE;
2718 }
2719
zeertzjq2e7cba32022-06-10 15:30:32 +01002720 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2721 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002723 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2724 && wp->w_lcs_chars.leadmultispace != NULL)
2725 {
2726 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002727 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2728 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002729 multispace_pos = 0;
2730 }
2731
2732 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2733 c = wp->w_lcs_chars.trail;
2734
2735 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2736 c = wp->w_lcs_chars.lead;
2737
zeertzjq2e7cba32022-06-10 15:30:32 +01002738 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002739 c = wp->w_lcs_chars.space;
2740
2741
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 if (!attr_pri)
2743 {
2744 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002745 extra_attr = hl_combine_attr(wlv.win_attr,
2746 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002747 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002748 }
2749 mb_c = c;
2750 if (enc_utf8 && utf_char2len(c) > 1)
2751 {
2752 mb_utf8 = TRUE;
2753 u8cc[0] = 0;
2754 c = 0xc0;
2755 }
2756 else
2757 mb_utf8 = FALSE;
2758 }
2759 }
2760
2761 // Handling of non-printable characters.
2762 if (!vim_isprintc(c))
2763 {
2764 // when getting a character from the file, we may have to
2765 // turn it into something else on the way to putting it
2766 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002767 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 {
2769 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002770 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002772 char_u *sbr = get_showbreak_value(wp);
2773
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774 // only adjust the tab_len, when at the first column
2775 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002776 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002777 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778#endif
2779 // tab amount depends on current column
2780#ifdef FEAT_VARTABS
2781 tab_len = tabstop_padding(vcol_adjusted,
2782 wp->w_buffer->b_p_ts,
2783 wp->w_buffer->b_p_vts_array) - 1;
2784#else
2785 tab_len = (int)wp->w_buffer->b_p_ts
2786 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2787#endif
2788
2789#ifdef FEAT_LINEBREAK
2790 if (!wp->w_p_lbr || !wp->w_p_list)
2791#endif
2792 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002794#ifdef FEAT_LINEBREAK
2795 else
2796 {
2797 char_u *p;
2798 int len;
2799 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002802# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002803 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002805 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002806
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002808 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002809 && old_boguscols > 0
2810 && wlv.n_extra > tab_len)
2811 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002812# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002813 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002815 // If wlv.n_extra > 0, it gives the number of
2816 // chars, to use for a tab, else we need to
2817 // calculate the width for a tab.
2818 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2819 len = tab_len * tab2_len;
2820 if (wp->w_lcs_chars.tab3)
2821 len += mb_char2len(wp->w_lcs_chars.tab3)
2822 - tab2_len;
2823 if (wlv.n_extra > 0)
2824 len += wlv.n_extra - tab_len;
2825 c = wp->w_lcs_chars.tab1;
2826 p = alloc(len + 1);
2827 if (p == NULL)
2828 wlv.n_extra = 0;
2829 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002831 vim_memset(p, ' ', len);
2832 p[len] = NUL;
2833 vim_free(wlv.p_extra_free);
2834 wlv.p_extra_free = p;
2835 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002836 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002837 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002838
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002839 if (*p == NUL)
2840 {
2841 tab_len = i;
2842 break;
2843 }
2844
2845 // if tab3 is given, use it for the last
2846 // char
2847 if (wp->w_lcs_chars.tab3
2848 && i == tab_len - 1)
2849 lcs = wp->w_lcs_chars.tab3;
2850 p += mb_char2bytes(lcs, p);
2851 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002853 }
2854 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002855# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002856 // n_extra will be increased by
2857 // FIX_FOX_BOGUSCOLS macro below, so need to
2858 // adjust for that here
2859 if (wlv.vcol_off > 0)
2860 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002861# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002862 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864 }
2865#endif
2866#ifdef FEAT_CONCEAL
2867 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869
2870 // Tab alignment should be identical regardless of
2871 // 'conceallevel' value. So tab compensates of all
2872 // previous concealed characters, and thus resets
2873 // vcol_off and boguscols accumulated so far in the
2874 // line. Note that the tab can be longer than
2875 // 'tabstop' when there are concealed characters.
2876 FIX_FOR_BOGUSCOLS;
2877
2878 // Make sure, the highlighting for the tab char will be
2879 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002880 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002882 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 tab_len += vc_saved;
2884 }
2885#endif
2886 mb_utf8 = FALSE; // don't draw as UTF-8
2887 if (wp->w_p_list)
2888 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002889 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002890 ? wp->w_lcs_chars.tab3
2891 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892#ifdef FEAT_LINEBREAK
2893 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002894 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 else
2896#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.c_extra = wp->w_lcs_chars.tab2;
2898 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 extra_attr = hl_combine_attr(wlv.win_attr,
2901 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 mb_c = c;
2904 if (enc_utf8 && utf_char2len(c) > 1)
2905 {
2906 mb_utf8 = TRUE;
2907 u8cc[0] = 0;
2908 c = 0xc0;
2909 }
2910 }
2911 else
2912 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 wlv.c_final = NUL;
2914 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 c = ' ';
2916 }
2917 }
2918 else if (c == NUL
2919 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002920 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2921 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 && VIsual_mode != Ctrl_V
2923 && (
2924# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002925 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002927 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928 && !(noinvcur
2929 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002930 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 && lcs_eol_one > 0)
2932 {
2933 // Display a '$' after the line or highlight an extra
2934 // character if the line break is included.
2935#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2936 // For a diff line the highlighting continues after the
2937 // "$".
2938 if (
2939# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002940 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941# ifdef LINE_ATTR
2942 &&
2943# endif
2944# endif
2945# ifdef LINE_ATTR
2946 line_attr == 0
2947# endif
2948 )
2949#endif
2950 {
2951 // In virtualedit, visual selections may extend
2952 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002953 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002954 && wlv.tocol != MAXCOL
2955 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002957 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002959 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2960 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 else
2962 c = ' ';
2963 lcs_eol_one = -1;
2964 --ptr; // put it back at the NUL
2965 if (!attr_pri)
2966 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002967 extra_attr = hl_combine_attr(wlv.win_attr,
2968 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 n_attr = 1;
2970 }
2971 mb_c = c;
2972 if (enc_utf8 && utf_char2len(c) > 1)
2973 {
2974 mb_utf8 = TRUE;
2975 u8cc[0] = 0;
2976 c = 0xc0;
2977 }
2978 else
2979 mb_utf8 = FALSE; // don't draw as UTF-8
2980 }
2981 else if (c != NUL)
2982 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2984 if (wlv.n_extra == 0)
2985 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986#ifdef FEAT_RIGHTLEFT
2987 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 wlv.c_extra = NUL;
2991 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992#ifdef FEAT_LINEBREAK
2993 if (wp->w_p_lbr)
2994 {
2995 char_u *p;
2996
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 c = *wlv.p_extra;
2998 p = alloc(wlv.n_extra + 1);
2999 vim_memset(p, ' ', wlv.n_extra);
3000 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3001 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003002 vim_free(wlv.p_extra_free);
3003 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 }
3005 else
3006#endif
3007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 wlv.n_extra = byte2cells(c) - 1;
3009 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 }
3011 if (!attr_pri)
3012 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003013 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003014 extra_attr = hl_combine_attr(wlv.win_attr,
3015 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 }
3018 mb_utf8 = FALSE; // don't draw as UTF-8
3019 }
3020 else if (VIsual_active
3021 && (VIsual_mode == Ctrl_V
3022 || VIsual_mode == 'v')
3023 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003024 && wlv.tocol != MAXCOL
3025 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 && (
3027#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003028 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003030 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 {
3032 c = ' ';
3033 --ptr; // put it back at the NUL
3034 }
3035#if defined(LINE_ATTR)
3036 else if ((
3037# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039# endif
3040# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003041 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042# endif
3043 line_attr != 0
3044 ) && (
3045# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003046 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003048 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003050 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051# endif
3052 < wp->w_width)))
3053 {
3054 // Highlight until the right side of the window
3055 c = ' ';
3056 --ptr; // put it back at the NUL
3057
3058 // Remember we do the char for line highlighting.
3059 ++did_line_attr;
3060
3061 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003062 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003064 || (wp->w_p_list &&
3065 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003068 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 wlv.diff_hlf = HLF_CHD;
3071 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3075 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003077 || (wlv.vcol >= left_curline_col
3078 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 wlv.char_attr = hl_combine_attr(
3080 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 }
3082 }
3083# endif
3084# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003085 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003087 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003088 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3089 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 if (!wlv.cul_screenline
3092 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003093 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003094 wlv.char_attr = hl_combine_attr(
3095 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 }
3097 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003098 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3099 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100 }
3101# endif
3102 }
3103#endif
3104 }
3105
3106#ifdef FEAT_CONCEAL
3107 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003108 && (wp != curwin || lnum != wp->w_cursor.lnum
3109 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3111 && !(lnum_in_visual_area
3112 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3113 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003115 if (((prev_syntax_id != syntax_seqnr
3116 && (syntax_flags & HL_CONCEAL) != 0)
3117 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003118 && (syn_get_sub_char() != NUL
3119 || (has_match_conc && match_conc)
3120 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 && wp->w_p_cole != 3)
3122 {
3123 // First time at this concealed item: display one
3124 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003125 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 c = match_conc;
3127 else if (syn_get_sub_char() != NUL)
3128 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003129 else if (wp->w_lcs_chars.conceal != NUL)
3130 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 else
3132 c = ' ';
3133
3134 prev_syntax_id = syntax_seqnr;
3135
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 if (wlv.n_extra > 0)
3137 wlv.vcol_off += wlv.n_extra;
3138 wlv.vcol += wlv.n_extra;
3139 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 {
3141# ifdef FEAT_RIGHTLEFT
3142 if (wp->w_p_rl)
3143 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 wlv.col -= wlv.n_extra;
3145 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 }
3147 else
3148# endif
3149 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003150 wlv.boguscols += wlv.n_extra;
3151 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 }
3153 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155 n_attr = 0;
3156 }
3157 else if (n_skip == 0)
3158 {
3159 is_concealing = TRUE;
3160 n_skip = 1;
3161 }
3162 mb_c = c;
3163 if (enc_utf8 && utf_char2len(c) > 1)
3164 {
3165 mb_utf8 = TRUE;
3166 u8cc[0] = 0;
3167 c = 0xc0;
3168 }
3169 else
3170 mb_utf8 = FALSE; // don't draw as UTF-8
3171 }
3172 else
3173 {
3174 prev_syntax_id = 0;
3175 is_concealing = FALSE;
3176 }
3177
3178 if (n_skip > 0 && did_decrement_ptr)
3179 // not showing the '>', put pointer back to avoid getting stuck
3180 ++ptr;
3181
3182#endif // FEAT_CONCEAL
3183 }
3184
3185#ifdef FEAT_CONCEAL
3186 // In the cursor line and we may be concealing characters: correct
3187 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003188 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 && wp == curwin && lnum == wp->w_cursor.lnum
3190 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003191 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003193# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003195 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003197# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 wp->w_wcol = wlv.col - wlv.boguscols;
3199 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 did_wcol = TRUE;
3201 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003202# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003203 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003204# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 }
3206#endif
3207
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003208 // Use "extra_attr", but don't override visual selection highlighting,
3209 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003210 // Don't use "extra_attr" until n_attr_skip is zero.
3211 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003212 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003213 && (!attr_pri
3214#ifdef FEAT_PROP_POPUP
3215 || (text_prop_flags & PT_FLAG_OVERRIDE)
3216#endif
3217 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 {
3219#ifdef LINE_ATTR
3220 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003221 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 else
3223#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003224 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 }
3226
3227#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3228 // XIM don't send preedit_start and preedit_end, but they send
3229 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3230 // im_is_preediting() here.
3231 if (p_imst == IM_ON_THE_SPOT
3232 && xic != NULL
3233 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003234 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 && !p_imdisable
3236 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 {
3239 colnr_T tcol;
3240
3241 if (preedit_end_col == MAXCOL)
3242 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3243 else
3244 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003245 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 {
3247 if (feedback_old_attr < 0)
3248 {
3249 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 wlv.char_attr = im_get_feedback_attr(feedback_col);
3253 if (wlv.char_attr < 0)
3254 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 feedback_col++;
3256 }
3257 else if (feedback_old_attr >= 0)
3258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 feedback_old_attr = -1;
3261 feedback_col = 0;
3262 }
3263 }
3264#endif
3265 // Handle the case where we are in column 0 but not on the first
3266 // character of the line and the user wants us to show us a
3267 // special character (via 'listchars' option "precedes:<char>".
3268 if (lcs_prec_todo != NUL
3269 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003270 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3271 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003273 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003275 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 && c != NUL)
3277 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003278 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279 lcs_prec_todo = NUL;
3280 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3281 {
3282 // Double-width character being overwritten by the "precedes"
3283 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.c_extra = MB_FILLER_CHAR;
3285 wlv.c_final = NUL;
3286 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 }
3290 mb_c = c;
3291 if (enc_utf8 && utf_char2len(c) > 1)
3292 {
3293 mb_utf8 = TRUE;
3294 u8cc[0] = 0;
3295 c = 0xc0;
3296 }
3297 else
3298 mb_utf8 = FALSE; // don't draw as UTF-8
3299 if (!attr_pri)
3300 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 saved_attr3 = wlv.char_attr; // save current attr
3302 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 n_attr3 = 1;
3304 }
3305 }
3306
3307 // At end of the text line or just after the last character.
3308 if ((c == NUL
3309#if defined(LINE_ATTR)
3310 || did_line_attr == 1
3311#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003312 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 {
3314#ifdef FEAT_SEARCH_EXTRA
3315 // flag to indicate whether prevcol equals startcol of search_hl or
3316 // one of the matches
3317 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3318 (long)(ptr - line) - (c == NUL));
3319#endif
3320 // Invert at least one char, used for Visual and empty line or
3321 // highlight match at end of line. If it's beyond the last
3322 // char on the screen, just overwrite that one (tricky!) Not
3323 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003324 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003325 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 && (VIsual_mode != Ctrl_V
3327 || lnum == VIsual.lnum
3328 || lnum == curwin->w_cursor.lnum)
3329 && c == NUL)
3330#ifdef FEAT_SEARCH_EXTRA
3331 // highlight 'hlsearch' match at end of line
3332 || (prevcol_hl_flag
3333# ifdef FEAT_SYN_HL
3334 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3335 && !(wp == curwin && VIsual_active))
3336# endif
3337# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339# endif
3340# if defined(LINE_ATTR)
3341 && did_line_attr <= 1
3342# endif
3343 )
3344#endif
3345 ))
3346 {
3347 int n = 0;
3348
3349#ifdef FEAT_RIGHTLEFT
3350 if (wp->w_p_rl)
3351 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003352 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 n = 1;
3354 }
3355 else
3356#endif
3357 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 n = -1;
3360 }
3361 if (n != 0)
3362 {
3363 // At the window boundary, highlight the last character
3364 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 wlv.off += n;
3366 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 }
3368 else
3369 {
3370 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003371 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003373 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 }
3375#ifdef FEAT_SEARCH_EXTRA
3376 if (area_attr == 0)
3377 {
3378 // Use attributes from match with highest priority among
3379 // 'search_hl' and the match list.
3380 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003381 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 }
3383#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386#ifdef FEAT_RIGHTLEFT
3387 if (wp->w_p_rl)
3388 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003389 --wlv.col;
3390 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003391 }
3392 else
3393#endif
3394 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003395 ++wlv.col;
3396 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003398 ++wlv.vcol;
3399 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003400 }
3401 }
3402
3403 // At end of the text line.
3404 if (c == NUL)
3405 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407
3408 // Update w_cline_height and w_cline_folded if the cursor line was
3409 // updated (saves a call to plines() later).
3410 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3411 {
3412 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003413 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414#ifdef FEAT_FOLDING
3415 curwin->w_cline_folded = FALSE;
3416#endif
3417 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3418 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 break;
3420 }
3421
3422 // Show "extends" character from 'listchars' if beyond the line end and
3423 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003424 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003425 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 && wp->w_p_list
3427 && !wp->w_p_wrap
3428#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003429 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430#endif
3431 && (
3432#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003437 || lcs_eol_one > 0
3438 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003441 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003442 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 mb_c = c;
3444 if (enc_utf8 && utf_char2len(c) > 1)
3445 {
3446 mb_utf8 = TRUE;
3447 u8cc[0] = 0;
3448 c = 0xc0;
3449 }
3450 else
3451 mb_utf8 = FALSE;
3452 }
3453
3454#ifdef FEAT_SYN_HL
3455 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 if (wlv.draw_color_col)
3457 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458
3459 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3460 // highlight the cursor position itself.
3461 // Also highlight the 'colorcolumn' if it is different than
3462 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003463 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3464 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 if (((wlv.draw_state == WL_LINE
3467 || wlv.draw_state == WL_BRI
3468 || wlv.draw_state == WL_SBR)
3469 && !lnum_in_visual_area
3470 && search_attr == 0
3471 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003472# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003473 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003474# endif
3475 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 {
3477 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3478 && lnum != wp->w_cursor.lnum)
3479 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003480 vcol_save_attr = wlv.char_attr;
3481 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3482 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003486 vcol_save_attr = wlv.char_attr;
3487 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 }
3489 }
3490#endif
3491
3492 // Store character to be displayed.
3493 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003494 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 {
3497 // Store the character.
3498#if defined(FEAT_RIGHTLEFT)
3499 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3500 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003501 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 --wlv.off;
3503 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 }
3505#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 if (enc_dbcs == DBCS_JPNU)
3508 {
3509 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003510 ScreenLines[wlv.off] = 0x8e;
3511 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512 }
3513 else if (enc_utf8)
3514 {
3515 if (mb_utf8)
3516 {
3517 int i;
3518
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003521 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 for (i = 0; i < Screen_mco; ++i)
3523 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 if (u8cc[i] == 0)
3526 break;
3527 }
3528 }
3529 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 }
3532 if (multi_attr)
3533 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003534 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535 multi_attr = 0;
3536 }
3537 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003541
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3543 {
3544 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 ++wlv.off;
3546 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 if (enc_utf8)
3548 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003549 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 else
3551 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003555 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556#endif
3557 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003558 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003559 // When "wlv.tocol" is halfway a character, set it to the end
3560 // of the character, otherwise highlighting won't stop.
3561 if (wlv.tocol == wlv.vcol)
3562 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003563
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566#ifdef FEAT_RIGHTLEFT
3567 if (wp->w_p_rl)
3568 {
3569 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 --wlv.off;
3571 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573#endif
3574 }
3575#ifdef FEAT_RIGHTLEFT
3576 if (wp->w_p_rl)
3577 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 --wlv.off;
3579 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 }
3581 else
3582#endif
3583 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 ++wlv.off;
3585 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 }
3587 }
3588#ifdef FEAT_CONCEAL
3589 else if (wp->w_p_cole > 0 && is_concealing)
3590 {
3591 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 if (wlv.n_extra > 0)
3594 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 if (wp->w_p_wrap)
3596 {
3597 // Special voodoo required if 'wrap' is on.
3598 //
3599 // Advance the column indicator to force the line
3600 // drawing to wrap early. This will make the line
3601 // take up the same screen space when parts are concealed,
3602 // so that cursor line computations aren't messed up.
3603 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003604 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 // trailing junk to be written out of the screen line
3606 // we are building, 'boguscols' keeps track of the number
3607 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003608 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003610 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611# ifdef FEAT_RIGHTLEFT
3612 if (wp->w_p_rl)
3613 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003614 wlv.col -= wlv.n_extra;
3615 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 }
3617 else
3618# endif
3619 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003620 wlv.col += wlv.n_extra;
3621 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 n_attr = 0;
3625 }
3626
3627
3628 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3629 {
3630 // Need to fill two screen columns.
3631# ifdef FEAT_RIGHTLEFT
3632 if (wp->w_p_rl)
3633 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 --wlv.boguscols;
3635 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 }
3637 else
3638# endif
3639 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ++wlv.boguscols;
3641 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643 }
3644
3645# ifdef FEAT_RIGHTLEFT
3646 if (wp->w_p_rl)
3647 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 --wlv.boguscols;
3649 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 }
3651 else
3652# endif
3653 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003654 ++wlv.boguscols;
3655 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 }
3657 }
3658 else
3659 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 wlv.vcol += wlv.n_extra;
3663 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003664 n_attr = 0;
3665 }
3666 }
3667
3668 }
3669#endif // FEAT_CONCEAL
3670 else
3671 --n_skip;
3672
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003673 // Only advance the "wlv.vcol" when after the 'number' or
3674 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003675 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003677 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678#endif
3679 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003680 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681
3682#ifdef FEAT_SYN_HL
3683 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003684 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685#endif
3686
3687 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003688 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3689 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690
3691 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003692 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003693 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003694 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003695 if (n_attr_skip > 0)
3696 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697
3698 // At end of screen line and there is more to come: Display the line
3699 // so far. If there is no more to display it is caught above.
3700 if ((
3701#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003704 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003705 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003706 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003708 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003710#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003711 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003712#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003713 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003714 && wlv.p_extra != at_end_str)
3715 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3716 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 )
3718 {
3719#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003720 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003721 wlv_screen_line(wp, &wlv, FALSE);
3722 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003725 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 ++wlv.row;
3728 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729
3730 // When not wrapping and finished diff lines, or when displayed
3731 // '$' and highlighting until last column, break here.
3732 if ((!wp->w_p_wrap
3733#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003734 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003735#endif
3736#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003737 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738#endif
3739 ) || lcs_eol_one == -1)
3740 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003741#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003742 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003743 {
3744 // do not output more of the line, only the "below" prop
3745 ptr += STRLEN(ptr);
3746# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003747 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003748# endif
3749 }
3750#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751
3752 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003753 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003755 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756#endif
3757 )
3758 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3760 draw_vsep_win(wp, wlv.row);
3761 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762 }
3763
3764 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 break;
3769 }
3770
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003771 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003773 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003775#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003776 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003777#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 && wp->w_width == Columns)
3779 {
3780 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782
3783 // Special trick to make copy/paste of wrapped lines work with
3784 // xterm/screen: write an extra character beyond the end of
3785 // the line. This will work with all terminal types
3786 // (regardless of the xn,am settings).
3787 // Only do this on a fast tty.
3788 // Only do this if the cursor is on the current line
3789 // (something has been written in it).
3790 // Don't do this for the GUI.
3791 // Don't do this for double-width characters.
3792 // Don't do this for a window not at the right screen border.
3793 if (p_tf
3794#ifdef FEAT_GUI
3795 && !gui.in_use
3796#endif
3797 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3799 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003801 || (*mb_off2cells)(
3802 LineOffset[wlv.screen_row - 1]
3803 + (int)Columns - 2,
3804 LineOffset[wlv.screen_row]
3805 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 {
3807 // First make sure we are at the end of the screen line,
3808 // then output the same character again to let the
3809 // terminal know about the wrap. If the terminal doesn't
3810 // auto-wrap, we overwrite the character.
3811 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003812 screen_char(LineOffset[wlv.screen_row - 1]
3813 + (unsigned)Columns - 1,
3814 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815
3816 // When there is a multi-byte character, just output a
3817 // space to keep it simple.
3818 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 out_char(' ');
3821 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003822 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 + (Columns - 1)]);
3824 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003825 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 screen_start(); // don't know where cursor is now
3827 }
3828 }
3829
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831
Bram Moolenaareed9d462021-02-15 20:38:25 +01003832 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003834 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003836 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003838 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003839 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840#endif
3841#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003842 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843 // When the filler lines are actually below the last line of the
3844 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003845 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846 break;
3847#endif
3848 }
3849
3850 } // for every character in the line
3851
3852#ifdef FEAT_SPELL
3853 // After an empty line check first word for capital.
3854 if (*skipwhite(line) == NUL)
3855 {
3856 capcol_lnum = lnum + 1;
3857 cap_col = 0;
3858 }
3859#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003860#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 vim_free(text_props);
3862 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003863 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864#endif
3865
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003866 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868}