blob: 2fbfe452cd7f93d157a24bac219d072a81c7e5c6 [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
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000148 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100149
150 // saved "extra" items for when draw_state becomes WL_LINE (again)
151 int saved_n_extra;
152 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000153 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000154 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100156 int saved_c_extra;
157 int saved_c_final;
158 int saved_char_attr;
159
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100160 char_u extra[NUMBUFLEN + MB_MAXBYTES];
161 // "%ld " and 'fdc' must fit in here, as well
162 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100163
Bram Moolenaar1306b362022-08-06 15:59:06 +0100164#ifdef FEAT_DIFF
165 hlf_T diff_hlf; // type of diff highlighting
166#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100167 int filler_lines; // nr of filler lines to be drawn
168 int filler_todo; // nr of filler lines still to do + 1
169#ifdef FEAT_SIGNS
170 sign_attrs_T sattr;
171#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100172} winlinevars_T;
173
174// draw_state values for items that are drawn in sequence:
175#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100176#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100177#ifdef FEAT_FOLDING
178# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
179#else
180# define WL_FOLD WL_CMDLINE
181#endif
182#ifdef FEAT_SIGNS
183# define WL_SIGN (WL_FOLD + 1) // column for signs
184#else
185# define WL_SIGN WL_FOLD // column for signs
186#endif
187#define WL_NR (WL_SIGN + 1) // line number
188#ifdef FEAT_LINEBREAK
189# define WL_BRI (WL_NR + 1) // 'breakindent'
190#else
191# define WL_BRI WL_NR
192#endif
193#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
194# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
195#else
196# define WL_SBR WL_BRI
197#endif
198#define WL_LINE (WL_SBR + 1) // text in the line
199
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100200#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200201/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 * Return TRUE if CursorLineSign highlight is to be used.
203 */
204 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100205use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000206{
207 return wp->w_p_cul
208 && lnum == wp->w_cursor.lnum
209 && (wp->w_p_culopt_flags & CULOPT_NBR);
210}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100211#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000212
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100213
214#ifdef FEAT_FOLDING
215/*
216 * Setup for drawing the 'foldcolumn', if there is one.
217 */
218 static void
219handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
220{
221 int fdc = compute_foldcolumn(wp, 0);
222
223 if (fdc <= 0)
224 return;
225
226 // Allocate a buffer, "wlv->extra[]" may already be in use.
227 vim_free(wlv->p_extra_free);
228 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000229 if (wlv->p_extra_free == NULL)
230 return;
231
232 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
233 wp, FALSE, wlv->lnum);
234 wlv->p_extra_free[wlv->n_extra] = NUL;
235 wlv->p_extra = wlv->p_extra_free;
236 wlv->c_extra = NUL;
237 wlv->c_final = NUL;
238 if (use_cursor_line_highlight(wp, wlv->lnum))
239 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
240 else
241 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100242}
243#endif
244
245#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000246/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100247 * Get information needed to display the sign in line "wlv->lnum" in window
248 * "wp".
249 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200250 * Otherwise the sign is going to be displayed in the sign column.
251 */
252 static void
253get_sign_display_info(
254 int nrcol,
255 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257{
258 int text_sign;
259# ifdef FEAT_SIGN_ICONS
260 int icon_sign;
261# endif
262
263 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->c_extra = ' ';
265 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100267 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268 else
269 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100270 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000272 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276
Bram Moolenaar1306b362022-08-06 15:59:06 +0100277 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200278#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100279 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200280#endif
281 )
282 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100283 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100285 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200286 if (gui.in_use && icon_sign != 0)
287 {
288 // Use the image in this position.
289 if (nrcol)
290 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100291 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 sprintf((char *)wlv->extra, "%-*c ",
293 number_width(wp), SIGN_BYTE);
294 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100295 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296 }
297 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200299# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100300 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
301 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200302 {
303 if (nrcol)
304 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100306 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100309 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 }
311 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313 }
314# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100315 wlv->c_final = NUL;
316 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
319# endif
320 if (text_sign != 0)
321 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100323 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 {
325 if (nrcol)
326 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100327 int width = number_width(wp) - 2;
328 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200329
330 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100331 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100332 vim_snprintf((char *)wlv->extra + n,
333 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100334 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100336 wlv->c_extra = NUL;
337 wlv->c_final = NUL;
338 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200339 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000340
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100341 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100342 && wlv->sattr.sat_culhl > 0)
343 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000344 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100345 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
347 }
348}
349#endif
350
Bram Moolenaard7657e92022-09-20 18:59:30 +0100351/*
352 * Display the absolute or relative line number. After the first row fill with
353 * blanks when the 'n' flag isn't in 'cpo'.
354 */
355 static void
356handle_lnum_col(
357 win_T *wp,
358 winlinevars_T *wlv,
359 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100360 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100361{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100362 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100363 int lnum_row = wlv->startrow + wlv->filler_lines
364#ifdef FEAT_PROP_POPUP
365 + wlv->text_prop_above_count
366#endif
367 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100368
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100371 // there is no line number in a wrapped line when "n" is in
372 // 'cpoptions', but 'breakindent' assumes it anyway.
373 && !((has_cpo_n
374#ifdef FEAT_LINEBREAK
375 && !wp->w_p_bri
376#endif
377 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100378 {
379#ifdef FEAT_SIGNS
380 // If 'signcolumn' is set to 'number' and a sign is present
381 // in 'lnum', then display the sign instead of the line
382 // number.
383 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
384 get_sign_display_info(TRUE, wp, wlv);
385 else
386#endif
387 {
388 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100389 // When there are text properties above the line put the line number
390 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100391 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100392 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100393 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100394 {
395 long num;
396 char *fmt = "%*ld ";
397
398 if (wp->w_p_nu && !wp->w_p_rnu)
399 // 'number' + 'norelativenumber'
400 num = (long)wlv->lnum;
401 else
402 {
403 // 'relativenumber', don't use negative numbers
404 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
405 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
406 {
407 // 'number' + 'relativenumber'
408 num = wlv->lnum;
409 fmt = "%-*ld ";
410 }
411 }
412
413 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100414 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100415 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
416 ++wlv->p_extra)
417 *wlv->p_extra = '-';
418#ifdef FEAT_RIGHTLEFT
419 if (wp->w_p_rl) // reverse line numbers
420 {
421 char_u *p1, *p2;
422 int t;
423
424 // like rl_mirror(), but keep the space at the end
425 p2 = skipwhite(wlv->extra);
426 p2 = skiptowhite(p2) - 1;
427 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
428 {
429 t = *p1;
430 *p1 = *p2;
431 *p2 = t;
432 }
433 }
434#endif
435 wlv->p_extra = wlv->extra;
436 wlv->c_extra = NUL;
437 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100438 }
439 else
440 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100441 wlv->c_extra = ' ';
442 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100443 }
444 wlv->n_extra = number_width(wp) + 1;
445 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
446#ifdef FEAT_SYN_HL
447 // When 'cursorline' is set highlight the line number of
448 // the current line differently.
449 // When 'cursorlineopt' does not have "line" only
450 // highlight the line number itself.
451 // TODO: Can we use CursorLine instead of CursorLineNr
452 // when CursorLineNr isn't set?
453 if (wp->w_p_cul
454 && wlv->lnum == wp->w_cursor.lnum
455 && (wp->w_p_culopt_flags & CULOPT_NBR)
456 && (wlv->row == wlv->startrow + wlv->filler_lines
457 || (wlv->row > wlv->startrow + wlv->filler_lines
458 && (wp->w_p_culopt_flags & CULOPT_LINE))))
459 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
460#endif
461 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
462 && HL_ATTR(HLF_LNA) != 0)
463 // Use LineNrAbove
464 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
465 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
466 && HL_ATTR(HLF_LNB) != 0)
467 // Use LineNrBelow
468 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
469 }
470#ifdef FEAT_SIGNS
471 if (num_attr)
472 wlv->char_attr = num_attr;
473#endif
474 }
475}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100476
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100477#ifdef FEAT_LINEBREAK
478 static void
479handle_breakindent(win_T *wp, winlinevars_T *wlv)
480{
481 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100482 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100483 // draw indent after showbreak value
484 wlv->draw_state = WL_BRI;
485 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
486 // After the showbreak, draw the breakindent
487 wlv->draw_state = WL_BRI - 1;
488
489 // draw 'breakindent': indent wrapped text accordingly
490 if (wlv->draw_state == WL_BRI - 1)
491 {
492 wlv->draw_state = WL_BRI;
493 // if wlv->need_showbreak is set, breakindent also applies
494 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
495# ifdef FEAT_DIFF
496 && wlv->filler_lines == 0
497# endif
498# ifdef FEAT_PROP_POPUP
499 && !wlv->dont_use_showbreak
500# endif
501 )
502 {
503 wlv->char_attr = 0;
504# ifdef FEAT_DIFF
505 if (wlv->diff_hlf != (hlf_T)0)
506 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
507# endif
508 wlv->p_extra = NULL;
509 wlv->c_extra = ' ';
510 wlv->c_final = NUL;
511 wlv->n_extra = get_breakindent_win(wp,
512 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
513 if (wlv->row == wlv->startrow)
514 {
515 wlv->n_extra -= win_col_off2(wp);
516 if (wlv->n_extra < 0)
517 wlv->n_extra = 0;
518 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100519 if (wp->w_skipcol > 0 && wlv->startrow == 0
520 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100521 wlv->need_showbreak = FALSE;
522 // Correct end of highlighted area for 'breakindent',
523 // required when 'linebreak' is also set.
524 if (wlv->tocol == wlv->vcol)
525 wlv->tocol += wlv->n_extra;
526 }
527 }
528}
529#endif
530
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100531#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
532 static void
533handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
534{
535# ifdef FEAT_DIFF
536 if (wlv->filler_todo > 0)
537 {
538 // Draw "deleted" diff line(s).
539 if (char2cells(wp->w_fill_chars.diff) > 1)
540 {
541 wlv->c_extra = '-';
542 wlv->c_final = NUL;
543 }
544 else
545 {
546 wlv->c_extra = wp->w_fill_chars.diff;
547 wlv->c_final = NUL;
548 }
549# ifdef FEAT_RIGHTLEFT
550 if (wp->w_p_rl)
551 wlv->n_extra = wlv->col + 1;
552 else
553# endif
554 wlv->n_extra = wp->w_width - wlv->col;
555 wlv->char_attr = HL_ATTR(HLF_DED);
556 }
557# endif
558
559# ifdef FEAT_LINEBREAK
560 char_u *sbr = get_showbreak_value(wp);
561 if (*sbr != NUL && wlv->need_showbreak)
562 {
563 // Draw 'showbreak' at the start of each broken line.
564 wlv->p_extra = sbr;
565 wlv->c_extra = NUL;
566 wlv->c_final = NUL;
567 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100568 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100569 wlv->need_showbreak = FALSE;
570 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
571 // Correct end of highlighted area for 'showbreak',
572 // required when 'linebreak' is also set.
573 if (wlv->tocol == wlv->vcol)
574 wlv->tocol += wlv->n_extra;
575 // combine 'showbreak' with 'wincolor'
576 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
577# ifdef FEAT_SYN_HL
578 // combine 'showbreak' with 'cursorline'
579 if (wlv->cul_attr != 0)
580 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
581# endif
582 }
583# endif
584}
585#endif
586
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100587#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100588/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100589 * Return the cell size of virtual text after truncation.
590 */
591 static int
592textprop_size_after_trunc(
593 win_T *wp,
594 int flags, // TP_FLAG_ALIGN_*
595 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100596 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 char_u *text,
598 int *n_used_ptr)
599{
600 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100601 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100602 int len = (int)STRLEN(text);
603 int strsize = 0;
604 int n_used;
605
Bram Moolenaar7e017462022-10-11 21:02:09 +0100606 // if the remaining size is to small and 'wrap' is set we wrap anyway and
607 // use the next line
608 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100609 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100610 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100611 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
613 {
614 int clen = ptr2cells(text + n_used);
615
616 if (strsize + clen > space)
617 break;
618 strsize += clen;
619 }
620 *n_used_ptr = n_used;
621 return strsize;
622}
623
624/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100625 * Take care of padding, right-align and truncation of virtual text after a
626 * line.
627 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
628 * padding, right-align and truncation. Otherwise only the size is computed.
629 * When "n_attr" is NULL returns the number of screen cells used.
630 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100631 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100632 int
633text_prop_position(
634 win_T *wp,
635 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000636 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int *n_extra, // nr of bytes for virtual text
639 char_u **p_extra, // virtual text
640 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000641 int *n_attr_skip, // cells to skip attr, NULL if not used
642 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200643{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100644 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100646 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000647 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100648 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000649 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100650 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100651 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100652 int before = room; // spaces before the text
653 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int n_used = *n_extra;
655 char_u *l = NULL;
656 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100657 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100658 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200659
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100660 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100661 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100662 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100663
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100664 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100665 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100666 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100667 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100668 if (after < 0)
669 {
670 // text "above" has too much padding to fit
671 padding += after;
672 after = 0;
673 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 }
675 else
676 {
677 // Right-align: fill with before
678 if (right)
679 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000680
681 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000682 if (below && vcol == 0 && col_with_padding == col_off
683 && wp->w_width - col_off == before)
684 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (before < 0
687 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000688 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
689 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100690 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100691 if (right && (wrap
692 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100693 {
694 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100695 before = wp->w_width - col_off - strsize + room;
696 if (before < 0)
697 before = 0;
698 else
699 n_used = *n_extra;
700 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000701 else if (below && before > vcol && do_skip)
702 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100703 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100704 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100705 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100706 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100707
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100708 // With 'nowrap' add one to show the "extends" character if needed (it
709 // doesn't show if the text just fits).
710 if (!wp->w_p_wrap
711 && n_used < *n_extra
712 && wp->w_lcs_chars.ext != NUL
713 && wp->w_p_list)
714 ++n_used;
715
716 // add 1 for NUL, 2 for when '…' is used
717 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100718 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100719 if (n_attr == NULL || l != NULL)
720 {
721 int off = 0;
722
723 if (n_attr != NULL)
724 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100725 vim_memset(l, ' ', before);
726 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 if (padding > 0)
728 {
729 vim_memset(l + off, ' ', padding);
730 off += padding;
731 }
732 vim_strncpy(l + off, *p_extra, n_used);
733 off += n_used;
734 }
735 else
736 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100737 off = before + after + padding + n_used;
738 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100739 }
740 if (n_attr != NULL)
741 {
742 if (n_used < *n_extra && wp->w_p_wrap)
743 {
744 char_u *lp = l + off - 1;
745
746 if (has_mbyte)
747 {
h-east4c42c7e2023-04-17 21:44:57 +0100748 char_u buf[MB_MAXBYTES + 1];
749 char_u *cp = buf;
750
751 // change the last character to '…', converted to the
752 // current 'encoding'
753 STRCPY(buf, "…");
754 if (!enc_utf8)
755 {
756 vimconv_T vc;
757
758 vc.vc_type = CONV_NONE;
759 convert_setup(&vc, (char_u *)"utf-8", p_enc);
760 if (vc.vc_type != CONV_NONE)
761 {
762 cp = string_convert(&vc, buf, NULL);
763 if (cp == NULL)
764 {
765 // when conversion fails use '>'
766 cp = buf;
767 STRCPY(buf, ">");
768 }
769 convert_setup(&vc, NULL, NULL);
770 }
771 }
772
773 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100774 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100775 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100776 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100777 if (cp != buf)
778 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100779 }
780 else
781 // change last character to '>'
782 *lp = '>';
783 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100784 else if (after > 0)
785 {
786 vim_memset(l + off, ' ', after);
787 l[off + after] = NUL;
788 }
789
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100790 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100791 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100792 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100793 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100794 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100795
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000796 // n_attr_skip will not be decremented before draw_state is
797 // WL_LINE
798 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100799 }
800 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100801 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100802
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100803 if (n_attr == NULL)
804 return cells;
805 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806}
807#endif
808
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100809/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100810 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100811 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
812 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100813 */
814 static void
815wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
816{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100817 if (wlv->row == 0 && wp->w_skipcol > 0
818#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100819 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100820 && *get_showbreak_value(wp) == NUL
821#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100822 // do not overwrite the 'listchars' "precedes" text with "<<<"
823 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100824 {
825 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100826 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100827 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100828
Bram Moolenaareb4de622022-10-15 13:42:17 +0100829 if (wp->w_p_nu && wp->w_p_rnu)
830 // Do not overwrite the line number, change "123 text" to
831 // "123>>>xt".
832 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
833 {
834 ++off;
835 ++skip;
836 }
837
838 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100839 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100840 if ((*mb_off2cells)(off, max_off) > 1)
841 // When the first half of a double-width character is
842 // overwritten, change the second half to a space.
843 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100844 ScreenLines[off] = '<';
845 if (enc_utf8)
846 ScreenLinesUC[off] = 0;
847 ScreenAttrs[off] = HL_ATTR(HLF_AT);
848 ++off;
849 }
850 }
851
852 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
853 negative_width ? -wp->w_width : wp->w_width,
854 wlv->screen_line_flags);
855}
856
857/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100858 * Called when finished with the line: draw the screen line and handle any
859 * highlighting until the right of the window.
860 */
861 static void
862draw_screen_line(win_T *wp, winlinevars_T *wlv)
863{
864#ifdef FEAT_SYN_HL
865 long v;
866
867 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
868 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100869 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100870 else
871 v = wp->w_leftcol;
872
873 // check if line ends before left margin
874 if (wlv->vcol < v + wlv->col - win_col_off(wp))
875 wlv->vcol = v + wlv->col - win_col_off(wp);
876# ifdef FEAT_CONCEAL
877 // Get rid of the boguscols now, we want to draw until the right
878 // edge for 'cursorcolumn'.
879 wlv->col -= wlv->boguscols;
880 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000881# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100882# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000883# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100884# endif
885
886 if (wlv->draw_color_col)
887 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
888
889 if (((wp->w_p_cuc
890 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
891 && (int)wp->w_virtcol <
892 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
893 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000894 || wlv->draw_color_col
895# ifdef LINE_ATTR
896 || wlv->line_attr != 0
897# endif
898 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100899# ifdef FEAT_RIGHTLEFT
900 && !wp->w_p_rl
901# endif
902 )
903 {
904 int rightmost_vcol = 0;
905 int i;
906
907 if (wp->w_p_cuc)
908 rightmost_vcol = wp->w_virtcol;
909 if (wlv->draw_color_col)
910 // determine rightmost colorcolumn to possibly draw
911 for (i = 0; wlv->color_cols[i] >= 0; ++i)
912 if (rightmost_vcol < wlv->color_cols[i])
913 rightmost_vcol = wlv->color_cols[i];
914
915 while (wlv->col < wp->w_width)
916 {
917 ScreenLines[wlv->off] = ' ';
918 if (enc_utf8)
919 ScreenLinesUC[wlv->off] = 0;
920 ScreenCols[wlv->off] = MAXCOL;
921 ++wlv->col;
922 if (wlv->draw_color_col)
923 wlv->draw_color_col = advance_color_col(
924 VCOL_HLC, &wlv->color_cols);
925
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000926 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100927 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000928 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100929 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000930 attr = HL_ATTR(HLF_MC);
931# ifdef LINE_ATTR
932 else if (wlv->line_attr != 0)
933 attr = wlv->line_attr;
934# endif
935 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100936
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000937 if (VCOL_HLC >= rightmost_vcol
938# ifdef LINE_ATTR
939 && wlv->line_attr == 0
940# endif
941 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100942 break;
943
944 ++wlv->vcol;
945 }
946 }
947#endif
948
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100949 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100950 ++wlv->row;
951 ++wlv->screen_row;
952}
953#undef VCOL_HLC
954
955/*
956 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100957 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100958 */
959 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100960win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100961{
962 wlv->col = 0;
963 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
964
965#ifdef FEAT_RIGHTLEFT
966 if (wp->w_p_rl)
967 {
968 // Rightleft window: process the text in the normal direction, but put
969 // it in current_ScreenLine[] from right to left. Start at the
970 // rightmost column of the window.
971 wlv->col = wp->w_width - 1;
972 wlv->off += wlv->col;
973 wlv->screen_line_flags |= SLF_RIGHTLEFT;
974 }
975#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100976 if (save_extra)
977 {
978 // reset the drawing state for the start of a wrapped line
979 wlv->draw_state = WL_START;
980 wlv->saved_n_extra = wlv->n_extra;
981 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000982 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000983 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000984 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100985 wlv->saved_c_extra = wlv->c_extra;
986 wlv->saved_c_final = wlv->c_final;
987#ifdef FEAT_SYN_HL
988 if (!(wlv->cul_screenline
989# ifdef FEAT_DIFF
990 && wlv->diff_hlf == (hlf_T)0
991# endif
992 ))
993 wlv->saved_char_attr = wlv->char_attr;
994 else
995#endif
996 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000997
998 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +0100999 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001000 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001001 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001002}
1003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001004/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001005 * Called when wlv->draw_state is set to WL_LINE.
1006 */
1007 static void
1008win_line_continue(winlinevars_T *wlv)
1009{
1010 if (wlv->saved_n_extra > 0)
1011 {
1012 // Continue item from end of wrapped line.
1013 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001014 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001015 wlv->c_extra = wlv->saved_c_extra;
1016 wlv->c_final = wlv->saved_c_final;
1017 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001018 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001019 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001020 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001021 wlv->char_attr = wlv->saved_char_attr;
1022 }
1023 else
1024 wlv->char_attr = wlv->win_attr;
1025}
1026
zeertzjqb7acea12022-12-12 13:20:43 +00001027#ifdef FEAT_SYN_HL
1028 static void
1029apply_cursorline_highlight(
1030 winlinevars_T *wlv,
1031 int sign_present UNUSED)
1032{
1033 wlv->cul_attr = HL_ATTR(HLF_CUL);
1034# ifdef FEAT_SIGNS
1035 // Combine the 'cursorline' and sign highlighting, depending on
1036 // the sign priority.
1037 if (sign_present && wlv->sattr.sat_linehl > 0)
1038 {
1039 if (wlv->sattr.sat_priority >= 100)
1040 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1041 else
1042 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1043 }
1044 else
1045# endif
1046# if defined(FEAT_QUICKFIX)
1047 // let the line attribute overrule 'cursorline', otherwise
1048 // it disappears when both have background set;
1049 // 'cursorline' can use underline or bold to make it show
1050 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1051# else
1052 wlv->line_attr = wlv->cul_attr;
1053# endif
1054}
1055#endif
1056
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001057/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001058 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001059 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001060 * When "number_only" is TRUE only update the number column.
1061 * "spv" is used to store information for spell checking, kept between
1062 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001063 * wp->w_virtcol needs to be valid.
1064 *
1065 * Return the number of last row the line occupies.
1066 */
1067 int
1068win_line(
1069 win_T *wp,
1070 linenr_T lnum,
1071 int startrow,
1072 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001073 int number_only,
1074 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001075{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001076 winlinevars_T wlv; // variables passed between functions
1077
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001079 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001080 char_u *line; // current line
1081 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082
Bram Moolenaar1306b362022-08-06 15:59:06 +01001083#ifdef FEAT_PROP_POPUP
1084 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1085#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001086#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001087 int in_linebreak = FALSE; // n_extra set for showing linebreak
1088#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001090 // displaying eol at end-of-line
1091 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001092 int lcs_prec_todo = wp->w_lcs_chars.prec;
1093 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001094
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001095 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001096 int saved_attr2 = 0; // char_attr saved for n_attr
1097 int n_attr3 = 0; // chars with overruling special attr
1098 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099
Bram Moolenaarcd105412022-10-10 19:50:42 +01001100 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1101 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001102#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001103 int skip_cells = 0; // nr of cells to skip for virtual text
1104 // after the line, when w_skipcol is
1105 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001106#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001108 int fromcol_prev = -2; // start of inverting after cursor
1109 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001110 int lnum_in_visual_area = FALSE;
1111 pos_T pos;
1112 long v;
1113
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114 int attr_pri = FALSE; // char_attr has priority
1115 int area_highlighting = FALSE; // Visual or incsearch highlighting
1116 // in this line
1117 int vi_attr = 0; // attributes for Visual and incsearch
1118 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 int area_attr = 0; // attributes desired by highlighting
1120 int search_attr = 0; // attributes desired by 'hlsearch'
1121#ifdef FEAT_SYN_HL
1122 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1123 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001124 int prev_syntax_col = -1; // column of prev_syntax_attr
1125 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 int has_syntax = FALSE; // this buffer has syntax highl.
1127 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001129#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001130 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001131 int text_prop_count;
1132 int text_prop_next = 0; // next text property to use
1133 textprop_T *text_props = NULL;
1134 int *text_prop_idxs = NULL;
1135 int text_props_active = 0;
1136 proptype_T *text_prop_type = NULL;
1137 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001138 int text_prop_attr_comb = 0; // text_prop_attr combined with
1139 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001140 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001141 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001142 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001143 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001144 int saved_search_attr = 0; // search_attr to be used when n_extra
1145 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001146 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001147 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001148#endif
1149#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001150 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151# define SPWORDLEN 150
1152 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1153 int nextlinecol = 0; // column where nextline[] starts
1154 int nextline_idx = 0; // index in nextline[] where next line
1155 // starts
1156 int spell_attr = 0; // attributes desired by spelling
1157 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158 int cur_checked_col = 0; // checked column for current line
1159#endif
1160 int extra_check = 0; // has extra highlighting
1161 int multi_attr = 0; // attributes desired by multibyte
1162 int mb_l = 1; // multi-byte byte length
1163 int mb_c = 0; // decoded multi-byte character
1164 int mb_utf8 = FALSE; // screen char is UTF-8 char
1165 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 int change_start = MAXCOL; // first col of changed area
1168 int change_end = -1; // last col of changed area
1169#endif
1170 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001171 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001172 int in_multispace = FALSE; // in multiple consecutive spaces
1173 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001174#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001175 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001178 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001179#ifdef FEAT_ARABIC
1180 int prev_c = 0; // previous Arabic character
1181 int prev_c1 = 0; // first composing char for prev_c
1182#endif
1183#if defined(LINE_ATTR)
1184 int did_line_attr = 0;
1185#endif
1186#ifdef FEAT_TERMINAL
1187 int get_term_attr = FALSE;
1188#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189
Martin Tournoijba43e762022-10-13 22:12:15 +01001190#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191 // margin columns for the screen line, needed for when 'cursorlineopt'
1192 // contains "screenline"
1193 int left_curline_col = 0;
1194 int right_curline_col = 0;
1195#endif
1196
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001197#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1198 int feedback_col = 0;
1199 int feedback_old_attr = -1;
1200#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201
1202#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1203 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001204#endif
1205#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001206 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207#endif
1208#ifdef FEAT_CONCEAL
1209 int syntax_flags = 0;
1210 int syntax_seqnr = 0;
1211 int prev_syntax_id = 0;
1212 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1213 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214 int did_wcol = FALSE;
1215 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001216# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001217# define FIX_FOR_BOGUSCOLS \
1218 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001219 wlv.n_extra += wlv.vcol_off_co; \
1220 wlv.vcol -= wlv.vcol_off_co; \
1221 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001222 wlv.col -= wlv.boguscols; \
1223 old_boguscols = wlv.boguscols; \
1224 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 }
1226#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001227# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228#endif
1229
1230 if (startrow > endrow) // past the end already!
1231 return startrow;
1232
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001233 CLEAR_FIELD(wlv);
1234
1235 wlv.lnum = lnum;
1236 wlv.startrow = startrow;
1237 wlv.row = startrow;
1238 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001239 wlv.fromcol = -10;
1240 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001241#ifdef FEAT_LINEBREAK
1242 wlv.vcol_sbr = -1;
1243#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244
1245 if (!number_only)
1246 {
1247 // To speed up the loop below, set extra_check when there is linebreak,
1248 // trailing white space and/or syntax processing to be done.
1249#ifdef FEAT_LINEBREAK
1250 extra_check = wp->w_p_lbr;
1251#endif
1252#ifdef FEAT_SYN_HL
1253 if (syntax_present(wp) && !wp->w_s->b_syn_error
1254# ifdef SYN_TIME_LIMIT
1255 && !wp->w_s->b_syn_slow
1256# endif
1257 )
1258 {
1259 // Prepare for syntax highlighting in this line. When there is an
1260 // error, stop syntax highlighting.
1261 save_did_emsg = did_emsg;
1262 did_emsg = FALSE;
1263 syntax_start(wp, lnum);
1264 if (did_emsg)
1265 wp->w_s->b_syn_error = TRUE;
1266 else
1267 {
1268 did_emsg = save_did_emsg;
1269#ifdef SYN_TIME_LIMIT
1270 if (!wp->w_s->b_syn_slow)
1271#endif
1272 {
1273 has_syntax = TRUE;
1274 extra_check = TRUE;
1275 }
1276 }
1277 }
1278
1279 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001280 wlv.color_cols = wp->w_p_cc_cols;
1281 if (wlv.color_cols != NULL)
1282 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283#endif
1284
1285#ifdef FEAT_TERMINAL
1286 if (term_show_buffer(wp->w_buffer))
1287 {
1288 extra_check = TRUE;
1289 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001290 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 }
1292#endif
1293
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 // handle Visual active in this window
1295 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1296 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001297 pos_T *top, *bot;
1298
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1300 {
1301 // Visual is after curwin->w_cursor
1302 top = &curwin->w_cursor;
1303 bot = &VIsual;
1304 }
1305 else
1306 {
1307 // Visual is before curwin->w_cursor
1308 top = &VIsual;
1309 bot = &curwin->w_cursor;
1310 }
1311 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1312 if (VIsual_mode == Ctrl_V)
1313 {
1314 // block mode
1315 if (lnum_in_visual_area)
1316 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001317 wlv.fromcol = wp->w_old_cursor_fcol;
1318 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001319 }
1320 }
1321 else
1322 {
1323 // non-block mode
1324 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001325 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 else if (lnum == top->lnum)
1327 {
1328 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001329 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001330 else
1331 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001332 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001334 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001335 }
1336 }
1337 if (VIsual_mode != 'V' && lnum == bot->lnum)
1338 {
1339 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1340 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 wlv.fromcol = -10;
1342 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 }
1344 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 else
1347 {
1348 pos = *bot;
1349 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1351 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 else
1353 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001354 getvvcol(wp, &pos, NULL, NULL,
1355 (colnr_T *)&wlv.tocol);
1356 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357 }
1358 }
1359 }
1360 }
1361
1362 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001363 if (!highlight_match && lnum == curwin->w_cursor.lnum
1364 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365#ifdef FEAT_GUI
1366 && !gui.in_use
1367#endif
1368 )
1369 noinvcur = TRUE;
1370
1371 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001372 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 {
1374 area_highlighting = TRUE;
1375 vi_attr = HL_ATTR(HLF_V);
1376#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1377 if ((clip_star.available && !clip_star.owned
1378 && clip_isautosel_star())
1379 || (clip_plus.available && !clip_plus.owned
1380 && clip_isautosel_plus()))
1381 vi_attr = HL_ATTR(HLF_VNC);
1382#endif
1383 }
1384 }
1385
1386 // handle 'incsearch' and ":s///c" highlighting
1387 else if (highlight_match
1388 && wp == curwin
1389 && lnum >= curwin->w_cursor.lnum
1390 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1391 {
1392 if (lnum == curwin->w_cursor.lnum)
1393 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001394 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001396 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001397 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1398 {
1399 pos.lnum = lnum;
1400 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001401 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 }
1403 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001404 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001406 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1407 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001408 area_highlighting = TRUE;
1409 vi_attr = HL_ATTR(HLF_I);
1410 }
1411 }
1412
1413#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001414 wlv.filler_lines = diff_check(wp, lnum);
1415 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001417 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418 {
1419 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001422 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001424 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 }
1426 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001427 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001428 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 area_highlighting = TRUE;
1430 }
1431 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001432 wlv.filler_lines = wp->w_topfill;
1433 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434#endif
1435
1436#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001437 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001438 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001439 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001440#endif
1441
1442#ifdef LINE_ATTR
1443# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001444 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001446 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447# endif
1448# if defined(FEAT_QUICKFIX)
1449 // Highlight the current line in the quickfix window.
1450 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001451 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001453 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 area_highlighting = TRUE;
1455#endif
1456
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001457#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001458 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001460 // Prepare for spell checking.
1461 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462
Luuk van Baal30805a12023-05-27 22:22:10 +01001463 // When a word wrapped from the previous line the start of the
1464 // current line is valid.
1465 if (lnum == spv->spv_checked_lnum)
1466 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001467 // Previous line was not spell checked, check for capital. This happens
1468 // for the first line in an updated region or after a closed fold.
1469 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1470 spv->spv_cap_col = 0;
1471 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001472 spv->spv_cap_col = -1;
1473 spv->spv_checked_lnum = 0;
1474
Luuk van Baal30805a12023-05-27 22:22:10 +01001475 // Get the start of the next line, so that words that wrap to the
1476 // next line are found too: "et<line-break>al.".
1477 // Trick: skip a few chars for C/shell/Vim comments
1478 nextline[SPWORDLEN] = NUL;
1479 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001480 {
1481 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1482 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1483 }
1484 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1485
1486 // If current line is empty, check first word in next line for capital.
1487 ptr = skipwhite(line);
1488 if (*ptr == NUL)
1489 {
1490 spv->spv_cap_col = 0;
1491 spv->spv_capcol_lnum = lnum + 1;
1492 }
1493 // For checking first word with a capital skip white space.
1494 else if (spv->spv_cap_col == 0)
1495 spv->spv_cap_col = ptr - line;
1496
Luuk van Baal30805a12023-05-27 22:22:10 +01001497 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 if (nextline[SPWORDLEN] == NUL)
1499 {
1500 // No next line or it is empty.
1501 nextlinecol = MAXCOL;
1502 nextline_idx = 0;
1503 }
1504 else
1505 {
1506 v = (long)STRLEN(line);
1507 if (v < SPWORDLEN)
1508 {
1509 // Short line, use it completely and append the start of the
1510 // next line.
1511 nextlinecol = 0;
1512 mch_memmove(nextline, line, (size_t)v);
1513 STRMOVE(nextline + v, nextline + SPWORDLEN);
1514 nextline_idx = v + 1;
1515 }
1516 else
1517 {
1518 // Long line, use only the last SPWORDLEN bytes.
1519 nextlinecol = v - SPWORDLEN;
1520 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1521 nextline_idx = SPWORDLEN + 1;
1522 }
1523 }
1524 }
1525#endif
1526
Luuk van Baale84c7732023-05-31 18:57:36 +01001527 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1528 ptr = line;
1529
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 if (wp->w_p_list)
1531 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001532 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001533 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001534 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001535 || wp->w_lcs_chars.trail
1536 || wp->w_lcs_chars.lead
1537 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001539
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001541 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 {
1543 trailcol = (colnr_T)STRLEN(ptr);
1544 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1545 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001546 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001548 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001549 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001550 {
1551 leadcol = 0;
1552 while (VIM_ISWHITE(ptr[leadcol]))
1553 ++leadcol;
1554 if (ptr[leadcol] == NUL)
1555 // in a line full of spaces all of them are treated as trailing
1556 leadcol = (colnr_T)0;
1557 else
1558 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001559 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001560 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 }
1562
Bram Moolenaard7657e92022-09-20 18:59:30 +01001563 wlv.wcr_attr = get_wcr_attr(wp);
1564 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001566 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567 area_highlighting = TRUE;
1568 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001569
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001570 // When w_skipcol is non-zero and there is virtual text above the actual
1571 // text, then this much of the virtual text is skipped.
1572 int skipcol_in_text_prop_above = 0;
1573
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001574#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001575 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001576 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001577
1578 char_u *prop_start;
1579 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1580 if (text_prop_count > 0)
1581 {
1582 // Make a copy of the properties, so that they are properly
1583 // aligned.
1584 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1585 if (text_props != NULL)
1586 mch_memmove(text_props, prop_start,
1587 text_prop_count * sizeof(textprop_T));
1588
1589 // Allocate an array for the indexes.
1590 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1591 if (text_prop_idxs == NULL)
1592 VIM_CLEAR(text_props);
1593
1594 if (text_props != NULL)
1595 {
1596 area_highlighting = TRUE;
1597 extra_check = TRUE;
1598
1599 // When skipping virtual text the props need to be sorted. The
1600 // order is reversed!
1601 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1602 {
1603 for (int i = 0; i < text_prop_count; ++i)
1604 text_prop_idxs[i] = i;
1605 sort_text_props(wp->w_buffer, text_props,
1606 text_prop_idxs, text_prop_count);
1607 }
1608
1609 // Text props "above" move the line number down to where the text
1610 // is. Only count the ones that are visible, not those that are
1611 // skipped because of w_skipcol.
1612 int text_width = wp->w_width - win_col_off(wp);
1613 for (int i = text_prop_count - 1; i >= 0; --i)
1614 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1615 {
1616 if (lnum == wp->w_topline
1617 && wp->w_skipcol - skipcol_in_text_prop_above
1618 >= text_width)
1619 {
1620 // This virtual text above is skipped, remove it from
1621 // the array.
1622 skipcol_in_text_prop_above += text_width;
1623 for (int j = i + 1; j < text_prop_count; ++j)
1624 text_props[j - 1] = text_props[j];
1625 ++i;
1626 --text_prop_count;
1627 }
1628 else
1629 ++wlv.text_prop_above_count;
1630 }
1631 }
1632 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001633
1634 if (number_only)
1635 {
1636 // skip over rows only used for virtual text above
1637 wlv.row += wlv.text_prop_above_count;
1638 if (wlv.row > endrow)
1639 return wlv.row;
1640 wlv.screen_row += wlv.text_prop_above_count;
1641 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642#endif
1643
1644 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1645 // first character to be displayed.
1646 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001647 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001648 else
1649 v = wp->w_leftcol;
1650 if (v > 0 && !number_only)
1651 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001652 char_u *prev_ptr = ptr;
1653 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001654 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001656 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001657 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001658 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001659 charsize = win_lbr_chartabsize(&cts, NULL);
1660 cts.cts_vcol += charsize;
1661 prev_ptr = cts.cts_ptr;
1662 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001663 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001664 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001665 ptr = cts.cts_ptr;
1666 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001667
1668 // When:
1669 // - 'cuc' is set, or
1670 // - 'colorcolumn' is set, or
1671 // - 'virtualedit' is set, or
1672 // - the visual mode is active,
1673 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001674 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001675#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001676 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677#endif
1678 virtual_active() ||
1679 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001680 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681
1682 // Handle a character that's not completely on the screen: Put ptr at
1683 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001684 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001685 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001686 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001687 ptr = prev_ptr;
1688 // If the character fits on the screen, don't need to skip it.
1689 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001690 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1691 && wlv.col == 0)
1692 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 }
1694
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001695#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001696 // If there the text doesn't reach to the desired column, need to skip
1697 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001698 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1699 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001700 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001701#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001702
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001703 // Adjust for when the inverted text is before the screen,
1704 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001705 if (wlv.tocol <= wlv.vcol)
1706 wlv.fromcol = 0;
1707 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1708 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001709
1710#ifdef FEAT_LINEBREAK
1711 // When w_skipcol is non-zero, first line needs 'showbreak'
1712 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001713 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714#endif
1715#ifdef FEAT_SPELL
1716 // When spell checking a word we need to figure out the start of the
1717 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001718 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 {
1720 int len;
1721 colnr_T linecol = (colnr_T)(ptr - line);
1722 hlf_T spell_hlf = HLF_COUNT;
1723
1724 pos = wp->w_cursor;
1725 wp->w_cursor.lnum = lnum;
1726 wp->w_cursor.col = linecol;
1727 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1728
1729 // spell_move_to() may call ml_get() and make "line" invalid
1730 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1731 ptr = line + linecol;
1732
1733 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1734 {
1735 // no bad word found at line start, don't check until end of a
1736 // word
1737 spell_hlf = HLF_COUNT;
1738 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1739 }
1740 else
1741 {
1742 // bad word found, use attributes until end of word
1743 word_end = wp->w_cursor.col + len + 1;
1744
1745 // Turn index into actual attributes.
1746 if (spell_hlf != HLF_COUNT)
1747 spell_attr = highlight_attr[spell_hlf];
1748 }
1749 wp->w_cursor = pos;
1750
1751# ifdef FEAT_SYN_HL
1752 // Need to restart syntax highlighting for this line.
1753 if (has_syntax)
1754 syntax_start(wp, lnum);
1755# endif
1756 }
1757#endif
1758 }
1759
1760 // Correct highlighting for cursor that can't be disabled.
1761 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001762 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763 {
1764 if (noinvcur)
1765 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001766 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 {
1768 // highlighting starts at cursor, let it start just after the
1769 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001770 fromcol_prev = wlv.fromcol;
1771 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 // restart highlighting after the cursor
1775 fromcol_prev = wp->w_virtcol;
1776 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001777 if (wlv.fromcol >= wlv.tocol)
1778 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 }
1780
1781#ifdef FEAT_SEARCH_EXTRA
1782 if (!number_only)
1783 {
1784 v = (long)(ptr - line);
1785 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1786 &line, &screen_search_hl,
1787 &search_attr);
1788 ptr = line + v; // "line" may have been updated
1789 }
1790#endif
1791
1792#ifdef FEAT_SYN_HL
1793 // Cursor line highlighting for 'cursorline' in the current window.
1794 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1795 {
1796 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001797 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001798 if (!(wp == curwin && VIsual_active)
1799 && wp->w_p_culopt_flags != CULOPT_NBR)
1800 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001801 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1803
zeertzjqb7acea12022-12-12 13:20:43 +00001804 // Only apply CursorLine highlight here when "screenline" is not
1805 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001806 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001807 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808 else
1809 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001810 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1812 }
1813 area_highlighting = TRUE;
1814 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 }
1816#endif
1817
Bram Moolenaar1306b362022-08-06 15:59:06 +01001818 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001819
1820 // Repeat for the whole displayed line.
1821 for (;;)
1822 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001823 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001824#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001825 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826#endif
1827#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001828 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001830
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001832 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001834#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001835 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001836 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001837 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001838 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001839 }
1840#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 if (wlv.draw_state == WL_CMDLINE - 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_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 if (cmdwin_type != 0 && wp == curwin)
1845 {
1846 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001847 wlv.n_extra = 1;
1848 wlv.c_extra = cmdwin_type;
1849 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001850 wlv.char_attr =
1851 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
1853 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001855 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001857 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001858 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 }
1860#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001864 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001865 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001867 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868 }
1869#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001870 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001872 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001873 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001874 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001876#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001877 // Check if 'breakindent' applies and show it.
1878 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1879 if (wlv.n_extra == 0)
1880 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001883 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001885 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001886 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001887 }
1888#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001890 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001892 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001893 }
1894 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001895
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001897 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001898 && wlv.vcol >= left_curline_col
1899 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 {
zeertzjqb7acea12022-12-12 13:20:43 +00001901 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902 }
1903#endif
1904
1905 // When still displaying '$' of change command, stop at cursor.
1906 // When only displaying the (relative) line number and that's done,
1907 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001908 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001909 && lnum == wp->w_cursor.lnum
1910 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001911 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001912#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001913 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914#endif
1915 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001916 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001917 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 // Pretend we have finished updating the window. Except when
1919 // 'cursorcolumn' is set.
1920#ifdef FEAT_SYN_HL
1921 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001922 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 else
1924#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001925 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926 break;
1927 }
1928
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 {
1931 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001932 if (wlv.vcol == wlv.fromcol
1933 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1934 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 && (*mb_ptr2cells)(ptr) > 1)
1936 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001937 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001938 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 area_attr = vi_attr; // start highlighting
1940 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001941 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001942 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 area_attr = 0; // stop highlighting
1944
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001945#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 if (text_props != NULL)
1947 {
1948 int pi;
1949 int bcol = (int)(ptr - line);
1950
Bram Moolenaar1306b362022-08-06 15:59:06 +01001951 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001952# ifdef FEAT_LINEBREAK
1953 && !in_linebreak
1954# endif
1955 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001956 --bcol; // still working on the previous char, e.g. Tab
1957
1958 // Check if any active property ends.
1959 for (pi = 0; pi < text_props_active; ++pi)
1960 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001961 int tpi = text_prop_idxs[pi];
1962 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001964 // An inline property ends when after the start column plus
1965 // length. An "above" property ends when used and n_extra
1966 // is zero.
1967 if ((tp->tp_col != MAXCOL
1968 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001969 {
1970 if (pi + 1 < text_props_active)
1971 mch_memmove(text_prop_idxs + pi,
1972 text_prop_idxs + pi + 1,
1973 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001974 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001975 --text_props_active;
1976 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001977# ifdef FEAT_LINEBREAK
1978 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001979 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001980 syntax_attr = 0;
1981# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 }
1983 }
1984
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001985# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001987 // not on the next char yet, don't start another prop
1988 --bcol;
1989# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001990 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001991
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001993 // With 'nowrap' and not in the first screen line only "below"
1994 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001996 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001997 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001998 && (wp->w_p_wrap
1999 || wlv.row == startrow
2000 || (text_props[text_prop_next].tp_flags
2001 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002002 || (bcol == 0
2003 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002004 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002005 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002006 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002007 if (text_props[text_prop_next].tp_col == MAXCOL
2008 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002009 + text_props[text_prop_next].tp_len)
2010 text_prop_idxs[text_props_active++] = text_prop_next;
2011 ++text_prop_next;
2012 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002014 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002015 {
2016 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002017 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002018 text_prop_flags = 0;
2019 text_prop_type = NULL;
2020 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002021 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002022 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002023 if (text_props_active > 0 && wlv.n_extra == 0
2024 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002026 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002027 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002028 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002029
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002030 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002031 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002032
2033 // Sort the properties on priority and/or starting last.
2034 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002035 sort_text_props(wp->w_buffer, text_props,
2036 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037
2038 for (pi = 0; pi < text_props_active; ++pi)
2039 {
2040 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002041 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002042 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002043 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044
Bram Moolenaarcd105412022-10-10 19:50:42 +01002045 // Only use a text property that can be displayed.
2046 // Skip "after" properties when wrap is off and at the
2047 // end of the window.
2048 if (pt != NULL
2049 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2050 && tp->tp_id != -MAXCOL
2051 && !(tp->tp_id < 0
2052 && !wp->w_p_wrap
2053 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2054 | TP_FLAG_ALIGN_ABOVE
2055 | TP_FLAG_ALIGN_BELOW)) == 0
2056 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002057 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002058 if (tp->tp_col == MAXCOL
2059 && *ptr == NUL
2060 && ((wp->w_p_list && lcs_eol_one > 0
2061 && (tp->tp_flags
2062 & TP_FLAG_ALIGN_ABOVE) == 0)
2063 || (ptr == line
2064 && !did_line
2065 && (tp->tp_flags
2066 & TP_FLAG_ALIGN_BELOW))))
2067 {
2068 // skip this prop, first display the '$' after
2069 // the line or display an empty line
2070 text_prop_follows = TRUE;
2071 if (used_tpi < 0)
2072 display_text_first = TRUE;
2073 continue;
2074 }
2075
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002076 if (pt->pt_hl_id > 0)
2077 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 text_prop_type = pt;
2079 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002080 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002081 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2082 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002083 text_prop_flags = pt->pt_flags;
2084 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002085 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002086 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 }
2088 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002089 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002090 && -text_prop_id
2091 <= wp->w_buffer->b_textprop_text.ga_len)
2092 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002093 textprop_T *tp = &text_props[used_tpi];
2094 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002095 ->b_textprop_text.ga_data)[
2096 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002097 int above = (tp->tp_flags
2098 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002099 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002100
2101 // reset the ID in the copy to avoid it being used
2102 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002103 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002104
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002105 if (p != NULL)
2106 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002107 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002108 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002109 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002110 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002111 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2112 int padding = tp->tp_col == MAXCOL
2113 && tp->tp_len > 1
2114 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002115
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002116 // Insert virtual text before the current
2117 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002118 wlv.p_extra = p;
2119 wlv.c_extra = NUL;
2120 wlv.c_final = NUL;
2121 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002122 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002123 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2124 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002125 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002126 // restore search_attr and area_attr when n_extra
2127 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002128 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002129 saved_area_attr = area_attr;
2130 search_attr = 0;
2131 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002132 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002133 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002134 if (*ptr == NUL)
2135 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002136 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002137#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002138 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002139 {
2140 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002141 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002142 wlv.need_showbreak = FALSE;
2143 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002144 }
2145#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002146 if ((right || above || below || !wrap
2147 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002148 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002149 char_u *prev_p_extra = wlv.p_extra;
2150 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002151
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002152 // Take care of padding, right-align and
2153 // truncation.
2154 // Shared with win_lbr_chartabsize(), must do
2155 // exactly the same.
2156 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002157 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002158 wlv.col,
2159 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002160 &n_attr, &wlv.n_attr_skip,
2161 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002162 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002163 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002164 // wlv.p_extra was allocated
2165 vim_free(p_extra_free2);
2166 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002167 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002168
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002169 if (above)
2170 wlv.vcol_off_tp = wlv.n_extra;
2171
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002172 if (lcs_eol_one < 0
2173 && wp->w_p_wrap
2174 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002175 + wlv.n_extra - 2 > wp->w_width)
2176 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002177 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002178
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002179 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002180 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002181 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002182 {
2183 draw_screen_line(wp, &wlv);
2184
2185 // When line got too long for screen break
2186 // here.
2187 if (wlv.row == endrow)
2188 {
2189 ++wlv.row;
2190 break;
2191 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002192 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002193 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002194 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002195 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002196 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002197
Bram Moolenaarcd105412022-10-10 19:50:42 +01002198 // If the text didn't reach until the first window
2199 // column we need to skip cells.
2200 if (skip_cells > 0)
2201 {
2202 if (wlv.n_extra > skip_cells)
2203 {
2204 wlv.n_extra -= skip_cells;
2205 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002206 wlv.n_attr_skip -= skip_cells;
2207 if (wlv.n_attr_skip < 0)
2208 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002209 skip_cells = 0;
2210 }
2211 else
2212 {
2213 // the whole text is left of the window, drop
2214 // it and advance to the next one
2215 skip_cells -= wlv.n_extra;
2216 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002217 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002218 bail_out = TRUE;
2219 }
2220 }
2221
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002222 // If another text prop follows the condition below at
2223 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002224 // If this is an "above" text prop and 'nowrap' the we
2225 // must wrap anyway.
2226 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002227 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002228 && (wp->w_p_wrap
2229 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002230 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002231
2232 if (bail_out)
2233 // starting a new line for "below"
2234 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002235 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002236 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002237 else if (text_prop_next < text_prop_count
2238 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002239 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2240 || (!wp->w_p_wrap
2241 && wlv.col == wp->w_width - 1
2242 && (text_props[text_prop_next].tp_flags
2243 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002244 // When at last-but-one character and a text property
2245 // follows after it, we may need to flush the line after
2246 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002247 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002248 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002249 }
2250#endif
2251
Bram Moolenaare38fc862022-08-11 17:24:50 +01002252#ifdef FEAT_SEARCH_EXTRA
2253 if (wlv.n_extra == 0)
2254 {
2255 // Check for start/end of 'hlsearch' and other matches.
2256 // After end, check for start/end of next match.
2257 // When another match, have to check for start again.
2258 v = (long)(ptr - line);
2259 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2260 &screen_search_hl, &has_match_conc,
2261 &match_conc, did_line_attr, lcs_eol_one,
2262 &on_last_col);
2263 ptr = line + v; // "line" may have been changed
2264 prev_ptr = ptr;
2265
2266 // Do not allow a conceal over EOL otherwise EOL will be missed
2267 // and bad things happen.
2268 if (*ptr == NUL)
2269 has_match_conc = 0;
2270 }
2271#endif
2272
2273#ifdef FEAT_DIFF
2274 if (wlv.diff_hlf != (hlf_T)0)
2275 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002276 // When there is extra text (e.g. virtual text) it gets the
2277 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002278 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2279 && wlv.n_extra == 0)
2280 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002281 if (wlv.diff_hlf == HLF_TXD
2282 && ((ptr - line > change_end && wlv.n_extra == 0)
2283 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002284 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002285 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002286 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2287 && wp->w_p_culopt_flags != CULOPT_NBR
2288 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2289 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002290 wlv.line_attr = hl_combine_attr(
2291 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002292 }
2293#endif
2294
Bram Moolenaara74fda62019-10-19 17:38:03 +02002295#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002296 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002297 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002298 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002299# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002300 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002301 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002302# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002303 // Get syntax attribute.
2304 if (has_syntax)
2305 {
2306 // Get the syntax attribute for the character. If there
2307 // is an error, disable syntax highlighting.
2308 save_did_emsg = did_emsg;
2309 did_emsg = FALSE;
2310
2311 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002312 if (v == prev_syntax_col)
2313 // at same column again
2314 syntax_attr = prev_syntax_attr;
2315 else
2316 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002317# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002318 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002319# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002320 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002321# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002322 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002323# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002324 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002325 prev_syntax_col = v;
2326 prev_syntax_attr = syntax_attr;
2327 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002328
Bram Moolenaar34390282019-10-16 14:38:26 +02002329 if (did_emsg)
2330 {
2331 wp->w_s->b_syn_error = TRUE;
2332 has_syntax = FALSE;
2333 syntax_attr = 0;
2334 }
2335 else
2336 did_emsg = save_did_emsg;
2337# ifdef SYN_TIME_LIMIT
2338 if (wp->w_s->b_syn_slow)
2339 has_syntax = FALSE;
2340# endif
2341
2342 // Need to get the line again, a multi-line regexp may
2343 // have made it invalid.
2344 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2345 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002346 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002347# ifdef FEAT_CONCEAL
2348 // no concealing past the end of the line, it interferes
2349 // with line highlighting
2350 if (*ptr == NUL)
2351 syntax_flags = 0;
2352 else
2353 syntax_flags = get_syntax_info(&syntax_seqnr);
2354# endif
2355 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002356 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002357# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002358 // Combine text property highlight into syntax highlight.
2359 if (text_prop_type != NULL)
2360 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002361 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002362 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2363 else
2364 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002365 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002366 }
2367# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002368#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002369
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 // Decide which of the highlight attributes to use.
2371 attr_pri = TRUE;
2372#ifdef LINE_ATTR
2373 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002374 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002375 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002376 if (!highlight_match)
2377 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002378 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002379# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002380 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002381# endif
2382 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002383 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002384 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002385 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002386# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002387 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002388# endif
2389 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002390 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002391 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2392 || wlv.vcol < wlv.fromcol
2393 || vcol_prev < fromcol_prev
2394 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002395 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002396 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002397 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002398# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002399 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002400# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002401 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002402# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002403 attr_pri = FALSE;
2404 }
2405#else
2406 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002407 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002409 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410#endif
2411 else
2412 {
2413 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002416#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002417 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002418#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002419 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002420#ifdef FEAT_PROP_POPUP
2421 // override with text property highlight when "override" is TRUE
2422 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002423 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002424#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002425 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002426
2427 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002428 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002429 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002430 if (wlv.char_attr == 0)
2431 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002432 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002433 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002434 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002435
2436 // Get the next character to put on the screen.
2437
2438 // The "p_extra" points to the extra stuff that is inserted to
2439 // represent special characters (non-printable stuff) and other
2440 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2443 // "p_extra[n_extra]".
2444 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002445 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002447 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002448 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002449 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2450 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002451 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2452 if (enc_utf8 && utf_char2len(c) > 1)
2453 {
2454 mb_utf8 = TRUE;
2455 u8cc[0] = 0;
2456 c = 0xc0;
2457 }
2458 else
2459 mb_utf8 = FALSE;
2460 }
2461 else
2462 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002463 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 if (has_mbyte)
2465 {
2466 mb_c = c;
2467 if (enc_utf8)
2468 {
2469 // If the UTF-8 character is more than one byte:
2470 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002471 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002472 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 mb_l = 1;
2475 else if (mb_l > 1)
2476 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 mb_utf8 = TRUE;
2479 c = 0xc0;
2480 }
2481 }
2482 else
2483 {
2484 // if this is a DBCS character, put it in "mb_c"
2485 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002486 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 mb_l = 1;
2488 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002489 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 }
2491 if (mb_l == 0) // at the NUL at end-of-line
2492 mb_l = 1;
2493
2494 // If a double-width char doesn't fit display a '>' in the
2495 // last column.
2496 if ((
2497# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002498 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002500 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 && (*mb_char2cells)(mb_c) == 2)
2502 {
2503 c = '>';
2504 mb_c = c;
2505 mb_l = 1;
2506 mb_utf8 = FALSE;
2507 multi_attr = HL_ATTR(HLF_AT);
2508#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002509 if (wlv.cul_attr)
2510 multi_attr = hl_combine_attr(
2511 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002512#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002513 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002514
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 // put the pointer back to output the double-width
2516 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002517 ++wlv.n_extra;
2518 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 }
2520 else
2521 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002522 wlv.n_extra -= mb_l - 1;
2523 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 }
2525 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002526 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002527 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002528 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002529#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002530 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002531 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002532 // Only restore search_attr and area_attr after "n_extra" in
2533 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002534 if (wlv.saved_n_extra <= 0)
2535 {
2536 if (search_attr == 0)
2537 search_attr = saved_search_attr;
2538 if (area_attr == 0 && *ptr != NUL)
2539 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002540
2541 if (wlv.extra_for_textprop)
2542 // wlv.extra_attr should be used at this position but
2543 // not any further.
2544 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002545 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002546
2547 wlv.extra_for_textprop = FALSE;
2548 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002549 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002550#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 }
2552 else
2553 {
2554#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002555 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002557 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 // Get a character from the line itself.
2560 c = *ptr;
2561#ifdef FEAT_LINEBREAK
2562 c0 = *ptr;
2563#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002564#ifdef FEAT_PROP_POPUP
2565 if (c == NUL)
2566 // text is finished, may display a "below" virtual text
2567 did_line = TRUE;
2568#endif
2569
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 if (has_mbyte)
2571 {
2572 mb_c = c;
2573 if (enc_utf8)
2574 {
2575 // If the UTF-8 character is more than one byte: Decode it
2576 // into "mb_c".
2577 mb_l = utfc_ptr2len(ptr);
2578 mb_utf8 = FALSE;
2579 if (mb_l > 1)
2580 {
2581 mb_c = utfc_ptr2char(ptr, u8cc);
2582 // Overlong encoded ASCII or ASCII with composing char
2583 // is displayed normally, except a NUL.
2584 if (mb_c < 0x80)
2585 {
2586 c = mb_c;
2587#ifdef FEAT_LINEBREAK
2588 c0 = mb_c;
2589#endif
2590 }
2591 mb_utf8 = TRUE;
2592
2593 // At start of the line we can have a composing char.
2594 // Draw it as a space with a composing char.
2595 if (utf_iscomposing(mb_c))
2596 {
2597 int i;
2598
2599 for (i = Screen_mco - 1; i > 0; --i)
2600 u8cc[i] = u8cc[i - 1];
2601 u8cc[0] = mb_c;
2602 mb_c = ' ';
2603 }
2604 }
2605
2606 if ((mb_l == 1 && c >= 0x80)
2607 || (mb_l >= 1 && mb_c == 0)
2608 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2609 {
2610 // Illegal UTF-8 byte: display as <xx>.
2611 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002612 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613# ifdef FEAT_RIGHTLEFT
2614 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002615 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002617 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002618 c = *wlv.p_extra;
2619 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2622 wlv.c_extra = NUL;
2623 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 if (area_attr == 0 && search_attr == 0)
2625 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002626 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002627 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002628 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002629 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 }
2631 }
2632 else if (mb_l == 0) // at the NUL at end-of-line
2633 mb_l = 1;
2634#ifdef FEAT_ARABIC
2635 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2636 {
2637 // Do Arabic shaping.
2638 int pc, pc1, nc;
2639 int pcc[MAX_MCO];
2640
2641 // The idea of what is the previous and next
2642 // character depends on 'rightleft'.
2643 if (wp->w_p_rl)
2644 {
2645 pc = prev_c;
2646 pc1 = prev_c1;
2647 nc = utf_ptr2char(ptr + mb_l);
2648 prev_c1 = u8cc[0];
2649 }
2650 else
2651 {
2652 pc = utfc_ptr2char(ptr + mb_l, pcc);
2653 nc = prev_c;
2654 pc1 = pcc[0];
2655 }
2656 prev_c = mb_c;
2657
2658 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2659 }
2660 else
2661 prev_c = mb_c;
2662#endif
2663 }
2664 else // enc_dbcs
2665 {
2666 mb_l = MB_BYTE2LEN(c);
2667 if (mb_l == 0) // at the NUL at end-of-line
2668 mb_l = 1;
2669 else if (mb_l > 1)
2670 {
2671 // We assume a second byte below 32 is illegal.
2672 // Hopefully this is OK for all double-byte encodings!
2673 if (ptr[1] >= 32)
2674 mb_c = (c << 8) + ptr[1];
2675 else
2676 {
2677 if (ptr[1] == NUL)
2678 {
2679 // head byte at end of line
2680 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002681 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002682 }
2683 else
2684 {
2685 // illegal tail byte
2686 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002687 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002688 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002689 wlv.p_extra = wlv.extra;
2690 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002691 wlv.c_extra = NUL;
2692 wlv.c_final = NUL;
2693 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002694 if (area_attr == 0 && search_attr == 0)
2695 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002696 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002697 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002698 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002699 // save current attr
2700 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 }
2702 mb_c = c;
2703 }
2704 }
2705 }
2706 // If a double-width char doesn't fit display a '>' in the
2707 // last column; the character is displayed at the start of the
2708 // next line.
2709 if ((
2710# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002711 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002713 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002714 && (*mb_char2cells)(mb_c) == 2)
2715 {
2716 c = '>';
2717 mb_c = c;
2718 mb_utf8 = FALSE;
2719 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002720 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 // Put pointer back so that the character will be
2722 // displayed at the start of the next line.
2723 --ptr;
2724#ifdef FEAT_CONCEAL
2725 did_decrement_ptr = TRUE;
2726#endif
2727 }
2728 else if (*ptr != NUL)
2729 ptr += mb_l - 1;
2730
2731 // If a double-width char doesn't fit at the left side display
2732 // a '<' in the first column. Don't do this for unprintable
2733 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002734 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 wlv.n_extra = 1;
2737 wlv.c_extra = MB_FILLER_CHAR;
2738 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739 c = ' ';
2740 if (area_attr == 0 && search_attr == 0)
2741 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002742 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002743 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002744 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002745 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 }
2747 mb_c = c;
2748 mb_utf8 = FALSE;
2749 mb_l = 1;
2750 }
2751
2752 }
2753 ++ptr;
2754
2755 if (extra_check)
2756 {
2757#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002758 // Check spelling (unless at the end of the line).
2759 // Only do this when there is no syntax highlighting, the
2760 // @Spell cluster is not used or the current syntax item
2761 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002762 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002763 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002764 {
2765 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002766 // do not calculate cap_col at the end of the line or when
2767 // only white space is following
2768 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002769# ifdef FEAT_SYN_HL
2770 !has_syntax ||
2771# endif
2772 can_spell))
2773 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002774 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002775 int len;
2776 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002777
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002780
2781 // Use nextline[] if possible, it has the start of the
2782 // next line concatenated.
2783 if ((prev_ptr - line) - nextlinecol >= 0)
2784 p = nextline + (prev_ptr - line) - nextlinecol;
2785 else
2786 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002787 spv->spv_cap_col -= (int)(prev_ptr - line);
2788 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2789 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002790 word_end = v + len;
2791
2792 // In Insert mode only highlight a word that
2793 // doesn't touch the cursor.
2794 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002795 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002796 && wp->w_cursor.lnum == lnum
2797 && wp->w_cursor.col >=
2798 (colnr_T)(prev_ptr - line)
2799 && wp->w_cursor.col < (colnr_T)word_end)
2800 {
2801 spell_hlf = HLF_COUNT;
2802 spell_redraw_lnum = lnum;
2803 }
2804
2805 if (spell_hlf == HLF_COUNT && p != prev_ptr
2806 && (p - nextline) + len > nextline_idx)
2807 {
2808 // Remember that the good word continues at the
2809 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002810 spv->spv_checked_lnum = lnum + 1;
2811 spv->spv_checked_col = (p - nextline) + len
2812 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 }
2814
2815 // Turn index into actual attributes.
2816 if (spell_hlf != HLF_COUNT)
2817 spell_attr = highlight_attr[spell_hlf];
2818
Luuk van Baal30805a12023-05-27 22:22:10 +01002819 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 {
2821 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002822 && (p - nextline) + spv->spv_cap_col
2823 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002824 {
2825 // Remember that the word in the next line
2826 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002827 spv->spv_capcol_lnum = lnum + 1;
2828 spv->spv_cap_col = ((p - nextline)
2829 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 }
2831 else
2832 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002833 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 }
2835 }
2836 }
2837 if (spell_attr != 0)
2838 {
2839 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2841 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002842 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002843 wlv.char_attr = hl_combine_attr(spell_attr,
2844 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002845 }
2846#endif
2847#ifdef FEAT_LINEBREAK
2848 // Found last space before word: check for line break.
2849 if (wp->w_p_lbr && c0 == c
2850 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2851 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002852 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2853 : 0;
2854 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002855 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002856
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002857 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002858# ifdef FEAT_PROP_POPUP
2859 // do not want virtual text counted here
2860 cts.cts_has_prop_with_text = FALSE;
2861# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002863 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002864
2865 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002866 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002867 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2870 if (wlv.n_extra < 0)
2871 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002872 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002873 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002874 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002875 // line break, but for TABs the highlighting should
2876 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002877 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002878
Bram Moolenaar1306b362022-08-06 15:59:06 +01002879 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002882 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 wp->w_buffer->b_p_vts_array) - 1;
2884# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002886 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887# endif
2888
Bram Moolenaar1306b362022-08-06 15:59:06 +01002889 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2890 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002891# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002893 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002894# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 if (VIM_ISWHITE(c))
2896 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002897# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 if (c == TAB)
2899 // See "Tab alignment" below.
2900 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002901# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 if (!wp->w_p_list)
2903 c = ' ';
2904 }
2905 }
2906#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002907 in_multispace = c == ' '
2908 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2909 if (!in_multispace)
2910 multispace_pos = 0;
2911
Bram Moolenaareed9d462021-02-15 20:38:25 +01002912 // 'list': Change char 160 to 'nbsp' and space to 'space'
2913 // setting in 'listchars'. But not when the character is
2914 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 if (wp->w_p_list
2916 && ((((c == 160 && mb_l == 1)
2917 || (mb_utf8
2918 && ((mb_c == 160 && mb_l == 2)
2919 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002920 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002921 || (c == ' '
2922 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002923 && (wp->w_lcs_chars.space
2924 || (in_multispace
2925 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002926 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002927 && ptr - line <= trailcol)))
2928 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002929 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2930 {
2931 c = wp->w_lcs_chars.multispace[multispace_pos++];
2932 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2933 multispace_pos = 0;
2934 }
2935 else
2936 c = (c == ' ') ? wp->w_lcs_chars.space
2937 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 if (area_attr == 0 && search_attr == 0)
2939 {
2940 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002941 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002942 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 }
2945 mb_c = c;
2946 if (enc_utf8 && utf_char2len(c) > 1)
2947 {
2948 mb_utf8 = TRUE;
2949 u8cc[0] = 0;
2950 c = 0xc0;
2951 }
2952 else
2953 mb_utf8 = FALSE;
2954 }
2955
zeertzjq2e7cba32022-06-10 15:30:32 +01002956 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2957 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002958 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002959 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2960 && wp->w_lcs_chars.leadmultispace != NULL)
2961 {
2962 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002963 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2964 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002965 multispace_pos = 0;
2966 }
2967
2968 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2969 c = wp->w_lcs_chars.trail;
2970
2971 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2972 c = wp->w_lcs_chars.lead;
2973
zeertzjq2e7cba32022-06-10 15:30:32 +01002974 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002975 c = wp->w_lcs_chars.space;
2976
2977
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002978 if (!attr_pri)
2979 {
2980 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002981 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002982 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002983 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002984 }
2985 mb_c = c;
2986 if (enc_utf8 && utf_char2len(c) > 1)
2987 {
2988 mb_utf8 = TRUE;
2989 u8cc[0] = 0;
2990 c = 0xc0;
2991 }
2992 else
2993 mb_utf8 = FALSE;
2994 }
2995 }
2996
2997 // Handling of non-printable characters.
2998 if (!vim_isprintc(c))
2999 {
3000 // when getting a character from the file, we may have to
3001 // turn it into something else on the way to putting it
3002 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003003 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003005 int tab_len = 0;
3006 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003008 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003009
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 // only adjust the tab_len, when at the first column
3011 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003012 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003013 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014#endif
3015 // tab amount depends on current column
3016#ifdef FEAT_VARTABS
3017 tab_len = tabstop_padding(vcol_adjusted,
3018 wp->w_buffer->b_p_ts,
3019 wp->w_buffer->b_p_vts_array) - 1;
3020#else
3021 tab_len = (int)wp->w_buffer->b_p_ts
3022 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3023#endif
3024
3025#ifdef FEAT_LINEBREAK
3026 if (!wp->w_p_lbr || !wp->w_p_list)
3027#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003028 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003030 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003031 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003032#ifdef FEAT_LINEBREAK
3033 else
3034 {
3035 char_u *p;
3036 int len;
3037 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003038 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003040# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003041 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003042 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003043 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003044
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003046 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 && old_boguscols > 0
3048 && wlv.n_extra > tab_len)
3049 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003050# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003051 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003053 // If wlv.n_extra > 0, it gives the number of chars
3054 // to use for a tab, else we need to calculate the
3055 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003056 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3057 len = tab_len * tab2_len;
3058 if (wp->w_lcs_chars.tab3)
3059 len += mb_char2len(wp->w_lcs_chars.tab3)
3060 - tab2_len;
3061 if (wlv.n_extra > 0)
3062 len += wlv.n_extra - tab_len;
3063 c = wp->w_lcs_chars.tab1;
3064 p = alloc(len + 1);
3065 if (p == NULL)
3066 wlv.n_extra = 0;
3067 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003069 vim_memset(p, ' ', len);
3070 p[len] = NUL;
3071 vim_free(wlv.p_extra_free);
3072 wlv.p_extra_free = p;
3073 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003074 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003075 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003076
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003077 if (*p == NUL)
3078 {
3079 tab_len = i;
3080 break;
3081 }
3082
3083 // if tab3 is given, use it for the last
3084 // char
3085 if (wp->w_lcs_chars.tab3
3086 && i == tab_len - 1)
3087 lcs = wp->w_lcs_chars.tab3;
3088 p += mb_char2bytes(lcs, p);
3089 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003091 }
3092 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003093# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003094 // n_extra will be increased by
3095 // FIX_FOX_BOGUSCOLS macro below, so need to
3096 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003097 if (wlv.vcol_off_co > 0)
3098 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003099# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003100 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003101 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003102 }
3103#endif
3104#ifdef FEAT_CONCEAL
3105 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003106 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107
3108 // Tab alignment should be identical regardless of
3109 // 'conceallevel' value. So tab compensates of all
3110 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003111 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003112 // line. Note that the tab can be longer than
3113 // 'tabstop' when there are concealed characters.
3114 FIX_FOR_BOGUSCOLS;
3115
3116 // Make sure, the highlighting for the tab char will be
3117 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003118 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003120 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003121 tab_len += vc_saved;
3122 }
3123#endif
3124 mb_utf8 = FALSE; // don't draw as UTF-8
3125 if (wp->w_p_list)
3126 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003127 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003128 ? wp->w_lcs_chars.tab3
3129 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003130#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003131 if (wp->w_p_lbr && wlv.p_extra != NULL
3132 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003133 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 else
3135#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003136 wlv.c_extra = wp->w_lcs_chars.tab2;
3137 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003138 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003139 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003140 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003141 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 mb_c = c;
3143 if (enc_utf8 && utf_char2len(c) > 1)
3144 {
3145 mb_utf8 = TRUE;
3146 u8cc[0] = 0;
3147 c = 0xc0;
3148 }
3149 }
3150 else
3151 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 wlv.c_final = NUL;
3153 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 c = ' ';
3155 }
3156 }
3157 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003158 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003160 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3161 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 && VIsual_mode != Ctrl_V
3163 && (
3164# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003165 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003167 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168 && !(noinvcur
3169 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003170 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171 && lcs_eol_one > 0)
3172 {
3173 // Display a '$' after the line or highlight an extra
3174 // character if the line break is included.
3175#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3176 // For a diff line the highlighting continues after the
3177 // "$".
3178 if (
3179# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181# ifdef LINE_ATTR
3182 &&
3183# endif
3184# endif
3185# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003186 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003187# endif
3188 )
3189#endif
3190 {
3191 // In virtualedit, visual selections may extend
3192 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003193 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003194 && wlv.tocol != MAXCOL
3195 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003196 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003197 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003199 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3200 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201 else
3202 c = ' ';
3203 lcs_eol_one = -1;
3204 --ptr; // put it back at the NUL
3205 if (!attr_pri)
3206 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003207 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003208 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003209 n_attr = 1;
3210 }
3211 mb_c = c;
3212 if (enc_utf8 && utf_char2len(c) > 1)
3213 {
3214 mb_utf8 = TRUE;
3215 u8cc[0] = 0;
3216 c = 0xc0;
3217 }
3218 else
3219 mb_utf8 = FALSE; // don't draw as UTF-8
3220 }
3221 else if (c != NUL)
3222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003223 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3224 if (wlv.n_extra == 0)
3225 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226#ifdef FEAT_RIGHTLEFT
3227 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003228 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003229#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.c_extra = NUL;
3231 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232#ifdef FEAT_LINEBREAK
3233 if (wp->w_p_lbr)
3234 {
3235 char_u *p;
3236
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 c = *wlv.p_extra;
3238 p = alloc(wlv.n_extra + 1);
3239 vim_memset(p, ' ', wlv.n_extra);
3240 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3241 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003242 vim_free(wlv.p_extra_free);
3243 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 }
3245 else
3246#endif
3247 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003248 wlv.n_extra = byte2cells(c) - 1;
3249 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 }
3251 if (!attr_pri)
3252 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003253 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003254 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003255 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003256 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
3258 mb_utf8 = FALSE; // don't draw as UTF-8
3259 }
3260 else if (VIsual_active
3261 && (VIsual_mode == Ctrl_V
3262 || VIsual_mode == 'v')
3263 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003264 && wlv.tocol != MAXCOL
3265 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 && (
3267#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003268 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 {
3272 c = ' ';
3273 --ptr; // put it back at the NUL
3274 }
3275#if defined(LINE_ATTR)
3276 else if ((
3277# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003278 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003279# endif
3280# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003281 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003283 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 ) && (
3285# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003286 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003290 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291# endif
3292 < wp->w_width)))
3293 {
3294 // Highlight until the right side of the window
3295 c = ' ';
3296 --ptr; // put it back at the NUL
3297
3298 // Remember we do the char for line highlighting.
3299 ++did_line_attr;
3300
3301 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003302 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003304 || (wp->w_p_list &&
3305 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003306 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003308 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003309 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 wlv.diff_hlf = HLF_CHD;
3311 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003313 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3315 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003317 || (wlv.vcol >= left_curline_col
3318 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003319 wlv.char_attr = hl_combine_attr(
3320 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 }
3322 }
3323# endif
3324# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003325 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003326 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003327 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003328 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3329 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003331 if (!wlv.cul_screenline
3332 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003333 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 wlv.char_attr = hl_combine_attr(
3335 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003337 else if (wlv.line_attr)
3338 wlv.char_attr = hl_combine_attr(
3339 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 }
3341# endif
3342 }
3343#endif
3344 }
3345
3346#ifdef FEAT_CONCEAL
3347 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003348 && (wp != curwin || lnum != wp->w_cursor.lnum
3349 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3351 && !(lnum_in_visual_area
3352 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3353 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003355 if (((prev_syntax_id != syntax_seqnr
3356 && (syntax_flags & HL_CONCEAL) != 0)
3357 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003358 && (syn_get_sub_char() != NUL
3359 || (has_match_conc && match_conc)
3360 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361 && wp->w_p_cole != 3)
3362 {
3363 // First time at this concealed item: display one
3364 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003365 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 c = match_conc;
3367 else if (syn_get_sub_char() != NUL)
3368 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003369 else if (wp->w_lcs_chars.conceal != NUL)
3370 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003371 else
3372 c = ' ';
3373
3374 prev_syntax_id = syntax_seqnr;
3375
Bram Moolenaar1306b362022-08-06 15:59:06 +01003376 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003377 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 wlv.vcol += wlv.n_extra;
3379 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 {
3381# ifdef FEAT_RIGHTLEFT
3382 if (wp->w_p_rl)
3383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 wlv.col -= wlv.n_extra;
3385 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 else
3388# endif
3389 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003390 wlv.boguscols += wlv.n_extra;
3391 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003392 }
3393 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 n_attr = 0;
3396 }
3397 else if (n_skip == 0)
3398 {
3399 is_concealing = TRUE;
3400 n_skip = 1;
3401 }
3402 mb_c = c;
3403 if (enc_utf8 && utf_char2len(c) > 1)
3404 {
3405 mb_utf8 = TRUE;
3406 u8cc[0] = 0;
3407 c = 0xc0;
3408 }
3409 else
3410 mb_utf8 = FALSE; // don't draw as UTF-8
3411 }
3412 else
3413 {
3414 prev_syntax_id = 0;
3415 is_concealing = FALSE;
3416 }
3417
3418 if (n_skip > 0 && did_decrement_ptr)
3419 // not showing the '>', put pointer back to avoid getting stuck
3420 ++ptr;
3421
3422#endif // FEAT_CONCEAL
3423 }
3424
3425#ifdef FEAT_CONCEAL
3426 // In the cursor line and we may be concealing characters: correct
3427 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003428 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429 && wp == curwin && lnum == wp->w_cursor.lnum
3430 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003431 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003433# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003434 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003435 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003437# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003438 wp->w_wcol = wlv.col - wlv.boguscols;
3439 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 did_wcol = TRUE;
3441 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003442# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003443 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003444# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 }
3446#endif
3447
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003448 // Use "wlv.extra_attr", but don't override visual selection
3449 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003450 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3451 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003452 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003453 && (!attr_pri
3454#ifdef FEAT_PROP_POPUP
3455 || (text_prop_flags & PT_FLAG_OVERRIDE)
3456#endif
3457 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 {
3459#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003460 if (wlv.line_attr)
3461 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462 else
3463#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003464 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003465#ifdef FEAT_PROP_POPUP
3466 if (reset_extra_attr)
3467 {
3468 reset_extra_attr = FALSE;
3469 wlv.extra_attr = 0;
3470 }
3471#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 }
3473
3474#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3475 // XIM don't send preedit_start and preedit_end, but they send
3476 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3477 // im_is_preediting() here.
3478 if (p_imst == IM_ON_THE_SPOT
3479 && xic != NULL
3480 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003481 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003482 && !p_imdisable
3483 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 {
3486 colnr_T tcol;
3487
3488 if (preedit_end_col == MAXCOL)
3489 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3490 else
3491 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 {
3494 if (feedback_old_attr < 0)
3495 {
3496 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003498 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 wlv.char_attr = im_get_feedback_attr(feedback_col);
3500 if (wlv.char_attr < 0)
3501 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003502 feedback_col++;
3503 }
3504 else if (feedback_old_attr >= 0)
3505 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507 feedback_old_attr = -1;
3508 feedback_col = 0;
3509 }
3510 }
3511#endif
3512 // Handle the case where we are in column 0 but not on the first
3513 // character of the line and the user wants us to show us a
3514 // special character (via 'listchars' option "precedes:<char>".
3515 if (lcs_prec_todo != NUL
3516 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003517 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3518 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003520 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003521#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003522 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 && c != NUL)
3524 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003525 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526 lcs_prec_todo = NUL;
3527 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3528 {
3529 // Double-width character being overwritten by the "precedes"
3530 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003531 wlv.c_extra = MB_FILLER_CHAR;
3532 wlv.c_final = NUL;
3533 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003535 wlv.extra_attr =
3536 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 }
3538 mb_c = c;
3539 if (enc_utf8 && utf_char2len(c) > 1)
3540 {
3541 mb_utf8 = TRUE;
3542 u8cc[0] = 0;
3543 c = 0xc0;
3544 }
3545 else
3546 mb_utf8 = FALSE; // don't draw as UTF-8
3547 if (!attr_pri)
3548 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003549 saved_attr3 = wlv.char_attr; // save current attr
3550 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003551 n_attr3 = 1;
3552 }
3553 }
3554
3555 // At end of the text line or just after the last character.
3556 if ((c == NUL
3557#if defined(LINE_ATTR)
3558 || did_line_attr == 1
3559#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 {
3562#ifdef FEAT_SEARCH_EXTRA
3563 // flag to indicate whether prevcol equals startcol of search_hl or
3564 // one of the matches
3565 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3566 (long)(ptr - line) - (c == NUL));
3567#endif
3568 // Invert at least one char, used for Visual and empty line or
3569 // highlight match at end of line. If it's beyond the last
3570 // char on the screen, just overwrite that one (tricky!) Not
3571 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003572 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003573 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 && (VIsual_mode != Ctrl_V
3575 || lnum == VIsual.lnum
3576 || lnum == curwin->w_cursor.lnum)
3577 && c == NUL)
3578#ifdef FEAT_SEARCH_EXTRA
3579 // highlight 'hlsearch' match at end of line
3580 || (prevcol_hl_flag
3581# ifdef FEAT_SYN_HL
3582 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3583 && !(wp == curwin && VIsual_active))
3584# endif
3585# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003586 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587# endif
3588# if defined(LINE_ATTR)
3589 && did_line_attr <= 1
3590# endif
3591 )
3592#endif
3593 ))
3594 {
3595 int n = 0;
3596
3597#ifdef FEAT_RIGHTLEFT
3598 if (wp->w_p_rl)
3599 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 n = 1;
3602 }
3603 else
3604#endif
3605 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003606 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 n = -1;
3608 }
3609 if (n != 0)
3610 {
3611 // At the window boundary, highlight the last character
3612 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 wlv.off += n;
3614 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003615 }
3616 else
3617 {
3618 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003619 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003620 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003621 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
3623#ifdef FEAT_SEARCH_EXTRA
3624 if (area_attr == 0)
3625 {
3626 // Use attributes from match with highest priority among
3627 // 'search_hl' and the match list.
3628 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003629 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 }
3631#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003633 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634#ifdef FEAT_RIGHTLEFT
3635 if (wp->w_p_rl)
3636 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003637 --wlv.col;
3638 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 }
3640 else
3641#endif
3642 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 ++wlv.col;
3644 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ++wlv.vcol;
3647 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648 }
3649 }
3650
3651 // At end of the text line.
3652 if (c == NUL)
3653 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003654#ifdef FEAT_PROP_POPUP
3655 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003657 // Put the pointer back to the NUL.
3658 --ptr;
3659 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003661 else
3662#endif
3663 {
3664 draw_screen_line(wp, &wlv);
3665
3666 // Update w_cline_height and w_cline_folded if the cursor line
3667 // was updated (saves a call to plines() later).
3668 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3669 {
3670 curwin->w_cline_row = startrow;
3671 curwin->w_cline_height = wlv.row - startrow;
3672#ifdef FEAT_FOLDING
3673 curwin->w_cline_folded = FALSE;
3674#endif
3675 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3676 }
3677 break;
3678 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 }
3680
3681 // Show "extends" character from 'listchars' if beyond the line end and
3682 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003683 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003684 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685 && wp->w_p_list
3686 && !wp->w_p_wrap
3687#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003688 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689#endif
3690 && (
3691#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003692 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003694 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003696 || lcs_eol_one > 0
3697 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003698 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003700 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003701 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 mb_c = c;
3703 if (enc_utf8 && utf_char2len(c) > 1)
3704 {
3705 mb_utf8 = TRUE;
3706 u8cc[0] = 0;
3707 c = 0xc0;
3708 }
3709 else
3710 mb_utf8 = FALSE;
3711 }
3712
3713#ifdef FEAT_SYN_HL
3714 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003715 if (wlv.draw_color_col)
3716 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717
3718 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3719 // highlight the cursor position itself.
3720 // Also highlight the 'colorcolumn' if it is different than
3721 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003722 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3723 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003725 if (((wlv.draw_state == WL_LINE
3726 || wlv.draw_state == WL_BRI
3727 || wlv.draw_state == WL_SBR)
3728 && !lnum_in_visual_area
3729 && search_attr == 0
3730 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003731# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003732 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003733# endif
3734 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003735 {
3736 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3737 && lnum != wp->w_cursor.lnum)
3738 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003739 vcol_save_attr = wlv.char_attr;
3740 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3741 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003743 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003745 vcol_save_attr = wlv.char_attr;
3746 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747 }
3748 }
3749#endif
3750
3751 // Store character to be displayed.
3752 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003753 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 {
3756 // Store the character.
3757#if defined(FEAT_RIGHTLEFT)
3758 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3759 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003760 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003761 --wlv.off;
3762 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 }
3764#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003765 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003766 if (enc_dbcs == DBCS_JPNU)
3767 {
3768 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 ScreenLines[wlv.off] = 0x8e;
3770 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 }
3772 else if (enc_utf8)
3773 {
3774 if (mb_utf8)
3775 {
3776 int i;
3777
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003778 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003780 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003781 for (i = 0; i < Screen_mco; ++i)
3782 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003783 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 if (u8cc[i] == 0)
3785 break;
3786 }
3787 }
3788 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003789 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790 }
3791 if (multi_attr)
3792 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794 multi_attr = 0;
3795 }
3796 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003797 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003800
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3802 {
3803 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003804 ++wlv.off;
3805 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003806 if (enc_utf8)
3807 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003808 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003809 else
3810 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003812 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003814 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003815#endif
3816 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003818 // When "wlv.tocol" is halfway a character, set it to the end
3819 // of the character, otherwise highlighting won't stop.
3820 if (wlv.tocol == wlv.vcol)
3821 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003822
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003823 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003824
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003825#ifdef FEAT_RIGHTLEFT
3826 if (wp->w_p_rl)
3827 {
3828 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003829 --wlv.off;
3830 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831 }
3832#endif
3833 }
3834#ifdef FEAT_RIGHTLEFT
3835 if (wp->w_p_rl)
3836 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003837 --wlv.off;
3838 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 }
3840 else
3841#endif
3842 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003843 ++wlv.off;
3844 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 }
3846 }
3847#ifdef FEAT_CONCEAL
3848 else if (wp->w_p_cole > 0 && is_concealing)
3849 {
3850 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003851 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003852 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003853 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854 if (wp->w_p_wrap)
3855 {
3856 // Special voodoo required if 'wrap' is on.
3857 //
3858 // Advance the column indicator to force the line
3859 // drawing to wrap early. This will make the line
3860 // take up the same screen space when parts are concealed,
3861 // so that cursor line computations aren't messed up.
3862 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003863 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 // trailing junk to be written out of the screen line
3865 // we are building, 'boguscols' keeps track of the number
3866 // of bad columns we have advanced.
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;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870# ifdef FEAT_RIGHTLEFT
3871 if (wp->w_p_rl)
3872 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003873 wlv.col -= wlv.n_extra;
3874 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 }
3876 else
3877# endif
3878 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003879 wlv.col += wlv.n_extra;
3880 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003882 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003883 n_attr = 0;
3884 }
3885
3886
3887 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3888 {
3889 // Need to fill two screen columns.
3890# ifdef FEAT_RIGHTLEFT
3891 if (wp->w_p_rl)
3892 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003893 --wlv.boguscols;
3894 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895 }
3896 else
3897# endif
3898 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 ++wlv.boguscols;
3900 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003901 }
3902 }
3903
3904# ifdef FEAT_RIGHTLEFT
3905 if (wp->w_p_rl)
3906 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003907 --wlv.boguscols;
3908 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003909 }
3910 else
3911# endif
3912 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003913 ++wlv.boguscols;
3914 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 }
3916 }
3917 else
3918 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003919 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003920 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003921 wlv.vcol += wlv.n_extra;
3922 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923 n_attr = 0;
3924 }
3925 }
3926
3927 }
3928#endif // FEAT_CONCEAL
3929 else
3930 --n_skip;
3931
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003932 // Only advance the "wlv.vcol" when after the 'number' or
3933 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003934 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003936 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937#endif
3938 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003940
3941#ifdef FEAT_SYN_HL
3942 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003943 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944#endif
3945
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003946 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003947 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3948 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003949
3950 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003951 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003952 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003953 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003954 if (wlv.n_attr_skip > 0)
3955 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956
3957 // At end of screen line and there is more to come: Display the line
3958 // so far. If there is no more to display it is caught above.
3959 if ((
3960#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003961 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003963 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003964 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003965 || *ptr != NUL
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
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003969#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003970 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003971#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003972 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003973 && wlv.p_extra != at_end_str)
3974 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3975 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 )
3977 {
3978#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003979 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003980 wlv_screen_line(wp, &wlv, FALSE);
3981 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003982 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003983 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003985 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003986#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003987 ++wlv.row;
3988 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989
3990 // When not wrapping and finished diff lines, or when displayed
3991 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003992 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003994 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003995#endif
3996#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003997 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003998#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003999 ) || lcs_eol_one == -1)
4000#ifdef FEAT_PROP_POPUP
4001 && !text_prop_follows
4002#endif
4003 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004004 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004005#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004006 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004007 {
4008 // do not output more of the line, only the "below" prop
4009 ptr += STRLEN(ptr);
4010# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004011 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004012# endif
4013 }
4014#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004015
4016 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004017 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004018#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004019 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020#endif
4021 )
4022 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004023 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4024 draw_vsep_win(wp, wlv.row);
4025 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026 }
4027
4028 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004029 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004030 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004031 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004032 break;
4033 }
4034
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004035 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004037 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004038#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004039#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004040 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004041#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004042 && wp->w_width == Columns)
4043 {
4044 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004045 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046
4047 // Special trick to make copy/paste of wrapped lines work with
4048 // xterm/screen: write an extra character beyond the end of
4049 // the line. This will work with all terminal types
4050 // (regardless of the xn,am settings).
4051 // Only do this on a fast tty.
4052 // Only do this if the cursor is on the current line
4053 // (something has been written in it).
4054 // Don't do this for the GUI.
4055 // Don't do this for double-width characters.
4056 // Don't do this for a window not at the right screen border.
4057 if (p_tf
4058#ifdef FEAT_GUI
4059 && !gui.in_use
4060#endif
4061 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004062 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4063 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004064 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004065 || (*mb_off2cells)(
4066 LineOffset[wlv.screen_row - 1]
4067 + (int)Columns - 2,
4068 LineOffset[wlv.screen_row]
4069 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004070 {
4071 // First make sure we are at the end of the screen line,
4072 // then output the same character again to let the
4073 // terminal know about the wrap. If the terminal doesn't
4074 // auto-wrap, we overwrite the character.
4075 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004076 screen_char(LineOffset[wlv.screen_row - 1]
4077 + (unsigned)Columns - 1,
4078 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004079
4080 // When there is a multi-byte character, just output a
4081 // space to keep it simple.
4082 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004084 out_char(' ');
4085 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004086 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087 + (Columns - 1)]);
4088 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004089 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090 screen_start(); // don't know where cursor is now
4091 }
4092 }
4093
Bram Moolenaar1306b362022-08-06 15:59:06 +01004094 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004095
Bram Moolenaareed9d462021-02-15 20:38:25 +01004096 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004098 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004100 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004102 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004103 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104#endif
4105#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004106 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004107 // When the filler lines are actually below the last line of the
4108 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004109 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110 break;
4111#endif
4112 }
4113
4114 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004115#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004116 vim_free(text_props);
4117 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004118 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004119#endif
4120
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004121 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004122 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004123}