blob: 4dde0d074039d479af3af4bc8768a39a216702a3 [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/*
80 * Get information needed to display the sign in line 'lnum' in window 'wp'.
81 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
82 * Otherwise the sign is going to be displayed in the sign column.
83 */
84 static void
85get_sign_display_info(
86 int nrcol,
87 win_T *wp,
88 linenr_T lnum UNUSED,
89 sign_attrs_T *sattr,
90 int wcr_attr,
91 int row,
92 int startrow,
93 int filler_lines UNUSED,
94 int filler_todo UNUSED,
95 int *c_extrap,
96 int *c_finalp,
97 char_u *extra,
98 char_u **pp_extra,
99 int *n_extrap,
100 int *char_attrp)
101{
102 int text_sign;
103# ifdef FEAT_SIGN_ICONS
104 int icon_sign;
105# endif
106
107 // Draw two cells with the sign value or blank.
108 *c_extrap = ' ';
109 *c_finalp = NUL;
110 if (nrcol)
111 *n_extrap = number_width(wp) + 1;
112 else
113 {
114 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
115 *n_extrap = 2;
116 }
117
118 if (row == startrow
119#ifdef FEAT_DIFF
120 + filler_lines && filler_todo <= 0
121#endif
122 )
123 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200124 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200125# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200126 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200127 if (gui.in_use && icon_sign != 0)
128 {
129 // Use the image in this position.
130 if (nrcol)
131 {
132 *c_extrap = NUL;
133 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
134 *pp_extra = extra;
135 *n_extrap = (int)STRLEN(*pp_extra);
136 }
137 else
138 *c_extrap = SIGN_BYTE;
139# ifdef FEAT_NETBEANS_INTG
140 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
141 {
142 if (nrcol)
143 {
144 *c_extrap = NUL;
145 sprintf((char *)extra, "%-*c ", number_width(wp),
146 MULTISIGN_BYTE);
147 *pp_extra = extra;
148 *n_extrap = (int)STRLEN(*pp_extra);
149 }
150 else
151 *c_extrap = MULTISIGN_BYTE;
152 }
153# endif
154 *c_finalp = NUL;
155 *char_attrp = icon_sign;
156 }
157 else
158# endif
159 if (text_sign != 0)
160 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200161 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200162 if (*pp_extra != NULL)
163 {
164 if (nrcol)
165 {
166 int n, width = number_width(wp) - 2;
167
168 for (n = 0; n < width; n++)
169 extra[n] = ' ';
170 extra[n] = 0;
171 STRCAT(extra, *pp_extra);
172 STRCAT(extra, " ");
173 *pp_extra = extra;
174 }
175 *c_extrap = NUL;
176 *c_finalp = NUL;
177 *n_extrap = (int)STRLEN(*pp_extra);
178 }
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200179 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200180 }
181 }
182}
183#endif
184
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100185#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186static textprop_T *current_text_props = NULL;
187static buf_T *current_buf = NULL;
188
189 static int
190text_prop_compare(const void *s1, const void *s2)
191{
192 int idx1, idx2;
193 proptype_T *pt1, *pt2;
194 colnr_T col1, col2;
195
196 idx1 = *(int *)s1;
197 idx2 = *(int *)s2;
198 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
199 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
200 if (pt1 == pt2)
201 return 0;
202 if (pt1 == NULL)
203 return -1;
204 if (pt2 == NULL)
205 return 1;
206 if (pt1->pt_priority != pt2->pt_priority)
207 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
208 col1 = current_text_props[idx1].tp_col;
209 col2 = current_text_props[idx2].tp_col;
210 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
211}
212#endif
213
214/*
215 * Display line "lnum" of window 'wp' on the screen.
216 * Start at row "startrow", stop when "endrow" is reached.
217 * wp->w_virtcol needs to be valid.
218 *
219 * Return the number of last row the line occupies.
220 */
221 int
222win_line(
223 win_T *wp,
224 linenr_T lnum,
225 int startrow,
226 int endrow,
227 int nochange UNUSED, // not updating for changed text
228 int number_only) // only update the number column
229{
230 int col = 0; // visual column on screen
231 unsigned off; // offset in ScreenLines/ScreenAttrs
232 int c = 0; // init for GCC
233 long vcol = 0; // virtual column (for tabs)
234#ifdef FEAT_LINEBREAK
235 long vcol_sbr = -1; // virtual column after showbreak
236#endif
237 long vcol_prev = -1; // "vcol" of previous character
238 char_u *line; // current line
239 char_u *ptr; // current position in "line"
240 int row; // row in the window, excl w_winrow
241 int screen_row; // row on the screen, incl w_winrow
242
243 char_u extra[21]; // "%ld " and 'fdc' must fit in here
244 int n_extra = 0; // number of extra chars
245 char_u *p_extra = NULL; // string of extra chars, plus NUL
246 char_u *p_extra_free = NULL; // p_extra needs to be freed
247 int c_extra = NUL; // extra chars, all the same
248 int c_final = NUL; // final char, mandatory if set
249 int extra_attr = 0; // attributes when n_extra != 0
250 static char_u *at_end_str = (char_u *)""; // used for p_extra when
251 // displaying lcs_eol at end-of-line
252 int lcs_eol_one = lcs_eol; // lcs_eol until it's been used
253 int lcs_prec_todo = lcs_prec; // lcs_prec until it's been used
254
255 // saved "extra" items for when draw_state becomes WL_LINE (again)
256 int saved_n_extra = 0;
257 char_u *saved_p_extra = NULL;
258 int saved_c_extra = 0;
259 int saved_c_final = 0;
260 int saved_char_attr = 0;
261
262 int n_attr = 0; // chars with special attr
263 int saved_attr2 = 0; // char_attr saved for n_attr
264 int n_attr3 = 0; // chars with overruling special attr
265 int saved_attr3 = 0; // char_attr saved for n_attr3
266
267 int n_skip = 0; // nr of chars to skip for 'nowrap'
268
269 int fromcol = -10; // start of inverting
270 int tocol = MAXCOL; // end of inverting
271 int fromcol_prev = -2; // start of inverting after cursor
272 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 int lnum_in_visual_area = FALSE;
274 pos_T pos;
275 long v;
276
277 int char_attr = 0; // attributes for next character
278 int attr_pri = FALSE; // char_attr has priority
279 int area_highlighting = FALSE; // Visual or incsearch highlighting
280 // in this line
281 int vi_attr = 0; // attributes for Visual and incsearch
282 // highlighting
283 int wcr_attr = 0; // attributes from 'wincolor'
284 int win_attr = 0; // background for whole window, except
285 // margins and "~" lines.
286 int area_attr = 0; // attributes desired by highlighting
287 int search_attr = 0; // attributes desired by 'hlsearch'
288#ifdef FEAT_SYN_HL
289 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
290 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200291 int prev_syntax_col = -1; // column of prev_syntax_attr
292 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 int has_syntax = FALSE; // this buffer has syntax highl.
294 int save_did_emsg;
295 int draw_color_col = FALSE; // highlight colorcolumn
296 int *color_cols = NULL; // pointer to according columns array
297#endif
298 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100299#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200300 int text_prop_count;
301 int text_prop_next = 0; // next text property to use
302 textprop_T *text_props = NULL;
303 int *text_prop_idxs = NULL;
304 int text_props_active = 0;
305 proptype_T *text_prop_type = NULL;
306 int text_prop_attr = 0;
307 int text_prop_combine = FALSE;
308#endif
309#ifdef FEAT_SPELL
310 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200311 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200312# define SPWORDLEN 150
313 char_u nextline[SPWORDLEN * 2];// text with start of the next line
314 int nextlinecol = 0; // column where nextline[] starts
315 int nextline_idx = 0; // index in nextline[] where next line
316 // starts
317 int spell_attr = 0; // attributes desired by spelling
318 int word_end = 0; // last byte with same spell_attr
319 static linenr_T checked_lnum = 0; // line number for "checked_col"
320 static int checked_col = 0; // column in "checked_lnum" up to which
321 // there are no spell errors
322 static int cap_col = -1; // column to check for Cap word
323 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
324 int cur_checked_col = 0; // checked column for current line
325#endif
326 int extra_check = 0; // has extra highlighting
327 int multi_attr = 0; // attributes desired by multibyte
328 int mb_l = 1; // multi-byte byte length
329 int mb_c = 0; // decoded multi-byte character
330 int mb_utf8 = FALSE; // screen char is UTF-8 char
331 int u8cc[MAX_MCO]; // composing UTF-8 chars
332#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
333 int filler_lines = 0; // nr of filler lines to be drawn
334 int filler_todo = 0; // nr of filler lines still to do + 1
335#endif
336#ifdef FEAT_DIFF
337 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
338 int change_start = MAXCOL; // first col of changed area
339 int change_end = -1; // last col of changed area
340#endif
341 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100342 colnr_T leadcol = 0; // start of leading spaces
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200343#ifdef FEAT_LINEBREAK
344 int need_showbreak = FALSE; // overlong line, skipping first x
345 // chars
346#endif
347#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
348 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
349# define LINE_ATTR
350 int line_attr = 0; // attribute for the whole line
351 int line_attr_save;
352#endif
353#ifdef FEAT_SIGNS
354 int sign_present = FALSE;
355 sign_attrs_T sattr;
356#endif
357#ifdef FEAT_ARABIC
358 int prev_c = 0; // previous Arabic character
359 int prev_c1 = 0; // first composing char for prev_c
360#endif
361#if defined(LINE_ATTR)
362 int did_line_attr = 0;
363#endif
364#ifdef FEAT_TERMINAL
365 int get_term_attr = FALSE;
366#endif
367#ifdef FEAT_SYN_HL
368 int cul_attr = 0; // set when 'cursorline' active
369
370 // 'cursorlineopt' has "screenline" and cursor is in this line
371 int cul_screenline = FALSE;
372
373 // margin columns for the screen line, needed for when 'cursorlineopt'
374 // contains "screenline"
375 int left_curline_col = 0;
376 int right_curline_col = 0;
377#endif
378
379 // draw_state: items that are drawn in sequence:
380#define WL_START 0 // nothing done yet
381#ifdef FEAT_CMDWIN
382# define WL_CMDLINE WL_START + 1 // cmdline window column
383#else
384# define WL_CMDLINE WL_START
385#endif
386#ifdef FEAT_FOLDING
387# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
388#else
389# define WL_FOLD WL_CMDLINE
390#endif
391#ifdef FEAT_SIGNS
392# define WL_SIGN WL_FOLD + 1 // column for signs
393#else
394# define WL_SIGN WL_FOLD // column for signs
395#endif
396#define WL_NR WL_SIGN + 1 // line number
397#ifdef FEAT_LINEBREAK
398# define WL_BRI WL_NR + 1 // 'breakindent'
399#else
400# define WL_BRI WL_NR
401#endif
402#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
403# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
404#else
405# define WL_SBR WL_BRI
406#endif
407#define WL_LINE WL_SBR + 1 // text in the line
408 int draw_state = WL_START; // what to draw next
409#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
410 int feedback_col = 0;
411 int feedback_old_attr = -1;
412#endif
413 int screen_line_flags = 0;
414
415#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
416 int match_conc = 0; // cchar for match functions
417#endif
418#ifdef FEAT_CONCEAL
419 int syntax_flags = 0;
420 int syntax_seqnr = 0;
421 int prev_syntax_id = 0;
422 int conceal_attr = HL_ATTR(HLF_CONCEAL);
423 int is_concealing = FALSE;
424 int boguscols = 0; // nonexistent columns added to force
425 // wrapping
426 int vcol_off = 0; // offset for concealed characters
427 int did_wcol = FALSE;
428 int old_boguscols = 0;
429# define VCOL_HLC (vcol - vcol_off)
430# define FIX_FOR_BOGUSCOLS \
431 { \
432 n_extra += vcol_off; \
433 vcol -= vcol_off; \
434 vcol_off = 0; \
435 col -= boguscols; \
436 old_boguscols = boguscols; \
437 boguscols = 0; \
438 }
439#else
440# define VCOL_HLC (vcol)
441#endif
442
443 if (startrow > endrow) // past the end already!
444 return startrow;
445
446 row = startrow;
447 screen_row = row + W_WINROW(wp);
448
449 if (!number_only)
450 {
451 // To speed up the loop below, set extra_check when there is linebreak,
452 // trailing white space and/or syntax processing to be done.
453#ifdef FEAT_LINEBREAK
454 extra_check = wp->w_p_lbr;
455#endif
456#ifdef FEAT_SYN_HL
457 if (syntax_present(wp) && !wp->w_s->b_syn_error
458# ifdef SYN_TIME_LIMIT
459 && !wp->w_s->b_syn_slow
460# endif
461 )
462 {
463 // Prepare for syntax highlighting in this line. When there is an
464 // error, stop syntax highlighting.
465 save_did_emsg = did_emsg;
466 did_emsg = FALSE;
467 syntax_start(wp, lnum);
468 if (did_emsg)
469 wp->w_s->b_syn_error = TRUE;
470 else
471 {
472 did_emsg = save_did_emsg;
473#ifdef SYN_TIME_LIMIT
474 if (!wp->w_s->b_syn_slow)
475#endif
476 {
477 has_syntax = TRUE;
478 extra_check = TRUE;
479 }
480 }
481 }
482
483 // Check for columns to display for 'colorcolumn'.
484 color_cols = wp->w_p_cc_cols;
485 if (color_cols != NULL)
486 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
487#endif
488
489#ifdef FEAT_TERMINAL
490 if (term_show_buffer(wp->w_buffer))
491 {
492 extra_check = TRUE;
493 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100494 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 }
496#endif
497
498#ifdef FEAT_SPELL
499 if (wp->w_p_spell
500 && *wp->w_s->b_p_spl != NUL
501 && wp->w_s->b_langp.ga_len > 0
502 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
503 {
504 // Prepare for spell checking.
505 has_spell = TRUE;
506 extra_check = TRUE;
507
508 // Get the start of the next line, so that words that wrap to the
509 // next line are found too: "et<line-break>al.".
510 // Trick: skip a few chars for C/shell/Vim comments
511 nextline[SPWORDLEN] = NUL;
512 if (lnum < wp->w_buffer->b_ml.ml_line_count)
513 {
514 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
515 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
516 }
517
518 // When a word wrapped from the previous line the start of the
519 // current line is valid.
520 if (lnum == checked_lnum)
521 cur_checked_col = checked_col;
522 checked_lnum = 0;
523
524 // When there was a sentence end in the previous line may require a
525 // word starting with capital in this line. In line 1 always check
526 // the first word.
527 if (lnum != capcol_lnum)
528 cap_col = -1;
529 if (lnum == 1)
530 cap_col = 0;
531 capcol_lnum = 0;
532 }
533#endif
534
535 // handle Visual active in this window
536 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
537 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100538 pos_T *top, *bot;
539
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200540 if (LTOREQ_POS(curwin->w_cursor, VIsual))
541 {
542 // Visual is after curwin->w_cursor
543 top = &curwin->w_cursor;
544 bot = &VIsual;
545 }
546 else
547 {
548 // Visual is before curwin->w_cursor
549 top = &VIsual;
550 bot = &curwin->w_cursor;
551 }
552 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
553 if (VIsual_mode == Ctrl_V)
554 {
555 // block mode
556 if (lnum_in_visual_area)
557 {
558 fromcol = wp->w_old_cursor_fcol;
559 tocol = wp->w_old_cursor_lcol;
560 }
561 }
562 else
563 {
564 // non-block mode
565 if (lnum > top->lnum && lnum <= bot->lnum)
566 fromcol = 0;
567 else if (lnum == top->lnum)
568 {
569 if (VIsual_mode == 'V') // linewise
570 fromcol = 0;
571 else
572 {
573 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
574 if (gchar_pos(top) == NUL)
575 tocol = fromcol + 1;
576 }
577 }
578 if (VIsual_mode != 'V' && lnum == bot->lnum)
579 {
580 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
581 {
582 fromcol = -10;
583 tocol = MAXCOL;
584 }
585 else if (bot->col == MAXCOL)
586 tocol = MAXCOL;
587 else
588 {
589 pos = *bot;
590 if (*p_sel == 'e')
591 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
592 else
593 {
594 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
595 ++tocol;
596 }
597 }
598 }
599 }
600
601 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200602 if (!highlight_match && lnum == curwin->w_cursor.lnum
603 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200604#ifdef FEAT_GUI
605 && !gui.in_use
606#endif
607 )
608 noinvcur = TRUE;
609
610 // if inverting in this line set area_highlighting
611 if (fromcol >= 0)
612 {
613 area_highlighting = TRUE;
614 vi_attr = HL_ATTR(HLF_V);
615#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
616 if ((clip_star.available && !clip_star.owned
617 && clip_isautosel_star())
618 || (clip_plus.available && !clip_plus.owned
619 && clip_isautosel_plus()))
620 vi_attr = HL_ATTR(HLF_VNC);
621#endif
622 }
623 }
624
625 // handle 'incsearch' and ":s///c" highlighting
626 else if (highlight_match
627 && wp == curwin
628 && lnum >= curwin->w_cursor.lnum
629 && lnum <= curwin->w_cursor.lnum + search_match_lines)
630 {
631 if (lnum == curwin->w_cursor.lnum)
632 getvcol(curwin, &(curwin->w_cursor),
633 (colnr_T *)&fromcol, NULL, NULL);
634 else
635 fromcol = 0;
636 if (lnum == curwin->w_cursor.lnum + search_match_lines)
637 {
638 pos.lnum = lnum;
639 pos.col = search_match_endcol;
640 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
641 }
642 else
643 tocol = MAXCOL;
644 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100645 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200646 tocol = fromcol + 1;
647 area_highlighting = TRUE;
648 vi_attr = HL_ATTR(HLF_I);
649 }
650 }
651
652#ifdef FEAT_DIFF
653 filler_lines = diff_check(wp, lnum);
654 if (filler_lines < 0)
655 {
656 if (filler_lines == -1)
657 {
658 if (diff_find_change(wp, lnum, &change_start, &change_end))
659 diff_hlf = HLF_ADD; // added line
660 else if (change_start == 0)
661 diff_hlf = HLF_TXD; // changed text
662 else
663 diff_hlf = HLF_CHD; // changed line
664 }
665 else
666 diff_hlf = HLF_ADD; // added line
667 filler_lines = 0;
668 area_highlighting = TRUE;
669 }
670 if (lnum == wp->w_topline)
671 filler_lines = wp->w_topfill;
672 filler_todo = filler_lines;
673#endif
674
675#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100676 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200677#endif
678
679#ifdef LINE_ATTR
680# ifdef FEAT_SIGNS
681 // If this line has a sign with line highlighting set line_attr.
682 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200683 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200684# endif
685# if defined(FEAT_QUICKFIX)
686 // Highlight the current line in the quickfix window.
687 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
688 line_attr = HL_ATTR(HLF_QFL);
689# endif
690 if (line_attr != 0)
691 area_highlighting = TRUE;
692#endif
693
694 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
695 ptr = line;
696
697#ifdef FEAT_SPELL
698 if (has_spell && !number_only)
699 {
700 // For checking first word with a capital skip white space.
701 if (cap_col == 0)
702 cap_col = getwhitecols(line);
703
704 // To be able to spell-check over line boundaries copy the end of the
705 // current line into nextline[]. Above the start of the next line was
706 // copied to nextline[SPWORDLEN].
707 if (nextline[SPWORDLEN] == NUL)
708 {
709 // No next line or it is empty.
710 nextlinecol = MAXCOL;
711 nextline_idx = 0;
712 }
713 else
714 {
715 v = (long)STRLEN(line);
716 if (v < SPWORDLEN)
717 {
718 // Short line, use it completely and append the start of the
719 // next line.
720 nextlinecol = 0;
721 mch_memmove(nextline, line, (size_t)v);
722 STRMOVE(nextline + v, nextline + SPWORDLEN);
723 nextline_idx = v + 1;
724 }
725 else
726 {
727 // Long line, use only the last SPWORDLEN bytes.
728 nextlinecol = v - SPWORDLEN;
729 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
730 nextline_idx = SPWORDLEN + 1;
731 }
732 }
733 }
734#endif
735
736 if (wp->w_p_list)
737 {
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100738 if (lcs_space || lcs_trail || lcs_lead || lcs_nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200739 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100740
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200741 // find start of trailing whitespace
742 if (lcs_trail)
743 {
744 trailcol = (colnr_T)STRLEN(ptr);
745 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
746 --trailcol;
747 trailcol += (colnr_T) (ptr - line);
748 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100749 // find end of leading whitespace
750 if (lcs_lead)
751 {
752 leadcol = 0;
753 while (VIM_ISWHITE(ptr[leadcol]))
754 ++leadcol;
755 if (ptr[leadcol] == NUL)
756 // in a line full of spaces all of them are treated as trailing
757 leadcol = (colnr_T)0;
758 else
759 // keep track of the first column not filled with spaces
760 leadcol += (colnr_T) (ptr - line) + 1;
761 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200762 }
763
764 wcr_attr = get_wcr_attr(wp);
765 if (wcr_attr != 0)
766 {
767 win_attr = wcr_attr;
768 area_highlighting = TRUE;
769 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200770
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100771#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772 if (WIN_IS_POPUP(wp))
773 screen_line_flags |= SLF_POPUP;
774#endif
775
776 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
777 // first character to be displayed.
778 if (wp->w_p_wrap)
779 v = wp->w_skipcol;
780 else
781 v = wp->w_leftcol;
782 if (v > 0 && !number_only)
783 {
784 char_u *prev_ptr = ptr;
785
786 while (vcol < v && *ptr != NUL)
787 {
788 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
789 vcol += c;
790 prev_ptr = ptr;
791 MB_PTR_ADV(ptr);
792 }
793
794 // When:
795 // - 'cuc' is set, or
796 // - 'colorcolumn' is set, or
797 // - 'virtualedit' is set, or
798 // - the visual mode is active,
799 // the end of the line may be before the start of the displayed part.
800 if (vcol < v && (
801#ifdef FEAT_SYN_HL
802 wp->w_p_cuc || draw_color_col ||
803#endif
804 virtual_active() ||
805 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
806 vcol = v;
807
808 // Handle a character that's not completely on the screen: Put ptr at
809 // that character but skip the first few screen characters.
810 if (vcol > v)
811 {
812 vcol -= c;
813 ptr = prev_ptr;
814 // If the character fits on the screen, don't need to skip it.
815 // Except for a TAB.
816 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
817 n_skip = v - vcol;
818 }
819
820 // Adjust for when the inverted text is before the screen,
821 // and when the start of the inverted text is before the screen.
822 if (tocol <= vcol)
823 fromcol = 0;
824 else if (fromcol >= 0 && fromcol < vcol)
825 fromcol = vcol;
826
827#ifdef FEAT_LINEBREAK
828 // When w_skipcol is non-zero, first line needs 'showbreak'
829 if (wp->w_p_wrap)
830 need_showbreak = TRUE;
831#endif
832#ifdef FEAT_SPELL
833 // When spell checking a word we need to figure out the start of the
834 // word and if it's badly spelled or not.
835 if (has_spell)
836 {
837 int len;
838 colnr_T linecol = (colnr_T)(ptr - line);
839 hlf_T spell_hlf = HLF_COUNT;
840
841 pos = wp->w_cursor;
842 wp->w_cursor.lnum = lnum;
843 wp->w_cursor.col = linecol;
844 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
845
846 // spell_move_to() may call ml_get() and make "line" invalid
847 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
848 ptr = line + linecol;
849
850 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
851 {
852 // no bad word found at line start, don't check until end of a
853 // word
854 spell_hlf = HLF_COUNT;
855 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
856 }
857 else
858 {
859 // bad word found, use attributes until end of word
860 word_end = wp->w_cursor.col + len + 1;
861
862 // Turn index into actual attributes.
863 if (spell_hlf != HLF_COUNT)
864 spell_attr = highlight_attr[spell_hlf];
865 }
866 wp->w_cursor = pos;
867
868# ifdef FEAT_SYN_HL
869 // Need to restart syntax highlighting for this line.
870 if (has_syntax)
871 syntax_start(wp, lnum);
872# endif
873 }
874#endif
875 }
876
877 // Correct highlighting for cursor that can't be disabled.
878 // Avoids having to check this for each character.
879 if (fromcol >= 0)
880 {
881 if (noinvcur)
882 {
883 if ((colnr_T)fromcol == wp->w_virtcol)
884 {
885 // highlighting starts at cursor, let it start just after the
886 // cursor
887 fromcol_prev = fromcol;
888 fromcol = -1;
889 }
890 else if ((colnr_T)fromcol < wp->w_virtcol)
891 // restart highlighting after the cursor
892 fromcol_prev = wp->w_virtcol;
893 }
894 if (fromcol >= tocol)
895 fromcol = -1;
896 }
897
898#ifdef FEAT_SEARCH_EXTRA
899 if (!number_only)
900 {
901 v = (long)(ptr - line);
902 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
903 &line, &screen_search_hl,
904 &search_attr);
905 ptr = line + v; // "line" may have been updated
906 }
907#endif
908
909#ifdef FEAT_SYN_HL
910 // Cursor line highlighting for 'cursorline' in the current window.
911 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
912 {
913 // Do not show the cursor line in the text when Visual mode is active,
914 // because it's not clear what is selected then. Do update
915 // w_last_cursorline.
916 if (!(wp == curwin && VIsual_active)
917 && wp->w_p_culopt_flags != CULOPT_NBR)
918 {
919 cul_screenline = (wp->w_p_wrap
920 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
921
922 // Only set line_attr here when "screenline" is not present in
923 // 'cursorlineopt'. Otherwise it's done later.
924 if (!cul_screenline)
925 {
926 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200927# ifdef FEAT_SIGNS
928 // Combine the 'cursorline' and sign highlighting, depending on
929 // the sign priority.
930 if (sign_present && sattr.sat_linehl > 0)
931 {
932 if (sattr.sat_priority >= 100)
933 line_attr = hl_combine_attr(cul_attr, line_attr);
934 else
935 line_attr = hl_combine_attr(line_attr, cul_attr);
936 }
937 else
938# endif
939 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200940 wp->w_last_cursorline = wp->w_cursor.lnum;
941 }
942 else
943 {
944 line_attr_save = line_attr;
945 wp->w_last_cursorline = 0;
946 margin_columns_win(wp, &left_curline_col, &right_curline_col);
947 }
948 area_highlighting = TRUE;
949 }
950 else
951 wp->w_last_cursorline = wp->w_cursor.lnum;
952 }
953#endif
954
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100955#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200956 {
957 char_u *prop_start;
958
959 text_prop_count = get_text_props(wp->w_buffer, lnum,
960 &prop_start, FALSE);
961 if (text_prop_count > 0)
962 {
963 // Make a copy of the properties, so that they are properly
964 // aligned.
965 text_props = ALLOC_MULT(textprop_T, text_prop_count);
966 if (text_props != NULL)
967 mch_memmove(text_props, prop_start,
968 text_prop_count * sizeof(textprop_T));
969
970 // Allocate an array for the indexes.
971 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
972 area_highlighting = TRUE;
973 extra_check = TRUE;
974 }
975 }
976#endif
977
978 off = (unsigned)(current_ScreenLine - ScreenLines);
979 col = 0;
980
981#ifdef FEAT_RIGHTLEFT
982 if (wp->w_p_rl)
983 {
984 // Rightleft window: process the text in the normal direction, but put
985 // it in current_ScreenLine[] from right to left. Start at the
986 // rightmost column of the window.
987 col = wp->w_width - 1;
988 off += col;
989 screen_line_flags |= SLF_RIGHTLEFT;
990 }
991#endif
992
993 // Repeat for the whole displayed line.
994 for (;;)
995 {
996#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +0200997 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200998#endif
999#ifdef FEAT_CONCEAL
1000 int did_decrement_ptr = FALSE;
1001#endif
1002 // Skip this quickly when working on the text.
1003 if (draw_state != WL_LINE)
1004 {
1005#ifdef FEAT_CMDWIN
1006 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1007 {
1008 draw_state = WL_CMDLINE;
1009 if (cmdwin_type != 0 && wp == curwin)
1010 {
1011 // Draw the cmdline character.
1012 n_extra = 1;
1013 c_extra = cmdwin_type;
1014 c_final = NUL;
1015 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1016 }
1017 }
1018#endif
1019
1020#ifdef FEAT_FOLDING
1021 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1022 {
1023 int fdc = compute_foldcolumn(wp, 0);
1024
1025 draw_state = WL_FOLD;
1026 if (fdc > 0)
1027 {
1028 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1029 // already be in use.
1030 vim_free(p_extra_free);
1031 p_extra_free = alloc(12 + 1);
1032
1033 if (p_extra_free != NULL)
1034 {
1035 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
1036 n_extra = fdc;
1037 p_extra_free[n_extra] = NUL;
1038 p_extra = p_extra_free;
1039 c_extra = NUL;
1040 c_final = NUL;
1041 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
1042 }
1043 }
1044 }
1045#endif
1046
1047#ifdef FEAT_SIGNS
1048 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1049 {
1050 draw_state = WL_SIGN;
1051 // Show the sign column when there are any signs in this
1052 // buffer or when using Netbeans.
1053 if (signcolumn_on(wp))
1054 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1055 row, startrow, filler_lines, filler_todo, &c_extra,
1056 &c_final, extra, &p_extra, &n_extra, &char_attr);
1057 }
1058#endif
1059
1060 if (draw_state == WL_NR - 1 && n_extra == 0)
1061 {
1062 draw_state = WL_NR;
1063 // Display the absolute or relative line number. After the
1064 // first fill with blanks when the 'n' flag isn't in 'cpo'
1065 if ((wp->w_p_nu || wp->w_p_rnu)
1066 && (row == startrow
1067#ifdef FEAT_DIFF
1068 + filler_lines
1069#endif
1070 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1071 {
1072#ifdef FEAT_SIGNS
1073 // If 'signcolumn' is set to 'number' and a sign is present
1074 // in 'lnum', then display the sign instead of the line
1075 // number.
1076 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1077 && sign_present)
1078 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1079 row, startrow, filler_lines, filler_todo,
1080 &c_extra, &c_final, extra, &p_extra, &n_extra,
1081 &char_attr);
1082 else
1083#endif
1084 {
1085 // Draw the line number (empty space after wrapping).
1086 if (row == startrow
1087#ifdef FEAT_DIFF
1088 + filler_lines
1089#endif
1090 )
1091 {
1092 long num;
1093 char *fmt = "%*ld ";
1094
1095 if (wp->w_p_nu && !wp->w_p_rnu)
1096 // 'number' + 'norelativenumber'
1097 num = (long)lnum;
1098 else
1099 {
1100 // 'relativenumber', don't use negative numbers
1101 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1102 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1103 {
1104 // 'number' + 'relativenumber'
1105 num = lnum;
1106 fmt = "%-*ld ";
1107 }
1108 }
1109
1110 sprintf((char *)extra, fmt,
1111 number_width(wp), num);
1112 if (wp->w_skipcol > 0)
1113 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1114 *p_extra = '-';
1115#ifdef FEAT_RIGHTLEFT
1116 if (wp->w_p_rl) // reverse line numbers
1117 {
1118 char_u *p1, *p2;
1119 int t;
1120
1121 // like rl_mirror(), but keep the space at the end
1122 p2 = skiptowhite(extra) - 1;
1123 for (p1 = extra; p1 < p2; ++p1, --p2)
1124 {
1125 t = *p1;
1126 *p1 = *p2;
1127 *p2 = t;
1128 }
1129 }
1130#endif
1131 p_extra = extra;
1132 c_extra = NUL;
1133 c_final = NUL;
1134 }
1135 else
1136 {
1137 c_extra = ' ';
1138 c_final = NUL;
1139 }
1140 n_extra = number_width(wp) + 1;
1141 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1142#ifdef FEAT_SYN_HL
1143 // When 'cursorline' is set highlight the line number of
1144 // the current line differently.
1145 // When 'cursorlineopt' has "screenline" only highlight
1146 // the line number itself.
1147 // TODO: Can we use CursorLine instead of CursorLineNr
1148 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001149 if (wp->w_p_cul
1150 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001151 && (wp->w_p_culopt_flags & CULOPT_NBR)
1152 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001153 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001154 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1155#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001156 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1157 && HL_ATTR(HLF_LNA) != 0)
1158 // Use LineNrAbove
1159 char_attr = hl_combine_attr(wcr_attr,
1160 HL_ATTR(HLF_LNA));
1161 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1162 && HL_ATTR(HLF_LNB) != 0)
1163 // Use LineNrBelow
1164 char_attr = hl_combine_attr(wcr_attr,
1165 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 }
1167 }
1168 }
1169
1170#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001171 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001172 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001173 // draw indent after showbreak value
1174 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001175 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001176 // After the showbreak, draw the breakindent
1177 draw_state = WL_BRI - 1;
1178
1179 // draw 'breakindent': indent wrapped text accordingly
1180 if (draw_state == WL_BRI - 1 && n_extra == 0)
1181 {
1182 draw_state = WL_BRI;
1183 // if need_showbreak is set, breakindent also applies
1184 if (wp->w_p_bri && n_extra == 0
1185 && (row != startrow || need_showbreak)
1186# ifdef FEAT_DIFF
1187 && filler_lines == 0
1188# endif
1189 )
1190 {
1191 char_attr = 0;
1192# ifdef FEAT_DIFF
1193 if (diff_hlf != (hlf_T)0)
1194 {
1195 char_attr = HL_ATTR(diff_hlf);
1196# ifdef FEAT_SYN_HL
1197 if (cul_attr != 0)
1198 char_attr = hl_combine_attr(char_attr, cul_attr);
1199# endif
1200 }
1201# endif
1202 p_extra = NULL;
1203 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001204 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205 n_extra = get_breakindent_win(wp,
1206 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001207 if (row == startrow)
1208 {
1209 n_extra -= win_col_off2(wp);
1210 if (n_extra < 0)
1211 n_extra = 0;
1212 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001213 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001214 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 // Correct end of highlighted area for 'breakindent',
1216 // required when 'linebreak' is also set.
1217 if (tocol == vcol)
1218 tocol += n_extra;
1219 }
1220 }
1221#endif
1222
1223#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1224 if (draw_state == WL_SBR - 1 && n_extra == 0)
1225 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001226 char_u *sbr;
1227
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001228 draw_state = WL_SBR;
1229# ifdef FEAT_DIFF
1230 if (filler_todo > 0)
1231 {
1232 // Draw "deleted" diff line(s).
1233 if (char2cells(fill_diff) > 1)
1234 {
1235 c_extra = '-';
1236 c_final = NUL;
1237 }
1238 else
1239 {
1240 c_extra = fill_diff;
1241 c_final = NUL;
1242 }
1243# ifdef FEAT_RIGHTLEFT
1244 if (wp->w_p_rl)
1245 n_extra = col + 1;
1246 else
1247# endif
1248 n_extra = wp->w_width - col;
1249 char_attr = HL_ATTR(HLF_DED);
1250 }
1251# endif
1252# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001253 sbr = get_showbreak_value(wp);
1254 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001255 {
1256 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001257 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258 c_extra = NUL;
1259 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001260 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001261 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1262 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001263 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 // Correct end of highlighted area for 'showbreak',
1265 // required when 'linebreak' is also set.
1266 if (tocol == vcol)
1267 tocol += n_extra;
1268 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001269 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270# ifdef FEAT_SYN_HL
1271 // combine 'showbreak' with 'cursorline'
1272 if (cul_attr != 0)
1273 char_attr = hl_combine_attr(char_attr, cul_attr);
1274# endif
1275 }
1276# endif
1277 }
1278#endif
1279
1280 if (draw_state == WL_LINE - 1 && n_extra == 0)
1281 {
1282 draw_state = WL_LINE;
1283 if (saved_n_extra)
1284 {
1285 // Continue item from end of wrapped line.
1286 n_extra = saved_n_extra;
1287 c_extra = saved_c_extra;
1288 c_final = saved_c_final;
1289 p_extra = saved_p_extra;
1290 char_attr = saved_char_attr;
1291 }
1292 else
1293 char_attr = win_attr;
1294 }
1295 }
1296#ifdef FEAT_SYN_HL
1297 if (cul_screenline)
1298 {
1299 if (draw_state == WL_LINE
1300 && vcol >= left_curline_col
1301 && vcol < right_curline_col)
1302 {
1303 cul_attr = HL_ATTR(HLF_CUL);
1304 line_attr = cul_attr;
1305 }
1306 else
1307 {
1308 cul_attr = 0;
1309 line_attr = line_attr_save;
1310 }
1311 }
1312#endif
1313
1314 // When still displaying '$' of change command, stop at cursor.
1315 // When only displaying the (relative) line number and that's done,
1316 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001317 if (((dollar_vcol >= 0 && wp == curwin
1318 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1319 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001320#ifdef FEAT_DIFF
1321 && filler_todo <= 0
1322#endif
1323 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001324 {
1325 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1326 screen_line_flags);
1327 // Pretend we have finished updating the window. Except when
1328 // 'cursorcolumn' is set.
1329#ifdef FEAT_SYN_HL
1330 if (wp->w_p_cuc)
1331 row = wp->w_cline_row + wp->w_cline_height;
1332 else
1333#endif
1334 row = wp->w_height;
1335 break;
1336 }
1337
Bram Moolenaar34390282019-10-16 14:38:26 +02001338 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 {
1340 // handle Visual or match highlighting in this line
1341 if (vcol == fromcol
1342 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1343 && (*mb_ptr2cells)(ptr) > 1)
1344 || ((int)vcol_prev == fromcol_prev
1345 && vcol_prev < vcol // not at margin
1346 && vcol < tocol))
1347 area_attr = vi_attr; // start highlighting
1348 else if (area_attr != 0
1349 && (vcol == tocol
1350 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1351 area_attr = 0; // stop highlighting
1352
1353#ifdef FEAT_SEARCH_EXTRA
1354 if (!n_extra)
1355 {
1356 // Check for start/end of 'hlsearch' and other matches.
1357 // After end, check for start/end of next match.
1358 // When another match, have to check for start again.
1359 v = (long)(ptr - line);
1360 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1361 &screen_search_hl, &has_match_conc,
1362 &match_conc, did_line_attr, lcs_eol_one);
1363 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001364
1365 // Do not allow a conceal over EOL otherwise EOL will be missed
1366 // and bad things happen.
1367 if (*ptr == NUL)
1368 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001369 }
1370#endif
1371
1372#ifdef FEAT_DIFF
1373 if (diff_hlf != (hlf_T)0)
1374 {
1375 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1376 && n_extra == 0)
1377 diff_hlf = HLF_TXD; // changed text
1378 if (diff_hlf == HLF_TXD && ptr - line > change_end
1379 && n_extra == 0)
1380 diff_hlf = HLF_CHD; // changed line
1381 line_attr = HL_ATTR(diff_hlf);
1382 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1383 && wp->w_p_culopt_flags != CULOPT_NBR
1384 && (!cul_screenline || (vcol >= left_curline_col
1385 && vcol <= right_curline_col)))
1386 line_attr = hl_combine_attr(
1387 line_attr, HL_ATTR(HLF_CUL));
1388 }
1389#endif
1390
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001391#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 if (text_props != NULL)
1393 {
1394 int pi;
1395 int bcol = (int)(ptr - line);
1396
1397 if (n_extra > 0)
1398 --bcol; // still working on the previous char, e.g. Tab
1399
1400 // Check if any active property ends.
1401 for (pi = 0; pi < text_props_active; ++pi)
1402 {
1403 int tpi = text_prop_idxs[pi];
1404
1405 if (bcol >= text_props[tpi].tp_col - 1
1406 + text_props[tpi].tp_len)
1407 {
1408 if (pi + 1 < text_props_active)
1409 mch_memmove(text_prop_idxs + pi,
1410 text_prop_idxs + pi + 1,
1411 sizeof(int)
1412 * (text_props_active - (pi + 1)));
1413 --text_props_active;
1414 --pi;
1415 }
1416 }
1417
1418 // Add any text property that starts in this column.
1419 while (text_prop_next < text_prop_count
1420 && bcol >= text_props[text_prop_next].tp_col - 1)
1421 text_prop_idxs[text_props_active++] = text_prop_next++;
1422
1423 text_prop_attr = 0;
1424 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001425 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 if (text_props_active > 0)
1427 {
1428 // Sort the properties on priority and/or starting last.
1429 // Then combine the attributes, highest priority last.
1430 current_text_props = text_props;
1431 current_buf = wp->w_buffer;
1432 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1433 sizeof(int), text_prop_compare);
1434
1435 for (pi = 0; pi < text_props_active; ++pi)
1436 {
1437 int tpi = text_prop_idxs[pi];
1438 proptype_T *pt = text_prop_type_by_id(
1439 wp->w_buffer, text_props[tpi].tp_type);
1440
1441 if (pt != NULL && pt->pt_hl_id > 0)
1442 {
1443 int pt_attr = syn_id2attr(pt->pt_hl_id);
1444
1445 text_prop_type = pt;
1446 text_prop_attr =
1447 hl_combine_attr(text_prop_attr, pt_attr);
1448 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1449 }
1450 }
1451 }
1452 }
1453#endif
1454
Bram Moolenaara74fda62019-10-19 17:38:03 +02001455#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001456 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001457 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001458 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001459# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001460 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001461 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001462# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001463 // Get syntax attribute.
1464 if (has_syntax)
1465 {
1466 // Get the syntax attribute for the character. If there
1467 // is an error, disable syntax highlighting.
1468 save_did_emsg = did_emsg;
1469 did_emsg = FALSE;
1470
1471 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001472 if (v == prev_syntax_col)
1473 // at same column again
1474 syntax_attr = prev_syntax_attr;
1475 else
1476 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001477# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001478 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001479# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001480 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001481# ifdef FEAT_SPELL
1482 has_spell ? &can_spell :
1483# endif
1484 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001485 prev_syntax_col = v;
1486 prev_syntax_attr = syntax_attr;
1487 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001488
Bram Moolenaar34390282019-10-16 14:38:26 +02001489 if (did_emsg)
1490 {
1491 wp->w_s->b_syn_error = TRUE;
1492 has_syntax = FALSE;
1493 syntax_attr = 0;
1494 }
1495 else
1496 did_emsg = save_did_emsg;
1497# ifdef SYN_TIME_LIMIT
1498 if (wp->w_s->b_syn_slow)
1499 has_syntax = FALSE;
1500# endif
1501
1502 // Need to get the line again, a multi-line regexp may
1503 // have made it invalid.
1504 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1505 ptr = line + v;
1506# ifdef FEAT_CONCEAL
1507 // no concealing past the end of the line, it interferes
1508 // with line highlighting
1509 if (*ptr == NUL)
1510 syntax_flags = 0;
1511 else
1512 syntax_flags = get_syntax_info(&syntax_seqnr);
1513# endif
1514 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001515 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001516# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001517 // Combine text property highlight into syntax highlight.
1518 if (text_prop_type != NULL)
1519 {
1520 if (text_prop_combine)
1521 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1522 else
1523 syntax_attr = text_prop_attr;
1524 }
1525# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001526#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001527
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528 // Decide which of the highlight attributes to use.
1529 attr_pri = TRUE;
1530#ifdef LINE_ATTR
1531 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001532 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001534# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001535 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001536# endif
1537 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001538 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001539 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001540 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001541# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001542 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001543# endif
1544 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001545 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1546 || vcol < fromcol || vcol_prev < fromcol_prev
1547 || vcol >= tocol))
1548 {
1549 // Use line_attr when not in the Visual or 'incsearch' area
1550 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001551# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001552 char_attr = hl_combine_attr(syntax_attr, line_attr);
1553# else
1554 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001555# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001556 attr_pri = FALSE;
1557 }
1558#else
1559 if (area_attr != 0)
1560 char_attr = area_attr;
1561 else if (search_attr != 0)
1562 char_attr = search_attr;
1563#endif
1564 else
1565 {
1566 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001567#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001568 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001569#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001570 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001571#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001572 }
1573 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001574
1575 // combine attribute with 'wincolor'
1576 if (win_attr != 0)
1577 {
1578 if (char_attr == 0)
1579 char_attr = win_attr;
1580 else
1581 char_attr = hl_combine_attr(win_attr, char_attr);
1582 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583
1584 // Get the next character to put on the screen.
1585
1586 // The "p_extra" points to the extra stuff that is inserted to
1587 // represent special characters (non-printable stuff) and other
1588 // things. When all characters are the same, c_extra is used.
1589 // If c_final is set, it will compulsorily be used at the end.
1590 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1591 // "p_extra[n_extra]".
1592 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1593 if (n_extra > 0)
1594 {
1595 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1596 {
1597 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1598 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1599 if (enc_utf8 && utf_char2len(c) > 1)
1600 {
1601 mb_utf8 = TRUE;
1602 u8cc[0] = 0;
1603 c = 0xc0;
1604 }
1605 else
1606 mb_utf8 = FALSE;
1607 }
1608 else
1609 {
1610 c = *p_extra;
1611 if (has_mbyte)
1612 {
1613 mb_c = c;
1614 if (enc_utf8)
1615 {
1616 // If the UTF-8 character is more than one byte:
1617 // Decode it into "mb_c".
1618 mb_l = utfc_ptr2len(p_extra);
1619 mb_utf8 = FALSE;
1620 if (mb_l > n_extra)
1621 mb_l = 1;
1622 else if (mb_l > 1)
1623 {
1624 mb_c = utfc_ptr2char(p_extra, u8cc);
1625 mb_utf8 = TRUE;
1626 c = 0xc0;
1627 }
1628 }
1629 else
1630 {
1631 // if this is a DBCS character, put it in "mb_c"
1632 mb_l = MB_BYTE2LEN(c);
1633 if (mb_l >= n_extra)
1634 mb_l = 1;
1635 else if (mb_l > 1)
1636 mb_c = (c << 8) + p_extra[1];
1637 }
1638 if (mb_l == 0) // at the NUL at end-of-line
1639 mb_l = 1;
1640
1641 // If a double-width char doesn't fit display a '>' in the
1642 // last column.
1643 if ((
1644# ifdef FEAT_RIGHTLEFT
1645 wp->w_p_rl ? (col <= 0) :
1646# endif
1647 (col >= wp->w_width - 1))
1648 && (*mb_char2cells)(mb_c) == 2)
1649 {
1650 c = '>';
1651 mb_c = c;
1652 mb_l = 1;
1653 mb_utf8 = FALSE;
1654 multi_attr = HL_ATTR(HLF_AT);
1655#ifdef FEAT_SYN_HL
1656 if (cul_attr)
1657 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1658#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001659 multi_attr = hl_combine_attr(win_attr, multi_attr);
1660
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001661 // put the pointer back to output the double-width
1662 // character at the start of the next line.
1663 ++n_extra;
1664 --p_extra;
1665 }
1666 else
1667 {
1668 n_extra -= mb_l - 1;
1669 p_extra += mb_l - 1;
1670 }
1671 }
1672 ++p_extra;
1673 }
1674 --n_extra;
1675 }
1676 else
1677 {
1678#ifdef FEAT_LINEBREAK
1679 int c0;
1680#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001681 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001682
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001683 // Get a character from the line itself.
1684 c = *ptr;
1685#ifdef FEAT_LINEBREAK
1686 c0 = *ptr;
1687#endif
1688 if (has_mbyte)
1689 {
1690 mb_c = c;
1691 if (enc_utf8)
1692 {
1693 // If the UTF-8 character is more than one byte: Decode it
1694 // into "mb_c".
1695 mb_l = utfc_ptr2len(ptr);
1696 mb_utf8 = FALSE;
1697 if (mb_l > 1)
1698 {
1699 mb_c = utfc_ptr2char(ptr, u8cc);
1700 // Overlong encoded ASCII or ASCII with composing char
1701 // is displayed normally, except a NUL.
1702 if (mb_c < 0x80)
1703 {
1704 c = mb_c;
1705#ifdef FEAT_LINEBREAK
1706 c0 = mb_c;
1707#endif
1708 }
1709 mb_utf8 = TRUE;
1710
1711 // At start of the line we can have a composing char.
1712 // Draw it as a space with a composing char.
1713 if (utf_iscomposing(mb_c))
1714 {
1715 int i;
1716
1717 for (i = Screen_mco - 1; i > 0; --i)
1718 u8cc[i] = u8cc[i - 1];
1719 u8cc[0] = mb_c;
1720 mb_c = ' ';
1721 }
1722 }
1723
1724 if ((mb_l == 1 && c >= 0x80)
1725 || (mb_l >= 1 && mb_c == 0)
1726 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1727 {
1728 // Illegal UTF-8 byte: display as <xx>.
1729 // Non-BMP character : display as ? or fullwidth ?.
1730 transchar_hex(extra, mb_c);
1731# ifdef FEAT_RIGHTLEFT
1732 if (wp->w_p_rl) // reverse
1733 rl_mirror(extra);
1734# endif
1735 p_extra = extra;
1736 c = *p_extra;
1737 mb_c = mb_ptr2char_adv(&p_extra);
1738 mb_utf8 = (c >= 0x80);
1739 n_extra = (int)STRLEN(p_extra);
1740 c_extra = NUL;
1741 c_final = NUL;
1742 if (area_attr == 0 && search_attr == 0)
1743 {
1744 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001745 extra_attr = hl_combine_attr(
1746 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 saved_attr2 = char_attr; // save current attr
1748 }
1749 }
1750 else if (mb_l == 0) // at the NUL at end-of-line
1751 mb_l = 1;
1752#ifdef FEAT_ARABIC
1753 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1754 {
1755 // Do Arabic shaping.
1756 int pc, pc1, nc;
1757 int pcc[MAX_MCO];
1758
1759 // The idea of what is the previous and next
1760 // character depends on 'rightleft'.
1761 if (wp->w_p_rl)
1762 {
1763 pc = prev_c;
1764 pc1 = prev_c1;
1765 nc = utf_ptr2char(ptr + mb_l);
1766 prev_c1 = u8cc[0];
1767 }
1768 else
1769 {
1770 pc = utfc_ptr2char(ptr + mb_l, pcc);
1771 nc = prev_c;
1772 pc1 = pcc[0];
1773 }
1774 prev_c = mb_c;
1775
1776 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1777 }
1778 else
1779 prev_c = mb_c;
1780#endif
1781 }
1782 else // enc_dbcs
1783 {
1784 mb_l = MB_BYTE2LEN(c);
1785 if (mb_l == 0) // at the NUL at end-of-line
1786 mb_l = 1;
1787 else if (mb_l > 1)
1788 {
1789 // We assume a second byte below 32 is illegal.
1790 // Hopefully this is OK for all double-byte encodings!
1791 if (ptr[1] >= 32)
1792 mb_c = (c << 8) + ptr[1];
1793 else
1794 {
1795 if (ptr[1] == NUL)
1796 {
1797 // head byte at end of line
1798 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001799 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001800 }
1801 else
1802 {
1803 // illegal tail byte
1804 mb_l = 2;
1805 STRCPY(extra, "XX");
1806 }
1807 p_extra = extra;
1808 n_extra = (int)STRLEN(extra) - 1;
1809 c_extra = NUL;
1810 c_final = NUL;
1811 c = *p_extra++;
1812 if (area_attr == 0 && search_attr == 0)
1813 {
1814 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001815 extra_attr = hl_combine_attr(
1816 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001817 saved_attr2 = char_attr; // save current attr
1818 }
1819 mb_c = c;
1820 }
1821 }
1822 }
1823 // If a double-width char doesn't fit display a '>' in the
1824 // last column; the character is displayed at the start of the
1825 // next line.
1826 if ((
1827# ifdef FEAT_RIGHTLEFT
1828 wp->w_p_rl ? (col <= 0) :
1829# endif
1830 (col >= wp->w_width - 1))
1831 && (*mb_char2cells)(mb_c) == 2)
1832 {
1833 c = '>';
1834 mb_c = c;
1835 mb_utf8 = FALSE;
1836 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001837 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001838 // Put pointer back so that the character will be
1839 // displayed at the start of the next line.
1840 --ptr;
1841#ifdef FEAT_CONCEAL
1842 did_decrement_ptr = TRUE;
1843#endif
1844 }
1845 else if (*ptr != NUL)
1846 ptr += mb_l - 1;
1847
1848 // If a double-width char doesn't fit at the left side display
1849 // a '<' in the first column. Don't do this for unprintable
1850 // characters.
1851 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1852 {
1853 n_extra = 1;
1854 c_extra = MB_FILLER_CHAR;
1855 c_final = NUL;
1856 c = ' ';
1857 if (area_attr == 0 && search_attr == 0)
1858 {
1859 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001860 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001861 saved_attr2 = char_attr; // save current attr
1862 }
1863 mb_c = c;
1864 mb_utf8 = FALSE;
1865 mb_l = 1;
1866 }
1867
1868 }
1869 ++ptr;
1870
1871 if (extra_check)
1872 {
1873#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001874 // Check spelling (unless at the end of the line).
1875 // Only do this when there is no syntax highlighting, the
1876 // @Spell cluster is not used or the current syntax item
1877 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001878 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 if (has_spell && v >= word_end && v > cur_checked_col)
1880 {
1881 spell_attr = 0;
1882 if (c != 0 && (
1883# ifdef FEAT_SYN_HL
1884 !has_syntax ||
1885# endif
1886 can_spell))
1887 {
1888 char_u *prev_ptr, *p;
1889 int len;
1890 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001891
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 if (has_mbyte)
1893 {
1894 prev_ptr = ptr - mb_l;
1895 v -= mb_l - 1;
1896 }
1897 else
1898 prev_ptr = ptr - 1;
1899
1900 // Use nextline[] if possible, it has the start of the
1901 // next line concatenated.
1902 if ((prev_ptr - line) - nextlinecol >= 0)
1903 p = nextline + (prev_ptr - line) - nextlinecol;
1904 else
1905 p = prev_ptr;
1906 cap_col -= (int)(prev_ptr - line);
1907 len = spell_check(wp, p, &spell_hlf, &cap_col,
1908 nochange);
1909 word_end = v + len;
1910
1911 // In Insert mode only highlight a word that
1912 // doesn't touch the cursor.
1913 if (spell_hlf != HLF_COUNT
1914 && (State & INSERT) != 0
1915 && wp->w_cursor.lnum == lnum
1916 && wp->w_cursor.col >=
1917 (colnr_T)(prev_ptr - line)
1918 && wp->w_cursor.col < (colnr_T)word_end)
1919 {
1920 spell_hlf = HLF_COUNT;
1921 spell_redraw_lnum = lnum;
1922 }
1923
1924 if (spell_hlf == HLF_COUNT && p != prev_ptr
1925 && (p - nextline) + len > nextline_idx)
1926 {
1927 // Remember that the good word continues at the
1928 // start of the next line.
1929 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001930 checked_col = (int)((p - nextline)
1931 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 }
1933
1934 // Turn index into actual attributes.
1935 if (spell_hlf != HLF_COUNT)
1936 spell_attr = highlight_attr[spell_hlf];
1937
1938 if (cap_col > 0)
1939 {
1940 if (p != prev_ptr
1941 && (p - nextline) + cap_col >= nextline_idx)
1942 {
1943 // Remember that the word in the next line
1944 // must start with a capital.
1945 capcol_lnum = lnum + 1;
1946 cap_col = (int)((p - nextline) + cap_col
1947 - nextline_idx);
1948 }
1949 else
1950 // Compute the actual column.
1951 cap_col += (int)(prev_ptr - line);
1952 }
1953 }
1954 }
1955 if (spell_attr != 0)
1956 {
1957 if (!attr_pri)
1958 char_attr = hl_combine_attr(char_attr, spell_attr);
1959 else
1960 char_attr = hl_combine_attr(spell_attr, char_attr);
1961 }
1962#endif
1963#ifdef FEAT_LINEBREAK
1964 // Found last space before word: check for line break.
1965 if (wp->w_p_lbr && c0 == c
1966 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1967 {
1968 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1969 char_u *p = ptr - (mb_off + 1);
1970
1971 // TODO: is passing p for start of the line OK?
1972 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1973 NULL) - 1;
1974 if (c == TAB && n_extra + col > wp->w_width)
1975# ifdef FEAT_VARTABS
1976 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1977 wp->w_buffer->b_p_vts_array) - 1;
1978# else
1979 n_extra = (int)wp->w_buffer->b_p_ts
1980 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1981# endif
1982
1983 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1984 c_final = NUL;
1985 if (VIM_ISWHITE(c))
1986 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001987# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988 if (c == TAB)
1989 // See "Tab alignment" below.
1990 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001991# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 if (!wp->w_p_list)
1993 c = ' ';
1994 }
1995 }
1996#endif
1997
1998 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
1999 // But not when the character is followed by a composing
2000 // character (use mb_l to check that).
2001 if (wp->w_p_list
2002 && ((((c == 160 && mb_l == 1)
2003 || (mb_utf8
2004 && ((mb_c == 160 && mb_l == 2)
2005 || (mb_c == 0x202f && mb_l == 3))))
2006 && lcs_nbsp)
2007 || (c == ' '
2008 && mb_l == 1
2009 && lcs_space
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002010 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011 && ptr - line <= trailcol)))
2012 {
2013 c = (c == ' ') ? lcs_space : lcs_nbsp;
2014 if (area_attr == 0 && search_attr == 0)
2015 {
2016 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002017 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002018 saved_attr2 = char_attr; // save current attr
2019 }
2020 mb_c = c;
2021 if (enc_utf8 && utf_char2len(c) > 1)
2022 {
2023 mb_utf8 = TRUE;
2024 u8cc[0] = 0;
2025 c = 0xc0;
2026 }
2027 else
2028 mb_utf8 = FALSE;
2029 }
2030
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002031 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2032 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 {
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002034 c = (ptr > line + trailcol) ? lcs_trail : lcs_lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 if (!attr_pri)
2036 {
2037 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002038 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 saved_attr2 = char_attr; // save current attr
2040 }
2041 mb_c = c;
2042 if (enc_utf8 && utf_char2len(c) > 1)
2043 {
2044 mb_utf8 = TRUE;
2045 u8cc[0] = 0;
2046 c = 0xc0;
2047 }
2048 else
2049 mb_utf8 = FALSE;
2050 }
2051 }
2052
2053 // Handling of non-printable characters.
2054 if (!vim_isprintc(c))
2055 {
2056 // when getting a character from the file, we may have to
2057 // turn it into something else on the way to putting it
2058 // into "ScreenLines".
2059 if (c == TAB && (!wp->w_p_list || lcs_tab1))
2060 {
2061 int tab_len = 0;
2062 long vcol_adjusted = vcol; // removed showbreak length
2063#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002064 char_u *sbr = get_showbreak_value(wp);
2065
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 // only adjust the tab_len, when at the first column
2067 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002068 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2069 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070#endif
2071 // tab amount depends on current column
2072#ifdef FEAT_VARTABS
2073 tab_len = tabstop_padding(vcol_adjusted,
2074 wp->w_buffer->b_p_ts,
2075 wp->w_buffer->b_p_vts_array) - 1;
2076#else
2077 tab_len = (int)wp->w_buffer->b_p_ts
2078 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2079#endif
2080
2081#ifdef FEAT_LINEBREAK
2082 if (!wp->w_p_lbr || !wp->w_p_list)
2083#endif
2084 // tab amount depends on current column
2085 n_extra = tab_len;
2086#ifdef FEAT_LINEBREAK
2087 else
2088 {
2089 char_u *p;
2090 int len;
2091 int i;
2092 int saved_nextra = n_extra;
2093
2094#ifdef FEAT_CONCEAL
2095 if (vcol_off > 0)
2096 // there are characters to conceal
2097 tab_len += vcol_off;
2098 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2099 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2100 && n_extra > tab_len)
2101 tab_len += n_extra - tab_len;
2102#endif
2103
2104 // if n_extra > 0, it gives the number of chars, to
2105 // use for a tab, else we need to calculate the width
2106 // for a tab
2107 len = (tab_len * mb_char2len(lcs_tab2));
2108 if (n_extra > 0)
2109 len += n_extra - tab_len;
2110 c = lcs_tab1;
2111 p = alloc(len + 1);
2112 vim_memset(p, ' ', len);
2113 p[len] = NUL;
2114 vim_free(p_extra_free);
2115 p_extra_free = p;
2116 for (i = 0; i < tab_len; i++)
2117 {
2118 int lcs = lcs_tab2;
2119
2120 if (*p == NUL)
2121 {
2122 tab_len = i;
2123 break;
2124 }
2125
2126 // if lcs_tab3 is given, need to change the char
2127 // for tab
2128 if (lcs_tab3 && i == tab_len - 1)
2129 lcs = lcs_tab3;
2130 mb_char2bytes(lcs, p);
2131 p += mb_char2len(lcs);
2132 n_extra += mb_char2len(lcs)
2133 - (saved_nextra > 0 ? 1 : 0);
2134 }
2135 p_extra = p_extra_free;
2136#ifdef FEAT_CONCEAL
2137 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2138 // macro below, so need to adjust for that here
2139 if (vcol_off > 0)
2140 n_extra -= vcol_off;
2141#endif
2142 }
2143#endif
2144#ifdef FEAT_CONCEAL
2145 {
2146 int vc_saved = vcol_off;
2147
2148 // Tab alignment should be identical regardless of
2149 // 'conceallevel' value. So tab compensates of all
2150 // previous concealed characters, and thus resets
2151 // vcol_off and boguscols accumulated so far in the
2152 // line. Note that the tab can be longer than
2153 // 'tabstop' when there are concealed characters.
2154 FIX_FOR_BOGUSCOLS;
2155
2156 // Make sure, the highlighting for the tab char will be
2157 // correctly set further below (effectively reverts the
2158 // FIX_FOR_BOGSUCOLS macro
2159 if (n_extra == tab_len + vc_saved && wp->w_p_list
2160 && lcs_tab1)
2161 tab_len += vc_saved;
2162 }
2163#endif
2164 mb_utf8 = FALSE; // don't draw as UTF-8
2165 if (wp->w_p_list)
2166 {
2167 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2168#ifdef FEAT_LINEBREAK
2169 if (wp->w_p_lbr)
2170 c_extra = NUL; // using p_extra from above
2171 else
2172#endif
2173 c_extra = lcs_tab2;
2174 c_final = lcs_tab3;
2175 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002176 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002177 saved_attr2 = char_attr; // save current attr
2178 mb_c = c;
2179 if (enc_utf8 && utf_char2len(c) > 1)
2180 {
2181 mb_utf8 = TRUE;
2182 u8cc[0] = 0;
2183 c = 0xc0;
2184 }
2185 }
2186 else
2187 {
2188 c_final = NUL;
2189 c_extra = ' ';
2190 c = ' ';
2191 }
2192 }
2193 else if (c == NUL
2194 && (wp->w_p_list
2195 || ((fromcol >= 0 || fromcol_prev >= 0)
2196 && tocol > vcol
2197 && VIsual_mode != Ctrl_V
2198 && (
2199# ifdef FEAT_RIGHTLEFT
2200 wp->w_p_rl ? (col >= 0) :
2201# endif
2202 (col < wp->w_width))
2203 && !(noinvcur
2204 && lnum == wp->w_cursor.lnum
2205 && (colnr_T)vcol == wp->w_virtcol)))
2206 && lcs_eol_one > 0)
2207 {
2208 // Display a '$' after the line or highlight an extra
2209 // character if the line break is included.
2210#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2211 // For a diff line the highlighting continues after the
2212 // "$".
2213 if (
2214# ifdef FEAT_DIFF
2215 diff_hlf == (hlf_T)0
2216# ifdef LINE_ATTR
2217 &&
2218# endif
2219# endif
2220# ifdef LINE_ATTR
2221 line_attr == 0
2222# endif
2223 )
2224#endif
2225 {
2226 // In virtualedit, visual selections may extend
2227 // beyond end of line.
2228 if (area_highlighting && virtual_active()
2229 && tocol != MAXCOL && vcol < tocol)
2230 n_extra = 0;
2231 else
2232 {
2233 p_extra = at_end_str;
2234 n_extra = 1;
2235 c_extra = NUL;
2236 c_final = NUL;
2237 }
2238 }
2239 if (wp->w_p_list && lcs_eol > 0)
2240 c = lcs_eol;
2241 else
2242 c = ' ';
2243 lcs_eol_one = -1;
2244 --ptr; // put it back at the NUL
2245 if (!attr_pri)
2246 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002247 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002248 n_attr = 1;
2249 }
2250 mb_c = c;
2251 if (enc_utf8 && utf_char2len(c) > 1)
2252 {
2253 mb_utf8 = TRUE;
2254 u8cc[0] = 0;
2255 c = 0xc0;
2256 }
2257 else
2258 mb_utf8 = FALSE; // don't draw as UTF-8
2259 }
2260 else if (c != NUL)
2261 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002262 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002263 if (n_extra == 0)
2264 n_extra = byte2cells(c) - 1;
2265#ifdef FEAT_RIGHTLEFT
2266 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2267 rl_mirror(p_extra); // reverse "<12>"
2268#endif
2269 c_extra = NUL;
2270 c_final = NUL;
2271#ifdef FEAT_LINEBREAK
2272 if (wp->w_p_lbr)
2273 {
2274 char_u *p;
2275
2276 c = *p_extra;
2277 p = alloc(n_extra + 1);
2278 vim_memset(p, ' ', n_extra);
2279 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2280 p[n_extra] = NUL;
2281 vim_free(p_extra_free);
2282 p_extra_free = p_extra = p;
2283 }
2284 else
2285#endif
2286 {
2287 n_extra = byte2cells(c) - 1;
2288 c = *p_extra++;
2289 }
2290 if (!attr_pri)
2291 {
2292 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002293 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002294 saved_attr2 = char_attr; // save current attr
2295 }
2296 mb_utf8 = FALSE; // don't draw as UTF-8
2297 }
2298 else if (VIsual_active
2299 && (VIsual_mode == Ctrl_V
2300 || VIsual_mode == 'v')
2301 && virtual_active()
2302 && tocol != MAXCOL
2303 && vcol < tocol
2304 && (
2305#ifdef FEAT_RIGHTLEFT
2306 wp->w_p_rl ? (col >= 0) :
2307#endif
2308 (col < wp->w_width)))
2309 {
2310 c = ' ';
2311 --ptr; // put it back at the NUL
2312 }
2313#if defined(LINE_ATTR)
2314 else if ((
2315# ifdef FEAT_DIFF
2316 diff_hlf != (hlf_T)0 ||
2317# endif
2318# ifdef FEAT_TERMINAL
2319 win_attr != 0 ||
2320# endif
2321 line_attr != 0
2322 ) && (
2323# ifdef FEAT_RIGHTLEFT
2324 wp->w_p_rl ? (col >= 0) :
2325# endif
2326 (col
2327# ifdef FEAT_CONCEAL
2328 - boguscols
2329# endif
2330 < wp->w_width)))
2331 {
2332 // Highlight until the right side of the window
2333 c = ' ';
2334 --ptr; // put it back at the NUL
2335
2336 // Remember we do the char for line highlighting.
2337 ++did_line_attr;
2338
2339 // don't do search HL for the rest of the line
2340 if (line_attr != 0 && char_attr == search_attr
2341 && (did_line_attr > 1
2342 || (wp->w_p_list && lcs_eol > 0)))
2343 char_attr = line_attr;
2344# ifdef FEAT_DIFF
2345 if (diff_hlf == HLF_TXD)
2346 {
2347 diff_hlf = HLF_CHD;
2348 if (vi_attr == 0 || char_attr != vi_attr)
2349 {
2350 char_attr = HL_ATTR(diff_hlf);
2351 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2352 && wp->w_p_culopt_flags != CULOPT_NBR
2353 && (!cul_screenline
2354 || (vcol >= left_curline_col
2355 && vcol <= right_curline_col)))
2356 char_attr = hl_combine_attr(
2357 char_attr, HL_ATTR(HLF_CUL));
2358 }
2359 }
2360# endif
2361# ifdef FEAT_TERMINAL
2362 if (win_attr != 0)
2363 {
2364 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002365 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2366 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002367 {
2368 if (!cul_screenline || (vcol >= left_curline_col
2369 && vcol <= right_curline_col))
2370 char_attr = hl_combine_attr(
2371 char_attr, HL_ATTR(HLF_CUL));
2372 }
2373 else if (line_attr)
2374 char_attr = hl_combine_attr(char_attr, line_attr);
2375 }
2376# endif
2377 }
2378#endif
2379 }
2380
2381#ifdef FEAT_CONCEAL
2382 if ( wp->w_p_cole > 0
2383 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2384 conceal_cursor_line(wp))
2385 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2386 && !(lnum_in_visual_area
2387 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2388 {
2389 char_attr = conceal_attr;
2390 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002391 && (syn_get_sub_char() != NUL
2392 || (has_match_conc && match_conc)
2393 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002394 && wp->w_p_cole != 3)
2395 {
2396 // First time at this concealed item: display one
2397 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002398 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002399 c = match_conc;
2400 else if (syn_get_sub_char() != NUL)
2401 c = syn_get_sub_char();
2402 else if (lcs_conceal != NUL)
2403 c = lcs_conceal;
2404 else
2405 c = ' ';
2406
2407 prev_syntax_id = syntax_seqnr;
2408
2409 if (n_extra > 0)
2410 vcol_off += n_extra;
2411 vcol += n_extra;
2412 if (wp->w_p_wrap && n_extra > 0)
2413 {
2414# ifdef FEAT_RIGHTLEFT
2415 if (wp->w_p_rl)
2416 {
2417 col -= n_extra;
2418 boguscols -= n_extra;
2419 }
2420 else
2421# endif
2422 {
2423 boguscols += n_extra;
2424 col += n_extra;
2425 }
2426 }
2427 n_extra = 0;
2428 n_attr = 0;
2429 }
2430 else if (n_skip == 0)
2431 {
2432 is_concealing = TRUE;
2433 n_skip = 1;
2434 }
2435 mb_c = c;
2436 if (enc_utf8 && utf_char2len(c) > 1)
2437 {
2438 mb_utf8 = TRUE;
2439 u8cc[0] = 0;
2440 c = 0xc0;
2441 }
2442 else
2443 mb_utf8 = FALSE; // don't draw as UTF-8
2444 }
2445 else
2446 {
2447 prev_syntax_id = 0;
2448 is_concealing = FALSE;
2449 }
2450
2451 if (n_skip > 0 && did_decrement_ptr)
2452 // not showing the '>', put pointer back to avoid getting stuck
2453 ++ptr;
2454
2455#endif // FEAT_CONCEAL
2456 }
2457
2458#ifdef FEAT_CONCEAL
2459 // In the cursor line and we may be concealing characters: correct
2460 // the cursor column when we reach its position.
2461 if (!did_wcol && draw_state == WL_LINE
2462 && wp == curwin && lnum == wp->w_cursor.lnum
2463 && conceal_cursor_line(wp)
2464 && (int)wp->w_virtcol <= vcol + n_skip)
2465 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002466# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002467 if (wp->w_p_rl)
2468 wp->w_wcol = wp->w_width - col + boguscols - 1;
2469 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002470# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002471 wp->w_wcol = col - boguscols;
2472 wp->w_wrow = row;
2473 did_wcol = TRUE;
2474 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002475# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002476 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002477# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002478 }
2479#endif
2480
2481 // Don't override visual selection highlighting.
2482 if (n_attr > 0
2483 && draw_state == WL_LINE
2484 && !attr_pri)
2485 {
2486#ifdef LINE_ATTR
2487 if (line_attr)
2488 char_attr = hl_combine_attr(extra_attr, line_attr);
2489 else
2490#endif
2491 char_attr = extra_attr;
2492 }
2493
2494#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2495 // XIM don't send preedit_start and preedit_end, but they send
2496 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2497 // im_is_preediting() here.
2498 if (p_imst == IM_ON_THE_SPOT
2499 && xic != NULL
2500 && lnum == wp->w_cursor.lnum
2501 && (State & INSERT)
2502 && !p_imdisable
2503 && im_is_preediting()
2504 && draw_state == WL_LINE)
2505 {
2506 colnr_T tcol;
2507
2508 if (preedit_end_col == MAXCOL)
2509 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2510 else
2511 tcol = preedit_end_col;
2512 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2513 {
2514 if (feedback_old_attr < 0)
2515 {
2516 feedback_col = 0;
2517 feedback_old_attr = char_attr;
2518 }
2519 char_attr = im_get_feedback_attr(feedback_col);
2520 if (char_attr < 0)
2521 char_attr = feedback_old_attr;
2522 feedback_col++;
2523 }
2524 else if (feedback_old_attr >= 0)
2525 {
2526 char_attr = feedback_old_attr;
2527 feedback_old_attr = -1;
2528 feedback_col = 0;
2529 }
2530 }
2531#endif
2532 // Handle the case where we are in column 0 but not on the first
2533 // character of the line and the user wants us to show us a
2534 // special character (via 'listchars' option "precedes:<char>".
2535 if (lcs_prec_todo != NUL
2536 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002537 && (wp->w_p_wrap ?
2538 (wp->w_skipcol > 0 && row == 0) :
2539 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002540#ifdef FEAT_DIFF
2541 && filler_todo <= 0
2542#endif
2543 && draw_state > WL_NR
2544 && c != NUL)
2545 {
2546 c = lcs_prec;
2547 lcs_prec_todo = NUL;
2548 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2549 {
2550 // Double-width character being overwritten by the "precedes"
2551 // character, need to fill up half the character.
2552 c_extra = MB_FILLER_CHAR;
2553 c_final = NUL;
2554 n_extra = 1;
2555 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002556 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 }
2558 mb_c = c;
2559 if (enc_utf8 && utf_char2len(c) > 1)
2560 {
2561 mb_utf8 = TRUE;
2562 u8cc[0] = 0;
2563 c = 0xc0;
2564 }
2565 else
2566 mb_utf8 = FALSE; // don't draw as UTF-8
2567 if (!attr_pri)
2568 {
2569 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002570 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002571 n_attr3 = 1;
2572 }
2573 }
2574
2575 // At end of the text line or just after the last character.
2576 if ((c == NUL
2577#if defined(LINE_ATTR)
2578 || did_line_attr == 1
2579#endif
2580 ) && eol_hl_off == 0)
2581 {
2582#ifdef FEAT_SEARCH_EXTRA
2583 // flag to indicate whether prevcol equals startcol of search_hl or
2584 // one of the matches
2585 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2586 (long)(ptr - line) - (c == NUL));
2587#endif
2588 // Invert at least one char, used for Visual and empty line or
2589 // highlight match at end of line. If it's beyond the last
2590 // char on the screen, just overwrite that one (tricky!) Not
2591 // needed when a '$' was displayed for 'list'.
2592 if (lcs_eol == lcs_eol_one
2593 && ((area_attr != 0 && vcol == fromcol
2594 && (VIsual_mode != Ctrl_V
2595 || lnum == VIsual.lnum
2596 || lnum == curwin->w_cursor.lnum)
2597 && c == NUL)
2598#ifdef FEAT_SEARCH_EXTRA
2599 // highlight 'hlsearch' match at end of line
2600 || (prevcol_hl_flag
2601# ifdef FEAT_SYN_HL
2602 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2603 && !(wp == curwin && VIsual_active))
2604# endif
2605# ifdef FEAT_DIFF
2606 && diff_hlf == (hlf_T)0
2607# endif
2608# if defined(LINE_ATTR)
2609 && did_line_attr <= 1
2610# endif
2611 )
2612#endif
2613 ))
2614 {
2615 int n = 0;
2616
2617#ifdef FEAT_RIGHTLEFT
2618 if (wp->w_p_rl)
2619 {
2620 if (col < 0)
2621 n = 1;
2622 }
2623 else
2624#endif
2625 {
2626 if (col >= wp->w_width)
2627 n = -1;
2628 }
2629 if (n != 0)
2630 {
2631 // At the window boundary, highlight the last character
2632 // instead (better than nothing).
2633 off += n;
2634 col += n;
2635 }
2636 else
2637 {
2638 // Add a blank character to highlight.
2639 ScreenLines[off] = ' ';
2640 if (enc_utf8)
2641 ScreenLinesUC[off] = 0;
2642 }
2643#ifdef FEAT_SEARCH_EXTRA
2644 if (area_attr == 0)
2645 {
2646 // Use attributes from match with highest priority among
2647 // 'search_hl' and the match list.
2648 get_search_match_hl(wp, &screen_search_hl,
2649 (long)(ptr - line), &char_attr);
2650 }
2651#endif
2652 ScreenAttrs[off] = char_attr;
2653#ifdef FEAT_RIGHTLEFT
2654 if (wp->w_p_rl)
2655 {
2656 --col;
2657 --off;
2658 }
2659 else
2660#endif
2661 {
2662 ++col;
2663 ++off;
2664 }
2665 ++vcol;
2666 eol_hl_off = 1;
2667 }
2668 }
2669
2670 // At end of the text line.
2671 if (c == NUL)
2672 {
2673#ifdef FEAT_SYN_HL
2674 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2675 if (wp->w_p_wrap)
2676 v = wp->w_skipcol;
2677 else
2678 v = wp->w_leftcol;
2679
2680 // check if line ends before left margin
2681 if (vcol < v + col - win_col_off(wp))
2682 vcol = v + col - win_col_off(wp);
2683#ifdef FEAT_CONCEAL
2684 // Get rid of the boguscols now, we want to draw until the right
2685 // edge for 'cursorcolumn'.
2686 col -= boguscols;
2687 boguscols = 0;
2688#endif
2689
2690 if (draw_color_col)
2691 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2692
2693 if (((wp->w_p_cuc
2694 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2695 && (int)wp->w_virtcol <
2696 wp->w_width * (row - startrow + 1) + v
2697 && lnum != wp->w_cursor.lnum)
2698 || draw_color_col
2699 || win_attr != 0)
2700# ifdef FEAT_RIGHTLEFT
2701 && !wp->w_p_rl
2702# endif
2703 )
2704 {
2705 int rightmost_vcol = 0;
2706 int i;
2707
2708 if (wp->w_p_cuc)
2709 rightmost_vcol = wp->w_virtcol;
2710 if (draw_color_col)
2711 // determine rightmost colorcolumn to possibly draw
2712 for (i = 0; color_cols[i] >= 0; ++i)
2713 if (rightmost_vcol < color_cols[i])
2714 rightmost_vcol = color_cols[i];
2715
2716 while (col < wp->w_width)
2717 {
2718 ScreenLines[off] = ' ';
2719 if (enc_utf8)
2720 ScreenLinesUC[off] = 0;
2721 ++col;
2722 if (draw_color_col)
2723 draw_color_col = advance_color_col(VCOL_HLC,
2724 &color_cols);
2725
2726 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2727 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2728 else if (draw_color_col && VCOL_HLC == *color_cols)
2729 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2730 else
2731 ScreenAttrs[off++] = win_attr;
2732
2733 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2734 break;
2735
2736 ++vcol;
2737 }
2738 }
2739#endif
2740
2741 screen_line(screen_row, wp->w_wincol, col,
2742 (int)wp->w_width, screen_line_flags);
2743 row++;
2744
2745 // Update w_cline_height and w_cline_folded if the cursor line was
2746 // updated (saves a call to plines() later).
2747 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2748 {
2749 curwin->w_cline_row = startrow;
2750 curwin->w_cline_height = row - startrow;
2751#ifdef FEAT_FOLDING
2752 curwin->w_cline_folded = FALSE;
2753#endif
2754 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2755 }
2756
2757 break;
2758 }
2759
2760 // Show "extends" character from 'listchars' if beyond the line end and
2761 // 'list' is set.
2762 if (lcs_ext != NUL
2763 && wp->w_p_list
2764 && !wp->w_p_wrap
2765#ifdef FEAT_DIFF
2766 && filler_todo <= 0
2767#endif
2768 && (
2769#ifdef FEAT_RIGHTLEFT
2770 wp->w_p_rl ? col == 0 :
2771#endif
2772 col == wp->w_width - 1)
2773 && (*ptr != NUL
2774 || (wp->w_p_list && lcs_eol_one > 0)
2775 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2776 {
2777 c = lcs_ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002778 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002779 mb_c = c;
2780 if (enc_utf8 && utf_char2len(c) > 1)
2781 {
2782 mb_utf8 = TRUE;
2783 u8cc[0] = 0;
2784 c = 0xc0;
2785 }
2786 else
2787 mb_utf8 = FALSE;
2788 }
2789
2790#ifdef FEAT_SYN_HL
2791 // advance to the next 'colorcolumn'
2792 if (draw_color_col)
2793 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2794
2795 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2796 // highlight the cursor position itself.
2797 // Also highlight the 'colorcolumn' if it is different than
2798 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002799 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2800 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002801 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002802 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002803 draw_state == WL_BRI ||
2804 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002805 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002806# ifdef FEAT_DIFF
2807 && filler_todo <= 0
2808# endif
2809 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 {
2811 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2812 && lnum != wp->w_cursor.lnum)
2813 {
2814 vcol_save_attr = char_attr;
2815 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2816 }
2817 else if (draw_color_col && VCOL_HLC == *color_cols)
2818 {
2819 vcol_save_attr = char_attr;
2820 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2821 }
2822 }
2823#endif
2824
2825 // Store character to be displayed.
2826 // Skip characters that are left of the screen for 'nowrap'.
2827 vcol_prev = vcol;
2828 if (draw_state < WL_LINE || n_skip <= 0)
2829 {
2830 // Store the character.
2831#if defined(FEAT_RIGHTLEFT)
2832 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2833 {
2834 // A double-wide character is: put first halve in left cell.
2835 --off;
2836 --col;
2837 }
2838#endif
2839 ScreenLines[off] = c;
2840 if (enc_dbcs == DBCS_JPNU)
2841 {
2842 if ((mb_c & 0xff00) == 0x8e00)
2843 ScreenLines[off] = 0x8e;
2844 ScreenLines2[off] = mb_c & 0xff;
2845 }
2846 else if (enc_utf8)
2847 {
2848 if (mb_utf8)
2849 {
2850 int i;
2851
2852 ScreenLinesUC[off] = mb_c;
2853 if ((c & 0xff) == 0)
2854 ScreenLines[off] = 0x80; // avoid storing zero
2855 for (i = 0; i < Screen_mco; ++i)
2856 {
2857 ScreenLinesC[i][off] = u8cc[i];
2858 if (u8cc[i] == 0)
2859 break;
2860 }
2861 }
2862 else
2863 ScreenLinesUC[off] = 0;
2864 }
2865 if (multi_attr)
2866 {
2867 ScreenAttrs[off] = multi_attr;
2868 multi_attr = 0;
2869 }
2870 else
2871 ScreenAttrs[off] = char_attr;
2872
2873 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2874 {
2875 // Need to fill two screen columns.
2876 ++off;
2877 ++col;
2878 if (enc_utf8)
2879 // UTF-8: Put a 0 in the second screen char.
2880 ScreenLines[off] = 0;
2881 else
2882 // DBCS: Put second byte in the second screen char.
2883 ScreenLines[off] = mb_c & 0xff;
2884 if (draw_state > WL_NR
2885#ifdef FEAT_DIFF
2886 && filler_todo <= 0
2887#endif
2888 )
2889 ++vcol;
2890 // When "tocol" is halfway a character, set it to the end of
2891 // the character, otherwise highlighting won't stop.
2892 if (tocol == vcol)
2893 ++tocol;
2894#ifdef FEAT_RIGHTLEFT
2895 if (wp->w_p_rl)
2896 {
2897 // now it's time to backup one cell
2898 --off;
2899 --col;
2900 }
2901#endif
2902 }
2903#ifdef FEAT_RIGHTLEFT
2904 if (wp->w_p_rl)
2905 {
2906 --off;
2907 --col;
2908 }
2909 else
2910#endif
2911 {
2912 ++off;
2913 ++col;
2914 }
2915 }
2916#ifdef FEAT_CONCEAL
2917 else if (wp->w_p_cole > 0 && is_concealing)
2918 {
2919 --n_skip;
2920 ++vcol_off;
2921 if (n_extra > 0)
2922 vcol_off += n_extra;
2923 if (wp->w_p_wrap)
2924 {
2925 // Special voodoo required if 'wrap' is on.
2926 //
2927 // Advance the column indicator to force the line
2928 // drawing to wrap early. This will make the line
2929 // take up the same screen space when parts are concealed,
2930 // so that cursor line computations aren't messed up.
2931 //
2932 // To avoid the fictitious advance of 'col' causing
2933 // trailing junk to be written out of the screen line
2934 // we are building, 'boguscols' keeps track of the number
2935 // of bad columns we have advanced.
2936 if (n_extra > 0)
2937 {
2938 vcol += n_extra;
2939# ifdef FEAT_RIGHTLEFT
2940 if (wp->w_p_rl)
2941 {
2942 col -= n_extra;
2943 boguscols -= n_extra;
2944 }
2945 else
2946# endif
2947 {
2948 col += n_extra;
2949 boguscols += n_extra;
2950 }
2951 n_extra = 0;
2952 n_attr = 0;
2953 }
2954
2955
2956 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2957 {
2958 // Need to fill two screen columns.
2959# ifdef FEAT_RIGHTLEFT
2960 if (wp->w_p_rl)
2961 {
2962 --boguscols;
2963 --col;
2964 }
2965 else
2966# endif
2967 {
2968 ++boguscols;
2969 ++col;
2970 }
2971 }
2972
2973# ifdef FEAT_RIGHTLEFT
2974 if (wp->w_p_rl)
2975 {
2976 --boguscols;
2977 --col;
2978 }
2979 else
2980# endif
2981 {
2982 ++boguscols;
2983 ++col;
2984 }
2985 }
2986 else
2987 {
2988 if (n_extra > 0)
2989 {
2990 vcol += n_extra;
2991 n_extra = 0;
2992 n_attr = 0;
2993 }
2994 }
2995
2996 }
2997#endif // FEAT_CONCEAL
2998 else
2999 --n_skip;
3000
3001 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3002 // column.
3003 if (draw_state > WL_NR
3004#ifdef FEAT_DIFF
3005 && filler_todo <= 0
3006#endif
3007 )
3008 ++vcol;
3009
3010#ifdef FEAT_SYN_HL
3011 if (vcol_save_attr >= 0)
3012 char_attr = vcol_save_attr;
3013#endif
3014
3015 // restore attributes after "predeces" in 'listchars'
3016 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3017 char_attr = saved_attr3;
3018
3019 // restore attributes after last 'listchars' or 'number' char
3020 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3021 char_attr = saved_attr2;
3022
3023 // At end of screen line and there is more to come: Display the line
3024 // so far. If there is no more to display it is caught above.
3025 if ((
3026#ifdef FEAT_RIGHTLEFT
3027 wp->w_p_rl ? (col < 0) :
3028#endif
3029 (col >= wp->w_width))
3030 && (*ptr != NUL
3031#ifdef FEAT_DIFF
3032 || filler_todo > 0
3033#endif
3034 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
3035 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3036 )
3037 {
3038#ifdef FEAT_CONCEAL
3039 screen_line(screen_row, wp->w_wincol, col - boguscols,
3040 (int)wp->w_width, screen_line_flags);
3041 boguscols = 0;
3042#else
3043 screen_line(screen_row, wp->w_wincol, col,
3044 (int)wp->w_width, screen_line_flags);
3045#endif
3046 ++row;
3047 ++screen_row;
3048
3049 // When not wrapping and finished diff lines, or when displayed
3050 // '$' and highlighting until last column, break here.
3051 if ((!wp->w_p_wrap
3052#ifdef FEAT_DIFF
3053 && filler_todo <= 0
3054#endif
3055 ) || lcs_eol_one == -1)
3056 break;
3057
3058 // When the window is too narrow draw all "@" lines.
3059 if (draw_state != WL_LINE
3060#ifdef FEAT_DIFF
3061 && filler_todo <= 0
3062#endif
3063 )
3064 {
3065 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3066 draw_vsep_win(wp, row);
3067 row = endrow;
3068 }
3069
3070 // When line got too long for screen break here.
3071 if (row == endrow)
3072 {
3073 ++row;
3074 break;
3075 }
3076
3077 if (screen_cur_row == screen_row - 1
3078#ifdef FEAT_DIFF
3079 && filler_todo <= 0
3080#endif
3081 && wp->w_width == Columns)
3082 {
3083 // Remember that the line wraps, used for modeless copy.
3084 LineWraps[screen_row - 1] = TRUE;
3085
3086 // Special trick to make copy/paste of wrapped lines work with
3087 // xterm/screen: write an extra character beyond the end of
3088 // the line. This will work with all terminal types
3089 // (regardless of the xn,am settings).
3090 // Only do this on a fast tty.
3091 // Only do this if the cursor is on the current line
3092 // (something has been written in it).
3093 // Don't do this for the GUI.
3094 // Don't do this for double-width characters.
3095 // Don't do this for a window not at the right screen border.
3096 if (p_tf
3097#ifdef FEAT_GUI
3098 && !gui.in_use
3099#endif
3100 && !(has_mbyte
3101 && ((*mb_off2cells)(LineOffset[screen_row],
3102 LineOffset[screen_row] + screen_Columns)
3103 == 2
3104 || (*mb_off2cells)(LineOffset[screen_row - 1]
3105 + (int)Columns - 2,
3106 LineOffset[screen_row] + screen_Columns)
3107 == 2)))
3108 {
3109 // First make sure we are at the end of the screen line,
3110 // then output the same character again to let the
3111 // terminal know about the wrap. If the terminal doesn't
3112 // auto-wrap, we overwrite the character.
3113 if (screen_cur_col != wp->w_width)
3114 screen_char(LineOffset[screen_row - 1]
3115 + (unsigned)Columns - 1,
3116 screen_row - 1, (int)(Columns - 1));
3117
3118 // When there is a multi-byte character, just output a
3119 // space to keep it simple.
3120 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3121 screen_row - 1] + (Columns - 1)]) > 1)
3122 out_char(' ');
3123 else
3124 out_char(ScreenLines[LineOffset[screen_row - 1]
3125 + (Columns - 1)]);
3126 // force a redraw of the first char on the next line
3127 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3128 screen_start(); // don't know where cursor is now
3129 }
3130 }
3131
3132 col = 0;
3133 off = (unsigned)(current_ScreenLine - ScreenLines);
3134#ifdef FEAT_RIGHTLEFT
3135 if (wp->w_p_rl)
3136 {
3137 col = wp->w_width - 1; // col is not used if breaking!
3138 off += col;
3139 }
3140#endif
3141
3142 // reset the drawing state for the start of a wrapped line
3143 draw_state = WL_START;
3144 saved_n_extra = n_extra;
3145 saved_p_extra = p_extra;
3146 saved_c_extra = c_extra;
3147 saved_c_final = c_final;
3148#ifdef FEAT_SYN_HL
3149 if (!(cul_screenline
3150# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003151 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003152# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003153 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003154 saved_char_attr = char_attr;
3155 else
3156#endif
3157 saved_char_attr = 0;
3158 n_extra = 0;
3159 lcs_prec_todo = lcs_prec;
3160#ifdef FEAT_LINEBREAK
3161# ifdef FEAT_DIFF
3162 if (filler_todo <= 0)
3163# endif
3164 need_showbreak = TRUE;
3165#endif
3166#ifdef FEAT_DIFF
3167 --filler_todo;
3168 // When the filler lines are actually below the last line of the
3169 // file, don't draw the line itself, break here.
3170 if (filler_todo == 0 && wp->w_botfill)
3171 break;
3172#endif
3173 }
3174
3175 } // for every character in the line
3176
3177#ifdef FEAT_SPELL
3178 // After an empty line check first word for capital.
3179 if (*skipwhite(line) == NUL)
3180 {
3181 capcol_lnum = lnum + 1;
3182 cap_col = 0;
3183 }
3184#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003185#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003186 vim_free(text_props);
3187 vim_free(text_prop_idxs);
3188#endif
3189
3190 vim_free(p_extra_free);
3191 return row;
3192}