blob: e68a602858c5dd898528ce51815f06c8fe366a88 [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
268 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100269 // displaying eol at end-of-line
270 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
271 int lcs_prec_todo = wp->w_lcs_chars.prec; // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200272
273 // saved "extra" items for when draw_state becomes WL_LINE (again)
274 int saved_n_extra = 0;
275 char_u *saved_p_extra = NULL;
276 int saved_c_extra = 0;
277 int saved_c_final = 0;
278 int saved_char_attr = 0;
279
280 int n_attr = 0; // chars with special attr
281 int saved_attr2 = 0; // char_attr saved for n_attr
282 int n_attr3 = 0; // chars with overruling special attr
283 int saved_attr3 = 0; // char_attr saved for n_attr3
284
285 int n_skip = 0; // nr of chars to skip for 'nowrap'
286
287 int fromcol = -10; // start of inverting
288 int tocol = MAXCOL; // end of inverting
289 int fromcol_prev = -2; // start of inverting after cursor
290 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291 int lnum_in_visual_area = FALSE;
292 pos_T pos;
293 long v;
294
295 int char_attr = 0; // attributes for next character
296 int attr_pri = FALSE; // char_attr has priority
297 int area_highlighting = FALSE; // Visual or incsearch highlighting
298 // in this line
299 int vi_attr = 0; // attributes for Visual and incsearch
300 // highlighting
301 int wcr_attr = 0; // attributes from 'wincolor'
302 int win_attr = 0; // background for whole window, except
303 // margins and "~" lines.
304 int area_attr = 0; // attributes desired by highlighting
305 int search_attr = 0; // attributes desired by 'hlsearch'
306#ifdef FEAT_SYN_HL
307 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
308 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200309 int prev_syntax_col = -1; // column of prev_syntax_attr
310 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200311 int has_syntax = FALSE; // this buffer has syntax highl.
312 int save_did_emsg;
313 int draw_color_col = FALSE; // highlight colorcolumn
314 int *color_cols = NULL; // pointer to according columns array
315#endif
316 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100317#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200318 int text_prop_count;
319 int text_prop_next = 0; // next text property to use
320 textprop_T *text_props = NULL;
321 int *text_prop_idxs = NULL;
322 int text_props_active = 0;
323 proptype_T *text_prop_type = NULL;
324 int text_prop_attr = 0;
325 int text_prop_combine = FALSE;
326#endif
327#ifdef FEAT_SPELL
328 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200329 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200330# define SPWORDLEN 150
331 char_u nextline[SPWORDLEN * 2];// text with start of the next line
332 int nextlinecol = 0; // column where nextline[] starts
333 int nextline_idx = 0; // index in nextline[] where next line
334 // starts
335 int spell_attr = 0; // attributes desired by spelling
336 int word_end = 0; // last byte with same spell_attr
337 static linenr_T checked_lnum = 0; // line number for "checked_col"
338 static int checked_col = 0; // column in "checked_lnum" up to which
339 // there are no spell errors
340 static int cap_col = -1; // column to check for Cap word
341 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
342 int cur_checked_col = 0; // checked column for current line
343#endif
344 int extra_check = 0; // has extra highlighting
345 int multi_attr = 0; // attributes desired by multibyte
346 int mb_l = 1; // multi-byte byte length
347 int mb_c = 0; // decoded multi-byte character
348 int mb_utf8 = FALSE; // screen char is UTF-8 char
349 int u8cc[MAX_MCO]; // composing UTF-8 chars
350#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
351 int filler_lines = 0; // nr of filler lines to be drawn
352 int filler_todo = 0; // nr of filler lines still to do + 1
353#endif
354#ifdef FEAT_DIFF
355 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
356 int change_start = MAXCOL; // first col of changed area
357 int change_end = -1; // last col of changed area
358#endif
359 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100360 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200361 int in_multispace = FALSE; // in multiple consecutive spaces
362 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200363#ifdef FEAT_LINEBREAK
364 int need_showbreak = FALSE; // overlong line, skipping first x
365 // chars
366#endif
367#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
368 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
369# define LINE_ATTR
370 int line_attr = 0; // attribute for the whole line
371 int line_attr_save;
372#endif
373#ifdef FEAT_SIGNS
374 int sign_present = FALSE;
375 sign_attrs_T sattr;
376#endif
377#ifdef FEAT_ARABIC
378 int prev_c = 0; // previous Arabic character
379 int prev_c1 = 0; // first composing char for prev_c
380#endif
381#if defined(LINE_ATTR)
382 int did_line_attr = 0;
383#endif
384#ifdef FEAT_TERMINAL
385 int get_term_attr = FALSE;
386#endif
387#ifdef FEAT_SYN_HL
388 int cul_attr = 0; // set when 'cursorline' active
389
390 // 'cursorlineopt' has "screenline" and cursor is in this line
391 int cul_screenline = FALSE;
392
393 // margin columns for the screen line, needed for when 'cursorlineopt'
394 // contains "screenline"
395 int left_curline_col = 0;
396 int right_curline_col = 0;
397#endif
398
399 // draw_state: items that are drawn in sequence:
400#define WL_START 0 // nothing done yet
401#ifdef FEAT_CMDWIN
402# define WL_CMDLINE WL_START + 1 // cmdline window column
403#else
404# define WL_CMDLINE WL_START
405#endif
406#ifdef FEAT_FOLDING
407# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
408#else
409# define WL_FOLD WL_CMDLINE
410#endif
411#ifdef FEAT_SIGNS
412# define WL_SIGN WL_FOLD + 1 // column for signs
413#else
414# define WL_SIGN WL_FOLD // column for signs
415#endif
416#define WL_NR WL_SIGN + 1 // line number
417#ifdef FEAT_LINEBREAK
418# define WL_BRI WL_NR + 1 // 'breakindent'
419#else
420# define WL_BRI WL_NR
421#endif
422#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
423# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
424#else
425# define WL_SBR WL_BRI
426#endif
427#define WL_LINE WL_SBR + 1 // text in the line
428 int draw_state = WL_START; // what to draw next
429#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
430 int feedback_col = 0;
431 int feedback_old_attr = -1;
432#endif
433 int screen_line_flags = 0;
434
435#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
436 int match_conc = 0; // cchar for match functions
437#endif
438#ifdef FEAT_CONCEAL
439 int syntax_flags = 0;
440 int syntax_seqnr = 0;
441 int prev_syntax_id = 0;
442 int conceal_attr = HL_ATTR(HLF_CONCEAL);
443 int is_concealing = FALSE;
444 int boguscols = 0; // nonexistent columns added to force
445 // wrapping
446 int vcol_off = 0; // offset for concealed characters
447 int did_wcol = FALSE;
448 int old_boguscols = 0;
449# define VCOL_HLC (vcol - vcol_off)
450# define FIX_FOR_BOGUSCOLS \
451 { \
452 n_extra += vcol_off; \
453 vcol -= vcol_off; \
454 vcol_off = 0; \
455 col -= boguscols; \
456 old_boguscols = boguscols; \
457 boguscols = 0; \
458 }
459#else
460# define VCOL_HLC (vcol)
461#endif
462
463 if (startrow > endrow) // past the end already!
464 return startrow;
465
466 row = startrow;
467 screen_row = row + W_WINROW(wp);
468
469 if (!number_only)
470 {
471 // To speed up the loop below, set extra_check when there is linebreak,
472 // trailing white space and/or syntax processing to be done.
473#ifdef FEAT_LINEBREAK
474 extra_check = wp->w_p_lbr;
475#endif
476#ifdef FEAT_SYN_HL
477 if (syntax_present(wp) && !wp->w_s->b_syn_error
478# ifdef SYN_TIME_LIMIT
479 && !wp->w_s->b_syn_slow
480# endif
481 )
482 {
483 // Prepare for syntax highlighting in this line. When there is an
484 // error, stop syntax highlighting.
485 save_did_emsg = did_emsg;
486 did_emsg = FALSE;
487 syntax_start(wp, lnum);
488 if (did_emsg)
489 wp->w_s->b_syn_error = TRUE;
490 else
491 {
492 did_emsg = save_did_emsg;
493#ifdef SYN_TIME_LIMIT
494 if (!wp->w_s->b_syn_slow)
495#endif
496 {
497 has_syntax = TRUE;
498 extra_check = TRUE;
499 }
500 }
501 }
502
503 // Check for columns to display for 'colorcolumn'.
504 color_cols = wp->w_p_cc_cols;
505 if (color_cols != NULL)
506 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
507#endif
508
509#ifdef FEAT_TERMINAL
510 if (term_show_buffer(wp->w_buffer))
511 {
512 extra_check = TRUE;
513 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100514 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200515 }
516#endif
517
518#ifdef FEAT_SPELL
519 if (wp->w_p_spell
520 && *wp->w_s->b_p_spl != NUL
521 && wp->w_s->b_langp.ga_len > 0
522 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
523 {
524 // Prepare for spell checking.
525 has_spell = TRUE;
526 extra_check = TRUE;
527
528 // Get the start of the next line, so that words that wrap to the
529 // next line are found too: "et<line-break>al.".
530 // Trick: skip a few chars for C/shell/Vim comments
531 nextline[SPWORDLEN] = NUL;
532 if (lnum < wp->w_buffer->b_ml.ml_line_count)
533 {
534 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
535 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
536 }
537
538 // When a word wrapped from the previous line the start of the
539 // current line is valid.
540 if (lnum == checked_lnum)
541 cur_checked_col = checked_col;
542 checked_lnum = 0;
543
544 // When there was a sentence end in the previous line may require a
545 // word starting with capital in this line. In line 1 always check
546 // the first word.
547 if (lnum != capcol_lnum)
548 cap_col = -1;
549 if (lnum == 1)
550 cap_col = 0;
551 capcol_lnum = 0;
552 }
553#endif
554
555 // handle Visual active in this window
556 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
557 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100558 pos_T *top, *bot;
559
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200560 if (LTOREQ_POS(curwin->w_cursor, VIsual))
561 {
562 // Visual is after curwin->w_cursor
563 top = &curwin->w_cursor;
564 bot = &VIsual;
565 }
566 else
567 {
568 // Visual is before curwin->w_cursor
569 top = &VIsual;
570 bot = &curwin->w_cursor;
571 }
572 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
573 if (VIsual_mode == Ctrl_V)
574 {
575 // block mode
576 if (lnum_in_visual_area)
577 {
578 fromcol = wp->w_old_cursor_fcol;
579 tocol = wp->w_old_cursor_lcol;
580 }
581 }
582 else
583 {
584 // non-block mode
585 if (lnum > top->lnum && lnum <= bot->lnum)
586 fromcol = 0;
587 else if (lnum == top->lnum)
588 {
589 if (VIsual_mode == 'V') // linewise
590 fromcol = 0;
591 else
592 {
593 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
594 if (gchar_pos(top) == NUL)
595 tocol = fromcol + 1;
596 }
597 }
598 if (VIsual_mode != 'V' && lnum == bot->lnum)
599 {
600 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
601 {
602 fromcol = -10;
603 tocol = MAXCOL;
604 }
605 else if (bot->col == MAXCOL)
606 tocol = MAXCOL;
607 else
608 {
609 pos = *bot;
610 if (*p_sel == 'e')
611 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
612 else
613 {
614 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
615 ++tocol;
616 }
617 }
618 }
619 }
620
621 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200622 if (!highlight_match && lnum == curwin->w_cursor.lnum
623 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200624#ifdef FEAT_GUI
625 && !gui.in_use
626#endif
627 )
628 noinvcur = TRUE;
629
630 // if inverting in this line set area_highlighting
631 if (fromcol >= 0)
632 {
633 area_highlighting = TRUE;
634 vi_attr = HL_ATTR(HLF_V);
635#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
636 if ((clip_star.available && !clip_star.owned
637 && clip_isautosel_star())
638 || (clip_plus.available && !clip_plus.owned
639 && clip_isautosel_plus()))
640 vi_attr = HL_ATTR(HLF_VNC);
641#endif
642 }
643 }
644
645 // handle 'incsearch' and ":s///c" highlighting
646 else if (highlight_match
647 && wp == curwin
648 && lnum >= curwin->w_cursor.lnum
649 && lnum <= curwin->w_cursor.lnum + search_match_lines)
650 {
651 if (lnum == curwin->w_cursor.lnum)
652 getvcol(curwin, &(curwin->w_cursor),
653 (colnr_T *)&fromcol, NULL, NULL);
654 else
655 fromcol = 0;
656 if (lnum == curwin->w_cursor.lnum + search_match_lines)
657 {
658 pos.lnum = lnum;
659 pos.col = search_match_endcol;
660 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
661 }
662 else
663 tocol = MAXCOL;
664 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100665 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200666 tocol = fromcol + 1;
667 area_highlighting = TRUE;
668 vi_attr = HL_ATTR(HLF_I);
669 }
670 }
671
672#ifdef FEAT_DIFF
673 filler_lines = diff_check(wp, lnum);
674 if (filler_lines < 0)
675 {
676 if (filler_lines == -1)
677 {
678 if (diff_find_change(wp, lnum, &change_start, &change_end))
679 diff_hlf = HLF_ADD; // added line
680 else if (change_start == 0)
681 diff_hlf = HLF_TXD; // changed text
682 else
683 diff_hlf = HLF_CHD; // changed line
684 }
685 else
686 diff_hlf = HLF_ADD; // added line
687 filler_lines = 0;
688 area_highlighting = TRUE;
689 }
690 if (lnum == wp->w_topline)
691 filler_lines = wp->w_topfill;
692 filler_todo = filler_lines;
693#endif
694
695#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100696 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200697#endif
698
699#ifdef LINE_ATTR
700# ifdef FEAT_SIGNS
701 // If this line has a sign with line highlighting set line_attr.
702 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200703 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200704# endif
705# if defined(FEAT_QUICKFIX)
706 // Highlight the current line in the quickfix window.
707 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
708 line_attr = HL_ATTR(HLF_QFL);
709# endif
710 if (line_attr != 0)
711 area_highlighting = TRUE;
712#endif
713
714 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
715 ptr = line;
716
717#ifdef FEAT_SPELL
718 if (has_spell && !number_only)
719 {
720 // For checking first word with a capital skip white space.
721 if (cap_col == 0)
722 cap_col = getwhitecols(line);
723
724 // To be able to spell-check over line boundaries copy the end of the
725 // current line into nextline[]. Above the start of the next line was
726 // copied to nextline[SPWORDLEN].
727 if (nextline[SPWORDLEN] == NUL)
728 {
729 // No next line or it is empty.
730 nextlinecol = MAXCOL;
731 nextline_idx = 0;
732 }
733 else
734 {
735 v = (long)STRLEN(line);
736 if (v < SPWORDLEN)
737 {
738 // Short line, use it completely and append the start of the
739 // next line.
740 nextlinecol = 0;
741 mch_memmove(nextline, line, (size_t)v);
742 STRMOVE(nextline + v, nextline + SPWORDLEN);
743 nextline_idx = v + 1;
744 }
745 else
746 {
747 // Long line, use only the last SPWORDLEN bytes.
748 nextlinecol = v - SPWORDLEN;
749 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
750 nextline_idx = SPWORDLEN + 1;
751 }
752 }
753 }
754#endif
755
756 if (wp->w_p_list)
757 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100758 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200759 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100760 || wp->w_lcs_chars.trail
761 || wp->w_lcs_chars.lead
762 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200763 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100764
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200765 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100766 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200767 {
768 trailcol = (colnr_T)STRLEN(ptr);
769 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
770 --trailcol;
771 trailcol += (colnr_T) (ptr - line);
772 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100773 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100774 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100775 {
776 leadcol = 0;
777 while (VIM_ISWHITE(ptr[leadcol]))
778 ++leadcol;
779 if (ptr[leadcol] == NUL)
780 // in a line full of spaces all of them are treated as trailing
781 leadcol = (colnr_T)0;
782 else
783 // keep track of the first column not filled with spaces
784 leadcol += (colnr_T) (ptr - line) + 1;
785 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200786 }
787
788 wcr_attr = get_wcr_attr(wp);
789 if (wcr_attr != 0)
790 {
791 win_attr = wcr_attr;
792 area_highlighting = TRUE;
793 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200794
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100795#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200796 if (WIN_IS_POPUP(wp))
797 screen_line_flags |= SLF_POPUP;
798#endif
799
800 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
801 // first character to be displayed.
802 if (wp->w_p_wrap)
803 v = wp->w_skipcol;
804 else
805 v = wp->w_leftcol;
806 if (v > 0 && !number_only)
807 {
808 char_u *prev_ptr = ptr;
809
810 while (vcol < v && *ptr != NUL)
811 {
812 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
813 vcol += c;
814 prev_ptr = ptr;
815 MB_PTR_ADV(ptr);
816 }
817
818 // When:
819 // - 'cuc' is set, or
820 // - 'colorcolumn' is set, or
821 // - 'virtualedit' is set, or
822 // - the visual mode is active,
823 // the end of the line may be before the start of the displayed part.
824 if (vcol < v && (
825#ifdef FEAT_SYN_HL
826 wp->w_p_cuc || draw_color_col ||
827#endif
828 virtual_active() ||
829 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
830 vcol = v;
831
832 // Handle a character that's not completely on the screen: Put ptr at
833 // that character but skip the first few screen characters.
834 if (vcol > v)
835 {
836 vcol -= c;
837 ptr = prev_ptr;
838 // If the character fits on the screen, don't need to skip it.
839 // Except for a TAB.
840 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
841 n_skip = v - vcol;
842 }
843
844 // Adjust for when the inverted text is before the screen,
845 // and when the start of the inverted text is before the screen.
846 if (tocol <= vcol)
847 fromcol = 0;
848 else if (fromcol >= 0 && fromcol < vcol)
849 fromcol = vcol;
850
851#ifdef FEAT_LINEBREAK
852 // When w_skipcol is non-zero, first line needs 'showbreak'
853 if (wp->w_p_wrap)
854 need_showbreak = TRUE;
855#endif
856#ifdef FEAT_SPELL
857 // When spell checking a word we need to figure out the start of the
858 // word and if it's badly spelled or not.
859 if (has_spell)
860 {
861 int len;
862 colnr_T linecol = (colnr_T)(ptr - line);
863 hlf_T spell_hlf = HLF_COUNT;
864
865 pos = wp->w_cursor;
866 wp->w_cursor.lnum = lnum;
867 wp->w_cursor.col = linecol;
868 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
869
870 // spell_move_to() may call ml_get() and make "line" invalid
871 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
872 ptr = line + linecol;
873
874 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
875 {
876 // no bad word found at line start, don't check until end of a
877 // word
878 spell_hlf = HLF_COUNT;
879 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
880 }
881 else
882 {
883 // bad word found, use attributes until end of word
884 word_end = wp->w_cursor.col + len + 1;
885
886 // Turn index into actual attributes.
887 if (spell_hlf != HLF_COUNT)
888 spell_attr = highlight_attr[spell_hlf];
889 }
890 wp->w_cursor = pos;
891
892# ifdef FEAT_SYN_HL
893 // Need to restart syntax highlighting for this line.
894 if (has_syntax)
895 syntax_start(wp, lnum);
896# endif
897 }
898#endif
899 }
900
901 // Correct highlighting for cursor that can't be disabled.
902 // Avoids having to check this for each character.
903 if (fromcol >= 0)
904 {
905 if (noinvcur)
906 {
907 if ((colnr_T)fromcol == wp->w_virtcol)
908 {
909 // highlighting starts at cursor, let it start just after the
910 // cursor
911 fromcol_prev = fromcol;
912 fromcol = -1;
913 }
914 else if ((colnr_T)fromcol < wp->w_virtcol)
915 // restart highlighting after the cursor
916 fromcol_prev = wp->w_virtcol;
917 }
918 if (fromcol >= tocol)
919 fromcol = -1;
920 }
921
922#ifdef FEAT_SEARCH_EXTRA
923 if (!number_only)
924 {
925 v = (long)(ptr - line);
926 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
927 &line, &screen_search_hl,
928 &search_attr);
929 ptr = line + v; // "line" may have been updated
930 }
931#endif
932
933#ifdef FEAT_SYN_HL
934 // Cursor line highlighting for 'cursorline' in the current window.
935 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
936 {
937 // Do not show the cursor line in the text when Visual mode is active,
938 // because it's not clear what is selected then. Do update
939 // w_last_cursorline.
940 if (!(wp == curwin && VIsual_active)
941 && wp->w_p_culopt_flags != CULOPT_NBR)
942 {
943 cul_screenline = (wp->w_p_wrap
944 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
945
946 // Only set line_attr here when "screenline" is not present in
947 // 'cursorlineopt'. Otherwise it's done later.
948 if (!cul_screenline)
949 {
950 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200951# ifdef FEAT_SIGNS
952 // Combine the 'cursorline' and sign highlighting, depending on
953 // the sign priority.
954 if (sign_present && sattr.sat_linehl > 0)
955 {
956 if (sattr.sat_priority >= 100)
957 line_attr = hl_combine_attr(cul_attr, line_attr);
958 else
959 line_attr = hl_combine_attr(line_attr, cul_attr);
960 }
961 else
962# endif
963 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200964 wp->w_last_cursorline = wp->w_cursor.lnum;
965 }
966 else
967 {
968 line_attr_save = line_attr;
969 wp->w_last_cursorline = 0;
970 margin_columns_win(wp, &left_curline_col, &right_curline_col);
971 }
972 area_highlighting = TRUE;
973 }
974 else
975 wp->w_last_cursorline = wp->w_cursor.lnum;
976 }
977#endif
978
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100979#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200980 {
981 char_u *prop_start;
982
983 text_prop_count = get_text_props(wp->w_buffer, lnum,
984 &prop_start, FALSE);
985 if (text_prop_count > 0)
986 {
987 // Make a copy of the properties, so that they are properly
988 // aligned.
989 text_props = ALLOC_MULT(textprop_T, text_prop_count);
990 if (text_props != NULL)
991 mch_memmove(text_props, prop_start,
992 text_prop_count * sizeof(textprop_T));
993
994 // Allocate an array for the indexes.
995 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
996 area_highlighting = TRUE;
997 extra_check = TRUE;
998 }
999 }
1000#endif
1001
1002 off = (unsigned)(current_ScreenLine - ScreenLines);
1003 col = 0;
1004
1005#ifdef FEAT_RIGHTLEFT
1006 if (wp->w_p_rl)
1007 {
1008 // Rightleft window: process the text in the normal direction, but put
1009 // it in current_ScreenLine[] from right to left. Start at the
1010 // rightmost column of the window.
1011 col = wp->w_width - 1;
1012 off += col;
1013 screen_line_flags |= SLF_RIGHTLEFT;
1014 }
1015#endif
1016
1017 // Repeat for the whole displayed line.
1018 for (;;)
1019 {
1020#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001021 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001022#endif
1023#ifdef FEAT_CONCEAL
1024 int did_decrement_ptr = FALSE;
1025#endif
1026 // Skip this quickly when working on the text.
1027 if (draw_state != WL_LINE)
1028 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001029#ifdef FEAT_SYN_HL
1030 if (cul_screenline)
1031 {
1032 cul_attr = 0;
1033 line_attr = line_attr_save;
1034 }
1035#endif
1036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001037#ifdef FEAT_CMDWIN
1038 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1039 {
1040 draw_state = WL_CMDLINE;
1041 if (cmdwin_type != 0 && wp == curwin)
1042 {
1043 // Draw the cmdline character.
1044 n_extra = 1;
1045 c_extra = cmdwin_type;
1046 c_final = NUL;
1047 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1048 }
1049 }
1050#endif
1051
1052#ifdef FEAT_FOLDING
1053 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1054 {
1055 int fdc = compute_foldcolumn(wp, 0);
1056
1057 draw_state = WL_FOLD;
1058 if (fdc > 0)
1059 {
1060 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1061 // already be in use.
1062 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001063 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001064 if (p_extra_free != NULL)
1065 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001066 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001067 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001068 p_extra_free[n_extra] = NUL;
1069 p_extra = p_extra_free;
1070 c_extra = NUL;
1071 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001072 if (use_cursor_line_sign(wp, lnum))
1073 char_attr =
1074 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1075 else
1076 char_attr =
1077 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 }
1079 }
1080 }
1081#endif
1082
1083#ifdef FEAT_SIGNS
1084 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1085 {
1086 draw_state = WL_SIGN;
1087 // Show the sign column when there are any signs in this
1088 // buffer or when using Netbeans.
1089 if (signcolumn_on(wp))
1090 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1091 row, startrow, filler_lines, filler_todo, &c_extra,
1092 &c_final, extra, &p_extra, &n_extra, &char_attr);
1093 }
1094#endif
1095
1096 if (draw_state == WL_NR - 1 && n_extra == 0)
1097 {
1098 draw_state = WL_NR;
1099 // Display the absolute or relative line number. After the
1100 // first fill with blanks when the 'n' flag isn't in 'cpo'
1101 if ((wp->w_p_nu || wp->w_p_rnu)
1102 && (row == startrow
1103#ifdef FEAT_DIFF
1104 + filler_lines
1105#endif
1106 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1107 {
1108#ifdef FEAT_SIGNS
1109 // If 'signcolumn' is set to 'number' and a sign is present
1110 // in 'lnum', then display the sign instead of the line
1111 // number.
1112 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1113 && sign_present)
1114 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1115 row, startrow, filler_lines, filler_todo,
1116 &c_extra, &c_final, extra, &p_extra, &n_extra,
1117 &char_attr);
1118 else
1119#endif
1120 {
1121 // Draw the line number (empty space after wrapping).
1122 if (row == startrow
1123#ifdef FEAT_DIFF
1124 + filler_lines
1125#endif
1126 )
1127 {
1128 long num;
1129 char *fmt = "%*ld ";
1130
1131 if (wp->w_p_nu && !wp->w_p_rnu)
1132 // 'number' + 'norelativenumber'
1133 num = (long)lnum;
1134 else
1135 {
1136 // 'relativenumber', don't use negative numbers
1137 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1138 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1139 {
1140 // 'number' + 'relativenumber'
1141 num = lnum;
1142 fmt = "%-*ld ";
1143 }
1144 }
1145
1146 sprintf((char *)extra, fmt,
1147 number_width(wp), num);
1148 if (wp->w_skipcol > 0)
1149 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1150 *p_extra = '-';
1151#ifdef FEAT_RIGHTLEFT
1152 if (wp->w_p_rl) // reverse line numbers
1153 {
1154 char_u *p1, *p2;
1155 int t;
1156
1157 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001158 p2 = skipwhite(extra);
1159 p2 = skiptowhite(p2) - 1;
1160 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001161 {
1162 t = *p1;
1163 *p1 = *p2;
1164 *p2 = t;
1165 }
1166 }
1167#endif
1168 p_extra = extra;
1169 c_extra = NUL;
1170 c_final = NUL;
1171 }
1172 else
1173 {
1174 c_extra = ' ';
1175 c_final = NUL;
1176 }
1177 n_extra = number_width(wp) + 1;
1178 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1179#ifdef FEAT_SYN_HL
1180 // When 'cursorline' is set highlight the line number of
1181 // the current line differently.
1182 // When 'cursorlineopt' has "screenline" only highlight
1183 // the line number itself.
1184 // TODO: Can we use CursorLine instead of CursorLineNr
1185 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001186 if (wp->w_p_cul
1187 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001188 && (wp->w_p_culopt_flags & CULOPT_NBR)
1189 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001190 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1192#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001193 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1194 && HL_ATTR(HLF_LNA) != 0)
1195 // Use LineNrAbove
1196 char_attr = hl_combine_attr(wcr_attr,
1197 HL_ATTR(HLF_LNA));
1198 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1199 && HL_ATTR(HLF_LNB) != 0)
1200 // Use LineNrBelow
1201 char_attr = hl_combine_attr(wcr_attr,
1202 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001203 }
1204 }
1205 }
1206
1207#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001208 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001209 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001210 // draw indent after showbreak value
1211 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001212 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001213 // After the showbreak, draw the breakindent
1214 draw_state = WL_BRI - 1;
1215
1216 // draw 'breakindent': indent wrapped text accordingly
1217 if (draw_state == WL_BRI - 1 && n_extra == 0)
1218 {
1219 draw_state = WL_BRI;
1220 // if need_showbreak is set, breakindent also applies
1221 if (wp->w_p_bri && n_extra == 0
1222 && (row != startrow || need_showbreak)
1223# ifdef FEAT_DIFF
1224 && filler_lines == 0
1225# endif
1226 )
1227 {
1228 char_attr = 0;
1229# ifdef FEAT_DIFF
1230 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001231 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232# endif
1233 p_extra = NULL;
1234 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001235 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 n_extra = get_breakindent_win(wp,
1237 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001238 if (row == startrow)
1239 {
1240 n_extra -= win_col_off2(wp);
1241 if (n_extra < 0)
1242 n_extra = 0;
1243 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001244 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001245 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246 // Correct end of highlighted area for 'breakindent',
1247 // required when 'linebreak' is also set.
1248 if (tocol == vcol)
1249 tocol += n_extra;
1250 }
1251 }
1252#endif
1253
1254#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1255 if (draw_state == WL_SBR - 1 && n_extra == 0)
1256 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001257 char_u *sbr;
1258
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001259 draw_state = WL_SBR;
1260# ifdef FEAT_DIFF
1261 if (filler_todo > 0)
1262 {
1263 // Draw "deleted" diff line(s).
1264 if (char2cells(fill_diff) > 1)
1265 {
1266 c_extra = '-';
1267 c_final = NUL;
1268 }
1269 else
1270 {
1271 c_extra = fill_diff;
1272 c_final = NUL;
1273 }
1274# ifdef FEAT_RIGHTLEFT
1275 if (wp->w_p_rl)
1276 n_extra = col + 1;
1277 else
1278# endif
1279 n_extra = wp->w_width - col;
1280 char_attr = HL_ATTR(HLF_DED);
1281 }
1282# endif
1283# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001284 sbr = get_showbreak_value(wp);
1285 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001286 {
1287 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001288 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001289 c_extra = NUL;
1290 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001291 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001292 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1293 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001294 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001295 // Correct end of highlighted area for 'showbreak',
1296 // required when 'linebreak' is also set.
1297 if (tocol == vcol)
1298 tocol += n_extra;
1299 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001300 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301# ifdef FEAT_SYN_HL
1302 // combine 'showbreak' with 'cursorline'
1303 if (cul_attr != 0)
1304 char_attr = hl_combine_attr(char_attr, cul_attr);
1305# endif
1306 }
1307# endif
1308 }
1309#endif
1310
1311 if (draw_state == WL_LINE - 1 && n_extra == 0)
1312 {
1313 draw_state = WL_LINE;
1314 if (saved_n_extra)
1315 {
1316 // Continue item from end of wrapped line.
1317 n_extra = saved_n_extra;
1318 c_extra = saved_c_extra;
1319 c_final = saved_c_final;
1320 p_extra = saved_p_extra;
1321 char_attr = saved_char_attr;
1322 }
1323 else
1324 char_attr = win_attr;
1325 }
1326 }
1327#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001328 if (cul_screenline && draw_state == WL_LINE
1329 && vcol >= left_curline_col
1330 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001331 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001332 cul_attr = HL_ATTR(HLF_CUL);
1333 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001334 }
1335#endif
1336
1337 // When still displaying '$' of change command, stop at cursor.
1338 // When only displaying the (relative) line number and that's done,
1339 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001340 if (((dollar_vcol >= 0 && wp == curwin
1341 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1342 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001343#ifdef FEAT_DIFF
1344 && filler_todo <= 0
1345#endif
1346 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 {
1348 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1349 screen_line_flags);
1350 // Pretend we have finished updating the window. Except when
1351 // 'cursorcolumn' is set.
1352#ifdef FEAT_SYN_HL
1353 if (wp->w_p_cuc)
1354 row = wp->w_cline_row + wp->w_cline_height;
1355 else
1356#endif
1357 row = wp->w_height;
1358 break;
1359 }
1360
Bram Moolenaar34390282019-10-16 14:38:26 +02001361 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001362 {
1363 // handle Visual or match highlighting in this line
1364 if (vcol == fromcol
1365 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1366 && (*mb_ptr2cells)(ptr) > 1)
1367 || ((int)vcol_prev == fromcol_prev
1368 && vcol_prev < vcol // not at margin
1369 && vcol < tocol))
1370 area_attr = vi_attr; // start highlighting
1371 else if (area_attr != 0
1372 && (vcol == tocol
1373 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1374 area_attr = 0; // stop highlighting
1375
1376#ifdef FEAT_SEARCH_EXTRA
1377 if (!n_extra)
1378 {
1379 // Check for start/end of 'hlsearch' and other matches.
1380 // After end, check for start/end of next match.
1381 // When another match, have to check for start again.
1382 v = (long)(ptr - line);
1383 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1384 &screen_search_hl, &has_match_conc,
1385 &match_conc, did_line_attr, lcs_eol_one);
1386 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001387
1388 // Do not allow a conceal over EOL otherwise EOL will be missed
1389 // and bad things happen.
1390 if (*ptr == NUL)
1391 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 }
1393#endif
1394
1395#ifdef FEAT_DIFF
1396 if (diff_hlf != (hlf_T)0)
1397 {
1398 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1399 && n_extra == 0)
1400 diff_hlf = HLF_TXD; // changed text
1401 if (diff_hlf == HLF_TXD && ptr - line > change_end
1402 && n_extra == 0)
1403 diff_hlf = HLF_CHD; // changed line
1404 line_attr = HL_ATTR(diff_hlf);
1405 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1406 && wp->w_p_culopt_flags != CULOPT_NBR
1407 && (!cul_screenline || (vcol >= left_curline_col
1408 && vcol <= right_curline_col)))
1409 line_attr = hl_combine_attr(
1410 line_attr, HL_ATTR(HLF_CUL));
1411 }
1412#endif
1413
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001414#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001415 if (text_props != NULL)
1416 {
1417 int pi;
1418 int bcol = (int)(ptr - line);
1419
1420 if (n_extra > 0)
1421 --bcol; // still working on the previous char, e.g. Tab
1422
1423 // Check if any active property ends.
1424 for (pi = 0; pi < text_props_active; ++pi)
1425 {
1426 int tpi = text_prop_idxs[pi];
1427
1428 if (bcol >= text_props[tpi].tp_col - 1
1429 + text_props[tpi].tp_len)
1430 {
1431 if (pi + 1 < text_props_active)
1432 mch_memmove(text_prop_idxs + pi,
1433 text_prop_idxs + pi + 1,
1434 sizeof(int)
1435 * (text_props_active - (pi + 1)));
1436 --text_props_active;
1437 --pi;
1438 }
1439 }
1440
1441 // Add any text property that starts in this column.
1442 while (text_prop_next < text_prop_count
1443 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001444 {
1445 if (bcol <= text_props[text_prop_next].tp_col - 1
1446 + text_props[text_prop_next].tp_len)
1447 text_prop_idxs[text_props_active++] = text_prop_next;
1448 ++text_prop_next;
1449 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450
1451 text_prop_attr = 0;
1452 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001453 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001454 if (text_props_active > 0)
1455 {
1456 // Sort the properties on priority and/or starting last.
1457 // Then combine the attributes, highest priority last.
1458 current_text_props = text_props;
1459 current_buf = wp->w_buffer;
1460 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1461 sizeof(int), text_prop_compare);
1462
1463 for (pi = 0; pi < text_props_active; ++pi)
1464 {
1465 int tpi = text_prop_idxs[pi];
1466 proptype_T *pt = text_prop_type_by_id(
1467 wp->w_buffer, text_props[tpi].tp_type);
1468
1469 if (pt != NULL && pt->pt_hl_id > 0)
1470 {
1471 int pt_attr = syn_id2attr(pt->pt_hl_id);
1472
1473 text_prop_type = pt;
1474 text_prop_attr =
1475 hl_combine_attr(text_prop_attr, pt_attr);
1476 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1477 }
1478 }
1479 }
1480 }
1481#endif
1482
Bram Moolenaara74fda62019-10-19 17:38:03 +02001483#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001484 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001485 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001486 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001487# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001488 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001489 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001490# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001491 // Get syntax attribute.
1492 if (has_syntax)
1493 {
1494 // Get the syntax attribute for the character. If there
1495 // is an error, disable syntax highlighting.
1496 save_did_emsg = did_emsg;
1497 did_emsg = FALSE;
1498
1499 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001500 if (v == prev_syntax_col)
1501 // at same column again
1502 syntax_attr = prev_syntax_attr;
1503 else
1504 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001505# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001506 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001507# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001508 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001509# ifdef FEAT_SPELL
1510 has_spell ? &can_spell :
1511# endif
1512 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001513 prev_syntax_col = v;
1514 prev_syntax_attr = syntax_attr;
1515 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001516
Bram Moolenaar34390282019-10-16 14:38:26 +02001517 if (did_emsg)
1518 {
1519 wp->w_s->b_syn_error = TRUE;
1520 has_syntax = FALSE;
1521 syntax_attr = 0;
1522 }
1523 else
1524 did_emsg = save_did_emsg;
1525# ifdef SYN_TIME_LIMIT
1526 if (wp->w_s->b_syn_slow)
1527 has_syntax = FALSE;
1528# endif
1529
1530 // Need to get the line again, a multi-line regexp may
1531 // have made it invalid.
1532 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1533 ptr = line + v;
1534# ifdef FEAT_CONCEAL
1535 // no concealing past the end of the line, it interferes
1536 // with line highlighting
1537 if (*ptr == NUL)
1538 syntax_flags = 0;
1539 else
1540 syntax_flags = get_syntax_info(&syntax_seqnr);
1541# endif
1542 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001543 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001544# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001545 // Combine text property highlight into syntax highlight.
1546 if (text_prop_type != NULL)
1547 {
1548 if (text_prop_combine)
1549 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1550 else
1551 syntax_attr = text_prop_attr;
1552 }
1553# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001554#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001555
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 // Decide which of the highlight attributes to use.
1557 attr_pri = TRUE;
1558#ifdef LINE_ATTR
1559 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001560 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001561 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001562 if (!highlight_match)
1563 // let search highlight show in Visual area if possible
1564 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001565# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001566 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001567# endif
1568 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001569 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001570 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001572# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001573 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001574# endif
1575 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1577 || vcol < fromcol || vcol_prev < fromcol_prev
1578 || vcol >= tocol))
1579 {
1580 // Use line_attr when not in the Visual or 'incsearch' area
1581 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001582# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001583 char_attr = hl_combine_attr(syntax_attr, line_attr);
1584# else
1585 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001586# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001587 attr_pri = FALSE;
1588 }
1589#else
1590 if (area_attr != 0)
1591 char_attr = area_attr;
1592 else if (search_attr != 0)
1593 char_attr = search_attr;
1594#endif
1595 else
1596 {
1597 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001599 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001600#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001601 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001602#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 }
1604 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001605
1606 // combine attribute with 'wincolor'
1607 if (win_attr != 0)
1608 {
1609 if (char_attr == 0)
1610 char_attr = win_attr;
1611 else
1612 char_attr = hl_combine_attr(win_attr, char_attr);
1613 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614
1615 // Get the next character to put on the screen.
1616
1617 // The "p_extra" points to the extra stuff that is inserted to
1618 // represent special characters (non-printable stuff) and other
1619 // things. When all characters are the same, c_extra is used.
1620 // If c_final is set, it will compulsorily be used at the end.
1621 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1622 // "p_extra[n_extra]".
1623 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1624 if (n_extra > 0)
1625 {
1626 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1627 {
1628 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1629 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1630 if (enc_utf8 && utf_char2len(c) > 1)
1631 {
1632 mb_utf8 = TRUE;
1633 u8cc[0] = 0;
1634 c = 0xc0;
1635 }
1636 else
1637 mb_utf8 = FALSE;
1638 }
1639 else
1640 {
1641 c = *p_extra;
1642 if (has_mbyte)
1643 {
1644 mb_c = c;
1645 if (enc_utf8)
1646 {
1647 // If the UTF-8 character is more than one byte:
1648 // Decode it into "mb_c".
1649 mb_l = utfc_ptr2len(p_extra);
1650 mb_utf8 = FALSE;
1651 if (mb_l > n_extra)
1652 mb_l = 1;
1653 else if (mb_l > 1)
1654 {
1655 mb_c = utfc_ptr2char(p_extra, u8cc);
1656 mb_utf8 = TRUE;
1657 c = 0xc0;
1658 }
1659 }
1660 else
1661 {
1662 // if this is a DBCS character, put it in "mb_c"
1663 mb_l = MB_BYTE2LEN(c);
1664 if (mb_l >= n_extra)
1665 mb_l = 1;
1666 else if (mb_l > 1)
1667 mb_c = (c << 8) + p_extra[1];
1668 }
1669 if (mb_l == 0) // at the NUL at end-of-line
1670 mb_l = 1;
1671
1672 // If a double-width char doesn't fit display a '>' in the
1673 // last column.
1674 if ((
1675# ifdef FEAT_RIGHTLEFT
1676 wp->w_p_rl ? (col <= 0) :
1677# endif
1678 (col >= wp->w_width - 1))
1679 && (*mb_char2cells)(mb_c) == 2)
1680 {
1681 c = '>';
1682 mb_c = c;
1683 mb_l = 1;
1684 mb_utf8 = FALSE;
1685 multi_attr = HL_ATTR(HLF_AT);
1686#ifdef FEAT_SYN_HL
1687 if (cul_attr)
1688 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1689#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001690 multi_attr = hl_combine_attr(win_attr, multi_attr);
1691
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001692 // put the pointer back to output the double-width
1693 // character at the start of the next line.
1694 ++n_extra;
1695 --p_extra;
1696 }
1697 else
1698 {
1699 n_extra -= mb_l - 1;
1700 p_extra += mb_l - 1;
1701 }
1702 }
1703 ++p_extra;
1704 }
1705 --n_extra;
1706 }
1707 else
1708 {
1709#ifdef FEAT_LINEBREAK
1710 int c0;
1711#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001712 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001713
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001714 // Get a character from the line itself.
1715 c = *ptr;
1716#ifdef FEAT_LINEBREAK
1717 c0 = *ptr;
1718#endif
1719 if (has_mbyte)
1720 {
1721 mb_c = c;
1722 if (enc_utf8)
1723 {
1724 // If the UTF-8 character is more than one byte: Decode it
1725 // into "mb_c".
1726 mb_l = utfc_ptr2len(ptr);
1727 mb_utf8 = FALSE;
1728 if (mb_l > 1)
1729 {
1730 mb_c = utfc_ptr2char(ptr, u8cc);
1731 // Overlong encoded ASCII or ASCII with composing char
1732 // is displayed normally, except a NUL.
1733 if (mb_c < 0x80)
1734 {
1735 c = mb_c;
1736#ifdef FEAT_LINEBREAK
1737 c0 = mb_c;
1738#endif
1739 }
1740 mb_utf8 = TRUE;
1741
1742 // At start of the line we can have a composing char.
1743 // Draw it as a space with a composing char.
1744 if (utf_iscomposing(mb_c))
1745 {
1746 int i;
1747
1748 for (i = Screen_mco - 1; i > 0; --i)
1749 u8cc[i] = u8cc[i - 1];
1750 u8cc[0] = mb_c;
1751 mb_c = ' ';
1752 }
1753 }
1754
1755 if ((mb_l == 1 && c >= 0x80)
1756 || (mb_l >= 1 && mb_c == 0)
1757 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1758 {
1759 // Illegal UTF-8 byte: display as <xx>.
1760 // Non-BMP character : display as ? or fullwidth ?.
1761 transchar_hex(extra, mb_c);
1762# ifdef FEAT_RIGHTLEFT
1763 if (wp->w_p_rl) // reverse
1764 rl_mirror(extra);
1765# endif
1766 p_extra = extra;
1767 c = *p_extra;
1768 mb_c = mb_ptr2char_adv(&p_extra);
1769 mb_utf8 = (c >= 0x80);
1770 n_extra = (int)STRLEN(p_extra);
1771 c_extra = NUL;
1772 c_final = NUL;
1773 if (area_attr == 0 && search_attr == 0)
1774 {
1775 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001776 extra_attr = hl_combine_attr(
1777 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 saved_attr2 = char_attr; // save current attr
1779 }
1780 }
1781 else if (mb_l == 0) // at the NUL at end-of-line
1782 mb_l = 1;
1783#ifdef FEAT_ARABIC
1784 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1785 {
1786 // Do Arabic shaping.
1787 int pc, pc1, nc;
1788 int pcc[MAX_MCO];
1789
1790 // The idea of what is the previous and next
1791 // character depends on 'rightleft'.
1792 if (wp->w_p_rl)
1793 {
1794 pc = prev_c;
1795 pc1 = prev_c1;
1796 nc = utf_ptr2char(ptr + mb_l);
1797 prev_c1 = u8cc[0];
1798 }
1799 else
1800 {
1801 pc = utfc_ptr2char(ptr + mb_l, pcc);
1802 nc = prev_c;
1803 pc1 = pcc[0];
1804 }
1805 prev_c = mb_c;
1806
1807 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1808 }
1809 else
1810 prev_c = mb_c;
1811#endif
1812 }
1813 else // enc_dbcs
1814 {
1815 mb_l = MB_BYTE2LEN(c);
1816 if (mb_l == 0) // at the NUL at end-of-line
1817 mb_l = 1;
1818 else if (mb_l > 1)
1819 {
1820 // We assume a second byte below 32 is illegal.
1821 // Hopefully this is OK for all double-byte encodings!
1822 if (ptr[1] >= 32)
1823 mb_c = (c << 8) + ptr[1];
1824 else
1825 {
1826 if (ptr[1] == NUL)
1827 {
1828 // head byte at end of line
1829 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001830 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 }
1832 else
1833 {
1834 // illegal tail byte
1835 mb_l = 2;
1836 STRCPY(extra, "XX");
1837 }
1838 p_extra = extra;
1839 n_extra = (int)STRLEN(extra) - 1;
1840 c_extra = NUL;
1841 c_final = NUL;
1842 c = *p_extra++;
1843 if (area_attr == 0 && search_attr == 0)
1844 {
1845 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001846 extra_attr = hl_combine_attr(
1847 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001848 saved_attr2 = char_attr; // save current attr
1849 }
1850 mb_c = c;
1851 }
1852 }
1853 }
1854 // If a double-width char doesn't fit display a '>' in the
1855 // last column; the character is displayed at the start of the
1856 // next line.
1857 if ((
1858# ifdef FEAT_RIGHTLEFT
1859 wp->w_p_rl ? (col <= 0) :
1860# endif
1861 (col >= wp->w_width - 1))
1862 && (*mb_char2cells)(mb_c) == 2)
1863 {
1864 c = '>';
1865 mb_c = c;
1866 mb_utf8 = FALSE;
1867 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001868 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001869 // Put pointer back so that the character will be
1870 // displayed at the start of the next line.
1871 --ptr;
1872#ifdef FEAT_CONCEAL
1873 did_decrement_ptr = TRUE;
1874#endif
1875 }
1876 else if (*ptr != NUL)
1877 ptr += mb_l - 1;
1878
1879 // If a double-width char doesn't fit at the left side display
1880 // a '<' in the first column. Don't do this for unprintable
1881 // characters.
1882 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1883 {
1884 n_extra = 1;
1885 c_extra = MB_FILLER_CHAR;
1886 c_final = NUL;
1887 c = ' ';
1888 if (area_attr == 0 && search_attr == 0)
1889 {
1890 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001891 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 saved_attr2 = char_attr; // save current attr
1893 }
1894 mb_c = c;
1895 mb_utf8 = FALSE;
1896 mb_l = 1;
1897 }
1898
1899 }
1900 ++ptr;
1901
1902 if (extra_check)
1903 {
1904#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 // Check spelling (unless at the end of the line).
1906 // Only do this when there is no syntax highlighting, the
1907 // @Spell cluster is not used or the current syntax item
1908 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001909 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001910 if (has_spell && v >= word_end && v > cur_checked_col)
1911 {
1912 spell_attr = 0;
1913 if (c != 0 && (
1914# ifdef FEAT_SYN_HL
1915 !has_syntax ||
1916# endif
1917 can_spell))
1918 {
1919 char_u *prev_ptr, *p;
1920 int len;
1921 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001922
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001923 if (has_mbyte)
1924 {
1925 prev_ptr = ptr - mb_l;
1926 v -= mb_l - 1;
1927 }
1928 else
1929 prev_ptr = ptr - 1;
1930
1931 // Use nextline[] if possible, it has the start of the
1932 // next line concatenated.
1933 if ((prev_ptr - line) - nextlinecol >= 0)
1934 p = nextline + (prev_ptr - line) - nextlinecol;
1935 else
1936 p = prev_ptr;
1937 cap_col -= (int)(prev_ptr - line);
1938 len = spell_check(wp, p, &spell_hlf, &cap_col,
1939 nochange);
1940 word_end = v + len;
1941
1942 // In Insert mode only highlight a word that
1943 // doesn't touch the cursor.
1944 if (spell_hlf != HLF_COUNT
1945 && (State & INSERT) != 0
1946 && wp->w_cursor.lnum == lnum
1947 && wp->w_cursor.col >=
1948 (colnr_T)(prev_ptr - line)
1949 && wp->w_cursor.col < (colnr_T)word_end)
1950 {
1951 spell_hlf = HLF_COUNT;
1952 spell_redraw_lnum = lnum;
1953 }
1954
1955 if (spell_hlf == HLF_COUNT && p != prev_ptr
1956 && (p - nextline) + len > nextline_idx)
1957 {
1958 // Remember that the good word continues at the
1959 // start of the next line.
1960 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001961 checked_col = (int)((p - nextline)
1962 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001963 }
1964
1965 // Turn index into actual attributes.
1966 if (spell_hlf != HLF_COUNT)
1967 spell_attr = highlight_attr[spell_hlf];
1968
1969 if (cap_col > 0)
1970 {
1971 if (p != prev_ptr
1972 && (p - nextline) + cap_col >= nextline_idx)
1973 {
1974 // Remember that the word in the next line
1975 // must start with a capital.
1976 capcol_lnum = lnum + 1;
1977 cap_col = (int)((p - nextline) + cap_col
1978 - nextline_idx);
1979 }
1980 else
1981 // Compute the actual column.
1982 cap_col += (int)(prev_ptr - line);
1983 }
1984 }
1985 }
1986 if (spell_attr != 0)
1987 {
1988 if (!attr_pri)
1989 char_attr = hl_combine_attr(char_attr, spell_attr);
1990 else
1991 char_attr = hl_combine_attr(spell_attr, char_attr);
1992 }
1993#endif
1994#ifdef FEAT_LINEBREAK
1995 // Found last space before word: check for line break.
1996 if (wp->w_p_lbr && c0 == c
1997 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1998 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02001999 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2000 : 0;
2001 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002002
2003 // TODO: is passing p for start of the line OK?
2004 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2005 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002006
2007 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002008 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002009 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002010 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002011 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002012 if (n_extra < 0)
2013 n_extra = 0;
2014 }
Bram Moolenaara06e3452021-05-29 17:56:37 +02002015
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002016 if (c == TAB && n_extra + col > wp->w_width)
2017# ifdef FEAT_VARTABS
2018 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2019 wp->w_buffer->b_p_vts_array) - 1;
2020# else
2021 n_extra = (int)wp->w_buffer->b_p_ts
2022 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2023# endif
2024
2025 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2026 c_final = NUL;
2027 if (VIM_ISWHITE(c))
2028 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002029# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002030 if (c == TAB)
2031 // See "Tab alignment" below.
2032 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002033# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002034 if (!wp->w_p_list)
2035 c = ' ';
2036 }
2037 }
2038#endif
2039
zeertzjqf14b8ba2021-09-10 16:58:30 +02002040 in_multispace = c == ' '
2041 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2042 if (!in_multispace)
2043 multispace_pos = 0;
2044
Bram Moolenaareed9d462021-02-15 20:38:25 +01002045 // 'list': Change char 160 to 'nbsp' and space to 'space'
2046 // setting in 'listchars'. But not when the character is
2047 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 if (wp->w_p_list
2049 && ((((c == 160 && mb_l == 1)
2050 || (mb_utf8
2051 && ((mb_c == 160 && mb_l == 2)
2052 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002053 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 || (c == ' '
2055 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002056 && (wp->w_lcs_chars.space
2057 || (in_multispace
2058 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002059 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 && ptr - line <= trailcol)))
2061 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002062 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2063 {
2064 c = wp->w_lcs_chars.multispace[multispace_pos++];
2065 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2066 multispace_pos = 0;
2067 }
2068 else
2069 c = (c == ' ') ? wp->w_lcs_chars.space
2070 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 if (area_attr == 0 && search_attr == 0)
2072 {
2073 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002074 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 saved_attr2 = char_attr; // save current attr
2076 }
2077 mb_c = c;
2078 if (enc_utf8 && utf_char2len(c) > 1)
2079 {
2080 mb_utf8 = TRUE;
2081 u8cc[0] = 0;
2082 c = 0xc0;
2083 }
2084 else
2085 mb_utf8 = FALSE;
2086 }
2087
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002088 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2089 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002091 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2092 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002093 if (!attr_pri)
2094 {
2095 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002096 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002097 saved_attr2 = char_attr; // save current attr
2098 }
2099 mb_c = c;
2100 if (enc_utf8 && utf_char2len(c) > 1)
2101 {
2102 mb_utf8 = TRUE;
2103 u8cc[0] = 0;
2104 c = 0xc0;
2105 }
2106 else
2107 mb_utf8 = FALSE;
2108 }
2109 }
2110
2111 // Handling of non-printable characters.
2112 if (!vim_isprintc(c))
2113 {
2114 // when getting a character from the file, we may have to
2115 // turn it into something else on the way to putting it
2116 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002117 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002118 {
2119 int tab_len = 0;
2120 long vcol_adjusted = vcol; // removed showbreak length
2121#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002122 char_u *sbr = get_showbreak_value(wp);
2123
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002124 // only adjust the tab_len, when at the first column
2125 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002126 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2127 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128#endif
2129 // tab amount depends on current column
2130#ifdef FEAT_VARTABS
2131 tab_len = tabstop_padding(vcol_adjusted,
2132 wp->w_buffer->b_p_ts,
2133 wp->w_buffer->b_p_vts_array) - 1;
2134#else
2135 tab_len = (int)wp->w_buffer->b_p_ts
2136 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2137#endif
2138
2139#ifdef FEAT_LINEBREAK
2140 if (!wp->w_p_lbr || !wp->w_p_list)
2141#endif
2142 // tab amount depends on current column
2143 n_extra = tab_len;
2144#ifdef FEAT_LINEBREAK
2145 else
2146 {
2147 char_u *p;
2148 int len;
2149 int i;
2150 int saved_nextra = n_extra;
2151
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002152# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002153 if (vcol_off > 0)
2154 // there are characters to conceal
2155 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002156
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002158 if (wp->w_p_list && wp->w_lcs_chars.tab1
2159 && old_boguscols > 0
2160 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002161 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002162# endif
2163 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002165 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002166 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002167 if (wp->w_lcs_chars.tab3)
2168 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002169 if (n_extra > 0)
2170 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002171 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002173 if (p == NULL)
2174 n_extra = 0;
2175 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002177 vim_memset(p, ' ', len);
2178 p[len] = NUL;
2179 vim_free(p_extra_free);
2180 p_extra_free = p;
2181 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002182 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002183 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002185 if (*p == NUL)
2186 {
2187 tab_len = i;
2188 break;
2189 }
2190
2191 // if tab3 is given, use it for the last char
2192 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2193 lcs = wp->w_lcs_chars.tab3;
2194 p += mb_char2bytes(lcs, p);
2195 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002197 }
2198 p_extra = p_extra_free;
2199# ifdef FEAT_CONCEAL
2200 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2201 // macro below, so need to adjust for that here
2202 if (vcol_off > 0)
2203 n_extra -= vcol_off;
2204# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002205 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 }
2207#endif
2208#ifdef FEAT_CONCEAL
2209 {
2210 int vc_saved = vcol_off;
2211
2212 // Tab alignment should be identical regardless of
2213 // 'conceallevel' value. So tab compensates of all
2214 // previous concealed characters, and thus resets
2215 // vcol_off and boguscols accumulated so far in the
2216 // line. Note that the tab can be longer than
2217 // 'tabstop' when there are concealed characters.
2218 FIX_FOR_BOGUSCOLS;
2219
2220 // Make sure, the highlighting for the tab char will be
2221 // correctly set further below (effectively reverts the
2222 // FIX_FOR_BOGSUCOLS macro
2223 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002224 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002225 tab_len += vc_saved;
2226 }
2227#endif
2228 mb_utf8 = FALSE; // don't draw as UTF-8
2229 if (wp->w_p_list)
2230 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002231 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2232 ? wp->w_lcs_chars.tab3
2233 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002234#ifdef FEAT_LINEBREAK
2235 if (wp->w_p_lbr)
2236 c_extra = NUL; // using p_extra from above
2237 else
2238#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002239 c_extra = wp->w_lcs_chars.tab2;
2240 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002242 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002243 saved_attr2 = char_attr; // save current attr
2244 mb_c = c;
2245 if (enc_utf8 && utf_char2len(c) > 1)
2246 {
2247 mb_utf8 = TRUE;
2248 u8cc[0] = 0;
2249 c = 0xc0;
2250 }
2251 }
2252 else
2253 {
2254 c_final = NUL;
2255 c_extra = ' ';
2256 c = ' ';
2257 }
2258 }
2259 else if (c == NUL
2260 && (wp->w_p_list
2261 || ((fromcol >= 0 || fromcol_prev >= 0)
2262 && tocol > vcol
2263 && VIsual_mode != Ctrl_V
2264 && (
2265# ifdef FEAT_RIGHTLEFT
2266 wp->w_p_rl ? (col >= 0) :
2267# endif
2268 (col < wp->w_width))
2269 && !(noinvcur
2270 && lnum == wp->w_cursor.lnum
2271 && (colnr_T)vcol == wp->w_virtcol)))
2272 && lcs_eol_one > 0)
2273 {
2274 // Display a '$' after the line or highlight an extra
2275 // character if the line break is included.
2276#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2277 // For a diff line the highlighting continues after the
2278 // "$".
2279 if (
2280# ifdef FEAT_DIFF
2281 diff_hlf == (hlf_T)0
2282# ifdef LINE_ATTR
2283 &&
2284# endif
2285# endif
2286# ifdef LINE_ATTR
2287 line_attr == 0
2288# endif
2289 )
2290#endif
2291 {
2292 // In virtualedit, visual selections may extend
2293 // beyond end of line.
2294 if (area_highlighting && virtual_active()
2295 && tocol != MAXCOL && vcol < tocol)
2296 n_extra = 0;
2297 else
2298 {
2299 p_extra = at_end_str;
2300 n_extra = 1;
2301 c_extra = NUL;
2302 c_final = NUL;
2303 }
2304 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002305 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2306 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002307 else
2308 c = ' ';
2309 lcs_eol_one = -1;
2310 --ptr; // put it back at the NUL
2311 if (!attr_pri)
2312 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002313 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002314 n_attr = 1;
2315 }
2316 mb_c = c;
2317 if (enc_utf8 && utf_char2len(c) > 1)
2318 {
2319 mb_utf8 = TRUE;
2320 u8cc[0] = 0;
2321 c = 0xc0;
2322 }
2323 else
2324 mb_utf8 = FALSE; // don't draw as UTF-8
2325 }
2326 else if (c != NUL)
2327 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002328 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002329 if (n_extra == 0)
2330 n_extra = byte2cells(c) - 1;
2331#ifdef FEAT_RIGHTLEFT
2332 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2333 rl_mirror(p_extra); // reverse "<12>"
2334#endif
2335 c_extra = NUL;
2336 c_final = NUL;
2337#ifdef FEAT_LINEBREAK
2338 if (wp->w_p_lbr)
2339 {
2340 char_u *p;
2341
2342 c = *p_extra;
2343 p = alloc(n_extra + 1);
2344 vim_memset(p, ' ', n_extra);
2345 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2346 p[n_extra] = NUL;
2347 vim_free(p_extra_free);
2348 p_extra_free = p_extra = p;
2349 }
2350 else
2351#endif
2352 {
2353 n_extra = byte2cells(c) - 1;
2354 c = *p_extra++;
2355 }
2356 if (!attr_pri)
2357 {
2358 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002359 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002360 saved_attr2 = char_attr; // save current attr
2361 }
2362 mb_utf8 = FALSE; // don't draw as UTF-8
2363 }
2364 else if (VIsual_active
2365 && (VIsual_mode == Ctrl_V
2366 || VIsual_mode == 'v')
2367 && virtual_active()
2368 && tocol != MAXCOL
2369 && vcol < tocol
2370 && (
2371#ifdef FEAT_RIGHTLEFT
2372 wp->w_p_rl ? (col >= 0) :
2373#endif
2374 (col < wp->w_width)))
2375 {
2376 c = ' ';
2377 --ptr; // put it back at the NUL
2378 }
2379#if defined(LINE_ATTR)
2380 else if ((
2381# ifdef FEAT_DIFF
2382 diff_hlf != (hlf_T)0 ||
2383# endif
2384# ifdef FEAT_TERMINAL
2385 win_attr != 0 ||
2386# endif
2387 line_attr != 0
2388 ) && (
2389# ifdef FEAT_RIGHTLEFT
2390 wp->w_p_rl ? (col >= 0) :
2391# endif
2392 (col
2393# ifdef FEAT_CONCEAL
2394 - boguscols
2395# endif
2396 < wp->w_width)))
2397 {
2398 // Highlight until the right side of the window
2399 c = ' ';
2400 --ptr; // put it back at the NUL
2401
2402 // Remember we do the char for line highlighting.
2403 ++did_line_attr;
2404
2405 // don't do search HL for the rest of the line
2406 if (line_attr != 0 && char_attr == search_attr
2407 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002408 || (wp->w_p_list &&
2409 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002410 char_attr = line_attr;
2411# ifdef FEAT_DIFF
2412 if (diff_hlf == HLF_TXD)
2413 {
2414 diff_hlf = HLF_CHD;
2415 if (vi_attr == 0 || char_attr != vi_attr)
2416 {
2417 char_attr = HL_ATTR(diff_hlf);
2418 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2419 && wp->w_p_culopt_flags != CULOPT_NBR
2420 && (!cul_screenline
2421 || (vcol >= left_curline_col
2422 && vcol <= right_curline_col)))
2423 char_attr = hl_combine_attr(
2424 char_attr, HL_ATTR(HLF_CUL));
2425 }
2426 }
2427# endif
2428# ifdef FEAT_TERMINAL
2429 if (win_attr != 0)
2430 {
2431 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002432 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2433 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002434 {
2435 if (!cul_screenline || (vcol >= left_curline_col
2436 && vcol <= right_curline_col))
2437 char_attr = hl_combine_attr(
2438 char_attr, HL_ATTR(HLF_CUL));
2439 }
2440 else if (line_attr)
2441 char_attr = hl_combine_attr(char_attr, line_attr);
2442 }
2443# endif
2444 }
2445#endif
2446 }
2447
2448#ifdef FEAT_CONCEAL
2449 if ( wp->w_p_cole > 0
2450 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2451 conceal_cursor_line(wp))
2452 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2453 && !(lnum_in_visual_area
2454 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2455 {
2456 char_attr = conceal_attr;
2457 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002458 && (syn_get_sub_char() != NUL
2459 || (has_match_conc && match_conc)
2460 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 && wp->w_p_cole != 3)
2462 {
2463 // First time at this concealed item: display one
2464 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002465 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002466 c = match_conc;
2467 else if (syn_get_sub_char() != NUL)
2468 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002469 else if (wp->w_lcs_chars.conceal != NUL)
2470 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 else
2472 c = ' ';
2473
2474 prev_syntax_id = syntax_seqnr;
2475
2476 if (n_extra > 0)
2477 vcol_off += n_extra;
2478 vcol += n_extra;
2479 if (wp->w_p_wrap && n_extra > 0)
2480 {
2481# ifdef FEAT_RIGHTLEFT
2482 if (wp->w_p_rl)
2483 {
2484 col -= n_extra;
2485 boguscols -= n_extra;
2486 }
2487 else
2488# endif
2489 {
2490 boguscols += n_extra;
2491 col += n_extra;
2492 }
2493 }
2494 n_extra = 0;
2495 n_attr = 0;
2496 }
2497 else if (n_skip == 0)
2498 {
2499 is_concealing = TRUE;
2500 n_skip = 1;
2501 }
2502 mb_c = c;
2503 if (enc_utf8 && utf_char2len(c) > 1)
2504 {
2505 mb_utf8 = TRUE;
2506 u8cc[0] = 0;
2507 c = 0xc0;
2508 }
2509 else
2510 mb_utf8 = FALSE; // don't draw as UTF-8
2511 }
2512 else
2513 {
2514 prev_syntax_id = 0;
2515 is_concealing = FALSE;
2516 }
2517
2518 if (n_skip > 0 && did_decrement_ptr)
2519 // not showing the '>', put pointer back to avoid getting stuck
2520 ++ptr;
2521
2522#endif // FEAT_CONCEAL
2523 }
2524
2525#ifdef FEAT_CONCEAL
2526 // In the cursor line and we may be concealing characters: correct
2527 // the cursor column when we reach its position.
2528 if (!did_wcol && draw_state == WL_LINE
2529 && wp == curwin && lnum == wp->w_cursor.lnum
2530 && conceal_cursor_line(wp)
2531 && (int)wp->w_virtcol <= vcol + n_skip)
2532 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002533# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002534 if (wp->w_p_rl)
2535 wp->w_wcol = wp->w_width - col + boguscols - 1;
2536 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002537# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002538 wp->w_wcol = col - boguscols;
2539 wp->w_wrow = row;
2540 did_wcol = TRUE;
2541 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002542# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002543 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002544# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002545 }
2546#endif
2547
2548 // Don't override visual selection highlighting.
2549 if (n_attr > 0
2550 && draw_state == WL_LINE
2551 && !attr_pri)
2552 {
2553#ifdef LINE_ATTR
2554 if (line_attr)
2555 char_attr = hl_combine_attr(extra_attr, line_attr);
2556 else
2557#endif
2558 char_attr = extra_attr;
2559 }
2560
2561#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2562 // XIM don't send preedit_start and preedit_end, but they send
2563 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2564 // im_is_preediting() here.
2565 if (p_imst == IM_ON_THE_SPOT
2566 && xic != NULL
2567 && lnum == wp->w_cursor.lnum
2568 && (State & INSERT)
2569 && !p_imdisable
2570 && im_is_preediting()
2571 && draw_state == WL_LINE)
2572 {
2573 colnr_T tcol;
2574
2575 if (preedit_end_col == MAXCOL)
2576 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2577 else
2578 tcol = preedit_end_col;
2579 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2580 {
2581 if (feedback_old_attr < 0)
2582 {
2583 feedback_col = 0;
2584 feedback_old_attr = char_attr;
2585 }
2586 char_attr = im_get_feedback_attr(feedback_col);
2587 if (char_attr < 0)
2588 char_attr = feedback_old_attr;
2589 feedback_col++;
2590 }
2591 else if (feedback_old_attr >= 0)
2592 {
2593 char_attr = feedback_old_attr;
2594 feedback_old_attr = -1;
2595 feedback_col = 0;
2596 }
2597 }
2598#endif
2599 // Handle the case where we are in column 0 but not on the first
2600 // character of the line and the user wants us to show us a
2601 // special character (via 'listchars' option "precedes:<char>".
2602 if (lcs_prec_todo != NUL
2603 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002604 && (wp->w_p_wrap ?
2605 (wp->w_skipcol > 0 && row == 0) :
2606 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002607#ifdef FEAT_DIFF
2608 && filler_todo <= 0
2609#endif
2610 && draw_state > WL_NR
2611 && c != NUL)
2612 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002613 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002614 lcs_prec_todo = NUL;
2615 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2616 {
2617 // Double-width character being overwritten by the "precedes"
2618 // character, need to fill up half the character.
2619 c_extra = MB_FILLER_CHAR;
2620 c_final = NUL;
2621 n_extra = 1;
2622 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002623 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002624 }
2625 mb_c = c;
2626 if (enc_utf8 && utf_char2len(c) > 1)
2627 {
2628 mb_utf8 = TRUE;
2629 u8cc[0] = 0;
2630 c = 0xc0;
2631 }
2632 else
2633 mb_utf8 = FALSE; // don't draw as UTF-8
2634 if (!attr_pri)
2635 {
2636 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002637 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002638 n_attr3 = 1;
2639 }
2640 }
2641
2642 // At end of the text line or just after the last character.
2643 if ((c == NUL
2644#if defined(LINE_ATTR)
2645 || did_line_attr == 1
2646#endif
2647 ) && eol_hl_off == 0)
2648 {
2649#ifdef FEAT_SEARCH_EXTRA
2650 // flag to indicate whether prevcol equals startcol of search_hl or
2651 // one of the matches
2652 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2653 (long)(ptr - line) - (c == NUL));
2654#endif
2655 // Invert at least one char, used for Visual and empty line or
2656 // highlight match at end of line. If it's beyond the last
2657 // char on the screen, just overwrite that one (tricky!) Not
2658 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002659 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 && ((area_attr != 0 && vcol == fromcol
2661 && (VIsual_mode != Ctrl_V
2662 || lnum == VIsual.lnum
2663 || lnum == curwin->w_cursor.lnum)
2664 && c == NUL)
2665#ifdef FEAT_SEARCH_EXTRA
2666 // highlight 'hlsearch' match at end of line
2667 || (prevcol_hl_flag
2668# ifdef FEAT_SYN_HL
2669 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2670 && !(wp == curwin && VIsual_active))
2671# endif
2672# ifdef FEAT_DIFF
2673 && diff_hlf == (hlf_T)0
2674# endif
2675# if defined(LINE_ATTR)
2676 && did_line_attr <= 1
2677# endif
2678 )
2679#endif
2680 ))
2681 {
2682 int n = 0;
2683
2684#ifdef FEAT_RIGHTLEFT
2685 if (wp->w_p_rl)
2686 {
2687 if (col < 0)
2688 n = 1;
2689 }
2690 else
2691#endif
2692 {
2693 if (col >= wp->w_width)
2694 n = -1;
2695 }
2696 if (n != 0)
2697 {
2698 // At the window boundary, highlight the last character
2699 // instead (better than nothing).
2700 off += n;
2701 col += n;
2702 }
2703 else
2704 {
2705 // Add a blank character to highlight.
2706 ScreenLines[off] = ' ';
2707 if (enc_utf8)
2708 ScreenLinesUC[off] = 0;
2709 }
2710#ifdef FEAT_SEARCH_EXTRA
2711 if (area_attr == 0)
2712 {
2713 // Use attributes from match with highest priority among
2714 // 'search_hl' and the match list.
2715 get_search_match_hl(wp, &screen_search_hl,
2716 (long)(ptr - line), &char_attr);
2717 }
2718#endif
2719 ScreenAttrs[off] = char_attr;
2720#ifdef FEAT_RIGHTLEFT
2721 if (wp->w_p_rl)
2722 {
2723 --col;
2724 --off;
2725 }
2726 else
2727#endif
2728 {
2729 ++col;
2730 ++off;
2731 }
2732 ++vcol;
2733 eol_hl_off = 1;
2734 }
2735 }
2736
2737 // At end of the text line.
2738 if (c == NUL)
2739 {
2740#ifdef FEAT_SYN_HL
2741 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2742 if (wp->w_p_wrap)
2743 v = wp->w_skipcol;
2744 else
2745 v = wp->w_leftcol;
2746
2747 // check if line ends before left margin
2748 if (vcol < v + col - win_col_off(wp))
2749 vcol = v + col - win_col_off(wp);
2750#ifdef FEAT_CONCEAL
2751 // Get rid of the boguscols now, we want to draw until the right
2752 // edge for 'cursorcolumn'.
2753 col -= boguscols;
2754 boguscols = 0;
2755#endif
2756
2757 if (draw_color_col)
2758 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2759
2760 if (((wp->w_p_cuc
2761 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2762 && (int)wp->w_virtcol <
2763 wp->w_width * (row - startrow + 1) + v
2764 && lnum != wp->w_cursor.lnum)
2765 || draw_color_col
2766 || win_attr != 0)
2767# ifdef FEAT_RIGHTLEFT
2768 && !wp->w_p_rl
2769# endif
2770 )
2771 {
2772 int rightmost_vcol = 0;
2773 int i;
2774
2775 if (wp->w_p_cuc)
2776 rightmost_vcol = wp->w_virtcol;
2777 if (draw_color_col)
2778 // determine rightmost colorcolumn to possibly draw
2779 for (i = 0; color_cols[i] >= 0; ++i)
2780 if (rightmost_vcol < color_cols[i])
2781 rightmost_vcol = color_cols[i];
2782
2783 while (col < wp->w_width)
2784 {
2785 ScreenLines[off] = ' ';
2786 if (enc_utf8)
2787 ScreenLinesUC[off] = 0;
2788 ++col;
2789 if (draw_color_col)
2790 draw_color_col = advance_color_col(VCOL_HLC,
2791 &color_cols);
2792
2793 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2794 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2795 else if (draw_color_col && VCOL_HLC == *color_cols)
2796 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2797 else
2798 ScreenAttrs[off++] = win_attr;
2799
2800 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2801 break;
2802
2803 ++vcol;
2804 }
2805 }
2806#endif
2807
2808 screen_line(screen_row, wp->w_wincol, col,
2809 (int)wp->w_width, screen_line_flags);
2810 row++;
2811
2812 // Update w_cline_height and w_cline_folded if the cursor line was
2813 // updated (saves a call to plines() later).
2814 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2815 {
2816 curwin->w_cline_row = startrow;
2817 curwin->w_cline_height = row - startrow;
2818#ifdef FEAT_FOLDING
2819 curwin->w_cline_folded = FALSE;
2820#endif
2821 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2822 }
2823
2824 break;
2825 }
2826
2827 // Show "extends" character from 'listchars' if beyond the line end and
2828 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002829 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002830 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002831 && wp->w_p_list
2832 && !wp->w_p_wrap
2833#ifdef FEAT_DIFF
2834 && filler_todo <= 0
2835#endif
2836 && (
2837#ifdef FEAT_RIGHTLEFT
2838 wp->w_p_rl ? col == 0 :
2839#endif
2840 col == wp->w_width - 1)
2841 && (*ptr != NUL
2842 || (wp->w_p_list && lcs_eol_one > 0)
2843 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2844 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002845 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002846 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 mb_c = c;
2848 if (enc_utf8 && utf_char2len(c) > 1)
2849 {
2850 mb_utf8 = TRUE;
2851 u8cc[0] = 0;
2852 c = 0xc0;
2853 }
2854 else
2855 mb_utf8 = FALSE;
2856 }
2857
2858#ifdef FEAT_SYN_HL
2859 // advance to the next 'colorcolumn'
2860 if (draw_color_col)
2861 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2862
2863 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2864 // highlight the cursor position itself.
2865 // Also highlight the 'colorcolumn' if it is different than
2866 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002867 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2868 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002869 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002870 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002871 draw_state == WL_BRI ||
2872 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002874# ifdef FEAT_DIFF
2875 && filler_todo <= 0
2876# endif
2877 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 {
2879 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2880 && lnum != wp->w_cursor.lnum)
2881 {
2882 vcol_save_attr = char_attr;
2883 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2884 }
2885 else if (draw_color_col && VCOL_HLC == *color_cols)
2886 {
2887 vcol_save_attr = char_attr;
2888 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2889 }
2890 }
2891#endif
2892
2893 // Store character to be displayed.
2894 // Skip characters that are left of the screen for 'nowrap'.
2895 vcol_prev = vcol;
2896 if (draw_state < WL_LINE || n_skip <= 0)
2897 {
2898 // Store the character.
2899#if defined(FEAT_RIGHTLEFT)
2900 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2901 {
2902 // A double-wide character is: put first halve in left cell.
2903 --off;
2904 --col;
2905 }
2906#endif
2907 ScreenLines[off] = c;
2908 if (enc_dbcs == DBCS_JPNU)
2909 {
2910 if ((mb_c & 0xff00) == 0x8e00)
2911 ScreenLines[off] = 0x8e;
2912 ScreenLines2[off] = mb_c & 0xff;
2913 }
2914 else if (enc_utf8)
2915 {
2916 if (mb_utf8)
2917 {
2918 int i;
2919
2920 ScreenLinesUC[off] = mb_c;
2921 if ((c & 0xff) == 0)
2922 ScreenLines[off] = 0x80; // avoid storing zero
2923 for (i = 0; i < Screen_mco; ++i)
2924 {
2925 ScreenLinesC[i][off] = u8cc[i];
2926 if (u8cc[i] == 0)
2927 break;
2928 }
2929 }
2930 else
2931 ScreenLinesUC[off] = 0;
2932 }
2933 if (multi_attr)
2934 {
2935 ScreenAttrs[off] = multi_attr;
2936 multi_attr = 0;
2937 }
2938 else
2939 ScreenAttrs[off] = char_attr;
2940
2941 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2942 {
2943 // Need to fill two screen columns.
2944 ++off;
2945 ++col;
2946 if (enc_utf8)
2947 // UTF-8: Put a 0 in the second screen char.
2948 ScreenLines[off] = 0;
2949 else
2950 // DBCS: Put second byte in the second screen char.
2951 ScreenLines[off] = mb_c & 0xff;
2952 if (draw_state > WL_NR
2953#ifdef FEAT_DIFF
2954 && filler_todo <= 0
2955#endif
2956 )
2957 ++vcol;
2958 // When "tocol" is halfway a character, set it to the end of
2959 // the character, otherwise highlighting won't stop.
2960 if (tocol == vcol)
2961 ++tocol;
2962#ifdef FEAT_RIGHTLEFT
2963 if (wp->w_p_rl)
2964 {
2965 // now it's time to backup one cell
2966 --off;
2967 --col;
2968 }
2969#endif
2970 }
2971#ifdef FEAT_RIGHTLEFT
2972 if (wp->w_p_rl)
2973 {
2974 --off;
2975 --col;
2976 }
2977 else
2978#endif
2979 {
2980 ++off;
2981 ++col;
2982 }
2983 }
2984#ifdef FEAT_CONCEAL
2985 else if (wp->w_p_cole > 0 && is_concealing)
2986 {
2987 --n_skip;
2988 ++vcol_off;
2989 if (n_extra > 0)
2990 vcol_off += n_extra;
2991 if (wp->w_p_wrap)
2992 {
2993 // Special voodoo required if 'wrap' is on.
2994 //
2995 // Advance the column indicator to force the line
2996 // drawing to wrap early. This will make the line
2997 // take up the same screen space when parts are concealed,
2998 // so that cursor line computations aren't messed up.
2999 //
3000 // To avoid the fictitious advance of 'col' causing
3001 // trailing junk to be written out of the screen line
3002 // we are building, 'boguscols' keeps track of the number
3003 // of bad columns we have advanced.
3004 if (n_extra > 0)
3005 {
3006 vcol += n_extra;
3007# ifdef FEAT_RIGHTLEFT
3008 if (wp->w_p_rl)
3009 {
3010 col -= n_extra;
3011 boguscols -= n_extra;
3012 }
3013 else
3014# endif
3015 {
3016 col += n_extra;
3017 boguscols += n_extra;
3018 }
3019 n_extra = 0;
3020 n_attr = 0;
3021 }
3022
3023
3024 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3025 {
3026 // Need to fill two screen columns.
3027# ifdef FEAT_RIGHTLEFT
3028 if (wp->w_p_rl)
3029 {
3030 --boguscols;
3031 --col;
3032 }
3033 else
3034# endif
3035 {
3036 ++boguscols;
3037 ++col;
3038 }
3039 }
3040
3041# ifdef FEAT_RIGHTLEFT
3042 if (wp->w_p_rl)
3043 {
3044 --boguscols;
3045 --col;
3046 }
3047 else
3048# endif
3049 {
3050 ++boguscols;
3051 ++col;
3052 }
3053 }
3054 else
3055 {
3056 if (n_extra > 0)
3057 {
3058 vcol += n_extra;
3059 n_extra = 0;
3060 n_attr = 0;
3061 }
3062 }
3063
3064 }
3065#endif // FEAT_CONCEAL
3066 else
3067 --n_skip;
3068
3069 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3070 // column.
3071 if (draw_state > WL_NR
3072#ifdef FEAT_DIFF
3073 && filler_todo <= 0
3074#endif
3075 )
3076 ++vcol;
3077
3078#ifdef FEAT_SYN_HL
3079 if (vcol_save_attr >= 0)
3080 char_attr = vcol_save_attr;
3081#endif
3082
3083 // restore attributes after "predeces" in 'listchars'
3084 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3085 char_attr = saved_attr3;
3086
3087 // restore attributes after last 'listchars' or 'number' char
3088 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3089 char_attr = saved_attr2;
3090
3091 // At end of screen line and there is more to come: Display the line
3092 // so far. If there is no more to display it is caught above.
3093 if ((
3094#ifdef FEAT_RIGHTLEFT
3095 wp->w_p_rl ? (col < 0) :
3096#endif
3097 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003098 && (draw_state != WL_LINE
3099 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003100#ifdef FEAT_DIFF
3101 || filler_todo > 0
3102#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003103 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3104 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003105 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3106 )
3107 {
3108#ifdef FEAT_CONCEAL
3109 screen_line(screen_row, wp->w_wincol, col - boguscols,
3110 (int)wp->w_width, screen_line_flags);
3111 boguscols = 0;
3112#else
3113 screen_line(screen_row, wp->w_wincol, col,
3114 (int)wp->w_width, screen_line_flags);
3115#endif
3116 ++row;
3117 ++screen_row;
3118
3119 // When not wrapping and finished diff lines, or when displayed
3120 // '$' and highlighting until last column, break here.
3121 if ((!wp->w_p_wrap
3122#ifdef FEAT_DIFF
3123 && filler_todo <= 0
3124#endif
3125 ) || lcs_eol_one == -1)
3126 break;
3127
3128 // When the window is too narrow draw all "@" lines.
3129 if (draw_state != WL_LINE
3130#ifdef FEAT_DIFF
3131 && filler_todo <= 0
3132#endif
3133 )
3134 {
3135 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3136 draw_vsep_win(wp, row);
3137 row = endrow;
3138 }
3139
3140 // When line got too long for screen break here.
3141 if (row == endrow)
3142 {
3143 ++row;
3144 break;
3145 }
3146
3147 if (screen_cur_row == screen_row - 1
3148#ifdef FEAT_DIFF
3149 && filler_todo <= 0
3150#endif
3151 && wp->w_width == Columns)
3152 {
3153 // Remember that the line wraps, used for modeless copy.
3154 LineWraps[screen_row - 1] = TRUE;
3155
3156 // Special trick to make copy/paste of wrapped lines work with
3157 // xterm/screen: write an extra character beyond the end of
3158 // the line. This will work with all terminal types
3159 // (regardless of the xn,am settings).
3160 // Only do this on a fast tty.
3161 // Only do this if the cursor is on the current line
3162 // (something has been written in it).
3163 // Don't do this for the GUI.
3164 // Don't do this for double-width characters.
3165 // Don't do this for a window not at the right screen border.
3166 if (p_tf
3167#ifdef FEAT_GUI
3168 && !gui.in_use
3169#endif
3170 && !(has_mbyte
3171 && ((*mb_off2cells)(LineOffset[screen_row],
3172 LineOffset[screen_row] + screen_Columns)
3173 == 2
3174 || (*mb_off2cells)(LineOffset[screen_row - 1]
3175 + (int)Columns - 2,
3176 LineOffset[screen_row] + screen_Columns)
3177 == 2)))
3178 {
3179 // First make sure we are at the end of the screen line,
3180 // then output the same character again to let the
3181 // terminal know about the wrap. If the terminal doesn't
3182 // auto-wrap, we overwrite the character.
3183 if (screen_cur_col != wp->w_width)
3184 screen_char(LineOffset[screen_row - 1]
3185 + (unsigned)Columns - 1,
3186 screen_row - 1, (int)(Columns - 1));
3187
3188 // When there is a multi-byte character, just output a
3189 // space to keep it simple.
3190 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3191 screen_row - 1] + (Columns - 1)]) > 1)
3192 out_char(' ');
3193 else
3194 out_char(ScreenLines[LineOffset[screen_row - 1]
3195 + (Columns - 1)]);
3196 // force a redraw of the first char on the next line
3197 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3198 screen_start(); // don't know where cursor is now
3199 }
3200 }
3201
3202 col = 0;
3203 off = (unsigned)(current_ScreenLine - ScreenLines);
3204#ifdef FEAT_RIGHTLEFT
3205 if (wp->w_p_rl)
3206 {
3207 col = wp->w_width - 1; // col is not used if breaking!
3208 off += col;
3209 }
3210#endif
3211
3212 // reset the drawing state for the start of a wrapped line
3213 draw_state = WL_START;
3214 saved_n_extra = n_extra;
3215 saved_p_extra = p_extra;
3216 saved_c_extra = c_extra;
3217 saved_c_final = c_final;
3218#ifdef FEAT_SYN_HL
3219 if (!(cul_screenline
3220# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003221 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003223 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003224 saved_char_attr = char_attr;
3225 else
3226#endif
3227 saved_char_attr = 0;
3228 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003229 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003230#ifdef FEAT_LINEBREAK
3231# ifdef FEAT_DIFF
3232 if (filler_todo <= 0)
3233# endif
3234 need_showbreak = TRUE;
3235#endif
3236#ifdef FEAT_DIFF
3237 --filler_todo;
3238 // When the filler lines are actually below the last line of the
3239 // file, don't draw the line itself, break here.
3240 if (filler_todo == 0 && wp->w_botfill)
3241 break;
3242#endif
3243 }
3244
3245 } // for every character in the line
3246
3247#ifdef FEAT_SPELL
3248 // After an empty line check first word for capital.
3249 if (*skipwhite(line) == NUL)
3250 {
3251 capcol_lnum = lnum + 1;
3252 cap_col = 0;
3253 }
3254#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003255#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003256 vim_free(text_props);
3257 vim_free(text_prop_idxs);
3258#endif
3259
3260 vim_free(p_extra_free);
3261 return row;
3262}