blob: 949d6f998aecfb5bfe18a39d864b91a85617f689 [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.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * 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
78#ifdef FEAT_SIGNS
79/*
Bram Moolenaare413ea02021-11-24 16:20:13 +000080 * Return TRUE if CursorLineSign highlight is to be used.
81 */
82 static int
83use_cursor_line_sign(win_T *wp, linenr_T lnum)
84{
85 return wp->w_p_cul
86 && lnum == wp->w_cursor.lnum
87 && (wp->w_p_culopt_flags & CULOPT_NBR);
88}
89
90/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020091 * Get information needed to display the sign in line 'lnum' in window 'wp'.
92 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
93 * Otherwise the sign is going to be displayed in the sign column.
94 */
95 static void
96get_sign_display_info(
97 int nrcol,
98 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +000099 linenr_T lnum,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200100 sign_attrs_T *sattr,
101 int wcr_attr,
102 int row,
103 int startrow,
104 int filler_lines UNUSED,
105 int filler_todo UNUSED,
106 int *c_extrap,
107 int *c_finalp,
108 char_u *extra,
109 char_u **pp_extra,
110 int *n_extrap,
111 int *char_attrp)
112{
113 int text_sign;
114# ifdef FEAT_SIGN_ICONS
115 int icon_sign;
116# endif
117
118 // Draw two cells with the sign value or blank.
119 *c_extrap = ' ';
120 *c_finalp = NUL;
121 if (nrcol)
122 *n_extrap = number_width(wp) + 1;
123 else
124 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000125 if (use_cursor_line_sign(wp, lnum))
126 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
127 else
128 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200129 *n_extrap = 2;
130 }
131
132 if (row == startrow
133#ifdef FEAT_DIFF
134 + filler_lines && filler_todo <= 0
135#endif
136 )
137 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200138 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200139# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200140 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141 if (gui.in_use && icon_sign != 0)
142 {
143 // Use the image in this position.
144 if (nrcol)
145 {
146 *c_extrap = NUL;
147 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
148 *pp_extra = extra;
149 *n_extrap = (int)STRLEN(*pp_extra);
150 }
151 else
152 *c_extrap = SIGN_BYTE;
153# ifdef FEAT_NETBEANS_INTG
154 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
155 {
156 if (nrcol)
157 {
158 *c_extrap = NUL;
159 sprintf((char *)extra, "%-*c ", number_width(wp),
160 MULTISIGN_BYTE);
161 *pp_extra = extra;
162 *n_extrap = (int)STRLEN(*pp_extra);
163 }
164 else
165 *c_extrap = MULTISIGN_BYTE;
166 }
167# endif
168 *c_finalp = NUL;
169 *char_attrp = icon_sign;
170 }
171 else
172# endif
173 if (text_sign != 0)
174 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200175 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200176 if (*pp_extra != NULL)
177 {
178 if (nrcol)
179 {
180 int n, width = number_width(wp) - 2;
181
182 for (n = 0; n < width; n++)
183 extra[n] = ' ';
184 extra[n] = 0;
185 STRCAT(extra, *pp_extra);
186 STRCAT(extra, " ");
187 *pp_extra = extra;
188 }
189 *c_extrap = NUL;
190 *c_finalp = NUL;
191 *n_extrap = (int)STRLEN(*pp_extra);
192 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
194 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
195 *char_attrp = sattr->sat_culhl;
196 else
197 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 }
199 }
200}
201#endif
202
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100203#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200204static textprop_T *current_text_props = NULL;
205static buf_T *current_buf = NULL;
206
207 static int
208text_prop_compare(const void *s1, const void *s2)
209{
210 int idx1, idx2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100211 textprop_T *tp1, *tp2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200212 proptype_T *pt1, *pt2;
213 colnr_T col1, col2;
214
215 idx1 = *(int *)s1;
216 idx2 = *(int *)s2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100217 tp1 = &current_text_props[idx1];
218 tp2 = &current_text_props[idx2];
219 pt1 = text_prop_type_by_id(current_buf, tp1->tp_type);
220 pt2 = text_prop_type_by_id(current_buf, tp2->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200221 if (pt1 == pt2)
222 return 0;
223 if (pt1 == NULL)
224 return -1;
225 if (pt2 == NULL)
226 return 1;
227 if (pt1->pt_priority != pt2->pt_priority)
228 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100229 col1 = tp1->tp_col;
230 col2 = tp2->tp_col;
231 if (col1 == MAXCOL && col2 == MAXCOL)
232 {
233 int flags1 = 0;
234 int flags2 = 0;
235
236 // order on 0: after, 1: right, 2: below
237 if (tp1->tp_flags & TP_FLAG_ALIGN_RIGHT)
238 flags1 = 1;
239 if (tp1->tp_flags & TP_FLAG_ALIGN_BELOW)
240 flags1 = 2;
241 if (tp2->tp_flags & TP_FLAG_ALIGN_RIGHT)
242 flags2 = 1;
243 if (tp2->tp_flags & TP_FLAG_ALIGN_BELOW)
244 flags2 = 2;
245 if (flags1 != flags2)
246 return flags1 < flags2 ? 1 : -1;
247 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200248 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
249}
250#endif
251
252/*
253 * Display line "lnum" of window 'wp' on the screen.
254 * Start at row "startrow", stop when "endrow" is reached.
255 * wp->w_virtcol needs to be valid.
256 *
257 * Return the number of last row the line occupies.
258 */
259 int
260win_line(
261 win_T *wp,
262 linenr_T lnum,
263 int startrow,
264 int endrow,
265 int nochange UNUSED, // not updating for changed text
266 int number_only) // only update the number column
267{
268 int col = 0; // visual column on screen
269 unsigned off; // offset in ScreenLines/ScreenAttrs
270 int c = 0; // init for GCC
271 long vcol = 0; // virtual column (for tabs)
272#ifdef FEAT_LINEBREAK
273 long vcol_sbr = -1; // virtual column after showbreak
274#endif
275 long vcol_prev = -1; // "vcol" of previous character
276 char_u *line; // current line
277 char_u *ptr; // current position in "line"
278 int row; // row in the window, excl w_winrow
279 int screen_row; // row on the screen, incl w_winrow
280
281 char_u extra[21]; // "%ld " and 'fdc' must fit in here
282 int n_extra = 0; // number of extra chars
283 char_u *p_extra = NULL; // string of extra chars, plus NUL
284 char_u *p_extra_free = NULL; // p_extra needs to be freed
285 int c_extra = NUL; // extra chars, all the same
286 int c_final = NUL; // final char, mandatory if set
287 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000288#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000289 int in_linebreak = FALSE; // n_extra set for showing linebreak
290#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100292 // displaying eol at end-of-line
293 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000294 int lcs_prec_todo = wp->w_lcs_chars.prec;
295 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200296
297 // saved "extra" items for when draw_state becomes WL_LINE (again)
298 int saved_n_extra = 0;
299 char_u *saved_p_extra = NULL;
300 int saved_c_extra = 0;
301 int saved_c_final = 0;
302 int saved_char_attr = 0;
303
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100304 int n_attr = 0; // chars with special attr
305 int n_attr_skip = 0; // chars to skip before using extra_attr
306 int saved_attr2 = 0; // char_attr saved for n_attr
307 int n_attr3 = 0; // chars with overruling special attr
308 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309
310 int n_skip = 0; // nr of chars to skip for 'nowrap'
311
312 int fromcol = -10; // start of inverting
313 int tocol = MAXCOL; // end of inverting
314 int fromcol_prev = -2; // start of inverting after cursor
315 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200316 int lnum_in_visual_area = FALSE;
317 pos_T pos;
318 long v;
319
320 int char_attr = 0; // attributes for next character
321 int attr_pri = FALSE; // char_attr has priority
322 int area_highlighting = FALSE; // Visual or incsearch highlighting
323 // in this line
324 int vi_attr = 0; // attributes for Visual and incsearch
325 // highlighting
326 int wcr_attr = 0; // attributes from 'wincolor'
327 int win_attr = 0; // background for whole window, except
328 // margins and "~" lines.
329 int area_attr = 0; // attributes desired by highlighting
330 int search_attr = 0; // attributes desired by 'hlsearch'
331#ifdef FEAT_SYN_HL
332 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
333 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200334 int prev_syntax_col = -1; // column of prev_syntax_attr
335 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336 int has_syntax = FALSE; // this buffer has syntax highl.
337 int save_did_emsg;
338 int draw_color_col = FALSE; // highlight colorcolumn
339 int *color_cols = NULL; // pointer to according columns array
340#endif
341 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100342#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343 int text_prop_count;
344 int text_prop_next = 0; // next text property to use
345 textprop_T *text_props = NULL;
346 int *text_prop_idxs = NULL;
347 int text_props_active = 0;
348 proptype_T *text_prop_type = NULL;
349 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100350 int text_prop_id = 0; // active property ID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200351 int text_prop_combine = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100352 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353#endif
354#ifdef FEAT_SPELL
355 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000356 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200357# define SPWORDLEN 150
358 char_u nextline[SPWORDLEN * 2];// text with start of the next line
359 int nextlinecol = 0; // column where nextline[] starts
360 int nextline_idx = 0; // index in nextline[] where next line
361 // starts
362 int spell_attr = 0; // attributes desired by spelling
363 int word_end = 0; // last byte with same spell_attr
364 static linenr_T checked_lnum = 0; // line number for "checked_col"
365 static int checked_col = 0; // column in "checked_lnum" up to which
366 // there are no spell errors
367 static int cap_col = -1; // column to check for Cap word
368 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
369 int cur_checked_col = 0; // checked column for current line
370#endif
371 int extra_check = 0; // has extra highlighting
372 int multi_attr = 0; // attributes desired by multibyte
373 int mb_l = 1; // multi-byte byte length
374 int mb_c = 0; // decoded multi-byte character
375 int mb_utf8 = FALSE; // screen char is UTF-8 char
376 int u8cc[MAX_MCO]; // composing UTF-8 chars
377#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
378 int filler_lines = 0; // nr of filler lines to be drawn
379 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000380#else
381# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200382#endif
383#ifdef FEAT_DIFF
384 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
385 int change_start = MAXCOL; // first col of changed area
386 int change_end = -1; // last col of changed area
387#endif
388 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100389 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200390 int in_multispace = FALSE; // in multiple consecutive spaces
391 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200392#ifdef FEAT_LINEBREAK
393 int need_showbreak = FALSE; // overlong line, skipping first x
394 // chars
395#endif
396#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
397 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
398# define LINE_ATTR
399 int line_attr = 0; // attribute for the whole line
400 int line_attr_save;
401#endif
402#ifdef FEAT_SIGNS
403 int sign_present = FALSE;
404 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000405 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200406#endif
407#ifdef FEAT_ARABIC
408 int prev_c = 0; // previous Arabic character
409 int prev_c1 = 0; // first composing char for prev_c
410#endif
411#if defined(LINE_ATTR)
412 int did_line_attr = 0;
413#endif
414#ifdef FEAT_TERMINAL
415 int get_term_attr = FALSE;
416#endif
417#ifdef FEAT_SYN_HL
418 int cul_attr = 0; // set when 'cursorline' active
419
420 // 'cursorlineopt' has "screenline" and cursor is in this line
421 int cul_screenline = FALSE;
422
423 // margin columns for the screen line, needed for when 'cursorlineopt'
424 // contains "screenline"
425 int left_curline_col = 0;
426 int right_curline_col = 0;
427#endif
428
429 // draw_state: items that are drawn in sequence:
430#define WL_START 0 // nothing done yet
431#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000432# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200433#else
434# define WL_CMDLINE WL_START
435#endif
436#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000437# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200438#else
439# define WL_FOLD WL_CMDLINE
440#endif
441#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000442# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443#else
444# define WL_SIGN WL_FOLD // column for signs
445#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000446#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200447#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000448# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200449#else
450# define WL_BRI WL_NR
451#endif
452#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000453# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200454#else
455# define WL_SBR WL_BRI
456#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000457#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200458 int draw_state = WL_START; // what to draw next
459#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
460 int feedback_col = 0;
461 int feedback_old_attr = -1;
462#endif
463 int screen_line_flags = 0;
464
465#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
466 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000467 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200468#endif
469#ifdef FEAT_CONCEAL
470 int syntax_flags = 0;
471 int syntax_seqnr = 0;
472 int prev_syntax_id = 0;
473 int conceal_attr = HL_ATTR(HLF_CONCEAL);
474 int is_concealing = FALSE;
475 int boguscols = 0; // nonexistent columns added to force
476 // wrapping
477 int vcol_off = 0; // offset for concealed characters
478 int did_wcol = FALSE;
479 int old_boguscols = 0;
480# define VCOL_HLC (vcol - vcol_off)
481# define FIX_FOR_BOGUSCOLS \
482 { \
483 n_extra += vcol_off; \
484 vcol -= vcol_off; \
485 vcol_off = 0; \
486 col -= boguscols; \
487 old_boguscols = boguscols; \
488 boguscols = 0; \
489 }
490#else
491# define VCOL_HLC (vcol)
492#endif
493
494 if (startrow > endrow) // past the end already!
495 return startrow;
496
497 row = startrow;
498 screen_row = row + W_WINROW(wp);
499
500 if (!number_only)
501 {
502 // To speed up the loop below, set extra_check when there is linebreak,
503 // trailing white space and/or syntax processing to be done.
504#ifdef FEAT_LINEBREAK
505 extra_check = wp->w_p_lbr;
506#endif
507#ifdef FEAT_SYN_HL
508 if (syntax_present(wp) && !wp->w_s->b_syn_error
509# ifdef SYN_TIME_LIMIT
510 && !wp->w_s->b_syn_slow
511# endif
512 )
513 {
514 // Prepare for syntax highlighting in this line. When there is an
515 // error, stop syntax highlighting.
516 save_did_emsg = did_emsg;
517 did_emsg = FALSE;
518 syntax_start(wp, lnum);
519 if (did_emsg)
520 wp->w_s->b_syn_error = TRUE;
521 else
522 {
523 did_emsg = save_did_emsg;
524#ifdef SYN_TIME_LIMIT
525 if (!wp->w_s->b_syn_slow)
526#endif
527 {
528 has_syntax = TRUE;
529 extra_check = TRUE;
530 }
531 }
532 }
533
534 // Check for columns to display for 'colorcolumn'.
535 color_cols = wp->w_p_cc_cols;
536 if (color_cols != NULL)
537 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
538#endif
539
540#ifdef FEAT_TERMINAL
541 if (term_show_buffer(wp->w_buffer))
542 {
543 extra_check = TRUE;
544 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100545 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200546 }
547#endif
548
549#ifdef FEAT_SPELL
550 if (wp->w_p_spell
551 && *wp->w_s->b_p_spl != NUL
552 && wp->w_s->b_langp.ga_len > 0
553 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
554 {
555 // Prepare for spell checking.
556 has_spell = TRUE;
557 extra_check = TRUE;
558
559 // Get the start of the next line, so that words that wrap to the
560 // next line are found too: "et<line-break>al.".
561 // Trick: skip a few chars for C/shell/Vim comments
562 nextline[SPWORDLEN] = NUL;
563 if (lnum < wp->w_buffer->b_ml.ml_line_count)
564 {
565 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
566 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
567 }
568
569 // When a word wrapped from the previous line the start of the
570 // current line is valid.
571 if (lnum == checked_lnum)
572 cur_checked_col = checked_col;
573 checked_lnum = 0;
574
575 // When there was a sentence end in the previous line may require a
576 // word starting with capital in this line. In line 1 always check
577 // the first word.
578 if (lnum != capcol_lnum)
579 cap_col = -1;
580 if (lnum == 1)
581 cap_col = 0;
582 capcol_lnum = 0;
583 }
584#endif
585
586 // handle Visual active in this window
587 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
588 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100589 pos_T *top, *bot;
590
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200591 if (LTOREQ_POS(curwin->w_cursor, VIsual))
592 {
593 // Visual is after curwin->w_cursor
594 top = &curwin->w_cursor;
595 bot = &VIsual;
596 }
597 else
598 {
599 // Visual is before curwin->w_cursor
600 top = &VIsual;
601 bot = &curwin->w_cursor;
602 }
603 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
604 if (VIsual_mode == Ctrl_V)
605 {
606 // block mode
607 if (lnum_in_visual_area)
608 {
609 fromcol = wp->w_old_cursor_fcol;
610 tocol = wp->w_old_cursor_lcol;
611 }
612 }
613 else
614 {
615 // non-block mode
616 if (lnum > top->lnum && lnum <= bot->lnum)
617 fromcol = 0;
618 else if (lnum == top->lnum)
619 {
620 if (VIsual_mode == 'V') // linewise
621 fromcol = 0;
622 else
623 {
624 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
625 if (gchar_pos(top) == NUL)
626 tocol = fromcol + 1;
627 }
628 }
629 if (VIsual_mode != 'V' && lnum == bot->lnum)
630 {
631 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
632 {
633 fromcol = -10;
634 tocol = MAXCOL;
635 }
636 else if (bot->col == MAXCOL)
637 tocol = MAXCOL;
638 else
639 {
640 pos = *bot;
641 if (*p_sel == 'e')
642 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
643 else
644 {
645 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
646 ++tocol;
647 }
648 }
649 }
650 }
651
652 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200653 if (!highlight_match && lnum == curwin->w_cursor.lnum
654 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200655#ifdef FEAT_GUI
656 && !gui.in_use
657#endif
658 )
659 noinvcur = TRUE;
660
661 // if inverting in this line set area_highlighting
662 if (fromcol >= 0)
663 {
664 area_highlighting = TRUE;
665 vi_attr = HL_ATTR(HLF_V);
666#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
667 if ((clip_star.available && !clip_star.owned
668 && clip_isautosel_star())
669 || (clip_plus.available && !clip_plus.owned
670 && clip_isautosel_plus()))
671 vi_attr = HL_ATTR(HLF_VNC);
672#endif
673 }
674 }
675
676 // handle 'incsearch' and ":s///c" highlighting
677 else if (highlight_match
678 && wp == curwin
679 && lnum >= curwin->w_cursor.lnum
680 && lnum <= curwin->w_cursor.lnum + search_match_lines)
681 {
682 if (lnum == curwin->w_cursor.lnum)
683 getvcol(curwin, &(curwin->w_cursor),
684 (colnr_T *)&fromcol, NULL, NULL);
685 else
686 fromcol = 0;
687 if (lnum == curwin->w_cursor.lnum + search_match_lines)
688 {
689 pos.lnum = lnum;
690 pos.col = search_match_endcol;
691 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
692 }
693 else
694 tocol = MAXCOL;
695 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100696 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200697 tocol = fromcol + 1;
698 area_highlighting = TRUE;
699 vi_attr = HL_ATTR(HLF_I);
700 }
701 }
702
703#ifdef FEAT_DIFF
704 filler_lines = diff_check(wp, lnum);
705 if (filler_lines < 0)
706 {
707 if (filler_lines == -1)
708 {
709 if (diff_find_change(wp, lnum, &change_start, &change_end))
710 diff_hlf = HLF_ADD; // added line
711 else if (change_start == 0)
712 diff_hlf = HLF_TXD; // changed text
713 else
714 diff_hlf = HLF_CHD; // changed line
715 }
716 else
717 diff_hlf = HLF_ADD; // added line
718 filler_lines = 0;
719 area_highlighting = TRUE;
720 }
721 if (lnum == wp->w_topline)
722 filler_lines = wp->w_topfill;
723 filler_todo = filler_lines;
724#endif
725
726#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100727 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000728 if (sign_present)
729 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200730#endif
731
732#ifdef LINE_ATTR
733# ifdef FEAT_SIGNS
734 // If this line has a sign with line highlighting set line_attr.
735 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200736 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200737# endif
738# if defined(FEAT_QUICKFIX)
739 // Highlight the current line in the quickfix window.
740 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
741 line_attr = HL_ATTR(HLF_QFL);
742# endif
743 if (line_attr != 0)
744 area_highlighting = TRUE;
745#endif
746
747 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
748 ptr = line;
749
750#ifdef FEAT_SPELL
751 if (has_spell && !number_only)
752 {
753 // For checking first word with a capital skip white space.
754 if (cap_col == 0)
755 cap_col = getwhitecols(line);
756
757 // To be able to spell-check over line boundaries copy the end of the
758 // current line into nextline[]. Above the start of the next line was
759 // copied to nextline[SPWORDLEN].
760 if (nextline[SPWORDLEN] == NUL)
761 {
762 // No next line or it is empty.
763 nextlinecol = MAXCOL;
764 nextline_idx = 0;
765 }
766 else
767 {
768 v = (long)STRLEN(line);
769 if (v < SPWORDLEN)
770 {
771 // Short line, use it completely and append the start of the
772 // next line.
773 nextlinecol = 0;
774 mch_memmove(nextline, line, (size_t)v);
775 STRMOVE(nextline + v, nextline + SPWORDLEN);
776 nextline_idx = v + 1;
777 }
778 else
779 {
780 // Long line, use only the last SPWORDLEN bytes.
781 nextlinecol = v - SPWORDLEN;
782 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
783 nextline_idx = SPWORDLEN + 1;
784 }
785 }
786 }
787#endif
788
789 if (wp->w_p_list)
790 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100791 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200792 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100793 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100794 || wp->w_lcs_chars.trail
795 || wp->w_lcs_chars.lead
796 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200797 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100798
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200799 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100800 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200801 {
802 trailcol = (colnr_T)STRLEN(ptr);
803 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
804 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100805 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100807 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100808 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100809 {
810 leadcol = 0;
811 while (VIM_ISWHITE(ptr[leadcol]))
812 ++leadcol;
813 if (ptr[leadcol] == NUL)
814 // in a line full of spaces all of them are treated as trailing
815 leadcol = (colnr_T)0;
816 else
817 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100818 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100819 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200820 }
821
822 wcr_attr = get_wcr_attr(wp);
823 if (wcr_attr != 0)
824 {
825 win_attr = wcr_attr;
826 area_highlighting = TRUE;
827 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200828
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100829#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830 if (WIN_IS_POPUP(wp))
831 screen_line_flags |= SLF_POPUP;
832#endif
833
834 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
835 // first character to be displayed.
836 if (wp->w_p_wrap)
837 v = wp->w_skipcol;
838 else
839 v = wp->w_leftcol;
840 if (v > 0 && !number_only)
841 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100842 char_u *prev_ptr = ptr;
843 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +0100844 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200845
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100846 init_chartabsize_arg(&cts, wp, lnum, vcol, line, ptr);
847 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200848 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100849 charsize = win_lbr_chartabsize(&cts, NULL);
850 cts.cts_vcol += charsize;
851 prev_ptr = cts.cts_ptr;
852 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200853 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100854 vcol = cts.cts_vcol;
855 ptr = cts.cts_ptr;
856 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200857
858 // When:
859 // - 'cuc' is set, or
860 // - 'colorcolumn' is set, or
861 // - 'virtualedit' is set, or
862 // - the visual mode is active,
863 // the end of the line may be before the start of the displayed part.
864 if (vcol < v && (
865#ifdef FEAT_SYN_HL
866 wp->w_p_cuc || draw_color_col ||
867#endif
868 virtual_active() ||
869 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
870 vcol = v;
871
872 // Handle a character that's not completely on the screen: Put ptr at
873 // that character but skip the first few screen characters.
874 if (vcol > v)
875 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100876 vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200877 ptr = prev_ptr;
878 // If the character fits on the screen, don't need to skip it.
879 // Except for a TAB.
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100880 if (( (*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB) && col == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200881 n_skip = v - vcol;
882 }
883
884 // Adjust for when the inverted text is before the screen,
885 // and when the start of the inverted text is before the screen.
886 if (tocol <= vcol)
887 fromcol = 0;
888 else if (fromcol >= 0 && fromcol < vcol)
889 fromcol = vcol;
890
891#ifdef FEAT_LINEBREAK
892 // When w_skipcol is non-zero, first line needs 'showbreak'
893 if (wp->w_p_wrap)
894 need_showbreak = TRUE;
895#endif
896#ifdef FEAT_SPELL
897 // When spell checking a word we need to figure out the start of the
898 // word and if it's badly spelled or not.
899 if (has_spell)
900 {
901 int len;
902 colnr_T linecol = (colnr_T)(ptr - line);
903 hlf_T spell_hlf = HLF_COUNT;
904
905 pos = wp->w_cursor;
906 wp->w_cursor.lnum = lnum;
907 wp->w_cursor.col = linecol;
908 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
909
910 // spell_move_to() may call ml_get() and make "line" invalid
911 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
912 ptr = line + linecol;
913
914 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
915 {
916 // no bad word found at line start, don't check until end of a
917 // word
918 spell_hlf = HLF_COUNT;
919 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
920 }
921 else
922 {
923 // bad word found, use attributes until end of word
924 word_end = wp->w_cursor.col + len + 1;
925
926 // Turn index into actual attributes.
927 if (spell_hlf != HLF_COUNT)
928 spell_attr = highlight_attr[spell_hlf];
929 }
930 wp->w_cursor = pos;
931
932# ifdef FEAT_SYN_HL
933 // Need to restart syntax highlighting for this line.
934 if (has_syntax)
935 syntax_start(wp, lnum);
936# endif
937 }
938#endif
939 }
940
941 // Correct highlighting for cursor that can't be disabled.
942 // Avoids having to check this for each character.
943 if (fromcol >= 0)
944 {
945 if (noinvcur)
946 {
947 if ((colnr_T)fromcol == wp->w_virtcol)
948 {
949 // highlighting starts at cursor, let it start just after the
950 // cursor
951 fromcol_prev = fromcol;
952 fromcol = -1;
953 }
954 else if ((colnr_T)fromcol < wp->w_virtcol)
955 // restart highlighting after the cursor
956 fromcol_prev = wp->w_virtcol;
957 }
958 if (fromcol >= tocol)
959 fromcol = -1;
960 }
961
962#ifdef FEAT_SEARCH_EXTRA
963 if (!number_only)
964 {
965 v = (long)(ptr - line);
966 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
967 &line, &screen_search_hl,
968 &search_attr);
969 ptr = line + v; // "line" may have been updated
970 }
971#endif
972
973#ifdef FEAT_SYN_HL
974 // Cursor line highlighting for 'cursorline' in the current window.
975 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
976 {
977 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +0000978 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200979 if (!(wp == curwin && VIsual_active)
980 && wp->w_p_culopt_flags != CULOPT_NBR)
981 {
982 cul_screenline = (wp->w_p_wrap
983 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
984
985 // Only set line_attr here when "screenline" is not present in
986 // 'cursorlineopt'. Otherwise it's done later.
987 if (!cul_screenline)
988 {
989 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200990# ifdef FEAT_SIGNS
991 // Combine the 'cursorline' and sign highlighting, depending on
992 // the sign priority.
993 if (sign_present && sattr.sat_linehl > 0)
994 {
995 if (sattr.sat_priority >= 100)
996 line_attr = hl_combine_attr(cul_attr, line_attr);
997 else
998 line_attr = hl_combine_attr(line_attr, cul_attr);
999 }
1000 else
1001# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001002# if defined(FEAT_QUICKFIX)
1003 line_attr = hl_combine_attr(line_attr, cul_attr);
1004# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +02001005 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +01001006# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001007 }
1008 else
1009 {
1010 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001011 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1012 }
1013 area_highlighting = TRUE;
1014 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001015 }
1016#endif
1017
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001018#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001019 {
1020 char_u *prop_start;
1021
1022 text_prop_count = get_text_props(wp->w_buffer, lnum,
1023 &prop_start, FALSE);
1024 if (text_prop_count > 0)
1025 {
1026 // Make a copy of the properties, so that they are properly
1027 // aligned.
1028 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1029 if (text_props != NULL)
1030 mch_memmove(text_props, prop_start,
1031 text_prop_count * sizeof(textprop_T));
1032
1033 // Allocate an array for the indexes.
1034 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1035 area_highlighting = TRUE;
1036 extra_check = TRUE;
1037 }
1038 }
1039#endif
1040
1041 off = (unsigned)(current_ScreenLine - ScreenLines);
1042 col = 0;
1043
1044#ifdef FEAT_RIGHTLEFT
1045 if (wp->w_p_rl)
1046 {
1047 // Rightleft window: process the text in the normal direction, but put
1048 // it in current_ScreenLine[] from right to left. Start at the
1049 // rightmost column of the window.
1050 col = wp->w_width - 1;
1051 off += col;
1052 screen_line_flags |= SLF_RIGHTLEFT;
1053 }
1054#endif
1055
1056 // Repeat for the whole displayed line.
1057 for (;;)
1058 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001059 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001061 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001062#endif
1063#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001064 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001065#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001066
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001067 // Skip this quickly when working on the text.
1068 if (draw_state != WL_LINE)
1069 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001070#ifdef FEAT_SYN_HL
1071 if (cul_screenline)
1072 {
1073 cul_attr = 0;
1074 line_attr = line_attr_save;
1075 }
1076#endif
1077
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078#ifdef FEAT_CMDWIN
1079 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1080 {
1081 draw_state = WL_CMDLINE;
1082 if (cmdwin_type != 0 && wp == curwin)
1083 {
1084 // Draw the cmdline character.
1085 n_extra = 1;
1086 c_extra = cmdwin_type;
1087 c_final = NUL;
1088 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1089 }
1090 }
1091#endif
1092
1093#ifdef FEAT_FOLDING
1094 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1095 {
1096 int fdc = compute_foldcolumn(wp, 0);
1097
1098 draw_state = WL_FOLD;
1099 if (fdc > 0)
1100 {
1101 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1102 // already be in use.
1103 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001104 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001105 if (p_extra_free != NULL)
1106 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001107 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001108 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001109 p_extra_free[n_extra] = NUL;
1110 p_extra = p_extra_free;
1111 c_extra = NUL;
1112 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001113 if (use_cursor_line_sign(wp, lnum))
1114 char_attr =
1115 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1116 else
1117 char_attr =
1118 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001119 }
1120 }
1121 }
1122#endif
1123
1124#ifdef FEAT_SIGNS
1125 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1126 {
1127 draw_state = WL_SIGN;
1128 // Show the sign column when there are any signs in this
1129 // buffer or when using Netbeans.
1130 if (signcolumn_on(wp))
1131 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1132 row, startrow, filler_lines, filler_todo, &c_extra,
1133 &c_final, extra, &p_extra, &n_extra, &char_attr);
1134 }
1135#endif
1136
1137 if (draw_state == WL_NR - 1 && n_extra == 0)
1138 {
1139 draw_state = WL_NR;
1140 // Display the absolute or relative line number. After the
1141 // first fill with blanks when the 'n' flag isn't in 'cpo'
1142 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001143 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001144 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1145 {
1146#ifdef FEAT_SIGNS
1147 // If 'signcolumn' is set to 'number' and a sign is present
1148 // in 'lnum', then display the sign instead of the line
1149 // number.
1150 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1151 && sign_present)
1152 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1153 row, startrow, filler_lines, filler_todo,
1154 &c_extra, &c_final, extra, &p_extra, &n_extra,
1155 &char_attr);
1156 else
1157#endif
1158 {
1159 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001160 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 {
1162 long num;
1163 char *fmt = "%*ld ";
1164
1165 if (wp->w_p_nu && !wp->w_p_rnu)
1166 // 'number' + 'norelativenumber'
1167 num = (long)lnum;
1168 else
1169 {
1170 // 'relativenumber', don't use negative numbers
1171 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1172 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1173 {
1174 // 'number' + 'relativenumber'
1175 num = lnum;
1176 fmt = "%-*ld ";
1177 }
1178 }
1179
1180 sprintf((char *)extra, fmt,
1181 number_width(wp), num);
1182 if (wp->w_skipcol > 0)
1183 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1184 *p_extra = '-';
1185#ifdef FEAT_RIGHTLEFT
1186 if (wp->w_p_rl) // reverse line numbers
1187 {
1188 char_u *p1, *p2;
1189 int t;
1190
1191 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001192 p2 = skipwhite(extra);
1193 p2 = skiptowhite(p2) - 1;
1194 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 {
1196 t = *p1;
1197 *p1 = *p2;
1198 *p2 = t;
1199 }
1200 }
1201#endif
1202 p_extra = extra;
1203 c_extra = NUL;
1204 c_final = NUL;
1205 }
1206 else
1207 {
1208 c_extra = ' ';
1209 c_final = NUL;
1210 }
1211 n_extra = number_width(wp) + 1;
1212 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1213#ifdef FEAT_SYN_HL
1214 // When 'cursorline' is set highlight the line number of
1215 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001216 // When 'cursorlineopt' does not have "line" only
1217 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 // TODO: Can we use CursorLine instead of CursorLineNr
1219 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001220 if (wp->w_p_cul
1221 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001223 && (row == startrow + filler_lines
1224 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001225 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001226 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1227#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001228 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1229 && HL_ATTR(HLF_LNA) != 0)
1230 // Use LineNrAbove
1231 char_attr = hl_combine_attr(wcr_attr,
1232 HL_ATTR(HLF_LNA));
1233 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1234 && HL_ATTR(HLF_LNB) != 0)
1235 // Use LineNrBelow
1236 char_attr = hl_combine_attr(wcr_attr,
1237 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001238 }
James McCoya80aad72021-12-22 19:45:28 +00001239#ifdef FEAT_SIGNS
1240 if (num_attr)
1241 char_attr = num_attr;
1242#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 }
1244 }
1245
1246#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001247 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001248 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001249 // draw indent after showbreak value
1250 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001251 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 // After the showbreak, draw the breakindent
1253 draw_state = WL_BRI - 1;
1254
1255 // draw 'breakindent': indent wrapped text accordingly
1256 if (draw_state == WL_BRI - 1 && n_extra == 0)
1257 {
1258 draw_state = WL_BRI;
1259 // if need_showbreak is set, breakindent also applies
Bram Moolenaarfe154992022-03-22 20:42:12 +00001260 if (wp->w_p_bri && (row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001261# ifdef FEAT_DIFF
1262 && filler_lines == 0
1263# endif
1264 )
1265 {
1266 char_attr = 0;
1267# ifdef FEAT_DIFF
1268 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001269 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270# endif
1271 p_extra = NULL;
1272 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001273 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274 n_extra = get_breakindent_win(wp,
1275 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001276 if (row == startrow)
1277 {
1278 n_extra -= win_col_off2(wp);
1279 if (n_extra < 0)
1280 n_extra = 0;
1281 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001282 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001283 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001284 // Correct end of highlighted area for 'breakindent',
1285 // required when 'linebreak' is also set.
1286 if (tocol == vcol)
1287 tocol += n_extra;
1288 }
1289 }
1290#endif
1291
1292#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1293 if (draw_state == WL_SBR - 1 && n_extra == 0)
1294 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001295 char_u *sbr;
1296
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 draw_state = WL_SBR;
1298# ifdef FEAT_DIFF
1299 if (filler_todo > 0)
1300 {
1301 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001302 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 {
1304 c_extra = '-';
1305 c_final = NUL;
1306 }
1307 else
1308 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001309 c_extra = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001310 c_final = NUL;
1311 }
1312# ifdef FEAT_RIGHTLEFT
1313 if (wp->w_p_rl)
1314 n_extra = col + 1;
1315 else
1316# endif
1317 n_extra = wp->w_width - col;
1318 char_attr = HL_ATTR(HLF_DED);
1319 }
1320# endif
1321# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001322 sbr = get_showbreak_value(wp);
1323 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001326 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001327 c_extra = NUL;
1328 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001329 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001330 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1331 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001332 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001333 // Correct end of highlighted area for 'showbreak',
1334 // required when 'linebreak' is also set.
1335 if (tocol == vcol)
1336 tocol += n_extra;
1337 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001338 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339# ifdef FEAT_SYN_HL
1340 // combine 'showbreak' with 'cursorline'
1341 if (cul_attr != 0)
1342 char_attr = hl_combine_attr(char_attr, cul_attr);
1343# endif
1344 }
1345# endif
1346 }
1347#endif
1348
1349 if (draw_state == WL_LINE - 1 && n_extra == 0)
1350 {
1351 draw_state = WL_LINE;
1352 if (saved_n_extra)
1353 {
1354 // Continue item from end of wrapped line.
1355 n_extra = saved_n_extra;
1356 c_extra = saved_c_extra;
1357 c_final = saved_c_final;
1358 p_extra = saved_p_extra;
1359 char_attr = saved_char_attr;
1360 }
1361 else
1362 char_attr = win_attr;
1363 }
1364 }
1365#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001366 if (cul_screenline && draw_state == WL_LINE
1367 && vcol >= left_curline_col
1368 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001370 cul_attr = HL_ATTR(HLF_CUL);
1371 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 }
1373#endif
1374
1375 // When still displaying '$' of change command, stop at cursor.
1376 // When only displaying the (relative) line number and that's done,
1377 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001378 if (((dollar_vcol >= 0 && wp == curwin
1379 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1380 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001381#ifdef FEAT_DIFF
1382 && filler_todo <= 0
1383#endif
1384 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001385 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001386 screen_line(wp, screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 screen_line_flags);
1388 // Pretend we have finished updating the window. Except when
1389 // 'cursorcolumn' is set.
1390#ifdef FEAT_SYN_HL
1391 if (wp->w_p_cuc)
1392 row = wp->w_cline_row + wp->w_cline_height;
1393 else
1394#endif
1395 row = wp->w_height;
1396 break;
1397 }
1398
Bram Moolenaar34390282019-10-16 14:38:26 +02001399 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 {
1401 // handle Visual or match highlighting in this line
1402 if (vcol == fromcol
1403 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1404 && (*mb_ptr2cells)(ptr) > 1)
1405 || ((int)vcol_prev == fromcol_prev
1406 && vcol_prev < vcol // not at margin
1407 && vcol < tocol))
1408 area_attr = vi_attr; // start highlighting
1409 else if (area_attr != 0
1410 && (vcol == tocol
1411 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1412 area_attr = 0; // stop highlighting
1413
1414#ifdef FEAT_SEARCH_EXTRA
1415 if (!n_extra)
1416 {
1417 // Check for start/end of 'hlsearch' and other matches.
1418 // After end, check for start/end of next match.
1419 // When another match, have to check for start again.
1420 v = (long)(ptr - line);
1421 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1422 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001423 &match_conc, did_line_attr, lcs_eol_one,
1424 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001425 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001426 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001427
1428 // Do not allow a conceal over EOL otherwise EOL will be missed
1429 // and bad things happen.
1430 if (*ptr == NUL)
1431 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001432 }
1433#endif
1434
1435#ifdef FEAT_DIFF
1436 if (diff_hlf != (hlf_T)0)
1437 {
1438 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1439 && n_extra == 0)
1440 diff_hlf = HLF_TXD; // changed text
1441 if (diff_hlf == HLF_TXD && ptr - line > change_end
1442 && n_extra == 0)
1443 diff_hlf = HLF_CHD; // changed line
1444 line_attr = HL_ATTR(diff_hlf);
1445 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1446 && wp->w_p_culopt_flags != CULOPT_NBR
1447 && (!cul_screenline || (vcol >= left_curline_col
1448 && vcol <= right_curline_col)))
1449 line_attr = hl_combine_attr(
1450 line_attr, HL_ATTR(HLF_CUL));
1451 }
1452#endif
1453
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001454#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 if (text_props != NULL)
1456 {
1457 int pi;
1458 int bcol = (int)(ptr - line);
1459
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001460 if (n_extra > 0
1461# ifdef FEAT_LINEBREAK
1462 && !in_linebreak
1463# endif
1464 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 --bcol; // still working on the previous char, e.g. Tab
1466
1467 // Check if any active property ends.
1468 for (pi = 0; pi < text_props_active; ++pi)
1469 {
1470 int tpi = text_prop_idxs[pi];
1471
1472 if (bcol >= text_props[tpi].tp_col - 1
1473 + text_props[tpi].tp_len)
1474 {
1475 if (pi + 1 < text_props_active)
1476 mch_memmove(text_prop_idxs + pi,
1477 text_prop_idxs + pi + 1,
1478 sizeof(int)
1479 * (text_props_active - (pi + 1)));
1480 --text_props_active;
1481 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001482# ifdef FEAT_LINEBREAK
1483 // not exactly right but should work in most cases
1484 if (in_linebreak && syntax_attr == text_prop_attr)
1485 syntax_attr = 0;
1486# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 }
1488 }
1489
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001490# ifdef FEAT_LINEBREAK
1491 if (n_extra > 0 && in_linebreak)
1492 // not on the next char yet, don't start another prop
1493 --bcol;
1494# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001495 // Add any text property that starts in this column.
1496 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001497 && (text_props[text_prop_next].tp_col == MAXCOL
1498 ? *ptr == NUL
1499 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001500 {
1501 if (bcol <= text_props[text_prop_next].tp_col - 1
1502 + text_props[text_prop_next].tp_len)
1503 text_prop_idxs[text_props_active++] = text_prop_next;
1504 ++text_prop_next;
1505 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506
1507 text_prop_attr = 0;
1508 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001509 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001510 text_prop_id = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001511 if (text_props_active > 0 && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001513 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001514 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001515 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001516
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 // Sort the properties on priority and/or starting last.
1518 // Then combine the attributes, highest priority last.
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001519 text_prop_follows = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001520 current_text_props = text_props;
1521 current_buf = wp->w_buffer;
1522 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1523 sizeof(int), text_prop_compare);
1524
1525 for (pi = 0; pi < text_props_active; ++pi)
1526 {
1527 int tpi = text_prop_idxs[pi];
1528 proptype_T *pt = text_prop_type_by_id(
1529 wp->w_buffer, text_props[tpi].tp_type);
1530
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001531 if (pt != NULL && pt->pt_hl_id > 0
1532 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001534 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001535 text_prop_type = pt;
1536 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001537 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001539 text_prop_id = text_props[tpi].tp_id;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001540 other_tpi = used_tpi;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001541 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001542 }
1543 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001544 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001545 && -text_prop_id
1546 <= wp->w_buffer->b_textprop_text.ga_len)
1547 {
1548 char_u *p = ((char_u **)wp->w_buffer
1549 ->b_textprop_text.ga_data)[
1550 -text_prop_id - 1];
1551 if (p != NULL)
1552 {
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001553 int right = (text_props[used_tpi].tp_flags
1554 & TP_FLAG_ALIGN_RIGHT);
1555 int below = (text_props[used_tpi].tp_flags
1556 & TP_FLAG_ALIGN_BELOW);
1557
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001558 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001559 c_extra = NUL;
1560 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001561 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001562 extra_attr = used_attr;
1563 n_attr = n_extra;
1564 text_prop_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001565 if (*ptr == NUL)
1566 // don't combine char attr after EOL
1567 text_prop_combine = FALSE;
1568
1569 // TODO: truncation if it doesn't fit
1570 if (right || below)
1571 {
1572 int added = wp->w_width - col;
1573 char_u *l;
1574
1575 // Right-align: fill with spaces
1576 // TODO: count screen columns
1577 if (right)
1578 added -= n_extra;
1579 if (added < 0 || (below && col == 0))
1580 added = 0;
1581 l = alloc(n_extra + added + 1);
1582 if (l != NULL)
1583 {
1584 vim_memset(l, ' ', added);
1585 STRCPY(l + added, p);
1586 vim_free(p_extra_free);
1587 p_extra = p_extra_free = l;
1588 n_extra += added;
1589 n_attr_skip = added;
1590 }
1591 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001592 }
1593 // reset the ID in the copy to avoid it being used
1594 // again
1595 text_props[used_tpi].tp_id = -MAXCOL;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001596
1597 // If another text prop follows the condition below at
1598 // the last window column must know.
1599 text_prop_follows = other_tpi != -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001600 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001601 }
1602 }
1603#endif
1604
Bram Moolenaara74fda62019-10-19 17:38:03 +02001605#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001606 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001607 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001608 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001609# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001610 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001611 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001612# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001613 // Get syntax attribute.
1614 if (has_syntax)
1615 {
1616 // Get the syntax attribute for the character. If there
1617 // is an error, disable syntax highlighting.
1618 save_did_emsg = did_emsg;
1619 did_emsg = FALSE;
1620
1621 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001622 if (v == prev_syntax_col)
1623 // at same column again
1624 syntax_attr = prev_syntax_attr;
1625 else
1626 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001627# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001628 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001629# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001630 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001631# ifdef FEAT_SPELL
1632 has_spell ? &can_spell :
1633# endif
1634 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001635 prev_syntax_col = v;
1636 prev_syntax_attr = syntax_attr;
1637 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001638
Bram Moolenaar34390282019-10-16 14:38:26 +02001639 if (did_emsg)
1640 {
1641 wp->w_s->b_syn_error = TRUE;
1642 has_syntax = FALSE;
1643 syntax_attr = 0;
1644 }
1645 else
1646 did_emsg = save_did_emsg;
1647# ifdef SYN_TIME_LIMIT
1648 if (wp->w_s->b_syn_slow)
1649 has_syntax = FALSE;
1650# endif
1651
1652 // Need to get the line again, a multi-line regexp may
1653 // have made it invalid.
1654 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1655 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001656 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001657# ifdef FEAT_CONCEAL
1658 // no concealing past the end of the line, it interferes
1659 // with line highlighting
1660 if (*ptr == NUL)
1661 syntax_flags = 0;
1662 else
1663 syntax_flags = get_syntax_info(&syntax_seqnr);
1664# endif
1665 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001666 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001667# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001668 // Combine text property highlight into syntax highlight.
1669 if (text_prop_type != NULL)
1670 {
1671 if (text_prop_combine)
1672 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1673 else
1674 syntax_attr = text_prop_attr;
1675 }
1676# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001677#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001678
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001679 // Decide which of the highlight attributes to use.
1680 attr_pri = TRUE;
1681#ifdef LINE_ATTR
1682 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001683 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001684 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001685 if (!highlight_match)
1686 // let search highlight show in Visual area if possible
1687 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001688# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001689 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001690# endif
1691 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001693 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001695# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001696 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001697# endif
1698 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001699 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1700 || vcol < fromcol || vcol_prev < fromcol_prev
1701 || vcol >= tocol))
1702 {
1703 // Use line_attr when not in the Visual or 'incsearch' area
1704 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001705# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001706 char_attr = hl_combine_attr(syntax_attr, line_attr);
1707# else
1708 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001709# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001710 attr_pri = FALSE;
1711 }
1712#else
1713 if (area_attr != 0)
1714 char_attr = area_attr;
1715 else if (search_attr != 0)
1716 char_attr = search_attr;
1717#endif
1718 else
1719 {
1720 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001721#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001722 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001723#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001724 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001725#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001726 }
1727 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001728
1729 // combine attribute with 'wincolor'
1730 if (win_attr != 0)
1731 {
1732 if (char_attr == 0)
1733 char_attr = win_attr;
1734 else
1735 char_attr = hl_combine_attr(win_attr, char_attr);
1736 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737
1738 // Get the next character to put on the screen.
1739
1740 // The "p_extra" points to the extra stuff that is inserted to
1741 // represent special characters (non-printable stuff) and other
1742 // things. When all characters are the same, c_extra is used.
1743 // If c_final is set, it will compulsorily be used at the end.
1744 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1745 // "p_extra[n_extra]".
1746 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1747 if (n_extra > 0)
1748 {
1749 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1750 {
1751 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1752 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1753 if (enc_utf8 && utf_char2len(c) > 1)
1754 {
1755 mb_utf8 = TRUE;
1756 u8cc[0] = 0;
1757 c = 0xc0;
1758 }
1759 else
1760 mb_utf8 = FALSE;
1761 }
1762 else
1763 {
1764 c = *p_extra;
1765 if (has_mbyte)
1766 {
1767 mb_c = c;
1768 if (enc_utf8)
1769 {
1770 // If the UTF-8 character is more than one byte:
1771 // Decode it into "mb_c".
1772 mb_l = utfc_ptr2len(p_extra);
1773 mb_utf8 = FALSE;
1774 if (mb_l > n_extra)
1775 mb_l = 1;
1776 else if (mb_l > 1)
1777 {
1778 mb_c = utfc_ptr2char(p_extra, u8cc);
1779 mb_utf8 = TRUE;
1780 c = 0xc0;
1781 }
1782 }
1783 else
1784 {
1785 // if this is a DBCS character, put it in "mb_c"
1786 mb_l = MB_BYTE2LEN(c);
1787 if (mb_l >= n_extra)
1788 mb_l = 1;
1789 else if (mb_l > 1)
1790 mb_c = (c << 8) + p_extra[1];
1791 }
1792 if (mb_l == 0) // at the NUL at end-of-line
1793 mb_l = 1;
1794
1795 // If a double-width char doesn't fit display a '>' in the
1796 // last column.
1797 if ((
1798# ifdef FEAT_RIGHTLEFT
1799 wp->w_p_rl ? (col <= 0) :
1800# endif
1801 (col >= wp->w_width - 1))
1802 && (*mb_char2cells)(mb_c) == 2)
1803 {
1804 c = '>';
1805 mb_c = c;
1806 mb_l = 1;
1807 mb_utf8 = FALSE;
1808 multi_attr = HL_ATTR(HLF_AT);
1809#ifdef FEAT_SYN_HL
1810 if (cul_attr)
1811 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1812#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001813 multi_attr = hl_combine_attr(win_attr, multi_attr);
1814
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001815 // put the pointer back to output the double-width
1816 // character at the start of the next line.
1817 ++n_extra;
1818 --p_extra;
1819 }
1820 else
1821 {
1822 n_extra -= mb_l - 1;
1823 p_extra += mb_l - 1;
1824 }
1825 }
1826 ++p_extra;
1827 }
1828 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001829#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001830 if (n_extra <= 0)
1831 in_linebreak = FALSE;
1832#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001833 }
1834 else
1835 {
1836#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001837 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001839 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001840 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001841
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001842 // Get a character from the line itself.
1843 c = *ptr;
1844#ifdef FEAT_LINEBREAK
1845 c0 = *ptr;
1846#endif
1847 if (has_mbyte)
1848 {
1849 mb_c = c;
1850 if (enc_utf8)
1851 {
1852 // If the UTF-8 character is more than one byte: Decode it
1853 // into "mb_c".
1854 mb_l = utfc_ptr2len(ptr);
1855 mb_utf8 = FALSE;
1856 if (mb_l > 1)
1857 {
1858 mb_c = utfc_ptr2char(ptr, u8cc);
1859 // Overlong encoded ASCII or ASCII with composing char
1860 // is displayed normally, except a NUL.
1861 if (mb_c < 0x80)
1862 {
1863 c = mb_c;
1864#ifdef FEAT_LINEBREAK
1865 c0 = mb_c;
1866#endif
1867 }
1868 mb_utf8 = TRUE;
1869
1870 // At start of the line we can have a composing char.
1871 // Draw it as a space with a composing char.
1872 if (utf_iscomposing(mb_c))
1873 {
1874 int i;
1875
1876 for (i = Screen_mco - 1; i > 0; --i)
1877 u8cc[i] = u8cc[i - 1];
1878 u8cc[0] = mb_c;
1879 mb_c = ' ';
1880 }
1881 }
1882
1883 if ((mb_l == 1 && c >= 0x80)
1884 || (mb_l >= 1 && mb_c == 0)
1885 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1886 {
1887 // Illegal UTF-8 byte: display as <xx>.
1888 // Non-BMP character : display as ? or fullwidth ?.
1889 transchar_hex(extra, mb_c);
1890# ifdef FEAT_RIGHTLEFT
1891 if (wp->w_p_rl) // reverse
1892 rl_mirror(extra);
1893# endif
1894 p_extra = extra;
1895 c = *p_extra;
1896 mb_c = mb_ptr2char_adv(&p_extra);
1897 mb_utf8 = (c >= 0x80);
1898 n_extra = (int)STRLEN(p_extra);
1899 c_extra = NUL;
1900 c_final = NUL;
1901 if (area_attr == 0 && search_attr == 0)
1902 {
1903 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001904 extra_attr = hl_combine_attr(
1905 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001906 saved_attr2 = char_attr; // save current attr
1907 }
1908 }
1909 else if (mb_l == 0) // at the NUL at end-of-line
1910 mb_l = 1;
1911#ifdef FEAT_ARABIC
1912 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1913 {
1914 // Do Arabic shaping.
1915 int pc, pc1, nc;
1916 int pcc[MAX_MCO];
1917
1918 // The idea of what is the previous and next
1919 // character depends on 'rightleft'.
1920 if (wp->w_p_rl)
1921 {
1922 pc = prev_c;
1923 pc1 = prev_c1;
1924 nc = utf_ptr2char(ptr + mb_l);
1925 prev_c1 = u8cc[0];
1926 }
1927 else
1928 {
1929 pc = utfc_ptr2char(ptr + mb_l, pcc);
1930 nc = prev_c;
1931 pc1 = pcc[0];
1932 }
1933 prev_c = mb_c;
1934
1935 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1936 }
1937 else
1938 prev_c = mb_c;
1939#endif
1940 }
1941 else // enc_dbcs
1942 {
1943 mb_l = MB_BYTE2LEN(c);
1944 if (mb_l == 0) // at the NUL at end-of-line
1945 mb_l = 1;
1946 else if (mb_l > 1)
1947 {
1948 // We assume a second byte below 32 is illegal.
1949 // Hopefully this is OK for all double-byte encodings!
1950 if (ptr[1] >= 32)
1951 mb_c = (c << 8) + ptr[1];
1952 else
1953 {
1954 if (ptr[1] == NUL)
1955 {
1956 // head byte at end of line
1957 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001958 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001959 }
1960 else
1961 {
1962 // illegal tail byte
1963 mb_l = 2;
1964 STRCPY(extra, "XX");
1965 }
1966 p_extra = extra;
1967 n_extra = (int)STRLEN(extra) - 1;
1968 c_extra = NUL;
1969 c_final = NUL;
1970 c = *p_extra++;
1971 if (area_attr == 0 && search_attr == 0)
1972 {
1973 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001974 extra_attr = hl_combine_attr(
1975 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001976 saved_attr2 = char_attr; // save current attr
1977 }
1978 mb_c = c;
1979 }
1980 }
1981 }
1982 // If a double-width char doesn't fit display a '>' in the
1983 // last column; the character is displayed at the start of the
1984 // next line.
1985 if ((
1986# ifdef FEAT_RIGHTLEFT
1987 wp->w_p_rl ? (col <= 0) :
1988# endif
1989 (col >= wp->w_width - 1))
1990 && (*mb_char2cells)(mb_c) == 2)
1991 {
1992 c = '>';
1993 mb_c = c;
1994 mb_utf8 = FALSE;
1995 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001996 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 // Put pointer back so that the character will be
1998 // displayed at the start of the next line.
1999 --ptr;
2000#ifdef FEAT_CONCEAL
2001 did_decrement_ptr = TRUE;
2002#endif
2003 }
2004 else if (*ptr != NUL)
2005 ptr += mb_l - 1;
2006
2007 // If a double-width char doesn't fit at the left side display
2008 // a '<' in the first column. Don't do this for unprintable
2009 // characters.
2010 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
2011 {
2012 n_extra = 1;
2013 c_extra = MB_FILLER_CHAR;
2014 c_final = NUL;
2015 c = ' ';
2016 if (area_attr == 0 && search_attr == 0)
2017 {
2018 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002019 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002020 saved_attr2 = char_attr; // save current attr
2021 }
2022 mb_c = c;
2023 mb_utf8 = FALSE;
2024 mb_l = 1;
2025 }
2026
2027 }
2028 ++ptr;
2029
2030 if (extra_check)
2031 {
2032#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 // Check spelling (unless at the end of the line).
2034 // Only do this when there is no syntax highlighting, the
2035 // @Spell cluster is not used or the current syntax item
2036 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002037 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002038 if (has_spell && v >= word_end && v > cur_checked_col)
2039 {
2040 spell_attr = 0;
2041 if (c != 0 && (
2042# ifdef FEAT_SYN_HL
2043 !has_syntax ||
2044# endif
2045 can_spell))
2046 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002047 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 int len;
2049 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002050
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002053
2054 // Use nextline[] if possible, it has the start of the
2055 // next line concatenated.
2056 if ((prev_ptr - line) - nextlinecol >= 0)
2057 p = nextline + (prev_ptr - line) - nextlinecol;
2058 else
2059 p = prev_ptr;
2060 cap_col -= (int)(prev_ptr - line);
2061 len = spell_check(wp, p, &spell_hlf, &cap_col,
2062 nochange);
2063 word_end = v + len;
2064
2065 // In Insert mode only highlight a word that
2066 // doesn't touch the cursor.
2067 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002068 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 && wp->w_cursor.lnum == lnum
2070 && wp->w_cursor.col >=
2071 (colnr_T)(prev_ptr - line)
2072 && wp->w_cursor.col < (colnr_T)word_end)
2073 {
2074 spell_hlf = HLF_COUNT;
2075 spell_redraw_lnum = lnum;
2076 }
2077
2078 if (spell_hlf == HLF_COUNT && p != prev_ptr
2079 && (p - nextline) + len > nextline_idx)
2080 {
2081 // Remember that the good word continues at the
2082 // start of the next line.
2083 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002084 checked_col = (int)((p - nextline)
2085 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002086 }
2087
2088 // Turn index into actual attributes.
2089 if (spell_hlf != HLF_COUNT)
2090 spell_attr = highlight_attr[spell_hlf];
2091
2092 if (cap_col > 0)
2093 {
2094 if (p != prev_ptr
2095 && (p - nextline) + cap_col >= nextline_idx)
2096 {
2097 // Remember that the word in the next line
2098 // must start with a capital.
2099 capcol_lnum = lnum + 1;
2100 cap_col = (int)((p - nextline) + cap_col
2101 - nextline_idx);
2102 }
2103 else
2104 // Compute the actual column.
2105 cap_col += (int)(prev_ptr - line);
2106 }
2107 }
2108 }
2109 if (spell_attr != 0)
2110 {
2111 if (!attr_pri)
2112 char_attr = hl_combine_attr(char_attr, spell_attr);
2113 else
2114 char_attr = hl_combine_attr(spell_attr, char_attr);
2115 }
2116#endif
2117#ifdef FEAT_LINEBREAK
2118 // Found last space before word: check for line break.
2119 if (wp->w_p_lbr && c0 == c
2120 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2121 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002122 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2123 : 0;
2124 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002125 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002127 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2128 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002129
2130 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002131 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002132 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002133 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002134 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002135 if (n_extra < 0)
2136 n_extra = 0;
2137 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002138 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002139 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002140 // line break, but for TABs the highlighting should
2141 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002142 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002143
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144 if (c == TAB && n_extra + col > wp->w_width)
2145# ifdef FEAT_VARTABS
2146 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2147 wp->w_buffer->b_p_vts_array) - 1;
2148# else
2149 n_extra = (int)wp->w_buffer->b_p_ts
2150 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2151# endif
2152
2153 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2154 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002155# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002156 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002157 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002158# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002159 if (VIM_ISWHITE(c))
2160 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002161# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 if (c == TAB)
2163 // See "Tab alignment" below.
2164 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002165# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002166 if (!wp->w_p_list)
2167 c = ' ';
2168 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 }
2171#endif
2172
zeertzjqf14b8ba2021-09-10 16:58:30 +02002173 in_multispace = c == ' '
2174 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2175 if (!in_multispace)
2176 multispace_pos = 0;
2177
Bram Moolenaareed9d462021-02-15 20:38:25 +01002178 // 'list': Change char 160 to 'nbsp' and space to 'space'
2179 // setting in 'listchars'. But not when the character is
2180 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002181 if (wp->w_p_list
2182 && ((((c == 160 && mb_l == 1)
2183 || (mb_utf8
2184 && ((mb_c == 160 && mb_l == 2)
2185 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002186 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 || (c == ' '
2188 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002189 && (wp->w_lcs_chars.space
2190 || (in_multispace
2191 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002192 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 && ptr - line <= trailcol)))
2194 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002195 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2196 {
2197 c = wp->w_lcs_chars.multispace[multispace_pos++];
2198 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2199 multispace_pos = 0;
2200 }
2201 else
2202 c = (c == ' ') ? wp->w_lcs_chars.space
2203 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002204 if (area_attr == 0 && search_attr == 0)
2205 {
2206 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002207 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 saved_attr2 = char_attr; // save current attr
2209 }
2210 mb_c = c;
2211 if (enc_utf8 && utf_char2len(c) > 1)
2212 {
2213 mb_utf8 = TRUE;
2214 u8cc[0] = 0;
2215 c = 0xc0;
2216 }
2217 else
2218 mb_utf8 = FALSE;
2219 }
2220
zeertzjq2e7cba32022-06-10 15:30:32 +01002221 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2222 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002224 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2225 && wp->w_lcs_chars.leadmultispace != NULL)
2226 {
2227 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002228 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2229 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002230 multispace_pos = 0;
2231 }
2232
2233 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2234 c = wp->w_lcs_chars.trail;
2235
2236 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2237 c = wp->w_lcs_chars.lead;
2238
zeertzjq2e7cba32022-06-10 15:30:32 +01002239 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002240 c = wp->w_lcs_chars.space;
2241
2242
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 if (!attr_pri)
2244 {
2245 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002246 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 saved_attr2 = char_attr; // save current attr
2248 }
2249 mb_c = c;
2250 if (enc_utf8 && utf_char2len(c) > 1)
2251 {
2252 mb_utf8 = TRUE;
2253 u8cc[0] = 0;
2254 c = 0xc0;
2255 }
2256 else
2257 mb_utf8 = FALSE;
2258 }
2259 }
2260
2261 // Handling of non-printable characters.
2262 if (!vim_isprintc(c))
2263 {
2264 // when getting a character from the file, we may have to
2265 // turn it into something else on the way to putting it
2266 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002267 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268 {
2269 int tab_len = 0;
2270 long vcol_adjusted = vcol; // removed showbreak length
2271#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002272 char_u *sbr = get_showbreak_value(wp);
2273
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002274 // only adjust the tab_len, when at the first column
2275 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002276 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2277 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278#endif
2279 // tab amount depends on current column
2280#ifdef FEAT_VARTABS
2281 tab_len = tabstop_padding(vcol_adjusted,
2282 wp->w_buffer->b_p_ts,
2283 wp->w_buffer->b_p_vts_array) - 1;
2284#else
2285 tab_len = (int)wp->w_buffer->b_p_ts
2286 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2287#endif
2288
2289#ifdef FEAT_LINEBREAK
2290 if (!wp->w_p_lbr || !wp->w_p_list)
2291#endif
2292 // tab amount depends on current column
2293 n_extra = tab_len;
2294#ifdef FEAT_LINEBREAK
2295 else
2296 {
2297 char_u *p;
2298 int len;
2299 int i;
2300 int saved_nextra = n_extra;
2301
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002302# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002303 if (vcol_off > 0)
2304 // there are characters to conceal
2305 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002306
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002308 if (wp->w_p_list && wp->w_lcs_chars.tab1
2309 && old_boguscols > 0
2310 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002311 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002312# endif
2313 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002315 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002316 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002317 if (wp->w_lcs_chars.tab3)
2318 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 if (n_extra > 0)
2320 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002321 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002323 if (p == NULL)
2324 n_extra = 0;
2325 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002326 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002327 vim_memset(p, ' ', len);
2328 p[len] = NUL;
2329 vim_free(p_extra_free);
2330 p_extra_free = p;
2331 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002332 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002333 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002335 if (*p == NUL)
2336 {
2337 tab_len = i;
2338 break;
2339 }
2340
2341 // if tab3 is given, use it for the last char
2342 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2343 lcs = wp->w_lcs_chars.tab3;
2344 p += mb_char2bytes(lcs, p);
2345 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002347 }
2348 p_extra = p_extra_free;
2349# ifdef FEAT_CONCEAL
2350 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2351 // macro below, so need to adjust for that here
2352 if (vcol_off > 0)
2353 n_extra -= vcol_off;
2354# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002355 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 }
2357#endif
2358#ifdef FEAT_CONCEAL
2359 {
2360 int vc_saved = vcol_off;
2361
2362 // Tab alignment should be identical regardless of
2363 // 'conceallevel' value. So tab compensates of all
2364 // previous concealed characters, and thus resets
2365 // vcol_off and boguscols accumulated so far in the
2366 // line. Note that the tab can be longer than
2367 // 'tabstop' when there are concealed characters.
2368 FIX_FOR_BOGUSCOLS;
2369
2370 // Make sure, the highlighting for the tab char will be
2371 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002372 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002374 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002375 tab_len += vc_saved;
2376 }
2377#endif
2378 mb_utf8 = FALSE; // don't draw as UTF-8
2379 if (wp->w_p_list)
2380 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002381 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2382 ? wp->w_lcs_chars.tab3
2383 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002384#ifdef FEAT_LINEBREAK
2385 if (wp->w_p_lbr)
2386 c_extra = NUL; // using p_extra from above
2387 else
2388#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002389 c_extra = wp->w_lcs_chars.tab2;
2390 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002391 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002392 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002393 saved_attr2 = char_attr; // save current attr
2394 mb_c = c;
2395 if (enc_utf8 && utf_char2len(c) > 1)
2396 {
2397 mb_utf8 = TRUE;
2398 u8cc[0] = 0;
2399 c = 0xc0;
2400 }
2401 }
2402 else
2403 {
2404 c_final = NUL;
2405 c_extra = ' ';
2406 c = ' ';
2407 }
2408 }
2409 else if (c == NUL
2410 && (wp->w_p_list
2411 || ((fromcol >= 0 || fromcol_prev >= 0)
2412 && tocol > vcol
2413 && VIsual_mode != Ctrl_V
2414 && (
2415# ifdef FEAT_RIGHTLEFT
2416 wp->w_p_rl ? (col >= 0) :
2417# endif
2418 (col < wp->w_width))
2419 && !(noinvcur
2420 && lnum == wp->w_cursor.lnum
2421 && (colnr_T)vcol == wp->w_virtcol)))
2422 && lcs_eol_one > 0)
2423 {
2424 // Display a '$' after the line or highlight an extra
2425 // character if the line break is included.
2426#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2427 // For a diff line the highlighting continues after the
2428 // "$".
2429 if (
2430# ifdef FEAT_DIFF
2431 diff_hlf == (hlf_T)0
2432# ifdef LINE_ATTR
2433 &&
2434# endif
2435# endif
2436# ifdef LINE_ATTR
2437 line_attr == 0
2438# endif
2439 )
2440#endif
2441 {
2442 // In virtualedit, visual selections may extend
2443 // beyond end of line.
2444 if (area_highlighting && virtual_active()
2445 && tocol != MAXCOL && vcol < tocol)
2446 n_extra = 0;
2447 else
2448 {
2449 p_extra = at_end_str;
2450 n_extra = 1;
2451 c_extra = NUL;
2452 c_final = NUL;
2453 }
2454 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002455 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2456 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002457 else
2458 c = ' ';
2459 lcs_eol_one = -1;
2460 --ptr; // put it back at the NUL
2461 if (!attr_pri)
2462 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002463 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002464 n_attr = 1;
2465 }
2466 mb_c = c;
2467 if (enc_utf8 && utf_char2len(c) > 1)
2468 {
2469 mb_utf8 = TRUE;
2470 u8cc[0] = 0;
2471 c = 0xc0;
2472 }
2473 else
2474 mb_utf8 = FALSE; // don't draw as UTF-8
2475 }
2476 else if (c != NUL)
2477 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002478 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002479 if (n_extra == 0)
2480 n_extra = byte2cells(c) - 1;
2481#ifdef FEAT_RIGHTLEFT
2482 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2483 rl_mirror(p_extra); // reverse "<12>"
2484#endif
2485 c_extra = NUL;
2486 c_final = NUL;
2487#ifdef FEAT_LINEBREAK
2488 if (wp->w_p_lbr)
2489 {
2490 char_u *p;
2491
2492 c = *p_extra;
2493 p = alloc(n_extra + 1);
2494 vim_memset(p, ' ', n_extra);
2495 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2496 p[n_extra] = NUL;
2497 vim_free(p_extra_free);
2498 p_extra_free = p_extra = p;
2499 }
2500 else
2501#endif
2502 {
2503 n_extra = byte2cells(c) - 1;
2504 c = *p_extra++;
2505 }
2506 if (!attr_pri)
2507 {
2508 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002509 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 saved_attr2 = char_attr; // save current attr
2511 }
2512 mb_utf8 = FALSE; // don't draw as UTF-8
2513 }
2514 else if (VIsual_active
2515 && (VIsual_mode == Ctrl_V
2516 || VIsual_mode == 'v')
2517 && virtual_active()
2518 && tocol != MAXCOL
2519 && vcol < tocol
2520 && (
2521#ifdef FEAT_RIGHTLEFT
2522 wp->w_p_rl ? (col >= 0) :
2523#endif
2524 (col < wp->w_width)))
2525 {
2526 c = ' ';
2527 --ptr; // put it back at the NUL
2528 }
2529#if defined(LINE_ATTR)
2530 else if ((
2531# ifdef FEAT_DIFF
2532 diff_hlf != (hlf_T)0 ||
2533# endif
2534# ifdef FEAT_TERMINAL
2535 win_attr != 0 ||
2536# endif
2537 line_attr != 0
2538 ) && (
2539# ifdef FEAT_RIGHTLEFT
2540 wp->w_p_rl ? (col >= 0) :
2541# endif
2542 (col
2543# ifdef FEAT_CONCEAL
2544 - boguscols
2545# endif
2546 < wp->w_width)))
2547 {
2548 // Highlight until the right side of the window
2549 c = ' ';
2550 --ptr; // put it back at the NUL
2551
2552 // Remember we do the char for line highlighting.
2553 ++did_line_attr;
2554
2555 // don't do search HL for the rest of the line
2556 if (line_attr != 0 && char_attr == search_attr
2557 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002558 || (wp->w_p_list &&
2559 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 char_attr = line_attr;
2561# ifdef FEAT_DIFF
2562 if (diff_hlf == HLF_TXD)
2563 {
2564 diff_hlf = HLF_CHD;
2565 if (vi_attr == 0 || char_attr != vi_attr)
2566 {
2567 char_attr = HL_ATTR(diff_hlf);
2568 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2569 && wp->w_p_culopt_flags != CULOPT_NBR
2570 && (!cul_screenline
2571 || (vcol >= left_curline_col
2572 && vcol <= right_curline_col)))
2573 char_attr = hl_combine_attr(
2574 char_attr, HL_ATTR(HLF_CUL));
2575 }
2576 }
2577# endif
2578# ifdef FEAT_TERMINAL
2579 if (win_attr != 0)
2580 {
2581 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002582 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2583 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 {
2585 if (!cul_screenline || (vcol >= left_curline_col
2586 && vcol <= right_curline_col))
2587 char_attr = hl_combine_attr(
2588 char_attr, HL_ATTR(HLF_CUL));
2589 }
2590 else if (line_attr)
2591 char_attr = hl_combine_attr(char_attr, line_attr);
2592 }
2593# endif
2594 }
2595#endif
2596 }
2597
2598#ifdef FEAT_CONCEAL
2599 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002600 && (wp != curwin || lnum != wp->w_cursor.lnum
2601 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2603 && !(lnum_in_visual_area
2604 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2605 {
2606 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002607 if (((prev_syntax_id != syntax_seqnr
2608 && (syntax_flags & HL_CONCEAL) != 0)
2609 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002610 && (syn_get_sub_char() != NUL
2611 || (has_match_conc && match_conc)
2612 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002613 && wp->w_p_cole != 3)
2614 {
2615 // First time at this concealed item: display one
2616 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002617 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 c = match_conc;
2619 else if (syn_get_sub_char() != NUL)
2620 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002621 else if (wp->w_lcs_chars.conceal != NUL)
2622 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 else
2624 c = ' ';
2625
2626 prev_syntax_id = syntax_seqnr;
2627
2628 if (n_extra > 0)
2629 vcol_off += n_extra;
2630 vcol += n_extra;
2631 if (wp->w_p_wrap && n_extra > 0)
2632 {
2633# ifdef FEAT_RIGHTLEFT
2634 if (wp->w_p_rl)
2635 {
2636 col -= n_extra;
2637 boguscols -= n_extra;
2638 }
2639 else
2640# endif
2641 {
2642 boguscols += n_extra;
2643 col += n_extra;
2644 }
2645 }
2646 n_extra = 0;
2647 n_attr = 0;
2648 }
2649 else if (n_skip == 0)
2650 {
2651 is_concealing = TRUE;
2652 n_skip = 1;
2653 }
2654 mb_c = c;
2655 if (enc_utf8 && utf_char2len(c) > 1)
2656 {
2657 mb_utf8 = TRUE;
2658 u8cc[0] = 0;
2659 c = 0xc0;
2660 }
2661 else
2662 mb_utf8 = FALSE; // don't draw as UTF-8
2663 }
2664 else
2665 {
2666 prev_syntax_id = 0;
2667 is_concealing = FALSE;
2668 }
2669
2670 if (n_skip > 0 && did_decrement_ptr)
2671 // not showing the '>', put pointer back to avoid getting stuck
2672 ++ptr;
2673
2674#endif // FEAT_CONCEAL
2675 }
2676
2677#ifdef FEAT_CONCEAL
2678 // In the cursor line and we may be concealing characters: correct
2679 // the cursor column when we reach its position.
2680 if (!did_wcol && draw_state == WL_LINE
2681 && wp == curwin && lnum == wp->w_cursor.lnum
2682 && conceal_cursor_line(wp)
2683 && (int)wp->w_virtcol <= vcol + n_skip)
2684 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002685# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002686 if (wp->w_p_rl)
2687 wp->w_wcol = wp->w_width - col + boguscols - 1;
2688 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002689# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 wp->w_wcol = col - boguscols;
2691 wp->w_wrow = row;
2692 did_wcol = TRUE;
2693 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002694# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002695 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002696# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002697 }
2698#endif
2699
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002700 // Use "extra_attr", but don't override visual selection highlighting.
2701 // Don't use "extra_attr" until n_attr_skip is zero.
2702 if (n_attr_skip == 0 && n_attr > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703 && draw_state == WL_LINE
2704 && !attr_pri)
2705 {
2706#ifdef LINE_ATTR
2707 if (line_attr)
2708 char_attr = hl_combine_attr(extra_attr, line_attr);
2709 else
2710#endif
2711 char_attr = extra_attr;
2712 }
2713
2714#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2715 // XIM don't send preedit_start and preedit_end, but they send
2716 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2717 // im_is_preediting() here.
2718 if (p_imst == IM_ON_THE_SPOT
2719 && xic != NULL
2720 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002721 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002722 && !p_imdisable
2723 && im_is_preediting()
2724 && draw_state == WL_LINE)
2725 {
2726 colnr_T tcol;
2727
2728 if (preedit_end_col == MAXCOL)
2729 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2730 else
2731 tcol = preedit_end_col;
2732 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2733 {
2734 if (feedback_old_attr < 0)
2735 {
2736 feedback_col = 0;
2737 feedback_old_attr = char_attr;
2738 }
2739 char_attr = im_get_feedback_attr(feedback_col);
2740 if (char_attr < 0)
2741 char_attr = feedback_old_attr;
2742 feedback_col++;
2743 }
2744 else if (feedback_old_attr >= 0)
2745 {
2746 char_attr = feedback_old_attr;
2747 feedback_old_attr = -1;
2748 feedback_col = 0;
2749 }
2750 }
2751#endif
2752 // Handle the case where we are in column 0 but not on the first
2753 // character of the line and the user wants us to show us a
2754 // special character (via 'listchars' option "precedes:<char>".
2755 if (lcs_prec_todo != NUL
2756 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002757 && (wp->w_p_wrap ?
2758 (wp->w_skipcol > 0 && row == 0) :
2759 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002760#ifdef FEAT_DIFF
2761 && filler_todo <= 0
2762#endif
2763 && draw_state > WL_NR
2764 && c != NUL)
2765 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002766 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002767 lcs_prec_todo = NUL;
2768 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2769 {
2770 // Double-width character being overwritten by the "precedes"
2771 // character, need to fill up half the character.
2772 c_extra = MB_FILLER_CHAR;
2773 c_final = NUL;
2774 n_extra = 1;
2775 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002776 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002777 }
2778 mb_c = c;
2779 if (enc_utf8 && utf_char2len(c) > 1)
2780 {
2781 mb_utf8 = TRUE;
2782 u8cc[0] = 0;
2783 c = 0xc0;
2784 }
2785 else
2786 mb_utf8 = FALSE; // don't draw as UTF-8
2787 if (!attr_pri)
2788 {
2789 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002790 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002791 n_attr3 = 1;
2792 }
2793 }
2794
2795 // At end of the text line or just after the last character.
2796 if ((c == NUL
2797#if defined(LINE_ATTR)
2798 || did_line_attr == 1
2799#endif
2800 ) && eol_hl_off == 0)
2801 {
2802#ifdef FEAT_SEARCH_EXTRA
2803 // flag to indicate whether prevcol equals startcol of search_hl or
2804 // one of the matches
2805 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2806 (long)(ptr - line) - (c == NUL));
2807#endif
2808 // Invert at least one char, used for Visual and empty line or
2809 // highlight match at end of line. If it's beyond the last
2810 // char on the screen, just overwrite that one (tricky!) Not
2811 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002812 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002813 && ((area_attr != 0 && vcol == fromcol
2814 && (VIsual_mode != Ctrl_V
2815 || lnum == VIsual.lnum
2816 || lnum == curwin->w_cursor.lnum)
2817 && c == NUL)
2818#ifdef FEAT_SEARCH_EXTRA
2819 // highlight 'hlsearch' match at end of line
2820 || (prevcol_hl_flag
2821# ifdef FEAT_SYN_HL
2822 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2823 && !(wp == curwin && VIsual_active))
2824# endif
2825# ifdef FEAT_DIFF
2826 && diff_hlf == (hlf_T)0
2827# endif
2828# if defined(LINE_ATTR)
2829 && did_line_attr <= 1
2830# endif
2831 )
2832#endif
2833 ))
2834 {
2835 int n = 0;
2836
2837#ifdef FEAT_RIGHTLEFT
2838 if (wp->w_p_rl)
2839 {
2840 if (col < 0)
2841 n = 1;
2842 }
2843 else
2844#endif
2845 {
2846 if (col >= wp->w_width)
2847 n = -1;
2848 }
2849 if (n != 0)
2850 {
2851 // At the window boundary, highlight the last character
2852 // instead (better than nothing).
2853 off += n;
2854 col += n;
2855 }
2856 else
2857 {
2858 // Add a blank character to highlight.
2859 ScreenLines[off] = ' ';
2860 if (enc_utf8)
2861 ScreenLinesUC[off] = 0;
2862 }
2863#ifdef FEAT_SEARCH_EXTRA
2864 if (area_attr == 0)
2865 {
2866 // Use attributes from match with highest priority among
2867 // 'search_hl' and the match list.
2868 get_search_match_hl(wp, &screen_search_hl,
2869 (long)(ptr - line), &char_attr);
2870 }
2871#endif
2872 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002873 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874#ifdef FEAT_RIGHTLEFT
2875 if (wp->w_p_rl)
2876 {
2877 --col;
2878 --off;
2879 }
2880 else
2881#endif
2882 {
2883 ++col;
2884 ++off;
2885 }
2886 ++vcol;
2887 eol_hl_off = 1;
2888 }
2889 }
2890
2891 // At end of the text line.
2892 if (c == NUL)
2893 {
2894#ifdef FEAT_SYN_HL
2895 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2896 if (wp->w_p_wrap)
2897 v = wp->w_skipcol;
2898 else
2899 v = wp->w_leftcol;
2900
2901 // check if line ends before left margin
2902 if (vcol < v + col - win_col_off(wp))
2903 vcol = v + col - win_col_off(wp);
2904#ifdef FEAT_CONCEAL
2905 // Get rid of the boguscols now, we want to draw until the right
2906 // edge for 'cursorcolumn'.
2907 col -= boguscols;
2908 boguscols = 0;
2909#endif
2910
2911 if (draw_color_col)
2912 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2913
2914 if (((wp->w_p_cuc
2915 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2916 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002917 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 && lnum != wp->w_cursor.lnum)
2919 || draw_color_col
2920 || win_attr != 0)
2921# ifdef FEAT_RIGHTLEFT
2922 && !wp->w_p_rl
2923# endif
2924 )
2925 {
2926 int rightmost_vcol = 0;
2927 int i;
2928
2929 if (wp->w_p_cuc)
2930 rightmost_vcol = wp->w_virtcol;
2931 if (draw_color_col)
2932 // determine rightmost colorcolumn to possibly draw
2933 for (i = 0; color_cols[i] >= 0; ++i)
2934 if (rightmost_vcol < color_cols[i])
2935 rightmost_vcol = color_cols[i];
2936
2937 while (col < wp->w_width)
2938 {
2939 ScreenLines[off] = ' ';
2940 if (enc_utf8)
2941 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002942 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002943 ++col;
2944 if (draw_color_col)
2945 draw_color_col = advance_color_col(VCOL_HLC,
2946 &color_cols);
2947
2948 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2949 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2950 else if (draw_color_col && VCOL_HLC == *color_cols)
2951 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2952 else
2953 ScreenAttrs[off++] = win_attr;
2954
2955 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2956 break;
2957
2958 ++vcol;
2959 }
2960 }
2961#endif
2962
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002963 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002964 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 row++;
2966
2967 // Update w_cline_height and w_cline_folded if the cursor line was
2968 // updated (saves a call to plines() later).
2969 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2970 {
2971 curwin->w_cline_row = startrow;
2972 curwin->w_cline_height = row - startrow;
2973#ifdef FEAT_FOLDING
2974 curwin->w_cline_folded = FALSE;
2975#endif
2976 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2977 }
2978
2979 break;
2980 }
2981
2982 // Show "extends" character from 'listchars' if beyond the line end and
2983 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002984 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002985 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002986 && wp->w_p_list
2987 && !wp->w_p_wrap
2988#ifdef FEAT_DIFF
2989 && filler_todo <= 0
2990#endif
2991 && (
2992#ifdef FEAT_RIGHTLEFT
2993 wp->w_p_rl ? col == 0 :
2994#endif
2995 col == wp->w_width - 1)
2996 && (*ptr != NUL
2997 || (wp->w_p_list && lcs_eol_one > 0)
2998 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2999 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003000 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01003001 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003002 mb_c = c;
3003 if (enc_utf8 && utf_char2len(c) > 1)
3004 {
3005 mb_utf8 = TRUE;
3006 u8cc[0] = 0;
3007 c = 0xc0;
3008 }
3009 else
3010 mb_utf8 = FALSE;
3011 }
3012
3013#ifdef FEAT_SYN_HL
3014 // advance to the next 'colorcolumn'
3015 if (draw_color_col)
3016 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
3017
3018 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3019 // highlight the cursor position itself.
3020 // Also highlight the 'colorcolumn' if it is different than
3021 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003022 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3023 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003025 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003026 draw_state == WL_BRI ||
3027 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003029# ifdef FEAT_DIFF
3030 && filler_todo <= 0
3031# endif
3032 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003033 {
3034 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3035 && lnum != wp->w_cursor.lnum)
3036 {
3037 vcol_save_attr = char_attr;
3038 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
3039 }
3040 else if (draw_color_col && VCOL_HLC == *color_cols)
3041 {
3042 vcol_save_attr = char_attr;
3043 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
3044 }
3045 }
3046#endif
3047
3048 // Store character to be displayed.
3049 // Skip characters that are left of the screen for 'nowrap'.
3050 vcol_prev = vcol;
3051 if (draw_state < WL_LINE || n_skip <= 0)
3052 {
3053 // Store the character.
3054#if defined(FEAT_RIGHTLEFT)
3055 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3056 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003057 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003058 --off;
3059 --col;
3060 }
3061#endif
3062 ScreenLines[off] = c;
3063 if (enc_dbcs == DBCS_JPNU)
3064 {
3065 if ((mb_c & 0xff00) == 0x8e00)
3066 ScreenLines[off] = 0x8e;
3067 ScreenLines2[off] = mb_c & 0xff;
3068 }
3069 else if (enc_utf8)
3070 {
3071 if (mb_utf8)
3072 {
3073 int i;
3074
3075 ScreenLinesUC[off] = mb_c;
3076 if ((c & 0xff) == 0)
3077 ScreenLines[off] = 0x80; // avoid storing zero
3078 for (i = 0; i < Screen_mco; ++i)
3079 {
3080 ScreenLinesC[i][off] = u8cc[i];
3081 if (u8cc[i] == 0)
3082 break;
3083 }
3084 }
3085 else
3086 ScreenLinesUC[off] = 0;
3087 }
3088 if (multi_attr)
3089 {
3090 ScreenAttrs[off] = multi_attr;
3091 multi_attr = 0;
3092 }
3093 else
3094 ScreenAttrs[off] = char_attr;
3095
Bram Moolenaarb9081882022-07-09 04:56:24 +01003096 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3097
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003098 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3099 {
3100 // Need to fill two screen columns.
3101 ++off;
3102 ++col;
3103 if (enc_utf8)
3104 // UTF-8: Put a 0 in the second screen char.
3105 ScreenLines[off] = 0;
3106 else
3107 // DBCS: Put second byte in the second screen char.
3108 ScreenLines[off] = mb_c & 0xff;
3109 if (draw_state > WL_NR
3110#ifdef FEAT_DIFF
3111 && filler_todo <= 0
3112#endif
3113 )
3114 ++vcol;
3115 // When "tocol" is halfway a character, set it to the end of
3116 // the character, otherwise highlighting won't stop.
3117 if (tocol == vcol)
3118 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003119
3120 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3121
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003122#ifdef FEAT_RIGHTLEFT
3123 if (wp->w_p_rl)
3124 {
3125 // now it's time to backup one cell
3126 --off;
3127 --col;
3128 }
3129#endif
3130 }
3131#ifdef FEAT_RIGHTLEFT
3132 if (wp->w_p_rl)
3133 {
3134 --off;
3135 --col;
3136 }
3137 else
3138#endif
3139 {
3140 ++off;
3141 ++col;
3142 }
3143 }
3144#ifdef FEAT_CONCEAL
3145 else if (wp->w_p_cole > 0 && is_concealing)
3146 {
3147 --n_skip;
3148 ++vcol_off;
3149 if (n_extra > 0)
3150 vcol_off += n_extra;
3151 if (wp->w_p_wrap)
3152 {
3153 // Special voodoo required if 'wrap' is on.
3154 //
3155 // Advance the column indicator to force the line
3156 // drawing to wrap early. This will make the line
3157 // take up the same screen space when parts are concealed,
3158 // so that cursor line computations aren't messed up.
3159 //
3160 // To avoid the fictitious advance of 'col' causing
3161 // trailing junk to be written out of the screen line
3162 // we are building, 'boguscols' keeps track of the number
3163 // of bad columns we have advanced.
3164 if (n_extra > 0)
3165 {
3166 vcol += n_extra;
3167# ifdef FEAT_RIGHTLEFT
3168 if (wp->w_p_rl)
3169 {
3170 col -= n_extra;
3171 boguscols -= n_extra;
3172 }
3173 else
3174# endif
3175 {
3176 col += n_extra;
3177 boguscols += n_extra;
3178 }
3179 n_extra = 0;
3180 n_attr = 0;
3181 }
3182
3183
3184 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3185 {
3186 // Need to fill two screen columns.
3187# ifdef FEAT_RIGHTLEFT
3188 if (wp->w_p_rl)
3189 {
3190 --boguscols;
3191 --col;
3192 }
3193 else
3194# endif
3195 {
3196 ++boguscols;
3197 ++col;
3198 }
3199 }
3200
3201# ifdef FEAT_RIGHTLEFT
3202 if (wp->w_p_rl)
3203 {
3204 --boguscols;
3205 --col;
3206 }
3207 else
3208# endif
3209 {
3210 ++boguscols;
3211 ++col;
3212 }
3213 }
3214 else
3215 {
3216 if (n_extra > 0)
3217 {
3218 vcol += n_extra;
3219 n_extra = 0;
3220 n_attr = 0;
3221 }
3222 }
3223
3224 }
3225#endif // FEAT_CONCEAL
3226 else
3227 --n_skip;
3228
3229 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3230 // column.
3231 if (draw_state > WL_NR
3232#ifdef FEAT_DIFF
3233 && filler_todo <= 0
3234#endif
3235 )
3236 ++vcol;
3237
3238#ifdef FEAT_SYN_HL
3239 if (vcol_save_attr >= 0)
3240 char_attr = vcol_save_attr;
3241#endif
3242
3243 // restore attributes after "predeces" in 'listchars'
3244 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3245 char_attr = saved_attr3;
3246
3247 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003248 if (n_attr > 0 && draw_state == WL_LINE
3249 && n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003250 char_attr = saved_attr2;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003251 if (n_attr_skip > 0)
3252 --n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253
3254 // At end of screen line and there is more to come: Display the line
3255 // so far. If there is no more to display it is caught above.
3256 if ((
3257#ifdef FEAT_RIGHTLEFT
3258 wp->w_p_rl ? (col < 0) :
3259#endif
3260 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003261 && (draw_state != WL_LINE
3262 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263#ifdef FEAT_DIFF
3264 || filler_todo > 0
3265#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003266#ifdef FEAT_PROP_POPUP
3267 || text_prop_follows
3268#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003269 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3270 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3272 )
3273 {
3274#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003275 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003276 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003277 boguscols = 0;
3278#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003279 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003280 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281#endif
3282 ++row;
3283 ++screen_row;
3284
3285 // When not wrapping and finished diff lines, or when displayed
3286 // '$' and highlighting until last column, break here.
3287 if ((!wp->w_p_wrap
3288#ifdef FEAT_DIFF
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003289 && filler_todo <= 0
3290#endif
3291#ifdef FEAT_PROP_POPUP
3292 && !text_prop_follows
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003293#endif
3294 ) || lcs_eol_one == -1)
3295 break;
3296
3297 // When the window is too narrow draw all "@" lines.
3298 if (draw_state != WL_LINE
3299#ifdef FEAT_DIFF
3300 && filler_todo <= 0
3301#endif
3302 )
3303 {
3304 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3305 draw_vsep_win(wp, row);
3306 row = endrow;
3307 }
3308
3309 // When line got too long for screen break here.
3310 if (row == endrow)
3311 {
3312 ++row;
3313 break;
3314 }
3315
3316 if (screen_cur_row == screen_row - 1
3317#ifdef FEAT_DIFF
3318 && filler_todo <= 0
3319#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01003320#ifdef FEAT_PROP_POPUP
3321 && !text_prop_follows
3322#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 && wp->w_width == Columns)
3324 {
3325 // Remember that the line wraps, used for modeless copy.
3326 LineWraps[screen_row - 1] = TRUE;
3327
3328 // Special trick to make copy/paste of wrapped lines work with
3329 // xterm/screen: write an extra character beyond the end of
3330 // the line. This will work with all terminal types
3331 // (regardless of the xn,am settings).
3332 // Only do this on a fast tty.
3333 // Only do this if the cursor is on the current line
3334 // (something has been written in it).
3335 // Don't do this for the GUI.
3336 // Don't do this for double-width characters.
3337 // Don't do this for a window not at the right screen border.
3338 if (p_tf
3339#ifdef FEAT_GUI
3340 && !gui.in_use
3341#endif
3342 && !(has_mbyte
3343 && ((*mb_off2cells)(LineOffset[screen_row],
3344 LineOffset[screen_row] + screen_Columns)
3345 == 2
3346 || (*mb_off2cells)(LineOffset[screen_row - 1]
3347 + (int)Columns - 2,
3348 LineOffset[screen_row] + screen_Columns)
3349 == 2)))
3350 {
3351 // First make sure we are at the end of the screen line,
3352 // then output the same character again to let the
3353 // terminal know about the wrap. If the terminal doesn't
3354 // auto-wrap, we overwrite the character.
3355 if (screen_cur_col != wp->w_width)
3356 screen_char(LineOffset[screen_row - 1]
3357 + (unsigned)Columns - 1,
3358 screen_row - 1, (int)(Columns - 1));
3359
3360 // When there is a multi-byte character, just output a
3361 // space to keep it simple.
3362 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3363 screen_row - 1] + (Columns - 1)]) > 1)
3364 out_char(' ');
3365 else
3366 out_char(ScreenLines[LineOffset[screen_row - 1]
3367 + (Columns - 1)]);
3368 // force a redraw of the first char on the next line
3369 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3370 screen_start(); // don't know where cursor is now
3371 }
3372 }
3373
3374 col = 0;
3375 off = (unsigned)(current_ScreenLine - ScreenLines);
3376#ifdef FEAT_RIGHTLEFT
3377 if (wp->w_p_rl)
3378 {
3379 col = wp->w_width - 1; // col is not used if breaking!
3380 off += col;
3381 }
3382#endif
3383
3384 // reset the drawing state for the start of a wrapped line
3385 draw_state = WL_START;
3386 saved_n_extra = n_extra;
3387 saved_p_extra = p_extra;
3388 saved_c_extra = c_extra;
3389 saved_c_final = c_final;
3390#ifdef FEAT_SYN_HL
3391 if (!(cul_screenline
3392# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003393 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003394# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003395 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003396 saved_char_attr = char_attr;
3397 else
3398#endif
3399 saved_char_attr = 0;
3400 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003401 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402#ifdef FEAT_LINEBREAK
3403# ifdef FEAT_DIFF
3404 if (filler_todo <= 0)
3405# endif
3406 need_showbreak = TRUE;
3407#endif
3408#ifdef FEAT_DIFF
3409 --filler_todo;
3410 // When the filler lines are actually below the last line of the
3411 // file, don't draw the line itself, break here.
3412 if (filler_todo == 0 && wp->w_botfill)
3413 break;
3414#endif
3415 }
3416
3417 } // for every character in the line
3418
3419#ifdef FEAT_SPELL
3420 // After an empty line check first word for capital.
3421 if (*skipwhite(line) == NUL)
3422 {
3423 capcol_lnum = lnum + 1;
3424 cap_col = 0;
3425 }
3426#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003427#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003428 vim_free(text_props);
3429 vim_free(text_prop_idxs);
3430#endif
3431
3432 vim_free(p_extra_free);
3433 return row;
3434}