blob: 804b1005af94518e6150e38317ec76e453e3a864 [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
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000640 int *n_attr_skip, // cells to skip attr, NULL if not used
641 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200642{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100643 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100645 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
646 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
647 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000648 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100649 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100650 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100651 int before = room; // spaces before the text
652 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100653 int n_used = *n_extra;
654 char_u *l = NULL;
655 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100657 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200658
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100659 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100660 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100661 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100662
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100663 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100664 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100666 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 }
668 else
669 {
670 // Right-align: fill with before
671 if (right)
672 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000673
674 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000675 if (below && vcol == 0 && col_with_padding == col_off
676 && wp->w_width - col_off == before)
677 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000678
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 if (before < 0
680 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000681 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
682 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100684 if (right && (wrap
685 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 {
687 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = wp->w_width - col_off - strsize + room;
689 if (before < 0)
690 before = 0;
691 else
692 n_used = *n_extra;
693 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000694 else if (below && before > vcol && do_skip)
695 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100696 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100697 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100699 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100700
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100701 // With 'nowrap' add one to show the "extends" character if needed (it
702 // doesn't show if the text just fits).
703 if (!wp->w_p_wrap
704 && n_used < *n_extra
705 && wp->w_lcs_chars.ext != NUL
706 && wp->w_p_list)
707 ++n_used;
708
709 // add 1 for NUL, 2 for when '…' is used
710 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100711 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 if (n_attr == NULL || l != NULL)
713 {
714 int off = 0;
715
716 if (n_attr != NULL)
717 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100718 vim_memset(l, ' ', before);
719 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100720 if (padding > 0)
721 {
722 vim_memset(l + off, ' ', padding);
723 off += padding;
724 }
725 vim_strncpy(l + off, *p_extra, n_used);
726 off += n_used;
727 }
728 else
729 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100730 off = before + after + padding + n_used;
731 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 }
733 if (n_attr != NULL)
734 {
735 if (n_used < *n_extra && wp->w_p_wrap)
736 {
737 char_u *lp = l + off - 1;
738
739 if (has_mbyte)
740 {
741 // change last character to '…'
742 lp -= (*mb_head_off)(l, lp);
743 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100744 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100745 }
746 else
747 // change last character to '>'
748 *lp = '>';
749 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100750 else if (after > 0)
751 {
752 vim_memset(l + off, ' ', after);
753 l[off + after] = NUL;
754 }
755
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100756 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100757 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100758 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100759 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100760 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100761
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000762 // n_attr_skip will not be decremented before draw_state is
763 // WL_LINE
764 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100765 }
766 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100767 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100768
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100769 if (n_attr == NULL)
770 return cells;
771 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772}
773#endif
774
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100775/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100776 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100777 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
778 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100779 */
780 static void
781wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
782{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100783 if (wlv->row == 0 && wp->w_skipcol > 0
784#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100785 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100786 && *get_showbreak_value(wp) == NUL
787#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100788 // do not overwrite the 'listchars' "precedes" text with "<<<"
789 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100790 {
791 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100792 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100793
Bram Moolenaareb4de622022-10-15 13:42:17 +0100794 if (wp->w_p_nu && wp->w_p_rnu)
795 // Do not overwrite the line number, change "123 text" to
796 // "123>>>xt".
797 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
798 {
799 ++off;
800 ++skip;
801 }
802
803 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100804 {
805 ScreenLines[off] = '<';
806 if (enc_utf8)
807 ScreenLinesUC[off] = 0;
808 ScreenAttrs[off] = HL_ATTR(HLF_AT);
809 ++off;
810 }
811 }
812
813 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
814 negative_width ? -wp->w_width : wp->w_width,
815 wlv->screen_line_flags);
816}
817
818/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100819 * Called when finished with the line: draw the screen line and handle any
820 * highlighting until the right of the window.
821 */
822 static void
823draw_screen_line(win_T *wp, winlinevars_T *wlv)
824{
825#ifdef FEAT_SYN_HL
826 long v;
827
828 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
829 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100830 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831 else
832 v = wp->w_leftcol;
833
834 // check if line ends before left margin
835 if (wlv->vcol < v + wlv->col - win_col_off(wp))
836 wlv->vcol = v + wlv->col - win_col_off(wp);
837# ifdef FEAT_CONCEAL
838 // Get rid of the boguscols now, we want to draw until the right
839 // edge for 'cursorcolumn'.
840 wlv->col -= wlv->boguscols;
841 wlv->boguscols = 0;
842# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
843# else
844# define VCOL_HLC (wlv->vcol)
845# endif
846
847 if (wlv->draw_color_col)
848 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
849
850 if (((wp->w_p_cuc
851 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
852 && (int)wp->w_virtcol <
853 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
854 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000855 || wlv->draw_color_col
856# ifdef LINE_ATTR
857 || wlv->line_attr != 0
858# endif
859 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100860# ifdef FEAT_RIGHTLEFT
861 && !wp->w_p_rl
862# endif
863 )
864 {
865 int rightmost_vcol = 0;
866 int i;
867
868 if (wp->w_p_cuc)
869 rightmost_vcol = wp->w_virtcol;
870 if (wlv->draw_color_col)
871 // determine rightmost colorcolumn to possibly draw
872 for (i = 0; wlv->color_cols[i] >= 0; ++i)
873 if (rightmost_vcol < wlv->color_cols[i])
874 rightmost_vcol = wlv->color_cols[i];
875
876 while (wlv->col < wp->w_width)
877 {
878 ScreenLines[wlv->off] = ' ';
879 if (enc_utf8)
880 ScreenLinesUC[wlv->off] = 0;
881 ScreenCols[wlv->off] = MAXCOL;
882 ++wlv->col;
883 if (wlv->draw_color_col)
884 wlv->draw_color_col = advance_color_col(
885 VCOL_HLC, &wlv->color_cols);
886
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000887 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100888 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000889 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000891 attr = HL_ATTR(HLF_MC);
892# ifdef LINE_ATTR
893 else if (wlv->line_attr != 0)
894 attr = wlv->line_attr;
895# endif
896 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100897
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000898 if (VCOL_HLC >= rightmost_vcol
899# ifdef LINE_ATTR
900 && wlv->line_attr == 0
901# endif
902 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100903 break;
904
905 ++wlv->vcol;
906 }
907 }
908#endif
909
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100910 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911 ++wlv->row;
912 ++wlv->screen_row;
913}
914#undef VCOL_HLC
915
916/*
917 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100918 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100919 */
920 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100921win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100922{
923 wlv->col = 0;
924 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
925
926#ifdef FEAT_RIGHTLEFT
927 if (wp->w_p_rl)
928 {
929 // Rightleft window: process the text in the normal direction, but put
930 // it in current_ScreenLine[] from right to left. Start at the
931 // rightmost column of the window.
932 wlv->col = wp->w_width - 1;
933 wlv->off += wlv->col;
934 wlv->screen_line_flags |= SLF_RIGHTLEFT;
935 }
936#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100937 if (save_extra)
938 {
939 // reset the drawing state for the start of a wrapped line
940 wlv->draw_state = WL_START;
941 wlv->saved_n_extra = wlv->n_extra;
942 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000943 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000944 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000945 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100946 wlv->saved_c_extra = wlv->c_extra;
947 wlv->saved_c_final = wlv->c_final;
948#ifdef FEAT_SYN_HL
949 if (!(wlv->cul_screenline
950# ifdef FEAT_DIFF
951 && wlv->diff_hlf == (hlf_T)0
952# endif
953 ))
954 wlv->saved_char_attr = wlv->char_attr;
955 else
956#endif
957 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000958
959 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100960 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000961 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100962 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100963}
964
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200965/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100966 * Called when wlv->draw_state is set to WL_LINE.
967 */
968 static void
969win_line_continue(winlinevars_T *wlv)
970{
971 if (wlv->saved_n_extra > 0)
972 {
973 // Continue item from end of wrapped line.
974 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +0000975 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100976 wlv->c_extra = wlv->saved_c_extra;
977 wlv->c_final = wlv->saved_c_final;
978 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000979 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000980 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000981 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100982 wlv->char_attr = wlv->saved_char_attr;
983 }
984 else
985 wlv->char_attr = wlv->win_attr;
986}
987
988/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200989 * Display line "lnum" of window 'wp' on the screen.
990 * Start at row "startrow", stop when "endrow" is reached.
991 * wp->w_virtcol needs to be valid.
992 *
993 * Return the number of last row the line occupies.
994 */
995 int
996win_line(
997 win_T *wp,
998 linenr_T lnum,
999 int startrow,
1000 int endrow,
1001 int nochange UNUSED, // not updating for changed text
1002 int number_only) // only update the number column
1003{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001004 winlinevars_T wlv; // variables passed between functions
1005
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001006 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001007 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008 char_u *line; // current line
1009 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010
Bram Moolenaar1306b362022-08-06 15:59:06 +01001011#ifdef FEAT_PROP_POPUP
1012 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1013#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001014#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001015 int in_linebreak = FALSE; // n_extra set for showing linebreak
1016#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001018 // displaying eol at end-of-line
1019 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001020 int lcs_prec_todo = wp->w_lcs_chars.prec;
1021 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001023 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001024 int saved_attr2 = 0; // char_attr saved for n_attr
1025 int n_attr3 = 0; // chars with overruling special attr
1026 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027
Bram Moolenaarcd105412022-10-10 19:50:42 +01001028 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1029 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001030#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001031 int skip_cells = 0; // nr of cells to skip for virtual text
1032 // after the line, when w_skipcol is
1033 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001034#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036 int fromcol_prev = -2; // start of inverting after cursor
1037 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 int lnum_in_visual_area = FALSE;
1039 pos_T pos;
1040 long v;
1041
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042 int attr_pri = FALSE; // char_attr has priority
1043 int area_highlighting = FALSE; // Visual or incsearch highlighting
1044 // in this line
1045 int vi_attr = 0; // attributes for Visual and incsearch
1046 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047 int area_attr = 0; // attributes desired by highlighting
1048 int search_attr = 0; // attributes desired by 'hlsearch'
1049#ifdef FEAT_SYN_HL
1050 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1051 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001052 int prev_syntax_col = -1; // column of prev_syntax_attr
1053 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054 int has_syntax = FALSE; // this buffer has syntax highl.
1055 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001057#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 int text_prop_count;
1059 int text_prop_next = 0; // next text property to use
1060 textprop_T *text_props = NULL;
1061 int *text_prop_idxs = NULL;
1062 int text_props_active = 0;
1063 proptype_T *text_prop_type = NULL;
1064 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001065 int text_prop_attr_comb = 0; // text_prop_attr combined with
1066 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001067 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001068 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001069 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001070 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001071 int saved_search_attr = 0; // search_attr to be used when n_extra
1072 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001073 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001074 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075#endif
1076#ifdef FEAT_SPELL
1077 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001078 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079# define SPWORDLEN 150
1080 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1081 int nextlinecol = 0; // column where nextline[] starts
1082 int nextline_idx = 0; // index in nextline[] where next line
1083 // starts
1084 int spell_attr = 0; // attributes desired by spelling
1085 int word_end = 0; // last byte with same spell_attr
1086 static linenr_T checked_lnum = 0; // line number for "checked_col"
1087 static int checked_col = 0; // column in "checked_lnum" up to which
1088 // there are no spell errors
1089 static int cap_col = -1; // column to check for Cap word
1090 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1091 int cur_checked_col = 0; // checked column for current line
1092#endif
1093 int extra_check = 0; // has extra highlighting
1094 int multi_attr = 0; // attributes desired by multibyte
1095 int mb_l = 1; // multi-byte byte length
1096 int mb_c = 0; // decoded multi-byte character
1097 int mb_utf8 = FALSE; // screen char is UTF-8 char
1098 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001100 int change_start = MAXCOL; // first col of changed area
1101 int change_end = -1; // last col of changed area
1102#endif
1103 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001104 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001105 int in_multispace = FALSE; // in multiple consecutive spaces
1106 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001107#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001108 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001111 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001112#ifdef FEAT_ARABIC
1113 int prev_c = 0; // previous Arabic character
1114 int prev_c1 = 0; // first composing char for prev_c
1115#endif
1116#if defined(LINE_ATTR)
1117 int did_line_attr = 0;
1118#endif
1119#ifdef FEAT_TERMINAL
1120 int get_term_attr = FALSE;
1121#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122
Martin Tournoijba43e762022-10-13 22:12:15 +01001123#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 // margin columns for the screen line, needed for when 'cursorlineopt'
1125 // contains "screenline"
1126 int left_curline_col = 0;
1127 int right_curline_col = 0;
1128#endif
1129
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1131 int feedback_col = 0;
1132 int feedback_old_attr = -1;
1133#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001134
1135#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1136 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001137#endif
1138#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001139 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140#endif
1141#ifdef FEAT_CONCEAL
1142 int syntax_flags = 0;
1143 int syntax_seqnr = 0;
1144 int prev_syntax_id = 0;
1145 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1146 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001147 int did_wcol = FALSE;
1148 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001149# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001150# define FIX_FOR_BOGUSCOLS \
1151 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001152 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001153 wlv.vcol -= wlv.vcol_off; \
1154 wlv.vcol_off = 0; \
1155 wlv.col -= wlv.boguscols; \
1156 old_boguscols = wlv.boguscols; \
1157 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158 }
1159#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001160# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161#endif
1162
1163 if (startrow > endrow) // past the end already!
1164 return startrow;
1165
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001166 CLEAR_FIELD(wlv);
1167
1168 wlv.lnum = lnum;
1169 wlv.startrow = startrow;
1170 wlv.row = startrow;
1171 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001172 wlv.fromcol = -10;
1173 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001174#ifdef FEAT_LINEBREAK
1175 wlv.vcol_sbr = -1;
1176#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177
1178 if (!number_only)
1179 {
1180 // To speed up the loop below, set extra_check when there is linebreak,
1181 // trailing white space and/or syntax processing to be done.
1182#ifdef FEAT_LINEBREAK
1183 extra_check = wp->w_p_lbr;
1184#endif
1185#ifdef FEAT_SYN_HL
1186 if (syntax_present(wp) && !wp->w_s->b_syn_error
1187# ifdef SYN_TIME_LIMIT
1188 && !wp->w_s->b_syn_slow
1189# endif
1190 )
1191 {
1192 // Prepare for syntax highlighting in this line. When there is an
1193 // error, stop syntax highlighting.
1194 save_did_emsg = did_emsg;
1195 did_emsg = FALSE;
1196 syntax_start(wp, lnum);
1197 if (did_emsg)
1198 wp->w_s->b_syn_error = TRUE;
1199 else
1200 {
1201 did_emsg = save_did_emsg;
1202#ifdef SYN_TIME_LIMIT
1203 if (!wp->w_s->b_syn_slow)
1204#endif
1205 {
1206 has_syntax = TRUE;
1207 extra_check = TRUE;
1208 }
1209 }
1210 }
1211
1212 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001213 wlv.color_cols = wp->w_p_cc_cols;
1214 if (wlv.color_cols != NULL)
1215 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216#endif
1217
1218#ifdef FEAT_TERMINAL
1219 if (term_show_buffer(wp->w_buffer))
1220 {
1221 extra_check = TRUE;
1222 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001223 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 }
1225#endif
1226
1227#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001228 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229 {
1230 // Prepare for spell checking.
1231 has_spell = TRUE;
1232 extra_check = TRUE;
1233
1234 // Get the start of the next line, so that words that wrap to the
1235 // next line are found too: "et<line-break>al.".
1236 // Trick: skip a few chars for C/shell/Vim comments
1237 nextline[SPWORDLEN] = NUL;
1238 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1239 {
1240 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1241 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1242 }
1243
1244 // When a word wrapped from the previous line the start of the
1245 // current line is valid.
1246 if (lnum == checked_lnum)
1247 cur_checked_col = checked_col;
1248 checked_lnum = 0;
1249
1250 // When there was a sentence end in the previous line may require a
1251 // word starting with capital in this line. In line 1 always check
1252 // the first word.
1253 if (lnum != capcol_lnum)
1254 cap_col = -1;
1255 if (lnum == 1)
1256 cap_col = 0;
1257 capcol_lnum = 0;
1258 }
1259#endif
1260
1261 // handle Visual active in this window
1262 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1263 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001264 pos_T *top, *bot;
1265
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001266 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1267 {
1268 // Visual is after curwin->w_cursor
1269 top = &curwin->w_cursor;
1270 bot = &VIsual;
1271 }
1272 else
1273 {
1274 // Visual is before curwin->w_cursor
1275 top = &VIsual;
1276 bot = &curwin->w_cursor;
1277 }
1278 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1279 if (VIsual_mode == Ctrl_V)
1280 {
1281 // block mode
1282 if (lnum_in_visual_area)
1283 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001284 wlv.fromcol = wp->w_old_cursor_fcol;
1285 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 }
1287 }
1288 else
1289 {
1290 // non-block mode
1291 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001292 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 else if (lnum == top->lnum)
1294 {
1295 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 else
1298 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001299 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001301 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 }
1303 }
1304 if (VIsual_mode != 'V' && lnum == bot->lnum)
1305 {
1306 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1307 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001308 wlv.fromcol = -10;
1309 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 }
1311 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001312 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 else
1314 {
1315 pos = *bot;
1316 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001317 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1318 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 else
1320 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001321 getvvcol(wp, &pos, NULL, NULL,
1322 (colnr_T *)&wlv.tocol);
1323 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 }
1325 }
1326 }
1327 }
1328
1329 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001330 if (!highlight_match && lnum == curwin->w_cursor.lnum
1331 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332#ifdef FEAT_GUI
1333 && !gui.in_use
1334#endif
1335 )
1336 noinvcur = TRUE;
1337
1338 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 {
1341 area_highlighting = TRUE;
1342 vi_attr = HL_ATTR(HLF_V);
1343#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1344 if ((clip_star.available && !clip_star.owned
1345 && clip_isautosel_star())
1346 || (clip_plus.available && !clip_plus.owned
1347 && clip_isautosel_plus()))
1348 vi_attr = HL_ATTR(HLF_VNC);
1349#endif
1350 }
1351 }
1352
1353 // handle 'incsearch' and ":s///c" highlighting
1354 else if (highlight_match
1355 && wp == curwin
1356 && lnum >= curwin->w_cursor.lnum
1357 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1358 {
1359 if (lnum == curwin->w_cursor.lnum)
1360 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001361 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001363 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1365 {
1366 pos.lnum = lnum;
1367 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001368 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001371 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001373 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1374 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001375 area_highlighting = TRUE;
1376 vi_attr = HL_ATTR(HLF_I);
1377 }
1378 }
1379
1380#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001381 wlv.filler_lines = diff_check(wp, lnum);
1382 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001384 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 {
1386 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001387 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001389 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001391 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 }
1393 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001394 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001395 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001396 area_highlighting = TRUE;
1397 }
1398 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001399 wlv.filler_lines = wp->w_topfill;
1400 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401#endif
1402
1403#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001404 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001405 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001406 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001407#endif
1408
1409#ifdef LINE_ATTR
1410# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001411 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001413 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414# endif
1415# if defined(FEAT_QUICKFIX)
1416 // Highlight the current line in the quickfix window.
1417 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001418 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001420 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 area_highlighting = TRUE;
1422#endif
1423
1424 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1425 ptr = line;
1426
1427#ifdef FEAT_SPELL
1428 if (has_spell && !number_only)
1429 {
1430 // For checking first word with a capital skip white space.
1431 if (cap_col == 0)
1432 cap_col = getwhitecols(line);
1433
1434 // To be able to spell-check over line boundaries copy the end of the
1435 // current line into nextline[]. Above the start of the next line was
1436 // copied to nextline[SPWORDLEN].
1437 if (nextline[SPWORDLEN] == NUL)
1438 {
1439 // No next line or it is empty.
1440 nextlinecol = MAXCOL;
1441 nextline_idx = 0;
1442 }
1443 else
1444 {
1445 v = (long)STRLEN(line);
1446 if (v < SPWORDLEN)
1447 {
1448 // Short line, use it completely and append the start of the
1449 // next line.
1450 nextlinecol = 0;
1451 mch_memmove(nextline, line, (size_t)v);
1452 STRMOVE(nextline + v, nextline + SPWORDLEN);
1453 nextline_idx = v + 1;
1454 }
1455 else
1456 {
1457 // Long line, use only the last SPWORDLEN bytes.
1458 nextlinecol = v - SPWORDLEN;
1459 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1460 nextline_idx = SPWORDLEN + 1;
1461 }
1462 }
1463 }
1464#endif
1465
1466 if (wp->w_p_list)
1467 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001468 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001469 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001470 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001471 || wp->w_lcs_chars.trail
1472 || wp->w_lcs_chars.lead
1473 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001475
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001477 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
1479 trailcol = (colnr_T)STRLEN(ptr);
1480 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1481 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001482 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001484 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001485 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001486 {
1487 leadcol = 0;
1488 while (VIM_ISWHITE(ptr[leadcol]))
1489 ++leadcol;
1490 if (ptr[leadcol] == NUL)
1491 // in a line full of spaces all of them are treated as trailing
1492 leadcol = (colnr_T)0;
1493 else
1494 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001495 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001496 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 }
1498
Bram Moolenaard7657e92022-09-20 18:59:30 +01001499 wlv.wcr_attr = get_wcr_attr(wp);
1500 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001502 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503 area_highlighting = TRUE;
1504 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001505
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001506 // When w_skipcol is non-zero and there is virtual text above the actual
1507 // text, then this much of the virtual text is skipped.
1508 int skipcol_in_text_prop_above = 0;
1509
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001510#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001512 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001513
1514 char_u *prop_start;
1515 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1516 if (text_prop_count > 0)
1517 {
1518 // Make a copy of the properties, so that they are properly
1519 // aligned.
1520 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1521 if (text_props != NULL)
1522 mch_memmove(text_props, prop_start,
1523 text_prop_count * sizeof(textprop_T));
1524
1525 // Allocate an array for the indexes.
1526 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1527 if (text_prop_idxs == NULL)
1528 VIM_CLEAR(text_props);
1529
1530 if (text_props != NULL)
1531 {
1532 area_highlighting = TRUE;
1533 extra_check = TRUE;
1534
1535 // When skipping virtual text the props need to be sorted. The
1536 // order is reversed!
1537 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1538 {
1539 for (int i = 0; i < text_prop_count; ++i)
1540 text_prop_idxs[i] = i;
1541 sort_text_props(wp->w_buffer, text_props,
1542 text_prop_idxs, text_prop_count);
1543 }
1544
1545 // Text props "above" move the line number down to where the text
1546 // is. Only count the ones that are visible, not those that are
1547 // skipped because of w_skipcol.
1548 int text_width = wp->w_width - win_col_off(wp);
1549 for (int i = text_prop_count - 1; i >= 0; --i)
1550 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1551 {
1552 if (lnum == wp->w_topline
1553 && wp->w_skipcol - skipcol_in_text_prop_above
1554 >= text_width)
1555 {
1556 // This virtual text above is skipped, remove it from
1557 // the array.
1558 skipcol_in_text_prop_above += text_width;
1559 for (int j = i + 1; j < text_prop_count; ++j)
1560 text_props[j - 1] = text_props[j];
1561 ++i;
1562 --text_prop_count;
1563 }
1564 else
1565 ++wlv.text_prop_above_count;
1566 }
1567 }
1568 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569#endif
1570
1571 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1572 // first character to be displayed.
1573 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001574 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 else
1576 v = wp->w_leftcol;
1577 if (v > 0 && !number_only)
1578 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001579 char_u *prev_ptr = ptr;
1580 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001581 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001583 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001584 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001585 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001586 charsize = win_lbr_chartabsize(&cts, NULL);
1587 cts.cts_vcol += charsize;
1588 prev_ptr = cts.cts_ptr;
1589 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001590 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001591 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001592 ptr = cts.cts_ptr;
1593 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594
1595 // When:
1596 // - 'cuc' is set, or
1597 // - 'colorcolumn' is set, or
1598 // - 'virtualedit' is set, or
1599 // - the visual mode is active,
1600 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001601 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001602#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001603 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001604#endif
1605 virtual_active() ||
1606 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001607 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001608
1609 // Handle a character that's not completely on the screen: Put ptr at
1610 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001611 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001613 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 ptr = prev_ptr;
1615 // If the character fits on the screen, don't need to skip it.
1616 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001617 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1618 && wlv.col == 0)
1619 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 }
1621
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001622#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001623 // If there the text doesn't reach to the desired column, need to skip
1624 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001625 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1626 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001627 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001628#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001629
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 // Adjust for when the inverted text is before the screen,
1631 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001632 if (wlv.tocol <= wlv.vcol)
1633 wlv.fromcol = 0;
1634 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1635 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636
1637#ifdef FEAT_LINEBREAK
1638 // When w_skipcol is non-zero, first line needs 'showbreak'
1639 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001640 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641#endif
1642#ifdef FEAT_SPELL
1643 // When spell checking a word we need to figure out the start of the
1644 // word and if it's badly spelled or not.
1645 if (has_spell)
1646 {
1647 int len;
1648 colnr_T linecol = (colnr_T)(ptr - line);
1649 hlf_T spell_hlf = HLF_COUNT;
1650
1651 pos = wp->w_cursor;
1652 wp->w_cursor.lnum = lnum;
1653 wp->w_cursor.col = linecol;
1654 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1655
1656 // spell_move_to() may call ml_get() and make "line" invalid
1657 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1658 ptr = line + linecol;
1659
1660 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1661 {
1662 // no bad word found at line start, don't check until end of a
1663 // word
1664 spell_hlf = HLF_COUNT;
1665 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1666 }
1667 else
1668 {
1669 // bad word found, use attributes until end of word
1670 word_end = wp->w_cursor.col + len + 1;
1671
1672 // Turn index into actual attributes.
1673 if (spell_hlf != HLF_COUNT)
1674 spell_attr = highlight_attr[spell_hlf];
1675 }
1676 wp->w_cursor = pos;
1677
1678# ifdef FEAT_SYN_HL
1679 // Need to restart syntax highlighting for this line.
1680 if (has_syntax)
1681 syntax_start(wp, lnum);
1682# endif
1683 }
1684#endif
1685 }
1686
1687 // Correct highlighting for cursor that can't be disabled.
1688 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001689 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 {
1691 if (noinvcur)
1692 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001693 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 {
1695 // highlighting starts at cursor, let it start just after the
1696 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001697 fromcol_prev = wlv.fromcol;
1698 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001700 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 // restart highlighting after the cursor
1702 fromcol_prev = wp->w_virtcol;
1703 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001704 if (wlv.fromcol >= wlv.tocol)
1705 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001706 }
1707
1708#ifdef FEAT_SEARCH_EXTRA
1709 if (!number_only)
1710 {
1711 v = (long)(ptr - line);
1712 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1713 &line, &screen_search_hl,
1714 &search_attr);
1715 ptr = line + v; // "line" may have been updated
1716 }
1717#endif
1718
1719#ifdef FEAT_SYN_HL
1720 // Cursor line highlighting for 'cursorline' in the current window.
1721 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1722 {
1723 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001724 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 if (!(wp == curwin && VIsual_active)
1726 && wp->w_p_culopt_flags != CULOPT_NBR)
1727 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001728 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1730
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001731 // Only set wlv.line_attr here when "screenline" is not present in
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001733 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001735 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001736# ifdef FEAT_SIGNS
1737 // Combine the 'cursorline' and sign highlighting, depending on
1738 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001739 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001740 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001741 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001742 wlv.line_attr = hl_combine_attr(
1743 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001744 else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001745 wlv.line_attr = hl_combine_attr(
1746 wlv.line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001747 }
1748 else
1749# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001750# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001751 // let the line attribute overrule 'cursorline', otherwise
1752 // it disappears when both have background set;
1753 // 'cursorline' can use underline or bold to make it show
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001754 wlv.line_attr = hl_combine_attr(
1755 wlv.cul_attr, wlv.line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001756# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001757 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001758# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 }
1760 else
1761 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001762 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1764 }
1765 area_highlighting = TRUE;
1766 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 }
1768#endif
1769
Bram Moolenaar1306b362022-08-06 15:59:06 +01001770 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771
1772 // Repeat for the whole displayed line.
1773 for (;;)
1774 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001775 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001777 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778#endif
1779#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001780 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001782
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001786#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001787 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001788 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001789 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001790 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001791 }
1792#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001793 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001795 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 if (cmdwin_type != 0 && wp == curwin)
1797 {
1798 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 wlv.n_extra = 1;
1800 wlv.c_extra = cmdwin_type;
1801 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001802 wlv.char_attr =
1803 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001804 }
1805 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001806#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001807 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001809 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001810 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 }
1812#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001814 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001816 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001817 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001819 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 }
1821#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001824 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001826 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001827 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001829 // Check if 'breakindent' applies and show it.
1830 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1831 if (wlv.n_extra == 0)
1832 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001837 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001838 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839 }
1840#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001844 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 }
1846 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001847
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001849 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001850 && wlv.vcol >= left_curline_col
1851 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001853 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001854 wlv.line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 }
1856#endif
1857
1858 // When still displaying '$' of change command, stop at cursor.
1859 // When only displaying the (relative) line number and that's done,
1860 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001861 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001862 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001863 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001865 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866#endif
1867 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001869 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870 // Pretend we have finished updating the window. Except when
1871 // 'cursorcolumn' is set.
1872#ifdef FEAT_SYN_HL
1873 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001874 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 else
1876#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001877 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 break;
1879 }
1880
Bram Moolenaar1306b362022-08-06 15:59:06 +01001881 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 {
1883 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001884 if (wlv.vcol == wlv.fromcol
1885 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1886 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 && (*mb_ptr2cells)(ptr) > 1)
1888 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001889 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001890 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 area_attr = vi_attr; // start highlighting
1892 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001893 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001894 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 area_attr = 0; // stop highlighting
1896
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001897#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 if (text_props != NULL)
1899 {
1900 int pi;
1901 int bcol = (int)(ptr - line);
1902
Bram Moolenaar1306b362022-08-06 15:59:06 +01001903 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001904# ifdef FEAT_LINEBREAK
1905 && !in_linebreak
1906# endif
1907 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908 --bcol; // still working on the previous char, e.g. Tab
1909
1910 // Check if any active property ends.
1911 for (pi = 0; pi < text_props_active; ++pi)
1912 {
1913 int tpi = text_prop_idxs[pi];
1914
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001915 if (text_props[tpi].tp_col != MAXCOL
1916 && bcol >= text_props[tpi].tp_col - 1
1917 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 {
1919 if (pi + 1 < text_props_active)
1920 mch_memmove(text_prop_idxs + pi,
1921 text_prop_idxs + pi + 1,
1922 sizeof(int)
1923 * (text_props_active - (pi + 1)));
1924 --text_props_active;
1925 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001926# ifdef FEAT_LINEBREAK
1927 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001928 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001929 syntax_attr = 0;
1930# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 }
1932 }
1933
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001934# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001935 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001936 // not on the next char yet, don't start another prop
1937 --bcol;
1938# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001940 // With 'nowrap' and not in the first screen line only "below"
1941 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001943 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001944 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001945 && (wp->w_p_wrap
1946 || wlv.row == startrow
1947 || (text_props[text_prop_next].tp_flags
1948 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001949 || (bcol == 0 &&
1950 (text_props[text_prop_next].tp_flags
1951 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001952 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001953 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001954 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001955 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1956 {
1957 // first display the '$' after the line
1958 text_prop_follows = TRUE;
1959 break;
1960 }
1961 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001962 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001963 + text_props[text_prop_next].tp_len)
1964 text_prop_idxs[text_props_active++] = text_prop_next;
1965 ++text_prop_next;
1966 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001967
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001968 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001969 {
1970 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001971 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001972 text_prop_flags = 0;
1973 text_prop_type = NULL;
1974 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001975 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001976 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001977 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001978 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001979 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001980 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001981 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001982
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001983 // Sort the properties on priority and/or starting last.
1984 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001985 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001986 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001987 sort_text_props(wp->w_buffer, text_props,
1988 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989
1990 for (pi = 0; pi < text_props_active; ++pi)
1991 {
1992 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001993 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001995 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996
Bram Moolenaarcd105412022-10-10 19:50:42 +01001997 // Only use a text property that can be displayed.
1998 // Skip "after" properties when wrap is off and at the
1999 // end of the window.
2000 if (pt != NULL
2001 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2002 && tp->tp_id != -MAXCOL
2003 && !(tp->tp_id < 0
2004 && !wp->w_p_wrap
2005 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2006 | TP_FLAG_ALIGN_ABOVE
2007 | TP_FLAG_ALIGN_BELOW)) == 0
2008 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002010 if (pt->pt_hl_id > 0)
2011 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 text_prop_type = pt;
2013 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002014 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002015 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002016 text_prop_flags = pt->pt_flags;
2017 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002018 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 }
2020 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002021 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002022 && -text_prop_id
2023 <= wp->w_buffer->b_textprop_text.ga_len)
2024 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002025 textprop_T *tp = &text_props[used_tpi];
2026 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002027 ->b_textprop_text.ga_data)[
2028 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002029 int above = (tp->tp_flags
2030 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002031 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032
2033 // reset the ID in the copy to avoid it being used
2034 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002035 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002036
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002037 if (p != NULL)
2038 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002041 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002042 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002043 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2044 int padding = tp->tp_col == MAXCOL
2045 && tp->tp_len > 1
2046 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002047
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002048 // Insert virtual text before the current
2049 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 wlv.p_extra = p;
2051 wlv.c_extra = NUL;
2052 wlv.c_final = NUL;
2053 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002054 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002055 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2056 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002057 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002058 // restore search_attr and area_attr when n_extra
2059 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002060 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002061 saved_area_attr = area_attr;
2062 search_attr = 0;
2063 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002064 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002065 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002066 if (*ptr == NUL)
2067 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002068 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002069#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002070 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002071 {
2072 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002073 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002074 wlv.need_showbreak = FALSE;
2075 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002076 }
2077#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002078 if ((right || above || below || !wrap
2079 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002080 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002081 char_u *prev_p_extra = wlv.p_extra;
2082 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002083
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002084 // Take care of padding, right-align and
2085 // truncation.
2086 // Shared with win_lbr_chartabsize(), must do
2087 // exactly the same.
2088 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002089 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002090 wlv.col,
2091 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002092 &n_attr, &wlv.n_attr_skip,
2093 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002094 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002095 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002096 // wlv.p_extra was allocated
2097 vim_free(p_extra_free2);
2098 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002099 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002100
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002101 if (lcs_eol_one < 0
2102 && wp->w_p_wrap
2103 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002104 + wlv.n_extra - 2 > wp->w_width)
2105 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002106 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002107
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002108 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002109 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002110 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002111 {
2112 draw_screen_line(wp, &wlv);
2113
2114 // When line got too long for screen break
2115 // here.
2116 if (wlv.row == endrow)
2117 {
2118 ++wlv.row;
2119 break;
2120 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002121 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002122 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002123 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002124 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002125 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002126
Bram Moolenaarcd105412022-10-10 19:50:42 +01002127 // If the text didn't reach until the first window
2128 // column we need to skip cells.
2129 if (skip_cells > 0)
2130 {
2131 if (wlv.n_extra > skip_cells)
2132 {
2133 wlv.n_extra -= skip_cells;
2134 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002135 wlv.n_attr_skip -= skip_cells;
2136 if (wlv.n_attr_skip < 0)
2137 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002138 skip_cells = 0;
2139 }
2140 else
2141 {
2142 // the whole text is left of the window, drop
2143 // it and advance to the next one
2144 skip_cells -= wlv.n_extra;
2145 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002146 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002147 bail_out = TRUE;
2148 }
2149 }
2150
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151 // If another text prop follows the condition below at
2152 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002153 // If this is an "above" text prop and 'nowrap' the we
2154 // must wrap anyway.
2155 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002156 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002157 && (wp->w_p_wrap
2158 || (text_props[other_tpi].tp_flags
2159 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002160
2161 if (bail_out)
2162 // starting a new line for "below"
2163 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002164 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002165 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002166 else if (text_prop_next < text_prop_count
2167 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002168 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2169 || (!wp->w_p_wrap
2170 && wlv.col == wp->w_width - 1
2171 && (text_props[text_prop_next].tp_flags
2172 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002173 // When at last-but-one character and a text property
2174 // follows after it, we may need to flush the line after
2175 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002176 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002177 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002178 }
2179#endif
2180
Bram Moolenaare38fc862022-08-11 17:24:50 +01002181#ifdef FEAT_SEARCH_EXTRA
2182 if (wlv.n_extra == 0)
2183 {
2184 // Check for start/end of 'hlsearch' and other matches.
2185 // After end, check for start/end of next match.
2186 // When another match, have to check for start again.
2187 v = (long)(ptr - line);
2188 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2189 &screen_search_hl, &has_match_conc,
2190 &match_conc, did_line_attr, lcs_eol_one,
2191 &on_last_col);
2192 ptr = line + v; // "line" may have been changed
2193 prev_ptr = ptr;
2194
2195 // Do not allow a conceal over EOL otherwise EOL will be missed
2196 // and bad things happen.
2197 if (*ptr == NUL)
2198 has_match_conc = 0;
2199 }
2200#endif
2201
2202#ifdef FEAT_DIFF
2203 if (wlv.diff_hlf != (hlf_T)0)
2204 {
2205 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2206 && wlv.n_extra == 0)
2207 wlv.diff_hlf = HLF_TXD; // changed text
2208 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2209 && wlv.n_extra == 0)
2210 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002211 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002212 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2213 && wp->w_p_culopt_flags != CULOPT_NBR
2214 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2215 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002216 wlv.line_attr = hl_combine_attr(
2217 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002218 }
2219#endif
2220
Bram Moolenaara74fda62019-10-19 17:38:03 +02002221#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002222 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002223 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002224 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002225# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002226 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002227 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002228# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002229 // Get syntax attribute.
2230 if (has_syntax)
2231 {
2232 // Get the syntax attribute for the character. If there
2233 // is an error, disable syntax highlighting.
2234 save_did_emsg = did_emsg;
2235 did_emsg = FALSE;
2236
2237 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002238 if (v == prev_syntax_col)
2239 // at same column again
2240 syntax_attr = prev_syntax_attr;
2241 else
2242 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002243# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002244 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002245# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002246 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002247# ifdef FEAT_SPELL
2248 has_spell ? &can_spell :
2249# endif
2250 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002251 prev_syntax_col = v;
2252 prev_syntax_attr = syntax_attr;
2253 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002254
Bram Moolenaar34390282019-10-16 14:38:26 +02002255 if (did_emsg)
2256 {
2257 wp->w_s->b_syn_error = TRUE;
2258 has_syntax = FALSE;
2259 syntax_attr = 0;
2260 }
2261 else
2262 did_emsg = save_did_emsg;
2263# ifdef SYN_TIME_LIMIT
2264 if (wp->w_s->b_syn_slow)
2265 has_syntax = FALSE;
2266# endif
2267
2268 // Need to get the line again, a multi-line regexp may
2269 // have made it invalid.
2270 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2271 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002272 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002273# ifdef FEAT_CONCEAL
2274 // no concealing past the end of the line, it interferes
2275 // with line highlighting
2276 if (*ptr == NUL)
2277 syntax_flags = 0;
2278 else
2279 syntax_flags = get_syntax_info(&syntax_seqnr);
2280# endif
2281 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002282 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002283# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002284 // Combine text property highlight into syntax highlight.
2285 if (text_prop_type != NULL)
2286 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002287 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002288 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2289 else
2290 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002291 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002292 }
2293# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002294#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002295
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002296 // Decide which of the highlight attributes to use.
2297 attr_pri = TRUE;
2298#ifdef LINE_ATTR
2299 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002300 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002301 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002302 if (!highlight_match)
2303 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002304 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002305# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002306 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002307# endif
2308 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002309 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002310 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002311 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002312# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002313 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002314# endif
2315 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002316 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002317 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2318 || wlv.vcol < wlv.fromcol
2319 || vcol_prev < fromcol_prev
2320 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002322 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002323 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002324# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002325 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002326# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002327 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002328# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 attr_pri = FALSE;
2330 }
2331#else
2332 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002333 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002335 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002336#endif
2337 else
2338 {
2339 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002340#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002341 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002342#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002343 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002344#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002345 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002346#ifdef FEAT_PROP_POPUP
2347 // override with text property highlight when "override" is TRUE
2348 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002349 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002350#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002352
2353 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002354 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002355 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002356 if (wlv.char_attr == 0)
2357 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002358 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002359 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002360 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361
2362 // Get the next character to put on the screen.
2363
2364 // The "p_extra" points to the extra stuff that is inserted to
2365 // represent special characters (non-printable stuff) and other
2366 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002367 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2369 // "p_extra[n_extra]".
2370 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002372 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002373 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002374 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2376 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2378 if (enc_utf8 && utf_char2len(c) > 1)
2379 {
2380 mb_utf8 = TRUE;
2381 u8cc[0] = 0;
2382 c = 0xc0;
2383 }
2384 else
2385 mb_utf8 = FALSE;
2386 }
2387 else
2388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002389 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002390 if (has_mbyte)
2391 {
2392 mb_c = c;
2393 if (enc_utf8)
2394 {
2395 // If the UTF-8 character is more than one byte:
2396 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 mb_l = 1;
2401 else if (mb_l > 1)
2402 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002403 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 mb_utf8 = TRUE;
2405 c = 0xc0;
2406 }
2407 }
2408 else
2409 {
2410 // if this is a DBCS character, put it in "mb_c"
2411 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002413 mb_l = 1;
2414 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002416 }
2417 if (mb_l == 0) // at the NUL at end-of-line
2418 mb_l = 1;
2419
2420 // If a double-width char doesn't fit display a '>' in the
2421 // last column.
2422 if ((
2423# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002424 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002426 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002427 && (*mb_char2cells)(mb_c) == 2)
2428 {
2429 c = '>';
2430 mb_c = c;
2431 mb_l = 1;
2432 mb_utf8 = FALSE;
2433 multi_attr = HL_ATTR(HLF_AT);
2434#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002435 if (wlv.cul_attr)
2436 multi_attr = hl_combine_attr(
2437 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002439 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002440
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 // put the pointer back to output the double-width
2442 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 ++wlv.n_extra;
2444 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445 }
2446 else
2447 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 wlv.n_extra -= mb_l - 1;
2449 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450 }
2451 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002452 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002455#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002457 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002458 // Only restore search_attr and area_attr after "n_extra" in
2459 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002460 if (wlv.saved_n_extra <= 0)
2461 {
2462 if (search_attr == 0)
2463 search_attr = saved_search_attr;
2464 if (area_attr == 0 && *ptr != NUL)
2465 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002466
2467 if (wlv.extra_for_textprop)
2468 // wlv.extra_attr should be used at this position but
2469 // not any further.
2470 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002471 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002472
2473 wlv.extra_for_textprop = FALSE;
2474 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002475 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002476#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002477 }
2478 else
2479 {
2480#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002481 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002483 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 // Get a character from the line itself.
2486 c = *ptr;
2487#ifdef FEAT_LINEBREAK
2488 c0 = *ptr;
2489#endif
2490 if (has_mbyte)
2491 {
2492 mb_c = c;
2493 if (enc_utf8)
2494 {
2495 // If the UTF-8 character is more than one byte: Decode it
2496 // into "mb_c".
2497 mb_l = utfc_ptr2len(ptr);
2498 mb_utf8 = FALSE;
2499 if (mb_l > 1)
2500 {
2501 mb_c = utfc_ptr2char(ptr, u8cc);
2502 // Overlong encoded ASCII or ASCII with composing char
2503 // is displayed normally, except a NUL.
2504 if (mb_c < 0x80)
2505 {
2506 c = mb_c;
2507#ifdef FEAT_LINEBREAK
2508 c0 = mb_c;
2509#endif
2510 }
2511 mb_utf8 = TRUE;
2512
2513 // At start of the line we can have a composing char.
2514 // Draw it as a space with a composing char.
2515 if (utf_iscomposing(mb_c))
2516 {
2517 int i;
2518
2519 for (i = Screen_mco - 1; i > 0; --i)
2520 u8cc[i] = u8cc[i - 1];
2521 u8cc[0] = mb_c;
2522 mb_c = ' ';
2523 }
2524 }
2525
2526 if ((mb_l == 1 && c >= 0x80)
2527 || (mb_l >= 1 && mb_c == 0)
2528 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2529 {
2530 // Illegal UTF-8 byte: display as <xx>.
2531 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002532 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002533# ifdef FEAT_RIGHTLEFT
2534 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002535 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002537 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002538 c = *wlv.p_extra;
2539 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2542 wlv.c_extra = NUL;
2543 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544 if (area_attr == 0 && search_attr == 0)
2545 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002547 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002548 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 }
2551 }
2552 else if (mb_l == 0) // at the NUL at end-of-line
2553 mb_l = 1;
2554#ifdef FEAT_ARABIC
2555 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2556 {
2557 // Do Arabic shaping.
2558 int pc, pc1, nc;
2559 int pcc[MAX_MCO];
2560
2561 // The idea of what is the previous and next
2562 // character depends on 'rightleft'.
2563 if (wp->w_p_rl)
2564 {
2565 pc = prev_c;
2566 pc1 = prev_c1;
2567 nc = utf_ptr2char(ptr + mb_l);
2568 prev_c1 = u8cc[0];
2569 }
2570 else
2571 {
2572 pc = utfc_ptr2char(ptr + mb_l, pcc);
2573 nc = prev_c;
2574 pc1 = pcc[0];
2575 }
2576 prev_c = mb_c;
2577
2578 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2579 }
2580 else
2581 prev_c = mb_c;
2582#endif
2583 }
2584 else // enc_dbcs
2585 {
2586 mb_l = MB_BYTE2LEN(c);
2587 if (mb_l == 0) // at the NUL at end-of-line
2588 mb_l = 1;
2589 else if (mb_l > 1)
2590 {
2591 // We assume a second byte below 32 is illegal.
2592 // Hopefully this is OK for all double-byte encodings!
2593 if (ptr[1] >= 32)
2594 mb_c = (c << 8) + ptr[1];
2595 else
2596 {
2597 if (ptr[1] == NUL)
2598 {
2599 // head byte at end of line
2600 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002601 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 }
2603 else
2604 {
2605 // illegal tail byte
2606 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002607 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002609 wlv.p_extra = wlv.extra;
2610 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002611 wlv.c_extra = NUL;
2612 wlv.c_final = NUL;
2613 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 if (area_attr == 0 && search_attr == 0)
2615 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002616 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002617 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002618 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 // save current attr
2620 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 }
2622 mb_c = c;
2623 }
2624 }
2625 }
2626 // If a double-width char doesn't fit display a '>' in the
2627 // last column; the character is displayed at the start of the
2628 // next line.
2629 if ((
2630# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002633 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 && (*mb_char2cells)(mb_c) == 2)
2635 {
2636 c = '>';
2637 mb_c = c;
2638 mb_utf8 = FALSE;
2639 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002640 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 // Put pointer back so that the character will be
2642 // displayed at the start of the next line.
2643 --ptr;
2644#ifdef FEAT_CONCEAL
2645 did_decrement_ptr = TRUE;
2646#endif
2647 }
2648 else if (*ptr != NUL)
2649 ptr += mb_l - 1;
2650
2651 // If a double-width char doesn't fit at the left side display
2652 // a '<' in the first column. Don't do this for unprintable
2653 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002654 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 wlv.n_extra = 1;
2657 wlv.c_extra = MB_FILLER_CHAR;
2658 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002659 c = ' ';
2660 if (area_attr == 0 && search_attr == 0)
2661 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002662 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002663 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002664 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002665 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 }
2667 mb_c = c;
2668 mb_utf8 = FALSE;
2669 mb_l = 1;
2670 }
2671
2672 }
2673 ++ptr;
2674
2675 if (extra_check)
2676 {
2677#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 // Check spelling (unless at the end of the line).
2679 // Only do this when there is no syntax highlighting, the
2680 // @Spell cluster is not used or the current syntax item
2681 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002682 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 if (has_spell && v >= word_end && v > cur_checked_col)
2684 {
2685 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002686 // do not calculate cap_col at the end of the line or when
2687 // only white space is following
2688 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689# ifdef FEAT_SYN_HL
2690 !has_syntax ||
2691# endif
2692 can_spell))
2693 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002694 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 int len;
2696 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002697
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002698 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700
2701 // Use nextline[] if possible, it has the start of the
2702 // next line concatenated.
2703 if ((prev_ptr - line) - nextlinecol >= 0)
2704 p = nextline + (prev_ptr - line) - nextlinecol;
2705 else
2706 p = prev_ptr;
2707 cap_col -= (int)(prev_ptr - line);
2708 len = spell_check(wp, p, &spell_hlf, &cap_col,
2709 nochange);
2710 word_end = v + len;
2711
2712 // In Insert mode only highlight a word that
2713 // doesn't touch the cursor.
2714 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002715 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002716 && wp->w_cursor.lnum == lnum
2717 && wp->w_cursor.col >=
2718 (colnr_T)(prev_ptr - line)
2719 && wp->w_cursor.col < (colnr_T)word_end)
2720 {
2721 spell_hlf = HLF_COUNT;
2722 spell_redraw_lnum = lnum;
2723 }
2724
2725 if (spell_hlf == HLF_COUNT && p != prev_ptr
2726 && (p - nextline) + len > nextline_idx)
2727 {
2728 // Remember that the good word continues at the
2729 // start of the next line.
2730 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002731 checked_col = (int)((p - nextline)
2732 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 }
2734
2735 // Turn index into actual attributes.
2736 if (spell_hlf != HLF_COUNT)
2737 spell_attr = highlight_attr[spell_hlf];
2738
2739 if (cap_col > 0)
2740 {
2741 if (p != prev_ptr
2742 && (p - nextline) + cap_col >= nextline_idx)
2743 {
2744 // Remember that the word in the next line
2745 // must start with a capital.
2746 capcol_lnum = lnum + 1;
2747 cap_col = (int)((p - nextline) + cap_col
2748 - nextline_idx);
2749 }
2750 else
2751 // Compute the actual column.
2752 cap_col += (int)(prev_ptr - line);
2753 }
2754 }
2755 }
2756 if (spell_attr != 0)
2757 {
2758 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002759 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2760 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002761 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002762 wlv.char_attr = hl_combine_attr(spell_attr,
2763 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 }
2765#endif
2766#ifdef FEAT_LINEBREAK
2767 // Found last space before word: check for line break.
2768 if (wp->w_p_lbr && c0 == c
2769 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2770 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002771 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2772 : 0;
2773 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002774 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002776 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002777# ifdef FEAT_PROP_POPUP
2778 // do not want virtual text counted here
2779 cts.cts_has_prop_with_text = FALSE;
2780# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002781 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002782 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002783
2784 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002785 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002786 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002787 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002788 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2789 if (wlv.n_extra < 0)
2790 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002791 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002792 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002793 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002794 // line break, but for TABs the highlighting should
2795 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002796 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002797
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002799# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002801 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 wp->w_buffer->b_p_vts_array) - 1;
2803# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002804 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002805 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806# endif
2807
Bram Moolenaar1306b362022-08-06 15:59:06 +01002808 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2809 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002810# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002812 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002813# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 if (VIM_ISWHITE(c))
2815 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002816# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 if (c == TAB)
2818 // See "Tab alignment" below.
2819 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002820# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 if (!wp->w_p_list)
2822 c = ' ';
2823 }
2824 }
2825#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002826 in_multispace = c == ' '
2827 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2828 if (!in_multispace)
2829 multispace_pos = 0;
2830
Bram Moolenaareed9d462021-02-15 20:38:25 +01002831 // 'list': Change char 160 to 'nbsp' and space to 'space'
2832 // setting in 'listchars'. But not when the character is
2833 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 if (wp->w_p_list
2835 && ((((c == 160 && mb_l == 1)
2836 || (mb_utf8
2837 && ((mb_c == 160 && mb_l == 2)
2838 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002839 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 || (c == ' '
2841 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002842 && (wp->w_lcs_chars.space
2843 || (in_multispace
2844 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002845 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 && ptr - line <= trailcol)))
2847 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002848 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2849 {
2850 c = wp->w_lcs_chars.multispace[multispace_pos++];
2851 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2852 multispace_pos = 0;
2853 }
2854 else
2855 c = (c == ' ') ? wp->w_lcs_chars.space
2856 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 if (area_attr == 0 && search_attr == 0)
2858 {
2859 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002860 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863 }
2864 mb_c = c;
2865 if (enc_utf8 && utf_char2len(c) > 1)
2866 {
2867 mb_utf8 = TRUE;
2868 u8cc[0] = 0;
2869 c = 0xc0;
2870 }
2871 else
2872 mb_utf8 = FALSE;
2873 }
2874
zeertzjq2e7cba32022-06-10 15:30:32 +01002875 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2876 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002878 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2879 && wp->w_lcs_chars.leadmultispace != NULL)
2880 {
2881 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002882 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2883 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002884 multispace_pos = 0;
2885 }
2886
2887 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2888 c = wp->w_lcs_chars.trail;
2889
2890 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2891 c = wp->w_lcs_chars.lead;
2892
zeertzjq2e7cba32022-06-10 15:30:32 +01002893 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002894 c = wp->w_lcs_chars.space;
2895
2896
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 if (!attr_pri)
2898 {
2899 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002900 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002901 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002903 }
2904 mb_c = c;
2905 if (enc_utf8 && utf_char2len(c) > 1)
2906 {
2907 mb_utf8 = TRUE;
2908 u8cc[0] = 0;
2909 c = 0xc0;
2910 }
2911 else
2912 mb_utf8 = FALSE;
2913 }
2914 }
2915
2916 // Handling of non-printable characters.
2917 if (!vim_isprintc(c))
2918 {
2919 // when getting a character from the file, we may have to
2920 // turn it into something else on the way to putting it
2921 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002922 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002924 int tab_len = 0;
2925 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002926#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002927 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002928
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 // only adjust the tab_len, when at the first column
2930 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002931 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002932 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933#endif
2934 // tab amount depends on current column
2935#ifdef FEAT_VARTABS
2936 tab_len = tabstop_padding(vcol_adjusted,
2937 wp->w_buffer->b_p_ts,
2938 wp->w_buffer->b_p_vts_array) - 1;
2939#else
2940 tab_len = (int)wp->w_buffer->b_p_ts
2941 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2942#endif
2943
2944#ifdef FEAT_LINEBREAK
2945 if (!wp->w_p_lbr || !wp->w_p_list)
2946#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002947 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002948 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002950 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951#ifdef FEAT_LINEBREAK
2952 else
2953 {
2954 char_u *p;
2955 int len;
2956 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002959# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002960 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002962 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002963
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002965 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 && old_boguscols > 0
2967 && wlv.n_extra > tab_len)
2968 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002969# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002970 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002972 // If wlv.n_extra > 0, it gives the number of chars
2973 // to use for a tab, else we need to calculate the
2974 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002975 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2976 len = tab_len * tab2_len;
2977 if (wp->w_lcs_chars.tab3)
2978 len += mb_char2len(wp->w_lcs_chars.tab3)
2979 - tab2_len;
2980 if (wlv.n_extra > 0)
2981 len += wlv.n_extra - tab_len;
2982 c = wp->w_lcs_chars.tab1;
2983 p = alloc(len + 1);
2984 if (p == NULL)
2985 wlv.n_extra = 0;
2986 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002988 vim_memset(p, ' ', len);
2989 p[len] = NUL;
2990 vim_free(wlv.p_extra_free);
2991 wlv.p_extra_free = p;
2992 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002993 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002994 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002995
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002996 if (*p == NUL)
2997 {
2998 tab_len = i;
2999 break;
3000 }
3001
3002 // if tab3 is given, use it for the last
3003 // char
3004 if (wp->w_lcs_chars.tab3
3005 && i == tab_len - 1)
3006 lcs = wp->w_lcs_chars.tab3;
3007 p += mb_char2bytes(lcs, p);
3008 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003010 }
3011 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003012# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003013 // n_extra will be increased by
3014 // FIX_FOX_BOGUSCOLS macro below, so need to
3015 // adjust for that here
3016 if (wlv.vcol_off > 0)
3017 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003018# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003019 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 }
3022#endif
3023#ifdef FEAT_CONCEAL
3024 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003025 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026
3027 // Tab alignment should be identical regardless of
3028 // 'conceallevel' value. So tab compensates of all
3029 // previous concealed characters, and thus resets
3030 // vcol_off and boguscols accumulated so far in the
3031 // line. Note that the tab can be longer than
3032 // 'tabstop' when there are concealed characters.
3033 FIX_FOR_BOGUSCOLS;
3034
3035 // Make sure, the highlighting for the tab char will be
3036 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003037 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003039 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 tab_len += vc_saved;
3041 }
3042#endif
3043 mb_utf8 = FALSE; // don't draw as UTF-8
3044 if (wp->w_p_list)
3045 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003047 ? wp->w_lcs_chars.tab3
3048 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003050 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 else
3053#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 wlv.c_extra = wp->w_lcs_chars.tab2;
3055 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003057 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003058 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 mb_c = c;
3061 if (enc_utf8 && utf_char2len(c) > 1)
3062 {
3063 mb_utf8 = TRUE;
3064 u8cc[0] = 0;
3065 c = 0xc0;
3066 }
3067 }
3068 else
3069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003070 wlv.c_final = NUL;
3071 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072 c = ' ';
3073 }
3074 }
3075 else if (c == NUL
3076 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003077 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3078 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 && VIsual_mode != Ctrl_V
3080 && (
3081# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003082 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003084 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085 && !(noinvcur
3086 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003087 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 && lcs_eol_one > 0)
3089 {
3090 // Display a '$' after the line or highlight an extra
3091 // character if the line break is included.
3092#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3093 // For a diff line the highlighting continues after the
3094 // "$".
3095 if (
3096# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003097 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098# ifdef LINE_ATTR
3099 &&
3100# endif
3101# endif
3102# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003103 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003104# endif
3105 )
3106#endif
3107 {
3108 // In virtualedit, visual selections may extend
3109 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003110 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003111 && wlv.tocol != MAXCOL
3112 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003114 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003115 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003116 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3117 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118 else
3119 c = ' ';
3120 lcs_eol_one = -1;
3121 --ptr; // put it back at the NUL
3122 if (!attr_pri)
3123 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003124 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 n_attr = 1;
3127 }
3128 mb_c = c;
3129 if (enc_utf8 && utf_char2len(c) > 1)
3130 {
3131 mb_utf8 = TRUE;
3132 u8cc[0] = 0;
3133 c = 0xc0;
3134 }
3135 else
3136 mb_utf8 = FALSE; // don't draw as UTF-8
3137 }
3138 else if (c != NUL)
3139 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003140 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3141 if (wlv.n_extra == 0)
3142 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143#ifdef FEAT_RIGHTLEFT
3144 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003145 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 wlv.c_extra = NUL;
3148 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149#ifdef FEAT_LINEBREAK
3150 if (wp->w_p_lbr)
3151 {
3152 char_u *p;
3153
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 c = *wlv.p_extra;
3155 p = alloc(wlv.n_extra + 1);
3156 vim_memset(p, ' ', wlv.n_extra);
3157 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3158 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003159 vim_free(wlv.p_extra_free);
3160 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 }
3162 else
3163#endif
3164 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003165 wlv.n_extra = byte2cells(c) - 1;
3166 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 }
3168 if (!attr_pri)
3169 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003171 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 }
3175 mb_utf8 = FALSE; // don't draw as UTF-8
3176 }
3177 else if (VIsual_active
3178 && (VIsual_mode == Ctrl_V
3179 || VIsual_mode == 'v')
3180 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003181 && wlv.tocol != MAXCOL
3182 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 && (
3184#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003187 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 {
3189 c = ' ';
3190 --ptr; // put it back at the NUL
3191 }
3192#if defined(LINE_ATTR)
3193 else if ((
3194# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003195 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196# endif
3197# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003199# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003200 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 ) && (
3202# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003203 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003205 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003207 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208# endif
3209 < wp->w_width)))
3210 {
3211 // Highlight until the right side of the window
3212 c = ' ';
3213 --ptr; // put it back at the NUL
3214
3215 // Remember we do the char for line highlighting.
3216 ++did_line_attr;
3217
3218 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003219 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003221 || (wp->w_p_list &&
3222 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003223 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003225 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003227 wlv.diff_hlf = HLF_CHD;
3228 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3232 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003233 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003234 || (wlv.vcol >= left_curline_col
3235 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003236 wlv.char_attr = hl_combine_attr(
3237 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 }
3239 }
3240# endif
3241# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003245 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3246 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003247 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 if (!wlv.cul_screenline
3249 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003250 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003251 wlv.char_attr = hl_combine_attr(
3252 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003254 else if (wlv.line_attr)
3255 wlv.char_attr = hl_combine_attr(
3256 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
3258# endif
3259 }
3260#endif
3261 }
3262
3263#ifdef FEAT_CONCEAL
3264 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003265 && (wp != curwin || lnum != wp->w_cursor.lnum
3266 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003267 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3268 && !(lnum_in_visual_area
3269 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3270 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003271 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003272 if (((prev_syntax_id != syntax_seqnr
3273 && (syntax_flags & HL_CONCEAL) != 0)
3274 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003275 && (syn_get_sub_char() != NUL
3276 || (has_match_conc && match_conc)
3277 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 && wp->w_p_cole != 3)
3279 {
3280 // First time at this concealed item: display one
3281 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003282 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 c = match_conc;
3284 else if (syn_get_sub_char() != NUL)
3285 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003286 else if (wp->w_lcs_chars.conceal != NUL)
3287 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 else
3289 c = ' ';
3290
3291 prev_syntax_id = syntax_seqnr;
3292
Bram Moolenaar1306b362022-08-06 15:59:06 +01003293 if (wlv.n_extra > 0)
3294 wlv.vcol_off += wlv.n_extra;
3295 wlv.vcol += wlv.n_extra;
3296 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003297 {
3298# ifdef FEAT_RIGHTLEFT
3299 if (wp->w_p_rl)
3300 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 wlv.col -= wlv.n_extra;
3302 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 }
3304 else
3305# endif
3306 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003307 wlv.boguscols += wlv.n_extra;
3308 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 }
3310 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 n_attr = 0;
3313 }
3314 else if (n_skip == 0)
3315 {
3316 is_concealing = TRUE;
3317 n_skip = 1;
3318 }
3319 mb_c = c;
3320 if (enc_utf8 && utf_char2len(c) > 1)
3321 {
3322 mb_utf8 = TRUE;
3323 u8cc[0] = 0;
3324 c = 0xc0;
3325 }
3326 else
3327 mb_utf8 = FALSE; // don't draw as UTF-8
3328 }
3329 else
3330 {
3331 prev_syntax_id = 0;
3332 is_concealing = FALSE;
3333 }
3334
3335 if (n_skip > 0 && did_decrement_ptr)
3336 // not showing the '>', put pointer back to avoid getting stuck
3337 ++ptr;
3338
3339#endif // FEAT_CONCEAL
3340 }
3341
3342#ifdef FEAT_CONCEAL
3343 // In the cursor line and we may be concealing characters: correct
3344 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003346 && wp == curwin && lnum == wp->w_cursor.lnum
3347 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003348 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003349 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003350# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003352 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003354# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 wp->w_wcol = wlv.col - wlv.boguscols;
3356 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 did_wcol = TRUE;
3358 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003359# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003360 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003361# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 }
3363#endif
3364
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003365 // Use "wlv.extra_attr", but don't override visual selection
3366 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003367 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3368 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003370 && (!attr_pri
3371#ifdef FEAT_PROP_POPUP
3372 || (text_prop_flags & PT_FLAG_OVERRIDE)
3373#endif
3374 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 {
3376#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003377 if (wlv.line_attr)
3378 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003379 else
3380#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003381 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003382#ifdef FEAT_PROP_POPUP
3383 if (reset_extra_attr)
3384 {
3385 reset_extra_attr = FALSE;
3386 wlv.extra_attr = 0;
3387 }
3388#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003389 }
3390
3391#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3392 // XIM don't send preedit_start and preedit_end, but they send
3393 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3394 // im_is_preediting() here.
3395 if (p_imst == IM_ON_THE_SPOT
3396 && xic != NULL
3397 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003398 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 && !p_imdisable
3400 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 {
3403 colnr_T tcol;
3404
3405 if (preedit_end_col == MAXCOL)
3406 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3407 else
3408 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003409 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
3411 if (feedback_old_attr < 0)
3412 {
3413 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 wlv.char_attr = im_get_feedback_attr(feedback_col);
3417 if (wlv.char_attr < 0)
3418 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003419 feedback_col++;
3420 }
3421 else if (feedback_old_attr >= 0)
3422 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 feedback_old_attr = -1;
3425 feedback_col = 0;
3426 }
3427 }
3428#endif
3429 // Handle the case where we are in column 0 but not on the first
3430 // character of the line and the user wants us to show us a
3431 // special character (via 'listchars' option "precedes:<char>".
3432 if (lcs_prec_todo != NUL
3433 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003434 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3435 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003437 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 && c != NUL)
3441 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003442 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 lcs_prec_todo = NUL;
3444 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3445 {
3446 // Double-width character being overwritten by the "precedes"
3447 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003448 wlv.c_extra = MB_FILLER_CHAR;
3449 wlv.c_final = NUL;
3450 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003452 wlv.extra_attr =
3453 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 }
3455 mb_c = c;
3456 if (enc_utf8 && utf_char2len(c) > 1)
3457 {
3458 mb_utf8 = TRUE;
3459 u8cc[0] = 0;
3460 c = 0xc0;
3461 }
3462 else
3463 mb_utf8 = FALSE; // don't draw as UTF-8
3464 if (!attr_pri)
3465 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003466 saved_attr3 = wlv.char_attr; // save current attr
3467 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 n_attr3 = 1;
3469 }
3470 }
3471
3472 // At end of the text line or just after the last character.
3473 if ((c == NUL
3474#if defined(LINE_ATTR)
3475 || did_line_attr == 1
3476#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003477 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 {
3479#ifdef FEAT_SEARCH_EXTRA
3480 // flag to indicate whether prevcol equals startcol of search_hl or
3481 // one of the matches
3482 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3483 (long)(ptr - line) - (c == NUL));
3484#endif
3485 // Invert at least one char, used for Visual and empty line or
3486 // highlight match at end of line. If it's beyond the last
3487 // char on the screen, just overwrite that one (tricky!) Not
3488 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003489 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003490 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 && (VIsual_mode != Ctrl_V
3492 || lnum == VIsual.lnum
3493 || lnum == curwin->w_cursor.lnum)
3494 && c == NUL)
3495#ifdef FEAT_SEARCH_EXTRA
3496 // highlight 'hlsearch' match at end of line
3497 || (prevcol_hl_flag
3498# ifdef FEAT_SYN_HL
3499 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3500 && !(wp == curwin && VIsual_active))
3501# endif
3502# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003503 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504# endif
3505# if defined(LINE_ATTR)
3506 && did_line_attr <= 1
3507# endif
3508 )
3509#endif
3510 ))
3511 {
3512 int n = 0;
3513
3514#ifdef FEAT_RIGHTLEFT
3515 if (wp->w_p_rl)
3516 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003517 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003518 n = 1;
3519 }
3520 else
3521#endif
3522 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003523 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524 n = -1;
3525 }
3526 if (n != 0)
3527 {
3528 // At the window boundary, highlight the last character
3529 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 wlv.off += n;
3531 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 }
3533 else
3534 {
3535 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003538 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540#ifdef FEAT_SEARCH_EXTRA
3541 if (area_attr == 0)
3542 {
3543 // Use attributes from match with highest priority among
3544 // 'search_hl' and the match list.
3545 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003546 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 }
3548#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003550 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551#ifdef FEAT_RIGHTLEFT
3552 if (wp->w_p_rl)
3553 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003554 --wlv.col;
3555 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 }
3557 else
3558#endif
3559 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 ++wlv.col;
3561 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003563 ++wlv.vcol;
3564 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 }
3566 }
3567
3568 // At end of the text line.
3569 if (c == NUL)
3570 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572
3573 // Update w_cline_height and w_cline_folded if the cursor line was
3574 // updated (saves a call to plines() later).
3575 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3576 {
3577 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579#ifdef FEAT_FOLDING
3580 curwin->w_cline_folded = FALSE;
3581#endif
3582 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3583 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003584 break;
3585 }
3586
3587 // Show "extends" character from 'listchars' if beyond the line end and
3588 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003589 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003590 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 && wp->w_p_list
3592 && !wp->w_p_wrap
3593#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003594 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595#endif
3596 && (
3597#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003602 || lcs_eol_one > 0
3603 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003604 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003606 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003607 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 mb_c = c;
3609 if (enc_utf8 && utf_char2len(c) > 1)
3610 {
3611 mb_utf8 = TRUE;
3612 u8cc[0] = 0;
3613 c = 0xc0;
3614 }
3615 else
3616 mb_utf8 = FALSE;
3617 }
3618
3619#ifdef FEAT_SYN_HL
3620 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 if (wlv.draw_color_col)
3622 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623
3624 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3625 // highlight the cursor position itself.
3626 // Also highlight the 'colorcolumn' if it is different than
3627 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003628 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3629 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 if (((wlv.draw_state == WL_LINE
3632 || wlv.draw_state == WL_BRI
3633 || wlv.draw_state == WL_SBR)
3634 && !lnum_in_visual_area
3635 && search_attr == 0
3636 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003637# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003638 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003639# endif
3640 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 {
3642 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3643 && lnum != wp->w_cursor.lnum)
3644 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003645 vcol_save_attr = wlv.char_attr;
3646 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3647 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003649 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003651 vcol_save_attr = wlv.char_attr;
3652 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 }
3654 }
3655#endif
3656
3657 // Store character to be displayed.
3658 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003659 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 {
3662 // Store the character.
3663#if defined(FEAT_RIGHTLEFT)
3664 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3665 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003666 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 --wlv.off;
3668 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003671 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 if (enc_dbcs == DBCS_JPNU)
3673 {
3674 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 ScreenLines[wlv.off] = 0x8e;
3676 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677 }
3678 else if (enc_utf8)
3679 {
3680 if (mb_utf8)
3681 {
3682 int i;
3683
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687 for (i = 0; i < Screen_mco; ++i)
3688 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 if (u8cc[i] == 0)
3691 break;
3692 }
3693 }
3694 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003695 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 }
3697 if (multi_attr)
3698 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700 multi_attr = 0;
3701 }
3702 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003703 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003706
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3708 {
3709 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003710 ++wlv.off;
3711 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712 if (enc_utf8)
3713 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003714 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 else
3716 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003718 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003720 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721#endif
3722 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003723 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003724 // When "wlv.tocol" is halfway a character, set it to the end
3725 // of the character, otherwise highlighting won't stop.
3726 if (wlv.tocol == wlv.vcol)
3727 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003728
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003729 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003730
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731#ifdef FEAT_RIGHTLEFT
3732 if (wp->w_p_rl)
3733 {
3734 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 --wlv.off;
3736 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003737 }
3738#endif
3739 }
3740#ifdef FEAT_RIGHTLEFT
3741 if (wp->w_p_rl)
3742 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 --wlv.off;
3744 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745 }
3746 else
3747#endif
3748 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003749 ++wlv.off;
3750 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 }
3752 }
3753#ifdef FEAT_CONCEAL
3754 else if (wp->w_p_cole > 0 && is_concealing)
3755 {
3756 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003757 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003758 if (wlv.n_extra > 0)
3759 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003760 if (wp->w_p_wrap)
3761 {
3762 // Special voodoo required if 'wrap' is on.
3763 //
3764 // Advance the column indicator to force the line
3765 // drawing to wrap early. This will make the line
3766 // take up the same screen space when parts are concealed,
3767 // so that cursor line computations aren't messed up.
3768 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 // trailing junk to be written out of the screen line
3771 // we are building, 'boguscols' keeps track of the number
3772 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003773 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003775 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776# ifdef FEAT_RIGHTLEFT
3777 if (wp->w_p_rl)
3778 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003779 wlv.col -= wlv.n_extra;
3780 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781 }
3782 else
3783# endif
3784 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003785 wlv.col += wlv.n_extra;
3786 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003788 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789 n_attr = 0;
3790 }
3791
3792
3793 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3794 {
3795 // Need to fill two screen columns.
3796# ifdef FEAT_RIGHTLEFT
3797 if (wp->w_p_rl)
3798 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 --wlv.boguscols;
3800 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 }
3802 else
3803# endif
3804 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003805 ++wlv.boguscols;
3806 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003807 }
3808 }
3809
3810# ifdef FEAT_RIGHTLEFT
3811 if (wp->w_p_rl)
3812 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003813 --wlv.boguscols;
3814 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 }
3816 else
3817# endif
3818 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003819 ++wlv.boguscols;
3820 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003821 }
3822 }
3823 else
3824 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003825 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003826 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003827 wlv.vcol += wlv.n_extra;
3828 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003829 n_attr = 0;
3830 }
3831 }
3832
3833 }
3834#endif // FEAT_CONCEAL
3835 else
3836 --n_skip;
3837
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003838 // Only advance the "wlv.vcol" when after the 'number' or
3839 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003840 if (wlv.draw_state > WL_NR
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
3844 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003845 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846
3847#ifdef FEAT_SYN_HL
3848 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003849 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850#endif
3851
3852 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003853 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3854 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855
3856 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003857 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003858 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003859 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003860 if (wlv.n_attr_skip > 0)
3861 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862
3863 // At end of screen line and there is more to come: Display the line
3864 // so far. If there is no more to display it is caught above.
3865 if ((
3866#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003867 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003869 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003870 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003871 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003873 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003874#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003875#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003876 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003877#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003878 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003879 && wlv.p_extra != at_end_str)
3880 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3881 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 )
3883 {
3884#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003885 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003886 wlv_screen_line(wp, &wlv, FALSE);
3887 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003888 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003890 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003891#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003892 ++wlv.row;
3893 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003894
3895 // When not wrapping and finished diff lines, or when displayed
3896 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003897 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003899 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003900#endif
3901#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003902 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003904 ) || lcs_eol_one == -1)
3905#ifdef FEAT_PROP_POPUP
3906 && !text_prop_follows
3907#endif
3908 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003910#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003911 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003912 {
3913 // do not output more of the line, only the "below" prop
3914 ptr += STRLEN(ptr);
3915# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003916 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003917# endif
3918 }
3919#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920
3921 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003922 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003924 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925#endif
3926 )
3927 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003928 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3929 draw_vsep_win(wp, wlv.row);
3930 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931 }
3932
3933 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003934 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003936 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937 break;
3938 }
3939
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003942 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003944#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003945 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003946#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947 && wp->w_width == Columns)
3948 {
3949 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003950 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951
3952 // Special trick to make copy/paste of wrapped lines work with
3953 // xterm/screen: write an extra character beyond the end of
3954 // the line. This will work with all terminal types
3955 // (regardless of the xn,am settings).
3956 // Only do this on a fast tty.
3957 // Only do this if the cursor is on the current line
3958 // (something has been written in it).
3959 // Don't do this for the GUI.
3960 // Don't do this for double-width characters.
3961 // Don't do this for a window not at the right screen border.
3962 if (p_tf
3963#ifdef FEAT_GUI
3964 && !gui.in_use
3965#endif
3966 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003967 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3968 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003970 || (*mb_off2cells)(
3971 LineOffset[wlv.screen_row - 1]
3972 + (int)Columns - 2,
3973 LineOffset[wlv.screen_row]
3974 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975 {
3976 // First make sure we are at the end of the screen line,
3977 // then output the same character again to let the
3978 // terminal know about the wrap. If the terminal doesn't
3979 // auto-wrap, we overwrite the character.
3980 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 screen_char(LineOffset[wlv.screen_row - 1]
3982 + (unsigned)Columns - 1,
3983 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984
3985 // When there is a multi-byte character, just output a
3986 // space to keep it simple.
3987 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003988 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989 out_char(' ');
3990 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003991 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003992 + (Columns - 1)]);
3993 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003994 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003995 screen_start(); // don't know where cursor is now
3996 }
3997 }
3998
Bram Moolenaar1306b362022-08-06 15:59:06 +01003999 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000
Bram Moolenaareed9d462021-02-15 20:38:25 +01004001 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004003 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004005 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004007 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004008 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009#endif
4010#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004011 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004012 // When the filler lines are actually below the last line of the
4013 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004014 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015 break;
4016#endif
4017 }
4018
4019 } // for every character in the line
4020
4021#ifdef FEAT_SPELL
4022 // After an empty line check first word for capital.
4023 if (*skipwhite(line) == NUL)
4024 {
4025 capcol_lnum = lnum + 1;
4026 cap_col = 0;
4027 }
4028#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004029#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030 vim_free(text_props);
4031 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004032 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033#endif
4034
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004035 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004036 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037}