blob: c1565cf23a9d5da95b32d0d4e3f242b9fa088678 [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,
615 int vcol, // current screen column
616 int *n_extra, // nr of bytes for virtual text
617 char_u **p_extra, // virtual text
618 int *n_attr, // attribute cells, NULL if not used
619 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200620{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100621 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100622 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100623 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
624 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
625 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
626 ? tp->tp_len - 1 : 0;
627 int col_with_padding = vcol + (below ? 0 : padding);
628 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100629 int before = room; // spaces before the text
630 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int n_used = *n_extra;
632 char_u *l = NULL;
633 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100635 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100638 {
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100639 int col_off = win_col_off(wp) + win_col_off2(wp);
640 int skip_add = 0;
641
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100642 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100643 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100645 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100646 }
647 else
648 {
649 // Right-align: fill with before
650 if (right)
651 before -= cells;
652 if (before < 0
653 || !(right || below)
654 || (below
655 ? (col_with_padding == 0 || !wp->w_p_wrap)
656 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100657 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
659 {
660 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 before = wp->w_width - col_off - strsize + room;
662 if (before < 0)
663 before = 0;
664 else
665 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100666 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100671 else if (below && before > 0)
672 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100673 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100674 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100675
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 // With 'nowrap' add one to show the "extends" character if needed (it
677 // doesn't show if the text just fits).
678 if (!wp->w_p_wrap
679 && n_used < *n_extra
680 && wp->w_lcs_chars.ext != NUL
681 && wp->w_p_list)
682 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100683 if (!wp->w_p_wrap && below && padding > 0)
684 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100685
686 // add 1 for NUL, 2 for when '…' is used
687 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 if (n_attr == NULL || l != NULL)
690 {
691 int off = 0;
692
693 if (n_attr != NULL)
694 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100695 vim_memset(l, ' ', before);
696 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100697 if (padding > 0)
698 {
699 vim_memset(l + off, ' ', padding);
700 off += padding;
701 }
702 vim_strncpy(l + off, *p_extra, n_used);
703 off += n_used;
704 }
705 else
706 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100707 off = before + after + padding + n_used;
708 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 }
710 if (n_attr != NULL)
711 {
712 if (n_used < *n_extra && wp->w_p_wrap)
713 {
714 char_u *lp = l + off - 1;
715
716 if (has_mbyte)
717 {
718 // change last character to '…'
719 lp -= (*mb_head_off)(l, lp);
720 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100721 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 }
723 else
724 // change last character to '>'
725 *lp = '>';
726 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100727 else if (after > 0)
728 {
729 vim_memset(l + off, ' ', after);
730 l[off + after] = NUL;
731 }
732
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100733 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100734 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100735 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100736 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100737 *n_attr -= padding + after;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100738 *n_attr_skip = before + padding + skip_add;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 }
740 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100741 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100742
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100743 if (n_attr == NULL)
744 return cells;
745 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200746}
747#endif
748
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100749/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100750 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100751 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
752 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100753 */
754 static void
755wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
756{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100757 if (wlv->row == 0 && wp->w_skipcol > 0
758#if defined(FEAT_LINEBREAK)
759 && *get_showbreak_value(wp) == NUL
760#endif
761 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100762 {
763 int off = (int)(current_ScreenLine - ScreenLines);
764
765 for (int i = 0; i < 3; ++i)
766 {
767 ScreenLines[off] = '<';
768 if (enc_utf8)
769 ScreenLinesUC[off] = 0;
770 ScreenAttrs[off] = HL_ATTR(HLF_AT);
771 ++off;
772 }
773 }
774
775 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
776 negative_width ? -wp->w_width : wp->w_width,
777 wlv->screen_line_flags);
778}
779
780/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100781 * Called when finished with the line: draw the screen line and handle any
782 * highlighting until the right of the window.
783 */
784 static void
785draw_screen_line(win_T *wp, winlinevars_T *wlv)
786{
787#ifdef FEAT_SYN_HL
788 long v;
789
790 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
791 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100792 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100793 else
794 v = wp->w_leftcol;
795
796 // check if line ends before left margin
797 if (wlv->vcol < v + wlv->col - win_col_off(wp))
798 wlv->vcol = v + wlv->col - win_col_off(wp);
799# ifdef FEAT_CONCEAL
800 // Get rid of the boguscols now, we want to draw until the right
801 // edge for 'cursorcolumn'.
802 wlv->col -= wlv->boguscols;
803 wlv->boguscols = 0;
804# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
805# else
806# define VCOL_HLC (wlv->vcol)
807# endif
808
809 if (wlv->draw_color_col)
810 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
811
812 if (((wp->w_p_cuc
813 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
814 && (int)wp->w_virtcol <
815 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
816 && wlv->lnum != wp->w_cursor.lnum)
817 || wlv->draw_color_col
818 || wlv->win_attr != 0)
819# ifdef FEAT_RIGHTLEFT
820 && !wp->w_p_rl
821# endif
822 )
823 {
824 int rightmost_vcol = 0;
825 int i;
826
827 if (wp->w_p_cuc)
828 rightmost_vcol = wp->w_virtcol;
829 if (wlv->draw_color_col)
830 // determine rightmost colorcolumn to possibly draw
831 for (i = 0; wlv->color_cols[i] >= 0; ++i)
832 if (rightmost_vcol < wlv->color_cols[i])
833 rightmost_vcol = wlv->color_cols[i];
834
835 while (wlv->col < wp->w_width)
836 {
837 ScreenLines[wlv->off] = ' ';
838 if (enc_utf8)
839 ScreenLinesUC[wlv->off] = 0;
840 ScreenCols[wlv->off] = MAXCOL;
841 ++wlv->col;
842 if (wlv->draw_color_col)
843 wlv->draw_color_col = advance_color_col(
844 VCOL_HLC, &wlv->color_cols);
845
846 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
847 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
848 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
849 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
850 else
851 ScreenAttrs[wlv->off++] = wlv->win_attr;
852
853 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
854 break;
855
856 ++wlv->vcol;
857 }
858 }
859#endif
860
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100861 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100862 ++wlv->row;
863 ++wlv->screen_row;
864}
865#undef VCOL_HLC
866
867/*
868 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100869 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870 */
871 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100872win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100873{
874 wlv->col = 0;
875 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
876
877#ifdef FEAT_RIGHTLEFT
878 if (wp->w_p_rl)
879 {
880 // Rightleft window: process the text in the normal direction, but put
881 // it in current_ScreenLine[] from right to left. Start at the
882 // rightmost column of the window.
883 wlv->col = wp->w_width - 1;
884 wlv->off += wlv->col;
885 wlv->screen_line_flags |= SLF_RIGHTLEFT;
886 }
887#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100888 if (save_extra)
889 {
890 // reset the drawing state for the start of a wrapped line
891 wlv->draw_state = WL_START;
892 wlv->saved_n_extra = wlv->n_extra;
893 wlv->saved_p_extra = wlv->p_extra;
894 wlv->saved_c_extra = wlv->c_extra;
895 wlv->saved_c_final = wlv->c_final;
896#ifdef FEAT_SYN_HL
897 if (!(wlv->cul_screenline
898# ifdef FEAT_DIFF
899 && wlv->diff_hlf == (hlf_T)0
900# endif
901 ))
902 wlv->saved_char_attr = wlv->char_attr;
903 else
904#endif
905 wlv->saved_char_attr = 0;
906 wlv->n_extra = 0;
907 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100908}
909
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200910/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100911 * Called when wlv->draw_state is set to WL_LINE.
912 */
913 static void
914win_line_continue(winlinevars_T *wlv)
915{
916 if (wlv->saved_n_extra > 0)
917 {
918 // Continue item from end of wrapped line.
919 wlv->n_extra = wlv->saved_n_extra;
920 wlv->c_extra = wlv->saved_c_extra;
921 wlv->c_final = wlv->saved_c_final;
922 wlv->p_extra = wlv->saved_p_extra;
923 wlv->char_attr = wlv->saved_char_attr;
924 }
925 else
926 wlv->char_attr = wlv->win_attr;
927}
928
929/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200930 * Display line "lnum" of window 'wp' on the screen.
931 * Start at row "startrow", stop when "endrow" is reached.
932 * wp->w_virtcol needs to be valid.
933 *
934 * Return the number of last row the line occupies.
935 */
936 int
937win_line(
938 win_T *wp,
939 linenr_T lnum,
940 int startrow,
941 int endrow,
942 int nochange UNUSED, // not updating for changed text
943 int number_only) // only update the number column
944{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 winlinevars_T wlv; // variables passed between functions
946
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100948 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949 char_u *line; // current line
950 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200951
Bram Moolenaar1306b362022-08-06 15:59:06 +0100952#ifdef FEAT_PROP_POPUP
953 char_u *p_extra_free2 = NULL; // another p_extra to be freed
954#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200955 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000956#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000957 int in_linebreak = FALSE; // n_extra set for showing linebreak
958#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200959 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100960 // displaying eol at end-of-line
961 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000962 int lcs_prec_todo = wp->w_lcs_chars.prec;
963 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100965 int n_attr = 0; // chars with special attr
966 int n_attr_skip = 0; // chars to skip before using extra_attr
967 int saved_attr2 = 0; // char_attr saved for n_attr
968 int n_attr3 = 0; // chars with overruling special attr
969 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200970
971 int n_skip = 0; // nr of chars to skip for 'nowrap'
972
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973 int fromcol_prev = -2; // start of inverting after cursor
974 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975 int lnum_in_visual_area = FALSE;
976 pos_T pos;
977 long v;
978
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 int attr_pri = FALSE; // char_attr has priority
980 int area_highlighting = FALSE; // Visual or incsearch highlighting
981 // in this line
982 int vi_attr = 0; // attributes for Visual and incsearch
983 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 int area_attr = 0; // attributes desired by highlighting
985 int search_attr = 0; // attributes desired by 'hlsearch'
986#ifdef FEAT_SYN_HL
987 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
988 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200989 int prev_syntax_col = -1; // column of prev_syntax_attr
990 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 int has_syntax = FALSE; // this buffer has syntax highl.
992 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200993#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100994#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200995 int text_prop_count;
996 int text_prop_next = 0; // next text property to use
997 textprop_T *text_props = NULL;
998 int *text_prop_idxs = NULL;
999 int text_props_active = 0;
1000 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001001 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001003 int text_prop_attr_comb = 0; // text_prop_attr combined with
1004 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001005 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001006 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001007 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001008 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001009 int saved_search_attr = 0; // search_attr to be used when n_extra
1010 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001011 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001012#endif
1013#ifdef FEAT_SPELL
1014 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001015 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001016# define SPWORDLEN 150
1017 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1018 int nextlinecol = 0; // column where nextline[] starts
1019 int nextline_idx = 0; // index in nextline[] where next line
1020 // starts
1021 int spell_attr = 0; // attributes desired by spelling
1022 int word_end = 0; // last byte with same spell_attr
1023 static linenr_T checked_lnum = 0; // line number for "checked_col"
1024 static int checked_col = 0; // column in "checked_lnum" up to which
1025 // there are no spell errors
1026 static int cap_col = -1; // column to check for Cap word
1027 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1028 int cur_checked_col = 0; // checked column for current line
1029#endif
1030 int extra_check = 0; // has extra highlighting
1031 int multi_attr = 0; // attributes desired by multibyte
1032 int mb_l = 1; // multi-byte byte length
1033 int mb_c = 0; // decoded multi-byte character
1034 int mb_utf8 = FALSE; // screen char is UTF-8 char
1035 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037 int change_start = MAXCOL; // first col of changed area
1038 int change_end = -1; // last col of changed area
1039#endif
1040 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001041 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001042 int in_multispace = FALSE; // in multiple consecutive spaces
1043 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1045 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1046# define LINE_ATTR
1047 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001048 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001051 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052#ifdef FEAT_ARABIC
1053 int prev_c = 0; // previous Arabic character
1054 int prev_c1 = 0; // first composing char for prev_c
1055#endif
1056#if defined(LINE_ATTR)
1057 int did_line_attr = 0;
1058#endif
1059#ifdef FEAT_TERMINAL
1060 int get_term_attr = FALSE;
1061#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001063#ifdef FEAT_SYN_HL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064 // margin columns for the screen line, needed for when 'cursorlineopt'
1065 // contains "screenline"
1066 int left_curline_col = 0;
1067 int right_curline_col = 0;
1068#endif
1069
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1071 int feedback_col = 0;
1072 int feedback_old_attr = -1;
1073#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074
1075#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1076 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001077 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078#endif
1079#ifdef FEAT_CONCEAL
1080 int syntax_flags = 0;
1081 int syntax_seqnr = 0;
1082 int prev_syntax_id = 0;
1083 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1084 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 int did_wcol = FALSE;
1086 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001087# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088# define FIX_FOR_BOGUSCOLS \
1089 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001090 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001091 wlv.vcol -= wlv.vcol_off; \
1092 wlv.vcol_off = 0; \
1093 wlv.col -= wlv.boguscols; \
1094 old_boguscols = wlv.boguscols; \
1095 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096 }
1097#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001098# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099#endif
1100
1101 if (startrow > endrow) // past the end already!
1102 return startrow;
1103
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104 CLEAR_FIELD(wlv);
1105
1106 wlv.lnum = lnum;
1107 wlv.startrow = startrow;
1108 wlv.row = startrow;
1109 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001110 wlv.fromcol = -10;
1111 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001112#ifdef FEAT_LINEBREAK
1113 wlv.vcol_sbr = -1;
1114#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115
1116 if (!number_only)
1117 {
1118 // To speed up the loop below, set extra_check when there is linebreak,
1119 // trailing white space and/or syntax processing to be done.
1120#ifdef FEAT_LINEBREAK
1121 extra_check = wp->w_p_lbr;
1122#endif
1123#ifdef FEAT_SYN_HL
1124 if (syntax_present(wp) && !wp->w_s->b_syn_error
1125# ifdef SYN_TIME_LIMIT
1126 && !wp->w_s->b_syn_slow
1127# endif
1128 )
1129 {
1130 // Prepare for syntax highlighting in this line. When there is an
1131 // error, stop syntax highlighting.
1132 save_did_emsg = did_emsg;
1133 did_emsg = FALSE;
1134 syntax_start(wp, lnum);
1135 if (did_emsg)
1136 wp->w_s->b_syn_error = TRUE;
1137 else
1138 {
1139 did_emsg = save_did_emsg;
1140#ifdef SYN_TIME_LIMIT
1141 if (!wp->w_s->b_syn_slow)
1142#endif
1143 {
1144 has_syntax = TRUE;
1145 extra_check = TRUE;
1146 }
1147 }
1148 }
1149
1150 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001151 wlv.color_cols = wp->w_p_cc_cols;
1152 if (wlv.color_cols != NULL)
1153 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154#endif
1155
1156#ifdef FEAT_TERMINAL
1157 if (term_show_buffer(wp->w_buffer))
1158 {
1159 extra_check = TRUE;
1160 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001161 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 }
1163#endif
1164
1165#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001166 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 {
1168 // Prepare for spell checking.
1169 has_spell = TRUE;
1170 extra_check = TRUE;
1171
1172 // Get the start of the next line, so that words that wrap to the
1173 // next line are found too: "et<line-break>al.".
1174 // Trick: skip a few chars for C/shell/Vim comments
1175 nextline[SPWORDLEN] = NUL;
1176 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1177 {
1178 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1179 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1180 }
1181
1182 // When a word wrapped from the previous line the start of the
1183 // current line is valid.
1184 if (lnum == checked_lnum)
1185 cur_checked_col = checked_col;
1186 checked_lnum = 0;
1187
1188 // When there was a sentence end in the previous line may require a
1189 // word starting with capital in this line. In line 1 always check
1190 // the first word.
1191 if (lnum != capcol_lnum)
1192 cap_col = -1;
1193 if (lnum == 1)
1194 cap_col = 0;
1195 capcol_lnum = 0;
1196 }
1197#endif
1198
1199 // handle Visual active in this window
1200 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1201 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001202 pos_T *top, *bot;
1203
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1205 {
1206 // Visual is after curwin->w_cursor
1207 top = &curwin->w_cursor;
1208 bot = &VIsual;
1209 }
1210 else
1211 {
1212 // Visual is before curwin->w_cursor
1213 top = &VIsual;
1214 bot = &curwin->w_cursor;
1215 }
1216 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1217 if (VIsual_mode == Ctrl_V)
1218 {
1219 // block mode
1220 if (lnum_in_visual_area)
1221 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001222 wlv.fromcol = wp->w_old_cursor_fcol;
1223 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 }
1225 }
1226 else
1227 {
1228 // non-block mode
1229 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001230 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 else if (lnum == top->lnum)
1232 {
1233 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001234 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235 else
1236 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001237 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240 }
1241 }
1242 if (VIsual_mode != 'V' && lnum == bot->lnum)
1243 {
1244 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1245 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001246 wlv.fromcol = -10;
1247 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 }
1249 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001250 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 else
1252 {
1253 pos = *bot;
1254 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001255 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1256 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 else
1258 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001259 getvvcol(wp, &pos, NULL, NULL,
1260 (colnr_T *)&wlv.tocol);
1261 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 }
1263 }
1264 }
1265 }
1266
1267 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001268 if (!highlight_match && lnum == curwin->w_cursor.lnum
1269 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270#ifdef FEAT_GUI
1271 && !gui.in_use
1272#endif
1273 )
1274 noinvcur = TRUE;
1275
1276 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001277 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 {
1279 area_highlighting = TRUE;
1280 vi_attr = HL_ATTR(HLF_V);
1281#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1282 if ((clip_star.available && !clip_star.owned
1283 && clip_isautosel_star())
1284 || (clip_plus.available && !clip_plus.owned
1285 && clip_isautosel_plus()))
1286 vi_attr = HL_ATTR(HLF_VNC);
1287#endif
1288 }
1289 }
1290
1291 // handle 'incsearch' and ":s///c" highlighting
1292 else if (highlight_match
1293 && wp == curwin
1294 && lnum >= curwin->w_cursor.lnum
1295 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1296 {
1297 if (lnum == curwin->w_cursor.lnum)
1298 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001299 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001301 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1303 {
1304 pos.lnum = lnum;
1305 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001306 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 }
1308 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001309 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001311 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1312 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 area_highlighting = TRUE;
1314 vi_attr = HL_ATTR(HLF_I);
1315 }
1316 }
1317
1318#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001319 wlv.filler_lines = diff_check(wp, lnum);
1320 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001322 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 {
1324 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001325 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001327 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001329 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 }
1331 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001332 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001333 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 area_highlighting = TRUE;
1335 }
1336 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001337 wlv.filler_lines = wp->w_topfill;
1338 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339#endif
1340
1341#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001342 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001343 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001344 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345#endif
1346
1347#ifdef LINE_ATTR
1348# ifdef FEAT_SIGNS
1349 // If this line has a sign with line highlighting set line_attr.
1350 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001351 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352# endif
1353# if defined(FEAT_QUICKFIX)
1354 // Highlight the current line in the quickfix window.
1355 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1356 line_attr = HL_ATTR(HLF_QFL);
1357# endif
1358 if (line_attr != 0)
1359 area_highlighting = TRUE;
1360#endif
1361
1362 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1363 ptr = line;
1364
1365#ifdef FEAT_SPELL
1366 if (has_spell && !number_only)
1367 {
1368 // For checking first word with a capital skip white space.
1369 if (cap_col == 0)
1370 cap_col = getwhitecols(line);
1371
1372 // To be able to spell-check over line boundaries copy the end of the
1373 // current line into nextline[]. Above the start of the next line was
1374 // copied to nextline[SPWORDLEN].
1375 if (nextline[SPWORDLEN] == NUL)
1376 {
1377 // No next line or it is empty.
1378 nextlinecol = MAXCOL;
1379 nextline_idx = 0;
1380 }
1381 else
1382 {
1383 v = (long)STRLEN(line);
1384 if (v < SPWORDLEN)
1385 {
1386 // Short line, use it completely and append the start of the
1387 // next line.
1388 nextlinecol = 0;
1389 mch_memmove(nextline, line, (size_t)v);
1390 STRMOVE(nextline + v, nextline + SPWORDLEN);
1391 nextline_idx = v + 1;
1392 }
1393 else
1394 {
1395 // Long line, use only the last SPWORDLEN bytes.
1396 nextlinecol = v - SPWORDLEN;
1397 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1398 nextline_idx = SPWORDLEN + 1;
1399 }
1400 }
1401 }
1402#endif
1403
1404 if (wp->w_p_list)
1405 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001406 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001407 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001408 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001409 || wp->w_lcs_chars.trail
1410 || wp->w_lcs_chars.lead
1411 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001413
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001415 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 {
1417 trailcol = (colnr_T)STRLEN(ptr);
1418 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1419 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001420 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001422 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001423 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001424 {
1425 leadcol = 0;
1426 while (VIM_ISWHITE(ptr[leadcol]))
1427 ++leadcol;
1428 if (ptr[leadcol] == NUL)
1429 // in a line full of spaces all of them are treated as trailing
1430 leadcol = (colnr_T)0;
1431 else
1432 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001433 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001434 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001435 }
1436
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 wlv.wcr_attr = get_wcr_attr(wp);
1438 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001440 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441 area_highlighting = TRUE;
1442 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001443
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001444#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001446 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447#endif
1448
1449 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1450 // first character to be displayed.
1451 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001452 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 else
1454 v = wp->w_leftcol;
1455 if (v > 0 && !number_only)
1456 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001457 char_u *prev_ptr = ptr;
1458 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001459 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001461 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001462 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001464 charsize = win_lbr_chartabsize(&cts, NULL);
1465 cts.cts_vcol += charsize;
1466 prev_ptr = cts.cts_ptr;
1467 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001469 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001470 ptr = cts.cts_ptr;
1471 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472
1473 // When:
1474 // - 'cuc' is set, or
1475 // - 'colorcolumn' is set, or
1476 // - 'virtualedit' is set, or
1477 // - the visual mode is active,
1478 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001479 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001481 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482#endif
1483 virtual_active() ||
1484 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001485 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486
1487 // Handle a character that's not completely on the screen: Put ptr at
1488 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001489 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001491 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 ptr = prev_ptr;
1493 // If the character fits on the screen, don't need to skip it.
1494 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001495 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1496 && wlv.col == 0)
1497 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 }
1499
1500 // Adjust for when the inverted text is before the screen,
1501 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001502 if (wlv.tocol <= wlv.vcol)
1503 wlv.fromcol = 0;
1504 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1505 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506
1507#ifdef FEAT_LINEBREAK
1508 // When w_skipcol is non-zero, first line needs 'showbreak'
1509 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001510 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511#endif
1512#ifdef FEAT_SPELL
1513 // When spell checking a word we need to figure out the start of the
1514 // word and if it's badly spelled or not.
1515 if (has_spell)
1516 {
1517 int len;
1518 colnr_T linecol = (colnr_T)(ptr - line);
1519 hlf_T spell_hlf = HLF_COUNT;
1520
1521 pos = wp->w_cursor;
1522 wp->w_cursor.lnum = lnum;
1523 wp->w_cursor.col = linecol;
1524 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1525
1526 // spell_move_to() may call ml_get() and make "line" invalid
1527 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1528 ptr = line + linecol;
1529
1530 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1531 {
1532 // no bad word found at line start, don't check until end of a
1533 // word
1534 spell_hlf = HLF_COUNT;
1535 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1536 }
1537 else
1538 {
1539 // bad word found, use attributes until end of word
1540 word_end = wp->w_cursor.col + len + 1;
1541
1542 // Turn index into actual attributes.
1543 if (spell_hlf != HLF_COUNT)
1544 spell_attr = highlight_attr[spell_hlf];
1545 }
1546 wp->w_cursor = pos;
1547
1548# ifdef FEAT_SYN_HL
1549 // Need to restart syntax highlighting for this line.
1550 if (has_syntax)
1551 syntax_start(wp, lnum);
1552# endif
1553 }
1554#endif
1555 }
1556
1557 // Correct highlighting for cursor that can't be disabled.
1558 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001559 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 {
1561 if (noinvcur)
1562 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001563 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001564 {
1565 // highlighting starts at cursor, let it start just after the
1566 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001567 fromcol_prev = wlv.fromcol;
1568 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001570 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 // restart highlighting after the cursor
1572 fromcol_prev = wp->w_virtcol;
1573 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001574 if (wlv.fromcol >= wlv.tocol)
1575 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 }
1577
1578#ifdef FEAT_SEARCH_EXTRA
1579 if (!number_only)
1580 {
1581 v = (long)(ptr - line);
1582 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1583 &line, &screen_search_hl,
1584 &search_attr);
1585 ptr = line + v; // "line" may have been updated
1586 }
1587#endif
1588
1589#ifdef FEAT_SYN_HL
1590 // Cursor line highlighting for 'cursorline' in the current window.
1591 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1592 {
1593 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001594 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 if (!(wp == curwin && VIsual_active)
1596 && wp->w_p_culopt_flags != CULOPT_NBR)
1597 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001598 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1600
1601 // Only set line_attr here when "screenline" is not present in
1602 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001603 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001605 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001606# ifdef FEAT_SIGNS
1607 // Combine the 'cursorline' and sign highlighting, depending on
1608 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001609 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001610 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001611 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001612 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001613 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001614 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001615 }
1616 else
1617# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001618# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001619 // let the line attribute overrule 'cursorline', otherwise
1620 // it disappears when both have background set;
1621 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001622 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001623# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001624 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001625# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 }
1627 else
1628 {
1629 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1631 }
1632 area_highlighting = TRUE;
1633 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 }
1635#endif
1636
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001637#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 {
1639 char_u *prop_start;
1640
1641 text_prop_count = get_text_props(wp->w_buffer, lnum,
1642 &prop_start, FALSE);
1643 if (text_prop_count > 0)
1644 {
1645 // Make a copy of the properties, so that they are properly
1646 // aligned.
1647 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1648 if (text_props != NULL)
1649 mch_memmove(text_props, prop_start,
1650 text_prop_count * sizeof(textprop_T));
1651
1652 // Allocate an array for the indexes.
1653 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001654 if (text_prop_idxs == NULL)
1655 VIM_CLEAR(text_props);
1656
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001657 if (text_props != NULL)
1658 {
1659 area_highlighting = TRUE;
1660 extra_check = TRUE;
1661 for (int i = 0; i < text_prop_count; ++i)
1662 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1663 ++wlv.text_prop_above_count;
1664 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 }
1666 }
1667#endif
1668
Bram Moolenaar1306b362022-08-06 15:59:06 +01001669 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670
1671 // Repeat for the whole displayed line.
1672 for (;;)
1673 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001674 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001676 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677#endif
1678#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001679 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001681
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001683 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001685#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001687 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001688 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001689 line_attr = line_attr_save;
1690 }
1691#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001692 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001694 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 if (cmdwin_type != 0 && wp == curwin)
1696 {
1697 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001698 wlv.n_extra = 1;
1699 wlv.c_extra = cmdwin_type;
1700 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001701 wlv.char_attr =
1702 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 }
1704 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001706 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001708 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001709 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 }
1711#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001713 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001715 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001716 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001718 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 }
1720#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001721 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001722 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001723 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001725 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001728 // Check if 'breakindent' applies and show it.
1729 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1730 if (wlv.n_extra == 0)
1731 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001734 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001735 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001736 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001737 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 }
1739#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001743 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 }
1745 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001746
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001749 && wlv.vcol >= left_curline_col
1750 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001752 wlv.cul_attr = HL_ATTR(HLF_CUL);
1753 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
1755#endif
1756
1757 // When still displaying '$' of change command, stop at cursor.
1758 // When only displaying the (relative) line number and that's done,
1759 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001760 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001761 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001762 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001764 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765#endif
1766 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001768 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 // Pretend we have finished updating the window. Except when
1770 // 'cursorcolumn' is set.
1771#ifdef FEAT_SYN_HL
1772 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001773 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 else
1775#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001776 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 break;
1778 }
1779
Bram Moolenaar1306b362022-08-06 15:59:06 +01001780 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 {
1782 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001783 if (wlv.vcol == wlv.fromcol
1784 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1785 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 && (*mb_ptr2cells)(ptr) > 1)
1787 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001788 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001789 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 area_attr = vi_attr; // start highlighting
1791 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001792 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001793 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 area_attr = 0; // stop highlighting
1795
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001796#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 if (text_props != NULL)
1798 {
1799 int pi;
1800 int bcol = (int)(ptr - line);
1801
Bram Moolenaar1306b362022-08-06 15:59:06 +01001802 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001803# ifdef FEAT_LINEBREAK
1804 && !in_linebreak
1805# endif
1806 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001807 --bcol; // still working on the previous char, e.g. Tab
1808
1809 // Check if any active property ends.
1810 for (pi = 0; pi < text_props_active; ++pi)
1811 {
1812 int tpi = text_prop_idxs[pi];
1813
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001814 if (text_props[tpi].tp_col != MAXCOL
1815 && bcol >= text_props[tpi].tp_col - 1
1816 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 {
1818 if (pi + 1 < text_props_active)
1819 mch_memmove(text_prop_idxs + pi,
1820 text_prop_idxs + pi + 1,
1821 sizeof(int)
1822 * (text_props_active - (pi + 1)));
1823 --text_props_active;
1824 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001825# ifdef FEAT_LINEBREAK
1826 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001827 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001828 syntax_attr = 0;
1829# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001830 }
1831 }
1832
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001833# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001834 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001835 // not on the next char yet, don't start another prop
1836 --bcol;
1837# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001839 // With 'nowrap' and not in the first screen line only "below"
1840 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001842 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001843 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001844 && (wp->w_p_wrap
1845 || wlv.row == startrow
1846 || (text_props[text_prop_next].tp_flags
1847 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001848 || (bcol == 0 &&
1849 (text_props[text_prop_next].tp_flags
1850 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001851 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001852 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001853 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001854 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1855 {
1856 // first display the '$' after the line
1857 text_prop_follows = TRUE;
1858 break;
1859 }
1860 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001861 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001862 + text_props[text_prop_next].tp_len)
1863 text_prop_idxs[text_props_active++] = text_prop_next;
1864 ++text_prop_next;
1865 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001867 if (wlv.n_extra == 0 || !extra_for_textprop)
1868 {
1869 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001870 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001871 text_prop_flags = 0;
1872 text_prop_type = NULL;
1873 text_prop_id = 0;
1874 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001875 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001877 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001878 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001879 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001880
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 // Sort the properties on priority and/or starting last.
1882 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001883 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001884 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001885 sort_text_props(wp->w_buffer, text_props,
1886 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887
1888 for (pi = 0; pi < text_props_active; ++pi)
1889 {
1890 int tpi = text_prop_idxs[pi];
1891 proptype_T *pt = text_prop_type_by_id(
1892 wp->w_buffer, text_props[tpi].tp_type);
1893
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001894 if (pt != NULL && (pt->pt_hl_id > 0
1895 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001896 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001898 if (pt->pt_hl_id > 0)
1899 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 text_prop_type = pt;
1901 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001902 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001903 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001904 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001905 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001906 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 }
1908 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001909 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001910 && -text_prop_id
1911 <= wp->w_buffer->b_textprop_text.ga_len)
1912 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001913 textprop_T *tp = &text_props[used_tpi];
1914 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001915 ->b_textprop_text.ga_data)[
1916 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001917 int above = (tp->tp_flags
1918 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919
1920 // reset the ID in the copy to avoid it being used
1921 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001922 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001924 if (p != NULL)
1925 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001926 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001927 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001928 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001929 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001930 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1931 int padding = tp->tp_col == MAXCOL
1932 && tp->tp_len > 1
1933 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001934
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001935 // Insert virtual text before the current
1936 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001937 wlv.p_extra = p;
1938 wlv.c_extra = NUL;
1939 wlv.c_final = NUL;
1940 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001941 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001942 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001943 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001944 // restore search_attr and area_attr when n_extra
1945 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001946 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001947 saved_area_attr = area_attr;
1948 search_attr = 0;
1949 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001950 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001951 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001952 if (*ptr == NUL)
1953 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001954 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001955#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001956 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001957 {
1958 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001959 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001960 wlv.need_showbreak = FALSE;
1961 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001962 }
1963#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001964 if ((right || above || below || !wrap
1965 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001966 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001967 char_u *prev_p_extra = wlv.p_extra;
1968 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001969
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001970 // Take care of padding, right-align and
1971 // truncation.
1972 // Shared with win_lbr_chartabsize(), must do
1973 // exactly the same.
1974 start_line = text_prop_position(wp, tp,
1975 wlv.col,
1976 &wlv.n_extra, &wlv.p_extra,
1977 &n_attr, &n_attr_skip);
1978 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001979 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001980 // wlv.p_extra was allocated
1981 vim_free(p_extra_free2);
1982 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001983 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001984
Bram Moolenaara4abe512022-09-15 19:44:09 +01001985 if (lcs_eol_one < 0 && wlv.col
1986 + wlv.n_extra - 2 > wp->w_width)
1987 // don't bail out at end of line
1988 lcs_eol_one = 0;
1989
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001990 // When 'wrap' is off then for "below" we need
1991 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001992 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001993 {
1994 draw_screen_line(wp, &wlv);
1995
1996 // When line got too long for screen break
1997 // here.
1998 if (wlv.row == endrow)
1999 {
2000 ++wlv.row;
2001 break;
2002 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002003 win_line_start(wp, &wlv, TRUE);
2004 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002005 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002006 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002007 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002008
2009 // If another text prop follows the condition below at
2010 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002011 // If this is an "above" text prop and 'nowrap' the we
2012 // must wrap anyway.
2013 text_prop_above = above;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002014 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002015 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002017 else if (text_prop_next < text_prop_count
2018 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002019 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2020 || (!wp->w_p_wrap
2021 && wlv.col == wp->w_width - 1
2022 && (text_props[text_prop_next].tp_flags
2023 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002024 // When at last-but-one character and a text property
2025 // follows after it, we may need to flush the line after
2026 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002027 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002028 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 }
2030#endif
2031
Bram Moolenaare38fc862022-08-11 17:24:50 +01002032#ifdef FEAT_SEARCH_EXTRA
2033 if (wlv.n_extra == 0)
2034 {
2035 // Check for start/end of 'hlsearch' and other matches.
2036 // After end, check for start/end of next match.
2037 // When another match, have to check for start again.
2038 v = (long)(ptr - line);
2039 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2040 &screen_search_hl, &has_match_conc,
2041 &match_conc, did_line_attr, lcs_eol_one,
2042 &on_last_col);
2043 ptr = line + v; // "line" may have been changed
2044 prev_ptr = ptr;
2045
2046 // Do not allow a conceal over EOL otherwise EOL will be missed
2047 // and bad things happen.
2048 if (*ptr == NUL)
2049 has_match_conc = 0;
2050 }
2051#endif
2052
2053#ifdef FEAT_DIFF
2054 if (wlv.diff_hlf != (hlf_T)0)
2055 {
2056 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2057 && wlv.n_extra == 0)
2058 wlv.diff_hlf = HLF_TXD; // changed text
2059 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2060 && wlv.n_extra == 0)
2061 wlv.diff_hlf = HLF_CHD; // changed line
2062 line_attr = HL_ATTR(wlv.diff_hlf);
2063 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2064 && wp->w_p_culopt_flags != CULOPT_NBR
2065 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2066 && wlv.vcol <= right_curline_col)))
2067 line_attr = hl_combine_attr(
2068 line_attr, HL_ATTR(HLF_CUL));
2069 }
2070#endif
2071
Bram Moolenaara74fda62019-10-19 17:38:03 +02002072#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002073 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002074 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002075 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002076# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002077 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002078 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002079# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002080 // Get syntax attribute.
2081 if (has_syntax)
2082 {
2083 // Get the syntax attribute for the character. If there
2084 // is an error, disable syntax highlighting.
2085 save_did_emsg = did_emsg;
2086 did_emsg = FALSE;
2087
2088 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002089 if (v == prev_syntax_col)
2090 // at same column again
2091 syntax_attr = prev_syntax_attr;
2092 else
2093 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002094# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002095 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002096# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002097 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002098# ifdef FEAT_SPELL
2099 has_spell ? &can_spell :
2100# endif
2101 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002102 prev_syntax_col = v;
2103 prev_syntax_attr = syntax_attr;
2104 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002105
Bram Moolenaar34390282019-10-16 14:38:26 +02002106 if (did_emsg)
2107 {
2108 wp->w_s->b_syn_error = TRUE;
2109 has_syntax = FALSE;
2110 syntax_attr = 0;
2111 }
2112 else
2113 did_emsg = save_did_emsg;
2114# ifdef SYN_TIME_LIMIT
2115 if (wp->w_s->b_syn_slow)
2116 has_syntax = FALSE;
2117# endif
2118
2119 // Need to get the line again, a multi-line regexp may
2120 // have made it invalid.
2121 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2122 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002123 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002124# ifdef FEAT_CONCEAL
2125 // no concealing past the end of the line, it interferes
2126 // with line highlighting
2127 if (*ptr == NUL)
2128 syntax_flags = 0;
2129 else
2130 syntax_flags = get_syntax_info(&syntax_seqnr);
2131# endif
2132 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002133 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002134# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002135 // Combine text property highlight into syntax highlight.
2136 if (text_prop_type != NULL)
2137 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002138 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002139 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2140 else
2141 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002142 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002143 }
2144# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002145#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002146
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002147 // Decide which of the highlight attributes to use.
2148 attr_pri = TRUE;
2149#ifdef LINE_ATTR
2150 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002151 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002152 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002153 if (!highlight_match)
2154 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002155 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002156# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002157 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002158# endif
2159 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002160 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002161 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002162 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002163# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002164 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002165# endif
2166 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002167 else if (line_attr != 0
2168 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2169 || wlv.vcol < wlv.fromcol
2170 || vcol_prev < fromcol_prev
2171 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 {
2173 // Use line_attr when not in the Visual or 'incsearch' area
2174 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002175# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002176 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002177# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002178 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002179# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 attr_pri = FALSE;
2181 }
2182#else
2183 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002184 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002185 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002186 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187#endif
2188 else
2189 {
2190 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002193#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002195#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002197#ifdef FEAT_PROP_POPUP
2198 // override with text property highlight when "override" is TRUE
2199 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002200 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002201#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002202 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002203
2204 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002205 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002206 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002207 if (wlv.char_attr == 0)
2208 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002209 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002211 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212
2213 // Get the next character to put on the screen.
2214
2215 // The "p_extra" points to the extra stuff that is inserted to
2216 // represent special characters (non-printable stuff) and other
2217 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2220 // "p_extra[n_extra]".
2221 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002226 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2227 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002228 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2229 if (enc_utf8 && utf_char2len(c) > 1)
2230 {
2231 mb_utf8 = TRUE;
2232 u8cc[0] = 0;
2233 c = 0xc0;
2234 }
2235 else
2236 mb_utf8 = FALSE;
2237 }
2238 else
2239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 if (has_mbyte)
2242 {
2243 mb_c = c;
2244 if (enc_utf8)
2245 {
2246 // If the UTF-8 character is more than one byte:
2247 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002248 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002250 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002251 mb_l = 1;
2252 else if (mb_l > 1)
2253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 mb_utf8 = TRUE;
2256 c = 0xc0;
2257 }
2258 }
2259 else
2260 {
2261 // if this is a DBCS character, put it in "mb_c"
2262 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002263 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 mb_l = 1;
2265 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002266 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 }
2268 if (mb_l == 0) // at the NUL at end-of-line
2269 mb_l = 1;
2270
2271 // If a double-width char doesn't fit display a '>' in the
2272 // last column.
2273 if ((
2274# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002275 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002277 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 && (*mb_char2cells)(mb_c) == 2)
2279 {
2280 c = '>';
2281 mb_c = c;
2282 mb_l = 1;
2283 mb_utf8 = FALSE;
2284 multi_attr = HL_ATTR(HLF_AT);
2285#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002286 if (wlv.cul_attr)
2287 multi_attr = hl_combine_attr(
2288 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002289#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002290 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002291
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 // put the pointer back to output the double-width
2293 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002294 ++wlv.n_extra;
2295 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 }
2297 else
2298 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 wlv.n_extra -= mb_l - 1;
2300 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 }
2302 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002303 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002305 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002306#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002308 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002309 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002310 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002311 if (search_attr == 0)
2312 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002313 if (area_attr == 0 && *ptr != NUL)
2314 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002315 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002316#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 }
2318 else
2319 {
2320#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002321 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002323 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 // Get a character from the line itself.
2326 c = *ptr;
2327#ifdef FEAT_LINEBREAK
2328 c0 = *ptr;
2329#endif
2330 if (has_mbyte)
2331 {
2332 mb_c = c;
2333 if (enc_utf8)
2334 {
2335 // If the UTF-8 character is more than one byte: Decode it
2336 // into "mb_c".
2337 mb_l = utfc_ptr2len(ptr);
2338 mb_utf8 = FALSE;
2339 if (mb_l > 1)
2340 {
2341 mb_c = utfc_ptr2char(ptr, u8cc);
2342 // Overlong encoded ASCII or ASCII with composing char
2343 // is displayed normally, except a NUL.
2344 if (mb_c < 0x80)
2345 {
2346 c = mb_c;
2347#ifdef FEAT_LINEBREAK
2348 c0 = mb_c;
2349#endif
2350 }
2351 mb_utf8 = TRUE;
2352
2353 // At start of the line we can have a composing char.
2354 // Draw it as a space with a composing char.
2355 if (utf_iscomposing(mb_c))
2356 {
2357 int i;
2358
2359 for (i = Screen_mco - 1; i > 0; --i)
2360 u8cc[i] = u8cc[i - 1];
2361 u8cc[0] = mb_c;
2362 mb_c = ' ';
2363 }
2364 }
2365
2366 if ((mb_l == 1 && c >= 0x80)
2367 || (mb_l >= 1 && mb_c == 0)
2368 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2369 {
2370 // Illegal UTF-8 byte: display as <xx>.
2371 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002372 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373# ifdef FEAT_RIGHTLEFT
2374 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002375 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002377 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 c = *wlv.p_extra;
2379 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2382 wlv.c_extra = NUL;
2383 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 if (area_attr == 0 && search_attr == 0)
2385 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002386 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002387 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002388 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 }
2391 }
2392 else if (mb_l == 0) // at the NUL at end-of-line
2393 mb_l = 1;
2394#ifdef FEAT_ARABIC
2395 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2396 {
2397 // Do Arabic shaping.
2398 int pc, pc1, nc;
2399 int pcc[MAX_MCO];
2400
2401 // The idea of what is the previous and next
2402 // character depends on 'rightleft'.
2403 if (wp->w_p_rl)
2404 {
2405 pc = prev_c;
2406 pc1 = prev_c1;
2407 nc = utf_ptr2char(ptr + mb_l);
2408 prev_c1 = u8cc[0];
2409 }
2410 else
2411 {
2412 pc = utfc_ptr2char(ptr + mb_l, pcc);
2413 nc = prev_c;
2414 pc1 = pcc[0];
2415 }
2416 prev_c = mb_c;
2417
2418 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2419 }
2420 else
2421 prev_c = mb_c;
2422#endif
2423 }
2424 else // enc_dbcs
2425 {
2426 mb_l = MB_BYTE2LEN(c);
2427 if (mb_l == 0) // at the NUL at end-of-line
2428 mb_l = 1;
2429 else if (mb_l > 1)
2430 {
2431 // We assume a second byte below 32 is illegal.
2432 // Hopefully this is OK for all double-byte encodings!
2433 if (ptr[1] >= 32)
2434 mb_c = (c << 8) + ptr[1];
2435 else
2436 {
2437 if (ptr[1] == NUL)
2438 {
2439 // head byte at end of line
2440 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002441 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 }
2443 else
2444 {
2445 // illegal tail byte
2446 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002447 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002449 wlv.p_extra = wlv.extra;
2450 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 wlv.c_extra = NUL;
2452 wlv.c_final = NUL;
2453 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 if (area_attr == 0 && search_attr == 0)
2455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002457 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002458 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002459 // save current attr
2460 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 }
2462 mb_c = c;
2463 }
2464 }
2465 }
2466 // If a double-width char doesn't fit display a '>' in the
2467 // last column; the character is displayed at the start of the
2468 // next line.
2469 if ((
2470# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002471 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002473 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 && (*mb_char2cells)(mb_c) == 2)
2475 {
2476 c = '>';
2477 mb_c = c;
2478 mb_utf8 = FALSE;
2479 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002480 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 // Put pointer back so that the character will be
2482 // displayed at the start of the next line.
2483 --ptr;
2484#ifdef FEAT_CONCEAL
2485 did_decrement_ptr = TRUE;
2486#endif
2487 }
2488 else if (*ptr != NUL)
2489 ptr += mb_l - 1;
2490
2491 // If a double-width char doesn't fit at the left side display
2492 // a '<' in the first column. Don't do this for unprintable
2493 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002495 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 wlv.n_extra = 1;
2497 wlv.c_extra = MB_FILLER_CHAR;
2498 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 c = ' ';
2500 if (area_attr == 0 && search_attr == 0)
2501 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002503 extra_attr = hl_combine_attr(
2504 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506 }
2507 mb_c = c;
2508 mb_utf8 = FALSE;
2509 mb_l = 1;
2510 }
2511
2512 }
2513 ++ptr;
2514
2515 if (extra_check)
2516 {
2517#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002518 // Check spelling (unless at the end of the line).
2519 // Only do this when there is no syntax highlighting, the
2520 // @Spell cluster is not used or the current syntax item
2521 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002522 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002523 if (has_spell && v >= word_end && v > cur_checked_col)
2524 {
2525 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002526 // do not calculate cap_col at the end of the line or when
2527 // only white space is following
2528 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002529# ifdef FEAT_SYN_HL
2530 !has_syntax ||
2531# endif
2532 can_spell))
2533 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002534 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535 int len;
2536 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002537
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540
2541 // Use nextline[] if possible, it has the start of the
2542 // next line concatenated.
2543 if ((prev_ptr - line) - nextlinecol >= 0)
2544 p = nextline + (prev_ptr - line) - nextlinecol;
2545 else
2546 p = prev_ptr;
2547 cap_col -= (int)(prev_ptr - line);
2548 len = spell_check(wp, p, &spell_hlf, &cap_col,
2549 nochange);
2550 word_end = v + len;
2551
2552 // In Insert mode only highlight a word that
2553 // doesn't touch the cursor.
2554 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002555 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556 && wp->w_cursor.lnum == lnum
2557 && wp->w_cursor.col >=
2558 (colnr_T)(prev_ptr - line)
2559 && wp->w_cursor.col < (colnr_T)word_end)
2560 {
2561 spell_hlf = HLF_COUNT;
2562 spell_redraw_lnum = lnum;
2563 }
2564
2565 if (spell_hlf == HLF_COUNT && p != prev_ptr
2566 && (p - nextline) + len > nextline_idx)
2567 {
2568 // Remember that the good word continues at the
2569 // start of the next line.
2570 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002571 checked_col = (int)((p - nextline)
2572 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 }
2574
2575 // Turn index into actual attributes.
2576 if (spell_hlf != HLF_COUNT)
2577 spell_attr = highlight_attr[spell_hlf];
2578
2579 if (cap_col > 0)
2580 {
2581 if (p != prev_ptr
2582 && (p - nextline) + cap_col >= nextline_idx)
2583 {
2584 // Remember that the word in the next line
2585 // must start with a capital.
2586 capcol_lnum = lnum + 1;
2587 cap_col = (int)((p - nextline) + cap_col
2588 - nextline_idx);
2589 }
2590 else
2591 // Compute the actual column.
2592 cap_col += (int)(prev_ptr - line);
2593 }
2594 }
2595 }
2596 if (spell_attr != 0)
2597 {
2598 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2600 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 wlv.char_attr = hl_combine_attr(spell_attr,
2603 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604 }
2605#endif
2606#ifdef FEAT_LINEBREAK
2607 // Found last space before word: check for line break.
2608 if (wp->w_p_lbr && c0 == c
2609 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2610 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002611 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2612 : 0;
2613 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002614 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002616 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002617# ifdef FEAT_PROP_POPUP
2618 // do not want virtual text counted here
2619 cts.cts_has_prop_with_text = FALSE;
2620# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002622 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002623
2624 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002625 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002626 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002627 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2629 if (wlv.n_extra < 0)
2630 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002631 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002632 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002633 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002634 // line break, but for TABs the highlighting should
2635 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002636 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002637
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002641 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 wp->w_buffer->b_p_vts_array) - 1;
2643# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002645 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646# endif
2647
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2649 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002650# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002651 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002652 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002653# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 if (VIM_ISWHITE(c))
2655 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002656# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002657 if (c == TAB)
2658 // See "Tab alignment" below.
2659 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002660# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002661 if (!wp->w_p_list)
2662 c = ' ';
2663 }
2664 }
2665#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002666 in_multispace = c == ' '
2667 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2668 if (!in_multispace)
2669 multispace_pos = 0;
2670
Bram Moolenaareed9d462021-02-15 20:38:25 +01002671 // 'list': Change char 160 to 'nbsp' and space to 'space'
2672 // setting in 'listchars'. But not when the character is
2673 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674 if (wp->w_p_list
2675 && ((((c == 160 && mb_l == 1)
2676 || (mb_utf8
2677 && ((mb_c == 160 && mb_l == 2)
2678 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002679 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680 || (c == ' '
2681 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002682 && (wp->w_lcs_chars.space
2683 || (in_multispace
2684 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002685 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 && ptr - line <= trailcol)))
2687 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002688 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2689 {
2690 c = wp->w_lcs_chars.multispace[multispace_pos++];
2691 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2692 multispace_pos = 0;
2693 }
2694 else
2695 c = (c == ' ') ? wp->w_lcs_chars.space
2696 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 if (area_attr == 0 && search_attr == 0)
2698 {
2699 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 extra_attr = hl_combine_attr(wlv.win_attr,
2701 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 }
2704 mb_c = c;
2705 if (enc_utf8 && utf_char2len(c) > 1)
2706 {
2707 mb_utf8 = TRUE;
2708 u8cc[0] = 0;
2709 c = 0xc0;
2710 }
2711 else
2712 mb_utf8 = FALSE;
2713 }
2714
zeertzjq2e7cba32022-06-10 15:30:32 +01002715 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2716 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002718 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2719 && wp->w_lcs_chars.leadmultispace != NULL)
2720 {
2721 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002722 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2723 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002724 multispace_pos = 0;
2725 }
2726
2727 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2728 c = wp->w_lcs_chars.trail;
2729
2730 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2731 c = wp->w_lcs_chars.lead;
2732
zeertzjq2e7cba32022-06-10 15:30:32 +01002733 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002734 c = wp->w_lcs_chars.space;
2735
2736
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737 if (!attr_pri)
2738 {
2739 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002740 extra_attr = hl_combine_attr(wlv.win_attr,
2741 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002742 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002743 }
2744 mb_c = c;
2745 if (enc_utf8 && utf_char2len(c) > 1)
2746 {
2747 mb_utf8 = TRUE;
2748 u8cc[0] = 0;
2749 c = 0xc0;
2750 }
2751 else
2752 mb_utf8 = FALSE;
2753 }
2754 }
2755
2756 // Handling of non-printable characters.
2757 if (!vim_isprintc(c))
2758 {
2759 // when getting a character from the file, we may have to
2760 // turn it into something else on the way to putting it
2761 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002762 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002763 {
2764 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002765 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002766#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002767 char_u *sbr = get_showbreak_value(wp);
2768
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 // only adjust the tab_len, when at the first column
2770 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002771 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002772 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773#endif
2774 // tab amount depends on current column
2775#ifdef FEAT_VARTABS
2776 tab_len = tabstop_padding(vcol_adjusted,
2777 wp->w_buffer->b_p_ts,
2778 wp->w_buffer->b_p_vts_array) - 1;
2779#else
2780 tab_len = (int)wp->w_buffer->b_p_ts
2781 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2782#endif
2783
2784#ifdef FEAT_LINEBREAK
2785 if (!wp->w_p_lbr || !wp->w_p_list)
2786#endif
2787 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002788 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002789#ifdef FEAT_LINEBREAK
2790 else
2791 {
2792 char_u *p;
2793 int len;
2794 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002797# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002798 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002800 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002801
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002803 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 && old_boguscols > 0
2805 && wlv.n_extra > tab_len)
2806 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002807# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002808 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002810 // If wlv.n_extra > 0, it gives the number of
2811 // chars, to use for a tab, else we need to
2812 // calculate the width for a tab.
2813 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2814 len = tab_len * tab2_len;
2815 if (wp->w_lcs_chars.tab3)
2816 len += mb_char2len(wp->w_lcs_chars.tab3)
2817 - tab2_len;
2818 if (wlv.n_extra > 0)
2819 len += wlv.n_extra - tab_len;
2820 c = wp->w_lcs_chars.tab1;
2821 p = alloc(len + 1);
2822 if (p == NULL)
2823 wlv.n_extra = 0;
2824 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002826 vim_memset(p, ' ', len);
2827 p[len] = NUL;
2828 vim_free(wlv.p_extra_free);
2829 wlv.p_extra_free = p;
2830 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002831 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002832 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002833
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002834 if (*p == NUL)
2835 {
2836 tab_len = i;
2837 break;
2838 }
2839
2840 // if tab3 is given, use it for the last
2841 // char
2842 if (wp->w_lcs_chars.tab3
2843 && i == tab_len - 1)
2844 lcs = wp->w_lcs_chars.tab3;
2845 p += mb_char2bytes(lcs, p);
2846 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002848 }
2849 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002850# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002851 // n_extra will be increased by
2852 // FIX_FOX_BOGUSCOLS macro below, so need to
2853 // adjust for that here
2854 if (wlv.vcol_off > 0)
2855 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002856# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002857 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 }
2860#endif
2861#ifdef FEAT_CONCEAL
2862 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864
2865 // Tab alignment should be identical regardless of
2866 // 'conceallevel' value. So tab compensates of all
2867 // previous concealed characters, and thus resets
2868 // vcol_off and boguscols accumulated so far in the
2869 // line. Note that the tab can be longer than
2870 // 'tabstop' when there are concealed characters.
2871 FIX_FOR_BOGUSCOLS;
2872
2873 // Make sure, the highlighting for the tab char will be
2874 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002875 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002876 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002877 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 tab_len += vc_saved;
2879 }
2880#endif
2881 mb_utf8 = FALSE; // don't draw as UTF-8
2882 if (wp->w_p_list)
2883 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002884 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002885 ? wp->w_lcs_chars.tab3
2886 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887#ifdef FEAT_LINEBREAK
2888 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002889 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 else
2891#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.c_extra = wp->w_lcs_chars.tab2;
2893 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002895 extra_attr = hl_combine_attr(wlv.win_attr,
2896 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 mb_c = c;
2899 if (enc_utf8 && utf_char2len(c) > 1)
2900 {
2901 mb_utf8 = TRUE;
2902 u8cc[0] = 0;
2903 c = 0xc0;
2904 }
2905 }
2906 else
2907 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002908 wlv.c_final = NUL;
2909 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 c = ' ';
2911 }
2912 }
2913 else if (c == NUL
2914 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002915 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2916 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 && VIsual_mode != Ctrl_V
2918 && (
2919# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002920 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002922 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 && !(noinvcur
2924 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002925 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926 && lcs_eol_one > 0)
2927 {
2928 // Display a '$' after the line or highlight an extra
2929 // character if the line break is included.
2930#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2931 // For a diff line the highlighting continues after the
2932 // "$".
2933 if (
2934# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936# ifdef LINE_ATTR
2937 &&
2938# endif
2939# endif
2940# ifdef LINE_ATTR
2941 line_attr == 0
2942# endif
2943 )
2944#endif
2945 {
2946 // In virtualedit, visual selections may extend
2947 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002948 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002949 && wlv.tocol != MAXCOL
2950 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002952 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002953 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002954 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2955 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 else
2957 c = ' ';
2958 lcs_eol_one = -1;
2959 --ptr; // put it back at the NUL
2960 if (!attr_pri)
2961 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002962 extra_attr = hl_combine_attr(wlv.win_attr,
2963 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 n_attr = 1;
2965 }
2966 mb_c = c;
2967 if (enc_utf8 && utf_char2len(c) > 1)
2968 {
2969 mb_utf8 = TRUE;
2970 u8cc[0] = 0;
2971 c = 0xc0;
2972 }
2973 else
2974 mb_utf8 = FALSE; // don't draw as UTF-8
2975 }
2976 else if (c != NUL)
2977 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002978 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2979 if (wlv.n_extra == 0)
2980 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981#ifdef FEAT_RIGHTLEFT
2982 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002985 wlv.c_extra = NUL;
2986 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987#ifdef FEAT_LINEBREAK
2988 if (wp->w_p_lbr)
2989 {
2990 char_u *p;
2991
Bram Moolenaar1306b362022-08-06 15:59:06 +01002992 c = *wlv.p_extra;
2993 p = alloc(wlv.n_extra + 1);
2994 vim_memset(p, ' ', wlv.n_extra);
2995 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2996 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002997 vim_free(wlv.p_extra_free);
2998 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999 }
3000 else
3001#endif
3002 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 wlv.n_extra = byte2cells(c) - 1;
3004 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 }
3006 if (!attr_pri)
3007 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 extra_attr = hl_combine_attr(wlv.win_attr,
3010 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003011 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 }
3013 mb_utf8 = FALSE; // don't draw as UTF-8
3014 }
3015 else if (VIsual_active
3016 && (VIsual_mode == Ctrl_V
3017 || VIsual_mode == 'v')
3018 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003019 && wlv.tocol != MAXCOL
3020 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 && (
3022#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003023 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026 {
3027 c = ' ';
3028 --ptr; // put it back at the NUL
3029 }
3030#if defined(LINE_ATTR)
3031 else if ((
3032# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003033 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034# endif
3035# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003036 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037# endif
3038 line_attr != 0
3039 ) && (
3040# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003041 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003043 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003044# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003045 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046# endif
3047 < wp->w_width)))
3048 {
3049 // Highlight until the right side of the window
3050 c = ' ';
3051 --ptr; // put it back at the NUL
3052
3053 // Remember we do the char for line highlighting.
3054 ++did_line_attr;
3055
3056 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003057 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003059 || (wp->w_p_list &&
3060 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003061 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 wlv.diff_hlf = HLF_CHD;
3066 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003068 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003069 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3070 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003071 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 || (wlv.vcol >= left_curline_col
3073 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003074 wlv.char_attr = hl_combine_attr(
3075 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 }
3077 }
3078# endif
3079# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003080 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003081 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003082 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003083 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3084 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 if (!wlv.cul_screenline
3087 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 wlv.char_attr = hl_combine_attr(
3090 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 }
3092 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3094 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 }
3096# endif
3097 }
3098#endif
3099 }
3100
3101#ifdef FEAT_CONCEAL
3102 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003103 && (wp != curwin || lnum != wp->w_cursor.lnum
3104 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3106 && !(lnum_in_visual_area
3107 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3108 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003110 if (((prev_syntax_id != syntax_seqnr
3111 && (syntax_flags & HL_CONCEAL) != 0)
3112 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003113 && (syn_get_sub_char() != NUL
3114 || (has_match_conc && match_conc)
3115 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 && wp->w_p_cole != 3)
3117 {
3118 // First time at this concealed item: display one
3119 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003120 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 c = match_conc;
3122 else if (syn_get_sub_char() != NUL)
3123 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003124 else if (wp->w_lcs_chars.conceal != NUL)
3125 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 else
3127 c = ' ';
3128
3129 prev_syntax_id = syntax_seqnr;
3130
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 if (wlv.n_extra > 0)
3132 wlv.vcol_off += wlv.n_extra;
3133 wlv.vcol += wlv.n_extra;
3134 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135 {
3136# ifdef FEAT_RIGHTLEFT
3137 if (wp->w_p_rl)
3138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.col -= wlv.n_extra;
3140 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 }
3142 else
3143# endif
3144 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 wlv.boguscols += wlv.n_extra;
3146 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 }
3148 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 n_attr = 0;
3151 }
3152 else if (n_skip == 0)
3153 {
3154 is_concealing = TRUE;
3155 n_skip = 1;
3156 }
3157 mb_c = c;
3158 if (enc_utf8 && utf_char2len(c) > 1)
3159 {
3160 mb_utf8 = TRUE;
3161 u8cc[0] = 0;
3162 c = 0xc0;
3163 }
3164 else
3165 mb_utf8 = FALSE; // don't draw as UTF-8
3166 }
3167 else
3168 {
3169 prev_syntax_id = 0;
3170 is_concealing = FALSE;
3171 }
3172
3173 if (n_skip > 0 && did_decrement_ptr)
3174 // not showing the '>', put pointer back to avoid getting stuck
3175 ++ptr;
3176
3177#endif // FEAT_CONCEAL
3178 }
3179
3180#ifdef FEAT_CONCEAL
3181 // In the cursor line and we may be concealing characters: correct
3182 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 && wp == curwin && lnum == wp->w_cursor.lnum
3185 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003186 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003188# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003190 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003192# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003193 wp->w_wcol = wlv.col - wlv.boguscols;
3194 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 did_wcol = TRUE;
3196 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003197# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003198 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003199# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 }
3201#endif
3202
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003203 // Use "extra_attr", but don't override visual selection highlighting,
3204 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003205 // Don't use "extra_attr" until n_attr_skip is zero.
3206 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003208 && (!attr_pri
3209#ifdef FEAT_PROP_POPUP
3210 || (text_prop_flags & PT_FLAG_OVERRIDE)
3211#endif
3212 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 {
3214#ifdef LINE_ATTR
3215 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003216 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 else
3218#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003219 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 }
3221
3222#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3223 // XIM don't send preedit_start and preedit_end, but they send
3224 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3225 // im_is_preediting() here.
3226 if (p_imst == IM_ON_THE_SPOT
3227 && xic != NULL
3228 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003229 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230 && !p_imdisable
3231 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003232 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 {
3234 colnr_T tcol;
3235
3236 if (preedit_end_col == MAXCOL)
3237 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3238 else
3239 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003240 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241 {
3242 if (feedback_old_attr < 0)
3243 {
3244 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003245 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.char_attr = im_get_feedback_attr(feedback_col);
3248 if (wlv.char_attr < 0)
3249 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 feedback_col++;
3251 }
3252 else if (feedback_old_attr >= 0)
3253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003254 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 feedback_old_attr = -1;
3256 feedback_col = 0;
3257 }
3258 }
3259#endif
3260 // Handle the case where we are in column 0 but not on the first
3261 // character of the line and the user wants us to show us a
3262 // special character (via 'listchars' option "precedes:<char>".
3263 if (lcs_prec_todo != NUL
3264 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003265 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3266 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003268 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 && c != NUL)
3272 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003273 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 lcs_prec_todo = NUL;
3275 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3276 {
3277 // Double-width character being overwritten by the "precedes"
3278 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 wlv.c_extra = MB_FILLER_CHAR;
3280 wlv.c_final = NUL;
3281 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003283 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
3285 mb_c = c;
3286 if (enc_utf8 && utf_char2len(c) > 1)
3287 {
3288 mb_utf8 = TRUE;
3289 u8cc[0] = 0;
3290 c = 0xc0;
3291 }
3292 else
3293 mb_utf8 = FALSE; // don't draw as UTF-8
3294 if (!attr_pri)
3295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 saved_attr3 = wlv.char_attr; // save current attr
3297 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 n_attr3 = 1;
3299 }
3300 }
3301
3302 // At end of the text line or just after the last character.
3303 if ((c == NUL
3304#if defined(LINE_ATTR)
3305 || did_line_attr == 1
3306#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003307 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 {
3309#ifdef FEAT_SEARCH_EXTRA
3310 // flag to indicate whether prevcol equals startcol of search_hl or
3311 // one of the matches
3312 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3313 (long)(ptr - line) - (c == NUL));
3314#endif
3315 // Invert at least one char, used for Visual and empty line or
3316 // highlight match at end of line. If it's beyond the last
3317 // char on the screen, just overwrite that one (tricky!) Not
3318 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003319 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003320 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 && (VIsual_mode != Ctrl_V
3322 || lnum == VIsual.lnum
3323 || lnum == curwin->w_cursor.lnum)
3324 && c == NUL)
3325#ifdef FEAT_SEARCH_EXTRA
3326 // highlight 'hlsearch' match at end of line
3327 || (prevcol_hl_flag
3328# ifdef FEAT_SYN_HL
3329 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3330 && !(wp == curwin && VIsual_active))
3331# endif
3332# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003333 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334# endif
3335# if defined(LINE_ATTR)
3336 && did_line_attr <= 1
3337# endif
3338 )
3339#endif
3340 ))
3341 {
3342 int n = 0;
3343
3344#ifdef FEAT_RIGHTLEFT
3345 if (wp->w_p_rl)
3346 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003347 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 n = 1;
3349 }
3350 else
3351#endif
3352 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003353 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 n = -1;
3355 }
3356 if (n != 0)
3357 {
3358 // At the window boundary, highlight the last character
3359 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003360 wlv.off += n;
3361 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 }
3363 else
3364 {
3365 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003366 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 }
3370#ifdef FEAT_SEARCH_EXTRA
3371 if (area_attr == 0)
3372 {
3373 // Use attributes from match with highest priority among
3374 // 'search_hl' and the match list.
3375 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 }
3378#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003379 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381#ifdef FEAT_RIGHTLEFT
3382 if (wp->w_p_rl)
3383 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 --wlv.col;
3385 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 else
3388#endif
3389 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 ++wlv.col;
3391 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003393 ++wlv.vcol;
3394 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 }
3396 }
3397
3398 // At end of the text line.
3399 if (c == NUL)
3400 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003401 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402
3403 // Update w_cline_height and w_cline_folded if the cursor line was
3404 // updated (saves a call to plines() later).
3405 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3406 {
3407 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409#ifdef FEAT_FOLDING
3410 curwin->w_cline_folded = FALSE;
3411#endif
3412 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3413 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 break;
3415 }
3416
3417 // Show "extends" character from 'listchars' if beyond the line end and
3418 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003419 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 && wp->w_p_list
3422 && !wp->w_p_wrap
3423#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003424 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425#endif
3426 && (
3427#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003432 || lcs_eol_one > 0
3433 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003434 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003435 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003436 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003437 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 mb_c = c;
3439 if (enc_utf8 && utf_char2len(c) > 1)
3440 {
3441 mb_utf8 = TRUE;
3442 u8cc[0] = 0;
3443 c = 0xc0;
3444 }
3445 else
3446 mb_utf8 = FALSE;
3447 }
3448
3449#ifdef FEAT_SYN_HL
3450 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 if (wlv.draw_color_col)
3452 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453
3454 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3455 // highlight the cursor position itself.
3456 // Also highlight the 'colorcolumn' if it is different than
3457 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003458 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3459 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003461 if (((wlv.draw_state == WL_LINE
3462 || wlv.draw_state == WL_BRI
3463 || wlv.draw_state == WL_SBR)
3464 && !lnum_in_visual_area
3465 && search_attr == 0
3466 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003467# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003468 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003469# endif
3470 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 {
3472 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3473 && lnum != wp->w_cursor.lnum)
3474 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003475 vcol_save_attr = wlv.char_attr;
3476 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3477 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003481 vcol_save_attr = wlv.char_attr;
3482 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484 }
3485#endif
3486
3487 // Store character to be displayed.
3488 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003490 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 {
3492 // Store the character.
3493#if defined(FEAT_RIGHTLEFT)
3494 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3495 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003496 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003497 --wlv.off;
3498 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 }
3500#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003501 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 if (enc_dbcs == DBCS_JPNU)
3503 {
3504 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenLines[wlv.off] = 0x8e;
3506 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 }
3508 else if (enc_utf8)
3509 {
3510 if (mb_utf8)
3511 {
3512 int i;
3513
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003514 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003516 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 for (i = 0; i < Screen_mco; ++i)
3518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 if (u8cc[i] == 0)
3521 break;
3522 }
3523 }
3524 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 }
3527 if (multi_attr)
3528 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 multi_attr = 0;
3531 }
3532 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003535 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003536
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3538 {
3539 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 ++wlv.off;
3541 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003542 if (enc_utf8)
3543 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 else
3546 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003550 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551#endif
3552 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003553 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003554 // When "wlv.tocol" is halfway a character, set it to the end
3555 // of the character, otherwise highlighting won't stop.
3556 if (wlv.tocol == wlv.vcol)
3557 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003558
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003559 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003560
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561#ifdef FEAT_RIGHTLEFT
3562 if (wp->w_p_rl)
3563 {
3564 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003565 --wlv.off;
3566 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 }
3568#endif
3569 }
3570#ifdef FEAT_RIGHTLEFT
3571 if (wp->w_p_rl)
3572 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 --wlv.off;
3574 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003575 }
3576 else
3577#endif
3578 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 ++wlv.off;
3580 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 }
3582 }
3583#ifdef FEAT_CONCEAL
3584 else if (wp->w_p_cole > 0 && is_concealing)
3585 {
3586 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003587 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003588 if (wlv.n_extra > 0)
3589 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 if (wp->w_p_wrap)
3591 {
3592 // Special voodoo required if 'wrap' is on.
3593 //
3594 // Advance the column indicator to force the line
3595 // drawing to wrap early. This will make the line
3596 // take up the same screen space when parts are concealed,
3597 // so that cursor line computations aren't messed up.
3598 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 // trailing junk to be written out of the screen line
3601 // we are building, 'boguscols' keeps track of the number
3602 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003603 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003605 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606# ifdef FEAT_RIGHTLEFT
3607 if (wp->w_p_rl)
3608 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003609 wlv.col -= wlv.n_extra;
3610 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003611 }
3612 else
3613# endif
3614 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003615 wlv.col += wlv.n_extra;
3616 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003618 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 n_attr = 0;
3620 }
3621
3622
3623 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3624 {
3625 // Need to fill two screen columns.
3626# ifdef FEAT_RIGHTLEFT
3627 if (wp->w_p_rl)
3628 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003629 --wlv.boguscols;
3630 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 }
3632 else
3633# endif
3634 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003635 ++wlv.boguscols;
3636 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 }
3638 }
3639
3640# ifdef FEAT_RIGHTLEFT
3641 if (wp->w_p_rl)
3642 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 --wlv.boguscols;
3644 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 }
3646 else
3647# endif
3648 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 ++wlv.boguscols;
3650 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 }
3652 }
3653 else
3654 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003657 wlv.vcol += wlv.n_extra;
3658 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 n_attr = 0;
3660 }
3661 }
3662
3663 }
3664#endif // FEAT_CONCEAL
3665 else
3666 --n_skip;
3667
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 // Only advance the "wlv.vcol" when after the 'number' or
3669 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003672 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673#endif
3674 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676
3677#ifdef FEAT_SYN_HL
3678 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003679 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680#endif
3681
3682 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003683 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3684 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685
3686 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003688 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003689 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003690 if (n_attr_skip > 0)
3691 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692
3693 // At end of screen line and there is more to come: Display the line
3694 // so far. If there is no more to display it is caught above.
3695 if ((
3696#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003697 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003700 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003701 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003703 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003705#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003706 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003707#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003708 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 && wlv.p_extra != at_end_str)
3710 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3711 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 )
3713 {
3714#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003715 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003716 wlv_screen_line(wp, &wlv, FALSE);
3717 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003718 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003720 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 ++wlv.row;
3723 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724
3725 // When not wrapping and finished diff lines, or when displayed
3726 // '$' and highlighting until last column, break here.
3727 if ((!wp->w_p_wrap
3728#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003729 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003730#endif
3731#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003732 && !text_prop_above && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733#endif
3734 ) || lcs_eol_one == -1)
3735 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003736#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003737 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003738 {
3739 // do not output more of the line, only the "below" prop
3740 ptr += STRLEN(ptr);
3741# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003742 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003743# endif
3744 }
3745#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746
3747 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003750 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751#endif
3752 )
3753 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003754 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3755 draw_vsep_win(wp, wlv.row);
3756 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 }
3758
3759 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003762 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 break;
3764 }
3765
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003768 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003770#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003771 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003772#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 && wp->w_width == Columns)
3774 {
3775 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777
3778 // Special trick to make copy/paste of wrapped lines work with
3779 // xterm/screen: write an extra character beyond the end of
3780 // the line. This will work with all terminal types
3781 // (regardless of the xn,am settings).
3782 // Only do this on a fast tty.
3783 // Only do this if the cursor is on the current line
3784 // (something has been written in it).
3785 // Don't do this for the GUI.
3786 // Don't do this for double-width characters.
3787 // Don't do this for a window not at the right screen border.
3788 if (p_tf
3789#ifdef FEAT_GUI
3790 && !gui.in_use
3791#endif
3792 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3794 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 || (*mb_off2cells)(
3797 LineOffset[wlv.screen_row - 1]
3798 + (int)Columns - 2,
3799 LineOffset[wlv.screen_row]
3800 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 {
3802 // First make sure we are at the end of the screen line,
3803 // then output the same character again to let the
3804 // terminal know about the wrap. If the terminal doesn't
3805 // auto-wrap, we overwrite the character.
3806 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003807 screen_char(LineOffset[wlv.screen_row - 1]
3808 + (unsigned)Columns - 1,
3809 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810
3811 // When there is a multi-byte character, just output a
3812 // space to keep it simple.
3813 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 out_char(' ');
3816 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818 + (Columns - 1)]);
3819 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 screen_start(); // don't know where cursor is now
3822 }
3823 }
3824
Bram Moolenaar1306b362022-08-06 15:59:06 +01003825 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826
Bram Moolenaareed9d462021-02-15 20:38:25 +01003827 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003829 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003830# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003831 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003833 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003834 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835#endif
3836#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003837 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 // When the filler lines are actually below the last line of the
3839 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003840 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841 break;
3842#endif
3843 }
3844
3845 } // for every character in the line
3846
3847#ifdef FEAT_SPELL
3848 // After an empty line check first word for capital.
3849 if (*skipwhite(line) == NUL)
3850 {
3851 capcol_lnum = lnum + 1;
3852 cap_col = 0;
3853 }
3854#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003855#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003856 vim_free(text_props);
3857 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003858 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859#endif
3860
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003861 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003862 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863}