blob: 848b3ae89200a020c2aa2c2279dfbd66f26ca25f [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;
zeertzjq58e1e012023-06-04 18:46:28 +0100153 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000154 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000155 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000156 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100157 int saved_c_extra;
158 int saved_c_final;
159 int saved_char_attr;
160
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100161 char_u extra[NUMBUFLEN + MB_MAXBYTES];
162 // "%ld " and 'fdc' must fit in here, as well
163 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100164
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_DIFF
166 hlf_T diff_hlf; // type of diff highlighting
167#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100168 int filler_lines; // nr of filler lines to be drawn
169 int filler_todo; // nr of filler lines still to do + 1
170#ifdef FEAT_SIGNS
171 sign_attrs_T sattr;
172#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100173} winlinevars_T;
174
175// draw_state values for items that are drawn in sequence:
176#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100177#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100178#ifdef FEAT_FOLDING
179# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
180#else
181# define WL_FOLD WL_CMDLINE
182#endif
183#ifdef FEAT_SIGNS
184# define WL_SIGN (WL_FOLD + 1) // column for signs
185#else
186# define WL_SIGN WL_FOLD // column for signs
187#endif
188#define WL_NR (WL_SIGN + 1) // line number
189#ifdef FEAT_LINEBREAK
190# define WL_BRI (WL_NR + 1) // 'breakindent'
191#else
192# define WL_BRI WL_NR
193#endif
194#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
195# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
196#else
197# define WL_SBR WL_BRI
198#endif
199#define WL_LINE (WL_SBR + 1) // text in the line
200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200202/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000203 * Return TRUE if CursorLineSign highlight is to be used.
204 */
205 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100206use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000207{
208 return wp->w_p_cul
209 && lnum == wp->w_cursor.lnum
210 && (wp->w_p_culopt_flags & CULOPT_NBR);
211}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100214
215#ifdef FEAT_FOLDING
216/*
217 * Setup for drawing the 'foldcolumn', if there is one.
218 */
219 static void
220handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
221{
222 int fdc = compute_foldcolumn(wp, 0);
223
224 if (fdc <= 0)
225 return;
226
227 // Allocate a buffer, "wlv->extra[]" may already be in use.
228 vim_free(wlv->p_extra_free);
229 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000230 if (wlv->p_extra_free == NULL)
231 return;
232
233 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100234 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000235 wlv->p_extra_free[wlv->n_extra] = NUL;
236 wlv->p_extra = wlv->p_extra_free;
237 wlv->c_extra = NUL;
238 wlv->c_final = NUL;
239 if (use_cursor_line_highlight(wp, wlv->lnum))
240 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
241 else
242 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100243}
244#endif
245
246#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000247/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100248 * Get information needed to display the sign in line "wlv->lnum" in window
249 * "wp".
250 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200251 * Otherwise the sign is going to be displayed in the sign column.
252 */
253 static void
254get_sign_display_info(
255 int nrcol,
256 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100257 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200258{
259 int text_sign;
260# ifdef FEAT_SIGN_ICONS
261 int icon_sign;
262# endif
263
264 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 wlv->c_extra = ' ';
266 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200267 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100268 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 else
270 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100271 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100272 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100274 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100275 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276 }
277
Bram Moolenaar1306b362022-08-06 15:59:06 +0100278 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200279#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281#endif
282 )
283 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100284 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287 if (gui.in_use && icon_sign != 0)
288 {
289 // Use the image in this position.
290 if (nrcol)
291 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100292 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100293 sprintf((char *)wlv->extra, "%-*c ",
294 number_width(wp), SIGN_BYTE);
295 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100296 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200297 }
298 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100299 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100301 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
302 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 {
304 if (nrcol)
305 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200308 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100309 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100310 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 }
312 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100313 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 }
315# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->c_final = NUL;
317 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 }
319 else
320# endif
321 if (text_sign != 0)
322 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100323 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200325 {
326 if (nrcol)
327 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100328 int width = number_width(wp) - 2;
329 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330
331 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100332 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100333 vim_snprintf((char *)wlv->extra + n,
334 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100335 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100337 wlv->c_extra = NUL;
338 wlv->c_final = NUL;
339 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200340 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000341
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100342 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100343 && wlv->sattr.sat_culhl > 0)
344 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000345 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100346 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347 }
348 }
349}
350#endif
351
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352/*
353 * Display the absolute or relative line number. After the first row fill with
354 * blanks when the 'n' flag isn't in 'cpo'.
355 */
356 static void
357handle_lnum_col(
358 win_T *wp,
359 winlinevars_T *wlv,
360 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100361 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100362{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100363 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100364 int lnum_row = wlv->startrow + wlv->filler_lines
365#ifdef FEAT_PROP_POPUP
366 + wlv->text_prop_above_count
367#endif
368 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369
Bram Moolenaard7657e92022-09-20 18:59:30 +0100370 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100371 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100372 // there is no line number in a wrapped line when "n" is in
373 // 'cpoptions', but 'breakindent' assumes it anyway.
374 && !((has_cpo_n
375#ifdef FEAT_LINEBREAK
376 && !wp->w_p_bri
377#endif
378 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100379 {
380#ifdef FEAT_SIGNS
381 // If 'signcolumn' is set to 'number' and a sign is present
382 // in 'lnum', then display the sign instead of the line
383 // number.
384 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
385 get_sign_display_info(TRUE, wp, wlv);
386 else
387#endif
388 {
389 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100390 // When there are text properties above the line put the line number
391 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100392 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100393 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100394 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100395 {
396 long num;
397 char *fmt = "%*ld ";
398
399 if (wp->w_p_nu && !wp->w_p_rnu)
400 // 'number' + 'norelativenumber'
401 num = (long)wlv->lnum;
402 else
403 {
404 // 'relativenumber', don't use negative numbers
405 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
406 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
407 {
408 // 'number' + 'relativenumber'
409 num = wlv->lnum;
410 fmt = "%-*ld ";
411 }
412 }
413
414 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100415 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100416 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
417 ++wlv->p_extra)
418 *wlv->p_extra = '-';
419#ifdef FEAT_RIGHTLEFT
420 if (wp->w_p_rl) // reverse line numbers
421 {
422 char_u *p1, *p2;
423 int t;
424
425 // like rl_mirror(), but keep the space at the end
426 p2 = skipwhite(wlv->extra);
427 p2 = skiptowhite(p2) - 1;
428 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
429 {
430 t = *p1;
431 *p1 = *p2;
432 *p2 = t;
433 }
434 }
435#endif
436 wlv->p_extra = wlv->extra;
437 wlv->c_extra = NUL;
438 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100439 }
440 else
441 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100442 wlv->c_extra = ' ';
443 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100444 }
445 wlv->n_extra = number_width(wp) + 1;
446 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
447#ifdef FEAT_SYN_HL
448 // When 'cursorline' is set highlight the line number of
449 // the current line differently.
450 // When 'cursorlineopt' does not have "line" only
451 // highlight the line number itself.
452 // TODO: Can we use CursorLine instead of CursorLineNr
453 // when CursorLineNr isn't set?
454 if (wp->w_p_cul
455 && wlv->lnum == wp->w_cursor.lnum
456 && (wp->w_p_culopt_flags & CULOPT_NBR)
457 && (wlv->row == wlv->startrow + wlv->filler_lines
458 || (wlv->row > wlv->startrow + wlv->filler_lines
459 && (wp->w_p_culopt_flags & CULOPT_LINE))))
460 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
461#endif
462 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
463 && HL_ATTR(HLF_LNA) != 0)
464 // Use LineNrAbove
465 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
466 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
467 && HL_ATTR(HLF_LNB) != 0)
468 // Use LineNrBelow
469 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
470 }
471#ifdef FEAT_SIGNS
472 if (num_attr)
473 wlv->char_attr = num_attr;
474#endif
475 }
476}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100477
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100478#ifdef FEAT_LINEBREAK
479 static void
480handle_breakindent(win_T *wp, winlinevars_T *wlv)
481{
482 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100483 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484 // draw indent after showbreak value
485 wlv->draw_state = WL_BRI;
486 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
487 // After the showbreak, draw the breakindent
488 wlv->draw_state = WL_BRI - 1;
489
490 // draw 'breakindent': indent wrapped text accordingly
491 if (wlv->draw_state == WL_BRI - 1)
492 {
493 wlv->draw_state = WL_BRI;
494 // if wlv->need_showbreak is set, breakindent also applies
495 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
496# ifdef FEAT_DIFF
497 && wlv->filler_lines == 0
498# endif
499# ifdef FEAT_PROP_POPUP
500 && !wlv->dont_use_showbreak
501# endif
502 )
503 {
504 wlv->char_attr = 0;
505# ifdef FEAT_DIFF
506 if (wlv->diff_hlf != (hlf_T)0)
507 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
508# endif
509 wlv->p_extra = NULL;
510 wlv->c_extra = ' ';
511 wlv->c_final = NUL;
512 wlv->n_extra = get_breakindent_win(wp,
513 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
514 if (wlv->row == wlv->startrow)
515 {
516 wlv->n_extra -= win_col_off2(wp);
517 if (wlv->n_extra < 0)
518 wlv->n_extra = 0;
519 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100520 if (wp->w_skipcol > 0 && wlv->startrow == 0
521 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100522 wlv->need_showbreak = FALSE;
523 // Correct end of highlighted area for 'breakindent',
524 // required when 'linebreak' is also set.
525 if (wlv->tocol == wlv->vcol)
526 wlv->tocol += wlv->n_extra;
527 }
528 }
529}
530#endif
531
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100532#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
533 static void
534handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
535{
536# ifdef FEAT_DIFF
537 if (wlv->filler_todo > 0)
538 {
539 // Draw "deleted" diff line(s).
540 if (char2cells(wp->w_fill_chars.diff) > 1)
541 {
542 wlv->c_extra = '-';
543 wlv->c_final = NUL;
544 }
545 else
546 {
547 wlv->c_extra = wp->w_fill_chars.diff;
548 wlv->c_final = NUL;
549 }
550# ifdef FEAT_RIGHTLEFT
551 if (wp->w_p_rl)
552 wlv->n_extra = wlv->col + 1;
553 else
554# endif
555 wlv->n_extra = wp->w_width - wlv->col;
556 wlv->char_attr = HL_ATTR(HLF_DED);
557 }
558# endif
559
560# ifdef FEAT_LINEBREAK
561 char_u *sbr = get_showbreak_value(wp);
562 if (*sbr != NUL && wlv->need_showbreak)
563 {
564 // Draw 'showbreak' at the start of each broken line.
565 wlv->p_extra = sbr;
566 wlv->c_extra = NUL;
567 wlv->c_final = NUL;
568 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100569 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100570 wlv->need_showbreak = FALSE;
571 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
572 // Correct end of highlighted area for 'showbreak',
573 // required when 'linebreak' is also set.
574 if (wlv->tocol == wlv->vcol)
575 wlv->tocol += wlv->n_extra;
576 // combine 'showbreak' with 'wincolor'
577 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
578# ifdef FEAT_SYN_HL
579 // combine 'showbreak' with 'cursorline'
580 if (wlv->cul_attr != 0)
581 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
582# endif
583 }
584# endif
585}
586#endif
587
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100588#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100589/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 * Return the cell size of virtual text after truncation.
591 */
592 static int
593textprop_size_after_trunc(
594 win_T *wp,
595 int flags, // TP_FLAG_ALIGN_*
596 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100597 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100598 char_u *text,
599 int *n_used_ptr)
600{
601 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100602 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100603 int len = (int)STRLEN(text);
604 int strsize = 0;
605 int n_used;
606
Bram Moolenaar7e017462022-10-11 21:02:09 +0100607 // if the remaining size is to small and 'wrap' is set we wrap anyway and
608 // use the next line
609 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100610 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100611 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100612 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100613 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
614 {
615 int clen = ptr2cells(text + n_used);
616
617 if (strsize + clen > space)
618 break;
619 strsize += clen;
620 }
621 *n_used_ptr = n_used;
622 return strsize;
623}
624
625/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 * Take care of padding, right-align and truncation of virtual text after a
627 * line.
628 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
629 * padding, right-align and truncation. Otherwise only the size is computed.
630 * When "n_attr" is NULL returns the number of screen cells used.
631 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100632 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int
634text_prop_position(
635 win_T *wp,
636 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000637 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100638 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100639 int *n_extra, // nr of bytes for virtual text
640 char_u **p_extra, // virtual text
641 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000642 int *n_attr_skip, // cells to skip attr, NULL if not used
643 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200644{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100645 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100646 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000648 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100649 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000650 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100651 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100652 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100653 int before = room; // spaces before the text
654 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 int n_used = *n_extra;
656 char_u *l = NULL;
657 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100659 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100661 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100662 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100663 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100664
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100665 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100668 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100669 if (after < 0)
670 {
671 // text "above" has too much padding to fit
672 padding += after;
673 after = 0;
674 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100675 }
676 else
677 {
678 // Right-align: fill with before
679 if (right)
680 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000681
682 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000683 if (below && vcol == 0 && col_with_padding == col_off
684 && wp->w_width - col_off == before)
685 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000686
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100687 if (before < 0
688 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000689 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
690 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100691 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100692 if (right && (wrap
693 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100694 {
695 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 before = wp->w_width - col_off - strsize + room;
697 if (before < 0)
698 before = 0;
699 else
700 n_used = *n_extra;
701 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000702 else if (below && before > vcol && do_skip)
703 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100704 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100705 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100706 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100707 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100708
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100709 // With 'nowrap' add one to show the "extends" character if needed (it
710 // doesn't show if the text just fits).
711 if (!wp->w_p_wrap
712 && n_used < *n_extra
713 && wp->w_lcs_chars.ext != NUL
714 && wp->w_p_list)
715 ++n_used;
716
717 // add 1 for NUL, 2 for when '…' is used
718 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100720 if (n_attr == NULL || l != NULL)
721 {
722 int off = 0;
723
724 if (n_attr != NULL)
725 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 vim_memset(l, ' ', before);
727 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 if (padding > 0)
729 {
730 vim_memset(l + off, ' ', padding);
731 off += padding;
732 }
733 vim_strncpy(l + off, *p_extra, n_used);
734 off += n_used;
735 }
736 else
737 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100738 off = before + after + padding + n_used;
739 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100740 }
741 if (n_attr != NULL)
742 {
743 if (n_used < *n_extra && wp->w_p_wrap)
744 {
745 char_u *lp = l + off - 1;
746
747 if (has_mbyte)
748 {
h-east4c42c7e2023-04-17 21:44:57 +0100749 char_u buf[MB_MAXBYTES + 1];
750 char_u *cp = buf;
751
752 // change the last character to '…', converted to the
753 // current 'encoding'
754 STRCPY(buf, "…");
755 if (!enc_utf8)
756 {
757 vimconv_T vc;
758
759 vc.vc_type = CONV_NONE;
760 convert_setup(&vc, (char_u *)"utf-8", p_enc);
761 if (vc.vc_type != CONV_NONE)
762 {
763 cp = string_convert(&vc, buf, NULL);
764 if (cp == NULL)
765 {
766 // when conversion fails use '>'
767 cp = buf;
768 STRCPY(buf, ">");
769 }
770 convert_setup(&vc, NULL, NULL);
771 }
772 }
773
774 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100775 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100776 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100777 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100778 if (cp != buf)
779 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100780 }
781 else
782 // change last character to '>'
783 *lp = '>';
784 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100785 else if (after > 0)
786 {
787 vim_memset(l + off, ' ', after);
788 l[off + after] = NUL;
789 }
790
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100791 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100792 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100793 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100794 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100795 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100796
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000797 // n_attr_skip will not be decremented before draw_state is
798 // WL_LINE
799 *n_attr_skip = before + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100800 }
801 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100802 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100803
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100804 if (n_attr == NULL)
805 return cells;
806 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200807}
808#endif
809
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100810/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100811 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100812 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
813 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100814 */
815 static void
816wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
817{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100818 if (wlv->row == 0 && wp->w_skipcol > 0
819#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100820 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100821 && *get_showbreak_value(wp) == NUL
822#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100823 // do not overwrite the 'listchars' "precedes" text with "<<<"
824 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100825 {
826 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100827 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100828 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100829
Bram Moolenaareb4de622022-10-15 13:42:17 +0100830 if (wp->w_p_nu && wp->w_p_rnu)
831 // Do not overwrite the line number, change "123 text" to
832 // "123>>>xt".
833 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
834 {
835 ++off;
836 ++skip;
837 }
838
839 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100840 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100841 if ((*mb_off2cells)(off, max_off) > 1)
842 // When the first half of a double-width character is
843 // overwritten, change the second half to a space.
844 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100845 ScreenLines[off] = '<';
846 if (enc_utf8)
847 ScreenLinesUC[off] = 0;
848 ScreenAttrs[off] = HL_ATTR(HLF_AT);
849 ++off;
850 }
851 }
852
853 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
854 negative_width ? -wp->w_width : wp->w_width,
855 wlv->screen_line_flags);
856}
857
858/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100859 * Called when finished with the line: draw the screen line and handle any
860 * highlighting until the right of the window.
861 */
862 static void
863draw_screen_line(win_T *wp, winlinevars_T *wlv)
864{
865#ifdef FEAT_SYN_HL
866 long v;
867
868 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
869 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100870 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100871 else
872 v = wp->w_leftcol;
873
874 // check if line ends before left margin
875 if (wlv->vcol < v + wlv->col - win_col_off(wp))
876 wlv->vcol = v + wlv->col - win_col_off(wp);
877# ifdef FEAT_CONCEAL
878 // Get rid of the boguscols now, we want to draw until the right
879 // edge for 'cursorcolumn'.
880 wlv->col -= wlv->boguscols;
881 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000882# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100883# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000884# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100885# endif
886
887 if (wlv->draw_color_col)
888 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
889
890 if (((wp->w_p_cuc
891 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
892 && (int)wp->w_virtcol <
893 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
894 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000895 || wlv->draw_color_col
896# ifdef LINE_ATTR
897 || wlv->line_attr != 0
898# endif
899 || wlv->win_attr != 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100900# ifdef FEAT_RIGHTLEFT
901 && !wp->w_p_rl
902# endif
903 )
904 {
905 int rightmost_vcol = 0;
906 int i;
907
908 if (wp->w_p_cuc)
909 rightmost_vcol = wp->w_virtcol;
910 if (wlv->draw_color_col)
911 // determine rightmost colorcolumn to possibly draw
912 for (i = 0; wlv->color_cols[i] >= 0; ++i)
913 if (rightmost_vcol < wlv->color_cols[i])
914 rightmost_vcol = wlv->color_cols[i];
915
916 while (wlv->col < wp->w_width)
917 {
918 ScreenLines[wlv->off] = ' ';
919 if (enc_utf8)
920 ScreenLinesUC[wlv->off] = 0;
921 ScreenCols[wlv->off] = MAXCOL;
922 ++wlv->col;
923 if (wlv->draw_color_col)
924 wlv->draw_color_col = advance_color_col(
925 VCOL_HLC, &wlv->color_cols);
926
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000927 int attr = wlv->win_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100928 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000929 attr = HL_ATTR(HLF_CUC);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100930 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000931 attr = HL_ATTR(HLF_MC);
932# ifdef LINE_ATTR
933 else if (wlv->line_attr != 0)
934 attr = wlv->line_attr;
935# endif
936 ScreenAttrs[wlv->off++] = attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100937
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000938 if (VCOL_HLC >= rightmost_vcol
939# ifdef LINE_ATTR
940 && wlv->line_attr == 0
941# endif
942 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100943 break;
944
945 ++wlv->vcol;
946 }
947 }
948#endif
949
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100950 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100951 ++wlv->row;
952 ++wlv->screen_row;
953}
954#undef VCOL_HLC
955
956/*
957 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100958 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100959 */
960 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100961win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100962{
963 wlv->col = 0;
964 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
965
966#ifdef FEAT_RIGHTLEFT
967 if (wp->w_p_rl)
968 {
969 // Rightleft window: process the text in the normal direction, but put
970 // it in current_ScreenLine[] from right to left. Start at the
971 // rightmost column of the window.
972 wlv->col = wp->w_width - 1;
973 wlv->off += wlv->col;
974 wlv->screen_line_flags |= SLF_RIGHTLEFT;
975 }
976#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100977 if (save_extra)
978 {
979 // reset the drawing state for the start of a wrapped line
980 wlv->draw_state = WL_START;
981 wlv->saved_n_extra = wlv->n_extra;
982 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100983 vim_free(wlv->saved_p_extra_free);
984 wlv->saved_p_extra_free = wlv->p_extra_free;
985 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000986 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000987 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000988 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100989 wlv->saved_c_extra = wlv->c_extra;
990 wlv->saved_c_final = wlv->c_final;
991#ifdef FEAT_SYN_HL
992 if (!(wlv->cul_screenline
993# ifdef FEAT_DIFF
994 && wlv->diff_hlf == (hlf_T)0
995# endif
996 ))
997 wlv->saved_char_attr = wlv->char_attr;
998 else
999#endif
1000 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001001
1002 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001003 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001004 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001006}
1007
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001008/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001009 * Called when wlv->draw_state is set to WL_LINE.
1010 */
1011 static void
1012win_line_continue(winlinevars_T *wlv)
1013{
1014 if (wlv->saved_n_extra > 0)
1015 {
1016 // Continue item from end of wrapped line.
1017 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001018 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001019 wlv->c_extra = wlv->saved_c_extra;
1020 wlv->c_final = wlv->saved_c_final;
1021 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001022 vim_free(wlv->p_extra_free);
1023 wlv->p_extra_free = wlv->saved_p_extra_free;
1024 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001025 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001026 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001027 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001028 wlv->char_attr = wlv->saved_char_attr;
1029 }
1030 else
1031 wlv->char_attr = wlv->win_attr;
1032}
1033
zeertzjqb7acea12022-12-12 13:20:43 +00001034#ifdef FEAT_SYN_HL
1035 static void
1036apply_cursorline_highlight(
1037 winlinevars_T *wlv,
1038 int sign_present UNUSED)
1039{
1040 wlv->cul_attr = HL_ATTR(HLF_CUL);
1041# ifdef FEAT_SIGNS
1042 // Combine the 'cursorline' and sign highlighting, depending on
1043 // the sign priority.
1044 if (sign_present && wlv->sattr.sat_linehl > 0)
1045 {
1046 if (wlv->sattr.sat_priority >= 100)
1047 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1048 else
1049 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1050 }
1051 else
1052# endif
1053# if defined(FEAT_QUICKFIX)
1054 // let the line attribute overrule 'cursorline', otherwise
1055 // it disappears when both have background set;
1056 // 'cursorline' can use underline or bold to make it show
1057 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1058# else
1059 wlv->line_attr = wlv->cul_attr;
1060# endif
1061}
1062#endif
1063
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001064/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001065 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 * Start at row "startrow", stop when "endrow" is reached.
Luuk van Baal30805a12023-05-27 22:22:10 +01001067 * When "number_only" is TRUE only update the number column.
1068 * "spv" is used to store information for spell checking, kept between
1069 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001070 * wp->w_virtcol needs to be valid.
1071 *
1072 * Return the number of last row the line occupies.
1073 */
1074 int
1075win_line(
1076 win_T *wp,
1077 linenr_T lnum,
1078 int startrow,
1079 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001080 int number_only,
1081 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001083 winlinevars_T wlv; // variables passed between functions
1084
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001085 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001086 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 char_u *line; // current line
1088 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089
Bram Moolenaar1306b362022-08-06 15:59:06 +01001090#ifdef FEAT_PROP_POPUP
1091 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1092#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001093#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001094 int in_linebreak = FALSE; // n_extra set for showing linebreak
1095#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001096 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +01001097 // displaying eol at end-of-line
1098 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001099 int lcs_prec_todo = wp->w_lcs_chars.prec;
1100 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001102 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001103 int saved_attr2 = 0; // char_attr saved for n_attr
1104 int n_attr3 = 0; // chars with overruling special attr
1105 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001106
Bram Moolenaarcd105412022-10-10 19:50:42 +01001107 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1108 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001109#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001110 int skip_cells = 0; // nr of cells to skip for virtual text
1111 // after the line, when w_skipcol is
1112 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001113#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001114
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001115 int fromcol_prev = -2; // start of inverting after cursor
1116 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 int lnum_in_visual_area = FALSE;
1118 pos_T pos;
1119 long v;
1120
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 int attr_pri = FALSE; // char_attr has priority
1122 int area_highlighting = FALSE; // Visual or incsearch highlighting
1123 // in this line
1124 int vi_attr = 0; // attributes for Visual and incsearch
1125 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 int area_attr = 0; // attributes desired by highlighting
1127 int search_attr = 0; // attributes desired by 'hlsearch'
1128#ifdef FEAT_SYN_HL
1129 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1130 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001131 int prev_syntax_col = -1; // column of prev_syntax_attr
1132 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133 int has_syntax = FALSE; // this buffer has syntax highl.
1134 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001136#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001137 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 int text_prop_count;
1139 int text_prop_next = 0; // next text property to use
1140 textprop_T *text_props = NULL;
1141 int *text_prop_idxs = NULL;
1142 int text_props_active = 0;
1143 proptype_T *text_prop_type = NULL;
1144 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001145 int text_prop_attr_comb = 0; // text_prop_attr combined with
1146 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001147 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001148 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001149 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001150 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001151 int saved_search_attr = 0; // search_attr to be used when n_extra
1152 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001153 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001154 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155#endif
1156#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001157 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158# define SPWORDLEN 150
1159 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1160 int nextlinecol = 0; // column where nextline[] starts
1161 int nextline_idx = 0; // index in nextline[] where next line
1162 // starts
1163 int spell_attr = 0; // attributes desired by spelling
1164 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 int cur_checked_col = 0; // checked column for current line
1166#endif
1167 int extra_check = 0; // has extra highlighting
1168 int multi_attr = 0; // attributes desired by multibyte
1169 int mb_l = 1; // multi-byte byte length
1170 int mb_c = 0; // decoded multi-byte character
1171 int mb_utf8 = FALSE; // screen char is UTF-8 char
1172 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 int change_start = MAXCOL; // first col of changed area
1175 int change_end = -1; // last col of changed area
1176#endif
1177 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001178 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001179 int in_multispace = FALSE; // in multiple consecutive spaces
1180 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001181#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001182 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001185 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001186#ifdef FEAT_ARABIC
1187 int prev_c = 0; // previous Arabic character
1188 int prev_c1 = 0; // first composing char for prev_c
1189#endif
1190#if defined(LINE_ATTR)
1191 int did_line_attr = 0;
1192#endif
1193#ifdef FEAT_TERMINAL
1194 int get_term_attr = FALSE;
1195#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196
Martin Tournoijba43e762022-10-13 22:12:15 +01001197#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 // margin columns for the screen line, needed for when 'cursorlineopt'
1199 // contains "screenline"
1200 int left_curline_col = 0;
1201 int right_curline_col = 0;
1202#endif
1203
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1205 int feedback_col = 0;
1206 int feedback_old_attr = -1;
1207#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208
1209#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1210 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001211#endif
1212#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001213 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214#endif
1215#ifdef FEAT_CONCEAL
1216 int syntax_flags = 0;
1217 int syntax_seqnr = 0;
1218 int prev_syntax_id = 0;
1219 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1220 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 int did_wcol = FALSE;
1222 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001223# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224# define FIX_FOR_BOGUSCOLS \
1225 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001226 wlv.n_extra += wlv.vcol_off_co; \
1227 wlv.vcol -= wlv.vcol_off_co; \
1228 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001229 wlv.col -= wlv.boguscols; \
1230 old_boguscols = wlv.boguscols; \
1231 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232 }
1233#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001234# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001235#endif
1236
1237 if (startrow > endrow) // past the end already!
1238 return startrow;
1239
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001240 CLEAR_FIELD(wlv);
1241
1242 wlv.lnum = lnum;
1243 wlv.startrow = startrow;
1244 wlv.row = startrow;
1245 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001246 wlv.fromcol = -10;
1247 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001248#ifdef FEAT_LINEBREAK
1249 wlv.vcol_sbr = -1;
1250#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251
1252 if (!number_only)
1253 {
1254 // To speed up the loop below, set extra_check when there is linebreak,
1255 // trailing white space and/or syntax processing to be done.
1256#ifdef FEAT_LINEBREAK
1257 extra_check = wp->w_p_lbr;
1258#endif
1259#ifdef FEAT_SYN_HL
1260 if (syntax_present(wp) && !wp->w_s->b_syn_error
1261# ifdef SYN_TIME_LIMIT
1262 && !wp->w_s->b_syn_slow
1263# endif
1264 )
1265 {
1266 // Prepare for syntax highlighting in this line. When there is an
1267 // error, stop syntax highlighting.
1268 save_did_emsg = did_emsg;
1269 did_emsg = FALSE;
1270 syntax_start(wp, lnum);
1271 if (did_emsg)
1272 wp->w_s->b_syn_error = TRUE;
1273 else
1274 {
1275 did_emsg = save_did_emsg;
1276#ifdef SYN_TIME_LIMIT
1277 if (!wp->w_s->b_syn_slow)
1278#endif
1279 {
1280 has_syntax = TRUE;
1281 extra_check = TRUE;
1282 }
1283 }
1284 }
1285
1286 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001287 wlv.color_cols = wp->w_p_cc_cols;
1288 if (wlv.color_cols != NULL)
1289 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290#endif
1291
1292#ifdef FEAT_TERMINAL
1293 if (term_show_buffer(wp->w_buffer))
1294 {
1295 extra_check = TRUE;
1296 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001297 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 }
1299#endif
1300
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 // handle Visual active in this window
1302 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1303 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001304 pos_T *top, *bot;
1305
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1307 {
1308 // Visual is after curwin->w_cursor
1309 top = &curwin->w_cursor;
1310 bot = &VIsual;
1311 }
1312 else
1313 {
1314 // Visual is before curwin->w_cursor
1315 top = &VIsual;
1316 bot = &curwin->w_cursor;
1317 }
1318 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1319 if (VIsual_mode == Ctrl_V)
1320 {
1321 // block mode
1322 if (lnum_in_visual_area)
1323 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001324 wlv.fromcol = wp->w_old_cursor_fcol;
1325 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001326 }
1327 }
1328 else
1329 {
1330 // non-block mode
1331 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001332 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 else if (lnum == top->lnum)
1334 {
1335 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001336 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001337 else
1338 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001339 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001341 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 }
1343 }
1344 if (VIsual_mode != 'V' && lnum == bot->lnum)
1345 {
1346 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1347 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001348 wlv.fromcol = -10;
1349 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 }
1351 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001352 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 else
1354 {
1355 pos = *bot;
1356 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001357 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1358 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 else
1360 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001361 getvvcol(wp, &pos, NULL, NULL,
1362 (colnr_T *)&wlv.tocol);
1363 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001364 }
1365 }
1366 }
1367 }
1368
1369 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001370 if (!highlight_match && lnum == curwin->w_cursor.lnum
1371 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372#ifdef FEAT_GUI
1373 && !gui.in_use
1374#endif
1375 )
1376 noinvcur = TRUE;
1377
1378 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001379 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001380 {
1381 area_highlighting = TRUE;
1382 vi_attr = HL_ATTR(HLF_V);
1383#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1384 if ((clip_star.available && !clip_star.owned
1385 && clip_isautosel_star())
1386 || (clip_plus.available && !clip_plus.owned
1387 && clip_isautosel_plus()))
1388 vi_attr = HL_ATTR(HLF_VNC);
1389#endif
1390 }
1391 }
1392
1393 // handle 'incsearch' and ":s///c" highlighting
1394 else if (highlight_match
1395 && wp == curwin
1396 && lnum >= curwin->w_cursor.lnum
1397 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1398 {
1399 if (lnum == curwin->w_cursor.lnum)
1400 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001401 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001402 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001404 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1405 {
1406 pos.lnum = lnum;
1407 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001408 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 }
1410 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001411 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001412 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001413 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1414 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 area_highlighting = TRUE;
1416 vi_attr = HL_ATTR(HLF_I);
1417 }
1418 }
1419
1420#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001421 wlv.filler_lines = diff_check(wp, lnum);
1422 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001424 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 {
1426 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001427 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001429 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001430 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
1433 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001434 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001435 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 area_highlighting = TRUE;
1437 }
1438 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001439 wlv.filler_lines = wp->w_topfill;
1440 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001441#endif
1442
1443#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001444 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001445 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001446 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001447#endif
1448
1449#ifdef LINE_ATTR
1450# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001451 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001452 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001453 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454# endif
1455# if defined(FEAT_QUICKFIX)
1456 // Highlight the current line in the quickfix window.
1457 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001458 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001459# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001460 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 area_highlighting = TRUE;
1462#endif
1463
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464#ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01001465 if (spv->spv_has_spell && !number_only)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001467 // Prepare for spell checking.
1468 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469
Luuk van Baal30805a12023-05-27 22:22:10 +01001470 // When a word wrapped from the previous line the start of the
1471 // current line is valid.
1472 if (lnum == spv->spv_checked_lnum)
1473 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001474 // Previous line was not spell checked, check for capital. This happens
1475 // for the first line in an updated region or after a closed fold.
1476 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1477 spv->spv_cap_col = 0;
1478 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001479 spv->spv_cap_col = -1;
1480 spv->spv_checked_lnum = 0;
1481
Luuk van Baal30805a12023-05-27 22:22:10 +01001482 // Get the start of the next line, so that words that wrap to the
1483 // next line are found too: "et<line-break>al.".
1484 // Trick: skip a few chars for C/shell/Vim comments
1485 nextline[SPWORDLEN] = NUL;
1486 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001487 {
1488 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1489 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1490 }
1491 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1492
1493 // If current line is empty, check first word in next line for capital.
1494 ptr = skipwhite(line);
1495 if (*ptr == NUL)
1496 {
1497 spv->spv_cap_col = 0;
1498 spv->spv_capcol_lnum = lnum + 1;
1499 }
1500 // For checking first word with a capital skip white space.
1501 else if (spv->spv_cap_col == 0)
1502 spv->spv_cap_col = ptr - line;
1503
Luuk van Baal30805a12023-05-27 22:22:10 +01001504 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505 if (nextline[SPWORDLEN] == NUL)
1506 {
1507 // No next line or it is empty.
1508 nextlinecol = MAXCOL;
1509 nextline_idx = 0;
1510 }
1511 else
1512 {
1513 v = (long)STRLEN(line);
1514 if (v < SPWORDLEN)
1515 {
1516 // Short line, use it completely and append the start of the
1517 // next line.
1518 nextlinecol = 0;
1519 mch_memmove(nextline, line, (size_t)v);
1520 STRMOVE(nextline + v, nextline + SPWORDLEN);
1521 nextline_idx = v + 1;
1522 }
1523 else
1524 {
1525 // Long line, use only the last SPWORDLEN bytes.
1526 nextlinecol = v - SPWORDLEN;
1527 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1528 nextline_idx = SPWORDLEN + 1;
1529 }
1530 }
1531 }
1532#endif
1533
Luuk van Baale84c7732023-05-31 18:57:36 +01001534 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1535 ptr = line;
1536
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 if (wp->w_p_list)
1538 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001539 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001540 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001541 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001542 || wp->w_lcs_chars.trail
1543 || wp->w_lcs_chars.lead
1544 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001546
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001548 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
1550 trailcol = (colnr_T)STRLEN(ptr);
1551 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1552 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001553 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001555 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001556 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001557 {
1558 leadcol = 0;
1559 while (VIM_ISWHITE(ptr[leadcol]))
1560 ++leadcol;
1561 if (ptr[leadcol] == NUL)
1562 // in a line full of spaces all of them are treated as trailing
1563 leadcol = (colnr_T)0;
1564 else
1565 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001566 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001567 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 }
1569
Bram Moolenaard7657e92022-09-20 18:59:30 +01001570 wlv.wcr_attr = get_wcr_attr(wp);
1571 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001573 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001574 area_highlighting = TRUE;
1575 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001576
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001577 // When w_skipcol is non-zero and there is virtual text above the actual
1578 // text, then this much of the virtual text is skipped.
1579 int skipcol_in_text_prop_above = 0;
1580
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001581#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001582 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001583 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001584
1585 char_u *prop_start;
1586 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1587 if (text_prop_count > 0)
1588 {
1589 // Make a copy of the properties, so that they are properly
1590 // aligned.
1591 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1592 if (text_props != NULL)
1593 mch_memmove(text_props, prop_start,
1594 text_prop_count * sizeof(textprop_T));
1595
1596 // Allocate an array for the indexes.
1597 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1598 if (text_prop_idxs == NULL)
1599 VIM_CLEAR(text_props);
1600
1601 if (text_props != NULL)
1602 {
1603 area_highlighting = TRUE;
1604 extra_check = TRUE;
1605
1606 // When skipping virtual text the props need to be sorted. The
1607 // order is reversed!
1608 if (lnum == wp->w_topline && wp->w_skipcol > 0)
1609 {
1610 for (int i = 0; i < text_prop_count; ++i)
1611 text_prop_idxs[i] = i;
1612 sort_text_props(wp->w_buffer, text_props,
1613 text_prop_idxs, text_prop_count);
1614 }
1615
1616 // Text props "above" move the line number down to where the text
1617 // is. Only count the ones that are visible, not those that are
1618 // skipped because of w_skipcol.
1619 int text_width = wp->w_width - win_col_off(wp);
1620 for (int i = text_prop_count - 1; i >= 0; --i)
1621 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1622 {
1623 if (lnum == wp->w_topline
1624 && wp->w_skipcol - skipcol_in_text_prop_above
1625 >= text_width)
1626 {
1627 // This virtual text above is skipped, remove it from
1628 // the array.
1629 skipcol_in_text_prop_above += text_width;
1630 for (int j = i + 1; j < text_prop_count; ++j)
1631 text_props[j - 1] = text_props[j];
1632 ++i;
1633 --text_prop_count;
1634 }
1635 else
1636 ++wlv.text_prop_above_count;
1637 }
1638 }
1639 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001640
1641 if (number_only)
1642 {
1643 // skip over rows only used for virtual text above
1644 wlv.row += wlv.text_prop_above_count;
1645 if (wlv.row > endrow)
1646 return wlv.row;
1647 wlv.screen_row += wlv.text_prop_above_count;
1648 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649#endif
1650
1651 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1652 // first character to be displayed.
1653 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001654 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001655 else
1656 v = wp->w_leftcol;
1657 if (v > 0 && !number_only)
1658 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001659 char_u *prev_ptr = ptr;
1660 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001661 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001662
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001663 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001664 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001666 charsize = win_lbr_chartabsize(&cts, NULL);
1667 cts.cts_vcol += charsize;
1668 prev_ptr = cts.cts_ptr;
1669 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001671 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001672 ptr = cts.cts_ptr;
1673 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674
1675 // When:
1676 // - 'cuc' is set, or
1677 // - 'colorcolumn' is set, or
1678 // - 'virtualedit' is set, or
1679 // - the visual mode is active,
1680 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001681 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001683 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684#endif
1685 virtual_active() ||
1686 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001687 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001688
1689 // Handle a character that's not completely on the screen: Put ptr at
1690 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001691 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001693 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 ptr = prev_ptr;
1695 // If the character fits on the screen, don't need to skip it.
1696 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001697 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1698 && wlv.col == 0)
1699 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001700 }
1701
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001702#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001703 // If there the text doesn't reach to the desired column, need to skip
1704 // "skip_cells" cells when virtual text follows.
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001705 if ((!wp->w_p_wrap || (lnum == wp->w_topline && wp->w_skipcol > 0))
1706 && v > wlv.vcol)
Bram Moolenaarcd105412022-10-10 19:50:42 +01001707 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001708#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001709
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 // Adjust for when the inverted text is before the screen,
1711 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001712 if (wlv.tocol <= wlv.vcol)
1713 wlv.fromcol = 0;
1714 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1715 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716
1717#ifdef FEAT_LINEBREAK
1718 // When w_skipcol is non-zero, first line needs 'showbreak'
1719 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001720 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721#endif
1722#ifdef FEAT_SPELL
1723 // When spell checking a word we need to figure out the start of the
1724 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001725 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 {
1727 int len;
1728 colnr_T linecol = (colnr_T)(ptr - line);
1729 hlf_T spell_hlf = HLF_COUNT;
1730
1731 pos = wp->w_cursor;
1732 wp->w_cursor.lnum = lnum;
1733 wp->w_cursor.col = linecol;
1734 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1735
1736 // spell_move_to() may call ml_get() and make "line" invalid
1737 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1738 ptr = line + linecol;
1739
1740 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1741 {
1742 // no bad word found at line start, don't check until end of a
1743 // word
1744 spell_hlf = HLF_COUNT;
1745 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1746 }
1747 else
1748 {
1749 // bad word found, use attributes until end of word
1750 word_end = wp->w_cursor.col + len + 1;
1751
1752 // Turn index into actual attributes.
1753 if (spell_hlf != HLF_COUNT)
1754 spell_attr = highlight_attr[spell_hlf];
1755 }
1756 wp->w_cursor = pos;
1757
1758# ifdef FEAT_SYN_HL
1759 // Need to restart syntax highlighting for this line.
1760 if (has_syntax)
1761 syntax_start(wp, lnum);
1762# endif
1763 }
1764#endif
1765 }
1766
1767 // Correct highlighting for cursor that can't be disabled.
1768 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001769 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
1771 if (noinvcur)
1772 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 {
1775 // highlighting starts at cursor, let it start just after the
1776 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001777 fromcol_prev = wlv.fromcol;
1778 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001780 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781 // restart highlighting after the cursor
1782 fromcol_prev = wp->w_virtcol;
1783 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001784 if (wlv.fromcol >= wlv.tocol)
1785 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 }
1787
1788#ifdef FEAT_SEARCH_EXTRA
1789 if (!number_only)
1790 {
1791 v = (long)(ptr - line);
1792 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1793 &line, &screen_search_hl,
1794 &search_attr);
1795 ptr = line + v; // "line" may have been updated
1796 }
1797#endif
1798
1799#ifdef FEAT_SYN_HL
1800 // Cursor line highlighting for 'cursorline' in the current window.
1801 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1802 {
1803 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001804 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 if (!(wp == curwin && VIsual_active)
1806 && wp->w_p_culopt_flags != CULOPT_NBR)
1807 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001808 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1810
zeertzjqb7acea12022-12-12 13:20:43 +00001811 // Only apply CursorLine highlight here when "screenline" is not
1812 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001813 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001814 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 else
1816 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001817 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001818 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1819 }
1820 area_highlighting = TRUE;
1821 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 }
1823#endif
1824
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001826
1827 // Repeat for the whole displayed line.
1828 for (;;)
1829 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001830 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001832 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833#endif
1834#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001835 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001839 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001841#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001842 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001843 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001844 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001845 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001846 }
1847#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001848 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851 if (cmdwin_type != 0 && wp == curwin)
1852 {
1853 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001854 wlv.n_extra = 1;
1855 wlv.c_extra = cmdwin_type;
1856 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001857 wlv.char_attr =
1858 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 }
1860 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001862 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001864 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001865 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001866 }
1867#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001868#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001869 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001870 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001871 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001872 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001873 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001874 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 }
1876#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001877 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001879 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001880 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001881 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001882 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001883#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001884 // Check if 'breakindent' applies and show it.
1885 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1886 if (wlv.n_extra == 0)
1887 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001890 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001893 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 }
1895#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001896 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001897 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001898 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001899 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 }
1901 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001902
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001905 && wlv.vcol >= left_curline_col
1906 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 {
zeertzjqb7acea12022-12-12 13:20:43 +00001908 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909 }
1910#endif
1911
1912 // When still displaying '$' of change command, stop at cursor.
1913 // When only displaying the (relative) line number and that's done,
1914 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001915 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001916 && lnum == wp->w_cursor.lnum
1917 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001918 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001920 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921#endif
1922 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001924 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001925 // Pretend we have finished updating the window. Except when
1926 // 'cursorcolumn' is set.
1927#ifdef FEAT_SYN_HL
1928 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001929 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930 else
1931#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001932 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933 break;
1934 }
1935
Bram Moolenaar1306b362022-08-06 15:59:06 +01001936 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 {
1938 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001939 if (wlv.vcol == wlv.fromcol
1940 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1941 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 && (*mb_ptr2cells)(ptr) > 1)
1943 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001944 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001945 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001946 area_attr = vi_attr; // start highlighting
1947 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001948 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001949 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 area_attr = 0; // stop highlighting
1951
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001952#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 if (text_props != NULL)
1954 {
1955 int pi;
1956 int bcol = (int)(ptr - line);
1957
Bram Moolenaar1306b362022-08-06 15:59:06 +01001958 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001959# ifdef FEAT_LINEBREAK
1960 && !in_linebreak
1961# endif
1962 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 --bcol; // still working on the previous char, e.g. Tab
1964
1965 // Check if any active property ends.
1966 for (pi = 0; pi < text_props_active; ++pi)
1967 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001968 int tpi = text_prop_idxs[pi];
1969 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001970
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001971 // An inline property ends when after the start column plus
1972 // length. An "above" property ends when used and n_extra
1973 // is zero.
1974 if ((tp->tp_col != MAXCOL
1975 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 {
1977 if (pi + 1 < text_props_active)
1978 mch_memmove(text_prop_idxs + pi,
1979 text_prop_idxs + pi + 1,
1980 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001981 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 --text_props_active;
1983 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001984# ifdef FEAT_LINEBREAK
1985 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001986 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001987 syntax_attr = 0;
1988# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989 }
1990 }
1991
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001992# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001993 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001994 // not on the next char yet, don't start another prop
1995 --bcol;
1996# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001997 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001998
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001999 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002000 // With 'nowrap' and not in the first screen line only "below"
2001 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002003 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002004 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002005 && (wp->w_p_wrap
2006 || wlv.row == startrow
2007 || (text_props[text_prop_next].tp_flags
2008 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002009 || (bcol == 0
2010 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002011 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002012 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002013 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002014 if (text_props[text_prop_next].tp_col == MAXCOL
2015 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002016 + text_props[text_prop_next].tp_len)
2017 text_prop_idxs[text_props_active++] = text_prop_next;
2018 ++text_prop_next;
2019 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002021 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002022 {
2023 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002024 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002025 text_prop_flags = 0;
2026 text_prop_type = NULL;
2027 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002028 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002029 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002030 if (text_props_active > 0 && wlv.n_extra == 0
2031 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002032 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002033 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002034 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002035 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002036
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002037 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002038 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002039
2040 // Sort the properties on priority and/or starting last.
2041 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002042 sort_text_props(wp->w_buffer, text_props,
2043 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044
2045 for (pi = 0; pi < text_props_active; ++pi)
2046 {
2047 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002048 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002049 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002050 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051
Bram Moolenaarcd105412022-10-10 19:50:42 +01002052 // Only use a text property that can be displayed.
2053 // Skip "after" properties when wrap is off and at the
2054 // end of the window.
2055 if (pt != NULL
2056 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2057 && tp->tp_id != -MAXCOL
2058 && !(tp->tp_id < 0
2059 && !wp->w_p_wrap
2060 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2061 | TP_FLAG_ALIGN_ABOVE
2062 | TP_FLAG_ALIGN_BELOW)) == 0
2063 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002064 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002065 if (tp->tp_col == MAXCOL
2066 && *ptr == NUL
2067 && ((wp->w_p_list && lcs_eol_one > 0
2068 && (tp->tp_flags
2069 & TP_FLAG_ALIGN_ABOVE) == 0)
2070 || (ptr == line
2071 && !did_line
2072 && (tp->tp_flags
2073 & TP_FLAG_ALIGN_BELOW))))
2074 {
2075 // skip this prop, first display the '$' after
2076 // the line or display an empty line
2077 text_prop_follows = TRUE;
2078 if (used_tpi < 0)
2079 display_text_first = TRUE;
2080 continue;
2081 }
2082
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002083 if (pt->pt_hl_id > 0)
2084 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002085 text_prop_type = pt;
2086 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002087 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002088 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2089 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002090 text_prop_flags = pt->pt_flags;
2091 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002092 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002093 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 }
2095 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002096 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002097 && -text_prop_id
2098 <= wp->w_buffer->b_textprop_text.ga_len)
2099 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002100 textprop_T *tp = &text_props[used_tpi];
2101 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002102 ->b_textprop_text.ga_data)[
2103 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002104 int above = (tp->tp_flags
2105 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002106 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002107
2108 // reset the ID in the copy to avoid it being used
2109 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002110 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002111
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002112 if (p != NULL)
2113 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002114 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002115 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002116 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002117 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002118 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
2119 int padding = tp->tp_col == MAXCOL
2120 && tp->tp_len > 1
2121 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002122
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002123 // Insert virtual text before the current
2124 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 wlv.p_extra = p;
2126 wlv.c_extra = NUL;
2127 wlv.c_final = NUL;
2128 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002129 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002130 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2131 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002132 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002133 // restore search_attr and area_attr when n_extra
2134 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002135 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002136 saved_area_attr = area_attr;
2137 search_attr = 0;
2138 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002139 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002140 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002141 if (*ptr == NUL)
2142 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002143 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002144#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002145 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002146 {
2147 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002148 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002149 wlv.need_showbreak = FALSE;
2150 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002151 }
2152#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002153 if ((right || above || below || !wrap
2154 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002155 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002156 char_u *prev_p_extra = wlv.p_extra;
2157 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002158
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002159 // Take care of padding, right-align and
2160 // truncation.
2161 // Shared with win_lbr_chartabsize(), must do
2162 // exactly the same.
2163 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002164 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002165 wlv.col,
2166 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002167 &n_attr, &wlv.n_attr_skip,
2168 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002169 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002170 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002171 // wlv.p_extra was allocated
2172 vim_free(p_extra_free2);
2173 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002174 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002175
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002176 if (above)
2177 wlv.vcol_off_tp = wlv.n_extra;
2178
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002179 if (lcs_eol_one < 0
2180 && wp->w_p_wrap
2181 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002182 + wlv.n_extra - 2 > wp->w_width)
2183 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002184 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002185
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002186 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002187 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002188 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002189 {
2190 draw_screen_line(wp, &wlv);
2191
2192 // When line got too long for screen break
2193 // here.
2194 if (wlv.row == endrow)
2195 {
2196 ++wlv.row;
2197 break;
2198 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002199 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002200 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002201 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002202 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002203 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002204
Bram Moolenaarcd105412022-10-10 19:50:42 +01002205 // If the text didn't reach until the first window
2206 // column we need to skip cells.
2207 if (skip_cells > 0)
2208 {
2209 if (wlv.n_extra > skip_cells)
2210 {
2211 wlv.n_extra -= skip_cells;
2212 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002213 wlv.n_attr_skip -= skip_cells;
2214 if (wlv.n_attr_skip < 0)
2215 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002216 skip_cells = 0;
2217 }
2218 else
2219 {
2220 // the whole text is left of the window, drop
2221 // it and advance to the next one
2222 skip_cells -= wlv.n_extra;
2223 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002224 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002225 bail_out = TRUE;
2226 }
2227 }
2228
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002229 // If another text prop follows the condition below at
2230 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002231 // If this is an "above" text prop and 'nowrap' the we
2232 // must wrap anyway.
2233 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002234 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002235 && (wp->w_p_wrap
2236 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002237 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002238
2239 if (bail_out)
2240 // starting a new line for "below"
2241 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002242 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002244 else if (text_prop_next < text_prop_count
2245 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002246 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2247 || (!wp->w_p_wrap
2248 && wlv.col == wp->w_width - 1
2249 && (text_props[text_prop_next].tp_flags
2250 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002251 // When at last-but-one character and a text property
2252 // follows after it, we may need to flush the line after
2253 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002254 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002255 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002256 }
2257#endif
2258
Bram Moolenaare38fc862022-08-11 17:24:50 +01002259#ifdef FEAT_SEARCH_EXTRA
2260 if (wlv.n_extra == 0)
2261 {
2262 // Check for start/end of 'hlsearch' and other matches.
2263 // After end, check for start/end of next match.
2264 // When another match, have to check for start again.
2265 v = (long)(ptr - line);
2266 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2267 &screen_search_hl, &has_match_conc,
2268 &match_conc, did_line_attr, lcs_eol_one,
2269 &on_last_col);
2270 ptr = line + v; // "line" may have been changed
2271 prev_ptr = ptr;
2272
2273 // Do not allow a conceal over EOL otherwise EOL will be missed
2274 // and bad things happen.
2275 if (*ptr == NUL)
2276 has_match_conc = 0;
2277 }
2278#endif
2279
2280#ifdef FEAT_DIFF
2281 if (wlv.diff_hlf != (hlf_T)0)
2282 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002283 // When there is extra text (e.g. virtual text) it gets the
2284 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002285 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2286 && wlv.n_extra == 0)
2287 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002288 if (wlv.diff_hlf == HLF_TXD
2289 && ((ptr - line > change_end && wlv.n_extra == 0)
2290 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002291 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002292 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002293 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2294 && wp->w_p_culopt_flags != CULOPT_NBR
2295 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2296 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002297 wlv.line_attr = hl_combine_attr(
2298 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002299 }
2300#endif
2301
Bram Moolenaara74fda62019-10-19 17:38:03 +02002302#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002303 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002304 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002305 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002306# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002307 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002308 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002309# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002310 // Get syntax attribute.
2311 if (has_syntax)
2312 {
2313 // Get the syntax attribute for the character. If there
2314 // is an error, disable syntax highlighting.
2315 save_did_emsg = did_emsg;
2316 did_emsg = FALSE;
2317
2318 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002319 if (v == prev_syntax_col)
2320 // at same column again
2321 syntax_attr = prev_syntax_attr;
2322 else
2323 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002324# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002325 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002326# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002327 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002328# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002329 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002330# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002331 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002332 prev_syntax_col = v;
2333 prev_syntax_attr = syntax_attr;
2334 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002335
Bram Moolenaar34390282019-10-16 14:38:26 +02002336 if (did_emsg)
2337 {
2338 wp->w_s->b_syn_error = TRUE;
2339 has_syntax = FALSE;
2340 syntax_attr = 0;
2341 }
2342 else
2343 did_emsg = save_did_emsg;
2344# ifdef SYN_TIME_LIMIT
2345 if (wp->w_s->b_syn_slow)
2346 has_syntax = FALSE;
2347# endif
2348
2349 // Need to get the line again, a multi-line regexp may
2350 // have made it invalid.
2351 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2352 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002353 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002354# ifdef FEAT_CONCEAL
2355 // no concealing past the end of the line, it interferes
2356 // with line highlighting
2357 if (*ptr == NUL)
2358 syntax_flags = 0;
2359 else
2360 syntax_flags = get_syntax_info(&syntax_seqnr);
2361# endif
2362 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002363 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002364# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002365 // Combine text property highlight into syntax highlight.
2366 if (text_prop_type != NULL)
2367 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002368 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002369 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2370 else
2371 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002372 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002373 }
2374# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002375#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002376
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002377 // Decide which of the highlight attributes to use.
2378 attr_pri = TRUE;
2379#ifdef LINE_ATTR
2380 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002381 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002382 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002383 if (!highlight_match)
2384 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002385 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_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 Moolenaar7528d1f2019-09-19 23:06:20 +02002390 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002391 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002392 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002393# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002394 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002395# endif
2396 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002397 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002398 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2399 || wlv.vcol < wlv.fromcol
2400 || vcol_prev < fromcol_prev
2401 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002403 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002404 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002405# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002406 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002407# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002408 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002409# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 attr_pri = FALSE;
2411 }
2412#else
2413 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002414 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002416 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417#endif
2418 else
2419 {
2420 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002421#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002422 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002423#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002424 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002425#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002426 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002427#ifdef FEAT_PROP_POPUP
2428 // override with text property highlight when "override" is TRUE
2429 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002430 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002431#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002432 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002433
2434 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002435 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002436 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002437 if (wlv.char_attr == 0)
2438 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002439 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002440 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002441 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002442
2443 // Get the next character to put on the screen.
2444
2445 // The "p_extra" points to the extra stuff that is inserted to
2446 // represent special characters (non-printable stuff) and other
2447 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002448 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2450 // "p_extra[n_extra]".
2451 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002452 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002453 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002454 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002456 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2457 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002458 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2459 if (enc_utf8 && utf_char2len(c) > 1)
2460 {
2461 mb_utf8 = TRUE;
2462 u8cc[0] = 0;
2463 c = 0xc0;
2464 }
2465 else
2466 mb_utf8 = FALSE;
2467 }
2468 else
2469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002470 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 if (has_mbyte)
2472 {
2473 mb_c = c;
2474 if (enc_utf8)
2475 {
2476 // If the UTF-8 character is more than one byte:
2477 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002478 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002481 mb_l = 1;
2482 else if (mb_l > 1)
2483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002485 mb_utf8 = TRUE;
2486 c = 0xc0;
2487 }
2488 }
2489 else
2490 {
2491 // if this is a DBCS character, put it in "mb_c"
2492 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002493 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494 mb_l = 1;
2495 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 }
2498 if (mb_l == 0) // at the NUL at end-of-line
2499 mb_l = 1;
2500
2501 // If a double-width char doesn't fit display a '>' in the
2502 // last column.
2503 if ((
2504# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002505 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002506# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002507 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002508 && (*mb_char2cells)(mb_c) == 2)
2509 {
2510 c = '>';
2511 mb_c = c;
2512 mb_l = 1;
2513 mb_utf8 = FALSE;
2514 multi_attr = HL_ATTR(HLF_AT);
2515#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002516 if (wlv.cul_attr)
2517 multi_attr = hl_combine_attr(
2518 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002520 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002521
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002522 // put the pointer back to output the double-width
2523 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002524 ++wlv.n_extra;
2525 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 }
2527 else
2528 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 wlv.n_extra -= mb_l - 1;
2530 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002531 }
2532 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002536#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002538 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002539 // Only restore search_attr and area_attr after "n_extra" in
2540 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002541 if (wlv.saved_n_extra <= 0)
2542 {
2543 if (search_attr == 0)
2544 search_attr = saved_search_attr;
2545 if (area_attr == 0 && *ptr != NUL)
2546 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002547
2548 if (wlv.extra_for_textprop)
2549 // wlv.extra_attr should be used at this position but
2550 // not any further.
2551 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002552 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002553
2554 wlv.extra_for_textprop = FALSE;
2555 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002556 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002557#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 }
2559 else
2560 {
2561#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002562 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002563#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002564 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 // Get a character from the line itself.
2567 c = *ptr;
2568#ifdef FEAT_LINEBREAK
2569 c0 = *ptr;
2570#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002571#ifdef FEAT_PROP_POPUP
2572 if (c == NUL)
2573 // text is finished, may display a "below" virtual text
2574 did_line = TRUE;
2575#endif
2576
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 if (has_mbyte)
2578 {
2579 mb_c = c;
2580 if (enc_utf8)
2581 {
2582 // If the UTF-8 character is more than one byte: Decode it
2583 // into "mb_c".
2584 mb_l = utfc_ptr2len(ptr);
2585 mb_utf8 = FALSE;
2586 if (mb_l > 1)
2587 {
2588 mb_c = utfc_ptr2char(ptr, u8cc);
2589 // Overlong encoded ASCII or ASCII with composing char
2590 // is displayed normally, except a NUL.
2591 if (mb_c < 0x80)
2592 {
2593 c = mb_c;
2594#ifdef FEAT_LINEBREAK
2595 c0 = mb_c;
2596#endif
2597 }
2598 mb_utf8 = TRUE;
2599
2600 // At start of the line we can have a composing char.
2601 // Draw it as a space with a composing char.
2602 if (utf_iscomposing(mb_c))
2603 {
2604 int i;
2605
2606 for (i = Screen_mco - 1; i > 0; --i)
2607 u8cc[i] = u8cc[i - 1];
2608 u8cc[0] = mb_c;
2609 mb_c = ' ';
2610 }
2611 }
2612
2613 if ((mb_l == 1 && c >= 0x80)
2614 || (mb_l >= 1 && mb_c == 0)
2615 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2616 {
2617 // Illegal UTF-8 byte: display as <xx>.
2618 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002619 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002620# ifdef FEAT_RIGHTLEFT
2621 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002622 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002624 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 c = *wlv.p_extra;
2626 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002628 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2629 wlv.c_extra = NUL;
2630 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 if (area_attr == 0 && search_attr == 0)
2632 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002634 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002635 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002636 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637 }
2638 }
2639 else if (mb_l == 0) // at the NUL at end-of-line
2640 mb_l = 1;
2641#ifdef FEAT_ARABIC
2642 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2643 {
2644 // Do Arabic shaping.
2645 int pc, pc1, nc;
2646 int pcc[MAX_MCO];
2647
2648 // The idea of what is the previous and next
2649 // character depends on 'rightleft'.
2650 if (wp->w_p_rl)
2651 {
2652 pc = prev_c;
2653 pc1 = prev_c1;
2654 nc = utf_ptr2char(ptr + mb_l);
2655 prev_c1 = u8cc[0];
2656 }
2657 else
2658 {
2659 pc = utfc_ptr2char(ptr + mb_l, pcc);
2660 nc = prev_c;
2661 pc1 = pcc[0];
2662 }
2663 prev_c = mb_c;
2664
2665 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2666 }
2667 else
2668 prev_c = mb_c;
2669#endif
2670 }
2671 else // enc_dbcs
2672 {
2673 mb_l = MB_BYTE2LEN(c);
2674 if (mb_l == 0) // at the NUL at end-of-line
2675 mb_l = 1;
2676 else if (mb_l > 1)
2677 {
2678 // We assume a second byte below 32 is illegal.
2679 // Hopefully this is OK for all double-byte encodings!
2680 if (ptr[1] >= 32)
2681 mb_c = (c << 8) + ptr[1];
2682 else
2683 {
2684 if (ptr[1] == NUL)
2685 {
2686 // head byte at end of line
2687 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002688 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002689 }
2690 else
2691 {
2692 // illegal tail byte
2693 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002694 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002696 wlv.p_extra = wlv.extra;
2697 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002698 wlv.c_extra = NUL;
2699 wlv.c_final = NUL;
2700 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002701 if (area_attr == 0 && search_attr == 0)
2702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002703 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002704 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002705 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002706 // save current attr
2707 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708 }
2709 mb_c = c;
2710 }
2711 }
2712 }
2713 // If a double-width char doesn't fit display a '>' in the
2714 // last column; the character is displayed at the start of the
2715 // next line.
2716 if ((
2717# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002718 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002720 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002721 && (*mb_char2cells)(mb_c) == 2)
2722 {
2723 c = '>';
2724 mb_c = c;
2725 mb_utf8 = FALSE;
2726 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002727 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 // Put pointer back so that the character will be
2729 // displayed at the start of the next line.
2730 --ptr;
2731#ifdef FEAT_CONCEAL
2732 did_decrement_ptr = TRUE;
2733#endif
2734 }
2735 else if (*ptr != NUL)
2736 ptr += mb_l - 1;
2737
2738 // If a double-width char doesn't fit at the left side display
2739 // a '<' in the first column. Don't do this for unprintable
2740 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002743 wlv.n_extra = 1;
2744 wlv.c_extra = MB_FILLER_CHAR;
2745 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 c = ' ';
2747 if (area_attr == 0 && search_attr == 0)
2748 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002750 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002751 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002753 }
2754 mb_c = c;
2755 mb_utf8 = FALSE;
2756 mb_l = 1;
2757 }
2758
2759 }
2760 ++ptr;
2761
2762 if (extra_check)
2763 {
2764#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002765 // Check spelling (unless at the end of the line).
2766 // Only do this when there is no syntax highlighting, the
2767 // @Spell cluster is not used or the current syntax item
2768 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002769 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002770 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771 {
2772 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002773 // do not calculate cap_col at the end of the line or when
2774 // only white space is following
2775 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776# ifdef FEAT_SYN_HL
2777 !has_syntax ||
2778# endif
2779 can_spell))
2780 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002781 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 int len;
2783 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002784
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002786 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002787
2788 // Use nextline[] if possible, it has the start of the
2789 // next line concatenated.
2790 if ((prev_ptr - line) - nextlinecol >= 0)
2791 p = nextline + (prev_ptr - line) - nextlinecol;
2792 else
2793 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002794 spv->spv_cap_col -= (int)(prev_ptr - line);
2795 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2796 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002797 word_end = v + len;
2798
2799 // In Insert mode only highlight a word that
2800 // doesn't touch the cursor.
2801 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002802 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 && wp->w_cursor.lnum == lnum
2804 && wp->w_cursor.col >=
2805 (colnr_T)(prev_ptr - line)
2806 && wp->w_cursor.col < (colnr_T)word_end)
2807 {
2808 spell_hlf = HLF_COUNT;
2809 spell_redraw_lnum = lnum;
2810 }
2811
2812 if (spell_hlf == HLF_COUNT && p != prev_ptr
2813 && (p - nextline) + len > nextline_idx)
2814 {
2815 // Remember that the good word continues at the
2816 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002817 spv->spv_checked_lnum = lnum + 1;
2818 spv->spv_checked_col = (p - nextline) + len
2819 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 }
2821
2822 // Turn index into actual attributes.
2823 if (spell_hlf != HLF_COUNT)
2824 spell_attr = highlight_attr[spell_hlf];
2825
Luuk van Baal30805a12023-05-27 22:22:10 +01002826 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 {
2828 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002829 && (p - nextline) + spv->spv_cap_col
2830 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 {
2832 // Remember that the word in the next line
2833 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002834 spv->spv_capcol_lnum = lnum + 1;
2835 spv->spv_cap_col = ((p - nextline)
2836 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002837 }
2838 else
2839 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002840 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
2842 }
2843 }
2844 if (spell_attr != 0)
2845 {
2846 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002847 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2848 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002849 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 wlv.char_attr = hl_combine_attr(spell_attr,
2851 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002852 }
2853#endif
2854#ifdef FEAT_LINEBREAK
2855 // Found last space before word: check for line break.
2856 if (wp->w_p_lbr && c0 == c
2857 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2858 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002859 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2860 : 0;
2861 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002862 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002863
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002864 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002865# ifdef FEAT_PROP_POPUP
2866 // do not want virtual text counted here
2867 cts.cts_has_prop_with_text = FALSE;
2868# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002870 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002871
2872 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002873 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002874 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002875 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002876 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2877 if (wlv.n_extra < 0)
2878 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002879 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002880 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002881 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002882 // line break, but for TABs the highlighting should
2883 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002884 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002885
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002889 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 wp->w_buffer->b_p_vts_array) - 1;
2891# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002892 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002893 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894# endif
2895
Bram Moolenaar1306b362022-08-06 15:59:06 +01002896 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2897 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002898# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002899 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002900 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002901# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902 if (VIM_ISWHITE(c))
2903 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002904# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 if (c == TAB)
2906 // See "Tab alignment" below.
2907 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002908# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 if (!wp->w_p_list)
2910 c = ' ';
2911 }
2912 }
2913#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002914 in_multispace = c == ' '
2915 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2916 if (!in_multispace)
2917 multispace_pos = 0;
2918
Bram Moolenaareed9d462021-02-15 20:38:25 +01002919 // 'list': Change char 160 to 'nbsp' and space to 'space'
2920 // setting in 'listchars'. But not when the character is
2921 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 if (wp->w_p_list
2923 && ((((c == 160 && mb_l == 1)
2924 || (mb_utf8
2925 && ((mb_c == 160 && mb_l == 2)
2926 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002927 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928 || (c == ' '
2929 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002930 && (wp->w_lcs_chars.space
2931 || (in_multispace
2932 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002933 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 && ptr - line <= trailcol)))
2935 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002936 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2937 {
2938 c = wp->w_lcs_chars.multispace[multispace_pos++];
2939 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2940 multispace_pos = 0;
2941 }
2942 else
2943 c = (c == ' ') ? wp->w_lcs_chars.space
2944 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 if (area_attr == 0 && search_attr == 0)
2946 {
2947 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002948 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002949 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002950 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 }
2952 mb_c = c;
2953 if (enc_utf8 && utf_char2len(c) > 1)
2954 {
2955 mb_utf8 = TRUE;
2956 u8cc[0] = 0;
2957 c = 0xc0;
2958 }
2959 else
2960 mb_utf8 = FALSE;
2961 }
2962
zeertzjq2e7cba32022-06-10 15:30:32 +01002963 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2964 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002966 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2967 && wp->w_lcs_chars.leadmultispace != NULL)
2968 {
2969 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002970 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2971 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002972 multispace_pos = 0;
2973 }
2974
2975 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2976 c = wp->w_lcs_chars.trail;
2977
2978 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2979 c = wp->w_lcs_chars.lead;
2980
zeertzjq2e7cba32022-06-10 15:30:32 +01002981 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002982 c = wp->w_lcs_chars.space;
2983
2984
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 if (!attr_pri)
2986 {
2987 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002988 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002989 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 }
2992 mb_c = c;
2993 if (enc_utf8 && utf_char2len(c) > 1)
2994 {
2995 mb_utf8 = TRUE;
2996 u8cc[0] = 0;
2997 c = 0xc0;
2998 }
2999 else
3000 mb_utf8 = FALSE;
3001 }
3002 }
3003
3004 // Handling of non-printable characters.
3005 if (!vim_isprintc(c))
3006 {
3007 // when getting a character from the file, we may have to
3008 // turn it into something else on the way to putting it
3009 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003010 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003012 int tab_len = 0;
3013 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003015 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003016
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 // only adjust the tab_len, when at the first column
3018 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003019 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003020 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021#endif
3022 // tab amount depends on current column
3023#ifdef FEAT_VARTABS
3024 tab_len = tabstop_padding(vcol_adjusted,
3025 wp->w_buffer->b_p_ts,
3026 wp->w_buffer->b_p_vts_array) - 1;
3027#else
3028 tab_len = (int)wp->w_buffer->b_p_ts
3029 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3030#endif
3031
3032#ifdef FEAT_LINEBREAK
3033 if (!wp->w_p_lbr || !wp->w_p_list)
3034#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003035 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003036 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003037 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003038 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003039#ifdef FEAT_LINEBREAK
3040 else
3041 {
3042 char_u *p;
3043 int len;
3044 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003047# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003048 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003050 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003051
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003052 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003053 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003054 && old_boguscols > 0
3055 && wlv.n_extra > tab_len)
3056 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003057# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003058 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003060 // If wlv.n_extra > 0, it gives the number of chars
3061 // to use for a tab, else we need to calculate the
3062 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003063 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3064 len = tab_len * tab2_len;
3065 if (wp->w_lcs_chars.tab3)
3066 len += mb_char2len(wp->w_lcs_chars.tab3)
3067 - tab2_len;
3068 if (wlv.n_extra > 0)
3069 len += wlv.n_extra - tab_len;
3070 c = wp->w_lcs_chars.tab1;
3071 p = alloc(len + 1);
3072 if (p == NULL)
3073 wlv.n_extra = 0;
3074 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003076 vim_memset(p, ' ', len);
3077 p[len] = NUL;
3078 vim_free(wlv.p_extra_free);
3079 wlv.p_extra_free = p;
3080 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003081 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003082 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003083
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003084 if (*p == NUL)
3085 {
3086 tab_len = i;
3087 break;
3088 }
3089
3090 // if tab3 is given, use it for the last
3091 // char
3092 if (wp->w_lcs_chars.tab3
3093 && i == tab_len - 1)
3094 lcs = wp->w_lcs_chars.tab3;
3095 p += mb_char2bytes(lcs, p);
3096 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003098 }
3099 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003100# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003101 // n_extra will be increased by
3102 // FIX_FOX_BOGUSCOLS macro below, so need to
3103 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003104 if (wlv.vcol_off_co > 0)
3105 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003106# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003107 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003109 }
3110#endif
3111#ifdef FEAT_CONCEAL
3112 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003113 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114
3115 // Tab alignment should be identical regardless of
3116 // 'conceallevel' value. So tab compensates of all
3117 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003118 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 // line. Note that the tab can be longer than
3120 // 'tabstop' when there are concealed characters.
3121 FIX_FOR_BOGUSCOLS;
3122
3123 // Make sure, the highlighting for the tab char will be
3124 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003125 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003126 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003127 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003128 tab_len += vc_saved;
3129 }
3130#endif
3131 mb_utf8 = FALSE; // don't draw as UTF-8
3132 if (wp->w_p_list)
3133 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003134 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003135 ? wp->w_lcs_chars.tab3
3136 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003138 if (wp->w_p_lbr && wlv.p_extra != NULL
3139 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003140 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 else
3142#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003143 wlv.c_extra = wp->w_lcs_chars.tab2;
3144 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003145 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003146 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003147 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003148 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003149 mb_c = c;
3150 if (enc_utf8 && utf_char2len(c) > 1)
3151 {
3152 mb_utf8 = TRUE;
3153 u8cc[0] = 0;
3154 c = 0xc0;
3155 }
3156 }
3157 else
3158 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 wlv.c_final = NUL;
3160 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 c = ' ';
3162 }
3163 }
3164 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003165 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003166 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003167 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3168 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 && VIsual_mode != Ctrl_V
3170 && (
3171# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003172 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 && !(noinvcur
3176 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003177 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 && lcs_eol_one > 0)
3179 {
3180 // Display a '$' after the line or highlight an extra
3181 // character if the line break is included.
3182#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3183 // For a diff line the highlighting continues after the
3184 // "$".
3185 if (
3186# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188# ifdef LINE_ATTR
3189 &&
3190# endif
3191# endif
3192# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003193 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003194# endif
3195 )
3196#endif
3197 {
3198 // In virtualedit, visual selections may extend
3199 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003200 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003201 && wlv.tocol != MAXCOL
3202 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003203 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003204 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003205 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003206 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3207 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 else
3209 c = ' ';
3210 lcs_eol_one = -1;
3211 --ptr; // put it back at the NUL
3212 if (!attr_pri)
3213 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003214 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003215 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 n_attr = 1;
3217 }
3218 mb_c = c;
3219 if (enc_utf8 && utf_char2len(c) > 1)
3220 {
3221 mb_utf8 = TRUE;
3222 u8cc[0] = 0;
3223 c = 0xc0;
3224 }
3225 else
3226 mb_utf8 = FALSE; // don't draw as UTF-8
3227 }
3228 else if (c != NUL)
3229 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003230 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3231 if (wlv.n_extra == 0)
3232 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233#ifdef FEAT_RIGHTLEFT
3234 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003235 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.c_extra = NUL;
3238 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239#ifdef FEAT_LINEBREAK
3240 if (wp->w_p_lbr)
3241 {
3242 char_u *p;
3243
Bram Moolenaar1306b362022-08-06 15:59:06 +01003244 c = *wlv.p_extra;
3245 p = alloc(wlv.n_extra + 1);
3246 vim_memset(p, ' ', wlv.n_extra);
3247 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3248 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003249 vim_free(wlv.p_extra_free);
3250 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 }
3252 else
3253#endif
3254 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 wlv.n_extra = byte2cells(c) - 1;
3256 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 }
3258 if (!attr_pri)
3259 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003260 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003261 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003262 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 }
3265 mb_utf8 = FALSE; // don't draw as UTF-8
3266 }
3267 else if (VIsual_active
3268 && (VIsual_mode == Ctrl_V
3269 || VIsual_mode == 'v')
3270 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003271 && wlv.tocol != MAXCOL
3272 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003273 && (
3274#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003275 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003277 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 {
3279 c = ' ';
3280 --ptr; // put it back at the NUL
3281 }
3282#if defined(LINE_ATTR)
3283 else if ((
3284# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003285 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286# endif
3287# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003290 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 ) && (
3292# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003293 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298# endif
3299 < wp->w_width)))
3300 {
3301 // Highlight until the right side of the window
3302 c = ' ';
3303 --ptr; // put it back at the NUL
3304
3305 // Remember we do the char for line highlighting.
3306 ++did_line_attr;
3307
3308 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003309 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003310 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003311 || (wp->w_p_list &&
3312 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003313 wlv.char_attr = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003314# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003315 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003316 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003317 wlv.diff_hlf = HLF_CHD;
3318 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003320 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003321 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3322 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003323 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 || (wlv.vcol >= left_curline_col
3325 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003326 wlv.char_attr = hl_combine_attr(
3327 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 }
3329 }
3330# endif
3331# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003332 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003334 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003335 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3336 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 if (!wlv.cul_screenline
3339 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003341 wlv.char_attr = hl_combine_attr(
3342 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003343 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003344 else if (wlv.line_attr)
3345 wlv.char_attr = hl_combine_attr(
3346 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348# endif
3349 }
3350#endif
3351 }
3352
3353#ifdef FEAT_CONCEAL
3354 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003355 && (wp != curwin || lnum != wp->w_cursor.lnum
3356 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003357 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3358 && !(lnum_in_visual_area
3359 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3360 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003361 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003362 if (((prev_syntax_id != syntax_seqnr
3363 && (syntax_flags & HL_CONCEAL) != 0)
3364 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003365 && (syn_get_sub_char() != NUL
3366 || (has_match_conc && match_conc)
3367 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368 && wp->w_p_cole != 3)
3369 {
3370 // First time at this concealed item: display one
3371 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003372 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003373 c = match_conc;
3374 else if (syn_get_sub_char() != NUL)
3375 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003376 else if (wp->w_lcs_chars.conceal != NUL)
3377 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 else
3379 c = ' ';
3380
3381 prev_syntax_id = syntax_seqnr;
3382
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003384 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 wlv.vcol += wlv.n_extra;
3386 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003387 {
3388# ifdef FEAT_RIGHTLEFT
3389 if (wp->w_p_rl)
3390 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003391 wlv.col -= wlv.n_extra;
3392 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394 else
3395# endif
3396 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 wlv.boguscols += wlv.n_extra;
3398 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 }
3400 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003401 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 n_attr = 0;
3403 }
3404 else if (n_skip == 0)
3405 {
3406 is_concealing = TRUE;
3407 n_skip = 1;
3408 }
3409 mb_c = c;
3410 if (enc_utf8 && utf_char2len(c) > 1)
3411 {
3412 mb_utf8 = TRUE;
3413 u8cc[0] = 0;
3414 c = 0xc0;
3415 }
3416 else
3417 mb_utf8 = FALSE; // don't draw as UTF-8
3418 }
3419 else
3420 {
3421 prev_syntax_id = 0;
3422 is_concealing = FALSE;
3423 }
3424
3425 if (n_skip > 0 && did_decrement_ptr)
3426 // not showing the '>', put pointer back to avoid getting stuck
3427 ++ptr;
3428
3429#endif // FEAT_CONCEAL
3430 }
3431
3432#ifdef FEAT_CONCEAL
3433 // In the cursor line and we may be concealing characters: correct
3434 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003435 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 && wp == curwin && lnum == wp->w_cursor.lnum
3437 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003438 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003440# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003442 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003443 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003444# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003445 wp->w_wcol = wlv.col - wlv.boguscols;
3446 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 did_wcol = TRUE;
3448 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003449# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003450 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003451# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 }
3453#endif
3454
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003455 // Use "wlv.extra_attr", but don't override visual selection
3456 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003457 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3458 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003460 && (!attr_pri
3461#ifdef FEAT_PROP_POPUP
3462 || (text_prop_flags & PT_FLAG_OVERRIDE)
3463#endif
3464 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003465 {
3466#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003467 if (wlv.line_attr)
3468 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 else
3470#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003471 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003472#ifdef FEAT_PROP_POPUP
3473 if (reset_extra_attr)
3474 {
3475 reset_extra_attr = FALSE;
3476 wlv.extra_attr = 0;
3477 }
3478#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 }
3480
3481#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3482 // XIM don't send preedit_start and preedit_end, but they send
3483 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3484 // im_is_preediting() here.
3485 if (p_imst == IM_ON_THE_SPOT
3486 && xic != NULL
3487 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003488 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 && !p_imdisable
3490 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492 {
3493 colnr_T tcol;
3494
3495 if (preedit_end_col == MAXCOL)
3496 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3497 else
3498 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003499 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003500 {
3501 if (feedback_old_attr < 0)
3502 {
3503 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003505 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 wlv.char_attr = im_get_feedback_attr(feedback_col);
3507 if (wlv.char_attr < 0)
3508 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 feedback_col++;
3510 }
3511 else if (feedback_old_attr >= 0)
3512 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003513 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 feedback_old_attr = -1;
3515 feedback_col = 0;
3516 }
3517 }
3518#endif
3519 // Handle the case where we are in column 0 but not on the first
3520 // character of the line and the user wants us to show us a
3521 // special character (via 'listchars' option "precedes:<char>".
3522 if (lcs_prec_todo != NUL
3523 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003524 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3525 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003526#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003527 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003529 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 && c != NUL)
3531 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003532 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 lcs_prec_todo = NUL;
3534 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3535 {
3536 // Double-width character being overwritten by the "precedes"
3537 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 wlv.c_extra = MB_FILLER_CHAR;
3539 wlv.c_final = NUL;
3540 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003541 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003542 wlv.extra_attr =
3543 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
3545 mb_c = c;
3546 if (enc_utf8 && utf_char2len(c) > 1)
3547 {
3548 mb_utf8 = TRUE;
3549 u8cc[0] = 0;
3550 c = 0xc0;
3551 }
3552 else
3553 mb_utf8 = FALSE; // don't draw as UTF-8
3554 if (!attr_pri)
3555 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003556 saved_attr3 = wlv.char_attr; // save current attr
3557 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 n_attr3 = 1;
3559 }
3560 }
3561
3562 // At end of the text line or just after the last character.
3563 if ((c == NUL
3564#if defined(LINE_ATTR)
3565 || did_line_attr == 1
3566#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003567 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 {
3569#ifdef FEAT_SEARCH_EXTRA
3570 // flag to indicate whether prevcol equals startcol of search_hl or
3571 // one of the matches
3572 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3573 (long)(ptr - line) - (c == NUL));
3574#endif
3575 // Invert at least one char, used for Visual and empty line or
3576 // highlight match at end of line. If it's beyond the last
3577 // char on the screen, just overwrite that one (tricky!) Not
3578 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003579 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003580 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003581 && (VIsual_mode != Ctrl_V
3582 || lnum == VIsual.lnum
3583 || lnum == curwin->w_cursor.lnum)
3584 && c == NUL)
3585#ifdef FEAT_SEARCH_EXTRA
3586 // highlight 'hlsearch' match at end of line
3587 || (prevcol_hl_flag
3588# ifdef FEAT_SYN_HL
3589 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3590 && !(wp == curwin && VIsual_active))
3591# endif
3592# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003593 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594# endif
3595# if defined(LINE_ATTR)
3596 && did_line_attr <= 1
3597# endif
3598 )
3599#endif
3600 ))
3601 {
3602 int n = 0;
3603
3604#ifdef FEAT_RIGHTLEFT
3605 if (wp->w_p_rl)
3606 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003607 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003608 n = 1;
3609 }
3610 else
3611#endif
3612 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 n = -1;
3615 }
3616 if (n != 0)
3617 {
3618 // At the window boundary, highlight the last character
3619 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 wlv.off += n;
3621 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 }
3623 else
3624 {
3625 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 }
3630#ifdef FEAT_SEARCH_EXTRA
3631 if (area_attr == 0)
3632 {
3633 // Use attributes from match with highest priority among
3634 // 'search_hl' and the match list.
3635 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003636 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 }
3638#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003639 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003640 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641#ifdef FEAT_RIGHTLEFT
3642 if (wp->w_p_rl)
3643 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003644 --wlv.col;
3645 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003646 }
3647 else
3648#endif
3649 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003650 ++wlv.col;
3651 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003653 ++wlv.vcol;
3654 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 }
3656 }
3657
3658 // At end of the text line.
3659 if (c == NUL)
3660 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003661#ifdef FEAT_PROP_POPUP
3662 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003664 // Put the pointer back to the NUL.
3665 --ptr;
3666 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003668 else
3669#endif
3670 {
3671 draw_screen_line(wp, &wlv);
3672
3673 // Update w_cline_height and w_cline_folded if the cursor line
3674 // was updated (saves a call to plines() later).
3675 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3676 {
3677 curwin->w_cline_row = startrow;
3678 curwin->w_cline_height = wlv.row - startrow;
3679#ifdef FEAT_FOLDING
3680 curwin->w_cline_folded = FALSE;
3681#endif
3682 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3683 }
3684 break;
3685 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 }
3687
3688 // Show "extends" character from 'listchars' if beyond the line end and
3689 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003690 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003691 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003692 && wp->w_p_list
3693 && !wp->w_p_wrap
3694#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003695 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003696#endif
3697 && (
3698#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003699 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003700#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003701 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003702 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003703 || lcs_eol_one > 0
3704 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003705 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003706 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003707 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003708 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003709 mb_c = c;
3710 if (enc_utf8 && utf_char2len(c) > 1)
3711 {
3712 mb_utf8 = TRUE;
3713 u8cc[0] = 0;
3714 c = 0xc0;
3715 }
3716 else
3717 mb_utf8 = FALSE;
3718 }
3719
3720#ifdef FEAT_SYN_HL
3721 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003722 if (wlv.draw_color_col)
3723 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003724
3725 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3726 // highlight the cursor position itself.
3727 // Also highlight the 'colorcolumn' if it is different than
3728 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003729 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3730 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003732 if (((wlv.draw_state == WL_LINE
3733 || wlv.draw_state == WL_BRI
3734 || wlv.draw_state == WL_SBR)
3735 && !lnum_in_visual_area
3736 && search_attr == 0
3737 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003738# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003739 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003740# endif
3741 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003742 {
3743 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3744 && lnum != wp->w_cursor.lnum)
3745 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 vcol_save_attr = wlv.char_attr;
3747 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3748 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003749 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003750 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003752 vcol_save_attr = wlv.char_attr;
3753 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003754 }
3755 }
3756#endif
3757
3758 // Store character to be displayed.
3759 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003761 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003762 {
3763 // Store the character.
3764#if defined(FEAT_RIGHTLEFT)
3765 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3766 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003767 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003768 --wlv.off;
3769 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770 }
3771#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003772 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003773 if (enc_dbcs == DBCS_JPNU)
3774 {
3775 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003776 ScreenLines[wlv.off] = 0x8e;
3777 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 }
3779 else if (enc_utf8)
3780 {
3781 if (mb_utf8)
3782 {
3783 int i;
3784
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003785 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003787 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788 for (i = 0; i < Screen_mco; ++i)
3789 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003790 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791 if (u8cc[i] == 0)
3792 break;
3793 }
3794 }
3795 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797 }
3798 if (multi_attr)
3799 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 multi_attr = 0;
3802 }
3803 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003804 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003807
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3809 {
3810 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003811 ++wlv.off;
3812 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003813 if (enc_utf8)
3814 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003815 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 else
3817 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003819 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003821 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003822#endif
3823 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003824 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003825 // When "wlv.tocol" is halfway a character, set it to the end
3826 // of the character, otherwise highlighting won't stop.
3827 if (wlv.tocol == wlv.vcol)
3828 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003829
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003830 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003831
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832#ifdef FEAT_RIGHTLEFT
3833 if (wp->w_p_rl)
3834 {
3835 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003836 --wlv.off;
3837 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 }
3839#endif
3840 }
3841#ifdef FEAT_RIGHTLEFT
3842 if (wp->w_p_rl)
3843 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003844 --wlv.off;
3845 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003846 }
3847 else
3848#endif
3849 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 ++wlv.off;
3851 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852 }
3853 }
3854#ifdef FEAT_CONCEAL
3855 else if (wp->w_p_cole > 0 && is_concealing)
3856 {
3857 --n_skip;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003858 ++wlv.vcol_off_co;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003859 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003860 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003861 if (wp->w_p_wrap)
3862 {
3863 // Special voodoo required if 'wrap' is on.
3864 //
3865 // Advance the column indicator to force the line
3866 // drawing to wrap early. This will make the line
3867 // take up the same screen space when parts are concealed,
3868 // so that cursor line computations aren't messed up.
3869 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003870 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003871 // trailing junk to be written out of the screen line
3872 // we are building, 'boguscols' keeps track of the number
3873 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003874 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003876 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877# ifdef FEAT_RIGHTLEFT
3878 if (wp->w_p_rl)
3879 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003880 wlv.col -= wlv.n_extra;
3881 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 }
3883 else
3884# endif
3885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003886 wlv.col += wlv.n_extra;
3887 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003889 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890 n_attr = 0;
3891 }
3892
3893
3894 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3895 {
3896 // Need to fill two screen columns.
3897# ifdef FEAT_RIGHTLEFT
3898 if (wp->w_p_rl)
3899 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003900 --wlv.boguscols;
3901 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 }
3903 else
3904# endif
3905 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003906 ++wlv.boguscols;
3907 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 }
3909 }
3910
3911# ifdef FEAT_RIGHTLEFT
3912 if (wp->w_p_rl)
3913 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003914 --wlv.boguscols;
3915 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003916 }
3917 else
3918# endif
3919 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003920 ++wlv.boguscols;
3921 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003922 }
3923 }
3924 else
3925 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003926 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003927 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003928 wlv.vcol += wlv.n_extra;
3929 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003930 n_attr = 0;
3931 }
3932 }
3933
3934 }
3935#endif // FEAT_CONCEAL
3936 else
3937 --n_skip;
3938
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003939 // Only advance the "wlv.vcol" when after the 'number' or
3940 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003941 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003942#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003943 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944#endif
3945 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947
3948#ifdef FEAT_SYN_HL
3949 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003950 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003951#endif
3952
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003953 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003954 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3955 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956
3957 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003958 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003959 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003960 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003961 if (wlv.n_attr_skip > 0)
3962 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003963
3964 // At end of screen line and there is more to come: Display the line
3965 // so far. If there is no more to display it is caught above.
3966 if ((
3967#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003968 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003970 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003971 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003972 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003974 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003976#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003977 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003978#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003979 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003980 && wlv.p_extra != at_end_str)
3981 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3982 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983 )
3984 {
3985#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003986 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003987 wlv_screen_line(wp, &wlv, FALSE);
3988 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003989 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003990 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003991#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003992 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003994 ++wlv.row;
3995 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996
3997 // When not wrapping and finished diff lines, or when displayed
3998 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003999 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004001 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004002#endif
4003#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004004 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004005#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01004006 ) || lcs_eol_one == -1)
4007#ifdef FEAT_PROP_POPUP
4008 && !text_prop_follows
4009#endif
4010 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004012#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004013 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004014 {
4015 // do not output more of the line, only the "below" prop
4016 ptr += STRLEN(ptr);
4017# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004018 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004019# endif
4020 }
4021#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004022
4023 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004024 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004025#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004026 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004027#endif
4028 )
4029 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004030 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4031 draw_vsep_win(wp, wlv.row);
4032 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004033 }
4034
4035 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004036 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004038 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004039 break;
4040 }
4041
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004042 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004044 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004045#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004046#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004047 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004048#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004049 && wp->w_width == Columns)
4050 {
4051 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004052 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004053
4054 // Special trick to make copy/paste of wrapped lines work with
4055 // xterm/screen: write an extra character beyond the end of
4056 // the line. This will work with all terminal types
4057 // (regardless of the xn,am settings).
4058 // Only do this on a fast tty.
4059 // Only do this if the cursor is on the current line
4060 // (something has been written in it).
4061 // Don't do this for the GUI.
4062 // Don't do this for double-width characters.
4063 // Don't do this for a window not at the right screen border.
4064 if (p_tf
4065#ifdef FEAT_GUI
4066 && !gui.in_use
4067#endif
4068 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004069 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4070 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004071 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004072 || (*mb_off2cells)(
4073 LineOffset[wlv.screen_row - 1]
4074 + (int)Columns - 2,
4075 LineOffset[wlv.screen_row]
4076 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 {
4078 // First make sure we are at the end of the screen line,
4079 // then output the same character again to let the
4080 // terminal know about the wrap. If the terminal doesn't
4081 // auto-wrap, we overwrite the character.
4082 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004083 screen_char(LineOffset[wlv.screen_row - 1]
4084 + (unsigned)Columns - 1,
4085 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004086
4087 // When there is a multi-byte character, just output a
4088 // space to keep it simple.
4089 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004090 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091 out_char(' ');
4092 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004093 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094 + (Columns - 1)]);
4095 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004096 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004097 screen_start(); // don't know where cursor is now
4098 }
4099 }
4100
Bram Moolenaar1306b362022-08-06 15:59:06 +01004101 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102
Bram Moolenaareed9d462021-02-15 20:38:25 +01004103 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004105 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004107 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004109 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004110 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004111#endif
4112#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004113 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004114 // When the filler lines are actually below the last line of the
4115 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004116 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004117 break;
4118#endif
4119 }
4120
4121 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004122#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004123 vim_free(text_props);
4124 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004125 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126#endif
4127
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004128 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004129 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004130 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131}