blob: be9ed9d36219a0245ad9229ef2d0c268cf9eb9cd [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;
211 proptype_T *pt1, *pt2;
212 colnr_T col1, col2;
213
214 idx1 = *(int *)s1;
215 idx2 = *(int *)s2;
216 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
217 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
218 if (pt1 == pt2)
219 return 0;
220 if (pt1 == NULL)
221 return -1;
222 if (pt2 == NULL)
223 return 1;
224 if (pt1->pt_priority != pt2->pt_priority)
225 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
226 col1 = current_text_props[idx1].tp_col;
227 col2 = current_text_props[idx2].tp_col;
228 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
229}
230#endif
231
232/*
233 * Display line "lnum" of window 'wp' on the screen.
234 * Start at row "startrow", stop when "endrow" is reached.
235 * wp->w_virtcol needs to be valid.
236 *
237 * Return the number of last row the line occupies.
238 */
239 int
240win_line(
241 win_T *wp,
242 linenr_T lnum,
243 int startrow,
244 int endrow,
245 int nochange UNUSED, // not updating for changed text
246 int number_only) // only update the number column
247{
248 int col = 0; // visual column on screen
249 unsigned off; // offset in ScreenLines/ScreenAttrs
250 int c = 0; // init for GCC
251 long vcol = 0; // virtual column (for tabs)
252#ifdef FEAT_LINEBREAK
253 long vcol_sbr = -1; // virtual column after showbreak
254#endif
255 long vcol_prev = -1; // "vcol" of previous character
256 char_u *line; // current line
257 char_u *ptr; // current position in "line"
258 int row; // row in the window, excl w_winrow
259 int screen_row; // row on the screen, incl w_winrow
260
261 char_u extra[21]; // "%ld " and 'fdc' must fit in here
262 int n_extra = 0; // number of extra chars
263 char_u *p_extra = NULL; // string of extra chars, plus NUL
264 char_u *p_extra_free = NULL; // p_extra needs to be freed
265 int c_extra = NUL; // extra chars, all the same
266 int c_final = NUL; // final char, mandatory if set
267 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000268#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000269 int in_linebreak = FALSE; // n_extra set for showing linebreak
270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100272 // displaying eol at end-of-line
273 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000274 int lcs_prec_todo = wp->w_lcs_chars.prec;
275 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276
277 // saved "extra" items for when draw_state becomes WL_LINE (again)
278 int saved_n_extra = 0;
279 char_u *saved_p_extra = NULL;
280 int saved_c_extra = 0;
281 int saved_c_final = 0;
282 int saved_char_attr = 0;
283
284 int n_attr = 0; // chars with special attr
285 int saved_attr2 = 0; // char_attr saved for n_attr
286 int n_attr3 = 0; // chars with overruling special attr
287 int saved_attr3 = 0; // char_attr saved for n_attr3
288
289 int n_skip = 0; // nr of chars to skip for 'nowrap'
290
291 int fromcol = -10; // start of inverting
292 int tocol = MAXCOL; // end of inverting
293 int fromcol_prev = -2; // start of inverting after cursor
294 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 int lnum_in_visual_area = FALSE;
296 pos_T pos;
297 long v;
298
299 int char_attr = 0; // attributes for next character
300 int attr_pri = FALSE; // char_attr has priority
301 int area_highlighting = FALSE; // Visual or incsearch highlighting
302 // in this line
303 int vi_attr = 0; // attributes for Visual and incsearch
304 // highlighting
305 int wcr_attr = 0; // attributes from 'wincolor'
306 int win_attr = 0; // background for whole window, except
307 // margins and "~" lines.
308 int area_attr = 0; // attributes desired by highlighting
309 int search_attr = 0; // attributes desired by 'hlsearch'
310#ifdef FEAT_SYN_HL
311 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
312 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200313 int prev_syntax_col = -1; // column of prev_syntax_attr
314 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 int has_syntax = FALSE; // this buffer has syntax highl.
316 int save_did_emsg;
317 int draw_color_col = FALSE; // highlight colorcolumn
318 int *color_cols = NULL; // pointer to according columns array
319#endif
320 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100321#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 int text_prop_count;
323 int text_prop_next = 0; // next text property to use
324 textprop_T *text_props = NULL;
325 int *text_prop_idxs = NULL;
326 int text_props_active = 0;
327 proptype_T *text_prop_type = NULL;
328 int text_prop_attr = 0;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100329 int text_prop_id = 0; // active property ID
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330 int text_prop_combine = FALSE;
331#endif
332#ifdef FEAT_SPELL
333 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaarae49aa82022-02-25 21:05:36 +0000334 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335# define SPWORDLEN 150
336 char_u nextline[SPWORDLEN * 2];// text with start of the next line
337 int nextlinecol = 0; // column where nextline[] starts
338 int nextline_idx = 0; // index in nextline[] where next line
339 // starts
340 int spell_attr = 0; // attributes desired by spelling
341 int word_end = 0; // last byte with same spell_attr
342 static linenr_T checked_lnum = 0; // line number for "checked_col"
343 static int checked_col = 0; // column in "checked_lnum" up to which
344 // there are no spell errors
345 static int cap_col = -1; // column to check for Cap word
346 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
347 int cur_checked_col = 0; // checked column for current line
348#endif
349 int extra_check = 0; // has extra highlighting
350 int multi_attr = 0; // attributes desired by multibyte
351 int mb_l = 1; // multi-byte byte length
352 int mb_c = 0; // decoded multi-byte character
353 int mb_utf8 = FALSE; // screen char is UTF-8 char
354 int u8cc[MAX_MCO]; // composing UTF-8 chars
355#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
356 int filler_lines = 0; // nr of filler lines to be drawn
357 int filler_todo = 0; // nr of filler lines still to do + 1
Bram Moolenaar936dc602022-03-06 20:47:01 +0000358#else
359# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200360#endif
361#ifdef FEAT_DIFF
362 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
363 int change_start = MAXCOL; // first col of changed area
364 int change_end = -1; // last col of changed area
365#endif
366 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100367 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200368 int in_multispace = FALSE; // in multiple consecutive spaces
369 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200370#ifdef FEAT_LINEBREAK
371 int need_showbreak = FALSE; // overlong line, skipping first x
372 // chars
373#endif
374#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
375 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
376# define LINE_ATTR
377 int line_attr = 0; // attribute for the whole line
378 int line_attr_save;
379#endif
380#ifdef FEAT_SIGNS
381 int sign_present = FALSE;
382 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000383 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200384#endif
385#ifdef FEAT_ARABIC
386 int prev_c = 0; // previous Arabic character
387 int prev_c1 = 0; // first composing char for prev_c
388#endif
389#if defined(LINE_ATTR)
390 int did_line_attr = 0;
391#endif
392#ifdef FEAT_TERMINAL
393 int get_term_attr = FALSE;
394#endif
395#ifdef FEAT_SYN_HL
396 int cul_attr = 0; // set when 'cursorline' active
397
398 // 'cursorlineopt' has "screenline" and cursor is in this line
399 int cul_screenline = FALSE;
400
401 // margin columns for the screen line, needed for when 'cursorlineopt'
402 // contains "screenline"
403 int left_curline_col = 0;
404 int right_curline_col = 0;
405#endif
406
407 // draw_state: items that are drawn in sequence:
408#define WL_START 0 // nothing done yet
409#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000410# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200411#else
412# define WL_CMDLINE WL_START
413#endif
414#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000415# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200416#else
417# define WL_FOLD WL_CMDLINE
418#endif
419#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000420# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200421#else
422# define WL_SIGN WL_FOLD // column for signs
423#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000424#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200425#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000426# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200427#else
428# define WL_BRI WL_NR
429#endif
430#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000431# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200432#else
433# define WL_SBR WL_BRI
434#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000435#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200436 int draw_state = WL_START; // what to draw next
437#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
438 int feedback_col = 0;
439 int feedback_old_attr = -1;
440#endif
441 int screen_line_flags = 0;
442
443#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
444 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000445 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200446#endif
447#ifdef FEAT_CONCEAL
448 int syntax_flags = 0;
449 int syntax_seqnr = 0;
450 int prev_syntax_id = 0;
451 int conceal_attr = HL_ATTR(HLF_CONCEAL);
452 int is_concealing = FALSE;
453 int boguscols = 0; // nonexistent columns added to force
454 // wrapping
455 int vcol_off = 0; // offset for concealed characters
456 int did_wcol = FALSE;
457 int old_boguscols = 0;
458# define VCOL_HLC (vcol - vcol_off)
459# define FIX_FOR_BOGUSCOLS \
460 { \
461 n_extra += vcol_off; \
462 vcol -= vcol_off; \
463 vcol_off = 0; \
464 col -= boguscols; \
465 old_boguscols = boguscols; \
466 boguscols = 0; \
467 }
468#else
469# define VCOL_HLC (vcol)
470#endif
471
472 if (startrow > endrow) // past the end already!
473 return startrow;
474
475 row = startrow;
476 screen_row = row + W_WINROW(wp);
477
478 if (!number_only)
479 {
480 // To speed up the loop below, set extra_check when there is linebreak,
481 // trailing white space and/or syntax processing to be done.
482#ifdef FEAT_LINEBREAK
483 extra_check = wp->w_p_lbr;
484#endif
485#ifdef FEAT_SYN_HL
486 if (syntax_present(wp) && !wp->w_s->b_syn_error
487# ifdef SYN_TIME_LIMIT
488 && !wp->w_s->b_syn_slow
489# endif
490 )
491 {
492 // Prepare for syntax highlighting in this line. When there is an
493 // error, stop syntax highlighting.
494 save_did_emsg = did_emsg;
495 did_emsg = FALSE;
496 syntax_start(wp, lnum);
497 if (did_emsg)
498 wp->w_s->b_syn_error = TRUE;
499 else
500 {
501 did_emsg = save_did_emsg;
502#ifdef SYN_TIME_LIMIT
503 if (!wp->w_s->b_syn_slow)
504#endif
505 {
506 has_syntax = TRUE;
507 extra_check = TRUE;
508 }
509 }
510 }
511
512 // Check for columns to display for 'colorcolumn'.
513 color_cols = wp->w_p_cc_cols;
514 if (color_cols != NULL)
515 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
516#endif
517
518#ifdef FEAT_TERMINAL
519 if (term_show_buffer(wp->w_buffer))
520 {
521 extra_check = TRUE;
522 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100523 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200524 }
525#endif
526
527#ifdef FEAT_SPELL
528 if (wp->w_p_spell
529 && *wp->w_s->b_p_spl != NUL
530 && wp->w_s->b_langp.ga_len > 0
531 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
532 {
533 // Prepare for spell checking.
534 has_spell = TRUE;
535 extra_check = TRUE;
536
537 // Get the start of the next line, so that words that wrap to the
538 // next line are found too: "et<line-break>al.".
539 // Trick: skip a few chars for C/shell/Vim comments
540 nextline[SPWORDLEN] = NUL;
541 if (lnum < wp->w_buffer->b_ml.ml_line_count)
542 {
543 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
544 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
545 }
546
547 // When a word wrapped from the previous line the start of the
548 // current line is valid.
549 if (lnum == checked_lnum)
550 cur_checked_col = checked_col;
551 checked_lnum = 0;
552
553 // When there was a sentence end in the previous line may require a
554 // word starting with capital in this line. In line 1 always check
555 // the first word.
556 if (lnum != capcol_lnum)
557 cap_col = -1;
558 if (lnum == 1)
559 cap_col = 0;
560 capcol_lnum = 0;
561 }
562#endif
563
564 // handle Visual active in this window
565 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
566 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100567 pos_T *top, *bot;
568
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200569 if (LTOREQ_POS(curwin->w_cursor, VIsual))
570 {
571 // Visual is after curwin->w_cursor
572 top = &curwin->w_cursor;
573 bot = &VIsual;
574 }
575 else
576 {
577 // Visual is before curwin->w_cursor
578 top = &VIsual;
579 bot = &curwin->w_cursor;
580 }
581 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
582 if (VIsual_mode == Ctrl_V)
583 {
584 // block mode
585 if (lnum_in_visual_area)
586 {
587 fromcol = wp->w_old_cursor_fcol;
588 tocol = wp->w_old_cursor_lcol;
589 }
590 }
591 else
592 {
593 // non-block mode
594 if (lnum > top->lnum && lnum <= bot->lnum)
595 fromcol = 0;
596 else if (lnum == top->lnum)
597 {
598 if (VIsual_mode == 'V') // linewise
599 fromcol = 0;
600 else
601 {
602 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
603 if (gchar_pos(top) == NUL)
604 tocol = fromcol + 1;
605 }
606 }
607 if (VIsual_mode != 'V' && lnum == bot->lnum)
608 {
609 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
610 {
611 fromcol = -10;
612 tocol = MAXCOL;
613 }
614 else if (bot->col == MAXCOL)
615 tocol = MAXCOL;
616 else
617 {
618 pos = *bot;
619 if (*p_sel == 'e')
620 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
621 else
622 {
623 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
624 ++tocol;
625 }
626 }
627 }
628 }
629
630 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200631 if (!highlight_match && lnum == curwin->w_cursor.lnum
632 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200633#ifdef FEAT_GUI
634 && !gui.in_use
635#endif
636 )
637 noinvcur = TRUE;
638
639 // if inverting in this line set area_highlighting
640 if (fromcol >= 0)
641 {
642 area_highlighting = TRUE;
643 vi_attr = HL_ATTR(HLF_V);
644#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
645 if ((clip_star.available && !clip_star.owned
646 && clip_isautosel_star())
647 || (clip_plus.available && !clip_plus.owned
648 && clip_isautosel_plus()))
649 vi_attr = HL_ATTR(HLF_VNC);
650#endif
651 }
652 }
653
654 // handle 'incsearch' and ":s///c" highlighting
655 else if (highlight_match
656 && wp == curwin
657 && lnum >= curwin->w_cursor.lnum
658 && lnum <= curwin->w_cursor.lnum + search_match_lines)
659 {
660 if (lnum == curwin->w_cursor.lnum)
661 getvcol(curwin, &(curwin->w_cursor),
662 (colnr_T *)&fromcol, NULL, NULL);
663 else
664 fromcol = 0;
665 if (lnum == curwin->w_cursor.lnum + search_match_lines)
666 {
667 pos.lnum = lnum;
668 pos.col = search_match_endcol;
669 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
670 }
671 else
672 tocol = MAXCOL;
673 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100674 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200675 tocol = fromcol + 1;
676 area_highlighting = TRUE;
677 vi_attr = HL_ATTR(HLF_I);
678 }
679 }
680
681#ifdef FEAT_DIFF
682 filler_lines = diff_check(wp, lnum);
683 if (filler_lines < 0)
684 {
685 if (filler_lines == -1)
686 {
687 if (diff_find_change(wp, lnum, &change_start, &change_end))
688 diff_hlf = HLF_ADD; // added line
689 else if (change_start == 0)
690 diff_hlf = HLF_TXD; // changed text
691 else
692 diff_hlf = HLF_CHD; // changed line
693 }
694 else
695 diff_hlf = HLF_ADD; // added line
696 filler_lines = 0;
697 area_highlighting = TRUE;
698 }
699 if (lnum == wp->w_topline)
700 filler_lines = wp->w_topfill;
701 filler_todo = filler_lines;
702#endif
703
704#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100705 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000706 if (sign_present)
707 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200708#endif
709
710#ifdef LINE_ATTR
711# ifdef FEAT_SIGNS
712 // If this line has a sign with line highlighting set line_attr.
713 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200714 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200715# endif
716# if defined(FEAT_QUICKFIX)
717 // Highlight the current line in the quickfix window.
718 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
719 line_attr = HL_ATTR(HLF_QFL);
720# endif
721 if (line_attr != 0)
722 area_highlighting = TRUE;
723#endif
724
725 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
726 ptr = line;
727
728#ifdef FEAT_SPELL
729 if (has_spell && !number_only)
730 {
731 // For checking first word with a capital skip white space.
732 if (cap_col == 0)
733 cap_col = getwhitecols(line);
734
735 // To be able to spell-check over line boundaries copy the end of the
736 // current line into nextline[]. Above the start of the next line was
737 // copied to nextline[SPWORDLEN].
738 if (nextline[SPWORDLEN] == NUL)
739 {
740 // No next line or it is empty.
741 nextlinecol = MAXCOL;
742 nextline_idx = 0;
743 }
744 else
745 {
746 v = (long)STRLEN(line);
747 if (v < SPWORDLEN)
748 {
749 // Short line, use it completely and append the start of the
750 // next line.
751 nextlinecol = 0;
752 mch_memmove(nextline, line, (size_t)v);
753 STRMOVE(nextline + v, nextline + SPWORDLEN);
754 nextline_idx = v + 1;
755 }
756 else
757 {
758 // Long line, use only the last SPWORDLEN bytes.
759 nextlinecol = v - SPWORDLEN;
760 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
761 nextline_idx = SPWORDLEN + 1;
762 }
763 }
764 }
765#endif
766
767 if (wp->w_p_list)
768 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100769 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200770 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100771 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100772 || wp->w_lcs_chars.trail
773 || wp->w_lcs_chars.lead
774 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100776
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100778 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200779 {
780 trailcol = (colnr_T)STRLEN(ptr);
781 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
782 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +0100783 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200784 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100785 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +0100786 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100787 {
788 leadcol = 0;
789 while (VIM_ISWHITE(ptr[leadcol]))
790 ++leadcol;
791 if (ptr[leadcol] == NUL)
792 // in a line full of spaces all of them are treated as trailing
793 leadcol = (colnr_T)0;
794 else
795 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +0100796 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100797 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200798 }
799
800 wcr_attr = get_wcr_attr(wp);
801 if (wcr_attr != 0)
802 {
803 win_attr = wcr_attr;
804 area_highlighting = TRUE;
805 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200806
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100807#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200808 if (WIN_IS_POPUP(wp))
809 screen_line_flags |= SLF_POPUP;
810#endif
811
812 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
813 // first character to be displayed.
814 if (wp->w_p_wrap)
815 v = wp->w_skipcol;
816 else
817 v = wp->w_leftcol;
818 if (v > 0 && !number_only)
819 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100820 char_u *prev_ptr = ptr;
821 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +0100822 int charsize = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200823
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100824 init_chartabsize_arg(&cts, wp, lnum, vcol, line, ptr);
825 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200826 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100827 charsize = win_lbr_chartabsize(&cts, NULL);
828 cts.cts_vcol += charsize;
829 prev_ptr = cts.cts_ptr;
830 MB_PTR_ADV(cts.cts_ptr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200831 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100832 vcol = cts.cts_vcol;
833 ptr = cts.cts_ptr;
834 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200835
836 // When:
837 // - 'cuc' is set, or
838 // - 'colorcolumn' is set, or
839 // - 'virtualedit' is set, or
840 // - the visual mode is active,
841 // the end of the line may be before the start of the displayed part.
842 if (vcol < v && (
843#ifdef FEAT_SYN_HL
844 wp->w_p_cuc || draw_color_col ||
845#endif
846 virtual_active() ||
847 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
848 vcol = v;
849
850 // Handle a character that's not completely on the screen: Put ptr at
851 // that character but skip the first few screen characters.
852 if (vcol > v)
853 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100854 vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200855 ptr = prev_ptr;
856 // If the character fits on the screen, don't need to skip it.
857 // Except for a TAB.
Bram Moolenaar7f9969c2022-07-25 18:13:54 +0100858 if (( (*mb_ptr2cells)(ptr) >= charsize || *ptr == TAB) && col == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200859 n_skip = v - vcol;
860 }
861
862 // Adjust for when the inverted text is before the screen,
863 // and when the start of the inverted text is before the screen.
864 if (tocol <= vcol)
865 fromcol = 0;
866 else if (fromcol >= 0 && fromcol < vcol)
867 fromcol = vcol;
868
869#ifdef FEAT_LINEBREAK
870 // When w_skipcol is non-zero, first line needs 'showbreak'
871 if (wp->w_p_wrap)
872 need_showbreak = TRUE;
873#endif
874#ifdef FEAT_SPELL
875 // When spell checking a word we need to figure out the start of the
876 // word and if it's badly spelled or not.
877 if (has_spell)
878 {
879 int len;
880 colnr_T linecol = (colnr_T)(ptr - line);
881 hlf_T spell_hlf = HLF_COUNT;
882
883 pos = wp->w_cursor;
884 wp->w_cursor.lnum = lnum;
885 wp->w_cursor.col = linecol;
886 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
887
888 // spell_move_to() may call ml_get() and make "line" invalid
889 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
890 ptr = line + linecol;
891
892 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
893 {
894 // no bad word found at line start, don't check until end of a
895 // word
896 spell_hlf = HLF_COUNT;
897 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
898 }
899 else
900 {
901 // bad word found, use attributes until end of word
902 word_end = wp->w_cursor.col + len + 1;
903
904 // Turn index into actual attributes.
905 if (spell_hlf != HLF_COUNT)
906 spell_attr = highlight_attr[spell_hlf];
907 }
908 wp->w_cursor = pos;
909
910# ifdef FEAT_SYN_HL
911 // Need to restart syntax highlighting for this line.
912 if (has_syntax)
913 syntax_start(wp, lnum);
914# endif
915 }
916#endif
917 }
918
919 // Correct highlighting for cursor that can't be disabled.
920 // Avoids having to check this for each character.
921 if (fromcol >= 0)
922 {
923 if (noinvcur)
924 {
925 if ((colnr_T)fromcol == wp->w_virtcol)
926 {
927 // highlighting starts at cursor, let it start just after the
928 // cursor
929 fromcol_prev = fromcol;
930 fromcol = -1;
931 }
932 else if ((colnr_T)fromcol < wp->w_virtcol)
933 // restart highlighting after the cursor
934 fromcol_prev = wp->w_virtcol;
935 }
936 if (fromcol >= tocol)
937 fromcol = -1;
938 }
939
940#ifdef FEAT_SEARCH_EXTRA
941 if (!number_only)
942 {
943 v = (long)(ptr - line);
944 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
945 &line, &screen_search_hl,
946 &search_attr);
947 ptr = line + v; // "line" may have been updated
948 }
949#endif
950
951#ifdef FEAT_SYN_HL
952 // Cursor line highlighting for 'cursorline' in the current window.
953 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
954 {
955 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +0000956 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200957 if (!(wp == curwin && VIsual_active)
958 && wp->w_p_culopt_flags != CULOPT_NBR)
959 {
960 cul_screenline = (wp->w_p_wrap
961 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
962
963 // Only set line_attr here when "screenline" is not present in
964 // 'cursorlineopt'. Otherwise it's done later.
965 if (!cul_screenline)
966 {
967 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200968# ifdef FEAT_SIGNS
969 // Combine the 'cursorline' and sign highlighting, depending on
970 // the sign priority.
971 if (sign_present && sattr.sat_linehl > 0)
972 {
973 if (sattr.sat_priority >= 100)
974 line_attr = hl_combine_attr(cul_attr, line_attr);
975 else
976 line_attr = hl_combine_attr(line_attr, cul_attr);
977 }
978 else
979# endif
Bram Moolenaar7fe956d2022-07-03 14:21:09 +0100980# if defined(FEAT_QUICKFIX)
981 line_attr = hl_combine_attr(line_attr, cul_attr);
982# else
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200983 line_attr = cul_attr;
Bram Moolenaar7fe956d2022-07-03 14:21:09 +0100984# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985 }
986 else
987 {
988 line_attr_save = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200989 margin_columns_win(wp, &left_curline_col, &right_curline_col);
990 }
991 area_highlighting = TRUE;
992 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200993 }
994#endif
995
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100996#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200997 {
998 char_u *prop_start;
999
1000 text_prop_count = get_text_props(wp->w_buffer, lnum,
1001 &prop_start, FALSE);
1002 if (text_prop_count > 0)
1003 {
1004 // Make a copy of the properties, so that they are properly
1005 // aligned.
1006 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1007 if (text_props != NULL)
1008 mch_memmove(text_props, prop_start,
1009 text_prop_count * sizeof(textprop_T));
1010
1011 // Allocate an array for the indexes.
1012 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1013 area_highlighting = TRUE;
1014 extra_check = TRUE;
1015 }
1016 }
1017#endif
1018
1019 off = (unsigned)(current_ScreenLine - ScreenLines);
1020 col = 0;
1021
1022#ifdef FEAT_RIGHTLEFT
1023 if (wp->w_p_rl)
1024 {
1025 // Rightleft window: process the text in the normal direction, but put
1026 // it in current_ScreenLine[] from right to left. Start at the
1027 // rightmost column of the window.
1028 col = wp->w_width - 1;
1029 off += col;
1030 screen_line_flags |= SLF_RIGHTLEFT;
1031 }
1032#endif
1033
1034 // Repeat for the whole displayed line.
1035 for (;;)
1036 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001037 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001038#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001039 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001040#endif
1041#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001042 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001043#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001044
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045 // Skip this quickly when working on the text.
1046 if (draw_state != WL_LINE)
1047 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001048#ifdef FEAT_SYN_HL
1049 if (cul_screenline)
1050 {
1051 cul_attr = 0;
1052 line_attr = line_attr_save;
1053 }
1054#endif
1055
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001056#ifdef FEAT_CMDWIN
1057 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1058 {
1059 draw_state = WL_CMDLINE;
1060 if (cmdwin_type != 0 && wp == curwin)
1061 {
1062 // Draw the cmdline character.
1063 n_extra = 1;
1064 c_extra = cmdwin_type;
1065 c_final = NUL;
1066 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1067 }
1068 }
1069#endif
1070
1071#ifdef FEAT_FOLDING
1072 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1073 {
1074 int fdc = compute_foldcolumn(wp, 0);
1075
1076 draw_state = WL_FOLD;
1077 if (fdc > 0)
1078 {
1079 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1080 // already be in use.
1081 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001082 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 if (p_extra_free != NULL)
1084 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001085 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001086 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001087 p_extra_free[n_extra] = NUL;
1088 p_extra = p_extra_free;
1089 c_extra = NUL;
1090 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001091 if (use_cursor_line_sign(wp, lnum))
1092 char_attr =
1093 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1094 else
1095 char_attr =
1096 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001097 }
1098 }
1099 }
1100#endif
1101
1102#ifdef FEAT_SIGNS
1103 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1104 {
1105 draw_state = WL_SIGN;
1106 // Show the sign column when there are any signs in this
1107 // buffer or when using Netbeans.
1108 if (signcolumn_on(wp))
1109 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1110 row, startrow, filler_lines, filler_todo, &c_extra,
1111 &c_final, extra, &p_extra, &n_extra, &char_attr);
1112 }
1113#endif
1114
1115 if (draw_state == WL_NR - 1 && n_extra == 0)
1116 {
1117 draw_state = WL_NR;
1118 // Display the absolute or relative line number. After the
1119 // first fill with blanks when the 'n' flag isn't in 'cpo'
1120 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001121 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001122 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1123 {
1124#ifdef FEAT_SIGNS
1125 // If 'signcolumn' is set to 'number' and a sign is present
1126 // in 'lnum', then display the sign instead of the line
1127 // number.
1128 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1129 && sign_present)
1130 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1131 row, startrow, filler_lines, filler_todo,
1132 &c_extra, &c_final, extra, &p_extra, &n_extra,
1133 &char_attr);
1134 else
1135#endif
1136 {
1137 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001138 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001139 {
1140 long num;
1141 char *fmt = "%*ld ";
1142
1143 if (wp->w_p_nu && !wp->w_p_rnu)
1144 // 'number' + 'norelativenumber'
1145 num = (long)lnum;
1146 else
1147 {
1148 // 'relativenumber', don't use negative numbers
1149 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1150 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1151 {
1152 // 'number' + 'relativenumber'
1153 num = lnum;
1154 fmt = "%-*ld ";
1155 }
1156 }
1157
1158 sprintf((char *)extra, fmt,
1159 number_width(wp), num);
1160 if (wp->w_skipcol > 0)
1161 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1162 *p_extra = '-';
1163#ifdef FEAT_RIGHTLEFT
1164 if (wp->w_p_rl) // reverse line numbers
1165 {
1166 char_u *p1, *p2;
1167 int t;
1168
1169 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001170 p2 = skipwhite(extra);
1171 p2 = skiptowhite(p2) - 1;
1172 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173 {
1174 t = *p1;
1175 *p1 = *p2;
1176 *p2 = t;
1177 }
1178 }
1179#endif
1180 p_extra = extra;
1181 c_extra = NUL;
1182 c_final = NUL;
1183 }
1184 else
1185 {
1186 c_extra = ' ';
1187 c_final = NUL;
1188 }
1189 n_extra = number_width(wp) + 1;
1190 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1191#ifdef FEAT_SYN_HL
1192 // When 'cursorline' is set highlight the line number of
1193 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001194 // When 'cursorlineopt' does not have "line" only
1195 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 // TODO: Can we use CursorLine instead of CursorLineNr
1197 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001198 if (wp->w_p_cul
1199 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001200 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001201 && (row == startrow + filler_lines
1202 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001203 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1205#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001206 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1207 && HL_ATTR(HLF_LNA) != 0)
1208 // Use LineNrAbove
1209 char_attr = hl_combine_attr(wcr_attr,
1210 HL_ATTR(HLF_LNA));
1211 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1212 && HL_ATTR(HLF_LNB) != 0)
1213 // Use LineNrBelow
1214 char_attr = hl_combine_attr(wcr_attr,
1215 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 }
James McCoya80aad72021-12-22 19:45:28 +00001217#ifdef FEAT_SIGNS
1218 if (num_attr)
1219 char_attr = num_attr;
1220#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 }
1222 }
1223
1224#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001225 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001226 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001227 // draw indent after showbreak value
1228 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001229 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 // After the showbreak, draw the breakindent
1231 draw_state = WL_BRI - 1;
1232
1233 // draw 'breakindent': indent wrapped text accordingly
1234 if (draw_state == WL_BRI - 1 && n_extra == 0)
1235 {
1236 draw_state = WL_BRI;
1237 // if need_showbreak is set, breakindent also applies
Bram Moolenaarfe154992022-03-22 20:42:12 +00001238 if (wp->w_p_bri && (row != startrow || need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239# ifdef FEAT_DIFF
1240 && filler_lines == 0
1241# endif
1242 )
1243 {
1244 char_attr = 0;
1245# ifdef FEAT_DIFF
1246 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001247 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248# endif
1249 p_extra = NULL;
1250 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001251 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001252 n_extra = get_breakindent_win(wp,
1253 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001254 if (row == startrow)
1255 {
1256 n_extra -= win_col_off2(wp);
1257 if (n_extra < 0)
1258 n_extra = 0;
1259 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001260 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001261 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001262 // Correct end of highlighted area for 'breakindent',
1263 // required when 'linebreak' is also set.
1264 if (tocol == vcol)
1265 tocol += n_extra;
1266 }
1267 }
1268#endif
1269
1270#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1271 if (draw_state == WL_SBR - 1 && n_extra == 0)
1272 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001273 char_u *sbr;
1274
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001275 draw_state = WL_SBR;
1276# ifdef FEAT_DIFF
1277 if (filler_todo > 0)
1278 {
1279 // Draw "deleted" diff line(s).
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001280 if (char2cells(wp->w_fill_chars.diff) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281 {
1282 c_extra = '-';
1283 c_final = NUL;
1284 }
1285 else
1286 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001287 c_extra = wp->w_fill_chars.diff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001288 c_final = NUL;
1289 }
1290# ifdef FEAT_RIGHTLEFT
1291 if (wp->w_p_rl)
1292 n_extra = col + 1;
1293 else
1294# endif
1295 n_extra = wp->w_width - col;
1296 char_attr = HL_ATTR(HLF_DED);
1297 }
1298# endif
1299# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001300 sbr = get_showbreak_value(wp);
1301 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001302 {
1303 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001304 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 c_extra = NUL;
1306 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001307 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001308 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1309 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001310 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001311 // Correct end of highlighted area for 'showbreak',
1312 // required when 'linebreak' is also set.
1313 if (tocol == vcol)
1314 tocol += n_extra;
1315 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001316 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001317# ifdef FEAT_SYN_HL
1318 // combine 'showbreak' with 'cursorline'
1319 if (cul_attr != 0)
1320 char_attr = hl_combine_attr(char_attr, cul_attr);
1321# endif
1322 }
1323# endif
1324 }
1325#endif
1326
1327 if (draw_state == WL_LINE - 1 && n_extra == 0)
1328 {
1329 draw_state = WL_LINE;
1330 if (saved_n_extra)
1331 {
1332 // Continue item from end of wrapped line.
1333 n_extra = saved_n_extra;
1334 c_extra = saved_c_extra;
1335 c_final = saved_c_final;
1336 p_extra = saved_p_extra;
1337 char_attr = saved_char_attr;
1338 }
1339 else
1340 char_attr = win_attr;
1341 }
1342 }
1343#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001344 if (cul_screenline && draw_state == WL_LINE
1345 && vcol >= left_curline_col
1346 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001348 cul_attr = HL_ATTR(HLF_CUL);
1349 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001350 }
1351#endif
1352
1353 // When still displaying '$' of change command, stop at cursor.
1354 // When only displaying the (relative) line number and that's done,
1355 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001356 if (((dollar_vcol >= 0 && wp == curwin
1357 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1358 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359#ifdef FEAT_DIFF
1360 && filler_todo <= 0
1361#endif
1362 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001363 {
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01001364 screen_line(wp, screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001365 screen_line_flags);
1366 // Pretend we have finished updating the window. Except when
1367 // 'cursorcolumn' is set.
1368#ifdef FEAT_SYN_HL
1369 if (wp->w_p_cuc)
1370 row = wp->w_cline_row + wp->w_cline_height;
1371 else
1372#endif
1373 row = wp->w_height;
1374 break;
1375 }
1376
Bram Moolenaar34390282019-10-16 14:38:26 +02001377 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001378 {
1379 // handle Visual or match highlighting in this line
1380 if (vcol == fromcol
1381 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1382 && (*mb_ptr2cells)(ptr) > 1)
1383 || ((int)vcol_prev == fromcol_prev
1384 && vcol_prev < vcol // not at margin
1385 && vcol < tocol))
1386 area_attr = vi_attr; // start highlighting
1387 else if (area_attr != 0
1388 && (vcol == tocol
1389 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1390 area_attr = 0; // stop highlighting
1391
1392#ifdef FEAT_SEARCH_EXTRA
1393 if (!n_extra)
1394 {
1395 // Check for start/end of 'hlsearch' and other matches.
1396 // After end, check for start/end of next match.
1397 // When another match, have to check for start again.
1398 v = (long)(ptr - line);
1399 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1400 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001401 &match_conc, did_line_attr, lcs_eol_one,
1402 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 ptr = line + v; // "line" may have been changed
Bram Moolenaarb9081882022-07-09 04:56:24 +01001404 prev_ptr = ptr;
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001405
1406 // Do not allow a conceal over EOL otherwise EOL will be missed
1407 // and bad things happen.
1408 if (*ptr == NUL)
1409 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 }
1411#endif
1412
1413#ifdef FEAT_DIFF
1414 if (diff_hlf != (hlf_T)0)
1415 {
1416 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1417 && n_extra == 0)
1418 diff_hlf = HLF_TXD; // changed text
1419 if (diff_hlf == HLF_TXD && ptr - line > change_end
1420 && n_extra == 0)
1421 diff_hlf = HLF_CHD; // changed line
1422 line_attr = HL_ATTR(diff_hlf);
1423 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1424 && wp->w_p_culopt_flags != CULOPT_NBR
1425 && (!cul_screenline || (vcol >= left_curline_col
1426 && vcol <= right_curline_col)))
1427 line_attr = hl_combine_attr(
1428 line_attr, HL_ATTR(HLF_CUL));
1429 }
1430#endif
1431
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001432#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001433 if (text_props != NULL)
1434 {
1435 int pi;
1436 int bcol = (int)(ptr - line);
1437
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001438 if (n_extra > 0
1439# ifdef FEAT_LINEBREAK
1440 && !in_linebreak
1441# endif
1442 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001443 --bcol; // still working on the previous char, e.g. Tab
1444
1445 // Check if any active property ends.
1446 for (pi = 0; pi < text_props_active; ++pi)
1447 {
1448 int tpi = text_prop_idxs[pi];
1449
1450 if (bcol >= text_props[tpi].tp_col - 1
1451 + text_props[tpi].tp_len)
1452 {
1453 if (pi + 1 < text_props_active)
1454 mch_memmove(text_prop_idxs + pi,
1455 text_prop_idxs + pi + 1,
1456 sizeof(int)
1457 * (text_props_active - (pi + 1)));
1458 --text_props_active;
1459 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001460# ifdef FEAT_LINEBREAK
1461 // not exactly right but should work in most cases
1462 if (in_linebreak && syntax_attr == text_prop_attr)
1463 syntax_attr = 0;
1464# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465 }
1466 }
1467
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001468# ifdef FEAT_LINEBREAK
1469 if (n_extra > 0 && in_linebreak)
1470 // not on the next char yet, don't start another prop
1471 --bcol;
1472# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473 // Add any text property that starts in this column.
1474 while (text_prop_next < text_prop_count
1475 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001476 {
1477 if (bcol <= text_props[text_prop_next].tp_col - 1
1478 + text_props[text_prop_next].tp_len)
1479 text_prop_idxs[text_props_active++] = text_prop_next;
1480 ++text_prop_next;
1481 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482
1483 text_prop_attr = 0;
1484 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001485 text_prop_type = NULL;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001486 text_prop_id = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487 if (text_props_active > 0)
1488 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001489 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001490 int used_attr = 0;
1491
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001492 // Sort the properties on priority and/or starting last.
1493 // Then combine the attributes, highest priority last.
1494 current_text_props = text_props;
1495 current_buf = wp->w_buffer;
1496 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1497 sizeof(int), text_prop_compare);
1498
1499 for (pi = 0; pi < text_props_active; ++pi)
1500 {
1501 int tpi = text_prop_idxs[pi];
1502 proptype_T *pt = text_prop_type_by_id(
1503 wp->w_buffer, text_props[tpi].tp_type);
1504
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001505 if (pt != NULL && pt->pt_hl_id > 0
1506 && text_props[tpi].tp_id != -MAXCOL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001508 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001509 text_prop_type = pt;
1510 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001511 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001513 text_prop_id = text_props[tpi].tp_id;
1514 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 }
1516 }
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01001517 if (n_extra == 0 && text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001518 && -text_prop_id
1519 <= wp->w_buffer->b_textprop_text.ga_len)
1520 {
1521 char_u *p = ((char_u **)wp->w_buffer
1522 ->b_textprop_text.ga_data)[
1523 -text_prop_id - 1];
1524 if (p != NULL)
1525 {
1526 p_extra = p;
Bram Moolenaar711483c2022-07-30 21:33:46 +01001527 c_extra = NUL;
1528 c_final = NUL;
Mike Williams04947892022-07-26 16:03:42 +01001529 n_extra = (int)STRLEN(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001530 extra_attr = used_attr;
1531 n_attr = n_extra;
1532 text_prop_attr = 0;
1533
1534 // If the cursor is on or after this position,
1535 // move it forward.
1536 if (wp == curwin
1537 && lnum == curwin->w_cursor.lnum
1538 && curwin->w_cursor.col >= vcol)
1539 curwin->w_cursor.col += n_extra;
1540 }
1541 // reset the ID in the copy to avoid it being used
1542 // again
1543 text_props[used_tpi].tp_id = -MAXCOL;
1544 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 }
1546 }
1547#endif
1548
Bram Moolenaara74fda62019-10-19 17:38:03 +02001549#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001550 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001551 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001552 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001553# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001554 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001555 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001556# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001557 // Get syntax attribute.
1558 if (has_syntax)
1559 {
1560 // Get the syntax attribute for the character. If there
1561 // is an error, disable syntax highlighting.
1562 save_did_emsg = did_emsg;
1563 did_emsg = FALSE;
1564
1565 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001566 if (v == prev_syntax_col)
1567 // at same column again
1568 syntax_attr = prev_syntax_attr;
1569 else
1570 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001571# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001572 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001573# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001574 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001575# ifdef FEAT_SPELL
1576 has_spell ? &can_spell :
1577# endif
1578 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001579 prev_syntax_col = v;
1580 prev_syntax_attr = syntax_attr;
1581 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001582
Bram Moolenaar34390282019-10-16 14:38:26 +02001583 if (did_emsg)
1584 {
1585 wp->w_s->b_syn_error = TRUE;
1586 has_syntax = FALSE;
1587 syntax_attr = 0;
1588 }
1589 else
1590 did_emsg = save_did_emsg;
1591# ifdef SYN_TIME_LIMIT
1592 if (wp->w_s->b_syn_slow)
1593 has_syntax = FALSE;
1594# endif
1595
1596 // Need to get the line again, a multi-line regexp may
1597 // have made it invalid.
1598 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1599 ptr = line + v;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001600 prev_ptr = ptr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001601# ifdef FEAT_CONCEAL
1602 // no concealing past the end of the line, it interferes
1603 // with line highlighting
1604 if (*ptr == NUL)
1605 syntax_flags = 0;
1606 else
1607 syntax_flags = get_syntax_info(&syntax_seqnr);
1608# endif
1609 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001610 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001611# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001612 // Combine text property highlight into syntax highlight.
1613 if (text_prop_type != NULL)
1614 {
1615 if (text_prop_combine)
1616 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1617 else
1618 syntax_attr = text_prop_attr;
1619 }
1620# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001621#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001622
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 // Decide which of the highlight attributes to use.
1624 attr_pri = TRUE;
1625#ifdef LINE_ATTR
1626 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001627 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001629 if (!highlight_match)
1630 // let search highlight show in Visual area if possible
1631 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001632# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001633 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001634# endif
1635 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001636 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001637 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001638 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001639# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001640 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001641# endif
1642 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1644 || vcol < fromcol || vcol_prev < fromcol_prev
1645 || vcol >= tocol))
1646 {
1647 // Use line_attr when not in the Visual or 'incsearch' area
1648 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001649# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001650 char_attr = hl_combine_attr(syntax_attr, line_attr);
1651# else
1652 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001653# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001654 attr_pri = FALSE;
1655 }
1656#else
1657 if (area_attr != 0)
1658 char_attr = area_attr;
1659 else if (search_attr != 0)
1660 char_attr = search_attr;
1661#endif
1662 else
1663 {
1664 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001665#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001666 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001667#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001668 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001669#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001670 }
1671 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001672
1673 // combine attribute with 'wincolor'
1674 if (win_attr != 0)
1675 {
1676 if (char_attr == 0)
1677 char_attr = win_attr;
1678 else
1679 char_attr = hl_combine_attr(win_attr, char_attr);
1680 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001681
1682 // Get the next character to put on the screen.
1683
1684 // The "p_extra" points to the extra stuff that is inserted to
1685 // represent special characters (non-printable stuff) and other
1686 // things. When all characters are the same, c_extra is used.
1687 // If c_final is set, it will compulsorily be used at the end.
1688 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1689 // "p_extra[n_extra]".
1690 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1691 if (n_extra > 0)
1692 {
1693 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1694 {
1695 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1696 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1697 if (enc_utf8 && utf_char2len(c) > 1)
1698 {
1699 mb_utf8 = TRUE;
1700 u8cc[0] = 0;
1701 c = 0xc0;
1702 }
1703 else
1704 mb_utf8 = FALSE;
1705 }
1706 else
1707 {
1708 c = *p_extra;
1709 if (has_mbyte)
1710 {
1711 mb_c = c;
1712 if (enc_utf8)
1713 {
1714 // If the UTF-8 character is more than one byte:
1715 // Decode it into "mb_c".
1716 mb_l = utfc_ptr2len(p_extra);
1717 mb_utf8 = FALSE;
1718 if (mb_l > n_extra)
1719 mb_l = 1;
1720 else if (mb_l > 1)
1721 {
1722 mb_c = utfc_ptr2char(p_extra, u8cc);
1723 mb_utf8 = TRUE;
1724 c = 0xc0;
1725 }
1726 }
1727 else
1728 {
1729 // if this is a DBCS character, put it in "mb_c"
1730 mb_l = MB_BYTE2LEN(c);
1731 if (mb_l >= n_extra)
1732 mb_l = 1;
1733 else if (mb_l > 1)
1734 mb_c = (c << 8) + p_extra[1];
1735 }
1736 if (mb_l == 0) // at the NUL at end-of-line
1737 mb_l = 1;
1738
1739 // If a double-width char doesn't fit display a '>' in the
1740 // last column.
1741 if ((
1742# ifdef FEAT_RIGHTLEFT
1743 wp->w_p_rl ? (col <= 0) :
1744# endif
1745 (col >= wp->w_width - 1))
1746 && (*mb_char2cells)(mb_c) == 2)
1747 {
1748 c = '>';
1749 mb_c = c;
1750 mb_l = 1;
1751 mb_utf8 = FALSE;
1752 multi_attr = HL_ATTR(HLF_AT);
1753#ifdef FEAT_SYN_HL
1754 if (cul_attr)
1755 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1756#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001757 multi_attr = hl_combine_attr(win_attr, multi_attr);
1758
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759 // put the pointer back to output the double-width
1760 // character at the start of the next line.
1761 ++n_extra;
1762 --p_extra;
1763 }
1764 else
1765 {
1766 n_extra -= mb_l - 1;
1767 p_extra += mb_l - 1;
1768 }
1769 }
1770 ++p_extra;
1771 }
1772 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001773#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001774 if (n_extra <= 0)
1775 in_linebreak = FALSE;
1776#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001777 }
1778 else
1779 {
1780#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01001781 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001783 VIM_CLEAR(p_extra_free);
Bram Moolenaarb9081882022-07-09 04:56:24 +01001784 prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001785
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786 // Get a character from the line itself.
1787 c = *ptr;
1788#ifdef FEAT_LINEBREAK
1789 c0 = *ptr;
1790#endif
1791 if (has_mbyte)
1792 {
1793 mb_c = c;
1794 if (enc_utf8)
1795 {
1796 // If the UTF-8 character is more than one byte: Decode it
1797 // into "mb_c".
1798 mb_l = utfc_ptr2len(ptr);
1799 mb_utf8 = FALSE;
1800 if (mb_l > 1)
1801 {
1802 mb_c = utfc_ptr2char(ptr, u8cc);
1803 // Overlong encoded ASCII or ASCII with composing char
1804 // is displayed normally, except a NUL.
1805 if (mb_c < 0x80)
1806 {
1807 c = mb_c;
1808#ifdef FEAT_LINEBREAK
1809 c0 = mb_c;
1810#endif
1811 }
1812 mb_utf8 = TRUE;
1813
1814 // At start of the line we can have a composing char.
1815 // Draw it as a space with a composing char.
1816 if (utf_iscomposing(mb_c))
1817 {
1818 int i;
1819
1820 for (i = Screen_mco - 1; i > 0; --i)
1821 u8cc[i] = u8cc[i - 1];
1822 u8cc[0] = mb_c;
1823 mb_c = ' ';
1824 }
1825 }
1826
1827 if ((mb_l == 1 && c >= 0x80)
1828 || (mb_l >= 1 && mb_c == 0)
1829 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1830 {
1831 // Illegal UTF-8 byte: display as <xx>.
1832 // Non-BMP character : display as ? or fullwidth ?.
1833 transchar_hex(extra, mb_c);
1834# ifdef FEAT_RIGHTLEFT
1835 if (wp->w_p_rl) // reverse
1836 rl_mirror(extra);
1837# endif
1838 p_extra = extra;
1839 c = *p_extra;
1840 mb_c = mb_ptr2char_adv(&p_extra);
1841 mb_utf8 = (c >= 0x80);
1842 n_extra = (int)STRLEN(p_extra);
1843 c_extra = NUL;
1844 c_final = NUL;
1845 if (area_attr == 0 && search_attr == 0)
1846 {
1847 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001848 extra_attr = hl_combine_attr(
1849 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 saved_attr2 = char_attr; // save current attr
1851 }
1852 }
1853 else if (mb_l == 0) // at the NUL at end-of-line
1854 mb_l = 1;
1855#ifdef FEAT_ARABIC
1856 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1857 {
1858 // Do Arabic shaping.
1859 int pc, pc1, nc;
1860 int pcc[MAX_MCO];
1861
1862 // The idea of what is the previous and next
1863 // character depends on 'rightleft'.
1864 if (wp->w_p_rl)
1865 {
1866 pc = prev_c;
1867 pc1 = prev_c1;
1868 nc = utf_ptr2char(ptr + mb_l);
1869 prev_c1 = u8cc[0];
1870 }
1871 else
1872 {
1873 pc = utfc_ptr2char(ptr + mb_l, pcc);
1874 nc = prev_c;
1875 pc1 = pcc[0];
1876 }
1877 prev_c = mb_c;
1878
1879 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1880 }
1881 else
1882 prev_c = mb_c;
1883#endif
1884 }
1885 else // enc_dbcs
1886 {
1887 mb_l = MB_BYTE2LEN(c);
1888 if (mb_l == 0) // at the NUL at end-of-line
1889 mb_l = 1;
1890 else if (mb_l > 1)
1891 {
1892 // We assume a second byte below 32 is illegal.
1893 // Hopefully this is OK for all double-byte encodings!
1894 if (ptr[1] >= 32)
1895 mb_c = (c << 8) + ptr[1];
1896 else
1897 {
1898 if (ptr[1] == NUL)
1899 {
1900 // head byte at end of line
1901 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001902 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 }
1904 else
1905 {
1906 // illegal tail byte
1907 mb_l = 2;
1908 STRCPY(extra, "XX");
1909 }
1910 p_extra = extra;
1911 n_extra = (int)STRLEN(extra) - 1;
1912 c_extra = NUL;
1913 c_final = NUL;
1914 c = *p_extra++;
1915 if (area_attr == 0 && search_attr == 0)
1916 {
1917 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001918 extra_attr = hl_combine_attr(
1919 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001920 saved_attr2 = char_attr; // save current attr
1921 }
1922 mb_c = c;
1923 }
1924 }
1925 }
1926 // If a double-width char doesn't fit display a '>' in the
1927 // last column; the character is displayed at the start of the
1928 // next line.
1929 if ((
1930# ifdef FEAT_RIGHTLEFT
1931 wp->w_p_rl ? (col <= 0) :
1932# endif
1933 (col >= wp->w_width - 1))
1934 && (*mb_char2cells)(mb_c) == 2)
1935 {
1936 c = '>';
1937 mb_c = c;
1938 mb_utf8 = FALSE;
1939 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001940 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 // Put pointer back so that the character will be
1942 // displayed at the start of the next line.
1943 --ptr;
1944#ifdef FEAT_CONCEAL
1945 did_decrement_ptr = TRUE;
1946#endif
1947 }
1948 else if (*ptr != NUL)
1949 ptr += mb_l - 1;
1950
1951 // If a double-width char doesn't fit at the left side display
1952 // a '<' in the first column. Don't do this for unprintable
1953 // characters.
1954 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1955 {
1956 n_extra = 1;
1957 c_extra = MB_FILLER_CHAR;
1958 c_final = NUL;
1959 c = ' ';
1960 if (area_attr == 0 && search_attr == 0)
1961 {
1962 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001963 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001964 saved_attr2 = char_attr; // save current attr
1965 }
1966 mb_c = c;
1967 mb_utf8 = FALSE;
1968 mb_l = 1;
1969 }
1970
1971 }
1972 ++ptr;
1973
1974 if (extra_check)
1975 {
1976#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 // Check spelling (unless at the end of the line).
1978 // Only do this when there is no syntax highlighting, the
1979 // @Spell cluster is not used or the current syntax item
1980 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001981 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 if (has_spell && v >= word_end && v > cur_checked_col)
1983 {
1984 spell_attr = 0;
1985 if (c != 0 && (
1986# ifdef FEAT_SYN_HL
1987 !has_syntax ||
1988# endif
1989 can_spell))
1990 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01001991 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 int len;
1993 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001994
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997
1998 // Use nextline[] if possible, it has the start of the
1999 // next line concatenated.
2000 if ((prev_ptr - line) - nextlinecol >= 0)
2001 p = nextline + (prev_ptr - line) - nextlinecol;
2002 else
2003 p = prev_ptr;
2004 cap_col -= (int)(prev_ptr - line);
2005 len = spell_check(wp, p, &spell_hlf, &cap_col,
2006 nochange);
2007 word_end = v + len;
2008
2009 // In Insert mode only highlight a word that
2010 // doesn't touch the cursor.
2011 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002012 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 && wp->w_cursor.lnum == lnum
2014 && wp->w_cursor.col >=
2015 (colnr_T)(prev_ptr - line)
2016 && wp->w_cursor.col < (colnr_T)word_end)
2017 {
2018 spell_hlf = HLF_COUNT;
2019 spell_redraw_lnum = lnum;
2020 }
2021
2022 if (spell_hlf == HLF_COUNT && p != prev_ptr
2023 && (p - nextline) + len > nextline_idx)
2024 {
2025 // Remember that the good word continues at the
2026 // start of the next line.
2027 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002028 checked_col = (int)((p - nextline)
2029 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030 }
2031
2032 // Turn index into actual attributes.
2033 if (spell_hlf != HLF_COUNT)
2034 spell_attr = highlight_attr[spell_hlf];
2035
2036 if (cap_col > 0)
2037 {
2038 if (p != prev_ptr
2039 && (p - nextline) + cap_col >= nextline_idx)
2040 {
2041 // Remember that the word in the next line
2042 // must start with a capital.
2043 capcol_lnum = lnum + 1;
2044 cap_col = (int)((p - nextline) + cap_col
2045 - nextline_idx);
2046 }
2047 else
2048 // Compute the actual column.
2049 cap_col += (int)(prev_ptr - line);
2050 }
2051 }
2052 }
2053 if (spell_attr != 0)
2054 {
2055 if (!attr_pri)
2056 char_attr = hl_combine_attr(char_attr, spell_attr);
2057 else
2058 char_attr = hl_combine_attr(spell_attr, char_attr);
2059 }
2060#endif
2061#ifdef FEAT_LINEBREAK
2062 // Found last space before word: check for line break.
2063 if (wp->w_p_lbr && c0 == c
2064 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2065 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002066 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2067 : 0;
2068 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002069 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002071 init_chartabsize_arg(&cts, wp, lnum, vcol, line, p);
2072 n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002073
2074 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002075 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002076 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002077 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002078 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002079 if (n_extra < 0)
2080 n_extra = 0;
2081 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002082 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002083 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002084 // line break, but for TABs the highlighting should
2085 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002086 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002087
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002088 if (c == TAB && n_extra + col > wp->w_width)
2089# ifdef FEAT_VARTABS
2090 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2091 wp->w_buffer->b_p_vts_array) - 1;
2092# else
2093 n_extra = (int)wp->w_buffer->b_p_ts
2094 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2095# endif
2096
2097 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2098 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002099# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002100 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002101 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002102# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002103 if (VIM_ISWHITE(c))
2104 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002105# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002106 if (c == TAB)
2107 // See "Tab alignment" below.
2108 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002109# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 if (!wp->w_p_list)
2111 c = ' ';
2112 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002113 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002114 }
2115#endif
2116
zeertzjqf14b8ba2021-09-10 16:58:30 +02002117 in_multispace = c == ' '
2118 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2119 if (!in_multispace)
2120 multispace_pos = 0;
2121
Bram Moolenaareed9d462021-02-15 20:38:25 +01002122 // 'list': Change char 160 to 'nbsp' and space to 'space'
2123 // setting in 'listchars'. But not when the character is
2124 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 if (wp->w_p_list
2126 && ((((c == 160 && mb_l == 1)
2127 || (mb_utf8
2128 && ((mb_c == 160 && mb_l == 2)
2129 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002130 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002131 || (c == ' '
2132 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002133 && (wp->w_lcs_chars.space
2134 || (in_multispace
2135 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002136 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137 && ptr - line <= trailcol)))
2138 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002139 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2140 {
2141 c = wp->w_lcs_chars.multispace[multispace_pos++];
2142 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2143 multispace_pos = 0;
2144 }
2145 else
2146 c = (c == ' ') ? wp->w_lcs_chars.space
2147 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002148 if (area_attr == 0 && search_attr == 0)
2149 {
2150 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002151 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002152 saved_attr2 = char_attr; // save current attr
2153 }
2154 mb_c = c;
2155 if (enc_utf8 && utf_char2len(c) > 1)
2156 {
2157 mb_utf8 = TRUE;
2158 u8cc[0] = 0;
2159 c = 0xc0;
2160 }
2161 else
2162 mb_utf8 = FALSE;
2163 }
2164
zeertzjq2e7cba32022-06-10 15:30:32 +01002165 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
2166 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002168 if (leadcol != 0 && in_multispace && ptr < line + leadcol
2169 && wp->w_lcs_chars.leadmultispace != NULL)
2170 {
2171 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01002172 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
2173 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002174 multispace_pos = 0;
2175 }
2176
2177 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
2178 c = wp->w_lcs_chars.trail;
2179
2180 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
2181 c = wp->w_lcs_chars.lead;
2182
zeertzjq2e7cba32022-06-10 15:30:32 +01002183 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01002184 c = wp->w_lcs_chars.space;
2185
2186
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002187 if (!attr_pri)
2188 {
2189 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002190 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191 saved_attr2 = char_attr; // save current attr
2192 }
2193 mb_c = c;
2194 if (enc_utf8 && utf_char2len(c) > 1)
2195 {
2196 mb_utf8 = TRUE;
2197 u8cc[0] = 0;
2198 c = 0xc0;
2199 }
2200 else
2201 mb_utf8 = FALSE;
2202 }
2203 }
2204
2205 // Handling of non-printable characters.
2206 if (!vim_isprintc(c))
2207 {
2208 // when getting a character from the file, we may have to
2209 // turn it into something else on the way to putting it
2210 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002211 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 {
2213 int tab_len = 0;
2214 long vcol_adjusted = vcol; // removed showbreak length
2215#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002216 char_u *sbr = get_showbreak_value(wp);
2217
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 // only adjust the tab_len, when at the first column
2219 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002220 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2221 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002222#endif
2223 // tab amount depends on current column
2224#ifdef FEAT_VARTABS
2225 tab_len = tabstop_padding(vcol_adjusted,
2226 wp->w_buffer->b_p_ts,
2227 wp->w_buffer->b_p_vts_array) - 1;
2228#else
2229 tab_len = (int)wp->w_buffer->b_p_ts
2230 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2231#endif
2232
2233#ifdef FEAT_LINEBREAK
2234 if (!wp->w_p_lbr || !wp->w_p_list)
2235#endif
2236 // tab amount depends on current column
2237 n_extra = tab_len;
2238#ifdef FEAT_LINEBREAK
2239 else
2240 {
2241 char_u *p;
2242 int len;
2243 int i;
2244 int saved_nextra = n_extra;
2245
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002246# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002247 if (vcol_off > 0)
2248 // there are characters to conceal
2249 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002250
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002251 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002252 if (wp->w_p_list && wp->w_lcs_chars.tab1
2253 && old_boguscols > 0
2254 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002255 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002256# endif
2257 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002258 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002259 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002260 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002261 if (wp->w_lcs_chars.tab3)
2262 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 if (n_extra > 0)
2264 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002265 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002266 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002267 if (p == NULL)
2268 n_extra = 0;
2269 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002271 vim_memset(p, ' ', len);
2272 p[len] = NUL;
2273 vim_free(p_extra_free);
2274 p_extra_free = p;
2275 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002276 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002277 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002278
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002279 if (*p == NUL)
2280 {
2281 tab_len = i;
2282 break;
2283 }
2284
2285 // if tab3 is given, use it for the last char
2286 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2287 lcs = wp->w_lcs_chars.tab3;
2288 p += mb_char2bytes(lcs, p);
2289 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002290 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002291 }
2292 p_extra = p_extra_free;
2293# ifdef FEAT_CONCEAL
2294 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2295 // macro below, so need to adjust for that here
2296 if (vcol_off > 0)
2297 n_extra -= vcol_off;
2298# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002299 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002300 }
2301#endif
2302#ifdef FEAT_CONCEAL
2303 {
2304 int vc_saved = vcol_off;
2305
2306 // Tab alignment should be identical regardless of
2307 // 'conceallevel' value. So tab compensates of all
2308 // previous concealed characters, and thus resets
2309 // vcol_off and boguscols accumulated so far in the
2310 // line. Note that the tab can be longer than
2311 // 'tabstop' when there are concealed characters.
2312 FIX_FOR_BOGUSCOLS;
2313
2314 // Make sure, the highlighting for the tab char will be
2315 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002316 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002317 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002318 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 tab_len += vc_saved;
2320 }
2321#endif
2322 mb_utf8 = FALSE; // don't draw as UTF-8
2323 if (wp->w_p_list)
2324 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002325 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2326 ? wp->w_lcs_chars.tab3
2327 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328#ifdef FEAT_LINEBREAK
2329 if (wp->w_p_lbr)
2330 c_extra = NUL; // using p_extra from above
2331 else
2332#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002333 c_extra = wp->w_lcs_chars.tab2;
2334 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002336 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 saved_attr2 = char_attr; // save current attr
2338 mb_c = c;
2339 if (enc_utf8 && utf_char2len(c) > 1)
2340 {
2341 mb_utf8 = TRUE;
2342 u8cc[0] = 0;
2343 c = 0xc0;
2344 }
2345 }
2346 else
2347 {
2348 c_final = NUL;
2349 c_extra = ' ';
2350 c = ' ';
2351 }
2352 }
2353 else if (c == NUL
2354 && (wp->w_p_list
2355 || ((fromcol >= 0 || fromcol_prev >= 0)
2356 && tocol > vcol
2357 && VIsual_mode != Ctrl_V
2358 && (
2359# ifdef FEAT_RIGHTLEFT
2360 wp->w_p_rl ? (col >= 0) :
2361# endif
2362 (col < wp->w_width))
2363 && !(noinvcur
2364 && lnum == wp->w_cursor.lnum
2365 && (colnr_T)vcol == wp->w_virtcol)))
2366 && lcs_eol_one > 0)
2367 {
2368 // Display a '$' after the line or highlight an extra
2369 // character if the line break is included.
2370#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2371 // For a diff line the highlighting continues after the
2372 // "$".
2373 if (
2374# ifdef FEAT_DIFF
2375 diff_hlf == (hlf_T)0
2376# ifdef LINE_ATTR
2377 &&
2378# endif
2379# endif
2380# ifdef LINE_ATTR
2381 line_attr == 0
2382# endif
2383 )
2384#endif
2385 {
2386 // In virtualedit, visual selections may extend
2387 // beyond end of line.
2388 if (area_highlighting && virtual_active()
2389 && tocol != MAXCOL && vcol < tocol)
2390 n_extra = 0;
2391 else
2392 {
2393 p_extra = at_end_str;
2394 n_extra = 1;
2395 c_extra = NUL;
2396 c_final = NUL;
2397 }
2398 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002399 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2400 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002401 else
2402 c = ' ';
2403 lcs_eol_one = -1;
2404 --ptr; // put it back at the NUL
2405 if (!attr_pri)
2406 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002407 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002408 n_attr = 1;
2409 }
2410 mb_c = c;
2411 if (enc_utf8 && utf_char2len(c) > 1)
2412 {
2413 mb_utf8 = TRUE;
2414 u8cc[0] = 0;
2415 c = 0xc0;
2416 }
2417 else
2418 mb_utf8 = FALSE; // don't draw as UTF-8
2419 }
2420 else if (c != NUL)
2421 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002422 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002423 if (n_extra == 0)
2424 n_extra = byte2cells(c) - 1;
2425#ifdef FEAT_RIGHTLEFT
2426 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2427 rl_mirror(p_extra); // reverse "<12>"
2428#endif
2429 c_extra = NUL;
2430 c_final = NUL;
2431#ifdef FEAT_LINEBREAK
2432 if (wp->w_p_lbr)
2433 {
2434 char_u *p;
2435
2436 c = *p_extra;
2437 p = alloc(n_extra + 1);
2438 vim_memset(p, ' ', n_extra);
2439 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2440 p[n_extra] = NUL;
2441 vim_free(p_extra_free);
2442 p_extra_free = p_extra = p;
2443 }
2444 else
2445#endif
2446 {
2447 n_extra = byte2cells(c) - 1;
2448 c = *p_extra++;
2449 }
2450 if (!attr_pri)
2451 {
2452 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002453 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002454 saved_attr2 = char_attr; // save current attr
2455 }
2456 mb_utf8 = FALSE; // don't draw as UTF-8
2457 }
2458 else if (VIsual_active
2459 && (VIsual_mode == Ctrl_V
2460 || VIsual_mode == 'v')
2461 && virtual_active()
2462 && tocol != MAXCOL
2463 && vcol < tocol
2464 && (
2465#ifdef FEAT_RIGHTLEFT
2466 wp->w_p_rl ? (col >= 0) :
2467#endif
2468 (col < wp->w_width)))
2469 {
2470 c = ' ';
2471 --ptr; // put it back at the NUL
2472 }
2473#if defined(LINE_ATTR)
2474 else if ((
2475# ifdef FEAT_DIFF
2476 diff_hlf != (hlf_T)0 ||
2477# endif
2478# ifdef FEAT_TERMINAL
2479 win_attr != 0 ||
2480# endif
2481 line_attr != 0
2482 ) && (
2483# ifdef FEAT_RIGHTLEFT
2484 wp->w_p_rl ? (col >= 0) :
2485# endif
2486 (col
2487# ifdef FEAT_CONCEAL
2488 - boguscols
2489# endif
2490 < wp->w_width)))
2491 {
2492 // Highlight until the right side of the window
2493 c = ' ';
2494 --ptr; // put it back at the NUL
2495
2496 // Remember we do the char for line highlighting.
2497 ++did_line_attr;
2498
2499 // don't do search HL for the rest of the line
2500 if (line_attr != 0 && char_attr == search_attr
2501 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002502 || (wp->w_p_list &&
2503 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002504 char_attr = line_attr;
2505# ifdef FEAT_DIFF
2506 if (diff_hlf == HLF_TXD)
2507 {
2508 diff_hlf = HLF_CHD;
2509 if (vi_attr == 0 || char_attr != vi_attr)
2510 {
2511 char_attr = HL_ATTR(diff_hlf);
2512 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2513 && wp->w_p_culopt_flags != CULOPT_NBR
2514 && (!cul_screenline
2515 || (vcol >= left_curline_col
2516 && vcol <= right_curline_col)))
2517 char_attr = hl_combine_attr(
2518 char_attr, HL_ATTR(HLF_CUL));
2519 }
2520 }
2521# endif
2522# ifdef FEAT_TERMINAL
2523 if (win_attr != 0)
2524 {
2525 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002526 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2527 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528 {
2529 if (!cul_screenline || (vcol >= left_curline_col
2530 && vcol <= right_curline_col))
2531 char_attr = hl_combine_attr(
2532 char_attr, HL_ATTR(HLF_CUL));
2533 }
2534 else if (line_attr)
2535 char_attr = hl_combine_attr(char_attr, line_attr);
2536 }
2537# endif
2538 }
2539#endif
2540 }
2541
2542#ifdef FEAT_CONCEAL
2543 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01002544 && (wp != curwin || lnum != wp->w_cursor.lnum
2545 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002546 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2547 && !(lnum_in_visual_area
2548 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2549 {
2550 char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01002551 if (((prev_syntax_id != syntax_seqnr
2552 && (syntax_flags & HL_CONCEAL) != 0)
2553 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002554 && (syn_get_sub_char() != NUL
2555 || (has_match_conc && match_conc)
2556 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 && wp->w_p_cole != 3)
2558 {
2559 // First time at this concealed item: display one
2560 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002561 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 c = match_conc;
2563 else if (syn_get_sub_char() != NUL)
2564 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002565 else if (wp->w_lcs_chars.conceal != NUL)
2566 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 else
2568 c = ' ';
2569
2570 prev_syntax_id = syntax_seqnr;
2571
2572 if (n_extra > 0)
2573 vcol_off += n_extra;
2574 vcol += n_extra;
2575 if (wp->w_p_wrap && n_extra > 0)
2576 {
2577# ifdef FEAT_RIGHTLEFT
2578 if (wp->w_p_rl)
2579 {
2580 col -= n_extra;
2581 boguscols -= n_extra;
2582 }
2583 else
2584# endif
2585 {
2586 boguscols += n_extra;
2587 col += n_extra;
2588 }
2589 }
2590 n_extra = 0;
2591 n_attr = 0;
2592 }
2593 else if (n_skip == 0)
2594 {
2595 is_concealing = TRUE;
2596 n_skip = 1;
2597 }
2598 mb_c = c;
2599 if (enc_utf8 && utf_char2len(c) > 1)
2600 {
2601 mb_utf8 = TRUE;
2602 u8cc[0] = 0;
2603 c = 0xc0;
2604 }
2605 else
2606 mb_utf8 = FALSE; // don't draw as UTF-8
2607 }
2608 else
2609 {
2610 prev_syntax_id = 0;
2611 is_concealing = FALSE;
2612 }
2613
2614 if (n_skip > 0 && did_decrement_ptr)
2615 // not showing the '>', put pointer back to avoid getting stuck
2616 ++ptr;
2617
2618#endif // FEAT_CONCEAL
2619 }
2620
2621#ifdef FEAT_CONCEAL
2622 // In the cursor line and we may be concealing characters: correct
2623 // the cursor column when we reach its position.
2624 if (!did_wcol && draw_state == WL_LINE
2625 && wp == curwin && lnum == wp->w_cursor.lnum
2626 && conceal_cursor_line(wp)
2627 && (int)wp->w_virtcol <= vcol + n_skip)
2628 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002629# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630 if (wp->w_p_rl)
2631 wp->w_wcol = wp->w_width - col + boguscols - 1;
2632 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002633# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634 wp->w_wcol = col - boguscols;
2635 wp->w_wrow = row;
2636 did_wcol = TRUE;
2637 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002638# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002639 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002640# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
2642#endif
2643
2644 // Don't override visual selection highlighting.
2645 if (n_attr > 0
2646 && draw_state == WL_LINE
2647 && !attr_pri)
2648 {
2649#ifdef LINE_ATTR
2650 if (line_attr)
2651 char_attr = hl_combine_attr(extra_attr, line_attr);
2652 else
2653#endif
2654 char_attr = extra_attr;
2655 }
2656
2657#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2658 // XIM don't send preedit_start and preedit_end, but they send
2659 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2660 // im_is_preediting() here.
2661 if (p_imst == IM_ON_THE_SPOT
2662 && xic != NULL
2663 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01002664 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 && !p_imdisable
2666 && im_is_preediting()
2667 && draw_state == WL_LINE)
2668 {
2669 colnr_T tcol;
2670
2671 if (preedit_end_col == MAXCOL)
2672 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2673 else
2674 tcol = preedit_end_col;
2675 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2676 {
2677 if (feedback_old_attr < 0)
2678 {
2679 feedback_col = 0;
2680 feedback_old_attr = char_attr;
2681 }
2682 char_attr = im_get_feedback_attr(feedback_col);
2683 if (char_attr < 0)
2684 char_attr = feedback_old_attr;
2685 feedback_col++;
2686 }
2687 else if (feedback_old_attr >= 0)
2688 {
2689 char_attr = feedback_old_attr;
2690 feedback_old_attr = -1;
2691 feedback_col = 0;
2692 }
2693 }
2694#endif
2695 // Handle the case where we are in column 0 but not on the first
2696 // character of the line and the user wants us to show us a
2697 // special character (via 'listchars' option "precedes:<char>".
2698 if (lcs_prec_todo != NUL
2699 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002700 && (wp->w_p_wrap ?
2701 (wp->w_skipcol > 0 && row == 0) :
2702 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002703#ifdef FEAT_DIFF
2704 && filler_todo <= 0
2705#endif
2706 && draw_state > WL_NR
2707 && c != NUL)
2708 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002709 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002710 lcs_prec_todo = NUL;
2711 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2712 {
2713 // Double-width character being overwritten by the "precedes"
2714 // character, need to fill up half the character.
2715 c_extra = MB_FILLER_CHAR;
2716 c_final = NUL;
2717 n_extra = 1;
2718 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002719 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002720 }
2721 mb_c = c;
2722 if (enc_utf8 && utf_char2len(c) > 1)
2723 {
2724 mb_utf8 = TRUE;
2725 u8cc[0] = 0;
2726 c = 0xc0;
2727 }
2728 else
2729 mb_utf8 = FALSE; // don't draw as UTF-8
2730 if (!attr_pri)
2731 {
2732 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002733 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002734 n_attr3 = 1;
2735 }
2736 }
2737
2738 // At end of the text line or just after the last character.
2739 if ((c == NUL
2740#if defined(LINE_ATTR)
2741 || did_line_attr == 1
2742#endif
2743 ) && eol_hl_off == 0)
2744 {
2745#ifdef FEAT_SEARCH_EXTRA
2746 // flag to indicate whether prevcol equals startcol of search_hl or
2747 // one of the matches
2748 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2749 (long)(ptr - line) - (c == NUL));
2750#endif
2751 // Invert at least one char, used for Visual and empty line or
2752 // highlight match at end of line. If it's beyond the last
2753 // char on the screen, just overwrite that one (tricky!) Not
2754 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002755 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 && ((area_attr != 0 && vcol == fromcol
2757 && (VIsual_mode != Ctrl_V
2758 || lnum == VIsual.lnum
2759 || lnum == curwin->w_cursor.lnum)
2760 && c == NUL)
2761#ifdef FEAT_SEARCH_EXTRA
2762 // highlight 'hlsearch' match at end of line
2763 || (prevcol_hl_flag
2764# ifdef FEAT_SYN_HL
2765 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2766 && !(wp == curwin && VIsual_active))
2767# endif
2768# ifdef FEAT_DIFF
2769 && diff_hlf == (hlf_T)0
2770# endif
2771# if defined(LINE_ATTR)
2772 && did_line_attr <= 1
2773# endif
2774 )
2775#endif
2776 ))
2777 {
2778 int n = 0;
2779
2780#ifdef FEAT_RIGHTLEFT
2781 if (wp->w_p_rl)
2782 {
2783 if (col < 0)
2784 n = 1;
2785 }
2786 else
2787#endif
2788 {
2789 if (col >= wp->w_width)
2790 n = -1;
2791 }
2792 if (n != 0)
2793 {
2794 // At the window boundary, highlight the last character
2795 // instead (better than nothing).
2796 off += n;
2797 col += n;
2798 }
2799 else
2800 {
2801 // Add a blank character to highlight.
2802 ScreenLines[off] = ' ';
2803 if (enc_utf8)
2804 ScreenLinesUC[off] = 0;
2805 }
2806#ifdef FEAT_SEARCH_EXTRA
2807 if (area_attr == 0)
2808 {
2809 // Use attributes from match with highest priority among
2810 // 'search_hl' and the match list.
2811 get_search_match_hl(wp, &screen_search_hl,
2812 (long)(ptr - line), &char_attr);
2813 }
2814#endif
2815 ScreenAttrs[off] = char_attr;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002816 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002817#ifdef FEAT_RIGHTLEFT
2818 if (wp->w_p_rl)
2819 {
2820 --col;
2821 --off;
2822 }
2823 else
2824#endif
2825 {
2826 ++col;
2827 ++off;
2828 }
2829 ++vcol;
2830 eol_hl_off = 1;
2831 }
2832 }
2833
2834 // At end of the text line.
2835 if (c == NUL)
2836 {
2837#ifdef FEAT_SYN_HL
2838 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2839 if (wp->w_p_wrap)
2840 v = wp->w_skipcol;
2841 else
2842 v = wp->w_leftcol;
2843
2844 // check if line ends before left margin
2845 if (vcol < v + col - win_col_off(wp))
2846 vcol = v + col - win_col_off(wp);
2847#ifdef FEAT_CONCEAL
2848 // Get rid of the boguscols now, we want to draw until the right
2849 // edge for 'cursorcolumn'.
2850 col -= boguscols;
2851 boguscols = 0;
2852#endif
2853
2854 if (draw_color_col)
2855 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2856
2857 if (((wp->w_p_cuc
2858 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2859 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002860 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 && lnum != wp->w_cursor.lnum)
2862 || draw_color_col
2863 || win_attr != 0)
2864# ifdef FEAT_RIGHTLEFT
2865 && !wp->w_p_rl
2866# endif
2867 )
2868 {
2869 int rightmost_vcol = 0;
2870 int i;
2871
2872 if (wp->w_p_cuc)
2873 rightmost_vcol = wp->w_virtcol;
2874 if (draw_color_col)
2875 // determine rightmost colorcolumn to possibly draw
2876 for (i = 0; color_cols[i] >= 0; ++i)
2877 if (rightmost_vcol < color_cols[i])
2878 rightmost_vcol = color_cols[i];
2879
2880 while (col < wp->w_width)
2881 {
2882 ScreenLines[off] = ' ';
2883 if (enc_utf8)
2884 ScreenLinesUC[off] = 0;
Bram Moolenaarb9081882022-07-09 04:56:24 +01002885 ScreenCols[off] = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 ++col;
2887 if (draw_color_col)
2888 draw_color_col = advance_color_col(VCOL_HLC,
2889 &color_cols);
2890
2891 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2892 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2893 else if (draw_color_col && VCOL_HLC == *color_cols)
2894 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2895 else
2896 ScreenAttrs[off++] = win_attr;
2897
2898 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2899 break;
2900
2901 ++vcol;
2902 }
2903 }
2904#endif
2905
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01002906 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002907 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 row++;
2909
2910 // Update w_cline_height and w_cline_folded if the cursor line was
2911 // updated (saves a call to plines() later).
2912 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2913 {
2914 curwin->w_cline_row = startrow;
2915 curwin->w_cline_height = row - startrow;
2916#ifdef FEAT_FOLDING
2917 curwin->w_cline_folded = FALSE;
2918#endif
2919 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2920 }
2921
2922 break;
2923 }
2924
2925 // Show "extends" character from 'listchars' if beyond the line end and
2926 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002927 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002928 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002929 && wp->w_p_list
2930 && !wp->w_p_wrap
2931#ifdef FEAT_DIFF
2932 && filler_todo <= 0
2933#endif
2934 && (
2935#ifdef FEAT_RIGHTLEFT
2936 wp->w_p_rl ? col == 0 :
2937#endif
2938 col == wp->w_width - 1)
2939 && (*ptr != NUL
2940 || (wp->w_p_list && lcs_eol_one > 0)
2941 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2942 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002943 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002944 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002945 mb_c = c;
2946 if (enc_utf8 && utf_char2len(c) > 1)
2947 {
2948 mb_utf8 = TRUE;
2949 u8cc[0] = 0;
2950 c = 0xc0;
2951 }
2952 else
2953 mb_utf8 = FALSE;
2954 }
2955
2956#ifdef FEAT_SYN_HL
2957 // advance to the next 'colorcolumn'
2958 if (draw_color_col)
2959 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2960
2961 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2962 // highlight the cursor position itself.
2963 // Also highlight the 'colorcolumn' if it is different than
2964 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002965 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2966 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002968 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002969 draw_state == WL_BRI ||
2970 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002972# ifdef FEAT_DIFF
2973 && filler_todo <= 0
2974# endif
2975 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002976 {
2977 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2978 && lnum != wp->w_cursor.lnum)
2979 {
2980 vcol_save_attr = char_attr;
2981 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2982 }
2983 else if (draw_color_col && VCOL_HLC == *color_cols)
2984 {
2985 vcol_save_attr = char_attr;
2986 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2987 }
2988 }
2989#endif
2990
2991 // Store character to be displayed.
2992 // Skip characters that are left of the screen for 'nowrap'.
2993 vcol_prev = vcol;
2994 if (draw_state < WL_LINE || n_skip <= 0)
2995 {
2996 // Store the character.
2997#if defined(FEAT_RIGHTLEFT)
2998 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2999 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003000 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 --off;
3002 --col;
3003 }
3004#endif
3005 ScreenLines[off] = c;
3006 if (enc_dbcs == DBCS_JPNU)
3007 {
3008 if ((mb_c & 0xff00) == 0x8e00)
3009 ScreenLines[off] = 0x8e;
3010 ScreenLines2[off] = mb_c & 0xff;
3011 }
3012 else if (enc_utf8)
3013 {
3014 if (mb_utf8)
3015 {
3016 int i;
3017
3018 ScreenLinesUC[off] = mb_c;
3019 if ((c & 0xff) == 0)
3020 ScreenLines[off] = 0x80; // avoid storing zero
3021 for (i = 0; i < Screen_mco; ++i)
3022 {
3023 ScreenLinesC[i][off] = u8cc[i];
3024 if (u8cc[i] == 0)
3025 break;
3026 }
3027 }
3028 else
3029 ScreenLinesUC[off] = 0;
3030 }
3031 if (multi_attr)
3032 {
3033 ScreenAttrs[off] = multi_attr;
3034 multi_attr = 0;
3035 }
3036 else
3037 ScreenAttrs[off] = char_attr;
3038
Bram Moolenaarb9081882022-07-09 04:56:24 +01003039 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3040
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003041 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3042 {
3043 // Need to fill two screen columns.
3044 ++off;
3045 ++col;
3046 if (enc_utf8)
3047 // UTF-8: Put a 0 in the second screen char.
3048 ScreenLines[off] = 0;
3049 else
3050 // DBCS: Put second byte in the second screen char.
3051 ScreenLines[off] = mb_c & 0xff;
3052 if (draw_state > WL_NR
3053#ifdef FEAT_DIFF
3054 && filler_todo <= 0
3055#endif
3056 )
3057 ++vcol;
3058 // When "tocol" is halfway a character, set it to the end of
3059 // the character, otherwise highlighting won't stop.
3060 if (tocol == vcol)
3061 ++tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003062
3063 ScreenCols[off] = (colnr_T)(prev_ptr - line);
3064
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003065#ifdef FEAT_RIGHTLEFT
3066 if (wp->w_p_rl)
3067 {
3068 // now it's time to backup one cell
3069 --off;
3070 --col;
3071 }
3072#endif
3073 }
3074#ifdef FEAT_RIGHTLEFT
3075 if (wp->w_p_rl)
3076 {
3077 --off;
3078 --col;
3079 }
3080 else
3081#endif
3082 {
3083 ++off;
3084 ++col;
3085 }
3086 }
3087#ifdef FEAT_CONCEAL
3088 else if (wp->w_p_cole > 0 && is_concealing)
3089 {
3090 --n_skip;
3091 ++vcol_off;
3092 if (n_extra > 0)
3093 vcol_off += n_extra;
3094 if (wp->w_p_wrap)
3095 {
3096 // Special voodoo required if 'wrap' is on.
3097 //
3098 // Advance the column indicator to force the line
3099 // drawing to wrap early. This will make the line
3100 // take up the same screen space when parts are concealed,
3101 // so that cursor line computations aren't messed up.
3102 //
3103 // To avoid the fictitious advance of 'col' causing
3104 // trailing junk to be written out of the screen line
3105 // we are building, 'boguscols' keeps track of the number
3106 // of bad columns we have advanced.
3107 if (n_extra > 0)
3108 {
3109 vcol += n_extra;
3110# ifdef FEAT_RIGHTLEFT
3111 if (wp->w_p_rl)
3112 {
3113 col -= n_extra;
3114 boguscols -= n_extra;
3115 }
3116 else
3117# endif
3118 {
3119 col += n_extra;
3120 boguscols += n_extra;
3121 }
3122 n_extra = 0;
3123 n_attr = 0;
3124 }
3125
3126
3127 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3128 {
3129 // Need to fill two screen columns.
3130# ifdef FEAT_RIGHTLEFT
3131 if (wp->w_p_rl)
3132 {
3133 --boguscols;
3134 --col;
3135 }
3136 else
3137# endif
3138 {
3139 ++boguscols;
3140 ++col;
3141 }
3142 }
3143
3144# ifdef FEAT_RIGHTLEFT
3145 if (wp->w_p_rl)
3146 {
3147 --boguscols;
3148 --col;
3149 }
3150 else
3151# endif
3152 {
3153 ++boguscols;
3154 ++col;
3155 }
3156 }
3157 else
3158 {
3159 if (n_extra > 0)
3160 {
3161 vcol += n_extra;
3162 n_extra = 0;
3163 n_attr = 0;
3164 }
3165 }
3166
3167 }
3168#endif // FEAT_CONCEAL
3169 else
3170 --n_skip;
3171
3172 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3173 // column.
3174 if (draw_state > WL_NR
3175#ifdef FEAT_DIFF
3176 && filler_todo <= 0
3177#endif
3178 )
3179 ++vcol;
3180
3181#ifdef FEAT_SYN_HL
3182 if (vcol_save_attr >= 0)
3183 char_attr = vcol_save_attr;
3184#endif
3185
3186 // restore attributes after "predeces" in 'listchars'
3187 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3188 char_attr = saved_attr3;
3189
3190 // restore attributes after last 'listchars' or 'number' char
3191 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3192 char_attr = saved_attr2;
3193
3194 // At end of screen line and there is more to come: Display the line
3195 // so far. If there is no more to display it is caught above.
3196 if ((
3197#ifdef FEAT_RIGHTLEFT
3198 wp->w_p_rl ? (col < 0) :
3199#endif
3200 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003201 && (draw_state != WL_LINE
3202 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003203#ifdef FEAT_DIFF
3204 || filler_todo > 0
3205#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003206 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3207 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3209 )
3210 {
3211#ifdef FEAT_CONCEAL
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003212 screen_line(wp, screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003213 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 boguscols = 0;
3215#else
Bram Moolenaar96ba25a2022-07-04 17:34:33 +01003216 screen_line(wp, screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003217 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003218#endif
3219 ++row;
3220 ++screen_row;
3221
3222 // When not wrapping and finished diff lines, or when displayed
3223 // '$' and highlighting until last column, break here.
3224 if ((!wp->w_p_wrap
3225#ifdef FEAT_DIFF
3226 && filler_todo <= 0
3227#endif
3228 ) || lcs_eol_one == -1)
3229 break;
3230
3231 // When the window is too narrow draw all "@" lines.
3232 if (draw_state != WL_LINE
3233#ifdef FEAT_DIFF
3234 && filler_todo <= 0
3235#endif
3236 )
3237 {
3238 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3239 draw_vsep_win(wp, row);
3240 row = endrow;
3241 }
3242
3243 // When line got too long for screen break here.
3244 if (row == endrow)
3245 {
3246 ++row;
3247 break;
3248 }
3249
3250 if (screen_cur_row == screen_row - 1
3251#ifdef FEAT_DIFF
3252 && filler_todo <= 0
3253#endif
3254 && wp->w_width == Columns)
3255 {
3256 // Remember that the line wraps, used for modeless copy.
3257 LineWraps[screen_row - 1] = TRUE;
3258
3259 // Special trick to make copy/paste of wrapped lines work with
3260 // xterm/screen: write an extra character beyond the end of
3261 // the line. This will work with all terminal types
3262 // (regardless of the xn,am settings).
3263 // Only do this on a fast tty.
3264 // Only do this if the cursor is on the current line
3265 // (something has been written in it).
3266 // Don't do this for the GUI.
3267 // Don't do this for double-width characters.
3268 // Don't do this for a window not at the right screen border.
3269 if (p_tf
3270#ifdef FEAT_GUI
3271 && !gui.in_use
3272#endif
3273 && !(has_mbyte
3274 && ((*mb_off2cells)(LineOffset[screen_row],
3275 LineOffset[screen_row] + screen_Columns)
3276 == 2
3277 || (*mb_off2cells)(LineOffset[screen_row - 1]
3278 + (int)Columns - 2,
3279 LineOffset[screen_row] + screen_Columns)
3280 == 2)))
3281 {
3282 // First make sure we are at the end of the screen line,
3283 // then output the same character again to let the
3284 // terminal know about the wrap. If the terminal doesn't
3285 // auto-wrap, we overwrite the character.
3286 if (screen_cur_col != wp->w_width)
3287 screen_char(LineOffset[screen_row - 1]
3288 + (unsigned)Columns - 1,
3289 screen_row - 1, (int)(Columns - 1));
3290
3291 // When there is a multi-byte character, just output a
3292 // space to keep it simple.
3293 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3294 screen_row - 1] + (Columns - 1)]) > 1)
3295 out_char(' ');
3296 else
3297 out_char(ScreenLines[LineOffset[screen_row - 1]
3298 + (Columns - 1)]);
3299 // force a redraw of the first char on the next line
3300 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3301 screen_start(); // don't know where cursor is now
3302 }
3303 }
3304
3305 col = 0;
3306 off = (unsigned)(current_ScreenLine - ScreenLines);
3307#ifdef FEAT_RIGHTLEFT
3308 if (wp->w_p_rl)
3309 {
3310 col = wp->w_width - 1; // col is not used if breaking!
3311 off += col;
3312 }
3313#endif
3314
3315 // reset the drawing state for the start of a wrapped line
3316 draw_state = WL_START;
3317 saved_n_extra = n_extra;
3318 saved_p_extra = p_extra;
3319 saved_c_extra = c_extra;
3320 saved_c_final = c_final;
3321#ifdef FEAT_SYN_HL
3322 if (!(cul_screenline
3323# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003324 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003325# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003326 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003327 saved_char_attr = char_attr;
3328 else
3329#endif
3330 saved_char_attr = 0;
3331 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003332 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333#ifdef FEAT_LINEBREAK
3334# ifdef FEAT_DIFF
3335 if (filler_todo <= 0)
3336# endif
3337 need_showbreak = TRUE;
3338#endif
3339#ifdef FEAT_DIFF
3340 --filler_todo;
3341 // When the filler lines are actually below the last line of the
3342 // file, don't draw the line itself, break here.
3343 if (filler_todo == 0 && wp->w_botfill)
3344 break;
3345#endif
3346 }
3347
3348 } // for every character in the line
3349
3350#ifdef FEAT_SPELL
3351 // After an empty line check first word for capital.
3352 if (*skipwhite(line) == NUL)
3353 {
3354 capcol_lnum = lnum + 1;
3355 cap_col = 0;
3356 }
3357#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003358#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359 vim_free(text_props);
3360 vim_free(text_prop_idxs);
3361#endif
3362
3363 vim_free(p_extra_free);
3364 return row;
3365}