blob: f3024c2fcc6699cc77db6f19f373a31ea68aa58c [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 Moolenaareb4de622022-10-15 13:42:17 +0100373 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
374 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100375 {
376 long num;
377 char *fmt = "%*ld ";
378
379 if (wp->w_p_nu && !wp->w_p_rnu)
380 // 'number' + 'norelativenumber'
381 num = (long)wlv->lnum;
382 else
383 {
384 // 'relativenumber', don't use negative numbers
385 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
386 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
387 {
388 // 'number' + 'relativenumber'
389 num = wlv->lnum;
390 fmt = "%-*ld ";
391 }
392 }
393
394 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100395 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
397 ++wlv->p_extra)
398 *wlv->p_extra = '-';
399#ifdef FEAT_RIGHTLEFT
400 if (wp->w_p_rl) // reverse line numbers
401 {
402 char_u *p1, *p2;
403 int t;
404
405 // like rl_mirror(), but keep the space at the end
406 p2 = skipwhite(wlv->extra);
407 p2 = skiptowhite(p2) - 1;
408 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
409 {
410 t = *p1;
411 *p1 = *p2;
412 *p2 = t;
413 }
414 }
415#endif
416 wlv->p_extra = wlv->extra;
417 wlv->c_extra = NUL;
418 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100419 }
420 else
421 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 wlv->c_extra = ' ';
423 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100424 }
425 wlv->n_extra = number_width(wp) + 1;
426 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
427#ifdef FEAT_SYN_HL
428 // When 'cursorline' is set highlight the line number of
429 // the current line differently.
430 // When 'cursorlineopt' does not have "line" only
431 // highlight the line number itself.
432 // TODO: Can we use CursorLine instead of CursorLineNr
433 // when CursorLineNr isn't set?
434 if (wp->w_p_cul
435 && wlv->lnum == wp->w_cursor.lnum
436 && (wp->w_p_culopt_flags & CULOPT_NBR)
437 && (wlv->row == wlv->startrow + wlv->filler_lines
438 || (wlv->row > wlv->startrow + wlv->filler_lines
439 && (wp->w_p_culopt_flags & CULOPT_LINE))))
440 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
441#endif
442 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
443 && HL_ATTR(HLF_LNA) != 0)
444 // Use LineNrAbove
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
446 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
447 && HL_ATTR(HLF_LNB) != 0)
448 // Use LineNrBelow
449 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
450 }
451#ifdef FEAT_SIGNS
452 if (num_attr)
453 wlv->char_attr = num_attr;
454#endif
455 }
456}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100457
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100458#ifdef FEAT_LINEBREAK
459 static void
460handle_breakindent(win_T *wp, winlinevars_T *wlv)
461{
462 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100463 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100464 // draw indent after showbreak value
465 wlv->draw_state = WL_BRI;
466 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
467 // After the showbreak, draw the breakindent
468 wlv->draw_state = WL_BRI - 1;
469
470 // draw 'breakindent': indent wrapped text accordingly
471 if (wlv->draw_state == WL_BRI - 1)
472 {
473 wlv->draw_state = WL_BRI;
474 // if wlv->need_showbreak is set, breakindent also applies
475 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
476# ifdef FEAT_DIFF
477 && wlv->filler_lines == 0
478# endif
479# ifdef FEAT_PROP_POPUP
480 && !wlv->dont_use_showbreak
481# endif
482 )
483 {
484 wlv->char_attr = 0;
485# ifdef FEAT_DIFF
486 if (wlv->diff_hlf != (hlf_T)0)
487 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
488# endif
489 wlv->p_extra = NULL;
490 wlv->c_extra = ' ';
491 wlv->c_final = NUL;
492 wlv->n_extra = get_breakindent_win(wp,
493 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
494 if (wlv->row == wlv->startrow)
495 {
496 wlv->n_extra -= win_col_off2(wp);
497 if (wlv->n_extra < 0)
498 wlv->n_extra = 0;
499 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100500 if (wp->w_skipcol > 0 && wlv->startrow == 0
501 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502 wlv->need_showbreak = FALSE;
503 // Correct end of highlighted area for 'breakindent',
504 // required when 'linebreak' is also set.
505 if (wlv->tocol == wlv->vcol)
506 wlv->tocol += wlv->n_extra;
507 }
508 }
509}
510#endif
511
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100512#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
513 static void
514handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
515{
516# ifdef FEAT_DIFF
517 if (wlv->filler_todo > 0)
518 {
519 // Draw "deleted" diff line(s).
520 if (char2cells(wp->w_fill_chars.diff) > 1)
521 {
522 wlv->c_extra = '-';
523 wlv->c_final = NUL;
524 }
525 else
526 {
527 wlv->c_extra = wp->w_fill_chars.diff;
528 wlv->c_final = NUL;
529 }
530# ifdef FEAT_RIGHTLEFT
531 if (wp->w_p_rl)
532 wlv->n_extra = wlv->col + 1;
533 else
534# endif
535 wlv->n_extra = wp->w_width - wlv->col;
536 wlv->char_attr = HL_ATTR(HLF_DED);
537 }
538# endif
539
540# ifdef FEAT_LINEBREAK
541 char_u *sbr = get_showbreak_value(wp);
542 if (*sbr != NUL && wlv->need_showbreak)
543 {
544 // Draw 'showbreak' at the start of each broken line.
545 wlv->p_extra = sbr;
546 wlv->c_extra = NUL;
547 wlv->c_final = NUL;
548 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100549 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100550 wlv->need_showbreak = FALSE;
551 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
552 // Correct end of highlighted area for 'showbreak',
553 // required when 'linebreak' is also set.
554 if (wlv->tocol == wlv->vcol)
555 wlv->tocol += wlv->n_extra;
556 // combine 'showbreak' with 'wincolor'
557 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
558# ifdef FEAT_SYN_HL
559 // combine 'showbreak' with 'cursorline'
560 if (wlv->cul_attr != 0)
561 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
562# endif
563 }
564# endif
565}
566#endif
567
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100568#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100569/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100570 * Return the cell size of virtual text after truncation.
571 */
572 static int
573textprop_size_after_trunc(
574 win_T *wp,
575 int flags, // TP_FLAG_ALIGN_*
576 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100577 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100578 char_u *text,
579 int *n_used_ptr)
580{
581 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100582 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100583 int len = (int)STRLEN(text);
584 int strsize = 0;
585 int n_used;
586
Bram Moolenaar7e017462022-10-11 21:02:09 +0100587 // if the remaining size is to small and 'wrap' is set we wrap anyway and
588 // use the next line
589 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100591 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100592 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100593 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
594 {
595 int clen = ptr2cells(text + n_used);
596
597 if (strsize + clen > space)
598 break;
599 strsize += clen;
600 }
601 *n_used_ptr = n_used;
602 return strsize;
603}
604
605/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100606 * Take care of padding, right-align and truncation of virtual text after a
607 * line.
608 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
609 * padding, right-align and truncation. Otherwise only the size is computed.
610 * When "n_attr" is NULL returns the number of screen cells used.
611 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100612 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 int
614text_prop_position(
615 win_T *wp,
616 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100617 int vcol UNUSED, // current text column
618 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100619 int *n_extra, // nr of bytes for virtual text
620 char_u **p_extra, // virtual text
621 int *n_attr, // attribute cells, NULL if not used
622 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200623{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
627 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
628 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
629 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100630 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int before = room; // spaces before the text
633 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100634 int n_used = *n_extra;
635 char_u *l = NULL;
636 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100637 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100638 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100639 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
640 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200641
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100642 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100643 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100644 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100645 int skip_add = 0;
646
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100647 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100650 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 }
652 else
653 {
654 // Right-align: fill with before
655 if (right)
656 before -= cells;
657 if (before < 0
658 || !(right || below)
659 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100660 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100663 if (right && (wrap
664 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 {
666 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 before = wp->w_width - col_off - strsize + room;
668 if (before < 0)
669 before = 0;
670 else
671 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100672 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100673 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100674 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100675 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100677 else if (below && before > 0)
678 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100679 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100680 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100681
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 // With 'nowrap' add one to show the "extends" character if needed (it
683 // doesn't show if the text just fits).
684 if (!wp->w_p_wrap
685 && n_used < *n_extra
686 && wp->w_lcs_chars.ext != NUL
687 && wp->w_p_list)
688 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100689 if (!wp->w_p_wrap && below && padding > 0)
690 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100691
692 // add 1 for NUL, 2 for when '…' is used
693 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100694 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100695 if (n_attr == NULL || l != NULL)
696 {
697 int off = 0;
698
699 if (n_attr != NULL)
700 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 vim_memset(l, ' ', before);
702 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 if (padding > 0)
704 {
705 vim_memset(l + off, ' ', padding);
706 off += padding;
707 }
708 vim_strncpy(l + off, *p_extra, n_used);
709 off += n_used;
710 }
711 else
712 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100713 off = before + after + padding + n_used;
714 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100715 }
716 if (n_attr != NULL)
717 {
718 if (n_used < *n_extra && wp->w_p_wrap)
719 {
720 char_u *lp = l + off - 1;
721
722 if (has_mbyte)
723 {
724 // change last character to '…'
725 lp -= (*mb_head_off)(l, lp);
726 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100727 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
729 else
730 // change last character to '>'
731 *lp = '>';
732 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100733 else if (after > 0)
734 {
735 vim_memset(l + off, ' ', after);
736 l[off + after] = NUL;
737 }
738
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100740 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100742 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100743 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100744
745 // Add "skip_add" when starting a new line or wrapping,
746 // n_attr_skip will then be decremented in the number column.
747 *n_attr_skip = before + padding
748 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 }
750 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100751 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100752
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100753 if (n_attr == NULL)
754 return cells;
755 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200756}
757#endif
758
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100759/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100760 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100761 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
762 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100763 */
764 static void
765wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
766{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100767 if (wlv->row == 0 && wp->w_skipcol > 0
768#if defined(FEAT_LINEBREAK)
769 && *get_showbreak_value(wp) == NUL
770#endif
771 )
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100772 {
773 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100774 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100775
Bram Moolenaareb4de622022-10-15 13:42:17 +0100776 if (wp->w_p_nu && wp->w_p_rnu)
777 // Do not overwrite the line number, change "123 text" to
778 // "123>>>xt".
779 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
780 {
781 ++off;
782 ++skip;
783 }
784
785 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100786 {
787 ScreenLines[off] = '<';
788 if (enc_utf8)
789 ScreenLinesUC[off] = 0;
790 ScreenAttrs[off] = HL_ATTR(HLF_AT);
791 ++off;
792 }
793 }
794
795 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
796 negative_width ? -wp->w_width : wp->w_width,
797 wlv->screen_line_flags);
798}
799
800/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100801 * Called when finished with the line: draw the screen line and handle any
802 * highlighting until the right of the window.
803 */
804 static void
805draw_screen_line(win_T *wp, winlinevars_T *wlv)
806{
807#ifdef FEAT_SYN_HL
808 long v;
809
810 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
811 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100812 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100813 else
814 v = wp->w_leftcol;
815
816 // check if line ends before left margin
817 if (wlv->vcol < v + wlv->col - win_col_off(wp))
818 wlv->vcol = v + wlv->col - win_col_off(wp);
819# ifdef FEAT_CONCEAL
820 // Get rid of the boguscols now, we want to draw until the right
821 // edge for 'cursorcolumn'.
822 wlv->col -= wlv->boguscols;
823 wlv->boguscols = 0;
824# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
825# else
826# define VCOL_HLC (wlv->vcol)
827# endif
828
829 if (wlv->draw_color_col)
830 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
831
832 if (((wp->w_p_cuc
833 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
834 && (int)wp->w_virtcol <
835 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
836 && wlv->lnum != wp->w_cursor.lnum)
837 || wlv->draw_color_col
838 || wlv->win_attr != 0)
839# ifdef FEAT_RIGHTLEFT
840 && !wp->w_p_rl
841# endif
842 )
843 {
844 int rightmost_vcol = 0;
845 int i;
846
847 if (wp->w_p_cuc)
848 rightmost_vcol = wp->w_virtcol;
849 if (wlv->draw_color_col)
850 // determine rightmost colorcolumn to possibly draw
851 for (i = 0; wlv->color_cols[i] >= 0; ++i)
852 if (rightmost_vcol < wlv->color_cols[i])
853 rightmost_vcol = wlv->color_cols[i];
854
855 while (wlv->col < wp->w_width)
856 {
857 ScreenLines[wlv->off] = ' ';
858 if (enc_utf8)
859 ScreenLinesUC[wlv->off] = 0;
860 ScreenCols[wlv->off] = MAXCOL;
861 ++wlv->col;
862 if (wlv->draw_color_col)
863 wlv->draw_color_col = advance_color_col(
864 VCOL_HLC, &wlv->color_cols);
865
866 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
867 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
868 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
869 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
870 else
871 ScreenAttrs[wlv->off++] = wlv->win_attr;
872
873 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
874 break;
875
876 ++wlv->vcol;
877 }
878 }
879#endif
880
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100881 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882 ++wlv->row;
883 ++wlv->screen_row;
884}
885#undef VCOL_HLC
886
887/*
888 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100889 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890 */
891 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100892win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100893{
894 wlv->col = 0;
895 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
896
897#ifdef FEAT_RIGHTLEFT
898 if (wp->w_p_rl)
899 {
900 // Rightleft window: process the text in the normal direction, but put
901 // it in current_ScreenLine[] from right to left. Start at the
902 // rightmost column of the window.
903 wlv->col = wp->w_width - 1;
904 wlv->off += wlv->col;
905 wlv->screen_line_flags |= SLF_RIGHTLEFT;
906 }
907#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100908 if (save_extra)
909 {
910 // reset the drawing state for the start of a wrapped line
911 wlv->draw_state = WL_START;
912 wlv->saved_n_extra = wlv->n_extra;
913 wlv->saved_p_extra = wlv->p_extra;
914 wlv->saved_c_extra = wlv->c_extra;
915 wlv->saved_c_final = wlv->c_final;
916#ifdef FEAT_SYN_HL
917 if (!(wlv->cul_screenline
918# ifdef FEAT_DIFF
919 && wlv->diff_hlf == (hlf_T)0
920# endif
921 ))
922 wlv->saved_char_attr = wlv->char_attr;
923 else
924#endif
925 wlv->saved_char_attr = 0;
926 wlv->n_extra = 0;
927 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100928}
929
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200930/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100931 * Called when wlv->draw_state is set to WL_LINE.
932 */
933 static void
934win_line_continue(winlinevars_T *wlv)
935{
936 if (wlv->saved_n_extra > 0)
937 {
938 // Continue item from end of wrapped line.
939 wlv->n_extra = wlv->saved_n_extra;
940 wlv->c_extra = wlv->saved_c_extra;
941 wlv->c_final = wlv->saved_c_final;
942 wlv->p_extra = wlv->saved_p_extra;
943 wlv->char_attr = wlv->saved_char_attr;
944 }
945 else
946 wlv->char_attr = wlv->win_attr;
947}
948
949/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200950 * Display line "lnum" of window 'wp' on the screen.
951 * Start at row "startrow", stop when "endrow" is reached.
952 * wp->w_virtcol needs to be valid.
953 *
954 * Return the number of last row the line occupies.
955 */
956 int
957win_line(
958 win_T *wp,
959 linenr_T lnum,
960 int startrow,
961 int endrow,
962 int nochange UNUSED, // not updating for changed text
963 int number_only) // only update the number column
964{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100965 winlinevars_T wlv; // variables passed between functions
966
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200967 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100968 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969 char_u *line; // current line
970 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971
Bram Moolenaar1306b362022-08-06 15:59:06 +0100972#ifdef FEAT_PROP_POPUP
973 char_u *p_extra_free2 = NULL; // another p_extra to be freed
974#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200975 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000976#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000977 int in_linebreak = FALSE; // n_extra set for showing linebreak
978#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100980 // displaying eol at end-of-line
981 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000982 int lcs_prec_todo = wp->w_lcs_chars.prec;
983 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100985 int n_attr = 0; // chars with special attr
986 int n_attr_skip = 0; // chars to skip before using extra_attr
987 int saved_attr2 = 0; // char_attr saved for n_attr
988 int n_attr3 = 0; // chars with overruling special attr
989 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990
Bram Moolenaarcd105412022-10-10 19:50:42 +0100991 int n_skip = 0; // nr of cells to skip for 'nowrap' or
992 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100993#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +0100994 int skip_cells = 0; // nr of cells to skip for virtual text
995 // after the line, when w_skipcol is
996 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +0100997#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200999 int fromcol_prev = -2; // start of inverting after cursor
1000 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001001 int lnum_in_visual_area = FALSE;
1002 pos_T pos;
1003 long v;
1004
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005 int attr_pri = FALSE; // char_attr has priority
1006 int area_highlighting = FALSE; // Visual or incsearch highlighting
1007 // in this line
1008 int vi_attr = 0; // attributes for Visual and incsearch
1009 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010 int area_attr = 0; // attributes desired by highlighting
1011 int search_attr = 0; // attributes desired by 'hlsearch'
1012#ifdef FEAT_SYN_HL
1013 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1014 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001015 int prev_syntax_col = -1; // column of prev_syntax_attr
1016 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int has_syntax = FALSE; // this buffer has syntax highl.
1018 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001020#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001021 int text_prop_count;
1022 int text_prop_next = 0; // next text property to use
1023 textprop_T *text_props = NULL;
1024 int *text_prop_idxs = NULL;
1025 int text_props_active = 0;
1026 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001027 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001029 int text_prop_attr_comb = 0; // text_prop_attr combined with
1030 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001031 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001032 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001033 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001034 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001035 int saved_search_attr = 0; // search_attr to be used when n_extra
1036 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001037 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038#endif
1039#ifdef FEAT_SPELL
1040 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001041 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042# define SPWORDLEN 150
1043 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1044 int nextlinecol = 0; // column where nextline[] starts
1045 int nextline_idx = 0; // index in nextline[] where next line
1046 // starts
1047 int spell_attr = 0; // attributes desired by spelling
1048 int word_end = 0; // last byte with same spell_attr
1049 static linenr_T checked_lnum = 0; // line number for "checked_col"
1050 static int checked_col = 0; // column in "checked_lnum" up to which
1051 // there are no spell errors
1052 static int cap_col = -1; // column to check for Cap word
1053 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1054 int cur_checked_col = 0; // checked column for current line
1055#endif
1056 int extra_check = 0; // has extra highlighting
1057 int multi_attr = 0; // attributes desired by multibyte
1058 int mb_l = 1; // multi-byte byte length
1059 int mb_c = 0; // decoded multi-byte character
1060 int mb_utf8 = FALSE; // screen char is UTF-8 char
1061 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063 int change_start = MAXCOL; // first col of changed area
1064 int change_end = -1; // last col of changed area
1065#endif
1066 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001067 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001068 int in_multispace = FALSE; // in multiple consecutive spaces
1069 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1071 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1072# define LINE_ATTR
1073 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001074 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001077 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078#ifdef FEAT_ARABIC
1079 int prev_c = 0; // previous Arabic character
1080 int prev_c1 = 0; // first composing char for prev_c
1081#endif
1082#if defined(LINE_ATTR)
1083 int did_line_attr = 0;
1084#endif
1085#ifdef FEAT_TERMINAL
1086 int get_term_attr = FALSE;
1087#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088
Martin Tournoijba43e762022-10-13 22:12:15 +01001089#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001090 // margin columns for the screen line, needed for when 'cursorlineopt'
1091 // contains "screenline"
1092 int left_curline_col = 0;
1093 int right_curline_col = 0;
1094#endif
1095
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1097 int feedback_col = 0;
1098 int feedback_old_attr = -1;
1099#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100
1101#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1102 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001103#endif
1104#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001105 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106#endif
1107#ifdef FEAT_CONCEAL
1108 int syntax_flags = 0;
1109 int syntax_seqnr = 0;
1110 int prev_syntax_id = 0;
1111 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1112 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 int did_wcol = FALSE;
1114 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001115# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116# define FIX_FOR_BOGUSCOLS \
1117 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001118 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001119 wlv.vcol -= wlv.vcol_off; \
1120 wlv.vcol_off = 0; \
1121 wlv.col -= wlv.boguscols; \
1122 old_boguscols = wlv.boguscols; \
1123 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 }
1125#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001126# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127#endif
1128
1129 if (startrow > endrow) // past the end already!
1130 return startrow;
1131
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001132 CLEAR_FIELD(wlv);
1133
1134 wlv.lnum = lnum;
1135 wlv.startrow = startrow;
1136 wlv.row = startrow;
1137 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001138 wlv.fromcol = -10;
1139 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001140#ifdef FEAT_LINEBREAK
1141 wlv.vcol_sbr = -1;
1142#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143
1144 if (!number_only)
1145 {
1146 // To speed up the loop below, set extra_check when there is linebreak,
1147 // trailing white space and/or syntax processing to be done.
1148#ifdef FEAT_LINEBREAK
1149 extra_check = wp->w_p_lbr;
1150#endif
1151#ifdef FEAT_SYN_HL
1152 if (syntax_present(wp) && !wp->w_s->b_syn_error
1153# ifdef SYN_TIME_LIMIT
1154 && !wp->w_s->b_syn_slow
1155# endif
1156 )
1157 {
1158 // Prepare for syntax highlighting in this line. When there is an
1159 // error, stop syntax highlighting.
1160 save_did_emsg = did_emsg;
1161 did_emsg = FALSE;
1162 syntax_start(wp, lnum);
1163 if (did_emsg)
1164 wp->w_s->b_syn_error = TRUE;
1165 else
1166 {
1167 did_emsg = save_did_emsg;
1168#ifdef SYN_TIME_LIMIT
1169 if (!wp->w_s->b_syn_slow)
1170#endif
1171 {
1172 has_syntax = TRUE;
1173 extra_check = TRUE;
1174 }
1175 }
1176 }
1177
1178 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001179 wlv.color_cols = wp->w_p_cc_cols;
1180 if (wlv.color_cols != NULL)
1181 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182#endif
1183
1184#ifdef FEAT_TERMINAL
1185 if (term_show_buffer(wp->w_buffer))
1186 {
1187 extra_check = TRUE;
1188 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001189 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001190 }
1191#endif
1192
1193#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001194 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 {
1196 // Prepare for spell checking.
1197 has_spell = TRUE;
1198 extra_check = TRUE;
1199
1200 // Get the start of the next line, so that words that wrap to the
1201 // next line are found too: "et<line-break>al.".
1202 // Trick: skip a few chars for C/shell/Vim comments
1203 nextline[SPWORDLEN] = NUL;
1204 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1205 {
1206 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1207 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1208 }
1209
1210 // When a word wrapped from the previous line the start of the
1211 // current line is valid.
1212 if (lnum == checked_lnum)
1213 cur_checked_col = checked_col;
1214 checked_lnum = 0;
1215
1216 // When there was a sentence end in the previous line may require a
1217 // word starting with capital in this line. In line 1 always check
1218 // the first word.
1219 if (lnum != capcol_lnum)
1220 cap_col = -1;
1221 if (lnum == 1)
1222 cap_col = 0;
1223 capcol_lnum = 0;
1224 }
1225#endif
1226
1227 // handle Visual active in this window
1228 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1229 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001230 pos_T *top, *bot;
1231
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1233 {
1234 // Visual is after curwin->w_cursor
1235 top = &curwin->w_cursor;
1236 bot = &VIsual;
1237 }
1238 else
1239 {
1240 // Visual is before curwin->w_cursor
1241 top = &VIsual;
1242 bot = &curwin->w_cursor;
1243 }
1244 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1245 if (VIsual_mode == Ctrl_V)
1246 {
1247 // block mode
1248 if (lnum_in_visual_area)
1249 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001250 wlv.fromcol = wp->w_old_cursor_fcol;
1251 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 }
1253 }
1254 else
1255 {
1256 // non-block mode
1257 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001258 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 else if (lnum == top->lnum)
1260 {
1261 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001262 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 else
1264 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001265 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001267 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001268 }
1269 }
1270 if (VIsual_mode != 'V' && lnum == bot->lnum)
1271 {
1272 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1273 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001274 wlv.fromcol = -10;
1275 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 }
1277 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 else
1280 {
1281 pos = *bot;
1282 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001283 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1284 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285 else
1286 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001287 getvvcol(wp, &pos, NULL, NULL,
1288 (colnr_T *)&wlv.tocol);
1289 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 }
1291 }
1292 }
1293 }
1294
1295 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001296 if (!highlight_match && lnum == curwin->w_cursor.lnum
1297 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298#ifdef FEAT_GUI
1299 && !gui.in_use
1300#endif
1301 )
1302 noinvcur = TRUE;
1303
1304 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001305 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 {
1307 area_highlighting = TRUE;
1308 vi_attr = HL_ATTR(HLF_V);
1309#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1310 if ((clip_star.available && !clip_star.owned
1311 && clip_isautosel_star())
1312 || (clip_plus.available && !clip_plus.owned
1313 && clip_isautosel_plus()))
1314 vi_attr = HL_ATTR(HLF_VNC);
1315#endif
1316 }
1317 }
1318
1319 // handle 'incsearch' and ":s///c" highlighting
1320 else if (highlight_match
1321 && wp == curwin
1322 && lnum >= curwin->w_cursor.lnum
1323 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1324 {
1325 if (lnum == curwin->w_cursor.lnum)
1326 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001327 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1331 {
1332 pos.lnum = lnum;
1333 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001334 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 }
1336 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001337 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001338 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1340 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 area_highlighting = TRUE;
1342 vi_attr = HL_ATTR(HLF_I);
1343 }
1344 }
1345
1346#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001347 wlv.filler_lines = diff_check(wp, lnum);
1348 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001350 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 {
1352 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001357 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001358 }
1359 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001360 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001361 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 area_highlighting = TRUE;
1363 }
1364 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001365 wlv.filler_lines = wp->w_topfill;
1366 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367#endif
1368
1369#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001370 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001371 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001372 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373#endif
1374
1375#ifdef LINE_ATTR
1376# ifdef FEAT_SIGNS
1377 // If this line has a sign with line highlighting set line_attr.
1378 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001379 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380# endif
1381# if defined(FEAT_QUICKFIX)
1382 // Highlight the current line in the quickfix window.
1383 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1384 line_attr = HL_ATTR(HLF_QFL);
1385# endif
1386 if (line_attr != 0)
1387 area_highlighting = TRUE;
1388#endif
1389
1390 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1391 ptr = line;
1392
1393#ifdef FEAT_SPELL
1394 if (has_spell && !number_only)
1395 {
1396 // For checking first word with a capital skip white space.
1397 if (cap_col == 0)
1398 cap_col = getwhitecols(line);
1399
1400 // To be able to spell-check over line boundaries copy the end of the
1401 // current line into nextline[]. Above the start of the next line was
1402 // copied to nextline[SPWORDLEN].
1403 if (nextline[SPWORDLEN] == NUL)
1404 {
1405 // No next line or it is empty.
1406 nextlinecol = MAXCOL;
1407 nextline_idx = 0;
1408 }
1409 else
1410 {
1411 v = (long)STRLEN(line);
1412 if (v < SPWORDLEN)
1413 {
1414 // Short line, use it completely and append the start of the
1415 // next line.
1416 nextlinecol = 0;
1417 mch_memmove(nextline, line, (size_t)v);
1418 STRMOVE(nextline + v, nextline + SPWORDLEN);
1419 nextline_idx = v + 1;
1420 }
1421 else
1422 {
1423 // Long line, use only the last SPWORDLEN bytes.
1424 nextlinecol = v - SPWORDLEN;
1425 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1426 nextline_idx = SPWORDLEN + 1;
1427 }
1428 }
1429 }
1430#endif
1431
1432 if (wp->w_p_list)
1433 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001434 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001435 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001436 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001437 || wp->w_lcs_chars.trail
1438 || wp->w_lcs_chars.lead
1439 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001441
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001443 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 {
1445 trailcol = (colnr_T)STRLEN(ptr);
1446 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1447 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001448 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001450 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001451 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001452 {
1453 leadcol = 0;
1454 while (VIM_ISWHITE(ptr[leadcol]))
1455 ++leadcol;
1456 if (ptr[leadcol] == NUL)
1457 // in a line full of spaces all of them are treated as trailing
1458 leadcol = (colnr_T)0;
1459 else
1460 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001461 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001462 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001463 }
1464
Bram Moolenaard7657e92022-09-20 18:59:30 +01001465 wlv.wcr_attr = get_wcr_attr(wp);
1466 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001467 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001468 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 area_highlighting = TRUE;
1470 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001471
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001472#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001474 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475#endif
1476
1477 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1478 // first character to be displayed.
1479 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001480 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 else
1482 v = wp->w_leftcol;
1483 if (v > 0 && !number_only)
1484 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001485 char_u *prev_ptr = ptr;
1486 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001487 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001489 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001490 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001491 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001492 charsize = win_lbr_chartabsize(&cts, NULL);
1493 cts.cts_vcol += charsize;
1494 prev_ptr = cts.cts_ptr;
1495 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001497 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001498 ptr = cts.cts_ptr;
1499 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500
1501 // When:
1502 // - 'cuc' is set, or
1503 // - 'colorcolumn' is set, or
1504 // - 'virtualedit' is set, or
1505 // - the visual mode is active,
1506 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001507 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001509 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510#endif
1511 virtual_active() ||
1512 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001513 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514
1515 // Handle a character that's not completely on the screen: Put ptr at
1516 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001517 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001519 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 ptr = prev_ptr;
1521 // If the character fits on the screen, don't need to skip it.
1522 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001523 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1524 && wlv.col == 0)
1525 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 }
1527
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001528#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001529 // If there the text doesn't reach to the desired column, need to skip
1530 // "skip_cells" cells when virtual text follows.
1531 if (!wp->w_p_wrap && v > wlv.vcol)
1532 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001533#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001534
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 // Adjust for when the inverted text is before the screen,
1536 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001537 if (wlv.tocol <= wlv.vcol)
1538 wlv.fromcol = 0;
1539 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1540 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541
1542#ifdef FEAT_LINEBREAK
1543 // When w_skipcol is non-zero, first line needs 'showbreak'
1544 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001545 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546#endif
1547#ifdef FEAT_SPELL
1548 // When spell checking a word we need to figure out the start of the
1549 // word and if it's badly spelled or not.
1550 if (has_spell)
1551 {
1552 int len;
1553 colnr_T linecol = (colnr_T)(ptr - line);
1554 hlf_T spell_hlf = HLF_COUNT;
1555
1556 pos = wp->w_cursor;
1557 wp->w_cursor.lnum = lnum;
1558 wp->w_cursor.col = linecol;
1559 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1560
1561 // spell_move_to() may call ml_get() and make "line" invalid
1562 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1563 ptr = line + linecol;
1564
1565 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1566 {
1567 // no bad word found at line start, don't check until end of a
1568 // word
1569 spell_hlf = HLF_COUNT;
1570 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1571 }
1572 else
1573 {
1574 // bad word found, use attributes until end of word
1575 word_end = wp->w_cursor.col + len + 1;
1576
1577 // Turn index into actual attributes.
1578 if (spell_hlf != HLF_COUNT)
1579 spell_attr = highlight_attr[spell_hlf];
1580 }
1581 wp->w_cursor = pos;
1582
1583# ifdef FEAT_SYN_HL
1584 // Need to restart syntax highlighting for this line.
1585 if (has_syntax)
1586 syntax_start(wp, lnum);
1587# endif
1588 }
1589#endif
1590 }
1591
1592 // Correct highlighting for cursor that can't be disabled.
1593 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001594 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 {
1596 if (noinvcur)
1597 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001598 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 {
1600 // highlighting starts at cursor, let it start just after the
1601 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001602 fromcol_prev = wlv.fromcol;
1603 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001605 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 // restart highlighting after the cursor
1607 fromcol_prev = wp->w_virtcol;
1608 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001609 if (wlv.fromcol >= wlv.tocol)
1610 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001611 }
1612
1613#ifdef FEAT_SEARCH_EXTRA
1614 if (!number_only)
1615 {
1616 v = (long)(ptr - line);
1617 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1618 &line, &screen_search_hl,
1619 &search_attr);
1620 ptr = line + v; // "line" may have been updated
1621 }
1622#endif
1623
1624#ifdef FEAT_SYN_HL
1625 // Cursor line highlighting for 'cursorline' in the current window.
1626 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1627 {
1628 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001629 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 if (!(wp == curwin && VIsual_active)
1631 && wp->w_p_culopt_flags != CULOPT_NBR)
1632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001633 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1635
1636 // Only set line_attr here when "screenline" is not present in
1637 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001638 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001640 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001641# ifdef FEAT_SIGNS
1642 // Combine the 'cursorline' and sign highlighting, depending on
1643 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001644 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001645 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001646 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001647 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001648 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001649 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001650 }
1651 else
1652# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001653# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001654 // let the line attribute overrule 'cursorline', otherwise
1655 // it disappears when both have background set;
1656 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001657 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001658# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001659 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001660# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 }
1662 else
1663 {
1664 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1666 }
1667 area_highlighting = TRUE;
1668 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 }
1670#endif
1671
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001672#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001673 {
1674 char_u *prop_start;
1675
1676 text_prop_count = get_text_props(wp->w_buffer, lnum,
1677 &prop_start, FALSE);
1678 if (text_prop_count > 0)
1679 {
1680 // Make a copy of the properties, so that they are properly
1681 // aligned.
1682 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1683 if (text_props != NULL)
1684 mch_memmove(text_props, prop_start,
1685 text_prop_count * sizeof(textprop_T));
1686
1687 // Allocate an array for the indexes.
1688 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001689 if (text_prop_idxs == NULL)
1690 VIM_CLEAR(text_props);
1691
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001692 if (text_props != NULL)
1693 {
1694 area_highlighting = TRUE;
1695 extra_check = TRUE;
1696 for (int i = 0; i < text_prop_count; ++i)
1697 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1698 ++wlv.text_prop_above_count;
1699 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 }
1701 }
1702#endif
1703
Bram Moolenaar1306b362022-08-06 15:59:06 +01001704 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001705
1706 // Repeat for the whole displayed line.
1707 for (;;)
1708 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001709 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001711 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712#endif
1713#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001714 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001716
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001717 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001718 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001720#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001721 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001722 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001723 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001724 line_attr = line_attr_save;
1725 }
1726#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001727 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001729 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 if (cmdwin_type != 0 && wp == curwin)
1731 {
1732 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 wlv.n_extra = 1;
1734 wlv.c_extra = cmdwin_type;
1735 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001736 wlv.char_attr =
1737 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001738 }
1739 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001741 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001742 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001743 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001744 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 }
1746#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001748 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001749 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001750 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001751 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001752 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001753 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
1755#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001757 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001758 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001759 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001760 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001763 // Check if 'breakindent' applies and show it.
1764 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1765 if (wlv.n_extra == 0)
1766 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001771 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001772 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
1774#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001775 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001778 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 }
1780 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001781
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001783 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001784 && wlv.vcol >= left_curline_col
1785 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001787 wlv.cul_attr = HL_ATTR(HLF_CUL);
1788 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 }
1790#endif
1791
1792 // When still displaying '$' of change command, stop at cursor.
1793 // When only displaying the (relative) line number and that's done,
1794 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001795 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001796 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001797 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001799 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800#endif
1801 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001803 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 // Pretend we have finished updating the window. Except when
1805 // 'cursorcolumn' is set.
1806#ifdef FEAT_SYN_HL
1807 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001808 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 else
1810#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001811 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 break;
1813 }
1814
Bram Moolenaar1306b362022-08-06 15:59:06 +01001815 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 {
1817 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001818 if (wlv.vcol == wlv.fromcol
1819 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1820 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 && (*mb_ptr2cells)(ptr) > 1)
1822 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001823 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001824 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 area_attr = vi_attr; // start highlighting
1826 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001827 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001828 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 area_attr = 0; // stop highlighting
1830
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001831#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 if (text_props != NULL)
1833 {
1834 int pi;
1835 int bcol = (int)(ptr - line);
1836
Bram Moolenaar1306b362022-08-06 15:59:06 +01001837 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001838# ifdef FEAT_LINEBREAK
1839 && !in_linebreak
1840# endif
1841 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 --bcol; // still working on the previous char, e.g. Tab
1843
1844 // Check if any active property ends.
1845 for (pi = 0; pi < text_props_active; ++pi)
1846 {
1847 int tpi = text_prop_idxs[pi];
1848
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001849 if (text_props[tpi].tp_col != MAXCOL
1850 && bcol >= text_props[tpi].tp_col - 1
1851 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 {
1853 if (pi + 1 < text_props_active)
1854 mch_memmove(text_prop_idxs + pi,
1855 text_prop_idxs + pi + 1,
1856 sizeof(int)
1857 * (text_props_active - (pi + 1)));
1858 --text_props_active;
1859 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001860# ifdef FEAT_LINEBREAK
1861 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001862 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001863 syntax_attr = 0;
1864# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 }
1866 }
1867
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001868# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001870 // not on the next char yet, don't start another prop
1871 --bcol;
1872# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001874 // With 'nowrap' and not in the first screen line only "below"
1875 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001877 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001878 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001879 && (wp->w_p_wrap
1880 || wlv.row == startrow
1881 || (text_props[text_prop_next].tp_flags
1882 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001883 || (bcol == 0 &&
1884 (text_props[text_prop_next].tp_flags
1885 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001886 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001887 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001888 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001889 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1890 {
1891 // first display the '$' after the line
1892 text_prop_follows = TRUE;
1893 break;
1894 }
1895 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001896 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001897 + text_props[text_prop_next].tp_len)
1898 text_prop_idxs[text_props_active++] = text_prop_next;
1899 ++text_prop_next;
1900 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001902 if (wlv.n_extra == 0 || !extra_for_textprop)
1903 {
1904 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001905 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001906 text_prop_flags = 0;
1907 text_prop_type = NULL;
1908 text_prop_id = 0;
1909 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001910 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001912 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001913 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001914 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001915
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 // Sort the properties on priority and/or starting last.
1917 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001918 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001919 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001920 sort_text_props(wp->w_buffer, text_props,
1921 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922
1923 for (pi = 0; pi < text_props_active; ++pi)
1924 {
1925 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001926 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001928 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929
Bram Moolenaarcd105412022-10-10 19:50:42 +01001930 // Only use a text property that can be displayed.
1931 // Skip "after" properties when wrap is off and at the
1932 // end of the window.
1933 if (pt != NULL
1934 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1935 && tp->tp_id != -MAXCOL
1936 && !(tp->tp_id < 0
1937 && !wp->w_p_wrap
1938 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1939 | TP_FLAG_ALIGN_ABOVE
1940 | TP_FLAG_ALIGN_BELOW)) == 0
1941 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001943 if (pt->pt_hl_id > 0)
1944 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945 text_prop_type = pt;
1946 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001947 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001948 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001949 text_prop_flags = pt->pt_flags;
1950 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001951 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 }
1953 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001954 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001955 && -text_prop_id
1956 <= wp->w_buffer->b_textprop_text.ga_len)
1957 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001958 textprop_T *tp = &text_props[used_tpi];
1959 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001960 ->b_textprop_text.ga_data)[
1961 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001962 int above = (tp->tp_flags
1963 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001964 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001965
1966 // reset the ID in the copy to avoid it being used
1967 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001968 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001969
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001970 if (p != NULL)
1971 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001972 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001973 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001974 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001975 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001976 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1977 int padding = tp->tp_col == MAXCOL
1978 && tp->tp_len > 1
1979 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001980
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001981 // Insert virtual text before the current
1982 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001983 wlv.p_extra = p;
1984 wlv.c_extra = NUL;
1985 wlv.c_final = NUL;
1986 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001987 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001988 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001989 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001990 // restore search_attr and area_attr when n_extra
1991 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01001992 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001993 saved_area_attr = area_attr;
1994 search_attr = 0;
1995 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001996 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001997 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001998 if (*ptr == NUL)
1999 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002000 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002001#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002002 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002003 {
2004 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002005 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002006 wlv.need_showbreak = FALSE;
2007 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002008 }
2009#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002010 if ((right || above || below || !wrap
2011 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002012 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002013 char_u *prev_p_extra = wlv.p_extra;
2014 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002016 // Take care of padding, right-align and
2017 // truncation.
2018 // Shared with win_lbr_chartabsize(), must do
2019 // exactly the same.
2020 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002021 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002022 wlv.col,
2023 &wlv.n_extra, &wlv.p_extra,
2024 &n_attr, &n_attr_skip);
2025 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002027 // wlv.p_extra was allocated
2028 vim_free(p_extra_free2);
2029 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002030 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002031
Bram Moolenaara4abe512022-09-15 19:44:09 +01002032 if (lcs_eol_one < 0 && wlv.col
2033 + wlv.n_extra - 2 > wp->w_width)
2034 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002035 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002036
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002037 // When 'wrap' is off then for "below" we need
2038 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002040 {
2041 draw_screen_line(wp, &wlv);
2042
2043 // When line got too long for screen break
2044 // here.
2045 if (wlv.row == endrow)
2046 {
2047 ++wlv.row;
2048 break;
2049 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002051 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002052 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002053 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002054 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002055
Bram Moolenaarcd105412022-10-10 19:50:42 +01002056 // If the text didn't reach until the first window
2057 // column we need to skip cells.
2058 if (skip_cells > 0)
2059 {
2060 if (wlv.n_extra > skip_cells)
2061 {
2062 wlv.n_extra -= skip_cells;
2063 wlv.p_extra += skip_cells;
2064 n_attr_skip -= skip_cells;
2065 if (n_attr_skip < 0)
2066 n_attr_skip = 0;
2067 skip_cells = 0;
2068 }
2069 else
2070 {
2071 // the whole text is left of the window, drop
2072 // it and advance to the next one
2073 skip_cells -= wlv.n_extra;
2074 wlv.n_extra = 0;
2075 n_attr_skip = 0;
2076 bail_out = TRUE;
2077 }
2078 }
2079
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002080 // If another text prop follows the condition below at
2081 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002082 // If this is an "above" text prop and 'nowrap' the we
2083 // must wrap anyway.
2084 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002085 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002086 && (wp->w_p_wrap
2087 || (text_props[other_tpi].tp_flags
2088 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002089
2090 if (bail_out)
2091 // starting a new line for "below"
2092 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002093 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002095 else if (text_prop_next < text_prop_count
2096 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002097 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2098 || (!wp->w_p_wrap
2099 && wlv.col == wp->w_width - 1
2100 && (text_props[text_prop_next].tp_flags
2101 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002102 // When at last-but-one character and a text property
2103 // follows after it, we may need to flush the line after
2104 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002105 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002106 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 }
2108#endif
2109
Bram Moolenaare38fc862022-08-11 17:24:50 +01002110#ifdef FEAT_SEARCH_EXTRA
2111 if (wlv.n_extra == 0)
2112 {
2113 // Check for start/end of 'hlsearch' and other matches.
2114 // After end, check for start/end of next match.
2115 // When another match, have to check for start again.
2116 v = (long)(ptr - line);
2117 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2118 &screen_search_hl, &has_match_conc,
2119 &match_conc, did_line_attr, lcs_eol_one,
2120 &on_last_col);
2121 ptr = line + v; // "line" may have been changed
2122 prev_ptr = ptr;
2123
2124 // Do not allow a conceal over EOL otherwise EOL will be missed
2125 // and bad things happen.
2126 if (*ptr == NUL)
2127 has_match_conc = 0;
2128 }
2129#endif
2130
2131#ifdef FEAT_DIFF
2132 if (wlv.diff_hlf != (hlf_T)0)
2133 {
2134 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2135 && wlv.n_extra == 0)
2136 wlv.diff_hlf = HLF_TXD; // changed text
2137 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2138 && wlv.n_extra == 0)
2139 wlv.diff_hlf = HLF_CHD; // changed line
2140 line_attr = HL_ATTR(wlv.diff_hlf);
2141 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2142 && wp->w_p_culopt_flags != CULOPT_NBR
2143 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2144 && wlv.vcol <= right_curline_col)))
2145 line_attr = hl_combine_attr(
2146 line_attr, HL_ATTR(HLF_CUL));
2147 }
2148#endif
2149
Bram Moolenaara74fda62019-10-19 17:38:03 +02002150#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002151 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002152 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002153 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002154# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002155 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002156 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002157# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002158 // Get syntax attribute.
2159 if (has_syntax)
2160 {
2161 // Get the syntax attribute for the character. If there
2162 // is an error, disable syntax highlighting.
2163 save_did_emsg = did_emsg;
2164 did_emsg = FALSE;
2165
2166 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002167 if (v == prev_syntax_col)
2168 // at same column again
2169 syntax_attr = prev_syntax_attr;
2170 else
2171 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002172# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002173 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002174# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002175 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002176# ifdef FEAT_SPELL
2177 has_spell ? &can_spell :
2178# endif
2179 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002180 prev_syntax_col = v;
2181 prev_syntax_attr = syntax_attr;
2182 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002183
Bram Moolenaar34390282019-10-16 14:38:26 +02002184 if (did_emsg)
2185 {
2186 wp->w_s->b_syn_error = TRUE;
2187 has_syntax = FALSE;
2188 syntax_attr = 0;
2189 }
2190 else
2191 did_emsg = save_did_emsg;
2192# ifdef SYN_TIME_LIMIT
2193 if (wp->w_s->b_syn_slow)
2194 has_syntax = FALSE;
2195# endif
2196
2197 // Need to get the line again, a multi-line regexp may
2198 // have made it invalid.
2199 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2200 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002201 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002202# ifdef FEAT_CONCEAL
2203 // no concealing past the end of the line, it interferes
2204 // with line highlighting
2205 if (*ptr == NUL)
2206 syntax_flags = 0;
2207 else
2208 syntax_flags = get_syntax_info(&syntax_seqnr);
2209# endif
2210 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002211 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002212# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002213 // Combine text property highlight into syntax highlight.
2214 if (text_prop_type != NULL)
2215 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002216 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002217 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2218 else
2219 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002220 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002221 }
2222# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002223#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002224
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 // Decide which of the highlight attributes to use.
2226 attr_pri = TRUE;
2227#ifdef LINE_ATTR
2228 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002230 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002231 if (!highlight_match)
2232 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002233 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002234# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002235 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002236# endif
2237 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002238 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002240 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002241# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002242 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002243# endif
2244 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002245 else if (line_attr != 0
2246 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2247 || wlv.vcol < wlv.fromcol
2248 || vcol_prev < fromcol_prev
2249 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002250 {
2251 // Use line_attr when not in the Visual or 'incsearch' area
2252 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002253# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002255# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002257# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 attr_pri = FALSE;
2259 }
2260#else
2261 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002262 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002264 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265#endif
2266 else
2267 {
2268 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002269#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002271#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002273#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002275#ifdef FEAT_PROP_POPUP
2276 // override with text property highlight when "override" is TRUE
2277 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002279#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002281
2282 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002283 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002284 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 if (wlv.char_attr == 0)
2286 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002287 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002288 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002289 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290
2291 // Get the next character to put on the screen.
2292
2293 // The "p_extra" points to the extra stuff that is inserted to
2294 // represent special characters (non-printable stuff) and other
2295 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002297 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2298 // "p_extra[n_extra]".
2299 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002300 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2305 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002306 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2307 if (enc_utf8 && utf_char2len(c) > 1)
2308 {
2309 mb_utf8 = TRUE;
2310 u8cc[0] = 0;
2311 c = 0xc0;
2312 }
2313 else
2314 mb_utf8 = FALSE;
2315 }
2316 else
2317 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002318 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 if (has_mbyte)
2320 {
2321 mb_c = c;
2322 if (enc_utf8)
2323 {
2324 // If the UTF-8 character is more than one byte:
2325 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002326 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002327 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 mb_l = 1;
2330 else if (mb_l > 1)
2331 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 mb_utf8 = TRUE;
2334 c = 0xc0;
2335 }
2336 }
2337 else
2338 {
2339 // if this is a DBCS character, put it in "mb_c"
2340 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002341 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342 mb_l = 1;
2343 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 }
2346 if (mb_l == 0) // at the NUL at end-of-line
2347 mb_l = 1;
2348
2349 // If a double-width char doesn't fit display a '>' in the
2350 // last column.
2351 if ((
2352# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002353 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002355 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 && (*mb_char2cells)(mb_c) == 2)
2357 {
2358 c = '>';
2359 mb_c = c;
2360 mb_l = 1;
2361 mb_utf8 = FALSE;
2362 multi_attr = HL_ATTR(HLF_AT);
2363#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002364 if (wlv.cul_attr)
2365 multi_attr = hl_combine_attr(
2366 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002368 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002369
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 // put the pointer back to output the double-width
2371 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 ++wlv.n_extra;
2373 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374 }
2375 else
2376 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 wlv.n_extra -= mb_l - 1;
2378 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 }
2380 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002384#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002386 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002387 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002388 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002389 if (search_attr == 0)
2390 search_attr = saved_search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002391 if (area_attr == 0 && *ptr != NUL)
2392 area_attr = saved_area_attr;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002393 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002394#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 }
2396 else
2397 {
2398#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002399 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002401 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403 // Get a character from the line itself.
2404 c = *ptr;
2405#ifdef FEAT_LINEBREAK
2406 c0 = *ptr;
2407#endif
2408 if (has_mbyte)
2409 {
2410 mb_c = c;
2411 if (enc_utf8)
2412 {
2413 // If the UTF-8 character is more than one byte: Decode it
2414 // into "mb_c".
2415 mb_l = utfc_ptr2len(ptr);
2416 mb_utf8 = FALSE;
2417 if (mb_l > 1)
2418 {
2419 mb_c = utfc_ptr2char(ptr, u8cc);
2420 // Overlong encoded ASCII or ASCII with composing char
2421 // is displayed normally, except a NUL.
2422 if (mb_c < 0x80)
2423 {
2424 c = mb_c;
2425#ifdef FEAT_LINEBREAK
2426 c0 = mb_c;
2427#endif
2428 }
2429 mb_utf8 = TRUE;
2430
2431 // At start of the line we can have a composing char.
2432 // Draw it as a space with a composing char.
2433 if (utf_iscomposing(mb_c))
2434 {
2435 int i;
2436
2437 for (i = Screen_mco - 1; i > 0; --i)
2438 u8cc[i] = u8cc[i - 1];
2439 u8cc[0] = mb_c;
2440 mb_c = ' ';
2441 }
2442 }
2443
2444 if ((mb_l == 1 && c >= 0x80)
2445 || (mb_l >= 1 && mb_c == 0)
2446 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2447 {
2448 // Illegal UTF-8 byte: display as <xx>.
2449 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002450 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451# ifdef FEAT_RIGHTLEFT
2452 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002453 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002455 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 c = *wlv.p_extra;
2457 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002459 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2460 wlv.c_extra = NUL;
2461 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002462 if (area_attr == 0 && search_attr == 0)
2463 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002465 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002466 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468 }
2469 }
2470 else if (mb_l == 0) // at the NUL at end-of-line
2471 mb_l = 1;
2472#ifdef FEAT_ARABIC
2473 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2474 {
2475 // Do Arabic shaping.
2476 int pc, pc1, nc;
2477 int pcc[MAX_MCO];
2478
2479 // The idea of what is the previous and next
2480 // character depends on 'rightleft'.
2481 if (wp->w_p_rl)
2482 {
2483 pc = prev_c;
2484 pc1 = prev_c1;
2485 nc = utf_ptr2char(ptr + mb_l);
2486 prev_c1 = u8cc[0];
2487 }
2488 else
2489 {
2490 pc = utfc_ptr2char(ptr + mb_l, pcc);
2491 nc = prev_c;
2492 pc1 = pcc[0];
2493 }
2494 prev_c = mb_c;
2495
2496 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2497 }
2498 else
2499 prev_c = mb_c;
2500#endif
2501 }
2502 else // enc_dbcs
2503 {
2504 mb_l = MB_BYTE2LEN(c);
2505 if (mb_l == 0) // at the NUL at end-of-line
2506 mb_l = 1;
2507 else if (mb_l > 1)
2508 {
2509 // We assume a second byte below 32 is illegal.
2510 // Hopefully this is OK for all double-byte encodings!
2511 if (ptr[1] >= 32)
2512 mb_c = (c << 8) + ptr[1];
2513 else
2514 {
2515 if (ptr[1] == NUL)
2516 {
2517 // head byte at end of line
2518 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002519 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002520 }
2521 else
2522 {
2523 // illegal tail byte
2524 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002525 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002527 wlv.p_extra = wlv.extra;
2528 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 wlv.c_extra = NUL;
2530 wlv.c_final = NUL;
2531 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 if (area_attr == 0 && search_attr == 0)
2533 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002535 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002536 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 // save current attr
2538 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002539 }
2540 mb_c = c;
2541 }
2542 }
2543 }
2544 // If a double-width char doesn't fit display a '>' in the
2545 // last column; the character is displayed at the start of the
2546 // next line.
2547 if ((
2548# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002549 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002551 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 && (*mb_char2cells)(mb_c) == 2)
2553 {
2554 c = '>';
2555 mb_c = c;
2556 mb_utf8 = FALSE;
2557 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002558 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 // Put pointer back so that the character will be
2560 // displayed at the start of the next line.
2561 --ptr;
2562#ifdef FEAT_CONCEAL
2563 did_decrement_ptr = TRUE;
2564#endif
2565 }
2566 else if (*ptr != NUL)
2567 ptr += mb_l - 1;
2568
2569 // If a double-width char doesn't fit at the left side display
2570 // a '<' in the first column. Don't do this for unprintable
2571 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002574 wlv.n_extra = 1;
2575 wlv.c_extra = MB_FILLER_CHAR;
2576 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 c = ' ';
2578 if (area_attr == 0 && search_attr == 0)
2579 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002581 extra_attr = hl_combine_attr(
2582 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 }
2585 mb_c = c;
2586 mb_utf8 = FALSE;
2587 mb_l = 1;
2588 }
2589
2590 }
2591 ++ptr;
2592
2593 if (extra_check)
2594 {
2595#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 // Check spelling (unless at the end of the line).
2597 // Only do this when there is no syntax highlighting, the
2598 // @Spell cluster is not used or the current syntax item
2599 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002600 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601 if (has_spell && v >= word_end && v > cur_checked_col)
2602 {
2603 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002604 // do not calculate cap_col at the end of the line or when
2605 // only white space is following
2606 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607# ifdef FEAT_SYN_HL
2608 !has_syntax ||
2609# endif
2610 can_spell))
2611 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002612 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613 int len;
2614 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002615
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618
2619 // Use nextline[] if possible, it has the start of the
2620 // next line concatenated.
2621 if ((prev_ptr - line) - nextlinecol >= 0)
2622 p = nextline + (prev_ptr - line) - nextlinecol;
2623 else
2624 p = prev_ptr;
2625 cap_col -= (int)(prev_ptr - line);
2626 len = spell_check(wp, p, &spell_hlf, &cap_col,
2627 nochange);
2628 word_end = v + len;
2629
2630 // In Insert mode only highlight a word that
2631 // doesn't touch the cursor.
2632 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002633 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 && wp->w_cursor.lnum == lnum
2635 && wp->w_cursor.col >=
2636 (colnr_T)(prev_ptr - line)
2637 && wp->w_cursor.col < (colnr_T)word_end)
2638 {
2639 spell_hlf = HLF_COUNT;
2640 spell_redraw_lnum = lnum;
2641 }
2642
2643 if (spell_hlf == HLF_COUNT && p != prev_ptr
2644 && (p - nextline) + len > nextline_idx)
2645 {
2646 // Remember that the good word continues at the
2647 // start of the next line.
2648 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002649 checked_col = (int)((p - nextline)
2650 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 }
2652
2653 // Turn index into actual attributes.
2654 if (spell_hlf != HLF_COUNT)
2655 spell_attr = highlight_attr[spell_hlf];
2656
2657 if (cap_col > 0)
2658 {
2659 if (p != prev_ptr
2660 && (p - nextline) + cap_col >= nextline_idx)
2661 {
2662 // Remember that the word in the next line
2663 // must start with a capital.
2664 capcol_lnum = lnum + 1;
2665 cap_col = (int)((p - nextline) + cap_col
2666 - nextline_idx);
2667 }
2668 else
2669 // Compute the actual column.
2670 cap_col += (int)(prev_ptr - line);
2671 }
2672 }
2673 }
2674 if (spell_attr != 0)
2675 {
2676 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002677 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2678 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002680 wlv.char_attr = hl_combine_attr(spell_attr,
2681 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 }
2683#endif
2684#ifdef FEAT_LINEBREAK
2685 // Found last space before word: check for line break.
2686 if (wp->w_p_lbr && c0 == c
2687 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2688 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002689 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2690 : 0;
2691 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002692 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002694 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002695# ifdef FEAT_PROP_POPUP
2696 // do not want virtual text counted here
2697 cts.cts_has_prop_with_text = FALSE;
2698# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002700 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002701
2702 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002703 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002704 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002705 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002706 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2707 if (wlv.n_extra < 0)
2708 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002709 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002710 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002711 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002712 // line break, but for TABs the highlighting should
2713 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002714 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002715
Bram Moolenaar1306b362022-08-06 15:59:06 +01002716 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002719 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 wp->w_buffer->b_p_vts_array) - 1;
2721# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002722 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002723 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724# endif
2725
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2727 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002728# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002730 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002731# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732 if (VIM_ISWHITE(c))
2733 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002734# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 if (c == TAB)
2736 // See "Tab alignment" below.
2737 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002738# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 if (!wp->w_p_list)
2740 c = ' ';
2741 }
2742 }
2743#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002744 in_multispace = c == ' '
2745 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2746 if (!in_multispace)
2747 multispace_pos = 0;
2748
Bram Moolenaareed9d462021-02-15 20:38:25 +01002749 // 'list': Change char 160 to 'nbsp' and space to 'space'
2750 // setting in 'listchars'. But not when the character is
2751 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 if (wp->w_p_list
2753 && ((((c == 160 && mb_l == 1)
2754 || (mb_utf8
2755 && ((mb_c == 160 && mb_l == 2)
2756 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002757 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 || (c == ' '
2759 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002760 && (wp->w_lcs_chars.space
2761 || (in_multispace
2762 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002763 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 && ptr - line <= trailcol)))
2765 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002766 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2767 {
2768 c = wp->w_lcs_chars.multispace[multispace_pos++];
2769 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2770 multispace_pos = 0;
2771 }
2772 else
2773 c = (c == ' ') ? wp->w_lcs_chars.space
2774 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 if (area_attr == 0 && search_attr == 0)
2776 {
2777 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002778 extra_attr = hl_combine_attr(wlv.win_attr,
2779 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002781 }
2782 mb_c = c;
2783 if (enc_utf8 && utf_char2len(c) > 1)
2784 {
2785 mb_utf8 = TRUE;
2786 u8cc[0] = 0;
2787 c = 0xc0;
2788 }
2789 else
2790 mb_utf8 = FALSE;
2791 }
2792
zeertzjq2e7cba32022-06-10 15:30:32 +01002793 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2794 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002796 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2797 && wp->w_lcs_chars.leadmultispace != NULL)
2798 {
2799 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002800 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2801 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002802 multispace_pos = 0;
2803 }
2804
2805 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2806 c = wp->w_lcs_chars.trail;
2807
2808 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2809 c = wp->w_lcs_chars.lead;
2810
zeertzjq2e7cba32022-06-10 15:30:32 +01002811 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002812 c = wp->w_lcs_chars.space;
2813
2814
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 if (!attr_pri)
2816 {
2817 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 extra_attr = hl_combine_attr(wlv.win_attr,
2819 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002820 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 }
2822 mb_c = c;
2823 if (enc_utf8 && utf_char2len(c) > 1)
2824 {
2825 mb_utf8 = TRUE;
2826 u8cc[0] = 0;
2827 c = 0xc0;
2828 }
2829 else
2830 mb_utf8 = FALSE;
2831 }
2832 }
2833
2834 // Handling of non-printable characters.
2835 if (!vim_isprintc(c))
2836 {
2837 // when getting a character from the file, we may have to
2838 // turn it into something else on the way to putting it
2839 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002840 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 {
2842 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002845 char_u *sbr = get_showbreak_value(wp);
2846
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 // only adjust the tab_len, when at the first column
2848 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002849 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002850 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851#endif
2852 // tab amount depends on current column
2853#ifdef FEAT_VARTABS
2854 tab_len = tabstop_padding(vcol_adjusted,
2855 wp->w_buffer->b_p_ts,
2856 wp->w_buffer->b_p_vts_array) - 1;
2857#else
2858 tab_len = (int)wp->w_buffer->b_p_ts
2859 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2860#endif
2861
2862#ifdef FEAT_LINEBREAK
2863 if (!wp->w_p_lbr || !wp->w_p_list)
2864#endif
2865 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002866 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867#ifdef FEAT_LINEBREAK
2868 else
2869 {
2870 char_u *p;
2871 int len;
2872 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002873 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002875# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002876 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002878 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002879
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002881 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002882 && old_boguscols > 0
2883 && wlv.n_extra > tab_len)
2884 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002885# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002886 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002888 // If wlv.n_extra > 0, it gives the number of
2889 // chars, to use for a tab, else we need to
2890 // calculate the width for a tab.
2891 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2892 len = tab_len * tab2_len;
2893 if (wp->w_lcs_chars.tab3)
2894 len += mb_char2len(wp->w_lcs_chars.tab3)
2895 - tab2_len;
2896 if (wlv.n_extra > 0)
2897 len += wlv.n_extra - tab_len;
2898 c = wp->w_lcs_chars.tab1;
2899 p = alloc(len + 1);
2900 if (p == NULL)
2901 wlv.n_extra = 0;
2902 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002904 vim_memset(p, ' ', len);
2905 p[len] = NUL;
2906 vim_free(wlv.p_extra_free);
2907 wlv.p_extra_free = p;
2908 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002909 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002910 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002911
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002912 if (*p == NUL)
2913 {
2914 tab_len = i;
2915 break;
2916 }
2917
2918 // if tab3 is given, use it for the last
2919 // char
2920 if (wp->w_lcs_chars.tab3
2921 && i == tab_len - 1)
2922 lcs = wp->w_lcs_chars.tab3;
2923 p += mb_char2bytes(lcs, p);
2924 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002926 }
2927 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002928# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002929 // n_extra will be increased by
2930 // FIX_FOX_BOGUSCOLS macro below, so need to
2931 // adjust for that here
2932 if (wlv.vcol_off > 0)
2933 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002934# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002935 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 }
2938#endif
2939#ifdef FEAT_CONCEAL
2940 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002941 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942
2943 // Tab alignment should be identical regardless of
2944 // 'conceallevel' value. So tab compensates of all
2945 // previous concealed characters, and thus resets
2946 // vcol_off and boguscols accumulated so far in the
2947 // line. Note that the tab can be longer than
2948 // 'tabstop' when there are concealed characters.
2949 FIX_FOR_BOGUSCOLS;
2950
2951 // Make sure, the highlighting for the tab char will be
2952 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002953 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002954 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002955 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 tab_len += vc_saved;
2957 }
2958#endif
2959 mb_utf8 = FALSE; // don't draw as UTF-8
2960 if (wp->w_p_list)
2961 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002963 ? wp->w_lcs_chars.tab3
2964 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965#ifdef FEAT_LINEBREAK
2966 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002967 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 else
2969#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002970 wlv.c_extra = wp->w_lcs_chars.tab2;
2971 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002973 extra_attr = hl_combine_attr(wlv.win_attr,
2974 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002975 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 mb_c = c;
2977 if (enc_utf8 && utf_char2len(c) > 1)
2978 {
2979 mb_utf8 = TRUE;
2980 u8cc[0] = 0;
2981 c = 0xc0;
2982 }
2983 }
2984 else
2985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002986 wlv.c_final = NUL;
2987 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 c = ' ';
2989 }
2990 }
2991 else if (c == NUL
2992 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002993 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
2994 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 && VIsual_mode != Ctrl_V
2996 && (
2997# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002998 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003000 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 && !(noinvcur
3002 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003003 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 && lcs_eol_one > 0)
3005 {
3006 // Display a '$' after the line or highlight an extra
3007 // character if the line break is included.
3008#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3009 // For a diff line the highlighting continues after the
3010 // "$".
3011 if (
3012# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003013 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014# ifdef LINE_ATTR
3015 &&
3016# endif
3017# endif
3018# ifdef LINE_ATTR
3019 line_attr == 0
3020# endif
3021 )
3022#endif
3023 {
3024 // In virtualedit, visual selections may extend
3025 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003026 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003027 && wlv.tocol != MAXCOL
3028 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003029 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003030 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003032 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3033 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 else
3035 c = ' ';
3036 lcs_eol_one = -1;
3037 --ptr; // put it back at the NUL
3038 if (!attr_pri)
3039 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003040 extra_attr = hl_combine_attr(wlv.win_attr,
3041 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 n_attr = 1;
3043 }
3044 mb_c = c;
3045 if (enc_utf8 && utf_char2len(c) > 1)
3046 {
3047 mb_utf8 = TRUE;
3048 u8cc[0] = 0;
3049 c = 0xc0;
3050 }
3051 else
3052 mb_utf8 = FALSE; // don't draw as UTF-8
3053 }
3054 else if (c != NUL)
3055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003056 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3057 if (wlv.n_extra == 0)
3058 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059#ifdef FEAT_RIGHTLEFT
3060 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003061 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003063 wlv.c_extra = NUL;
3064 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065#ifdef FEAT_LINEBREAK
3066 if (wp->w_p_lbr)
3067 {
3068 char_u *p;
3069
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 c = *wlv.p_extra;
3071 p = alloc(wlv.n_extra + 1);
3072 vim_memset(p, ' ', wlv.n_extra);
3073 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3074 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003075 vim_free(wlv.p_extra_free);
3076 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003077 }
3078 else
3079#endif
3080 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 wlv.n_extra = byte2cells(c) - 1;
3082 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 }
3084 if (!attr_pri)
3085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003086 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003087 extra_attr = hl_combine_attr(wlv.win_attr,
3088 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003089 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 }
3091 mb_utf8 = FALSE; // don't draw as UTF-8
3092 }
3093 else if (VIsual_active
3094 && (VIsual_mode == Ctrl_V
3095 || VIsual_mode == 'v')
3096 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003097 && wlv.tocol != MAXCOL
3098 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003099 && (
3100#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003101 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003103 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104 {
3105 c = ' ';
3106 --ptr; // put it back at the NUL
3107 }
3108#if defined(LINE_ATTR)
3109 else if ((
3110# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003111 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112# endif
3113# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003114 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115# endif
3116 line_attr != 0
3117 ) && (
3118# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003119 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003121 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124# endif
3125 < wp->w_width)))
3126 {
3127 // Highlight until the right side of the window
3128 c = ' ';
3129 --ptr; // put it back at the NUL
3130
3131 // Remember we do the char for line highlighting.
3132 ++did_line_attr;
3133
3134 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003135 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003137 || (wp->w_p_list &&
3138 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 wlv.diff_hlf = HLF_CHD;
3144 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003146 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3148 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003149 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003150 || (wlv.vcol >= left_curline_col
3151 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 wlv.char_attr = hl_combine_attr(
3153 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 }
3155 }
3156# endif
3157# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003161 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3162 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003163 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 if (!wlv.cul_screenline
3165 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003166 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003167 wlv.char_attr = hl_combine_attr(
3168 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 }
3170 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003171 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3172 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 }
3174# endif
3175 }
3176#endif
3177 }
3178
3179#ifdef FEAT_CONCEAL
3180 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003181 && (wp != curwin || lnum != wp->w_cursor.lnum
3182 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3184 && !(lnum_in_visual_area
3185 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3186 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003188 if (((prev_syntax_id != syntax_seqnr
3189 && (syntax_flags & HL_CONCEAL) != 0)
3190 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003191 && (syn_get_sub_char() != NUL
3192 || (has_match_conc && match_conc)
3193 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194 && wp->w_p_cole != 3)
3195 {
3196 // First time at this concealed item: display one
3197 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003198 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199 c = match_conc;
3200 else if (syn_get_sub_char() != NUL)
3201 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003202 else if (wp->w_lcs_chars.conceal != NUL)
3203 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 else
3205 c = ' ';
3206
3207 prev_syntax_id = syntax_seqnr;
3208
Bram Moolenaar1306b362022-08-06 15:59:06 +01003209 if (wlv.n_extra > 0)
3210 wlv.vcol_off += wlv.n_extra;
3211 wlv.vcol += wlv.n_extra;
3212 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 {
3214# ifdef FEAT_RIGHTLEFT
3215 if (wp->w_p_rl)
3216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 wlv.col -= wlv.n_extra;
3218 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 }
3220 else
3221# endif
3222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 wlv.boguscols += wlv.n_extra;
3224 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003225 }
3226 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003227 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 n_attr = 0;
3229 }
3230 else if (n_skip == 0)
3231 {
3232 is_concealing = TRUE;
3233 n_skip = 1;
3234 }
3235 mb_c = c;
3236 if (enc_utf8 && utf_char2len(c) > 1)
3237 {
3238 mb_utf8 = TRUE;
3239 u8cc[0] = 0;
3240 c = 0xc0;
3241 }
3242 else
3243 mb_utf8 = FALSE; // don't draw as UTF-8
3244 }
3245 else
3246 {
3247 prev_syntax_id = 0;
3248 is_concealing = FALSE;
3249 }
3250
3251 if (n_skip > 0 && did_decrement_ptr)
3252 // not showing the '>', put pointer back to avoid getting stuck
3253 ++ptr;
3254
3255#endif // FEAT_CONCEAL
3256 }
3257
3258#ifdef FEAT_CONCEAL
3259 // In the cursor line and we may be concealing characters: correct
3260 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 && wp == curwin && lnum == wp->w_cursor.lnum
3263 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003264 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003266# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003270# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003271 wp->w_wcol = wlv.col - wlv.boguscols;
3272 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 did_wcol = TRUE;
3274 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003275# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003276 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003277# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 }
3279#endif
3280
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003281 // Use "extra_attr", but don't override visual selection highlighting,
3282 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003283 // Don't use "extra_attr" until n_attr_skip is zero.
3284 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003285 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003286 && (!attr_pri
3287#ifdef FEAT_PROP_POPUP
3288 || (text_prop_flags & PT_FLAG_OVERRIDE)
3289#endif
3290 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 {
3292#ifdef LINE_ATTR
3293 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003294 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 else
3296#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003297 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 }
3299
3300#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3301 // XIM don't send preedit_start and preedit_end, but they send
3302 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3303 // im_is_preediting() here.
3304 if (p_imst == IM_ON_THE_SPOT
3305 && xic != NULL
3306 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003307 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003308 && !p_imdisable
3309 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 {
3312 colnr_T tcol;
3313
3314 if (preedit_end_col == MAXCOL)
3315 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3316 else
3317 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 {
3320 if (feedback_old_attr < 0)
3321 {
3322 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003323 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003324 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003325 wlv.char_attr = im_get_feedback_attr(feedback_col);
3326 if (wlv.char_attr < 0)
3327 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 feedback_col++;
3329 }
3330 else if (feedback_old_attr >= 0)
3331 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 feedback_old_attr = -1;
3334 feedback_col = 0;
3335 }
3336 }
3337#endif
3338 // Handle the case where we are in column 0 but not on the first
3339 // character of the line and the user wants us to show us a
3340 // special character (via 'listchars' option "precedes:<char>".
3341 if (lcs_prec_todo != NUL
3342 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003343 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3344 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003346 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003348 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 && c != NUL)
3350 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003351 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003352 lcs_prec_todo = NUL;
3353 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3354 {
3355 // Double-width character being overwritten by the "precedes"
3356 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003357 wlv.c_extra = MB_FILLER_CHAR;
3358 wlv.c_final = NUL;
3359 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 }
3363 mb_c = c;
3364 if (enc_utf8 && utf_char2len(c) > 1)
3365 {
3366 mb_utf8 = TRUE;
3367 u8cc[0] = 0;
3368 c = 0xc0;
3369 }
3370 else
3371 mb_utf8 = FALSE; // don't draw as UTF-8
3372 if (!attr_pri)
3373 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003374 saved_attr3 = wlv.char_attr; // save current attr
3375 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 n_attr3 = 1;
3377 }
3378 }
3379
3380 // At end of the text line or just after the last character.
3381 if ((c == NUL
3382#if defined(LINE_ATTR)
3383 || did_line_attr == 1
3384#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 {
3387#ifdef FEAT_SEARCH_EXTRA
3388 // flag to indicate whether prevcol equals startcol of search_hl or
3389 // one of the matches
3390 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3391 (long)(ptr - line) - (c == NUL));
3392#endif
3393 // Invert at least one char, used for Visual and empty line or
3394 // highlight match at end of line. If it's beyond the last
3395 // char on the screen, just overwrite that one (tricky!) Not
3396 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003397 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003398 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 && (VIsual_mode != Ctrl_V
3400 || lnum == VIsual.lnum
3401 || lnum == curwin->w_cursor.lnum)
3402 && c == NUL)
3403#ifdef FEAT_SEARCH_EXTRA
3404 // highlight 'hlsearch' match at end of line
3405 || (prevcol_hl_flag
3406# ifdef FEAT_SYN_HL
3407 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3408 && !(wp == curwin && VIsual_active))
3409# endif
3410# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003411 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412# endif
3413# if defined(LINE_ATTR)
3414 && did_line_attr <= 1
3415# endif
3416 )
3417#endif
3418 ))
3419 {
3420 int n = 0;
3421
3422#ifdef FEAT_RIGHTLEFT
3423 if (wp->w_p_rl)
3424 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003425 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 n = 1;
3427 }
3428 else
3429#endif
3430 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 n = -1;
3433 }
3434 if (n != 0)
3435 {
3436 // At the window boundary, highlight the last character
3437 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003438 wlv.off += n;
3439 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 }
3441 else
3442 {
3443 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 }
3448#ifdef FEAT_SEARCH_EXTRA
3449 if (area_attr == 0)
3450 {
3451 // Use attributes from match with highest priority among
3452 // 'search_hl' and the match list.
3453 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 }
3456#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003458 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459#ifdef FEAT_RIGHTLEFT
3460 if (wp->w_p_rl)
3461 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 --wlv.col;
3463 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465 else
3466#endif
3467 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 ++wlv.col;
3469 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003471 ++wlv.vcol;
3472 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 }
3474 }
3475
3476 // At end of the text line.
3477 if (c == NUL)
3478 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480
3481 // Update w_cline_height and w_cline_folded if the cursor line was
3482 // updated (saves a call to plines() later).
3483 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3484 {
3485 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487#ifdef FEAT_FOLDING
3488 curwin->w_cline_folded = FALSE;
3489#endif
3490 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3491 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 break;
3493 }
3494
3495 // Show "extends" character from 'listchars' if beyond the line end and
3496 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003497 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003498 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 && wp->w_p_list
3500 && !wp->w_p_wrap
3501#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003502 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503#endif
3504 && (
3505#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003506 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003510 || lcs_eol_one > 0
3511 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003512 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003514 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003515 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 mb_c = c;
3517 if (enc_utf8 && utf_char2len(c) > 1)
3518 {
3519 mb_utf8 = TRUE;
3520 u8cc[0] = 0;
3521 c = 0xc0;
3522 }
3523 else
3524 mb_utf8 = FALSE;
3525 }
3526
3527#ifdef FEAT_SYN_HL
3528 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 if (wlv.draw_color_col)
3530 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531
3532 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3533 // highlight the cursor position itself.
3534 // Also highlight the 'colorcolumn' if it is different than
3535 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003536 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3537 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003539 if (((wlv.draw_state == WL_LINE
3540 || wlv.draw_state == WL_BRI
3541 || wlv.draw_state == WL_SBR)
3542 && !lnum_in_visual_area
3543 && search_attr == 0
3544 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003545# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003546 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003547# endif
3548 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 {
3550 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3551 && lnum != wp->w_cursor.lnum)
3552 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 vcol_save_attr = wlv.char_attr;
3554 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3555 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 vcol_save_attr = wlv.char_attr;
3560 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 }
3562 }
3563#endif
3564
3565 // Store character to be displayed.
3566 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003568 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 {
3570 // Store the character.
3571#if defined(FEAT_RIGHTLEFT)
3572 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3573 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003574 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003575 --wlv.off;
3576 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 }
3578#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 if (enc_dbcs == DBCS_JPNU)
3581 {
3582 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003583 ScreenLines[wlv.off] = 0x8e;
3584 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 }
3586 else if (enc_utf8)
3587 {
3588 if (mb_utf8)
3589 {
3590 int i;
3591
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 for (i = 0; i < Screen_mco; ++i)
3596 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003597 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 if (u8cc[i] == 0)
3599 break;
3600 }
3601 }
3602 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003603 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 }
3605 if (multi_attr)
3606 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 multi_attr = 0;
3609 }
3610 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003614
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3616 {
3617 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ++wlv.off;
3619 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 if (enc_utf8)
3621 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003622 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 else
3624 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003625 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003626 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003628 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629#endif
3630 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003631 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003632 // When "wlv.tocol" is halfway a character, set it to the end
3633 // of the character, otherwise highlighting won't stop.
3634 if (wlv.tocol == wlv.vcol)
3635 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003636
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003638
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639#ifdef FEAT_RIGHTLEFT
3640 if (wp->w_p_rl)
3641 {
3642 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 --wlv.off;
3644 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 }
3646#endif
3647 }
3648#ifdef FEAT_RIGHTLEFT
3649 if (wp->w_p_rl)
3650 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003651 --wlv.off;
3652 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 }
3654 else
3655#endif
3656 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 ++wlv.off;
3658 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 }
3660 }
3661#ifdef FEAT_CONCEAL
3662 else if (wp->w_p_cole > 0 && is_concealing)
3663 {
3664 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003665 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003666 if (wlv.n_extra > 0)
3667 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 if (wp->w_p_wrap)
3669 {
3670 // Special voodoo required if 'wrap' is on.
3671 //
3672 // Advance the column indicator to force the line
3673 // drawing to wrap early. This will make the line
3674 // take up the same screen space when parts are concealed,
3675 // so that cursor line computations aren't messed up.
3676 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003677 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 // trailing junk to be written out of the screen line
3679 // we are building, 'boguscols' keeps track of the number
3680 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003681 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003683 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684# ifdef FEAT_RIGHTLEFT
3685 if (wp->w_p_rl)
3686 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 wlv.col -= wlv.n_extra;
3688 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689 }
3690 else
3691# endif
3692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003693 wlv.col += wlv.n_extra;
3694 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003696 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 n_attr = 0;
3698 }
3699
3700
3701 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3702 {
3703 // Need to fill two screen columns.
3704# ifdef FEAT_RIGHTLEFT
3705 if (wp->w_p_rl)
3706 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 --wlv.boguscols;
3708 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 }
3710 else
3711# endif
3712 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 ++wlv.boguscols;
3714 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 }
3716 }
3717
3718# ifdef FEAT_RIGHTLEFT
3719 if (wp->w_p_rl)
3720 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 --wlv.boguscols;
3722 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 }
3724 else
3725# endif
3726 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003727 ++wlv.boguscols;
3728 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 }
3730 }
3731 else
3732 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003733 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003735 wlv.vcol += wlv.n_extra;
3736 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 n_attr = 0;
3738 }
3739 }
3740
3741 }
3742#endif // FEAT_CONCEAL
3743 else
3744 --n_skip;
3745
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003746 // Only advance the "wlv.vcol" when after the 'number' or
3747 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003750 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751#endif
3752 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754
3755#ifdef FEAT_SYN_HL
3756 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003757 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758#endif
3759
3760 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003761 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3762 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763
3764 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003765 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003766 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003767 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003768 if (n_attr_skip > 0)
3769 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770
3771 // At end of screen line and there is more to come: Display the line
3772 // so far. If there is no more to display it is caught above.
3773 if ((
3774#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003778 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003779 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003781 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003783#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003784 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003785#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003786 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003787 && wlv.p_extra != at_end_str)
3788 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3789 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790 )
3791 {
3792#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003793 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003794 wlv_screen_line(wp, &wlv, FALSE);
3795 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003798 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ++wlv.row;
3801 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802
3803 // When not wrapping and finished diff lines, or when displayed
3804 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003805 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003807 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003808#endif
3809#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003810 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003812 ) || lcs_eol_one == -1)
3813#ifdef FEAT_PROP_POPUP
3814 && !text_prop_follows
3815#endif
3816 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003818#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003819 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003820 {
3821 // do not output more of the line, only the "below" prop
3822 ptr += STRLEN(ptr);
3823# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003824 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003825# endif
3826 }
3827#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828
3829 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003832 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833#endif
3834 )
3835 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3837 draw_vsep_win(wp, wlv.row);
3838 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 }
3840
3841 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003842 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003844 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 break;
3846 }
3847
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003850 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003852#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003853 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003854#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 && wp->w_width == Columns)
3856 {
3857 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003858 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859
3860 // Special trick to make copy/paste of wrapped lines work with
3861 // xterm/screen: write an extra character beyond the end of
3862 // the line. This will work with all terminal types
3863 // (regardless of the xn,am settings).
3864 // Only do this on a fast tty.
3865 // Only do this if the cursor is on the current line
3866 // (something has been written in it).
3867 // Don't do this for the GUI.
3868 // Don't do this for double-width characters.
3869 // Don't do this for a window not at the right screen border.
3870 if (p_tf
3871#ifdef FEAT_GUI
3872 && !gui.in_use
3873#endif
3874 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3876 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003878 || (*mb_off2cells)(
3879 LineOffset[wlv.screen_row - 1]
3880 + (int)Columns - 2,
3881 LineOffset[wlv.screen_row]
3882 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883 {
3884 // First make sure we are at the end of the screen line,
3885 // then output the same character again to let the
3886 // terminal know about the wrap. If the terminal doesn't
3887 // auto-wrap, we overwrite the character.
3888 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 screen_char(LineOffset[wlv.screen_row - 1]
3890 + (unsigned)Columns - 1,
3891 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892
3893 // When there is a multi-byte character, just output a
3894 // space to keep it simple.
3895 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897 out_char(' ');
3898 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 + (Columns - 1)]);
3901 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003902 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 screen_start(); // don't know where cursor is now
3904 }
3905 }
3906
Bram Moolenaar1306b362022-08-06 15:59:06 +01003907 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908
Bram Moolenaareed9d462021-02-15 20:38:25 +01003909 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003911 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003913 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003915 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003916 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003917#endif
3918#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003919 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 // When the filler lines are actually below the last line of the
3921 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003922 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923 break;
3924#endif
3925 }
3926
3927 } // for every character in the line
3928
3929#ifdef FEAT_SPELL
3930 // After an empty line check first word for capital.
3931 if (*skipwhite(line) == NUL)
3932 {
3933 capcol_lnum = lnum + 1;
3934 cap_col = 0;
3935 }
3936#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003937#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938 vim_free(text_props);
3939 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003940 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941#endif
3942
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003943 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945}