blob: 26886bd9455e170a14bc5188084f519b83ad22a7 [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.
105
106 int screen_line_flags; // flags for screen_line()
107
108 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
109 int cul_screenline;
110
111 int char_attr; // attributes for the next character
112
113 int n_extra; // number of extra bytes
114 char_u *p_extra; // string of extra chars, plus NUL, only used
115 // when c_extra and c_final are NUL
116 int c_extra; // extra chars, all the same
117 int c_final; // final char, mandatory if set
118
119 // saved "extra" items for when draw_state becomes WL_LINE (again)
120 int saved_n_extra;
121 char_u *saved_p_extra;
122 int saved_c_extra;
123 int saved_c_final;
124 int saved_char_attr;
125
126#ifdef FEAT_DIFF
127 hlf_T diff_hlf; // type of diff highlighting
128#endif
129} winlinevars_T;
130
131// draw_state values for items that are drawn in sequence:
132#define WL_START 0 // nothing done yet, must be zero
133#ifdef FEAT_CMDWIN
134# define WL_CMDLINE (WL_START + 1) // cmdline window column
135#else
136# define WL_CMDLINE WL_START
137#endif
138#ifdef FEAT_FOLDING
139# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
140#else
141# define WL_FOLD WL_CMDLINE
142#endif
143#ifdef FEAT_SIGNS
144# define WL_SIGN (WL_FOLD + 1) // column for signs
145#else
146# define WL_SIGN WL_FOLD // column for signs
147#endif
148#define WL_NR (WL_SIGN + 1) // line number
149#ifdef FEAT_LINEBREAK
150# define WL_BRI (WL_NR + 1) // 'breakindent'
151#else
152# define WL_BRI WL_NR
153#endif
154#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
155# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
156#else
157# define WL_SBR WL_BRI
158#endif
159#define WL_LINE (WL_SBR + 1) // text in the line
160
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200161#ifdef FEAT_SIGNS
162/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000163 * Return TRUE if CursorLineSign highlight is to be used.
164 */
165 static int
166use_cursor_line_sign(win_T *wp, linenr_T lnum)
167{
168 return wp->w_p_cul
169 && lnum == wp->w_cursor.lnum
170 && (wp->w_p_culopt_flags & CULOPT_NBR);
171}
172
173/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200174 * Get information needed to display the sign in line 'lnum' in window 'wp'.
175 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
176 * Otherwise the sign is going to be displayed in the sign column.
177 */
178 static void
179get_sign_display_info(
180 int nrcol,
181 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +0000182 linenr_T lnum,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100183 winlinevars_T *wlv,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200184 sign_attrs_T *sattr,
185 int wcr_attr,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186 int filler_lines UNUSED,
187 int filler_todo UNUSED,
Bram Moolenaar1306b362022-08-06 15:59:06 +0100188 char_u *extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200189{
190 int text_sign;
191# ifdef FEAT_SIGN_ICONS
192 int icon_sign;
193# endif
194
195 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100196 wlv->c_extra = ' ';
197 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100199 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200200 else
201 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000202 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100203 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000204 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100205 wlv->char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
206 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200207 }
208
Bram Moolenaar1306b362022-08-06 15:59:06 +0100209 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210#ifdef FEAT_DIFF
211 + filler_lines && filler_todo <= 0
212#endif
213 )
214 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200215 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200216# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200217 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200218 if (gui.in_use && icon_sign != 0)
219 {
220 // Use the image in this position.
221 if (nrcol)
222 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100223 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200224 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100225 wlv->p_extra = extra;
226 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200227 }
228 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100229 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200230# ifdef FEAT_NETBEANS_INTG
231 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
232 {
233 if (nrcol)
234 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100235 wlv->c_extra = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200236 sprintf((char *)extra, "%-*c ", number_width(wp),
237 MULTISIGN_BYTE);
Bram Moolenaar1306b362022-08-06 15:59:06 +0100238 wlv->p_extra = extra;
239 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200240 }
241 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100242 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200243 }
244# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100245 wlv->c_final = NUL;
246 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200247 }
248 else
249# endif
250 if (text_sign != 0)
251 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100252 wlv->p_extra = sattr->sat_text;
253 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200254 {
255 if (nrcol)
256 {
257 int n, width = number_width(wp) - 2;
258
259 for (n = 0; n < width; n++)
260 extra[n] = ' ';
261 extra[n] = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100262 STRCAT(extra, wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200263 STRCAT(extra, " ");
Bram Moolenaar1306b362022-08-06 15:59:06 +0100264 wlv->p_extra = extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200265 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100266 wlv->c_extra = NUL;
267 wlv->c_final = NUL;
268 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200269 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000270
271 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100272 wlv->char_attr = sattr->sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000273 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->char_attr = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 }
276 }
277}
278#endif
279
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100280#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100281/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100282 * Take care of padding, right-align and truncation of virtual text after a
283 * line.
284 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
285 * padding, right-align and truncation. Otherwise only the size is computed.
286 * When "n_attr" is NULL returns the number of screen cells used.
287 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100288 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100289 int
290text_prop_position(
291 win_T *wp,
292 textprop_T *tp,
293 int vcol, // current screen column
294 int *n_extra, // nr of bytes for virtual text
295 char_u **p_extra, // virtual text
296 int *n_attr, // attribute cells, NULL if not used
297 int *n_attr_skip) // cells to skip attr, NULL if not used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200298{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100299 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
300 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
301 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
302 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
303 ? tp->tp_len - 1 : 0;
304 int col_with_padding = vcol + (below ? 0 : padding);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100305 int col_off = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100306 int room = wp->w_width - col_with_padding;
307 int added = room;
308 int n_used = *n_extra;
309 char_u *l = NULL;
310 int strsize = vim_strsize(*p_extra);
311 int cells = wrap ? strsize
312 : textprop_size_after_trunc(wp, below, added, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100314 if (wrap || right || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100315 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100316 // Right-align: fill with spaces
317 if (right)
318 added -= cells;
319 if (added < 0
320 || !(right || below)
321 || (below
322 ? (col_with_padding == 0 || !wp->w_p_wrap)
323 : (n_used < *n_extra)))
324 {
325 if (right && (wrap || room < PROP_TEXT_MIN_CELLS))
326 {
327 // right-align on next line instead of wrapping if possible
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100328 col_off = win_col_off(wp) + win_col_off2(wp);
329 added = wp->w_width - col_off - strsize + room;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100330 if (added < 0)
331 added = 0;
332 else
333 n_used = *n_extra;
334 }
335 else
336 added = 0;
337 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100338
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100339 // With 'nowrap' add one to show the "extends" character if needed (it
340 // doesn't show if the text just fits).
341 if (!wp->w_p_wrap
342 && n_used < *n_extra
343 && wp->w_lcs_chars.ext != NUL
344 && wp->w_p_list)
345 ++n_used;
346
347 // add 1 for NUL, 2 for when '…' is used
348 if (n_attr != NULL)
349 l = alloc(n_used + added + padding + 3);
350 if (n_attr == NULL || l != NULL)
351 {
352 int off = 0;
353
354 if (n_attr != NULL)
355 {
356 vim_memset(l, ' ', added);
357 off += added;
358 if (padding > 0)
359 {
360 vim_memset(l + off, ' ', padding);
361 off += padding;
362 }
363 vim_strncpy(l + off, *p_extra, n_used);
364 off += n_used;
365 }
366 else
367 {
368 off = added + padding + n_used;
369 cells += added + padding;
370 }
371 if (n_attr != NULL)
372 {
373 if (n_used < *n_extra && wp->w_p_wrap)
374 {
375 char_u *lp = l + off - 1;
376
377 if (has_mbyte)
378 {
379 // change last character to '…'
380 lp -= (*mb_head_off)(l, lp);
381 STRCPY(lp, "…");
382 n_used = lp - l + 3 - padding;
383 }
384 else
385 // change last character to '>'
386 *lp = '>';
387 }
388 *p_extra = l;
389 *n_extra = n_used + added + padding;
390 *n_attr = mb_charlen(*p_extra);
Bram Moolenaarc8bf59e2022-08-28 16:39:22 +0100391 *n_attr_skip = added + padding + col_off;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100392 }
393 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100394 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100395
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100396 if (n_attr == NULL)
397 return cells;
398 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200399}
400#endif
401
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100402/*
403 * Called when finished with the line: draw the screen line and handle any
404 * highlighting until the right of the window.
405 */
406 static void
407draw_screen_line(win_T *wp, winlinevars_T *wlv)
408{
409#ifdef FEAT_SYN_HL
410 long v;
411
412 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
413 if (wp->w_p_wrap)
414 v = wp->w_skipcol;
415 else
416 v = wp->w_leftcol;
417
418 // check if line ends before left margin
419 if (wlv->vcol < v + wlv->col - win_col_off(wp))
420 wlv->vcol = v + wlv->col - win_col_off(wp);
421# ifdef FEAT_CONCEAL
422 // Get rid of the boguscols now, we want to draw until the right
423 // edge for 'cursorcolumn'.
424 wlv->col -= wlv->boguscols;
425 wlv->boguscols = 0;
426# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
427# else
428# define VCOL_HLC (wlv->vcol)
429# endif
430
431 if (wlv->draw_color_col)
432 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
433
434 if (((wp->w_p_cuc
435 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
436 && (int)wp->w_virtcol <
437 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
438 && wlv->lnum != wp->w_cursor.lnum)
439 || wlv->draw_color_col
440 || wlv->win_attr != 0)
441# ifdef FEAT_RIGHTLEFT
442 && !wp->w_p_rl
443# endif
444 )
445 {
446 int rightmost_vcol = 0;
447 int i;
448
449 if (wp->w_p_cuc)
450 rightmost_vcol = wp->w_virtcol;
451 if (wlv->draw_color_col)
452 // determine rightmost colorcolumn to possibly draw
453 for (i = 0; wlv->color_cols[i] >= 0; ++i)
454 if (rightmost_vcol < wlv->color_cols[i])
455 rightmost_vcol = wlv->color_cols[i];
456
457 while (wlv->col < wp->w_width)
458 {
459 ScreenLines[wlv->off] = ' ';
460 if (enc_utf8)
461 ScreenLinesUC[wlv->off] = 0;
462 ScreenCols[wlv->off] = MAXCOL;
463 ++wlv->col;
464 if (wlv->draw_color_col)
465 wlv->draw_color_col = advance_color_col(
466 VCOL_HLC, &wlv->color_cols);
467
468 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
469 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
470 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
471 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
472 else
473 ScreenAttrs[wlv->off++] = wlv->win_attr;
474
475 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
476 break;
477
478 ++wlv->vcol;
479 }
480 }
481#endif
482
483 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
484 wp->w_width, wlv->screen_line_flags);
485 ++wlv->row;
486 ++wlv->screen_row;
487}
488#undef VCOL_HLC
489
490/*
491 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100492 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100493 */
494 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100495win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100496{
497 wlv->col = 0;
498 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
499
500#ifdef FEAT_RIGHTLEFT
501 if (wp->w_p_rl)
502 {
503 // Rightleft window: process the text in the normal direction, but put
504 // it in current_ScreenLine[] from right to left. Start at the
505 // rightmost column of the window.
506 wlv->col = wp->w_width - 1;
507 wlv->off += wlv->col;
508 wlv->screen_line_flags |= SLF_RIGHTLEFT;
509 }
510#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100511 if (save_extra)
512 {
513 // reset the drawing state for the start of a wrapped line
514 wlv->draw_state = WL_START;
515 wlv->saved_n_extra = wlv->n_extra;
516 wlv->saved_p_extra = wlv->p_extra;
517 wlv->saved_c_extra = wlv->c_extra;
518 wlv->saved_c_final = wlv->c_final;
519#ifdef FEAT_SYN_HL
520 if (!(wlv->cul_screenline
521# ifdef FEAT_DIFF
522 && wlv->diff_hlf == (hlf_T)0
523# endif
524 ))
525 wlv->saved_char_attr = wlv->char_attr;
526 else
527#endif
528 wlv->saved_char_attr = 0;
529 wlv->n_extra = 0;
530 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100531}
532
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200533/*
534 * Display line "lnum" of window 'wp' on the screen.
535 * Start at row "startrow", stop when "endrow" is reached.
536 * wp->w_virtcol needs to be valid.
537 *
538 * Return the number of last row the line occupies.
539 */
540 int
541win_line(
542 win_T *wp,
543 linenr_T lnum,
544 int startrow,
545 int endrow,
546 int nochange UNUSED, // not updating for changed text
547 int number_only) // only update the number column
548{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100549 winlinevars_T wlv; // variables passed between functions
550
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200551 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200552#ifdef FEAT_LINEBREAK
553 long vcol_sbr = -1; // virtual column after showbreak
554#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100555 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200556 char_u *line; // current line
557 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200558
559 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200560 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100561#ifdef FEAT_PROP_POPUP
562 char_u *p_extra_free2 = NULL; // another p_extra to be freed
563#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200564 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000565#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000566 int in_linebreak = FALSE; // n_extra set for showing linebreak
567#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200568 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100569 // displaying eol at end-of-line
570 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000571 int lcs_prec_todo = wp->w_lcs_chars.prec;
572 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100574 int n_attr = 0; // chars with special attr
575 int n_attr_skip = 0; // chars to skip before using extra_attr
576 int saved_attr2 = 0; // char_attr saved for n_attr
577 int n_attr3 = 0; // chars with overruling special attr
578 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200579
580 int n_skip = 0; // nr of chars to skip for 'nowrap'
581
582 int fromcol = -10; // start of inverting
583 int tocol = MAXCOL; // end of inverting
584 int fromcol_prev = -2; // start of inverting after cursor
585 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200586 int lnum_in_visual_area = FALSE;
587 pos_T pos;
588 long v;
589
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200590 int attr_pri = FALSE; // char_attr has priority
591 int area_highlighting = FALSE; // Visual or incsearch highlighting
592 // in this line
593 int vi_attr = 0; // attributes for Visual and incsearch
594 // highlighting
595 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200596 int area_attr = 0; // attributes desired by highlighting
597 int search_attr = 0; // attributes desired by 'hlsearch'
598#ifdef FEAT_SYN_HL
599 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
600 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200601 int prev_syntax_col = -1; // column of prev_syntax_attr
602 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200603 int has_syntax = FALSE; // this buffer has syntax highl.
604 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200605#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100606#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200607 int text_prop_count;
608 int text_prop_next = 0; // next text property to use
609 textprop_T *text_props = NULL;
610 int *text_prop_idxs = NULL;
611 int text_props_active = 0;
612 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100613 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200614 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100615 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100616 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100617 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100618 int saved_search_attr = 0; // search_attr to be used when n_extra
619 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200620#endif
621#ifdef FEAT_SPELL
622 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000623 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200624# define SPWORDLEN 150
625 char_u nextline[SPWORDLEN * 2];// text with start of the next line
626 int nextlinecol = 0; // column where nextline[] starts
627 int nextline_idx = 0; // index in nextline[] where next line
628 // starts
629 int spell_attr = 0; // attributes desired by spelling
630 int word_end = 0; // last byte with same spell_attr
631 static linenr_T checked_lnum = 0; // line number for "checked_col"
632 static int checked_col = 0; // column in "checked_lnum" up to which
633 // there are no spell errors
634 static int cap_col = -1; // column to check for Cap word
635 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
636 int cur_checked_col = 0; // checked column for current line
637#endif
638 int extra_check = 0; // has extra highlighting
639 int multi_attr = 0; // attributes desired by multibyte
640 int mb_l = 1; // multi-byte byte length
641 int mb_c = 0; // decoded multi-byte character
642 int mb_utf8 = FALSE; // screen char is UTF-8 char
643 int u8cc[MAX_MCO]; // composing UTF-8 chars
644#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
645 int filler_lines = 0; // nr of filler lines to be drawn
646 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000647#else
648# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200649#endif
650#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200651 int change_start = MAXCOL; // first col of changed area
652 int change_end = -1; // last col of changed area
653#endif
654 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100655 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200656 int in_multispace = FALSE; // in multiple consecutive spaces
657 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200658#ifdef FEAT_LINEBREAK
659 int need_showbreak = FALSE; // overlong line, skipping first x
660 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100661 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200662#endif
663#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
664 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
665# define LINE_ATTR
666 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100667 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200668#endif
669#ifdef FEAT_SIGNS
670 int sign_present = FALSE;
671 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000672 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200673#endif
674#ifdef FEAT_ARABIC
675 int prev_c = 0; // previous Arabic character
676 int prev_c1 = 0; // first composing char for prev_c
677#endif
678#if defined(LINE_ATTR)
679 int did_line_attr = 0;
680#endif
681#ifdef FEAT_TERMINAL
682 int get_term_attr = FALSE;
683#endif
684#ifdef FEAT_SYN_HL
685 int cul_attr = 0; // set when 'cursorline' active
686
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200687 // margin columns for the screen line, needed for when 'cursorlineopt'
688 // contains "screenline"
689 int left_curline_col = 0;
690 int right_curline_col = 0;
691#endif
692
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200693#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
694 int feedback_col = 0;
695 int feedback_old_attr = -1;
696#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200697
698#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
699 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000700 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200701#endif
702#ifdef FEAT_CONCEAL
703 int syntax_flags = 0;
704 int syntax_seqnr = 0;
705 int prev_syntax_id = 0;
706 int conceal_attr = HL_ATTR(HLF_CONCEAL);
707 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200708 int did_wcol = FALSE;
709 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100710# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200711# define FIX_FOR_BOGUSCOLS \
712 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100713 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100714 wlv.vcol -= wlv.vcol_off; \
715 wlv.vcol_off = 0; \
716 wlv.col -= wlv.boguscols; \
717 old_boguscols = wlv.boguscols; \
718 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200719 }
720#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100721# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200722#endif
723
724 if (startrow > endrow) // past the end already!
725 return startrow;
726
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100727 CLEAR_FIELD(wlv);
728
729 wlv.lnum = lnum;
730 wlv.startrow = startrow;
731 wlv.row = startrow;
732 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200733
734 if (!number_only)
735 {
736 // To speed up the loop below, set extra_check when there is linebreak,
737 // trailing white space and/or syntax processing to be done.
738#ifdef FEAT_LINEBREAK
739 extra_check = wp->w_p_lbr;
740#endif
741#ifdef FEAT_SYN_HL
742 if (syntax_present(wp) && !wp->w_s->b_syn_error
743# ifdef SYN_TIME_LIMIT
744 && !wp->w_s->b_syn_slow
745# endif
746 )
747 {
748 // Prepare for syntax highlighting in this line. When there is an
749 // error, stop syntax highlighting.
750 save_did_emsg = did_emsg;
751 did_emsg = FALSE;
752 syntax_start(wp, lnum);
753 if (did_emsg)
754 wp->w_s->b_syn_error = TRUE;
755 else
756 {
757 did_emsg = save_did_emsg;
758#ifdef SYN_TIME_LIMIT
759 if (!wp->w_s->b_syn_slow)
760#endif
761 {
762 has_syntax = TRUE;
763 extra_check = TRUE;
764 }
765 }
766 }
767
768 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100769 wlv.color_cols = wp->w_p_cc_cols;
770 if (wlv.color_cols != NULL)
771 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772#endif
773
774#ifdef FEAT_TERMINAL
775 if (term_show_buffer(wp->w_buffer))
776 {
777 extra_check = TRUE;
778 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100779 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200780 }
781#endif
782
783#ifdef FEAT_SPELL
784 if (wp->w_p_spell
785 && *wp->w_s->b_p_spl != NUL
786 && wp->w_s->b_langp.ga_len > 0
787 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
788 {
789 // Prepare for spell checking.
790 has_spell = TRUE;
791 extra_check = TRUE;
792
793 // Get the start of the next line, so that words that wrap to the
794 // next line are found too: "et<line-break>al.".
795 // Trick: skip a few chars for C/shell/Vim comments
796 nextline[SPWORDLEN] = NUL;
797 if (lnum < wp->w_buffer->b_ml.ml_line_count)
798 {
799 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
800 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
801 }
802
803 // When a word wrapped from the previous line the start of the
804 // current line is valid.
805 if (lnum == checked_lnum)
806 cur_checked_col = checked_col;
807 checked_lnum = 0;
808
809 // When there was a sentence end in the previous line may require a
810 // word starting with capital in this line. In line 1 always check
811 // the first word.
812 if (lnum != capcol_lnum)
813 cap_col = -1;
814 if (lnum == 1)
815 cap_col = 0;
816 capcol_lnum = 0;
817 }
818#endif
819
820 // handle Visual active in this window
821 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
822 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100823 pos_T *top, *bot;
824
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200825 if (LTOREQ_POS(curwin->w_cursor, VIsual))
826 {
827 // Visual is after curwin->w_cursor
828 top = &curwin->w_cursor;
829 bot = &VIsual;
830 }
831 else
832 {
833 // Visual is before curwin->w_cursor
834 top = &VIsual;
835 bot = &curwin->w_cursor;
836 }
837 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
838 if (VIsual_mode == Ctrl_V)
839 {
840 // block mode
841 if (lnum_in_visual_area)
842 {
843 fromcol = wp->w_old_cursor_fcol;
844 tocol = wp->w_old_cursor_lcol;
845 }
846 }
847 else
848 {
849 // non-block mode
850 if (lnum > top->lnum && lnum <= bot->lnum)
851 fromcol = 0;
852 else if (lnum == top->lnum)
853 {
854 if (VIsual_mode == 'V') // linewise
855 fromcol = 0;
856 else
857 {
858 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
859 if (gchar_pos(top) == NUL)
860 tocol = fromcol + 1;
861 }
862 }
863 if (VIsual_mode != 'V' && lnum == bot->lnum)
864 {
865 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
866 {
867 fromcol = -10;
868 tocol = MAXCOL;
869 }
870 else if (bot->col == MAXCOL)
871 tocol = MAXCOL;
872 else
873 {
874 pos = *bot;
875 if (*p_sel == 'e')
876 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
877 else
878 {
879 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
880 ++tocol;
881 }
882 }
883 }
884 }
885
886 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200887 if (!highlight_match && lnum == curwin->w_cursor.lnum
888 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200889#ifdef FEAT_GUI
890 && !gui.in_use
891#endif
892 )
893 noinvcur = TRUE;
894
895 // if inverting in this line set area_highlighting
896 if (fromcol >= 0)
897 {
898 area_highlighting = TRUE;
899 vi_attr = HL_ATTR(HLF_V);
900#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
901 if ((clip_star.available && !clip_star.owned
902 && clip_isautosel_star())
903 || (clip_plus.available && !clip_plus.owned
904 && clip_isautosel_plus()))
905 vi_attr = HL_ATTR(HLF_VNC);
906#endif
907 }
908 }
909
910 // handle 'incsearch' and ":s///c" highlighting
911 else if (highlight_match
912 && wp == curwin
913 && lnum >= curwin->w_cursor.lnum
914 && lnum <= curwin->w_cursor.lnum + search_match_lines)
915 {
916 if (lnum == curwin->w_cursor.lnum)
917 getvcol(curwin, &(curwin->w_cursor),
918 (colnr_T *)&fromcol, NULL, NULL);
919 else
920 fromcol = 0;
921 if (lnum == curwin->w_cursor.lnum + search_match_lines)
922 {
923 pos.lnum = lnum;
924 pos.col = search_match_endcol;
925 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
926 }
927 else
928 tocol = MAXCOL;
929 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100930 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200931 tocol = fromcol + 1;
932 area_highlighting = TRUE;
933 vi_attr = HL_ATTR(HLF_I);
934 }
935 }
936
937#ifdef FEAT_DIFF
938 filler_lines = diff_check(wp, lnum);
939 if (filler_lines < 0)
940 {
941 if (filler_lines == -1)
942 {
943 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100944 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200945 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100946 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200947 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100948 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200949 }
950 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100951 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200952 filler_lines = 0;
953 area_highlighting = TRUE;
954 }
955 if (lnum == wp->w_topline)
956 filler_lines = wp->w_topfill;
957 filler_todo = filler_lines;
958#endif
959
960#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100961 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000962 if (sign_present)
963 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964#endif
965
966#ifdef LINE_ATTR
967# ifdef FEAT_SIGNS
968 // If this line has a sign with line highlighting set line_attr.
969 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200970 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200971# endif
972# if defined(FEAT_QUICKFIX)
973 // Highlight the current line in the quickfix window.
974 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
975 line_attr = HL_ATTR(HLF_QFL);
976# endif
977 if (line_attr != 0)
978 area_highlighting = TRUE;
979#endif
980
981 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
982 ptr = line;
983
984#ifdef FEAT_SPELL
985 if (has_spell && !number_only)
986 {
987 // For checking first word with a capital skip white space.
988 if (cap_col == 0)
989 cap_col = getwhitecols(line);
990
991 // To be able to spell-check over line boundaries copy the end of the
992 // current line into nextline[]. Above the start of the next line was
993 // copied to nextline[SPWORDLEN].
994 if (nextline[SPWORDLEN] == NUL)
995 {
996 // No next line or it is empty.
997 nextlinecol = MAXCOL;
998 nextline_idx = 0;
999 }
1000 else
1001 {
1002 v = (long)STRLEN(line);
1003 if (v < SPWORDLEN)
1004 {
1005 // Short line, use it completely and append the start of the
1006 // next line.
1007 nextlinecol = 0;
1008 mch_memmove(nextline, line, (size_t)v);
1009 STRMOVE(nextline + v, nextline + SPWORDLEN);
1010 nextline_idx = v + 1;
1011 }
1012 else
1013 {
1014 // Long line, use only the last SPWORDLEN bytes.
1015 nextlinecol = v - SPWORDLEN;
1016 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1017 nextline_idx = SPWORDLEN + 1;
1018 }
1019 }
1020 }
1021#endif
1022
1023 if (wp->w_p_list)
1024 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001025 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001026 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001027 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001028 || wp->w_lcs_chars.trail
1029 || wp->w_lcs_chars.lead
1030 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001032
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001033 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001034 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001035 {
1036 trailcol = (colnr_T)STRLEN(ptr);
1037 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1038 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001039 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001041 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001042 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001043 {
1044 leadcol = 0;
1045 while (VIM_ISWHITE(ptr[leadcol]))
1046 ++leadcol;
1047 if (ptr[leadcol] == NUL)
1048 // in a line full of spaces all of them are treated as trailing
1049 leadcol = (colnr_T)0;
1050 else
1051 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001052 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001053 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054 }
1055
1056 wcr_attr = get_wcr_attr(wp);
1057 if (wcr_attr != 0)
1058 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001059 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060 area_highlighting = TRUE;
1061 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001062
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001063#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001065 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066#endif
1067
1068 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1069 // first character to be displayed.
1070 if (wp->w_p_wrap)
1071 v = wp->w_skipcol;
1072 else
1073 v = wp->w_leftcol;
1074 if (v > 0 && !number_only)
1075 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001076 char_u *prev_ptr = ptr;
1077 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001078 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001079
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001080 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001081 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001082 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001083 charsize = win_lbr_chartabsize(&cts, NULL);
1084 cts.cts_vcol += charsize;
1085 prev_ptr = cts.cts_ptr;
1086 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001088 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001089 ptr = cts.cts_ptr;
1090 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001091
1092 // When:
1093 // - 'cuc' is set, or
1094 // - 'colorcolumn' is set, or
1095 // - 'virtualedit' is set, or
1096 // - the visual mode is active,
1097 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001098 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001099#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001100 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001101#endif
1102 virtual_active() ||
1103 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001104 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105
1106 // Handle a character that's not completely on the screen: Put ptr at
1107 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001108 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001110 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001111 ptr = prev_ptr;
1112 // If the character fits on the screen, don't need to skip it.
1113 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001114 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1115 && wlv.col == 0)
1116 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001117 }
1118
1119 // Adjust for when the inverted text is before the screen,
1120 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001121 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001123 else if (fromcol >= 0 && fromcol < wlv.vcol)
1124 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125
1126#ifdef FEAT_LINEBREAK
1127 // When w_skipcol is non-zero, first line needs 'showbreak'
1128 if (wp->w_p_wrap)
1129 need_showbreak = TRUE;
1130#endif
1131#ifdef FEAT_SPELL
1132 // When spell checking a word we need to figure out the start of the
1133 // word and if it's badly spelled or not.
1134 if (has_spell)
1135 {
1136 int len;
1137 colnr_T linecol = (colnr_T)(ptr - line);
1138 hlf_T spell_hlf = HLF_COUNT;
1139
1140 pos = wp->w_cursor;
1141 wp->w_cursor.lnum = lnum;
1142 wp->w_cursor.col = linecol;
1143 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1144
1145 // spell_move_to() may call ml_get() and make "line" invalid
1146 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1147 ptr = line + linecol;
1148
1149 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1150 {
1151 // no bad word found at line start, don't check until end of a
1152 // word
1153 spell_hlf = HLF_COUNT;
1154 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1155 }
1156 else
1157 {
1158 // bad word found, use attributes until end of word
1159 word_end = wp->w_cursor.col + len + 1;
1160
1161 // Turn index into actual attributes.
1162 if (spell_hlf != HLF_COUNT)
1163 spell_attr = highlight_attr[spell_hlf];
1164 }
1165 wp->w_cursor = pos;
1166
1167# ifdef FEAT_SYN_HL
1168 // Need to restart syntax highlighting for this line.
1169 if (has_syntax)
1170 syntax_start(wp, lnum);
1171# endif
1172 }
1173#endif
1174 }
1175
1176 // Correct highlighting for cursor that can't be disabled.
1177 // Avoids having to check this for each character.
1178 if (fromcol >= 0)
1179 {
1180 if (noinvcur)
1181 {
1182 if ((colnr_T)fromcol == wp->w_virtcol)
1183 {
1184 // highlighting starts at cursor, let it start just after the
1185 // cursor
1186 fromcol_prev = fromcol;
1187 fromcol = -1;
1188 }
1189 else if ((colnr_T)fromcol < wp->w_virtcol)
1190 // restart highlighting after the cursor
1191 fromcol_prev = wp->w_virtcol;
1192 }
1193 if (fromcol >= tocol)
1194 fromcol = -1;
1195 }
1196
1197#ifdef FEAT_SEARCH_EXTRA
1198 if (!number_only)
1199 {
1200 v = (long)(ptr - line);
1201 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1202 &line, &screen_search_hl,
1203 &search_attr);
1204 ptr = line + v; // "line" may have been updated
1205 }
1206#endif
1207
1208#ifdef FEAT_SYN_HL
1209 // Cursor line highlighting for 'cursorline' in the current window.
1210 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1211 {
1212 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001213 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001214 if (!(wp == curwin && VIsual_active)
1215 && wp->w_p_culopt_flags != CULOPT_NBR)
1216 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001217 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1219
1220 // Only set line_attr here when "screenline" is not present in
1221 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001222 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223 {
1224 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001225# ifdef FEAT_SIGNS
1226 // Combine the 'cursorline' and sign highlighting, depending on
1227 // the sign priority.
1228 if (sign_present && sattr.sat_linehl > 0)
1229 {
1230 if (sattr.sat_priority >= 100)
1231 line_attr = hl_combine_attr(cul_attr, line_attr);
1232 else
1233 line_attr = hl_combine_attr(line_attr, cul_attr);
1234 }
1235 else
1236# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001237# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001238 // let the line attribute overrule 'cursorline', otherwise
1239 // it disappears when both have background set;
1240 // 'cursorline' can use underline or bold to make it show
1241 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001242# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001243 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001244# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001245 }
1246 else
1247 {
1248 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1250 }
1251 area_highlighting = TRUE;
1252 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001253 }
1254#endif
1255
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001256#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001257 {
1258 char_u *prop_start;
1259
1260 text_prop_count = get_text_props(wp->w_buffer, lnum,
1261 &prop_start, FALSE);
1262 if (text_prop_count > 0)
1263 {
1264 // Make a copy of the properties, so that they are properly
1265 // aligned.
1266 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1267 if (text_props != NULL)
1268 mch_memmove(text_props, prop_start,
1269 text_prop_count * sizeof(textprop_T));
1270
1271 // Allocate an array for the indexes.
1272 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001273 if (text_prop_idxs == NULL)
1274 VIM_CLEAR(text_props);
1275
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001276 area_highlighting = TRUE;
1277 extra_check = TRUE;
1278 }
1279 }
1280#endif
1281
Bram Moolenaar1306b362022-08-06 15:59:06 +01001282 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001283
1284 // Repeat for the whole displayed line.
1285 for (;;)
1286 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001287 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001289 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001290#endif
1291#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001292 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001294
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001296 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001298#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001299 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001300 {
1301 cul_attr = 0;
1302 line_attr = line_attr_save;
1303 }
1304#endif
1305
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001307 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001308 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001309 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 if (cmdwin_type != 0 && wp == curwin)
1311 {
1312 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001313 wlv.n_extra = 1;
1314 wlv.c_extra = cmdwin_type;
1315 wlv.c_final = NUL;
1316 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317 }
1318 }
1319#endif
1320
1321#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001322 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001323 {
1324 int fdc = compute_foldcolumn(wp, 0);
1325
Bram Moolenaar1306b362022-08-06 15:59:06 +01001326 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 if (fdc > 0)
1328 {
1329 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1330 // already be in use.
1331 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001332 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 if (p_extra_free != NULL)
1334 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001335 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001336 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001337 p_extra_free[wlv.n_extra] = NUL;
1338 wlv.p_extra = p_extra_free;
1339 wlv.c_extra = NUL;
1340 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001341 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001342 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001343 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1344 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001345 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001346 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 }
1348 }
1349 }
1350#endif
1351
1352#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001353 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001354 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001355 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 // Show the sign column when there are any signs in this
1357 // buffer or when using Netbeans.
1358 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001359 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1360 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001361 }
1362#endif
1363
Bram Moolenaar1306b362022-08-06 15:59:06 +01001364 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001366 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 // Display the absolute or relative line number. After the
1368 // first fill with blanks when the 'n' flag isn't in 'cpo'
1369 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001370 && (wlv.row == startrow + filler_lines
1371 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 {
1373#ifdef FEAT_SIGNS
1374 // If 'signcolumn' is set to 'number' and a sign is present
1375 // in 'lnum', then display the sign instead of the line
1376 // number.
1377 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1378 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001379 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1380 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381 else
1382#endif
1383 {
1384 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001385 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 {
1387 long num;
1388 char *fmt = "%*ld ";
1389
1390 if (wp->w_p_nu && !wp->w_p_rnu)
1391 // 'number' + 'norelativenumber'
1392 num = (long)lnum;
1393 else
1394 {
1395 // 'relativenumber', don't use negative numbers
1396 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1397 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1398 {
1399 // 'number' + 'relativenumber'
1400 num = lnum;
1401 fmt = "%-*ld ";
1402 }
1403 }
1404
1405 sprintf((char *)extra, fmt,
1406 number_width(wp), num);
1407 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001408 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1409 ++wlv.p_extra)
1410 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411#ifdef FEAT_RIGHTLEFT
1412 if (wp->w_p_rl) // reverse line numbers
1413 {
1414 char_u *p1, *p2;
1415 int t;
1416
1417 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001418 p2 = skipwhite(extra);
1419 p2 = skiptowhite(p2) - 1;
1420 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 {
1422 t = *p1;
1423 *p1 = *p2;
1424 *p2 = t;
1425 }
1426 }
1427#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001428 wlv.p_extra = extra;
1429 wlv.c_extra = NUL;
1430 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 }
1432 else
1433 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001434 wlv.c_extra = ' ';
1435 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001437 wlv.n_extra = number_width(wp) + 1;
1438 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001439#ifdef FEAT_SYN_HL
1440 // When 'cursorline' is set highlight the line number of
1441 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001442 // When 'cursorlineopt' does not have "line" only
1443 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001444 // TODO: Can we use CursorLine instead of CursorLineNr
1445 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001446 if (wp->w_p_cul
1447 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001449 && (wlv.row == startrow + filler_lines
1450 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001451 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001452 wlv.char_attr = hl_combine_attr(wcr_attr,
1453 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001455 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1456 && HL_ATTR(HLF_LNA) != 0)
1457 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001458 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001459 HL_ATTR(HLF_LNA));
1460 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1461 && HL_ATTR(HLF_LNB) != 0)
1462 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001463 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001464 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 }
James McCoya80aad72021-12-22 19:45:28 +00001466#ifdef FEAT_SIGNS
1467 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001468 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001469#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470 }
1471 }
1472
1473#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001474 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1475 && wlv.n_extra == 0
1476 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001478 wlv.draw_state = WL_BRI;
1479 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1480 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483
1484 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001485 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001488 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001489 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490# ifdef FEAT_DIFF
1491 && filler_lines == 0
1492# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001493# ifdef FEAT_PROP_POPUP
1494 && !dont_use_showbreak
1495# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496 )
1497 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001498 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001500 if (wlv.diff_hlf != (hlf_T)0)
1501 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001503 wlv.p_extra = NULL;
1504 wlv.c_extra = ' ';
1505 wlv.c_final = NUL;
1506 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001508 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001509 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001510 wlv.n_extra -= win_col_off2(wp);
1511 if (wlv.n_extra < 0)
1512 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001513 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001514 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001515 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001516 // Correct end of highlighted area for 'breakindent',
1517 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001518 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001519 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 }
1521 }
1522#endif
1523
1524#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001525 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001526 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001527 char_u *sbr;
1528
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530# ifdef FEAT_DIFF
1531 if (filler_todo > 0)
1532 {
1533 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001534 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001536 wlv.c_extra = '-';
1537 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 }
1539 else
1540 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001541 wlv.c_extra = wp->w_fill_chars.diff;
1542 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 }
1544# ifdef FEAT_RIGHTLEFT
1545 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001546 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001547 else
1548# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001549 wlv.n_extra = wp->w_width - wlv.col;
1550 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 }
1552# endif
1553# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001554 sbr = get_showbreak_value(wp);
1555 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 {
1557 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001558 wlv.p_extra = sbr;
1559 wlv.c_extra = NUL;
1560 wlv.c_final = NUL;
1561 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001562 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1563 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001564 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 // Correct end of highlighted area for 'showbreak',
1566 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001567 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001568 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001570 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1571 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572# ifdef FEAT_SYN_HL
1573 // combine 'showbreak' with 'cursorline'
1574 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001575 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1576 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001577# endif
1578 }
1579# endif
1580 }
1581#endif
1582
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001585 wlv.draw_state = WL_LINE;
1586 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 {
1588 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001589 wlv.n_extra = wlv.saved_n_extra;
1590 wlv.c_extra = wlv.saved_c_extra;
1591 wlv.c_final = wlv.saved_c_final;
1592 wlv.p_extra = wlv.saved_p_extra;
1593 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 }
1595 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001596 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 }
1598 }
1599#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001601 && wlv.vcol >= left_curline_col
1602 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001604 cul_attr = HL_ATTR(HLF_CUL);
1605 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001606 }
1607#endif
1608
1609 // When still displaying '$' of change command, stop at cursor.
1610 // When only displaying the (relative) line number and that's done,
1611 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001612 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001613 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001614 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001615#ifdef FEAT_DIFF
1616 && filler_todo <= 0
1617#endif
1618 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001619 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001620 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1621 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 // Pretend we have finished updating the window. Except when
1623 // 'cursorcolumn' is set.
1624#ifdef FEAT_SYN_HL
1625 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001626 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 else
1628#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001629 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 break;
1631 }
1632
Bram Moolenaar1306b362022-08-06 15:59:06 +01001633 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001634 {
1635 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001636 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001637 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 && (*mb_ptr2cells)(ptr) > 1)
1639 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001640 && vcol_prev < wlv.vcol // not at margin
1641 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001642 area_attr = vi_attr; // start highlighting
1643 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001644 && (wlv.vcol == tocol
1645 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001646 area_attr = 0; // stop highlighting
1647
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001648#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001649 if (text_props != NULL)
1650 {
1651 int pi;
1652 int bcol = (int)(ptr - line);
1653
Bram Moolenaar1306b362022-08-06 15:59:06 +01001654 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001655# ifdef FEAT_LINEBREAK
1656 && !in_linebreak
1657# endif
1658 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001659 --bcol; // still working on the previous char, e.g. Tab
1660
1661 // Check if any active property ends.
1662 for (pi = 0; pi < text_props_active; ++pi)
1663 {
1664 int tpi = text_prop_idxs[pi];
1665
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001666 if (text_props[tpi].tp_col != MAXCOL
1667 && bcol >= text_props[tpi].tp_col - 1
1668 + text_props[tpi].tp_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 {
1670 if (pi + 1 < text_props_active)
1671 mch_memmove(text_prop_idxs + pi,
1672 text_prop_idxs + pi + 1,
1673 sizeof(int)
1674 * (text_props_active - (pi + 1)));
1675 --text_props_active;
1676 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001677# ifdef FEAT_LINEBREAK
1678 // not exactly right but should work in most cases
1679 if (in_linebreak && syntax_attr == text_prop_attr)
1680 syntax_attr = 0;
1681# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682 }
1683 }
1684
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001685# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001686 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001687 // not on the next char yet, don't start another prop
1688 --bcol;
1689# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001691 // With 'nowrap' and not in the first screen line only "below"
1692 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001693 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001694 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001695 ? (*ptr == NUL
1696 && (wp->w_p_wrap
1697 || wlv.row == startrow
1698 || (text_props[text_prop_next].tp_flags
1699 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001700 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001701 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001702 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001703 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1704 {
1705 // first display the '$' after the line
1706 text_prop_follows = TRUE;
1707 break;
1708 }
1709 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001710 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001711 + text_props[text_prop_next].tp_len)
1712 text_prop_idxs[text_props_active++] = text_prop_next;
1713 ++text_prop_next;
1714 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001716 if (wlv.n_extra == 0 || !extra_for_textprop)
1717 {
1718 text_prop_attr = 0;
1719 text_prop_flags = 0;
1720 text_prop_type = NULL;
1721 text_prop_id = 0;
1722 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001723 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001725 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001726 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001727 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001728
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001729 // Sort the properties on priority and/or starting last.
1730 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001731 text_prop_follows = FALSE;
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001732 sort_text_props(wp->w_buffer, text_props,
1733 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001734
1735 for (pi = 0; pi < text_props_active; ++pi)
1736 {
1737 int tpi = text_prop_idxs[pi];
1738 proptype_T *pt = text_prop_type_by_id(
1739 wp->w_buffer, text_props[tpi].tp_type);
1740
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001741 if (pt != NULL && (pt->pt_hl_id > 0
1742 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001743 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001745 if (pt->pt_hl_id > 0)
1746 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 text_prop_type = pt;
1748 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001749 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001750 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001751 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001752 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001753 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
1755 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001756 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001757 && -text_prop_id
1758 <= wp->w_buffer->b_textprop_text.ga_len)
1759 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001760 textprop_T *tp = &text_props[used_tpi];
1761 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001762 ->b_textprop_text.ga_data)[
1763 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001764
1765 // reset the ID in the copy to avoid it being used
1766 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001767 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001769 if (p != NULL)
1770 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001771 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001772 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001773 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001774 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001775 int wrap = (tp->tp_flags & TP_FLAG_WRAP);
1776 int padding = tp->tp_col == MAXCOL
1777 && tp->tp_len > 1
1778 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001779
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001780 // Insert virtual text before the current
1781 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001782 wlv.p_extra = p;
1783 wlv.c_extra = NUL;
1784 wlv.c_final = NUL;
1785 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001786 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001787 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001788 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001789 saved_search_attr = search_attr;
1790 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001791 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001792 if (*ptr == NUL)
1793 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001794 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001795#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001796 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001797 {
1798 // no 'showbreak' before "below" text property
1799 // or after "right" text property
1800 need_showbreak = FALSE;
1801 dont_use_showbreak = TRUE;
1802 }
1803#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001804 // Keep in sync with where
1805 // textprop_size_after_trunc() is called in
1806 // win_lbr_chartabsize().
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001807 if ((right || below || !wrap || padding > 0)
1808 && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001809 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001810 char_u *prev_p_extra = wlv.p_extra;
1811 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001812
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001813 // Take care of padding, right-align and
1814 // truncation.
1815 // Shared with win_lbr_chartabsize(), must do
1816 // exactly the same.
1817 start_line = text_prop_position(wp, tp,
1818 wlv.col,
1819 &wlv.n_extra, &wlv.p_extra,
1820 &n_attr, &n_attr_skip);
1821 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001822 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001823 // wlv.p_extra was allocated
1824 vim_free(p_extra_free2);
1825 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001826 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001827
1828 // When 'wrap' is off then for "below" we need
1829 // to start a new line explictly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01001830 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001831 {
1832 draw_screen_line(wp, &wlv);
1833
1834 // When line got too long for screen break
1835 // here.
1836 if (wlv.row == endrow)
1837 {
1838 ++wlv.row;
1839 break;
1840 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001841 win_line_start(wp, &wlv, TRUE);
1842 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001843 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001844 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001845 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001846
1847 // If another text prop follows the condition below at
1848 // the last window column must know.
1849 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001850 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001852 else if (text_prop_next < text_prop_count
1853 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001854 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1855 || (!wp->w_p_wrap
1856 && wlv.col == wp->w_width - 1
1857 && (text_props[text_prop_next].tp_flags
1858 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001859 // When at last-but-one character and a text property
1860 // follows after it, we may need to flush the line after
1861 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001862 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001863 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001864 }
1865#endif
1866
Bram Moolenaare38fc862022-08-11 17:24:50 +01001867#ifdef FEAT_SEARCH_EXTRA
1868 if (wlv.n_extra == 0)
1869 {
1870 // Check for start/end of 'hlsearch' and other matches.
1871 // After end, check for start/end of next match.
1872 // When another match, have to check for start again.
1873 v = (long)(ptr - line);
1874 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1875 &screen_search_hl, &has_match_conc,
1876 &match_conc, did_line_attr, lcs_eol_one,
1877 &on_last_col);
1878 ptr = line + v; // "line" may have been changed
1879 prev_ptr = ptr;
1880
1881 // Do not allow a conceal over EOL otherwise EOL will be missed
1882 // and bad things happen.
1883 if (*ptr == NUL)
1884 has_match_conc = 0;
1885 }
1886#endif
1887
1888#ifdef FEAT_DIFF
1889 if (wlv.diff_hlf != (hlf_T)0)
1890 {
1891 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1892 && wlv.n_extra == 0)
1893 wlv.diff_hlf = HLF_TXD; // changed text
1894 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1895 && wlv.n_extra == 0)
1896 wlv.diff_hlf = HLF_CHD; // changed line
1897 line_attr = HL_ATTR(wlv.diff_hlf);
1898 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1899 && wp->w_p_culopt_flags != CULOPT_NBR
1900 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1901 && wlv.vcol <= right_curline_col)))
1902 line_attr = hl_combine_attr(
1903 line_attr, HL_ATTR(HLF_CUL));
1904 }
1905#endif
1906
Bram Moolenaara74fda62019-10-19 17:38:03 +02001907#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001909 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001910 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001911# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001912 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001913 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001914# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001915 // Get syntax attribute.
1916 if (has_syntax)
1917 {
1918 // Get the syntax attribute for the character. If there
1919 // is an error, disable syntax highlighting.
1920 save_did_emsg = did_emsg;
1921 did_emsg = FALSE;
1922
1923 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001924 if (v == prev_syntax_col)
1925 // at same column again
1926 syntax_attr = prev_syntax_attr;
1927 else
1928 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001929# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001930 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001931# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001932 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001933# ifdef FEAT_SPELL
1934 has_spell ? &can_spell :
1935# endif
1936 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001937 prev_syntax_col = v;
1938 prev_syntax_attr = syntax_attr;
1939 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001940
Bram Moolenaar34390282019-10-16 14:38:26 +02001941 if (did_emsg)
1942 {
1943 wp->w_s->b_syn_error = TRUE;
1944 has_syntax = FALSE;
1945 syntax_attr = 0;
1946 }
1947 else
1948 did_emsg = save_did_emsg;
1949# ifdef SYN_TIME_LIMIT
1950 if (wp->w_s->b_syn_slow)
1951 has_syntax = FALSE;
1952# endif
1953
1954 // Need to get the line again, a multi-line regexp may
1955 // have made it invalid.
1956 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1957 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001958 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001959# ifdef FEAT_CONCEAL
1960 // no concealing past the end of the line, it interferes
1961 // with line highlighting
1962 if (*ptr == NUL)
1963 syntax_flags = 0;
1964 else
1965 syntax_flags = get_syntax_info(&syntax_seqnr);
1966# endif
1967 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001968 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001969# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001970 // Combine text property highlight into syntax highlight.
1971 if (text_prop_type != NULL)
1972 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001973 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001974 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1975 else
1976 syntax_attr = text_prop_attr;
1977 }
1978# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001979#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001980
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001981 // Decide which of the highlight attributes to use.
1982 attr_pri = TRUE;
1983#ifdef LINE_ATTR
1984 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001985 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001986 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001987 if (!highlight_match)
1988 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001990# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001991 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001992# endif
1993 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001995 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001996 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001997# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001998 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001999# endif
2000 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002002 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
2003 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 {
2005 // Use line_attr when not in the Visual or 'incsearch' area
2006 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002007# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002008 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002009# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002010 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002011# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 attr_pri = FALSE;
2013 }
2014#else
2015 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002018 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019#endif
2020 else
2021 {
2022 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002023#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002024 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002025#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002026 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002027#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002029#ifdef FEAT_PROP_POPUP
2030 // override with text property highlight when "override" is TRUE
2031 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002033#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002035
2036 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002037 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002038 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002039 if (wlv.char_attr == 0)
2040 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002041 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002042 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002043 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044
2045 // Get the next character to put on the screen.
2046
2047 // The "p_extra" points to the extra stuff that is inserted to
2048 // represent special characters (non-printable stuff) and other
2049 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002050 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2052 // "p_extra[n_extra]".
2053 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002054 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002056 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002058 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2059 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2061 if (enc_utf8 && utf_char2len(c) > 1)
2062 {
2063 mb_utf8 = TRUE;
2064 u8cc[0] = 0;
2065 c = 0xc0;
2066 }
2067 else
2068 mb_utf8 = FALSE;
2069 }
2070 else
2071 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002072 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 if (has_mbyte)
2074 {
2075 mb_c = c;
2076 if (enc_utf8)
2077 {
2078 // If the UTF-8 character is more than one byte:
2079 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002080 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002082 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 mb_l = 1;
2084 else if (mb_l > 1)
2085 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002086 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 mb_utf8 = TRUE;
2088 c = 0xc0;
2089 }
2090 }
2091 else
2092 {
2093 // if this is a DBCS character, put it in "mb_c"
2094 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002095 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 mb_l = 1;
2097 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002098 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 }
2100 if (mb_l == 0) // at the NUL at end-of-line
2101 mb_l = 1;
2102
2103 // If a double-width char doesn't fit display a '>' in the
2104 // last column.
2105 if ((
2106# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002107 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002108# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002109 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 && (*mb_char2cells)(mb_c) == 2)
2111 {
2112 c = '>';
2113 mb_c = c;
2114 mb_l = 1;
2115 mb_utf8 = FALSE;
2116 multi_attr = HL_ATTR(HLF_AT);
2117#ifdef FEAT_SYN_HL
2118 if (cul_attr)
2119 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2120#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002121 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002122
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123 // put the pointer back to output the double-width
2124 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002125 ++wlv.n_extra;
2126 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 }
2128 else
2129 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002130 wlv.n_extra -= mb_l - 1;
2131 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 }
2133 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002134 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002135 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002136 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002137#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002138 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002139 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002140 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002141 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002142 if (search_attr == 0)
2143 search_attr = saved_search_attr;
2144 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002145#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 }
2147 else
2148 {
2149#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002150 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002152 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002154 // Get a character from the line itself.
2155 c = *ptr;
2156#ifdef FEAT_LINEBREAK
2157 c0 = *ptr;
2158#endif
2159 if (has_mbyte)
2160 {
2161 mb_c = c;
2162 if (enc_utf8)
2163 {
2164 // If the UTF-8 character is more than one byte: Decode it
2165 // into "mb_c".
2166 mb_l = utfc_ptr2len(ptr);
2167 mb_utf8 = FALSE;
2168 if (mb_l > 1)
2169 {
2170 mb_c = utfc_ptr2char(ptr, u8cc);
2171 // Overlong encoded ASCII or ASCII with composing char
2172 // is displayed normally, except a NUL.
2173 if (mb_c < 0x80)
2174 {
2175 c = mb_c;
2176#ifdef FEAT_LINEBREAK
2177 c0 = mb_c;
2178#endif
2179 }
2180 mb_utf8 = TRUE;
2181
2182 // At start of the line we can have a composing char.
2183 // Draw it as a space with a composing char.
2184 if (utf_iscomposing(mb_c))
2185 {
2186 int i;
2187
2188 for (i = Screen_mco - 1; i > 0; --i)
2189 u8cc[i] = u8cc[i - 1];
2190 u8cc[0] = mb_c;
2191 mb_c = ' ';
2192 }
2193 }
2194
2195 if ((mb_l == 1 && c >= 0x80)
2196 || (mb_l >= 1 && mb_c == 0)
2197 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2198 {
2199 // Illegal UTF-8 byte: display as <xx>.
2200 // Non-BMP character : display as ? or fullwidth ?.
2201 transchar_hex(extra, mb_c);
2202# ifdef FEAT_RIGHTLEFT
2203 if (wp->w_p_rl) // reverse
2204 rl_mirror(extra);
2205# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002206 wlv.p_extra = extra;
2207 c = *wlv.p_extra;
2208 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002210 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2211 wlv.c_extra = NUL;
2212 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002213 if (area_attr == 0 && search_attr == 0)
2214 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002215 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002216 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002217 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002218 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002219 }
2220 }
2221 else if (mb_l == 0) // at the NUL at end-of-line
2222 mb_l = 1;
2223#ifdef FEAT_ARABIC
2224 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2225 {
2226 // Do Arabic shaping.
2227 int pc, pc1, nc;
2228 int pcc[MAX_MCO];
2229
2230 // The idea of what is the previous and next
2231 // character depends on 'rightleft'.
2232 if (wp->w_p_rl)
2233 {
2234 pc = prev_c;
2235 pc1 = prev_c1;
2236 nc = utf_ptr2char(ptr + mb_l);
2237 prev_c1 = u8cc[0];
2238 }
2239 else
2240 {
2241 pc = utfc_ptr2char(ptr + mb_l, pcc);
2242 nc = prev_c;
2243 pc1 = pcc[0];
2244 }
2245 prev_c = mb_c;
2246
2247 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2248 }
2249 else
2250 prev_c = mb_c;
2251#endif
2252 }
2253 else // enc_dbcs
2254 {
2255 mb_l = MB_BYTE2LEN(c);
2256 if (mb_l == 0) // at the NUL at end-of-line
2257 mb_l = 1;
2258 else if (mb_l > 1)
2259 {
2260 // We assume a second byte below 32 is illegal.
2261 // Hopefully this is OK for all double-byte encodings!
2262 if (ptr[1] >= 32)
2263 mb_c = (c << 8) + ptr[1];
2264 else
2265 {
2266 if (ptr[1] == NUL)
2267 {
2268 // head byte at end of line
2269 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002270 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002271 }
2272 else
2273 {
2274 // illegal tail byte
2275 mb_l = 2;
2276 STRCPY(extra, "XX");
2277 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 wlv.p_extra = extra;
2279 wlv.n_extra = (int)STRLEN(extra) - 1;
2280 wlv.c_extra = NUL;
2281 wlv.c_final = NUL;
2282 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002283 if (area_attr == 0 && search_attr == 0)
2284 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002285 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002286 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002287 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002288 // save current attr
2289 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 }
2291 mb_c = c;
2292 }
2293 }
2294 }
2295 // If a double-width char doesn't fit display a '>' in the
2296 // last column; the character is displayed at the start of the
2297 // next line.
2298 if ((
2299# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002300 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002301# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002302 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 && (*mb_char2cells)(mb_c) == 2)
2304 {
2305 c = '>';
2306 mb_c = c;
2307 mb_utf8 = FALSE;
2308 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002309 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002310 // Put pointer back so that the character will be
2311 // displayed at the start of the next line.
2312 --ptr;
2313#ifdef FEAT_CONCEAL
2314 did_decrement_ptr = TRUE;
2315#endif
2316 }
2317 else if (*ptr != NUL)
2318 ptr += mb_l - 1;
2319
2320 // If a double-width char doesn't fit at the left side display
2321 // a '<' in the first column. Don't do this for unprintable
2322 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002323 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002325 wlv.n_extra = 1;
2326 wlv.c_extra = MB_FILLER_CHAR;
2327 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328 c = ' ';
2329 if (area_attr == 0 && search_attr == 0)
2330 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002331 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002332 extra_attr = hl_combine_attr(
2333 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002334 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 }
2336 mb_c = c;
2337 mb_utf8 = FALSE;
2338 mb_l = 1;
2339 }
2340
2341 }
2342 ++ptr;
2343
2344 if (extra_check)
2345 {
2346#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347 // Check spelling (unless at the end of the line).
2348 // Only do this when there is no syntax highlighting, the
2349 // @Spell cluster is not used or the current syntax item
2350 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002351 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 if (has_spell && v >= word_end && v > cur_checked_col)
2353 {
2354 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002355 // do not calculate cap_col at the end of the line or when
2356 // only white space is following
2357 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002358# ifdef FEAT_SYN_HL
2359 !has_syntax ||
2360# endif
2361 can_spell))
2362 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002363 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002364 int len;
2365 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002366
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369
2370 // Use nextline[] if possible, it has the start of the
2371 // next line concatenated.
2372 if ((prev_ptr - line) - nextlinecol >= 0)
2373 p = nextline + (prev_ptr - line) - nextlinecol;
2374 else
2375 p = prev_ptr;
2376 cap_col -= (int)(prev_ptr - line);
2377 len = spell_check(wp, p, &spell_hlf, &cap_col,
2378 nochange);
2379 word_end = v + len;
2380
2381 // In Insert mode only highlight a word that
2382 // doesn't touch the cursor.
2383 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002384 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002385 && wp->w_cursor.lnum == lnum
2386 && wp->w_cursor.col >=
2387 (colnr_T)(prev_ptr - line)
2388 && wp->w_cursor.col < (colnr_T)word_end)
2389 {
2390 spell_hlf = HLF_COUNT;
2391 spell_redraw_lnum = lnum;
2392 }
2393
2394 if (spell_hlf == HLF_COUNT && p != prev_ptr
2395 && (p - nextline) + len > nextline_idx)
2396 {
2397 // Remember that the good word continues at the
2398 // start of the next line.
2399 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002400 checked_col = (int)((p - nextline)
2401 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002402 }
2403
2404 // Turn index into actual attributes.
2405 if (spell_hlf != HLF_COUNT)
2406 spell_attr = highlight_attr[spell_hlf];
2407
2408 if (cap_col > 0)
2409 {
2410 if (p != prev_ptr
2411 && (p - nextline) + cap_col >= nextline_idx)
2412 {
2413 // Remember that the word in the next line
2414 // must start with a capital.
2415 capcol_lnum = lnum + 1;
2416 cap_col = (int)((p - nextline) + cap_col
2417 - nextline_idx);
2418 }
2419 else
2420 // Compute the actual column.
2421 cap_col += (int)(prev_ptr - line);
2422 }
2423 }
2424 }
2425 if (spell_attr != 0)
2426 {
2427 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002428 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2429 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002430 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002431 wlv.char_attr = hl_combine_attr(spell_attr,
2432 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002433 }
2434#endif
2435#ifdef FEAT_LINEBREAK
2436 // Found last space before word: check for line break.
2437 if (wp->w_p_lbr && c0 == c
2438 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2439 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002440 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2441 : 0;
2442 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002443 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002444
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002445 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002446# ifdef FEAT_PROP_POPUP
2447 // do not want virtual text counted here
2448 cts.cts_has_prop_with_text = FALSE;
2449# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002450 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002451 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002452
2453 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002454 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002455 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002456 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002457 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2458 if (wlv.n_extra < 0)
2459 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002460 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002461 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002462 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002463 // line break, but for TABs the highlighting should
2464 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002465 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002466
Bram Moolenaar1306b362022-08-06 15:59:06 +01002467 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002468# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002469 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002470 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 wp->w_buffer->b_p_vts_array) - 1;
2472# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002473 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002474 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002475# endif
2476
Bram Moolenaar1306b362022-08-06 15:59:06 +01002477 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2478 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002479# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002480 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002481 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002482# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002483 if (VIM_ISWHITE(c))
2484 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002485# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 if (c == TAB)
2487 // See "Tab alignment" below.
2488 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002489# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002490 if (!wp->w_p_list)
2491 c = ' ';
2492 }
2493 }
2494#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002495 in_multispace = c == ' '
2496 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2497 if (!in_multispace)
2498 multispace_pos = 0;
2499
Bram Moolenaareed9d462021-02-15 20:38:25 +01002500 // 'list': Change char 160 to 'nbsp' and space to 'space'
2501 // setting in 'listchars'. But not when the character is
2502 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002503 if (wp->w_p_list
2504 && ((((c == 160 && mb_l == 1)
2505 || (mb_utf8
2506 && ((mb_c == 160 && mb_l == 2)
2507 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002508 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002509 || (c == ' '
2510 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002511 && (wp->w_lcs_chars.space
2512 || (in_multispace
2513 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002514 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 && ptr - line <= trailcol)))
2516 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002517 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2518 {
2519 c = wp->w_lcs_chars.multispace[multispace_pos++];
2520 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2521 multispace_pos = 0;
2522 }
2523 else
2524 c = (c == ' ') ? wp->w_lcs_chars.space
2525 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 if (area_attr == 0 && search_attr == 0)
2527 {
2528 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002529 extra_attr = hl_combine_attr(wlv.win_attr,
2530 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532 }
2533 mb_c = c;
2534 if (enc_utf8 && utf_char2len(c) > 1)
2535 {
2536 mb_utf8 = TRUE;
2537 u8cc[0] = 0;
2538 c = 0xc0;
2539 }
2540 else
2541 mb_utf8 = FALSE;
2542 }
2543
zeertzjq2e7cba32022-06-10 15:30:32 +01002544 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2545 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002547 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2548 && wp->w_lcs_chars.leadmultispace != NULL)
2549 {
2550 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002551 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2552 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002553 multispace_pos = 0;
2554 }
2555
2556 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2557 c = wp->w_lcs_chars.trail;
2558
2559 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2560 c = wp->w_lcs_chars.lead;
2561
zeertzjq2e7cba32022-06-10 15:30:32 +01002562 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002563 c = wp->w_lcs_chars.space;
2564
2565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 if (!attr_pri)
2567 {
2568 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002569 extra_attr = hl_combine_attr(wlv.win_attr,
2570 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002571 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 }
2573 mb_c = c;
2574 if (enc_utf8 && utf_char2len(c) > 1)
2575 {
2576 mb_utf8 = TRUE;
2577 u8cc[0] = 0;
2578 c = 0xc0;
2579 }
2580 else
2581 mb_utf8 = FALSE;
2582 }
2583 }
2584
2585 // Handling of non-printable characters.
2586 if (!vim_isprintc(c))
2587 {
2588 // when getting a character from the file, we may have to
2589 // turn it into something else on the way to putting it
2590 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002591 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 {
2593 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002594 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002595#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002596 char_u *sbr = get_showbreak_value(wp);
2597
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002598 // only adjust the tab_len, when at the first column
2599 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002600 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2601 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602#endif
2603 // tab amount depends on current column
2604#ifdef FEAT_VARTABS
2605 tab_len = tabstop_padding(vcol_adjusted,
2606 wp->w_buffer->b_p_ts,
2607 wp->w_buffer->b_p_vts_array) - 1;
2608#else
2609 tab_len = (int)wp->w_buffer->b_p_ts
2610 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2611#endif
2612
2613#ifdef FEAT_LINEBREAK
2614 if (!wp->w_p_lbr || !wp->w_p_list)
2615#endif
2616 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618#ifdef FEAT_LINEBREAK
2619 else
2620 {
2621 char_u *p;
2622 int len;
2623 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002624 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002625
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002626# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002627 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002629 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002630
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002632 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 && old_boguscols > 0
2634 && wlv.n_extra > tab_len)
2635 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002636# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002637 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002639 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002640 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002641 if (wp->w_lcs_chars.tab3)
2642 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 if (wlv.n_extra > 0)
2644 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002645 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002647 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002649 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002651 vim_memset(p, ' ', len);
2652 p[len] = NUL;
2653 vim_free(p_extra_free);
2654 p_extra_free = p;
2655 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002656 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002657 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002658
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002659 if (*p == NUL)
2660 {
2661 tab_len = i;
2662 break;
2663 }
2664
2665 // if tab3 is given, use it for the last char
2666 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2667 lcs = wp->w_lcs_chars.tab3;
2668 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002669 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002670 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002671 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002672 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002673# ifdef FEAT_CONCEAL
2674 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2675 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002676 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002677 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002678# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002679 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680 }
2681#endif
2682#ifdef FEAT_CONCEAL
2683 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002684 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002685
2686 // Tab alignment should be identical regardless of
2687 // 'conceallevel' value. So tab compensates of all
2688 // previous concealed characters, and thus resets
2689 // vcol_off and boguscols accumulated so far in the
2690 // line. Note that the tab can be longer than
2691 // 'tabstop' when there are concealed characters.
2692 FIX_FOR_BOGUSCOLS;
2693
2694 // Make sure, the highlighting for the tab char will be
2695 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002696 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002697 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002698 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 tab_len += vc_saved;
2700 }
2701#endif
2702 mb_utf8 = FALSE; // don't draw as UTF-8
2703 if (wp->w_p_list)
2704 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002705 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002706 ? wp->w_lcs_chars.tab3
2707 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002708#ifdef FEAT_LINEBREAK
2709 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002710 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002711 else
2712#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 wlv.c_extra = wp->w_lcs_chars.tab2;
2714 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002716 extra_attr = hl_combine_attr(wlv.win_attr,
2717 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002718 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002719 mb_c = c;
2720 if (enc_utf8 && utf_char2len(c) > 1)
2721 {
2722 mb_utf8 = TRUE;
2723 u8cc[0] = 0;
2724 c = 0xc0;
2725 }
2726 }
2727 else
2728 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002729 wlv.c_final = NUL;
2730 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 c = ' ';
2732 }
2733 }
2734 else if (c == NUL
2735 && (wp->w_p_list
2736 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002737 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738 && VIsual_mode != Ctrl_V
2739 && (
2740# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002741 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002743 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 && !(noinvcur
2745 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002746 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002747 && lcs_eol_one > 0)
2748 {
2749 // Display a '$' after the line or highlight an extra
2750 // character if the line break is included.
2751#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2752 // For a diff line the highlighting continues after the
2753 // "$".
2754 if (
2755# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002756 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757# ifdef LINE_ATTR
2758 &&
2759# endif
2760# endif
2761# ifdef LINE_ATTR
2762 line_attr == 0
2763# endif
2764 )
2765#endif
2766 {
2767 // In virtualedit, visual selections may extend
2768 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002769 if (!(area_highlighting && virtual_active()
2770 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002771 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002772 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002773 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002774 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2775 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002776 else
2777 c = ' ';
2778 lcs_eol_one = -1;
2779 --ptr; // put it back at the NUL
2780 if (!attr_pri)
2781 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002782 extra_attr = hl_combine_attr(wlv.win_attr,
2783 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002784 n_attr = 1;
2785 }
2786 mb_c = c;
2787 if (enc_utf8 && utf_char2len(c) > 1)
2788 {
2789 mb_utf8 = TRUE;
2790 u8cc[0] = 0;
2791 c = 0xc0;
2792 }
2793 else
2794 mb_utf8 = FALSE; // don't draw as UTF-8
2795 }
2796 else if (c != NUL)
2797 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002798 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2799 if (wlv.n_extra == 0)
2800 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801#ifdef FEAT_RIGHTLEFT
2802 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002803 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002805 wlv.c_extra = NUL;
2806 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002807#ifdef FEAT_LINEBREAK
2808 if (wp->w_p_lbr)
2809 {
2810 char_u *p;
2811
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 c = *wlv.p_extra;
2813 p = alloc(wlv.n_extra + 1);
2814 vim_memset(p, ' ', wlv.n_extra);
2815 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2816 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002819 }
2820 else
2821#endif
2822 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002823 wlv.n_extra = byte2cells(c) - 1;
2824 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 }
2826 if (!attr_pri)
2827 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002828 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 extra_attr = hl_combine_attr(wlv.win_attr,
2830 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002831 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832 }
2833 mb_utf8 = FALSE; // don't draw as UTF-8
2834 }
2835 else if (VIsual_active
2836 && (VIsual_mode == Ctrl_V
2837 || VIsual_mode == 'v')
2838 && virtual_active()
2839 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 && (
2842#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002843 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002844#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 {
2847 c = ' ';
2848 --ptr; // put it back at the NUL
2849 }
2850#if defined(LINE_ATTR)
2851 else if ((
2852# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002853 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002854# endif
2855# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002856 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857# endif
2858 line_attr != 0
2859 ) && (
2860# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002861 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002863 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002864# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002865 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866# endif
2867 < wp->w_width)))
2868 {
2869 // Highlight until the right side of the window
2870 c = ' ';
2871 --ptr; // put it back at the NUL
2872
2873 // Remember we do the char for line highlighting.
2874 ++did_line_attr;
2875
2876 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002877 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002879 || (wp->w_p_list &&
2880 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002881 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002882# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002883 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002885 wlv.diff_hlf = HLF_CHD;
2886 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002887 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002888 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2890 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002891 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002892 || (wlv.vcol >= left_curline_col
2893 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002894 wlv.char_attr = hl_combine_attr(
2895 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 }
2897 }
2898# endif
2899# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002900 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002902 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002903 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2904 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002906 if (!wlv.cul_screenline
2907 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002908 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002909 wlv.char_attr = hl_combine_attr(
2910 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002911 }
2912 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2914 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002915 }
2916# endif
2917 }
2918#endif
2919 }
2920
2921#ifdef FEAT_CONCEAL
2922 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002923 && (wp != curwin || lnum != wp->w_cursor.lnum
2924 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2926 && !(lnum_in_visual_area
2927 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2928 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002929 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002930 if (((prev_syntax_id != syntax_seqnr
2931 && (syntax_flags & HL_CONCEAL) != 0)
2932 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002933 && (syn_get_sub_char() != NUL
2934 || (has_match_conc && match_conc)
2935 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002936 && wp->w_p_cole != 3)
2937 {
2938 // First time at this concealed item: display one
2939 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002940 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002941 c = match_conc;
2942 else if (syn_get_sub_char() != NUL)
2943 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002944 else if (wp->w_lcs_chars.conceal != NUL)
2945 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 else
2947 c = ' ';
2948
2949 prev_syntax_id = syntax_seqnr;
2950
Bram Moolenaar1306b362022-08-06 15:59:06 +01002951 if (wlv.n_extra > 0)
2952 wlv.vcol_off += wlv.n_extra;
2953 wlv.vcol += wlv.n_extra;
2954 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 {
2956# ifdef FEAT_RIGHTLEFT
2957 if (wp->w_p_rl)
2958 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002959 wlv.col -= wlv.n_extra;
2960 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002961 }
2962 else
2963# endif
2964 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 wlv.boguscols += wlv.n_extra;
2966 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 }
2968 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002970 n_attr = 0;
2971 }
2972 else if (n_skip == 0)
2973 {
2974 is_concealing = TRUE;
2975 n_skip = 1;
2976 }
2977 mb_c = c;
2978 if (enc_utf8 && utf_char2len(c) > 1)
2979 {
2980 mb_utf8 = TRUE;
2981 u8cc[0] = 0;
2982 c = 0xc0;
2983 }
2984 else
2985 mb_utf8 = FALSE; // don't draw as UTF-8
2986 }
2987 else
2988 {
2989 prev_syntax_id = 0;
2990 is_concealing = FALSE;
2991 }
2992
2993 if (n_skip > 0 && did_decrement_ptr)
2994 // not showing the '>', put pointer back to avoid getting stuck
2995 ++ptr;
2996
2997#endif // FEAT_CONCEAL
2998 }
2999
3000#ifdef FEAT_CONCEAL
3001 // In the cursor line and we may be concealing characters: correct
3002 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 && wp == curwin && lnum == wp->w_cursor.lnum
3005 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003006 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003008# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003010 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003011 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003012# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003013 wp->w_wcol = wlv.col - wlv.boguscols;
3014 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003015 did_wcol = TRUE;
3016 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003017# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003018 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003019# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 }
3021#endif
3022
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003023 // Use "extra_attr", but don't override visual selection highlighting,
3024 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003025 // Don't use "extra_attr" until n_attr_skip is zero.
3026 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003027 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003028 && (!attr_pri
3029#ifdef FEAT_PROP_POPUP
3030 || (text_prop_flags & PT_FLAG_OVERRIDE)
3031#endif
3032 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 {
3034#ifdef LINE_ATTR
3035 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003036 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 else
3038#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003039 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003040 }
3041
3042#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3043 // XIM don't send preedit_start and preedit_end, but they send
3044 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3045 // im_is_preediting() here.
3046 if (p_imst == IM_ON_THE_SPOT
3047 && xic != NULL
3048 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003049 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 && !p_imdisable
3051 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003052 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 {
3054 colnr_T tcol;
3055
3056 if (preedit_end_col == MAXCOL)
3057 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3058 else
3059 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003060 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 {
3062 if (feedback_old_attr < 0)
3063 {
3064 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003065 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003066 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003067 wlv.char_attr = im_get_feedback_attr(feedback_col);
3068 if (wlv.char_attr < 0)
3069 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 feedback_col++;
3071 }
3072 else if (feedback_old_attr >= 0)
3073 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003074 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003075 feedback_old_attr = -1;
3076 feedback_col = 0;
3077 }
3078 }
3079#endif
3080 // Handle the case where we are in column 0 but not on the first
3081 // character of the line and the user wants us to show us a
3082 // special character (via 'listchars' option "precedes:<char>".
3083 if (lcs_prec_todo != NUL
3084 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003085 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003086 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003087 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088#ifdef FEAT_DIFF
3089 && filler_todo <= 0
3090#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003091 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003092 && c != NUL)
3093 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003094 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003095 lcs_prec_todo = NUL;
3096 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3097 {
3098 // Double-width character being overwritten by the "precedes"
3099 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003100 wlv.c_extra = MB_FILLER_CHAR;
3101 wlv.c_final = NUL;
3102 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003104 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 }
3106 mb_c = c;
3107 if (enc_utf8 && utf_char2len(c) > 1)
3108 {
3109 mb_utf8 = TRUE;
3110 u8cc[0] = 0;
3111 c = 0xc0;
3112 }
3113 else
3114 mb_utf8 = FALSE; // don't draw as UTF-8
3115 if (!attr_pri)
3116 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003117 saved_attr3 = wlv.char_attr; // save current attr
3118 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003119 n_attr3 = 1;
3120 }
3121 }
3122
3123 // At end of the text line or just after the last character.
3124 if ((c == NUL
3125#if defined(LINE_ATTR)
3126 || did_line_attr == 1
3127#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003128 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003129 {
3130#ifdef FEAT_SEARCH_EXTRA
3131 // flag to indicate whether prevcol equals startcol of search_hl or
3132 // one of the matches
3133 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3134 (long)(ptr - line) - (c == NUL));
3135#endif
3136 // Invert at least one char, used for Visual and empty line or
3137 // highlight match at end of line. If it's beyond the last
3138 // char on the screen, just overwrite that one (tricky!) Not
3139 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003140 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003141 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 && (VIsual_mode != Ctrl_V
3143 || lnum == VIsual.lnum
3144 || lnum == curwin->w_cursor.lnum)
3145 && c == NUL)
3146#ifdef FEAT_SEARCH_EXTRA
3147 // highlight 'hlsearch' match at end of line
3148 || (prevcol_hl_flag
3149# ifdef FEAT_SYN_HL
3150 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3151 && !(wp == curwin && VIsual_active))
3152# endif
3153# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003154 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003155# endif
3156# if defined(LINE_ATTR)
3157 && did_line_attr <= 1
3158# endif
3159 )
3160#endif
3161 ))
3162 {
3163 int n = 0;
3164
3165#ifdef FEAT_RIGHTLEFT
3166 if (wp->w_p_rl)
3167 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003168 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169 n = 1;
3170 }
3171 else
3172#endif
3173 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003174 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 n = -1;
3176 }
3177 if (n != 0)
3178 {
3179 // At the window boundary, highlight the last character
3180 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003181 wlv.off += n;
3182 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183 }
3184 else
3185 {
3186 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003187 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003189 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003190 }
3191#ifdef FEAT_SEARCH_EXTRA
3192 if (area_attr == 0)
3193 {
3194 // Use attributes from match with highest priority among
3195 // 'search_hl' and the match list.
3196 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003197 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 }
3199#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003200 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003201 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003202#ifdef FEAT_RIGHTLEFT
3203 if (wp->w_p_rl)
3204 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003205 --wlv.col;
3206 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207 }
3208 else
3209#endif
3210 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003211 ++wlv.col;
3212 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003213 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003214 ++wlv.vcol;
3215 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003216 }
3217 }
3218
3219 // At end of the text line.
3220 if (c == NUL)
3221 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003222 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003223
3224 // Update w_cline_height and w_cline_folded if the cursor line was
3225 // updated (saves a call to plines() later).
3226 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3227 {
3228 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003229 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230#ifdef FEAT_FOLDING
3231 curwin->w_cline_folded = FALSE;
3232#endif
3233 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3234 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003235 break;
3236 }
3237
3238 // Show "extends" character from 'listchars' if beyond the line end and
3239 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003240 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003241 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242 && wp->w_p_list
3243 && !wp->w_p_wrap
3244#ifdef FEAT_DIFF
3245 && filler_todo <= 0
3246#endif
3247 && (
3248#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003249 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003251 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003252 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003253 || lcs_eol_one > 0
3254 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003257 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003258 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 mb_c = c;
3260 if (enc_utf8 && utf_char2len(c) > 1)
3261 {
3262 mb_utf8 = TRUE;
3263 u8cc[0] = 0;
3264 c = 0xc0;
3265 }
3266 else
3267 mb_utf8 = FALSE;
3268 }
3269
3270#ifdef FEAT_SYN_HL
3271 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003272 if (wlv.draw_color_col)
3273 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274
3275 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3276 // highlight the cursor position itself.
3277 // Also highlight the 'colorcolumn' if it is different than
3278 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003279 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3280 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 if (((wlv.draw_state == WL_LINE
3283 || wlv.draw_state == WL_BRI
3284 || wlv.draw_state == WL_SBR)
3285 && !lnum_in_visual_area
3286 && search_attr == 0
3287 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003288# ifdef FEAT_DIFF
3289 && filler_todo <= 0
3290# endif
3291 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 {
3293 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3294 && lnum != wp->w_cursor.lnum)
3295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 vcol_save_attr = wlv.char_attr;
3297 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3298 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003300 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003302 vcol_save_attr = wlv.char_attr;
3303 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
3305 }
3306#endif
3307
3308 // Store character to be displayed.
3309 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003310 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003311 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 {
3313 // Store the character.
3314#if defined(FEAT_RIGHTLEFT)
3315 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3316 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003317 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003318 --wlv.off;
3319 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 }
3321#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003322 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 if (enc_dbcs == DBCS_JPNU)
3324 {
3325 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003326 ScreenLines[wlv.off] = 0x8e;
3327 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 }
3329 else if (enc_utf8)
3330 {
3331 if (mb_utf8)
3332 {
3333 int i;
3334
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003335 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003336 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003337 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003338 for (i = 0; i < Screen_mco; ++i)
3339 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 if (u8cc[i] == 0)
3342 break;
3343 }
3344 }
3345 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003346 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 }
3348 if (multi_attr)
3349 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003350 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003351 multi_attr = 0;
3352 }
3353 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003354 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003355
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003356 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003357
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3359 {
3360 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 ++wlv.off;
3362 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003363 if (enc_utf8)
3364 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003365 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366 else
3367 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003368 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370#ifdef FEAT_DIFF
3371 && filler_todo <= 0
3372#endif
3373 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003374 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003375 // When "tocol" is halfway a character, set it to the end of
3376 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003379
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003380 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003381
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382#ifdef FEAT_RIGHTLEFT
3383 if (wp->w_p_rl)
3384 {
3385 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003386 --wlv.off;
3387 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003388 }
3389#endif
3390 }
3391#ifdef FEAT_RIGHTLEFT
3392 if (wp->w_p_rl)
3393 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003394 --wlv.off;
3395 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 }
3397 else
3398#endif
3399 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003400 ++wlv.off;
3401 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 }
3403 }
3404#ifdef FEAT_CONCEAL
3405 else if (wp->w_p_cole > 0 && is_concealing)
3406 {
3407 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003409 if (wlv.n_extra > 0)
3410 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411 if (wp->w_p_wrap)
3412 {
3413 // Special voodoo required if 'wrap' is on.
3414 //
3415 // Advance the column indicator to force the line
3416 // drawing to wrap early. This will make the line
3417 // take up the same screen space when parts are concealed,
3418 // so that cursor line computations aren't messed up.
3419 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003420 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421 // trailing junk to be written out of the screen line
3422 // we are building, 'boguscols' keeps track of the number
3423 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003424 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003426 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427# ifdef FEAT_RIGHTLEFT
3428 if (wp->w_p_rl)
3429 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003430 wlv.col -= wlv.n_extra;
3431 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003432 }
3433 else
3434# endif
3435 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 wlv.col += wlv.n_extra;
3437 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003438 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003439 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003440 n_attr = 0;
3441 }
3442
3443
3444 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3445 {
3446 // Need to fill two screen columns.
3447# ifdef FEAT_RIGHTLEFT
3448 if (wp->w_p_rl)
3449 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 --wlv.boguscols;
3451 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 }
3453 else
3454# endif
3455 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003456 ++wlv.boguscols;
3457 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 }
3459 }
3460
3461# ifdef FEAT_RIGHTLEFT
3462 if (wp->w_p_rl)
3463 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003464 --wlv.boguscols;
3465 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467 else
3468# endif
3469 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 ++wlv.boguscols;
3471 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003472 }
3473 }
3474 else
3475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003477 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003478 wlv.vcol += wlv.n_extra;
3479 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003480 n_attr = 0;
3481 }
3482 }
3483
3484 }
3485#endif // FEAT_CONCEAL
3486 else
3487 --n_skip;
3488
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003489 // Only advance the "wlv.vcol" when after the 'number' or
3490 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003491 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003492#ifdef FEAT_DIFF
3493 && filler_todo <= 0
3494#endif
3495 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003496 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497
3498#ifdef FEAT_SYN_HL
3499 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501#endif
3502
3503 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003504 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3505 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506
3507 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003508 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003509 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003510 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003511 if (n_attr_skip > 0)
3512 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513
3514 // At end of screen line and there is more to come: Display the line
3515 // so far. If there is no more to display it is caught above.
3516 if ((
3517#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003518 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003519#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003520 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003521 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003522 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523#ifdef FEAT_DIFF
3524 || filler_todo > 0
3525#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003526#ifdef FEAT_PROP_POPUP
3527 || text_prop_follows
3528#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003529 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003530 && wlv.p_extra != at_end_str)
3531 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3532 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003533 )
3534 {
3535#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003536 screen_line(wp, wlv.screen_row, wp->w_wincol,
3537 wlv.col - wlv.boguscols,
3538 wp->w_width, wlv.screen_line_flags);
3539 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003541 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3542 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003543#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003544 ++wlv.row;
3545 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546
3547 // When not wrapping and finished diff lines, or when displayed
3548 // '$' and highlighting until last column, break here.
3549 if ((!wp->w_p_wrap
3550#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003551 && filler_todo <= 0
3552#endif
3553#ifdef FEAT_PROP_POPUP
3554 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555#endif
3556 ) || lcs_eol_one == -1)
3557 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003558#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003559 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003560 {
3561 // do not output more of the line, only the "below" prop
3562 ptr += STRLEN(ptr);
3563# ifdef FEAT_LINEBREAK
3564 dont_use_showbreak = TRUE;
3565# endif
3566 }
3567#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568
3569 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003570 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003571#ifdef FEAT_DIFF
3572 && filler_todo <= 0
3573#endif
3574 )
3575 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003576 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3577 draw_vsep_win(wp, wlv.row);
3578 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 }
3580
3581 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003584 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 break;
3586 }
3587
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589#ifdef FEAT_DIFF
3590 && filler_todo <= 0
3591#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003592#ifdef FEAT_PROP_POPUP
3593 && !text_prop_follows
3594#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003595 && wp->w_width == Columns)
3596 {
3597 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003598 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599
3600 // Special trick to make copy/paste of wrapped lines work with
3601 // xterm/screen: write an extra character beyond the end of
3602 // the line. This will work with all terminal types
3603 // (regardless of the xn,am settings).
3604 // Only do this on a fast tty.
3605 // Only do this if the cursor is on the current line
3606 // (something has been written in it).
3607 // Don't do this for the GUI.
3608 // Don't do this for double-width characters.
3609 // Don't do this for a window not at the right screen border.
3610 if (p_tf
3611#ifdef FEAT_GUI
3612 && !gui.in_use
3613#endif
3614 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003615 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3616 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003617 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003618 || (*mb_off2cells)(
3619 LineOffset[wlv.screen_row - 1]
3620 + (int)Columns - 2,
3621 LineOffset[wlv.screen_row]
3622 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003623 {
3624 // First make sure we are at the end of the screen line,
3625 // then output the same character again to let the
3626 // terminal know about the wrap. If the terminal doesn't
3627 // auto-wrap, we overwrite the character.
3628 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003629 screen_char(LineOffset[wlv.screen_row - 1]
3630 + (unsigned)Columns - 1,
3631 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632
3633 // When there is a multi-byte character, just output a
3634 // space to keep it simple.
3635 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 out_char(' ');
3638 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003639 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 + (Columns - 1)]);
3641 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003642 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003643 screen_start(); // don't know where cursor is now
3644 }
3645 }
3646
Bram Moolenaar1306b362022-08-06 15:59:06 +01003647 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003648
Bram Moolenaareed9d462021-02-15 20:38:25 +01003649 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003650#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003651 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003653 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003655 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 need_showbreak = TRUE;
3657#endif
3658#ifdef FEAT_DIFF
3659 --filler_todo;
3660 // When the filler lines are actually below the last line of the
3661 // file, don't draw the line itself, break here.
3662 if (filler_todo == 0 && wp->w_botfill)
3663 break;
3664#endif
3665 }
3666
3667 } // for every character in the line
3668
3669#ifdef FEAT_SPELL
3670 // After an empty line check first word for capital.
3671 if (*skipwhite(line) == NUL)
3672 {
3673 capcol_lnum = lnum + 1;
3674 cap_col = 0;
3675 }
3676#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003677#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003678 vim_free(text_props);
3679 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003680 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#endif
3682
3683 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003684 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003685}