blob: 137b888654d2cfbfd1f1a6454b648c59b9f45dd9 [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 Moolenaar1306b362022-08-06 15:59:06 +010078// structure with variables passed between win_line() and other functions
79typedef struct {
80 int draw_state; // what to draw next
81
82 linenr_T lnum; // line number to be drawn
83
84 int startrow; // first row in the window to be drawn
85 int row; // row in the window, excl w_winrow
86 int screen_row; // row on the screen, incl w_winrow
87
88 long vcol; // virtual column, before wrapping
89 int col; // visual column on screen, after wrapping
90#ifdef FEAT_CONCEAL
91 int boguscols; // nonexistent columns added to "col" to force
92 // wrapping
93 int vcol_off; // offset for concealed characters
94#endif
95#ifdef FEAT_SYN_HL
96 int draw_color_col; // highlight colorcolumn
97 int *color_cols; // pointer to according columns array
98#endif
99 int eol_hl_off; // 1 if highlighted char after EOL
100
101 unsigned off; // offset in ScreenLines/ScreenAttrs
102
103 int win_attr; // background for the whole window, except
104 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100105 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100106#ifdef FEAT_SYN_HL
107 int cul_attr; // set when 'cursorline' active
108#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100109
110 int screen_line_flags; // flags for screen_line()
111
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100112 int fromcol; // start of inverting
113 int tocol; // end of inverting
114
115#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100116 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100117 int need_showbreak; // overlong line, skipping first x chars
118 int dont_use_showbreak; // do not use 'showbreak'
119#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100120#ifdef FEAT_PROP_POPUP
121 int text_prop_above_count;
122#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100123
Bram Moolenaar1306b362022-08-06 15:59:06 +0100124 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
125 int cul_screenline;
126
127 int char_attr; // attributes for the next character
128
129 int n_extra; // number of extra bytes
130 char_u *p_extra; // string of extra chars, plus NUL, only used
131 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100132 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000133 int extra_attr; // attributes for p_extra, should be combined
134 // with win_attr if needed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100135 int c_extra; // extra chars, all the same
136 int c_final; // final char, mandatory if set
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000137 int extra_for_textprop; // wlv.n_extra set for textprop
Bram Moolenaar1306b362022-08-06 15:59:06 +0100138
139 // saved "extra" items for when draw_state becomes WL_LINE (again)
140 int saved_n_extra;
141 char_u *saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000142 int saved_extra_attr;
143 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100144 int saved_c_extra;
145 int saved_c_final;
146 int saved_char_attr;
147
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100148 char_u extra[NUMBUFLEN + MB_MAXBYTES];
149 // "%ld " and 'fdc' must fit in here, as well
150 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100151
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152#ifdef FEAT_DIFF
153 hlf_T diff_hlf; // type of diff highlighting
154#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100155 int filler_lines; // nr of filler lines to be drawn
156 int filler_todo; // nr of filler lines still to do + 1
157#ifdef FEAT_SIGNS
158 sign_attrs_T sattr;
159#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160} winlinevars_T;
161
162// draw_state values for items that are drawn in sequence:
163#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100164#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100165#ifdef FEAT_FOLDING
166# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
167#else
168# define WL_FOLD WL_CMDLINE
169#endif
170#ifdef FEAT_SIGNS
171# define WL_SIGN (WL_FOLD + 1) // column for signs
172#else
173# define WL_SIGN WL_FOLD // column for signs
174#endif
175#define WL_NR (WL_SIGN + 1) // line number
176#ifdef FEAT_LINEBREAK
177# define WL_BRI (WL_NR + 1) // 'breakindent'
178#else
179# define WL_BRI WL_NR
180#endif
181#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
182# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
183#else
184# define WL_SBR WL_BRI
185#endif
186#define WL_LINE (WL_SBR + 1) // text in the line
187
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100188#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000190 * Return TRUE if CursorLineSign highlight is to be used.
191 */
192 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100193use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000194{
195 return wp->w_p_cul
196 && lnum == wp->w_cursor.lnum
197 && (wp->w_p_culopt_flags & CULOPT_NBR);
198}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100199#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000200
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100201
202#ifdef FEAT_FOLDING
203/*
204 * Setup for drawing the 'foldcolumn', if there is one.
205 */
206 static void
207handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
208{
209 int fdc = compute_foldcolumn(wp, 0);
210
211 if (fdc <= 0)
212 return;
213
214 // Allocate a buffer, "wlv->extra[]" may already be in use.
215 vim_free(wlv->p_extra_free);
216 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
217 if (wlv->p_extra_free != NULL)
218 {
219 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
220 wp, FALSE, wlv->lnum);
221 wlv->p_extra_free[wlv->n_extra] = NUL;
222 wlv->p_extra = wlv->p_extra_free;
223 wlv->c_extra = NUL;
224 wlv->c_final = NUL;
225 if (use_cursor_line_highlight(wp, wlv->lnum))
226 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
227 else
228 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
229 }
230}
231#endif
232
233#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000234/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100235 * Get information needed to display the sign in line "wlv->lnum" in window
236 * "wp".
237 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200238 * Otherwise the sign is going to be displayed in the sign column.
239 */
240 static void
241get_sign_display_info(
242 int nrcol,
243 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100244 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200245{
246 int text_sign;
247# ifdef FEAT_SIGN_ICONS
248 int icon_sign;
249# endif
250
251 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->c_extra = ' ';
253 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100255 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200256 else
257 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100258 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100259 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000260 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100261 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 }
264
Bram Moolenaar1306b362022-08-06 15:59:06 +0100265 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100267 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200268#endif
269 )
270 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100271 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100273 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200274 if (gui.in_use && icon_sign != 0)
275 {
276 // Use the image in this position.
277 if (nrcol)
278 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100279 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 sprintf((char *)wlv->extra, "%-*c ",
281 number_width(wp), SIGN_BYTE);
282 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
289 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200290 {
291 if (nrcol)
292 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100293 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100296 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100297 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298 }
299 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 }
302# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100303 wlv->c_final = NUL;
304 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200305 }
306 else
307# endif
308 if (text_sign != 0)
309 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100310 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100311 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312 {
313 if (nrcol)
314 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100315 int width = number_width(wp) - 2;
316 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317
318 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100319 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100320 vim_snprintf((char *)wlv->extra + n,
321 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100322 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200323 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100324 wlv->c_extra = NUL;
325 wlv->c_final = NUL;
326 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200327 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000328
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100329 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100330 && wlv->sattr.sat_culhl > 0)
331 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000332 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100333 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334 }
335 }
336}
337#endif
338
Bram Moolenaard7657e92022-09-20 18:59:30 +0100339/*
340 * Display the absolute or relative line number. After the first row fill with
341 * blanks when the 'n' flag isn't in 'cpo'.
342 */
343 static void
344handle_lnum_col(
345 win_T *wp,
346 winlinevars_T *wlv,
347 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100348 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100350 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100351 int lnum_row = wlv->startrow + wlv->filler_lines
352#ifdef FEAT_PROP_POPUP
353 + wlv->text_prop_above_count
354#endif
355 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100356
Bram Moolenaard7657e92022-09-20 18:59:30 +0100357 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100358 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100359 // there is no line number in a wrapped line when "n" is in
360 // 'cpoptions', but 'breakindent' assumes it anyway.
361 && !((has_cpo_n
362#ifdef FEAT_LINEBREAK
363 && !wp->w_p_bri
364#endif
365 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100366 {
367#ifdef FEAT_SIGNS
368 // If 'signcolumn' is set to 'number' and a sign is present
369 // in 'lnum', then display the sign instead of the line
370 // number.
371 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
372 get_sign_display_info(TRUE, wp, wlv);
373 else
374#endif
375 {
376 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100377 // When there are text properties above the line put the line number
378 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100379 if (wlv->row == lnum_row
Bram Moolenaareb4de622022-10-15 13:42:17 +0100380 && (wp->w_skipcol == 0 || wlv->row > wp->w_winrow
381 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100382 {
383 long num;
384 char *fmt = "%*ld ";
385
386 if (wp->w_p_nu && !wp->w_p_rnu)
387 // 'number' + 'norelativenumber'
388 num = (long)wlv->lnum;
389 else
390 {
391 // 'relativenumber', don't use negative numbers
392 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
393 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
394 {
395 // 'number' + 'relativenumber'
396 num = wlv->lnum;
397 fmt = "%-*ld ";
398 }
399 }
400
401 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100402 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100403 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
404 ++wlv->p_extra)
405 *wlv->p_extra = '-';
406#ifdef FEAT_RIGHTLEFT
407 if (wp->w_p_rl) // reverse line numbers
408 {
409 char_u *p1, *p2;
410 int t;
411
412 // like rl_mirror(), but keep the space at the end
413 p2 = skipwhite(wlv->extra);
414 p2 = skiptowhite(p2) - 1;
415 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
416 {
417 t = *p1;
418 *p1 = *p2;
419 *p2 = t;
420 }
421 }
422#endif
423 wlv->p_extra = wlv->extra;
424 wlv->c_extra = NUL;
425 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100426 }
427 else
428 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100429 wlv->c_extra = ' ';
430 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100431 }
432 wlv->n_extra = number_width(wp) + 1;
433 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
434#ifdef FEAT_SYN_HL
435 // When 'cursorline' is set highlight the line number of
436 // the current line differently.
437 // When 'cursorlineopt' does not have "line" only
438 // highlight the line number itself.
439 // TODO: Can we use CursorLine instead of CursorLineNr
440 // when CursorLineNr isn't set?
441 if (wp->w_p_cul
442 && wlv->lnum == wp->w_cursor.lnum
443 && (wp->w_p_culopt_flags & CULOPT_NBR)
444 && (wlv->row == wlv->startrow + wlv->filler_lines
445 || (wlv->row > wlv->startrow + wlv->filler_lines
446 && (wp->w_p_culopt_flags & CULOPT_LINE))))
447 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
448#endif
449 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
450 && HL_ATTR(HLF_LNA) != 0)
451 // Use LineNrAbove
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
453 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
454 && HL_ATTR(HLF_LNB) != 0)
455 // Use LineNrBelow
456 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
457 }
458#ifdef FEAT_SIGNS
459 if (num_attr)
460 wlv->char_attr = num_attr;
461#endif
462 }
463}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100464
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100465#ifdef FEAT_LINEBREAK
466 static void
467handle_breakindent(win_T *wp, winlinevars_T *wlv)
468{
469 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100470 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100471 // draw indent after showbreak value
472 wlv->draw_state = WL_BRI;
473 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
474 // After the showbreak, draw the breakindent
475 wlv->draw_state = WL_BRI - 1;
476
477 // draw 'breakindent': indent wrapped text accordingly
478 if (wlv->draw_state == WL_BRI - 1)
479 {
480 wlv->draw_state = WL_BRI;
481 // if wlv->need_showbreak is set, breakindent also applies
482 if (wp->w_p_bri && (wlv->row != wlv->startrow || wlv->need_showbreak)
483# ifdef FEAT_DIFF
484 && wlv->filler_lines == 0
485# endif
486# ifdef FEAT_PROP_POPUP
487 && !wlv->dont_use_showbreak
488# endif
489 )
490 {
491 wlv->char_attr = 0;
492# ifdef FEAT_DIFF
493 if (wlv->diff_hlf != (hlf_T)0)
494 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
495# endif
496 wlv->p_extra = NULL;
497 wlv->c_extra = ' ';
498 wlv->c_final = NUL;
499 wlv->n_extra = get_breakindent_win(wp,
500 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
501 if (wlv->row == wlv->startrow)
502 {
503 wlv->n_extra -= win_col_off2(wp);
504 if (wlv->n_extra < 0)
505 wlv->n_extra = 0;
506 }
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100507 if (wp->w_skipcol > 0 && wlv->startrow == 0
508 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100509 wlv->need_showbreak = FALSE;
510 // Correct end of highlighted area for 'breakindent',
511 // required when 'linebreak' is also set.
512 if (wlv->tocol == wlv->vcol)
513 wlv->tocol += wlv->n_extra;
514 }
515 }
516}
517#endif
518
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100519#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
520 static void
521handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
522{
523# ifdef FEAT_DIFF
524 if (wlv->filler_todo > 0)
525 {
526 // Draw "deleted" diff line(s).
527 if (char2cells(wp->w_fill_chars.diff) > 1)
528 {
529 wlv->c_extra = '-';
530 wlv->c_final = NUL;
531 }
532 else
533 {
534 wlv->c_extra = wp->w_fill_chars.diff;
535 wlv->c_final = NUL;
536 }
537# ifdef FEAT_RIGHTLEFT
538 if (wp->w_p_rl)
539 wlv->n_extra = wlv->col + 1;
540 else
541# endif
542 wlv->n_extra = wp->w_width - wlv->col;
543 wlv->char_attr = HL_ATTR(HLF_DED);
544 }
545# endif
546
547# ifdef FEAT_LINEBREAK
548 char_u *sbr = get_showbreak_value(wp);
549 if (*sbr != NUL && wlv->need_showbreak)
550 {
551 // Draw 'showbreak' at the start of each broken line.
552 wlv->p_extra = sbr;
553 wlv->c_extra = NUL;
554 wlv->c_final = NUL;
555 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaar693729a2022-10-02 22:10:25 +0100556 if (wp->w_skipcol == 0 || wlv->startrow != 0 || !wp->w_p_wrap)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100557 wlv->need_showbreak = FALSE;
558 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
559 // Correct end of highlighted area for 'showbreak',
560 // required when 'linebreak' is also set.
561 if (wlv->tocol == wlv->vcol)
562 wlv->tocol += wlv->n_extra;
563 // combine 'showbreak' with 'wincolor'
564 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
565# ifdef FEAT_SYN_HL
566 // combine 'showbreak' with 'cursorline'
567 if (wlv->cul_attr != 0)
568 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
569# endif
570 }
571# endif
572}
573#endif
574
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100575#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100576/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100577 * Return the cell size of virtual text after truncation.
578 */
579 static int
580textprop_size_after_trunc(
581 win_T *wp,
582 int flags, // TP_FLAG_ALIGN_*
583 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100584 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100585 char_u *text,
586 int *n_used_ptr)
587{
588 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100589 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100590 int len = (int)STRLEN(text);
591 int strsize = 0;
592 int n_used;
593
Bram Moolenaar7e017462022-10-11 21:02:09 +0100594 // if the remaining size is to small and 'wrap' is set we wrap anyway and
595 // use the next line
596 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100597 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100598 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100599 space -= padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100600 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
601 {
602 int clen = ptr2cells(text + n_used);
603
604 if (strsize + clen > space)
605 break;
606 strsize += clen;
607 }
608 *n_used_ptr = n_used;
609 return strsize;
610}
611
612/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100613 * Take care of padding, right-align and truncation of virtual text after a
614 * line.
615 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
616 * padding, right-align and truncation. Otherwise only the size is computed.
617 * When "n_attr" is NULL returns the number of screen cells used.
618 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100619 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100620 int
621text_prop_position(
622 win_T *wp,
623 textprop_T *tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100624 int vcol UNUSED, // current text column
625 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100626 int *n_extra, // nr of bytes for virtual text
627 char_u **p_extra, // virtual text
628 int *n_attr, // attribute cells, NULL if not used
629 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100631 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100632 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100633 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
634 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
635 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
636 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100637 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100638 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100639 int before = room; // spaces before the text
640 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100641 int n_used = *n_extra;
642 char_u *l = NULL;
643 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100644 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100645 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar1206c162022-10-10 15:40:04 +0100646 int cont_on_next_line = below && col_with_padding > win_col_off(wp)
647 && !wp->w_p_wrap;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200648
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100649 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100650 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100651 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100652 int skip_add = 0;
653
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100654 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100655 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100656 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100657 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100658 }
659 else
660 {
661 // Right-align: fill with before
662 if (right)
663 before -= cells;
664 if (before < 0
665 || !(right || below)
666 || (below
Bram Moolenaarccf28372022-10-10 21:10:03 +0100667 ? (col_with_padding <= col_off || !wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100668 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100669 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100670 if (right && (wrap
671 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100672 {
673 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 before = wp->w_width - col_off - strsize + room;
675 if (before < 0)
676 before = 0;
677 else
678 n_used = *n_extra;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100679 skip_add = col_off;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100680 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100681 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100683 }
Bram Moolenaar2fdc9b52022-09-20 15:59:22 +0100684 else if (below && before > 0)
685 // include 'number' column et al.
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100686 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100688
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 // With 'nowrap' add one to show the "extends" character if needed (it
690 // doesn't show if the text just fits).
691 if (!wp->w_p_wrap
692 && n_used < *n_extra
693 && wp->w_lcs_chars.ext != NUL
694 && wp->w_p_list)
695 ++n_used;
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100696 if (!wp->w_p_wrap && below && padding > 0)
697 skip_add = col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100698
699 // add 1 for NUL, 2 for when '…' is used
700 if (n_attr != NULL)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100701 l = alloc(n_used + before + after + padding + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100702 if (n_attr == NULL || l != NULL)
703 {
704 int off = 0;
705
706 if (n_attr != NULL)
707 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 vim_memset(l, ' ', before);
709 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100710 if (padding > 0)
711 {
712 vim_memset(l + off, ' ', padding);
713 off += padding;
714 }
715 vim_strncpy(l + off, *p_extra, n_used);
716 off += n_used;
717 }
718 else
719 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100720 off = before + after + padding + n_used;
721 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100722 }
723 if (n_attr != NULL)
724 {
725 if (n_used < *n_extra && wp->w_p_wrap)
726 {
727 char_u *lp = l + off - 1;
728
729 if (has_mbyte)
730 {
731 // change last character to '…'
732 lp -= (*mb_head_off)(l, lp);
733 STRCPY(lp, "…");
Bram Moolenaar13845c42022-10-09 15:26:03 +0100734 n_used = lp - l + 3 - before - padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100735 }
736 else
737 // change last character to '>'
738 *lp = '>';
739 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100740 else if (after > 0)
741 {
742 vim_memset(l + off, ' ', after);
743 l[off + after] = NUL;
744 }
745
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100746 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100748 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100749 if (above)
Bram Moolenaarccfaa072022-09-20 16:15:30 +0100750 *n_attr -= padding + after;
Bram Moolenaar1206c162022-10-10 15:40:04 +0100751
752 // Add "skip_add" when starting a new line or wrapping,
753 // n_attr_skip will then be decremented in the number column.
754 *n_attr_skip = before + padding
755 + (cont_on_next_line || before > 0 ? skip_add : 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100756 }
757 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100758 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100759
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100760 if (n_attr == NULL)
761 return cells;
762 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763}
764#endif
765
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100766/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100767 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100768 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
769 * when 'showbreak' is not set.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100770 */
771 static void
772wlv_screen_line(win_T *wp, winlinevars_T *wlv, int negative_width)
773{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100774 if (wlv->row == 0 && wp->w_skipcol > 0
775#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100776 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100777 && *get_showbreak_value(wp) == NUL
778#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100779 // do not overwrite the 'listchars' "precedes" text with "<<<"
780 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100781 {
782 int off = (int)(current_ScreenLine - ScreenLines);
Bram Moolenaareb4de622022-10-15 13:42:17 +0100783 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100784
Bram Moolenaareb4de622022-10-15 13:42:17 +0100785 if (wp->w_p_nu && wp->w_p_rnu)
786 // Do not overwrite the line number, change "123 text" to
787 // "123>>>xt".
788 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
789 {
790 ++off;
791 ++skip;
792 }
793
794 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100795 {
796 ScreenLines[off] = '<';
797 if (enc_utf8)
798 ScreenLinesUC[off] = 0;
799 ScreenAttrs[off] = HL_ATTR(HLF_AT);
800 ++off;
801 }
802 }
803
804 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
805 negative_width ? -wp->w_width : wp->w_width,
806 wlv->screen_line_flags);
807}
808
809/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100810 * Called when finished with the line: draw the screen line and handle any
811 * highlighting until the right of the window.
812 */
813 static void
814draw_screen_line(win_T *wp, winlinevars_T *wlv)
815{
816#ifdef FEAT_SYN_HL
817 long v;
818
819 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
820 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100821 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100822 else
823 v = wp->w_leftcol;
824
825 // check if line ends before left margin
826 if (wlv->vcol < v + wlv->col - win_col_off(wp))
827 wlv->vcol = v + wlv->col - win_col_off(wp);
828# ifdef FEAT_CONCEAL
829 // Get rid of the boguscols now, we want to draw until the right
830 // edge for 'cursorcolumn'.
831 wlv->col -= wlv->boguscols;
832 wlv->boguscols = 0;
833# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
834# else
835# define VCOL_HLC (wlv->vcol)
836# endif
837
838 if (wlv->draw_color_col)
839 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
840
841 if (((wp->w_p_cuc
842 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
843 && (int)wp->w_virtcol <
844 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
845 && wlv->lnum != wp->w_cursor.lnum)
846 || wlv->draw_color_col
847 || wlv->win_attr != 0)
848# ifdef FEAT_RIGHTLEFT
849 && !wp->w_p_rl
850# endif
851 )
852 {
853 int rightmost_vcol = 0;
854 int i;
855
856 if (wp->w_p_cuc)
857 rightmost_vcol = wp->w_virtcol;
858 if (wlv->draw_color_col)
859 // determine rightmost colorcolumn to possibly draw
860 for (i = 0; wlv->color_cols[i] >= 0; ++i)
861 if (rightmost_vcol < wlv->color_cols[i])
862 rightmost_vcol = wlv->color_cols[i];
863
864 while (wlv->col < wp->w_width)
865 {
866 ScreenLines[wlv->off] = ' ';
867 if (enc_utf8)
868 ScreenLinesUC[wlv->off] = 0;
869 ScreenCols[wlv->off] = MAXCOL;
870 ++wlv->col;
871 if (wlv->draw_color_col)
872 wlv->draw_color_col = advance_color_col(
873 VCOL_HLC, &wlv->color_cols);
874
875 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
876 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
877 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
878 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
879 else
880 ScreenAttrs[wlv->off++] = wlv->win_attr;
881
882 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
883 break;
884
885 ++wlv->vcol;
886 }
887 }
888#endif
889
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100890 wlv_screen_line(wp, wlv, FALSE);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100891 ++wlv->row;
892 ++wlv->screen_row;
893}
894#undef VCOL_HLC
895
896/*
897 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100898 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100899 */
900 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100901win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902{
903 wlv->col = 0;
904 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
905
906#ifdef FEAT_RIGHTLEFT
907 if (wp->w_p_rl)
908 {
909 // Rightleft window: process the text in the normal direction, but put
910 // it in current_ScreenLine[] from right to left. Start at the
911 // rightmost column of the window.
912 wlv->col = wp->w_width - 1;
913 wlv->off += wlv->col;
914 wlv->screen_line_flags |= SLF_RIGHTLEFT;
915 }
916#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100917 if (save_extra)
918 {
919 // reset the drawing state for the start of a wrapped line
920 wlv->draw_state = WL_START;
921 wlv->saved_n_extra = wlv->n_extra;
922 wlv->saved_p_extra = wlv->p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000923 wlv->saved_extra_attr = wlv->extra_attr;
924 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100925 wlv->saved_c_extra = wlv->c_extra;
926 wlv->saved_c_final = wlv->c_final;
927#ifdef FEAT_SYN_HL
928 if (!(wlv->cul_screenline
929# ifdef FEAT_DIFF
930 && wlv->diff_hlf == (hlf_T)0
931# endif
932 ))
933 wlv->saved_char_attr = wlv->char_attr;
934 else
935#endif
936 wlv->saved_char_attr = 0;
937 wlv->n_extra = 0;
938 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100939}
940
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200941/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100942 * Called when wlv->draw_state is set to WL_LINE.
943 */
944 static void
945win_line_continue(winlinevars_T *wlv)
946{
947 if (wlv->saved_n_extra > 0)
948 {
949 // Continue item from end of wrapped line.
950 wlv->n_extra = wlv->saved_n_extra;
951 wlv->c_extra = wlv->saved_c_extra;
952 wlv->c_final = wlv->saved_c_final;
953 wlv->p_extra = wlv->saved_p_extra;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000954 wlv->extra_attr = wlv->saved_extra_attr;
955 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100956 wlv->char_attr = wlv->saved_char_attr;
957 }
958 else
959 wlv->char_attr = wlv->win_attr;
960}
961
962/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200963 * Display line "lnum" of window 'wp' on the screen.
964 * Start at row "startrow", stop when "endrow" is reached.
965 * wp->w_virtcol needs to be valid.
966 *
967 * Return the number of last row the line occupies.
968 */
969 int
970win_line(
971 win_T *wp,
972 linenr_T lnum,
973 int startrow,
974 int endrow,
975 int nochange UNUSED, // not updating for changed text
976 int number_only) // only update the number column
977{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100978 winlinevars_T wlv; // variables passed between functions
979
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100981 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200982 char_u *line; // current line
983 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984
Bram Moolenaar1306b362022-08-06 15:59:06 +0100985#ifdef FEAT_PROP_POPUP
986 char_u *p_extra_free2 = NULL; // another p_extra to be freed
987#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000988#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000989 int in_linebreak = FALSE; // n_extra set for showing linebreak
990#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200991 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100992 // displaying eol at end-of-line
993 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000994 int lcs_prec_todo = wp->w_lcs_chars.prec;
995 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200996
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100997 int n_attr = 0; // chars with special attr
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000998 int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100999 int saved_attr2 = 0; // char_attr saved for n_attr
1000 int n_attr3 = 0; // chars with overruling special attr
1001 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001002
Bram Moolenaarcd105412022-10-10 19:50:42 +01001003 int n_skip = 0; // nr of cells to skip for 'nowrap' or
1004 // concealing
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001005#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001006 int skip_cells = 0; // nr of cells to skip for virtual text
1007 // after the line, when w_skipcol is
1008 // larger than the text length
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001009#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001010
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 int fromcol_prev = -2; // start of inverting after cursor
1012 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 int lnum_in_visual_area = FALSE;
1014 pos_T pos;
1015 long v;
1016
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001017 int attr_pri = FALSE; // char_attr has priority
1018 int area_highlighting = FALSE; // Visual or incsearch highlighting
1019 // in this line
1020 int vi_attr = 0; // attributes for Visual and incsearch
1021 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022 int area_attr = 0; // attributes desired by highlighting
1023 int search_attr = 0; // attributes desired by 'hlsearch'
1024#ifdef FEAT_SYN_HL
1025 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1026 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001027 int prev_syntax_col = -1; // column of prev_syntax_attr
1028 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001029 int has_syntax = FALSE; // this buffer has syntax highl.
1030 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001032#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 int text_prop_count;
1034 int text_prop_next = 0; // next text property to use
1035 textprop_T *text_props = NULL;
1036 int *text_prop_idxs = NULL;
1037 int text_props_active = 0;
1038 proptype_T *text_prop_type = NULL;
1039 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001040 int text_prop_attr_comb = 0; // text_prop_attr combined with
1041 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001042 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001043 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001044 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001045 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001046 int saved_search_attr = 0; // search_attr to be used when n_extra
1047 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001048 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001049#endif
1050#ifdef FEAT_SPELL
1051 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001052 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001053# define SPWORDLEN 150
1054 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1055 int nextlinecol = 0; // column where nextline[] starts
1056 int nextline_idx = 0; // index in nextline[] where next line
1057 // starts
1058 int spell_attr = 0; // attributes desired by spelling
1059 int word_end = 0; // last byte with same spell_attr
1060 static linenr_T checked_lnum = 0; // line number for "checked_col"
1061 static int checked_col = 0; // column in "checked_lnum" up to which
1062 // there are no spell errors
1063 static int cap_col = -1; // column to check for Cap word
1064 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
1065 int cur_checked_col = 0; // checked column for current line
1066#endif
1067 int extra_check = 0; // has extra highlighting
1068 int multi_attr = 0; // attributes desired by multibyte
1069 int mb_l = 1; // multi-byte byte length
1070 int mb_c = 0; // decoded multi-byte character
1071 int mb_utf8 = FALSE; // screen char is UTF-8 char
1072 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074 int change_start = MAXCOL; // first col of changed area
1075 int change_end = -1; // last col of changed area
1076#endif
1077 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001078 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001079 int in_multispace = FALSE; // in multiple consecutive spaces
1080 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001081#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
1082 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
1083# define LINE_ATTR
1084 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +01001085 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001088 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001089#ifdef FEAT_ARABIC
1090 int prev_c = 0; // previous Arabic character
1091 int prev_c1 = 0; // first composing char for prev_c
1092#endif
1093#if defined(LINE_ATTR)
1094 int did_line_attr = 0;
1095#endif
1096#ifdef FEAT_TERMINAL
1097 int get_term_attr = FALSE;
1098#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099
Martin Tournoijba43e762022-10-13 22:12:15 +01001100#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101 // margin columns for the screen line, needed for when 'cursorlineopt'
1102 // contains "screenline"
1103 int left_curline_col = 0;
1104 int right_curline_col = 0;
1105#endif
1106
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001107#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1108 int feedback_col = 0;
1109 int feedback_old_attr = -1;
1110#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111
1112#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1113 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001114#endif
1115#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001116 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117#endif
1118#ifdef FEAT_CONCEAL
1119 int syntax_flags = 0;
1120 int syntax_seqnr = 0;
1121 int prev_syntax_id = 0;
1122 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1123 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001124 int did_wcol = FALSE;
1125 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001126# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001127# define FIX_FOR_BOGUSCOLS \
1128 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +01001129 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001130 wlv.vcol -= wlv.vcol_off; \
1131 wlv.vcol_off = 0; \
1132 wlv.col -= wlv.boguscols; \
1133 old_boguscols = wlv.boguscols; \
1134 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135 }
1136#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138#endif
1139
1140 if (startrow > endrow) // past the end already!
1141 return startrow;
1142
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001143 CLEAR_FIELD(wlv);
1144
1145 wlv.lnum = lnum;
1146 wlv.startrow = startrow;
1147 wlv.row = startrow;
1148 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001149 wlv.fromcol = -10;
1150 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001151#ifdef FEAT_LINEBREAK
1152 wlv.vcol_sbr = -1;
1153#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154
1155 if (!number_only)
1156 {
1157 // To speed up the loop below, set extra_check when there is linebreak,
1158 // trailing white space and/or syntax processing to be done.
1159#ifdef FEAT_LINEBREAK
1160 extra_check = wp->w_p_lbr;
1161#endif
1162#ifdef FEAT_SYN_HL
1163 if (syntax_present(wp) && !wp->w_s->b_syn_error
1164# ifdef SYN_TIME_LIMIT
1165 && !wp->w_s->b_syn_slow
1166# endif
1167 )
1168 {
1169 // Prepare for syntax highlighting in this line. When there is an
1170 // error, stop syntax highlighting.
1171 save_did_emsg = did_emsg;
1172 did_emsg = FALSE;
1173 syntax_start(wp, lnum);
1174 if (did_emsg)
1175 wp->w_s->b_syn_error = TRUE;
1176 else
1177 {
1178 did_emsg = save_did_emsg;
1179#ifdef SYN_TIME_LIMIT
1180 if (!wp->w_s->b_syn_slow)
1181#endif
1182 {
1183 has_syntax = TRUE;
1184 extra_check = TRUE;
1185 }
1186 }
1187 }
1188
1189 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001190 wlv.color_cols = wp->w_p_cc_cols;
1191 if (wlv.color_cols != NULL)
1192 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193#endif
1194
1195#ifdef FEAT_TERMINAL
1196 if (term_show_buffer(wp->w_buffer))
1197 {
1198 extra_check = TRUE;
1199 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001200 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201 }
1202#endif
1203
1204#ifdef FEAT_SPELL
Bram Moolenaaree09fcc2022-09-25 20:58:30 +01001205 if (spell_check_window(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206 {
1207 // Prepare for spell checking.
1208 has_spell = TRUE;
1209 extra_check = TRUE;
1210
1211 // Get the start of the next line, so that words that wrap to the
1212 // next line are found too: "et<line-break>al.".
1213 // Trick: skip a few chars for C/shell/Vim comments
1214 nextline[SPWORDLEN] = NUL;
1215 if (lnum < wp->w_buffer->b_ml.ml_line_count)
1216 {
1217 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1218 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1219 }
1220
1221 // When a word wrapped from the previous line the start of the
1222 // current line is valid.
1223 if (lnum == checked_lnum)
1224 cur_checked_col = checked_col;
1225 checked_lnum = 0;
1226
1227 // When there was a sentence end in the previous line may require a
1228 // word starting with capital in this line. In line 1 always check
1229 // the first word.
1230 if (lnum != capcol_lnum)
1231 cap_col = -1;
1232 if (lnum == 1)
1233 cap_col = 0;
1234 capcol_lnum = 0;
1235 }
1236#endif
1237
1238 // handle Visual active in this window
1239 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1240 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001241 pos_T *top, *bot;
1242
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1244 {
1245 // Visual is after curwin->w_cursor
1246 top = &curwin->w_cursor;
1247 bot = &VIsual;
1248 }
1249 else
1250 {
1251 // Visual is before curwin->w_cursor
1252 top = &VIsual;
1253 bot = &curwin->w_cursor;
1254 }
1255 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1256 if (VIsual_mode == Ctrl_V)
1257 {
1258 // block mode
1259 if (lnum_in_visual_area)
1260 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001261 wlv.fromcol = wp->w_old_cursor_fcol;
1262 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 }
1265 else
1266 {
1267 // non-block mode
1268 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001269 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270 else if (lnum == top->lnum)
1271 {
1272 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001273 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 else
1275 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001276 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001277 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001278 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 }
1280 }
1281 if (VIsual_mode != 'V' && lnum == bot->lnum)
1282 {
1283 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1284 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001285 wlv.fromcol = -10;
1286 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001287 }
1288 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001289 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290 else
1291 {
1292 pos = *bot;
1293 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001294 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1295 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001296 else
1297 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001298 getvvcol(wp, &pos, NULL, NULL,
1299 (colnr_T *)&wlv.tocol);
1300 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 }
1302 }
1303 }
1304 }
1305
1306 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001307 if (!highlight_match && lnum == curwin->w_cursor.lnum
1308 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309#ifdef FEAT_GUI
1310 && !gui.in_use
1311#endif
1312 )
1313 noinvcur = TRUE;
1314
1315 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001316 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 {
1318 area_highlighting = TRUE;
1319 vi_attr = HL_ATTR(HLF_V);
1320#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1321 if ((clip_star.available && !clip_star.owned
1322 && clip_isautosel_star())
1323 || (clip_plus.available && !clip_plus.owned
1324 && clip_isautosel_plus()))
1325 vi_attr = HL_ATTR(HLF_VNC);
1326#endif
1327 }
1328 }
1329
1330 // handle 'incsearch' and ":s///c" highlighting
1331 else if (highlight_match
1332 && wp == curwin
1333 && lnum >= curwin->w_cursor.lnum
1334 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1335 {
1336 if (lnum == curwin->w_cursor.lnum)
1337 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001338 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001340 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001341 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1342 {
1343 pos.lnum = lnum;
1344 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001345 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 }
1347 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001348 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001349 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001350 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1351 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 area_highlighting = TRUE;
1353 vi_attr = HL_ATTR(HLF_I);
1354 }
1355 }
1356
1357#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001358 wlv.filler_lines = diff_check(wp, lnum);
1359 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001360 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001361 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
1363 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001368 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001371 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001372 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001373 area_highlighting = TRUE;
1374 }
1375 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001376 wlv.filler_lines = wp->w_topfill;
1377 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378#endif
1379
1380#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001381 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001382 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001383 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001384#endif
1385
1386#ifdef LINE_ATTR
1387# ifdef FEAT_SIGNS
1388 // If this line has a sign with line highlighting set line_attr.
1389 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001390 line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001391# endif
1392# if defined(FEAT_QUICKFIX)
1393 // Highlight the current line in the quickfix window.
1394 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
1395 line_attr = HL_ATTR(HLF_QFL);
1396# endif
1397 if (line_attr != 0)
1398 area_highlighting = TRUE;
1399#endif
1400
1401 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1402 ptr = line;
1403
1404#ifdef FEAT_SPELL
1405 if (has_spell && !number_only)
1406 {
1407 // For checking first word with a capital skip white space.
1408 if (cap_col == 0)
1409 cap_col = getwhitecols(line);
1410
1411 // To be able to spell-check over line boundaries copy the end of the
1412 // current line into nextline[]. Above the start of the next line was
1413 // copied to nextline[SPWORDLEN].
1414 if (nextline[SPWORDLEN] == NUL)
1415 {
1416 // No next line or it is empty.
1417 nextlinecol = MAXCOL;
1418 nextline_idx = 0;
1419 }
1420 else
1421 {
1422 v = (long)STRLEN(line);
1423 if (v < SPWORDLEN)
1424 {
1425 // Short line, use it completely and append the start of the
1426 // next line.
1427 nextlinecol = 0;
1428 mch_memmove(nextline, line, (size_t)v);
1429 STRMOVE(nextline + v, nextline + SPWORDLEN);
1430 nextline_idx = v + 1;
1431 }
1432 else
1433 {
1434 // Long line, use only the last SPWORDLEN bytes.
1435 nextlinecol = v - SPWORDLEN;
1436 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1437 nextline_idx = SPWORDLEN + 1;
1438 }
1439 }
1440 }
1441#endif
1442
1443 if (wp->w_p_list)
1444 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001445 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001446 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001447 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001448 || wp->w_lcs_chars.trail
1449 || wp->w_lcs_chars.lead
1450 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001452
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001454 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 {
1456 trailcol = (colnr_T)STRLEN(ptr);
1457 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1458 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001459 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001461 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001462 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001463 {
1464 leadcol = 0;
1465 while (VIM_ISWHITE(ptr[leadcol]))
1466 ++leadcol;
1467 if (ptr[leadcol] == NUL)
1468 // in a line full of spaces all of them are treated as trailing
1469 leadcol = (colnr_T)0;
1470 else
1471 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001472 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001473 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 }
1475
Bram Moolenaard7657e92022-09-20 18:59:30 +01001476 wlv.wcr_attr = get_wcr_attr(wp);
1477 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001479 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001480 area_highlighting = TRUE;
1481 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001482
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001483#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001485 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486#endif
1487
1488 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1489 // first character to be displayed.
1490 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +01001491 v = startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 else
1493 v = wp->w_leftcol;
1494 if (v > 0 && !number_only)
1495 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001496 char_u *prev_ptr = ptr;
1497 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001498 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001500 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001501 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001503 charsize = win_lbr_chartabsize(&cts, NULL);
1504 cts.cts_vcol += charsize;
1505 prev_ptr = cts.cts_ptr;
1506 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001509 ptr = cts.cts_ptr;
1510 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511
1512 // When:
1513 // - 'cuc' is set, or
1514 // - 'colorcolumn' is set, or
1515 // - 'virtualedit' is set, or
1516 // - the visual mode is active,
1517 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001518 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001519#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001520 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001521#endif
1522 virtual_active() ||
1523 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001524 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001525
1526 // Handle a character that's not completely on the screen: Put ptr at
1527 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001528 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001529 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001530 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001531 ptr = prev_ptr;
1532 // If the character fits on the screen, don't need to skip it.
1533 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001534 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1535 && wlv.col == 0)
1536 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 }
1538
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001539#ifdef FEAT_PROP_POPUP
Bram Moolenaarcd105412022-10-10 19:50:42 +01001540 // If there the text doesn't reach to the desired column, need to skip
1541 // "skip_cells" cells when virtual text follows.
1542 if (!wp->w_p_wrap && v > wlv.vcol)
1543 skip_cells = v - wlv.vcol;
Bram Moolenaard3283fb2022-10-10 20:33:25 +01001544#endif
Bram Moolenaarcd105412022-10-10 19:50:42 +01001545
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001546 // Adjust for when the inverted text is before the screen,
1547 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001548 if (wlv.tocol <= wlv.vcol)
1549 wlv.fromcol = 0;
1550 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1551 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552
1553#ifdef FEAT_LINEBREAK
1554 // When w_skipcol is non-zero, first line needs 'showbreak'
1555 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001556 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001557#endif
1558#ifdef FEAT_SPELL
1559 // When spell checking a word we need to figure out the start of the
1560 // word and if it's badly spelled or not.
1561 if (has_spell)
1562 {
1563 int len;
1564 colnr_T linecol = (colnr_T)(ptr - line);
1565 hlf_T spell_hlf = HLF_COUNT;
1566
1567 pos = wp->w_cursor;
1568 wp->w_cursor.lnum = lnum;
1569 wp->w_cursor.col = linecol;
1570 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1571
1572 // spell_move_to() may call ml_get() and make "line" invalid
1573 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1574 ptr = line + linecol;
1575
1576 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1577 {
1578 // no bad word found at line start, don't check until end of a
1579 // word
1580 spell_hlf = HLF_COUNT;
1581 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1582 }
1583 else
1584 {
1585 // bad word found, use attributes until end of word
1586 word_end = wp->w_cursor.col + len + 1;
1587
1588 // Turn index into actual attributes.
1589 if (spell_hlf != HLF_COUNT)
1590 spell_attr = highlight_attr[spell_hlf];
1591 }
1592 wp->w_cursor = pos;
1593
1594# ifdef FEAT_SYN_HL
1595 // Need to restart syntax highlighting for this line.
1596 if (has_syntax)
1597 syntax_start(wp, lnum);
1598# endif
1599 }
1600#endif
1601 }
1602
1603 // Correct highlighting for cursor that can't be disabled.
1604 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001605 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 {
1607 if (noinvcur)
1608 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001609 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 {
1611 // highlighting starts at cursor, let it start just after the
1612 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001613 fromcol_prev = wlv.fromcol;
1614 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001616 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 // restart highlighting after the cursor
1618 fromcol_prev = wp->w_virtcol;
1619 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001620 if (wlv.fromcol >= wlv.tocol)
1621 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 }
1623
1624#ifdef FEAT_SEARCH_EXTRA
1625 if (!number_only)
1626 {
1627 v = (long)(ptr - line);
1628 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1629 &line, &screen_search_hl,
1630 &search_attr);
1631 ptr = line + v; // "line" may have been updated
1632 }
1633#endif
1634
1635#ifdef FEAT_SYN_HL
1636 // Cursor line highlighting for 'cursorline' in the current window.
1637 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1638 {
1639 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001640 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641 if (!(wp == curwin && VIsual_active)
1642 && wp->w_p_culopt_flags != CULOPT_NBR)
1643 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001644 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001645 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1646
1647 // Only set line_attr here when "screenline" is not present in
1648 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001649 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001650 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001651 wlv.cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001652# ifdef FEAT_SIGNS
1653 // Combine the 'cursorline' and sign highlighting, depending on
1654 // the sign priority.
Bram Moolenaard7657e92022-09-20 18:59:30 +01001655 if (sign_present && wlv.sattr.sat_linehl > 0)
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001656 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001657 if (wlv.sattr.sat_priority >= 100)
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001658 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001659 else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001660 line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001661 }
1662 else
1663# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001664# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001665 // let the line attribute overrule 'cursorline', otherwise
1666 // it disappears when both have background set;
1667 // 'cursorline' can use underline or bold to make it show
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001668 line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001669# else
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001670 line_attr = wlv.cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001671# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001672 }
1673 else
1674 {
1675 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001676 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1677 }
1678 area_highlighting = TRUE;
1679 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001680 }
1681#endif
1682
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001683#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 {
1685 char_u *prop_start;
1686
1687 text_prop_count = get_text_props(wp->w_buffer, lnum,
1688 &prop_start, FALSE);
1689 if (text_prop_count > 0)
1690 {
1691 // Make a copy of the properties, so that they are properly
1692 // aligned.
1693 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1694 if (text_props != NULL)
1695 mch_memmove(text_props, prop_start,
1696 text_prop_count * sizeof(textprop_T));
1697
1698 // Allocate an array for the indexes.
1699 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001700 if (text_prop_idxs == NULL)
1701 VIM_CLEAR(text_props);
1702
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001703 if (text_props != NULL)
1704 {
1705 area_highlighting = TRUE;
1706 extra_check = TRUE;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +01001707 // text props "above" move the line number down to where the
1708 // text is.
Bram Moolenaarec5e1482022-09-21 16:38:13 +01001709 for (int i = 0; i < text_prop_count; ++i)
1710 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1711 ++wlv.text_prop_above_count;
1712 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713 }
1714 }
1715#endif
1716
Bram Moolenaar1306b362022-08-06 15:59:06 +01001717 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718
1719 // Repeat for the whole displayed line.
1720 for (;;)
1721 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001722 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001724 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725#endif
1726#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001727 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001728#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001729
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001730 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001731 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001733#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001734 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001735 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001736 wlv.cul_attr = 0;
zeertzjq4f33bc22021-08-05 17:57:02 +02001737 line_attr = line_attr_save;
1738 }
1739#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001740 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001742 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001743 if (cmdwin_type != 0 && wp == curwin)
1744 {
1745 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001746 wlv.n_extra = 1;
1747 wlv.c_extra = cmdwin_type;
1748 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001749 wlv.char_attr =
1750 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
1752 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001753#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001754 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001756 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001757 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758 }
1759#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001760#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001761 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001762 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001763 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001766 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001767 }
1768#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001769 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001770 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001771 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001772 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001773 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001774 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001776 // Check if 'breakindent' applies and show it.
1777 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1778 if (wlv.n_extra == 0)
1779 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001781#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001782 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001784 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001785 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 }
1787#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001788 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001790 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001791 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 }
1793 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001794
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001795#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001796 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001797 && wlv.vcol >= left_curline_col
1798 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001800 wlv.cul_attr = HL_ATTR(HLF_CUL);
1801 line_attr = wlv.cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001802 }
1803#endif
1804
1805 // When still displaying '$' of change command, stop at cursor.
1806 // When only displaying the (relative) line number and that's done,
1807 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001808 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001809 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001810 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001811#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001812 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001813#endif
1814 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 {
Bram Moolenaar406b5d82022-10-03 16:44:12 +01001816 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 // Pretend we have finished updating the window. Except when
1818 // 'cursorcolumn' is set.
1819#ifdef FEAT_SYN_HL
1820 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001821 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 else
1823#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001824 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001825 break;
1826 }
1827
Bram Moolenaar1306b362022-08-06 15:59:06 +01001828 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001829 {
1830 // handle Visual or match highlighting in this line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001831 if (wlv.vcol == wlv.fromcol
1832 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
1833 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001834 && (*mb_ptr2cells)(ptr) > 1)
1835 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001836 && vcol_prev < wlv.vcol // not at margin
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001837 && wlv.vcol < wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 area_attr = vi_attr; // start highlighting
1839 else if (area_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001840 && (wlv.vcol == wlv.tocol
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001841 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 area_attr = 0; // stop highlighting
1843
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001844#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 if (text_props != NULL)
1846 {
1847 int pi;
1848 int bcol = (int)(ptr - line);
1849
Bram Moolenaar1306b362022-08-06 15:59:06 +01001850 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001851# ifdef FEAT_LINEBREAK
1852 && !in_linebreak
1853# endif
1854 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001855 --bcol; // still working on the previous char, e.g. Tab
1856
1857 // Check if any active property ends.
1858 for (pi = 0; pi < text_props_active; ++pi)
1859 {
1860 int tpi = text_prop_idxs[pi];
1861
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001862 if (text_props[tpi].tp_col != MAXCOL
1863 && bcol >= text_props[tpi].tp_col - 1
1864 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001865 {
1866 if (pi + 1 < text_props_active)
1867 mch_memmove(text_prop_idxs + pi,
1868 text_prop_idxs + pi + 1,
1869 sizeof(int)
1870 * (text_props_active - (pi + 1)));
1871 --text_props_active;
1872 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001873# ifdef FEAT_LINEBREAK
1874 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001875 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001876 syntax_attr = 0;
1877# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001878 }
1879 }
1880
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001881# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001882 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001883 // not on the next char yet, don't start another prop
1884 --bcol;
1885# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001886 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001887 // With 'nowrap' and not in the first screen line only "below"
1888 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001889 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001890 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001891 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001892 && (wp->w_p_wrap
1893 || wlv.row == startrow
1894 || (text_props[text_prop_next].tp_flags
1895 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01001896 || (bcol == 0 &&
1897 (text_props[text_prop_next].tp_flags
1898 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001899 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001900 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001901 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001902 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1903 {
1904 // first display the '$' after the line
1905 text_prop_follows = TRUE;
1906 break;
1907 }
1908 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001909 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001910 + text_props[text_prop_next].tp_len)
1911 text_prop_idxs[text_props_active++] = text_prop_next;
1912 ++text_prop_next;
1913 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001915 if (wlv.n_extra == 0 || !wlv.extra_for_textprop)
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001916 {
1917 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001918 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001919 text_prop_flags = 0;
1920 text_prop_type = NULL;
1921 text_prop_id = 0;
1922 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001925 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001926 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001927 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001928
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 // Sort the properties on priority and/or starting last.
1930 // Then combine the attributes, highest priority last.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001931 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001932 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001933 sort_text_props(wp->w_buffer, text_props,
1934 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935
1936 for (pi = 0; pi < text_props_active; ++pi)
1937 {
1938 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001939 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01001941 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942
Bram Moolenaarcd105412022-10-10 19:50:42 +01001943 // Only use a text property that can be displayed.
1944 // Skip "after" properties when wrap is off and at the
1945 // end of the window.
1946 if (pt != NULL
1947 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
1948 && tp->tp_id != -MAXCOL
1949 && !(tp->tp_id < 0
1950 && !wp->w_p_wrap
1951 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
1952 | TP_FLAG_ALIGN_ABOVE
1953 | TP_FLAG_ALIGN_BELOW)) == 0
1954 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001955 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001956 if (pt->pt_hl_id > 0)
1957 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001958 text_prop_type = pt;
1959 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001960 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001961 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01001962 text_prop_flags = pt->pt_flags;
1963 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001964 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 }
1966 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001967 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001968 && -text_prop_id
1969 <= wp->w_buffer->b_textprop_text.ga_len)
1970 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001971 textprop_T *tp = &text_props[used_tpi];
1972 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001973 ->b_textprop_text.ga_data)[
1974 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001975 int above = (tp->tp_flags
1976 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01001977 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001978
1979 // reset the ID in the copy to avoid it being used
1980 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001981 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001982
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001983 if (p != NULL)
1984 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001985 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001986 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001987 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001988 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001989 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1990 int padding = tp->tp_col == MAXCOL
1991 && tp->tp_len > 1
1992 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001993
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001994 // Insert virtual text before the current
1995 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 wlv.p_extra = p;
1997 wlv.c_extra = NUL;
1998 wlv.c_final = NUL;
1999 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002000 wlv.extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002001 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2002 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002003 n_attr = mb_charlen(p);
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002004 // restore search_attr and area_attr when n_extra
2005 // is down to zero
Bram Moolenaare38fc862022-08-11 17:24:50 +01002006 saved_search_attr = search_attr;
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01002007 saved_area_attr = area_attr;
2008 search_attr = 0;
2009 area_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002010 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002011 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002012 if (*ptr == NUL)
2013 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002014 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002015#ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002016 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002017 {
2018 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002019 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002020 wlv.need_showbreak = FALSE;
2021 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002022 }
2023#endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002024 if ((right || above || below || !wrap
2025 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002026 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002027 char_u *prev_p_extra = wlv.p_extra;
2028 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002029
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002030 // Take care of padding, right-align and
2031 // truncation.
2032 // Shared with win_lbr_chartabsize(), must do
2033 // exactly the same.
2034 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002035 wlv.vcol,
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002036 wlv.col,
2037 &wlv.n_extra, &wlv.p_extra,
2038 &n_attr, &n_attr_skip);
2039 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002040 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002041 // wlv.p_extra was allocated
2042 vim_free(p_extra_free2);
2043 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002044 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002045
Bram Moolenaara4abe512022-09-15 19:44:09 +01002046 if (lcs_eol_one < 0 && wlv.col
2047 + wlv.n_extra - 2 > wp->w_width)
2048 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002049 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002050
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002051 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002052 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002053 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002054 {
2055 draw_screen_line(wp, &wlv);
2056
2057 // When line got too long for screen break
2058 // here.
2059 if (wlv.row == endrow)
2060 {
2061 ++wlv.row;
2062 break;
2063 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002064 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002065 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002066 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002067 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002068 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002069
Bram Moolenaarcd105412022-10-10 19:50:42 +01002070 // If the text didn't reach until the first window
2071 // column we need to skip cells.
2072 if (skip_cells > 0)
2073 {
2074 if (wlv.n_extra > skip_cells)
2075 {
2076 wlv.n_extra -= skip_cells;
2077 wlv.p_extra += skip_cells;
2078 n_attr_skip -= skip_cells;
2079 if (n_attr_skip < 0)
2080 n_attr_skip = 0;
2081 skip_cells = 0;
2082 }
2083 else
2084 {
2085 // the whole text is left of the window, drop
2086 // it and advance to the next one
2087 skip_cells -= wlv.n_extra;
2088 wlv.n_extra = 0;
2089 n_attr_skip = 0;
2090 bail_out = TRUE;
2091 }
2092 }
2093
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002094 // If another text prop follows the condition below at
2095 // the last window column must know.
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002096 // If this is an "above" text prop and 'nowrap' the we
2097 // must wrap anyway.
2098 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002099 text_prop_follows |= other_tpi != -1
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002100 && (wp->w_p_wrap
2101 || (text_props[other_tpi].tp_flags
2102 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002103
2104 if (bail_out)
2105 // starting a new line for "below"
2106 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002107 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002109 else if (text_prop_next < text_prop_count
2110 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002111 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2112 || (!wp->w_p_wrap
2113 && wlv.col == wp->w_width - 1
2114 && (text_props[text_prop_next].tp_flags
2115 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002116 // When at last-but-one character and a text property
2117 // follows after it, we may need to flush the line after
2118 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002119 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002120 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002121 }
2122#endif
2123
Bram Moolenaare38fc862022-08-11 17:24:50 +01002124#ifdef FEAT_SEARCH_EXTRA
2125 if (wlv.n_extra == 0)
2126 {
2127 // Check for start/end of 'hlsearch' and other matches.
2128 // After end, check for start/end of next match.
2129 // When another match, have to check for start again.
2130 v = (long)(ptr - line);
2131 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2132 &screen_search_hl, &has_match_conc,
2133 &match_conc, did_line_attr, lcs_eol_one,
2134 &on_last_col);
2135 ptr = line + v; // "line" may have been changed
2136 prev_ptr = ptr;
2137
2138 // Do not allow a conceal over EOL otherwise EOL will be missed
2139 // and bad things happen.
2140 if (*ptr == NUL)
2141 has_match_conc = 0;
2142 }
2143#endif
2144
2145#ifdef FEAT_DIFF
2146 if (wlv.diff_hlf != (hlf_T)0)
2147 {
2148 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2149 && wlv.n_extra == 0)
2150 wlv.diff_hlf = HLF_TXD; // changed text
2151 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
2152 && wlv.n_extra == 0)
2153 wlv.diff_hlf = HLF_CHD; // changed line
2154 line_attr = HL_ATTR(wlv.diff_hlf);
2155 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2156 && wp->w_p_culopt_flags != CULOPT_NBR
2157 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2158 && wlv.vcol <= right_curline_col)))
2159 line_attr = hl_combine_attr(
2160 line_attr, HL_ATTR(HLF_CUL));
2161 }
2162#endif
2163
Bram Moolenaara74fda62019-10-19 17:38:03 +02002164#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002165 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002166 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002167 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002168# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002169 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002170 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002171# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002172 // Get syntax attribute.
2173 if (has_syntax)
2174 {
2175 // Get the syntax attribute for the character. If there
2176 // is an error, disable syntax highlighting.
2177 save_did_emsg = did_emsg;
2178 did_emsg = FALSE;
2179
2180 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002181 if (v == prev_syntax_col)
2182 // at same column again
2183 syntax_attr = prev_syntax_attr;
2184 else
2185 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002186# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002187 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002188# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002189 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002190# ifdef FEAT_SPELL
2191 has_spell ? &can_spell :
2192# endif
2193 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002194 prev_syntax_col = v;
2195 prev_syntax_attr = syntax_attr;
2196 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002197
Bram Moolenaar34390282019-10-16 14:38:26 +02002198 if (did_emsg)
2199 {
2200 wp->w_s->b_syn_error = TRUE;
2201 has_syntax = FALSE;
2202 syntax_attr = 0;
2203 }
2204 else
2205 did_emsg = save_did_emsg;
2206# ifdef SYN_TIME_LIMIT
2207 if (wp->w_s->b_syn_slow)
2208 has_syntax = FALSE;
2209# endif
2210
2211 // Need to get the line again, a multi-line regexp may
2212 // have made it invalid.
2213 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2214 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002215 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002216# ifdef FEAT_CONCEAL
2217 // no concealing past the end of the line, it interferes
2218 // with line highlighting
2219 if (*ptr == NUL)
2220 syntax_flags = 0;
2221 else
2222 syntax_flags = get_syntax_info(&syntax_seqnr);
2223# endif
2224 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002225 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002226# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002227 // Combine text property highlight into syntax highlight.
2228 if (text_prop_type != NULL)
2229 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002230 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002231 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2232 else
2233 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002234 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002235 }
2236# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002237#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002238
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002239 // Decide which of the highlight attributes to use.
2240 attr_pri = TRUE;
2241#ifdef LINE_ATTR
2242 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002243 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002244 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002245 if (!highlight_match)
2246 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002247 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002248# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002249 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002250# endif
2251 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002253 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002254 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002255# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002256 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002257# endif
2258 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002259 else if (line_attr != 0
2260 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2261 || wlv.vcol < wlv.fromcol
2262 || vcol_prev < fromcol_prev
2263 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 {
2265 // Use line_attr when not in the Visual or 'incsearch' area
2266 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002267# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002268 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002269# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002270 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002271# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002272 attr_pri = FALSE;
2273 }
2274#else
2275 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002276 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279#endif
2280 else
2281 {
2282 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002284 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002285#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002286 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002287#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002288 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002289#ifdef FEAT_PROP_POPUP
2290 // override with text property highlight when "override" is TRUE
2291 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002292 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002293#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002295
2296 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002297 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002298 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002299 if (wlv.char_attr == 0)
2300 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002301 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002302 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002303 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002304
2305 // Get the next character to put on the screen.
2306
2307 // The "p_extra" points to the extra stuff that is inserted to
2308 // represent special characters (non-printable stuff) and other
2309 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002310 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2312 // "p_extra[n_extra]".
2313 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002314 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002315 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002316 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002318 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2319 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002320 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2321 if (enc_utf8 && utf_char2len(c) > 1)
2322 {
2323 mb_utf8 = TRUE;
2324 u8cc[0] = 0;
2325 c = 0xc0;
2326 }
2327 else
2328 mb_utf8 = FALSE;
2329 }
2330 else
2331 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002332 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002333 if (has_mbyte)
2334 {
2335 mb_c = c;
2336 if (enc_utf8)
2337 {
2338 // If the UTF-8 character is more than one byte:
2339 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002340 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002342 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 mb_l = 1;
2344 else if (mb_l > 1)
2345 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002346 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 mb_utf8 = TRUE;
2348 c = 0xc0;
2349 }
2350 }
2351 else
2352 {
2353 // if this is a DBCS character, put it in "mb_c"
2354 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002355 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 mb_l = 1;
2357 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002358 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002359 }
2360 if (mb_l == 0) // at the NUL at end-of-line
2361 mb_l = 1;
2362
2363 // If a double-width char doesn't fit display a '>' in the
2364 // last column.
2365 if ((
2366# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002367 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002369 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002370 && (*mb_char2cells)(mb_c) == 2)
2371 {
2372 c = '>';
2373 mb_c = c;
2374 mb_l = 1;
2375 mb_utf8 = FALSE;
2376 multi_attr = HL_ATTR(HLF_AT);
2377#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002378 if (wlv.cul_attr)
2379 multi_attr = hl_combine_attr(
2380 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002381#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002382 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002383
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384 // put the pointer back to output the double-width
2385 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002386 ++wlv.n_extra;
2387 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002388 }
2389 else
2390 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002391 wlv.n_extra -= mb_l - 1;
2392 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 }
2394 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002395 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002397 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002398#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002399 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002400 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002401 wlv.extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002402 in_linebreak = FALSE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002403
2404 // only restore search_attr and area_attr after extra in the
2405 // next screen line is also done
2406 if (wlv.saved_n_extra <= 0)
2407 {
2408 if (search_attr == 0)
2409 search_attr = saved_search_attr;
2410 if (area_attr == 0 && *ptr != NUL)
2411 area_attr = saved_area_attr;
2412 }
Bram Moolenaare38fc862022-08-11 17:24:50 +01002413 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002414#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002415 }
2416 else
2417 {
2418#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002419 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002420#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002421 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002422
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 // Get a character from the line itself.
2424 c = *ptr;
2425#ifdef FEAT_LINEBREAK
2426 c0 = *ptr;
2427#endif
2428 if (has_mbyte)
2429 {
2430 mb_c = c;
2431 if (enc_utf8)
2432 {
2433 // If the UTF-8 character is more than one byte: Decode it
2434 // into "mb_c".
2435 mb_l = utfc_ptr2len(ptr);
2436 mb_utf8 = FALSE;
2437 if (mb_l > 1)
2438 {
2439 mb_c = utfc_ptr2char(ptr, u8cc);
2440 // Overlong encoded ASCII or ASCII with composing char
2441 // is displayed normally, except a NUL.
2442 if (mb_c < 0x80)
2443 {
2444 c = mb_c;
2445#ifdef FEAT_LINEBREAK
2446 c0 = mb_c;
2447#endif
2448 }
2449 mb_utf8 = TRUE;
2450
2451 // At start of the line we can have a composing char.
2452 // Draw it as a space with a composing char.
2453 if (utf_iscomposing(mb_c))
2454 {
2455 int i;
2456
2457 for (i = Screen_mco - 1; i > 0; --i)
2458 u8cc[i] = u8cc[i - 1];
2459 u8cc[0] = mb_c;
2460 mb_c = ' ';
2461 }
2462 }
2463
2464 if ((mb_l == 1 && c >= 0x80)
2465 || (mb_l >= 1 && mb_c == 0)
2466 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2467 {
2468 // Illegal UTF-8 byte: display as <xx>.
2469 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002470 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471# ifdef FEAT_RIGHTLEFT
2472 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002473 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002475 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002476 c = *wlv.p_extra;
2477 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002479 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2480 wlv.c_extra = NUL;
2481 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002482 if (area_attr == 0 && search_attr == 0)
2483 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002484 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002485 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002486 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002487 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 }
2489 }
2490 else if (mb_l == 0) // at the NUL at end-of-line
2491 mb_l = 1;
2492#ifdef FEAT_ARABIC
2493 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2494 {
2495 // Do Arabic shaping.
2496 int pc, pc1, nc;
2497 int pcc[MAX_MCO];
2498
2499 // The idea of what is the previous and next
2500 // character depends on 'rightleft'.
2501 if (wp->w_p_rl)
2502 {
2503 pc = prev_c;
2504 pc1 = prev_c1;
2505 nc = utf_ptr2char(ptr + mb_l);
2506 prev_c1 = u8cc[0];
2507 }
2508 else
2509 {
2510 pc = utfc_ptr2char(ptr + mb_l, pcc);
2511 nc = prev_c;
2512 pc1 = pcc[0];
2513 }
2514 prev_c = mb_c;
2515
2516 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2517 }
2518 else
2519 prev_c = mb_c;
2520#endif
2521 }
2522 else // enc_dbcs
2523 {
2524 mb_l = MB_BYTE2LEN(c);
2525 if (mb_l == 0) // at the NUL at end-of-line
2526 mb_l = 1;
2527 else if (mb_l > 1)
2528 {
2529 // We assume a second byte below 32 is illegal.
2530 // Hopefully this is OK for all double-byte encodings!
2531 if (ptr[1] >= 32)
2532 mb_c = (c << 8) + ptr[1];
2533 else
2534 {
2535 if (ptr[1] == NUL)
2536 {
2537 // head byte at end of line
2538 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002539 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540 }
2541 else
2542 {
2543 // illegal tail byte
2544 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002545 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002547 wlv.p_extra = wlv.extra;
2548 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 wlv.c_extra = NUL;
2550 wlv.c_final = NUL;
2551 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002552 if (area_attr == 0 && search_attr == 0)
2553 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002554 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002555 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002556 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 // save current attr
2558 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002559 }
2560 mb_c = c;
2561 }
2562 }
2563 }
2564 // If a double-width char doesn't fit display a '>' in the
2565 // last column; the character is displayed at the start of the
2566 // next line.
2567 if ((
2568# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002569 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002571 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 && (*mb_char2cells)(mb_c) == 2)
2573 {
2574 c = '>';
2575 mb_c = c;
2576 mb_utf8 = FALSE;
2577 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002578 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 // Put pointer back so that the character will be
2580 // displayed at the start of the next line.
2581 --ptr;
2582#ifdef FEAT_CONCEAL
2583 did_decrement_ptr = TRUE;
2584#endif
2585 }
2586 else if (*ptr != NUL)
2587 ptr += mb_l - 1;
2588
2589 // If a double-width char doesn't fit at the left side display
2590 // a '<' in the first column. Don't do this for unprintable
2591 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002592 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002593 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002594 wlv.n_extra = 1;
2595 wlv.c_extra = MB_FILLER_CHAR;
2596 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002597 c = ' ';
2598 if (area_attr == 0 && search_attr == 0)
2599 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002600 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002601 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002602 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002603 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002604 }
2605 mb_c = c;
2606 mb_utf8 = FALSE;
2607 mb_l = 1;
2608 }
2609
2610 }
2611 ++ptr;
2612
2613 if (extra_check)
2614 {
2615#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002616 // Check spelling (unless at the end of the line).
2617 // Only do this when there is no syntax highlighting, the
2618 // @Spell cluster is not used or the current syntax item
2619 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002620 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621 if (has_spell && v >= word_end && v > cur_checked_col)
2622 {
2623 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002624 // do not calculate cap_col at the end of the line or when
2625 // only white space is following
2626 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002627# ifdef FEAT_SYN_HL
2628 !has_syntax ||
2629# endif
2630 can_spell))
2631 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002632 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 int len;
2634 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002635
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002636 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638
2639 // Use nextline[] if possible, it has the start of the
2640 // next line concatenated.
2641 if ((prev_ptr - line) - nextlinecol >= 0)
2642 p = nextline + (prev_ptr - line) - nextlinecol;
2643 else
2644 p = prev_ptr;
2645 cap_col -= (int)(prev_ptr - line);
2646 len = spell_check(wp, p, &spell_hlf, &cap_col,
2647 nochange);
2648 word_end = v + len;
2649
2650 // In Insert mode only highlight a word that
2651 // doesn't touch the cursor.
2652 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002653 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 && wp->w_cursor.lnum == lnum
2655 && wp->w_cursor.col >=
2656 (colnr_T)(prev_ptr - line)
2657 && wp->w_cursor.col < (colnr_T)word_end)
2658 {
2659 spell_hlf = HLF_COUNT;
2660 spell_redraw_lnum = lnum;
2661 }
2662
2663 if (spell_hlf == HLF_COUNT && p != prev_ptr
2664 && (p - nextline) + len > nextline_idx)
2665 {
2666 // Remember that the good word continues at the
2667 // start of the next line.
2668 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002669 checked_col = (int)((p - nextline)
2670 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002671 }
2672
2673 // Turn index into actual attributes.
2674 if (spell_hlf != HLF_COUNT)
2675 spell_attr = highlight_attr[spell_hlf];
2676
2677 if (cap_col > 0)
2678 {
2679 if (p != prev_ptr
2680 && (p - nextline) + cap_col >= nextline_idx)
2681 {
2682 // Remember that the word in the next line
2683 // must start with a capital.
2684 capcol_lnum = lnum + 1;
2685 cap_col = (int)((p - nextline) + cap_col
2686 - nextline_idx);
2687 }
2688 else
2689 // Compute the actual column.
2690 cap_col += (int)(prev_ptr - line);
2691 }
2692 }
2693 }
2694 if (spell_attr != 0)
2695 {
2696 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002697 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2698 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002700 wlv.char_attr = hl_combine_attr(spell_attr,
2701 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002702 }
2703#endif
2704#ifdef FEAT_LINEBREAK
2705 // Found last space before word: check for line break.
2706 if (wp->w_p_lbr && c0 == c
2707 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2708 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002709 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2710 : 0;
2711 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002712 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002714 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002715# ifdef FEAT_PROP_POPUP
2716 // do not want virtual text counted here
2717 cts.cts_has_prop_with_text = FALSE;
2718# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002719 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002720 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002721
2722 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002723 // space for it again.
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002724 if (wlv.vcol == wlv.vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002725 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002726 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2727 if (wlv.n_extra < 0)
2728 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002729 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002730 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002731 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002732 // line break, but for TABs the highlighting should
2733 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002734 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002735
Bram Moolenaar1306b362022-08-06 15:59:06 +01002736 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002737# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002739 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 wp->w_buffer->b_p_vts_array) - 1;
2741# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002742 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002743 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744# endif
2745
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2747 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002748# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002750 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002751# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 if (VIM_ISWHITE(c))
2753 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002754# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002755 if (c == TAB)
2756 // See "Tab alignment" below.
2757 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002758# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002759 if (!wp->w_p_list)
2760 c = ' ';
2761 }
2762 }
2763#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002764 in_multispace = c == ' '
2765 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2766 if (!in_multispace)
2767 multispace_pos = 0;
2768
Bram Moolenaareed9d462021-02-15 20:38:25 +01002769 // 'list': Change char 160 to 'nbsp' and space to 'space'
2770 // setting in 'listchars'. But not when the character is
2771 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002772 if (wp->w_p_list
2773 && ((((c == 160 && mb_l == 1)
2774 || (mb_utf8
2775 && ((mb_c == 160 && mb_l == 2)
2776 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002777 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 || (c == ' '
2779 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002780 && (wp->w_lcs_chars.space
2781 || (in_multispace
2782 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002783 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 && ptr - line <= trailcol)))
2785 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002786 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2787 {
2788 c = wp->w_lcs_chars.multispace[multispace_pos++];
2789 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2790 multispace_pos = 0;
2791 }
2792 else
2793 c = (c == ' ') ? wp->w_lcs_chars.space
2794 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002795 if (area_attr == 0 && search_attr == 0)
2796 {
2797 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002798 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002799 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002800 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 }
2802 mb_c = c;
2803 if (enc_utf8 && utf_char2len(c) > 1)
2804 {
2805 mb_utf8 = TRUE;
2806 u8cc[0] = 0;
2807 c = 0xc0;
2808 }
2809 else
2810 mb_utf8 = FALSE;
2811 }
2812
zeertzjq2e7cba32022-06-10 15:30:32 +01002813 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2814 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002815 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002816 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2817 && wp->w_lcs_chars.leadmultispace != NULL)
2818 {
2819 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002820 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2821 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002822 multispace_pos = 0;
2823 }
2824
2825 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2826 c = wp->w_lcs_chars.trail;
2827
2828 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2829 c = wp->w_lcs_chars.lead;
2830
zeertzjq2e7cba32022-06-10 15:30:32 +01002831 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002832 c = wp->w_lcs_chars.space;
2833
2834
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002835 if (!attr_pri)
2836 {
2837 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002838 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002840 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
2842 mb_c = c;
2843 if (enc_utf8 && utf_char2len(c) > 1)
2844 {
2845 mb_utf8 = TRUE;
2846 u8cc[0] = 0;
2847 c = 0xc0;
2848 }
2849 else
2850 mb_utf8 = FALSE;
2851 }
2852 }
2853
2854 // Handling of non-printable characters.
2855 if (!vim_isprintc(c))
2856 {
2857 // when getting a character from the file, we may have to
2858 // turn it into something else on the way to putting it
2859 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002860 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 {
2862 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002865 char_u *sbr = get_showbreak_value(wp);
2866
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 // only adjust the tab_len, when at the first column
2868 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002869 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871#endif
2872 // tab amount depends on current column
2873#ifdef FEAT_VARTABS
2874 tab_len = tabstop_padding(vcol_adjusted,
2875 wp->w_buffer->b_p_ts,
2876 wp->w_buffer->b_p_vts_array) - 1;
2877#else
2878 tab_len = (int)wp->w_buffer->b_p_ts
2879 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2880#endif
2881
2882#ifdef FEAT_LINEBREAK
2883 if (!wp->w_p_lbr || !wp->w_p_list)
2884#endif
2885 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887#ifdef FEAT_LINEBREAK
2888 else
2889 {
2890 char_u *p;
2891 int len;
2892 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002895# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002896 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002898 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002899
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002901 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 && old_boguscols > 0
2903 && wlv.n_extra > tab_len)
2904 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002905# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002906 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002907 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002908 // If wlv.n_extra > 0, it gives the number of
2909 // chars, to use for a tab, else we need to
2910 // calculate the width for a tab.
2911 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
2912 len = tab_len * tab2_len;
2913 if (wp->w_lcs_chars.tab3)
2914 len += mb_char2len(wp->w_lcs_chars.tab3)
2915 - tab2_len;
2916 if (wlv.n_extra > 0)
2917 len += wlv.n_extra - tab_len;
2918 c = wp->w_lcs_chars.tab1;
2919 p = alloc(len + 1);
2920 if (p == NULL)
2921 wlv.n_extra = 0;
2922 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002924 vim_memset(p, ' ', len);
2925 p[len] = NUL;
2926 vim_free(wlv.p_extra_free);
2927 wlv.p_extra_free = p;
2928 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002929 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002930 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002931
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002932 if (*p == NUL)
2933 {
2934 tab_len = i;
2935 break;
2936 }
2937
2938 // if tab3 is given, use it for the last
2939 // char
2940 if (wp->w_lcs_chars.tab3
2941 && i == tab_len - 1)
2942 lcs = wp->w_lcs_chars.tab3;
2943 p += mb_char2bytes(lcs, p);
2944 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002946 }
2947 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002948# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002949 // n_extra will be increased by
2950 // FIX_FOX_BOGUSCOLS macro below, so need to
2951 // adjust for that here
2952 if (wlv.vcol_off > 0)
2953 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002954# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01002955 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002957 }
2958#endif
2959#ifdef FEAT_CONCEAL
2960 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002961 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962
2963 // Tab alignment should be identical regardless of
2964 // 'conceallevel' value. So tab compensates of all
2965 // previous concealed characters, and thus resets
2966 // vcol_off and boguscols accumulated so far in the
2967 // line. Note that the tab can be longer than
2968 // 'tabstop' when there are concealed characters.
2969 FIX_FOR_BOGUSCOLS;
2970
2971 // Make sure, the highlighting for the tab char will be
2972 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002973 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002974 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002975 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 tab_len += vc_saved;
2977 }
2978#endif
2979 mb_utf8 = FALSE; // don't draw as UTF-8
2980 if (wp->w_p_list)
2981 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002982 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002983 ? wp->w_lcs_chars.tab3
2984 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985#ifdef FEAT_LINEBREAK
2986 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 else
2989#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002990 wlv.c_extra = wp->w_lcs_chars.tab2;
2991 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002992 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002993 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002995 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002996 mb_c = c;
2997 if (enc_utf8 && utf_char2len(c) > 1)
2998 {
2999 mb_utf8 = TRUE;
3000 u8cc[0] = 0;
3001 c = 0xc0;
3002 }
3003 }
3004 else
3005 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003006 wlv.c_final = NUL;
3007 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003008 c = ' ';
3009 }
3010 }
3011 else if (c == NUL
3012 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003013 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3014 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 && VIsual_mode != Ctrl_V
3016 && (
3017# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003018 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003019# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003020 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 && !(noinvcur
3022 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003023 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 && lcs_eol_one > 0)
3025 {
3026 // Display a '$' after the line or highlight an extra
3027 // character if the line break is included.
3028#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3029 // For a diff line the highlighting continues after the
3030 // "$".
3031 if (
3032# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003033 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034# ifdef LINE_ATTR
3035 &&
3036# endif
3037# endif
3038# ifdef LINE_ATTR
3039 line_attr == 0
3040# endif
3041 )
3042#endif
3043 {
3044 // In virtualedit, visual selections may extend
3045 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003046 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003047 && wlv.tocol != MAXCOL
3048 && wlv.vcol < wlv.tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003050 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003052 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3053 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 else
3055 c = ' ';
3056 lcs_eol_one = -1;
3057 --ptr; // put it back at the NUL
3058 if (!attr_pri)
3059 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003060 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003061 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003062 n_attr = 1;
3063 }
3064 mb_c = c;
3065 if (enc_utf8 && utf_char2len(c) > 1)
3066 {
3067 mb_utf8 = TRUE;
3068 u8cc[0] = 0;
3069 c = 0xc0;
3070 }
3071 else
3072 mb_utf8 = FALSE; // don't draw as UTF-8
3073 }
3074 else if (c != NUL)
3075 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003076 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3077 if (wlv.n_extra == 0)
3078 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079#ifdef FEAT_RIGHTLEFT
3080 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003081 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003082#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003083 wlv.c_extra = NUL;
3084 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003085#ifdef FEAT_LINEBREAK
3086 if (wp->w_p_lbr)
3087 {
3088 char_u *p;
3089
Bram Moolenaar1306b362022-08-06 15:59:06 +01003090 c = *wlv.p_extra;
3091 p = alloc(wlv.n_extra + 1);
3092 vim_memset(p, ' ', wlv.n_extra);
3093 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3094 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003095 vim_free(wlv.p_extra_free);
3096 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003097 }
3098 else
3099#endif
3100 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 wlv.n_extra = byte2cells(c) - 1;
3102 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 }
3104 if (!attr_pri)
3105 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003106 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003107 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003108 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003109 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 }
3111 mb_utf8 = FALSE; // don't draw as UTF-8
3112 }
3113 else if (VIsual_active
3114 && (VIsual_mode == Ctrl_V
3115 || VIsual_mode == 'v')
3116 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003117 && wlv.tocol != MAXCOL
3118 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 && (
3120#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003121 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003123 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003124 {
3125 c = ' ';
3126 --ptr; // put it back at the NUL
3127 }
3128#if defined(LINE_ATTR)
3129 else if ((
3130# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003131 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132# endif
3133# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003134 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003135# endif
3136 line_attr != 0
3137 ) && (
3138# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003139 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144# endif
3145 < wp->w_width)))
3146 {
3147 // Highlight until the right side of the window
3148 c = ' ';
3149 --ptr; // put it back at the NUL
3150
3151 // Remember we do the char for line highlighting.
3152 ++did_line_attr;
3153
3154 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01003155 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003156 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003157 || (wp->w_p_list &&
3158 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003159 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003160# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003161 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003163 wlv.diff_hlf = HLF_CHD;
3164 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3168 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003169 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003170 || (wlv.vcol >= left_curline_col
3171 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003172 wlv.char_attr = hl_combine_attr(
3173 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 }
3175 }
3176# endif
3177# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003178 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003180 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003181 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3182 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003184 if (!wlv.cul_screenline
3185 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003186 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003187 wlv.char_attr = hl_combine_attr(
3188 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003189 }
3190 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003191 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3192 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003193 }
3194# endif
3195 }
3196#endif
3197 }
3198
3199#ifdef FEAT_CONCEAL
3200 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003201 && (wp != curwin || lnum != wp->w_cursor.lnum
3202 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3204 && !(lnum_in_visual_area
3205 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3206 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003208 if (((prev_syntax_id != syntax_seqnr
3209 && (syntax_flags & HL_CONCEAL) != 0)
3210 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003211 && (syn_get_sub_char() != NUL
3212 || (has_match_conc && match_conc)
3213 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 && wp->w_p_cole != 3)
3215 {
3216 // First time at this concealed item: display one
3217 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003218 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 c = match_conc;
3220 else if (syn_get_sub_char() != NUL)
3221 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003222 else if (wp->w_lcs_chars.conceal != NUL)
3223 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 else
3225 c = ' ';
3226
3227 prev_syntax_id = syntax_seqnr;
3228
Bram Moolenaar1306b362022-08-06 15:59:06 +01003229 if (wlv.n_extra > 0)
3230 wlv.vcol_off += wlv.n_extra;
3231 wlv.vcol += wlv.n_extra;
3232 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 {
3234# ifdef FEAT_RIGHTLEFT
3235 if (wp->w_p_rl)
3236 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003237 wlv.col -= wlv.n_extra;
3238 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239 }
3240 else
3241# endif
3242 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003243 wlv.boguscols += wlv.n_extra;
3244 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003245 }
3246 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003247 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 n_attr = 0;
3249 }
3250 else if (n_skip == 0)
3251 {
3252 is_concealing = TRUE;
3253 n_skip = 1;
3254 }
3255 mb_c = c;
3256 if (enc_utf8 && utf_char2len(c) > 1)
3257 {
3258 mb_utf8 = TRUE;
3259 u8cc[0] = 0;
3260 c = 0xc0;
3261 }
3262 else
3263 mb_utf8 = FALSE; // don't draw as UTF-8
3264 }
3265 else
3266 {
3267 prev_syntax_id = 0;
3268 is_concealing = FALSE;
3269 }
3270
3271 if (n_skip > 0 && did_decrement_ptr)
3272 // not showing the '>', put pointer back to avoid getting stuck
3273 ++ptr;
3274
3275#endif // FEAT_CONCEAL
3276 }
3277
3278#ifdef FEAT_CONCEAL
3279 // In the cursor line and we may be concealing characters: correct
3280 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003281 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003282 && wp == curwin && lnum == wp->w_cursor.lnum
3283 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003286# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003287 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003288 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003290# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003291 wp->w_wcol = wlv.col - wlv.boguscols;
3292 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293 did_wcol = TRUE;
3294 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003295# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003296 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003297# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 }
3299#endif
3300
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003301 // Use "wlv.extra_attr", but don't override visual selection
3302 // highlighting, unless text property overrides.
3303 // Don't use "wlv.extra_attr" until n_attr_skip is zero.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003304 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003305 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003306 && (!attr_pri
3307#ifdef FEAT_PROP_POPUP
3308 || (text_prop_flags & PT_FLAG_OVERRIDE)
3309#endif
3310 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 {
3312#ifdef LINE_ATTR
3313 if (line_attr)
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003314 wlv.char_attr = hl_combine_attr(line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003315 else
3316#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003317 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003318 }
3319
3320#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3321 // XIM don't send preedit_start and preedit_end, but they send
3322 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3323 // im_is_preediting() here.
3324 if (p_imst == IM_ON_THE_SPOT
3325 && xic != NULL
3326 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003327 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 && !p_imdisable
3329 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003330 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 {
3332 colnr_T tcol;
3333
3334 if (preedit_end_col == MAXCOL)
3335 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3336 else
3337 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 {
3340 if (feedback_old_attr < 0)
3341 {
3342 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003343 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003344 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003345 wlv.char_attr = im_get_feedback_attr(feedback_col);
3346 if (wlv.char_attr < 0)
3347 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003348 feedback_col++;
3349 }
3350 else if (feedback_old_attr >= 0)
3351 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003352 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003353 feedback_old_attr = -1;
3354 feedback_col = 0;
3355 }
3356 }
3357#endif
3358 // Handle the case where we are in column 0 but not on the first
3359 // character of the line and the user wants us to show us a
3360 // special character (via 'listchars' option "precedes:<char>".
3361 if (lcs_prec_todo != NUL
3362 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003363 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3364 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003366 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003368 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003369 && c != NUL)
3370 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003371 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 lcs_prec_todo = NUL;
3373 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3374 {
3375 // Double-width character being overwritten by the "precedes"
3376 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003377 wlv.c_extra = MB_FILLER_CHAR;
3378 wlv.c_final = NUL;
3379 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003381 wlv.extra_attr =
3382 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003383 }
3384 mb_c = c;
3385 if (enc_utf8 && utf_char2len(c) > 1)
3386 {
3387 mb_utf8 = TRUE;
3388 u8cc[0] = 0;
3389 c = 0xc0;
3390 }
3391 else
3392 mb_utf8 = FALSE; // don't draw as UTF-8
3393 if (!attr_pri)
3394 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003395 saved_attr3 = wlv.char_attr; // save current attr
3396 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003397 n_attr3 = 1;
3398 }
3399 }
3400
3401 // At end of the text line or just after the last character.
3402 if ((c == NUL
3403#if defined(LINE_ATTR)
3404 || did_line_attr == 1
3405#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 {
3408#ifdef FEAT_SEARCH_EXTRA
3409 // flag to indicate whether prevcol equals startcol of search_hl or
3410 // one of the matches
3411 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3412 (long)(ptr - line) - (c == NUL));
3413#endif
3414 // Invert at least one char, used for Visual and empty line or
3415 // highlight match at end of line. If it's beyond the last
3416 // char on the screen, just overwrite that one (tricky!) Not
3417 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003418 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003419 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 && (VIsual_mode != Ctrl_V
3421 || lnum == VIsual.lnum
3422 || lnum == curwin->w_cursor.lnum)
3423 && c == NUL)
3424#ifdef FEAT_SEARCH_EXTRA
3425 // highlight 'hlsearch' match at end of line
3426 || (prevcol_hl_flag
3427# ifdef FEAT_SYN_HL
3428 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3429 && !(wp == curwin && VIsual_active))
3430# endif
3431# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003432 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433# endif
3434# if defined(LINE_ATTR)
3435 && did_line_attr <= 1
3436# endif
3437 )
3438#endif
3439 ))
3440 {
3441 int n = 0;
3442
3443#ifdef FEAT_RIGHTLEFT
3444 if (wp->w_p_rl)
3445 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003446 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003447 n = 1;
3448 }
3449 else
3450#endif
3451 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003452 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003453 n = -1;
3454 }
3455 if (n != 0)
3456 {
3457 // At the window boundary, highlight the last character
3458 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003459 wlv.off += n;
3460 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 }
3462 else
3463 {
3464 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003465 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003467 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003468 }
3469#ifdef FEAT_SEARCH_EXTRA
3470 if (area_attr == 0)
3471 {
3472 // Use attributes from match with highest priority among
3473 // 'search_hl' and the match list.
3474 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003475 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476 }
3477#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003479 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480#ifdef FEAT_RIGHTLEFT
3481 if (wp->w_p_rl)
3482 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003483 --wlv.col;
3484 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486 else
3487#endif
3488 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 ++wlv.col;
3490 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003491 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003492 ++wlv.vcol;
3493 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494 }
3495 }
3496
3497 // At end of the text line.
3498 if (c == NUL)
3499 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003500 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501
3502 // Update w_cline_height and w_cline_folded if the cursor line was
3503 // updated (saves a call to plines() later).
3504 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3505 {
3506 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003507 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508#ifdef FEAT_FOLDING
3509 curwin->w_cline_folded = FALSE;
3510#endif
3511 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3512 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 break;
3514 }
3515
3516 // Show "extends" character from 'listchars' if beyond the line end and
3517 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003518 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003519 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 && wp->w_p_list
3521 && !wp->w_p_wrap
3522#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003523 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524#endif
3525 && (
3526#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003527 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003528#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003529 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003531 || lcs_eol_one > 0
3532 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003533 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003535 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 mb_c = c;
3538 if (enc_utf8 && utf_char2len(c) > 1)
3539 {
3540 mb_utf8 = TRUE;
3541 u8cc[0] = 0;
3542 c = 0xc0;
3543 }
3544 else
3545 mb_utf8 = FALSE;
3546 }
3547
3548#ifdef FEAT_SYN_HL
3549 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003550 if (wlv.draw_color_col)
3551 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552
3553 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3554 // highlight the cursor position itself.
3555 // Also highlight the 'colorcolumn' if it is different than
3556 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003557 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3558 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003560 if (((wlv.draw_state == WL_LINE
3561 || wlv.draw_state == WL_BRI
3562 || wlv.draw_state == WL_SBR)
3563 && !lnum_in_visual_area
3564 && search_attr == 0
3565 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003566# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003567 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003568# endif
3569 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 {
3571 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3572 && lnum != wp->w_cursor.lnum)
3573 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003574 vcol_save_attr = wlv.char_attr;
3575 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3576 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003577 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003578 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 vcol_save_attr = wlv.char_attr;
3581 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 }
3583 }
3584#endif
3585
3586 // Store character to be displayed.
3587 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003589 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003590 {
3591 // Store the character.
3592#if defined(FEAT_RIGHTLEFT)
3593 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3594 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003595 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003596 --wlv.off;
3597 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003598 }
3599#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003600 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 if (enc_dbcs == DBCS_JPNU)
3602 {
3603 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003604 ScreenLines[wlv.off] = 0x8e;
3605 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003606 }
3607 else if (enc_utf8)
3608 {
3609 if (mb_utf8)
3610 {
3611 int i;
3612
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 for (i = 0; i < Screen_mco; ++i)
3617 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003619 if (u8cc[i] == 0)
3620 break;
3621 }
3622 }
3623 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003624 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003625 }
3626 if (multi_attr)
3627 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003628 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003629 multi_attr = 0;
3630 }
3631 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003632 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003633
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003634 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003635
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3637 {
3638 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 ++wlv.off;
3640 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 if (enc_utf8)
3642 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003643 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003644 else
3645 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003649 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#endif
3651 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003652 ++wlv.vcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003653 // When "wlv.tocol" is halfway a character, set it to the end
3654 // of the character, otherwise highlighting won't stop.
3655 if (wlv.tocol == wlv.vcol)
3656 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003657
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003658 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003659
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003660#ifdef FEAT_RIGHTLEFT
3661 if (wp->w_p_rl)
3662 {
3663 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003664 --wlv.off;
3665 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003666 }
3667#endif
3668 }
3669#ifdef FEAT_RIGHTLEFT
3670 if (wp->w_p_rl)
3671 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003672 --wlv.off;
3673 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003674 }
3675 else
3676#endif
3677 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003678 ++wlv.off;
3679 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 }
3681 }
3682#ifdef FEAT_CONCEAL
3683 else if (wp->w_p_cole > 0 && is_concealing)
3684 {
3685 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003686 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 if (wlv.n_extra > 0)
3688 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003689 if (wp->w_p_wrap)
3690 {
3691 // Special voodoo required if 'wrap' is on.
3692 //
3693 // Advance the column indicator to force the line
3694 // drawing to wrap early. This will make the line
3695 // take up the same screen space when parts are concealed,
3696 // so that cursor line computations aren't messed up.
3697 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003698 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 // trailing junk to be written out of the screen line
3700 // we are building, 'boguscols' keeps track of the number
3701 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003702 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003703 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003704 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705# ifdef FEAT_RIGHTLEFT
3706 if (wp->w_p_rl)
3707 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003708 wlv.col -= wlv.n_extra;
3709 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003710 }
3711 else
3712# endif
3713 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003714 wlv.col += wlv.n_extra;
3715 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003717 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718 n_attr = 0;
3719 }
3720
3721
3722 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3723 {
3724 // Need to fill two screen columns.
3725# ifdef FEAT_RIGHTLEFT
3726 if (wp->w_p_rl)
3727 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003728 --wlv.boguscols;
3729 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 }
3731 else
3732# endif
3733 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003734 ++wlv.boguscols;
3735 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003736 }
3737 }
3738
3739# ifdef FEAT_RIGHTLEFT
3740 if (wp->w_p_rl)
3741 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003742 --wlv.boguscols;
3743 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003744 }
3745 else
3746# endif
3747 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003748 ++wlv.boguscols;
3749 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003750 }
3751 }
3752 else
3753 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003754 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003756 wlv.vcol += wlv.n_extra;
3757 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 n_attr = 0;
3759 }
3760 }
3761
3762 }
3763#endif // FEAT_CONCEAL
3764 else
3765 --n_skip;
3766
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 // Only advance the "wlv.vcol" when after the 'number' or
3768 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003769 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003770#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003771 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003772#endif
3773 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003774 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775
3776#ifdef FEAT_SYN_HL
3777 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003778 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003779#endif
3780
3781 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003782 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3783 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784
3785 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003787 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003788 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003789 if (n_attr_skip > 0)
3790 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003791
3792 // At end of screen line and there is more to come: Display the line
3793 // so far. If there is no more to display it is caught above.
3794 if ((
3795#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003796 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003797#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003798 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003799 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003800 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003802 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003803#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003804#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003805 || text_prop_above || text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003806#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003807 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003808 && wlv.p_extra != at_end_str)
3809 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3810 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003811 )
3812 {
3813#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01003814 wlv.col -= wlv.boguscols;
Bram Moolenaar75008662022-10-04 22:40:56 +01003815 wlv_screen_line(wp, &wlv, FALSE);
3816 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003817 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003818#else
Bram Moolenaareb47d6d2022-10-03 17:45:55 +01003819 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003821 ++wlv.row;
3822 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003823
3824 // When not wrapping and finished diff lines, or when displayed
3825 // '$' and highlighting until last column, break here.
Bram Moolenaar877151b2022-10-11 15:29:50 +01003826 if (((!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003828 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003829#endif
3830#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01003831 && !text_prop_above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003832#endif
Bram Moolenaar877151b2022-10-11 15:29:50 +01003833 ) || lcs_eol_one == -1)
3834#ifdef FEAT_PROP_POPUP
3835 && !text_prop_follows
3836#endif
3837 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003838 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003839#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003840 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003841 {
3842 // do not output more of the line, only the "below" prop
3843 ptr += STRLEN(ptr);
3844# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003845 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003846# endif
3847 }
3848#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849
3850 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003851 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003852#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003853 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003854#endif
3855 )
3856 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003857 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3858 draw_vsep_win(wp, wlv.row);
3859 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860 }
3861
3862 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003863 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003864 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003865 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 break;
3867 }
3868
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003869 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003870#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003871 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003872#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003873#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01003874 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003875#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 && wp->w_width == Columns)
3877 {
3878 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003879 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003880
3881 // Special trick to make copy/paste of wrapped lines work with
3882 // xterm/screen: write an extra character beyond the end of
3883 // the line. This will work with all terminal types
3884 // (regardless of the xn,am settings).
3885 // Only do this on a fast tty.
3886 // Only do this if the cursor is on the current line
3887 // (something has been written in it).
3888 // Don't do this for the GUI.
3889 // Don't do this for double-width characters.
3890 // Don't do this for a window not at the right screen border.
3891 if (p_tf
3892#ifdef FEAT_GUI
3893 && !gui.in_use
3894#endif
3895 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003896 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3897 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003898 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003899 || (*mb_off2cells)(
3900 LineOffset[wlv.screen_row - 1]
3901 + (int)Columns - 2,
3902 LineOffset[wlv.screen_row]
3903 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 {
3905 // First make sure we are at the end of the screen line,
3906 // then output the same character again to let the
3907 // terminal know about the wrap. If the terminal doesn't
3908 // auto-wrap, we overwrite the character.
3909 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003910 screen_char(LineOffset[wlv.screen_row - 1]
3911 + (unsigned)Columns - 1,
3912 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003913
3914 // When there is a multi-byte character, just output a
3915 // space to keep it simple.
3916 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003917 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 out_char(' ');
3919 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003920 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 + (Columns - 1)]);
3922 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003923 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003924 screen_start(); // don't know where cursor is now
3925 }
3926 }
3927
Bram Moolenaar1306b362022-08-06 15:59:06 +01003928 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929
Bram Moolenaareed9d462021-02-15 20:38:25 +01003930 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003932 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003934 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003935# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003936 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003937 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003938#endif
3939#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003940 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 // When the filler lines are actually below the last line of the
3942 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01003943 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 break;
3945#endif
3946 }
3947
3948 } // for every character in the line
3949
3950#ifdef FEAT_SPELL
3951 // After an empty line check first word for capital.
3952 if (*skipwhite(line) == NUL)
3953 {
3954 capcol_lnum = lnum + 1;
3955 cap_col = 0;
3956 }
3957#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003958#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003959 vim_free(text_props);
3960 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003961 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003962#endif
3963
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003964 vim_free(wlv.p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003965 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003966}