blob: 869bdaa0efeb4190effb9eca290b09de556ef9ac [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
185#ifdef FEAT_TEXT_PROP
186static 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
273 pos_T *top, *bot;
274 int lnum_in_visual_area = FALSE;
275 pos_T pos;
276 long v;
277
278 int char_attr = 0; // attributes for next character
279 int attr_pri = FALSE; // char_attr has priority
280 int area_highlighting = FALSE; // Visual or incsearch highlighting
281 // in this line
282 int vi_attr = 0; // attributes for Visual and incsearch
283 // highlighting
284 int wcr_attr = 0; // attributes from 'wincolor'
285 int win_attr = 0; // background for whole window, except
286 // margins and "~" lines.
287 int area_attr = 0; // attributes desired by highlighting
288 int search_attr = 0; // attributes desired by 'hlsearch'
289#ifdef FEAT_SYN_HL
290 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
291 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200292 int prev_syntax_col = -1; // column of prev_syntax_attr
293 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200294 int has_syntax = FALSE; // this buffer has syntax highl.
295 int save_did_emsg;
296 int draw_color_col = FALSE; // highlight colorcolumn
297 int *color_cols = NULL; // pointer to according columns array
298#endif
299 int eol_hl_off = 0; // 1 if highlighted char after EOL
300#ifdef FEAT_TEXT_PROP
301 int text_prop_count;
302 int text_prop_next = 0; // next text property to use
303 textprop_T *text_props = NULL;
304 int *text_prop_idxs = NULL;
305 int text_props_active = 0;
306 proptype_T *text_prop_type = NULL;
307 int text_prop_attr = 0;
308 int text_prop_combine = FALSE;
309#endif
310#ifdef FEAT_SPELL
311 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200312 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200313# define SPWORDLEN 150
314 char_u nextline[SPWORDLEN * 2];// text with start of the next line
315 int nextlinecol = 0; // column where nextline[] starts
316 int nextline_idx = 0; // index in nextline[] where next line
317 // starts
318 int spell_attr = 0; // attributes desired by spelling
319 int word_end = 0; // last byte with same spell_attr
320 static linenr_T checked_lnum = 0; // line number for "checked_col"
321 static int checked_col = 0; // column in "checked_lnum" up to which
322 // there are no spell errors
323 static int cap_col = -1; // column to check for Cap word
324 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
325 int cur_checked_col = 0; // checked column for current line
326#endif
327 int extra_check = 0; // has extra highlighting
328 int multi_attr = 0; // attributes desired by multibyte
329 int mb_l = 1; // multi-byte byte length
330 int mb_c = 0; // decoded multi-byte character
331 int mb_utf8 = FALSE; // screen char is UTF-8 char
332 int u8cc[MAX_MCO]; // composing UTF-8 chars
333#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
334 int filler_lines = 0; // nr of filler lines to be drawn
335 int filler_todo = 0; // nr of filler lines still to do + 1
336#endif
337#ifdef FEAT_DIFF
338 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
339 int change_start = MAXCOL; // first col of changed area
340 int change_end = -1; // last col of changed area
341#endif
342 colnr_T trailcol = MAXCOL; // start of trailing spaces
343#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;
494 win_attr = term_get_attr(wp->w_buffer, lnum, -1);
495 }
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 {
538 if (LTOREQ_POS(curwin->w_cursor, VIsual))
539 {
540 // Visual is after curwin->w_cursor
541 top = &curwin->w_cursor;
542 bot = &VIsual;
543 }
544 else
545 {
546 // Visual is before curwin->w_cursor
547 top = &VIsual;
548 bot = &curwin->w_cursor;
549 }
550 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
551 if (VIsual_mode == Ctrl_V)
552 {
553 // block mode
554 if (lnum_in_visual_area)
555 {
556 fromcol = wp->w_old_cursor_fcol;
557 tocol = wp->w_old_cursor_lcol;
558 }
559 }
560 else
561 {
562 // non-block mode
563 if (lnum > top->lnum && lnum <= bot->lnum)
564 fromcol = 0;
565 else if (lnum == top->lnum)
566 {
567 if (VIsual_mode == 'V') // linewise
568 fromcol = 0;
569 else
570 {
571 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
572 if (gchar_pos(top) == NUL)
573 tocol = fromcol + 1;
574 }
575 }
576 if (VIsual_mode != 'V' && lnum == bot->lnum)
577 {
578 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
579 {
580 fromcol = -10;
581 tocol = MAXCOL;
582 }
583 else if (bot->col == MAXCOL)
584 tocol = MAXCOL;
585 else
586 {
587 pos = *bot;
588 if (*p_sel == 'e')
589 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
590 else
591 {
592 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
593 ++tocol;
594 }
595 }
596 }
597 }
598
599 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200600 if (!highlight_match && lnum == curwin->w_cursor.lnum
601 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200602#ifdef FEAT_GUI
603 && !gui.in_use
604#endif
605 )
606 noinvcur = TRUE;
607
608 // if inverting in this line set area_highlighting
609 if (fromcol >= 0)
610 {
611 area_highlighting = TRUE;
612 vi_attr = HL_ATTR(HLF_V);
613#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
614 if ((clip_star.available && !clip_star.owned
615 && clip_isautosel_star())
616 || (clip_plus.available && !clip_plus.owned
617 && clip_isautosel_plus()))
618 vi_attr = HL_ATTR(HLF_VNC);
619#endif
620 }
621 }
622
623 // handle 'incsearch' and ":s///c" highlighting
624 else if (highlight_match
625 && wp == curwin
626 && lnum >= curwin->w_cursor.lnum
627 && lnum <= curwin->w_cursor.lnum + search_match_lines)
628 {
629 if (lnum == curwin->w_cursor.lnum)
630 getvcol(curwin, &(curwin->w_cursor),
631 (colnr_T *)&fromcol, NULL, NULL);
632 else
633 fromcol = 0;
634 if (lnum == curwin->w_cursor.lnum + search_match_lines)
635 {
636 pos.lnum = lnum;
637 pos.col = search_match_endcol;
638 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
639 }
640 else
641 tocol = MAXCOL;
642 // do at least one character; happens when past end of line
643 if (fromcol == tocol)
644 tocol = fromcol + 1;
645 area_highlighting = TRUE;
646 vi_attr = HL_ATTR(HLF_I);
647 }
648 }
649
650#ifdef FEAT_DIFF
651 filler_lines = diff_check(wp, lnum);
652 if (filler_lines < 0)
653 {
654 if (filler_lines == -1)
655 {
656 if (diff_find_change(wp, lnum, &change_start, &change_end))
657 diff_hlf = HLF_ADD; // added line
658 else if (change_start == 0)
659 diff_hlf = HLF_TXD; // changed text
660 else
661 diff_hlf = HLF_CHD; // changed line
662 }
663 else
664 diff_hlf = HLF_ADD; // added line
665 filler_lines = 0;
666 area_highlighting = TRUE;
667 }
668 if (lnum == wp->w_topline)
669 filler_lines = wp->w_topfill;
670 filler_todo = filler_lines;
671#endif
672
673#ifdef FEAT_SIGNS
674 sign_present = buf_get_signattrs(wp->w_buffer, lnum, &sattr);
675#endif
676
677#ifdef LINE_ATTR
678# ifdef FEAT_SIGNS
679 // If this line has a sign with line highlighting set line_attr.
680 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200681 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200682# endif
683# if defined(FEAT_QUICKFIX)
684 // Highlight the current line in the quickfix window.
685 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
686 line_attr = HL_ATTR(HLF_QFL);
687# endif
688 if (line_attr != 0)
689 area_highlighting = TRUE;
690#endif
691
692 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
693 ptr = line;
694
695#ifdef FEAT_SPELL
696 if (has_spell && !number_only)
697 {
698 // For checking first word with a capital skip white space.
699 if (cap_col == 0)
700 cap_col = getwhitecols(line);
701
702 // To be able to spell-check over line boundaries copy the end of the
703 // current line into nextline[]. Above the start of the next line was
704 // copied to nextline[SPWORDLEN].
705 if (nextline[SPWORDLEN] == NUL)
706 {
707 // No next line or it is empty.
708 nextlinecol = MAXCOL;
709 nextline_idx = 0;
710 }
711 else
712 {
713 v = (long)STRLEN(line);
714 if (v < SPWORDLEN)
715 {
716 // Short line, use it completely and append the start of the
717 // next line.
718 nextlinecol = 0;
719 mch_memmove(nextline, line, (size_t)v);
720 STRMOVE(nextline + v, nextline + SPWORDLEN);
721 nextline_idx = v + 1;
722 }
723 else
724 {
725 // Long line, use only the last SPWORDLEN bytes.
726 nextlinecol = v - SPWORDLEN;
727 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
728 nextline_idx = SPWORDLEN + 1;
729 }
730 }
731 }
732#endif
733
734 if (wp->w_p_list)
735 {
736 if (lcs_space || lcs_trail || lcs_nbsp)
737 extra_check = TRUE;
738 // find start of trailing whitespace
739 if (lcs_trail)
740 {
741 trailcol = (colnr_T)STRLEN(ptr);
742 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
743 --trailcol;
744 trailcol += (colnr_T) (ptr - line);
745 }
746 }
747
748 wcr_attr = get_wcr_attr(wp);
749 if (wcr_attr != 0)
750 {
751 win_attr = wcr_attr;
752 area_highlighting = TRUE;
753 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200754 if (vi_attr != 0 && win_attr != 0)
755 vi_attr = hl_combine_attr(win_attr, vi_attr);
756
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200757#ifdef FEAT_TEXT_PROP
758 if (WIN_IS_POPUP(wp))
759 screen_line_flags |= SLF_POPUP;
760#endif
761
762 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
763 // first character to be displayed.
764 if (wp->w_p_wrap)
765 v = wp->w_skipcol;
766 else
767 v = wp->w_leftcol;
768 if (v > 0 && !number_only)
769 {
770 char_u *prev_ptr = ptr;
771
772 while (vcol < v && *ptr != NUL)
773 {
774 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
775 vcol += c;
776 prev_ptr = ptr;
777 MB_PTR_ADV(ptr);
778 }
779
780 // When:
781 // - 'cuc' is set, or
782 // - 'colorcolumn' is set, or
783 // - 'virtualedit' is set, or
784 // - the visual mode is active,
785 // the end of the line may be before the start of the displayed part.
786 if (vcol < v && (
787#ifdef FEAT_SYN_HL
788 wp->w_p_cuc || draw_color_col ||
789#endif
790 virtual_active() ||
791 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
792 vcol = v;
793
794 // Handle a character that's not completely on the screen: Put ptr at
795 // that character but skip the first few screen characters.
796 if (vcol > v)
797 {
798 vcol -= c;
799 ptr = prev_ptr;
800 // If the character fits on the screen, don't need to skip it.
801 // Except for a TAB.
802 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
803 n_skip = v - vcol;
804 }
805
806 // Adjust for when the inverted text is before the screen,
807 // and when the start of the inverted text is before the screen.
808 if (tocol <= vcol)
809 fromcol = 0;
810 else if (fromcol >= 0 && fromcol < vcol)
811 fromcol = vcol;
812
813#ifdef FEAT_LINEBREAK
814 // When w_skipcol is non-zero, first line needs 'showbreak'
815 if (wp->w_p_wrap)
816 need_showbreak = TRUE;
817#endif
818#ifdef FEAT_SPELL
819 // When spell checking a word we need to figure out the start of the
820 // word and if it's badly spelled or not.
821 if (has_spell)
822 {
823 int len;
824 colnr_T linecol = (colnr_T)(ptr - line);
825 hlf_T spell_hlf = HLF_COUNT;
826
827 pos = wp->w_cursor;
828 wp->w_cursor.lnum = lnum;
829 wp->w_cursor.col = linecol;
830 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
831
832 // spell_move_to() may call ml_get() and make "line" invalid
833 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
834 ptr = line + linecol;
835
836 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
837 {
838 // no bad word found at line start, don't check until end of a
839 // word
840 spell_hlf = HLF_COUNT;
841 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
842 }
843 else
844 {
845 // bad word found, use attributes until end of word
846 word_end = wp->w_cursor.col + len + 1;
847
848 // Turn index into actual attributes.
849 if (spell_hlf != HLF_COUNT)
850 spell_attr = highlight_attr[spell_hlf];
851 }
852 wp->w_cursor = pos;
853
854# ifdef FEAT_SYN_HL
855 // Need to restart syntax highlighting for this line.
856 if (has_syntax)
857 syntax_start(wp, lnum);
858# endif
859 }
860#endif
861 }
862
863 // Correct highlighting for cursor that can't be disabled.
864 // Avoids having to check this for each character.
865 if (fromcol >= 0)
866 {
867 if (noinvcur)
868 {
869 if ((colnr_T)fromcol == wp->w_virtcol)
870 {
871 // highlighting starts at cursor, let it start just after the
872 // cursor
873 fromcol_prev = fromcol;
874 fromcol = -1;
875 }
876 else if ((colnr_T)fromcol < wp->w_virtcol)
877 // restart highlighting after the cursor
878 fromcol_prev = wp->w_virtcol;
879 }
880 if (fromcol >= tocol)
881 fromcol = -1;
882 }
883
884#ifdef FEAT_SEARCH_EXTRA
885 if (!number_only)
886 {
887 v = (long)(ptr - line);
888 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
889 &line, &screen_search_hl,
890 &search_attr);
891 ptr = line + v; // "line" may have been updated
892 }
893#endif
894
895#ifdef FEAT_SYN_HL
896 // Cursor line highlighting for 'cursorline' in the current window.
897 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
898 {
899 // Do not show the cursor line in the text when Visual mode is active,
900 // because it's not clear what is selected then. Do update
901 // w_last_cursorline.
902 if (!(wp == curwin && VIsual_active)
903 && wp->w_p_culopt_flags != CULOPT_NBR)
904 {
905 cul_screenline = (wp->w_p_wrap
906 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
907
908 // Only set line_attr here when "screenline" is not present in
909 // 'cursorlineopt'. Otherwise it's done later.
910 if (!cul_screenline)
911 {
912 cul_attr = HL_ATTR(HLF_CUL);
913 line_attr = cul_attr;
914 wp->w_last_cursorline = wp->w_cursor.lnum;
915 }
916 else
917 {
918 line_attr_save = line_attr;
919 wp->w_last_cursorline = 0;
920 margin_columns_win(wp, &left_curline_col, &right_curline_col);
921 }
922 area_highlighting = TRUE;
923 }
924 else
925 wp->w_last_cursorline = wp->w_cursor.lnum;
926 }
927#endif
928
929#ifdef FEAT_TEXT_PROP
930 {
931 char_u *prop_start;
932
933 text_prop_count = get_text_props(wp->w_buffer, lnum,
934 &prop_start, FALSE);
935 if (text_prop_count > 0)
936 {
937 // Make a copy of the properties, so that they are properly
938 // aligned.
939 text_props = ALLOC_MULT(textprop_T, text_prop_count);
940 if (text_props != NULL)
941 mch_memmove(text_props, prop_start,
942 text_prop_count * sizeof(textprop_T));
943
944 // Allocate an array for the indexes.
945 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
946 area_highlighting = TRUE;
947 extra_check = TRUE;
948 }
949 }
950#endif
951
952 off = (unsigned)(current_ScreenLine - ScreenLines);
953 col = 0;
954
955#ifdef FEAT_RIGHTLEFT
956 if (wp->w_p_rl)
957 {
958 // Rightleft window: process the text in the normal direction, but put
959 // it in current_ScreenLine[] from right to left. Start at the
960 // rightmost column of the window.
961 col = wp->w_width - 1;
962 off += col;
963 screen_line_flags |= SLF_RIGHTLEFT;
964 }
965#endif
966
967 // Repeat for the whole displayed line.
968 for (;;)
969 {
970#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
971 int has_match_conc = 0; // match wants to conceal
972#endif
973#ifdef FEAT_CONCEAL
974 int did_decrement_ptr = FALSE;
975#endif
976 // Skip this quickly when working on the text.
977 if (draw_state != WL_LINE)
978 {
979#ifdef FEAT_CMDWIN
980 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
981 {
982 draw_state = WL_CMDLINE;
983 if (cmdwin_type != 0 && wp == curwin)
984 {
985 // Draw the cmdline character.
986 n_extra = 1;
987 c_extra = cmdwin_type;
988 c_final = NUL;
989 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
990 }
991 }
992#endif
993
994#ifdef FEAT_FOLDING
995 if (draw_state == WL_FOLD - 1 && n_extra == 0)
996 {
997 int fdc = compute_foldcolumn(wp, 0);
998
999 draw_state = WL_FOLD;
1000 if (fdc > 0)
1001 {
1002 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1003 // already be in use.
1004 vim_free(p_extra_free);
1005 p_extra_free = alloc(12 + 1);
1006
1007 if (p_extra_free != NULL)
1008 {
1009 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
1010 n_extra = fdc;
1011 p_extra_free[n_extra] = NUL;
1012 p_extra = p_extra_free;
1013 c_extra = NUL;
1014 c_final = NUL;
1015 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
1016 }
1017 }
1018 }
1019#endif
1020
1021#ifdef FEAT_SIGNS
1022 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1023 {
1024 draw_state = WL_SIGN;
1025 // Show the sign column when there are any signs in this
1026 // buffer or when using Netbeans.
1027 if (signcolumn_on(wp))
1028 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1029 row, startrow, filler_lines, filler_todo, &c_extra,
1030 &c_final, extra, &p_extra, &n_extra, &char_attr);
1031 }
1032#endif
1033
1034 if (draw_state == WL_NR - 1 && n_extra == 0)
1035 {
1036 draw_state = WL_NR;
1037 // Display the absolute or relative line number. After the
1038 // first fill with blanks when the 'n' flag isn't in 'cpo'
1039 if ((wp->w_p_nu || wp->w_p_rnu)
1040 && (row == startrow
1041#ifdef FEAT_DIFF
1042 + filler_lines
1043#endif
1044 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1045 {
1046#ifdef FEAT_SIGNS
1047 // If 'signcolumn' is set to 'number' and a sign is present
1048 // in 'lnum', then display the sign instead of the line
1049 // number.
1050 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1051 && sign_present)
1052 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1053 row, startrow, filler_lines, filler_todo,
1054 &c_extra, &c_final, extra, &p_extra, &n_extra,
1055 &char_attr);
1056 else
1057#endif
1058 {
1059 // Draw the line number (empty space after wrapping).
1060 if (row == startrow
1061#ifdef FEAT_DIFF
1062 + filler_lines
1063#endif
1064 )
1065 {
1066 long num;
1067 char *fmt = "%*ld ";
1068
1069 if (wp->w_p_nu && !wp->w_p_rnu)
1070 // 'number' + 'norelativenumber'
1071 num = (long)lnum;
1072 else
1073 {
1074 // 'relativenumber', don't use negative numbers
1075 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1076 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1077 {
1078 // 'number' + 'relativenumber'
1079 num = lnum;
1080 fmt = "%-*ld ";
1081 }
1082 }
1083
1084 sprintf((char *)extra, fmt,
1085 number_width(wp), num);
1086 if (wp->w_skipcol > 0)
1087 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1088 *p_extra = '-';
1089#ifdef FEAT_RIGHTLEFT
1090 if (wp->w_p_rl) // reverse line numbers
1091 {
1092 char_u *p1, *p2;
1093 int t;
1094
1095 // like rl_mirror(), but keep the space at the end
1096 p2 = skiptowhite(extra) - 1;
1097 for (p1 = extra; p1 < p2; ++p1, --p2)
1098 {
1099 t = *p1;
1100 *p1 = *p2;
1101 *p2 = t;
1102 }
1103 }
1104#endif
1105 p_extra = extra;
1106 c_extra = NUL;
1107 c_final = NUL;
1108 }
1109 else
1110 {
1111 c_extra = ' ';
1112 c_final = NUL;
1113 }
1114 n_extra = number_width(wp) + 1;
1115 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1116#ifdef FEAT_SYN_HL
1117 // When 'cursorline' is set highlight the line number of
1118 // the current line differently.
1119 // When 'cursorlineopt' has "screenline" only highlight
1120 // the line number itself.
1121 // TODO: Can we use CursorLine instead of CursorLineNr
1122 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001123 if (wp->w_p_cul
1124 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001125 && (wp->w_p_culopt_flags & CULOPT_NBR)
1126 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001127 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001128 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1129#endif
1130 }
1131 }
1132 }
1133
1134#ifdef FEAT_LINEBREAK
1135 if (wp->w_p_brisbr && draw_state == WL_BRI - 1
1136 && n_extra == 0 && *p_sbr != NUL)
1137 // draw indent after showbreak value
1138 draw_state = WL_BRI;
1139 else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0)
1140 // After the showbreak, draw the breakindent
1141 draw_state = WL_BRI - 1;
1142
1143 // draw 'breakindent': indent wrapped text accordingly
1144 if (draw_state == WL_BRI - 1 && n_extra == 0)
1145 {
1146 draw_state = WL_BRI;
1147 // if need_showbreak is set, breakindent also applies
1148 if (wp->w_p_bri && n_extra == 0
1149 && (row != startrow || need_showbreak)
1150# ifdef FEAT_DIFF
1151 && filler_lines == 0
1152# endif
1153 )
1154 {
1155 char_attr = 0;
1156# ifdef FEAT_DIFF
1157 if (diff_hlf != (hlf_T)0)
1158 {
1159 char_attr = HL_ATTR(diff_hlf);
1160# ifdef FEAT_SYN_HL
1161 if (cul_attr != 0)
1162 char_attr = hl_combine_attr(char_attr, cul_attr);
1163# endif
1164 }
1165# endif
1166 p_extra = NULL;
1167 c_extra = ' ';
1168 n_extra = get_breakindent_win(wp,
1169 ml_get_buf(wp->w_buffer, lnum, FALSE));
1170 // Correct end of highlighted area for 'breakindent',
1171 // required when 'linebreak' is also set.
1172 if (tocol == vcol)
1173 tocol += n_extra;
1174 }
1175 }
1176#endif
1177
1178#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1179 if (draw_state == WL_SBR - 1 && n_extra == 0)
1180 {
1181 draw_state = WL_SBR;
1182# ifdef FEAT_DIFF
1183 if (filler_todo > 0)
1184 {
1185 // Draw "deleted" diff line(s).
1186 if (char2cells(fill_diff) > 1)
1187 {
1188 c_extra = '-';
1189 c_final = NUL;
1190 }
1191 else
1192 {
1193 c_extra = fill_diff;
1194 c_final = NUL;
1195 }
1196# ifdef FEAT_RIGHTLEFT
1197 if (wp->w_p_rl)
1198 n_extra = col + 1;
1199 else
1200# endif
1201 n_extra = wp->w_width - col;
1202 char_attr = HL_ATTR(HLF_DED);
1203 }
1204# endif
1205# ifdef FEAT_LINEBREAK
1206 if (*p_sbr != NUL && need_showbreak)
1207 {
1208 // Draw 'showbreak' at the start of each broken line.
1209 p_extra = p_sbr;
1210 c_extra = NUL;
1211 c_final = NUL;
1212 n_extra = (int)STRLEN(p_sbr);
1213 char_attr = HL_ATTR(HLF_AT);
1214 need_showbreak = FALSE;
1215 vcol_sbr = vcol + MB_CHARLEN(p_sbr);
1216 // Correct end of highlighted area for 'showbreak',
1217 // required when 'linebreak' is also set.
1218 if (tocol == vcol)
1219 tocol += n_extra;
1220 // combine 'showbreak' with 'wincolor'
1221 if (win_attr != 0)
1222 char_attr = hl_combine_attr(win_attr, char_attr);
1223# ifdef FEAT_SYN_HL
1224 // combine 'showbreak' with 'cursorline'
1225 if (cul_attr != 0)
1226 char_attr = hl_combine_attr(char_attr, cul_attr);
1227# endif
1228 }
1229# endif
1230 }
1231#endif
1232
1233 if (draw_state == WL_LINE - 1 && n_extra == 0)
1234 {
1235 draw_state = WL_LINE;
1236 if (saved_n_extra)
1237 {
1238 // Continue item from end of wrapped line.
1239 n_extra = saved_n_extra;
1240 c_extra = saved_c_extra;
1241 c_final = saved_c_final;
1242 p_extra = saved_p_extra;
1243 char_attr = saved_char_attr;
1244 }
1245 else
1246 char_attr = win_attr;
1247 }
1248 }
1249#ifdef FEAT_SYN_HL
1250 if (cul_screenline)
1251 {
1252 if (draw_state == WL_LINE
1253 && vcol >= left_curline_col
1254 && vcol < right_curline_col)
1255 {
1256 cul_attr = HL_ATTR(HLF_CUL);
1257 line_attr = cul_attr;
1258 }
1259 else
1260 {
1261 cul_attr = 0;
1262 line_attr = line_attr_save;
1263 }
1264 }
1265#endif
1266
1267 // When still displaying '$' of change command, stop at cursor.
1268 // When only displaying the (relative) line number and that's done,
1269 // stop here.
1270 if ((dollar_vcol >= 0 && wp == curwin
1271 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
1272#ifdef FEAT_DIFF
1273 && filler_todo <= 0
1274#endif
1275 )
1276 || (number_only && draw_state > WL_NR))
1277 {
1278 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1279 screen_line_flags);
1280 // Pretend we have finished updating the window. Except when
1281 // 'cursorcolumn' is set.
1282#ifdef FEAT_SYN_HL
1283 if (wp->w_p_cuc)
1284 row = wp->w_cline_row + wp->w_cline_height;
1285 else
1286#endif
1287 row = wp->w_height;
1288 break;
1289 }
1290
Bram Moolenaar34390282019-10-16 14:38:26 +02001291 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001292 {
1293 // handle Visual or match highlighting in this line
1294 if (vcol == fromcol
1295 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1296 && (*mb_ptr2cells)(ptr) > 1)
1297 || ((int)vcol_prev == fromcol_prev
1298 && vcol_prev < vcol // not at margin
1299 && vcol < tocol))
1300 area_attr = vi_attr; // start highlighting
1301 else if (area_attr != 0
1302 && (vcol == tocol
1303 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1304 area_attr = 0; // stop highlighting
1305
1306#ifdef FEAT_SEARCH_EXTRA
1307 if (!n_extra)
1308 {
1309 // Check for start/end of 'hlsearch' and other matches.
1310 // After end, check for start/end of next match.
1311 // When another match, have to check for start again.
1312 v = (long)(ptr - line);
1313 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1314 &screen_search_hl, &has_match_conc,
1315 &match_conc, did_line_attr, lcs_eol_one);
1316 ptr = line + v; // "line" may have been changed
1317 }
1318#endif
1319
1320#ifdef FEAT_DIFF
1321 if (diff_hlf != (hlf_T)0)
1322 {
1323 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1324 && n_extra == 0)
1325 diff_hlf = HLF_TXD; // changed text
1326 if (diff_hlf == HLF_TXD && ptr - line > change_end
1327 && n_extra == 0)
1328 diff_hlf = HLF_CHD; // changed line
1329 line_attr = HL_ATTR(diff_hlf);
1330 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1331 && wp->w_p_culopt_flags != CULOPT_NBR
1332 && (!cul_screenline || (vcol >= left_curline_col
1333 && vcol <= right_curline_col)))
1334 line_attr = hl_combine_attr(
1335 line_attr, HL_ATTR(HLF_CUL));
1336 }
1337#endif
1338
1339#ifdef FEAT_TEXT_PROP
1340 if (text_props != NULL)
1341 {
1342 int pi;
1343 int bcol = (int)(ptr - line);
1344
1345 if (n_extra > 0)
1346 --bcol; // still working on the previous char, e.g. Tab
1347
1348 // Check if any active property ends.
1349 for (pi = 0; pi < text_props_active; ++pi)
1350 {
1351 int tpi = text_prop_idxs[pi];
1352
1353 if (bcol >= text_props[tpi].tp_col - 1
1354 + text_props[tpi].tp_len)
1355 {
1356 if (pi + 1 < text_props_active)
1357 mch_memmove(text_prop_idxs + pi,
1358 text_prop_idxs + pi + 1,
1359 sizeof(int)
1360 * (text_props_active - (pi + 1)));
1361 --text_props_active;
1362 --pi;
1363 }
1364 }
1365
1366 // Add any text property that starts in this column.
1367 while (text_prop_next < text_prop_count
1368 && bcol >= text_props[text_prop_next].tp_col - 1)
1369 text_prop_idxs[text_props_active++] = text_prop_next++;
1370
1371 text_prop_attr = 0;
1372 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001373 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001374 if (text_props_active > 0)
1375 {
1376 // Sort the properties on priority and/or starting last.
1377 // Then combine the attributes, highest priority last.
1378 current_text_props = text_props;
1379 current_buf = wp->w_buffer;
1380 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1381 sizeof(int), text_prop_compare);
1382
1383 for (pi = 0; pi < text_props_active; ++pi)
1384 {
1385 int tpi = text_prop_idxs[pi];
1386 proptype_T *pt = text_prop_type_by_id(
1387 wp->w_buffer, text_props[tpi].tp_type);
1388
1389 if (pt != NULL && pt->pt_hl_id > 0)
1390 {
1391 int pt_attr = syn_id2attr(pt->pt_hl_id);
1392
1393 text_prop_type = pt;
1394 text_prop_attr =
1395 hl_combine_attr(text_prop_attr, pt_attr);
1396 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1397 }
1398 }
1399 }
1400 }
1401#endif
1402
Bram Moolenaara74fda62019-10-19 17:38:03 +02001403#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001404 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001405 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001406 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001407# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001408 if (get_term_attr)
Bram Moolenaar34390282019-10-16 14:38:26 +02001409 syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001410# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001411 // Get syntax attribute.
1412 if (has_syntax)
1413 {
1414 // Get the syntax attribute for the character. If there
1415 // is an error, disable syntax highlighting.
1416 save_did_emsg = did_emsg;
1417 did_emsg = FALSE;
1418
1419 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001420 if (v == prev_syntax_col)
1421 // at same column again
1422 syntax_attr = prev_syntax_attr;
1423 else
1424 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001425# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001426 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001427# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001428 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001429# ifdef FEAT_SPELL
1430 has_spell ? &can_spell :
1431# endif
1432 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001433 prev_syntax_col = v;
1434 prev_syntax_attr = syntax_attr;
1435 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001436
1437 // combine syntax attribute with 'wincolor'
1438 if (syntax_attr != 0 && win_attr != 0)
1439 syntax_attr = hl_combine_attr(win_attr, syntax_attr);
1440
1441 if (did_emsg)
1442 {
1443 wp->w_s->b_syn_error = TRUE;
1444 has_syntax = FALSE;
1445 syntax_attr = 0;
1446 }
1447 else
1448 did_emsg = save_did_emsg;
1449# ifdef SYN_TIME_LIMIT
1450 if (wp->w_s->b_syn_slow)
1451 has_syntax = FALSE;
1452# endif
1453
1454 // Need to get the line again, a multi-line regexp may
1455 // have made it invalid.
1456 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1457 ptr = line + v;
1458# ifdef FEAT_CONCEAL
1459 // no concealing past the end of the line, it interferes
1460 // with line highlighting
1461 if (*ptr == NUL)
1462 syntax_flags = 0;
1463 else
1464 syntax_flags = get_syntax_info(&syntax_seqnr);
1465# endif
1466 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001467 }
Bram Moolenaara74fda62019-10-19 17:38:03 +02001468#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001469
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001470 // Decide which of the highlight attributes to use.
1471 attr_pri = TRUE;
1472#ifdef LINE_ATTR
1473 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001474 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001475 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001476# ifdef FEAT_SYN_HL
1477 if (syntax_attr != 0)
1478 char_attr = hl_combine_attr(syntax_attr, char_attr);
1479# endif
1480 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001482 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001483 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001484# ifdef FEAT_SYN_HL
1485 if (syntax_attr != 0)
1486 char_attr = hl_combine_attr(syntax_attr, char_attr);
1487# endif
1488 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489# ifdef FEAT_TEXT_PROP
1490 else if (text_prop_type != NULL)
1491 {
Bram Moolenaar053f7122019-09-23 22:17:15 +02001492 char_attr = hl_combine_attr(line_attr != 0
1493 ? line_attr
1494 : syntax_attr != 0
1495 ? syntax_attr
1496 : win_attr, text_prop_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001497 }
1498# endif
1499 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1500 || vcol < fromcol || vcol_prev < fromcol_prev
1501 || vcol >= tocol))
1502 {
1503 // Use line_attr when not in the Visual or 'incsearch' area
1504 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001505# ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001506 if (syntax_attr != 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001507 char_attr = hl_combine_attr(syntax_attr, line_attr);
1508 else
1509# endif
1510 char_attr = line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001511 attr_pri = FALSE;
1512 }
1513#else
1514 if (area_attr != 0)
1515 char_attr = area_attr;
1516 else if (search_attr != 0)
1517 char_attr = search_attr;
1518#endif
1519 else
1520 {
1521 attr_pri = FALSE;
1522#ifdef FEAT_TEXT_PROP
1523 if (text_prop_type != NULL)
1524 {
1525 if (text_prop_combine)
1526 char_attr = hl_combine_attr(
1527 syntax_attr, text_prop_attr);
1528 else
1529 char_attr = hl_combine_attr(
1530 win_attr, text_prop_attr);
1531 }
1532 else
1533#endif
1534#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001535 char_attr = syntax_attr;
1536#else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001537 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001538#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001539 }
1540 }
1541 if (char_attr == 0)
1542 char_attr = win_attr;
1543
1544 // Get the next character to put on the screen.
1545
1546 // The "p_extra" points to the extra stuff that is inserted to
1547 // represent special characters (non-printable stuff) and other
1548 // things. When all characters are the same, c_extra is used.
1549 // If c_final is set, it will compulsorily be used at the end.
1550 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1551 // "p_extra[n_extra]".
1552 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1553 if (n_extra > 0)
1554 {
1555 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1556 {
1557 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1558 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1559 if (enc_utf8 && utf_char2len(c) > 1)
1560 {
1561 mb_utf8 = TRUE;
1562 u8cc[0] = 0;
1563 c = 0xc0;
1564 }
1565 else
1566 mb_utf8 = FALSE;
1567 }
1568 else
1569 {
1570 c = *p_extra;
1571 if (has_mbyte)
1572 {
1573 mb_c = c;
1574 if (enc_utf8)
1575 {
1576 // If the UTF-8 character is more than one byte:
1577 // Decode it into "mb_c".
1578 mb_l = utfc_ptr2len(p_extra);
1579 mb_utf8 = FALSE;
1580 if (mb_l > n_extra)
1581 mb_l = 1;
1582 else if (mb_l > 1)
1583 {
1584 mb_c = utfc_ptr2char(p_extra, u8cc);
1585 mb_utf8 = TRUE;
1586 c = 0xc0;
1587 }
1588 }
1589 else
1590 {
1591 // if this is a DBCS character, put it in "mb_c"
1592 mb_l = MB_BYTE2LEN(c);
1593 if (mb_l >= n_extra)
1594 mb_l = 1;
1595 else if (mb_l > 1)
1596 mb_c = (c << 8) + p_extra[1];
1597 }
1598 if (mb_l == 0) // at the NUL at end-of-line
1599 mb_l = 1;
1600
1601 // If a double-width char doesn't fit display a '>' in the
1602 // last column.
1603 if ((
1604# ifdef FEAT_RIGHTLEFT
1605 wp->w_p_rl ? (col <= 0) :
1606# endif
1607 (col >= wp->w_width - 1))
1608 && (*mb_char2cells)(mb_c) == 2)
1609 {
1610 c = '>';
1611 mb_c = c;
1612 mb_l = 1;
1613 mb_utf8 = FALSE;
1614 multi_attr = HL_ATTR(HLF_AT);
1615#ifdef FEAT_SYN_HL
1616 if (cul_attr)
1617 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1618#endif
1619 // put the pointer back to output the double-width
1620 // character at the start of the next line.
1621 ++n_extra;
1622 --p_extra;
1623 }
1624 else
1625 {
1626 n_extra -= mb_l - 1;
1627 p_extra += mb_l - 1;
1628 }
1629 }
1630 ++p_extra;
1631 }
1632 --n_extra;
1633 }
1634 else
1635 {
1636#ifdef FEAT_LINEBREAK
1637 int c0;
1638#endif
1639
1640 if (p_extra_free != NULL)
1641 VIM_CLEAR(p_extra_free);
1642 // Get a character from the line itself.
1643 c = *ptr;
1644#ifdef FEAT_LINEBREAK
1645 c0 = *ptr;
1646#endif
1647 if (has_mbyte)
1648 {
1649 mb_c = c;
1650 if (enc_utf8)
1651 {
1652 // If the UTF-8 character is more than one byte: Decode it
1653 // into "mb_c".
1654 mb_l = utfc_ptr2len(ptr);
1655 mb_utf8 = FALSE;
1656 if (mb_l > 1)
1657 {
1658 mb_c = utfc_ptr2char(ptr, u8cc);
1659 // Overlong encoded ASCII or ASCII with composing char
1660 // is displayed normally, except a NUL.
1661 if (mb_c < 0x80)
1662 {
1663 c = mb_c;
1664#ifdef FEAT_LINEBREAK
1665 c0 = mb_c;
1666#endif
1667 }
1668 mb_utf8 = TRUE;
1669
1670 // At start of the line we can have a composing char.
1671 // Draw it as a space with a composing char.
1672 if (utf_iscomposing(mb_c))
1673 {
1674 int i;
1675
1676 for (i = Screen_mco - 1; i > 0; --i)
1677 u8cc[i] = u8cc[i - 1];
1678 u8cc[0] = mb_c;
1679 mb_c = ' ';
1680 }
1681 }
1682
1683 if ((mb_l == 1 && c >= 0x80)
1684 || (mb_l >= 1 && mb_c == 0)
1685 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1686 {
1687 // Illegal UTF-8 byte: display as <xx>.
1688 // Non-BMP character : display as ? or fullwidth ?.
1689 transchar_hex(extra, mb_c);
1690# ifdef FEAT_RIGHTLEFT
1691 if (wp->w_p_rl) // reverse
1692 rl_mirror(extra);
1693# endif
1694 p_extra = extra;
1695 c = *p_extra;
1696 mb_c = mb_ptr2char_adv(&p_extra);
1697 mb_utf8 = (c >= 0x80);
1698 n_extra = (int)STRLEN(p_extra);
1699 c_extra = NUL;
1700 c_final = NUL;
1701 if (area_attr == 0 && search_attr == 0)
1702 {
1703 n_attr = n_extra + 1;
1704 extra_attr = HL_ATTR(HLF_8);
1705 saved_attr2 = char_attr; // save current attr
1706 }
1707 }
1708 else if (mb_l == 0) // at the NUL at end-of-line
1709 mb_l = 1;
1710#ifdef FEAT_ARABIC
1711 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1712 {
1713 // Do Arabic shaping.
1714 int pc, pc1, nc;
1715 int pcc[MAX_MCO];
1716
1717 // The idea of what is the previous and next
1718 // character depends on 'rightleft'.
1719 if (wp->w_p_rl)
1720 {
1721 pc = prev_c;
1722 pc1 = prev_c1;
1723 nc = utf_ptr2char(ptr + mb_l);
1724 prev_c1 = u8cc[0];
1725 }
1726 else
1727 {
1728 pc = utfc_ptr2char(ptr + mb_l, pcc);
1729 nc = prev_c;
1730 pc1 = pcc[0];
1731 }
1732 prev_c = mb_c;
1733
1734 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1735 }
1736 else
1737 prev_c = mb_c;
1738#endif
1739 }
1740 else // enc_dbcs
1741 {
1742 mb_l = MB_BYTE2LEN(c);
1743 if (mb_l == 0) // at the NUL at end-of-line
1744 mb_l = 1;
1745 else if (mb_l > 1)
1746 {
1747 // We assume a second byte below 32 is illegal.
1748 // Hopefully this is OK for all double-byte encodings!
1749 if (ptr[1] >= 32)
1750 mb_c = (c << 8) + ptr[1];
1751 else
1752 {
1753 if (ptr[1] == NUL)
1754 {
1755 // head byte at end of line
1756 mb_l = 1;
1757 transchar_nonprint(extra, c);
1758 }
1759 else
1760 {
1761 // illegal tail byte
1762 mb_l = 2;
1763 STRCPY(extra, "XX");
1764 }
1765 p_extra = extra;
1766 n_extra = (int)STRLEN(extra) - 1;
1767 c_extra = NUL;
1768 c_final = NUL;
1769 c = *p_extra++;
1770 if (area_attr == 0 && search_attr == 0)
1771 {
1772 n_attr = n_extra + 1;
1773 extra_attr = HL_ATTR(HLF_8);
1774 saved_attr2 = char_attr; // save current attr
1775 }
1776 mb_c = c;
1777 }
1778 }
1779 }
1780 // If a double-width char doesn't fit display a '>' in the
1781 // last column; the character is displayed at the start of the
1782 // next line.
1783 if ((
1784# ifdef FEAT_RIGHTLEFT
1785 wp->w_p_rl ? (col <= 0) :
1786# endif
1787 (col >= wp->w_width - 1))
1788 && (*mb_char2cells)(mb_c) == 2)
1789 {
1790 c = '>';
1791 mb_c = c;
1792 mb_utf8 = FALSE;
1793 mb_l = 1;
1794 multi_attr = HL_ATTR(HLF_AT);
1795 // Put pointer back so that the character will be
1796 // displayed at the start of the next line.
1797 --ptr;
1798#ifdef FEAT_CONCEAL
1799 did_decrement_ptr = TRUE;
1800#endif
1801 }
1802 else if (*ptr != NUL)
1803 ptr += mb_l - 1;
1804
1805 // If a double-width char doesn't fit at the left side display
1806 // a '<' in the first column. Don't do this for unprintable
1807 // characters.
1808 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1809 {
1810 n_extra = 1;
1811 c_extra = MB_FILLER_CHAR;
1812 c_final = NUL;
1813 c = ' ';
1814 if (area_attr == 0 && search_attr == 0)
1815 {
1816 n_attr = n_extra + 1;
1817 extra_attr = HL_ATTR(HLF_AT);
1818 saved_attr2 = char_attr; // save current attr
1819 }
1820 mb_c = c;
1821 mb_utf8 = FALSE;
1822 mb_l = 1;
1823 }
1824
1825 }
1826 ++ptr;
1827
1828 if (extra_check)
1829 {
1830#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001831 // Check spelling (unless at the end of the line).
1832 // Only do this when there is no syntax highlighting, the
1833 // @Spell cluster is not used or the current syntax item
1834 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001835 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 if (has_spell && v >= word_end && v > cur_checked_col)
1837 {
1838 spell_attr = 0;
1839 if (c != 0 && (
1840# ifdef FEAT_SYN_HL
1841 !has_syntax ||
1842# endif
1843 can_spell))
1844 {
1845 char_u *prev_ptr, *p;
1846 int len;
1847 hlf_T spell_hlf = HLF_COUNT;
1848 if (has_mbyte)
1849 {
1850 prev_ptr = ptr - mb_l;
1851 v -= mb_l - 1;
1852 }
1853 else
1854 prev_ptr = ptr - 1;
1855
1856 // Use nextline[] if possible, it has the start of the
1857 // next line concatenated.
1858 if ((prev_ptr - line) - nextlinecol >= 0)
1859 p = nextline + (prev_ptr - line) - nextlinecol;
1860 else
1861 p = prev_ptr;
1862 cap_col -= (int)(prev_ptr - line);
1863 len = spell_check(wp, p, &spell_hlf, &cap_col,
1864 nochange);
1865 word_end = v + len;
1866
1867 // In Insert mode only highlight a word that
1868 // doesn't touch the cursor.
1869 if (spell_hlf != HLF_COUNT
1870 && (State & INSERT) != 0
1871 && wp->w_cursor.lnum == lnum
1872 && wp->w_cursor.col >=
1873 (colnr_T)(prev_ptr - line)
1874 && wp->w_cursor.col < (colnr_T)word_end)
1875 {
1876 spell_hlf = HLF_COUNT;
1877 spell_redraw_lnum = lnum;
1878 }
1879
1880 if (spell_hlf == HLF_COUNT && p != prev_ptr
1881 && (p - nextline) + len > nextline_idx)
1882 {
1883 // Remember that the good word continues at the
1884 // start of the next line.
1885 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001886 checked_col = (int)((p - nextline)
1887 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 }
1889
1890 // Turn index into actual attributes.
1891 if (spell_hlf != HLF_COUNT)
1892 spell_attr = highlight_attr[spell_hlf];
1893
1894 if (cap_col > 0)
1895 {
1896 if (p != prev_ptr
1897 && (p - nextline) + cap_col >= nextline_idx)
1898 {
1899 // Remember that the word in the next line
1900 // must start with a capital.
1901 capcol_lnum = lnum + 1;
1902 cap_col = (int)((p - nextline) + cap_col
1903 - nextline_idx);
1904 }
1905 else
1906 // Compute the actual column.
1907 cap_col += (int)(prev_ptr - line);
1908 }
1909 }
1910 }
1911 if (spell_attr != 0)
1912 {
1913 if (!attr_pri)
1914 char_attr = hl_combine_attr(char_attr, spell_attr);
1915 else
1916 char_attr = hl_combine_attr(spell_attr, char_attr);
1917 }
1918#endif
1919#ifdef FEAT_LINEBREAK
1920 // Found last space before word: check for line break.
1921 if (wp->w_p_lbr && c0 == c
1922 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1923 {
1924 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1925 char_u *p = ptr - (mb_off + 1);
1926
1927 // TODO: is passing p for start of the line OK?
1928 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1929 NULL) - 1;
1930 if (c == TAB && n_extra + col > wp->w_width)
1931# ifdef FEAT_VARTABS
1932 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1933 wp->w_buffer->b_p_vts_array) - 1;
1934# else
1935 n_extra = (int)wp->w_buffer->b_p_ts
1936 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1937# endif
1938
1939 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1940 c_final = NUL;
1941 if (VIM_ISWHITE(c))
1942 {
1943#ifdef FEAT_CONCEAL
1944 if (c == TAB)
1945 // See "Tab alignment" below.
1946 FIX_FOR_BOGUSCOLS;
1947#endif
1948 if (!wp->w_p_list)
1949 c = ' ';
1950 }
1951 }
1952#endif
1953
1954 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
1955 // But not when the character is followed by a composing
1956 // character (use mb_l to check that).
1957 if (wp->w_p_list
1958 && ((((c == 160 && mb_l == 1)
1959 || (mb_utf8
1960 && ((mb_c == 160 && mb_l == 2)
1961 || (mb_c == 0x202f && mb_l == 3))))
1962 && lcs_nbsp)
1963 || (c == ' '
1964 && mb_l == 1
1965 && lcs_space
1966 && ptr - line <= trailcol)))
1967 {
1968 c = (c == ' ') ? lcs_space : lcs_nbsp;
1969 if (area_attr == 0 && search_attr == 0)
1970 {
1971 n_attr = 1;
1972 extra_attr = HL_ATTR(HLF_8);
1973 saved_attr2 = char_attr; // save current attr
1974 }
1975 mb_c = c;
1976 if (enc_utf8 && utf_char2len(c) > 1)
1977 {
1978 mb_utf8 = TRUE;
1979 u8cc[0] = 0;
1980 c = 0xc0;
1981 }
1982 else
1983 mb_utf8 = FALSE;
1984 }
1985
1986 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
1987 {
1988 c = lcs_trail;
1989 if (!attr_pri)
1990 {
1991 n_attr = 1;
1992 extra_attr = HL_ATTR(HLF_8);
1993 saved_attr2 = char_attr; // save current attr
1994 }
1995 mb_c = c;
1996 if (enc_utf8 && utf_char2len(c) > 1)
1997 {
1998 mb_utf8 = TRUE;
1999 u8cc[0] = 0;
2000 c = 0xc0;
2001 }
2002 else
2003 mb_utf8 = FALSE;
2004 }
2005 }
2006
2007 // Handling of non-printable characters.
2008 if (!vim_isprintc(c))
2009 {
2010 // when getting a character from the file, we may have to
2011 // turn it into something else on the way to putting it
2012 // into "ScreenLines".
2013 if (c == TAB && (!wp->w_p_list || lcs_tab1))
2014 {
2015 int tab_len = 0;
2016 long vcol_adjusted = vcol; // removed showbreak length
2017#ifdef FEAT_LINEBREAK
2018 // only adjust the tab_len, when at the first column
2019 // after the showbreak value was drawn
2020 if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2021 vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
2022#endif
2023 // tab amount depends on current column
2024#ifdef FEAT_VARTABS
2025 tab_len = tabstop_padding(vcol_adjusted,
2026 wp->w_buffer->b_p_ts,
2027 wp->w_buffer->b_p_vts_array) - 1;
2028#else
2029 tab_len = (int)wp->w_buffer->b_p_ts
2030 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2031#endif
2032
2033#ifdef FEAT_LINEBREAK
2034 if (!wp->w_p_lbr || !wp->w_p_list)
2035#endif
2036 // tab amount depends on current column
2037 n_extra = tab_len;
2038#ifdef FEAT_LINEBREAK
2039 else
2040 {
2041 char_u *p;
2042 int len;
2043 int i;
2044 int saved_nextra = n_extra;
2045
2046#ifdef FEAT_CONCEAL
2047 if (vcol_off > 0)
2048 // there are characters to conceal
2049 tab_len += vcol_off;
2050 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2051 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2052 && n_extra > tab_len)
2053 tab_len += n_extra - tab_len;
2054#endif
2055
2056 // if n_extra > 0, it gives the number of chars, to
2057 // use for a tab, else we need to calculate the width
2058 // for a tab
2059 len = (tab_len * mb_char2len(lcs_tab2));
2060 if (n_extra > 0)
2061 len += n_extra - tab_len;
2062 c = lcs_tab1;
2063 p = alloc(len + 1);
2064 vim_memset(p, ' ', len);
2065 p[len] = NUL;
2066 vim_free(p_extra_free);
2067 p_extra_free = p;
2068 for (i = 0; i < tab_len; i++)
2069 {
2070 int lcs = lcs_tab2;
2071
2072 if (*p == NUL)
2073 {
2074 tab_len = i;
2075 break;
2076 }
2077
2078 // if lcs_tab3 is given, need to change the char
2079 // for tab
2080 if (lcs_tab3 && i == tab_len - 1)
2081 lcs = lcs_tab3;
2082 mb_char2bytes(lcs, p);
2083 p += mb_char2len(lcs);
2084 n_extra += mb_char2len(lcs)
2085 - (saved_nextra > 0 ? 1 : 0);
2086 }
2087 p_extra = p_extra_free;
2088#ifdef FEAT_CONCEAL
2089 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2090 // macro below, so need to adjust for that here
2091 if (vcol_off > 0)
2092 n_extra -= vcol_off;
2093#endif
2094 }
2095#endif
2096#ifdef FEAT_CONCEAL
2097 {
2098 int vc_saved = vcol_off;
2099
2100 // Tab alignment should be identical regardless of
2101 // 'conceallevel' value. So tab compensates of all
2102 // previous concealed characters, and thus resets
2103 // vcol_off and boguscols accumulated so far in the
2104 // line. Note that the tab can be longer than
2105 // 'tabstop' when there are concealed characters.
2106 FIX_FOR_BOGUSCOLS;
2107
2108 // Make sure, the highlighting for the tab char will be
2109 // correctly set further below (effectively reverts the
2110 // FIX_FOR_BOGSUCOLS macro
2111 if (n_extra == tab_len + vc_saved && wp->w_p_list
2112 && lcs_tab1)
2113 tab_len += vc_saved;
2114 }
2115#endif
2116 mb_utf8 = FALSE; // don't draw as UTF-8
2117 if (wp->w_p_list)
2118 {
2119 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2120#ifdef FEAT_LINEBREAK
2121 if (wp->w_p_lbr)
2122 c_extra = NUL; // using p_extra from above
2123 else
2124#endif
2125 c_extra = lcs_tab2;
2126 c_final = lcs_tab3;
2127 n_attr = tab_len + 1;
2128 extra_attr = HL_ATTR(HLF_8);
2129 saved_attr2 = char_attr; // save current attr
2130 mb_c = c;
2131 if (enc_utf8 && utf_char2len(c) > 1)
2132 {
2133 mb_utf8 = TRUE;
2134 u8cc[0] = 0;
2135 c = 0xc0;
2136 }
2137 }
2138 else
2139 {
2140 c_final = NUL;
2141 c_extra = ' ';
2142 c = ' ';
2143 }
2144 }
2145 else if (c == NUL
2146 && (wp->w_p_list
2147 || ((fromcol >= 0 || fromcol_prev >= 0)
2148 && tocol > vcol
2149 && VIsual_mode != Ctrl_V
2150 && (
2151# ifdef FEAT_RIGHTLEFT
2152 wp->w_p_rl ? (col >= 0) :
2153# endif
2154 (col < wp->w_width))
2155 && !(noinvcur
2156 && lnum == wp->w_cursor.lnum
2157 && (colnr_T)vcol == wp->w_virtcol)))
2158 && lcs_eol_one > 0)
2159 {
2160 // Display a '$' after the line or highlight an extra
2161 // character if the line break is included.
2162#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2163 // For a diff line the highlighting continues after the
2164 // "$".
2165 if (
2166# ifdef FEAT_DIFF
2167 diff_hlf == (hlf_T)0
2168# ifdef LINE_ATTR
2169 &&
2170# endif
2171# endif
2172# ifdef LINE_ATTR
2173 line_attr == 0
2174# endif
2175 )
2176#endif
2177 {
2178 // In virtualedit, visual selections may extend
2179 // beyond end of line.
2180 if (area_highlighting && virtual_active()
2181 && tocol != MAXCOL && vcol < tocol)
2182 n_extra = 0;
2183 else
2184 {
2185 p_extra = at_end_str;
2186 n_extra = 1;
2187 c_extra = NUL;
2188 c_final = NUL;
2189 }
2190 }
2191 if (wp->w_p_list && lcs_eol > 0)
2192 c = lcs_eol;
2193 else
2194 c = ' ';
2195 lcs_eol_one = -1;
2196 --ptr; // put it back at the NUL
2197 if (!attr_pri)
2198 {
2199 extra_attr = HL_ATTR(HLF_AT);
2200 n_attr = 1;
2201 }
2202 mb_c = c;
2203 if (enc_utf8 && utf_char2len(c) > 1)
2204 {
2205 mb_utf8 = TRUE;
2206 u8cc[0] = 0;
2207 c = 0xc0;
2208 }
2209 else
2210 mb_utf8 = FALSE; // don't draw as UTF-8
2211 }
2212 else if (c != NUL)
2213 {
2214 p_extra = transchar(c);
2215 if (n_extra == 0)
2216 n_extra = byte2cells(c) - 1;
2217#ifdef FEAT_RIGHTLEFT
2218 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2219 rl_mirror(p_extra); // reverse "<12>"
2220#endif
2221 c_extra = NUL;
2222 c_final = NUL;
2223#ifdef FEAT_LINEBREAK
2224 if (wp->w_p_lbr)
2225 {
2226 char_u *p;
2227
2228 c = *p_extra;
2229 p = alloc(n_extra + 1);
2230 vim_memset(p, ' ', n_extra);
2231 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2232 p[n_extra] = NUL;
2233 vim_free(p_extra_free);
2234 p_extra_free = p_extra = p;
2235 }
2236 else
2237#endif
2238 {
2239 n_extra = byte2cells(c) - 1;
2240 c = *p_extra++;
2241 }
2242 if (!attr_pri)
2243 {
2244 n_attr = n_extra + 1;
2245 extra_attr = HL_ATTR(HLF_8);
2246 saved_attr2 = char_attr; // save current attr
2247 }
2248 mb_utf8 = FALSE; // don't draw as UTF-8
2249 }
2250 else if (VIsual_active
2251 && (VIsual_mode == Ctrl_V
2252 || VIsual_mode == 'v')
2253 && virtual_active()
2254 && tocol != MAXCOL
2255 && vcol < tocol
2256 && (
2257#ifdef FEAT_RIGHTLEFT
2258 wp->w_p_rl ? (col >= 0) :
2259#endif
2260 (col < wp->w_width)))
2261 {
2262 c = ' ';
2263 --ptr; // put it back at the NUL
2264 }
2265#if defined(LINE_ATTR)
2266 else if ((
2267# ifdef FEAT_DIFF
2268 diff_hlf != (hlf_T)0 ||
2269# endif
2270# ifdef FEAT_TERMINAL
2271 win_attr != 0 ||
2272# endif
2273 line_attr != 0
2274 ) && (
2275# ifdef FEAT_RIGHTLEFT
2276 wp->w_p_rl ? (col >= 0) :
2277# endif
2278 (col
2279# ifdef FEAT_CONCEAL
2280 - boguscols
2281# endif
2282 < wp->w_width)))
2283 {
2284 // Highlight until the right side of the window
2285 c = ' ';
2286 --ptr; // put it back at the NUL
2287
2288 // Remember we do the char for line highlighting.
2289 ++did_line_attr;
2290
2291 // don't do search HL for the rest of the line
2292 if (line_attr != 0 && char_attr == search_attr
2293 && (did_line_attr > 1
2294 || (wp->w_p_list && lcs_eol > 0)))
2295 char_attr = line_attr;
2296# ifdef FEAT_DIFF
2297 if (diff_hlf == HLF_TXD)
2298 {
2299 diff_hlf = HLF_CHD;
2300 if (vi_attr == 0 || char_attr != vi_attr)
2301 {
2302 char_attr = HL_ATTR(diff_hlf);
2303 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2304 && wp->w_p_culopt_flags != CULOPT_NBR
2305 && (!cul_screenline
2306 || (vcol >= left_curline_col
2307 && vcol <= right_curline_col)))
2308 char_attr = hl_combine_attr(
2309 char_attr, HL_ATTR(HLF_CUL));
2310 }
2311 }
2312# endif
2313# ifdef FEAT_TERMINAL
2314 if (win_attr != 0)
2315 {
2316 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002317 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2318 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002319 {
2320 if (!cul_screenline || (vcol >= left_curline_col
2321 && vcol <= right_curline_col))
2322 char_attr = hl_combine_attr(
2323 char_attr, HL_ATTR(HLF_CUL));
2324 }
2325 else if (line_attr)
2326 char_attr = hl_combine_attr(char_attr, line_attr);
2327 }
2328# endif
2329 }
2330#endif
2331 }
2332
2333#ifdef FEAT_CONCEAL
2334 if ( wp->w_p_cole > 0
2335 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2336 conceal_cursor_line(wp))
2337 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2338 && !(lnum_in_visual_area
2339 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2340 {
2341 char_attr = conceal_attr;
2342 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
2343 && (syn_get_sub_char() != NUL || match_conc
2344 || wp->w_p_cole == 1)
2345 && wp->w_p_cole != 3)
2346 {
2347 // First time at this concealed item: display one
2348 // character.
2349 if (match_conc)
2350 c = match_conc;
2351 else if (syn_get_sub_char() != NUL)
2352 c = syn_get_sub_char();
2353 else if (lcs_conceal != NUL)
2354 c = lcs_conceal;
2355 else
2356 c = ' ';
2357
2358 prev_syntax_id = syntax_seqnr;
2359
2360 if (n_extra > 0)
2361 vcol_off += n_extra;
2362 vcol += n_extra;
2363 if (wp->w_p_wrap && n_extra > 0)
2364 {
2365# ifdef FEAT_RIGHTLEFT
2366 if (wp->w_p_rl)
2367 {
2368 col -= n_extra;
2369 boguscols -= n_extra;
2370 }
2371 else
2372# endif
2373 {
2374 boguscols += n_extra;
2375 col += n_extra;
2376 }
2377 }
2378 n_extra = 0;
2379 n_attr = 0;
2380 }
2381 else if (n_skip == 0)
2382 {
2383 is_concealing = TRUE;
2384 n_skip = 1;
2385 }
2386 mb_c = c;
2387 if (enc_utf8 && utf_char2len(c) > 1)
2388 {
2389 mb_utf8 = TRUE;
2390 u8cc[0] = 0;
2391 c = 0xc0;
2392 }
2393 else
2394 mb_utf8 = FALSE; // don't draw as UTF-8
2395 }
2396 else
2397 {
2398 prev_syntax_id = 0;
2399 is_concealing = FALSE;
2400 }
2401
2402 if (n_skip > 0 && did_decrement_ptr)
2403 // not showing the '>', put pointer back to avoid getting stuck
2404 ++ptr;
2405
2406#endif // FEAT_CONCEAL
2407 }
2408
2409#ifdef FEAT_CONCEAL
2410 // In the cursor line and we may be concealing characters: correct
2411 // the cursor column when we reach its position.
2412 if (!did_wcol && draw_state == WL_LINE
2413 && wp == curwin && lnum == wp->w_cursor.lnum
2414 && conceal_cursor_line(wp)
2415 && (int)wp->w_virtcol <= vcol + n_skip)
2416 {
2417# ifdef FEAT_RIGHTLEFT
2418 if (wp->w_p_rl)
2419 wp->w_wcol = wp->w_width - col + boguscols - 1;
2420 else
2421# endif
2422 wp->w_wcol = col - boguscols;
2423 wp->w_wrow = row;
2424 did_wcol = TRUE;
2425 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
2426 }
2427#endif
2428
2429 // Don't override visual selection highlighting.
2430 if (n_attr > 0
2431 && draw_state == WL_LINE
2432 && !attr_pri)
2433 {
2434#ifdef LINE_ATTR
2435 if (line_attr)
2436 char_attr = hl_combine_attr(extra_attr, line_attr);
2437 else
2438#endif
2439 char_attr = extra_attr;
2440 }
2441
2442#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2443 // XIM don't send preedit_start and preedit_end, but they send
2444 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2445 // im_is_preediting() here.
2446 if (p_imst == IM_ON_THE_SPOT
2447 && xic != NULL
2448 && lnum == wp->w_cursor.lnum
2449 && (State & INSERT)
2450 && !p_imdisable
2451 && im_is_preediting()
2452 && draw_state == WL_LINE)
2453 {
2454 colnr_T tcol;
2455
2456 if (preedit_end_col == MAXCOL)
2457 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2458 else
2459 tcol = preedit_end_col;
2460 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2461 {
2462 if (feedback_old_attr < 0)
2463 {
2464 feedback_col = 0;
2465 feedback_old_attr = char_attr;
2466 }
2467 char_attr = im_get_feedback_attr(feedback_col);
2468 if (char_attr < 0)
2469 char_attr = feedback_old_attr;
2470 feedback_col++;
2471 }
2472 else if (feedback_old_attr >= 0)
2473 {
2474 char_attr = feedback_old_attr;
2475 feedback_old_attr = -1;
2476 feedback_col = 0;
2477 }
2478 }
2479#endif
2480 // Handle the case where we are in column 0 but not on the first
2481 // character of the line and the user wants us to show us a
2482 // special character (via 'listchars' option "precedes:<char>".
2483 if (lcs_prec_todo != NUL
2484 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002485 && (wp->w_p_wrap ?
2486 (wp->w_skipcol > 0 && row == 0) :
2487 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488#ifdef FEAT_DIFF
2489 && filler_todo <= 0
2490#endif
2491 && draw_state > WL_NR
2492 && c != NUL)
2493 {
2494 c = lcs_prec;
2495 lcs_prec_todo = NUL;
2496 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2497 {
2498 // Double-width character being overwritten by the "precedes"
2499 // character, need to fill up half the character.
2500 c_extra = MB_FILLER_CHAR;
2501 c_final = NUL;
2502 n_extra = 1;
2503 n_attr = 2;
2504 extra_attr = HL_ATTR(HLF_AT);
2505 }
2506 mb_c = c;
2507 if (enc_utf8 && utf_char2len(c) > 1)
2508 {
2509 mb_utf8 = TRUE;
2510 u8cc[0] = 0;
2511 c = 0xc0;
2512 }
2513 else
2514 mb_utf8 = FALSE; // don't draw as UTF-8
2515 if (!attr_pri)
2516 {
2517 saved_attr3 = char_attr; // save current attr
2518 char_attr = HL_ATTR(HLF_AT); // later copied to char_attr
2519 n_attr3 = 1;
2520 }
2521 }
2522
2523 // At end of the text line or just after the last character.
2524 if ((c == NUL
2525#if defined(LINE_ATTR)
2526 || did_line_attr == 1
2527#endif
2528 ) && eol_hl_off == 0)
2529 {
2530#ifdef FEAT_SEARCH_EXTRA
2531 // flag to indicate whether prevcol equals startcol of search_hl or
2532 // one of the matches
2533 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2534 (long)(ptr - line) - (c == NUL));
2535#endif
2536 // Invert at least one char, used for Visual and empty line or
2537 // highlight match at end of line. If it's beyond the last
2538 // char on the screen, just overwrite that one (tricky!) Not
2539 // needed when a '$' was displayed for 'list'.
2540 if (lcs_eol == lcs_eol_one
2541 && ((area_attr != 0 && vcol == fromcol
2542 && (VIsual_mode != Ctrl_V
2543 || lnum == VIsual.lnum
2544 || lnum == curwin->w_cursor.lnum)
2545 && c == NUL)
2546#ifdef FEAT_SEARCH_EXTRA
2547 // highlight 'hlsearch' match at end of line
2548 || (prevcol_hl_flag
2549# ifdef FEAT_SYN_HL
2550 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2551 && !(wp == curwin && VIsual_active))
2552# endif
2553# ifdef FEAT_DIFF
2554 && diff_hlf == (hlf_T)0
2555# endif
2556# if defined(LINE_ATTR)
2557 && did_line_attr <= 1
2558# endif
2559 )
2560#endif
2561 ))
2562 {
2563 int n = 0;
2564
2565#ifdef FEAT_RIGHTLEFT
2566 if (wp->w_p_rl)
2567 {
2568 if (col < 0)
2569 n = 1;
2570 }
2571 else
2572#endif
2573 {
2574 if (col >= wp->w_width)
2575 n = -1;
2576 }
2577 if (n != 0)
2578 {
2579 // At the window boundary, highlight the last character
2580 // instead (better than nothing).
2581 off += n;
2582 col += n;
2583 }
2584 else
2585 {
2586 // Add a blank character to highlight.
2587 ScreenLines[off] = ' ';
2588 if (enc_utf8)
2589 ScreenLinesUC[off] = 0;
2590 }
2591#ifdef FEAT_SEARCH_EXTRA
2592 if (area_attr == 0)
2593 {
2594 // Use attributes from match with highest priority among
2595 // 'search_hl' and the match list.
2596 get_search_match_hl(wp, &screen_search_hl,
2597 (long)(ptr - line), &char_attr);
2598 }
2599#endif
2600 ScreenAttrs[off] = char_attr;
2601#ifdef FEAT_RIGHTLEFT
2602 if (wp->w_p_rl)
2603 {
2604 --col;
2605 --off;
2606 }
2607 else
2608#endif
2609 {
2610 ++col;
2611 ++off;
2612 }
2613 ++vcol;
2614 eol_hl_off = 1;
2615 }
2616 }
2617
2618 // At end of the text line.
2619 if (c == NUL)
2620 {
2621#ifdef FEAT_SYN_HL
2622 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2623 if (wp->w_p_wrap)
2624 v = wp->w_skipcol;
2625 else
2626 v = wp->w_leftcol;
2627
2628 // check if line ends before left margin
2629 if (vcol < v + col - win_col_off(wp))
2630 vcol = v + col - win_col_off(wp);
2631#ifdef FEAT_CONCEAL
2632 // Get rid of the boguscols now, we want to draw until the right
2633 // edge for 'cursorcolumn'.
2634 col -= boguscols;
2635 boguscols = 0;
2636#endif
2637
2638 if (draw_color_col)
2639 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2640
2641 if (((wp->w_p_cuc
2642 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2643 && (int)wp->w_virtcol <
2644 wp->w_width * (row - startrow + 1) + v
2645 && lnum != wp->w_cursor.lnum)
2646 || draw_color_col
2647 || win_attr != 0)
2648# ifdef FEAT_RIGHTLEFT
2649 && !wp->w_p_rl
2650# endif
2651 )
2652 {
2653 int rightmost_vcol = 0;
2654 int i;
2655
2656 if (wp->w_p_cuc)
2657 rightmost_vcol = wp->w_virtcol;
2658 if (draw_color_col)
2659 // determine rightmost colorcolumn to possibly draw
2660 for (i = 0; color_cols[i] >= 0; ++i)
2661 if (rightmost_vcol < color_cols[i])
2662 rightmost_vcol = color_cols[i];
2663
2664 while (col < wp->w_width)
2665 {
2666 ScreenLines[off] = ' ';
2667 if (enc_utf8)
2668 ScreenLinesUC[off] = 0;
2669 ++col;
2670 if (draw_color_col)
2671 draw_color_col = advance_color_col(VCOL_HLC,
2672 &color_cols);
2673
2674 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2675 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2676 else if (draw_color_col && VCOL_HLC == *color_cols)
2677 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2678 else
2679 ScreenAttrs[off++] = win_attr;
2680
2681 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2682 break;
2683
2684 ++vcol;
2685 }
2686 }
2687#endif
2688
2689 screen_line(screen_row, wp->w_wincol, col,
2690 (int)wp->w_width, screen_line_flags);
2691 row++;
2692
2693 // Update w_cline_height and w_cline_folded if the cursor line was
2694 // updated (saves a call to plines() later).
2695 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2696 {
2697 curwin->w_cline_row = startrow;
2698 curwin->w_cline_height = row - startrow;
2699#ifdef FEAT_FOLDING
2700 curwin->w_cline_folded = FALSE;
2701#endif
2702 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2703 }
2704
2705 break;
2706 }
2707
2708 // Show "extends" character from 'listchars' if beyond the line end and
2709 // 'list' is set.
2710 if (lcs_ext != NUL
2711 && wp->w_p_list
2712 && !wp->w_p_wrap
2713#ifdef FEAT_DIFF
2714 && filler_todo <= 0
2715#endif
2716 && (
2717#ifdef FEAT_RIGHTLEFT
2718 wp->w_p_rl ? col == 0 :
2719#endif
2720 col == wp->w_width - 1)
2721 && (*ptr != NUL
2722 || (wp->w_p_list && lcs_eol_one > 0)
2723 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2724 {
2725 c = lcs_ext;
2726 char_attr = HL_ATTR(HLF_AT);
2727 mb_c = c;
2728 if (enc_utf8 && utf_char2len(c) > 1)
2729 {
2730 mb_utf8 = TRUE;
2731 u8cc[0] = 0;
2732 c = 0xc0;
2733 }
2734 else
2735 mb_utf8 = FALSE;
2736 }
2737
2738#ifdef FEAT_SYN_HL
2739 // advance to the next 'colorcolumn'
2740 if (draw_color_col)
2741 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2742
2743 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2744 // highlight the cursor position itself.
2745 // Also highlight the 'colorcolumn' if it is different than
2746 // 'cursorcolumn'
2747 vcol_save_attr = -1;
2748 if (draw_state == WL_LINE && !lnum_in_visual_area
2749 && search_attr == 0 && area_attr == 0)
2750 {
2751 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2752 && lnum != wp->w_cursor.lnum)
2753 {
2754 vcol_save_attr = char_attr;
2755 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2756 }
2757 else if (draw_color_col && VCOL_HLC == *color_cols)
2758 {
2759 vcol_save_attr = char_attr;
2760 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2761 }
2762 }
2763#endif
2764
2765 // Store character to be displayed.
2766 // Skip characters that are left of the screen for 'nowrap'.
2767 vcol_prev = vcol;
2768 if (draw_state < WL_LINE || n_skip <= 0)
2769 {
2770 // Store the character.
2771#if defined(FEAT_RIGHTLEFT)
2772 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2773 {
2774 // A double-wide character is: put first halve in left cell.
2775 --off;
2776 --col;
2777 }
2778#endif
2779 ScreenLines[off] = c;
2780 if (enc_dbcs == DBCS_JPNU)
2781 {
2782 if ((mb_c & 0xff00) == 0x8e00)
2783 ScreenLines[off] = 0x8e;
2784 ScreenLines2[off] = mb_c & 0xff;
2785 }
2786 else if (enc_utf8)
2787 {
2788 if (mb_utf8)
2789 {
2790 int i;
2791
2792 ScreenLinesUC[off] = mb_c;
2793 if ((c & 0xff) == 0)
2794 ScreenLines[off] = 0x80; // avoid storing zero
2795 for (i = 0; i < Screen_mco; ++i)
2796 {
2797 ScreenLinesC[i][off] = u8cc[i];
2798 if (u8cc[i] == 0)
2799 break;
2800 }
2801 }
2802 else
2803 ScreenLinesUC[off] = 0;
2804 }
2805 if (multi_attr)
2806 {
2807 ScreenAttrs[off] = multi_attr;
2808 multi_attr = 0;
2809 }
2810 else
2811 ScreenAttrs[off] = char_attr;
2812
2813 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2814 {
2815 // Need to fill two screen columns.
2816 ++off;
2817 ++col;
2818 if (enc_utf8)
2819 // UTF-8: Put a 0 in the second screen char.
2820 ScreenLines[off] = 0;
2821 else
2822 // DBCS: Put second byte in the second screen char.
2823 ScreenLines[off] = mb_c & 0xff;
2824 if (draw_state > WL_NR
2825#ifdef FEAT_DIFF
2826 && filler_todo <= 0
2827#endif
2828 )
2829 ++vcol;
2830 // When "tocol" is halfway a character, set it to the end of
2831 // the character, otherwise highlighting won't stop.
2832 if (tocol == vcol)
2833 ++tocol;
2834#ifdef FEAT_RIGHTLEFT
2835 if (wp->w_p_rl)
2836 {
2837 // now it's time to backup one cell
2838 --off;
2839 --col;
2840 }
2841#endif
2842 }
2843#ifdef FEAT_RIGHTLEFT
2844 if (wp->w_p_rl)
2845 {
2846 --off;
2847 --col;
2848 }
2849 else
2850#endif
2851 {
2852 ++off;
2853 ++col;
2854 }
2855 }
2856#ifdef FEAT_CONCEAL
2857 else if (wp->w_p_cole > 0 && is_concealing)
2858 {
2859 --n_skip;
2860 ++vcol_off;
2861 if (n_extra > 0)
2862 vcol_off += n_extra;
2863 if (wp->w_p_wrap)
2864 {
2865 // Special voodoo required if 'wrap' is on.
2866 //
2867 // Advance the column indicator to force the line
2868 // drawing to wrap early. This will make the line
2869 // take up the same screen space when parts are concealed,
2870 // so that cursor line computations aren't messed up.
2871 //
2872 // To avoid the fictitious advance of 'col' causing
2873 // trailing junk to be written out of the screen line
2874 // we are building, 'boguscols' keeps track of the number
2875 // of bad columns we have advanced.
2876 if (n_extra > 0)
2877 {
2878 vcol += n_extra;
2879# ifdef FEAT_RIGHTLEFT
2880 if (wp->w_p_rl)
2881 {
2882 col -= n_extra;
2883 boguscols -= n_extra;
2884 }
2885 else
2886# endif
2887 {
2888 col += n_extra;
2889 boguscols += n_extra;
2890 }
2891 n_extra = 0;
2892 n_attr = 0;
2893 }
2894
2895
2896 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2897 {
2898 // Need to fill two screen columns.
2899# ifdef FEAT_RIGHTLEFT
2900 if (wp->w_p_rl)
2901 {
2902 --boguscols;
2903 --col;
2904 }
2905 else
2906# endif
2907 {
2908 ++boguscols;
2909 ++col;
2910 }
2911 }
2912
2913# ifdef FEAT_RIGHTLEFT
2914 if (wp->w_p_rl)
2915 {
2916 --boguscols;
2917 --col;
2918 }
2919 else
2920# endif
2921 {
2922 ++boguscols;
2923 ++col;
2924 }
2925 }
2926 else
2927 {
2928 if (n_extra > 0)
2929 {
2930 vcol += n_extra;
2931 n_extra = 0;
2932 n_attr = 0;
2933 }
2934 }
2935
2936 }
2937#endif // FEAT_CONCEAL
2938 else
2939 --n_skip;
2940
2941 // Only advance the "vcol" when after the 'number' or 'relativenumber'
2942 // column.
2943 if (draw_state > WL_NR
2944#ifdef FEAT_DIFF
2945 && filler_todo <= 0
2946#endif
2947 )
2948 ++vcol;
2949
2950#ifdef FEAT_SYN_HL
2951 if (vcol_save_attr >= 0)
2952 char_attr = vcol_save_attr;
2953#endif
2954
2955 // restore attributes after "predeces" in 'listchars'
2956 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
2957 char_attr = saved_attr3;
2958
2959 // restore attributes after last 'listchars' or 'number' char
2960 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
2961 char_attr = saved_attr2;
2962
2963 // At end of screen line and there is more to come: Display the line
2964 // so far. If there is no more to display it is caught above.
2965 if ((
2966#ifdef FEAT_RIGHTLEFT
2967 wp->w_p_rl ? (col < 0) :
2968#endif
2969 (col >= wp->w_width))
2970 && (*ptr != NUL
2971#ifdef FEAT_DIFF
2972 || filler_todo > 0
2973#endif
2974 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
2975 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
2976 )
2977 {
2978#ifdef FEAT_CONCEAL
2979 screen_line(screen_row, wp->w_wincol, col - boguscols,
2980 (int)wp->w_width, screen_line_flags);
2981 boguscols = 0;
2982#else
2983 screen_line(screen_row, wp->w_wincol, col,
2984 (int)wp->w_width, screen_line_flags);
2985#endif
2986 ++row;
2987 ++screen_row;
2988
2989 // When not wrapping and finished diff lines, or when displayed
2990 // '$' and highlighting until last column, break here.
2991 if ((!wp->w_p_wrap
2992#ifdef FEAT_DIFF
2993 && filler_todo <= 0
2994#endif
2995 ) || lcs_eol_one == -1)
2996 break;
2997
2998 // When the window is too narrow draw all "@" lines.
2999 if (draw_state != WL_LINE
3000#ifdef FEAT_DIFF
3001 && filler_todo <= 0
3002#endif
3003 )
3004 {
3005 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3006 draw_vsep_win(wp, row);
3007 row = endrow;
3008 }
3009
3010 // When line got too long for screen break here.
3011 if (row == endrow)
3012 {
3013 ++row;
3014 break;
3015 }
3016
3017 if (screen_cur_row == screen_row - 1
3018#ifdef FEAT_DIFF
3019 && filler_todo <= 0
3020#endif
3021 && wp->w_width == Columns)
3022 {
3023 // Remember that the line wraps, used for modeless copy.
3024 LineWraps[screen_row - 1] = TRUE;
3025
3026 // Special trick to make copy/paste of wrapped lines work with
3027 // xterm/screen: write an extra character beyond the end of
3028 // the line. This will work with all terminal types
3029 // (regardless of the xn,am settings).
3030 // Only do this on a fast tty.
3031 // Only do this if the cursor is on the current line
3032 // (something has been written in it).
3033 // Don't do this for the GUI.
3034 // Don't do this for double-width characters.
3035 // Don't do this for a window not at the right screen border.
3036 if (p_tf
3037#ifdef FEAT_GUI
3038 && !gui.in_use
3039#endif
3040 && !(has_mbyte
3041 && ((*mb_off2cells)(LineOffset[screen_row],
3042 LineOffset[screen_row] + screen_Columns)
3043 == 2
3044 || (*mb_off2cells)(LineOffset[screen_row - 1]
3045 + (int)Columns - 2,
3046 LineOffset[screen_row] + screen_Columns)
3047 == 2)))
3048 {
3049 // First make sure we are at the end of the screen line,
3050 // then output the same character again to let the
3051 // terminal know about the wrap. If the terminal doesn't
3052 // auto-wrap, we overwrite the character.
3053 if (screen_cur_col != wp->w_width)
3054 screen_char(LineOffset[screen_row - 1]
3055 + (unsigned)Columns - 1,
3056 screen_row - 1, (int)(Columns - 1));
3057
3058 // When there is a multi-byte character, just output a
3059 // space to keep it simple.
3060 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3061 screen_row - 1] + (Columns - 1)]) > 1)
3062 out_char(' ');
3063 else
3064 out_char(ScreenLines[LineOffset[screen_row - 1]
3065 + (Columns - 1)]);
3066 // force a redraw of the first char on the next line
3067 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3068 screen_start(); // don't know where cursor is now
3069 }
3070 }
3071
3072 col = 0;
3073 off = (unsigned)(current_ScreenLine - ScreenLines);
3074#ifdef FEAT_RIGHTLEFT
3075 if (wp->w_p_rl)
3076 {
3077 col = wp->w_width - 1; // col is not used if breaking!
3078 off += col;
3079 }
3080#endif
3081
3082 // reset the drawing state for the start of a wrapped line
3083 draw_state = WL_START;
3084 saved_n_extra = n_extra;
3085 saved_p_extra = p_extra;
3086 saved_c_extra = c_extra;
3087 saved_c_final = c_final;
3088#ifdef FEAT_SYN_HL
3089 if (!(cul_screenline
3090# ifdef FEAT_DIFF
3091 && diff_hlf == (hlf_T)0)
3092# endif
3093 )
3094 saved_char_attr = char_attr;
3095 else
3096#endif
3097 saved_char_attr = 0;
3098 n_extra = 0;
3099 lcs_prec_todo = lcs_prec;
3100#ifdef FEAT_LINEBREAK
3101# ifdef FEAT_DIFF
3102 if (filler_todo <= 0)
3103# endif
3104 need_showbreak = TRUE;
3105#endif
3106#ifdef FEAT_DIFF
3107 --filler_todo;
3108 // When the filler lines are actually below the last line of the
3109 // file, don't draw the line itself, break here.
3110 if (filler_todo == 0 && wp->w_botfill)
3111 break;
3112#endif
3113 }
3114
3115 } // for every character in the line
3116
3117#ifdef FEAT_SPELL
3118 // After an empty line check first word for capital.
3119 if (*skipwhite(line) == NUL)
3120 {
3121 capcol_lnum = lnum + 1;
3122 cap_col = 0;
3123 }
3124#endif
3125#ifdef FEAT_TEXT_PROP
3126 vim_free(text_props);
3127 vim_free(text_prop_idxs);
3128#endif
3129
3130 vim_free(p_extra_free);
3131 return row;
3132}
3133