blob: b2a5951435cb6bf7a9342abbe00440a9a88b2f50 [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
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100462 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100463 // 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))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100581 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100582 int len = (int)STRLEN(text);
583 int strsize = 0;
584 int n_used;
585
Bram Moolenaar7e017462022-10-11 21:02:09 +0100586 // if the remaining size is to small and 'wrap' is set we wrap anyway and
587 // use the next line
588 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100590 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100591 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100592 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
593 {
594 int clen = ptr2cells(text + n_used);
595
596 if (strsize + clen > space)
597 break;
598 strsize += clen;
599 }
600 *n_used_ptr = n_used;
601 return strsize;
602}
603
604/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100605 * Take care of padding, right-align and truncation of virtual text after a
606 * line.
607 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
608 * padding, right-align and truncation. Otherwise only the size is computed.
609 * When "n_attr" is NULL returns the number of screen cells used.
610 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100611 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100612 int
613text_prop_position(
614 win_T *wp,
615 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100616 int vcol UNUSED, // current text column
617 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100618 int *n_extra, // nr of bytes for virtual text
619 char_u **p_extra, // virtual text
620 int *n_attr, // attribute cells, NULL if not used
621 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200622{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100623 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
626 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
627 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
628 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100629 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100630 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 int before = room; // spaces before the text
632 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int n_used = *n_extra;
634 char_u *l = NULL;
635 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100637 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100638 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
639 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200640
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100641 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100642 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100643 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100644 int skip_add = 0;
645
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100646 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100648 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100649 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 }
651 else
652 {
653 // Right-align: fill with before
654 if (right)
655 before -= cells;
656 if (before < 0
657 || !(right || below)
658 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100659 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100661 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100662 if (right && (wrap
663 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 {
665 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = wp->w_width - col_off - strsize + room;
667 if (before < 0)
668 before = 0;
669 else
670 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100671 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100676 else if (below && before > 0)
677 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100678 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100679 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100680
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 // With 'nowrap' add one to show the "extends" character if needed (it
682 // doesn't show if the text just fits).
683 if (!wp->w_p_wrap
684 && n_used < *n_extra
685 && wp->w_lcs_chars.ext != NUL
686 && wp->w_p_list)
687 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100688 if (!wp->w_p_wrap && below && padding > 0)
689 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690
691 // add 1 for NUL, 2 for when '…' is used
692 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100694 if (n_attr == NULL || l != NULL)
695 {
696 int off = 0;
697
698 if (n_attr != NULL)
699 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100700 vim_memset(l, ' ', before);
701 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 if (padding > 0)
703 {
704 vim_memset(l + off, ' ', padding);
705 off += padding;
706 }
707 vim_strncpy(l + off, *p_extra, n_used);
708 off += n_used;
709 }
710 else
711 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100712 off = before + after + padding + n_used;
713 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100714 }
715 if (n_attr != NULL)
716 {
717 if (n_used < *n_extra && wp->w_p_wrap)
718 {
719 char_u *lp = l + off - 1;
720
721 if (has_mbyte)
722 {
723 // change last character to '…'
724 lp -= (*mb_head_off)(l, lp);
725 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100726 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
728 else
729 // change last character to '>'
730 *lp = '>';
731 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100732 else if (after > 0)
733 {
734 vim_memset(l + off, ' ', after);
735 l[off + after] = NUL;
736 }
737
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100738 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100739 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100741 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100742 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100743
744 // Add "skip_add" when starting a new line or wrapping,
745 // n_attr_skip will then be decremented in the number column.
746 *n_attr_skip = before + padding
747 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100748 }
749 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100750 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100751
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100752 if (n_attr == NULL)
753 return cells;
754 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200755}
756#endif
757
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100758/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100759 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100760 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
761 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100762 */
763 static void
764wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
765{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100766 if (wlv->row == 0 && wp->w_skipcol > 0
767#if defined(FEAT_LINEBREAK)
768 && *get_showbreak_value(wp) == NUL
769#endif
770 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100771 {
772 int off = (int)(current_ScreenLine - ScreenLines);
773
774 for (int i = 0; i < 3; ++i)
775 {
776 ScreenLines[off] = '<';
777 if (enc_utf8)
778 ScreenLinesUC[off] = 0;
779 ScreenAttrs[off] = HL_ATTR(HLF_AT);
780 ++off;
781 }
782 }
783
784 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
785 negative_width ? -wp->w_width : wp->w_width,
786 wlv->screen_line_flags);
787}
788
789/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100790 * Called when finished with the line: draw the screen line and handle any
791 * highlighting until the right of the window.
792 */
793 static void
794draw_screen_line(win_T *wp, winlinevars_T *wlv)
795{
796#ifdef FEAT_SYN_HL
797 long v;
798
799 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
800 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100801 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100802 else
803 v = wp->w_leftcol;
804
805 // check if line ends before left margin
806 if (wlv->vcol < v + wlv->col - win_col_off(wp))
807 wlv->vcol = v + wlv->col - win_col_off(wp);
808# ifdef FEAT_CONCEAL
809 // Get rid of the boguscols now, we want to draw until the right
810 // edge for 'cursorcolumn'.
811 wlv->col -= wlv->boguscols;
812 wlv->boguscols = 0;
813# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
814# else
815# define VCOL_HLC (wlv->vcol)
816# endif
817
818 if (wlv->draw_color_col)
819 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
820
821 if (((wp->w_p_cuc
822 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
823 && (int)wp->w_virtcol <
824 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
825 && wlv->lnum != wp->w_cursor.lnum)
826 || wlv->draw_color_col
827 || wlv->win_attr != 0)
828# ifdef FEAT_RIGHTLEFT
829 && !wp->w_p_rl
830# endif
831 )
832 {
833 int rightmost_vcol = 0;
834 int i;
835
836 if (wp->w_p_cuc)
837 rightmost_vcol = wp->w_virtcol;
838 if (wlv->draw_color_col)
839 // determine rightmost colorcolumn to possibly draw
840 for (i = 0; wlv->color_cols[i] >= 0; ++i)
841 if (rightmost_vcol < wlv->color_cols[i])
842 rightmost_vcol = wlv->color_cols[i];
843
844 while (wlv->col < wp->w_width)
845 {
846 ScreenLines[wlv->off] = ' ';
847 if (enc_utf8)
848 ScreenLinesUC[wlv->off] = 0;
849 ScreenCols[wlv->off] = MAXCOL;
850 ++wlv->col;
851 if (wlv->draw_color_col)
852 wlv->draw_color_col = advance_color_col(
853 VCOL_HLC, &wlv->color_cols);
854
855 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
856 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
857 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
858 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
859 else
860 ScreenAttrs[wlv->off++] = wlv->win_attr;
861
862 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
863 break;
864
865 ++wlv->vcol;
866 }
867 }
868#endif
869
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100870 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871 ++wlv->row;
872 ++wlv->screen_row;
873}
874#undef VCOL_HLC
875
876/*
877 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100878 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100879 */
880 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100881win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882{
883 wlv->col = 0;
884 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
885
886#ifdef FEAT_RIGHTLEFT
887 if (wp->w_p_rl)
888 {
889 // Rightleft window: process the text in the normal direction, but put
890 // it in current_ScreenLine[] from right to left. Start at the
891 // rightmost column of the window.
892 wlv->col = wp->w_width - 1;
893 wlv->off += wlv->col;
894 wlv->screen_line_flags |= SLF_RIGHTLEFT;
895 }
896#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100897 if (save_extra)
898 {
899 // reset the drawing state for the start of a wrapped line
900 wlv->draw_state = WL_START;
901 wlv->saved_n_extra = wlv->n_extra;
902 wlv->saved_p_extra = wlv->p_extra;
903 wlv->saved_c_extra = wlv->c_extra;
904 wlv->saved_c_final = wlv->c_final;
905#ifdef FEAT_SYN_HL
906 if (!(wlv->cul_screenline
907# ifdef FEAT_DIFF
908 && wlv->diff_hlf == (hlf_T)0
909# endif
910 ))
911 wlv->saved_char_attr = wlv->char_attr;
912 else
913#endif
914 wlv->saved_char_attr = 0;
915 wlv->n_extra = 0;
916 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100917}
918
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200919/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100920 * Called when wlv->draw_state is set to WL_LINE.
921 */
922 static void
923win_line_continue(winlinevars_T *wlv)
924{
925 if (wlv->saved_n_extra > 0)
926 {
927 // Continue item from end of wrapped line.
928 wlv->n_extra = wlv->saved_n_extra;
929 wlv->c_extra = wlv->saved_c_extra;
930 wlv->c_final = wlv->saved_c_final;
931 wlv->p_extra = wlv->saved_p_extra;
932 wlv->char_attr = wlv->saved_char_attr;
933 }
934 else
935 wlv->char_attr = wlv->win_attr;
936}
937
938/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200939 * Display line "lnum" of window 'wp' on the screen.
940 * Start at row "startrow", stop when "endrow" is reached.
941 * wp->w_virtcol needs to be valid.
942 *
943 * Return the number of last row the line occupies.
944 */
945 int
946win_line(
947 win_T *wp,
948 linenr_T lnum,
949 int startrow,
950 int endrow,
951 int nochange UNUSED, // not updating for changed text
952 int number_only) // only update the number column
953{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100954 winlinevars_T wlv; // variables passed between functions
955
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100957 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200958 char_u *line; // current line
959 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200960
Bram Moolenaar1306b362022-08-06 15:59:06 +0100961#ifdef FEAT_PROP_POPUP
962 char_u *p_extra_free2 = NULL; // another p_extra to be freed
963#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000965#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000966 int in_linebreak = FALSE; // n_extra set for showing linebreak
967#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200968 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100969 // displaying eol at end-of-line
970 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000971 int lcs_prec_todo = wp->w_lcs_chars.prec;
972 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200973
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100974 int n_attr = 0; // chars with special attr
975 int n_attr_skip = 0; // chars to skip before using extra_attr
976 int saved_attr2 = 0; // char_attr saved for n_attr
977 int n_attr3 = 0; // chars with overruling special attr
978 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979
Bram Moolenaarcd105412022-10-10 19:50:42 +0100980 int n_skip = 0; // nr of cells to skip for 'nowrap' or
981 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100982#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100983 int skip_cells = 0; // nr of cells to skip for virtual text
984 // after the line, when w_skipcol is
985 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100986#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200987
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 int fromcol_prev = -2; // start of inverting after cursor
989 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 int lnum_in_visual_area = FALSE;
991 pos_T pos;
992 long v;
993
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200994 int attr_pri = FALSE; // char_attr has priority
995 int area_highlighting = FALSE; // Visual or incsearch highlighting
996 // in this line
997 int vi_attr = 0; // attributes for Visual and incsearch
998 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 int area_attr = 0; // attributes desired by highlighting
1000 int search_attr = 0; // attributes desired by 'hlsearch'
1001#ifdef FEAT_SYN_HL
1002 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1003 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001004 int prev_syntax_col = -1; // column of prev_syntax_attr
1005 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 int has_syntax = FALSE; // this buffer has syntax highl.
1007 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001009#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010 int text_prop_count;
1011 int text_prop_next = 0; // next text property to use
1012 textprop_T *text_props = NULL;
1013 int *text_prop_idxs = NULL;
1014 int text_props_active = 0;
1015 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001016 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001018 int text_prop_attr_comb = 0; // text_prop_attr combined with
1019 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001020 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001021 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001022 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001023 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001024 int saved_search_attr = 0; // search_attr to be used when n_extra
1025 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001026 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027#endif
1028#ifdef FEAT_SPELL
1029 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001030 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031# define SPWORDLEN 150
1032 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1033 int nextlinecol = 0; // column where nextline[] starts
1034 int nextline_idx = 0; // index in nextline[] where next line
1035 // starts
1036 int spell_attr = 0; // attributes desired by spelling
1037 int word_end = 0; // last byte with same spell_attr
1038 static linenr_T checked_lnum = 0; // line number for "checked_col"
1039 static int checked_col = 0; // column in "checked_lnum" up to which
1040 // there are no spell errors
1041 static int cap_col = -1; // column to check for Cap word
1042 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1043 int cur_checked_col = 0; // checked column for current line
1044#endif
1045 int extra_check = 0; // has extra highlighting
1046 int multi_attr = 0; // attributes desired by multibyte
1047 int mb_l = 1; // multi-byte byte length
1048 int mb_c = 0; // decoded multi-byte character
1049 int mb_utf8 = FALSE; // screen char is UTF-8 char
1050 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052 int change_start = MAXCOL; // first col of changed area
1053 int change_end = -1; // last col of changed area
1054#endif
1055 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001056 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001057 int in_multispace = FALSE; // in multiple consecutive spaces
1058 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1060 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1061# define LINE_ATTR
1062 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001063 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001066 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067#ifdef FEAT_ARABIC
1068 int prev_c = 0; // previous Arabic character
1069 int prev_c1 = 0; // first composing char for prev_c
1070#endif
1071#if defined(LINE_ATTR)
1072 int did_line_attr = 0;
1073#endif
1074#ifdef FEAT_TERMINAL
1075 int get_term_attr = FALSE;
1076#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077
Martin Tournoijba43e762022-10-13 22:12:15 +01001078#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079 // margin columns for the screen line, needed for when 'cursorlineopt'
1080 // contains "screenline"
1081 int left_curline_col = 0;
1082 int right_curline_col = 0;
1083#endif
1084
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1086 int feedback_col = 0;
1087 int feedback_old_attr = -1;
1088#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089
1090#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1091 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001092#endif
1093#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001094 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001095#endif
1096#ifdef FEAT_CONCEAL
1097 int syntax_flags = 0;
1098 int syntax_seqnr = 0;
1099 int prev_syntax_id = 0;
1100 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1101 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001102 int did_wcol = FALSE;
1103 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105# define FIX_FOR_BOGUSCOLS \
1106 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001107 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001108 wlv.vcol -= wlv.vcol_off; \
1109 wlv.vcol_off = 0; \
1110 wlv.col -= wlv.boguscols; \
1111 old_boguscols = wlv.boguscols; \
1112 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 }
1114#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001115# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116#endif
1117
1118 if (startrow > endrow) // past the end already!
1119 return startrow;
1120
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001121 CLEAR_FIELD(wlv);
1122
1123 wlv.lnum = lnum;
1124 wlv.startrow = startrow;
1125 wlv.row = startrow;
1126 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001127 wlv.fromcol = -10;
1128 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001129#ifdef FEAT_LINEBREAK
1130 wlv.vcol_sbr = -1;
1131#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001132
1133 if (!number_only)
1134 {
1135 // To speed up the loop below, set extra_check when there is linebreak,
1136 // trailing white space and/or syntax processing to be done.
1137#ifdef FEAT_LINEBREAK
1138 extra_check = wp->w_p_lbr;
1139#endif
1140#ifdef FEAT_SYN_HL
1141 if (syntax_present(wp) && !wp->w_s->b_syn_error
1142# ifdef SYN_TIME_LIMIT
1143 && !wp->w_s->b_syn_slow
1144# endif
1145 )
1146 {
1147 // Prepare for syntax highlighting in this line. When there is an
1148 // error, stop syntax highlighting.
1149 save_did_emsg = did_emsg;
1150 did_emsg = FALSE;
1151 syntax_start(wp, lnum);
1152 if (did_emsg)
1153 wp->w_s->b_syn_error = TRUE;
1154 else
1155 {
1156 did_emsg = save_did_emsg;
1157#ifdef SYN_TIME_LIMIT
1158 if (!wp->w_s->b_syn_slow)
1159#endif
1160 {
1161 has_syntax = TRUE;
1162 extra_check = TRUE;
1163 }
1164 }
1165 }
1166
1167 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001168 wlv.color_cols = wp->w_p_cc_cols;
1169 if (wlv.color_cols != NULL)
1170 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171#endif
1172
1173#ifdef FEAT_TERMINAL
1174 if (term_show_buffer(wp->w_buffer))
1175 {
1176 extra_check = TRUE;
1177 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001178 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179 }
1180#endif
1181
1182#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001183 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184 {
1185 // Prepare for spell checking.
1186 has_spell = TRUE;
1187 extra_check = TRUE;
1188
1189 // Get the start of the next line, so that words that wrap to the
1190 // next line are found too: "et<line-break>al.".
1191 // Trick: skip a few chars for C/shell/Vim comments
1192 nextline[SPWORDLEN] = NUL;
1193 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1194 {
1195 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1196 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1197 }
1198
1199 // When a word wrapped from the previous line the start of the
1200 // current line is valid.
1201 if (lnum == checked_lnum)
1202 cur_checked_col = checked_col;
1203 checked_lnum = 0;
1204
1205 // When there was a sentence end in the previous line may require a
1206 // word starting with capital in this line. In line 1 always check
1207 // the first word.
1208 if (lnum != capcol_lnum)
1209 cap_col = -1;
1210 if (lnum == 1)
1211 cap_col = 0;
1212 capcol_lnum = 0;
1213 }
1214#endif
1215
1216 // handle Visual active in this window
1217 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1218 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001219 pos_T *top, *bot;
1220
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1222 {
1223 // Visual is after curwin->w_cursor
1224 top = &curwin->w_cursor;
1225 bot = &VIsual;
1226 }
1227 else
1228 {
1229 // Visual is before curwin->w_cursor
1230 top = &VIsual;
1231 bot = &curwin->w_cursor;
1232 }
1233 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1234 if (VIsual_mode == Ctrl_V)
1235 {
1236 // block mode
1237 if (lnum_in_visual_area)
1238 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 wlv.fromcol = wp->w_old_cursor_fcol;
1240 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 }
1242 }
1243 else
1244 {
1245 // non-block mode
1246 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001247 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 else if (lnum == top->lnum)
1249 {
1250 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001251 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 else
1253 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001254 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001256 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 }
1258 }
1259 if (VIsual_mode != 'V' && lnum == bot->lnum)
1260 {
1261 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1262 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001263 wlv.fromcol = -10;
1264 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001265 }
1266 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001267 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 else
1269 {
1270 pos = *bot;
1271 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001272 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1273 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 else
1275 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 getvvcol(wp, &pos, NULL, NULL,
1277 (colnr_T *)&wlv.tocol);
1278 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 }
1280 }
1281 }
1282 }
1283
1284 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001285 if (!highlight_match && lnum == curwin->w_cursor.lnum
1286 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287#ifdef FEAT_GUI
1288 && !gui.in_use
1289#endif
1290 )
1291 noinvcur = TRUE;
1292
1293 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001294 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 {
1296 area_highlighting = TRUE;
1297 vi_attr = HL_ATTR(HLF_V);
1298#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1299 if ((clip_star.available && !clip_star.owned
1300 && clip_isautosel_star())
1301 || (clip_plus.available && !clip_plus.owned
1302 && clip_isautosel_plus()))
1303 vi_attr = HL_ATTR(HLF_VNC);
1304#endif
1305 }
1306 }
1307
1308 // handle 'incsearch' and ":s///c" highlighting
1309 else if (highlight_match
1310 && wp == curwin
1311 && lnum >= curwin->w_cursor.lnum
1312 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1313 {
1314 if (lnum == curwin->w_cursor.lnum)
1315 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001318 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1320 {
1321 pos.lnum = lnum;
1322 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001323 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 }
1325 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001326 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001328 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1329 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 area_highlighting = TRUE;
1331 vi_attr = HL_ATTR(HLF_I);
1332 }
1333 }
1334
1335#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001336 wlv.filler_lines = diff_check(wp, lnum);
1337 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001339 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 {
1341 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001342 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001344 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001345 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001346 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
1348 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001349 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001350 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 area_highlighting = TRUE;
1352 }
1353 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001354 wlv.filler_lines = wp->w_topfill;
1355 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356#endif
1357
1358#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001359 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001360 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001361 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362#endif
1363
1364#ifdef LINE_ATTR
1365# ifdef FEAT_SIGNS
1366 // If this line has a sign with line highlighting set line_attr.
1367 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001368 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369# endif
1370# if defined(FEAT_QUICKFIX)
1371 // Highlight the current line in the quickfix window.
1372 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1373 line_attr = HL_ATTR(HLF_QFL);
1374# endif
1375 if (line_attr != 0)
1376 area_highlighting = TRUE;
1377#endif
1378
1379 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1380 ptr = line;
1381
1382#ifdef FEAT_SPELL
1383 if (has_spell && !number_only)
1384 {
1385 // For checking first word with a capital skip white space.
1386 if (cap_col == 0)
1387 cap_col = getwhitecols(line);
1388
1389 // To be able to spell-check over line boundaries copy the end of the
1390 // current line into nextline[]. Above the start of the next line was
1391 // copied to nextline[SPWORDLEN].
1392 if (nextline[SPWORDLEN] == NUL)
1393 {
1394 // No next line or it is empty.
1395 nextlinecol = MAXCOL;
1396 nextline_idx = 0;
1397 }
1398 else
1399 {
1400 v = (long)STRLEN(line);
1401 if (v < SPWORDLEN)
1402 {
1403 // Short line, use it completely and append the start of the
1404 // next line.
1405 nextlinecol = 0;
1406 mch_memmove(nextline, line, (size_t)v);
1407 STRMOVE(nextline + v, nextline + SPWORDLEN);
1408 nextline_idx = v + 1;
1409 }
1410 else
1411 {
1412 // Long line, use only the last SPWORDLEN bytes.
1413 nextlinecol = v - SPWORDLEN;
1414 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1415 nextline_idx = SPWORDLEN + 1;
1416 }
1417 }
1418 }
1419#endif
1420
1421 if (wp->w_p_list)
1422 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001423 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001424 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001425 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001426 || wp->w_lcs_chars.trail
1427 || wp->w_lcs_chars.lead
1428 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001430
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001432 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 {
1434 trailcol = (colnr_T)STRLEN(ptr);
1435 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1436 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001437 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001439 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001440 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001441 {
1442 leadcol = 0;
1443 while (VIM_ISWHITE(ptr[leadcol]))
1444 ++leadcol;
1445 if (ptr[leadcol] == NUL)
1446 // in a line full of spaces all of them are treated as trailing
1447 leadcol = (colnr_T)0;
1448 else
1449 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001450 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001451 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 }
1453
Bram Moolenaard7657e92022-09-20 18:59:30 +01001454 wlv.wcr_attr = get_wcr_attr(wp);
1455 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001457 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 area_highlighting = TRUE;
1459 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001460
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001461#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001463 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464#endif
1465
1466 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1467 // first character to be displayed.
1468 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001469 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470 else
1471 v = wp->w_leftcol;
1472 if (v > 0 && !number_only)
1473 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001474 char_u *prev_ptr = ptr;
1475 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001476 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001478 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001479 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001481 charsize = win_lbr_chartabsize(&cts, NULL);
1482 cts.cts_vcol += charsize;
1483 prev_ptr = cts.cts_ptr;
1484 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001486 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001487 ptr = cts.cts_ptr;
1488 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489
1490 // When:
1491 // - 'cuc' is set, or
1492 // - 'colorcolumn' is set, or
1493 // - 'virtualedit' is set, or
1494 // - the visual mode is active,
1495 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001496 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001498 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499#endif
1500 virtual_active() ||
1501 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001502 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503
1504 // Handle a character that's not completely on the screen: Put ptr at
1505 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001506 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 ptr = prev_ptr;
1510 // If the character fits on the screen, don't need to skip it.
1511 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001512 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1513 && wlv.col == 0)
1514 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
1516
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001517#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001518 // If there the text doesn't reach to the desired column, need to skip
1519 // "skip_cells" cells when virtual text follows.
1520 if (!wp->w_p_wrap && v > wlv.vcol)
1521 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001522#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001523
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001524 // Adjust for when the inverted text is before the screen,
1525 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001526 if (wlv.tocol <= wlv.vcol)
1527 wlv.fromcol = 0;
1528 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1529 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530
1531#ifdef FEAT_LINEBREAK
1532 // When w_skipcol is non-zero, first line needs 'showbreak'
1533 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001534 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535#endif
1536#ifdef FEAT_SPELL
1537 // When spell checking a word we need to figure out the start of the
1538 // word and if it's badly spelled or not.
1539 if (has_spell)
1540 {
1541 int len;
1542 colnr_T linecol = (colnr_T)(ptr - line);
1543 hlf_T spell_hlf = HLF_COUNT;
1544
1545 pos = wp->w_cursor;
1546 wp->w_cursor.lnum = lnum;
1547 wp->w_cursor.col = linecol;
1548 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1549
1550 // spell_move_to() may call ml_get() and make "line" invalid
1551 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1552 ptr = line + linecol;
1553
1554 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1555 {
1556 // no bad word found at line start, don't check until end of a
1557 // word
1558 spell_hlf = HLF_COUNT;
1559 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1560 }
1561 else
1562 {
1563 // bad word found, use attributes until end of word
1564 word_end = wp->w_cursor.col + len + 1;
1565
1566 // Turn index into actual attributes.
1567 if (spell_hlf != HLF_COUNT)
1568 spell_attr = highlight_attr[spell_hlf];
1569 }
1570 wp->w_cursor = pos;
1571
1572# ifdef FEAT_SYN_HL
1573 // Need to restart syntax highlighting for this line.
1574 if (has_syntax)
1575 syntax_start(wp, lnum);
1576# endif
1577 }
1578#endif
1579 }
1580
1581 // Correct highlighting for cursor that can't be disabled.
1582 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001583 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 {
1585 if (noinvcur)
1586 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001587 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 {
1589 // highlighting starts at cursor, let it start just after the
1590 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001591 fromcol_prev = wlv.fromcol;
1592 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001594 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 // restart highlighting after the cursor
1596 fromcol_prev = wp->w_virtcol;
1597 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001598 if (wlv.fromcol >= wlv.tocol)
1599 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 }
1601
1602#ifdef FEAT_SEARCH_EXTRA
1603 if (!number_only)
1604 {
1605 v = (long)(ptr - line);
1606 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1607 &line, &screen_search_hl,
1608 &search_attr);
1609 ptr = line + v; // "line" may have been updated
1610 }
1611#endif
1612
1613#ifdef FEAT_SYN_HL
1614 // Cursor line highlighting for 'cursorline' in the current window.
1615 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1616 {
1617 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001618 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 if (!(wp == curwin && VIsual_active)
1620 && wp->w_p_culopt_flags != CULOPT_NBR)
1621 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001622 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1624
1625 // Only set line_attr here when "screenline" is not present in
1626 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001627 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001629 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001630# ifdef FEAT_SIGNS
1631 // Combine the 'cursorline' and sign highlighting, depending on
1632 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001633 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001634 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001635 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001636 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001637 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001638 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001639 }
1640 else
1641# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001642# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001643 // let the line attribute overrule 'cursorline', otherwise
1644 // it disappears when both have background set;
1645 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001646 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001647# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001648 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001649# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
1651 else
1652 {
1653 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1655 }
1656 area_highlighting = TRUE;
1657 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 }
1659#endif
1660
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001661#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662 {
1663 char_u *prop_start;
1664
1665 text_prop_count = get_text_props(wp->w_buffer, lnum,
1666 &prop_start, FALSE);
1667 if (text_prop_count > 0)
1668 {
1669 // Make a copy of the properties, so that they are properly
1670 // aligned.
1671 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1672 if (text_props != NULL)
1673 mch_memmove(text_props, prop_start,
1674 text_prop_count * sizeof(textprop_T));
1675
1676 // Allocate an array for the indexes.
1677 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001678 if (text_prop_idxs == NULL)
1679 VIM_CLEAR(text_props);
1680
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001681 if (text_props != NULL)
1682 {
1683 area_highlighting = TRUE;
1684 extra_check = TRUE;
1685 for (int i = 0; i < text_prop_count; ++i)
1686 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1687 ++wlv.text_prop_above_count;
1688 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001689 }
1690 }
1691#endif
1692
Bram Moolenaar1306b362022-08-06 15:59:06 +01001693 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694
1695 // Repeat for the whole displayed line.
1696 for (;;)
1697 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001698 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001700 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701#endif
1702#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001703 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001705
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001707 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001709#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001711 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001712 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001713 line_attr = line_attr_save;
1714 }
1715#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001716 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001718 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 if (cmdwin_type != 0 && wp == curwin)
1720 {
1721 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001722 wlv.n_extra = 1;
1723 wlv.c_extra = cmdwin_type;
1724 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001725 wlv.char_attr =
1726 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 }
1728 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001730 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001732 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001733 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 }
1735#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001737 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001739 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001742 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 }
1744#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001745 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001747 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001749 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001750 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001752 // Check if 'breakindent' applies and show it.
1753 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1754 if (wlv.n_extra == 0)
1755 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001760 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001761 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 }
1763#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001766 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001767 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 }
1769 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001770
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001772 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001773 && wlv.vcol >= left_curline_col
1774 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001776 wlv.cul_attr = HL_ATTR(HLF_CUL);
1777 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 }
1779#endif
1780
1781 // When still displaying '$' of change command, stop at cursor.
1782 // When only displaying the (relative) line number and that's done,
1783 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001784 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001785 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001786 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001788 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789#endif
1790 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001792 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 // Pretend we have finished updating the window. Except when
1794 // 'cursorcolumn' is set.
1795#ifdef FEAT_SYN_HL
1796 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001797 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 else
1799#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001800 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 break;
1802 }
1803
Bram Moolenaar1306b362022-08-06 15:59:06 +01001804 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 {
1806 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001807 if (wlv.vcol == wlv.fromcol
1808 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1809 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 && (*mb_ptr2cells)(ptr) > 1)
1811 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001812 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001813 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 area_attr = vi_attr; // start highlighting
1815 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001816 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001817 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 area_attr = 0; // stop highlighting
1819
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001820#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 if (text_props != NULL)
1822 {
1823 int pi;
1824 int bcol = (int)(ptr - line);
1825
Bram Moolenaar1306b362022-08-06 15:59:06 +01001826 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001827# ifdef FEAT_LINEBREAK
1828 && !in_linebreak
1829# endif
1830 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 --bcol; // still working on the previous char, e.g. Tab
1832
1833 // Check if any active property ends.
1834 for (pi = 0; pi < text_props_active; ++pi)
1835 {
1836 int tpi = text_prop_idxs[pi];
1837
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001838 if (text_props[tpi].tp_col != MAXCOL
1839 && bcol >= text_props[tpi].tp_col - 1
1840 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 {
1842 if (pi + 1 < text_props_active)
1843 mch_memmove(text_prop_idxs + pi,
1844 text_prop_idxs + pi + 1,
1845 sizeof(int)
1846 * (text_props_active - (pi + 1)));
1847 --text_props_active;
1848 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001849# ifdef FEAT_LINEBREAK
1850 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001851 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001852 syntax_attr = 0;
1853# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 }
1855 }
1856
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001857# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001858 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001859 // not on the next char yet, don't start another prop
1860 --bcol;
1861# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001863 // With 'nowrap' and not in the first screen line only "below"
1864 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001866 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001867 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001868 && (wp->w_p_wrap
1869 || wlv.row == startrow
1870 || (text_props[text_prop_next].tp_flags
1871 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001872 || (bcol == 0 &&
1873 (text_props[text_prop_next].tp_flags
1874 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001875 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001876 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001877 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001878 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1879 {
1880 // first display the '$' after the line
1881 text_prop_follows = TRUE;
1882 break;
1883 }
1884 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001885 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001886 + text_props[text_prop_next].tp_len)
1887 text_prop_idxs[text_props_active++] = text_prop_next;
1888 ++text_prop_next;
1889 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001891 if (wlv.n_extra == 0 || !extra_for_textprop)
1892 {
1893 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001894 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001895 text_prop_flags = 0;
1896 text_prop_type = NULL;
1897 text_prop_id = 0;
1898 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001899 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001901 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001902 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001903 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001904
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 // Sort the properties on priority and/or starting last.
1906 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001907 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001908 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001909 sort_text_props(wp->w_buffer, text_props,
1910 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911
1912 for (pi = 0; pi < text_props_active; ++pi)
1913 {
1914 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001915 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001917 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918
Bram Moolenaarcd105412022-10-10 19:50:42 +01001919 // Only use a text property that can be displayed.
1920 // Skip "after" properties when wrap is off and at the
1921 // end of the window.
1922 if (pt != NULL
1923 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1924 && tp->tp_id != -MAXCOL
1925 && !(tp->tp_id < 0
1926 && !wp->w_p_wrap
1927 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1928 | TP_FLAG_ALIGN_ABOVE
1929 | TP_FLAG_ALIGN_BELOW)) == 0
1930 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001932 if (pt->pt_hl_id > 0)
1933 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 text_prop_type = pt;
1935 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001936 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001937 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001938 text_prop_flags = pt->pt_flags;
1939 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001940 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 }
1942 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001943 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001944 && -text_prop_id
1945 <= wp->w_buffer->b_textprop_text.ga_len)
1946 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001947 textprop_T *tp = &text_props[used_tpi];
1948 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001949 ->b_textprop_text.ga_data)[
1950 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001951 int above = (tp->tp_flags
1952 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001953 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001954
1955 // reset the ID in the copy to avoid it being used
1956 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001958
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001959 if (p != NULL)
1960 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001961 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001962 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001963 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001964 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001965 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1966 int padding = tp->tp_col == MAXCOL
1967 && tp->tp_len > 1
1968 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001969
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001970 // Insert virtual text before the current
1971 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001972 wlv.p_extra = p;
1973 wlv.c_extra = NUL;
1974 wlv.c_final = NUL;
1975 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001976 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001977 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001978 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001979 // restore search_attr and area_attr when n_extra
1980 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001981 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001982 saved_area_attr = area_attr;
1983 search_attr = 0;
1984 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001985 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001986 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001987 if (*ptr == NUL)
1988 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001989 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001990#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001991 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001992 {
1993 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001994 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001995 wlv.need_showbreak = FALSE;
1996 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001997 }
1998#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01001999 if ((right || above || below || !wrap
2000 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002001 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002002 char_u *prev_p_extra = wlv.p_extra;
2003 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002004
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002005 // Take care of padding, right-align and
2006 // truncation.
2007 // Shared with win_lbr_chartabsize(), must do
2008 // exactly the same.
2009 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002010 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002011 wlv.col,
2012 &wlv.n_extra, &wlv.p_extra,
2013 &n_attr, &n_attr_skip);
2014 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002016 // wlv.p_extra was allocated
2017 vim_free(p_extra_free2);
2018 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002019 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002020
Bram Moolenaara4abe512022-09-15 19:44:09 +01002021 if (lcs_eol_one < 0 && wlv.col
2022 + wlv.n_extra - 2 > wp->w_width)
2023 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002024 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002025
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002026 // When 'wrap' is off then for "below" we need
2027 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002028 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002029 {
2030 draw_screen_line(wp, &wlv);
2031
2032 // When line got too long for screen break
2033 // here.
2034 if (wlv.row == endrow)
2035 {
2036 ++wlv.row;
2037 break;
2038 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002039 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002040 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002041 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002043 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002044
Bram Moolenaarcd105412022-10-10 19:50:42 +01002045 // If the text didn't reach until the first window
2046 // column we need to skip cells.
2047 if (skip_cells > 0)
2048 {
2049 if (wlv.n_extra > skip_cells)
2050 {
2051 wlv.n_extra -= skip_cells;
2052 wlv.p_extra += skip_cells;
2053 n_attr_skip -= skip_cells;
2054 if (n_attr_skip < 0)
2055 n_attr_skip = 0;
2056 skip_cells = 0;
2057 }
2058 else
2059 {
2060 // the whole text is left of the window, drop
2061 // it and advance to the next one
2062 skip_cells -= wlv.n_extra;
2063 wlv.n_extra = 0;
2064 n_attr_skip = 0;
2065 bail_out = TRUE;
2066 }
2067 }
2068
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069 // If another text prop follows the condition below at
2070 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002071 // If this is an "above" text prop and 'nowrap' the we
2072 // must wrap anyway.
2073 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002074 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002075 && (wp->w_p_wrap
2076 || (text_props[other_tpi].tp_flags
2077 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002078
2079 if (bail_out)
2080 // starting a new line for "below"
2081 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002082 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002084 else if (text_prop_next < text_prop_count
2085 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002086 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2087 || (!wp->w_p_wrap
2088 && wlv.col == wp->w_width - 1
2089 && (text_props[text_prop_next].tp_flags
2090 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002091 // When at last-but-one character and a text property
2092 // follows after it, we may need to flush the line after
2093 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002094 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002095 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 }
2097#endif
2098
Bram Moolenaare38fc862022-08-11 17:24:50 +01002099#ifdef FEAT_SEARCH_EXTRA
2100 if (wlv.n_extra == 0)
2101 {
2102 // Check for start/end of 'hlsearch' and other matches.
2103 // After end, check for start/end of next match.
2104 // When another match, have to check for start again.
2105 v = (long)(ptr - line);
2106 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2107 &screen_search_hl, &has_match_conc,
2108 &match_conc, did_line_attr, lcs_eol_one,
2109 &on_last_col);
2110 ptr = line + v; // "line" may have been changed
2111 prev_ptr = ptr;
2112
2113 // Do not allow a conceal over EOL otherwise EOL will be missed
2114 // and bad things happen.
2115 if (*ptr == NUL)
2116 has_match_conc = 0;
2117 }
2118#endif
2119
2120#ifdef FEAT_DIFF
2121 if (wlv.diff_hlf != (hlf_T)0)
2122 {
2123 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2124 && wlv.n_extra == 0)
2125 wlv.diff_hlf = HLF_TXD; // changed text
2126 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2127 && wlv.n_extra == 0)
2128 wlv.diff_hlf = HLF_CHD; // changed line
2129 line_attr = HL_ATTR(wlv.diff_hlf);
2130 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2131 && wp->w_p_culopt_flags != CULOPT_NBR
2132 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2133 && wlv.vcol <= right_curline_col)))
2134 line_attr = hl_combine_attr(
2135 line_attr, HL_ATTR(HLF_CUL));
2136 }
2137#endif
2138
Bram Moolenaara74fda62019-10-19 17:38:03 +02002139#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002140 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002141 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002142 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002143# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002144 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002145 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002146# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002147 // Get syntax attribute.
2148 if (has_syntax)
2149 {
2150 // Get the syntax attribute for the character. If there
2151 // is an error, disable syntax highlighting.
2152 save_did_emsg = did_emsg;
2153 did_emsg = FALSE;
2154
2155 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002156 if (v == prev_syntax_col)
2157 // at same column again
2158 syntax_attr = prev_syntax_attr;
2159 else
2160 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002161# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002162 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002163# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002164 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002165# ifdef FEAT_SPELL
2166 has_spell ? &can_spell :
2167# endif
2168 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002169 prev_syntax_col = v;
2170 prev_syntax_attr = syntax_attr;
2171 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002172
Bram Moolenaar34390282019-10-16 14:38:26 +02002173 if (did_emsg)
2174 {
2175 wp->w_s->b_syn_error = TRUE;
2176 has_syntax = FALSE;
2177 syntax_attr = 0;
2178 }
2179 else
2180 did_emsg = save_did_emsg;
2181# ifdef SYN_TIME_LIMIT
2182 if (wp->w_s->b_syn_slow)
2183 has_syntax = FALSE;
2184# endif
2185
2186 // Need to get the line again, a multi-line regexp may
2187 // have made it invalid.
2188 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2189 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002190 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002191# ifdef FEAT_CONCEAL
2192 // no concealing past the end of the line, it interferes
2193 // with line highlighting
2194 if (*ptr == NUL)
2195 syntax_flags = 0;
2196 else
2197 syntax_flags = get_syntax_info(&syntax_seqnr);
2198# endif
2199 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002200 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002201# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002202 // Combine text property highlight into syntax highlight.
2203 if (text_prop_type != NULL)
2204 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002205 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002206 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2207 else
2208 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002209 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002210 }
2211# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002212#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002213
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002214 // Decide which of the highlight attributes to use.
2215 attr_pri = TRUE;
2216#ifdef LINE_ATTR
2217 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002218 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002219 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002220 if (!highlight_match)
2221 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002223# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002224 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002225# endif
2226 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002227 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002228 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002230# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002231 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002232# endif
2233 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002234 else if (line_attr != 0
2235 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2236 || wlv.vcol < wlv.fromcol
2237 || vcol_prev < fromcol_prev
2238 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 {
2240 // Use line_attr when not in the Visual or 'incsearch' area
2241 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002242# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002243 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002244# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002245 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002246# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 attr_pri = FALSE;
2248 }
2249#else
2250 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002251 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002253 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002254#endif
2255 else
2256 {
2257 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002259 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002260#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002261 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002262#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002264#ifdef FEAT_PROP_POPUP
2265 // override with text property highlight when "override" is TRUE
2266 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002267 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002268#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002270
2271 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002272 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002273 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002274 if (wlv.char_attr == 0)
2275 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002276 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002277 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002278 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279
2280 // Get the next character to put on the screen.
2281
2282 // The "p_extra" points to the extra stuff that is inserted to
2283 // represent special characters (non-printable stuff) and other
2284 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002286 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2287 // "p_extra[n_extra]".
2288 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002289 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002291 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002293 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2294 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002295 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2296 if (enc_utf8 && utf_char2len(c) > 1)
2297 {
2298 mb_utf8 = TRUE;
2299 u8cc[0] = 0;
2300 c = 0xc0;
2301 }
2302 else
2303 mb_utf8 = FALSE;
2304 }
2305 else
2306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 if (has_mbyte)
2309 {
2310 mb_c = c;
2311 if (enc_utf8)
2312 {
2313 // If the UTF-8 character is more than one byte:
2314 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002315 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002316 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002317 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002318 mb_l = 1;
2319 else if (mb_l > 1)
2320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002321 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 mb_utf8 = TRUE;
2323 c = 0xc0;
2324 }
2325 }
2326 else
2327 {
2328 // if this is a DBCS character, put it in "mb_c"
2329 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002330 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 mb_l = 1;
2332 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002333 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334 }
2335 if (mb_l == 0) // at the NUL at end-of-line
2336 mb_l = 1;
2337
2338 // If a double-width char doesn't fit display a '>' in the
2339 // last column.
2340 if ((
2341# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002342 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002344 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 && (*mb_char2cells)(mb_c) == 2)
2346 {
2347 c = '>';
2348 mb_c = c;
2349 mb_l = 1;
2350 mb_utf8 = FALSE;
2351 multi_attr = HL_ATTR(HLF_AT);
2352#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002353 if (wlv.cul_attr)
2354 multi_attr = hl_combine_attr(
2355 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002357 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002358
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 // put the pointer back to output the double-width
2360 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002361 ++wlv.n_extra;
2362 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002363 }
2364 else
2365 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 wlv.n_extra -= mb_l - 1;
2367 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 }
2369 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002370 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002371 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002373#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002375 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002376 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002377 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002378 if (search_attr == 0)
2379 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002380 if (area_attr == 0 && *ptr != NUL)
2381 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002382 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002383#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 }
2385 else
2386 {
2387#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002388 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002390 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002392 // Get a character from the line itself.
2393 c = *ptr;
2394#ifdef FEAT_LINEBREAK
2395 c0 = *ptr;
2396#endif
2397 if (has_mbyte)
2398 {
2399 mb_c = c;
2400 if (enc_utf8)
2401 {
2402 // If the UTF-8 character is more than one byte: Decode it
2403 // into "mb_c".
2404 mb_l = utfc_ptr2len(ptr);
2405 mb_utf8 = FALSE;
2406 if (mb_l > 1)
2407 {
2408 mb_c = utfc_ptr2char(ptr, u8cc);
2409 // Overlong encoded ASCII or ASCII with composing char
2410 // is displayed normally, except a NUL.
2411 if (mb_c < 0x80)
2412 {
2413 c = mb_c;
2414#ifdef FEAT_LINEBREAK
2415 c0 = mb_c;
2416#endif
2417 }
2418 mb_utf8 = TRUE;
2419
2420 // At start of the line we can have a composing char.
2421 // Draw it as a space with a composing char.
2422 if (utf_iscomposing(mb_c))
2423 {
2424 int i;
2425
2426 for (i = Screen_mco - 1; i > 0; --i)
2427 u8cc[i] = u8cc[i - 1];
2428 u8cc[0] = mb_c;
2429 mb_c = ' ';
2430 }
2431 }
2432
2433 if ((mb_l == 1 && c >= 0x80)
2434 || (mb_l >= 1 && mb_c == 0)
2435 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2436 {
2437 // Illegal UTF-8 byte: display as <xx>.
2438 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002439 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002440# ifdef FEAT_RIGHTLEFT
2441 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002442 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002443# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002444 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 c = *wlv.p_extra;
2446 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002447 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2449 wlv.c_extra = NUL;
2450 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 if (area_attr == 0 && search_attr == 0)
2452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002454 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002455 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 }
2458 }
2459 else if (mb_l == 0) // at the NUL at end-of-line
2460 mb_l = 1;
2461#ifdef FEAT_ARABIC
2462 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2463 {
2464 // Do Arabic shaping.
2465 int pc, pc1, nc;
2466 int pcc[MAX_MCO];
2467
2468 // The idea of what is the previous and next
2469 // character depends on 'rightleft'.
2470 if (wp->w_p_rl)
2471 {
2472 pc = prev_c;
2473 pc1 = prev_c1;
2474 nc = utf_ptr2char(ptr + mb_l);
2475 prev_c1 = u8cc[0];
2476 }
2477 else
2478 {
2479 pc = utfc_ptr2char(ptr + mb_l, pcc);
2480 nc = prev_c;
2481 pc1 = pcc[0];
2482 }
2483 prev_c = mb_c;
2484
2485 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2486 }
2487 else
2488 prev_c = mb_c;
2489#endif
2490 }
2491 else // enc_dbcs
2492 {
2493 mb_l = MB_BYTE2LEN(c);
2494 if (mb_l == 0) // at the NUL at end-of-line
2495 mb_l = 1;
2496 else if (mb_l > 1)
2497 {
2498 // We assume a second byte below 32 is illegal.
2499 // Hopefully this is OK for all double-byte encodings!
2500 if (ptr[1] >= 32)
2501 mb_c = (c << 8) + ptr[1];
2502 else
2503 {
2504 if (ptr[1] == NUL)
2505 {
2506 // head byte at end of line
2507 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002508 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 }
2510 else
2511 {
2512 // illegal tail byte
2513 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002514 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002516 wlv.p_extra = wlv.extra;
2517 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 wlv.c_extra = NUL;
2519 wlv.c_final = NUL;
2520 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 if (area_attr == 0 && search_attr == 0)
2522 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002523 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002524 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002525 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 // save current attr
2527 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 }
2529 mb_c = c;
2530 }
2531 }
2532 }
2533 // If a double-width char doesn't fit display a '>' in the
2534 // last column; the character is displayed at the start of the
2535 // next line.
2536 if ((
2537# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002538 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002540 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 && (*mb_char2cells)(mb_c) == 2)
2542 {
2543 c = '>';
2544 mb_c = c;
2545 mb_utf8 = FALSE;
2546 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002547 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 // Put pointer back so that the character will be
2549 // displayed at the start of the next line.
2550 --ptr;
2551#ifdef FEAT_CONCEAL
2552 did_decrement_ptr = TRUE;
2553#endif
2554 }
2555 else if (*ptr != NUL)
2556 ptr += mb_l - 1;
2557
2558 // If a double-width char doesn't fit at the left side display
2559 // a '<' in the first column. Don't do this for unprintable
2560 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 wlv.n_extra = 1;
2564 wlv.c_extra = MB_FILLER_CHAR;
2565 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 c = ' ';
2567 if (area_attr == 0 && search_attr == 0)
2568 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002570 extra_attr = hl_combine_attr(
2571 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 }
2574 mb_c = c;
2575 mb_utf8 = FALSE;
2576 mb_l = 1;
2577 }
2578
2579 }
2580 ++ptr;
2581
2582 if (extra_check)
2583 {
2584#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002585 // Check spelling (unless at the end of the line).
2586 // Only do this when there is no syntax highlighting, the
2587 // @Spell cluster is not used or the current syntax item
2588 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002589 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 if (has_spell && v >= word_end && v > cur_checked_col)
2591 {
2592 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002593 // do not calculate cap_col at the end of the line or when
2594 // only white space is following
2595 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596# ifdef FEAT_SYN_HL
2597 !has_syntax ||
2598# endif
2599 can_spell))
2600 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002601 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 int len;
2603 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002604
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607
2608 // Use nextline[] if possible, it has the start of the
2609 // next line concatenated.
2610 if ((prev_ptr - line) - nextlinecol >= 0)
2611 p = nextline + (prev_ptr - line) - nextlinecol;
2612 else
2613 p = prev_ptr;
2614 cap_col -= (int)(prev_ptr - line);
2615 len = spell_check(wp, p, &spell_hlf, &cap_col,
2616 nochange);
2617 word_end = v + len;
2618
2619 // In Insert mode only highlight a word that
2620 // doesn't touch the cursor.
2621 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002622 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 && wp->w_cursor.lnum == lnum
2624 && wp->w_cursor.col >=
2625 (colnr_T)(prev_ptr - line)
2626 && wp->w_cursor.col < (colnr_T)word_end)
2627 {
2628 spell_hlf = HLF_COUNT;
2629 spell_redraw_lnum = lnum;
2630 }
2631
2632 if (spell_hlf == HLF_COUNT && p != prev_ptr
2633 && (p - nextline) + len > nextline_idx)
2634 {
2635 // Remember that the good word continues at the
2636 // start of the next line.
2637 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002638 checked_col = (int)((p - nextline)
2639 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 }
2641
2642 // Turn index into actual attributes.
2643 if (spell_hlf != HLF_COUNT)
2644 spell_attr = highlight_attr[spell_hlf];
2645
2646 if (cap_col > 0)
2647 {
2648 if (p != prev_ptr
2649 && (p - nextline) + cap_col >= nextline_idx)
2650 {
2651 // Remember that the word in the next line
2652 // must start with a capital.
2653 capcol_lnum = lnum + 1;
2654 cap_col = (int)((p - nextline) + cap_col
2655 - nextline_idx);
2656 }
2657 else
2658 // Compute the actual column.
2659 cap_col += (int)(prev_ptr - line);
2660 }
2661 }
2662 }
2663 if (spell_attr != 0)
2664 {
2665 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002666 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2667 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002669 wlv.char_attr = hl_combine_attr(spell_attr,
2670 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 }
2672#endif
2673#ifdef FEAT_LINEBREAK
2674 // Found last space before word: check for line break.
2675 if (wp->w_p_lbr && c0 == c
2676 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2677 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002678 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2679 : 0;
2680 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002681 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002683 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002684# ifdef FEAT_PROP_POPUP
2685 // do not want virtual text counted here
2686 cts.cts_has_prop_with_text = FALSE;
2687# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002688 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002689 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002690
2691 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002692 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002693 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002694 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002695 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2696 if (wlv.n_extra < 0)
2697 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002698 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002699 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002700 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002701 // line break, but for TABs the highlighting should
2702 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002703 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002704
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002707 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002708 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 wp->w_buffer->b_p_vts_array) - 1;
2710# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002711 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002712 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713# endif
2714
Bram Moolenaar1306b362022-08-06 15:59:06 +01002715 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2716 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002717# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002719 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002720# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 if (VIM_ISWHITE(c))
2722 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002723# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 if (c == TAB)
2725 // See "Tab alignment" below.
2726 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002727# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 if (!wp->w_p_list)
2729 c = ' ';
2730 }
2731 }
2732#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002733 in_multispace = c == ' '
2734 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2735 if (!in_multispace)
2736 multispace_pos = 0;
2737
Bram Moolenaareed9d462021-02-15 20:38:25 +01002738 // 'list': Change char 160 to 'nbsp' and space to 'space'
2739 // setting in 'listchars'. But not when the character is
2740 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 if (wp->w_p_list
2742 && ((((c == 160 && mb_l == 1)
2743 || (mb_utf8
2744 && ((mb_c == 160 && mb_l == 2)
2745 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002746 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 || (c == ' '
2748 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002749 && (wp->w_lcs_chars.space
2750 || (in_multispace
2751 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002752 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 && ptr - line <= trailcol)))
2754 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002755 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2756 {
2757 c = wp->w_lcs_chars.multispace[multispace_pos++];
2758 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2759 multispace_pos = 0;
2760 }
2761 else
2762 c = (c == ' ') ? wp->w_lcs_chars.space
2763 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 if (area_attr == 0 && search_attr == 0)
2765 {
2766 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002767 extra_attr = hl_combine_attr(wlv.win_attr,
2768 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002770 }
2771 mb_c = c;
2772 if (enc_utf8 && utf_char2len(c) > 1)
2773 {
2774 mb_utf8 = TRUE;
2775 u8cc[0] = 0;
2776 c = 0xc0;
2777 }
2778 else
2779 mb_utf8 = FALSE;
2780 }
2781
zeertzjq2e7cba32022-06-10 15:30:32 +01002782 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2783 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002785 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2786 && wp->w_lcs_chars.leadmultispace != NULL)
2787 {
2788 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002789 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2790 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002791 multispace_pos = 0;
2792 }
2793
2794 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2795 c = wp->w_lcs_chars.trail;
2796
2797 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2798 c = wp->w_lcs_chars.lead;
2799
zeertzjq2e7cba32022-06-10 15:30:32 +01002800 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002801 c = wp->w_lcs_chars.space;
2802
2803
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 if (!attr_pri)
2805 {
2806 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002807 extra_attr = hl_combine_attr(wlv.win_attr,
2808 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002809 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 }
2811 mb_c = c;
2812 if (enc_utf8 && utf_char2len(c) > 1)
2813 {
2814 mb_utf8 = TRUE;
2815 u8cc[0] = 0;
2816 c = 0xc0;
2817 }
2818 else
2819 mb_utf8 = FALSE;
2820 }
2821 }
2822
2823 // Handling of non-printable characters.
2824 if (!vim_isprintc(c))
2825 {
2826 // when getting a character from the file, we may have to
2827 // turn it into something else on the way to putting it
2828 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002829 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 {
2831 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002832 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002834 char_u *sbr = get_showbreak_value(wp);
2835
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 // only adjust the tab_len, when at the first column
2837 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002838 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840#endif
2841 // tab amount depends on current column
2842#ifdef FEAT_VARTABS
2843 tab_len = tabstop_padding(vcol_adjusted,
2844 wp->w_buffer->b_p_ts,
2845 wp->w_buffer->b_p_vts_array) - 1;
2846#else
2847 tab_len = (int)wp->w_buffer->b_p_ts
2848 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2849#endif
2850
2851#ifdef FEAT_LINEBREAK
2852 if (!wp->w_p_lbr || !wp->w_p_list)
2853#endif
2854 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856#ifdef FEAT_LINEBREAK
2857 else
2858 {
2859 char_u *p;
2860 int len;
2861 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002864# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002867 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002868
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002870 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002871 && old_boguscols > 0
2872 && wlv.n_extra > tab_len)
2873 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002874# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002875 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002876 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002877 // If wlv.n_extra > 0, it gives the number of
2878 // chars, to use for a tab, else we need to
2879 // calculate the width for a tab.
2880 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2881 len = tab_len * tab2_len;
2882 if (wp->w_lcs_chars.tab3)
2883 len += mb_char2len(wp->w_lcs_chars.tab3)
2884 - tab2_len;
2885 if (wlv.n_extra > 0)
2886 len += wlv.n_extra - tab_len;
2887 c = wp->w_lcs_chars.tab1;
2888 p = alloc(len + 1);
2889 if (p == NULL)
2890 wlv.n_extra = 0;
2891 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002893 vim_memset(p, ' ', len);
2894 p[len] = NUL;
2895 vim_free(wlv.p_extra_free);
2896 wlv.p_extra_free = p;
2897 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002898 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002899 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002900
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002901 if (*p == NUL)
2902 {
2903 tab_len = i;
2904 break;
2905 }
2906
2907 // if tab3 is given, use it for the last
2908 // char
2909 if (wp->w_lcs_chars.tab3
2910 && i == tab_len - 1)
2911 lcs = wp->w_lcs_chars.tab3;
2912 p += mb_char2bytes(lcs, p);
2913 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002915 }
2916 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002917# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002918 // n_extra will be increased by
2919 // FIX_FOX_BOGUSCOLS macro below, so need to
2920 // adjust for that here
2921 if (wlv.vcol_off > 0)
2922 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002923# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002924 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926 }
2927#endif
2928#ifdef FEAT_CONCEAL
2929 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002930 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931
2932 // Tab alignment should be identical regardless of
2933 // 'conceallevel' value. So tab compensates of all
2934 // previous concealed characters, and thus resets
2935 // vcol_off and boguscols accumulated so far in the
2936 // line. Note that the tab can be longer than
2937 // 'tabstop' when there are concealed characters.
2938 FIX_FOR_BOGUSCOLS;
2939
2940 // Make sure, the highlighting for the tab char will be
2941 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002942 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002944 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 tab_len += vc_saved;
2946 }
2947#endif
2948 mb_utf8 = FALSE; // don't draw as UTF-8
2949 if (wp->w_p_list)
2950 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002952 ? wp->w_lcs_chars.tab3
2953 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954#ifdef FEAT_LINEBREAK
2955 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 else
2958#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 wlv.c_extra = wp->w_lcs_chars.tab2;
2960 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002962 extra_attr = hl_combine_attr(wlv.win_attr,
2963 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 mb_c = c;
2966 if (enc_utf8 && utf_char2len(c) > 1)
2967 {
2968 mb_utf8 = TRUE;
2969 u8cc[0] = 0;
2970 c = 0xc0;
2971 }
2972 }
2973 else
2974 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 wlv.c_final = NUL;
2976 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002977 c = ' ';
2978 }
2979 }
2980 else if (c == NUL
2981 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002982 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2983 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 && VIsual_mode != Ctrl_V
2985 && (
2986# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002987 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002989 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 && !(noinvcur
2991 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002992 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 && lcs_eol_one > 0)
2994 {
2995 // Display a '$' after the line or highlight an extra
2996 // character if the line break is included.
2997#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2998 // For a diff line the highlighting continues after the
2999 // "$".
3000 if (
3001# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003003# ifdef LINE_ATTR
3004 &&
3005# endif
3006# endif
3007# ifdef LINE_ATTR
3008 line_attr == 0
3009# endif
3010 )
3011#endif
3012 {
3013 // In virtualedit, visual selections may extend
3014 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003015 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003016 && wlv.tocol != MAXCOL
3017 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003018 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003019 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003021 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3022 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003023 else
3024 c = ' ';
3025 lcs_eol_one = -1;
3026 --ptr; // put it back at the NUL
3027 if (!attr_pri)
3028 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003029 extra_attr = hl_combine_attr(wlv.win_attr,
3030 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 n_attr = 1;
3032 }
3033 mb_c = c;
3034 if (enc_utf8 && utf_char2len(c) > 1)
3035 {
3036 mb_utf8 = TRUE;
3037 u8cc[0] = 0;
3038 c = 0xc0;
3039 }
3040 else
3041 mb_utf8 = FALSE; // don't draw as UTF-8
3042 }
3043 else if (c != NUL)
3044 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3046 if (wlv.n_extra == 0)
3047 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048#ifdef FEAT_RIGHTLEFT
3049 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003050 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 wlv.c_extra = NUL;
3053 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054#ifdef FEAT_LINEBREAK
3055 if (wp->w_p_lbr)
3056 {
3057 char_u *p;
3058
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 c = *wlv.p_extra;
3060 p = alloc(wlv.n_extra + 1);
3061 vim_memset(p, ' ', wlv.n_extra);
3062 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3063 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003064 vim_free(wlv.p_extra_free);
3065 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 }
3067 else
3068#endif
3069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 wlv.n_extra = byte2cells(c) - 1;
3071 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 }
3073 if (!attr_pri)
3074 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003075 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003076 extra_attr = hl_combine_attr(wlv.win_attr,
3077 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003078 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 }
3080 mb_utf8 = FALSE; // don't draw as UTF-8
3081 }
3082 else if (VIsual_active
3083 && (VIsual_mode == Ctrl_V
3084 || VIsual_mode == 'v')
3085 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003086 && wlv.tocol != MAXCOL
3087 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 && (
3089#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003090 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003092 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 {
3094 c = ' ';
3095 --ptr; // put it back at the NUL
3096 }
3097#if defined(LINE_ATTR)
3098 else if ((
3099# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003100 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101# endif
3102# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003103 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104# endif
3105 line_attr != 0
3106 ) && (
3107# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003108 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003110 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003112 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113# endif
3114 < wp->w_width)))
3115 {
3116 // Highlight until the right side of the window
3117 c = ' ';
3118 --ptr; // put it back at the NUL
3119
3120 // Remember we do the char for line highlighting.
3121 ++did_line_attr;
3122
3123 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003124 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003126 || (wp->w_p_list &&
3127 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003130 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003131 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003132 wlv.diff_hlf = HLF_CHD;
3133 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3137 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003138 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 || (wlv.vcol >= left_curline_col
3140 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 wlv.char_attr = hl_combine_attr(
3142 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143 }
3144 }
3145# endif
3146# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003147 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003148 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003150 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3151 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 if (!wlv.cul_screenline
3154 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003155 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003156 wlv.char_attr = hl_combine_attr(
3157 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003158 }
3159 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3161 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 }
3163# endif
3164 }
3165#endif
3166 }
3167
3168#ifdef FEAT_CONCEAL
3169 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003170 && (wp != curwin || lnum != wp->w_cursor.lnum
3171 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3173 && !(lnum_in_visual_area
3174 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3175 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003176 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003177 if (((prev_syntax_id != syntax_seqnr
3178 && (syntax_flags & HL_CONCEAL) != 0)
3179 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003180 && (syn_get_sub_char() != NUL
3181 || (has_match_conc && match_conc)
3182 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 && wp->w_p_cole != 3)
3184 {
3185 // First time at this concealed item: display one
3186 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003187 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 c = match_conc;
3189 else if (syn_get_sub_char() != NUL)
3190 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003191 else if (wp->w_lcs_chars.conceal != NUL)
3192 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 else
3194 c = ' ';
3195
3196 prev_syntax_id = syntax_seqnr;
3197
Bram Moolenaar1306b362022-08-06 15:59:06 +01003198 if (wlv.n_extra > 0)
3199 wlv.vcol_off += wlv.n_extra;
3200 wlv.vcol += wlv.n_extra;
3201 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 {
3203# ifdef FEAT_RIGHTLEFT
3204 if (wp->w_p_rl)
3205 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003206 wlv.col -= wlv.n_extra;
3207 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 }
3209 else
3210# endif
3211 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003212 wlv.boguscols += wlv.n_extra;
3213 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 }
3215 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217 n_attr = 0;
3218 }
3219 else if (n_skip == 0)
3220 {
3221 is_concealing = TRUE;
3222 n_skip = 1;
3223 }
3224 mb_c = c;
3225 if (enc_utf8 && utf_char2len(c) > 1)
3226 {
3227 mb_utf8 = TRUE;
3228 u8cc[0] = 0;
3229 c = 0xc0;
3230 }
3231 else
3232 mb_utf8 = FALSE; // don't draw as UTF-8
3233 }
3234 else
3235 {
3236 prev_syntax_id = 0;
3237 is_concealing = FALSE;
3238 }
3239
3240 if (n_skip > 0 && did_decrement_ptr)
3241 // not showing the '>', put pointer back to avoid getting stuck
3242 ++ptr;
3243
3244#endif // FEAT_CONCEAL
3245 }
3246
3247#ifdef FEAT_CONCEAL
3248 // In the cursor line and we may be concealing characters: correct
3249 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003250 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 && wp == curwin && lnum == wp->w_cursor.lnum
3252 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003253 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003255# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003259# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003260 wp->w_wcol = wlv.col - wlv.boguscols;
3261 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 did_wcol = TRUE;
3263 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003264# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003265 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003266# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 }
3268#endif
3269
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003270 // Use "extra_attr", but don't override visual selection highlighting,
3271 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003272 // Don't use "extra_attr" until n_attr_skip is zero.
3273 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003274 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003275 && (!attr_pri
3276#ifdef FEAT_PROP_POPUP
3277 || (text_prop_flags & PT_FLAG_OVERRIDE)
3278#endif
3279 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003280 {
3281#ifdef LINE_ATTR
3282 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003283 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 else
3285#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 }
3288
3289#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3290 // XIM don't send preedit_start and preedit_end, but they send
3291 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3292 // im_is_preediting() here.
3293 if (p_imst == IM_ON_THE_SPOT
3294 && xic != NULL
3295 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003296 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 && !p_imdisable
3298 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003299 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 {
3301 colnr_T tcol;
3302
3303 if (preedit_end_col == MAXCOL)
3304 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3305 else
3306 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003307 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 {
3309 if (feedback_old_attr < 0)
3310 {
3311 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 wlv.char_attr = im_get_feedback_attr(feedback_col);
3315 if (wlv.char_attr < 0)
3316 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 feedback_col++;
3318 }
3319 else if (feedback_old_attr >= 0)
3320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 feedback_old_attr = -1;
3323 feedback_col = 0;
3324 }
3325 }
3326#endif
3327 // Handle the case where we are in column 0 but not on the first
3328 // character of the line and the user wants us to show us a
3329 // special character (via 'listchars' option "precedes:<char>".
3330 if (lcs_prec_todo != NUL
3331 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003332 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3333 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003335 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003337 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 && c != NUL)
3339 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003340 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 lcs_prec_todo = NUL;
3342 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3343 {
3344 // Double-width character being overwritten by the "precedes"
3345 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003346 wlv.c_extra = MB_FILLER_CHAR;
3347 wlv.c_final = NUL;
3348 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 }
3352 mb_c = c;
3353 if (enc_utf8 && utf_char2len(c) > 1)
3354 {
3355 mb_utf8 = TRUE;
3356 u8cc[0] = 0;
3357 c = 0xc0;
3358 }
3359 else
3360 mb_utf8 = FALSE; // don't draw as UTF-8
3361 if (!attr_pri)
3362 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003363 saved_attr3 = wlv.char_attr; // save current attr
3364 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 n_attr3 = 1;
3366 }
3367 }
3368
3369 // At end of the text line or just after the last character.
3370 if ((c == NUL
3371#if defined(LINE_ATTR)
3372 || did_line_attr == 1
3373#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 {
3376#ifdef FEAT_SEARCH_EXTRA
3377 // flag to indicate whether prevcol equals startcol of search_hl or
3378 // one of the matches
3379 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3380 (long)(ptr - line) - (c == NUL));
3381#endif
3382 // Invert at least one char, used for Visual and empty line or
3383 // highlight match at end of line. If it's beyond the last
3384 // char on the screen, just overwrite that one (tricky!) Not
3385 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003386 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003387 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 && (VIsual_mode != Ctrl_V
3389 || lnum == VIsual.lnum
3390 || lnum == curwin->w_cursor.lnum)
3391 && c == NUL)
3392#ifdef FEAT_SEARCH_EXTRA
3393 // highlight 'hlsearch' match at end of line
3394 || (prevcol_hl_flag
3395# ifdef FEAT_SYN_HL
3396 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3397 && !(wp == curwin && VIsual_active))
3398# endif
3399# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003400 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401# endif
3402# if defined(LINE_ATTR)
3403 && did_line_attr <= 1
3404# endif
3405 )
3406#endif
3407 ))
3408 {
3409 int n = 0;
3410
3411#ifdef FEAT_RIGHTLEFT
3412 if (wp->w_p_rl)
3413 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003414 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 n = 1;
3416 }
3417 else
3418#endif
3419 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 n = -1;
3422 }
3423 if (n != 0)
3424 {
3425 // At the window boundary, highlight the last character
3426 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003427 wlv.off += n;
3428 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 }
3430 else
3431 {
3432 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003433 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
3437#ifdef FEAT_SEARCH_EXTRA
3438 if (area_attr == 0)
3439 {
3440 // Use attributes from match with highest priority among
3441 // 'search_hl' and the match list.
3442 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003443 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444 }
3445#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003446 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003447 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448#ifdef FEAT_RIGHTLEFT
3449 if (wp->w_p_rl)
3450 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003451 --wlv.col;
3452 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 }
3454 else
3455#endif
3456 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003457 ++wlv.col;
3458 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 ++wlv.vcol;
3461 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 }
3463 }
3464
3465 // At end of the text line.
3466 if (c == NUL)
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469
3470 // Update w_cline_height and w_cline_folded if the cursor line was
3471 // updated (saves a call to plines() later).
3472 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3473 {
3474 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003475 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476#ifdef FEAT_FOLDING
3477 curwin->w_cline_folded = FALSE;
3478#endif
3479 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3480 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 break;
3482 }
3483
3484 // Show "extends" character from 'listchars' if beyond the line end and
3485 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003486 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003487 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003488 && wp->w_p_list
3489 && !wp->w_p_wrap
3490#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003491 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492#endif
3493 && (
3494#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003495 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003497 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003499 || lcs_eol_one > 0
3500 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003503 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 mb_c = c;
3506 if (enc_utf8 && utf_char2len(c) > 1)
3507 {
3508 mb_utf8 = TRUE;
3509 u8cc[0] = 0;
3510 c = 0xc0;
3511 }
3512 else
3513 mb_utf8 = FALSE;
3514 }
3515
3516#ifdef FEAT_SYN_HL
3517 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 if (wlv.draw_color_col)
3519 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520
3521 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3522 // highlight the cursor position itself.
3523 // Also highlight the 'colorcolumn' if it is different than
3524 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003525 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3526 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003528 if (((wlv.draw_state == WL_LINE
3529 || wlv.draw_state == WL_BRI
3530 || wlv.draw_state == WL_SBR)
3531 && !lnum_in_visual_area
3532 && search_attr == 0
3533 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003534# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003535 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003536# endif
3537 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 {
3539 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3540 && lnum != wp->w_cursor.lnum)
3541 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003542 vcol_save_attr = wlv.char_attr;
3543 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3544 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 vcol_save_attr = wlv.char_attr;
3549 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551 }
3552#endif
3553
3554 // Store character to be displayed.
3555 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003556 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003557 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 {
3559 // Store the character.
3560#if defined(FEAT_RIGHTLEFT)
3561 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3562 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003563 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003564 --wlv.off;
3565 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 }
3567#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 if (enc_dbcs == DBCS_JPNU)
3570 {
3571 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 ScreenLines[wlv.off] = 0x8e;
3573 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 }
3575 else if (enc_utf8)
3576 {
3577 if (mb_utf8)
3578 {
3579 int i;
3580
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003583 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 for (i = 0; i < Screen_mco; ++i)
3585 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 if (u8cc[i] == 0)
3588 break;
3589 }
3590 }
3591 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 }
3594 if (multi_attr)
3595 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 multi_attr = 0;
3598 }
3599 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003602 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003603
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3605 {
3606 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ++wlv.off;
3608 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 if (enc_utf8)
3610 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003611 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 else
3613 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003614 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003615 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003617 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618#endif
3619 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003621 // When "wlv.tocol" is halfway a character, set it to the end
3622 // of the character, otherwise highlighting won't stop.
3623 if (wlv.tocol == wlv.vcol)
3624 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003625
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003627
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628#ifdef FEAT_RIGHTLEFT
3629 if (wp->w_p_rl)
3630 {
3631 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 --wlv.off;
3633 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634 }
3635#endif
3636 }
3637#ifdef FEAT_RIGHTLEFT
3638 if (wp->w_p_rl)
3639 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 --wlv.off;
3641 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643 else
3644#endif
3645 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ++wlv.off;
3647 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 }
3649 }
3650#ifdef FEAT_CONCEAL
3651 else if (wp->w_p_cole > 0 && is_concealing)
3652 {
3653 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003654 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 if (wlv.n_extra > 0)
3656 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657 if (wp->w_p_wrap)
3658 {
3659 // Special voodoo required if 'wrap' is on.
3660 //
3661 // Advance the column indicator to force the line
3662 // drawing to wrap early. This will make the line
3663 // take up the same screen space when parts are concealed,
3664 // so that cursor line computations aren't messed up.
3665 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 // trailing junk to be written out of the screen line
3668 // we are building, 'boguscols' keeps track of the number
3669 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003670 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003671 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003672 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673# ifdef FEAT_RIGHTLEFT
3674 if (wp->w_p_rl)
3675 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003676 wlv.col -= wlv.n_extra;
3677 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 }
3679 else
3680# endif
3681 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003682 wlv.col += wlv.n_extra;
3683 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 n_attr = 0;
3687 }
3688
3689
3690 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3691 {
3692 // Need to fill two screen columns.
3693# ifdef FEAT_RIGHTLEFT
3694 if (wp->w_p_rl)
3695 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 --wlv.boguscols;
3697 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 }
3699 else
3700# endif
3701 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 ++wlv.boguscols;
3703 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705 }
3706
3707# ifdef FEAT_RIGHTLEFT
3708 if (wp->w_p_rl)
3709 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 --wlv.boguscols;
3711 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 }
3713 else
3714# endif
3715 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 ++wlv.boguscols;
3717 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 }
3719 }
3720 else
3721 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003722 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003724 wlv.vcol += wlv.n_extra;
3725 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726 n_attr = 0;
3727 }
3728 }
3729
3730 }
3731#endif // FEAT_CONCEAL
3732 else
3733 --n_skip;
3734
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 // Only advance the "wlv.vcol" when after the 'number' or
3736 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003737 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003739 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003740#endif
3741 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743
3744#ifdef FEAT_SYN_HL
3745 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747#endif
3748
3749 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003750 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3751 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752
3753 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003755 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003757 if (n_attr_skip > 0)
3758 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759
3760 // At end of screen line and there is more to come: Display the line
3761 // so far. If there is no more to display it is caught above.
3762 if ((
3763#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003768 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003770 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003772#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003773 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003774#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003775 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003776 && wlv.p_extra != at_end_str)
3777 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3778 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 )
3780 {
3781#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003782 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003783 wlv_screen_line(wp, &wlv, FALSE);
3784 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003787 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 ++wlv.row;
3790 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791
3792 // When not wrapping and finished diff lines, or when displayed
3793 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003794 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003796 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003797#endif
3798#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003799 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003800#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003801 ) || lcs_eol_one == -1)
3802#ifdef FEAT_PROP_POPUP
3803 && !text_prop_follows
3804#endif
3805 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003807#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003808 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003809 {
3810 // do not output more of the line, only the "below" prop
3811 ptr += STRLEN(ptr);
3812# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003813 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003814# endif
3815 }
3816#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817
3818 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003819 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003821 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822#endif
3823 )
3824 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003825 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3826 draw_vsep_win(wp, wlv.row);
3827 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 }
3829
3830 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003831 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003833 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 break;
3835 }
3836
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003837 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003839 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003840#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003841#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003842 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003843#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003844 && wp->w_width == Columns)
3845 {
3846 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003847 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848
3849 // Special trick to make copy/paste of wrapped lines work with
3850 // xterm/screen: write an extra character beyond the end of
3851 // the line. This will work with all terminal types
3852 // (regardless of the xn,am settings).
3853 // Only do this on a fast tty.
3854 // Only do this if the cursor is on the current line
3855 // (something has been written in it).
3856 // Don't do this for the GUI.
3857 // Don't do this for double-width characters.
3858 // Don't do this for a window not at the right screen border.
3859 if (p_tf
3860#ifdef FEAT_GUI
3861 && !gui.in_use
3862#endif
3863 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003864 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3865 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 || (*mb_off2cells)(
3868 LineOffset[wlv.screen_row - 1]
3869 + (int)Columns - 2,
3870 LineOffset[wlv.screen_row]
3871 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 {
3873 // First make sure we are at the end of the screen line,
3874 // then output the same character again to let the
3875 // terminal know about the wrap. If the terminal doesn't
3876 // auto-wrap, we overwrite the character.
3877 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003878 screen_char(LineOffset[wlv.screen_row - 1]
3879 + (unsigned)Columns - 1,
3880 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881
3882 // When there is a multi-byte character, just output a
3883 // space to keep it simple.
3884 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003885 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886 out_char(' ');
3887 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003888 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889 + (Columns - 1)]);
3890 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892 screen_start(); // don't know where cursor is now
3893 }
3894 }
3895
Bram Moolenaar1306b362022-08-06 15:59:06 +01003896 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897
Bram Moolenaareed9d462021-02-15 20:38:25 +01003898 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003900 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003902 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003904 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003905 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906#endif
3907#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003908 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 // When the filler lines are actually below the last line of the
3910 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003911 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912 break;
3913#endif
3914 }
3915
3916 } // for every character in the line
3917
3918#ifdef FEAT_SPELL
3919 // After an empty line check first word for capital.
3920 if (*skipwhite(line) == NUL)
3921 {
3922 capcol_lnum = lnum + 1;
3923 cap_col = 0;
3924 }
3925#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003926#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927 vim_free(text_props);
3928 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003929 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003930#endif
3931
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003932 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003933 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934}