blob: bde5ec8247a4a35cae2fe2754754c5de67120013 [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 Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
99 int vcol_off; // offset for concealed characters
100#endif
101#ifdef FEAT_SYN_HL
102 int draw_color_col; // highlight colorcolumn
103 int *color_cols; // pointer to according columns array
104#endif
105 int eol_hl_off; // 1 if highlighted char after EOL
106
107 unsigned off; // offset in ScreenLines/ScreenAttrs
108
109 int win_attr; // background for the whole window, except
110 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100111 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100112#ifdef FEAT_SYN_HL
113 int cul_attr; // set when 'cursorline' active
114#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000115#ifdef LINE_ATTR
116 int line_attr; // for the whole line, includes 'cursorline'
117#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100118
119 int screen_line_flags; // flags for screen_line()
120
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100121 int fromcol; // start of inverting
122 int tocol; // end of inverting
123
124#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100125 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100126 int need_showbreak; // overlong line, skipping first x chars
127 int dont_use_showbreak; // do not use 'showbreak'
128#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100129#ifdef FEAT_PROP_POPUP
130 int text_prop_above_count;
131#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100132
Bram Moolenaar1306b362022-08-06 15:59:06 +0100133 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
134 int cul_screenline;
135
136 int char_attr; // attributes for the next character
137
138 int n_extra; // number of extra bytes
139 char_u *p_extra; // string of extra chars, plus NUL, only used
140 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100141 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000142 int extra_attr; // attributes for p_extra, should be combined
143 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000144 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100145 int c_extra; // extra chars, all the same
146 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000147 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100148
149 // saved "extra" items for when draw_state becomes WL_LINE (again)
150 int saved_n_extra;
151 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000152 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000153 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000154 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100155 int saved_c_extra;
156 int saved_c_final;
157 int saved_char_attr;
158
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100159 char_u extra[NUMBUFLEN + MB_MAXBYTES];
160 // "%ld " and 'fdc' must fit in here, as well
161 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100162
Bram Moolenaar1306b362022-08-06 15:59:06 +0100163#ifdef FEAT_DIFF
164 hlf_T diff_hlf; // type of diff highlighting
165#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100166 int filler_lines; // nr of filler lines to be drawn
167 int filler_todo; // nr of filler lines still to do + 1
168#ifdef FEAT_SIGNS
169 sign_attrs_T sattr;
170#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100171} winlinevars_T;
172
173// draw_state values for items that are drawn in sequence:
174#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100175#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100176#ifdef FEAT_FOLDING
177# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
178#else
179# define WL_FOLD WL_CMDLINE
180#endif
181#ifdef FEAT_SIGNS
182# define WL_SIGN (WL_FOLD + 1) // column for signs
183#else
184# define WL_SIGN WL_FOLD // column for signs
185#endif
186#define WL_NR (WL_SIGN + 1) // line number
187#ifdef FEAT_LINEBREAK
188# define WL_BRI (WL_NR + 1) // 'breakindent'
189#else
190# define WL_BRI WL_NR
191#endif
192#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
193# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
194#else
195# define WL_SBR WL_BRI
196#endif
197#define WL_LINE (WL_SBR + 1) // text in the line
198
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100199#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000201 * Return TRUE if CursorLineSign highlight is to be used.
202 */
203 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100204use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000205{
206 return wp->w_p_cul
207 && lnum == wp->w_cursor.lnum
208 && (wp->w_p_culopt_flags & CULOPT_NBR);
209}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100210#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000211
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212
213#ifdef FEAT_FOLDING
214/*
215 * Setup for drawing the 'foldcolumn', if there is one.
216 */
217 static void
218handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
219{
220 int fdc = compute_foldcolumn(wp, 0);
221
222 if (fdc <= 0)
223 return;
224
225 // Allocate a buffer, "wlv->extra[]" may already be in use.
226 vim_free(wlv->p_extra_free);
227 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
228 if (wlv->p_extra_free != NULL)
229 {
230 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
231 wp, FALSE, wlv->lnum);
232 wlv->p_extra_free[wlv->n_extra] = NUL;
233 wlv->p_extra = wlv->p_extra_free;
234 wlv->c_extra = NUL;
235 wlv->c_final = NUL;
236 if (use_cursor_line_highlight(wp, wlv->lnum))
237 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
238 else
239 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
240 }
241}
242#endif
243
244#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000245/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100246 * Get information needed to display the sign in line "wlv->lnum" in window
247 * "wp".
248 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200249 * Otherwise the sign is going to be displayed in the sign column.
250 */
251 static void
252get_sign_display_info(
253 int nrcol,
254 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100255 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256{
257 int text_sign;
258# ifdef FEAT_SIGN_ICONS
259 int icon_sign;
260# endif
261
262 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100263 wlv->c_extra = ' ';
264 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267 else
268 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100269 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100270 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000271 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100273 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 }
275
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279#endif
280 )
281 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100282 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200283# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100284 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285 if (gui.in_use && icon_sign != 0)
286 {
287 // Use the image in this position.
288 if (nrcol)
289 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100290 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100291 sprintf((char *)wlv->extra, "%-*c ",
292 number_width(wp), SIGN_BYTE);
293 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100294 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 }
296 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100299 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
300 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 {
302 if (nrcol)
303 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100304 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100305 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100308 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 }
310 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 }
313# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100314 wlv->c_final = NUL;
315 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 }
317 else
318# endif
319 if (text_sign != 0)
320 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100321 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 {
324 if (nrcol)
325 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100326 int width = number_width(wp) - 2;
327 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200328
329 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100330 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100331 vim_snprintf((char *)wlv->extra + n,
332 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100335 wlv->c_extra = NUL;
336 wlv->c_final = NUL;
337 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200338 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000339
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100340 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100341 && wlv->sattr.sat_culhl > 0)
342 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000343 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100344 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200345 }
346 }
347}
348#endif
349
Bram Moolenaard7657e92022-09-20 18:59:30 +0100350/*
351 * Display the absolute or relative line number. After the first row fill with
352 * blanks when the 'n' flag isn't in 'cpo'.
353 */
354 static void
355handle_lnum_col(
356 win_T *wp,
357 winlinevars_T *wlv,
358 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100359 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100360{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100361 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100362 int lnum_row = wlv->startrow + wlv->filler_lines
363#ifdef FEAT_PROP_POPUP
364 + wlv->text_prop_above_count
365#endif
366 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100367
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100369 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100370 // there is no line number in a wrapped line when "n" is in
371 // 'cpoptions', but 'breakindent' assumes it anyway.
372 && !((has_cpo_n
373#ifdef FEAT_LINEBREAK
374 && !wp->w_p_bri
375#endif
376 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100377 {
378#ifdef FEAT_SIGNS
379 // If 'signcolumn' is set to 'number' and a sign is present
380 // in 'lnum', then display the sign instead of the line
381 // number.
382 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
383 get_sign_display_info(TRUE, wp, wlv);
384 else
385#endif
386 {
387 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100388 // When there are text properties above the line put the line number
389 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100390 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100391 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
392 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100393 {
394 long num;
395 char *fmt = "%*ld ";
396
397 if (wp->w_p_nu && !wp->w_p_rnu)
398 // 'number' + 'norelativenumber'
399 num = (long)wlv->lnum;
400 else
401 {
402 // 'relativenumber', don't use negative numbers
403 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
404 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
405 {
406 // 'number' + 'relativenumber'
407 num = wlv->lnum;
408 fmt = "%-*ld ";
409 }
410 }
411
412 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100413 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100414 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
415 ++wlv->p_extra)
416 *wlv->p_extra = '-';
417#ifdef FEAT_RIGHTLEFT
418 if (wp->w_p_rl) // reverse line numbers
419 {
420 char_u *p1, *p2;
421 int t;
422
423 // like rl_mirror(), but keep the space at the end
424 p2 = skipwhite(wlv->extra);
425 p2 = skiptowhite(p2) - 1;
426 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
427 {
428 t = *p1;
429 *p1 = *p2;
430 *p2 = t;
431 }
432 }
433#endif
434 wlv->p_extra = wlv->extra;
435 wlv->c_extra = NUL;
436 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100437 }
438 else
439 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100440 wlv->c_extra = ' ';
441 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100442 }
443 wlv->n_extra = number_width(wp) + 1;
444 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
445#ifdef FEAT_SYN_HL
446 // When 'cursorline' is set highlight the line number of
447 // the current line differently.
448 // When 'cursorlineopt' does not have "line" only
449 // highlight the line number itself.
450 // TODO: Can we use CursorLine instead of CursorLineNr
451 // when CursorLineNr isn't set?
452 if (wp->w_p_cul
453 && wlv->lnum == wp->w_cursor.lnum
454 && (wp->w_p_culopt_flags & CULOPT_NBR)
455 && (wlv->row == wlv->startrow + wlv->filler_lines
456 || (wlv->row > wlv->startrow + wlv->filler_lines
457 && (wp->w_p_culopt_flags & CULOPT_LINE))))
458 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
459#endif
460 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
461 && HL_ATTR(HLF_LNA) != 0)
462 // Use LineNrAbove
463 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
464 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
465 && HL_ATTR(HLF_LNB) != 0)
466 // Use LineNrBelow
467 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
468 }
469#ifdef FEAT_SIGNS
470 if (num_attr)
471 wlv->char_attr = num_attr;
472#endif
473 }
474}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100475
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100476#ifdef FEAT_LINEBREAK
477 static void
478handle_breakindent(win_T *wp, winlinevars_T *wlv)
479{
480 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100481 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100482 // draw indent after showbreak value
483 wlv->draw_state = WL_BRI;
484 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
485 // After the showbreak, draw the breakindent
486 wlv->draw_state = WL_BRI - 1;
487
488 // draw 'breakindent': indent wrapped text accordingly
489 if (wlv->draw_state == WL_BRI - 1)
490 {
491 wlv->draw_state = WL_BRI;
492 // if wlv->need_showbreak is set, breakindent also applies
493 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
494# ifdef FEAT_DIFF
495 && wlv->filler_lines == 0
496# endif
497# ifdef FEAT_PROP_POPUP
498 && !wlv->dont_use_showbreak
499# endif
500 )
501 {
502 wlv->char_attr = 0;
503# ifdef FEAT_DIFF
504 if (wlv->diff_hlf != (hlf_T)0)
505 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
506# endif
507 wlv->p_extra = NULL;
508 wlv->c_extra = ' ';
509 wlv->c_final = NUL;
510 wlv->n_extra = get_breakindent_win(wp,
511 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
512 if (wlv->row == wlv->startrow)
513 {
514 wlv->n_extra -= win_col_off2(wp);
515 if (wlv->n_extra < 0)
516 wlv->n_extra = 0;
517 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100518 if (wp->w_skipcol > 0 && wlv->startrow == 0
519 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100520 wlv->need_showbreak = FALSE;
521 // Correct end of highlighted area for 'breakindent',
522 // required when 'linebreak' is also set.
523 if (wlv->tocol == wlv->vcol)
524 wlv->tocol += wlv->n_extra;
525 }
526 }
527}
528#endif
529
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100530#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
531 static void
532handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
533{
534# ifdef FEAT_DIFF
535 if (wlv->filler_todo > 0)
536 {
537 // Draw "deleted" diff line(s).
538 if (char2cells(wp->w_fill_chars.diff) > 1)
539 {
540 wlv->c_extra = '-';
541 wlv->c_final = NUL;
542 }
543 else
544 {
545 wlv->c_extra = wp->w_fill_chars.diff;
546 wlv->c_final = NUL;
547 }
548# ifdef FEAT_RIGHTLEFT
549 if (wp->w_p_rl)
550 wlv->n_extra = wlv->col + 1;
551 else
552# endif
553 wlv->n_extra = wp->w_width - wlv->col;
554 wlv->char_attr = HL_ATTR(HLF_DED);
555 }
556# endif
557
558# ifdef FEAT_LINEBREAK
559 char_u *sbr = get_showbreak_value(wp);
560 if (*sbr != NUL && wlv->need_showbreak)
561 {
562 // Draw 'showbreak' at the start of each broken line.
563 wlv->p_extra = sbr;
564 wlv->c_extra = NUL;
565 wlv->c_final = NUL;
566 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100567 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100568 wlv->need_showbreak = FALSE;
569 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
570 // Correct end of highlighted area for 'showbreak',
571 // required when 'linebreak' is also set.
572 if (wlv->tocol == wlv->vcol)
573 wlv->tocol += wlv->n_extra;
574 // combine 'showbreak' with 'wincolor'
575 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
576# ifdef FEAT_SYN_HL
577 // combine 'showbreak' with 'cursorline'
578 if (wlv->cul_attr != 0)
579 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
580# endif
581 }
582# endif
583}
584#endif
585
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100586#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100587/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100588 * Return the cell size of virtual text after truncation.
589 */
590 static int
591textprop_size_after_trunc(
592 win_T *wp,
593 int flags, // TP_FLAG_ALIGN_*
594 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100595 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100596 char_u *text,
597 int *n_used_ptr)
598{
599 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100600 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100601 int len = (int)STRLEN(text);
602 int strsize = 0;
603 int n_used;
604
Bram Moolenaar7e017462022-10-11 21:02:09 +0100605 // if the remaining size is to small and 'wrap' is set we wrap anyway and
606 // use the next line
607 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100608 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100609 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100610 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
612 {
613 int clen = ptr2cells(text + n_used);
614
615 if (strsize + clen > space)
616 break;
617 strsize += clen;
618 }
619 *n_used_ptr = n_used;
620 return strsize;
621}
622
623/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100624 * Take care of padding, right-align and truncation of virtual text after a
625 * line.
626 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
627 * padding, right-align and truncation. Otherwise only the size is computed.
628 * When "n_attr" is NULL returns the number of screen cells used.
629 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100630 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int
632text_prop_position(
633 win_T *wp,
634 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000635 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100636 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100637 int *n_extra, // nr of bytes for virtual text
638 char_u **p_extra, // virtual text
639 int *n_attr, // attribute cells, NULL if not used
640 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200641{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100642 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100643 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
645 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
646 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000647 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100648 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100649 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100650 int before = room; // spaces before the text
651 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100652 int n_used = *n_extra;
653 char_u *l = NULL;
654 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100655 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100656 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100659 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100660 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100661
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100662 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100663 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100665 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 }
667 else
668 {
669 // Right-align: fill with before
670 if (right)
671 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000672
673 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000674 if (below && vcol == 0 && col_with_padding == col_off
675 && wp->w_width - col_off == before)
676 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000677
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100678 if (before < 0
679 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000680 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
681 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100682 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100683 if (right && (wrap
684 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100685 {
686 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 before = wp->w_width - col_off - strsize + room;
688 if (before < 0)
689 before = 0;
690 else
691 n_used = *n_extra;
692 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100693 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100694 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100695 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100696 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100697
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698 // With 'nowrap' add one to show the "extends" character if needed (it
699 // doesn't show if the text just fits).
700 if (!wp->w_p_wrap
701 && n_used < *n_extra
702 && wp->w_lcs_chars.ext != NUL
703 && wp->w_p_list)
704 ++n_used;
705
706 // add 1 for NUL, 2 for when '…' is used
707 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 if (n_attr == NULL || l != NULL)
710 {
711 int off = 0;
712
713 if (n_attr != NULL)
714 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 vim_memset(l, ' ', before);
716 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100717 if (padding > 0)
718 {
719 vim_memset(l + off, ' ', padding);
720 off += padding;
721 }
722 vim_strncpy(l + off, *p_extra, n_used);
723 off += n_used;
724 }
725 else
726 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100727 off = before + after + padding + n_used;
728 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100729 }
730 if (n_attr != NULL)
731 {
732 if (n_used < *n_extra && wp->w_p_wrap)
733 {
734 char_u *lp = l + off - 1;
735
736 if (has_mbyte)
737 {
738 // change last character to '…'
739 lp -= (*mb_head_off)(l, lp);
740 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100741 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100742 }
743 else
744 // change last character to '>'
745 *lp = '>';
746 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 else if (after > 0)
748 {
749 vim_memset(l + off, ' ', after);
750 l[off + after] = NUL;
751 }
752
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100753 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100754 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100755 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100756 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100757 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100758
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000759 // n_attr_skip will not be decremented before draw_state is
760 // WL_LINE
761 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100762 }
763 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100764 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100765
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100766 if (n_attr == NULL)
767 return cells;
768 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200769}
770#endif
771
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100772/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100773 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100774 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
775 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100776 */
777 static void
778wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
779{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100780 if (wlv->row == 0 && wp->w_skipcol > 0
781#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100782 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100783 && *get_showbreak_value(wp) == NUL
784#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100785 // do not overwrite the 'listchars' "precedes" text with "<<<"
786 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100787 {
788 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100789 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100790
Bram Moolenaareb4de622022-10-15 13:42:17 +0100791 if (wp->w_p_nu && wp->w_p_rnu)
792 // Do not overwrite the line number, change "123 text" to
793 // "123>>>xt".
794 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
795 {
796 ++off;
797 ++skip;
798 }
799
800 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100801 {
802 ScreenLines[off] = '<';
803 if (enc_utf8)
804 ScreenLinesUC[off] = 0;
805 ScreenAttrs[off] = HL_ATTR(HLF_AT);
806 ++off;
807 }
808 }
809
810 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
811 negative_width ? -wp->w_width : wp->w_width,
812 wlv->screen_line_flags);
813}
814
815/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100816 * Called when finished with the line: draw the screen line and handle any
817 * highlighting until the right of the window.
818 */
819 static void
820draw_screen_line(win_T *wp, winlinevars_T *wlv)
821{
822#ifdef FEAT_SYN_HL
823 long v;
824
825 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
826 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100827 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100828 else
829 v = wp->w_leftcol;
830
831 // check if line ends before left margin
832 if (wlv->vcol < v + wlv->col - win_col_off(wp))
833 wlv->vcol = v + wlv->col - win_col_off(wp);
834# ifdef FEAT_CONCEAL
835 // Get rid of the boguscols now, we want to draw until the right
836 // edge for 'cursorcolumn'.
837 wlv->col -= wlv->boguscols;
838 wlv->boguscols = 0;
839# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
840# else
841# define VCOL_HLC (wlv->vcol)
842# endif
843
844 if (wlv->draw_color_col)
845 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
846
847 if (((wp->w_p_cuc
848 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
849 && (int)wp->w_virtcol <
850 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
851 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000852 || wlv->draw_color_col
853# ifdef LINE_ATTR
854 || wlv->line_attr != 0
855# endif
856 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100857# ifdef FEAT_RIGHTLEFT
858 && !wp->w_p_rl
859# endif
860 )
861 {
862 int rightmost_vcol = 0;
863 int i;
864
865 if (wp->w_p_cuc)
866 rightmost_vcol = wp->w_virtcol;
867 if (wlv->draw_color_col)
868 // determine rightmost colorcolumn to possibly draw
869 for (i = 0; wlv->color_cols[i] >= 0; ++i)
870 if (rightmost_vcol < wlv->color_cols[i])
871 rightmost_vcol = wlv->color_cols[i];
872
873 while (wlv->col < wp->w_width)
874 {
875 ScreenLines[wlv->off] = ' ';
876 if (enc_utf8)
877 ScreenLinesUC[wlv->off] = 0;
878 ScreenCols[wlv->off] = MAXCOL;
879 ++wlv->col;
880 if (wlv->draw_color_col)
881 wlv->draw_color_col = advance_color_col(
882 VCOL_HLC, &wlv->color_cols);
883
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000884 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100885 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000886 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100887 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000888 attr = HL_ATTR(HLF_MC);
889# ifdef LINE_ATTR
890 else if (wlv->line_attr != 0)
891 attr = wlv->line_attr;
892# endif
893 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000895 if (VCOL_HLC >= rightmost_vcol
896# ifdef LINE_ATTR
897 && wlv->line_attr == 0
898# endif
899 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100900 break;
901
902 ++wlv->vcol;
903 }
904 }
905#endif
906
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100907 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100908 ++wlv->row;
909 ++wlv->screen_row;
910}
911#undef VCOL_HLC
912
913/*
914 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100915 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100916 */
917 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100918win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100919{
920 wlv->col = 0;
921 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
922
923#ifdef FEAT_RIGHTLEFT
924 if (wp->w_p_rl)
925 {
926 // Rightleft window: process the text in the normal direction, but put
927 // it in current_ScreenLine[] from right to left. Start at the
928 // rightmost column of the window.
929 wlv->col = wp->w_width - 1;
930 wlv->off += wlv->col;
931 wlv->screen_line_flags |= SLF_RIGHTLEFT;
932 }
933#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100934 if (save_extra)
935 {
936 // reset the drawing state for the start of a wrapped line
937 wlv->draw_state = WL_START;
938 wlv->saved_n_extra = wlv->n_extra;
939 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000940 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000941 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000942 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100943 wlv->saved_c_extra = wlv->c_extra;
944 wlv->saved_c_final = wlv->c_final;
945#ifdef FEAT_SYN_HL
946 if (!(wlv->cul_screenline
947# ifdef FEAT_DIFF
948 && wlv->diff_hlf == (hlf_T)0
949# endif
950 ))
951 wlv->saved_char_attr = wlv->char_attr;
952 else
953#endif
954 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000955
956 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100957 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000958 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100959 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100960}
961
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200962/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100963 * Called when wlv->draw_state is set to WL_LINE.
964 */
965 static void
966win_line_continue(winlinevars_T *wlv)
967{
968 if (wlv->saved_n_extra > 0)
969 {
970 // Continue item from end of wrapped line.
971 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000972 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100973 wlv->c_extra = wlv->saved_c_extra;
974 wlv->c_final = wlv->saved_c_final;
975 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000976 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000977 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000978 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100979 wlv->char_attr = wlv->saved_char_attr;
980 }
981 else
982 wlv->char_attr = wlv->win_attr;
983}
984
985/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200986 * Display line "lnum" of window 'wp' on the screen.
987 * Start at row "startrow", stop when "endrow" is reached.
988 * wp->w_virtcol needs to be valid.
989 *
990 * Return the number of last row the line occupies.
991 */
992 int
993win_line(
994 win_T *wp,
995 linenr_T lnum,
996 int startrow,
997 int endrow,
998 int nochange UNUSED, // not updating for changed text
999 int number_only) // only update the number column
1000{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001001 winlinevars_T wlv; // variables passed between functions
1002
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001005 char_u *line; // current line
1006 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007
Bram Moolenaar1306b362022-08-06 15:59:06 +01001008#ifdef FEAT_PROP_POPUP
1009 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1010#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001011#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001012 int in_linebreak = FALSE; // n_extra set for showing linebreak
1013#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001014 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001015 // displaying eol at end-of-line
1016 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001017 int lcs_prec_todo = wp->w_lcs_chars.prec;
1018 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001020 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001021 int saved_attr2 = 0; // char_attr saved for n_attr
1022 int n_attr3 = 0; // chars with overruling special attr
1023 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001024
Bram Moolenaarcd105412022-10-10 19:50:42 +01001025 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1026 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001027#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001028 int skip_cells = 0; // nr of cells to skip for virtual text
1029 // after the line, when w_skipcol is
1030 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001031#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 int fromcol_prev = -2; // start of inverting after cursor
1034 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 int lnum_in_visual_area = FALSE;
1036 pos_T pos;
1037 long v;
1038
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001039 int attr_pri = FALSE; // char_attr has priority
1040 int area_highlighting = FALSE; // Visual or incsearch highlighting
1041 // in this line
1042 int vi_attr = 0; // attributes for Visual and incsearch
1043 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001044 int area_attr = 0; // attributes desired by highlighting
1045 int search_attr = 0; // attributes desired by 'hlsearch'
1046#ifdef FEAT_SYN_HL
1047 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1048 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001049 int prev_syntax_col = -1; // column of prev_syntax_attr
1050 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001051 int has_syntax = FALSE; // this buffer has syntax highl.
1052 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001054#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001055 int text_prop_count;
1056 int text_prop_next = 0; // next text property to use
1057 textprop_T *text_props = NULL;
1058 int *text_prop_idxs = NULL;
1059 int text_props_active = 0;
1060 proptype_T *text_prop_type = NULL;
1061 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001062 int text_prop_attr_comb = 0; // text_prop_attr combined with
1063 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001064 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001065 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001066 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001067 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001068 int saved_search_attr = 0; // search_attr to be used when n_extra
1069 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001070 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001071 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072#endif
1073#ifdef FEAT_SPELL
1074 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001075 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076# define SPWORDLEN 150
1077 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1078 int nextlinecol = 0; // column where nextline[] starts
1079 int nextline_idx = 0; // index in nextline[] where next line
1080 // starts
1081 int spell_attr = 0; // attributes desired by spelling
1082 int word_end = 0; // last byte with same spell_attr
1083 static linenr_T checked_lnum = 0; // line number for "checked_col"
1084 static int checked_col = 0; // column in "checked_lnum" up to which
1085 // there are no spell errors
1086 static int cap_col = -1; // column to check for Cap word
1087 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1088 int cur_checked_col = 0; // checked column for current line
1089#endif
1090 int extra_check = 0; // has extra highlighting
1091 int multi_attr = 0; // attributes desired by multibyte
1092 int mb_l = 1; // multi-byte byte length
1093 int mb_c = 0; // decoded multi-byte character
1094 int mb_utf8 = FALSE; // screen char is UTF-8 char
1095 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 int change_start = MAXCOL; // first col of changed area
1098 int change_end = -1; // last col of changed area
1099#endif
1100 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001101 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001102 int in_multispace = FALSE; // in multiple consecutive spaces
1103 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001104#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001105 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001108 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109#ifdef FEAT_ARABIC
1110 int prev_c = 0; // previous Arabic character
1111 int prev_c1 = 0; // first composing char for prev_c
1112#endif
1113#if defined(LINE_ATTR)
1114 int did_line_attr = 0;
1115#endif
1116#ifdef FEAT_TERMINAL
1117 int get_term_attr = FALSE;
1118#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119
Martin Tournoijba43e762022-10-13 22:12:15 +01001120#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 // margin columns for the screen line, needed for when 'cursorlineopt'
1122 // contains "screenline"
1123 int left_curline_col = 0;
1124 int right_curline_col = 0;
1125#endif
1126
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1128 int feedback_col = 0;
1129 int feedback_old_attr = -1;
1130#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131
1132#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1133 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001134#endif
1135#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001136 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001137#endif
1138#ifdef FEAT_CONCEAL
1139 int syntax_flags = 0;
1140 int syntax_seqnr = 0;
1141 int prev_syntax_id = 0;
1142 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1143 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 int did_wcol = FALSE;
1145 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001146# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147# define FIX_FOR_BOGUSCOLS \
1148 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001149 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001150 wlv.vcol -= wlv.vcol_off; \
1151 wlv.vcol_off = 0; \
1152 wlv.col -= wlv.boguscols; \
1153 old_boguscols = wlv.boguscols; \
1154 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155 }
1156#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001157# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158#endif
1159
1160 if (startrow > endrow) // past the end already!
1161 return startrow;
1162
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001163 CLEAR_FIELD(wlv);
1164
1165 wlv.lnum = lnum;
1166 wlv.startrow = startrow;
1167 wlv.row = startrow;
1168 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001169 wlv.fromcol = -10;
1170 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001171#ifdef FEAT_LINEBREAK
1172 wlv.vcol_sbr = -1;
1173#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174
1175 if (!number_only)
1176 {
1177 // To speed up the loop below, set extra_check when there is linebreak,
1178 // trailing white space and/or syntax processing to be done.
1179#ifdef FEAT_LINEBREAK
1180 extra_check = wp->w_p_lbr;
1181#endif
1182#ifdef FEAT_SYN_HL
1183 if (syntax_present(wp) && !wp->w_s->b_syn_error
1184# ifdef SYN_TIME_LIMIT
1185 && !wp->w_s->b_syn_slow
1186# endif
1187 )
1188 {
1189 // Prepare for syntax highlighting in this line. When there is an
1190 // error, stop syntax highlighting.
1191 save_did_emsg = did_emsg;
1192 did_emsg = FALSE;
1193 syntax_start(wp, lnum);
1194 if (did_emsg)
1195 wp->w_s->b_syn_error = TRUE;
1196 else
1197 {
1198 did_emsg = save_did_emsg;
1199#ifdef SYN_TIME_LIMIT
1200 if (!wp->w_s->b_syn_slow)
1201#endif
1202 {
1203 has_syntax = TRUE;
1204 extra_check = TRUE;
1205 }
1206 }
1207 }
1208
1209 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001210 wlv.color_cols = wp->w_p_cc_cols;
1211 if (wlv.color_cols != NULL)
1212 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213#endif
1214
1215#ifdef FEAT_TERMINAL
1216 if (term_show_buffer(wp->w_buffer))
1217 {
1218 extra_check = TRUE;
1219 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001220 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 }
1222#endif
1223
1224#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001225 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 {
1227 // Prepare for spell checking.
1228 has_spell = TRUE;
1229 extra_check = TRUE;
1230
1231 // Get the start of the next line, so that words that wrap to the
1232 // next line are found too: "et<line-break>al.".
1233 // Trick: skip a few chars for C/shell/Vim comments
1234 nextline[SPWORDLEN] = NUL;
1235 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1236 {
1237 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1238 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1239 }
1240
1241 // When a word wrapped from the previous line the start of the
1242 // current line is valid.
1243 if (lnum == checked_lnum)
1244 cur_checked_col = checked_col;
1245 checked_lnum = 0;
1246
1247 // When there was a sentence end in the previous line may require a
1248 // word starting with capital in this line. In line 1 always check
1249 // the first word.
1250 if (lnum != capcol_lnum)
1251 cap_col = -1;
1252 if (lnum == 1)
1253 cap_col = 0;
1254 capcol_lnum = 0;
1255 }
1256#endif
1257
1258 // handle Visual active in this window
1259 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1260 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001261 pos_T *top, *bot;
1262
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1264 {
1265 // Visual is after curwin->w_cursor
1266 top = &curwin->w_cursor;
1267 bot = &VIsual;
1268 }
1269 else
1270 {
1271 // Visual is before curwin->w_cursor
1272 top = &VIsual;
1273 bot = &curwin->w_cursor;
1274 }
1275 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1276 if (VIsual_mode == Ctrl_V)
1277 {
1278 // block mode
1279 if (lnum_in_visual_area)
1280 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001281 wlv.fromcol = wp->w_old_cursor_fcol;
1282 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283 }
1284 }
1285 else
1286 {
1287 // non-block mode
1288 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001289 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 else if (lnum == top->lnum)
1291 {
1292 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001293 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 else
1295 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 }
1300 }
1301 if (VIsual_mode != 'V' && lnum == bot->lnum)
1302 {
1303 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1304 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001305 wlv.fromcol = -10;
1306 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 }
1308 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001309 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 else
1311 {
1312 pos = *bot;
1313 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001314 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1315 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 else
1317 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001318 getvvcol(wp, &pos, NULL, NULL,
1319 (colnr_T *)&wlv.tocol);
1320 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001321 }
1322 }
1323 }
1324 }
1325
1326 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001327 if (!highlight_match && lnum == curwin->w_cursor.lnum
1328 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001329#ifdef FEAT_GUI
1330 && !gui.in_use
1331#endif
1332 )
1333 noinvcur = TRUE;
1334
1335 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001336 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 {
1338 area_highlighting = TRUE;
1339 vi_attr = HL_ATTR(HLF_V);
1340#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1341 if ((clip_star.available && !clip_star.owned
1342 && clip_isautosel_star())
1343 || (clip_plus.available && !clip_plus.owned
1344 && clip_isautosel_plus()))
1345 vi_attr = HL_ATTR(HLF_VNC);
1346#endif
1347 }
1348 }
1349
1350 // handle 'incsearch' and ":s///c" highlighting
1351 else if (highlight_match
1352 && wp == curwin
1353 && lnum >= curwin->w_cursor.lnum
1354 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1355 {
1356 if (lnum == curwin->w_cursor.lnum)
1357 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001358 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001360 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1362 {
1363 pos.lnum = lnum;
1364 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001365 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001366 }
1367 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001368 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001370 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1371 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 area_highlighting = TRUE;
1373 vi_attr = HL_ATTR(HLF_I);
1374 }
1375 }
1376
1377#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001378 wlv.filler_lines = diff_check(wp, lnum);
1379 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001381 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 {
1383 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001384 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001386 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001388 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001389 }
1390 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001391 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001392 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 area_highlighting = TRUE;
1394 }
1395 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001396 wlv.filler_lines = wp->w_topfill;
1397 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398#endif
1399
1400#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001401 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001402 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001403 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404#endif
1405
1406#ifdef LINE_ATTR
1407# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001408 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001410 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411# endif
1412# if defined(FEAT_QUICKFIX)
1413 // Highlight the current line in the quickfix window.
1414 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001415 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001417 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 area_highlighting = TRUE;
1419#endif
1420
1421 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1422 ptr = line;
1423
1424#ifdef FEAT_SPELL
1425 if (has_spell && !number_only)
1426 {
1427 // For checking first word with a capital skip white space.
1428 if (cap_col == 0)
1429 cap_col = getwhitecols(line);
1430
1431 // To be able to spell-check over line boundaries copy the end of the
1432 // current line into nextline[]. Above the start of the next line was
1433 // copied to nextline[SPWORDLEN].
1434 if (nextline[SPWORDLEN] == NUL)
1435 {
1436 // No next line or it is empty.
1437 nextlinecol = MAXCOL;
1438 nextline_idx = 0;
1439 }
1440 else
1441 {
1442 v = (long)STRLEN(line);
1443 if (v < SPWORDLEN)
1444 {
1445 // Short line, use it completely and append the start of the
1446 // next line.
1447 nextlinecol = 0;
1448 mch_memmove(nextline, line, (size_t)v);
1449 STRMOVE(nextline + v, nextline + SPWORDLEN);
1450 nextline_idx = v + 1;
1451 }
1452 else
1453 {
1454 // Long line, use only the last SPWORDLEN bytes.
1455 nextlinecol = v - SPWORDLEN;
1456 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1457 nextline_idx = SPWORDLEN + 1;
1458 }
1459 }
1460 }
1461#endif
1462
1463 if (wp->w_p_list)
1464 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001465 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001466 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001467 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001468 || wp->w_lcs_chars.trail
1469 || wp->w_lcs_chars.lead
1470 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001472
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001474 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 {
1476 trailcol = (colnr_T)STRLEN(ptr);
1477 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1478 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001479 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001481 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001482 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001483 {
1484 leadcol = 0;
1485 while (VIM_ISWHITE(ptr[leadcol]))
1486 ++leadcol;
1487 if (ptr[leadcol] == NUL)
1488 // in a line full of spaces all of them are treated as trailing
1489 leadcol = (colnr_T)0;
1490 else
1491 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001492 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001493 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 }
1495
Bram Moolenaard7657e92022-09-20 18:59:30 +01001496 wlv.wcr_attr = get_wcr_attr(wp);
1497 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001499 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500 area_highlighting = TRUE;
1501 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001502
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001503#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001505 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506#endif
1507
1508 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1509 // first character to be displayed.
1510 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001511 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 else
1513 v = wp->w_leftcol;
1514 if (v > 0 && !number_only)
1515 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001516 char_u *prev_ptr = ptr;
1517 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001518 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001520 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001521 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001522 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001523 charsize = win_lbr_chartabsize(&cts, NULL);
1524 cts.cts_vcol += charsize;
1525 prev_ptr = cts.cts_ptr;
1526 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001528 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001529 ptr = cts.cts_ptr;
1530 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531
1532 // When:
1533 // - 'cuc' is set, or
1534 // - 'colorcolumn' is set, or
1535 // - 'virtualedit' is set, or
1536 // - the visual mode is active,
1537 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001538 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001540 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541#endif
1542 virtual_active() ||
1543 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001544 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545
1546 // Handle a character that's not completely on the screen: Put ptr at
1547 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001548 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001550 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 ptr = prev_ptr;
1552 // If the character fits on the screen, don't need to skip it.
1553 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001554 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1555 && wlv.col == 0)
1556 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557 }
1558
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001559#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001560 // If there the text doesn't reach to the desired column, need to skip
1561 // "skip_cells" cells when virtual text follows.
1562 if (!wp->w_p_wrap && v > wlv.vcol)
1563 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001564#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001566 // Adjust for when the inverted text is before the screen,
1567 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001568 if (wlv.tocol <= wlv.vcol)
1569 wlv.fromcol = 0;
1570 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1571 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572
1573#ifdef FEAT_LINEBREAK
1574 // When w_skipcol is non-zero, first line needs 'showbreak'
1575 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001576 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577#endif
1578#ifdef FEAT_SPELL
1579 // When spell checking a word we need to figure out the start of the
1580 // word and if it's badly spelled or not.
1581 if (has_spell)
1582 {
1583 int len;
1584 colnr_T linecol = (colnr_T)(ptr - line);
1585 hlf_T spell_hlf = HLF_COUNT;
1586
1587 pos = wp->w_cursor;
1588 wp->w_cursor.lnum = lnum;
1589 wp->w_cursor.col = linecol;
1590 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1591
1592 // spell_move_to() may call ml_get() and make "line" invalid
1593 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1594 ptr = line + linecol;
1595
1596 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1597 {
1598 // no bad word found at line start, don't check until end of a
1599 // word
1600 spell_hlf = HLF_COUNT;
1601 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1602 }
1603 else
1604 {
1605 // bad word found, use attributes until end of word
1606 word_end = wp->w_cursor.col + len + 1;
1607
1608 // Turn index into actual attributes.
1609 if (spell_hlf != HLF_COUNT)
1610 spell_attr = highlight_attr[spell_hlf];
1611 }
1612 wp->w_cursor = pos;
1613
1614# ifdef FEAT_SYN_HL
1615 // Need to restart syntax highlighting for this line.
1616 if (has_syntax)
1617 syntax_start(wp, lnum);
1618# endif
1619 }
1620#endif
1621 }
1622
1623 // Correct highlighting for cursor that can't be disabled.
1624 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001625 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 {
1627 if (noinvcur)
1628 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001629 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 {
1631 // highlighting starts at cursor, let it start just after the
1632 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001633 fromcol_prev = wlv.fromcol;
1634 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001636 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637 // restart highlighting after the cursor
1638 fromcol_prev = wp->w_virtcol;
1639 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001640 if (wlv.fromcol >= wlv.tocol)
1641 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642 }
1643
1644#ifdef FEAT_SEARCH_EXTRA
1645 if (!number_only)
1646 {
1647 v = (long)(ptr - line);
1648 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1649 &line, &screen_search_hl,
1650 &search_attr);
1651 ptr = line + v; // "line" may have been updated
1652 }
1653#endif
1654
1655#ifdef FEAT_SYN_HL
1656 // Cursor line highlighting for 'cursorline' in the current window.
1657 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1658 {
1659 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001660 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 if (!(wp == curwin && VIsual_active)
1662 && wp->w_p_culopt_flags != CULOPT_NBR)
1663 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001664 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1666
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001667 // Only set wlv.line_attr here when "screenline" is not present in
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001668 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001669 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001671 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001672# ifdef FEAT_SIGNS
1673 // Combine the 'cursorline' and sign highlighting, depending on
1674 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001675 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001676 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001677 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001678 wlv.line_attr = hl_combine_attr(
1679 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001680 else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001681 wlv.line_attr = hl_combine_attr(
1682 wlv.line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001683 }
1684 else
1685# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001686# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001687 // let the line attribute overrule 'cursorline', otherwise
1688 // it disappears when both have background set;
1689 // 'cursorline' can use underline or bold to make it show
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001690 wlv.line_attr = hl_combine_attr(
1691 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001692# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001693 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001694# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001695 }
1696 else
1697 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001698 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1700 }
1701 area_highlighting = TRUE;
1702 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 }
1704#endif
1705
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001706#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 {
1708 char_u *prop_start;
1709
1710 text_prop_count = get_text_props(wp->w_buffer, lnum,
1711 &prop_start, FALSE);
1712 if (text_prop_count > 0)
1713 {
1714 // Make a copy of the properties, so that they are properly
1715 // aligned.
1716 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1717 if (text_props != NULL)
1718 mch_memmove(text_props, prop_start,
1719 text_prop_count * sizeof(textprop_T));
1720
1721 // Allocate an array for the indexes.
1722 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001723 if (text_prop_idxs == NULL)
1724 VIM_CLEAR(text_props);
1725
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001726 if (text_props != NULL)
1727 {
1728 area_highlighting = TRUE;
1729 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001730 // text props "above" move the line number down to where the
1731 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001732 for (int i = 0; i < text_prop_count; ++i)
1733 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1734 ++wlv.text_prop_above_count;
1735 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 }
1737 }
1738#endif
1739
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741
1742 // Repeat for the whole displayed line.
1743 for (;;)
1744 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001745 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001746#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001747 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001748#endif
1749#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001750 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001752
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001756#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001757 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001758 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001759 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001760 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001761 }
1762#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001764 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001765 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 if (cmdwin_type != 0 && wp == curwin)
1767 {
1768 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 wlv.n_extra = 1;
1770 wlv.c_extra = cmdwin_type;
1771 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001772 wlv.char_attr =
1773 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
1775 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001777 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001779 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001780 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 }
1782#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001786 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001789 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 }
1791#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001793 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001794 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001795 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001796 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001799 // Check if 'breakindent' applies and show it.
1800 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1801 if (wlv.n_extra == 0)
1802 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001803#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001805 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001807 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001808 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 }
1810#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001811 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001814 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 }
1816 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001817
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001820 && wlv.vcol >= left_curline_col
1821 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001823 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001824 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 }
1826#endif
1827
1828 // When still displaying '$' of change command, stop at cursor.
1829 // When only displaying the (relative) line number and that's done,
1830 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001831 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001832 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001833 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001835 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836#endif
1837 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001839 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 // Pretend we have finished updating the window. Except when
1841 // 'cursorcolumn' is set.
1842#ifdef FEAT_SYN_HL
1843 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001844 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 else
1846#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001847 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 break;
1849 }
1850
Bram Moolenaar1306b362022-08-06 15:59:06 +01001851 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 {
1853 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001854 if (wlv.vcol == wlv.fromcol
1855 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1856 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 && (*mb_ptr2cells)(ptr) > 1)
1858 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001859 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001860 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 area_attr = vi_attr; // start highlighting
1862 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001863 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001864 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 area_attr = 0; // stop highlighting
1866
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001867#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 if (text_props != NULL)
1869 {
1870 int pi;
1871 int bcol = (int)(ptr - line);
1872
Bram Moolenaar1306b362022-08-06 15:59:06 +01001873 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001874# ifdef FEAT_LINEBREAK
1875 && !in_linebreak
1876# endif
1877 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 --bcol; // still working on the previous char, e.g. Tab
1879
1880 // Check if any active property ends.
1881 for (pi = 0; pi < text_props_active; ++pi)
1882 {
1883 int tpi = text_prop_idxs[pi];
1884
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001885 if (text_props[tpi].tp_col != MAXCOL
1886 && bcol >= text_props[tpi].tp_col - 1
1887 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 {
1889 if (pi + 1 < text_props_active)
1890 mch_memmove(text_prop_idxs + pi,
1891 text_prop_idxs + pi + 1,
1892 sizeof(int)
1893 * (text_props_active - (pi + 1)));
1894 --text_props_active;
1895 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001896# ifdef FEAT_LINEBREAK
1897 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001898 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001899 syntax_attr = 0;
1900# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901 }
1902 }
1903
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001904# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001905 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001906 // not on the next char yet, don't start another prop
1907 --bcol;
1908# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001910 // With 'nowrap' and not in the first screen line only "below"
1911 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001913 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001914 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001915 && (wp->w_p_wrap
1916 || wlv.row == startrow
1917 || (text_props[text_prop_next].tp_flags
1918 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001919 || (bcol == 0 &&
1920 (text_props[text_prop_next].tp_flags
1921 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001922 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001923 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001924 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001925 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1926 {
1927 // first display the '$' after the line
1928 text_prop_follows = TRUE;
1929 break;
1930 }
1931 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001932 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001933 + text_props[text_prop_next].tp_len)
1934 text_prop_idxs[text_props_active++] = text_prop_next;
1935 ++text_prop_next;
1936 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001938 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001939 {
1940 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001941 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001942 text_prop_flags = 0;
1943 text_prop_type = NULL;
1944 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001945 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001946 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001947 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001949 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001950 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001951 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001952
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 // Sort the properties on priority and/or starting last.
1954 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001955 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001956 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001957 sort_text_props(wp->w_buffer, text_props,
1958 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959
1960 for (pi = 0; pi < text_props_active; ++pi)
1961 {
1962 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001963 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001965 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001966
Bram Moolenaarcd105412022-10-10 19:50:42 +01001967 // Only use a text property that can be displayed.
1968 // Skip "after" properties when wrap is off and at the
1969 // end of the window.
1970 if (pt != NULL
1971 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1972 && tp->tp_id != -MAXCOL
1973 && !(tp->tp_id < 0
1974 && !wp->w_p_wrap
1975 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1976 | TP_FLAG_ALIGN_ABOVE
1977 | TP_FLAG_ALIGN_BELOW)) == 0
1978 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001979 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001980 if (pt->pt_hl_id > 0)
1981 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 text_prop_type = pt;
1983 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001984 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001985 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001986 text_prop_flags = pt->pt_flags;
1987 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001988 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 }
1990 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001991 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001992 && -text_prop_id
1993 <= wp->w_buffer->b_textprop_text.ga_len)
1994 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001995 textprop_T *tp = &text_props[used_tpi];
1996 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001997 ->b_textprop_text.ga_data)[
1998 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001999 int above = (tp->tp_flags
2000 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002001 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002002
2003 // reset the ID in the copy to avoid it being used
2004 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002005 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002006
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002007 if (p != NULL)
2008 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002009 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002010 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002011 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002012 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002013 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2014 int padding = tp->tp_col == MAXCOL
2015 && tp->tp_len > 1
2016 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002017
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002018 // Insert virtual text before the current
2019 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002020 wlv.p_extra = p;
2021 wlv.c_extra = NUL;
2022 wlv.c_final = NUL;
2023 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002024 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002025 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2026 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002027 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002028 // restore search_attr and area_attr when n_extra
2029 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002030 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002031 saved_area_attr = area_attr;
2032 search_attr = 0;
2033 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002034 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002035 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002036 if (*ptr == NUL)
2037 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002038 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002039#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002040 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002041 {
2042 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002043 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002044 wlv.need_showbreak = FALSE;
2045 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002046 }
2047#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002048 if ((right || above || below || !wrap
2049 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002050 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002051 char_u *prev_p_extra = wlv.p_extra;
2052 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002053
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002054 // Take care of padding, right-align and
2055 // truncation.
2056 // Shared with win_lbr_chartabsize(), must do
2057 // exactly the same.
2058 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002059 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002060 wlv.col,
2061 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002062 &n_attr, &wlv.n_attr_skip);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002063 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002064 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002065 // wlv.p_extra was allocated
2066 vim_free(p_extra_free2);
2067 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002068 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002069
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002070 if (lcs_eol_one < 0
2071 && wp->w_p_wrap
2072 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002073 + wlv.n_extra - 2 > wp->w_width)
2074 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002075 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002076
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002077 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002078 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002079 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002080 {
2081 draw_screen_line(wp, &wlv);
2082
2083 // When line got too long for screen break
2084 // here.
2085 if (wlv.row == endrow)
2086 {
2087 ++wlv.row;
2088 break;
2089 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002090 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002091 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002092 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002093 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002094 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002095
Bram Moolenaarcd105412022-10-10 19:50:42 +01002096 // If the text didn't reach until the first window
2097 // column we need to skip cells.
2098 if (skip_cells > 0)
2099 {
2100 if (wlv.n_extra > skip_cells)
2101 {
2102 wlv.n_extra -= skip_cells;
2103 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002104 wlv.n_attr_skip -= skip_cells;
2105 if (wlv.n_attr_skip < 0)
2106 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002107 skip_cells = 0;
2108 }
2109 else
2110 {
2111 // the whole text is left of the window, drop
2112 // it and advance to the next one
2113 skip_cells -= wlv.n_extra;
2114 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002115 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002116 bail_out = TRUE;
2117 }
2118 }
2119
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120 // If another text prop follows the condition below at
2121 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002122 // If this is an "above" text prop and 'nowrap' the we
2123 // must wrap anyway.
2124 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002125 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002126 && (wp->w_p_wrap
2127 || (text_props[other_tpi].tp_flags
2128 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002129
2130 if (bail_out)
2131 // starting a new line for "below"
2132 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002133 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002134 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002135 else if (text_prop_next < text_prop_count
2136 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002137 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2138 || (!wp->w_p_wrap
2139 && wlv.col == wp->w_width - 1
2140 && (text_props[text_prop_next].tp_flags
2141 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002142 // When at last-but-one character and a text property
2143 // follows after it, we may need to flush the line after
2144 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002145 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002146 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002147 }
2148#endif
2149
Bram Moolenaare38fc862022-08-11 17:24:50 +01002150#ifdef FEAT_SEARCH_EXTRA
2151 if (wlv.n_extra == 0)
2152 {
2153 // Check for start/end of 'hlsearch' and other matches.
2154 // After end, check for start/end of next match.
2155 // When another match, have to check for start again.
2156 v = (long)(ptr - line);
2157 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2158 &screen_search_hl, &has_match_conc,
2159 &match_conc, did_line_attr, lcs_eol_one,
2160 &on_last_col);
2161 ptr = line + v; // "line" may have been changed
2162 prev_ptr = ptr;
2163
2164 // Do not allow a conceal over EOL otherwise EOL will be missed
2165 // and bad things happen.
2166 if (*ptr == NUL)
2167 has_match_conc = 0;
2168 }
2169#endif
2170
2171#ifdef FEAT_DIFF
2172 if (wlv.diff_hlf != (hlf_T)0)
2173 {
2174 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2175 && wlv.n_extra == 0)
2176 wlv.diff_hlf = HLF_TXD; // changed text
2177 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2178 && wlv.n_extra == 0)
2179 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002180 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002181 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2182 && wp->w_p_culopt_flags != CULOPT_NBR
2183 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2184 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002185 wlv.line_attr = hl_combine_attr(
2186 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002187 }
2188#endif
2189
Bram Moolenaara74fda62019-10-19 17:38:03 +02002190#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002191 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002192 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002193 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002194# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002195 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002196 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002197# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002198 // Get syntax attribute.
2199 if (has_syntax)
2200 {
2201 // Get the syntax attribute for the character. If there
2202 // is an error, disable syntax highlighting.
2203 save_did_emsg = did_emsg;
2204 did_emsg = FALSE;
2205
2206 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002207 if (v == prev_syntax_col)
2208 // at same column again
2209 syntax_attr = prev_syntax_attr;
2210 else
2211 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002212# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002213 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002214# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002215 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002216# ifdef FEAT_SPELL
2217 has_spell ? &can_spell :
2218# endif
2219 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002220 prev_syntax_col = v;
2221 prev_syntax_attr = syntax_attr;
2222 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002223
Bram Moolenaar34390282019-10-16 14:38:26 +02002224 if (did_emsg)
2225 {
2226 wp->w_s->b_syn_error = TRUE;
2227 has_syntax = FALSE;
2228 syntax_attr = 0;
2229 }
2230 else
2231 did_emsg = save_did_emsg;
2232# ifdef SYN_TIME_LIMIT
2233 if (wp->w_s->b_syn_slow)
2234 has_syntax = FALSE;
2235# endif
2236
2237 // Need to get the line again, a multi-line regexp may
2238 // have made it invalid.
2239 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2240 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002241 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002242# ifdef FEAT_CONCEAL
2243 // no concealing past the end of the line, it interferes
2244 // with line highlighting
2245 if (*ptr == NUL)
2246 syntax_flags = 0;
2247 else
2248 syntax_flags = get_syntax_info(&syntax_seqnr);
2249# endif
2250 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002251 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002252# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002253 // Combine text property highlight into syntax highlight.
2254 if (text_prop_type != NULL)
2255 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002256 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002257 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2258 else
2259 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002260 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002261 }
2262# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002263#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002264
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002265 // Decide which of the highlight attributes to use.
2266 attr_pri = TRUE;
2267#ifdef LINE_ATTR
2268 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002269 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002270 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002271 if (!highlight_match)
2272 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002273 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002274# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002275 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002276# endif
2277 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002279 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002280 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002281# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002282 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002283# endif
2284 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002285 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002286 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2287 || wlv.vcol < wlv.fromcol
2288 || vcol_prev < fromcol_prev
2289 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002291 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002292 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002293# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002294 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002295# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002296 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002297# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002298 attr_pri = FALSE;
2299 }
2300#else
2301 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002305#endif
2306 else
2307 {
2308 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002311#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002313#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002315#ifdef FEAT_PROP_POPUP
2316 // override with text property highlight when "override" is TRUE
2317 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002318 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002319#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002321
2322 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002323 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002324 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002325 if (wlv.char_attr == 0)
2326 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002327 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002328 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002329 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330
2331 // Get the next character to put on the screen.
2332
2333 // The "p_extra" points to the extra stuff that is inserted to
2334 // represent special characters (non-printable stuff) and other
2335 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002336 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2338 // "p_extra[n_extra]".
2339 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002344 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2345 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2347 if (enc_utf8 && utf_char2len(c) > 1)
2348 {
2349 mb_utf8 = TRUE;
2350 u8cc[0] = 0;
2351 c = 0xc0;
2352 }
2353 else
2354 mb_utf8 = FALSE;
2355 }
2356 else
2357 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002358 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 if (has_mbyte)
2360 {
2361 mb_c = c;
2362 if (enc_utf8)
2363 {
2364 // If the UTF-8 character is more than one byte:
2365 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 mb_l = 1;
2370 else if (mb_l > 1)
2371 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002372 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 mb_utf8 = TRUE;
2374 c = 0xc0;
2375 }
2376 }
2377 else
2378 {
2379 // if this is a DBCS character, put it in "mb_c"
2380 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 mb_l = 1;
2383 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 }
2386 if (mb_l == 0) // at the NUL at end-of-line
2387 mb_l = 1;
2388
2389 // If a double-width char doesn't fit display a '>' in the
2390 // last column.
2391 if ((
2392# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002393 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002395 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 && (*mb_char2cells)(mb_c) == 2)
2397 {
2398 c = '>';
2399 mb_c = c;
2400 mb_l = 1;
2401 mb_utf8 = FALSE;
2402 multi_attr = HL_ATTR(HLF_AT);
2403#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002404 if (wlv.cul_attr)
2405 multi_attr = hl_combine_attr(
2406 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002408 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002409
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 // put the pointer back to output the double-width
2411 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 ++wlv.n_extra;
2413 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 }
2415 else
2416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 wlv.n_extra -= mb_l - 1;
2418 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 }
2420 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002421 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002424#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002426 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002427 // Only restore search_attr and area_attr after "n_extra" in
2428 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002429 if (wlv.saved_n_extra <= 0)
2430 {
2431 if (search_attr == 0)
2432 search_attr = saved_search_attr;
2433 if (area_attr == 0 && *ptr != NUL)
2434 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002435
2436 if (wlv.extra_for_textprop)
2437 // wlv.extra_attr should be used at this position but
2438 // not any further.
2439 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002440 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002441
2442 wlv.extra_for_textprop = FALSE;
2443 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002444 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002445#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 }
2447 else
2448 {
2449#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002450 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002452 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 // Get a character from the line itself.
2455 c = *ptr;
2456#ifdef FEAT_LINEBREAK
2457 c0 = *ptr;
2458#endif
2459 if (has_mbyte)
2460 {
2461 mb_c = c;
2462 if (enc_utf8)
2463 {
2464 // If the UTF-8 character is more than one byte: Decode it
2465 // into "mb_c".
2466 mb_l = utfc_ptr2len(ptr);
2467 mb_utf8 = FALSE;
2468 if (mb_l > 1)
2469 {
2470 mb_c = utfc_ptr2char(ptr, u8cc);
2471 // Overlong encoded ASCII or ASCII with composing char
2472 // is displayed normally, except a NUL.
2473 if (mb_c < 0x80)
2474 {
2475 c = mb_c;
2476#ifdef FEAT_LINEBREAK
2477 c0 = mb_c;
2478#endif
2479 }
2480 mb_utf8 = TRUE;
2481
2482 // At start of the line we can have a composing char.
2483 // Draw it as a space with a composing char.
2484 if (utf_iscomposing(mb_c))
2485 {
2486 int i;
2487
2488 for (i = Screen_mco - 1; i > 0; --i)
2489 u8cc[i] = u8cc[i - 1];
2490 u8cc[0] = mb_c;
2491 mb_c = ' ';
2492 }
2493 }
2494
2495 if ((mb_l == 1 && c >= 0x80)
2496 || (mb_l >= 1 && mb_c == 0)
2497 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2498 {
2499 // Illegal UTF-8 byte: display as <xx>.
2500 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002501 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502# ifdef FEAT_RIGHTLEFT
2503 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002504 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002506 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002507 c = *wlv.p_extra;
2508 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002510 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2511 wlv.c_extra = NUL;
2512 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 if (area_attr == 0 && search_attr == 0)
2514 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002515 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002516 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002517 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002518 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 }
2520 }
2521 else if (mb_l == 0) // at the NUL at end-of-line
2522 mb_l = 1;
2523#ifdef FEAT_ARABIC
2524 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2525 {
2526 // Do Arabic shaping.
2527 int pc, pc1, nc;
2528 int pcc[MAX_MCO];
2529
2530 // The idea of what is the previous and next
2531 // character depends on 'rightleft'.
2532 if (wp->w_p_rl)
2533 {
2534 pc = prev_c;
2535 pc1 = prev_c1;
2536 nc = utf_ptr2char(ptr + mb_l);
2537 prev_c1 = u8cc[0];
2538 }
2539 else
2540 {
2541 pc = utfc_ptr2char(ptr + mb_l, pcc);
2542 nc = prev_c;
2543 pc1 = pcc[0];
2544 }
2545 prev_c = mb_c;
2546
2547 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2548 }
2549 else
2550 prev_c = mb_c;
2551#endif
2552 }
2553 else // enc_dbcs
2554 {
2555 mb_l = MB_BYTE2LEN(c);
2556 if (mb_l == 0) // at the NUL at end-of-line
2557 mb_l = 1;
2558 else if (mb_l > 1)
2559 {
2560 // We assume a second byte below 32 is illegal.
2561 // Hopefully this is OK for all double-byte encodings!
2562 if (ptr[1] >= 32)
2563 mb_c = (c << 8) + ptr[1];
2564 else
2565 {
2566 if (ptr[1] == NUL)
2567 {
2568 // head byte at end of line
2569 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002570 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 }
2572 else
2573 {
2574 // illegal tail byte
2575 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002576 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002578 wlv.p_extra = wlv.extra;
2579 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 wlv.c_extra = NUL;
2581 wlv.c_final = NUL;
2582 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002583 if (area_attr == 0 && search_attr == 0)
2584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002585 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002586 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002587 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002588 // save current attr
2589 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 }
2591 mb_c = c;
2592 }
2593 }
2594 }
2595 // If a double-width char doesn't fit display a '>' in the
2596 // last column; the character is displayed at the start of the
2597 // next line.
2598 if ((
2599# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002600 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002601# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002602 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 && (*mb_char2cells)(mb_c) == 2)
2604 {
2605 c = '>';
2606 mb_c = c;
2607 mb_utf8 = FALSE;
2608 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002609 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 // Put pointer back so that the character will be
2611 // displayed at the start of the next line.
2612 --ptr;
2613#ifdef FEAT_CONCEAL
2614 did_decrement_ptr = TRUE;
2615#endif
2616 }
2617 else if (*ptr != NUL)
2618 ptr += mb_l - 1;
2619
2620 // If a double-width char doesn't fit at the left side display
2621 // a '<' in the first column. Don't do this for unprintable
2622 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 wlv.n_extra = 1;
2626 wlv.c_extra = MB_FILLER_CHAR;
2627 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 c = ' ';
2629 if (area_attr == 0 && search_attr == 0)
2630 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002632 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002633 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002634 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 }
2636 mb_c = c;
2637 mb_utf8 = FALSE;
2638 mb_l = 1;
2639 }
2640
2641 }
2642 ++ptr;
2643
2644 if (extra_check)
2645 {
2646#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002647 // Check spelling (unless at the end of the line).
2648 // Only do this when there is no syntax highlighting, the
2649 // @Spell cluster is not used or the current syntax item
2650 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002651 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 if (has_spell && v >= word_end && v > cur_checked_col)
2653 {
2654 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002655 // do not calculate cap_col at the end of the line or when
2656 // only white space is following
2657 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658# ifdef FEAT_SYN_HL
2659 !has_syntax ||
2660# endif
2661 can_spell))
2662 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002663 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 int len;
2665 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002666
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669
2670 // Use nextline[] if possible, it has the start of the
2671 // next line concatenated.
2672 if ((prev_ptr - line) - nextlinecol >= 0)
2673 p = nextline + (prev_ptr - line) - nextlinecol;
2674 else
2675 p = prev_ptr;
2676 cap_col -= (int)(prev_ptr - line);
2677 len = spell_check(wp, p, &spell_hlf, &cap_col,
2678 nochange);
2679 word_end = v + len;
2680
2681 // In Insert mode only highlight a word that
2682 // doesn't touch the cursor.
2683 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002684 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 && wp->w_cursor.lnum == lnum
2686 && wp->w_cursor.col >=
2687 (colnr_T)(prev_ptr - line)
2688 && wp->w_cursor.col < (colnr_T)word_end)
2689 {
2690 spell_hlf = HLF_COUNT;
2691 spell_redraw_lnum = lnum;
2692 }
2693
2694 if (spell_hlf == HLF_COUNT && p != prev_ptr
2695 && (p - nextline) + len > nextline_idx)
2696 {
2697 // Remember that the good word continues at the
2698 // start of the next line.
2699 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002700 checked_col = (int)((p - nextline)
2701 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 }
2703
2704 // Turn index into actual attributes.
2705 if (spell_hlf != HLF_COUNT)
2706 spell_attr = highlight_attr[spell_hlf];
2707
2708 if (cap_col > 0)
2709 {
2710 if (p != prev_ptr
2711 && (p - nextline) + cap_col >= nextline_idx)
2712 {
2713 // Remember that the word in the next line
2714 // must start with a capital.
2715 capcol_lnum = lnum + 1;
2716 cap_col = (int)((p - nextline) + cap_col
2717 - nextline_idx);
2718 }
2719 else
2720 // Compute the actual column.
2721 cap_col += (int)(prev_ptr - line);
2722 }
2723 }
2724 }
2725 if (spell_attr != 0)
2726 {
2727 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002728 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2729 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002731 wlv.char_attr = hl_combine_attr(spell_attr,
2732 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 }
2734#endif
2735#ifdef FEAT_LINEBREAK
2736 // Found last space before word: check for line break.
2737 if (wp->w_p_lbr && c0 == c
2738 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2739 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002740 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2741 : 0;
2742 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002743 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002745 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002746# ifdef FEAT_PROP_POPUP
2747 // do not want virtual text counted here
2748 cts.cts_has_prop_with_text = FALSE;
2749# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002750 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002751 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002752
2753 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002754 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002755 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002756 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002757 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2758 if (wlv.n_extra < 0)
2759 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002760 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002761 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002762 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002763 // line break, but for TABs the highlighting should
2764 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002765 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002766
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002770 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 wp->w_buffer->b_p_vts_array) - 1;
2772# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002773 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002774 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775# endif
2776
Bram Moolenaar1306b362022-08-06 15:59:06 +01002777 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2778 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002779# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002780 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002781 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002782# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783 if (VIM_ISWHITE(c))
2784 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002785# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 if (c == TAB)
2787 // See "Tab alignment" below.
2788 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002789# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 if (!wp->w_p_list)
2791 c = ' ';
2792 }
2793 }
2794#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002795 in_multispace = c == ' '
2796 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2797 if (!in_multispace)
2798 multispace_pos = 0;
2799
Bram Moolenaareed9d462021-02-15 20:38:25 +01002800 // 'list': Change char 160 to 'nbsp' and space to 'space'
2801 // setting in 'listchars'. But not when the character is
2802 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 if (wp->w_p_list
2804 && ((((c == 160 && mb_l == 1)
2805 || (mb_utf8
2806 && ((mb_c == 160 && mb_l == 2)
2807 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002808 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 || (c == ' '
2810 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002811 && (wp->w_lcs_chars.space
2812 || (in_multispace
2813 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002814 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 && ptr - line <= trailcol)))
2816 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002817 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2818 {
2819 c = wp->w_lcs_chars.multispace[multispace_pos++];
2820 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2821 multispace_pos = 0;
2822 }
2823 else
2824 c = (c == ' ') ? wp->w_lcs_chars.space
2825 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002826 if (area_attr == 0 && search_attr == 0)
2827 {
2828 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002829 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002830 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002831 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 }
2833 mb_c = c;
2834 if (enc_utf8 && utf_char2len(c) > 1)
2835 {
2836 mb_utf8 = TRUE;
2837 u8cc[0] = 0;
2838 c = 0xc0;
2839 }
2840 else
2841 mb_utf8 = FALSE;
2842 }
2843
zeertzjq2e7cba32022-06-10 15:30:32 +01002844 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2845 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002847 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2848 && wp->w_lcs_chars.leadmultispace != NULL)
2849 {
2850 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002851 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2852 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002853 multispace_pos = 0;
2854 }
2855
2856 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2857 c = wp->w_lcs_chars.trail;
2858
2859 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2860 c = wp->w_lcs_chars.lead;
2861
zeertzjq2e7cba32022-06-10 15:30:32 +01002862 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002863 c = wp->w_lcs_chars.space;
2864
2865
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 if (!attr_pri)
2867 {
2868 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002869 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002871 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 }
2873 mb_c = c;
2874 if (enc_utf8 && utf_char2len(c) > 1)
2875 {
2876 mb_utf8 = TRUE;
2877 u8cc[0] = 0;
2878 c = 0xc0;
2879 }
2880 else
2881 mb_utf8 = FALSE;
2882 }
2883 }
2884
2885 // Handling of non-printable characters.
2886 if (!vim_isprintc(c))
2887 {
2888 // when getting a character from the file, we may have to
2889 // turn it into something else on the way to putting it
2890 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002891 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002892 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002893 int tab_len = 0;
2894 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002896 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002897
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 // only adjust the tab_len, when at the first column
2899 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002900 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002901 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902#endif
2903 // tab amount depends on current column
2904#ifdef FEAT_VARTABS
2905 tab_len = tabstop_padding(vcol_adjusted,
2906 wp->w_buffer->b_p_ts,
2907 wp->w_buffer->b_p_vts_array) - 1;
2908#else
2909 tab_len = (int)wp->w_buffer->b_p_ts
2910 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2911#endif
2912
2913#ifdef FEAT_LINEBREAK
2914 if (!wp->w_p_lbr || !wp->w_p_list)
2915#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002916 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002918 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002919 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920#ifdef FEAT_LINEBREAK
2921 else
2922 {
2923 char_u *p;
2924 int len;
2925 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002926 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002928# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002929 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002931 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002932
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002934 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 && old_boguscols > 0
2936 && wlv.n_extra > tab_len)
2937 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002938# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002939 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002941 // If wlv.n_extra > 0, it gives the number of chars
2942 // to use for a tab, else we need to calculate the
2943 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002944 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2945 len = tab_len * tab2_len;
2946 if (wp->w_lcs_chars.tab3)
2947 len += mb_char2len(wp->w_lcs_chars.tab3)
2948 - tab2_len;
2949 if (wlv.n_extra > 0)
2950 len += wlv.n_extra - tab_len;
2951 c = wp->w_lcs_chars.tab1;
2952 p = alloc(len + 1);
2953 if (p == NULL)
2954 wlv.n_extra = 0;
2955 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002957 vim_memset(p, ' ', len);
2958 p[len] = NUL;
2959 vim_free(wlv.p_extra_free);
2960 wlv.p_extra_free = p;
2961 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002962 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002963 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002964
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002965 if (*p == NUL)
2966 {
2967 tab_len = i;
2968 break;
2969 }
2970
2971 // if tab3 is given, use it for the last
2972 // char
2973 if (wp->w_lcs_chars.tab3
2974 && i == tab_len - 1)
2975 lcs = wp->w_lcs_chars.tab3;
2976 p += mb_char2bytes(lcs, p);
2977 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002979 }
2980 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002981# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002982 // n_extra will be increased by
2983 // FIX_FOX_BOGUSCOLS macro below, so need to
2984 // adjust for that here
2985 if (wlv.vcol_off > 0)
2986 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002987# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002988 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002990 }
2991#endif
2992#ifdef FEAT_CONCEAL
2993 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995
2996 // Tab alignment should be identical regardless of
2997 // 'conceallevel' value. So tab compensates of all
2998 // previous concealed characters, and thus resets
2999 // vcol_off and boguscols accumulated so far in the
3000 // line. Note that the tab can be longer than
3001 // 'tabstop' when there are concealed characters.
3002 FIX_FOR_BOGUSCOLS;
3003
3004 // Make sure, the highlighting for the tab char will be
3005 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003006 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003007 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003008 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 tab_len += vc_saved;
3010 }
3011#endif
3012 mb_utf8 = FALSE; // don't draw as UTF-8
3013 if (wp->w_p_list)
3014 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003015 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003016 ? wp->w_lcs_chars.tab3
3017 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003019 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003020 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 else
3022#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 wlv.c_extra = wp->w_lcs_chars.tab2;
3024 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003026 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003027 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003028 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 mb_c = c;
3030 if (enc_utf8 && utf_char2len(c) > 1)
3031 {
3032 mb_utf8 = TRUE;
3033 u8cc[0] = 0;
3034 c = 0xc0;
3035 }
3036 }
3037 else
3038 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 wlv.c_final = NUL;
3040 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 c = ' ';
3042 }
3043 }
3044 else if (c == NUL
3045 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003046 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3047 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 && VIsual_mode != Ctrl_V
3049 && (
3050# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003051 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003053 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 && !(noinvcur
3055 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003056 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 && lcs_eol_one > 0)
3058 {
3059 // Display a '$' after the line or highlight an extra
3060 // character if the line break is included.
3061#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3062 // For a diff line the highlighting continues after the
3063 // "$".
3064 if (
3065# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067# ifdef LINE_ATTR
3068 &&
3069# endif
3070# endif
3071# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003072 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003073# endif
3074 )
3075#endif
3076 {
3077 // In virtualedit, visual selections may extend
3078 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003079 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003080 && wlv.tocol != MAXCOL
3081 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003082 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003083 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003085 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3086 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 else
3088 c = ' ';
3089 lcs_eol_one = -1;
3090 --ptr; // put it back at the NUL
3091 if (!attr_pri)
3092 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003093 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003094 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 n_attr = 1;
3096 }
3097 mb_c = c;
3098 if (enc_utf8 && utf_char2len(c) > 1)
3099 {
3100 mb_utf8 = TRUE;
3101 u8cc[0] = 0;
3102 c = 0xc0;
3103 }
3104 else
3105 mb_utf8 = FALSE; // don't draw as UTF-8
3106 }
3107 else if (c != NUL)
3108 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3110 if (wlv.n_extra == 0)
3111 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112#ifdef FEAT_RIGHTLEFT
3113 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003114 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003116 wlv.c_extra = NUL;
3117 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118#ifdef FEAT_LINEBREAK
3119 if (wp->w_p_lbr)
3120 {
3121 char_u *p;
3122
Bram Moolenaar1306b362022-08-06 15:59:06 +01003123 c = *wlv.p_extra;
3124 p = alloc(wlv.n_extra + 1);
3125 vim_memset(p, ' ', wlv.n_extra);
3126 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3127 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003128 vim_free(wlv.p_extra_free);
3129 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130 }
3131 else
3132#endif
3133 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003134 wlv.n_extra = byte2cells(c) - 1;
3135 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 }
3137 if (!attr_pri)
3138 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003139 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003140 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003142 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143 }
3144 mb_utf8 = FALSE; // don't draw as UTF-8
3145 }
3146 else if (VIsual_active
3147 && (VIsual_mode == Ctrl_V
3148 || VIsual_mode == 'v')
3149 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003150 && wlv.tocol != MAXCOL
3151 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152 && (
3153#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003154 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003156 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 {
3158 c = ' ';
3159 --ptr; // put it back at the NUL
3160 }
3161#if defined(LINE_ATTR)
3162 else if ((
3163# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003164 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165# endif
3166# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003167 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003169 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003170 ) && (
3171# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003176 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177# endif
3178 < wp->w_width)))
3179 {
3180 // Highlight until the right side of the window
3181 c = ' ';
3182 --ptr; // put it back at the NUL
3183
3184 // Remember we do the char for line highlighting.
3185 ++did_line_attr;
3186
3187 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003188 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003190 || (wp->w_p_list &&
3191 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003192 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003194 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003196 wlv.diff_hlf = HLF_CHD;
3197 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003199 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3201 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003203 || (wlv.vcol >= left_curline_col
3204 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 wlv.char_attr = hl_combine_attr(
3206 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 }
3208 }
3209# endif
3210# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003211 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003213 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003214 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3215 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003217 if (!wlv.cul_screenline
3218 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003219 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003220 wlv.char_attr = hl_combine_attr(
3221 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003223 else if (wlv.line_attr)
3224 wlv.char_attr = hl_combine_attr(
3225 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 }
3227# endif
3228 }
3229#endif
3230 }
3231
3232#ifdef FEAT_CONCEAL
3233 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003234 && (wp != curwin || lnum != wp->w_cursor.lnum
3235 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3237 && !(lnum_in_visual_area
3238 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3239 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003241 if (((prev_syntax_id != syntax_seqnr
3242 && (syntax_flags & HL_CONCEAL) != 0)
3243 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003244 && (syn_get_sub_char() != NUL
3245 || (has_match_conc && match_conc)
3246 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 && wp->w_p_cole != 3)
3248 {
3249 // First time at this concealed item: display one
3250 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003251 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 c = match_conc;
3253 else if (syn_get_sub_char() != NUL)
3254 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003255 else if (wp->w_lcs_chars.conceal != NUL)
3256 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 else
3258 c = ' ';
3259
3260 prev_syntax_id = syntax_seqnr;
3261
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 if (wlv.n_extra > 0)
3263 wlv.vcol_off += wlv.n_extra;
3264 wlv.vcol += wlv.n_extra;
3265 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 {
3267# ifdef FEAT_RIGHTLEFT
3268 if (wp->w_p_rl)
3269 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003270 wlv.col -= wlv.n_extra;
3271 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272 }
3273 else
3274# endif
3275 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003276 wlv.boguscols += wlv.n_extra;
3277 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 }
3279 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 n_attr = 0;
3282 }
3283 else if (n_skip == 0)
3284 {
3285 is_concealing = TRUE;
3286 n_skip = 1;
3287 }
3288 mb_c = c;
3289 if (enc_utf8 && utf_char2len(c) > 1)
3290 {
3291 mb_utf8 = TRUE;
3292 u8cc[0] = 0;
3293 c = 0xc0;
3294 }
3295 else
3296 mb_utf8 = FALSE; // don't draw as UTF-8
3297 }
3298 else
3299 {
3300 prev_syntax_id = 0;
3301 is_concealing = FALSE;
3302 }
3303
3304 if (n_skip > 0 && did_decrement_ptr)
3305 // not showing the '>', put pointer back to avoid getting stuck
3306 ++ptr;
3307
3308#endif // FEAT_CONCEAL
3309 }
3310
3311#ifdef FEAT_CONCEAL
3312 // In the cursor line and we may be concealing characters: correct
3313 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 && wp == curwin && lnum == wp->w_cursor.lnum
3316 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003317 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003319# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003323# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 wp->w_wcol = wlv.col - wlv.boguscols;
3325 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 did_wcol = TRUE;
3327 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003328# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003329 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003330# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 }
3332#endif
3333
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003334 // Use "wlv.extra_attr", but don't override visual selection
3335 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003336 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3337 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003339 && (!attr_pri
3340#ifdef FEAT_PROP_POPUP
3341 || (text_prop_flags & PT_FLAG_OVERRIDE)
3342#endif
3343 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 {
3345#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003346 if (wlv.line_attr)
3347 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 else
3349#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003350 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003351#ifdef FEAT_PROP_POPUP
3352 if (reset_extra_attr)
3353 {
3354 reset_extra_attr = FALSE;
3355 wlv.extra_attr = 0;
3356 }
3357#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 }
3359
3360#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3361 // XIM don't send preedit_start and preedit_end, but they send
3362 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3363 // im_is_preediting() here.
3364 if (p_imst == IM_ON_THE_SPOT
3365 && xic != NULL
3366 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003367 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 && !p_imdisable
3369 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003370 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 {
3372 colnr_T tcol;
3373
3374 if (preedit_end_col == MAXCOL)
3375 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3376 else
3377 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003378 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 {
3380 if (feedback_old_attr < 0)
3381 {
3382 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 wlv.char_attr = im_get_feedback_attr(feedback_col);
3386 if (wlv.char_attr < 0)
3387 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 feedback_col++;
3389 }
3390 else if (feedback_old_attr >= 0)
3391 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 feedback_old_attr = -1;
3394 feedback_col = 0;
3395 }
3396 }
3397#endif
3398 // Handle the case where we are in column 0 but not on the first
3399 // character of the line and the user wants us to show us a
3400 // special character (via 'listchars' option "precedes:<char>".
3401 if (lcs_prec_todo != NUL
3402 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003403 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3404 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003406 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003408 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 && c != NUL)
3410 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003411 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003412 lcs_prec_todo = NUL;
3413 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3414 {
3415 // Double-width character being overwritten by the "precedes"
3416 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003417 wlv.c_extra = MB_FILLER_CHAR;
3418 wlv.c_final = NUL;
3419 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003421 wlv.extra_attr =
3422 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 }
3424 mb_c = c;
3425 if (enc_utf8 && utf_char2len(c) > 1)
3426 {
3427 mb_utf8 = TRUE;
3428 u8cc[0] = 0;
3429 c = 0xc0;
3430 }
3431 else
3432 mb_utf8 = FALSE; // don't draw as UTF-8
3433 if (!attr_pri)
3434 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 saved_attr3 = wlv.char_attr; // save current attr
3436 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 n_attr3 = 1;
3438 }
3439 }
3440
3441 // At end of the text line or just after the last character.
3442 if ((c == NUL
3443#if defined(LINE_ATTR)
3444 || did_line_attr == 1
3445#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 {
3448#ifdef FEAT_SEARCH_EXTRA
3449 // flag to indicate whether prevcol equals startcol of search_hl or
3450 // one of the matches
3451 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3452 (long)(ptr - line) - (c == NUL));
3453#endif
3454 // Invert at least one char, used for Visual and empty line or
3455 // highlight match at end of line. If it's beyond the last
3456 // char on the screen, just overwrite that one (tricky!) Not
3457 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003458 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003459 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003460 && (VIsual_mode != Ctrl_V
3461 || lnum == VIsual.lnum
3462 || lnum == curwin->w_cursor.lnum)
3463 && c == NUL)
3464#ifdef FEAT_SEARCH_EXTRA
3465 // highlight 'hlsearch' match at end of line
3466 || (prevcol_hl_flag
3467# ifdef FEAT_SYN_HL
3468 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3469 && !(wp == curwin && VIsual_active))
3470# endif
3471# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003472 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473# endif
3474# if defined(LINE_ATTR)
3475 && did_line_attr <= 1
3476# endif
3477 )
3478#endif
3479 ))
3480 {
3481 int n = 0;
3482
3483#ifdef FEAT_RIGHTLEFT
3484 if (wp->w_p_rl)
3485 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003486 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003487 n = 1;
3488 }
3489 else
3490#endif
3491 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 n = -1;
3494 }
3495 if (n != 0)
3496 {
3497 // At the window boundary, highlight the last character
3498 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003499 wlv.off += n;
3500 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 }
3502 else
3503 {
3504 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003505 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
3509#ifdef FEAT_SEARCH_EXTRA
3510 if (area_attr == 0)
3511 {
3512 // Use attributes from match with highest priority among
3513 // 'search_hl' and the match list.
3514 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003515 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 }
3517#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003519 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520#ifdef FEAT_RIGHTLEFT
3521 if (wp->w_p_rl)
3522 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 --wlv.col;
3524 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 }
3526 else
3527#endif
3528 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 ++wlv.col;
3530 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003532 ++wlv.vcol;
3533 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 }
3535 }
3536
3537 // At end of the text line.
3538 if (c == NUL)
3539 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003540 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541
3542 // Update w_cline_height and w_cline_folded if the cursor line was
3543 // updated (saves a call to plines() later).
3544 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3545 {
3546 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003547 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548#ifdef FEAT_FOLDING
3549 curwin->w_cline_folded = FALSE;
3550#endif
3551 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3552 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 break;
3554 }
3555
3556 // Show "extends" character from 'listchars' if beyond the line end and
3557 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003558 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003559 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560 && wp->w_p_list
3561 && !wp->w_p_wrap
3562#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003563 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564#endif
3565 && (
3566#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003571 || lcs_eol_one > 0
3572 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003573 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003575 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003576 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 mb_c = c;
3578 if (enc_utf8 && utf_char2len(c) > 1)
3579 {
3580 mb_utf8 = TRUE;
3581 u8cc[0] = 0;
3582 c = 0xc0;
3583 }
3584 else
3585 mb_utf8 = FALSE;
3586 }
3587
3588#ifdef FEAT_SYN_HL
3589 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003590 if (wlv.draw_color_col)
3591 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592
3593 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3594 // highlight the cursor position itself.
3595 // Also highlight the 'colorcolumn' if it is different than
3596 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003597 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3598 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003600 if (((wlv.draw_state == WL_LINE
3601 || wlv.draw_state == WL_BRI
3602 || wlv.draw_state == WL_SBR)
3603 && !lnum_in_visual_area
3604 && search_attr == 0
3605 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003606# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003607 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003608# endif
3609 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003610 {
3611 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3612 && lnum != wp->w_cursor.lnum)
3613 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003614 vcol_save_attr = wlv.char_attr;
3615 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3616 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003620 vcol_save_attr = wlv.char_attr;
3621 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
3623 }
3624#endif
3625
3626 // Store character to be displayed.
3627 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003629 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 {
3631 // Store the character.
3632#if defined(FEAT_RIGHTLEFT)
3633 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3634 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003635 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 --wlv.off;
3637 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 }
3639#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 if (enc_dbcs == DBCS_JPNU)
3642 {
3643 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 ScreenLines[wlv.off] = 0x8e;
3645 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 }
3647 else if (enc_utf8)
3648 {
3649 if (mb_utf8)
3650 {
3651 int i;
3652
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003655 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 for (i = 0; i < Screen_mco; ++i)
3657 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 if (u8cc[i] == 0)
3660 break;
3661 }
3662 }
3663 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003664 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665 }
3666 if (multi_attr)
3667 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 multi_attr = 0;
3670 }
3671 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003672 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003675
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3677 {
3678 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 ++wlv.off;
3680 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681 if (enc_utf8)
3682 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003683 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 else
3685 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003689 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690#endif
3691 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003693 // When "wlv.tocol" is halfway a character, set it to the end
3694 // of the character, otherwise highlighting won't stop.
3695 if (wlv.tocol == wlv.vcol)
3696 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003697
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003699
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700#ifdef FEAT_RIGHTLEFT
3701 if (wp->w_p_rl)
3702 {
3703 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003704 --wlv.off;
3705 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 }
3707#endif
3708 }
3709#ifdef FEAT_RIGHTLEFT
3710 if (wp->w_p_rl)
3711 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 --wlv.off;
3713 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 }
3715 else
3716#endif
3717 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003718 ++wlv.off;
3719 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 }
3721 }
3722#ifdef FEAT_CONCEAL
3723 else if (wp->w_p_cole > 0 && is_concealing)
3724 {
3725 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003727 if (wlv.n_extra > 0)
3728 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 if (wp->w_p_wrap)
3730 {
3731 // Special voodoo required if 'wrap' is on.
3732 //
3733 // Advance the column indicator to force the line
3734 // drawing to wrap early. This will make the line
3735 // take up the same screen space when parts are concealed,
3736 // so that cursor line computations aren't messed up.
3737 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003738 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739 // trailing junk to be written out of the screen line
3740 // we are building, 'boguscols' keeps track of the number
3741 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003744 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745# ifdef FEAT_RIGHTLEFT
3746 if (wp->w_p_rl)
3747 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003748 wlv.col -= wlv.n_extra;
3749 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 }
3751 else
3752# endif
3753 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 wlv.col += wlv.n_extra;
3755 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003756 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003757 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 n_attr = 0;
3759 }
3760
3761
3762 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3763 {
3764 // Need to fill two screen columns.
3765# ifdef FEAT_RIGHTLEFT
3766 if (wp->w_p_rl)
3767 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003768 --wlv.boguscols;
3769 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 }
3771 else
3772# endif
3773 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 ++wlv.boguscols;
3775 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 }
3777 }
3778
3779# ifdef FEAT_RIGHTLEFT
3780 if (wp->w_p_rl)
3781 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003782 --wlv.boguscols;
3783 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
3785 else
3786# endif
3787 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003788 ++wlv.boguscols;
3789 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790 }
3791 }
3792 else
3793 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003794 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003796 wlv.vcol += wlv.n_extra;
3797 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 n_attr = 0;
3799 }
3800 }
3801
3802 }
3803#endif // FEAT_CONCEAL
3804 else
3805 --n_skip;
3806
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003807 // Only advance the "wlv.vcol" when after the 'number' or
3808 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003809 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003811 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812#endif
3813 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003814 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815
3816#ifdef FEAT_SYN_HL
3817 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003818 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819#endif
3820
3821 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003822 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3823 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003824
3825 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003826 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003827 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003828 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003829 if (wlv.n_attr_skip > 0)
3830 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831
3832 // At end of screen line and there is more to come: Display the line
3833 // so far. If there is no more to display it is caught above.
3834 if ((
3835#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003838 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003839 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003840 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003842 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003844#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003845 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003846#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003847 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003848 && wlv.p_extra != at_end_str)
3849 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3850 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 )
3852 {
3853#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003854 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003855 wlv_screen_line(wp, &wlv, FALSE);
3856 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003857 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003859 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 ++wlv.row;
3862 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863
3864 // When not wrapping and finished diff lines, or when displayed
3865 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003866 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003868 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003869#endif
3870#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003871 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003873 ) || lcs_eol_one == -1)
3874#ifdef FEAT_PROP_POPUP
3875 && !text_prop_follows
3876#endif
3877 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003878 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003879#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003880 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003881 {
3882 // do not output more of the line, only the "below" prop
3883 ptr += STRLEN(ptr);
3884# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003885 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003886# endif
3887 }
3888#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889
3890 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003891 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003893 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894#endif
3895 )
3896 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003897 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3898 draw_vsep_win(wp, wlv.row);
3899 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 }
3901
3902 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003903 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003905 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 break;
3907 }
3908
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003909 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003911 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003913#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003914 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003915#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 && wp->w_width == Columns)
3917 {
3918 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003919 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920
3921 // Special trick to make copy/paste of wrapped lines work with
3922 // xterm/screen: write an extra character beyond the end of
3923 // the line. This will work with all terminal types
3924 // (regardless of the xn,am settings).
3925 // Only do this on a fast tty.
3926 // Only do this if the cursor is on the current line
3927 // (something has been written in it).
3928 // Don't do this for the GUI.
3929 // Don't do this for double-width characters.
3930 // Don't do this for a window not at the right screen border.
3931 if (p_tf
3932#ifdef FEAT_GUI
3933 && !gui.in_use
3934#endif
3935 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003936 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3937 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 || (*mb_off2cells)(
3940 LineOffset[wlv.screen_row - 1]
3941 + (int)Columns - 2,
3942 LineOffset[wlv.screen_row]
3943 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 {
3945 // First make sure we are at the end of the screen line,
3946 // then output the same character again to let the
3947 // terminal know about the wrap. If the terminal doesn't
3948 // auto-wrap, we overwrite the character.
3949 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 screen_char(LineOffset[wlv.screen_row - 1]
3951 + (unsigned)Columns - 1,
3952 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003953
3954 // When there is a multi-byte character, just output a
3955 // space to keep it simple.
3956 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003957 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958 out_char(' ');
3959 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003960 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003961 + (Columns - 1)]);
3962 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003963 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964 screen_start(); // don't know where cursor is now
3965 }
3966 }
3967
Bram Moolenaar1306b362022-08-06 15:59:06 +01003968 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969
Bram Moolenaareed9d462021-02-15 20:38:25 +01003970 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003971#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003972 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003974 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003976 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003977 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978#endif
3979#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003980 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003981 // When the filler lines are actually below the last line of the
3982 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003983 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 break;
3985#endif
3986 }
3987
3988 } // for every character in the line
3989
3990#ifdef FEAT_SPELL
3991 // After an empty line check first word for capital.
3992 if (*skipwhite(line) == NUL)
3993 {
3994 capcol_lnum = lnum + 1;
3995 cap_col = 0;
3996 }
3997#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003998#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 vim_free(text_props);
4000 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004001 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002#endif
4003
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004004 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004005 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006}