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