blob: 7125b800f69cd9a13b17972ebefb2eb994df52e9 [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;
329 int text_prop_combine = FALSE;
330#endif
331#ifdef FEAT_SPELL
332 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200333 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334# define SPWORDLEN 150
335 char_u nextline[SPWORDLEN * 2];// text with start of the next line
336 int nextlinecol = 0; // column where nextline[] starts
337 int nextline_idx = 0; // index in nextline[] where next line
338 // starts
339 int spell_attr = 0; // attributes desired by spelling
340 int word_end = 0; // last byte with same spell_attr
341 static linenr_T checked_lnum = 0; // line number for "checked_col"
342 static int checked_col = 0; // column in "checked_lnum" up to which
343 // there are no spell errors
344 static int cap_col = -1; // column to check for Cap word
345 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
346 int cur_checked_col = 0; // checked column for current line
347#endif
348 int extra_check = 0; // has extra highlighting
349 int multi_attr = 0; // attributes desired by multibyte
350 int mb_l = 1; // multi-byte byte length
351 int mb_c = 0; // decoded multi-byte character
352 int mb_utf8 = FALSE; // screen char is UTF-8 char
353 int u8cc[MAX_MCO]; // composing UTF-8 chars
354#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
355 int filler_lines = 0; // nr of filler lines to be drawn
356 int filler_todo = 0; // nr of filler lines still to do + 1
357#endif
358#ifdef FEAT_DIFF
359 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
360 int change_start = MAXCOL; // first col of changed area
361 int change_end = -1; // last col of changed area
362#endif
363 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100364 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200365 int in_multispace = FALSE; // in multiple consecutive spaces
366 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200367#ifdef FEAT_LINEBREAK
368 int need_showbreak = FALSE; // overlong line, skipping first x
369 // chars
370#endif
371#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
372 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
373# define LINE_ATTR
374 int line_attr = 0; // attribute for the whole line
375 int line_attr_save;
376#endif
377#ifdef FEAT_SIGNS
378 int sign_present = FALSE;
379 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000380 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200381#endif
382#ifdef FEAT_ARABIC
383 int prev_c = 0; // previous Arabic character
384 int prev_c1 = 0; // first composing char for prev_c
385#endif
386#if defined(LINE_ATTR)
387 int did_line_attr = 0;
388#endif
389#ifdef FEAT_TERMINAL
390 int get_term_attr = FALSE;
391#endif
392#ifdef FEAT_SYN_HL
393 int cul_attr = 0; // set when 'cursorline' active
394
395 // 'cursorlineopt' has "screenline" and cursor is in this line
396 int cul_screenline = FALSE;
397
398 // margin columns for the screen line, needed for when 'cursorlineopt'
399 // contains "screenline"
400 int left_curline_col = 0;
401 int right_curline_col = 0;
402#endif
403
404 // draw_state: items that are drawn in sequence:
405#define WL_START 0 // nothing done yet
406#ifdef FEAT_CMDWIN
407# define WL_CMDLINE WL_START + 1 // cmdline window column
408#else
409# define WL_CMDLINE WL_START
410#endif
411#ifdef FEAT_FOLDING
412# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
413#else
414# define WL_FOLD WL_CMDLINE
415#endif
416#ifdef FEAT_SIGNS
417# define WL_SIGN WL_FOLD + 1 // column for signs
418#else
419# define WL_SIGN WL_FOLD // column for signs
420#endif
421#define WL_NR WL_SIGN + 1 // line number
422#ifdef FEAT_LINEBREAK
423# define WL_BRI WL_NR + 1 // 'breakindent'
424#else
425# define WL_BRI WL_NR
426#endif
427#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
428# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
429#else
430# define WL_SBR WL_BRI
431#endif
432#define WL_LINE WL_SBR + 1 // text in the line
433 int draw_state = WL_START; // what to draw next
434#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
435 int feedback_col = 0;
436 int feedback_old_attr = -1;
437#endif
438 int screen_line_flags = 0;
439
440#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
441 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000442 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200443#endif
444#ifdef FEAT_CONCEAL
445 int syntax_flags = 0;
446 int syntax_seqnr = 0;
447 int prev_syntax_id = 0;
448 int conceal_attr = HL_ATTR(HLF_CONCEAL);
449 int is_concealing = FALSE;
450 int boguscols = 0; // nonexistent columns added to force
451 // wrapping
452 int vcol_off = 0; // offset for concealed characters
453 int did_wcol = FALSE;
454 int old_boguscols = 0;
455# define VCOL_HLC (vcol - vcol_off)
456# define FIX_FOR_BOGUSCOLS \
457 { \
458 n_extra += vcol_off; \
459 vcol -= vcol_off; \
460 vcol_off = 0; \
461 col -= boguscols; \
462 old_boguscols = boguscols; \
463 boguscols = 0; \
464 }
465#else
466# define VCOL_HLC (vcol)
467#endif
468
469 if (startrow > endrow) // past the end already!
470 return startrow;
471
472 row = startrow;
473 screen_row = row + W_WINROW(wp);
474
475 if (!number_only)
476 {
477 // To speed up the loop below, set extra_check when there is linebreak,
478 // trailing white space and/or syntax processing to be done.
479#ifdef FEAT_LINEBREAK
480 extra_check = wp->w_p_lbr;
481#endif
482#ifdef FEAT_SYN_HL
483 if (syntax_present(wp) && !wp->w_s->b_syn_error
484# ifdef SYN_TIME_LIMIT
485 && !wp->w_s->b_syn_slow
486# endif
487 )
488 {
489 // Prepare for syntax highlighting in this line. When there is an
490 // error, stop syntax highlighting.
491 save_did_emsg = did_emsg;
492 did_emsg = FALSE;
493 syntax_start(wp, lnum);
494 if (did_emsg)
495 wp->w_s->b_syn_error = TRUE;
496 else
497 {
498 did_emsg = save_did_emsg;
499#ifdef SYN_TIME_LIMIT
500 if (!wp->w_s->b_syn_slow)
501#endif
502 {
503 has_syntax = TRUE;
504 extra_check = TRUE;
505 }
506 }
507 }
508
509 // Check for columns to display for 'colorcolumn'.
510 color_cols = wp->w_p_cc_cols;
511 if (color_cols != NULL)
512 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
513#endif
514
515#ifdef FEAT_TERMINAL
516 if (term_show_buffer(wp->w_buffer))
517 {
518 extra_check = TRUE;
519 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100520 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200521 }
522#endif
523
524#ifdef FEAT_SPELL
525 if (wp->w_p_spell
526 && *wp->w_s->b_p_spl != NUL
527 && wp->w_s->b_langp.ga_len > 0
528 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
529 {
530 // Prepare for spell checking.
531 has_spell = TRUE;
532 extra_check = TRUE;
533
534 // Get the start of the next line, so that words that wrap to the
535 // next line are found too: "et<line-break>al.".
536 // Trick: skip a few chars for C/shell/Vim comments
537 nextline[SPWORDLEN] = NUL;
538 if (lnum < wp->w_buffer->b_ml.ml_line_count)
539 {
540 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
541 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
542 }
543
544 // When a word wrapped from the previous line the start of the
545 // current line is valid.
546 if (lnum == checked_lnum)
547 cur_checked_col = checked_col;
548 checked_lnum = 0;
549
550 // When there was a sentence end in the previous line may require a
551 // word starting with capital in this line. In line 1 always check
552 // the first word.
553 if (lnum != capcol_lnum)
554 cap_col = -1;
555 if (lnum == 1)
556 cap_col = 0;
557 capcol_lnum = 0;
558 }
559#endif
560
561 // handle Visual active in this window
562 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
563 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100564 pos_T *top, *bot;
565
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200566 if (LTOREQ_POS(curwin->w_cursor, VIsual))
567 {
568 // Visual is after curwin->w_cursor
569 top = &curwin->w_cursor;
570 bot = &VIsual;
571 }
572 else
573 {
574 // Visual is before curwin->w_cursor
575 top = &VIsual;
576 bot = &curwin->w_cursor;
577 }
578 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
579 if (VIsual_mode == Ctrl_V)
580 {
581 // block mode
582 if (lnum_in_visual_area)
583 {
584 fromcol = wp->w_old_cursor_fcol;
585 tocol = wp->w_old_cursor_lcol;
586 }
587 }
588 else
589 {
590 // non-block mode
591 if (lnum > top->lnum && lnum <= bot->lnum)
592 fromcol = 0;
593 else if (lnum == top->lnum)
594 {
595 if (VIsual_mode == 'V') // linewise
596 fromcol = 0;
597 else
598 {
599 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
600 if (gchar_pos(top) == NUL)
601 tocol = fromcol + 1;
602 }
603 }
604 if (VIsual_mode != 'V' && lnum == bot->lnum)
605 {
606 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
607 {
608 fromcol = -10;
609 tocol = MAXCOL;
610 }
611 else if (bot->col == MAXCOL)
612 tocol = MAXCOL;
613 else
614 {
615 pos = *bot;
616 if (*p_sel == 'e')
617 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
618 else
619 {
620 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
621 ++tocol;
622 }
623 }
624 }
625 }
626
627 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200628 if (!highlight_match && lnum == curwin->w_cursor.lnum
629 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200630#ifdef FEAT_GUI
631 && !gui.in_use
632#endif
633 )
634 noinvcur = TRUE;
635
636 // if inverting in this line set area_highlighting
637 if (fromcol >= 0)
638 {
639 area_highlighting = TRUE;
640 vi_attr = HL_ATTR(HLF_V);
641#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
642 if ((clip_star.available && !clip_star.owned
643 && clip_isautosel_star())
644 || (clip_plus.available && !clip_plus.owned
645 && clip_isautosel_plus()))
646 vi_attr = HL_ATTR(HLF_VNC);
647#endif
648 }
649 }
650
651 // handle 'incsearch' and ":s///c" highlighting
652 else if (highlight_match
653 && wp == curwin
654 && lnum >= curwin->w_cursor.lnum
655 && lnum <= curwin->w_cursor.lnum + search_match_lines)
656 {
657 if (lnum == curwin->w_cursor.lnum)
658 getvcol(curwin, &(curwin->w_cursor),
659 (colnr_T *)&fromcol, NULL, NULL);
660 else
661 fromcol = 0;
662 if (lnum == curwin->w_cursor.lnum + search_match_lines)
663 {
664 pos.lnum = lnum;
665 pos.col = search_match_endcol;
666 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
667 }
668 else
669 tocol = MAXCOL;
670 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100671 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200672 tocol = fromcol + 1;
673 area_highlighting = TRUE;
674 vi_attr = HL_ATTR(HLF_I);
675 }
676 }
677
678#ifdef FEAT_DIFF
679 filler_lines = diff_check(wp, lnum);
680 if (filler_lines < 0)
681 {
682 if (filler_lines == -1)
683 {
684 if (diff_find_change(wp, lnum, &change_start, &change_end))
685 diff_hlf = HLF_ADD; // added line
686 else if (change_start == 0)
687 diff_hlf = HLF_TXD; // changed text
688 else
689 diff_hlf = HLF_CHD; // changed line
690 }
691 else
692 diff_hlf = HLF_ADD; // added line
693 filler_lines = 0;
694 area_highlighting = TRUE;
695 }
696 if (lnum == wp->w_topline)
697 filler_lines = wp->w_topfill;
698 filler_todo = filler_lines;
699#endif
700
701#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100702 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000703 if (sign_present)
704 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200705#endif
706
707#ifdef LINE_ATTR
708# ifdef FEAT_SIGNS
709 // If this line has a sign with line highlighting set line_attr.
710 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200711 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200712# endif
713# if defined(FEAT_QUICKFIX)
714 // Highlight the current line in the quickfix window.
715 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
716 line_attr = HL_ATTR(HLF_QFL);
717# endif
718 if (line_attr != 0)
719 area_highlighting = TRUE;
720#endif
721
722 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
723 ptr = line;
724
725#ifdef FEAT_SPELL
726 if (has_spell && !number_only)
727 {
728 // For checking first word with a capital skip white space.
729 if (cap_col == 0)
730 cap_col = getwhitecols(line);
731
732 // To be able to spell-check over line boundaries copy the end of the
733 // current line into nextline[]. Above the start of the next line was
734 // copied to nextline[SPWORDLEN].
735 if (nextline[SPWORDLEN] == NUL)
736 {
737 // No next line or it is empty.
738 nextlinecol = MAXCOL;
739 nextline_idx = 0;
740 }
741 else
742 {
743 v = (long)STRLEN(line);
744 if (v < SPWORDLEN)
745 {
746 // Short line, use it completely and append the start of the
747 // next line.
748 nextlinecol = 0;
749 mch_memmove(nextline, line, (size_t)v);
750 STRMOVE(nextline + v, nextline + SPWORDLEN);
751 nextline_idx = v + 1;
752 }
753 else
754 {
755 // Long line, use only the last SPWORDLEN bytes.
756 nextlinecol = v - SPWORDLEN;
757 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
758 nextline_idx = SPWORDLEN + 1;
759 }
760 }
761 }
762#endif
763
764 if (wp->w_p_list)
765 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100766 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200767 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100768 || wp->w_lcs_chars.trail
769 || wp->w_lcs_chars.lead
770 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200771 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100772
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100774 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 {
776 trailcol = (colnr_T)STRLEN(ptr);
777 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
778 --trailcol;
779 trailcol += (colnr_T) (ptr - line);
780 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100781 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100782 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100783 {
784 leadcol = 0;
785 while (VIM_ISWHITE(ptr[leadcol]))
786 ++leadcol;
787 if (ptr[leadcol] == NUL)
788 // in a line full of spaces all of them are treated as trailing
789 leadcol = (colnr_T)0;
790 else
791 // keep track of the first column not filled with spaces
792 leadcol += (colnr_T) (ptr - line) + 1;
793 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200794 }
795
796 wcr_attr = get_wcr_attr(wp);
797 if (wcr_attr != 0)
798 {
799 win_attr = wcr_attr;
800 area_highlighting = TRUE;
801 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200802
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100803#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200804 if (WIN_IS_POPUP(wp))
805 screen_line_flags |= SLF_POPUP;
806#endif
807
808 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
809 // first character to be displayed.
810 if (wp->w_p_wrap)
811 v = wp->w_skipcol;
812 else
813 v = wp->w_leftcol;
814 if (v > 0 && !number_only)
815 {
816 char_u *prev_ptr = ptr;
817
818 while (vcol < v && *ptr != NUL)
819 {
820 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
821 vcol += c;
822 prev_ptr = ptr;
823 MB_PTR_ADV(ptr);
824 }
825
826 // When:
827 // - 'cuc' is set, or
828 // - 'colorcolumn' is set, or
829 // - 'virtualedit' is set, or
830 // - the visual mode is active,
831 // the end of the line may be before the start of the displayed part.
832 if (vcol < v && (
833#ifdef FEAT_SYN_HL
834 wp->w_p_cuc || draw_color_col ||
835#endif
836 virtual_active() ||
837 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
838 vcol = v;
839
840 // Handle a character that's not completely on the screen: Put ptr at
841 // that character but skip the first few screen characters.
842 if (vcol > v)
843 {
844 vcol -= c;
845 ptr = prev_ptr;
846 // If the character fits on the screen, don't need to skip it.
847 // Except for a TAB.
848 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
849 n_skip = v - vcol;
850 }
851
852 // Adjust for when the inverted text is before the screen,
853 // and when the start of the inverted text is before the screen.
854 if (tocol <= vcol)
855 fromcol = 0;
856 else if (fromcol >= 0 && fromcol < vcol)
857 fromcol = vcol;
858
859#ifdef FEAT_LINEBREAK
860 // When w_skipcol is non-zero, first line needs 'showbreak'
861 if (wp->w_p_wrap)
862 need_showbreak = TRUE;
863#endif
864#ifdef FEAT_SPELL
865 // When spell checking a word we need to figure out the start of the
866 // word and if it's badly spelled or not.
867 if (has_spell)
868 {
869 int len;
870 colnr_T linecol = (colnr_T)(ptr - line);
871 hlf_T spell_hlf = HLF_COUNT;
872
873 pos = wp->w_cursor;
874 wp->w_cursor.lnum = lnum;
875 wp->w_cursor.col = linecol;
876 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
877
878 // spell_move_to() may call ml_get() and make "line" invalid
879 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
880 ptr = line + linecol;
881
882 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
883 {
884 // no bad word found at line start, don't check until end of a
885 // word
886 spell_hlf = HLF_COUNT;
887 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
888 }
889 else
890 {
891 // bad word found, use attributes until end of word
892 word_end = wp->w_cursor.col + len + 1;
893
894 // Turn index into actual attributes.
895 if (spell_hlf != HLF_COUNT)
896 spell_attr = highlight_attr[spell_hlf];
897 }
898 wp->w_cursor = pos;
899
900# ifdef FEAT_SYN_HL
901 // Need to restart syntax highlighting for this line.
902 if (has_syntax)
903 syntax_start(wp, lnum);
904# endif
905 }
906#endif
907 }
908
909 // Correct highlighting for cursor that can't be disabled.
910 // Avoids having to check this for each character.
911 if (fromcol >= 0)
912 {
913 if (noinvcur)
914 {
915 if ((colnr_T)fromcol == wp->w_virtcol)
916 {
917 // highlighting starts at cursor, let it start just after the
918 // cursor
919 fromcol_prev = fromcol;
920 fromcol = -1;
921 }
922 else if ((colnr_T)fromcol < wp->w_virtcol)
923 // restart highlighting after the cursor
924 fromcol_prev = wp->w_virtcol;
925 }
926 if (fromcol >= tocol)
927 fromcol = -1;
928 }
929
930#ifdef FEAT_SEARCH_EXTRA
931 if (!number_only)
932 {
933 v = (long)(ptr - line);
934 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
935 &line, &screen_search_hl,
936 &search_attr);
937 ptr = line + v; // "line" may have been updated
938 }
939#endif
940
941#ifdef FEAT_SYN_HL
942 // Cursor line highlighting for 'cursorline' in the current window.
943 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
944 {
945 // Do not show the cursor line in the text when Visual mode is active,
946 // because it's not clear what is selected then. Do update
947 // w_last_cursorline.
948 if (!(wp == curwin && VIsual_active)
949 && wp->w_p_culopt_flags != CULOPT_NBR)
950 {
951 cul_screenline = (wp->w_p_wrap
952 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
953
954 // Only set line_attr here when "screenline" is not present in
955 // 'cursorlineopt'. Otherwise it's done later.
956 if (!cul_screenline)
957 {
958 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200959# ifdef FEAT_SIGNS
960 // Combine the 'cursorline' and sign highlighting, depending on
961 // the sign priority.
962 if (sign_present && sattr.sat_linehl > 0)
963 {
964 if (sattr.sat_priority >= 100)
965 line_attr = hl_combine_attr(cul_attr, line_attr);
966 else
967 line_attr = hl_combine_attr(line_attr, cul_attr);
968 }
969 else
970# endif
971 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200972 wp->w_last_cursorline = wp->w_cursor.lnum;
973 }
974 else
975 {
976 line_attr_save = line_attr;
977 wp->w_last_cursorline = 0;
978 margin_columns_win(wp, &left_curline_col, &right_curline_col);
979 }
980 area_highlighting = TRUE;
981 }
982 else
983 wp->w_last_cursorline = wp->w_cursor.lnum;
984 }
985#endif
986
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100987#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200988 {
989 char_u *prop_start;
990
991 text_prop_count = get_text_props(wp->w_buffer, lnum,
992 &prop_start, FALSE);
993 if (text_prop_count > 0)
994 {
995 // Make a copy of the properties, so that they are properly
996 // aligned.
997 text_props = ALLOC_MULT(textprop_T, text_prop_count);
998 if (text_props != NULL)
999 mch_memmove(text_props, prop_start,
1000 text_prop_count * sizeof(textprop_T));
1001
1002 // Allocate an array for the indexes.
1003 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1004 area_highlighting = TRUE;
1005 extra_check = TRUE;
1006 }
1007 }
1008#endif
1009
1010 off = (unsigned)(current_ScreenLine - ScreenLines);
1011 col = 0;
1012
1013#ifdef FEAT_RIGHTLEFT
1014 if (wp->w_p_rl)
1015 {
1016 // Rightleft window: process the text in the normal direction, but put
1017 // it in current_ScreenLine[] from right to left. Start at the
1018 // rightmost column of the window.
1019 col = wp->w_width - 1;
1020 off += col;
1021 screen_line_flags |= SLF_RIGHTLEFT;
1022 }
1023#endif
1024
1025 // Repeat for the whole displayed line.
1026 for (;;)
1027 {
1028#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001029 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001030#endif
1031#ifdef FEAT_CONCEAL
1032 int did_decrement_ptr = FALSE;
1033#endif
1034 // Skip this quickly when working on the text.
1035 if (draw_state != WL_LINE)
1036 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001037#ifdef FEAT_SYN_HL
1038 if (cul_screenline)
1039 {
1040 cul_attr = 0;
1041 line_attr = line_attr_save;
1042 }
1043#endif
1044
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001045#ifdef FEAT_CMDWIN
1046 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1047 {
1048 draw_state = WL_CMDLINE;
1049 if (cmdwin_type != 0 && wp == curwin)
1050 {
1051 // Draw the cmdline character.
1052 n_extra = 1;
1053 c_extra = cmdwin_type;
1054 c_final = NUL;
1055 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1056 }
1057 }
1058#endif
1059
1060#ifdef FEAT_FOLDING
1061 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1062 {
1063 int fdc = compute_foldcolumn(wp, 0);
1064
1065 draw_state = WL_FOLD;
1066 if (fdc > 0)
1067 {
1068 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1069 // already be in use.
1070 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001071 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001072 if (p_extra_free != NULL)
1073 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001074 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001075 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001076 p_extra_free[n_extra] = NUL;
1077 p_extra = p_extra_free;
1078 c_extra = NUL;
1079 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001080 if (use_cursor_line_sign(wp, lnum))
1081 char_attr =
1082 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1083 else
1084 char_attr =
1085 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001086 }
1087 }
1088 }
1089#endif
1090
1091#ifdef FEAT_SIGNS
1092 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1093 {
1094 draw_state = WL_SIGN;
1095 // Show the sign column when there are any signs in this
1096 // buffer or when using Netbeans.
1097 if (signcolumn_on(wp))
1098 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1099 row, startrow, filler_lines, filler_todo, &c_extra,
1100 &c_final, extra, &p_extra, &n_extra, &char_attr);
1101 }
1102#endif
1103
1104 if (draw_state == WL_NR - 1 && n_extra == 0)
1105 {
1106 draw_state = WL_NR;
1107 // Display the absolute or relative line number. After the
1108 // first fill with blanks when the 'n' flag isn't in 'cpo'
1109 if ((wp->w_p_nu || wp->w_p_rnu)
1110 && (row == startrow
1111#ifdef FEAT_DIFF
1112 + filler_lines
1113#endif
1114 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1115 {
1116#ifdef FEAT_SIGNS
1117 // If 'signcolumn' is set to 'number' and a sign is present
1118 // in 'lnum', then display the sign instead of the line
1119 // number.
1120 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1121 && sign_present)
1122 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1123 row, startrow, filler_lines, filler_todo,
1124 &c_extra, &c_final, extra, &p_extra, &n_extra,
1125 &char_attr);
1126 else
1127#endif
1128 {
1129 // Draw the line number (empty space after wrapping).
1130 if (row == startrow
1131#ifdef FEAT_DIFF
1132 + filler_lines
1133#endif
1134 )
1135 {
1136 long num;
1137 char *fmt = "%*ld ";
1138
1139 if (wp->w_p_nu && !wp->w_p_rnu)
1140 // 'number' + 'norelativenumber'
1141 num = (long)lnum;
1142 else
1143 {
1144 // 'relativenumber', don't use negative numbers
1145 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1146 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1147 {
1148 // 'number' + 'relativenumber'
1149 num = lnum;
1150 fmt = "%-*ld ";
1151 }
1152 }
1153
1154 sprintf((char *)extra, fmt,
1155 number_width(wp), num);
1156 if (wp->w_skipcol > 0)
1157 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1158 *p_extra = '-';
1159#ifdef FEAT_RIGHTLEFT
1160 if (wp->w_p_rl) // reverse line numbers
1161 {
1162 char_u *p1, *p2;
1163 int t;
1164
1165 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001166 p2 = skipwhite(extra);
1167 p2 = skiptowhite(p2) - 1;
1168 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 {
1170 t = *p1;
1171 *p1 = *p2;
1172 *p2 = t;
1173 }
1174 }
1175#endif
1176 p_extra = extra;
1177 c_extra = NUL;
1178 c_final = NUL;
1179 }
1180 else
1181 {
1182 c_extra = ' ';
1183 c_final = NUL;
1184 }
1185 n_extra = number_width(wp) + 1;
1186 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1187#ifdef FEAT_SYN_HL
1188 // When 'cursorline' is set highlight the line number of
1189 // the current line differently.
1190 // When 'cursorlineopt' has "screenline" only highlight
1191 // the line number itself.
1192 // TODO: Can we use CursorLine instead of CursorLineNr
1193 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001194 if (wp->w_p_cul
1195 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 && (wp->w_p_culopt_flags & CULOPT_NBR)
1197 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001198 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001199 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1200#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001201 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1202 && HL_ATTR(HLF_LNA) != 0)
1203 // Use LineNrAbove
1204 char_attr = hl_combine_attr(wcr_attr,
1205 HL_ATTR(HLF_LNA));
1206 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1207 && HL_ATTR(HLF_LNB) != 0)
1208 // Use LineNrBelow
1209 char_attr = hl_combine_attr(wcr_attr,
1210 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 }
James McCoya80aad72021-12-22 19:45:28 +00001212#ifdef FEAT_SIGNS
1213 if (num_attr)
1214 char_attr = num_attr;
1215#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001216 }
1217 }
1218
1219#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001220 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001221 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001222 // draw indent after showbreak value
1223 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001224 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001225 // After the showbreak, draw the breakindent
1226 draw_state = WL_BRI - 1;
1227
1228 // draw 'breakindent': indent wrapped text accordingly
1229 if (draw_state == WL_BRI - 1 && n_extra == 0)
1230 {
1231 draw_state = WL_BRI;
1232 // if need_showbreak is set, breakindent also applies
1233 if (wp->w_p_bri && n_extra == 0
1234 && (row != startrow || need_showbreak)
1235# ifdef FEAT_DIFF
1236 && filler_lines == 0
1237# endif
1238 )
1239 {
1240 char_attr = 0;
1241# ifdef FEAT_DIFF
1242 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001243 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244# endif
1245 p_extra = NULL;
1246 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001247 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 n_extra = get_breakindent_win(wp,
1249 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001250 if (row == startrow)
1251 {
1252 n_extra -= win_col_off2(wp);
1253 if (n_extra < 0)
1254 n_extra = 0;
1255 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001256 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001257 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 // Correct end of highlighted area for 'breakindent',
1259 // required when 'linebreak' is also set.
1260 if (tocol == vcol)
1261 tocol += n_extra;
1262 }
1263 }
1264#endif
1265
1266#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1267 if (draw_state == WL_SBR - 1 && n_extra == 0)
1268 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001269 char_u *sbr;
1270
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 draw_state = WL_SBR;
1272# ifdef FEAT_DIFF
1273 if (filler_todo > 0)
1274 {
1275 // Draw "deleted" diff line(s).
1276 if (char2cells(fill_diff) > 1)
1277 {
1278 c_extra = '-';
1279 c_final = NUL;
1280 }
1281 else
1282 {
1283 c_extra = fill_diff;
1284 c_final = NUL;
1285 }
1286# ifdef FEAT_RIGHTLEFT
1287 if (wp->w_p_rl)
1288 n_extra = col + 1;
1289 else
1290# endif
1291 n_extra = wp->w_width - col;
1292 char_attr = HL_ATTR(HLF_DED);
1293 }
1294# endif
1295# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001296 sbr = get_showbreak_value(wp);
1297 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001298 {
1299 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001300 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301 c_extra = NUL;
1302 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001303 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001304 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1305 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001306 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001307 // Correct end of highlighted area for 'showbreak',
1308 // required when 'linebreak' is also set.
1309 if (tocol == vcol)
1310 tocol += n_extra;
1311 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001312 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001313# ifdef FEAT_SYN_HL
1314 // combine 'showbreak' with 'cursorline'
1315 if (cul_attr != 0)
1316 char_attr = hl_combine_attr(char_attr, cul_attr);
1317# endif
1318 }
1319# endif
1320 }
1321#endif
1322
1323 if (draw_state == WL_LINE - 1 && n_extra == 0)
1324 {
1325 draw_state = WL_LINE;
1326 if (saved_n_extra)
1327 {
1328 // Continue item from end of wrapped line.
1329 n_extra = saved_n_extra;
1330 c_extra = saved_c_extra;
1331 c_final = saved_c_final;
1332 p_extra = saved_p_extra;
1333 char_attr = saved_char_attr;
1334 }
1335 else
1336 char_attr = win_attr;
1337 }
1338 }
1339#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001340 if (cul_screenline && draw_state == WL_LINE
1341 && vcol >= left_curline_col
1342 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001344 cul_attr = HL_ATTR(HLF_CUL);
1345 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001346 }
1347#endif
1348
1349 // When still displaying '$' of change command, stop at cursor.
1350 // When only displaying the (relative) line number and that's done,
1351 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001352 if (((dollar_vcol >= 0 && wp == curwin
1353 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1354 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355#ifdef FEAT_DIFF
1356 && filler_todo <= 0
1357#endif
1358 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001359 {
1360 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1361 screen_line_flags);
1362 // Pretend we have finished updating the window. Except when
1363 // 'cursorcolumn' is set.
1364#ifdef FEAT_SYN_HL
1365 if (wp->w_p_cuc)
1366 row = wp->w_cline_row + wp->w_cline_height;
1367 else
1368#endif
1369 row = wp->w_height;
1370 break;
1371 }
1372
Bram Moolenaar34390282019-10-16 14:38:26 +02001373 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 {
1375 // handle Visual or match highlighting in this line
1376 if (vcol == fromcol
1377 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1378 && (*mb_ptr2cells)(ptr) > 1)
1379 || ((int)vcol_prev == fromcol_prev
1380 && vcol_prev < vcol // not at margin
1381 && vcol < tocol))
1382 area_attr = vi_attr; // start highlighting
1383 else if (area_attr != 0
1384 && (vcol == tocol
1385 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1386 area_attr = 0; // stop highlighting
1387
1388#ifdef FEAT_SEARCH_EXTRA
1389 if (!n_extra)
1390 {
1391 // Check for start/end of 'hlsearch' and other matches.
1392 // After end, check for start/end of next match.
1393 // When another match, have to check for start again.
1394 v = (long)(ptr - line);
1395 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1396 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001397 &match_conc, did_line_attr, lcs_eol_one,
1398 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001400
1401 // Do not allow a conceal over EOL otherwise EOL will be missed
1402 // and bad things happen.
1403 if (*ptr == NUL)
1404 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 }
1406#endif
1407
1408#ifdef FEAT_DIFF
1409 if (diff_hlf != (hlf_T)0)
1410 {
1411 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1412 && n_extra == 0)
1413 diff_hlf = HLF_TXD; // changed text
1414 if (diff_hlf == HLF_TXD && ptr - line > change_end
1415 && n_extra == 0)
1416 diff_hlf = HLF_CHD; // changed line
1417 line_attr = HL_ATTR(diff_hlf);
1418 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1419 && wp->w_p_culopt_flags != CULOPT_NBR
1420 && (!cul_screenline || (vcol >= left_curline_col
1421 && vcol <= right_curline_col)))
1422 line_attr = hl_combine_attr(
1423 line_attr, HL_ATTR(HLF_CUL));
1424 }
1425#endif
1426
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001427#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001428 if (text_props != NULL)
1429 {
1430 int pi;
1431 int bcol = (int)(ptr - line);
1432
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001433 if (n_extra > 0
1434# ifdef FEAT_LINEBREAK
1435 && !in_linebreak
1436# endif
1437 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001438 --bcol; // still working on the previous char, e.g. Tab
1439
1440 // Check if any active property ends.
1441 for (pi = 0; pi < text_props_active; ++pi)
1442 {
1443 int tpi = text_prop_idxs[pi];
1444
1445 if (bcol >= text_props[tpi].tp_col - 1
1446 + text_props[tpi].tp_len)
1447 {
1448 if (pi + 1 < text_props_active)
1449 mch_memmove(text_prop_idxs + pi,
1450 text_prop_idxs + pi + 1,
1451 sizeof(int)
1452 * (text_props_active - (pi + 1)));
1453 --text_props_active;
1454 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001455# ifdef FEAT_LINEBREAK
1456 // not exactly right but should work in most cases
1457 if (in_linebreak && syntax_attr == text_prop_attr)
1458 syntax_attr = 0;
1459# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001460 }
1461 }
1462
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001463# ifdef FEAT_LINEBREAK
1464 if (n_extra > 0 && in_linebreak)
1465 // not on the next char yet, don't start another prop
1466 --bcol;
1467# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001468 // Add any text property that starts in this column.
1469 while (text_prop_next < text_prop_count
1470 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001471 {
1472 if (bcol <= text_props[text_prop_next].tp_col - 1
1473 + text_props[text_prop_next].tp_len)
1474 text_prop_idxs[text_props_active++] = text_prop_next;
1475 ++text_prop_next;
1476 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477
1478 text_prop_attr = 0;
1479 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001480 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 if (text_props_active > 0)
1482 {
1483 // Sort the properties on priority and/or starting last.
1484 // Then combine the attributes, highest priority last.
1485 current_text_props = text_props;
1486 current_buf = wp->w_buffer;
1487 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1488 sizeof(int), text_prop_compare);
1489
1490 for (pi = 0; pi < text_props_active; ++pi)
1491 {
1492 int tpi = text_prop_idxs[pi];
1493 proptype_T *pt = text_prop_type_by_id(
1494 wp->w_buffer, text_props[tpi].tp_type);
1495
1496 if (pt != NULL && pt->pt_hl_id > 0)
1497 {
1498 int pt_attr = syn_id2attr(pt->pt_hl_id);
1499
1500 text_prop_type = pt;
1501 text_prop_attr =
1502 hl_combine_attr(text_prop_attr, pt_attr);
1503 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1504 }
1505 }
1506 }
1507 }
1508#endif
1509
Bram Moolenaara74fda62019-10-19 17:38:03 +02001510#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001511 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001512 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001513 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001514# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001515 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001516 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001517# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001518 // Get syntax attribute.
1519 if (has_syntax)
1520 {
1521 // Get the syntax attribute for the character. If there
1522 // is an error, disable syntax highlighting.
1523 save_did_emsg = did_emsg;
1524 did_emsg = FALSE;
1525
1526 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001527 if (v == prev_syntax_col)
1528 // at same column again
1529 syntax_attr = prev_syntax_attr;
1530 else
1531 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001532# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001533 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001534# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001535 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001536# ifdef FEAT_SPELL
1537 has_spell ? &can_spell :
1538# endif
1539 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001540 prev_syntax_col = v;
1541 prev_syntax_attr = syntax_attr;
1542 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001543
Bram Moolenaar34390282019-10-16 14:38:26 +02001544 if (did_emsg)
1545 {
1546 wp->w_s->b_syn_error = TRUE;
1547 has_syntax = FALSE;
1548 syntax_attr = 0;
1549 }
1550 else
1551 did_emsg = save_did_emsg;
1552# ifdef SYN_TIME_LIMIT
1553 if (wp->w_s->b_syn_slow)
1554 has_syntax = FALSE;
1555# endif
1556
1557 // Need to get the line again, a multi-line regexp may
1558 // have made it invalid.
1559 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1560 ptr = line + v;
1561# ifdef FEAT_CONCEAL
1562 // no concealing past the end of the line, it interferes
1563 // with line highlighting
1564 if (*ptr == NUL)
1565 syntax_flags = 0;
1566 else
1567 syntax_flags = get_syntax_info(&syntax_seqnr);
1568# endif
1569 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001570 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001571# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001572 // Combine text property highlight into syntax highlight.
1573 if (text_prop_type != NULL)
1574 {
1575 if (text_prop_combine)
1576 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1577 else
1578 syntax_attr = text_prop_attr;
1579 }
1580# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001581#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 // Decide which of the highlight attributes to use.
1584 attr_pri = TRUE;
1585#ifdef LINE_ATTR
1586 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001587 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001588 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001589 if (!highlight_match)
1590 // let search highlight show in Visual area if possible
1591 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001592# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001593 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001594# endif
1595 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001597 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001599# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001600 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001601# endif
1602 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1604 || vcol < fromcol || vcol_prev < fromcol_prev
1605 || vcol >= tocol))
1606 {
1607 // Use line_attr when not in the Visual or 'incsearch' area
1608 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001609# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001610 char_attr = hl_combine_attr(syntax_attr, line_attr);
1611# else
1612 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001613# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 attr_pri = FALSE;
1615 }
1616#else
1617 if (area_attr != 0)
1618 char_attr = area_attr;
1619 else if (search_attr != 0)
1620 char_attr = search_attr;
1621#endif
1622 else
1623 {
1624 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001625#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001626 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001627#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001628 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001629#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001630 }
1631 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001632
1633 // combine attribute with 'wincolor'
1634 if (win_attr != 0)
1635 {
1636 if (char_attr == 0)
1637 char_attr = win_attr;
1638 else
1639 char_attr = hl_combine_attr(win_attr, char_attr);
1640 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001641
1642 // Get the next character to put on the screen.
1643
1644 // The "p_extra" points to the extra stuff that is inserted to
1645 // represent special characters (non-printable stuff) and other
1646 // things. When all characters are the same, c_extra is used.
1647 // If c_final is set, it will compulsorily be used at the end.
1648 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1649 // "p_extra[n_extra]".
1650 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1651 if (n_extra > 0)
1652 {
1653 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1654 {
1655 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1656 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1657 if (enc_utf8 && utf_char2len(c) > 1)
1658 {
1659 mb_utf8 = TRUE;
1660 u8cc[0] = 0;
1661 c = 0xc0;
1662 }
1663 else
1664 mb_utf8 = FALSE;
1665 }
1666 else
1667 {
1668 c = *p_extra;
1669 if (has_mbyte)
1670 {
1671 mb_c = c;
1672 if (enc_utf8)
1673 {
1674 // If the UTF-8 character is more than one byte:
1675 // Decode it into "mb_c".
1676 mb_l = utfc_ptr2len(p_extra);
1677 mb_utf8 = FALSE;
1678 if (mb_l > n_extra)
1679 mb_l = 1;
1680 else if (mb_l > 1)
1681 {
1682 mb_c = utfc_ptr2char(p_extra, u8cc);
1683 mb_utf8 = TRUE;
1684 c = 0xc0;
1685 }
1686 }
1687 else
1688 {
1689 // if this is a DBCS character, put it in "mb_c"
1690 mb_l = MB_BYTE2LEN(c);
1691 if (mb_l >= n_extra)
1692 mb_l = 1;
1693 else if (mb_l > 1)
1694 mb_c = (c << 8) + p_extra[1];
1695 }
1696 if (mb_l == 0) // at the NUL at end-of-line
1697 mb_l = 1;
1698
1699 // If a double-width char doesn't fit display a '>' in the
1700 // last column.
1701 if ((
1702# ifdef FEAT_RIGHTLEFT
1703 wp->w_p_rl ? (col <= 0) :
1704# endif
1705 (col >= wp->w_width - 1))
1706 && (*mb_char2cells)(mb_c) == 2)
1707 {
1708 c = '>';
1709 mb_c = c;
1710 mb_l = 1;
1711 mb_utf8 = FALSE;
1712 multi_attr = HL_ATTR(HLF_AT);
1713#ifdef FEAT_SYN_HL
1714 if (cul_attr)
1715 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1716#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001717 multi_attr = hl_combine_attr(win_attr, multi_attr);
1718
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001719 // put the pointer back to output the double-width
1720 // character at the start of the next line.
1721 ++n_extra;
1722 --p_extra;
1723 }
1724 else
1725 {
1726 n_extra -= mb_l - 1;
1727 p_extra += mb_l - 1;
1728 }
1729 }
1730 ++p_extra;
1731 }
1732 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001733#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001734 if (n_extra <= 0)
1735 in_linebreak = FALSE;
1736#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001737 }
1738 else
1739 {
1740#ifdef FEAT_LINEBREAK
1741 int c0;
1742#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001743 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001744
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001745 // Get a character from the line itself.
1746 c = *ptr;
1747#ifdef FEAT_LINEBREAK
1748 c0 = *ptr;
1749#endif
1750 if (has_mbyte)
1751 {
1752 mb_c = c;
1753 if (enc_utf8)
1754 {
1755 // If the UTF-8 character is more than one byte: Decode it
1756 // into "mb_c".
1757 mb_l = utfc_ptr2len(ptr);
1758 mb_utf8 = FALSE;
1759 if (mb_l > 1)
1760 {
1761 mb_c = utfc_ptr2char(ptr, u8cc);
1762 // Overlong encoded ASCII or ASCII with composing char
1763 // is displayed normally, except a NUL.
1764 if (mb_c < 0x80)
1765 {
1766 c = mb_c;
1767#ifdef FEAT_LINEBREAK
1768 c0 = mb_c;
1769#endif
1770 }
1771 mb_utf8 = TRUE;
1772
1773 // At start of the line we can have a composing char.
1774 // Draw it as a space with a composing char.
1775 if (utf_iscomposing(mb_c))
1776 {
1777 int i;
1778
1779 for (i = Screen_mco - 1; i > 0; --i)
1780 u8cc[i] = u8cc[i - 1];
1781 u8cc[0] = mb_c;
1782 mb_c = ' ';
1783 }
1784 }
1785
1786 if ((mb_l == 1 && c >= 0x80)
1787 || (mb_l >= 1 && mb_c == 0)
1788 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1789 {
1790 // Illegal UTF-8 byte: display as <xx>.
1791 // Non-BMP character : display as ? or fullwidth ?.
1792 transchar_hex(extra, mb_c);
1793# ifdef FEAT_RIGHTLEFT
1794 if (wp->w_p_rl) // reverse
1795 rl_mirror(extra);
1796# endif
1797 p_extra = extra;
1798 c = *p_extra;
1799 mb_c = mb_ptr2char_adv(&p_extra);
1800 mb_utf8 = (c >= 0x80);
1801 n_extra = (int)STRLEN(p_extra);
1802 c_extra = NUL;
1803 c_final = NUL;
1804 if (area_attr == 0 && search_attr == 0)
1805 {
1806 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001807 extra_attr = hl_combine_attr(
1808 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001809 saved_attr2 = char_attr; // save current attr
1810 }
1811 }
1812 else if (mb_l == 0) // at the NUL at end-of-line
1813 mb_l = 1;
1814#ifdef FEAT_ARABIC
1815 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1816 {
1817 // Do Arabic shaping.
1818 int pc, pc1, nc;
1819 int pcc[MAX_MCO];
1820
1821 // The idea of what is the previous and next
1822 // character depends on 'rightleft'.
1823 if (wp->w_p_rl)
1824 {
1825 pc = prev_c;
1826 pc1 = prev_c1;
1827 nc = utf_ptr2char(ptr + mb_l);
1828 prev_c1 = u8cc[0];
1829 }
1830 else
1831 {
1832 pc = utfc_ptr2char(ptr + mb_l, pcc);
1833 nc = prev_c;
1834 pc1 = pcc[0];
1835 }
1836 prev_c = mb_c;
1837
1838 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1839 }
1840 else
1841 prev_c = mb_c;
1842#endif
1843 }
1844 else // enc_dbcs
1845 {
1846 mb_l = MB_BYTE2LEN(c);
1847 if (mb_l == 0) // at the NUL at end-of-line
1848 mb_l = 1;
1849 else if (mb_l > 1)
1850 {
1851 // We assume a second byte below 32 is illegal.
1852 // Hopefully this is OK for all double-byte encodings!
1853 if (ptr[1] >= 32)
1854 mb_c = (c << 8) + ptr[1];
1855 else
1856 {
1857 if (ptr[1] == NUL)
1858 {
1859 // head byte at end of line
1860 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001861 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001862 }
1863 else
1864 {
1865 // illegal tail byte
1866 mb_l = 2;
1867 STRCPY(extra, "XX");
1868 }
1869 p_extra = extra;
1870 n_extra = (int)STRLEN(extra) - 1;
1871 c_extra = NUL;
1872 c_final = NUL;
1873 c = *p_extra++;
1874 if (area_attr == 0 && search_attr == 0)
1875 {
1876 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001877 extra_attr = hl_combine_attr(
1878 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 saved_attr2 = char_attr; // save current attr
1880 }
1881 mb_c = c;
1882 }
1883 }
1884 }
1885 // If a double-width char doesn't fit display a '>' in the
1886 // last column; the character is displayed at the start of the
1887 // next line.
1888 if ((
1889# ifdef FEAT_RIGHTLEFT
1890 wp->w_p_rl ? (col <= 0) :
1891# endif
1892 (col >= wp->w_width - 1))
1893 && (*mb_char2cells)(mb_c) == 2)
1894 {
1895 c = '>';
1896 mb_c = c;
1897 mb_utf8 = FALSE;
1898 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001899 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001900 // Put pointer back so that the character will be
1901 // displayed at the start of the next line.
1902 --ptr;
1903#ifdef FEAT_CONCEAL
1904 did_decrement_ptr = TRUE;
1905#endif
1906 }
1907 else if (*ptr != NUL)
1908 ptr += mb_l - 1;
1909
1910 // If a double-width char doesn't fit at the left side display
1911 // a '<' in the first column. Don't do this for unprintable
1912 // characters.
1913 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1914 {
1915 n_extra = 1;
1916 c_extra = MB_FILLER_CHAR;
1917 c_final = NUL;
1918 c = ' ';
1919 if (area_attr == 0 && search_attr == 0)
1920 {
1921 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001922 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 saved_attr2 = char_attr; // save current attr
1924 }
1925 mb_c = c;
1926 mb_utf8 = FALSE;
1927 mb_l = 1;
1928 }
1929
1930 }
1931 ++ptr;
1932
1933 if (extra_check)
1934 {
1935#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936 // Check spelling (unless at the end of the line).
1937 // Only do this when there is no syntax highlighting, the
1938 // @Spell cluster is not used or the current syntax item
1939 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001940 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 if (has_spell && v >= word_end && v > cur_checked_col)
1942 {
1943 spell_attr = 0;
1944 if (c != 0 && (
1945# ifdef FEAT_SYN_HL
1946 !has_syntax ||
1947# endif
1948 can_spell))
1949 {
1950 char_u *prev_ptr, *p;
1951 int len;
1952 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001953
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001954 if (has_mbyte)
1955 {
1956 prev_ptr = ptr - mb_l;
1957 v -= mb_l - 1;
1958 }
1959 else
1960 prev_ptr = ptr - 1;
1961
1962 // Use nextline[] if possible, it has the start of the
1963 // next line concatenated.
1964 if ((prev_ptr - line) - nextlinecol >= 0)
1965 p = nextline + (prev_ptr - line) - nextlinecol;
1966 else
1967 p = prev_ptr;
1968 cap_col -= (int)(prev_ptr - line);
1969 len = spell_check(wp, p, &spell_hlf, &cap_col,
1970 nochange);
1971 word_end = v + len;
1972
1973 // In Insert mode only highlight a word that
1974 // doesn't touch the cursor.
1975 if (spell_hlf != HLF_COUNT
1976 && (State & INSERT) != 0
1977 && wp->w_cursor.lnum == lnum
1978 && wp->w_cursor.col >=
1979 (colnr_T)(prev_ptr - line)
1980 && wp->w_cursor.col < (colnr_T)word_end)
1981 {
1982 spell_hlf = HLF_COUNT;
1983 spell_redraw_lnum = lnum;
1984 }
1985
1986 if (spell_hlf == HLF_COUNT && p != prev_ptr
1987 && (p - nextline) + len > nextline_idx)
1988 {
1989 // Remember that the good word continues at the
1990 // start of the next line.
1991 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001992 checked_col = (int)((p - nextline)
1993 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 }
1995
1996 // Turn index into actual attributes.
1997 if (spell_hlf != HLF_COUNT)
1998 spell_attr = highlight_attr[spell_hlf];
1999
2000 if (cap_col > 0)
2001 {
2002 if (p != prev_ptr
2003 && (p - nextline) + cap_col >= nextline_idx)
2004 {
2005 // Remember that the word in the next line
2006 // must start with a capital.
2007 capcol_lnum = lnum + 1;
2008 cap_col = (int)((p - nextline) + cap_col
2009 - nextline_idx);
2010 }
2011 else
2012 // Compute the actual column.
2013 cap_col += (int)(prev_ptr - line);
2014 }
2015 }
2016 }
2017 if (spell_attr != 0)
2018 {
2019 if (!attr_pri)
2020 char_attr = hl_combine_attr(char_attr, spell_attr);
2021 else
2022 char_attr = hl_combine_attr(spell_attr, char_attr);
2023 }
2024#endif
2025#ifdef FEAT_LINEBREAK
2026 // Found last space before word: check for line break.
2027 if (wp->w_p_lbr && c0 == c
2028 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2029 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002030 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2031 : 0;
2032 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033
2034 // TODO: is passing p for start of the line OK?
2035 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2036 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002037
2038 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002039 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002040 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002041 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002042 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002043 if (n_extra < 0)
2044 n_extra = 0;
2045 }
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002046 if (on_last_col)
2047 // Do not continue search/match highlighting over the
2048 // line break.
2049 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002050
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002051 if (c == TAB && n_extra + col > wp->w_width)
2052# ifdef FEAT_VARTABS
2053 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2054 wp->w_buffer->b_p_vts_array) - 1;
2055# else
2056 n_extra = (int)wp->w_buffer->b_p_ts
2057 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2058# endif
2059
2060 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2061 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002062# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002063 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002064 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002065# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 if (VIM_ISWHITE(c))
2067 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002068# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002069 if (c == TAB)
2070 // See "Tab alignment" below.
2071 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002072# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 if (!wp->w_p_list)
2074 c = ' ';
2075 }
2076 }
2077#endif
2078
zeertzjqf14b8ba2021-09-10 16:58:30 +02002079 in_multispace = c == ' '
2080 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2081 if (!in_multispace)
2082 multispace_pos = 0;
2083
Bram Moolenaareed9d462021-02-15 20:38:25 +01002084 // 'list': Change char 160 to 'nbsp' and space to 'space'
2085 // setting in 'listchars'. But not when the character is
2086 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 if (wp->w_p_list
2088 && ((((c == 160 && mb_l == 1)
2089 || (mb_utf8
2090 && ((mb_c == 160 && mb_l == 2)
2091 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002092 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 || (c == ' '
2094 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002095 && (wp->w_lcs_chars.space
2096 || (in_multispace
2097 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002098 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002099 && ptr - line <= trailcol)))
2100 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002101 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2102 {
2103 c = wp->w_lcs_chars.multispace[multispace_pos++];
2104 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2105 multispace_pos = 0;
2106 }
2107 else
2108 c = (c == ' ') ? wp->w_lcs_chars.space
2109 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 if (area_attr == 0 && search_attr == 0)
2111 {
2112 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002113 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002114 saved_attr2 = char_attr; // save current attr
2115 }
2116 mb_c = c;
2117 if (enc_utf8 && utf_char2len(c) > 1)
2118 {
2119 mb_utf8 = TRUE;
2120 u8cc[0] = 0;
2121 c = 0xc0;
2122 }
2123 else
2124 mb_utf8 = FALSE;
2125 }
2126
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002127 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2128 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002129 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002130 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2131 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002132 if (!attr_pri)
2133 {
2134 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002135 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002136 saved_attr2 = char_attr; // save current attr
2137 }
2138 mb_c = c;
2139 if (enc_utf8 && utf_char2len(c) > 1)
2140 {
2141 mb_utf8 = TRUE;
2142 u8cc[0] = 0;
2143 c = 0xc0;
2144 }
2145 else
2146 mb_utf8 = FALSE;
2147 }
2148 }
2149
2150 // Handling of non-printable characters.
2151 if (!vim_isprintc(c))
2152 {
2153 // when getting a character from the file, we may have to
2154 // turn it into something else on the way to putting it
2155 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002156 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 {
2158 int tab_len = 0;
2159 long vcol_adjusted = vcol; // removed showbreak length
2160#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002161 char_u *sbr = get_showbreak_value(wp);
2162
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 // only adjust the tab_len, when at the first column
2164 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002165 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2166 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167#endif
2168 // tab amount depends on current column
2169#ifdef FEAT_VARTABS
2170 tab_len = tabstop_padding(vcol_adjusted,
2171 wp->w_buffer->b_p_ts,
2172 wp->w_buffer->b_p_vts_array) - 1;
2173#else
2174 tab_len = (int)wp->w_buffer->b_p_ts
2175 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2176#endif
2177
2178#ifdef FEAT_LINEBREAK
2179 if (!wp->w_p_lbr || !wp->w_p_list)
2180#endif
2181 // tab amount depends on current column
2182 n_extra = tab_len;
2183#ifdef FEAT_LINEBREAK
2184 else
2185 {
2186 char_u *p;
2187 int len;
2188 int i;
2189 int saved_nextra = n_extra;
2190
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002191# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002192 if (vcol_off > 0)
2193 // there are characters to conceal
2194 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002195
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002197 if (wp->w_p_list && wp->w_lcs_chars.tab1
2198 && old_boguscols > 0
2199 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002201# endif
2202 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002204 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002205 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002206 if (wp->w_lcs_chars.tab3)
2207 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 if (n_extra > 0)
2209 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002210 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002212 if (p == NULL)
2213 n_extra = 0;
2214 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002215 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002216 vim_memset(p, ' ', len);
2217 p[len] = NUL;
2218 vim_free(p_extra_free);
2219 p_extra_free = p;
2220 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002221 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002222 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002224 if (*p == NUL)
2225 {
2226 tab_len = i;
2227 break;
2228 }
2229
2230 // if tab3 is given, use it for the last char
2231 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2232 lcs = wp->w_lcs_chars.tab3;
2233 p += mb_char2bytes(lcs, p);
2234 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002235 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002236 }
2237 p_extra = p_extra_free;
2238# ifdef FEAT_CONCEAL
2239 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2240 // macro below, so need to adjust for that here
2241 if (vcol_off > 0)
2242 n_extra -= vcol_off;
2243# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002244 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002245 }
2246#endif
2247#ifdef FEAT_CONCEAL
2248 {
2249 int vc_saved = vcol_off;
2250
2251 // Tab alignment should be identical regardless of
2252 // 'conceallevel' value. So tab compensates of all
2253 // previous concealed characters, and thus resets
2254 // vcol_off and boguscols accumulated so far in the
2255 // line. Note that the tab can be longer than
2256 // 'tabstop' when there are concealed characters.
2257 FIX_FOR_BOGUSCOLS;
2258
2259 // Make sure, the highlighting for the tab char will be
2260 // correctly set further below (effectively reverts the
2261 // FIX_FOR_BOGSUCOLS macro
2262 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002263 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002264 tab_len += vc_saved;
2265 }
2266#endif
2267 mb_utf8 = FALSE; // don't draw as UTF-8
2268 if (wp->w_p_list)
2269 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002270 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2271 ? wp->w_lcs_chars.tab3
2272 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002273#ifdef FEAT_LINEBREAK
2274 if (wp->w_p_lbr)
2275 c_extra = NUL; // using p_extra from above
2276 else
2277#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002278 c_extra = wp->w_lcs_chars.tab2;
2279 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002280 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002281 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002282 saved_attr2 = char_attr; // save current attr
2283 mb_c = c;
2284 if (enc_utf8 && utf_char2len(c) > 1)
2285 {
2286 mb_utf8 = TRUE;
2287 u8cc[0] = 0;
2288 c = 0xc0;
2289 }
2290 }
2291 else
2292 {
2293 c_final = NUL;
2294 c_extra = ' ';
2295 c = ' ';
2296 }
2297 }
2298 else if (c == NUL
2299 && (wp->w_p_list
2300 || ((fromcol >= 0 || fromcol_prev >= 0)
2301 && tocol > vcol
2302 && VIsual_mode != Ctrl_V
2303 && (
2304# ifdef FEAT_RIGHTLEFT
2305 wp->w_p_rl ? (col >= 0) :
2306# endif
2307 (col < wp->w_width))
2308 && !(noinvcur
2309 && lnum == wp->w_cursor.lnum
2310 && (colnr_T)vcol == wp->w_virtcol)))
2311 && lcs_eol_one > 0)
2312 {
2313 // Display a '$' after the line or highlight an extra
2314 // character if the line break is included.
2315#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2316 // For a diff line the highlighting continues after the
2317 // "$".
2318 if (
2319# ifdef FEAT_DIFF
2320 diff_hlf == (hlf_T)0
2321# ifdef LINE_ATTR
2322 &&
2323# endif
2324# endif
2325# ifdef LINE_ATTR
2326 line_attr == 0
2327# endif
2328 )
2329#endif
2330 {
2331 // In virtualedit, visual selections may extend
2332 // beyond end of line.
2333 if (area_highlighting && virtual_active()
2334 && tocol != MAXCOL && vcol < tocol)
2335 n_extra = 0;
2336 else
2337 {
2338 p_extra = at_end_str;
2339 n_extra = 1;
2340 c_extra = NUL;
2341 c_final = NUL;
2342 }
2343 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002344 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2345 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002346 else
2347 c = ' ';
2348 lcs_eol_one = -1;
2349 --ptr; // put it back at the NUL
2350 if (!attr_pri)
2351 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002352 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353 n_attr = 1;
2354 }
2355 mb_c = c;
2356 if (enc_utf8 && utf_char2len(c) > 1)
2357 {
2358 mb_utf8 = TRUE;
2359 u8cc[0] = 0;
2360 c = 0xc0;
2361 }
2362 else
2363 mb_utf8 = FALSE; // don't draw as UTF-8
2364 }
2365 else if (c != NUL)
2366 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002367 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002368 if (n_extra == 0)
2369 n_extra = byte2cells(c) - 1;
2370#ifdef FEAT_RIGHTLEFT
2371 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2372 rl_mirror(p_extra); // reverse "<12>"
2373#endif
2374 c_extra = NUL;
2375 c_final = NUL;
2376#ifdef FEAT_LINEBREAK
2377 if (wp->w_p_lbr)
2378 {
2379 char_u *p;
2380
2381 c = *p_extra;
2382 p = alloc(n_extra + 1);
2383 vim_memset(p, ' ', n_extra);
2384 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2385 p[n_extra] = NUL;
2386 vim_free(p_extra_free);
2387 p_extra_free = p_extra = p;
2388 }
2389 else
2390#endif
2391 {
2392 n_extra = byte2cells(c) - 1;
2393 c = *p_extra++;
2394 }
2395 if (!attr_pri)
2396 {
2397 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002398 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002399 saved_attr2 = char_attr; // save current attr
2400 }
2401 mb_utf8 = FALSE; // don't draw as UTF-8
2402 }
2403 else if (VIsual_active
2404 && (VIsual_mode == Ctrl_V
2405 || VIsual_mode == 'v')
2406 && virtual_active()
2407 && tocol != MAXCOL
2408 && vcol < tocol
2409 && (
2410#ifdef FEAT_RIGHTLEFT
2411 wp->w_p_rl ? (col >= 0) :
2412#endif
2413 (col < wp->w_width)))
2414 {
2415 c = ' ';
2416 --ptr; // put it back at the NUL
2417 }
2418#if defined(LINE_ATTR)
2419 else if ((
2420# ifdef FEAT_DIFF
2421 diff_hlf != (hlf_T)0 ||
2422# endif
2423# ifdef FEAT_TERMINAL
2424 win_attr != 0 ||
2425# endif
2426 line_attr != 0
2427 ) && (
2428# ifdef FEAT_RIGHTLEFT
2429 wp->w_p_rl ? (col >= 0) :
2430# endif
2431 (col
2432# ifdef FEAT_CONCEAL
2433 - boguscols
2434# endif
2435 < wp->w_width)))
2436 {
2437 // Highlight until the right side of the window
2438 c = ' ';
2439 --ptr; // put it back at the NUL
2440
2441 // Remember we do the char for line highlighting.
2442 ++did_line_attr;
2443
2444 // don't do search HL for the rest of the line
2445 if (line_attr != 0 && char_attr == search_attr
2446 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002447 || (wp->w_p_list &&
2448 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002449 char_attr = line_attr;
2450# ifdef FEAT_DIFF
2451 if (diff_hlf == HLF_TXD)
2452 {
2453 diff_hlf = HLF_CHD;
2454 if (vi_attr == 0 || char_attr != vi_attr)
2455 {
2456 char_attr = HL_ATTR(diff_hlf);
2457 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2458 && wp->w_p_culopt_flags != CULOPT_NBR
2459 && (!cul_screenline
2460 || (vcol >= left_curline_col
2461 && vcol <= right_curline_col)))
2462 char_attr = hl_combine_attr(
2463 char_attr, HL_ATTR(HLF_CUL));
2464 }
2465 }
2466# endif
2467# ifdef FEAT_TERMINAL
2468 if (win_attr != 0)
2469 {
2470 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002471 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2472 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002473 {
2474 if (!cul_screenline || (vcol >= left_curline_col
2475 && vcol <= right_curline_col))
2476 char_attr = hl_combine_attr(
2477 char_attr, HL_ATTR(HLF_CUL));
2478 }
2479 else if (line_attr)
2480 char_attr = hl_combine_attr(char_attr, line_attr);
2481 }
2482# endif
2483 }
2484#endif
2485 }
2486
2487#ifdef FEAT_CONCEAL
2488 if ( wp->w_p_cole > 0
2489 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2490 conceal_cursor_line(wp))
2491 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2492 && !(lnum_in_visual_area
2493 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2494 {
2495 char_attr = conceal_attr;
2496 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002497 && (syn_get_sub_char() != NUL
2498 || (has_match_conc && match_conc)
2499 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002500 && wp->w_p_cole != 3)
2501 {
2502 // First time at this concealed item: display one
2503 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002504 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 c = match_conc;
2506 else if (syn_get_sub_char() != NUL)
2507 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002508 else if (wp->w_lcs_chars.conceal != NUL)
2509 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002510 else
2511 c = ' ';
2512
2513 prev_syntax_id = syntax_seqnr;
2514
2515 if (n_extra > 0)
2516 vcol_off += n_extra;
2517 vcol += n_extra;
2518 if (wp->w_p_wrap && n_extra > 0)
2519 {
2520# ifdef FEAT_RIGHTLEFT
2521 if (wp->w_p_rl)
2522 {
2523 col -= n_extra;
2524 boguscols -= n_extra;
2525 }
2526 else
2527# endif
2528 {
2529 boguscols += n_extra;
2530 col += n_extra;
2531 }
2532 }
2533 n_extra = 0;
2534 n_attr = 0;
2535 }
2536 else if (n_skip == 0)
2537 {
2538 is_concealing = TRUE;
2539 n_skip = 1;
2540 }
2541 mb_c = c;
2542 if (enc_utf8 && utf_char2len(c) > 1)
2543 {
2544 mb_utf8 = TRUE;
2545 u8cc[0] = 0;
2546 c = 0xc0;
2547 }
2548 else
2549 mb_utf8 = FALSE; // don't draw as UTF-8
2550 }
2551 else
2552 {
2553 prev_syntax_id = 0;
2554 is_concealing = FALSE;
2555 }
2556
2557 if (n_skip > 0 && did_decrement_ptr)
2558 // not showing the '>', put pointer back to avoid getting stuck
2559 ++ptr;
2560
2561#endif // FEAT_CONCEAL
2562 }
2563
2564#ifdef FEAT_CONCEAL
2565 // In the cursor line and we may be concealing characters: correct
2566 // the cursor column when we reach its position.
2567 if (!did_wcol && draw_state == WL_LINE
2568 && wp == curwin && lnum == wp->w_cursor.lnum
2569 && conceal_cursor_line(wp)
2570 && (int)wp->w_virtcol <= vcol + n_skip)
2571 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002572# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 if (wp->w_p_rl)
2574 wp->w_wcol = wp->w_width - col + boguscols - 1;
2575 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002576# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002577 wp->w_wcol = col - boguscols;
2578 wp->w_wrow = row;
2579 did_wcol = TRUE;
2580 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002581# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002582 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002583# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002584 }
2585#endif
2586
2587 // Don't override visual selection highlighting.
2588 if (n_attr > 0
2589 && draw_state == WL_LINE
2590 && !attr_pri)
2591 {
2592#ifdef LINE_ATTR
2593 if (line_attr)
2594 char_attr = hl_combine_attr(extra_attr, line_attr);
2595 else
2596#endif
2597 char_attr = extra_attr;
2598 }
2599
2600#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2601 // XIM don't send preedit_start and preedit_end, but they send
2602 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2603 // im_is_preediting() here.
2604 if (p_imst == IM_ON_THE_SPOT
2605 && xic != NULL
2606 && lnum == wp->w_cursor.lnum
2607 && (State & INSERT)
2608 && !p_imdisable
2609 && im_is_preediting()
2610 && draw_state == WL_LINE)
2611 {
2612 colnr_T tcol;
2613
2614 if (preedit_end_col == MAXCOL)
2615 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2616 else
2617 tcol = preedit_end_col;
2618 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2619 {
2620 if (feedback_old_attr < 0)
2621 {
2622 feedback_col = 0;
2623 feedback_old_attr = char_attr;
2624 }
2625 char_attr = im_get_feedback_attr(feedback_col);
2626 if (char_attr < 0)
2627 char_attr = feedback_old_attr;
2628 feedback_col++;
2629 }
2630 else if (feedback_old_attr >= 0)
2631 {
2632 char_attr = feedback_old_attr;
2633 feedback_old_attr = -1;
2634 feedback_col = 0;
2635 }
2636 }
2637#endif
2638 // Handle the case where we are in column 0 but not on the first
2639 // character of the line and the user wants us to show us a
2640 // special character (via 'listchars' option "precedes:<char>".
2641 if (lcs_prec_todo != NUL
2642 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002643 && (wp->w_p_wrap ?
2644 (wp->w_skipcol > 0 && row == 0) :
2645 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646#ifdef FEAT_DIFF
2647 && filler_todo <= 0
2648#endif
2649 && draw_state > WL_NR
2650 && c != NUL)
2651 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002652 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653 lcs_prec_todo = NUL;
2654 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2655 {
2656 // Double-width character being overwritten by the "precedes"
2657 // character, need to fill up half the character.
2658 c_extra = MB_FILLER_CHAR;
2659 c_final = NUL;
2660 n_extra = 1;
2661 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002662 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002663 }
2664 mb_c = c;
2665 if (enc_utf8 && utf_char2len(c) > 1)
2666 {
2667 mb_utf8 = TRUE;
2668 u8cc[0] = 0;
2669 c = 0xc0;
2670 }
2671 else
2672 mb_utf8 = FALSE; // don't draw as UTF-8
2673 if (!attr_pri)
2674 {
2675 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002676 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 n_attr3 = 1;
2678 }
2679 }
2680
2681 // At end of the text line or just after the last character.
2682 if ((c == NUL
2683#if defined(LINE_ATTR)
2684 || did_line_attr == 1
2685#endif
2686 ) && eol_hl_off == 0)
2687 {
2688#ifdef FEAT_SEARCH_EXTRA
2689 // flag to indicate whether prevcol equals startcol of search_hl or
2690 // one of the matches
2691 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2692 (long)(ptr - line) - (c == NUL));
2693#endif
2694 // Invert at least one char, used for Visual and empty line or
2695 // highlight match at end of line. If it's beyond the last
2696 // char on the screen, just overwrite that one (tricky!) Not
2697 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002698 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002699 && ((area_attr != 0 && vcol == fromcol
2700 && (VIsual_mode != Ctrl_V
2701 || lnum == VIsual.lnum
2702 || lnum == curwin->w_cursor.lnum)
2703 && c == NUL)
2704#ifdef FEAT_SEARCH_EXTRA
2705 // highlight 'hlsearch' match at end of line
2706 || (prevcol_hl_flag
2707# ifdef FEAT_SYN_HL
2708 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2709 && !(wp == curwin && VIsual_active))
2710# endif
2711# ifdef FEAT_DIFF
2712 && diff_hlf == (hlf_T)0
2713# endif
2714# if defined(LINE_ATTR)
2715 && did_line_attr <= 1
2716# endif
2717 )
2718#endif
2719 ))
2720 {
2721 int n = 0;
2722
2723#ifdef FEAT_RIGHTLEFT
2724 if (wp->w_p_rl)
2725 {
2726 if (col < 0)
2727 n = 1;
2728 }
2729 else
2730#endif
2731 {
2732 if (col >= wp->w_width)
2733 n = -1;
2734 }
2735 if (n != 0)
2736 {
2737 // At the window boundary, highlight the last character
2738 // instead (better than nothing).
2739 off += n;
2740 col += n;
2741 }
2742 else
2743 {
2744 // Add a blank character to highlight.
2745 ScreenLines[off] = ' ';
2746 if (enc_utf8)
2747 ScreenLinesUC[off] = 0;
2748 }
2749#ifdef FEAT_SEARCH_EXTRA
2750 if (area_attr == 0)
2751 {
2752 // Use attributes from match with highest priority among
2753 // 'search_hl' and the match list.
2754 get_search_match_hl(wp, &screen_search_hl,
2755 (long)(ptr - line), &char_attr);
2756 }
2757#endif
2758 ScreenAttrs[off] = char_attr;
2759#ifdef FEAT_RIGHTLEFT
2760 if (wp->w_p_rl)
2761 {
2762 --col;
2763 --off;
2764 }
2765 else
2766#endif
2767 {
2768 ++col;
2769 ++off;
2770 }
2771 ++vcol;
2772 eol_hl_off = 1;
2773 }
2774 }
2775
2776 // At end of the text line.
2777 if (c == NUL)
2778 {
2779#ifdef FEAT_SYN_HL
2780 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2781 if (wp->w_p_wrap)
2782 v = wp->w_skipcol;
2783 else
2784 v = wp->w_leftcol;
2785
2786 // check if line ends before left margin
2787 if (vcol < v + col - win_col_off(wp))
2788 vcol = v + col - win_col_off(wp);
2789#ifdef FEAT_CONCEAL
2790 // Get rid of the boguscols now, we want to draw until the right
2791 // edge for 'cursorcolumn'.
2792 col -= boguscols;
2793 boguscols = 0;
2794#endif
2795
2796 if (draw_color_col)
2797 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2798
2799 if (((wp->w_p_cuc
2800 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2801 && (int)wp->w_virtcol <
2802 wp->w_width * (row - startrow + 1) + v
2803 && lnum != wp->w_cursor.lnum)
2804 || draw_color_col
2805 || win_attr != 0)
2806# ifdef FEAT_RIGHTLEFT
2807 && !wp->w_p_rl
2808# endif
2809 )
2810 {
2811 int rightmost_vcol = 0;
2812 int i;
2813
2814 if (wp->w_p_cuc)
2815 rightmost_vcol = wp->w_virtcol;
2816 if (draw_color_col)
2817 // determine rightmost colorcolumn to possibly draw
2818 for (i = 0; color_cols[i] >= 0; ++i)
2819 if (rightmost_vcol < color_cols[i])
2820 rightmost_vcol = color_cols[i];
2821
2822 while (col < wp->w_width)
2823 {
2824 ScreenLines[off] = ' ';
2825 if (enc_utf8)
2826 ScreenLinesUC[off] = 0;
2827 ++col;
2828 if (draw_color_col)
2829 draw_color_col = advance_color_col(VCOL_HLC,
2830 &color_cols);
2831
2832 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2833 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2834 else if (draw_color_col && VCOL_HLC == *color_cols)
2835 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2836 else
2837 ScreenAttrs[off++] = win_attr;
2838
2839 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2840 break;
2841
2842 ++vcol;
2843 }
2844 }
2845#endif
2846
2847 screen_line(screen_row, wp->w_wincol, col,
2848 (int)wp->w_width, screen_line_flags);
2849 row++;
2850
2851 // Update w_cline_height and w_cline_folded if the cursor line was
2852 // updated (saves a call to plines() later).
2853 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2854 {
2855 curwin->w_cline_row = startrow;
2856 curwin->w_cline_height = row - startrow;
2857#ifdef FEAT_FOLDING
2858 curwin->w_cline_folded = FALSE;
2859#endif
2860 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2861 }
2862
2863 break;
2864 }
2865
2866 // Show "extends" character from 'listchars' if beyond the line end and
2867 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002868 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002869 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002870 && wp->w_p_list
2871 && !wp->w_p_wrap
2872#ifdef FEAT_DIFF
2873 && filler_todo <= 0
2874#endif
2875 && (
2876#ifdef FEAT_RIGHTLEFT
2877 wp->w_p_rl ? col == 0 :
2878#endif
2879 col == wp->w_width - 1)
2880 && (*ptr != NUL
2881 || (wp->w_p_list && lcs_eol_one > 0)
2882 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2883 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002884 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002885 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 mb_c = c;
2887 if (enc_utf8 && utf_char2len(c) > 1)
2888 {
2889 mb_utf8 = TRUE;
2890 u8cc[0] = 0;
2891 c = 0xc0;
2892 }
2893 else
2894 mb_utf8 = FALSE;
2895 }
2896
2897#ifdef FEAT_SYN_HL
2898 // advance to the next 'colorcolumn'
2899 if (draw_color_col)
2900 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2901
2902 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2903 // highlight the cursor position itself.
2904 // Also highlight the 'colorcolumn' if it is different than
2905 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002906 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2907 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002908 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002909 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002910 draw_state == WL_BRI ||
2911 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002913# ifdef FEAT_DIFF
2914 && filler_todo <= 0
2915# endif
2916 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 {
2918 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2919 && lnum != wp->w_cursor.lnum)
2920 {
2921 vcol_save_attr = char_attr;
2922 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2923 }
2924 else if (draw_color_col && VCOL_HLC == *color_cols)
2925 {
2926 vcol_save_attr = char_attr;
2927 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2928 }
2929 }
2930#endif
2931
2932 // Store character to be displayed.
2933 // Skip characters that are left of the screen for 'nowrap'.
2934 vcol_prev = vcol;
2935 if (draw_state < WL_LINE || n_skip <= 0)
2936 {
2937 // Store the character.
2938#if defined(FEAT_RIGHTLEFT)
2939 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2940 {
2941 // A double-wide character is: put first halve in left cell.
2942 --off;
2943 --col;
2944 }
2945#endif
2946 ScreenLines[off] = c;
2947 if (enc_dbcs == DBCS_JPNU)
2948 {
2949 if ((mb_c & 0xff00) == 0x8e00)
2950 ScreenLines[off] = 0x8e;
2951 ScreenLines2[off] = mb_c & 0xff;
2952 }
2953 else if (enc_utf8)
2954 {
2955 if (mb_utf8)
2956 {
2957 int i;
2958
2959 ScreenLinesUC[off] = mb_c;
2960 if ((c & 0xff) == 0)
2961 ScreenLines[off] = 0x80; // avoid storing zero
2962 for (i = 0; i < Screen_mco; ++i)
2963 {
2964 ScreenLinesC[i][off] = u8cc[i];
2965 if (u8cc[i] == 0)
2966 break;
2967 }
2968 }
2969 else
2970 ScreenLinesUC[off] = 0;
2971 }
2972 if (multi_attr)
2973 {
2974 ScreenAttrs[off] = multi_attr;
2975 multi_attr = 0;
2976 }
2977 else
2978 ScreenAttrs[off] = char_attr;
2979
2980 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2981 {
2982 // Need to fill two screen columns.
2983 ++off;
2984 ++col;
2985 if (enc_utf8)
2986 // UTF-8: Put a 0 in the second screen char.
2987 ScreenLines[off] = 0;
2988 else
2989 // DBCS: Put second byte in the second screen char.
2990 ScreenLines[off] = mb_c & 0xff;
2991 if (draw_state > WL_NR
2992#ifdef FEAT_DIFF
2993 && filler_todo <= 0
2994#endif
2995 )
2996 ++vcol;
2997 // When "tocol" is halfway a character, set it to the end of
2998 // the character, otherwise highlighting won't stop.
2999 if (tocol == vcol)
3000 ++tocol;
3001#ifdef FEAT_RIGHTLEFT
3002 if (wp->w_p_rl)
3003 {
3004 // now it's time to backup one cell
3005 --off;
3006 --col;
3007 }
3008#endif
3009 }
3010#ifdef FEAT_RIGHTLEFT
3011 if (wp->w_p_rl)
3012 {
3013 --off;
3014 --col;
3015 }
3016 else
3017#endif
3018 {
3019 ++off;
3020 ++col;
3021 }
3022 }
3023#ifdef FEAT_CONCEAL
3024 else if (wp->w_p_cole > 0 && is_concealing)
3025 {
3026 --n_skip;
3027 ++vcol_off;
3028 if (n_extra > 0)
3029 vcol_off += n_extra;
3030 if (wp->w_p_wrap)
3031 {
3032 // Special voodoo required if 'wrap' is on.
3033 //
3034 // Advance the column indicator to force the line
3035 // drawing to wrap early. This will make the line
3036 // take up the same screen space when parts are concealed,
3037 // so that cursor line computations aren't messed up.
3038 //
3039 // To avoid the fictitious advance of 'col' causing
3040 // trailing junk to be written out of the screen line
3041 // we are building, 'boguscols' keeps track of the number
3042 // of bad columns we have advanced.
3043 if (n_extra > 0)
3044 {
3045 vcol += n_extra;
3046# ifdef FEAT_RIGHTLEFT
3047 if (wp->w_p_rl)
3048 {
3049 col -= n_extra;
3050 boguscols -= n_extra;
3051 }
3052 else
3053# endif
3054 {
3055 col += n_extra;
3056 boguscols += n_extra;
3057 }
3058 n_extra = 0;
3059 n_attr = 0;
3060 }
3061
3062
3063 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3064 {
3065 // Need to fill two screen columns.
3066# ifdef FEAT_RIGHTLEFT
3067 if (wp->w_p_rl)
3068 {
3069 --boguscols;
3070 --col;
3071 }
3072 else
3073# endif
3074 {
3075 ++boguscols;
3076 ++col;
3077 }
3078 }
3079
3080# ifdef FEAT_RIGHTLEFT
3081 if (wp->w_p_rl)
3082 {
3083 --boguscols;
3084 --col;
3085 }
3086 else
3087# endif
3088 {
3089 ++boguscols;
3090 ++col;
3091 }
3092 }
3093 else
3094 {
3095 if (n_extra > 0)
3096 {
3097 vcol += n_extra;
3098 n_extra = 0;
3099 n_attr = 0;
3100 }
3101 }
3102
3103 }
3104#endif // FEAT_CONCEAL
3105 else
3106 --n_skip;
3107
3108 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3109 // column.
3110 if (draw_state > WL_NR
3111#ifdef FEAT_DIFF
3112 && filler_todo <= 0
3113#endif
3114 )
3115 ++vcol;
3116
3117#ifdef FEAT_SYN_HL
3118 if (vcol_save_attr >= 0)
3119 char_attr = vcol_save_attr;
3120#endif
3121
3122 // restore attributes after "predeces" in 'listchars'
3123 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3124 char_attr = saved_attr3;
3125
3126 // restore attributes after last 'listchars' or 'number' char
3127 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3128 char_attr = saved_attr2;
3129
3130 // At end of screen line and there is more to come: Display the line
3131 // so far. If there is no more to display it is caught above.
3132 if ((
3133#ifdef FEAT_RIGHTLEFT
3134 wp->w_p_rl ? (col < 0) :
3135#endif
3136 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003137 && (draw_state != WL_LINE
3138 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139#ifdef FEAT_DIFF
3140 || filler_todo > 0
3141#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003142 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3143 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3145 )
3146 {
3147#ifdef FEAT_CONCEAL
3148 screen_line(screen_row, wp->w_wincol, col - boguscols,
3149 (int)wp->w_width, screen_line_flags);
3150 boguscols = 0;
3151#else
3152 screen_line(screen_row, wp->w_wincol, col,
3153 (int)wp->w_width, screen_line_flags);
3154#endif
3155 ++row;
3156 ++screen_row;
3157
3158 // When not wrapping and finished diff lines, or when displayed
3159 // '$' and highlighting until last column, break here.
3160 if ((!wp->w_p_wrap
3161#ifdef FEAT_DIFF
3162 && filler_todo <= 0
3163#endif
3164 ) || lcs_eol_one == -1)
3165 break;
3166
3167 // When the window is too narrow draw all "@" lines.
3168 if (draw_state != WL_LINE
3169#ifdef FEAT_DIFF
3170 && filler_todo <= 0
3171#endif
3172 )
3173 {
3174 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3175 draw_vsep_win(wp, row);
3176 row = endrow;
3177 }
3178
3179 // When line got too long for screen break here.
3180 if (row == endrow)
3181 {
3182 ++row;
3183 break;
3184 }
3185
3186 if (screen_cur_row == screen_row - 1
3187#ifdef FEAT_DIFF
3188 && filler_todo <= 0
3189#endif
3190 && wp->w_width == Columns)
3191 {
3192 // Remember that the line wraps, used for modeless copy.
3193 LineWraps[screen_row - 1] = TRUE;
3194
3195 // Special trick to make copy/paste of wrapped lines work with
3196 // xterm/screen: write an extra character beyond the end of
3197 // the line. This will work with all terminal types
3198 // (regardless of the xn,am settings).
3199 // Only do this on a fast tty.
3200 // Only do this if the cursor is on the current line
3201 // (something has been written in it).
3202 // Don't do this for the GUI.
3203 // Don't do this for double-width characters.
3204 // Don't do this for a window not at the right screen border.
3205 if (p_tf
3206#ifdef FEAT_GUI
3207 && !gui.in_use
3208#endif
3209 && !(has_mbyte
3210 && ((*mb_off2cells)(LineOffset[screen_row],
3211 LineOffset[screen_row] + screen_Columns)
3212 == 2
3213 || (*mb_off2cells)(LineOffset[screen_row - 1]
3214 + (int)Columns - 2,
3215 LineOffset[screen_row] + screen_Columns)
3216 == 2)))
3217 {
3218 // First make sure we are at the end of the screen line,
3219 // then output the same character again to let the
3220 // terminal know about the wrap. If the terminal doesn't
3221 // auto-wrap, we overwrite the character.
3222 if (screen_cur_col != wp->w_width)
3223 screen_char(LineOffset[screen_row - 1]
3224 + (unsigned)Columns - 1,
3225 screen_row - 1, (int)(Columns - 1));
3226
3227 // When there is a multi-byte character, just output a
3228 // space to keep it simple.
3229 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3230 screen_row - 1] + (Columns - 1)]) > 1)
3231 out_char(' ');
3232 else
3233 out_char(ScreenLines[LineOffset[screen_row - 1]
3234 + (Columns - 1)]);
3235 // force a redraw of the first char on the next line
3236 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3237 screen_start(); // don't know where cursor is now
3238 }
3239 }
3240
3241 col = 0;
3242 off = (unsigned)(current_ScreenLine - ScreenLines);
3243#ifdef FEAT_RIGHTLEFT
3244 if (wp->w_p_rl)
3245 {
3246 col = wp->w_width - 1; // col is not used if breaking!
3247 off += col;
3248 }
3249#endif
3250
3251 // reset the drawing state for the start of a wrapped line
3252 draw_state = WL_START;
3253 saved_n_extra = n_extra;
3254 saved_p_extra = p_extra;
3255 saved_c_extra = c_extra;
3256 saved_c_final = c_final;
3257#ifdef FEAT_SYN_HL
3258 if (!(cul_screenline
3259# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003260 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003261# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003262 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003263 saved_char_attr = char_attr;
3264 else
3265#endif
3266 saved_char_attr = 0;
3267 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003268 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003269#ifdef FEAT_LINEBREAK
3270# ifdef FEAT_DIFF
3271 if (filler_todo <= 0)
3272# endif
3273 need_showbreak = TRUE;
3274#endif
3275#ifdef FEAT_DIFF
3276 --filler_todo;
3277 // When the filler lines are actually below the last line of the
3278 // file, don't draw the line itself, break here.
3279 if (filler_todo == 0 && wp->w_botfill)
3280 break;
3281#endif
3282 }
3283
3284 } // for every character in the line
3285
3286#ifdef FEAT_SPELL
3287 // After an empty line check first word for capital.
3288 if (*skipwhite(line) == NUL)
3289 {
3290 capcol_lnum = lnum + 1;
3291 cap_col = 0;
3292 }
3293#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003294#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 vim_free(text_props);
3296 vim_free(text_prop_idxs);
3297#endif
3298
3299 vim_free(p_extra_free);
3300 return row;
3301}