blob: b4208a833c7025fd658581636c1a483973d683ee [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);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000646 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 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 Moolenaar51b2fc22023-01-21 15:54:59 +00002019 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2020 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002021 text_prop_flags = pt->pt_flags;
2022 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002023 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024 }
2025 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002027 && -text_prop_id
2028 <= wp->w_buffer->b_textprop_text.ga_len)
2029 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002030 textprop_T *tp = &text_props[used_tpi];
2031 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002032 ->b_textprop_text.ga_data)[
2033 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002034 int above = (tp->tp_flags
2035 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002036 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002037
2038 // reset the ID in the copy to avoid it being used
2039 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002040 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002041
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002042 if (p != NULL)
2043 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002044 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002045 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002046 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002047 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002048 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2049 int padding = tp->tp_col == MAXCOL
2050 && tp->tp_len > 1
2051 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002052
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002053 // Insert virtual text before the current
2054 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002055 wlv.p_extra = p;
2056 wlv.c_extra = NUL;
2057 wlv.c_final = NUL;
2058 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002059 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002060 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2061 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002062 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002063 // restore search_attr and area_attr when n_extra
2064 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002065 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002066 saved_area_attr = area_attr;
2067 search_attr = 0;
2068 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002069 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002070 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002071 if (*ptr == NUL)
2072 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002073 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002074#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002075 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002076 {
2077 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002078 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002079 wlv.need_showbreak = FALSE;
2080 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002081 }
2082#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002083 if ((right || above || below || !wrap
2084 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002085 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002086 char_u *prev_p_extra = wlv.p_extra;
2087 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002088
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002089 // Take care of padding, right-align and
2090 // truncation.
2091 // Shared with win_lbr_chartabsize(), must do
2092 // exactly the same.
2093 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002094 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002095 wlv.col,
2096 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002097 &n_attr, &wlv.n_attr_skip,
2098 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002099 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002100 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002101 // wlv.p_extra was allocated
2102 vim_free(p_extra_free2);
2103 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002104 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002105
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002106 if (lcs_eol_one < 0
2107 && wp->w_p_wrap
2108 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002109 + wlv.n_extra - 2 > wp->w_width)
2110 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002111 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002112
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002113 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002114 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002115 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002116 {
2117 draw_screen_line(wp, &wlv);
2118
2119 // When line got too long for screen break
2120 // here.
2121 if (wlv.row == endrow)
2122 {
2123 ++wlv.row;
2124 break;
2125 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002126 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002127 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002128 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002129 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002130 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002131
Bram Moolenaarcd105412022-10-10 19:50:42 +01002132 // If the text didn't reach until the first window
2133 // column we need to skip cells.
2134 if (skip_cells > 0)
2135 {
2136 if (wlv.n_extra > skip_cells)
2137 {
2138 wlv.n_extra -= skip_cells;
2139 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002140 wlv.n_attr_skip -= skip_cells;
2141 if (wlv.n_attr_skip < 0)
2142 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002143 skip_cells = 0;
2144 }
2145 else
2146 {
2147 // the whole text is left of the window, drop
2148 // it and advance to the next one
2149 skip_cells -= wlv.n_extra;
2150 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002151 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002152 bail_out = TRUE;
2153 }
2154 }
2155
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002156 // If another text prop follows the condition below at
2157 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002158 // If this is an "above" text prop and 'nowrap' the we
2159 // must wrap anyway.
2160 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002161 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002162 && (wp->w_p_wrap
2163 || (text_props[other_tpi].tp_flags
2164 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002165
2166 if (bail_out)
2167 // starting a new line for "below"
2168 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002171 else if (text_prop_next < text_prop_count
2172 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002173 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2174 || (!wp->w_p_wrap
2175 && wlv.col == wp->w_width - 1
2176 && (text_props[text_prop_next].tp_flags
2177 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002178 // When at last-but-one character and a text property
2179 // follows after it, we may need to flush the line after
2180 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002181 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002182 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002183 }
2184#endif
2185
Bram Moolenaare38fc862022-08-11 17:24:50 +01002186#ifdef FEAT_SEARCH_EXTRA
2187 if (wlv.n_extra == 0)
2188 {
2189 // Check for start/end of 'hlsearch' and other matches.
2190 // After end, check for start/end of next match.
2191 // When another match, have to check for start again.
2192 v = (long)(ptr - line);
2193 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2194 &screen_search_hl, &has_match_conc,
2195 &match_conc, did_line_attr, lcs_eol_one,
2196 &on_last_col);
2197 ptr = line + v; // "line" may have been changed
2198 prev_ptr = ptr;
2199
2200 // Do not allow a conceal over EOL otherwise EOL will be missed
2201 // and bad things happen.
2202 if (*ptr == NUL)
2203 has_match_conc = 0;
2204 }
2205#endif
2206
2207#ifdef FEAT_DIFF
2208 if (wlv.diff_hlf != (hlf_T)0)
2209 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002210 // When there is extra text (e.g. virtual text) it gets the
2211 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002212 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2213 && wlv.n_extra == 0)
2214 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002215 if (wlv.diff_hlf == HLF_TXD
2216 && ((ptr - line > change_end && wlv.n_extra == 0)
2217 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002218 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002219 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002220 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2221 && wp->w_p_culopt_flags != CULOPT_NBR
2222 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2223 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002224 wlv.line_attr = hl_combine_attr(
2225 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002226 }
2227#endif
2228
Bram Moolenaara74fda62019-10-19 17:38:03 +02002229#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002230 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002231 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002232 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002233# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002234 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002235 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002236# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002237 // Get syntax attribute.
2238 if (has_syntax)
2239 {
2240 // Get the syntax attribute for the character. If there
2241 // is an error, disable syntax highlighting.
2242 save_did_emsg = did_emsg;
2243 did_emsg = FALSE;
2244
2245 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002246 if (v == prev_syntax_col)
2247 // at same column again
2248 syntax_attr = prev_syntax_attr;
2249 else
2250 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002251# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002252 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002253# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002254 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002255# ifdef FEAT_SPELL
2256 has_spell ? &can_spell :
2257# endif
2258 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002259 prev_syntax_col = v;
2260 prev_syntax_attr = syntax_attr;
2261 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002262
Bram Moolenaar34390282019-10-16 14:38:26 +02002263 if (did_emsg)
2264 {
2265 wp->w_s->b_syn_error = TRUE;
2266 has_syntax = FALSE;
2267 syntax_attr = 0;
2268 }
2269 else
2270 did_emsg = save_did_emsg;
2271# ifdef SYN_TIME_LIMIT
2272 if (wp->w_s->b_syn_slow)
2273 has_syntax = FALSE;
2274# endif
2275
2276 // Need to get the line again, a multi-line regexp may
2277 // have made it invalid.
2278 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2279 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002280 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002281# ifdef FEAT_CONCEAL
2282 // no concealing past the end of the line, it interferes
2283 // with line highlighting
2284 if (*ptr == NUL)
2285 syntax_flags = 0;
2286 else
2287 syntax_flags = get_syntax_info(&syntax_seqnr);
2288# endif
2289 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002290 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002291# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002292 // Combine text property highlight into syntax highlight.
2293 if (text_prop_type != NULL)
2294 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002295 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002296 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2297 else
2298 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002299 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002300 }
2301# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002302#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002303
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304 // Decide which of the highlight attributes to use.
2305 attr_pri = TRUE;
2306#ifdef LINE_ATTR
2307 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002308 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002309 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002310 if (!highlight_match)
2311 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002312 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002313# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002314 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002315# endif
2316 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002318 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002319 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002320# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002321 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002322# endif
2323 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002324 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002325 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2326 || wlv.vcol < wlv.fromcol
2327 || vcol_prev < fromcol_prev
2328 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002330 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002332# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002333 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002334# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002335 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002336# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 attr_pri = FALSE;
2338 }
2339#else
2340 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002341 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002343 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002344#endif
2345 else
2346 {
2347 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002349 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002350#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002351 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002352#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002354#ifdef FEAT_PROP_POPUP
2355 // override with text property highlight when "override" is TRUE
2356 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002357 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002358#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002360
2361 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002362 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002363 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002364 if (wlv.char_attr == 0)
2365 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002366 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002367 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002368 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369
2370 // Get the next character to put on the screen.
2371
2372 // The "p_extra" points to the extra stuff that is inserted to
2373 // represent special characters (non-printable stuff) and other
2374 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002375 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2377 // "p_extra[n_extra]".
2378 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002379 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002380 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002383 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2384 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2386 if (enc_utf8 && utf_char2len(c) > 1)
2387 {
2388 mb_utf8 = TRUE;
2389 u8cc[0] = 0;
2390 c = 0xc0;
2391 }
2392 else
2393 mb_utf8 = FALSE;
2394 }
2395 else
2396 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002398 if (has_mbyte)
2399 {
2400 mb_c = c;
2401 if (enc_utf8)
2402 {
2403 // If the UTF-8 character is more than one byte:
2404 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002405 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002406 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002407 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408 mb_l = 1;
2409 else if (mb_l > 1)
2410 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002411 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002412 mb_utf8 = TRUE;
2413 c = 0xc0;
2414 }
2415 }
2416 else
2417 {
2418 // if this is a DBCS character, put it in "mb_c"
2419 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002420 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421 mb_l = 1;
2422 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002424 }
2425 if (mb_l == 0) // at the NUL at end-of-line
2426 mb_l = 1;
2427
2428 // If a double-width char doesn't fit display a '>' in the
2429 // last column.
2430 if ((
2431# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002432 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002434 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435 && (*mb_char2cells)(mb_c) == 2)
2436 {
2437 c = '>';
2438 mb_c = c;
2439 mb_l = 1;
2440 mb_utf8 = FALSE;
2441 multi_attr = HL_ATTR(HLF_AT);
2442#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002443 if (wlv.cul_attr)
2444 multi_attr = hl_combine_attr(
2445 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002447 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002448
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 // put the pointer back to output the double-width
2450 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 ++wlv.n_extra;
2452 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 }
2454 else
2455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 wlv.n_extra -= mb_l - 1;
2457 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 }
2459 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002460 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002462 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002463#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002465 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002466 // Only restore search_attr and area_attr after "n_extra" in
2467 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002468 if (wlv.saved_n_extra <= 0)
2469 {
2470 if (search_attr == 0)
2471 search_attr = saved_search_attr;
2472 if (area_attr == 0 && *ptr != NUL)
2473 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002474
2475 if (wlv.extra_for_textprop)
2476 // wlv.extra_attr should be used at this position but
2477 // not any further.
2478 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002479 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002480
2481 wlv.extra_for_textprop = FALSE;
2482 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002483 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002484#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 }
2486 else
2487 {
2488#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002489 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002491 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 // Get a character from the line itself.
2494 c = *ptr;
2495#ifdef FEAT_LINEBREAK
2496 c0 = *ptr;
2497#endif
2498 if (has_mbyte)
2499 {
2500 mb_c = c;
2501 if (enc_utf8)
2502 {
2503 // If the UTF-8 character is more than one byte: Decode it
2504 // into "mb_c".
2505 mb_l = utfc_ptr2len(ptr);
2506 mb_utf8 = FALSE;
2507 if (mb_l > 1)
2508 {
2509 mb_c = utfc_ptr2char(ptr, u8cc);
2510 // Overlong encoded ASCII or ASCII with composing char
2511 // is displayed normally, except a NUL.
2512 if (mb_c < 0x80)
2513 {
2514 c = mb_c;
2515#ifdef FEAT_LINEBREAK
2516 c0 = mb_c;
2517#endif
2518 }
2519 mb_utf8 = TRUE;
2520
2521 // At start of the line we can have a composing char.
2522 // Draw it as a space with a composing char.
2523 if (utf_iscomposing(mb_c))
2524 {
2525 int i;
2526
2527 for (i = Screen_mco - 1; i > 0; --i)
2528 u8cc[i] = u8cc[i - 1];
2529 u8cc[0] = mb_c;
2530 mb_c = ' ';
2531 }
2532 }
2533
2534 if ((mb_l == 1 && c >= 0x80)
2535 || (mb_l >= 1 && mb_c == 0)
2536 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2537 {
2538 // Illegal UTF-8 byte: display as <xx>.
2539 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002540 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541# ifdef FEAT_RIGHTLEFT
2542 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002543 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002544# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002545 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 c = *wlv.p_extra;
2547 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002548 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2550 wlv.c_extra = NUL;
2551 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 if (area_attr == 0 && search_attr == 0)
2553 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002555 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 }
2559 }
2560 else if (mb_l == 0) // at the NUL at end-of-line
2561 mb_l = 1;
2562#ifdef FEAT_ARABIC
2563 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2564 {
2565 // Do Arabic shaping.
2566 int pc, pc1, nc;
2567 int pcc[MAX_MCO];
2568
2569 // The idea of what is the previous and next
2570 // character depends on 'rightleft'.
2571 if (wp->w_p_rl)
2572 {
2573 pc = prev_c;
2574 pc1 = prev_c1;
2575 nc = utf_ptr2char(ptr + mb_l);
2576 prev_c1 = u8cc[0];
2577 }
2578 else
2579 {
2580 pc = utfc_ptr2char(ptr + mb_l, pcc);
2581 nc = prev_c;
2582 pc1 = pcc[0];
2583 }
2584 prev_c = mb_c;
2585
2586 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2587 }
2588 else
2589 prev_c = mb_c;
2590#endif
2591 }
2592 else // enc_dbcs
2593 {
2594 mb_l = MB_BYTE2LEN(c);
2595 if (mb_l == 0) // at the NUL at end-of-line
2596 mb_l = 1;
2597 else if (mb_l > 1)
2598 {
2599 // We assume a second byte below 32 is illegal.
2600 // Hopefully this is OK for all double-byte encodings!
2601 if (ptr[1] >= 32)
2602 mb_c = (c << 8) + ptr[1];
2603 else
2604 {
2605 if (ptr[1] == NUL)
2606 {
2607 // head byte at end of line
2608 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002609 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002610 }
2611 else
2612 {
2613 // illegal tail byte
2614 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002615 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002617 wlv.p_extra = wlv.extra;
2618 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002619 wlv.c_extra = NUL;
2620 wlv.c_final = NUL;
2621 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 if (area_attr == 0 && search_attr == 0)
2623 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002625 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002626 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 // save current attr
2628 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002629 }
2630 mb_c = c;
2631 }
2632 }
2633 }
2634 // If a double-width char doesn't fit display a '>' in the
2635 // last column; the character is displayed at the start of the
2636 // next line.
2637 if ((
2638# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002639 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002641 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 && (*mb_char2cells)(mb_c) == 2)
2643 {
2644 c = '>';
2645 mb_c = c;
2646 mb_utf8 = FALSE;
2647 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002648 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 // Put pointer back so that the character will be
2650 // displayed at the start of the next line.
2651 --ptr;
2652#ifdef FEAT_CONCEAL
2653 did_decrement_ptr = TRUE;
2654#endif
2655 }
2656 else if (*ptr != NUL)
2657 ptr += mb_l - 1;
2658
2659 // If a double-width char doesn't fit at the left side display
2660 // a '<' in the first column. Don't do this for unprintable
2661 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002662 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002664 wlv.n_extra = 1;
2665 wlv.c_extra = MB_FILLER_CHAR;
2666 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 c = ' ';
2668 if (area_attr == 0 && search_attr == 0)
2669 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002670 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002671 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002672 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002673 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674 }
2675 mb_c = c;
2676 mb_utf8 = FALSE;
2677 mb_l = 1;
2678 }
2679
2680 }
2681 ++ptr;
2682
2683 if (extra_check)
2684 {
2685#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 // Check spelling (unless at the end of the line).
2687 // Only do this when there is no syntax highlighting, the
2688 // @Spell cluster is not used or the current syntax item
2689 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002690 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002691 if (has_spell && v >= word_end && v > cur_checked_col)
2692 {
2693 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002694 // do not calculate cap_col at the end of the line or when
2695 // only white space is following
2696 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697# ifdef FEAT_SYN_HL
2698 !has_syntax ||
2699# endif
2700 can_spell))
2701 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002702 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 int len;
2704 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002705
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002706 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002707 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708
2709 // Use nextline[] if possible, it has the start of the
2710 // next line concatenated.
2711 if ((prev_ptr - line) - nextlinecol >= 0)
2712 p = nextline + (prev_ptr - line) - nextlinecol;
2713 else
2714 p = prev_ptr;
2715 cap_col -= (int)(prev_ptr - line);
2716 len = spell_check(wp, p, &spell_hlf, &cap_col,
2717 nochange);
2718 word_end = v + len;
2719
2720 // In Insert mode only highlight a word that
2721 // doesn't touch the cursor.
2722 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002723 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002724 && wp->w_cursor.lnum == lnum
2725 && wp->w_cursor.col >=
2726 (colnr_T)(prev_ptr - line)
2727 && wp->w_cursor.col < (colnr_T)word_end)
2728 {
2729 spell_hlf = HLF_COUNT;
2730 spell_redraw_lnum = lnum;
2731 }
2732
2733 if (spell_hlf == HLF_COUNT && p != prev_ptr
2734 && (p - nextline) + len > nextline_idx)
2735 {
2736 // Remember that the good word continues at the
2737 // start of the next line.
2738 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002739 checked_col = (int)((p - nextline)
2740 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741 }
2742
2743 // Turn index into actual attributes.
2744 if (spell_hlf != HLF_COUNT)
2745 spell_attr = highlight_attr[spell_hlf];
2746
2747 if (cap_col > 0)
2748 {
2749 if (p != prev_ptr
2750 && (p - nextline) + cap_col >= nextline_idx)
2751 {
2752 // Remember that the word in the next line
2753 // must start with a capital.
2754 capcol_lnum = lnum + 1;
2755 cap_col = (int)((p - nextline) + cap_col
2756 - nextline_idx);
2757 }
2758 else
2759 // Compute the actual column.
2760 cap_col += (int)(prev_ptr - line);
2761 }
2762 }
2763 }
2764 if (spell_attr != 0)
2765 {
2766 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002767 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2768 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002770 wlv.char_attr = hl_combine_attr(spell_attr,
2771 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 }
2773#endif
2774#ifdef FEAT_LINEBREAK
2775 // Found last space before word: check for line break.
2776 if (wp->w_p_lbr && c0 == c
2777 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2778 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002779 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2780 : 0;
2781 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002782 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002783
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002784 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002785# ifdef FEAT_PROP_POPUP
2786 // do not want virtual text counted here
2787 cts.cts_has_prop_with_text = FALSE;
2788# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002789 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002790 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002791
2792 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002793 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002794 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002795 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2797 if (wlv.n_extra < 0)
2798 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002799 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002800 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002801 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002802 // line break, but for TABs the highlighting should
2803 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002804 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002805
Bram Moolenaar1306b362022-08-06 15:59:06 +01002806 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002808 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002809 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 wp->w_buffer->b_p_vts_array) - 1;
2811# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002813 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814# endif
2815
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2817 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002818# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002820 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002821# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002822 if (VIM_ISWHITE(c))
2823 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002824# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 if (c == TAB)
2826 // See "Tab alignment" below.
2827 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002828# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002829 if (!wp->w_p_list)
2830 c = ' ';
2831 }
2832 }
2833#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002834 in_multispace = c == ' '
2835 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2836 if (!in_multispace)
2837 multispace_pos = 0;
2838
Bram Moolenaareed9d462021-02-15 20:38:25 +01002839 // 'list': Change char 160 to 'nbsp' and space to 'space'
2840 // setting in 'listchars'. But not when the character is
2841 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 if (wp->w_p_list
2843 && ((((c == 160 && mb_l == 1)
2844 || (mb_utf8
2845 && ((mb_c == 160 && mb_l == 2)
2846 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002847 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 || (c == ' '
2849 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002850 && (wp->w_lcs_chars.space
2851 || (in_multispace
2852 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002853 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854 && ptr - line <= trailcol)))
2855 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002856 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2857 {
2858 c = wp->w_lcs_chars.multispace[multispace_pos++];
2859 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2860 multispace_pos = 0;
2861 }
2862 else
2863 c = (c == ' ') ? wp->w_lcs_chars.space
2864 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 if (area_attr == 0 && search_attr == 0)
2866 {
2867 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002868 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002869 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002870 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 }
2872 mb_c = c;
2873 if (enc_utf8 && utf_char2len(c) > 1)
2874 {
2875 mb_utf8 = TRUE;
2876 u8cc[0] = 0;
2877 c = 0xc0;
2878 }
2879 else
2880 mb_utf8 = FALSE;
2881 }
2882
zeertzjq2e7cba32022-06-10 15:30:32 +01002883 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2884 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002886 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2887 && wp->w_lcs_chars.leadmultispace != NULL)
2888 {
2889 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002890 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2891 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002892 multispace_pos = 0;
2893 }
2894
2895 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2896 c = wp->w_lcs_chars.trail;
2897
2898 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2899 c = wp->w_lcs_chars.lead;
2900
zeertzjq2e7cba32022-06-10 15:30:32 +01002901 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002902 c = wp->w_lcs_chars.space;
2903
2904
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 if (!attr_pri)
2906 {
2907 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002908 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002909 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002910 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
2912 mb_c = c;
2913 if (enc_utf8 && utf_char2len(c) > 1)
2914 {
2915 mb_utf8 = TRUE;
2916 u8cc[0] = 0;
2917 c = 0xc0;
2918 }
2919 else
2920 mb_utf8 = FALSE;
2921 }
2922 }
2923
2924 // Handling of non-printable characters.
2925 if (!vim_isprintc(c))
2926 {
2927 // when getting a character from the file, we may have to
2928 // turn it into something else on the way to putting it
2929 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002930 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002932 int tab_len = 0;
2933 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002935 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002936
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 // only adjust the tab_len, when at the first column
2938 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002939 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002940 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941#endif
2942 // tab amount depends on current column
2943#ifdef FEAT_VARTABS
2944 tab_len = tabstop_padding(vcol_adjusted,
2945 wp->w_buffer->b_p_ts,
2946 wp->w_buffer->b_p_vts_array) - 1;
2947#else
2948 tab_len = (int)wp->w_buffer->b_p_ts
2949 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2950#endif
2951
2952#ifdef FEAT_LINEBREAK
2953 if (!wp->w_p_lbr || !wp->w_p_list)
2954#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002955 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002957 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002958 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002959#ifdef FEAT_LINEBREAK
2960 else
2961 {
2962 char_u *p;
2963 int len;
2964 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002966
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002967# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002968 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002969 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002970 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002971
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002973 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 && old_boguscols > 0
2975 && wlv.n_extra > tab_len)
2976 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002977# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002978 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002980 // If wlv.n_extra > 0, it gives the number of chars
2981 // to use for a tab, else we need to calculate the
2982 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002983 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2984 len = tab_len * tab2_len;
2985 if (wp->w_lcs_chars.tab3)
2986 len += mb_char2len(wp->w_lcs_chars.tab3)
2987 - tab2_len;
2988 if (wlv.n_extra > 0)
2989 len += wlv.n_extra - tab_len;
2990 c = wp->w_lcs_chars.tab1;
2991 p = alloc(len + 1);
2992 if (p == NULL)
2993 wlv.n_extra = 0;
2994 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002996 vim_memset(p, ' ', len);
2997 p[len] = NUL;
2998 vim_free(wlv.p_extra_free);
2999 wlv.p_extra_free = p;
3000 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003001 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003002 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003003
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003004 if (*p == NUL)
3005 {
3006 tab_len = i;
3007 break;
3008 }
3009
3010 // if tab3 is given, use it for the last
3011 // char
3012 if (wp->w_lcs_chars.tab3
3013 && i == tab_len - 1)
3014 lcs = wp->w_lcs_chars.tab3;
3015 p += mb_char2bytes(lcs, p);
3016 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003018 }
3019 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003020# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003021 // n_extra will be increased by
3022 // FIX_FOX_BOGUSCOLS macro below, so need to
3023 // adjust for that here
3024 if (wlv.vcol_off > 0)
3025 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003026# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003027 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 }
3030#endif
3031#ifdef FEAT_CONCEAL
3032 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003033 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034
3035 // Tab alignment should be identical regardless of
3036 // 'conceallevel' value. So tab compensates of all
3037 // previous concealed characters, and thus resets
3038 // vcol_off and boguscols accumulated so far in the
3039 // line. Note that the tab can be longer than
3040 // 'tabstop' when there are concealed characters.
3041 FIX_FOR_BOGUSCOLS;
3042
3043 // Make sure, the highlighting for the tab char will be
3044 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003045 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003046 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003047 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003048 tab_len += vc_saved;
3049 }
3050#endif
3051 mb_utf8 = FALSE; // don't draw as UTF-8
3052 if (wp->w_p_list)
3053 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003055 ? wp->w_lcs_chars.tab3
3056 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003058 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003059 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060 else
3061#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003062 wlv.c_extra = wp->w_lcs_chars.tab2;
3063 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003065 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003066 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 mb_c = c;
3069 if (enc_utf8 && utf_char2len(c) > 1)
3070 {
3071 mb_utf8 = TRUE;
3072 u8cc[0] = 0;
3073 c = 0xc0;
3074 }
3075 }
3076 else
3077 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003078 wlv.c_final = NUL;
3079 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 c = ' ';
3081 }
3082 }
3083 else if (c == NUL
3084 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003085 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3086 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 && VIsual_mode != Ctrl_V
3088 && (
3089# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003090 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003092 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003093 && !(noinvcur
3094 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003095 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 && lcs_eol_one > 0)
3097 {
3098 // Display a '$' after the line or highlight an extra
3099 // character if the line break is included.
3100#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3101 // For a diff line the highlighting continues after the
3102 // "$".
3103 if (
3104# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003105 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106# ifdef LINE_ATTR
3107 &&
3108# endif
3109# endif
3110# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003111 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112# endif
3113 )
3114#endif
3115 {
3116 // In virtualedit, visual selections may extend
3117 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003118 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003119 && wlv.tocol != MAXCOL
3120 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003121 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003122 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003124 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3125 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 else
3127 c = ' ';
3128 lcs_eol_one = -1;
3129 --ptr; // put it back at the NUL
3130 if (!attr_pri)
3131 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003132 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003133 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 n_attr = 1;
3135 }
3136 mb_c = c;
3137 if (enc_utf8 && utf_char2len(c) > 1)
3138 {
3139 mb_utf8 = TRUE;
3140 u8cc[0] = 0;
3141 c = 0xc0;
3142 }
3143 else
3144 mb_utf8 = FALSE; // don't draw as UTF-8
3145 }
3146 else if (c != NUL)
3147 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3149 if (wlv.n_extra == 0)
3150 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151#ifdef FEAT_RIGHTLEFT
3152 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003153 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 wlv.c_extra = NUL;
3156 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157#ifdef FEAT_LINEBREAK
3158 if (wp->w_p_lbr)
3159 {
3160 char_u *p;
3161
Bram Moolenaar1306b362022-08-06 15:59:06 +01003162 c = *wlv.p_extra;
3163 p = alloc(wlv.n_extra + 1);
3164 vim_memset(p, ' ', wlv.n_extra);
3165 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3166 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003167 vim_free(wlv.p_extra_free);
3168 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 }
3170 else
3171#endif
3172 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003173 wlv.n_extra = byte2cells(c) - 1;
3174 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 }
3176 if (!attr_pri)
3177 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003178 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003179 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003180 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
3183 mb_utf8 = FALSE; // don't draw as UTF-8
3184 }
3185 else if (VIsual_active
3186 && (VIsual_mode == Ctrl_V
3187 || VIsual_mode == 'v')
3188 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003189 && wlv.tocol != MAXCOL
3190 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 && (
3192#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003193 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003195 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 {
3197 c = ' ';
3198 --ptr; // put it back at the NUL
3199 }
3200#if defined(LINE_ATTR)
3201 else if ((
3202# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003203 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204# endif
3205# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003206 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003208 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 ) && (
3210# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003211 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003212# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003213 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216# endif
3217 < wp->w_width)))
3218 {
3219 // Highlight until the right side of the window
3220 c = ' ';
3221 --ptr; // put it back at the NUL
3222
3223 // Remember we do the char for line highlighting.
3224 ++did_line_attr;
3225
3226 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003227 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003228 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003229 || (wp->w_p_list &&
3230 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003231 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003233 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 wlv.diff_hlf = HLF_CHD;
3236 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003238 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3240 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003241 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 || (wlv.vcol >= left_curline_col
3243 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 wlv.char_attr = hl_combine_attr(
3245 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003246 }
3247 }
3248# endif
3249# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003250 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003252 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003253 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3254 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 if (!wlv.cul_screenline
3257 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003258 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 wlv.char_attr = hl_combine_attr(
3260 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003262 else if (wlv.line_attr)
3263 wlv.char_attr = hl_combine_attr(
3264 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 }
3266# endif
3267 }
3268#endif
3269 }
3270
3271#ifdef FEAT_CONCEAL
3272 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003273 && (wp != curwin || lnum != wp->w_cursor.lnum
3274 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003275 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3276 && !(lnum_in_visual_area
3277 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003280 if (((prev_syntax_id != syntax_seqnr
3281 && (syntax_flags & HL_CONCEAL) != 0)
3282 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003283 && (syn_get_sub_char() != NUL
3284 || (has_match_conc && match_conc)
3285 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 && wp->w_p_cole != 3)
3287 {
3288 // First time at this concealed item: display one
3289 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003290 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 c = match_conc;
3292 else if (syn_get_sub_char() != NUL)
3293 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003294 else if (wp->w_lcs_chars.conceal != NUL)
3295 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 else
3297 c = ' ';
3298
3299 prev_syntax_id = syntax_seqnr;
3300
Bram Moolenaar1306b362022-08-06 15:59:06 +01003301 if (wlv.n_extra > 0)
3302 wlv.vcol_off += wlv.n_extra;
3303 wlv.vcol += wlv.n_extra;
3304 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003305 {
3306# ifdef FEAT_RIGHTLEFT
3307 if (wp->w_p_rl)
3308 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003309 wlv.col -= wlv.n_extra;
3310 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 }
3312 else
3313# endif
3314 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 wlv.boguscols += wlv.n_extra;
3316 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317 }
3318 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003319 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 n_attr = 0;
3321 }
3322 else if (n_skip == 0)
3323 {
3324 is_concealing = TRUE;
3325 n_skip = 1;
3326 }
3327 mb_c = c;
3328 if (enc_utf8 && utf_char2len(c) > 1)
3329 {
3330 mb_utf8 = TRUE;
3331 u8cc[0] = 0;
3332 c = 0xc0;
3333 }
3334 else
3335 mb_utf8 = FALSE; // don't draw as UTF-8
3336 }
3337 else
3338 {
3339 prev_syntax_id = 0;
3340 is_concealing = FALSE;
3341 }
3342
3343 if (n_skip > 0 && did_decrement_ptr)
3344 // not showing the '>', put pointer back to avoid getting stuck
3345 ++ptr;
3346
3347#endif // FEAT_CONCEAL
3348 }
3349
3350#ifdef FEAT_CONCEAL
3351 // In the cursor line and we may be concealing characters: correct
3352 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354 && wp == curwin && lnum == wp->w_cursor.lnum
3355 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003356 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003358# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003360 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003362# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003363 wp->w_wcol = wlv.col - wlv.boguscols;
3364 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365 did_wcol = TRUE;
3366 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003367# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003368 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003369# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 }
3371#endif
3372
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003373 // Use "wlv.extra_attr", but don't override visual selection
3374 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003375 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3376 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003378 && (!attr_pri
3379#ifdef FEAT_PROP_POPUP
3380 || (text_prop_flags & PT_FLAG_OVERRIDE)
3381#endif
3382 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 {
3384#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003385 if (wlv.line_attr)
3386 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 else
3388#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003389 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003390#ifdef FEAT_PROP_POPUP
3391 if (reset_extra_attr)
3392 {
3393 reset_extra_attr = FALSE;
3394 wlv.extra_attr = 0;
3395 }
3396#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
3398
3399#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3400 // XIM don't send preedit_start and preedit_end, but they send
3401 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3402 // im_is_preediting() here.
3403 if (p_imst == IM_ON_THE_SPOT
3404 && xic != NULL
3405 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003406 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 && !p_imdisable
3408 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
3411 colnr_T tcol;
3412
3413 if (preedit_end_col == MAXCOL)
3414 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3415 else
3416 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 {
3419 if (feedback_old_attr < 0)
3420 {
3421 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003422 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 wlv.char_attr = im_get_feedback_attr(feedback_col);
3425 if (wlv.char_attr < 0)
3426 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427 feedback_col++;
3428 }
3429 else if (feedback_old_attr >= 0)
3430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003431 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 feedback_old_attr = -1;
3433 feedback_col = 0;
3434 }
3435 }
3436#endif
3437 // Handle the case where we are in column 0 but not on the first
3438 // character of the line and the user wants us to show us a
3439 // special character (via 'listchars' option "precedes:<char>".
3440 if (lcs_prec_todo != NUL
3441 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003442 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3443 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003444#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003445 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003447 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003448 && c != NUL)
3449 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003450 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 lcs_prec_todo = NUL;
3452 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3453 {
3454 // Double-width character being overwritten by the "precedes"
3455 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.c_extra = MB_FILLER_CHAR;
3457 wlv.c_final = NUL;
3458 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003460 wlv.extra_attr =
3461 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 }
3463 mb_c = c;
3464 if (enc_utf8 && utf_char2len(c) > 1)
3465 {
3466 mb_utf8 = TRUE;
3467 u8cc[0] = 0;
3468 c = 0xc0;
3469 }
3470 else
3471 mb_utf8 = FALSE; // don't draw as UTF-8
3472 if (!attr_pri)
3473 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 saved_attr3 = wlv.char_attr; // save current attr
3475 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 n_attr3 = 1;
3477 }
3478 }
3479
3480 // At end of the text line or just after the last character.
3481 if ((c == NUL
3482#if defined(LINE_ATTR)
3483 || did_line_attr == 1
3484#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003485 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 {
3487#ifdef FEAT_SEARCH_EXTRA
3488 // flag to indicate whether prevcol equals startcol of search_hl or
3489 // one of the matches
3490 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3491 (long)(ptr - line) - (c == NUL));
3492#endif
3493 // Invert at least one char, used for Visual and empty line or
3494 // highlight match at end of line. If it's beyond the last
3495 // char on the screen, just overwrite that one (tricky!) Not
3496 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003497 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003498 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 && (VIsual_mode != Ctrl_V
3500 || lnum == VIsual.lnum
3501 || lnum == curwin->w_cursor.lnum)
3502 && c == NUL)
3503#ifdef FEAT_SEARCH_EXTRA
3504 // highlight 'hlsearch' match at end of line
3505 || (prevcol_hl_flag
3506# ifdef FEAT_SYN_HL
3507 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3508 && !(wp == curwin && VIsual_active))
3509# endif
3510# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003511 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003512# endif
3513# if defined(LINE_ATTR)
3514 && did_line_attr <= 1
3515# endif
3516 )
3517#endif
3518 ))
3519 {
3520 int n = 0;
3521
3522#ifdef FEAT_RIGHTLEFT
3523 if (wp->w_p_rl)
3524 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 n = 1;
3527 }
3528 else
3529#endif
3530 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003531 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 n = -1;
3533 }
3534 if (n != 0)
3535 {
3536 // At the window boundary, highlight the last character
3537 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003538 wlv.off += n;
3539 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 }
3541 else
3542 {
3543 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003545 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003546 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003547 }
3548#ifdef FEAT_SEARCH_EXTRA
3549 if (area_attr == 0)
3550 {
3551 // Use attributes from match with highest priority among
3552 // 'search_hl' and the match list.
3553 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003554 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 }
3556#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003557 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003558 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559#ifdef FEAT_RIGHTLEFT
3560 if (wp->w_p_rl)
3561 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003562 --wlv.col;
3563 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003564 }
3565 else
3566#endif
3567 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 ++wlv.col;
3569 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 ++wlv.vcol;
3572 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573 }
3574 }
3575
3576 // At end of the text line.
3577 if (c == NUL)
3578 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003579 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580
3581 // Update w_cline_height and w_cline_folded if the cursor line was
3582 // updated (saves a call to plines() later).
3583 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3584 {
3585 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587#ifdef FEAT_FOLDING
3588 curwin->w_cline_folded = FALSE;
3589#endif
3590 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3591 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003592 break;
3593 }
3594
3595 // Show "extends" character from 'listchars' if beyond the line end and
3596 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003597 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003598 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 && wp->w_p_list
3600 && !wp->w_p_wrap
3601#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003602 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603#endif
3604 && (
3605#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003608 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003609 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003610 || lcs_eol_one > 0
3611 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003612 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003613 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003614 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003615 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 mb_c = c;
3617 if (enc_utf8 && utf_char2len(c) > 1)
3618 {
3619 mb_utf8 = TRUE;
3620 u8cc[0] = 0;
3621 c = 0xc0;
3622 }
3623 else
3624 mb_utf8 = FALSE;
3625 }
3626
3627#ifdef FEAT_SYN_HL
3628 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003629 if (wlv.draw_color_col)
3630 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631
3632 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3633 // highlight the cursor position itself.
3634 // Also highlight the 'colorcolumn' if it is different than
3635 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003636 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3637 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003639 if (((wlv.draw_state == WL_LINE
3640 || wlv.draw_state == WL_BRI
3641 || wlv.draw_state == WL_SBR)
3642 && !lnum_in_visual_area
3643 && search_attr == 0
3644 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003645# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003646 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003647# endif
3648 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649 {
3650 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3651 && lnum != wp->w_cursor.lnum)
3652 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 vcol_save_attr = wlv.char_attr;
3654 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3655 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003657 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003659 vcol_save_attr = wlv.char_attr;
3660 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 }
3662 }
3663#endif
3664
3665 // Store character to be displayed.
3666 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003668 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 {
3670 // Store the character.
3671#if defined(FEAT_RIGHTLEFT)
3672 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3673 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003674 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003675 --wlv.off;
3676 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677 }
3678#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003679 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 if (enc_dbcs == DBCS_JPNU)
3681 {
3682 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003683 ScreenLines[wlv.off] = 0x8e;
3684 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 }
3686 else if (enc_utf8)
3687 {
3688 if (mb_utf8)
3689 {
3690 int i;
3691
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 for (i = 0; i < Screen_mco; ++i)
3696 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003697 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003698 if (u8cc[i] == 0)
3699 break;
3700 }
3701 }
3702 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003703 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 }
3705 if (multi_attr)
3706 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003707 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003708 multi_attr = 0;
3709 }
3710 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003711 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003712
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003714
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3716 {
3717 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003718 ++wlv.off;
3719 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 if (enc_utf8)
3721 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 else
3724 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003725 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003726 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003728 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729#endif
3730 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003732 // When "wlv.tocol" is halfway a character, set it to the end
3733 // of the character, otherwise highlighting won't stop.
3734 if (wlv.tocol == wlv.vcol)
3735 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003736
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003738
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003739#ifdef FEAT_RIGHTLEFT
3740 if (wp->w_p_rl)
3741 {
3742 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 --wlv.off;
3744 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003745 }
3746#endif
3747 }
3748#ifdef FEAT_RIGHTLEFT
3749 if (wp->w_p_rl)
3750 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003751 --wlv.off;
3752 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 }
3754 else
3755#endif
3756 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003757 ++wlv.off;
3758 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003759 }
3760 }
3761#ifdef FEAT_CONCEAL
3762 else if (wp->w_p_cole > 0 && is_concealing)
3763 {
3764 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003766 if (wlv.n_extra > 0)
3767 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003768 if (wp->w_p_wrap)
3769 {
3770 // Special voodoo required if 'wrap' is on.
3771 //
3772 // Advance the column indicator to force the line
3773 // drawing to wrap early. This will make the line
3774 // take up the same screen space when parts are concealed,
3775 // so that cursor line computations aren't messed up.
3776 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 // trailing junk to be written out of the screen line
3779 // we are building, 'boguscols' keeps track of the number
3780 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003781 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003783 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784# ifdef FEAT_RIGHTLEFT
3785 if (wp->w_p_rl)
3786 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003787 wlv.col -= wlv.n_extra;
3788 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003789 }
3790 else
3791# endif
3792 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003793 wlv.col += wlv.n_extra;
3794 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003796 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 n_attr = 0;
3798 }
3799
3800
3801 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3802 {
3803 // Need to fill two screen columns.
3804# ifdef FEAT_RIGHTLEFT
3805 if (wp->w_p_rl)
3806 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003807 --wlv.boguscols;
3808 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809 }
3810 else
3811# endif
3812 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003813 ++wlv.boguscols;
3814 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815 }
3816 }
3817
3818# ifdef FEAT_RIGHTLEFT
3819 if (wp->w_p_rl)
3820 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 --wlv.boguscols;
3822 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 }
3824 else
3825# endif
3826 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003827 ++wlv.boguscols;
3828 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003829 }
3830 }
3831 else
3832 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003833 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003834 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003835 wlv.vcol += wlv.n_extra;
3836 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003837 n_attr = 0;
3838 }
3839 }
3840
3841 }
3842#endif // FEAT_CONCEAL
3843 else
3844 --n_skip;
3845
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 // Only advance the "wlv.vcol" when after the 'number' or
3847 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003848 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003850 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851#endif
3852 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003853 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854
3855#ifdef FEAT_SYN_HL
3856 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003857 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003858#endif
3859
3860 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003861 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3862 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863
3864 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003865 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003866 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003867 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003868 if (wlv.n_attr_skip > 0)
3869 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870
3871 // At end of screen line and there is more to come: Display the line
3872 // so far. If there is no more to display it is caught above.
3873 if ((
3874#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003877 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003878 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003879 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003881 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003883#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003884 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003885#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003886 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003887 && wlv.p_extra != at_end_str)
3888 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3889 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 )
3891 {
3892#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003893 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003894 wlv_screen_line(wp, &wlv, FALSE);
3895 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 wlv.boguscols = 0;
Alexey Radkovaaa16b02023-01-04 11:15:30 +00003897 wlv.vcol_off = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003899 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 ++wlv.row;
3902 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903
3904 // When not wrapping and finished diff lines, or when displayed
3905 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003906 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003908 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003909#endif
3910#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003911 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003913 ) || lcs_eol_one == -1)
3914#ifdef FEAT_PROP_POPUP
3915 && !text_prop_follows
3916#endif
3917 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003919#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003920 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003921 {
3922 // do not output more of the line, only the "below" prop
3923 ptr += STRLEN(ptr);
3924# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003925 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003926# endif
3927 }
3928#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929
3930 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003931 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003933 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934#endif
3935 )
3936 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003937 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3938 draw_vsep_win(wp, wlv.row);
3939 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940 }
3941
3942 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 break;
3947 }
3948
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003949 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003951 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003953#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003954 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003955#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 && wp->w_width == Columns)
3957 {
3958 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003959 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960
3961 // Special trick to make copy/paste of wrapped lines work with
3962 // xterm/screen: write an extra character beyond the end of
3963 // the line. This will work with all terminal types
3964 // (regardless of the xn,am settings).
3965 // Only do this on a fast tty.
3966 // Only do this if the cursor is on the current line
3967 // (something has been written in it).
3968 // Don't do this for the GUI.
3969 // Don't do this for double-width characters.
3970 // Don't do this for a window not at the right screen border.
3971 if (p_tf
3972#ifdef FEAT_GUI
3973 && !gui.in_use
3974#endif
3975 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003976 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3977 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003979 || (*mb_off2cells)(
3980 LineOffset[wlv.screen_row - 1]
3981 + (int)Columns - 2,
3982 LineOffset[wlv.screen_row]
3983 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 {
3985 // First make sure we are at the end of the screen line,
3986 // then output the same character again to let the
3987 // terminal know about the wrap. If the terminal doesn't
3988 // auto-wrap, we overwrite the character.
3989 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003990 screen_char(LineOffset[wlv.screen_row - 1]
3991 + (unsigned)Columns - 1,
3992 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993
3994 // When there is a multi-byte character, just output a
3995 // space to keep it simple.
3996 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003997 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998 out_char(' ');
3999 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004000 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004001 + (Columns - 1)]);
4002 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004003 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004 screen_start(); // don't know where cursor is now
4005 }
4006 }
4007
Bram Moolenaar1306b362022-08-06 15:59:06 +01004008 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004009
Bram Moolenaareed9d462021-02-15 20:38:25 +01004010 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004012 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004013# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004014 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004016 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004017 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018#endif
4019#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004020 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004021 // When the filler lines are actually below the last line of the
4022 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004023 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024 break;
4025#endif
4026 }
4027
4028 } // for every character in the line
4029
4030#ifdef FEAT_SPELL
4031 // After an empty line check first word for capital.
4032 if (*skipwhite(line) == NUL)
4033 {
4034 capcol_lnum = lnum + 1;
4035 cap_col = 0;
4036 }
4037#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004038#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 vim_free(text_props);
4040 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004041 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042#endif
4043
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004044 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004045 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046}