blob: 4328c06c53a1a96982bc4cc4864e13dd8ec1d349 [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;
1948 int active_before = text_props_active;
1949
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001951 // With 'nowrap' and not in the first screen line only "below"
1952 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001954 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001955 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001956 && (wp->w_p_wrap
1957 || wlv.row == startrow
1958 || (text_props[text_prop_next].tp_flags
1959 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001960 || (bcol == 0
1961 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001962 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001963 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001964 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001965 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001966 && *ptr == NUL
1967 && ((wp->w_p_list && lcs_eol_one > 0)
1968 || (ptr == line
1969 && !did_line
1970 && (text_props[text_prop_next].tp_flags
1971 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001972 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001973 // first display the '$' after the line or display an
1974 // empty line
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001975 text_prop_follows = TRUE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001976 if (text_props_active == active_before)
1977 display_text_first = TRUE;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001978 break;
1979 }
1980 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001981 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001982 + text_props[text_prop_next].tp_len)
1983 text_prop_idxs[text_props_active++] = text_prop_next;
1984 ++text_prop_next;
1985 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001987 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001988 {
1989 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001990 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001991 text_prop_flags = 0;
1992 text_prop_type = NULL;
1993 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001994 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001995 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001996 if (text_props_active > 0 && wlv.n_extra == 0
1997 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001999 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002000 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002001 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002002
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002003 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002004 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002005
2006 // Sort the properties on priority and/or starting last.
2007 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002008 sort_text_props(wp->w_buffer, text_props,
2009 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010
2011 for (pi = 0; pi < text_props_active; ++pi)
2012 {
2013 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002014 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002016 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017
Bram Moolenaarcd105412022-10-10 19:50:42 +01002018 // Only use a text property that can be displayed.
2019 // Skip "after" properties when wrap is off and at the
2020 // end of the window.
2021 if (pt != NULL
2022 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2023 && tp->tp_id != -MAXCOL
2024 && !(tp->tp_id < 0
2025 && !wp->w_p_wrap
2026 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2027 | TP_FLAG_ALIGN_ABOVE
2028 | TP_FLAG_ALIGN_BELOW)) == 0
2029 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002031 if (pt->pt_hl_id > 0)
2032 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 text_prop_type = pt;
2034 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002035 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002036 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2037 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002038 text_prop_flags = pt->pt_flags;
2039 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002040 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041 }
2042 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002043 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002044 && -text_prop_id
2045 <= wp->w_buffer->b_textprop_text.ga_len)
2046 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002047 textprop_T *tp = &text_props[used_tpi];
2048 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002049 ->b_textprop_text.ga_data)[
2050 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002051 int above = (tp->tp_flags
2052 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002053 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002054
2055 // reset the ID in the copy to avoid it being used
2056 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002057 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002059 if (p != NULL)
2060 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002061 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002062 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002063 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002064 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002065 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2066 int padding = tp->tp_col == MAXCOL
2067 && tp->tp_len > 1
2068 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002070 // Insert virtual text before the current
2071 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072 wlv.p_extra = p;
2073 wlv.c_extra = NUL;
2074 wlv.c_final = NUL;
2075 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002076 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002077 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2078 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002079 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002080 // restore search_attr and area_attr when n_extra
2081 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002082 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002083 saved_area_attr = area_attr;
2084 search_attr = 0;
2085 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002086 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002087 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002088 if (*ptr == NUL)
2089 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002090 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002091#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002092 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002093 {
2094 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002095 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002096 wlv.need_showbreak = FALSE;
2097 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002098 }
2099#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002100 if ((right || above || below || !wrap
2101 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002102 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002103 char_u *prev_p_extra = wlv.p_extra;
2104 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002105
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002106 // Take care of padding, right-align and
2107 // truncation.
2108 // Shared with win_lbr_chartabsize(), must do
2109 // exactly the same.
2110 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002111 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002112 wlv.col,
2113 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002114 &n_attr, &wlv.n_attr_skip,
2115 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002116 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002117 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002118 // wlv.p_extra was allocated
2119 vim_free(p_extra_free2);
2120 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002121 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002122
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002123 if (lcs_eol_one < 0
2124 && wp->w_p_wrap
2125 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002126 + wlv.n_extra - 2 > wp->w_width)
2127 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002128 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002129
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002130 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002131 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002132 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002133 {
2134 draw_screen_line(wp, &wlv);
2135
2136 // When line got too long for screen break
2137 // here.
2138 if (wlv.row == endrow)
2139 {
2140 ++wlv.row;
2141 break;
2142 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002143 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002144 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002145 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002146 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002147 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002148
Bram Moolenaarcd105412022-10-10 19:50:42 +01002149 // If the text didn't reach until the first window
2150 // column we need to skip cells.
2151 if (skip_cells > 0)
2152 {
2153 if (wlv.n_extra > skip_cells)
2154 {
2155 wlv.n_extra -= skip_cells;
2156 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002157 wlv.n_attr_skip -= skip_cells;
2158 if (wlv.n_attr_skip < 0)
2159 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002160 skip_cells = 0;
2161 }
2162 else
2163 {
2164 // the whole text is left of the window, drop
2165 // it and advance to the next one
2166 skip_cells -= wlv.n_extra;
2167 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002168 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002169 bail_out = TRUE;
2170 }
2171 }
2172
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002173 // If another text prop follows the condition below at
2174 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002175 // If this is an "above" text prop and 'nowrap' the we
2176 // must wrap anyway.
2177 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002178 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002179 && (wp->w_p_wrap
2180 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002181 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002182
2183 if (bail_out)
2184 // starting a new line for "below"
2185 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002186 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002188 else if (text_prop_next < text_prop_count
2189 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002190 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2191 || (!wp->w_p_wrap
2192 && wlv.col == wp->w_width - 1
2193 && (text_props[text_prop_next].tp_flags
2194 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002195 // When at last-but-one character and a text property
2196 // follows after it, we may need to flush the line after
2197 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002198 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002199 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 }
2201#endif
2202
Bram Moolenaare38fc862022-08-11 17:24:50 +01002203#ifdef FEAT_SEARCH_EXTRA
2204 if (wlv.n_extra == 0)
2205 {
2206 // Check for start/end of 'hlsearch' and other matches.
2207 // After end, check for start/end of next match.
2208 // When another match, have to check for start again.
2209 v = (long)(ptr - line);
2210 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2211 &screen_search_hl, &has_match_conc,
2212 &match_conc, did_line_attr, lcs_eol_one,
2213 &on_last_col);
2214 ptr = line + v; // "line" may have been changed
2215 prev_ptr = ptr;
2216
2217 // Do not allow a conceal over EOL otherwise EOL will be missed
2218 // and bad things happen.
2219 if (*ptr == NUL)
2220 has_match_conc = 0;
2221 }
2222#endif
2223
2224#ifdef FEAT_DIFF
2225 if (wlv.diff_hlf != (hlf_T)0)
2226 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002227 // When there is extra text (e.g. virtual text) it gets the
2228 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002229 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2230 && wlv.n_extra == 0)
2231 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002232 if (wlv.diff_hlf == HLF_TXD
2233 && ((ptr - line > change_end && wlv.n_extra == 0)
2234 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002235 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002236 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002237 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2238 && wp->w_p_culopt_flags != CULOPT_NBR
2239 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2240 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002241 wlv.line_attr = hl_combine_attr(
2242 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002243 }
2244#endif
2245
Bram Moolenaara74fda62019-10-19 17:38:03 +02002246#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002248 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002249 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002250# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002251 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002252 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002253# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002254 // Get syntax attribute.
2255 if (has_syntax)
2256 {
2257 // Get the syntax attribute for the character. If there
2258 // is an error, disable syntax highlighting.
2259 save_did_emsg = did_emsg;
2260 did_emsg = FALSE;
2261
2262 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002263 if (v == prev_syntax_col)
2264 // at same column again
2265 syntax_attr = prev_syntax_attr;
2266 else
2267 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002268# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002269 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002270# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002271 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002272# ifdef FEAT_SPELL
2273 has_spell ? &can_spell :
2274# endif
2275 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002276 prev_syntax_col = v;
2277 prev_syntax_attr = syntax_attr;
2278 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002279
Bram Moolenaar34390282019-10-16 14:38:26 +02002280 if (did_emsg)
2281 {
2282 wp->w_s->b_syn_error = TRUE;
2283 has_syntax = FALSE;
2284 syntax_attr = 0;
2285 }
2286 else
2287 did_emsg = save_did_emsg;
2288# ifdef SYN_TIME_LIMIT
2289 if (wp->w_s->b_syn_slow)
2290 has_syntax = FALSE;
2291# endif
2292
2293 // Need to get the line again, a multi-line regexp may
2294 // have made it invalid.
2295 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2296 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002297 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002298# ifdef FEAT_CONCEAL
2299 // no concealing past the end of the line, it interferes
2300 // with line highlighting
2301 if (*ptr == NUL)
2302 syntax_flags = 0;
2303 else
2304 syntax_flags = get_syntax_info(&syntax_seqnr);
2305# endif
2306 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002307 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002308# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002309 // Combine text property highlight into syntax highlight.
2310 if (text_prop_type != NULL)
2311 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002312 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002313 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2314 else
2315 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002316 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002317 }
2318# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002319#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002320
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002321 // Decide which of the highlight attributes to use.
2322 attr_pri = TRUE;
2323#ifdef LINE_ATTR
2324 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002325 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002326 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002327 if (!highlight_match)
2328 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002329 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002330# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002331 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002332# endif
2333 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002335 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002336 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002337# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002338 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002339# endif
2340 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002341 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002342 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2343 || wlv.vcol < wlv.fromcol
2344 || vcol_prev < fromcol_prev
2345 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002347 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002349# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002350 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002351# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002352 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002353# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002354 attr_pri = FALSE;
2355 }
2356#else
2357 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002358 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002360 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361#endif
2362 else
2363 {
2364 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002366 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002367#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002368 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002369#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002371#ifdef FEAT_PROP_POPUP
2372 // override with text property highlight when "override" is TRUE
2373 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002374 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002375#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002376 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002377
2378 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002379 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002380 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002381 if (wlv.char_attr == 0)
2382 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002383 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002384 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002385 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386
2387 // Get the next character to put on the screen.
2388
2389 // The "p_extra" points to the extra stuff that is inserted to
2390 // represent special characters (non-printable stuff) and other
2391 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002392 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2394 // "p_extra[n_extra]".
2395 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002396 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002398 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002399 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002400 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2401 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2403 if (enc_utf8 && utf_char2len(c) > 1)
2404 {
2405 mb_utf8 = TRUE;
2406 u8cc[0] = 0;
2407 c = 0xc0;
2408 }
2409 else
2410 mb_utf8 = FALSE;
2411 }
2412 else
2413 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002414 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415 if (has_mbyte)
2416 {
2417 mb_c = c;
2418 if (enc_utf8)
2419 {
2420 // If the UTF-8 character is more than one byte:
2421 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 mb_l = 1;
2426 else if (mb_l > 1)
2427 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002429 mb_utf8 = TRUE;
2430 c = 0xc0;
2431 }
2432 }
2433 else
2434 {
2435 // if this is a DBCS character, put it in "mb_c"
2436 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002437 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002438 mb_l = 1;
2439 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002441 }
2442 if (mb_l == 0) // at the NUL at end-of-line
2443 mb_l = 1;
2444
2445 // If a double-width char doesn't fit display a '>' in the
2446 // last column.
2447 if ((
2448# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002449 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002450# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002451 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452 && (*mb_char2cells)(mb_c) == 2)
2453 {
2454 c = '>';
2455 mb_c = c;
2456 mb_l = 1;
2457 mb_utf8 = FALSE;
2458 multi_attr = HL_ATTR(HLF_AT);
2459#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002460 if (wlv.cul_attr)
2461 multi_attr = hl_combine_attr(
2462 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002463#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002464 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002465
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 // put the pointer back to output the double-width
2467 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002468 ++wlv.n_extra;
2469 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 }
2471 else
2472 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 wlv.n_extra -= mb_l - 1;
2474 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475 }
2476 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002480#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002481 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002482 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002483 // Only restore search_attr and area_attr after "n_extra" in
2484 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002485 if (wlv.saved_n_extra <= 0)
2486 {
2487 if (search_attr == 0)
2488 search_attr = saved_search_attr;
2489 if (area_attr == 0 && *ptr != NUL)
2490 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002491
2492 if (wlv.extra_for_textprop)
2493 // wlv.extra_attr should be used at this position but
2494 // not any further.
2495 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002496 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002497
2498 wlv.extra_for_textprop = FALSE;
2499 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002500 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002501#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 }
2503 else
2504 {
2505#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002506 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002508 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 // Get a character from the line itself.
2511 c = *ptr;
2512#ifdef FEAT_LINEBREAK
2513 c0 = *ptr;
2514#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002515#ifdef FEAT_PROP_POPUP
2516 if (c == NUL)
2517 // text is finished, may display a "below" virtual text
2518 did_line = TRUE;
2519#endif
2520
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 if (has_mbyte)
2522 {
2523 mb_c = c;
2524 if (enc_utf8)
2525 {
2526 // If the UTF-8 character is more than one byte: Decode it
2527 // into "mb_c".
2528 mb_l = utfc_ptr2len(ptr);
2529 mb_utf8 = FALSE;
2530 if (mb_l > 1)
2531 {
2532 mb_c = utfc_ptr2char(ptr, u8cc);
2533 // Overlong encoded ASCII or ASCII with composing char
2534 // is displayed normally, except a NUL.
2535 if (mb_c < 0x80)
2536 {
2537 c = mb_c;
2538#ifdef FEAT_LINEBREAK
2539 c0 = mb_c;
2540#endif
2541 }
2542 mb_utf8 = TRUE;
2543
2544 // At start of the line we can have a composing char.
2545 // Draw it as a space with a composing char.
2546 if (utf_iscomposing(mb_c))
2547 {
2548 int i;
2549
2550 for (i = Screen_mco - 1; i > 0; --i)
2551 u8cc[i] = u8cc[i - 1];
2552 u8cc[0] = mb_c;
2553 mb_c = ' ';
2554 }
2555 }
2556
2557 if ((mb_l == 1 && c >= 0x80)
2558 || (mb_l >= 1 && mb_c == 0)
2559 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2560 {
2561 // Illegal UTF-8 byte: display as <xx>.
2562 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002563 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564# ifdef FEAT_RIGHTLEFT
2565 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002566 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002568 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 c = *wlv.p_extra;
2570 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002572 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2573 wlv.c_extra = NUL;
2574 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002575 if (area_attr == 0 && search_attr == 0)
2576 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002577 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002578 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002579 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002580 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 }
2582 }
2583 else if (mb_l == 0) // at the NUL at end-of-line
2584 mb_l = 1;
2585#ifdef FEAT_ARABIC
2586 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2587 {
2588 // Do Arabic shaping.
2589 int pc, pc1, nc;
2590 int pcc[MAX_MCO];
2591
2592 // The idea of what is the previous and next
2593 // character depends on 'rightleft'.
2594 if (wp->w_p_rl)
2595 {
2596 pc = prev_c;
2597 pc1 = prev_c1;
2598 nc = utf_ptr2char(ptr + mb_l);
2599 prev_c1 = u8cc[0];
2600 }
2601 else
2602 {
2603 pc = utfc_ptr2char(ptr + mb_l, pcc);
2604 nc = prev_c;
2605 pc1 = pcc[0];
2606 }
2607 prev_c = mb_c;
2608
2609 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2610 }
2611 else
2612 prev_c = mb_c;
2613#endif
2614 }
2615 else // enc_dbcs
2616 {
2617 mb_l = MB_BYTE2LEN(c);
2618 if (mb_l == 0) // at the NUL at end-of-line
2619 mb_l = 1;
2620 else if (mb_l > 1)
2621 {
2622 // We assume a second byte below 32 is illegal.
2623 // Hopefully this is OK for all double-byte encodings!
2624 if (ptr[1] >= 32)
2625 mb_c = (c << 8) + ptr[1];
2626 else
2627 {
2628 if (ptr[1] == NUL)
2629 {
2630 // head byte at end of line
2631 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002632 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 }
2634 else
2635 {
2636 // illegal tail byte
2637 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002638 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002639 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002640 wlv.p_extra = wlv.extra;
2641 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002642 wlv.c_extra = NUL;
2643 wlv.c_final = NUL;
2644 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 if (area_attr == 0 && search_attr == 0)
2646 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002647 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002648 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002649 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002650 // save current attr
2651 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002652 }
2653 mb_c = c;
2654 }
2655 }
2656 }
2657 // If a double-width char doesn't fit display a '>' in the
2658 // last column; the character is displayed at the start of the
2659 // next line.
2660 if ((
2661# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002662 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002664 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 && (*mb_char2cells)(mb_c) == 2)
2666 {
2667 c = '>';
2668 mb_c = c;
2669 mb_utf8 = FALSE;
2670 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002671 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672 // Put pointer back so that the character will be
2673 // displayed at the start of the next line.
2674 --ptr;
2675#ifdef FEAT_CONCEAL
2676 did_decrement_ptr = TRUE;
2677#endif
2678 }
2679 else if (*ptr != NUL)
2680 ptr += mb_l - 1;
2681
2682 // If a double-width char doesn't fit at the left side display
2683 // a '<' in the first column. Don't do this for unprintable
2684 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002685 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002687 wlv.n_extra = 1;
2688 wlv.c_extra = MB_FILLER_CHAR;
2689 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 c = ' ';
2691 if (area_attr == 0 && search_attr == 0)
2692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002693 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002694 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002695 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002696 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 }
2698 mb_c = c;
2699 mb_utf8 = FALSE;
2700 mb_l = 1;
2701 }
2702
2703 }
2704 ++ptr;
2705
2706 if (extra_check)
2707 {
2708#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002709 // Check spelling (unless at the end of the line).
2710 // Only do this when there is no syntax highlighting, the
2711 // @Spell cluster is not used or the current syntax item
2712 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002713 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 if (has_spell && v >= word_end && v > cur_checked_col)
2715 {
2716 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002717 // do not calculate cap_col at the end of the line or when
2718 // only white space is following
2719 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720# ifdef FEAT_SYN_HL
2721 !has_syntax ||
2722# endif
2723 can_spell))
2724 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002725 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726 int len;
2727 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002728
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002729 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002730 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731
2732 // Use nextline[] if possible, it has the start of the
2733 // next line concatenated.
2734 if ((prev_ptr - line) - nextlinecol >= 0)
2735 p = nextline + (prev_ptr - line) - nextlinecol;
2736 else
2737 p = prev_ptr;
2738 cap_col -= (int)(prev_ptr - line);
2739 len = spell_check(wp, p, &spell_hlf, &cap_col,
2740 nochange);
2741 word_end = v + len;
2742
2743 // In Insert mode only highlight a word that
2744 // doesn't touch the cursor.
2745 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002746 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 && wp->w_cursor.lnum == lnum
2748 && wp->w_cursor.col >=
2749 (colnr_T)(prev_ptr - line)
2750 && wp->w_cursor.col < (colnr_T)word_end)
2751 {
2752 spell_hlf = HLF_COUNT;
2753 spell_redraw_lnum = lnum;
2754 }
2755
2756 if (spell_hlf == HLF_COUNT && p != prev_ptr
2757 && (p - nextline) + len > nextline_idx)
2758 {
2759 // Remember that the good word continues at the
2760 // start of the next line.
2761 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002762 checked_col = (int)((p - nextline)
2763 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 }
2765
2766 // Turn index into actual attributes.
2767 if (spell_hlf != HLF_COUNT)
2768 spell_attr = highlight_attr[spell_hlf];
2769
2770 if (cap_col > 0)
2771 {
2772 if (p != prev_ptr
2773 && (p - nextline) + cap_col >= nextline_idx)
2774 {
2775 // Remember that the word in the next line
2776 // must start with a capital.
2777 capcol_lnum = lnum + 1;
2778 cap_col = (int)((p - nextline) + cap_col
2779 - nextline_idx);
2780 }
2781 else
2782 // Compute the actual column.
2783 cap_col += (int)(prev_ptr - line);
2784 }
2785 }
2786 }
2787 if (spell_attr != 0)
2788 {
2789 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002790 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2791 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002792 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002793 wlv.char_attr = hl_combine_attr(spell_attr,
2794 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 }
2796#endif
2797#ifdef FEAT_LINEBREAK
2798 // Found last space before word: check for line break.
2799 if (wp->w_p_lbr && c0 == c
2800 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2801 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002802 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2803 : 0;
2804 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002805 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002806
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002807 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002808# ifdef FEAT_PROP_POPUP
2809 // do not want virtual text counted here
2810 cts.cts_has_prop_with_text = FALSE;
2811# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002813 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002814
2815 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002816 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002817 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002818 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2820 if (wlv.n_extra < 0)
2821 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002822 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002823 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002824 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002825 // line break, but for TABs the highlighting should
2826 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002827 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002828
Bram Moolenaar1306b362022-08-06 15:59:06 +01002829 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002831 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002832 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002833 wp->w_buffer->b_p_vts_array) - 1;
2834# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002835 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002836 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837# endif
2838
Bram Moolenaar1306b362022-08-06 15:59:06 +01002839 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2840 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002841# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002842 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002843 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002844# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 if (VIM_ISWHITE(c))
2846 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002847# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 if (c == TAB)
2849 // See "Tab alignment" below.
2850 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002851# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 if (!wp->w_p_list)
2853 c = ' ';
2854 }
2855 }
2856#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002857 in_multispace = c == ' '
2858 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2859 if (!in_multispace)
2860 multispace_pos = 0;
2861
Bram Moolenaareed9d462021-02-15 20:38:25 +01002862 // 'list': Change char 160 to 'nbsp' and space to 'space'
2863 // setting in 'listchars'. But not when the character is
2864 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 if (wp->w_p_list
2866 && ((((c == 160 && mb_l == 1)
2867 || (mb_utf8
2868 && ((mb_c == 160 && mb_l == 2)
2869 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002870 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 || (c == ' '
2872 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002873 && (wp->w_lcs_chars.space
2874 || (in_multispace
2875 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002876 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002877 && ptr - line <= trailcol)))
2878 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002879 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2880 {
2881 c = wp->w_lcs_chars.multispace[multispace_pos++];
2882 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2883 multispace_pos = 0;
2884 }
2885 else
2886 c = (c == ' ') ? wp->w_lcs_chars.space
2887 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002888 if (area_attr == 0 && search_attr == 0)
2889 {
2890 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002891 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002892 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 }
2895 mb_c = c;
2896 if (enc_utf8 && utf_char2len(c) > 1)
2897 {
2898 mb_utf8 = TRUE;
2899 u8cc[0] = 0;
2900 c = 0xc0;
2901 }
2902 else
2903 mb_utf8 = FALSE;
2904 }
2905
zeertzjq2e7cba32022-06-10 15:30:32 +01002906 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2907 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002909 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2910 && wp->w_lcs_chars.leadmultispace != NULL)
2911 {
2912 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002913 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2914 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002915 multispace_pos = 0;
2916 }
2917
2918 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2919 c = wp->w_lcs_chars.trail;
2920
2921 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2922 c = wp->w_lcs_chars.lead;
2923
zeertzjq2e7cba32022-06-10 15:30:32 +01002924 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002925 c = wp->w_lcs_chars.space;
2926
2927
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928 if (!attr_pri)
2929 {
2930 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002931 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002932 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002933 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 }
2935 mb_c = c;
2936 if (enc_utf8 && utf_char2len(c) > 1)
2937 {
2938 mb_utf8 = TRUE;
2939 u8cc[0] = 0;
2940 c = 0xc0;
2941 }
2942 else
2943 mb_utf8 = FALSE;
2944 }
2945 }
2946
2947 // Handling of non-printable characters.
2948 if (!vim_isprintc(c))
2949 {
2950 // when getting a character from the file, we may have to
2951 // turn it into something else on the way to putting it
2952 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002953 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002955 int tab_len = 0;
2956 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002958 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01002959
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 // only adjust the tab_len, when at the first column
2961 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002962 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002963 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964#endif
2965 // tab amount depends on current column
2966#ifdef FEAT_VARTABS
2967 tab_len = tabstop_padding(vcol_adjusted,
2968 wp->w_buffer->b_p_ts,
2969 wp->w_buffer->b_p_vts_array) - 1;
2970#else
2971 tab_len = (int)wp->w_buffer->b_p_ts
2972 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2973#endif
2974
2975#ifdef FEAT_LINEBREAK
2976 if (!wp->w_p_lbr || !wp->w_p_list)
2977#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002978 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002980 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00002981 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002982#ifdef FEAT_LINEBREAK
2983 else
2984 {
2985 char_u *p;
2986 int len;
2987 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002988 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002990# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002991 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002993 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002994
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002996 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 && old_boguscols > 0
2998 && wlv.n_extra > tab_len)
2999 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003000# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003001 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003003 // If wlv.n_extra > 0, it gives the number of chars
3004 // to use for a tab, else we need to calculate the
3005 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003006 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3007 len = tab_len * tab2_len;
3008 if (wp->w_lcs_chars.tab3)
3009 len += mb_char2len(wp->w_lcs_chars.tab3)
3010 - tab2_len;
3011 if (wlv.n_extra > 0)
3012 len += wlv.n_extra - tab_len;
3013 c = wp->w_lcs_chars.tab1;
3014 p = alloc(len + 1);
3015 if (p == NULL)
3016 wlv.n_extra = 0;
3017 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003019 vim_memset(p, ' ', len);
3020 p[len] = NUL;
3021 vim_free(wlv.p_extra_free);
3022 wlv.p_extra_free = p;
3023 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003024 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003025 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003026
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003027 if (*p == NUL)
3028 {
3029 tab_len = i;
3030 break;
3031 }
3032
3033 // if tab3 is given, use it for the last
3034 // char
3035 if (wp->w_lcs_chars.tab3
3036 && i == tab_len - 1)
3037 lcs = wp->w_lcs_chars.tab3;
3038 p += mb_char2bytes(lcs, p);
3039 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003041 }
3042 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003043# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003044 // n_extra will be increased by
3045 // FIX_FOX_BOGUSCOLS macro below, so need to
3046 // adjust for that here
3047 if (wlv.vcol_off > 0)
3048 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003049# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003050 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 }
3053#endif
3054#ifdef FEAT_CONCEAL
3055 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003056 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057
3058 // Tab alignment should be identical regardless of
3059 // 'conceallevel' value. So tab compensates of all
3060 // previous concealed characters, and thus resets
3061 // vcol_off and boguscols accumulated so far in the
3062 // line. Note that the tab can be longer than
3063 // 'tabstop' when there are concealed characters.
3064 FIX_FOR_BOGUSCOLS;
3065
3066 // Make sure, the highlighting for the tab char will be
3067 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003068 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003069 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003070 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003071 tab_len += vc_saved;
3072 }
3073#endif
3074 mb_utf8 = FALSE; // don't draw as UTF-8
3075 if (wp->w_p_list)
3076 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003077 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003078 ? wp->w_lcs_chars.tab3
3079 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003081 if (wp->w_p_lbr && wlv.p_extra != NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003082 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003083 else
3084#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003085 wlv.c_extra = wp->w_lcs_chars.tab2;
3086 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003088 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003089 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003090 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003091 mb_c = c;
3092 if (enc_utf8 && utf_char2len(c) > 1)
3093 {
3094 mb_utf8 = TRUE;
3095 u8cc[0] = 0;
3096 c = 0xc0;
3097 }
3098 }
3099 else
3100 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 wlv.c_final = NUL;
3102 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 c = ' ';
3104 }
3105 }
3106 else if (c == NUL
3107 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003108 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3109 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 && VIsual_mode != Ctrl_V
3111 && (
3112# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003113 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003115 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 && !(noinvcur
3117 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003118 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 && lcs_eol_one > 0)
3120 {
3121 // Display a '$' after the line or highlight an extra
3122 // character if the line break is included.
3123#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3124 // For a diff line the highlighting continues after the
3125 // "$".
3126 if (
3127# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003128 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129# ifdef LINE_ATTR
3130 &&
3131# endif
3132# endif
3133# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003134 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135# endif
3136 )
3137#endif
3138 {
3139 // In virtualedit, visual selections may extend
3140 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003141 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003142 && wlv.tocol != MAXCOL
3143 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003144 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003145 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003147 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3148 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 else
3150 c = ' ';
3151 lcs_eol_one = -1;
3152 --ptr; // put it back at the NUL
3153 if (!attr_pri)
3154 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003155 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003156 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003157 n_attr = 1;
3158 }
3159 mb_c = c;
3160 if (enc_utf8 && utf_char2len(c) > 1)
3161 {
3162 mb_utf8 = TRUE;
3163 u8cc[0] = 0;
3164 c = 0xc0;
3165 }
3166 else
3167 mb_utf8 = FALSE; // don't draw as UTF-8
3168 }
3169 else if (c != NUL)
3170 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003171 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3172 if (wlv.n_extra == 0)
3173 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174#ifdef FEAT_RIGHTLEFT
3175 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003176 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003178 wlv.c_extra = NUL;
3179 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003180#ifdef FEAT_LINEBREAK
3181 if (wp->w_p_lbr)
3182 {
3183 char_u *p;
3184
Bram Moolenaar1306b362022-08-06 15:59:06 +01003185 c = *wlv.p_extra;
3186 p = alloc(wlv.n_extra + 1);
3187 vim_memset(p, ' ', wlv.n_extra);
3188 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3189 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003190 vim_free(wlv.p_extra_free);
3191 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003192 }
3193 else
3194#endif
3195 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003196 wlv.n_extra = byte2cells(c) - 1;
3197 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 }
3199 if (!attr_pri)
3200 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003201 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003202 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003203 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003204 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 }
3206 mb_utf8 = FALSE; // don't draw as UTF-8
3207 }
3208 else if (VIsual_active
3209 && (VIsual_mode == Ctrl_V
3210 || VIsual_mode == 'v')
3211 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003212 && wlv.tocol != MAXCOL
3213 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 && (
3215#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003216 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003217#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003218 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 {
3220 c = ' ';
3221 --ptr; // put it back at the NUL
3222 }
3223#if defined(LINE_ATTR)
3224 else if ((
3225# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003226 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003227# endif
3228# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003231 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 ) && (
3233# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003234 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003236 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003238 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239# endif
3240 < wp->w_width)))
3241 {
3242 // Highlight until the right side of the window
3243 c = ' ';
3244 --ptr; // put it back at the NUL
3245
3246 // Remember we do the char for line highlighting.
3247 ++did_line_attr;
3248
3249 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003250 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003252 || (wp->w_p_list &&
3253 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003254 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003255# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003258 wlv.diff_hlf = HLF_CHD;
3259 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003261 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3263 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003264 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003265 || (wlv.vcol >= left_curline_col
3266 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003267 wlv.char_attr = hl_combine_attr(
3268 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269 }
3270 }
3271# endif
3272# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003273 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003275 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003276 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3277 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003279 if (!wlv.cul_screenline
3280 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 wlv.char_attr = hl_combine_attr(
3283 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003285 else if (wlv.line_attr)
3286 wlv.char_attr = hl_combine_attr(
3287 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
3289# endif
3290 }
3291#endif
3292 }
3293
3294#ifdef FEAT_CONCEAL
3295 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003296 && (wp != curwin || lnum != wp->w_cursor.lnum
3297 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3299 && !(lnum_in_visual_area
3300 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3301 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003302 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003303 if (((prev_syntax_id != syntax_seqnr
3304 && (syntax_flags & HL_CONCEAL) != 0)
3305 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003306 && (syn_get_sub_char() != NUL
3307 || (has_match_conc && match_conc)
3308 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 && wp->w_p_cole != 3)
3310 {
3311 // First time at this concealed item: display one
3312 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003313 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 c = match_conc;
3315 else if (syn_get_sub_char() != NUL)
3316 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003317 else if (wp->w_lcs_chars.conceal != NUL)
3318 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 else
3320 c = ' ';
3321
3322 prev_syntax_id = syntax_seqnr;
3323
Bram Moolenaar1306b362022-08-06 15:59:06 +01003324 if (wlv.n_extra > 0)
3325 wlv.vcol_off += wlv.n_extra;
3326 wlv.vcol += wlv.n_extra;
3327 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 {
3329# ifdef FEAT_RIGHTLEFT
3330 if (wp->w_p_rl)
3331 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003332 wlv.col -= wlv.n_extra;
3333 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 }
3335 else
3336# endif
3337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 wlv.boguscols += wlv.n_extra;
3339 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 }
3341 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003342 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 n_attr = 0;
3344 }
3345 else if (n_skip == 0)
3346 {
3347 is_concealing = TRUE;
3348 n_skip = 1;
3349 }
3350 mb_c = c;
3351 if (enc_utf8 && utf_char2len(c) > 1)
3352 {
3353 mb_utf8 = TRUE;
3354 u8cc[0] = 0;
3355 c = 0xc0;
3356 }
3357 else
3358 mb_utf8 = FALSE; // don't draw as UTF-8
3359 }
3360 else
3361 {
3362 prev_syntax_id = 0;
3363 is_concealing = FALSE;
3364 }
3365
3366 if (n_skip > 0 && did_decrement_ptr)
3367 // not showing the '>', put pointer back to avoid getting stuck
3368 ++ptr;
3369
3370#endif // FEAT_CONCEAL
3371 }
3372
3373#ifdef FEAT_CONCEAL
3374 // In the cursor line and we may be concealing characters: correct
3375 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003377 && wp == curwin && lnum == wp->w_cursor.lnum
3378 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003379 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003381# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003383 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003384 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003385# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 wp->w_wcol = wlv.col - wlv.boguscols;
3387 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 did_wcol = TRUE;
3389 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003390# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003391 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003392# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394#endif
3395
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003396 // Use "wlv.extra_attr", but don't override visual selection
3397 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003398 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3399 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003400 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003401 && (!attr_pri
3402#ifdef FEAT_PROP_POPUP
3403 || (text_prop_flags & PT_FLAG_OVERRIDE)
3404#endif
3405 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003406 {
3407#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003408 if (wlv.line_attr)
3409 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003410 else
3411#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003412 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003413#ifdef FEAT_PROP_POPUP
3414 if (reset_extra_attr)
3415 {
3416 reset_extra_attr = FALSE;
3417 wlv.extra_attr = 0;
3418 }
3419#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 }
3421
3422#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3423 // XIM don't send preedit_start and preedit_end, but they send
3424 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3425 // im_is_preediting() here.
3426 if (p_imst == IM_ON_THE_SPOT
3427 && xic != NULL
3428 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003429 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003430 && !p_imdisable
3431 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433 {
3434 colnr_T tcol;
3435
3436 if (preedit_end_col == MAXCOL)
3437 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3438 else
3439 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 {
3442 if (feedback_old_attr < 0)
3443 {
3444 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003445 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003447 wlv.char_attr = im_get_feedback_attr(feedback_col);
3448 if (wlv.char_attr < 0)
3449 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 feedback_col++;
3451 }
3452 else if (feedback_old_attr >= 0)
3453 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003454 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 feedback_old_attr = -1;
3456 feedback_col = 0;
3457 }
3458 }
3459#endif
3460 // Handle the case where we are in column 0 but not on the first
3461 // character of the line and the user wants us to show us a
3462 // special character (via 'listchars' option "precedes:<char>".
3463 if (lcs_prec_todo != NUL
3464 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003465 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3466 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003468 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003470 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 && c != NUL)
3472 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003473 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003474 lcs_prec_todo = NUL;
3475 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3476 {
3477 // Double-width character being overwritten by the "precedes"
3478 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 wlv.c_extra = MB_FILLER_CHAR;
3480 wlv.c_final = NUL;
3481 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003483 wlv.extra_attr =
3484 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486 mb_c = c;
3487 if (enc_utf8 && utf_char2len(c) > 1)
3488 {
3489 mb_utf8 = TRUE;
3490 u8cc[0] = 0;
3491 c = 0xc0;
3492 }
3493 else
3494 mb_utf8 = FALSE; // don't draw as UTF-8
3495 if (!attr_pri)
3496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 saved_attr3 = wlv.char_attr; // save current attr
3498 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 n_attr3 = 1;
3500 }
3501 }
3502
3503 // At end of the text line or just after the last character.
3504 if ((c == NUL
3505#if defined(LINE_ATTR)
3506 || did_line_attr == 1
3507#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003508 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 {
3510#ifdef FEAT_SEARCH_EXTRA
3511 // flag to indicate whether prevcol equals startcol of search_hl or
3512 // one of the matches
3513 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3514 (long)(ptr - line) - (c == NUL));
3515#endif
3516 // Invert at least one char, used for Visual and empty line or
3517 // highlight match at end of line. If it's beyond the last
3518 // char on the screen, just overwrite that one (tricky!) Not
3519 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003520 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003521 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003522 && (VIsual_mode != Ctrl_V
3523 || lnum == VIsual.lnum
3524 || lnum == curwin->w_cursor.lnum)
3525 && c == NUL)
3526#ifdef FEAT_SEARCH_EXTRA
3527 // highlight 'hlsearch' match at end of line
3528 || (prevcol_hl_flag
3529# ifdef FEAT_SYN_HL
3530 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3531 && !(wp == curwin && VIsual_active))
3532# endif
3533# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003535# endif
3536# if defined(LINE_ATTR)
3537 && did_line_attr <= 1
3538# endif
3539 )
3540#endif
3541 ))
3542 {
3543 int n = 0;
3544
3545#ifdef FEAT_RIGHTLEFT
3546 if (wp->w_p_rl)
3547 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003548 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003549 n = 1;
3550 }
3551 else
3552#endif
3553 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003554 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 n = -1;
3556 }
3557 if (n != 0)
3558 {
3559 // At the window boundary, highlight the last character
3560 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003561 wlv.off += n;
3562 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564 else
3565 {
3566 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003569 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 }
3571#ifdef FEAT_SEARCH_EXTRA
3572 if (area_attr == 0)
3573 {
3574 // Use attributes from match with highest priority among
3575 // 'search_hl' and the match list.
3576 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003577 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003578 }
3579#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003581 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582#ifdef FEAT_RIGHTLEFT
3583 if (wp->w_p_rl)
3584 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003585 --wlv.col;
3586 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 }
3588 else
3589#endif
3590 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003591 ++wlv.col;
3592 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003594 ++wlv.vcol;
3595 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 }
3597 }
3598
3599 // At end of the text line.
3600 if (c == NUL)
3601 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003602#ifdef FEAT_PROP_POPUP
3603 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003605 // Put the pointer back to the NUL.
3606 --ptr;
3607 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003609 else
3610#endif
3611 {
3612 draw_screen_line(wp, &wlv);
3613
3614 // Update w_cline_height and w_cline_folded if the cursor line
3615 // was updated (saves a call to plines() later).
3616 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3617 {
3618 curwin->w_cline_row = startrow;
3619 curwin->w_cline_height = wlv.row - startrow;
3620#ifdef FEAT_FOLDING
3621 curwin->w_cline_folded = FALSE;
3622#endif
3623 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3624 }
3625 break;
3626 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 }
3628
3629 // Show "extends" character from 'listchars' if beyond the line end and
3630 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003631 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633 && wp->w_p_list
3634 && !wp->w_p_wrap
3635#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003636 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637#endif
3638 && (
3639#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003642 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003644 || lcs_eol_one > 0
3645 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003646 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003648 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003649 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650 mb_c = c;
3651 if (enc_utf8 && utf_char2len(c) > 1)
3652 {
3653 mb_utf8 = TRUE;
3654 u8cc[0] = 0;
3655 c = 0xc0;
3656 }
3657 else
3658 mb_utf8 = FALSE;
3659 }
3660
3661#ifdef FEAT_SYN_HL
3662 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003663 if (wlv.draw_color_col)
3664 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665
3666 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3667 // highlight the cursor position itself.
3668 // Also highlight the 'colorcolumn' if it is different than
3669 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003670 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3671 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003672 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003673 if (((wlv.draw_state == WL_LINE
3674 || wlv.draw_state == WL_BRI
3675 || wlv.draw_state == WL_SBR)
3676 && !lnum_in_visual_area
3677 && search_attr == 0
3678 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003679# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003680 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003681# endif
3682 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 {
3684 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3685 && lnum != wp->w_cursor.lnum)
3686 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 vcol_save_attr = wlv.char_attr;
3688 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3689 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003691 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003693 vcol_save_attr = wlv.char_attr;
3694 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 }
3696 }
3697#endif
3698
3699 // Store character to be displayed.
3700 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 {
3704 // Store the character.
3705#if defined(FEAT_RIGHTLEFT)
3706 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3707 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003708 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003709 --wlv.off;
3710 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 }
3712#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003713 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003714 if (enc_dbcs == DBCS_JPNU)
3715 {
3716 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003717 ScreenLines[wlv.off] = 0x8e;
3718 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003719 }
3720 else if (enc_utf8)
3721 {
3722 if (mb_utf8)
3723 {
3724 int i;
3725
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003726 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003727 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003729 for (i = 0; i < Screen_mco; ++i)
3730 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003731 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003732 if (u8cc[i] == 0)
3733 break;
3734 }
3735 }
3736 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003737 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003738 }
3739 if (multi_attr)
3740 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003741 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 multi_attr = 0;
3743 }
3744 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003745 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003746
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003747 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003748
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3750 {
3751 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003752 ++wlv.off;
3753 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 if (enc_utf8)
3755 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 else
3758 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003759 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003760 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003762 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763#endif
3764 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003766 // When "wlv.tocol" is halfway a character, set it to the end
3767 // of the character, otherwise highlighting won't stop.
3768 if (wlv.tocol == wlv.vcol)
3769 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003770
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003771 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003772
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773#ifdef FEAT_RIGHTLEFT
3774 if (wp->w_p_rl)
3775 {
3776 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 --wlv.off;
3778 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 }
3780#endif
3781 }
3782#ifdef FEAT_RIGHTLEFT
3783 if (wp->w_p_rl)
3784 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 --wlv.off;
3786 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003787 }
3788 else
3789#endif
3790 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 ++wlv.off;
3792 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 }
3794 }
3795#ifdef FEAT_CONCEAL
3796 else if (wp->w_p_cole > 0 && is_concealing)
3797 {
3798 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003800 if (wlv.n_extra > 0)
3801 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 if (wp->w_p_wrap)
3803 {
3804 // Special voodoo required if 'wrap' is on.
3805 //
3806 // Advance the column indicator to force the line
3807 // drawing to wrap early. This will make the line
3808 // take up the same screen space when parts are concealed,
3809 // so that cursor line computations aren't messed up.
3810 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812 // trailing junk to be written out of the screen line
3813 // we are building, 'boguscols' keeps track of the number
3814 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003815 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003817 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818# ifdef FEAT_RIGHTLEFT
3819 if (wp->w_p_rl)
3820 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003821 wlv.col -= wlv.n_extra;
3822 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823 }
3824 else
3825# endif
3826 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003827 wlv.col += wlv.n_extra;
3828 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003829 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003830 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 n_attr = 0;
3832 }
3833
3834
3835 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3836 {
3837 // Need to fill two screen columns.
3838# ifdef FEAT_RIGHTLEFT
3839 if (wp->w_p_rl)
3840 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003841 --wlv.boguscols;
3842 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843 }
3844 else
3845# endif
3846 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003847 ++wlv.boguscols;
3848 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 }
3850 }
3851
3852# ifdef FEAT_RIGHTLEFT
3853 if (wp->w_p_rl)
3854 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003855 --wlv.boguscols;
3856 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 }
3858 else
3859# endif
3860 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003861 ++wlv.boguscols;
3862 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863 }
3864 }
3865 else
3866 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003867 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003869 wlv.vcol += wlv.n_extra;
3870 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871 n_attr = 0;
3872 }
3873 }
3874
3875 }
3876#endif // FEAT_CONCEAL
3877 else
3878 --n_skip;
3879
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003880 // Only advance the "wlv.vcol" when after the 'number' or
3881 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003882 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003884 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003885#endif
3886 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003887 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888
3889#ifdef FEAT_SYN_HL
3890 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003891 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892#endif
3893
3894 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003895 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3896 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003897
3898 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003899 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003900 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003901 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003902 if (wlv.n_attr_skip > 0)
3903 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904
3905 // At end of screen line and there is more to come: Display the line
3906 // so far. If there is no more to display it is caught above.
3907 if ((
3908#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003909 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003910#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003911 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003912 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003913 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003915 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003917#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003918 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003919#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003920 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003921 && wlv.p_extra != at_end_str)
3922 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3923 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924 )
3925 {
3926#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003927 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003928 wlv_screen_line(wp, &wlv, FALSE);
3929 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003930 wlv.boguscols = 0;
Alexey Radkovaaa16b02023-01-04 11:15:30 +00003931 wlv.vcol_off = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003933 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003934#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003935 ++wlv.row;
3936 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937
3938 // When not wrapping and finished diff lines, or when displayed
3939 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003940 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003942 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003943#endif
3944#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003945 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003947 ) || lcs_eol_one == -1)
3948#ifdef FEAT_PROP_POPUP
3949 && !text_prop_follows
3950#endif
3951 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003953#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003954 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003955 {
3956 // do not output more of the line, only the "below" prop
3957 ptr += STRLEN(ptr);
3958# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003959 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003960# endif
3961 }
3962#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003963
3964 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003965 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003966#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003967 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968#endif
3969 )
3970 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003971 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3972 draw_vsep_win(wp, wlv.row);
3973 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974 }
3975
3976 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003977 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003979 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003980 break;
3981 }
3982
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003983 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003985 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003987#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003988 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003989#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003990 && wp->w_width == Columns)
3991 {
3992 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003993 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003994
3995 // Special trick to make copy/paste of wrapped lines work with
3996 // xterm/screen: write an extra character beyond the end of
3997 // the line. This will work with all terminal types
3998 // (regardless of the xn,am settings).
3999 // Only do this on a fast tty.
4000 // Only do this if the cursor is on the current line
4001 // (something has been written in it).
4002 // Don't do this for the GUI.
4003 // Don't do this for double-width characters.
4004 // Don't do this for a window not at the right screen border.
4005 if (p_tf
4006#ifdef FEAT_GUI
4007 && !gui.in_use
4008#endif
4009 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004010 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4011 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004012 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004013 || (*mb_off2cells)(
4014 LineOffset[wlv.screen_row - 1]
4015 + (int)Columns - 2,
4016 LineOffset[wlv.screen_row]
4017 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018 {
4019 // First make sure we are at the end of the screen line,
4020 // then output the same character again to let the
4021 // terminal know about the wrap. If the terminal doesn't
4022 // auto-wrap, we overwrite the character.
4023 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004024 screen_char(LineOffset[wlv.screen_row - 1]
4025 + (unsigned)Columns - 1,
4026 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027
4028 // When there is a multi-byte character, just output a
4029 // space to keep it simple.
4030 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004031 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032 out_char(' ');
4033 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004034 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004035 + (Columns - 1)]);
4036 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004037 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004038 screen_start(); // don't know where cursor is now
4039 }
4040 }
4041
Bram Moolenaar1306b362022-08-06 15:59:06 +01004042 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043
Bram Moolenaareed9d462021-02-15 20:38:25 +01004044 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004046 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004047# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004048 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004050 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004051 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052#endif
4053#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004054 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055 // When the filler lines are actually below the last line of the
4056 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004057 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004058 break;
4059#endif
4060 }
4061
4062 } // for every character in the line
4063
4064#ifdef FEAT_SPELL
4065 // After an empty line check first word for capital.
4066 if (*skipwhite(line) == NUL)
4067 {
4068 capcol_lnum = lnum + 1;
4069 cap_col = 0;
4070 }
4071#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004072#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073 vim_free(text_props);
4074 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004075 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004076#endif
4077
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004078 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004079 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080}