blob: d8dc303e312eeb7c8e2b2ecda969d2fc17492985 [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);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000228 if (wlv->p_extra_free == NULL)
229 return;
230
231 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
232 wp, FALSE, wlv->lnum);
233 wlv->p_extra_free[wlv->n_extra] = NUL;
234 wlv->p_extra = wlv->p_extra_free;
235 wlv->c_extra = NUL;
236 wlv->c_final = NUL;
237 if (use_cursor_line_highlight(wp, wlv->lnum))
238 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
239 else
240 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100241}
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
zeertzjqb7acea12022-12-12 13:20:43 +0000988#ifdef FEAT_SYN_HL
989 static void
990apply_cursorline_highlight(
991 winlinevars_T *wlv,
992 int sign_present UNUSED)
993{
994 wlv->cul_attr = HL_ATTR(HLF_CUL);
995# ifdef FEAT_SIGNS
996 // Combine the 'cursorline' and sign highlighting, depending on
997 // the sign priority.
998 if (sign_present && wlv->sattr.sat_linehl > 0)
999 {
1000 if (wlv->sattr.sat_priority >= 100)
1001 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1002 else
1003 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1004 }
1005 else
1006# endif
1007# if defined(FEAT_QUICKFIX)
1008 // let the line attribute overrule 'cursorline', otherwise
1009 // it disappears when both have background set;
1010 // 'cursorline' can use underline or bold to make it show
1011 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1012# else
1013 wlv->line_attr = wlv->cul_attr;
1014# endif
1015}
1016#endif
1017
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001018/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 * Display line "lnum" of window 'wp' on the screen.
1020 * Start at row "startrow", stop when "endrow" is reached.
1021 * wp->w_virtcol needs to be valid.
1022 *
1023 * Return the number of last row the line occupies.
1024 */
1025 int
1026win_line(
1027 win_T *wp,
1028 linenr_T lnum,
1029 int startrow,
1030 int endrow,
1031 int nochange UNUSED, // not updating for changed text
1032 int number_only) // only update the number column
1033{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001034 winlinevars_T wlv; // variables passed between functions
1035
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001037 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038 char_u *line; // current line
1039 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040
Bram Moolenaar1306b362022-08-06 15:59:06 +01001041#ifdef FEAT_PROP_POPUP
1042 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1043#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001044#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001045 int in_linebreak = FALSE; // n_extra set for showing linebreak
1046#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001048 // displaying eol at end-of-line
1049 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001050 int lcs_prec_todo = wp->w_lcs_chars.prec;
1051 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001052
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001053 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001054 int saved_attr2 = 0; // char_attr saved for n_attr
1055 int n_attr3 = 0; // chars with overruling special attr
1056 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001057
Bram Moolenaarcd105412022-10-10 19:50:42 +01001058 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1059 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001060#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001061 int skip_cells = 0; // nr of cells to skip for virtual text
1062 // after the line, when w_skipcol is
1063 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001064#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 int fromcol_prev = -2; // start of inverting after cursor
1067 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068 int lnum_in_visual_area = FALSE;
1069 pos_T pos;
1070 long v;
1071
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 int attr_pri = FALSE; // char_attr has priority
1073 int area_highlighting = FALSE; // Visual or incsearch highlighting
1074 // in this line
1075 int vi_attr = 0; // attributes for Visual and incsearch
1076 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001077 int area_attr = 0; // attributes desired by highlighting
1078 int search_attr = 0; // attributes desired by 'hlsearch'
1079#ifdef FEAT_SYN_HL
1080 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1081 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001082 int prev_syntax_col = -1; // column of prev_syntax_attr
1083 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001084 int has_syntax = FALSE; // this buffer has syntax highl.
1085 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001087#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 int text_prop_count;
1089 int text_prop_next = 0; // next text property to use
1090 textprop_T *text_props = NULL;
1091 int *text_prop_idxs = NULL;
1092 int text_props_active = 0;
1093 proptype_T *text_prop_type = NULL;
1094 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001095 int text_prop_attr_comb = 0; // text_prop_attr combined with
1096 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001097 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001098 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001099 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001100 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001101 int saved_search_attr = 0; // search_attr to be used when n_extra
1102 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001103 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001104 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105#endif
1106#ifdef FEAT_SPELL
1107 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001108 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109# define SPWORDLEN 150
1110 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1111 int nextlinecol = 0; // column where nextline[] starts
1112 int nextline_idx = 0; // index in nextline[] where next line
1113 // starts
1114 int spell_attr = 0; // attributes desired by spelling
1115 int word_end = 0; // last byte with same spell_attr
1116 static linenr_T checked_lnum = 0; // line number for "checked_col"
1117 static int checked_col = 0; // column in "checked_lnum" up to which
1118 // there are no spell errors
1119 static int cap_col = -1; // column to check for Cap word
1120 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1121 int cur_checked_col = 0; // checked column for current line
1122#endif
1123 int extra_check = 0; // has extra highlighting
1124 int multi_attr = 0; // attributes desired by multibyte
1125 int mb_l = 1; // multi-byte byte length
1126 int mb_c = 0; // decoded multi-byte character
1127 int mb_utf8 = FALSE; // screen char is UTF-8 char
1128 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001129#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 int change_start = MAXCOL; // first col of changed area
1131 int change_end = -1; // last col of changed area
1132#endif
1133 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001134 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001135 int in_multispace = FALSE; // in multiple consecutive spaces
1136 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001137#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001138 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001141 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001142#ifdef FEAT_ARABIC
1143 int prev_c = 0; // previous Arabic character
1144 int prev_c1 = 0; // first composing char for prev_c
1145#endif
1146#if defined(LINE_ATTR)
1147 int did_line_attr = 0;
1148#endif
1149#ifdef FEAT_TERMINAL
1150 int get_term_attr = FALSE;
1151#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001152
Martin Tournoijba43e762022-10-13 22:12:15 +01001153#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 // margin columns for the screen line, needed for when 'cursorlineopt'
1155 // contains "screenline"
1156 int left_curline_col = 0;
1157 int right_curline_col = 0;
1158#endif
1159
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1161 int feedback_col = 0;
1162 int feedback_old_attr = -1;
1163#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164
1165#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1166 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001167#endif
1168#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001169 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001170#endif
1171#ifdef FEAT_CONCEAL
1172 int syntax_flags = 0;
1173 int syntax_seqnr = 0;
1174 int prev_syntax_id = 0;
1175 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1176 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 int did_wcol = FALSE;
1178 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001179# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180# define FIX_FOR_BOGUSCOLS \
1181 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001182 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001183 wlv.vcol -= wlv.vcol_off; \
1184 wlv.vcol_off = 0; \
1185 wlv.col -= wlv.boguscols; \
1186 old_boguscols = wlv.boguscols; \
1187 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 }
1189#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001190# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191#endif
1192
1193 if (startrow > endrow) // past the end already!
1194 return startrow;
1195
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001196 CLEAR_FIELD(wlv);
1197
1198 wlv.lnum = lnum;
1199 wlv.startrow = startrow;
1200 wlv.row = startrow;
1201 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001202 wlv.fromcol = -10;
1203 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001204#ifdef FEAT_LINEBREAK
1205 wlv.vcol_sbr = -1;
1206#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207
1208 if (!number_only)
1209 {
1210 // To speed up the loop below, set extra_check when there is linebreak,
1211 // trailing white space and/or syntax processing to be done.
1212#ifdef FEAT_LINEBREAK
1213 extra_check = wp->w_p_lbr;
1214#endif
1215#ifdef FEAT_SYN_HL
1216 if (syntax_present(wp) && !wp->w_s->b_syn_error
1217# ifdef SYN_TIME_LIMIT
1218 && !wp->w_s->b_syn_slow
1219# endif
1220 )
1221 {
1222 // Prepare for syntax highlighting in this line. When there is an
1223 // error, stop syntax highlighting.
1224 save_did_emsg = did_emsg;
1225 did_emsg = FALSE;
1226 syntax_start(wp, lnum);
1227 if (did_emsg)
1228 wp->w_s->b_syn_error = TRUE;
1229 else
1230 {
1231 did_emsg = save_did_emsg;
1232#ifdef SYN_TIME_LIMIT
1233 if (!wp->w_s->b_syn_slow)
1234#endif
1235 {
1236 has_syntax = TRUE;
1237 extra_check = TRUE;
1238 }
1239 }
1240 }
1241
1242 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001243 wlv.color_cols = wp->w_p_cc_cols;
1244 if (wlv.color_cols != NULL)
1245 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246#endif
1247
1248#ifdef FEAT_TERMINAL
1249 if (term_show_buffer(wp->w_buffer))
1250 {
1251 extra_check = TRUE;
1252 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001253 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 }
1255#endif
1256
1257#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001258 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 {
1260 // Prepare for spell checking.
1261 has_spell = TRUE;
1262 extra_check = TRUE;
1263
1264 // Get the start of the next line, so that words that wrap to the
1265 // next line are found too: "et<line-break>al.".
1266 // Trick: skip a few chars for C/shell/Vim comments
1267 nextline[SPWORDLEN] = NUL;
1268 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1269 {
1270 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1271 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1272 }
1273
1274 // When a word wrapped from the previous line the start of the
1275 // current line is valid.
1276 if (lnum == checked_lnum)
1277 cur_checked_col = checked_col;
1278 checked_lnum = 0;
1279
1280 // When there was a sentence end in the previous line may require a
1281 // word starting with capital in this line. In line 1 always check
1282 // the first word.
1283 if (lnum != capcol_lnum)
1284 cap_col = -1;
1285 if (lnum == 1)
1286 cap_col = 0;
1287 capcol_lnum = 0;
1288 }
1289#endif
1290
1291 // handle Visual active in this window
1292 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1293 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001294 pos_T *top, *bot;
1295
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1297 {
1298 // Visual is after curwin->w_cursor
1299 top = &curwin->w_cursor;
1300 bot = &VIsual;
1301 }
1302 else
1303 {
1304 // Visual is before curwin->w_cursor
1305 top = &VIsual;
1306 bot = &curwin->w_cursor;
1307 }
1308 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1309 if (VIsual_mode == Ctrl_V)
1310 {
1311 // block mode
1312 if (lnum_in_visual_area)
1313 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001314 wlv.fromcol = wp->w_old_cursor_fcol;
1315 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001316 }
1317 }
1318 else
1319 {
1320 // non-block mode
1321 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001322 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 else if (lnum == top->lnum)
1324 {
1325 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001326 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 else
1328 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001331 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 }
1333 }
1334 if (VIsual_mode != 'V' && lnum == bot->lnum)
1335 {
1336 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1337 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 wlv.fromcol = -10;
1339 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 }
1341 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001342 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 else
1344 {
1345 pos = *bot;
1346 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001347 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1348 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 else
1350 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001351 getvvcol(wp, &pos, NULL, NULL,
1352 (colnr_T *)&wlv.tocol);
1353 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 }
1355 }
1356 }
1357 }
1358
1359 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001360 if (!highlight_match && lnum == curwin->w_cursor.lnum
1361 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362#ifdef FEAT_GUI
1363 && !gui.in_use
1364#endif
1365 )
1366 noinvcur = TRUE;
1367
1368 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001369 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 {
1371 area_highlighting = TRUE;
1372 vi_attr = HL_ATTR(HLF_V);
1373#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1374 if ((clip_star.available && !clip_star.owned
1375 && clip_isautosel_star())
1376 || (clip_plus.available && !clip_plus.owned
1377 && clip_isautosel_plus()))
1378 vi_attr = HL_ATTR(HLF_VNC);
1379#endif
1380 }
1381 }
1382
1383 // handle 'incsearch' and ":s///c" highlighting
1384 else if (highlight_match
1385 && wp == curwin
1386 && lnum >= curwin->w_cursor.lnum
1387 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1388 {
1389 if (lnum == curwin->w_cursor.lnum)
1390 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001391 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001393 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1395 {
1396 pos.lnum = lnum;
1397 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001398 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 }
1400 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001401 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1404 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 area_highlighting = TRUE;
1406 vi_attr = HL_ATTR(HLF_I);
1407 }
1408 }
1409
1410#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001411 wlv.filler_lines = diff_check(wp, lnum);
1412 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001413 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001414 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 {
1416 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001417 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001419 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001420 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001421 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001422 }
1423 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001424 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001425 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 area_highlighting = TRUE;
1427 }
1428 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001429 wlv.filler_lines = wp->w_topfill;
1430 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431#endif
1432
1433#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001434 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001435 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001436 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001437#endif
1438
1439#ifdef LINE_ATTR
1440# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001441 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001443 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444# endif
1445# if defined(FEAT_QUICKFIX)
1446 // Highlight the current line in the quickfix window.
1447 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001448 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001449# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001450 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 area_highlighting = TRUE;
1452#endif
1453
1454 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1455 ptr = line;
1456
1457#ifdef FEAT_SPELL
1458 if (has_spell && !number_only)
1459 {
1460 // For checking first word with a capital skip white space.
1461 if (cap_col == 0)
1462 cap_col = getwhitecols(line);
1463
1464 // To be able to spell-check over line boundaries copy the end of the
1465 // current line into nextline[]. Above the start of the next line was
1466 // copied to nextline[SPWORDLEN].
1467 if (nextline[SPWORDLEN] == NUL)
1468 {
1469 // No next line or it is empty.
1470 nextlinecol = MAXCOL;
1471 nextline_idx = 0;
1472 }
1473 else
1474 {
1475 v = (long)STRLEN(line);
1476 if (v < SPWORDLEN)
1477 {
1478 // Short line, use it completely and append the start of the
1479 // next line.
1480 nextlinecol = 0;
1481 mch_memmove(nextline, line, (size_t)v);
1482 STRMOVE(nextline + v, nextline + SPWORDLEN);
1483 nextline_idx = v + 1;
1484 }
1485 else
1486 {
1487 // Long line, use only the last SPWORDLEN bytes.
1488 nextlinecol = v - SPWORDLEN;
1489 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1490 nextline_idx = SPWORDLEN + 1;
1491 }
1492 }
1493 }
1494#endif
1495
1496 if (wp->w_p_list)
1497 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001498 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001499 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001500 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001501 || wp->w_lcs_chars.trail
1502 || wp->w_lcs_chars.lead
1503 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001504 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001505
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001507 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508 {
1509 trailcol = (colnr_T)STRLEN(ptr);
1510 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1511 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001512 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001514 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001515 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001516 {
1517 leadcol = 0;
1518 while (VIM_ISWHITE(ptr[leadcol]))
1519 ++leadcol;
1520 if (ptr[leadcol] == NUL)
1521 // in a line full of spaces all of them are treated as trailing
1522 leadcol = (colnr_T)0;
1523 else
1524 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001525 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001526 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001527 }
1528
Bram Moolenaard7657e92022-09-20 18:59:30 +01001529 wlv.wcr_attr = get_wcr_attr(wp);
1530 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001532 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 area_highlighting = TRUE;
1534 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001535
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001536 // When w_skipcol is non-zero and there is virtual text above the actual
1537 // text, then this much of the virtual text is skipped.
1538 int skipcol_in_text_prop_above = 0;
1539
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001540#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001541 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001542 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001543
1544 char_u *prop_start;
1545 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1546 if (text_prop_count > 0)
1547 {
1548 // Make a copy of the properties, so that they are properly
1549 // aligned.
1550 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1551 if (text_props != NULL)
1552 mch_memmove(text_props, prop_start,
1553 text_prop_count * sizeof(textprop_T));
1554
1555 // Allocate an array for the indexes.
1556 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1557 if (text_prop_idxs == NULL)
1558 VIM_CLEAR(text_props);
1559
1560 if (text_props != NULL)
1561 {
1562 area_highlighting = TRUE;
1563 extra_check = TRUE;
1564
1565 // When skipping virtual text the props need to be sorted. The
1566 // order is reversed!
1567 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1568 {
1569 for (int i = 0; i < text_prop_count; ++i)
1570 text_prop_idxs[i] = i;
1571 sort_text_props(wp->w_buffer, text_props,
1572 text_prop_idxs, text_prop_count);
1573 }
1574
1575 // Text props "above" move the line number down to where the text
1576 // is. Only count the ones that are visible, not those that are
1577 // skipped because of w_skipcol.
1578 int text_width = wp->w_width - win_col_off(wp);
1579 for (int i = text_prop_count - 1; i >= 0; --i)
1580 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1581 {
1582 if (lnum == wp->w_topline
1583 && wp->w_skipcol - skipcol_in_text_prop_above
1584 >= text_width)
1585 {
1586 // This virtual text above is skipped, remove it from
1587 // the array.
1588 skipcol_in_text_prop_above += text_width;
1589 for (int j = i + 1; j < text_prop_count; ++j)
1590 text_props[j - 1] = text_props[j];
1591 ++i;
1592 --text_prop_count;
1593 }
1594 else
1595 ++wlv.text_prop_above_count;
1596 }
1597 }
1598 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599#endif
1600
1601 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1602 // first character to be displayed.
1603 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001604 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 else
1606 v = wp->w_leftcol;
1607 if (v > 0 && !number_only)
1608 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001609 char_u *prev_ptr = ptr;
1610 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001611 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001612
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001613 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001614 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001616 charsize = win_lbr_chartabsize(&cts, NULL);
1617 cts.cts_vcol += charsize;
1618 prev_ptr = cts.cts_ptr;
1619 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001621 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001622 ptr = cts.cts_ptr;
1623 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001624
1625 // When:
1626 // - 'cuc' is set, or
1627 // - 'colorcolumn' is set, or
1628 // - 'virtualedit' is set, or
1629 // - the visual mode is active,
1630 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001631 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001632#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001633 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634#endif
1635 virtual_active() ||
1636 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001637 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638
1639 // Handle a character that's not completely on the screen: Put ptr at
1640 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001641 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001643 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 ptr = prev_ptr;
1645 // If the character fits on the screen, don't need to skip it.
1646 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001647 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1648 && wlv.col == 0)
1649 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 }
1651
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001652#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001653 // If there the text doesn't reach to the desired column, need to skip
1654 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001655 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1656 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001657 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001658#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001659
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660 // Adjust for when the inverted text is before the screen,
1661 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001662 if (wlv.tocol <= wlv.vcol)
1663 wlv.fromcol = 0;
1664 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1665 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001666
1667#ifdef FEAT_LINEBREAK
1668 // When w_skipcol is non-zero, first line needs 'showbreak'
1669 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001670 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001671#endif
1672#ifdef FEAT_SPELL
1673 // When spell checking a word we need to figure out the start of the
1674 // word and if it's badly spelled or not.
1675 if (has_spell)
1676 {
1677 int len;
1678 colnr_T linecol = (colnr_T)(ptr - line);
1679 hlf_T spell_hlf = HLF_COUNT;
1680
1681 pos = wp->w_cursor;
1682 wp->w_cursor.lnum = lnum;
1683 wp->w_cursor.col = linecol;
1684 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1685
1686 // spell_move_to() may call ml_get() and make "line" invalid
1687 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1688 ptr = line + linecol;
1689
1690 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1691 {
1692 // no bad word found at line start, don't check until end of a
1693 // word
1694 spell_hlf = HLF_COUNT;
1695 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1696 }
1697 else
1698 {
1699 // bad word found, use attributes until end of word
1700 word_end = wp->w_cursor.col + len + 1;
1701
1702 // Turn index into actual attributes.
1703 if (spell_hlf != HLF_COUNT)
1704 spell_attr = highlight_attr[spell_hlf];
1705 }
1706 wp->w_cursor = pos;
1707
1708# ifdef FEAT_SYN_HL
1709 // Need to restart syntax highlighting for this line.
1710 if (has_syntax)
1711 syntax_start(wp, lnum);
1712# endif
1713 }
1714#endif
1715 }
1716
1717 // Correct highlighting for cursor that can't be disabled.
1718 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001719 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 {
1721 if (noinvcur)
1722 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001723 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 {
1725 // highlighting starts at cursor, let it start just after the
1726 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001727 fromcol_prev = wlv.fromcol;
1728 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001730 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001731 // restart highlighting after the cursor
1732 fromcol_prev = wp->w_virtcol;
1733 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001734 if (wlv.fromcol >= wlv.tocol)
1735 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001736 }
1737
1738#ifdef FEAT_SEARCH_EXTRA
1739 if (!number_only)
1740 {
1741 v = (long)(ptr - line);
1742 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1743 &line, &screen_search_hl,
1744 &search_attr);
1745 ptr = line + v; // "line" may have been updated
1746 }
1747#endif
1748
1749#ifdef FEAT_SYN_HL
1750 // Cursor line highlighting for 'cursorline' in the current window.
1751 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1752 {
1753 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001754 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 if (!(wp == curwin && VIsual_active)
1756 && wp->w_p_culopt_flags != CULOPT_NBR)
1757 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001758 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1760
zeertzjqb7acea12022-12-12 13:20:43 +00001761 // Only apply CursorLine highlight here when "screenline" is not
1762 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001763 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001764 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 else
1766 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001767 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1769 }
1770 area_highlighting = TRUE;
1771 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 }
1773#endif
1774
Bram Moolenaar1306b362022-08-06 15:59:06 +01001775 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776
1777 // Repeat for the whole displayed line.
1778 for (;;)
1779 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001780 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001782 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783#endif
1784#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001785 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001787
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001788 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001789 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001790 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001791#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001792 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001793 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001794 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001795 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001796 }
1797#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001798 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001800 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001801 if (cmdwin_type != 0 && wp == curwin)
1802 {
1803 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001804 wlv.n_extra = 1;
1805 wlv.c_extra = cmdwin_type;
1806 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001807 wlv.char_attr =
1808 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 }
1810 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001812 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001814 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001815 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001816 }
1817#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001819 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001820 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001821 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001822 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001823 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001824 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 }
1826#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001827 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001828 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001829 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001830 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001831 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001832 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001834 // Check if 'breakindent' applies and show it.
1835 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1836 if (wlv.n_extra == 0)
1837 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001840 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001843 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 }
1845#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001846 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001848 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001849 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 }
1851 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001852
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001853#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001854 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001855 && wlv.vcol >= left_curline_col
1856 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001857 {
zeertzjqb7acea12022-12-12 13:20:43 +00001858 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 }
1860#endif
1861
1862 // When still displaying '$' of change command, stop at cursor.
1863 // When only displaying the (relative) line number and that's done,
1864 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001865 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001866 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001867 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001869 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870#endif
1871 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001872 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001873 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 // Pretend we have finished updating the window. Except when
1875 // 'cursorcolumn' is set.
1876#ifdef FEAT_SYN_HL
1877 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001878 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 else
1880#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001881 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 break;
1883 }
1884
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 {
1887 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001888 if (wlv.vcol == wlv.fromcol
1889 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1890 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 && (*mb_ptr2cells)(ptr) > 1)
1892 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001893 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001894 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001895 area_attr = vi_attr; // start highlighting
1896 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001897 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001898 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001899 area_attr = 0; // stop highlighting
1900
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001901#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 if (text_props != NULL)
1903 {
1904 int pi;
1905 int bcol = (int)(ptr - line);
1906
Bram Moolenaar1306b362022-08-06 15:59:06 +01001907 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001908# ifdef FEAT_LINEBREAK
1909 && !in_linebreak
1910# endif
1911 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912 --bcol; // still working on the previous char, e.g. Tab
1913
1914 // Check if any active property ends.
1915 for (pi = 0; pi < text_props_active; ++pi)
1916 {
1917 int tpi = text_prop_idxs[pi];
1918
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001919 if (text_props[tpi].tp_col != MAXCOL
1920 && bcol >= text_props[tpi].tp_col - 1
1921 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001922 {
1923 if (pi + 1 < text_props_active)
1924 mch_memmove(text_prop_idxs + pi,
1925 text_prop_idxs + pi + 1,
1926 sizeof(int)
1927 * (text_props_active - (pi + 1)));
1928 --text_props_active;
1929 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001930# ifdef FEAT_LINEBREAK
1931 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001932 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001933 syntax_attr = 0;
1934# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 }
1936 }
1937
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001938# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001939 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001940 // not on the next char yet, don't start another prop
1941 --bcol;
1942# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001944 // With 'nowrap' and not in the first screen line only "below"
1945 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001947 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001948 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001949 && (wp->w_p_wrap
1950 || wlv.row == startrow
1951 || (text_props[text_prop_next].tp_flags
1952 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001953 || (bcol == 0 &&
1954 (text_props[text_prop_next].tp_flags
1955 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001956 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001957 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001958 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001959 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1960 {
1961 // first display the '$' after the line
1962 text_prop_follows = TRUE;
1963 break;
1964 }
1965 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001966 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001967 + text_props[text_prop_next].tp_len)
1968 text_prop_idxs[text_props_active++] = text_prop_next;
1969 ++text_prop_next;
1970 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001971
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001972 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001973 {
1974 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001975 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001976 text_prop_flags = 0;
1977 text_prop_type = NULL;
1978 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001979 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001980 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001981 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001983 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001984 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001985 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001986
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001987 // Sort the properties on priority and/or starting last.
1988 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001989 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001990 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001991 sort_text_props(wp->w_buffer, text_props,
1992 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001993
1994 for (pi = 0; pi < text_props_active; ++pi)
1995 {
1996 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001997 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001999 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000
Bram Moolenaarcd105412022-10-10 19:50:42 +01002001 // Only use a text property that can be displayed.
2002 // Skip "after" properties when wrap is off and at the
2003 // end of the window.
2004 if (pt != NULL
2005 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2006 && tp->tp_id != -MAXCOL
2007 && !(tp->tp_id < 0
2008 && !wp->w_p_wrap
2009 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2010 | TP_FLAG_ALIGN_ABOVE
2011 | TP_FLAG_ALIGN_BELOW)) == 0
2012 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002014 if (pt->pt_hl_id > 0)
2015 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 text_prop_type = pt;
2017 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002018 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002019 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002020 text_prop_flags = pt->pt_flags;
2021 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002022 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023 }
2024 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002025 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002026 && -text_prop_id
2027 <= wp->w_buffer->b_textprop_text.ga_len)
2028 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002029 textprop_T *tp = &text_props[used_tpi];
2030 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002031 ->b_textprop_text.ga_data)[
2032 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002033 int above = (tp->tp_flags
2034 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002035 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002036
2037 // reset the ID in the copy to avoid it being used
2038 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002039 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002040
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002041 if (p != NULL)
2042 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002043 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002044 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002045 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002046 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002047 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2048 int padding = tp->tp_col == MAXCOL
2049 && tp->tp_len > 1
2050 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002051
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002052 // Insert virtual text before the current
2053 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002054 wlv.p_extra = p;
2055 wlv.c_extra = NUL;
2056 wlv.c_final = NUL;
2057 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002058 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002059 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2060 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002061 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002062 // restore search_attr and area_attr when n_extra
2063 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002064 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002065 saved_area_attr = area_attr;
2066 search_attr = 0;
2067 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002068 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002069 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002070 if (*ptr == NUL)
2071 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002072 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002073#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002074 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002075 {
2076 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002077 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002078 wlv.need_showbreak = FALSE;
2079 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002080 }
2081#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002082 if ((right || above || below || !wrap
2083 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002084 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002085 char_u *prev_p_extra = wlv.p_extra;
2086 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002087
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002088 // Take care of padding, right-align and
2089 // truncation.
2090 // Shared with win_lbr_chartabsize(), must do
2091 // exactly the same.
2092 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002093 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002094 wlv.col,
2095 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002096 &n_attr, &wlv.n_attr_skip,
2097 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002098 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002099 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002100 // wlv.p_extra was allocated
2101 vim_free(p_extra_free2);
2102 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002103 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002104
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002105 if (lcs_eol_one < 0
2106 && wp->w_p_wrap
2107 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002108 + wlv.n_extra - 2 > wp->w_width)
2109 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002110 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002111
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002112 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002113 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002114 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002115 {
2116 draw_screen_line(wp, &wlv);
2117
2118 // When line got too long for screen break
2119 // here.
2120 if (wlv.row == endrow)
2121 {
2122 ++wlv.row;
2123 break;
2124 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002126 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002127 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002128 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002129 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002130
Bram Moolenaarcd105412022-10-10 19:50:42 +01002131 // If the text didn't reach until the first window
2132 // column we need to skip cells.
2133 if (skip_cells > 0)
2134 {
2135 if (wlv.n_extra > skip_cells)
2136 {
2137 wlv.n_extra -= skip_cells;
2138 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002139 wlv.n_attr_skip -= skip_cells;
2140 if (wlv.n_attr_skip < 0)
2141 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002142 skip_cells = 0;
2143 }
2144 else
2145 {
2146 // the whole text is left of the window, drop
2147 // it and advance to the next one
2148 skip_cells -= wlv.n_extra;
2149 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002150 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002151 bail_out = TRUE;
2152 }
2153 }
2154
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002155 // If another text prop follows the condition below at
2156 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002157 // If this is an "above" text prop and 'nowrap' the we
2158 // must wrap anyway.
2159 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002160 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002161 && (wp->w_p_wrap
2162 || (text_props[other_tpi].tp_flags
2163 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002164
2165 if (bail_out)
2166 // starting a new line for "below"
2167 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002168 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002170 else if (text_prop_next < text_prop_count
2171 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002172 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2173 || (!wp->w_p_wrap
2174 && wlv.col == wp->w_width - 1
2175 && (text_props[text_prop_next].tp_flags
2176 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002177 // When at last-but-one character and a text property
2178 // follows after it, we may need to flush the line after
2179 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002180 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002181 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 }
2183#endif
2184
Bram Moolenaare38fc862022-08-11 17:24:50 +01002185#ifdef FEAT_SEARCH_EXTRA
2186 if (wlv.n_extra == 0)
2187 {
2188 // Check for start/end of 'hlsearch' and other matches.
2189 // After end, check for start/end of next match.
2190 // When another match, have to check for start again.
2191 v = (long)(ptr - line);
2192 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2193 &screen_search_hl, &has_match_conc,
2194 &match_conc, did_line_attr, lcs_eol_one,
2195 &on_last_col);
2196 ptr = line + v; // "line" may have been changed
2197 prev_ptr = ptr;
2198
2199 // Do not allow a conceal over EOL otherwise EOL will be missed
2200 // and bad things happen.
2201 if (*ptr == NUL)
2202 has_match_conc = 0;
2203 }
2204#endif
2205
2206#ifdef FEAT_DIFF
2207 if (wlv.diff_hlf != (hlf_T)0)
2208 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002209 // When there is extra text (e.g. virtual text) it gets the
2210 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002211 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2212 && wlv.n_extra == 0)
2213 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002214 if (wlv.diff_hlf == HLF_TXD
2215 && ((ptr - line > change_end && wlv.n_extra == 0)
2216 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002217 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002218 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002219 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2220 && wp->w_p_culopt_flags != CULOPT_NBR
2221 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2222 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002223 wlv.line_attr = hl_combine_attr(
2224 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002225 }
2226#endif
2227
Bram Moolenaara74fda62019-10-19 17:38:03 +02002228#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002229 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002230 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002231 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002232# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002233 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002234 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002235# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002236 // Get syntax attribute.
2237 if (has_syntax)
2238 {
2239 // Get the syntax attribute for the character. If there
2240 // is an error, disable syntax highlighting.
2241 save_did_emsg = did_emsg;
2242 did_emsg = FALSE;
2243
2244 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002245 if (v == prev_syntax_col)
2246 // at same column again
2247 syntax_attr = prev_syntax_attr;
2248 else
2249 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002250# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002251 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002252# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002253 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002254# ifdef FEAT_SPELL
2255 has_spell ? &can_spell :
2256# endif
2257 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002258 prev_syntax_col = v;
2259 prev_syntax_attr = syntax_attr;
2260 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002261
Bram Moolenaar34390282019-10-16 14:38:26 +02002262 if (did_emsg)
2263 {
2264 wp->w_s->b_syn_error = TRUE;
2265 has_syntax = FALSE;
2266 syntax_attr = 0;
2267 }
2268 else
2269 did_emsg = save_did_emsg;
2270# ifdef SYN_TIME_LIMIT
2271 if (wp->w_s->b_syn_slow)
2272 has_syntax = FALSE;
2273# endif
2274
2275 // Need to get the line again, a multi-line regexp may
2276 // have made it invalid.
2277 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2278 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002279 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002280# ifdef FEAT_CONCEAL
2281 // no concealing past the end of the line, it interferes
2282 // with line highlighting
2283 if (*ptr == NUL)
2284 syntax_flags = 0;
2285 else
2286 syntax_flags = get_syntax_info(&syntax_seqnr);
2287# endif
2288 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002289 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002290# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002291 // Combine text property highlight into syntax highlight.
2292 if (text_prop_type != NULL)
2293 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002294 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002295 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2296 else
2297 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002298 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002299 }
2300# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002301#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002302
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 // Decide which of the highlight attributes to use.
2304 attr_pri = TRUE;
2305#ifdef LINE_ATTR
2306 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002307 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002308 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002309 if (!highlight_match)
2310 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002311 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_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 Moolenaar7528d1f2019-09-19 23:06:20 +02002316 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002317 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002318 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002319# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002320 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002321# endif
2322 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002323 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002324 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2325 || wlv.vcol < wlv.fromcol
2326 || vcol_prev < fromcol_prev
2327 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002329 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002330 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002331# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002332 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002333# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002334 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002335# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002336 attr_pri = FALSE;
2337 }
2338#else
2339 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343#endif
2344 else
2345 {
2346 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002348 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002349#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002350 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002351#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002353#ifdef FEAT_PROP_POPUP
2354 // override with text property highlight when "override" is TRUE
2355 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002356 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002357#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002359
2360 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002361 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002362 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002363 if (wlv.char_attr == 0)
2364 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002365 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002367 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368
2369 // Get the next character to put on the screen.
2370
2371 // The "p_extra" points to the extra stuff that is inserted to
2372 // represent special characters (non-printable stuff) and other
2373 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2376 // "p_extra[n_extra]".
2377 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002382 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2383 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2385 if (enc_utf8 && utf_char2len(c) > 1)
2386 {
2387 mb_utf8 = TRUE;
2388 u8cc[0] = 0;
2389 c = 0xc0;
2390 }
2391 else
2392 mb_utf8 = FALSE;
2393 }
2394 else
2395 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 if (has_mbyte)
2398 {
2399 mb_c = c;
2400 if (enc_utf8)
2401 {
2402 // If the UTF-8 character is more than one byte:
2403 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002404 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002406 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002407 mb_l = 1;
2408 else if (mb_l > 1)
2409 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002410 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002411 mb_utf8 = TRUE;
2412 c = 0xc0;
2413 }
2414 }
2415 else
2416 {
2417 // if this is a DBCS character, put it in "mb_c"
2418 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420 mb_l = 1;
2421 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 }
2424 if (mb_l == 0) // at the NUL at end-of-line
2425 mb_l = 1;
2426
2427 // If a double-width char doesn't fit display a '>' in the
2428 // last column.
2429 if ((
2430# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002431 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002433 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 && (*mb_char2cells)(mb_c) == 2)
2435 {
2436 c = '>';
2437 mb_c = c;
2438 mb_l = 1;
2439 mb_utf8 = FALSE;
2440 multi_attr = HL_ATTR(HLF_AT);
2441#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002442 if (wlv.cul_attr)
2443 multi_attr = hl_combine_attr(
2444 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002445#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002446 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002447
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 // put the pointer back to output the double-width
2449 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002450 ++wlv.n_extra;
2451 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452 }
2453 else
2454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002455 wlv.n_extra -= mb_l - 1;
2456 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 }
2458 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002459 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002460 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002462#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002463 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002464 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002465 // Only restore search_attr and area_attr after "n_extra" in
2466 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002467 if (wlv.saved_n_extra <= 0)
2468 {
2469 if (search_attr == 0)
2470 search_attr = saved_search_attr;
2471 if (area_attr == 0 && *ptr != NUL)
2472 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002473
2474 if (wlv.extra_for_textprop)
2475 // wlv.extra_attr should be used at this position but
2476 // not any further.
2477 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002478 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002479
2480 wlv.extra_for_textprop = FALSE;
2481 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002482 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002483#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002484 }
2485 else
2486 {
2487#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002488 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002489#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002490 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002491
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 // Get a character from the line itself.
2493 c = *ptr;
2494#ifdef FEAT_LINEBREAK
2495 c0 = *ptr;
2496#endif
2497 if (has_mbyte)
2498 {
2499 mb_c = c;
2500 if (enc_utf8)
2501 {
2502 // If the UTF-8 character is more than one byte: Decode it
2503 // into "mb_c".
2504 mb_l = utfc_ptr2len(ptr);
2505 mb_utf8 = FALSE;
2506 if (mb_l > 1)
2507 {
2508 mb_c = utfc_ptr2char(ptr, u8cc);
2509 // Overlong encoded ASCII or ASCII with composing char
2510 // is displayed normally, except a NUL.
2511 if (mb_c < 0x80)
2512 {
2513 c = mb_c;
2514#ifdef FEAT_LINEBREAK
2515 c0 = mb_c;
2516#endif
2517 }
2518 mb_utf8 = TRUE;
2519
2520 // At start of the line we can have a composing char.
2521 // Draw it as a space with a composing char.
2522 if (utf_iscomposing(mb_c))
2523 {
2524 int i;
2525
2526 for (i = Screen_mco - 1; i > 0; --i)
2527 u8cc[i] = u8cc[i - 1];
2528 u8cc[0] = mb_c;
2529 mb_c = ' ';
2530 }
2531 }
2532
2533 if ((mb_l == 1 && c >= 0x80)
2534 || (mb_l >= 1 && mb_c == 0)
2535 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2536 {
2537 // Illegal UTF-8 byte: display as <xx>.
2538 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002539 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540# ifdef FEAT_RIGHTLEFT
2541 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002542 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002544 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 c = *wlv.p_extra;
2546 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002548 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2549 wlv.c_extra = NUL;
2550 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 if (area_attr == 0 && search_attr == 0)
2552 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002553 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002554 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002555 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002556 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558 }
2559 else if (mb_l == 0) // at the NUL at end-of-line
2560 mb_l = 1;
2561#ifdef FEAT_ARABIC
2562 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2563 {
2564 // Do Arabic shaping.
2565 int pc, pc1, nc;
2566 int pcc[MAX_MCO];
2567
2568 // The idea of what is the previous and next
2569 // character depends on 'rightleft'.
2570 if (wp->w_p_rl)
2571 {
2572 pc = prev_c;
2573 pc1 = prev_c1;
2574 nc = utf_ptr2char(ptr + mb_l);
2575 prev_c1 = u8cc[0];
2576 }
2577 else
2578 {
2579 pc = utfc_ptr2char(ptr + mb_l, pcc);
2580 nc = prev_c;
2581 pc1 = pcc[0];
2582 }
2583 prev_c = mb_c;
2584
2585 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2586 }
2587 else
2588 prev_c = mb_c;
2589#endif
2590 }
2591 else // enc_dbcs
2592 {
2593 mb_l = MB_BYTE2LEN(c);
2594 if (mb_l == 0) // at the NUL at end-of-line
2595 mb_l = 1;
2596 else if (mb_l > 1)
2597 {
2598 // We assume a second byte below 32 is illegal.
2599 // Hopefully this is OK for all double-byte encodings!
2600 if (ptr[1] >= 32)
2601 mb_c = (c << 8) + ptr[1];
2602 else
2603 {
2604 if (ptr[1] == NUL)
2605 {
2606 // head byte at end of line
2607 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002608 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 }
2610 else
2611 {
2612 // illegal tail byte
2613 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002614 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002616 wlv.p_extra = wlv.extra;
2617 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 wlv.c_extra = NUL;
2619 wlv.c_final = NUL;
2620 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 if (area_attr == 0 && search_attr == 0)
2622 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002623 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002624 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002625 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 // save current attr
2627 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 }
2629 mb_c = c;
2630 }
2631 }
2632 }
2633 // If a double-width char doesn't fit display a '>' in the
2634 // last column; the character is displayed at the start of the
2635 // next line.
2636 if ((
2637# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002638 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002640 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 && (*mb_char2cells)(mb_c) == 2)
2642 {
2643 c = '>';
2644 mb_c = c;
2645 mb_utf8 = FALSE;
2646 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002647 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 // Put pointer back so that the character will be
2649 // displayed at the start of the next line.
2650 --ptr;
2651#ifdef FEAT_CONCEAL
2652 did_decrement_ptr = TRUE;
2653#endif
2654 }
2655 else if (*ptr != NUL)
2656 ptr += mb_l - 1;
2657
2658 // If a double-width char doesn't fit at the left side display
2659 // a '<' in the first column. Don't do this for unprintable
2660 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002661 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002662 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002663 wlv.n_extra = 1;
2664 wlv.c_extra = MB_FILLER_CHAR;
2665 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666 c = ' ';
2667 if (area_attr == 0 && search_attr == 0)
2668 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002669 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002670 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002671 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002672 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 }
2674 mb_c = c;
2675 mb_utf8 = FALSE;
2676 mb_l = 1;
2677 }
2678
2679 }
2680 ++ptr;
2681
2682 if (extra_check)
2683 {
2684#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685 // Check spelling (unless at the end of the line).
2686 // Only do this when there is no syntax highlighting, the
2687 // @Spell cluster is not used or the current syntax item
2688 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002689 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 if (has_spell && v >= word_end && v > cur_checked_col)
2691 {
2692 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002693 // do not calculate cap_col at the end of the line or when
2694 // only white space is following
2695 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696# ifdef FEAT_SYN_HL
2697 !has_syntax ||
2698# endif
2699 can_spell))
2700 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002701 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 int len;
2703 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002704
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707
2708 // Use nextline[] if possible, it has the start of the
2709 // next line concatenated.
2710 if ((prev_ptr - line) - nextlinecol >= 0)
2711 p = nextline + (prev_ptr - line) - nextlinecol;
2712 else
2713 p = prev_ptr;
2714 cap_col -= (int)(prev_ptr - line);
2715 len = spell_check(wp, p, &spell_hlf, &cap_col,
2716 nochange);
2717 word_end = v + len;
2718
2719 // In Insert mode only highlight a word that
2720 // doesn't touch the cursor.
2721 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002722 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723 && wp->w_cursor.lnum == lnum
2724 && wp->w_cursor.col >=
2725 (colnr_T)(prev_ptr - line)
2726 && wp->w_cursor.col < (colnr_T)word_end)
2727 {
2728 spell_hlf = HLF_COUNT;
2729 spell_redraw_lnum = lnum;
2730 }
2731
2732 if (spell_hlf == HLF_COUNT && p != prev_ptr
2733 && (p - nextline) + len > nextline_idx)
2734 {
2735 // Remember that the good word continues at the
2736 // start of the next line.
2737 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002738 checked_col = (int)((p - nextline)
2739 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 }
2741
2742 // Turn index into actual attributes.
2743 if (spell_hlf != HLF_COUNT)
2744 spell_attr = highlight_attr[spell_hlf];
2745
2746 if (cap_col > 0)
2747 {
2748 if (p != prev_ptr
2749 && (p - nextline) + cap_col >= nextline_idx)
2750 {
2751 // Remember that the word in the next line
2752 // must start with a capital.
2753 capcol_lnum = lnum + 1;
2754 cap_col = (int)((p - nextline) + cap_col
2755 - nextline_idx);
2756 }
2757 else
2758 // Compute the actual column.
2759 cap_col += (int)(prev_ptr - line);
2760 }
2761 }
2762 }
2763 if (spell_attr != 0)
2764 {
2765 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002766 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2767 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002769 wlv.char_attr = hl_combine_attr(spell_attr,
2770 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 }
2772#endif
2773#ifdef FEAT_LINEBREAK
2774 // Found last space before word: check for line break.
2775 if (wp->w_p_lbr && c0 == c
2776 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2777 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002778 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2779 : 0;
2780 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002781 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002783 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002784# ifdef FEAT_PROP_POPUP
2785 // do not want virtual text counted here
2786 cts.cts_has_prop_with_text = FALSE;
2787# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002788 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002789 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002790
2791 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002792 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002793 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002794 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002795 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2796 if (wlv.n_extra < 0)
2797 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002798 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002799 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002800 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002801 // line break, but for TABs the highlighting should
2802 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002803 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002804
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002807 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002808 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 wp->w_buffer->b_p_vts_array) - 1;
2810# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002812 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813# endif
2814
Bram Moolenaar1306b362022-08-06 15:59:06 +01002815 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2816 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002817# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002819 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002820# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 if (VIM_ISWHITE(c))
2822 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002823# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 if (c == TAB)
2825 // See "Tab alignment" below.
2826 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002827# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828 if (!wp->w_p_list)
2829 c = ' ';
2830 }
2831 }
2832#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002833 in_multispace = c == ' '
2834 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2835 if (!in_multispace)
2836 multispace_pos = 0;
2837
Bram Moolenaareed9d462021-02-15 20:38:25 +01002838 // 'list': Change char 160 to 'nbsp' and space to 'space'
2839 // setting in 'listchars'. But not when the character is
2840 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 if (wp->w_p_list
2842 && ((((c == 160 && mb_l == 1)
2843 || (mb_utf8
2844 && ((mb_c == 160 && mb_l == 2)
2845 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002846 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 || (c == ' '
2848 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002849 && (wp->w_lcs_chars.space
2850 || (in_multispace
2851 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002852 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 && ptr - line <= trailcol)))
2854 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002855 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2856 {
2857 c = wp->w_lcs_chars.multispace[multispace_pos++];
2858 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2859 multispace_pos = 0;
2860 }
2861 else
2862 c = (c == ' ') ? wp->w_lcs_chars.space
2863 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864 if (area_attr == 0 && search_attr == 0)
2865 {
2866 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002867 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002868 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 }
2871 mb_c = c;
2872 if (enc_utf8 && utf_char2len(c) > 1)
2873 {
2874 mb_utf8 = TRUE;
2875 u8cc[0] = 0;
2876 c = 0xc0;
2877 }
2878 else
2879 mb_utf8 = FALSE;
2880 }
2881
zeertzjq2e7cba32022-06-10 15:30:32 +01002882 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2883 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002885 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2886 && wp->w_lcs_chars.leadmultispace != NULL)
2887 {
2888 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002889 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2890 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002891 multispace_pos = 0;
2892 }
2893
2894 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2895 c = wp->w_lcs_chars.trail;
2896
2897 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2898 c = wp->w_lcs_chars.lead;
2899
zeertzjq2e7cba32022-06-10 15:30:32 +01002900 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002901 c = wp->w_lcs_chars.space;
2902
2903
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 if (!attr_pri)
2905 {
2906 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002907 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002908 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002909 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 }
2911 mb_c = c;
2912 if (enc_utf8 && utf_char2len(c) > 1)
2913 {
2914 mb_utf8 = TRUE;
2915 u8cc[0] = 0;
2916 c = 0xc0;
2917 }
2918 else
2919 mb_utf8 = FALSE;
2920 }
2921 }
2922
2923 // Handling of non-printable characters.
2924 if (!vim_isprintc(c))
2925 {
2926 // when getting a character from the file, we may have to
2927 // turn it into something else on the way to putting it
2928 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002929 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002931 int tab_len = 0;
2932 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002934 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002935
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 // only adjust the tab_len, when at the first column
2937 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002938 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002939 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940#endif
2941 // tab amount depends on current column
2942#ifdef FEAT_VARTABS
2943 tab_len = tabstop_padding(vcol_adjusted,
2944 wp->w_buffer->b_p_ts,
2945 wp->w_buffer->b_p_vts_array) - 1;
2946#else
2947 tab_len = (int)wp->w_buffer->b_p_ts
2948 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2949#endif
2950
2951#ifdef FEAT_LINEBREAK
2952 if (!wp->w_p_lbr || !wp->w_p_list)
2953#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002954 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002956 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002957 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958#ifdef FEAT_LINEBREAK
2959 else
2960 {
2961 char_u *p;
2962 int len;
2963 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002964 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002966# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002967 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002969 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002970
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002972 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002973 && old_boguscols > 0
2974 && wlv.n_extra > tab_len)
2975 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002976# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002977 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002979 // If wlv.n_extra > 0, it gives the number of chars
2980 // to use for a tab, else we need to calculate the
2981 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002982 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2983 len = tab_len * tab2_len;
2984 if (wp->w_lcs_chars.tab3)
2985 len += mb_char2len(wp->w_lcs_chars.tab3)
2986 - tab2_len;
2987 if (wlv.n_extra > 0)
2988 len += wlv.n_extra - tab_len;
2989 c = wp->w_lcs_chars.tab1;
2990 p = alloc(len + 1);
2991 if (p == NULL)
2992 wlv.n_extra = 0;
2993 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002994 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002995 vim_memset(p, ' ', len);
2996 p[len] = NUL;
2997 vim_free(wlv.p_extra_free);
2998 wlv.p_extra_free = p;
2999 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003000 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003001 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003002
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003003 if (*p == NUL)
3004 {
3005 tab_len = i;
3006 break;
3007 }
3008
3009 // if tab3 is given, use it for the last
3010 // char
3011 if (wp->w_lcs_chars.tab3
3012 && i == tab_len - 1)
3013 lcs = wp->w_lcs_chars.tab3;
3014 p += mb_char2bytes(lcs, p);
3015 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003017 }
3018 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003019# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003020 // n_extra will be increased by
3021 // FIX_FOX_BOGUSCOLS macro below, so need to
3022 // adjust for that here
3023 if (wlv.vcol_off > 0)
3024 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003025# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003026 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 }
3029#endif
3030#ifdef FEAT_CONCEAL
3031 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003032 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033
3034 // Tab alignment should be identical regardless of
3035 // 'conceallevel' value. So tab compensates of all
3036 // previous concealed characters, and thus resets
3037 // vcol_off and boguscols accumulated so far in the
3038 // line. Note that the tab can be longer than
3039 // 'tabstop' when there are concealed characters.
3040 FIX_FOR_BOGUSCOLS;
3041
3042 // Make sure, the highlighting for the tab char will be
3043 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003044 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003046 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 tab_len += vc_saved;
3048 }
3049#endif
3050 mb_utf8 = FALSE; // don't draw as UTF-8
3051 if (wp->w_p_list)
3052 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003053 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003054 ? wp->w_lcs_chars.tab3
3055 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003056#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003057 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 else
3060#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003061 wlv.c_extra = wp->w_lcs_chars.tab2;
3062 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003064 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003065 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003066 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003067 mb_c = c;
3068 if (enc_utf8 && utf_char2len(c) > 1)
3069 {
3070 mb_utf8 = TRUE;
3071 u8cc[0] = 0;
3072 c = 0xc0;
3073 }
3074 }
3075 else
3076 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 wlv.c_final = NUL;
3078 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 c = ' ';
3080 }
3081 }
3082 else if (c == NUL
3083 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003084 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3085 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 && VIsual_mode != Ctrl_V
3087 && (
3088# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003089 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003091 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 && !(noinvcur
3093 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003094 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 && lcs_eol_one > 0)
3096 {
3097 // Display a '$' after the line or highlight an extra
3098 // character if the line break is included.
3099#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3100 // For a diff line the highlighting continues after the
3101 // "$".
3102 if (
3103# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003104 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105# ifdef LINE_ATTR
3106 &&
3107# endif
3108# endif
3109# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003110 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111# endif
3112 )
3113#endif
3114 {
3115 // In virtualedit, visual selections may extend
3116 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003117 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003118 && wlv.tocol != MAXCOL
3119 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003120 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003121 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003123 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3124 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003125 else
3126 c = ' ';
3127 lcs_eol_one = -1;
3128 --ptr; // put it back at the NUL
3129 if (!attr_pri)
3130 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003131 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003132 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133 n_attr = 1;
3134 }
3135 mb_c = c;
3136 if (enc_utf8 && utf_char2len(c) > 1)
3137 {
3138 mb_utf8 = TRUE;
3139 u8cc[0] = 0;
3140 c = 0xc0;
3141 }
3142 else
3143 mb_utf8 = FALSE; // don't draw as UTF-8
3144 }
3145 else if (c != NUL)
3146 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003147 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3148 if (wlv.n_extra == 0)
3149 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150#ifdef FEAT_RIGHTLEFT
3151 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 wlv.c_extra = NUL;
3155 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156#ifdef FEAT_LINEBREAK
3157 if (wp->w_p_lbr)
3158 {
3159 char_u *p;
3160
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 c = *wlv.p_extra;
3162 p = alloc(wlv.n_extra + 1);
3163 vim_memset(p, ' ', wlv.n_extra);
3164 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3165 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003166 vim_free(wlv.p_extra_free);
3167 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 }
3169 else
3170#endif
3171 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003172 wlv.n_extra = byte2cells(c) - 1;
3173 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 }
3175 if (!attr_pri)
3176 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003178 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003179 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 }
3182 mb_utf8 = FALSE; // don't draw as UTF-8
3183 }
3184 else if (VIsual_active
3185 && (VIsual_mode == Ctrl_V
3186 || VIsual_mode == 'v')
3187 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003188 && wlv.tocol != MAXCOL
3189 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 && (
3191#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003192 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003194 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003195 {
3196 c = ' ';
3197 --ptr; // put it back at the NUL
3198 }
3199#if defined(LINE_ATTR)
3200 else if ((
3201# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003202 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203# endif
3204# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003205 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003206# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003207 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 ) && (
3209# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003210 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003212 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003214 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003215# endif
3216 < wp->w_width)))
3217 {
3218 // Highlight until the right side of the window
3219 c = ' ';
3220 --ptr; // put it back at the NUL
3221
3222 // Remember we do the char for line highlighting.
3223 ++did_line_attr;
3224
3225 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003226 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003228 || (wp->w_p_list &&
3229 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003230 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003232 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003234 wlv.diff_hlf = HLF_CHD;
3235 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3239 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003240 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003241 || (wlv.vcol >= left_curline_col
3242 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003243 wlv.char_attr = hl_combine_attr(
3244 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 }
3246 }
3247# endif
3248# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003251 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003252 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3253 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003254 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 if (!wlv.cul_screenline
3256 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003257 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003258 wlv.char_attr = hl_combine_attr(
3259 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003261 else if (wlv.line_attr)
3262 wlv.char_attr = hl_combine_attr(
3263 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265# endif
3266 }
3267#endif
3268 }
3269
3270#ifdef FEAT_CONCEAL
3271 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003272 && (wp != curwin || lnum != wp->w_cursor.lnum
3273 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3275 && !(lnum_in_visual_area
3276 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3277 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003279 if (((prev_syntax_id != syntax_seqnr
3280 && (syntax_flags & HL_CONCEAL) != 0)
3281 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003282 && (syn_get_sub_char() != NUL
3283 || (has_match_conc && match_conc)
3284 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 && wp->w_p_cole != 3)
3286 {
3287 // First time at this concealed item: display one
3288 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003289 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 c = match_conc;
3291 else if (syn_get_sub_char() != NUL)
3292 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003293 else if (wp->w_lcs_chars.conceal != NUL)
3294 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 else
3296 c = ' ';
3297
3298 prev_syntax_id = syntax_seqnr;
3299
Bram Moolenaar1306b362022-08-06 15:59:06 +01003300 if (wlv.n_extra > 0)
3301 wlv.vcol_off += wlv.n_extra;
3302 wlv.vcol += wlv.n_extra;
3303 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 {
3305# ifdef FEAT_RIGHTLEFT
3306 if (wp->w_p_rl)
3307 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003308 wlv.col -= wlv.n_extra;
3309 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 }
3311 else
3312# endif
3313 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003314 wlv.boguscols += wlv.n_extra;
3315 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 }
3317 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003318 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 n_attr = 0;
3320 }
3321 else if (n_skip == 0)
3322 {
3323 is_concealing = TRUE;
3324 n_skip = 1;
3325 }
3326 mb_c = c;
3327 if (enc_utf8 && utf_char2len(c) > 1)
3328 {
3329 mb_utf8 = TRUE;
3330 u8cc[0] = 0;
3331 c = 0xc0;
3332 }
3333 else
3334 mb_utf8 = FALSE; // don't draw as UTF-8
3335 }
3336 else
3337 {
3338 prev_syntax_id = 0;
3339 is_concealing = FALSE;
3340 }
3341
3342 if (n_skip > 0 && did_decrement_ptr)
3343 // not showing the '>', put pointer back to avoid getting stuck
3344 ++ptr;
3345
3346#endif // FEAT_CONCEAL
3347 }
3348
3349#ifdef FEAT_CONCEAL
3350 // In the cursor line and we may be concealing characters: correct
3351 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 && wp == curwin && lnum == wp->w_cursor.lnum
3354 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003355 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003357# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003359 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003360 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003361# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003362 wp->w_wcol = wlv.col - wlv.boguscols;
3363 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364 did_wcol = TRUE;
3365 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003366# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003367 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003368# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 }
3370#endif
3371
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003372 // Use "wlv.extra_attr", but don't override visual selection
3373 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003374 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3375 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003377 && (!attr_pri
3378#ifdef FEAT_PROP_POPUP
3379 || (text_prop_flags & PT_FLAG_OVERRIDE)
3380#endif
3381 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 {
3383#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003384 if (wlv.line_attr)
3385 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 else
3387#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003388 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003389#ifdef FEAT_PROP_POPUP
3390 if (reset_extra_attr)
3391 {
3392 reset_extra_attr = FALSE;
3393 wlv.extra_attr = 0;
3394 }
3395#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 }
3397
3398#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3399 // XIM don't send preedit_start and preedit_end, but they send
3400 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3401 // im_is_preediting() here.
3402 if (p_imst == IM_ON_THE_SPOT
3403 && xic != NULL
3404 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003405 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 && !p_imdisable
3407 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003408 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 {
3410 colnr_T tcol;
3411
3412 if (preedit_end_col == MAXCOL)
3413 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3414 else
3415 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003416 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417 {
3418 if (feedback_old_attr < 0)
3419 {
3420 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003421 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 wlv.char_attr = im_get_feedback_attr(feedback_col);
3424 if (wlv.char_attr < 0)
3425 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 feedback_col++;
3427 }
3428 else if (feedback_old_attr >= 0)
3429 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003430 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431 feedback_old_attr = -1;
3432 feedback_col = 0;
3433 }
3434 }
3435#endif
3436 // Handle the case where we are in column 0 but not on the first
3437 // character of the line and the user wants us to show us a
3438 // special character (via 'listchars' option "precedes:<char>".
3439 if (lcs_prec_todo != NUL
3440 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003441 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3442 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003444 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003446 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 && c != NUL)
3448 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003449 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 lcs_prec_todo = NUL;
3451 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3452 {
3453 // Double-width character being overwritten by the "precedes"
3454 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 wlv.c_extra = MB_FILLER_CHAR;
3456 wlv.c_final = NUL;
3457 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003459 wlv.extra_attr =
3460 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
3462 mb_c = c;
3463 if (enc_utf8 && utf_char2len(c) > 1)
3464 {
3465 mb_utf8 = TRUE;
3466 u8cc[0] = 0;
3467 c = 0xc0;
3468 }
3469 else
3470 mb_utf8 = FALSE; // don't draw as UTF-8
3471 if (!attr_pri)
3472 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003473 saved_attr3 = wlv.char_attr; // save current attr
3474 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 n_attr3 = 1;
3476 }
3477 }
3478
3479 // At end of the text line or just after the last character.
3480 if ((c == NUL
3481#if defined(LINE_ATTR)
3482 || did_line_attr == 1
3483#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003484 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 {
3486#ifdef FEAT_SEARCH_EXTRA
3487 // flag to indicate whether prevcol equals startcol of search_hl or
3488 // one of the matches
3489 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3490 (long)(ptr - line) - (c == NUL));
3491#endif
3492 // Invert at least one char, used for Visual and empty line or
3493 // highlight match at end of line. If it's beyond the last
3494 // char on the screen, just overwrite that one (tricky!) Not
3495 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003496 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003497 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 && (VIsual_mode != Ctrl_V
3499 || lnum == VIsual.lnum
3500 || lnum == curwin->w_cursor.lnum)
3501 && c == NUL)
3502#ifdef FEAT_SEARCH_EXTRA
3503 // highlight 'hlsearch' match at end of line
3504 || (prevcol_hl_flag
3505# ifdef FEAT_SYN_HL
3506 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3507 && !(wp == curwin && VIsual_active))
3508# endif
3509# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511# endif
3512# if defined(LINE_ATTR)
3513 && did_line_attr <= 1
3514# endif
3515 )
3516#endif
3517 ))
3518 {
3519 int n = 0;
3520
3521#ifdef FEAT_RIGHTLEFT
3522 if (wp->w_p_rl)
3523 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003524 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003525 n = 1;
3526 }
3527 else
3528#endif
3529 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003530 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003531 n = -1;
3532 }
3533 if (n != 0)
3534 {
3535 // At the window boundary, highlight the last character
3536 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003537 wlv.off += n;
3538 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539 }
3540 else
3541 {
3542 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003543 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003545 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547#ifdef FEAT_SEARCH_EXTRA
3548 if (area_attr == 0)
3549 {
3550 // Use attributes from match with highest priority among
3551 // 'search_hl' and the match list.
3552 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003553 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003554 }
3555#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003556 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003557 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558#ifdef FEAT_RIGHTLEFT
3559 if (wp->w_p_rl)
3560 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003561 --wlv.col;
3562 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564 else
3565#endif
3566 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 ++wlv.col;
3568 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003570 ++wlv.vcol;
3571 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 }
3573 }
3574
3575 // At end of the text line.
3576 if (c == NUL)
3577 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579
3580 // Update w_cline_height and w_cline_folded if the cursor line was
3581 // updated (saves a call to plines() later).
3582 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3583 {
3584 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586#ifdef FEAT_FOLDING
3587 curwin->w_cline_folded = FALSE;
3588#endif
3589 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3590 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 break;
3592 }
3593
3594 // Show "extends" character from 'listchars' if beyond the line end and
3595 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003596 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003597 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 && wp->w_p_list
3599 && !wp->w_p_wrap
3600#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003601 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003602#endif
3603 && (
3604#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003605 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003609 || lcs_eol_one > 0
3610 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003611 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003613 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003614 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 mb_c = c;
3616 if (enc_utf8 && utf_char2len(c) > 1)
3617 {
3618 mb_utf8 = TRUE;
3619 u8cc[0] = 0;
3620 c = 0xc0;
3621 }
3622 else
3623 mb_utf8 = FALSE;
3624 }
3625
3626#ifdef FEAT_SYN_HL
3627 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 if (wlv.draw_color_col)
3629 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630
3631 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3632 // highlight the cursor position itself.
3633 // Also highlight the 'colorcolumn' if it is different than
3634 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003635 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3636 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003638 if (((wlv.draw_state == WL_LINE
3639 || wlv.draw_state == WL_BRI
3640 || wlv.draw_state == WL_SBR)
3641 && !lnum_in_visual_area
3642 && search_attr == 0
3643 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003644# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003645 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003646# endif
3647 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 {
3649 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3650 && lnum != wp->w_cursor.lnum)
3651 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003652 vcol_save_attr = wlv.char_attr;
3653 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3654 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003656 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003657 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003658 vcol_save_attr = wlv.char_attr;
3659 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
3661 }
3662#endif
3663
3664 // Store character to be displayed.
3665 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003666 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003667 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003668 {
3669 // Store the character.
3670#if defined(FEAT_RIGHTLEFT)
3671 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3672 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003673 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003674 --wlv.off;
3675 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 }
3677#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 if (enc_dbcs == DBCS_JPNU)
3680 {
3681 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003682 ScreenLines[wlv.off] = 0x8e;
3683 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003684 }
3685 else if (enc_utf8)
3686 {
3687 if (mb_utf8)
3688 {
3689 int i;
3690
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003693 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 for (i = 0; i < Screen_mco; ++i)
3695 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003696 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 if (u8cc[i] == 0)
3698 break;
3699 }
3700 }
3701 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003702 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 }
3704 if (multi_attr)
3705 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003706 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 multi_attr = 0;
3708 }
3709 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003710 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003712 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003713
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3715 {
3716 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 ++wlv.off;
3718 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719 if (enc_utf8)
3720 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003722 else
3723 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003724 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003726#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003727 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728#endif
3729 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003731 // When "wlv.tocol" is halfway a character, set it to the end
3732 // of the character, otherwise highlighting won't stop.
3733 if (wlv.tocol == wlv.vcol)
3734 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003735
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003736 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003737
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738#ifdef FEAT_RIGHTLEFT
3739 if (wp->w_p_rl)
3740 {
3741 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 --wlv.off;
3743 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 }
3745#endif
3746 }
3747#ifdef FEAT_RIGHTLEFT
3748 if (wp->w_p_rl)
3749 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 --wlv.off;
3751 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003752 }
3753 else
3754#endif
3755 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ++wlv.off;
3757 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 }
3759 }
3760#ifdef FEAT_CONCEAL
3761 else if (wp->w_p_cole > 0 && is_concealing)
3762 {
3763 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003764 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003765 if (wlv.n_extra > 0)
3766 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 if (wp->w_p_wrap)
3768 {
3769 // Special voodoo required if 'wrap' is on.
3770 //
3771 // Advance the column indicator to force the line
3772 // drawing to wrap early. This will make the line
3773 // take up the same screen space when parts are concealed,
3774 // so that cursor line computations aren't messed up.
3775 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777 // trailing junk to be written out of the screen line
3778 // we are building, 'boguscols' keeps track of the number
3779 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003780 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003782 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783# ifdef FEAT_RIGHTLEFT
3784 if (wp->w_p_rl)
3785 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 wlv.col -= wlv.n_extra;
3787 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 }
3789 else
3790# endif
3791 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003792 wlv.col += wlv.n_extra;
3793 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003795 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003796 n_attr = 0;
3797 }
3798
3799
3800 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3801 {
3802 // Need to fill two screen columns.
3803# ifdef FEAT_RIGHTLEFT
3804 if (wp->w_p_rl)
3805 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 --wlv.boguscols;
3807 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808 }
3809 else
3810# endif
3811 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003812 ++wlv.boguscols;
3813 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814 }
3815 }
3816
3817# ifdef FEAT_RIGHTLEFT
3818 if (wp->w_p_rl)
3819 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003820 --wlv.boguscols;
3821 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822 }
3823 else
3824# endif
3825 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003826 ++wlv.boguscols;
3827 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003828 }
3829 }
3830 else
3831 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003832 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003834 wlv.vcol += wlv.n_extra;
3835 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836 n_attr = 0;
3837 }
3838 }
3839
3840 }
3841#endif // FEAT_CONCEAL
3842 else
3843 --n_skip;
3844
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003845 // Only advance the "wlv.vcol" when after the 'number' or
3846 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003847 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003848#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003849 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003850#endif
3851 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003852 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853
3854#ifdef FEAT_SYN_HL
3855 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003856 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857#endif
3858
3859 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003860 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3861 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862
3863 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003864 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003865 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003866 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003867 if (wlv.n_attr_skip > 0)
3868 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003869
3870 // At end of screen line and there is more to come: Display the line
3871 // so far. If there is no more to display it is caught above.
3872 if ((
3873#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003874 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003876 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003877 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003878 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003879#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003880 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003882#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003883 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003884#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003885 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 && wlv.p_extra != at_end_str)
3887 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3888 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889 )
3890 {
3891#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003892 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003893 wlv_screen_line(wp, &wlv, FALSE);
3894 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003895 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003897 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 ++wlv.row;
3900 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901
3902 // When not wrapping and finished diff lines, or when displayed
3903 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003904 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003905#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003906 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003907#endif
3908#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003909 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003911 ) || lcs_eol_one == -1)
3912#ifdef FEAT_PROP_POPUP
3913 && !text_prop_follows
3914#endif
3915 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003917#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003918 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003919 {
3920 // do not output more of the line, only the "below" prop
3921 ptr += STRLEN(ptr);
3922# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003923 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003924# endif
3925 }
3926#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927
3928 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003929 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003930#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003931 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932#endif
3933 )
3934 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003935 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3936 draw_vsep_win(wp, wlv.row);
3937 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938 }
3939
3940 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003941 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003942 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 break;
3945 }
3946
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003947 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003949 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003951#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003952 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003953#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003954 && wp->w_width == Columns)
3955 {
3956 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003957 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958
3959 // Special trick to make copy/paste of wrapped lines work with
3960 // xterm/screen: write an extra character beyond the end of
3961 // the line. This will work with all terminal types
3962 // (regardless of the xn,am settings).
3963 // Only do this on a fast tty.
3964 // Only do this if the cursor is on the current line
3965 // (something has been written in it).
3966 // Don't do this for the GUI.
3967 // Don't do this for double-width characters.
3968 // Don't do this for a window not at the right screen border.
3969 if (p_tf
3970#ifdef FEAT_GUI
3971 && !gui.in_use
3972#endif
3973 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003974 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3975 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003977 || (*mb_off2cells)(
3978 LineOffset[wlv.screen_row - 1]
3979 + (int)Columns - 2,
3980 LineOffset[wlv.screen_row]
3981 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 {
3983 // First make sure we are at the end of the screen line,
3984 // then output the same character again to let the
3985 // terminal know about the wrap. If the terminal doesn't
3986 // auto-wrap, we overwrite the character.
3987 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003988 screen_char(LineOffset[wlv.screen_row - 1]
3989 + (unsigned)Columns - 1,
3990 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991
3992 // When there is a multi-byte character, just output a
3993 // space to keep it simple.
3994 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003995 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996 out_char(' ');
3997 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003998 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003999 + (Columns - 1)]);
4000 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004001 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002 screen_start(); // don't know where cursor is now
4003 }
4004 }
4005
Bram Moolenaar1306b362022-08-06 15:59:06 +01004006 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004007
Bram Moolenaareed9d462021-02-15 20:38:25 +01004008 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004010 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004012 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004013# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004014 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004015 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016#endif
4017#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004018 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004019 // When the filler lines are actually below the last line of the
4020 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004021 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004022 break;
4023#endif
4024 }
4025
4026 } // for every character in the line
4027
4028#ifdef FEAT_SPELL
4029 // After an empty line check first word for capital.
4030 if (*skipwhite(line) == NUL)
4031 {
4032 capcol_lnum = lnum + 1;
4033 cap_col = 0;
4034 }
4035#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004036#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 vim_free(text_props);
4038 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004039 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040#endif
4041
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004042 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044}