blob: 72dff66c03f78e2eb58e8bee2b694475a1d447a3 [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 Moolenaar9d9a20e2023-02-11 13:49:01 +00001088 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 int text_prop_count;
1090 int text_prop_next = 0; // next text property to use
1091 textprop_T *text_props = NULL;
1092 int *text_prop_idxs = NULL;
1093 int text_props_active = 0;
1094 proptype_T *text_prop_type = NULL;
1095 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001096 int text_prop_attr_comb = 0; // text_prop_attr combined with
1097 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001098 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001099 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001100 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001101 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001102 int saved_search_attr = 0; // search_attr to be used when n_extra
1103 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001104 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001105 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106#endif
1107#ifdef FEAT_SPELL
1108 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001109 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110# define SPWORDLEN 150
1111 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1112 int nextlinecol = 0; // column where nextline[] starts
1113 int nextline_idx = 0; // index in nextline[] where next line
1114 // starts
1115 int spell_attr = 0; // attributes desired by spelling
1116 int word_end = 0; // last byte with same spell_attr
1117 static linenr_T checked_lnum = 0; // line number for "checked_col"
1118 static int checked_col = 0; // column in "checked_lnum" up to which
1119 // there are no spell errors
1120 static int cap_col = -1; // column to check for Cap word
1121 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1122 int cur_checked_col = 0; // checked column for current line
1123#endif
1124 int extra_check = 0; // has extra highlighting
1125 int multi_attr = 0; // attributes desired by multibyte
1126 int mb_l = 1; // multi-byte byte length
1127 int mb_c = 0; // decoded multi-byte character
1128 int mb_utf8 = FALSE; // screen char is UTF-8 char
1129 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131 int change_start = MAXCOL; // first col of changed area
1132 int change_end = -1; // last col of changed area
1133#endif
1134 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001135 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001136 int in_multispace = FALSE; // in multiple consecutive spaces
1137 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001138#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001139 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001141 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001142 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143#ifdef FEAT_ARABIC
1144 int prev_c = 0; // previous Arabic character
1145 int prev_c1 = 0; // first composing char for prev_c
1146#endif
1147#if defined(LINE_ATTR)
1148 int did_line_attr = 0;
1149#endif
1150#ifdef FEAT_TERMINAL
1151 int get_term_attr = FALSE;
1152#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153
Martin Tournoijba43e762022-10-13 22:12:15 +01001154#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155 // margin columns for the screen line, needed for when 'cursorlineopt'
1156 // contains "screenline"
1157 int left_curline_col = 0;
1158 int right_curline_col = 0;
1159#endif
1160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1162 int feedback_col = 0;
1163 int feedback_old_attr = -1;
1164#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165
1166#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1167 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001168#endif
1169#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001170 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171#endif
1172#ifdef FEAT_CONCEAL
1173 int syntax_flags = 0;
1174 int syntax_seqnr = 0;
1175 int prev_syntax_id = 0;
1176 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1177 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 int did_wcol = FALSE;
1179 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001180# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181# define FIX_FOR_BOGUSCOLS \
1182 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001183 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001184 wlv.vcol -= wlv.vcol_off; \
1185 wlv.vcol_off = 0; \
1186 wlv.col -= wlv.boguscols; \
1187 old_boguscols = wlv.boguscols; \
1188 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 }
1190#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001191# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001192#endif
1193
1194 if (startrow > endrow) // past the end already!
1195 return startrow;
1196
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001197 CLEAR_FIELD(wlv);
1198
1199 wlv.lnum = lnum;
1200 wlv.startrow = startrow;
1201 wlv.row = startrow;
1202 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001203 wlv.fromcol = -10;
1204 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001205#ifdef FEAT_LINEBREAK
1206 wlv.vcol_sbr = -1;
1207#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208
1209 if (!number_only)
1210 {
1211 // To speed up the loop below, set extra_check when there is linebreak,
1212 // trailing white space and/or syntax processing to be done.
1213#ifdef FEAT_LINEBREAK
1214 extra_check = wp->w_p_lbr;
1215#endif
1216#ifdef FEAT_SYN_HL
1217 if (syntax_present(wp) && !wp->w_s->b_syn_error
1218# ifdef SYN_TIME_LIMIT
1219 && !wp->w_s->b_syn_slow
1220# endif
1221 )
1222 {
1223 // Prepare for syntax highlighting in this line. When there is an
1224 // error, stop syntax highlighting.
1225 save_did_emsg = did_emsg;
1226 did_emsg = FALSE;
1227 syntax_start(wp, lnum);
1228 if (did_emsg)
1229 wp->w_s->b_syn_error = TRUE;
1230 else
1231 {
1232 did_emsg = save_did_emsg;
1233#ifdef SYN_TIME_LIMIT
1234 if (!wp->w_s->b_syn_slow)
1235#endif
1236 {
1237 has_syntax = TRUE;
1238 extra_check = TRUE;
1239 }
1240 }
1241 }
1242
1243 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001244 wlv.color_cols = wp->w_p_cc_cols;
1245 if (wlv.color_cols != NULL)
1246 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247#endif
1248
1249#ifdef FEAT_TERMINAL
1250 if (term_show_buffer(wp->w_buffer))
1251 {
1252 extra_check = TRUE;
1253 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001254 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 }
1256#endif
1257
1258#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001259 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260 {
1261 // Prepare for spell checking.
1262 has_spell = TRUE;
1263 extra_check = TRUE;
1264
1265 // Get the start of the next line, so that words that wrap to the
1266 // next line are found too: "et<line-break>al.".
1267 // Trick: skip a few chars for C/shell/Vim comments
1268 nextline[SPWORDLEN] = NUL;
1269 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1270 {
1271 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1272 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1273 }
1274
1275 // When a word wrapped from the previous line the start of the
1276 // current line is valid.
1277 if (lnum == checked_lnum)
1278 cur_checked_col = checked_col;
1279 checked_lnum = 0;
1280
1281 // When there was a sentence end in the previous line may require a
1282 // word starting with capital in this line. In line 1 always check
1283 // the first word.
1284 if (lnum != capcol_lnum)
1285 cap_col = -1;
1286 if (lnum == 1)
1287 cap_col = 0;
1288 capcol_lnum = 0;
1289 }
1290#endif
1291
1292 // handle Visual active in this window
1293 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1294 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001295 pos_T *top, *bot;
1296
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1298 {
1299 // Visual is after curwin->w_cursor
1300 top = &curwin->w_cursor;
1301 bot = &VIsual;
1302 }
1303 else
1304 {
1305 // Visual is before curwin->w_cursor
1306 top = &VIsual;
1307 bot = &curwin->w_cursor;
1308 }
1309 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1310 if (VIsual_mode == Ctrl_V)
1311 {
1312 // block mode
1313 if (lnum_in_visual_area)
1314 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001315 wlv.fromcol = wp->w_old_cursor_fcol;
1316 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 }
1318 }
1319 else
1320 {
1321 // non-block mode
1322 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001323 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 else if (lnum == top->lnum)
1325 {
1326 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001327 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001328 else
1329 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001330 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001332 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 }
1334 }
1335 if (VIsual_mode != 'V' && lnum == bot->lnum)
1336 {
1337 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1338 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 wlv.fromcol = -10;
1340 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 }
1342 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001343 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344 else
1345 {
1346 pos = *bot;
1347 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001348 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1349 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 else
1351 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001352 getvvcol(wp, &pos, NULL, NULL,
1353 (colnr_T *)&wlv.tocol);
1354 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 }
1356 }
1357 }
1358 }
1359
1360 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001361 if (!highlight_match && lnum == curwin->w_cursor.lnum
1362 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363#ifdef FEAT_GUI
1364 && !gui.in_use
1365#endif
1366 )
1367 noinvcur = TRUE;
1368
1369 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001370 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001371 {
1372 area_highlighting = TRUE;
1373 vi_attr = HL_ATTR(HLF_V);
1374#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1375 if ((clip_star.available && !clip_star.owned
1376 && clip_isautosel_star())
1377 || (clip_plus.available && !clip_plus.owned
1378 && clip_isautosel_plus()))
1379 vi_attr = HL_ATTR(HLF_VNC);
1380#endif
1381 }
1382 }
1383
1384 // handle 'incsearch' and ":s///c" highlighting
1385 else if (highlight_match
1386 && wp == curwin
1387 && lnum >= curwin->w_cursor.lnum
1388 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1389 {
1390 if (lnum == curwin->w_cursor.lnum)
1391 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001392 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001393 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001394 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1396 {
1397 pos.lnum = lnum;
1398 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001399 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 }
1401 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001402 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001404 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1405 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001406 area_highlighting = TRUE;
1407 vi_attr = HL_ATTR(HLF_I);
1408 }
1409 }
1410
1411#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001412 wlv.filler_lines = diff_check(wp, lnum);
1413 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001415 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 {
1417 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001418 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001419 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001422 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 }
1424 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001425 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001426 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 area_highlighting = TRUE;
1428 }
1429 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001430 wlv.filler_lines = wp->w_topfill;
1431 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432#endif
1433
1434#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001435 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001436 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438#endif
1439
1440#ifdef LINE_ATTR
1441# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001442 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001444 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445# endif
1446# if defined(FEAT_QUICKFIX)
1447 // Highlight the current line in the quickfix window.
1448 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001449 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001451 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 area_highlighting = TRUE;
1453#endif
1454
1455 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1456 ptr = line;
1457
1458#ifdef FEAT_SPELL
1459 if (has_spell && !number_only)
1460 {
1461 // For checking first word with a capital skip white space.
1462 if (cap_col == 0)
1463 cap_col = getwhitecols(line);
1464
1465 // To be able to spell-check over line boundaries copy the end of the
1466 // current line into nextline[]. Above the start of the next line was
1467 // copied to nextline[SPWORDLEN].
1468 if (nextline[SPWORDLEN] == NUL)
1469 {
1470 // No next line or it is empty.
1471 nextlinecol = MAXCOL;
1472 nextline_idx = 0;
1473 }
1474 else
1475 {
1476 v = (long)STRLEN(line);
1477 if (v < SPWORDLEN)
1478 {
1479 // Short line, use it completely and append the start of the
1480 // next line.
1481 nextlinecol = 0;
1482 mch_memmove(nextline, line, (size_t)v);
1483 STRMOVE(nextline + v, nextline + SPWORDLEN);
1484 nextline_idx = v + 1;
1485 }
1486 else
1487 {
1488 // Long line, use only the last SPWORDLEN bytes.
1489 nextlinecol = v - SPWORDLEN;
1490 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1491 nextline_idx = SPWORDLEN + 1;
1492 }
1493 }
1494 }
1495#endif
1496
1497 if (wp->w_p_list)
1498 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001499 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001500 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001501 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001502 || wp->w_lcs_chars.trail
1503 || wp->w_lcs_chars.lead
1504 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001506
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001508 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 {
1510 trailcol = (colnr_T)STRLEN(ptr);
1511 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1512 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001513 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001514 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001515 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001516 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001517 {
1518 leadcol = 0;
1519 while (VIM_ISWHITE(ptr[leadcol]))
1520 ++leadcol;
1521 if (ptr[leadcol] == NUL)
1522 // in a line full of spaces all of them are treated as trailing
1523 leadcol = (colnr_T)0;
1524 else
1525 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001526 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001527 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 }
1529
Bram Moolenaard7657e92022-09-20 18:59:30 +01001530 wlv.wcr_attr = get_wcr_attr(wp);
1531 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001532 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001533 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001534 area_highlighting = TRUE;
1535 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001536
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001537 // When w_skipcol is non-zero and there is virtual text above the actual
1538 // text, then this much of the virtual text is skipped.
1539 int skipcol_in_text_prop_above = 0;
1540
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001541#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001543 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001544
1545 char_u *prop_start;
1546 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1547 if (text_prop_count > 0)
1548 {
1549 // Make a copy of the properties, so that they are properly
1550 // aligned.
1551 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1552 if (text_props != NULL)
1553 mch_memmove(text_props, prop_start,
1554 text_prop_count * sizeof(textprop_T));
1555
1556 // Allocate an array for the indexes.
1557 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1558 if (text_prop_idxs == NULL)
1559 VIM_CLEAR(text_props);
1560
1561 if (text_props != NULL)
1562 {
1563 area_highlighting = TRUE;
1564 extra_check = TRUE;
1565
1566 // When skipping virtual text the props need to be sorted. The
1567 // order is reversed!
1568 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1569 {
1570 for (int i = 0; i < text_prop_count; ++i)
1571 text_prop_idxs[i] = i;
1572 sort_text_props(wp->w_buffer, text_props,
1573 text_prop_idxs, text_prop_count);
1574 }
1575
1576 // Text props "above" move the line number down to where the text
1577 // is. Only count the ones that are visible, not those that are
1578 // skipped because of w_skipcol.
1579 int text_width = wp->w_width - win_col_off(wp);
1580 for (int i = text_prop_count - 1; i >= 0; --i)
1581 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1582 {
1583 if (lnum == wp->w_topline
1584 && wp->w_skipcol - skipcol_in_text_prop_above
1585 >= text_width)
1586 {
1587 // This virtual text above is skipped, remove it from
1588 // the array.
1589 skipcol_in_text_prop_above += text_width;
1590 for (int j = i + 1; j < text_prop_count; ++j)
1591 text_props[j - 1] = text_props[j];
1592 ++i;
1593 --text_prop_count;
1594 }
1595 else
1596 ++wlv.text_prop_above_count;
1597 }
1598 }
1599 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600#endif
1601
1602 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1603 // first character to be displayed.
1604 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001605 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 else
1607 v = wp->w_leftcol;
1608 if (v > 0 && !number_only)
1609 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001610 char_u *prev_ptr = ptr;
1611 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001612 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001614 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001615 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001616 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001617 charsize = win_lbr_chartabsize(&cts, NULL);
1618 cts.cts_vcol += charsize;
1619 prev_ptr = cts.cts_ptr;
1620 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001622 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001623 ptr = cts.cts_ptr;
1624 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625
1626 // When:
1627 // - 'cuc' is set, or
1628 // - 'colorcolumn' is set, or
1629 // - 'virtualedit' is set, or
1630 // - the visual mode is active,
1631 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001632 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001633#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001634 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635#endif
1636 virtual_active() ||
1637 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001638 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001639
1640 // Handle a character that's not completely on the screen: Put ptr at
1641 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001642 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001644 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 ptr = prev_ptr;
1646 // If the character fits on the screen, don't need to skip it.
1647 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001648 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1649 && wlv.col == 0)
1650 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001651 }
1652
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001653#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001654 // If there the text doesn't reach to the desired column, need to skip
1655 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001656 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1657 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001658 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001659#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001660
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 // Adjust for when the inverted text is before the screen,
1662 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001663 if (wlv.tocol <= wlv.vcol)
1664 wlv.fromcol = 0;
1665 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1666 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667
1668#ifdef FEAT_LINEBREAK
1669 // When w_skipcol is non-zero, first line needs 'showbreak'
1670 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001671 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672#endif
1673#ifdef FEAT_SPELL
1674 // When spell checking a word we need to figure out the start of the
1675 // word and if it's badly spelled or not.
1676 if (has_spell)
1677 {
1678 int len;
1679 colnr_T linecol = (colnr_T)(ptr - line);
1680 hlf_T spell_hlf = HLF_COUNT;
1681
1682 pos = wp->w_cursor;
1683 wp->w_cursor.lnum = lnum;
1684 wp->w_cursor.col = linecol;
1685 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1686
1687 // spell_move_to() may call ml_get() and make "line" invalid
1688 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1689 ptr = line + linecol;
1690
1691 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1692 {
1693 // no bad word found at line start, don't check until end of a
1694 // word
1695 spell_hlf = HLF_COUNT;
1696 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1697 }
1698 else
1699 {
1700 // bad word found, use attributes until end of word
1701 word_end = wp->w_cursor.col + len + 1;
1702
1703 // Turn index into actual attributes.
1704 if (spell_hlf != HLF_COUNT)
1705 spell_attr = highlight_attr[spell_hlf];
1706 }
1707 wp->w_cursor = pos;
1708
1709# ifdef FEAT_SYN_HL
1710 // Need to restart syntax highlighting for this line.
1711 if (has_syntax)
1712 syntax_start(wp, lnum);
1713# endif
1714 }
1715#endif
1716 }
1717
1718 // Correct highlighting for cursor that can't be disabled.
1719 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001720 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721 {
1722 if (noinvcur)
1723 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001724 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 {
1726 // highlighting starts at cursor, let it start just after the
1727 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001728 fromcol_prev = wlv.fromcol;
1729 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001731 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 // restart highlighting after the cursor
1733 fromcol_prev = wp->w_virtcol;
1734 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001735 if (wlv.fromcol >= wlv.tocol)
1736 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 }
1738
1739#ifdef FEAT_SEARCH_EXTRA
1740 if (!number_only)
1741 {
1742 v = (long)(ptr - line);
1743 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1744 &line, &screen_search_hl,
1745 &search_attr);
1746 ptr = line + v; // "line" may have been updated
1747 }
1748#endif
1749
1750#ifdef FEAT_SYN_HL
1751 // Cursor line highlighting for 'cursorline' in the current window.
1752 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1753 {
1754 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001755 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001756 if (!(wp == curwin && VIsual_active)
1757 && wp->w_p_culopt_flags != CULOPT_NBR)
1758 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001759 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1761
zeertzjqb7acea12022-12-12 13:20:43 +00001762 // Only apply CursorLine highlight here when "screenline" is not
1763 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001765 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766 else
1767 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001768 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1770 }
1771 area_highlighting = TRUE;
1772 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 }
1774#endif
1775
Bram Moolenaar1306b362022-08-06 15:59:06 +01001776 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777
1778 // Repeat for the whole displayed line.
1779 for (;;)
1780 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001781 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001783 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001784#endif
1785#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001786 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001788
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001790 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001792#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001793 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001794 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001795 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001796 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001797 }
1798#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001799 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001801 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 if (cmdwin_type != 0 && wp == curwin)
1803 {
1804 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001805 wlv.n_extra = 1;
1806 wlv.c_extra = cmdwin_type;
1807 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001808 wlv.char_attr =
1809 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001810 }
1811 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001812#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001815 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001816 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 }
1818#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001820 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001821 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001822 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001823 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001825 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826 }
1827#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001830 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001831 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001832 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001835 // Check if 'breakindent' applies and show it.
1836 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1837 if (wlv.n_extra == 0)
1838 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001839#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001843 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001844 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 }
1846#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001849 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001850 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851 }
1852 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001853
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001856 && wlv.vcol >= left_curline_col
1857 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 {
zeertzjqb7acea12022-12-12 13:20:43 +00001859 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 }
1861#endif
1862
1863 // When still displaying '$' of change command, stop at cursor.
1864 // When only displaying the (relative) line number and that's done,
1865 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001866 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001867 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001868 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001870 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871#endif
1872 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001874 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 // Pretend we have finished updating the window. Except when
1876 // 'cursorcolumn' is set.
1877#ifdef FEAT_SYN_HL
1878 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001879 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001880 else
1881#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001882 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883 break;
1884 }
1885
Bram Moolenaar1306b362022-08-06 15:59:06 +01001886 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 {
1888 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001889 if (wlv.vcol == wlv.fromcol
1890 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1891 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 && (*mb_ptr2cells)(ptr) > 1)
1893 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001894 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001895 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 area_attr = vi_attr; // start highlighting
1897 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001898 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001899 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 area_attr = 0; // stop highlighting
1901
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001902#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 if (text_props != NULL)
1904 {
1905 int pi;
1906 int bcol = (int)(ptr - line);
1907
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001909# ifdef FEAT_LINEBREAK
1910 && !in_linebreak
1911# endif
1912 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 --bcol; // still working on the previous char, e.g. Tab
1914
1915 // Check if any active property ends.
1916 for (pi = 0; pi < text_props_active; ++pi)
1917 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001918 int tpi = text_prop_idxs[pi];
1919 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001921 // An inline property ends when after the start column plus
1922 // length. An "above" property ends when used and n_extra
1923 // is zero.
1924 if ((tp->tp_col != MAXCOL
1925 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 {
1927 if (pi + 1 < text_props_active)
1928 mch_memmove(text_prop_idxs + pi,
1929 text_prop_idxs + pi + 1,
1930 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001931 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 --text_props_active;
1933 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001934# ifdef FEAT_LINEBREAK
1935 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001936 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001937 syntax_attr = 0;
1938# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 }
1940 }
1941
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001942# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001943 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001944 // not on the next char yet, don't start another prop
1945 --bcol;
1946# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001947 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001948
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001949 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001950 // With 'nowrap' and not in the first screen line only "below"
1951 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001953 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001954 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001955 && (wp->w_p_wrap
1956 || wlv.row == startrow
1957 || (text_props[text_prop_next].tp_flags
1958 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001959 || (bcol == 0
1960 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001961 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001962 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001963 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001964 if (text_props[text_prop_next].tp_col == MAXCOL
1965 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001966 + text_props[text_prop_next].tp_len)
1967 text_prop_idxs[text_props_active++] = text_prop_next;
1968 ++text_prop_next;
1969 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001971 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001972 {
1973 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001974 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001975 text_prop_flags = 0;
1976 text_prop_type = NULL;
1977 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001978 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001979 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001980 if (text_props_active > 0 && wlv.n_extra == 0
1981 && !display_text_first)
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 Moolenaarc9dc03f2022-09-12 17:51:07 +01001987 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001988 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001989
1990 // Sort the properties on priority and/or starting last.
1991 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001992 sort_text_props(wp->w_buffer, text_props,
1993 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994
1995 for (pi = 0; pi < text_props_active; ++pi)
1996 {
1997 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001998 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002000 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001
Bram Moolenaarcd105412022-10-10 19:50:42 +01002002 // Only use a text property that can be displayed.
2003 // Skip "after" properties when wrap is off and at the
2004 // end of the window.
2005 if (pt != NULL
2006 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2007 && tp->tp_id != -MAXCOL
2008 && !(tp->tp_id < 0
2009 && !wp->w_p_wrap
2010 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2011 | TP_FLAG_ALIGN_ABOVE
2012 | TP_FLAG_ALIGN_BELOW)) == 0
2013 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002014 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002015 if (tp->tp_col == MAXCOL
2016 && *ptr == NUL
2017 && ((wp->w_p_list && lcs_eol_one > 0
2018 && (tp->tp_flags
2019 & TP_FLAG_ALIGN_ABOVE) == 0)
2020 || (ptr == line
2021 && !did_line
2022 && (tp->tp_flags
2023 & TP_FLAG_ALIGN_BELOW))))
2024 {
2025 // skip this prop, first display the '$' after
2026 // the line or display an empty line
2027 text_prop_follows = TRUE;
2028 if (used_tpi < 0)
2029 display_text_first = TRUE;
2030 continue;
2031 }
2032
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002033 if (pt->pt_hl_id > 0)
2034 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 text_prop_type = pt;
2036 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002037 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002038 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2039 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002040 text_prop_flags = pt->pt_flags;
2041 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002042 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002043 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044 }
2045 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002046 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002047 && -text_prop_id
2048 <= wp->w_buffer->b_textprop_text.ga_len)
2049 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002050 textprop_T *tp = &text_props[used_tpi];
2051 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002052 ->b_textprop_text.ga_data)[
2053 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002054 int above = (tp->tp_flags
2055 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002056 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002057
2058 // reset the ID in the copy to avoid it being used
2059 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002060 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002061
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002062 if (p != NULL)
2063 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002064 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002065 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002066 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002067 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002068 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2069 int padding = tp->tp_col == MAXCOL
2070 && tp->tp_len > 1
2071 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002072
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002073 // Insert virtual text before the current
2074 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002075 wlv.p_extra = p;
2076 wlv.c_extra = NUL;
2077 wlv.c_final = NUL;
2078 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002079 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002080 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2081 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002082 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002083 // restore search_attr and area_attr when n_extra
2084 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002085 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002086 saved_area_attr = area_attr;
2087 search_attr = 0;
2088 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002089 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002090 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002091 if (*ptr == NUL)
2092 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002093 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002094#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002095 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002096 {
2097 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002098 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002099 wlv.need_showbreak = FALSE;
2100 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002101 }
2102#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002103 if ((right || above || below || !wrap
2104 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002105 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002106 char_u *prev_p_extra = wlv.p_extra;
2107 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002108
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002109 // Take care of padding, right-align and
2110 // truncation.
2111 // Shared with win_lbr_chartabsize(), must do
2112 // exactly the same.
2113 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002114 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002115 wlv.col,
2116 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002117 &n_attr, &wlv.n_attr_skip,
2118 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002119 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 // wlv.p_extra was allocated
2122 vim_free(p_extra_free2);
2123 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002124 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002125
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002126 if (lcs_eol_one < 0
2127 && wp->w_p_wrap
2128 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002129 + wlv.n_extra - 2 > wp->w_width)
2130 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002131 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002132
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002133 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002134 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002135 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002136 {
2137 draw_screen_line(wp, &wlv);
2138
2139 // When line got too long for screen break
2140 // here.
2141 if (wlv.row == endrow)
2142 {
2143 ++wlv.row;
2144 break;
2145 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002146 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002147 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002148 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002149 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002150 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151
Bram Moolenaarcd105412022-10-10 19:50:42 +01002152 // If the text didn't reach until the first window
2153 // column we need to skip cells.
2154 if (skip_cells > 0)
2155 {
2156 if (wlv.n_extra > skip_cells)
2157 {
2158 wlv.n_extra -= skip_cells;
2159 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002160 wlv.n_attr_skip -= skip_cells;
2161 if (wlv.n_attr_skip < 0)
2162 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002163 skip_cells = 0;
2164 }
2165 else
2166 {
2167 // the whole text is left of the window, drop
2168 // it and advance to the next one
2169 skip_cells -= wlv.n_extra;
2170 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002171 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002172 bail_out = TRUE;
2173 }
2174 }
2175
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002176 // If another text prop follows the condition below at
2177 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002178 // If this is an "above" text prop and 'nowrap' the we
2179 // must wrap anyway.
2180 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002181 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002182 && (wp->w_p_wrap
2183 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002184 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002185
2186 if (bail_out)
2187 // starting a new line for "below"
2188 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002189 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002190 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002191 else if (text_prop_next < text_prop_count
2192 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002193 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2194 || (!wp->w_p_wrap
2195 && wlv.col == wp->w_width - 1
2196 && (text_props[text_prop_next].tp_flags
2197 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002198 // When at last-but-one character and a text property
2199 // follows after it, we may need to flush the line after
2200 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002201 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002202 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 }
2204#endif
2205
Bram Moolenaare38fc862022-08-11 17:24:50 +01002206#ifdef FEAT_SEARCH_EXTRA
2207 if (wlv.n_extra == 0)
2208 {
2209 // Check for start/end of 'hlsearch' and other matches.
2210 // After end, check for start/end of next match.
2211 // When another match, have to check for start again.
2212 v = (long)(ptr - line);
2213 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2214 &screen_search_hl, &has_match_conc,
2215 &match_conc, did_line_attr, lcs_eol_one,
2216 &on_last_col);
2217 ptr = line + v; // "line" may have been changed
2218 prev_ptr = ptr;
2219
2220 // Do not allow a conceal over EOL otherwise EOL will be missed
2221 // and bad things happen.
2222 if (*ptr == NUL)
2223 has_match_conc = 0;
2224 }
2225#endif
2226
2227#ifdef FEAT_DIFF
2228 if (wlv.diff_hlf != (hlf_T)0)
2229 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002230 // When there is extra text (e.g. virtual text) it gets the
2231 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002232 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2233 && wlv.n_extra == 0)
2234 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002235 if (wlv.diff_hlf == HLF_TXD
2236 && ((ptr - line > change_end && wlv.n_extra == 0)
2237 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002238 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002239 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002240 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2241 && wp->w_p_culopt_flags != CULOPT_NBR
2242 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2243 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002244 wlv.line_attr = hl_combine_attr(
2245 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002246 }
2247#endif
2248
Bram Moolenaara74fda62019-10-19 17:38:03 +02002249#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002250 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002251 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002252 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002253# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002254 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002255 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002256# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002257 // Get syntax attribute.
2258 if (has_syntax)
2259 {
2260 // Get the syntax attribute for the character. If there
2261 // is an error, disable syntax highlighting.
2262 save_did_emsg = did_emsg;
2263 did_emsg = FALSE;
2264
2265 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002266 if (v == prev_syntax_col)
2267 // at same column again
2268 syntax_attr = prev_syntax_attr;
2269 else
2270 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002271# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002272 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002273# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002274 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002275# ifdef FEAT_SPELL
2276 has_spell ? &can_spell :
2277# endif
2278 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002279 prev_syntax_col = v;
2280 prev_syntax_attr = syntax_attr;
2281 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002282
Bram Moolenaar34390282019-10-16 14:38:26 +02002283 if (did_emsg)
2284 {
2285 wp->w_s->b_syn_error = TRUE;
2286 has_syntax = FALSE;
2287 syntax_attr = 0;
2288 }
2289 else
2290 did_emsg = save_did_emsg;
2291# ifdef SYN_TIME_LIMIT
2292 if (wp->w_s->b_syn_slow)
2293 has_syntax = FALSE;
2294# endif
2295
2296 // Need to get the line again, a multi-line regexp may
2297 // have made it invalid.
2298 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2299 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002300 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002301# ifdef FEAT_CONCEAL
2302 // no concealing past the end of the line, it interferes
2303 // with line highlighting
2304 if (*ptr == NUL)
2305 syntax_flags = 0;
2306 else
2307 syntax_flags = get_syntax_info(&syntax_seqnr);
2308# endif
2309 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002310 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002311# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002312 // Combine text property highlight into syntax highlight.
2313 if (text_prop_type != NULL)
2314 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002315 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002316 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2317 else
2318 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002319 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002320 }
2321# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002322#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002323
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 // Decide which of the highlight attributes to use.
2325 attr_pri = TRUE;
2326#ifdef LINE_ATTR
2327 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002328 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002329 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002330 if (!highlight_match)
2331 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002333# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002335# endif
2336 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002338 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002339 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002340# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002341 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002342# endif
2343 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002344 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002345 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2346 || wlv.vcol < wlv.fromcol
2347 || vcol_prev < fromcol_prev
2348 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002350 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002352# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002353 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002354# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002355 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002356# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002357 attr_pri = FALSE;
2358 }
2359#else
2360 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002361 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002362 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002363 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364#endif
2365 else
2366 {
2367 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002369 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002370#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002371 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002372#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002374#ifdef FEAT_PROP_POPUP
2375 // override with text property highlight when "override" is TRUE
2376 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002377 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002378#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002379 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002380
2381 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002382 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 if (wlv.char_attr == 0)
2385 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002386 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002388 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002389
2390 // Get the next character to put on the screen.
2391
2392 // The "p_extra" points to the extra stuff that is inserted to
2393 // represent special characters (non-printable stuff) and other
2394 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002395 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2397 // "p_extra[n_extra]".
2398 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002400 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002401 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002403 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2404 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002405 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2406 if (enc_utf8 && utf_char2len(c) > 1)
2407 {
2408 mb_utf8 = TRUE;
2409 u8cc[0] = 0;
2410 c = 0xc0;
2411 }
2412 else
2413 mb_utf8 = FALSE;
2414 }
2415 else
2416 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002418 if (has_mbyte)
2419 {
2420 mb_c = c;
2421 if (enc_utf8)
2422 {
2423 // If the UTF-8 character is more than one byte:
2424 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002425 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002427 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428 mb_l = 1;
2429 else if (mb_l > 1)
2430 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002431 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 mb_utf8 = TRUE;
2433 c = 0xc0;
2434 }
2435 }
2436 else
2437 {
2438 // if this is a DBCS character, put it in "mb_c"
2439 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 mb_l = 1;
2442 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002443 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444 }
2445 if (mb_l == 0) // at the NUL at end-of-line
2446 mb_l = 1;
2447
2448 // If a double-width char doesn't fit display a '>' in the
2449 // last column.
2450 if ((
2451# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002452 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002454 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 && (*mb_char2cells)(mb_c) == 2)
2456 {
2457 c = '>';
2458 mb_c = c;
2459 mb_l = 1;
2460 mb_utf8 = FALSE;
2461 multi_attr = HL_ATTR(HLF_AT);
2462#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002463 if (wlv.cul_attr)
2464 multi_attr = hl_combine_attr(
2465 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002467 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002468
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002469 // put the pointer back to output the double-width
2470 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002471 ++wlv.n_extra;
2472 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 }
2474 else
2475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 wlv.n_extra -= mb_l - 1;
2477 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 }
2479 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002482 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002483#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002485 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002486 // Only restore search_attr and area_attr after "n_extra" in
2487 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002488 if (wlv.saved_n_extra <= 0)
2489 {
2490 if (search_attr == 0)
2491 search_attr = saved_search_attr;
2492 if (area_attr == 0 && *ptr != NUL)
2493 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002494
2495 if (wlv.extra_for_textprop)
2496 // wlv.extra_attr should be used at this position but
2497 // not any further.
2498 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002499 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002500
2501 wlv.extra_for_textprop = FALSE;
2502 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002503 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002504#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 }
2506 else
2507 {
2508#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002509 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002511 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002512
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 // Get a character from the line itself.
2514 c = *ptr;
2515#ifdef FEAT_LINEBREAK
2516 c0 = *ptr;
2517#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002518#ifdef FEAT_PROP_POPUP
2519 if (c == NUL)
2520 // text is finished, may display a "below" virtual text
2521 did_line = TRUE;
2522#endif
2523
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 if (has_mbyte)
2525 {
2526 mb_c = c;
2527 if (enc_utf8)
2528 {
2529 // If the UTF-8 character is more than one byte: Decode it
2530 // into "mb_c".
2531 mb_l = utfc_ptr2len(ptr);
2532 mb_utf8 = FALSE;
2533 if (mb_l > 1)
2534 {
2535 mb_c = utfc_ptr2char(ptr, u8cc);
2536 // Overlong encoded ASCII or ASCII with composing char
2537 // is displayed normally, except a NUL.
2538 if (mb_c < 0x80)
2539 {
2540 c = mb_c;
2541#ifdef FEAT_LINEBREAK
2542 c0 = mb_c;
2543#endif
2544 }
2545 mb_utf8 = TRUE;
2546
2547 // At start of the line we can have a composing char.
2548 // Draw it as a space with a composing char.
2549 if (utf_iscomposing(mb_c))
2550 {
2551 int i;
2552
2553 for (i = Screen_mco - 1; i > 0; --i)
2554 u8cc[i] = u8cc[i - 1];
2555 u8cc[0] = mb_c;
2556 mb_c = ' ';
2557 }
2558 }
2559
2560 if ((mb_l == 1 && c >= 0x80)
2561 || (mb_l >= 1 && mb_c == 0)
2562 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2563 {
2564 // Illegal UTF-8 byte: display as <xx>.
2565 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002566 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567# ifdef FEAT_RIGHTLEFT
2568 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002569 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002571 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 c = *wlv.p_extra;
2573 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002575 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2576 wlv.c_extra = NUL;
2577 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002578 if (area_attr == 0 && search_attr == 0)
2579 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002581 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002582 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002583 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 }
2585 }
2586 else if (mb_l == 0) // at the NUL at end-of-line
2587 mb_l = 1;
2588#ifdef FEAT_ARABIC
2589 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2590 {
2591 // Do Arabic shaping.
2592 int pc, pc1, nc;
2593 int pcc[MAX_MCO];
2594
2595 // The idea of what is the previous and next
2596 // character depends on 'rightleft'.
2597 if (wp->w_p_rl)
2598 {
2599 pc = prev_c;
2600 pc1 = prev_c1;
2601 nc = utf_ptr2char(ptr + mb_l);
2602 prev_c1 = u8cc[0];
2603 }
2604 else
2605 {
2606 pc = utfc_ptr2char(ptr + mb_l, pcc);
2607 nc = prev_c;
2608 pc1 = pcc[0];
2609 }
2610 prev_c = mb_c;
2611
2612 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2613 }
2614 else
2615 prev_c = mb_c;
2616#endif
2617 }
2618 else // enc_dbcs
2619 {
2620 mb_l = MB_BYTE2LEN(c);
2621 if (mb_l == 0) // at the NUL at end-of-line
2622 mb_l = 1;
2623 else if (mb_l > 1)
2624 {
2625 // We assume a second byte below 32 is illegal.
2626 // Hopefully this is OK for all double-byte encodings!
2627 if (ptr[1] >= 32)
2628 mb_c = (c << 8) + ptr[1];
2629 else
2630 {
2631 if (ptr[1] == NUL)
2632 {
2633 // head byte at end of line
2634 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002635 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 }
2637 else
2638 {
2639 // illegal tail byte
2640 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002641 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002643 wlv.p_extra = wlv.extra;
2644 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002645 wlv.c_extra = NUL;
2646 wlv.c_final = NUL;
2647 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002648 if (area_attr == 0 && search_attr == 0)
2649 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002650 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002651 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002652 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002653 // save current attr
2654 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 }
2656 mb_c = c;
2657 }
2658 }
2659 }
2660 // If a double-width char doesn't fit display a '>' in the
2661 // last column; the character is displayed at the start of the
2662 // next line.
2663 if ((
2664# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002665 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002667 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002668 && (*mb_char2cells)(mb_c) == 2)
2669 {
2670 c = '>';
2671 mb_c = c;
2672 mb_utf8 = FALSE;
2673 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002674 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 // Put pointer back so that the character will be
2676 // displayed at the start of the next line.
2677 --ptr;
2678#ifdef FEAT_CONCEAL
2679 did_decrement_ptr = TRUE;
2680#endif
2681 }
2682 else if (*ptr != NUL)
2683 ptr += mb_l - 1;
2684
2685 // If a double-width char doesn't fit at the left side display
2686 // a '<' in the first column. Don't do this for unprintable
2687 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002688 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002690 wlv.n_extra = 1;
2691 wlv.c_extra = MB_FILLER_CHAR;
2692 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002693 c = ' ';
2694 if (area_attr == 0 && search_attr == 0)
2695 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002696 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002697 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002698 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002700 }
2701 mb_c = c;
2702 mb_utf8 = FALSE;
2703 mb_l = 1;
2704 }
2705
2706 }
2707 ++ptr;
2708
2709 if (extra_check)
2710 {
2711#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712 // Check spelling (unless at the end of the line).
2713 // Only do this when there is no syntax highlighting, the
2714 // @Spell cluster is not used or the current syntax item
2715 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002716 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002717 if (has_spell && v >= word_end && v > cur_checked_col)
2718 {
2719 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002720 // do not calculate cap_col at the end of the line or when
2721 // only white space is following
2722 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002723# ifdef FEAT_SYN_HL
2724 !has_syntax ||
2725# endif
2726 can_spell))
2727 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002728 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 int len;
2730 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002731
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002732 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734
2735 // Use nextline[] if possible, it has the start of the
2736 // next line concatenated.
2737 if ((prev_ptr - line) - nextlinecol >= 0)
2738 p = nextline + (prev_ptr - line) - nextlinecol;
2739 else
2740 p = prev_ptr;
2741 cap_col -= (int)(prev_ptr - line);
2742 len = spell_check(wp, p, &spell_hlf, &cap_col,
2743 nochange);
2744 word_end = v + len;
2745
2746 // In Insert mode only highlight a word that
2747 // doesn't touch the cursor.
2748 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002749 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 && wp->w_cursor.lnum == lnum
2751 && wp->w_cursor.col >=
2752 (colnr_T)(prev_ptr - line)
2753 && wp->w_cursor.col < (colnr_T)word_end)
2754 {
2755 spell_hlf = HLF_COUNT;
2756 spell_redraw_lnum = lnum;
2757 }
2758
2759 if (spell_hlf == HLF_COUNT && p != prev_ptr
2760 && (p - nextline) + len > nextline_idx)
2761 {
2762 // Remember that the good word continues at the
2763 // start of the next line.
2764 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002765 checked_col = (int)((p - nextline)
2766 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 }
2768
2769 // Turn index into actual attributes.
2770 if (spell_hlf != HLF_COUNT)
2771 spell_attr = highlight_attr[spell_hlf];
2772
2773 if (cap_col > 0)
2774 {
2775 if (p != prev_ptr
2776 && (p - nextline) + cap_col >= nextline_idx)
2777 {
2778 // Remember that the word in the next line
2779 // must start with a capital.
2780 capcol_lnum = lnum + 1;
2781 cap_col = (int)((p - nextline) + cap_col
2782 - nextline_idx);
2783 }
2784 else
2785 // Compute the actual column.
2786 cap_col += (int)(prev_ptr - line);
2787 }
2788 }
2789 }
2790 if (spell_attr != 0)
2791 {
2792 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2794 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 wlv.char_attr = hl_combine_attr(spell_attr,
2797 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002798 }
2799#endif
2800#ifdef FEAT_LINEBREAK
2801 // Found last space before word: check for line break.
2802 if (wp->w_p_lbr && c0 == c
2803 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2804 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002805 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2806 : 0;
2807 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002808 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002810 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002811# ifdef FEAT_PROP_POPUP
2812 // do not want virtual text counted here
2813 cts.cts_has_prop_with_text = FALSE;
2814# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002815 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002816 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002817
2818 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002819 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002820 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002821 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002822 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2823 if (wlv.n_extra < 0)
2824 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002825 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002826 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002827 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002828 // line break, but for TABs the highlighting should
2829 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002830 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002831
Bram Moolenaar1306b362022-08-06 15:59:06 +01002832 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002834 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002835 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 wp->w_buffer->b_p_vts_array) - 1;
2837# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002838 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840# endif
2841
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2843 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002844# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002845 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002846 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002847# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 if (VIM_ISWHITE(c))
2849 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002850# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002851 if (c == TAB)
2852 // See "Tab alignment" below.
2853 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002854# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 if (!wp->w_p_list)
2856 c = ' ';
2857 }
2858 }
2859#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002860 in_multispace = c == ' '
2861 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2862 if (!in_multispace)
2863 multispace_pos = 0;
2864
Bram Moolenaareed9d462021-02-15 20:38:25 +01002865 // 'list': Change char 160 to 'nbsp' and space to 'space'
2866 // setting in 'listchars'. But not when the character is
2867 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 if (wp->w_p_list
2869 && ((((c == 160 && mb_l == 1)
2870 || (mb_utf8
2871 && ((mb_c == 160 && mb_l == 2)
2872 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002873 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 || (c == ' '
2875 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002876 && (wp->w_lcs_chars.space
2877 || (in_multispace
2878 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002879 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 && ptr - line <= trailcol)))
2881 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002882 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2883 {
2884 c = wp->w_lcs_chars.multispace[multispace_pos++];
2885 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2886 multispace_pos = 0;
2887 }
2888 else
2889 c = (c == ' ') ? wp->w_lcs_chars.space
2890 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891 if (area_attr == 0 && search_attr == 0)
2892 {
2893 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002894 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002895 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 }
2898 mb_c = c;
2899 if (enc_utf8 && utf_char2len(c) > 1)
2900 {
2901 mb_utf8 = TRUE;
2902 u8cc[0] = 0;
2903 c = 0xc0;
2904 }
2905 else
2906 mb_utf8 = FALSE;
2907 }
2908
zeertzjq2e7cba32022-06-10 15:30:32 +01002909 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2910 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002912 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2913 && wp->w_lcs_chars.leadmultispace != NULL)
2914 {
2915 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002916 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2917 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002918 multispace_pos = 0;
2919 }
2920
2921 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2922 c = wp->w_lcs_chars.trail;
2923
2924 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2925 c = wp->w_lcs_chars.lead;
2926
zeertzjq2e7cba32022-06-10 15:30:32 +01002927 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002928 c = wp->w_lcs_chars.space;
2929
2930
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002931 if (!attr_pri)
2932 {
2933 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002934 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002935 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002936 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 }
2938 mb_c = c;
2939 if (enc_utf8 && utf_char2len(c) > 1)
2940 {
2941 mb_utf8 = TRUE;
2942 u8cc[0] = 0;
2943 c = 0xc0;
2944 }
2945 else
2946 mb_utf8 = FALSE;
2947 }
2948 }
2949
2950 // Handling of non-printable characters.
2951 if (!vim_isprintc(c))
2952 {
2953 // when getting a character from the file, we may have to
2954 // turn it into something else on the way to putting it
2955 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002956 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002958 int tab_len = 0;
2959 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002961 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002962
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002963 // only adjust the tab_len, when at the first column
2964 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002965 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002966 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967#endif
2968 // tab amount depends on current column
2969#ifdef FEAT_VARTABS
2970 tab_len = tabstop_padding(vcol_adjusted,
2971 wp->w_buffer->b_p_ts,
2972 wp->w_buffer->b_p_vts_array) - 1;
2973#else
2974 tab_len = (int)wp->w_buffer->b_p_ts
2975 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2976#endif
2977
2978#ifdef FEAT_LINEBREAK
2979 if (!wp->w_p_lbr || !wp->w_p_list)
2980#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002981 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002984 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985#ifdef FEAT_LINEBREAK
2986 else
2987 {
2988 char_u *p;
2989 int len;
2990 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002991 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002993# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002996 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002997
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002998 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002999 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003000 && old_boguscols > 0
3001 && wlv.n_extra > tab_len)
3002 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003003# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003004 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003005 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003006 // If wlv.n_extra > 0, it gives the number of chars
3007 // to use for a tab, else we need to calculate the
3008 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003009 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3010 len = tab_len * tab2_len;
3011 if (wp->w_lcs_chars.tab3)
3012 len += mb_char2len(wp->w_lcs_chars.tab3)
3013 - tab2_len;
3014 if (wlv.n_extra > 0)
3015 len += wlv.n_extra - tab_len;
3016 c = wp->w_lcs_chars.tab1;
3017 p = alloc(len + 1);
3018 if (p == NULL)
3019 wlv.n_extra = 0;
3020 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003022 vim_memset(p, ' ', len);
3023 p[len] = NUL;
3024 vim_free(wlv.p_extra_free);
3025 wlv.p_extra_free = p;
3026 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003027 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003028 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003029
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003030 if (*p == NUL)
3031 {
3032 tab_len = i;
3033 break;
3034 }
3035
3036 // if tab3 is given, use it for the last
3037 // char
3038 if (wp->w_lcs_chars.tab3
3039 && i == tab_len - 1)
3040 lcs = wp->w_lcs_chars.tab3;
3041 p += mb_char2bytes(lcs, p);
3042 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003043 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003044 }
3045 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003046# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003047 // n_extra will be increased by
3048 // FIX_FOX_BOGUSCOLS macro below, so need to
3049 // adjust for that here
3050 if (wlv.vcol_off > 0)
3051 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003052# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003053 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003055 }
3056#endif
3057#ifdef FEAT_CONCEAL
3058 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003059 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003060
3061 // Tab alignment should be identical regardless of
3062 // 'conceallevel' value. So tab compensates of all
3063 // previous concealed characters, and thus resets
3064 // vcol_off and boguscols accumulated so far in the
3065 // line. Note that the tab can be longer than
3066 // 'tabstop' when there are concealed characters.
3067 FIX_FOR_BOGUSCOLS;
3068
3069 // Make sure, the highlighting for the tab char will be
3070 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003071 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003072 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003073 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 tab_len += vc_saved;
3075 }
3076#endif
3077 mb_utf8 = FALSE; // don't draw as UTF-8
3078 if (wp->w_p_list)
3079 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003080 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003081 ? wp->w_lcs_chars.tab3
3082 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003084 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003085 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003086 else
3087#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003088 wlv.c_extra = wp->w_lcs_chars.tab2;
3089 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003091 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003092 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003093 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 mb_c = c;
3095 if (enc_utf8 && utf_char2len(c) > 1)
3096 {
3097 mb_utf8 = TRUE;
3098 u8cc[0] = 0;
3099 c = 0xc0;
3100 }
3101 }
3102 else
3103 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003104 wlv.c_final = NUL;
3105 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003106 c = ' ';
3107 }
3108 }
3109 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003110 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003111 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003112 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3113 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 && VIsual_mode != Ctrl_V
3115 && (
3116# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003117 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003118# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003119 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120 && !(noinvcur
3121 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003122 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003123 && lcs_eol_one > 0)
3124 {
3125 // Display a '$' after the line or highlight an extra
3126 // character if the line break is included.
3127#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3128 // For a diff line the highlighting continues after the
3129 // "$".
3130 if (
3131# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003132 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003133# ifdef LINE_ATTR
3134 &&
3135# endif
3136# endif
3137# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003138 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139# endif
3140 )
3141#endif
3142 {
3143 // In virtualedit, visual selections may extend
3144 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003145 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003146 && wlv.tocol != MAXCOL
3147 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003149 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003151 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3152 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 else
3154 c = ' ';
3155 lcs_eol_one = -1;
3156 --ptr; // put it back at the NUL
3157 if (!attr_pri)
3158 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003159 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003160 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 n_attr = 1;
3162 }
3163 mb_c = c;
3164 if (enc_utf8 && utf_char2len(c) > 1)
3165 {
3166 mb_utf8 = TRUE;
3167 u8cc[0] = 0;
3168 c = 0xc0;
3169 }
3170 else
3171 mb_utf8 = FALSE; // don't draw as UTF-8
3172 }
3173 else if (c != NUL)
3174 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003175 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3176 if (wlv.n_extra == 0)
3177 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178#ifdef FEAT_RIGHTLEFT
3179 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003182 wlv.c_extra = NUL;
3183 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184#ifdef FEAT_LINEBREAK
3185 if (wp->w_p_lbr)
3186 {
3187 char_u *p;
3188
Bram Moolenaar1306b362022-08-06 15:59:06 +01003189 c = *wlv.p_extra;
3190 p = alloc(wlv.n_extra + 1);
3191 vim_memset(p, ' ', wlv.n_extra);
3192 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3193 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003194 vim_free(wlv.p_extra_free);
3195 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003196 }
3197 else
3198#endif
3199 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 wlv.n_extra = byte2cells(c) - 1;
3201 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202 }
3203 if (!attr_pri)
3204 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003205 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003206 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003207 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003208 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 }
3210 mb_utf8 = FALSE; // don't draw as UTF-8
3211 }
3212 else if (VIsual_active
3213 && (VIsual_mode == Ctrl_V
3214 || VIsual_mode == 'v')
3215 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003216 && wlv.tocol != MAXCOL
3217 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218 && (
3219#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003220 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003222 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223 {
3224 c = ' ';
3225 --ptr; // put it back at the NUL
3226 }
3227#if defined(LINE_ATTR)
3228 else if ((
3229# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231# endif
3232# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003233 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003235 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 ) && (
3237# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003240 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003241# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003242 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243# endif
3244 < wp->w_width)))
3245 {
3246 // Highlight until the right side of the window
3247 c = ' ';
3248 --ptr; // put it back at the NUL
3249
3250 // Remember we do the char for line highlighting.
3251 ++did_line_attr;
3252
3253 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003254 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003256 || (wp->w_p_list &&
3257 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003258 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003262 wlv.diff_hlf = HLF_CHD;
3263 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3267 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003269 || (wlv.vcol >= left_curline_col
3270 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003271 wlv.char_attr = hl_combine_attr(
3272 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 }
3274 }
3275# endif
3276# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003280 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3281 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003283 if (!wlv.cul_screenline
3284 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003285 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 wlv.char_attr = hl_combine_attr(
3287 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003289 else if (wlv.line_attr)
3290 wlv.char_attr = hl_combine_attr(
3291 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 }
3293# endif
3294 }
3295#endif
3296 }
3297
3298#ifdef FEAT_CONCEAL
3299 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003300 && (wp != curwin || lnum != wp->w_cursor.lnum
3301 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3303 && !(lnum_in_visual_area
3304 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3305 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003306 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003307 if (((prev_syntax_id != syntax_seqnr
3308 && (syntax_flags & HL_CONCEAL) != 0)
3309 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003310 && (syn_get_sub_char() != NUL
3311 || (has_match_conc && match_conc)
3312 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313 && wp->w_p_cole != 3)
3314 {
3315 // First time at this concealed item: display one
3316 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003317 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 c = match_conc;
3319 else if (syn_get_sub_char() != NUL)
3320 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003321 else if (wp->w_lcs_chars.conceal != NUL)
3322 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 else
3324 c = ' ';
3325
3326 prev_syntax_id = syntax_seqnr;
3327
Bram Moolenaar1306b362022-08-06 15:59:06 +01003328 if (wlv.n_extra > 0)
3329 wlv.vcol_off += wlv.n_extra;
3330 wlv.vcol += wlv.n_extra;
3331 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003332 {
3333# ifdef FEAT_RIGHTLEFT
3334 if (wp->w_p_rl)
3335 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003336 wlv.col -= wlv.n_extra;
3337 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 }
3339 else
3340# endif
3341 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 wlv.boguscols += wlv.n_extra;
3343 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
3345 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003346 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 n_attr = 0;
3348 }
3349 else if (n_skip == 0)
3350 {
3351 is_concealing = TRUE;
3352 n_skip = 1;
3353 }
3354 mb_c = c;
3355 if (enc_utf8 && utf_char2len(c) > 1)
3356 {
3357 mb_utf8 = TRUE;
3358 u8cc[0] = 0;
3359 c = 0xc0;
3360 }
3361 else
3362 mb_utf8 = FALSE; // don't draw as UTF-8
3363 }
3364 else
3365 {
3366 prev_syntax_id = 0;
3367 is_concealing = FALSE;
3368 }
3369
3370 if (n_skip > 0 && did_decrement_ptr)
3371 // not showing the '>', put pointer back to avoid getting stuck
3372 ++ptr;
3373
3374#endif // FEAT_CONCEAL
3375 }
3376
3377#ifdef FEAT_CONCEAL
3378 // In the cursor line and we may be concealing characters: correct
3379 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003381 && wp == curwin && lnum == wp->w_cursor.lnum
3382 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003385# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003389# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003390 wp->w_wcol = wlv.col - wlv.boguscols;
3391 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 did_wcol = TRUE;
3393 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003394# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003395 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003396# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 }
3398#endif
3399
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003400 // Use "wlv.extra_attr", but don't override visual selection
3401 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003402 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3403 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003404 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003405 && (!attr_pri
3406#ifdef FEAT_PROP_POPUP
3407 || (text_prop_flags & PT_FLAG_OVERRIDE)
3408#endif
3409 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 {
3411#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003412 if (wlv.line_attr)
3413 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003414 else
3415#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003416 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003417#ifdef FEAT_PROP_POPUP
3418 if (reset_extra_attr)
3419 {
3420 reset_extra_attr = FALSE;
3421 wlv.extra_attr = 0;
3422 }
3423#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 }
3425
3426#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3427 // XIM don't send preedit_start and preedit_end, but they send
3428 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3429 // im_is_preediting() here.
3430 if (p_imst == IM_ON_THE_SPOT
3431 && xic != NULL
3432 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003433 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 && !p_imdisable
3435 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 {
3438 colnr_T tcol;
3439
3440 if (preedit_end_col == MAXCOL)
3441 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3442 else
3443 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003444 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 {
3446 if (feedback_old_attr < 0)
3447 {
3448 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003449 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 wlv.char_attr = im_get_feedback_attr(feedback_col);
3452 if (wlv.char_attr < 0)
3453 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 feedback_col++;
3455 }
3456 else if (feedback_old_attr >= 0)
3457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 feedback_old_attr = -1;
3460 feedback_col = 0;
3461 }
3462 }
3463#endif
3464 // Handle the case where we are in column 0 but not on the first
3465 // character of the line and the user wants us to show us a
3466 // special character (via 'listchars' option "precedes:<char>".
3467 if (lcs_prec_todo != NUL
3468 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003469 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3470 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003472 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 && c != NUL)
3476 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003477 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003478 lcs_prec_todo = NUL;
3479 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3480 {
3481 // Double-width character being overwritten by the "precedes"
3482 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 wlv.c_extra = MB_FILLER_CHAR;
3484 wlv.c_final = NUL;
3485 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003486 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003487 wlv.extra_attr =
3488 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
3490 mb_c = c;
3491 if (enc_utf8 && utf_char2len(c) > 1)
3492 {
3493 mb_utf8 = TRUE;
3494 u8cc[0] = 0;
3495 c = 0xc0;
3496 }
3497 else
3498 mb_utf8 = FALSE; // don't draw as UTF-8
3499 if (!attr_pri)
3500 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003501 saved_attr3 = wlv.char_attr; // save current attr
3502 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503 n_attr3 = 1;
3504 }
3505 }
3506
3507 // At end of the text line or just after the last character.
3508 if ((c == NUL
3509#if defined(LINE_ATTR)
3510 || did_line_attr == 1
3511#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 {
3514#ifdef FEAT_SEARCH_EXTRA
3515 // flag to indicate whether prevcol equals startcol of search_hl or
3516 // one of the matches
3517 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3518 (long)(ptr - line) - (c == NUL));
3519#endif
3520 // Invert at least one char, used for Visual and empty line or
3521 // highlight match at end of line. If it's beyond the last
3522 // char on the screen, just overwrite that one (tricky!) Not
3523 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003524 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003525 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 && (VIsual_mode != Ctrl_V
3527 || lnum == VIsual.lnum
3528 || lnum == curwin->w_cursor.lnum)
3529 && c == NUL)
3530#ifdef FEAT_SEARCH_EXTRA
3531 // highlight 'hlsearch' match at end of line
3532 || (prevcol_hl_flag
3533# ifdef FEAT_SYN_HL
3534 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3535 && !(wp == curwin && VIsual_active))
3536# endif
3537# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539# endif
3540# if defined(LINE_ATTR)
3541 && did_line_attr <= 1
3542# endif
3543 )
3544#endif
3545 ))
3546 {
3547 int n = 0;
3548
3549#ifdef FEAT_RIGHTLEFT
3550 if (wp->w_p_rl)
3551 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003552 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 n = 1;
3554 }
3555 else
3556#endif
3557 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003558 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 n = -1;
3560 }
3561 if (n != 0)
3562 {
3563 // At the window boundary, highlight the last character
3564 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003565 wlv.off += n;
3566 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 }
3568 else
3569 {
3570 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003571 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003572 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003573 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 }
3575#ifdef FEAT_SEARCH_EXTRA
3576 if (area_attr == 0)
3577 {
3578 // Use attributes from match with highest priority among
3579 // 'search_hl' and the match list.
3580 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 }
3583#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003584 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586#ifdef FEAT_RIGHTLEFT
3587 if (wp->w_p_rl)
3588 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 --wlv.col;
3590 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 }
3592 else
3593#endif
3594 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 ++wlv.col;
3596 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 ++wlv.vcol;
3599 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 }
3601 }
3602
3603 // At end of the text line.
3604 if (c == NUL)
3605 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003606#ifdef FEAT_PROP_POPUP
3607 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003609 // Put the pointer back to the NUL.
3610 --ptr;
3611 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003613 else
3614#endif
3615 {
3616 draw_screen_line(wp, &wlv);
3617
3618 // Update w_cline_height and w_cline_folded if the cursor line
3619 // was updated (saves a call to plines() later).
3620 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3621 {
3622 curwin->w_cline_row = startrow;
3623 curwin->w_cline_height = wlv.row - startrow;
3624#ifdef FEAT_FOLDING
3625 curwin->w_cline_folded = FALSE;
3626#endif
3627 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3628 }
3629 break;
3630 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003631 }
3632
3633 // Show "extends" character from 'listchars' if beyond the line end and
3634 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003635 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003636 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 && wp->w_p_list
3638 && !wp->w_p_wrap
3639#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003640 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#endif
3642 && (
3643#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003648 || lcs_eol_one > 0
3649 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003650 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003651 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003652 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 mb_c = c;
3655 if (enc_utf8 && utf_char2len(c) > 1)
3656 {
3657 mb_utf8 = TRUE;
3658 u8cc[0] = 0;
3659 c = 0xc0;
3660 }
3661 else
3662 mb_utf8 = FALSE;
3663 }
3664
3665#ifdef FEAT_SYN_HL
3666 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003667 if (wlv.draw_color_col)
3668 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669
3670 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3671 // highlight the cursor position itself.
3672 // Also highlight the 'colorcolumn' if it is different than
3673 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003674 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3675 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003676 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003677 if (((wlv.draw_state == WL_LINE
3678 || wlv.draw_state == WL_BRI
3679 || wlv.draw_state == WL_SBR)
3680 && !lnum_in_visual_area
3681 && search_attr == 0
3682 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003683# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003684 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003685# endif
3686 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003687 {
3688 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3689 && lnum != wp->w_cursor.lnum)
3690 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003691 vcol_save_attr = wlv.char_attr;
3692 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3693 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003695 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003697 vcol_save_attr = wlv.char_attr;
3698 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 }
3700 }
3701#endif
3702
3703 // Store character to be displayed.
3704 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003705 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003706 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 {
3708 // Store the character.
3709#if defined(FEAT_RIGHTLEFT)
3710 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3711 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003712 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 --wlv.off;
3714 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 }
3716#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 if (enc_dbcs == DBCS_JPNU)
3719 {
3720 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003721 ScreenLines[wlv.off] = 0x8e;
3722 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 }
3724 else if (enc_utf8)
3725 {
3726 if (mb_utf8)
3727 {
3728 int i;
3729
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003730 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003732 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003733 for (i = 0; i < Screen_mco; ++i)
3734 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003735 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 if (u8cc[i] == 0)
3737 break;
3738 }
3739 }
3740 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003741 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 }
3743 if (multi_attr)
3744 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003745 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746 multi_attr = 0;
3747 }
3748 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003749 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003751 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003752
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003753 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3754 {
3755 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ++wlv.off;
3757 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 if (enc_utf8)
3759 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 else
3762 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003763 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003764 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003765#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003766 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767#endif
3768 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003770 // When "wlv.tocol" is halfway a character, set it to the end
3771 // of the character, otherwise highlighting won't stop.
3772 if (wlv.tocol == wlv.vcol)
3773 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003774
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003776
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003777#ifdef FEAT_RIGHTLEFT
3778 if (wp->w_p_rl)
3779 {
3780 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 --wlv.off;
3782 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003783 }
3784#endif
3785 }
3786#ifdef FEAT_RIGHTLEFT
3787 if (wp->w_p_rl)
3788 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 --wlv.off;
3790 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 }
3792 else
3793#endif
3794 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003795 ++wlv.off;
3796 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 }
3798 }
3799#ifdef FEAT_CONCEAL
3800 else if (wp->w_p_cole > 0 && is_concealing)
3801 {
3802 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003804 if (wlv.n_extra > 0)
3805 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 if (wp->w_p_wrap)
3807 {
3808 // Special voodoo required if 'wrap' is on.
3809 //
3810 // Advance the column indicator to force the line
3811 // drawing to wrap early. This will make the line
3812 // take up the same screen space when parts are concealed,
3813 // so that cursor line computations aren't messed up.
3814 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003815 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 // trailing junk to be written out of the screen line
3817 // we are building, 'boguscols' keeps track of the number
3818 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003819 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003821 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822# ifdef FEAT_RIGHTLEFT
3823 if (wp->w_p_rl)
3824 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003825 wlv.col -= wlv.n_extra;
3826 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827 }
3828 else
3829# endif
3830 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003831 wlv.col += wlv.n_extra;
3832 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003834 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835 n_attr = 0;
3836 }
3837
3838
3839 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3840 {
3841 // Need to fill two screen columns.
3842# ifdef FEAT_RIGHTLEFT
3843 if (wp->w_p_rl)
3844 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003845 --wlv.boguscols;
3846 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847 }
3848 else
3849# endif
3850 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003851 ++wlv.boguscols;
3852 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853 }
3854 }
3855
3856# ifdef FEAT_RIGHTLEFT
3857 if (wp->w_p_rl)
3858 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003859 --wlv.boguscols;
3860 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 }
3862 else
3863# endif
3864 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 ++wlv.boguscols;
3866 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003867 }
3868 }
3869 else
3870 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003871 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003873 wlv.vcol += wlv.n_extra;
3874 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 n_attr = 0;
3876 }
3877 }
3878
3879 }
3880#endif // FEAT_CONCEAL
3881 else
3882 --n_skip;
3883
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003884 // Only advance the "wlv.vcol" when after the 'number' or
3885 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003887#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003888 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003889#endif
3890 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892
3893#ifdef FEAT_SYN_HL
3894 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003895 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003896#endif
3897
3898 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003899 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3900 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901
3902 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003903 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003904 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003905 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003906 if (wlv.n_attr_skip > 0)
3907 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908
3909 // At end of screen line and there is more to come: Display the line
3910 // so far. If there is no more to display it is caught above.
3911 if ((
3912#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003913 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003915 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003916 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003917 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003919 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003921#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003922 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003923#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003924 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003925 && wlv.p_extra != at_end_str)
3926 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3927 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928 )
3929 {
3930#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003931 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003932 wlv_screen_line(wp, &wlv, FALSE);
3933 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003934 wlv.boguscols = 0;
Alexey Radkovaaa16b02023-01-04 11:15:30 +00003935 wlv.vcol_off = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003937 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 ++wlv.row;
3940 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941
3942 // When not wrapping and finished diff lines, or when displayed
3943 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003944 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003946 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003947#endif
3948#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003949 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003951 ) || lcs_eol_one == -1)
3952#ifdef FEAT_PROP_POPUP
3953 && !text_prop_follows
3954#endif
3955 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003957#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003958 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003959 {
3960 // do not output more of the line, only the "below" prop
3961 ptr += STRLEN(ptr);
3962# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003963 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003964# endif
3965 }
3966#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003967
3968 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003969 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003971 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003972#endif
3973 )
3974 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003975 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3976 draw_vsep_win(wp, wlv.row);
3977 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978 }
3979
3980 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003983 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 break;
3985 }
3986
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003987 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003988#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003989 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003991#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003992 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003993#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003994 && wp->w_width == Columns)
3995 {
3996 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003997 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998
3999 // Special trick to make copy/paste of wrapped lines work with
4000 // xterm/screen: write an extra character beyond the end of
4001 // the line. This will work with all terminal types
4002 // (regardless of the xn,am settings).
4003 // Only do this on a fast tty.
4004 // Only do this if the cursor is on the current line
4005 // (something has been written in it).
4006 // Don't do this for the GUI.
4007 // Don't do this for double-width characters.
4008 // Don't do this for a window not at the right screen border.
4009 if (p_tf
4010#ifdef FEAT_GUI
4011 && !gui.in_use
4012#endif
4013 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004014 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4015 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004017 || (*mb_off2cells)(
4018 LineOffset[wlv.screen_row - 1]
4019 + (int)Columns - 2,
4020 LineOffset[wlv.screen_row]
4021 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004022 {
4023 // First make sure we are at the end of the screen line,
4024 // then output the same character again to let the
4025 // terminal know about the wrap. If the terminal doesn't
4026 // auto-wrap, we overwrite the character.
4027 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004028 screen_char(LineOffset[wlv.screen_row - 1]
4029 + (unsigned)Columns - 1,
4030 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004031
4032 // When there is a multi-byte character, just output a
4033 // space to keep it simple.
4034 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004035 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 out_char(' ');
4037 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004038 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 + (Columns - 1)]);
4040 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004041 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042 screen_start(); // don't know where cursor is now
4043 }
4044 }
4045
Bram Moolenaar1306b362022-08-06 15:59:06 +01004046 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047
Bram Moolenaareed9d462021-02-15 20:38:25 +01004048 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004050 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004052 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004054 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004055 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004056#endif
4057#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004058 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004059 // When the filler lines are actually below the last line of the
4060 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004061 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004062 break;
4063#endif
4064 }
4065
4066 } // for every character in the line
4067
4068#ifdef FEAT_SPELL
4069 // After an empty line check first word for capital.
4070 if (*skipwhite(line) == NUL)
4071 {
4072 capcol_lnum = lnum + 1;
4073 cap_col = 0;
4074 }
4075#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004076#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 vim_free(text_props);
4078 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004079 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080#endif
4081
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004082 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084}