blob: b29f5b19aefd79f47b3557a64c73de70a71091fe [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 Moolenaar05ad5ff2019-11-30 22:48:27 +0100280#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200281static textprop_T *current_text_props = NULL;
282static buf_T *current_buf = NULL;
283
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100284/*
285 * Function passed to qsort() to sort text properties.
286 * Return 1 if "s1" has priority over "s2", -1 if the other way around, zero if
287 * both have the same priority.
288 */
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289 static int
290text_prop_compare(const void *s1, const void *s2)
291{
292 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100293 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 proptype_T *pt1, *pt2;
295 colnr_T col1, col2;
296
297 idx1 = *(int *)s1;
298 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100299 tp1 = &current_text_props[idx1];
300 tp2 = &current_text_props[idx2];
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100301 col1 = tp1->tp_col;
302 col2 = tp2->tp_col;
303 if (col1 == MAXCOL && col2 == MAXCOL)
304 {
305 int flags1 = 0;
306 int flags2 = 0;
307
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100308 // both props add text are after the line, order on 0: after (default),
309 // 1: right, 2: below (comes last)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100310 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
311 flags1 = 1;
312 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
313 flags1 = 2;
314 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
315 flags2 = 1;
316 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
317 flags2 = 2;
318 if (flags1 != flags2)
319 return flags1 < flags2 ? 1 : -1;
320 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100321
322 // property that inserts text has priority over one that doesn't
323 if ((tp1->tp_id < 0) != (tp2->tp_id < 0))
324 return tp1->tp_id < 0 ? 1 : -1;
325
326 // check highest priority, defined by the type
Bram Moolenaardb9b96d2022-08-06 17:38:53 +0100327 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
328 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100329 if (pt1 != pt2)
330 {
331 if (pt1 == NULL)
332 return -1;
333 if (pt2 == NULL)
334 return 1;
335 if (pt1->pt_priority != pt2->pt_priority)
336 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
337 }
338
339 // same priority, one that starts first wins
340 if (col1 != col2)
341 return col1 < col2 ? 1 : -1;
Bram Moolenaare89aeed2022-08-22 13:00:16 +0100342
343 // for a property with text the id can be used as tie breaker
344 if (tp1->tp_id < 0)
345 return tp1->tp_id > tp2->tp_id ? 1 : -1;
346
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100347 return 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200348}
349#endif
350
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100351/*
352 * Called when finished with the line: draw the screen line and handle any
353 * highlighting until the right of the window.
354 */
355 static void
356draw_screen_line(win_T *wp, winlinevars_T *wlv)
357{
358#ifdef FEAT_SYN_HL
359 long v;
360
361 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
362 if (wp->w_p_wrap)
363 v = wp->w_skipcol;
364 else
365 v = wp->w_leftcol;
366
367 // check if line ends before left margin
368 if (wlv->vcol < v + wlv->col - win_col_off(wp))
369 wlv->vcol = v + wlv->col - win_col_off(wp);
370# ifdef FEAT_CONCEAL
371 // Get rid of the boguscols now, we want to draw until the right
372 // edge for 'cursorcolumn'.
373 wlv->col -= wlv->boguscols;
374 wlv->boguscols = 0;
375# define VCOL_HLC (wlv->vcol - wlv->vcol_off)
376# else
377# define VCOL_HLC (wlv->vcol)
378# endif
379
380 if (wlv->draw_color_col)
381 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
382
383 if (((wp->w_p_cuc
384 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
385 && (int)wp->w_virtcol <
386 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
387 && wlv->lnum != wp->w_cursor.lnum)
388 || wlv->draw_color_col
389 || wlv->win_attr != 0)
390# ifdef FEAT_RIGHTLEFT
391 && !wp->w_p_rl
392# endif
393 )
394 {
395 int rightmost_vcol = 0;
396 int i;
397
398 if (wp->w_p_cuc)
399 rightmost_vcol = wp->w_virtcol;
400 if (wlv->draw_color_col)
401 // determine rightmost colorcolumn to possibly draw
402 for (i = 0; wlv->color_cols[i] >= 0; ++i)
403 if (rightmost_vcol < wlv->color_cols[i])
404 rightmost_vcol = wlv->color_cols[i];
405
406 while (wlv->col < wp->w_width)
407 {
408 ScreenLines[wlv->off] = ' ';
409 if (enc_utf8)
410 ScreenLinesUC[wlv->off] = 0;
411 ScreenCols[wlv->off] = MAXCOL;
412 ++wlv->col;
413 if (wlv->draw_color_col)
414 wlv->draw_color_col = advance_color_col(
415 VCOL_HLC, &wlv->color_cols);
416
417 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
418 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_CUC);
419 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
420 ScreenAttrs[wlv->off++] = HL_ATTR(HLF_MC);
421 else
422 ScreenAttrs[wlv->off++] = wlv->win_attr;
423
424 if (VCOL_HLC >= rightmost_vcol && wlv->win_attr == 0)
425 break;
426
427 ++wlv->vcol;
428 }
429 }
430#endif
431
432 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
433 wp->w_width, wlv->screen_line_flags);
434 ++wlv->row;
435 ++wlv->screen_row;
436}
437#undef VCOL_HLC
438
439/*
440 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100441 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100442 */
443 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +0100444win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100445{
446 wlv->col = 0;
447 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
448
449#ifdef FEAT_RIGHTLEFT
450 if (wp->w_p_rl)
451 {
452 // Rightleft window: process the text in the normal direction, but put
453 // it in current_ScreenLine[] from right to left. Start at the
454 // rightmost column of the window.
455 wlv->col = wp->w_width - 1;
456 wlv->off += wlv->col;
457 wlv->screen_line_flags |= SLF_RIGHTLEFT;
458 }
459#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100460 if (save_extra)
461 {
462 // reset the drawing state for the start of a wrapped line
463 wlv->draw_state = WL_START;
464 wlv->saved_n_extra = wlv->n_extra;
465 wlv->saved_p_extra = wlv->p_extra;
466 wlv->saved_c_extra = wlv->c_extra;
467 wlv->saved_c_final = wlv->c_final;
468#ifdef FEAT_SYN_HL
469 if (!(wlv->cul_screenline
470# ifdef FEAT_DIFF
471 && wlv->diff_hlf == (hlf_T)0
472# endif
473 ))
474 wlv->saved_char_attr = wlv->char_attr;
475 else
476#endif
477 wlv->saved_char_attr = 0;
478 wlv->n_extra = 0;
479 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100480}
481
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200482/*
483 * Display line "lnum" of window 'wp' on the screen.
484 * Start at row "startrow", stop when "endrow" is reached.
485 * wp->w_virtcol needs to be valid.
486 *
487 * Return the number of last row the line occupies.
488 */
489 int
490win_line(
491 win_T *wp,
492 linenr_T lnum,
493 int startrow,
494 int endrow,
495 int nochange UNUSED, // not updating for changed text
496 int number_only) // only update the number column
497{
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100498 winlinevars_T wlv; // variables passed between functions
499
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200500 int c = 0; // init for GCC
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200501#ifdef FEAT_LINEBREAK
502 long vcol_sbr = -1; // virtual column after showbreak
503#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100504 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200505 char_u *line; // current line
506 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200507
508 char_u extra[21]; // "%ld " and 'fdc' must fit in here
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200509 char_u *p_extra_free = NULL; // p_extra needs to be freed
Bram Moolenaar1306b362022-08-06 15:59:06 +0100510#ifdef FEAT_PROP_POPUP
511 char_u *p_extra_free2 = NULL; // another p_extra to be freed
512#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200513 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000514#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000515 int in_linebreak = FALSE; // n_extra set for showing linebreak
516#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200517 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100518 // displaying eol at end-of-line
519 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000520 int lcs_prec_todo = wp->w_lcs_chars.prec;
521 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200522
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100523 int n_attr = 0; // chars with special attr
524 int n_attr_skip = 0; // chars to skip before using extra_attr
525 int saved_attr2 = 0; // char_attr saved for n_attr
526 int n_attr3 = 0; // chars with overruling special attr
527 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200528
529 int n_skip = 0; // nr of chars to skip for 'nowrap'
530
531 int fromcol = -10; // start of inverting
532 int tocol = MAXCOL; // end of inverting
533 int fromcol_prev = -2; // start of inverting after cursor
534 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200535 int lnum_in_visual_area = FALSE;
536 pos_T pos;
537 long v;
538
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200539 int attr_pri = FALSE; // char_attr has priority
540 int area_highlighting = FALSE; // Visual or incsearch highlighting
541 // in this line
542 int vi_attr = 0; // attributes for Visual and incsearch
543 // highlighting
544 int wcr_attr = 0; // attributes from 'wincolor'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200545 int area_attr = 0; // attributes desired by highlighting
546 int search_attr = 0; // attributes desired by 'hlsearch'
547#ifdef FEAT_SYN_HL
548 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
549 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200550 int prev_syntax_col = -1; // column of prev_syntax_attr
551 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200552 int has_syntax = FALSE; // this buffer has syntax highl.
553 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200554#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100555#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200556 int text_prop_count;
557 int text_prop_next = 0; // next text property to use
558 textprop_T *text_props = NULL;
559 int *text_prop_idxs = NULL;
560 int text_props_active = 0;
561 proptype_T *text_prop_type = NULL;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +0100562 int extra_for_textprop = FALSE; // wlv.n_extra set for textprop
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200563 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100564 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +0100565 int text_prop_flags = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100566 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +0100567 int saved_search_attr = 0; // search_attr to be used when n_extra
568 // goes to zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200569#endif
570#ifdef FEAT_SPELL
571 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000572 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200573# define SPWORDLEN 150
574 char_u nextline[SPWORDLEN * 2];// text with start of the next line
575 int nextlinecol = 0; // column where nextline[] starts
576 int nextline_idx = 0; // index in nextline[] where next line
577 // starts
578 int spell_attr = 0; // attributes desired by spelling
579 int word_end = 0; // last byte with same spell_attr
580 static linenr_T checked_lnum = 0; // line number for "checked_col"
581 static int checked_col = 0; // column in "checked_lnum" up to which
582 // there are no spell errors
583 static int cap_col = -1; // column to check for Cap word
584 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
585 int cur_checked_col = 0; // checked column for current line
586#endif
587 int extra_check = 0; // has extra highlighting
588 int multi_attr = 0; // attributes desired by multibyte
589 int mb_l = 1; // multi-byte byte length
590 int mb_c = 0; // decoded multi-byte character
591 int mb_utf8 = FALSE; // screen char is UTF-8 char
592 int u8cc[MAX_MCO]; // composing UTF-8 chars
593#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
594 int filler_lines = 0; // nr of filler lines to be drawn
595 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000596#else
597# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200598#endif
599#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200600 int change_start = MAXCOL; // first col of changed area
601 int change_end = -1; // last col of changed area
602#endif
603 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100604 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200605 int in_multispace = FALSE; // in multiple consecutive spaces
606 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200607#ifdef FEAT_LINEBREAK
608 int need_showbreak = FALSE; // overlong line, skipping first x
609 // chars
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +0100610 int dont_use_showbreak = FALSE; // do not use 'showbreak'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200611#endif
612#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
613 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
614# define LINE_ATTR
615 int line_attr = 0; // attribute for the whole line
Bram Moolenaarbf915842022-08-06 22:38:02 +0100616 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200617#endif
618#ifdef FEAT_SIGNS
619 int sign_present = FALSE;
620 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000621 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200622#endif
623#ifdef FEAT_ARABIC
624 int prev_c = 0; // previous Arabic character
625 int prev_c1 = 0; // first composing char for prev_c
626#endif
627#if defined(LINE_ATTR)
628 int did_line_attr = 0;
629#endif
630#ifdef FEAT_TERMINAL
631 int get_term_attr = FALSE;
632#endif
633#ifdef FEAT_SYN_HL
634 int cul_attr = 0; // set when 'cursorline' active
635
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200636 // margin columns for the screen line, needed for when 'cursorlineopt'
637 // contains "screenline"
638 int left_curline_col = 0;
639 int right_curline_col = 0;
640#endif
641
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200642#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
643 int feedback_col = 0;
644 int feedback_old_attr = -1;
645#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646
647#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
648 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000649 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200650#endif
651#ifdef FEAT_CONCEAL
652 int syntax_flags = 0;
653 int syntax_seqnr = 0;
654 int prev_syntax_id = 0;
655 int conceal_attr = HL_ATTR(HLF_CONCEAL);
656 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200657 int did_wcol = FALSE;
658 int old_boguscols = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100659# define VCOL_HLC (wlv.vcol - wlv.vcol_off)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200660# define FIX_FOR_BOGUSCOLS \
661 { \
Bram Moolenaar1306b362022-08-06 15:59:06 +0100662 wlv.n_extra += wlv.vcol_off; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100663 wlv.vcol -= wlv.vcol_off; \
664 wlv.vcol_off = 0; \
665 wlv.col -= wlv.boguscols; \
666 old_boguscols = wlv.boguscols; \
667 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200668 }
669#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100670# define VCOL_HLC (wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671#endif
672
673 if (startrow > endrow) // past the end already!
674 return startrow;
675
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100676 CLEAR_FIELD(wlv);
677
678 wlv.lnum = lnum;
679 wlv.startrow = startrow;
680 wlv.row = startrow;
681 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200682
683 if (!number_only)
684 {
685 // To speed up the loop below, set extra_check when there is linebreak,
686 // trailing white space and/or syntax processing to be done.
687#ifdef FEAT_LINEBREAK
688 extra_check = wp->w_p_lbr;
689#endif
690#ifdef FEAT_SYN_HL
691 if (syntax_present(wp) && !wp->w_s->b_syn_error
692# ifdef SYN_TIME_LIMIT
693 && !wp->w_s->b_syn_slow
694# endif
695 )
696 {
697 // Prepare for syntax highlighting in this line. When there is an
698 // error, stop syntax highlighting.
699 save_did_emsg = did_emsg;
700 did_emsg = FALSE;
701 syntax_start(wp, lnum);
702 if (did_emsg)
703 wp->w_s->b_syn_error = TRUE;
704 else
705 {
706 did_emsg = save_did_emsg;
707#ifdef SYN_TIME_LIMIT
708 if (!wp->w_s->b_syn_slow)
709#endif
710 {
711 has_syntax = TRUE;
712 extra_check = TRUE;
713 }
714 }
715 }
716
717 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100718 wlv.color_cols = wp->w_p_cc_cols;
719 if (wlv.color_cols != NULL)
720 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200721#endif
722
723#ifdef FEAT_TERMINAL
724 if (term_show_buffer(wp->w_buffer))
725 {
726 extra_check = TRUE;
727 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100728 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200729 }
730#endif
731
732#ifdef FEAT_SPELL
733 if (wp->w_p_spell
734 && *wp->w_s->b_p_spl != NUL
735 && wp->w_s->b_langp.ga_len > 0
736 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
737 {
738 // Prepare for spell checking.
739 has_spell = TRUE;
740 extra_check = TRUE;
741
742 // Get the start of the next line, so that words that wrap to the
743 // next line are found too: "et<line-break>al.".
744 // Trick: skip a few chars for C/shell/Vim comments
745 nextline[SPWORDLEN] = NUL;
746 if (lnum < wp->w_buffer->b_ml.ml_line_count)
747 {
748 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
749 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
750 }
751
752 // When a word wrapped from the previous line the start of the
753 // current line is valid.
754 if (lnum == checked_lnum)
755 cur_checked_col = checked_col;
756 checked_lnum = 0;
757
758 // When there was a sentence end in the previous line may require a
759 // word starting with capital in this line. In line 1 always check
760 // the first word.
761 if (lnum != capcol_lnum)
762 cap_col = -1;
763 if (lnum == 1)
764 cap_col = 0;
765 capcol_lnum = 0;
766 }
767#endif
768
769 // handle Visual active in this window
770 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
771 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100772 pos_T *top, *bot;
773
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200774 if (LTOREQ_POS(curwin->w_cursor, VIsual))
775 {
776 // Visual is after curwin->w_cursor
777 top = &curwin->w_cursor;
778 bot = &VIsual;
779 }
780 else
781 {
782 // Visual is before curwin->w_cursor
783 top = &VIsual;
784 bot = &curwin->w_cursor;
785 }
786 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
787 if (VIsual_mode == Ctrl_V)
788 {
789 // block mode
790 if (lnum_in_visual_area)
791 {
792 fromcol = wp->w_old_cursor_fcol;
793 tocol = wp->w_old_cursor_lcol;
794 }
795 }
796 else
797 {
798 // non-block mode
799 if (lnum > top->lnum && lnum <= bot->lnum)
800 fromcol = 0;
801 else if (lnum == top->lnum)
802 {
803 if (VIsual_mode == 'V') // linewise
804 fromcol = 0;
805 else
806 {
807 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
808 if (gchar_pos(top) == NUL)
809 tocol = fromcol + 1;
810 }
811 }
812 if (VIsual_mode != 'V' && lnum == bot->lnum)
813 {
814 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
815 {
816 fromcol = -10;
817 tocol = MAXCOL;
818 }
819 else if (bot->col == MAXCOL)
820 tocol = MAXCOL;
821 else
822 {
823 pos = *bot;
824 if (*p_sel == 'e')
825 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
826 else
827 {
828 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
829 ++tocol;
830 }
831 }
832 }
833 }
834
835 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200836 if (!highlight_match && lnum == curwin->w_cursor.lnum
837 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200838#ifdef FEAT_GUI
839 && !gui.in_use
840#endif
841 )
842 noinvcur = TRUE;
843
844 // if inverting in this line set area_highlighting
845 if (fromcol >= 0)
846 {
847 area_highlighting = TRUE;
848 vi_attr = HL_ATTR(HLF_V);
849#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
850 if ((clip_star.available && !clip_star.owned
851 && clip_isautosel_star())
852 || (clip_plus.available && !clip_plus.owned
853 && clip_isautosel_plus()))
854 vi_attr = HL_ATTR(HLF_VNC);
855#endif
856 }
857 }
858
859 // handle 'incsearch' and ":s///c" highlighting
860 else if (highlight_match
861 && wp == curwin
862 && lnum >= curwin->w_cursor.lnum
863 && lnum <= curwin->w_cursor.lnum + search_match_lines)
864 {
865 if (lnum == curwin->w_cursor.lnum)
866 getvcol(curwin, &(curwin->w_cursor),
867 (colnr_T *)&fromcol, NULL, NULL);
868 else
869 fromcol = 0;
870 if (lnum == curwin->w_cursor.lnum + search_match_lines)
871 {
872 pos.lnum = lnum;
873 pos.col = search_match_endcol;
874 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
875 }
876 else
877 tocol = MAXCOL;
878 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100879 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200880 tocol = fromcol + 1;
881 area_highlighting = TRUE;
882 vi_attr = HL_ATTR(HLF_I);
883 }
884 }
885
886#ifdef FEAT_DIFF
887 filler_lines = diff_check(wp, lnum);
888 if (filler_lines < 0)
889 {
890 if (filler_lines == -1)
891 {
892 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +0100893 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200894 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100895 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200896 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100897 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200898 }
899 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100900 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200901 filler_lines = 0;
902 area_highlighting = TRUE;
903 }
904 if (lnum == wp->w_topline)
905 filler_lines = wp->w_topfill;
906 filler_todo = filler_lines;
907#endif
908
909#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100910 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000911 if (sign_present)
912 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200913#endif
914
915#ifdef LINE_ATTR
916# ifdef FEAT_SIGNS
917 // If this line has a sign with line highlighting set line_attr.
918 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200919 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200920# endif
921# if defined(FEAT_QUICKFIX)
922 // Highlight the current line in the quickfix window.
923 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
924 line_attr = HL_ATTR(HLF_QFL);
925# endif
926 if (line_attr != 0)
927 area_highlighting = TRUE;
928#endif
929
930 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
931 ptr = line;
932
933#ifdef FEAT_SPELL
934 if (has_spell && !number_only)
935 {
936 // For checking first word with a capital skip white space.
937 if (cap_col == 0)
938 cap_col = getwhitecols(line);
939
940 // To be able to spell-check over line boundaries copy the end of the
941 // current line into nextline[]. Above the start of the next line was
942 // copied to nextline[SPWORDLEN].
943 if (nextline[SPWORDLEN] == NUL)
944 {
945 // No next line or it is empty.
946 nextlinecol = MAXCOL;
947 nextline_idx = 0;
948 }
949 else
950 {
951 v = (long)STRLEN(line);
952 if (v < SPWORDLEN)
953 {
954 // Short line, use it completely and append the start of the
955 // next line.
956 nextlinecol = 0;
957 mch_memmove(nextline, line, (size_t)v);
958 STRMOVE(nextline + v, nextline + SPWORDLEN);
959 nextline_idx = v + 1;
960 }
961 else
962 {
963 // Long line, use only the last SPWORDLEN bytes.
964 nextlinecol = v - SPWORDLEN;
965 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
966 nextline_idx = SPWORDLEN + 1;
967 }
968 }
969 }
970#endif
971
972 if (wp->w_p_list)
973 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100974 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200975 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100976 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100977 || wp->w_lcs_chars.trail
978 || wp->w_lcs_chars.lead
979 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100981
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200982 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100983 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200984 {
985 trailcol = (colnr_T)STRLEN(ptr);
986 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
987 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100988 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200989 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100990 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100991 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100992 {
993 leadcol = 0;
994 while (VIM_ISWHITE(ptr[leadcol]))
995 ++leadcol;
996 if (ptr[leadcol] == NUL)
997 // in a line full of spaces all of them are treated as trailing
998 leadcol = (colnr_T)0;
999 else
1000 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001001 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001002 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001003 }
1004
1005 wcr_attr = get_wcr_attr(wp);
1006 if (wcr_attr != 0)
1007 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001008 wlv.win_attr = wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001009 area_highlighting = TRUE;
1010 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001011
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001012#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001013 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001014 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015#endif
1016
1017 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1018 // first character to be displayed.
1019 if (wp->w_p_wrap)
1020 v = wp->w_skipcol;
1021 else
1022 v = wp->w_leftcol;
1023 if (v > 0 && !number_only)
1024 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001025 char_u *prev_ptr = ptr;
1026 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001027 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001028
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001029 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001030 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001031 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001032 charsize = win_lbr_chartabsize(&cts, NULL);
1033 cts.cts_vcol += charsize;
1034 prev_ptr = cts.cts_ptr;
1035 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001036 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001037 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001038 ptr = cts.cts_ptr;
1039 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040
1041 // When:
1042 // - 'cuc' is set, or
1043 // - 'colorcolumn' is set, or
1044 // - 'virtualedit' is set, or
1045 // - the visual mode is active,
1046 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001047 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001048#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001049 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001050#endif
1051 virtual_active() ||
1052 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001053 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001054
1055 // Handle a character that's not completely on the screen: Put ptr at
1056 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001057 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001059 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060 ptr = prev_ptr;
1061 // If the character fits on the screen, don't need to skip it.
1062 // Except for a TAB.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001063 if (((*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB)
1064 && wlv.col == 0)
1065 n_skip = v - wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001066 }
1067
1068 // Adjust for when the inverted text is before the screen,
1069 // and when the start of the inverted text is before the screen.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001070 if (tocol <= wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001071 fromcol = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001072 else if (fromcol >= 0 && fromcol < wlv.vcol)
1073 fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074
1075#ifdef FEAT_LINEBREAK
1076 // When w_skipcol is non-zero, first line needs 'showbreak'
1077 if (wp->w_p_wrap)
1078 need_showbreak = TRUE;
1079#endif
1080#ifdef FEAT_SPELL
1081 // When spell checking a word we need to figure out the start of the
1082 // word and if it's badly spelled or not.
1083 if (has_spell)
1084 {
1085 int len;
1086 colnr_T linecol = (colnr_T)(ptr - line);
1087 hlf_T spell_hlf = HLF_COUNT;
1088
1089 pos = wp->w_cursor;
1090 wp->w_cursor.lnum = lnum;
1091 wp->w_cursor.col = linecol;
1092 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1093
1094 // spell_move_to() may call ml_get() and make "line" invalid
1095 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1096 ptr = line + linecol;
1097
1098 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1099 {
1100 // no bad word found at line start, don't check until end of a
1101 // word
1102 spell_hlf = HLF_COUNT;
1103 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1104 }
1105 else
1106 {
1107 // bad word found, use attributes until end of word
1108 word_end = wp->w_cursor.col + len + 1;
1109
1110 // Turn index into actual attributes.
1111 if (spell_hlf != HLF_COUNT)
1112 spell_attr = highlight_attr[spell_hlf];
1113 }
1114 wp->w_cursor = pos;
1115
1116# ifdef FEAT_SYN_HL
1117 // Need to restart syntax highlighting for this line.
1118 if (has_syntax)
1119 syntax_start(wp, lnum);
1120# endif
1121 }
1122#endif
1123 }
1124
1125 // Correct highlighting for cursor that can't be disabled.
1126 // Avoids having to check this for each character.
1127 if (fromcol >= 0)
1128 {
1129 if (noinvcur)
1130 {
1131 if ((colnr_T)fromcol == wp->w_virtcol)
1132 {
1133 // highlighting starts at cursor, let it start just after the
1134 // cursor
1135 fromcol_prev = fromcol;
1136 fromcol = -1;
1137 }
1138 else if ((colnr_T)fromcol < wp->w_virtcol)
1139 // restart highlighting after the cursor
1140 fromcol_prev = wp->w_virtcol;
1141 }
1142 if (fromcol >= tocol)
1143 fromcol = -1;
1144 }
1145
1146#ifdef FEAT_SEARCH_EXTRA
1147 if (!number_only)
1148 {
1149 v = (long)(ptr - line);
1150 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1151 &line, &screen_search_hl,
1152 &search_attr);
1153 ptr = line + v; // "line" may have been updated
1154 }
1155#endif
1156
1157#ifdef FEAT_SYN_HL
1158 // Cursor line highlighting for 'cursorline' in the current window.
1159 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1160 {
1161 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001162 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 if (!(wp == curwin && VIsual_active)
1164 && wp->w_p_culopt_flags != CULOPT_NBR)
1165 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001166 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001167 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1168
1169 // Only set line_attr here when "screenline" is not present in
1170 // 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001171 if (!wlv.cul_screenline)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001172 {
1173 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001174# ifdef FEAT_SIGNS
1175 // Combine the 'cursorline' and sign highlighting, depending on
1176 // the sign priority.
1177 if (sign_present && sattr.sat_linehl > 0)
1178 {
1179 if (sattr.sat_priority >= 100)
1180 line_attr = hl_combine_attr(cul_attr, line_attr);
1181 else
1182 line_attr = hl_combine_attr(line_attr, cul_attr);
1183 }
1184 else
1185# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001186# if defined(FEAT_QUICKFIX)
Bram Moolenaar6e5c6112022-08-08 16:03:06 +01001187 // let the line attribute overrule 'cursorline', otherwise
1188 // it disappears when both have background set;
1189 // 'cursorline' can use underline or bold to make it show
1190 line_attr = hl_combine_attr(cul_attr, line_attr);
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001191# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001192 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001193# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 }
1195 else
1196 {
1197 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001198 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1199 }
1200 area_highlighting = TRUE;
1201 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001202 }
1203#endif
1204
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001205#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001206 {
1207 char_u *prop_start;
1208
1209 text_prop_count = get_text_props(wp->w_buffer, lnum,
1210 &prop_start, FALSE);
1211 if (text_prop_count > 0)
1212 {
1213 // Make a copy of the properties, so that they are properly
1214 // aligned.
1215 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1216 if (text_props != NULL)
1217 mch_memmove(text_props, prop_start,
1218 text_prop_count * sizeof(textprop_T));
1219
1220 // Allocate an array for the indexes.
1221 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1222 area_highlighting = TRUE;
1223 extra_check = TRUE;
1224 }
1225 }
1226#endif
1227
Bram Moolenaar1306b362022-08-06 15:59:06 +01001228 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229
1230 // Repeat for the whole displayed line.
1231 for (;;)
1232 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001233 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001235 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236#endif
1237#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001238 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001240
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001242 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001244#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001245 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001246 {
1247 cul_attr = 0;
1248 line_attr = line_attr_save;
1249 }
1250#endif
1251
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252#ifdef FEAT_CMDWIN
Bram Moolenaar1306b362022-08-06 15:59:06 +01001253 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001255 wlv.draw_state = WL_CMDLINE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001256 if (cmdwin_type != 0 && wp == curwin)
1257 {
1258 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001259 wlv.n_extra = 1;
1260 wlv.c_extra = cmdwin_type;
1261 wlv.c_final = NUL;
1262 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001263 }
1264 }
1265#endif
1266
1267#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001268 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 {
1270 int fdc = compute_foldcolumn(wp, 0);
1271
Bram Moolenaar1306b362022-08-06 15:59:06 +01001272 wlv.draw_state = WL_FOLD;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001273 if (fdc > 0)
1274 {
1275 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1276 // already be in use.
1277 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001278 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001279 if (p_extra_free != NULL)
1280 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001281 wlv.n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001282 FALSE, lnum);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001283 p_extra_free[wlv.n_extra] = NUL;
1284 wlv.p_extra = p_extra_free;
1285 wlv.c_extra = NUL;
1286 wlv.c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001287 if (use_cursor_line_sign(wp, lnum))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001288 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001289 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1290 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001291 wlv.char_attr =
Bram Moolenaare413ea02021-11-24 16:20:13 +00001292 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001293 }
1294 }
1295 }
1296#endif
1297
1298#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001299 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001301 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 // Show the sign column when there are any signs in this
1303 // buffer or when using Netbeans.
1304 if (signcolumn_on(wp))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001305 get_sign_display_info(FALSE, wp, lnum, &wlv, &sattr,
1306 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 }
1308#endif
1309
Bram Moolenaar1306b362022-08-06 15:59:06 +01001310 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001312 wlv.draw_state = WL_NR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313 // Display the absolute or relative line number. After the
1314 // first fill with blanks when the 'n' flag isn't in 'cpo'
1315 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001316 && (wlv.row == startrow + filler_lines
1317 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001318 {
1319#ifdef FEAT_SIGNS
1320 // If 'signcolumn' is set to 'number' and a sign is present
1321 // in 'lnum', then display the sign instead of the line
1322 // number.
1323 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1324 && sign_present)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001325 get_sign_display_info(TRUE, wp, lnum, &wlv, &sattr,
1326 wcr_attr, filler_lines, filler_todo, extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 else
1328#endif
1329 {
1330 // Draw the line number (empty space after wrapping).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001331 if (wlv.row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001332 {
1333 long num;
1334 char *fmt = "%*ld ";
1335
1336 if (wp->w_p_nu && !wp->w_p_rnu)
1337 // 'number' + 'norelativenumber'
1338 num = (long)lnum;
1339 else
1340 {
1341 // 'relativenumber', don't use negative numbers
1342 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1343 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1344 {
1345 // 'number' + 'relativenumber'
1346 num = lnum;
1347 fmt = "%-*ld ";
1348 }
1349 }
1350
1351 sprintf((char *)extra, fmt,
1352 number_width(wp), num);
1353 if (wp->w_skipcol > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001354 for (wlv.p_extra = extra; *wlv.p_extra == ' ';
1355 ++wlv.p_extra)
1356 *wlv.p_extra = '-';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357#ifdef FEAT_RIGHTLEFT
1358 if (wp->w_p_rl) // reverse line numbers
1359 {
1360 char_u *p1, *p2;
1361 int t;
1362
1363 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001364 p2 = skipwhite(extra);
1365 p2 = skiptowhite(p2) - 1;
1366 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 {
1368 t = *p1;
1369 *p1 = *p2;
1370 *p2 = t;
1371 }
1372 }
1373#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001374 wlv.p_extra = extra;
1375 wlv.c_extra = NUL;
1376 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001377 }
1378 else
1379 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001380 wlv.c_extra = ' ';
1381 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001382 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001383 wlv.n_extra = number_width(wp) + 1;
1384 wlv.char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385#ifdef FEAT_SYN_HL
1386 // When 'cursorline' is set highlight the line number of
1387 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001388 // When 'cursorlineopt' does not have "line" only
1389 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 // TODO: Can we use CursorLine instead of CursorLineNr
1391 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001392 if (wp->w_p_cul
1393 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001394 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001395 && (wlv.row == startrow + filler_lines
1396 || (wlv.row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001397 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001398 wlv.char_attr = hl_combine_attr(wcr_attr,
1399 HL_ATTR(HLF_CLN));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001401 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1402 && HL_ATTR(HLF_LNA) != 0)
1403 // Use LineNrAbove
Bram Moolenaar1306b362022-08-06 15:59:06 +01001404 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001405 HL_ATTR(HLF_LNA));
1406 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1407 && HL_ATTR(HLF_LNB) != 0)
1408 // Use LineNrBelow
Bram Moolenaar1306b362022-08-06 15:59:06 +01001409 wlv.char_attr = hl_combine_attr(wcr_attr,
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001410 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001411 }
James McCoya80aad72021-12-22 19:45:28 +00001412#ifdef FEAT_SIGNS
1413 if (num_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001414 wlv.char_attr = num_attr;
James McCoya80aad72021-12-22 19:45:28 +00001415#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001416 }
1417 }
1418
1419#ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001420 if (wp->w_briopt_sbr && wlv.draw_state == WL_BRI - 1
1421 && wlv.n_extra == 0
1422 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001423 // draw indent after showbreak value
Bram Moolenaar1306b362022-08-06 15:59:06 +01001424 wlv.draw_state = WL_BRI;
1425 else if (wp->w_briopt_sbr && wlv.draw_state == WL_SBR
1426 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001427 // After the showbreak, draw the breakindent
Bram Moolenaar1306b362022-08-06 15:59:06 +01001428 wlv.draw_state = WL_BRI - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429
1430 // draw 'breakindent': indent wrapped text accordingly
Bram Moolenaar1306b362022-08-06 15:59:06 +01001431 if (wlv.draw_state == WL_BRI - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001433 wlv.draw_state = WL_BRI;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 // if need_showbreak is set, breakindent also applies
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001435 if (wp->w_p_bri && (wlv.row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001436# ifdef FEAT_DIFF
1437 && filler_lines == 0
1438# endif
Bram Moolenaar73c38422022-08-07 11:53:40 +01001439# ifdef FEAT_PROP_POPUP
1440 && !dont_use_showbreak
1441# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001442 )
1443 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001444 wlv.char_attr = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001445# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01001446 if (wlv.diff_hlf != (hlf_T)0)
1447 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001449 wlv.p_extra = NULL;
1450 wlv.c_extra = ' ';
1451 wlv.c_final = NUL;
1452 wlv.n_extra = get_breakindent_win(wp,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001454 if (wlv.row == startrow)
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001456 wlv.n_extra -= win_col_off2(wp);
1457 if (wlv.n_extra < 0)
1458 wlv.n_extra = 0;
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001459 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001460 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001461 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001462 // Correct end of highlighted area for 'breakindent',
1463 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001464 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001465 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001466 }
1467 }
1468#endif
1469
1470#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001471 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001473 char_u *sbr;
1474
Bram Moolenaar1306b362022-08-06 15:59:06 +01001475 wlv.draw_state = WL_SBR;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476# ifdef FEAT_DIFF
1477 if (filler_todo > 0)
1478 {
1479 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001480 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001482 wlv.c_extra = '-';
1483 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001484 }
1485 else
1486 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001487 wlv.c_extra = wp->w_fill_chars.diff;
1488 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 }
1490# ifdef FEAT_RIGHTLEFT
1491 if (wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001492 wlv.n_extra = wlv.col + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493 else
1494# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001495 wlv.n_extra = wp->w_width - wlv.col;
1496 wlv.char_attr = HL_ATTR(HLF_DED);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 }
1498# endif
1499# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001500 sbr = get_showbreak_value(wp);
1501 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001502 {
1503 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001504 wlv.p_extra = sbr;
1505 wlv.c_extra = NUL;
1506 wlv.c_final = NUL;
1507 wlv.n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001508 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1509 need_showbreak = FALSE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001510 vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511 // Correct end of highlighted area for 'showbreak',
1512 // required when 'linebreak' is also set.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001513 if (tocol == wlv.vcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001514 tocol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 // combine 'showbreak' with 'wincolor'
Bram Moolenaar1306b362022-08-06 15:59:06 +01001516 wlv.char_attr = hl_combine_attr(wlv.win_attr,
1517 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518# ifdef FEAT_SYN_HL
1519 // combine 'showbreak' with 'cursorline'
1520 if (cul_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001521 wlv.char_attr = hl_combine_attr(wlv.char_attr,
1522 cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001523# endif
1524 }
1525# endif
1526 }
1527#endif
1528
Bram Moolenaar1306b362022-08-06 15:59:06 +01001529 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001530 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001531 wlv.draw_state = WL_LINE;
1532 if (wlv.saved_n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
1534 // Continue item from end of wrapped line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001535 wlv.n_extra = wlv.saved_n_extra;
1536 wlv.c_extra = wlv.saved_c_extra;
1537 wlv.c_final = wlv.saved_c_final;
1538 wlv.p_extra = wlv.saved_p_extra;
1539 wlv.char_attr = wlv.saved_char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 }
1541 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001542 wlv.char_attr = wlv.win_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001543 }
1544 }
1545#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001546 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001547 && wlv.vcol >= left_curline_col
1548 && wlv.vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001549 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001550 cul_attr = HL_ATTR(HLF_CUL);
1551 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001552 }
1553#endif
1554
1555 // When still displaying '$' of change command, stop at cursor.
1556 // When only displaying the (relative) line number and that's done,
1557 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001558 if (((dollar_vcol >= 0 && wp == curwin
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001559 && lnum == wp->w_cursor.lnum && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001560 || (number_only && wlv.draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561#ifdef FEAT_DIFF
1562 && filler_todo <= 0
1563#endif
1564 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001565 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001566 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col, -wp->w_width,
1567 wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001568 // Pretend we have finished updating the window. Except when
1569 // 'cursorcolumn' is set.
1570#ifdef FEAT_SYN_HL
1571 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001572 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001573 else
1574#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001575 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 break;
1577 }
1578
Bram Moolenaar1306b362022-08-06 15:59:06 +01001579 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001580 {
1581 // handle Visual or match highlighting in this line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001582 if (wlv.vcol == fromcol
Bram Moolenaar1306b362022-08-06 15:59:06 +01001583 || (has_mbyte && wlv.vcol + 1 == fromcol && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 && (*mb_ptr2cells)(ptr) > 1)
1585 || ((int)vcol_prev == fromcol_prev
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001586 && vcol_prev < wlv.vcol // not at margin
1587 && wlv.vcol < tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 area_attr = vi_attr; // start highlighting
1589 else if (area_attr != 0
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001590 && (wlv.vcol == tocol
1591 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 area_attr = 0; // stop highlighting
1593
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001594#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 if (text_props != NULL)
1596 {
1597 int pi;
1598 int bcol = (int)(ptr - line);
1599
Bram Moolenaar1306b362022-08-06 15:59:06 +01001600 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001601# ifdef FEAT_LINEBREAK
1602 && !in_linebreak
1603# endif
1604 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001605 --bcol; // still working on the previous char, e.g. Tab
1606
1607 // Check if any active property ends.
1608 for (pi = 0; pi < text_props_active; ++pi)
1609 {
1610 int tpi = text_prop_idxs[pi];
1611
1612 if (bcol >= text_props[tpi].tp_col - 1
1613 + text_props[tpi].tp_len)
1614 {
1615 if (pi + 1 < text_props_active)
1616 mch_memmove(text_prop_idxs + pi,
1617 text_prop_idxs + pi + 1,
1618 sizeof(int)
1619 * (text_props_active - (pi + 1)));
1620 --text_props_active;
1621 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001622# ifdef FEAT_LINEBREAK
1623 // not exactly right but should work in most cases
1624 if (in_linebreak && syntax_attr == text_prop_attr)
1625 syntax_attr = 0;
1626# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001627 }
1628 }
1629
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001630# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01001631 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001632 // not on the next char yet, don't start another prop
1633 --bcol;
1634# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001635 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001636 // With 'nowrap' and not in the first screen line only "below"
1637 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001639 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001640 ? (*ptr == NUL
1641 && (wp->w_p_wrap
1642 || wlv.row == startrow
1643 || (text_props[text_prop_next].tp_flags
1644 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001645 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001646 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001647 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001648 && *ptr == NUL && wp->w_p_list && lcs_eol_one > 0)
1649 {
1650 // first display the '$' after the line
1651 text_prop_follows = TRUE;
1652 break;
1653 }
1654 if (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01001655 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001656 + text_props[text_prop_next].tp_len)
1657 text_prop_idxs[text_props_active++] = text_prop_next;
1658 ++text_prop_next;
1659 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001660
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001661 if (wlv.n_extra == 0 || !extra_for_textprop)
1662 {
1663 text_prop_attr = 0;
1664 text_prop_flags = 0;
1665 text_prop_type = NULL;
1666 text_prop_id = 0;
1667 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001668 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001669 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001670 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001671 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001672 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001673
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001674 // Sort the properties on priority and/or starting last.
1675 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001676 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001677 current_text_props = text_props;
1678 current_buf = wp->w_buffer;
1679 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1680 sizeof(int), text_prop_compare);
1681
1682 for (pi = 0; pi < text_props_active; ++pi)
1683 {
1684 int tpi = text_prop_idxs[pi];
1685 proptype_T *pt = text_prop_type_by_id(
1686 wp->w_buffer, text_props[tpi].tp_type);
1687
Bram Moolenaar3331dd02022-08-10 16:49:02 +01001688 if (pt != NULL && (pt->pt_hl_id > 0
1689 || text_props[tpi].tp_id < 0)
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001690 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001691 {
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01001692 if (pt->pt_hl_id > 0)
1693 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 text_prop_type = pt;
1695 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001696 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001697 text_prop_flags = pt->pt_flags;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001698 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001699 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001700 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001701 }
1702 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001703 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001704 && -text_prop_id
1705 <= wp->w_buffer->b_textprop_text.ga_len)
1706 {
1707 char_u *p = ((char_u **)wp->w_buffer
1708 ->b_textprop_text.ga_data)[
1709 -text_prop_id - 1];
Bram Moolenaar1306b362022-08-06 15:59:06 +01001710
1711 // reset the ID in the copy to avoid it being used
1712 // again
1713 text_props[used_tpi].tp_id = -MAXCOL;
1714
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001715 if (p != NULL)
1716 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001717 int right = (text_props[used_tpi].tp_flags
1718 & TP_FLAG_ALIGN_RIGHT);
1719 int below = (text_props[used_tpi].tp_flags
1720 & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001721 int wrap = (text_props[used_tpi].tp_flags
1722 & TP_FLAG_WRAP);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001723
Bram Moolenaar1306b362022-08-06 15:59:06 +01001724 wlv.p_extra = p;
1725 wlv.c_extra = NUL;
1726 wlv.c_final = NUL;
1727 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01001728 extra_for_textprop = TRUE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001729 extra_attr = used_attr;
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01001730 n_attr = mb_charlen(p);
Bram Moolenaare38fc862022-08-11 17:24:50 +01001731 saved_search_attr = search_attr;
1732 search_attr = 0; // restore when n_extra is zero
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001733 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001734 if (*ptr == NUL)
1735 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001736 text_prop_flags &= ~PT_FLAG_COMBINE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001737#ifdef FEAT_LINEBREAK
Bram Moolenaarcba69522022-08-06 21:03:53 +01001738 if (below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01001739 {
1740 // no 'showbreak' before "below" text property
1741 // or after "right" text property
1742 need_showbreak = FALSE;
1743 dont_use_showbreak = TRUE;
1744 }
1745#endif
Bram Moolenaar398649e2022-08-04 15:03:48 +01001746 // Keep in sync with where
1747 // textprop_size_after_trunc() is called in
1748 // win_lbr_chartabsize().
1749 if ((right || below || !wrap) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001750 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001751 int added = wp->w_width - wlv.col;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001752 int n_used = wlv.n_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001753 char_u *l;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001754 int strsize = wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001755 ? vim_strsize(wlv.p_extra)
1756 : textprop_size_after_trunc(wp,
1757 below, added, wlv.p_extra, &n_used);
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001758
Bram Moolenaar1306b362022-08-06 15:59:06 +01001759 if (wrap || right || below
1760 || n_used < wlv.n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001761 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01001762 // Right-align: fill with spaces
1763 if (right)
1764 added -= strsize;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001765 if (added < 0
1766 || (below
1767 ? wlv.col == 0 || !wp->w_p_wrap
Bram Moolenaar1306b362022-08-06 15:59:06 +01001768 : n_used < wlv.n_extra))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001769 added = 0;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01001770
1771 // With 'nowrap' add one to show the
1772 // "extends" character if needed (it
1773 // doesn't show it the text just fits).
1774 if (!wp->w_p_wrap
1775 && n_used < wlv.n_extra
1776 && wp->w_lcs_chars.ext != NUL
1777 && wp->w_p_list)
1778 ++n_used;
1779
Bram Moolenaar398649e2022-08-04 15:03:48 +01001780 // add 1 for NUL, 2 for when '…' is used
1781 l = alloc(n_used + added + 3);
1782 if (l != NULL)
1783 {
1784 vim_memset(l, ' ', added);
Bram Moolenaar1306b362022-08-06 15:59:06 +01001785 vim_strncpy(l + added, wlv.p_extra,
1786 n_used);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001787 if (n_used < wlv.n_extra
1788 && wp->w_p_wrap)
Bram Moolenaar398649e2022-08-04 15:03:48 +01001789 {
1790 char_u *lp = l + added + n_used - 1;
1791
1792 if (has_mbyte)
1793 {
1794 // change last character to '…'
1795 lp -= (*mb_head_off)(l, lp);
1796 STRCPY(lp, "…");
1797 n_used = lp - l + 3;
1798 }
1799 else
1800 // change last character to '>'
1801 *lp = '>';
1802 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001803 vim_free(p_extra_free2);
1804 wlv.p_extra = p_extra_free2 = l;
1805 wlv.n_extra = n_used + added;
Bram Moolenaar398649e2022-08-04 15:03:48 +01001806 n_attr_skip = added;
Bram Moolenaar1d8844a2022-08-10 13:39:35 +01001807 n_attr = mb_charlen(wlv.p_extra);
Bram Moolenaar398649e2022-08-04 15:03:48 +01001808 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001809 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001810
1811 // When 'wrap' is off then for "below" we need
1812 // to start a new line explictly.
Bram Moolenaardb9b96d2022-08-06 17:38:53 +01001813 if (below && wlv.col > win_col_off(wp)
1814 && !wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001815 {
1816 draw_screen_line(wp, &wlv);
1817
1818 // When line got too long for screen break
1819 // here.
1820 if (wlv.row == endrow)
1821 {
1822 ++wlv.row;
1823 break;
1824 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01001825 win_line_start(wp, &wlv, TRUE);
1826 continue;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001827 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001828 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001829 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001830
1831 // If another text prop follows the condition below at
1832 // the last window column must know.
1833 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001834 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01001836 else if (text_prop_next < text_prop_count
1837 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001838 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
1839 || (!wp->w_p_wrap
1840 && wlv.col == wp->w_width - 1
1841 && (text_props[text_prop_next].tp_flags
1842 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01001843 // When at last-but-one character and a text property
1844 // follows after it, we may need to flush the line after
1845 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01001846 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01001847 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 }
1849#endif
1850
Bram Moolenaare38fc862022-08-11 17:24:50 +01001851#ifdef FEAT_SEARCH_EXTRA
1852 if (wlv.n_extra == 0)
1853 {
1854 // Check for start/end of 'hlsearch' and other matches.
1855 // After end, check for start/end of next match.
1856 // When another match, have to check for start again.
1857 v = (long)(ptr - line);
1858 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1859 &screen_search_hl, &has_match_conc,
1860 &match_conc, did_line_attr, lcs_eol_one,
1861 &on_last_col);
1862 ptr = line + v; // "line" may have been changed
1863 prev_ptr = ptr;
1864
1865 // Do not allow a conceal over EOL otherwise EOL will be missed
1866 // and bad things happen.
1867 if (*ptr == NUL)
1868 has_match_conc = 0;
1869 }
1870#endif
1871
1872#ifdef FEAT_DIFF
1873 if (wlv.diff_hlf != (hlf_T)0)
1874 {
1875 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
1876 && wlv.n_extra == 0)
1877 wlv.diff_hlf = HLF_TXD; // changed text
1878 if (wlv.diff_hlf == HLF_TXD && ptr - line > change_end
1879 && wlv.n_extra == 0)
1880 wlv.diff_hlf = HLF_CHD; // changed line
1881 line_attr = HL_ATTR(wlv.diff_hlf);
1882 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1883 && wp->w_p_culopt_flags != CULOPT_NBR
1884 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
1885 && wlv.vcol <= right_curline_col)))
1886 line_attr = hl_combine_attr(
1887 line_attr, HL_ATTR(HLF_CUL));
1888 }
1889#endif
1890
Bram Moolenaara74fda62019-10-19 17:38:03 +02001891#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001892 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001893 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001894 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001895# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001896 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001897 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001898# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001899 // Get syntax attribute.
1900 if (has_syntax)
1901 {
1902 // Get the syntax attribute for the character. If there
1903 // is an error, disable syntax highlighting.
1904 save_did_emsg = did_emsg;
1905 did_emsg = FALSE;
1906
1907 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001908 if (v == prev_syntax_col)
1909 // at same column again
1910 syntax_attr = prev_syntax_attr;
1911 else
1912 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001913# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001914 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001915# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001916 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001917# ifdef FEAT_SPELL
1918 has_spell ? &can_spell :
1919# endif
1920 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001921 prev_syntax_col = v;
1922 prev_syntax_attr = syntax_attr;
1923 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001924
Bram Moolenaar34390282019-10-16 14:38:26 +02001925 if (did_emsg)
1926 {
1927 wp->w_s->b_syn_error = TRUE;
1928 has_syntax = FALSE;
1929 syntax_attr = 0;
1930 }
1931 else
1932 did_emsg = save_did_emsg;
1933# ifdef SYN_TIME_LIMIT
1934 if (wp->w_s->b_syn_slow)
1935 has_syntax = FALSE;
1936# endif
1937
1938 // Need to get the line again, a multi-line regexp may
1939 // have made it invalid.
1940 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1941 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001942 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001943# ifdef FEAT_CONCEAL
1944 // no concealing past the end of the line, it interferes
1945 // with line highlighting
1946 if (*ptr == NUL)
1947 syntax_flags = 0;
1948 else
1949 syntax_flags = get_syntax_info(&syntax_seqnr);
1950# endif
1951 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001952 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001953# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001954 // Combine text property highlight into syntax highlight.
1955 if (text_prop_type != NULL)
1956 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001957 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01001958 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1959 else
1960 syntax_attr = text_prop_attr;
1961 }
1962# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001963#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001964
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001965 // Decide which of the highlight attributes to use.
1966 attr_pri = TRUE;
1967#ifdef LINE_ATTR
1968 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001969 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001970 wlv.char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001971 if (!highlight_match)
1972 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01001973 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001974# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001975 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001976# endif
1977 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001978 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001979 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001980 wlv.char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001981# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001982 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001983# endif
1984 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001986 || wlv.vcol < fromcol || vcol_prev < fromcol_prev
1987 || wlv.vcol >= tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988 {
1989 // Use line_attr when not in the Visual or 'incsearch' area
1990 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001991# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001992 wlv.char_attr = hl_combine_attr(syntax_attr, line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01001993# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001994 wlv.char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001995# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996 attr_pri = FALSE;
1997 }
1998#else
1999 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002000 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002002 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002003#endif
2004 else
2005 {
2006 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002008 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002009#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002010 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002011#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002012 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002013#ifdef FEAT_PROP_POPUP
2014 // override with text property highlight when "override" is TRUE
2015 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002016 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002017#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002018 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002019
2020 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002022 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002023 if (wlv.char_attr == 0)
2024 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002025 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002026 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002027 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028
2029 // Get the next character to put on the screen.
2030
2031 // The "p_extra" points to the extra stuff that is inserted to
2032 // represent special characters (non-printable stuff) and other
2033 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002034 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2036 // "p_extra[n_extra]".
2037 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002038 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002040 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002042 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2043 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2045 if (enc_utf8 && utf_char2len(c) > 1)
2046 {
2047 mb_utf8 = TRUE;
2048 u8cc[0] = 0;
2049 c = 0xc0;
2050 }
2051 else
2052 mb_utf8 = FALSE;
2053 }
2054 else
2055 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002056 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002057 if (has_mbyte)
2058 {
2059 mb_c = c;
2060 if (enc_utf8)
2061 {
2062 // If the UTF-8 character is more than one byte:
2063 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002064 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002065 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002066 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 mb_l = 1;
2068 else if (mb_l > 1)
2069 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002070 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 mb_utf8 = TRUE;
2072 c = 0xc0;
2073 }
2074 }
2075 else
2076 {
2077 // if this is a DBCS character, put it in "mb_c"
2078 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002079 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080 mb_l = 1;
2081 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002082 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002083 }
2084 if (mb_l == 0) // at the NUL at end-of-line
2085 mb_l = 1;
2086
2087 // If a double-width char doesn't fit display a '>' in the
2088 // last column.
2089 if ((
2090# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002091 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002092# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002093 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094 && (*mb_char2cells)(mb_c) == 2)
2095 {
2096 c = '>';
2097 mb_c = c;
2098 mb_l = 1;
2099 mb_utf8 = FALSE;
2100 multi_attr = HL_ATTR(HLF_AT);
2101#ifdef FEAT_SYN_HL
2102 if (cul_attr)
2103 multi_attr = hl_combine_attr(multi_attr, cul_attr);
2104#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002105 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002106
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 // put the pointer back to output the double-width
2108 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002109 ++wlv.n_extra;
2110 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 }
2112 else
2113 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002114 wlv.n_extra -= mb_l - 1;
2115 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002116 }
2117 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002118 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002119 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002120 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002121#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002122 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002123 {
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002124 extra_for_textprop = FALSE;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002125 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002126 if (search_attr == 0)
2127 search_attr = saved_search_attr;
2128 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002129#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130 }
2131 else
2132 {
2133#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002134 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002135#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01002136 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002138 // Get a character from the line itself.
2139 c = *ptr;
2140#ifdef FEAT_LINEBREAK
2141 c0 = *ptr;
2142#endif
2143 if (has_mbyte)
2144 {
2145 mb_c = c;
2146 if (enc_utf8)
2147 {
2148 // If the UTF-8 character is more than one byte: Decode it
2149 // into "mb_c".
2150 mb_l = utfc_ptr2len(ptr);
2151 mb_utf8 = FALSE;
2152 if (mb_l > 1)
2153 {
2154 mb_c = utfc_ptr2char(ptr, u8cc);
2155 // Overlong encoded ASCII or ASCII with composing char
2156 // is displayed normally, except a NUL.
2157 if (mb_c < 0x80)
2158 {
2159 c = mb_c;
2160#ifdef FEAT_LINEBREAK
2161 c0 = mb_c;
2162#endif
2163 }
2164 mb_utf8 = TRUE;
2165
2166 // At start of the line we can have a composing char.
2167 // Draw it as a space with a composing char.
2168 if (utf_iscomposing(mb_c))
2169 {
2170 int i;
2171
2172 for (i = Screen_mco - 1; i > 0; --i)
2173 u8cc[i] = u8cc[i - 1];
2174 u8cc[0] = mb_c;
2175 mb_c = ' ';
2176 }
2177 }
2178
2179 if ((mb_l == 1 && c >= 0x80)
2180 || (mb_l >= 1 && mb_c == 0)
2181 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2182 {
2183 // Illegal UTF-8 byte: display as <xx>.
2184 // Non-BMP character : display as ? or fullwidth ?.
2185 transchar_hex(extra, mb_c);
2186# ifdef FEAT_RIGHTLEFT
2187 if (wp->w_p_rl) // reverse
2188 rl_mirror(extra);
2189# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002190 wlv.p_extra = extra;
2191 c = *wlv.p_extra;
2192 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002194 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2195 wlv.c_extra = NUL;
2196 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002197 if (area_attr == 0 && search_attr == 0)
2198 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002199 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002200 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002201 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 }
2204 }
2205 else if (mb_l == 0) // at the NUL at end-of-line
2206 mb_l = 1;
2207#ifdef FEAT_ARABIC
2208 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2209 {
2210 // Do Arabic shaping.
2211 int pc, pc1, nc;
2212 int pcc[MAX_MCO];
2213
2214 // The idea of what is the previous and next
2215 // character depends on 'rightleft'.
2216 if (wp->w_p_rl)
2217 {
2218 pc = prev_c;
2219 pc1 = prev_c1;
2220 nc = utf_ptr2char(ptr + mb_l);
2221 prev_c1 = u8cc[0];
2222 }
2223 else
2224 {
2225 pc = utfc_ptr2char(ptr + mb_l, pcc);
2226 nc = prev_c;
2227 pc1 = pcc[0];
2228 }
2229 prev_c = mb_c;
2230
2231 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2232 }
2233 else
2234 prev_c = mb_c;
2235#endif
2236 }
2237 else // enc_dbcs
2238 {
2239 mb_l = MB_BYTE2LEN(c);
2240 if (mb_l == 0) // at the NUL at end-of-line
2241 mb_l = 1;
2242 else if (mb_l > 1)
2243 {
2244 // We assume a second byte below 32 is illegal.
2245 // Hopefully this is OK for all double-byte encodings!
2246 if (ptr[1] >= 32)
2247 mb_c = (c << 8) + ptr[1];
2248 else
2249 {
2250 if (ptr[1] == NUL)
2251 {
2252 // head byte at end of line
2253 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002254 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 }
2256 else
2257 {
2258 // illegal tail byte
2259 mb_l = 2;
2260 STRCPY(extra, "XX");
2261 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002262 wlv.p_extra = extra;
2263 wlv.n_extra = (int)STRLEN(extra) - 1;
2264 wlv.c_extra = NUL;
2265 wlv.c_final = NUL;
2266 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002267 if (area_attr == 0 && search_attr == 0)
2268 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002269 n_attr = wlv.n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002270 extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002271 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002272 // save current attr
2273 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 }
2275 mb_c = c;
2276 }
2277 }
2278 }
2279 // If a double-width char doesn't fit display a '>' in the
2280 // last column; the character is displayed at the start of the
2281 // next line.
2282 if ((
2283# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002284 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002285# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002286 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002287 && (*mb_char2cells)(mb_c) == 2)
2288 {
2289 c = '>';
2290 mb_c = c;
2291 mb_utf8 = FALSE;
2292 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002293 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 // Put pointer back so that the character will be
2295 // displayed at the start of the next line.
2296 --ptr;
2297#ifdef FEAT_CONCEAL
2298 did_decrement_ptr = TRUE;
2299#endif
2300 }
2301 else if (*ptr != NUL)
2302 ptr += mb_l - 1;
2303
2304 // If a double-width char doesn't fit at the left side display
2305 // a '<' in the first column. Don't do this for unprintable
2306 // characters.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002307 if (n_skip > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002308 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002309 wlv.n_extra = 1;
2310 wlv.c_extra = MB_FILLER_CHAR;
2311 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002312 c = ' ';
2313 if (area_attr == 0 && search_attr == 0)
2314 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002315 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002316 extra_attr = hl_combine_attr(
2317 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002318 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 }
2320 mb_c = c;
2321 mb_utf8 = FALSE;
2322 mb_l = 1;
2323 }
2324
2325 }
2326 ++ptr;
2327
2328 if (extra_check)
2329 {
2330#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002331 // Check spelling (unless at the end of the line).
2332 // Only do this when there is no syntax highlighting, the
2333 // @Spell cluster is not used or the current syntax item
2334 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002335 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002336 if (has_spell && v >= word_end && v > cur_checked_col)
2337 {
2338 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002339 // do not calculate cap_col at the end of the line or when
2340 // only white space is following
2341 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002342# ifdef FEAT_SYN_HL
2343 !has_syntax ||
2344# endif
2345 can_spell))
2346 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002347 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002348 int len;
2349 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002350
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002351 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002352 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353
2354 // Use nextline[] if possible, it has the start of the
2355 // next line concatenated.
2356 if ((prev_ptr - line) - nextlinecol >= 0)
2357 p = nextline + (prev_ptr - line) - nextlinecol;
2358 else
2359 p = prev_ptr;
2360 cap_col -= (int)(prev_ptr - line);
2361 len = spell_check(wp, p, &spell_hlf, &cap_col,
2362 nochange);
2363 word_end = v + len;
2364
2365 // In Insert mode only highlight a word that
2366 // doesn't touch the cursor.
2367 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002368 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002369 && wp->w_cursor.lnum == lnum
2370 && wp->w_cursor.col >=
2371 (colnr_T)(prev_ptr - line)
2372 && wp->w_cursor.col < (colnr_T)word_end)
2373 {
2374 spell_hlf = HLF_COUNT;
2375 spell_redraw_lnum = lnum;
2376 }
2377
2378 if (spell_hlf == HLF_COUNT && p != prev_ptr
2379 && (p - nextline) + len > nextline_idx)
2380 {
2381 // Remember that the good word continues at the
2382 // start of the next line.
2383 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002384 checked_col = (int)((p - nextline)
2385 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002386 }
2387
2388 // Turn index into actual attributes.
2389 if (spell_hlf != HLF_COUNT)
2390 spell_attr = highlight_attr[spell_hlf];
2391
2392 if (cap_col > 0)
2393 {
2394 if (p != prev_ptr
2395 && (p - nextline) + cap_col >= nextline_idx)
2396 {
2397 // Remember that the word in the next line
2398 // must start with a capital.
2399 capcol_lnum = lnum + 1;
2400 cap_col = (int)((p - nextline) + cap_col
2401 - nextline_idx);
2402 }
2403 else
2404 // Compute the actual column.
2405 cap_col += (int)(prev_ptr - line);
2406 }
2407 }
2408 }
2409 if (spell_attr != 0)
2410 {
2411 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002412 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2413 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002414 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 wlv.char_attr = hl_combine_attr(spell_attr,
2416 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002417 }
2418#endif
2419#ifdef FEAT_LINEBREAK
2420 // Found last space before word: check for line break.
2421 if (wp->w_p_lbr && c0 == c
2422 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2423 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002424 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2425 : 0;
2426 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002427 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002428
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002429 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002430# ifdef FEAT_PROP_POPUP
2431 // do not want virtual text counted here
2432 cts.cts_has_prop_with_text = FALSE;
2433# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002434 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002435 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002436
2437 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002438 // space for it again.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002439 if (wlv.vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002440 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002441 wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
2442 if (wlv.n_extra < 0)
2443 wlv.n_extra = 0;
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002444 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002445 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002446 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002447 // line break, but for TABs the highlighting should
2448 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002449 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002450
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002452# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01002453 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002454 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002455 wp->w_buffer->b_p_vts_array) - 1;
2456# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002457 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002458 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002459# endif
2460
Bram Moolenaar1306b362022-08-06 15:59:06 +01002461 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2462 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002463# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01002464 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002465 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002466# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 if (VIM_ISWHITE(c))
2468 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002469# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 if (c == TAB)
2471 // See "Tab alignment" below.
2472 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002473# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002474 if (!wp->w_p_list)
2475 c = ' ';
2476 }
2477 }
2478#endif
zeertzjqf14b8ba2021-09-10 16:58:30 +02002479 in_multispace = c == ' '
2480 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2481 if (!in_multispace)
2482 multispace_pos = 0;
2483
Bram Moolenaareed9d462021-02-15 20:38:25 +01002484 // 'list': Change char 160 to 'nbsp' and space to 'space'
2485 // setting in 'listchars'. But not when the character is
2486 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002487 if (wp->w_p_list
2488 && ((((c == 160 && mb_l == 1)
2489 || (mb_utf8
2490 && ((mb_c == 160 && mb_l == 2)
2491 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002492 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 || (c == ' '
2494 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002495 && (wp->w_lcs_chars.space
2496 || (in_multispace
2497 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002498 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 && ptr - line <= trailcol)))
2500 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002501 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2502 {
2503 c = wp->w_lcs_chars.multispace[multispace_pos++];
2504 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2505 multispace_pos = 0;
2506 }
2507 else
2508 c = (c == ' ') ? wp->w_lcs_chars.space
2509 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 if (area_attr == 0 && search_attr == 0)
2511 {
2512 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002513 extra_attr = hl_combine_attr(wlv.win_attr,
2514 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002515 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002516 }
2517 mb_c = c;
2518 if (enc_utf8 && utf_char2len(c) > 1)
2519 {
2520 mb_utf8 = TRUE;
2521 u8cc[0] = 0;
2522 c = 0xc0;
2523 }
2524 else
2525 mb_utf8 = FALSE;
2526 }
2527
zeertzjq2e7cba32022-06-10 15:30:32 +01002528 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2529 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002531 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2532 && wp->w_lcs_chars.leadmultispace != NULL)
2533 {
2534 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002535 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2536 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002537 multispace_pos = 0;
2538 }
2539
2540 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2541 c = wp->w_lcs_chars.trail;
2542
2543 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2544 c = wp->w_lcs_chars.lead;
2545
zeertzjq2e7cba32022-06-10 15:30:32 +01002546 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002547 c = wp->w_lcs_chars.space;
2548
2549
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002550 if (!attr_pri)
2551 {
2552 n_attr = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002553 extra_attr = hl_combine_attr(wlv.win_attr,
2554 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002555 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002556 }
2557 mb_c = c;
2558 if (enc_utf8 && utf_char2len(c) > 1)
2559 {
2560 mb_utf8 = TRUE;
2561 u8cc[0] = 0;
2562 c = 0xc0;
2563 }
2564 else
2565 mb_utf8 = FALSE;
2566 }
2567 }
2568
2569 // Handling of non-printable characters.
2570 if (!vim_isprintc(c))
2571 {
2572 // when getting a character from the file, we may have to
2573 // turn it into something else on the way to putting it
2574 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002575 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002576 {
2577 int tab_len = 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002578 long vcol_adjusted = wlv.vcol; // removed showbreak length
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002580 char_u *sbr = get_showbreak_value(wp);
2581
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 // only adjust the tab_len, when at the first column
2583 // after the showbreak value was drawn
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002584 if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
2585 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586#endif
2587 // tab amount depends on current column
2588#ifdef FEAT_VARTABS
2589 tab_len = tabstop_padding(vcol_adjusted,
2590 wp->w_buffer->b_p_ts,
2591 wp->w_buffer->b_p_vts_array) - 1;
2592#else
2593 tab_len = (int)wp->w_buffer->b_p_ts
2594 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2595#endif
2596
2597#ifdef FEAT_LINEBREAK
2598 if (!wp->w_p_lbr || !wp->w_p_list)
2599#endif
2600 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 wlv.n_extra = tab_len;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602#ifdef FEAT_LINEBREAK
2603 else
2604 {
2605 char_u *p;
2606 int len;
2607 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002610# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002611 if (wlv.vcol_off > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 // there are characters to conceal
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002613 tab_len += wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002614
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002616 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 && old_boguscols > 0
2618 && wlv.n_extra > tab_len)
2619 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002620# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002621 // If wlv.n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002622 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002623 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002624 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002625 if (wp->w_lcs_chars.tab3)
2626 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 if (wlv.n_extra > 0)
2628 len += wlv.n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002629 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002631 if (p == NULL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002632 wlv.n_extra = 0;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002633 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002635 vim_memset(p, ' ', len);
2636 p[len] = NUL;
2637 vim_free(p_extra_free);
2638 p_extra_free = p;
2639 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002641 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002643 if (*p == NUL)
2644 {
2645 tab_len = i;
2646 break;
2647 }
2648
2649 // if tab3 is given, use it for the last char
2650 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2651 lcs = wp->w_lcs_chars.tab3;
2652 p += mb_char2bytes(lcs, p);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002653 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002654 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002655 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002656 wlv.p_extra = p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002657# ifdef FEAT_CONCEAL
2658 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2659 // macro below, so need to adjust for that here
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002660 if (wlv.vcol_off > 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002661 wlv.n_extra -= wlv.vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002662# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002664 }
2665#endif
2666#ifdef FEAT_CONCEAL
2667 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002668 int vc_saved = wlv.vcol_off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669
2670 // Tab alignment should be identical regardless of
2671 // 'conceallevel' value. So tab compensates of all
2672 // previous concealed characters, and thus resets
2673 // vcol_off and boguscols accumulated so far in the
2674 // line. Note that the tab can be longer than
2675 // 'tabstop' when there are concealed characters.
2676 FIX_FOR_BOGUSCOLS;
2677
2678 // Make sure, the highlighting for the tab char will be
2679 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002680 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01002681 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002682 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002683 tab_len += vc_saved;
2684 }
2685#endif
2686 mb_utf8 = FALSE; // don't draw as UTF-8
2687 if (wp->w_p_list)
2688 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002689 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01002690 ? wp->w_lcs_chars.tab3
2691 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002692#ifdef FEAT_LINEBREAK
2693 if (wp->w_p_lbr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002694 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002695 else
2696#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002697 wlv.c_extra = wp->w_lcs_chars.tab2;
2698 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 n_attr = tab_len + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002700 extra_attr = hl_combine_attr(wlv.win_attr,
2701 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002702 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 mb_c = c;
2704 if (enc_utf8 && utf_char2len(c) > 1)
2705 {
2706 mb_utf8 = TRUE;
2707 u8cc[0] = 0;
2708 c = 0xc0;
2709 }
2710 }
2711 else
2712 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002713 wlv.c_final = NUL;
2714 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002715 c = ' ';
2716 }
2717 }
2718 else if (c == NUL
2719 && (wp->w_p_list
2720 || ((fromcol >= 0 || fromcol_prev >= 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002721 && tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 && VIsual_mode != Ctrl_V
2723 && (
2724# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002725 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002726# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002727 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 && !(noinvcur
2729 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002730 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002731 && lcs_eol_one > 0)
2732 {
2733 // Display a '$' after the line or highlight an extra
2734 // character if the line break is included.
2735#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2736 // For a diff line the highlighting continues after the
2737 // "$".
2738 if (
2739# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002741# ifdef LINE_ATTR
2742 &&
2743# endif
2744# endif
2745# ifdef LINE_ATTR
2746 line_attr == 0
2747# endif
2748 )
2749#endif
2750 {
2751 // In virtualedit, visual selections may extend
2752 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002753 if (!(area_highlighting && virtual_active()
2754 && tocol != MAXCOL && wlv.vcol < tocol))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002755 wlv.p_extra = at_end_str;
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01002756 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002757 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002758 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2759 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760 else
2761 c = ' ';
2762 lcs_eol_one = -1;
2763 --ptr; // put it back at the NUL
2764 if (!attr_pri)
2765 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002766 extra_attr = hl_combine_attr(wlv.win_attr,
2767 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002768 n_attr = 1;
2769 }
2770 mb_c = c;
2771 if (enc_utf8 && utf_char2len(c) > 1)
2772 {
2773 mb_utf8 = TRUE;
2774 u8cc[0] = 0;
2775 c = 0xc0;
2776 }
2777 else
2778 mb_utf8 = FALSE; // don't draw as UTF-8
2779 }
2780 else if (c != NUL)
2781 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002782 wlv.p_extra = transchar_buf(wp->w_buffer, c);
2783 if (wlv.n_extra == 0)
2784 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002785#ifdef FEAT_RIGHTLEFT
2786 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002789 wlv.c_extra = NUL;
2790 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791#ifdef FEAT_LINEBREAK
2792 if (wp->w_p_lbr)
2793 {
2794 char_u *p;
2795
Bram Moolenaar1306b362022-08-06 15:59:06 +01002796 c = *wlv.p_extra;
2797 p = alloc(wlv.n_extra + 1);
2798 vim_memset(p, ' ', wlv.n_extra);
2799 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
2800 p[wlv.n_extra] = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 vim_free(p_extra_free);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002802 p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002803 }
2804 else
2805#endif
2806 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002807 wlv.n_extra = byte2cells(c) - 1;
2808 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002809 }
2810 if (!attr_pri)
2811 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002812 n_attr = wlv.n_extra + 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002813 extra_attr = hl_combine_attr(wlv.win_attr,
2814 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002815 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 }
2817 mb_utf8 = FALSE; // don't draw as UTF-8
2818 }
2819 else if (VIsual_active
2820 && (VIsual_mode == Ctrl_V
2821 || VIsual_mode == 'v')
2822 && virtual_active()
2823 && tocol != MAXCOL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 && wlv.vcol < tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002825 && (
2826#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002827 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002828#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002829 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002830 {
2831 c = ' ';
2832 --ptr; // put it back at the NUL
2833 }
2834#if defined(LINE_ATTR)
2835 else if ((
2836# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002837 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838# endif
2839# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841# endif
2842 line_attr != 0
2843 ) && (
2844# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002845 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002847 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002849 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002850# endif
2851 < wp->w_width)))
2852 {
2853 // Highlight until the right side of the window
2854 c = ' ';
2855 --ptr; // put it back at the NUL
2856
2857 // Remember we do the char for line highlighting.
2858 ++did_line_attr;
2859
2860 // don't do search HL for the rest of the line
Bram Moolenaar1306b362022-08-06 15:59:06 +01002861 if (line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002862 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002863 || (wp->w_p_list &&
2864 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 wlv.char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002869 wlv.diff_hlf = HLF_CHD;
2870 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002872 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2874 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01002875 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002876 || (wlv.vcol >= left_curline_col
2877 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002878 wlv.char_attr = hl_combine_attr(
2879 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 }
2881 }
2882# endif
2883# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002884 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002885 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002886 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002887 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2888 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002890 if (!wlv.cul_screenline
2891 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002892 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002893 wlv.char_attr = hl_combine_attr(
2894 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 }
2896 else if (line_attr)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002897 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2898 line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 }
2900# endif
2901 }
2902#endif
2903 }
2904
2905#ifdef FEAT_CONCEAL
2906 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002907 && (wp != curwin || lnum != wp->w_cursor.lnum
2908 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2910 && !(lnum_in_visual_area
2911 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2912 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002913 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002914 if (((prev_syntax_id != syntax_seqnr
2915 && (syntax_flags & HL_CONCEAL) != 0)
2916 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002917 && (syn_get_sub_char() != NUL
2918 || (has_match_conc && match_conc)
2919 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002920 && wp->w_p_cole != 3)
2921 {
2922 // First time at this concealed item: display one
2923 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002924 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002925 c = match_conc;
2926 else if (syn_get_sub_char() != NUL)
2927 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002928 else if (wp->w_lcs_chars.conceal != NUL)
2929 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002930 else
2931 c = ' ';
2932
2933 prev_syntax_id = syntax_seqnr;
2934
Bram Moolenaar1306b362022-08-06 15:59:06 +01002935 if (wlv.n_extra > 0)
2936 wlv.vcol_off += wlv.n_extra;
2937 wlv.vcol += wlv.n_extra;
2938 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 {
2940# ifdef FEAT_RIGHTLEFT
2941 if (wp->w_p_rl)
2942 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002943 wlv.col -= wlv.n_extra;
2944 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 }
2946 else
2947# endif
2948 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002949 wlv.boguscols += wlv.n_extra;
2950 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002951 }
2952 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002953 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 n_attr = 0;
2955 }
2956 else if (n_skip == 0)
2957 {
2958 is_concealing = TRUE;
2959 n_skip = 1;
2960 }
2961 mb_c = c;
2962 if (enc_utf8 && utf_char2len(c) > 1)
2963 {
2964 mb_utf8 = TRUE;
2965 u8cc[0] = 0;
2966 c = 0xc0;
2967 }
2968 else
2969 mb_utf8 = FALSE; // don't draw as UTF-8
2970 }
2971 else
2972 {
2973 prev_syntax_id = 0;
2974 is_concealing = FALSE;
2975 }
2976
2977 if (n_skip > 0 && did_decrement_ptr)
2978 // not showing the '>', put pointer back to avoid getting stuck
2979 ++ptr;
2980
2981#endif // FEAT_CONCEAL
2982 }
2983
2984#ifdef FEAT_CONCEAL
2985 // In the cursor line and we may be concealing characters: correct
2986 // the cursor column when we reach its position.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002987 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002988 && wp == curwin && lnum == wp->w_cursor.lnum
2989 && conceal_cursor_line(wp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002990 && (int)wp->w_virtcol <= wlv.vcol + n_skip)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002991 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002992# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002994 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002995 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002996# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002997 wp->w_wcol = wlv.col - wlv.boguscols;
2998 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002999 did_wcol = TRUE;
3000 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003001# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003002 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003003# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 }
3005#endif
3006
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01003007 // Use "extra_attr", but don't override visual selection highlighting,
3008 // unless text property overrides.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003009 // Don't use "extra_attr" until n_attr_skip is zero.
3010 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003011 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003012 && (!attr_pri
3013#ifdef FEAT_PROP_POPUP
3014 || (text_prop_flags & PT_FLAG_OVERRIDE)
3015#endif
3016 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003017 {
3018#ifdef LINE_ATTR
3019 if (line_attr)
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01003020 wlv.char_attr = hl_combine_attr(line_attr, extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003021 else
3022#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003023 wlv.char_attr = extra_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 }
3025
3026#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3027 // XIM don't send preedit_start and preedit_end, but they send
3028 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3029 // im_is_preediting() here.
3030 if (p_imst == IM_ON_THE_SPOT
3031 && xic != NULL
3032 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003033 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003034 && !p_imdisable
3035 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003036 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003037 {
3038 colnr_T tcol;
3039
3040 if (preedit_end_col == MAXCOL)
3041 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3042 else
3043 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003044 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 {
3046 if (feedback_old_attr < 0)
3047 {
3048 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003049 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003050 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.char_attr = im_get_feedback_attr(feedback_col);
3052 if (wlv.char_attr < 0)
3053 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003054 feedback_col++;
3055 }
3056 else if (feedback_old_attr >= 0)
3057 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 feedback_old_attr = -1;
3060 feedback_col = 0;
3061 }
3062 }
3063#endif
3064 // Handle the case where we are in column 0 but not on the first
3065 // character of the line and the user wants us to show us a
3066 // special character (via 'listchars' option "precedes:<char>".
3067 if (lcs_prec_todo != NUL
3068 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003069 && (wp->w_p_wrap ?
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003070 (wp->w_skipcol > 0 && wlv.row == 0) :
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02003071 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003072#ifdef FEAT_DIFF
3073 && filler_todo <= 0
3074#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003075 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 && c != NUL)
3077 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003078 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003079 lcs_prec_todo = NUL;
3080 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3081 {
3082 // Double-width character being overwritten by the "precedes"
3083 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003084 wlv.c_extra = MB_FILLER_CHAR;
3085 wlv.c_final = NUL;
3086 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003087 n_attr = 2;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003088 extra_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003089 }
3090 mb_c = c;
3091 if (enc_utf8 && utf_char2len(c) > 1)
3092 {
3093 mb_utf8 = TRUE;
3094 u8cc[0] = 0;
3095 c = 0xc0;
3096 }
3097 else
3098 mb_utf8 = FALSE; // don't draw as UTF-8
3099 if (!attr_pri)
3100 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003101 saved_attr3 = wlv.char_attr; // save current attr
3102 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003103 n_attr3 = 1;
3104 }
3105 }
3106
3107 // At end of the text line or just after the last character.
3108 if ((c == NUL
3109#if defined(LINE_ATTR)
3110 || did_line_attr == 1
3111#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003112 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 {
3114#ifdef FEAT_SEARCH_EXTRA
3115 // flag to indicate whether prevcol equals startcol of search_hl or
3116 // one of the matches
3117 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3118 (long)(ptr - line) - (c == NUL));
3119#endif
3120 // Invert at least one char, used for Visual and empty line or
3121 // highlight match at end of line. If it's beyond the last
3122 // char on the screen, just overwrite that one (tricky!) Not
3123 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003124 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003125 && ((area_attr != 0 && wlv.vcol == fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003126 && (VIsual_mode != Ctrl_V
3127 || lnum == VIsual.lnum
3128 || lnum == curwin->w_cursor.lnum)
3129 && c == NUL)
3130#ifdef FEAT_SEARCH_EXTRA
3131 // highlight 'hlsearch' match at end of line
3132 || (prevcol_hl_flag
3133# ifdef FEAT_SYN_HL
3134 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3135 && !(wp == curwin && VIsual_active))
3136# endif
3137# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003138 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139# endif
3140# if defined(LINE_ATTR)
3141 && did_line_attr <= 1
3142# endif
3143 )
3144#endif
3145 ))
3146 {
3147 int n = 0;
3148
3149#ifdef FEAT_RIGHTLEFT
3150 if (wp->w_p_rl)
3151 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003152 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 n = 1;
3154 }
3155 else
3156#endif
3157 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003158 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 n = -1;
3160 }
3161 if (n != 0)
3162 {
3163 // At the window boundary, highlight the last character
3164 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003165 wlv.off += n;
3166 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003167 }
3168 else
3169 {
3170 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003171 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003173 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 }
3175#ifdef FEAT_SEARCH_EXTRA
3176 if (area_attr == 0)
3177 {
3178 // Use attributes from match with highest priority among
3179 // 'search_hl' and the match list.
3180 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003181 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 }
3183#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003184 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003185 ScreenCols[wlv.off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186#ifdef FEAT_RIGHTLEFT
3187 if (wp->w_p_rl)
3188 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003189 --wlv.col;
3190 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003191 }
3192 else
3193#endif
3194 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003195 ++wlv.col;
3196 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003197 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003198 ++wlv.vcol;
3199 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 }
3201 }
3202
3203 // At end of the text line.
3204 if (c == NUL)
3205 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003206 draw_screen_line(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003207
3208 // Update w_cline_height and w_cline_folded if the cursor line was
3209 // updated (saves a call to plines() later).
3210 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3211 {
3212 curwin->w_cline_row = startrow;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003213 curwin->w_cline_height = wlv.row - startrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214#ifdef FEAT_FOLDING
3215 curwin->w_cline_folded = FALSE;
3216#endif
3217 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3218 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003219 break;
3220 }
3221
3222 // Show "extends" character from 'listchars' if beyond the line end and
3223 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003224 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003225 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 && wp->w_p_list
3227 && !wp->w_p_wrap
3228#ifdef FEAT_DIFF
3229 && filler_todo <= 0
3230#endif
3231 && (
3232#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003233 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003235 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003236 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003237 || lcs_eol_one > 0
3238 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003239 || *wlv.p_extra != NUL))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003240 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003241 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003242 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243 mb_c = c;
3244 if (enc_utf8 && utf_char2len(c) > 1)
3245 {
3246 mb_utf8 = TRUE;
3247 u8cc[0] = 0;
3248 c = 0xc0;
3249 }
3250 else
3251 mb_utf8 = FALSE;
3252 }
3253
3254#ifdef FEAT_SYN_HL
3255 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003256 if (wlv.draw_color_col)
3257 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258
3259 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3260 // highlight the cursor position itself.
3261 // Also highlight the 'colorcolumn' if it is different than
3262 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003263 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3264 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003265 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 if (((wlv.draw_state == WL_LINE
3267 || wlv.draw_state == WL_BRI
3268 || wlv.draw_state == WL_SBR)
3269 && !lnum_in_visual_area
3270 && search_attr == 0
3271 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003272# ifdef FEAT_DIFF
3273 && filler_todo <= 0
3274# endif
3275 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276 {
3277 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3278 && lnum != wp->w_cursor.lnum)
3279 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003280 vcol_save_attr = wlv.char_attr;
3281 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3282 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003284 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003285 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003286 vcol_save_attr = wlv.char_attr;
3287 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003288 }
3289 }
3290#endif
3291
3292 // Store character to be displayed.
3293 // Skip characters that are left of the screen for 'nowrap'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003294 vcol_prev = wlv.vcol;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003295 if (wlv.draw_state < WL_LINE || n_skip <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296 {
3297 // Store the character.
3298#if defined(FEAT_RIGHTLEFT)
3299 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3300 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003301 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003302 --wlv.off;
3303 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 }
3305#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 if (enc_dbcs == DBCS_JPNU)
3308 {
3309 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003310 ScreenLines[wlv.off] = 0x8e;
3311 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003312 }
3313 else if (enc_utf8)
3314 {
3315 if (mb_utf8)
3316 {
3317 int i;
3318
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003319 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003320 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003321 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003322 for (i = 0; i < Screen_mco; ++i)
3323 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003324 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325 if (u8cc[i] == 0)
3326 break;
3327 }
3328 }
3329 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003330 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 }
3332 if (multi_attr)
3333 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335 multi_attr = 0;
3336 }
3337 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003338 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003341
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003342 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3343 {
3344 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003345 ++wlv.off;
3346 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003347 if (enc_utf8)
3348 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003349 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350 else
3351 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003352 ScreenLines[wlv.off] = mb_c & 0xff;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003354#ifdef FEAT_DIFF
3355 && filler_todo <= 0
3356#endif
3357 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003358 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 // When "tocol" is halfway a character, set it to the end of
3360 // the character, otherwise highlighting won't stop.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003361 if (tocol == wlv.vcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003363
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003364 ScreenCols[wlv.off] = (colnr_T)(prev_ptr - line);
Bram Moolenaarb9081882022-07-09 04:56:24 +01003365
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003366#ifdef FEAT_RIGHTLEFT
3367 if (wp->w_p_rl)
3368 {
3369 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003370 --wlv.off;
3371 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003372 }
3373#endif
3374 }
3375#ifdef FEAT_RIGHTLEFT
3376 if (wp->w_p_rl)
3377 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003378 --wlv.off;
3379 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 else
3382#endif
3383 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003384 ++wlv.off;
3385 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 }
3388#ifdef FEAT_CONCEAL
3389 else if (wp->w_p_cole > 0 && is_concealing)
3390 {
3391 --n_skip;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003392 ++wlv.vcol_off;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003393 if (wlv.n_extra > 0)
3394 wlv.vcol_off += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 if (wp->w_p_wrap)
3396 {
3397 // Special voodoo required if 'wrap' is on.
3398 //
3399 // Advance the column indicator to force the line
3400 // drawing to wrap early. This will make the line
3401 // take up the same screen space when parts are concealed,
3402 // so that cursor line computations aren't messed up.
3403 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405 // trailing junk to be written out of the screen line
3406 // we are building, 'boguscols' keeps track of the number
3407 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003408 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003410 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411# ifdef FEAT_RIGHTLEFT
3412 if (wp->w_p_rl)
3413 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 wlv.col -= wlv.n_extra;
3415 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003416 }
3417 else
3418# endif
3419 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.col += wlv.n_extra;
3421 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003423 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 n_attr = 0;
3425 }
3426
3427
3428 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3429 {
3430 // Need to fill two screen columns.
3431# ifdef FEAT_RIGHTLEFT
3432 if (wp->w_p_rl)
3433 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003434 --wlv.boguscols;
3435 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003436 }
3437 else
3438# endif
3439 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003440 ++wlv.boguscols;
3441 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003442 }
3443 }
3444
3445# ifdef FEAT_RIGHTLEFT
3446 if (wp->w_p_rl)
3447 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 --wlv.boguscols;
3449 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450 }
3451 else
3452# endif
3453 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003454 ++wlv.boguscols;
3455 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456 }
3457 }
3458 else
3459 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003460 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 wlv.vcol += wlv.n_extra;
3463 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 n_attr = 0;
3465 }
3466 }
3467
3468 }
3469#endif // FEAT_CONCEAL
3470 else
3471 --n_skip;
3472
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003473 // Only advance the "wlv.vcol" when after the 'number' or
3474 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003475 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003476#ifdef FEAT_DIFF
3477 && filler_todo <= 0
3478#endif
3479 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003480 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481
3482#ifdef FEAT_SYN_HL
3483 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003484 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485#endif
3486
3487 // restore attributes after "predeces" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01003488 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3489 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003490
3491 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01003492 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003493 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003494 wlv.char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003495 if (n_attr_skip > 0)
3496 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003497
3498 // At end of screen line and there is more to come: Display the line
3499 // so far. If there is no more to display it is caught above.
3500 if ((
3501#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003502 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003503#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003505 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003506 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003507#ifdef FEAT_DIFF
3508 || filler_todo > 0
3509#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003510#ifdef FEAT_PROP_POPUP
3511 || text_prop_follows
3512#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003513 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 && wlv.p_extra != at_end_str)
3515 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
3516 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 )
3518 {
3519#ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003520 screen_line(wp, wlv.screen_row, wp->w_wincol,
3521 wlv.col - wlv.boguscols,
3522 wp->w_width, wlv.screen_line_flags);
3523 wlv.boguscols = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003524#else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003525 screen_line(wp, wlv.screen_row, wp->w_wincol, wlv.col,
3526 wp->w_width, wlv.screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003528 ++wlv.row;
3529 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003530
3531 // When not wrapping and finished diff lines, or when displayed
3532 // '$' and highlighting until last column, break here.
3533 if ((!wp->w_p_wrap
3534#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003535 && filler_todo <= 0
3536#endif
3537#ifdef FEAT_PROP_POPUP
3538 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003539#endif
3540 ) || lcs_eol_one == -1)
3541 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003542#ifdef FEAT_PROP_POPUP
Bram Moolenaar83bf11a2022-08-06 22:23:40 +01003543 if (!wp->w_p_wrap && text_prop_follows)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01003544 {
3545 // do not output more of the line, only the "below" prop
3546 ptr += STRLEN(ptr);
3547# ifdef FEAT_LINEBREAK
3548 dont_use_showbreak = TRUE;
3549# endif
3550 }
3551#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552
3553 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003554 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555#ifdef FEAT_DIFF
3556 && filler_todo <= 0
3557#endif
3558 )
3559 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003560 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
3561 draw_vsep_win(wp, wlv.row);
3562 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003563 }
3564
3565 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003566 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003567 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003568 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003569 break;
3570 }
3571
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003572 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003573#ifdef FEAT_DIFF
3574 && filler_todo <= 0
3575#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003576#ifdef FEAT_PROP_POPUP
3577 && !text_prop_follows
3578#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003579 && wp->w_width == Columns)
3580 {
3581 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003582 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583
3584 // Special trick to make copy/paste of wrapped lines work with
3585 // xterm/screen: write an extra character beyond the end of
3586 // the line. This will work with all terminal types
3587 // (regardless of the xn,am settings).
3588 // Only do this on a fast tty.
3589 // Only do this if the cursor is on the current line
3590 // (something has been written in it).
3591 // Don't do this for the GUI.
3592 // Don't do this for double-width characters.
3593 // Don't do this for a window not at the right screen border.
3594 if (p_tf
3595#ifdef FEAT_GUI
3596 && !gui.in_use
3597#endif
3598 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
3600 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003602 || (*mb_off2cells)(
3603 LineOffset[wlv.screen_row - 1]
3604 + (int)Columns - 2,
3605 LineOffset[wlv.screen_row]
3606 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003607 {
3608 // First make sure we are at the end of the screen line,
3609 // then output the same character again to let the
3610 // terminal know about the wrap. If the terminal doesn't
3611 // auto-wrap, we overwrite the character.
3612 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003613 screen_char(LineOffset[wlv.screen_row - 1]
3614 + (unsigned)Columns - 1,
3615 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616
3617 // When there is a multi-byte character, just output a
3618 // space to keep it simple.
3619 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003620 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003621 out_char(' ');
3622 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003623 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003624 + (Columns - 1)]);
3625 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003626 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003627 screen_start(); // don't know where cursor is now
3628 }
3629 }
3630
Bram Moolenaar1306b362022-08-06 15:59:06 +01003631 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632
Bram Moolenaareed9d462021-02-15 20:38:25 +01003633 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003634#ifdef FEAT_LINEBREAK
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003635 if (!dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636# ifdef FEAT_DIFF
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003637 && filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01003639 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003640 need_showbreak = TRUE;
3641#endif
3642#ifdef FEAT_DIFF
3643 --filler_todo;
3644 // When the filler lines are actually below the last line of the
3645 // file, don't draw the line itself, break here.
3646 if (filler_todo == 0 && wp->w_botfill)
3647 break;
3648#endif
3649 }
3650
3651 } // for every character in the line
3652
3653#ifdef FEAT_SPELL
3654 // After an empty line check first word for capital.
3655 if (*skipwhite(line) == NUL)
3656 {
3657 capcol_lnum = lnum + 1;
3658 cap_col = 0;
3659 }
3660#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003661#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 vim_free(text_props);
3663 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01003664 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003665#endif
3666
3667 vim_free(p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003668 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669}