blob: b5814114b6e2428d67d8d82b983b036c8b86930c [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
78#ifdef FEAT_SIGNS
79/*
80 * Get information needed to display the sign in line 'lnum' in window 'wp'.
81 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
82 * Otherwise the sign is going to be displayed in the sign column.
83 */
84 static void
85get_sign_display_info(
86 int nrcol,
87 win_T *wp,
88 linenr_T lnum UNUSED,
89 sign_attrs_T *sattr,
90 int wcr_attr,
91 int row,
92 int startrow,
93 int filler_lines UNUSED,
94 int filler_todo UNUSED,
95 int *c_extrap,
96 int *c_finalp,
97 char_u *extra,
98 char_u **pp_extra,
99 int *n_extrap,
100 int *char_attrp)
101{
102 int text_sign;
103# ifdef FEAT_SIGN_ICONS
104 int icon_sign;
105# endif
106
107 // Draw two cells with the sign value or blank.
108 *c_extrap = ' ';
109 *c_finalp = NUL;
110 if (nrcol)
111 *n_extrap = number_width(wp) + 1;
112 else
113 {
114 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
115 *n_extrap = 2;
116 }
117
118 if (row == startrow
119#ifdef FEAT_DIFF
120 + filler_lines && filler_todo <= 0
121#endif
122 )
123 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200124 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200125# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200126 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200127 if (gui.in_use && icon_sign != 0)
128 {
129 // Use the image in this position.
130 if (nrcol)
131 {
132 *c_extrap = NUL;
133 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
134 *pp_extra = extra;
135 *n_extrap = (int)STRLEN(*pp_extra);
136 }
137 else
138 *c_extrap = SIGN_BYTE;
139# ifdef FEAT_NETBEANS_INTG
140 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
141 {
142 if (nrcol)
143 {
144 *c_extrap = NUL;
145 sprintf((char *)extra, "%-*c ", number_width(wp),
146 MULTISIGN_BYTE);
147 *pp_extra = extra;
148 *n_extrap = (int)STRLEN(*pp_extra);
149 }
150 else
151 *c_extrap = MULTISIGN_BYTE;
152 }
153# endif
154 *c_finalp = NUL;
155 *char_attrp = icon_sign;
156 }
157 else
158# endif
159 if (text_sign != 0)
160 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200161 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200162 if (*pp_extra != NULL)
163 {
164 if (nrcol)
165 {
166 int n, width = number_width(wp) - 2;
167
168 for (n = 0; n < width; n++)
169 extra[n] = ' ';
170 extra[n] = 0;
171 STRCAT(extra, *pp_extra);
172 STRCAT(extra, " ");
173 *pp_extra = extra;
174 }
175 *c_extrap = NUL;
176 *c_finalp = NUL;
177 *n_extrap = (int)STRLEN(*pp_extra);
178 }
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200179 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200180 }
181 }
182}
183#endif
184
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100185#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200186static textprop_T *current_text_props = NULL;
187static buf_T *current_buf = NULL;
188
189 static int
190text_prop_compare(const void *s1, const void *s2)
191{
192 int idx1, idx2;
193 proptype_T *pt1, *pt2;
194 colnr_T col1, col2;
195
196 idx1 = *(int *)s1;
197 idx2 = *(int *)s2;
198 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
199 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
200 if (pt1 == pt2)
201 return 0;
202 if (pt1 == NULL)
203 return -1;
204 if (pt2 == NULL)
205 return 1;
206 if (pt1->pt_priority != pt2->pt_priority)
207 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
208 col1 = current_text_props[idx1].tp_col;
209 col2 = current_text_props[idx2].tp_col;
210 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
211}
212#endif
213
214/*
215 * Display line "lnum" of window 'wp' on the screen.
216 * Start at row "startrow", stop when "endrow" is reached.
217 * wp->w_virtcol needs to be valid.
218 *
219 * Return the number of last row the line occupies.
220 */
221 int
222win_line(
223 win_T *wp,
224 linenr_T lnum,
225 int startrow,
226 int endrow,
227 int nochange UNUSED, // not updating for changed text
228 int number_only) // only update the number column
229{
230 int col = 0; // visual column on screen
231 unsigned off; // offset in ScreenLines/ScreenAttrs
232 int c = 0; // init for GCC
233 long vcol = 0; // virtual column (for tabs)
234#ifdef FEAT_LINEBREAK
235 long vcol_sbr = -1; // virtual column after showbreak
236#endif
237 long vcol_prev = -1; // "vcol" of previous character
238 char_u *line; // current line
239 char_u *ptr; // current position in "line"
240 int row; // row in the window, excl w_winrow
241 int screen_row; // row on the screen, incl w_winrow
242
243 char_u extra[21]; // "%ld " and 'fdc' must fit in here
244 int n_extra = 0; // number of extra chars
245 char_u *p_extra = NULL; // string of extra chars, plus NUL
246 char_u *p_extra_free = NULL; // p_extra needs to be freed
247 int c_extra = NUL; // extra chars, all the same
248 int c_final = NUL; // final char, mandatory if set
249 int extra_attr = 0; // attributes when n_extra != 0
250 static char_u *at_end_str = (char_u *)""; // used for p_extra when
251 // displaying lcs_eol at end-of-line
252 int lcs_eol_one = lcs_eol; // lcs_eol until it's been used
253 int lcs_prec_todo = lcs_prec; // lcs_prec until it's been used
254
255 // saved "extra" items for when draw_state becomes WL_LINE (again)
256 int saved_n_extra = 0;
257 char_u *saved_p_extra = NULL;
258 int saved_c_extra = 0;
259 int saved_c_final = 0;
260 int saved_char_attr = 0;
261
262 int n_attr = 0; // chars with special attr
263 int saved_attr2 = 0; // char_attr saved for n_attr
264 int n_attr3 = 0; // chars with overruling special attr
265 int saved_attr3 = 0; // char_attr saved for n_attr3
266
267 int n_skip = 0; // nr of chars to skip for 'nowrap'
268
269 int fromcol = -10; // start of inverting
270 int tocol = MAXCOL; // end of inverting
271 int fromcol_prev = -2; // start of inverting after cursor
272 int noinvcur = FALSE; // don't invert the cursor
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
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100300#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200301 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;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100494 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200495 }
496#endif
497
498#ifdef FEAT_SPELL
499 if (wp->w_p_spell
500 && *wp->w_s->b_p_spl != NUL
501 && wp->w_s->b_langp.ga_len > 0
502 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
503 {
504 // Prepare for spell checking.
505 has_spell = TRUE;
506 extra_check = TRUE;
507
508 // Get the start of the next line, so that words that wrap to the
509 // next line are found too: "et<line-break>al.".
510 // Trick: skip a few chars for C/shell/Vim comments
511 nextline[SPWORDLEN] = NUL;
512 if (lnum < wp->w_buffer->b_ml.ml_line_count)
513 {
514 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
515 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
516 }
517
518 // When a word wrapped from the previous line the start of the
519 // current line is valid.
520 if (lnum == checked_lnum)
521 cur_checked_col = checked_col;
522 checked_lnum = 0;
523
524 // When there was a sentence end in the previous line may require a
525 // word starting with capital in this line. In line 1 always check
526 // the first word.
527 if (lnum != capcol_lnum)
528 cap_col = -1;
529 if (lnum == 1)
530 cap_col = 0;
531 capcol_lnum = 0;
532 }
533#endif
534
535 // handle Visual active in this window
536 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
537 {
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
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100674 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200675#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
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100755#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200756 if (WIN_IS_POPUP(wp))
757 screen_line_flags |= SLF_POPUP;
758#endif
759
760 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
761 // first character to be displayed.
762 if (wp->w_p_wrap)
763 v = wp->w_skipcol;
764 else
765 v = wp->w_leftcol;
766 if (v > 0 && !number_only)
767 {
768 char_u *prev_ptr = ptr;
769
770 while (vcol < v && *ptr != NUL)
771 {
772 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
773 vcol += c;
774 prev_ptr = ptr;
775 MB_PTR_ADV(ptr);
776 }
777
778 // When:
779 // - 'cuc' is set, or
780 // - 'colorcolumn' is set, or
781 // - 'virtualedit' is set, or
782 // - the visual mode is active,
783 // the end of the line may be before the start of the displayed part.
784 if (vcol < v && (
785#ifdef FEAT_SYN_HL
786 wp->w_p_cuc || draw_color_col ||
787#endif
788 virtual_active() ||
789 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
790 vcol = v;
791
792 // Handle a character that's not completely on the screen: Put ptr at
793 // that character but skip the first few screen characters.
794 if (vcol > v)
795 {
796 vcol -= c;
797 ptr = prev_ptr;
798 // If the character fits on the screen, don't need to skip it.
799 // Except for a TAB.
800 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
801 n_skip = v - vcol;
802 }
803
804 // Adjust for when the inverted text is before the screen,
805 // and when the start of the inverted text is before the screen.
806 if (tocol <= vcol)
807 fromcol = 0;
808 else if (fromcol >= 0 && fromcol < vcol)
809 fromcol = vcol;
810
811#ifdef FEAT_LINEBREAK
812 // When w_skipcol is non-zero, first line needs 'showbreak'
813 if (wp->w_p_wrap)
814 need_showbreak = TRUE;
815#endif
816#ifdef FEAT_SPELL
817 // When spell checking a word we need to figure out the start of the
818 // word and if it's badly spelled or not.
819 if (has_spell)
820 {
821 int len;
822 colnr_T linecol = (colnr_T)(ptr - line);
823 hlf_T spell_hlf = HLF_COUNT;
824
825 pos = wp->w_cursor;
826 wp->w_cursor.lnum = lnum;
827 wp->w_cursor.col = linecol;
828 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
829
830 // spell_move_to() may call ml_get() and make "line" invalid
831 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
832 ptr = line + linecol;
833
834 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
835 {
836 // no bad word found at line start, don't check until end of a
837 // word
838 spell_hlf = HLF_COUNT;
839 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
840 }
841 else
842 {
843 // bad word found, use attributes until end of word
844 word_end = wp->w_cursor.col + len + 1;
845
846 // Turn index into actual attributes.
847 if (spell_hlf != HLF_COUNT)
848 spell_attr = highlight_attr[spell_hlf];
849 }
850 wp->w_cursor = pos;
851
852# ifdef FEAT_SYN_HL
853 // Need to restart syntax highlighting for this line.
854 if (has_syntax)
855 syntax_start(wp, lnum);
856# endif
857 }
858#endif
859 }
860
861 // Correct highlighting for cursor that can't be disabled.
862 // Avoids having to check this for each character.
863 if (fromcol >= 0)
864 {
865 if (noinvcur)
866 {
867 if ((colnr_T)fromcol == wp->w_virtcol)
868 {
869 // highlighting starts at cursor, let it start just after the
870 // cursor
871 fromcol_prev = fromcol;
872 fromcol = -1;
873 }
874 else if ((colnr_T)fromcol < wp->w_virtcol)
875 // restart highlighting after the cursor
876 fromcol_prev = wp->w_virtcol;
877 }
878 if (fromcol >= tocol)
879 fromcol = -1;
880 }
881
882#ifdef FEAT_SEARCH_EXTRA
883 if (!number_only)
884 {
885 v = (long)(ptr - line);
886 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
887 &line, &screen_search_hl,
888 &search_attr);
889 ptr = line + v; // "line" may have been updated
890 }
891#endif
892
893#ifdef FEAT_SYN_HL
894 // Cursor line highlighting for 'cursorline' in the current window.
895 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
896 {
897 // Do not show the cursor line in the text when Visual mode is active,
898 // because it's not clear what is selected then. Do update
899 // w_last_cursorline.
900 if (!(wp == curwin && VIsual_active)
901 && wp->w_p_culopt_flags != CULOPT_NBR)
902 {
903 cul_screenline = (wp->w_p_wrap
904 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
905
906 // Only set line_attr here when "screenline" is not present in
907 // 'cursorlineopt'. Otherwise it's done later.
908 if (!cul_screenline)
909 {
910 cul_attr = HL_ATTR(HLF_CUL);
911 line_attr = cul_attr;
912 wp->w_last_cursorline = wp->w_cursor.lnum;
913 }
914 else
915 {
916 line_attr_save = line_attr;
917 wp->w_last_cursorline = 0;
918 margin_columns_win(wp, &left_curline_col, &right_curline_col);
919 }
920 area_highlighting = TRUE;
921 }
922 else
923 wp->w_last_cursorline = wp->w_cursor.lnum;
924 }
925#endif
926
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100927#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200928 {
929 char_u *prop_start;
930
931 text_prop_count = get_text_props(wp->w_buffer, lnum,
932 &prop_start, FALSE);
933 if (text_prop_count > 0)
934 {
935 // Make a copy of the properties, so that they are properly
936 // aligned.
937 text_props = ALLOC_MULT(textprop_T, text_prop_count);
938 if (text_props != NULL)
939 mch_memmove(text_props, prop_start,
940 text_prop_count * sizeof(textprop_T));
941
942 // Allocate an array for the indexes.
943 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
944 area_highlighting = TRUE;
945 extra_check = TRUE;
946 }
947 }
948#endif
949
950 off = (unsigned)(current_ScreenLine - ScreenLines);
951 col = 0;
952
953#ifdef FEAT_RIGHTLEFT
954 if (wp->w_p_rl)
955 {
956 // Rightleft window: process the text in the normal direction, but put
957 // it in current_ScreenLine[] from right to left. Start at the
958 // rightmost column of the window.
959 col = wp->w_width - 1;
960 off += col;
961 screen_line_flags |= SLF_RIGHTLEFT;
962 }
963#endif
964
965 // Repeat for the whole displayed line.
966 for (;;)
967 {
968#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
969 int has_match_conc = 0; // match wants to conceal
970#endif
971#ifdef FEAT_CONCEAL
972 int did_decrement_ptr = FALSE;
973#endif
974 // Skip this quickly when working on the text.
975 if (draw_state != WL_LINE)
976 {
977#ifdef FEAT_CMDWIN
978 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
979 {
980 draw_state = WL_CMDLINE;
981 if (cmdwin_type != 0 && wp == curwin)
982 {
983 // Draw the cmdline character.
984 n_extra = 1;
985 c_extra = cmdwin_type;
986 c_final = NUL;
987 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
988 }
989 }
990#endif
991
992#ifdef FEAT_FOLDING
993 if (draw_state == WL_FOLD - 1 && n_extra == 0)
994 {
995 int fdc = compute_foldcolumn(wp, 0);
996
997 draw_state = WL_FOLD;
998 if (fdc > 0)
999 {
1000 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1001 // already be in use.
1002 vim_free(p_extra_free);
1003 p_extra_free = alloc(12 + 1);
1004
1005 if (p_extra_free != NULL)
1006 {
1007 fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
1008 n_extra = fdc;
1009 p_extra_free[n_extra] = NUL;
1010 p_extra = p_extra_free;
1011 c_extra = NUL;
1012 c_final = NUL;
1013 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
1014 }
1015 }
1016 }
1017#endif
1018
1019#ifdef FEAT_SIGNS
1020 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1021 {
1022 draw_state = WL_SIGN;
1023 // Show the sign column when there are any signs in this
1024 // buffer or when using Netbeans.
1025 if (signcolumn_on(wp))
1026 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1027 row, startrow, filler_lines, filler_todo, &c_extra,
1028 &c_final, extra, &p_extra, &n_extra, &char_attr);
1029 }
1030#endif
1031
1032 if (draw_state == WL_NR - 1 && n_extra == 0)
1033 {
1034 draw_state = WL_NR;
1035 // Display the absolute or relative line number. After the
1036 // first fill with blanks when the 'n' flag isn't in 'cpo'
1037 if ((wp->w_p_nu || wp->w_p_rnu)
1038 && (row == startrow
1039#ifdef FEAT_DIFF
1040 + filler_lines
1041#endif
1042 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1043 {
1044#ifdef FEAT_SIGNS
1045 // If 'signcolumn' is set to 'number' and a sign is present
1046 // in 'lnum', then display the sign instead of the line
1047 // number.
1048 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1049 && sign_present)
1050 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1051 row, startrow, filler_lines, filler_todo,
1052 &c_extra, &c_final, extra, &p_extra, &n_extra,
1053 &char_attr);
1054 else
1055#endif
1056 {
1057 // Draw the line number (empty space after wrapping).
1058 if (row == startrow
1059#ifdef FEAT_DIFF
1060 + filler_lines
1061#endif
1062 )
1063 {
1064 long num;
1065 char *fmt = "%*ld ";
1066
1067 if (wp->w_p_nu && !wp->w_p_rnu)
1068 // 'number' + 'norelativenumber'
1069 num = (long)lnum;
1070 else
1071 {
1072 // 'relativenumber', don't use negative numbers
1073 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1074 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1075 {
1076 // 'number' + 'relativenumber'
1077 num = lnum;
1078 fmt = "%-*ld ";
1079 }
1080 }
1081
1082 sprintf((char *)extra, fmt,
1083 number_width(wp), num);
1084 if (wp->w_skipcol > 0)
1085 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1086 *p_extra = '-';
1087#ifdef FEAT_RIGHTLEFT
1088 if (wp->w_p_rl) // reverse line numbers
1089 {
1090 char_u *p1, *p2;
1091 int t;
1092
1093 // like rl_mirror(), but keep the space at the end
1094 p2 = skiptowhite(extra) - 1;
1095 for (p1 = extra; p1 < p2; ++p1, --p2)
1096 {
1097 t = *p1;
1098 *p1 = *p2;
1099 *p2 = t;
1100 }
1101 }
1102#endif
1103 p_extra = extra;
1104 c_extra = NUL;
1105 c_final = NUL;
1106 }
1107 else
1108 {
1109 c_extra = ' ';
1110 c_final = NUL;
1111 }
1112 n_extra = number_width(wp) + 1;
1113 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1114#ifdef FEAT_SYN_HL
1115 // When 'cursorline' is set highlight the line number of
1116 // the current line differently.
1117 // When 'cursorlineopt' has "screenline" only highlight
1118 // the line number itself.
1119 // TODO: Can we use CursorLine instead of CursorLineNr
1120 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001121 if (wp->w_p_cul
1122 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 && (wp->w_p_culopt_flags & CULOPT_NBR)
1124 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001125 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001126 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1127#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001128 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1129 && HL_ATTR(HLF_LNA) != 0)
1130 // Use LineNrAbove
1131 char_attr = hl_combine_attr(wcr_attr,
1132 HL_ATTR(HLF_LNA));
1133 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1134 && HL_ATTR(HLF_LNB) != 0)
1135 // Use LineNrBelow
1136 char_attr = hl_combine_attr(wcr_attr,
1137 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 }
1139 }
1140 }
1141
1142#ifdef FEAT_LINEBREAK
1143 if (wp->w_p_brisbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001144 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001145 // draw indent after showbreak value
1146 draw_state = WL_BRI;
1147 else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0)
1148 // After the showbreak, draw the breakindent
1149 draw_state = WL_BRI - 1;
1150
1151 // draw 'breakindent': indent wrapped text accordingly
1152 if (draw_state == WL_BRI - 1 && n_extra == 0)
1153 {
1154 draw_state = WL_BRI;
1155 // if need_showbreak is set, breakindent also applies
1156 if (wp->w_p_bri && n_extra == 0
1157 && (row != startrow || need_showbreak)
1158# ifdef FEAT_DIFF
1159 && filler_lines == 0
1160# endif
1161 )
1162 {
1163 char_attr = 0;
1164# ifdef FEAT_DIFF
1165 if (diff_hlf != (hlf_T)0)
1166 {
1167 char_attr = HL_ATTR(diff_hlf);
1168# ifdef FEAT_SYN_HL
1169 if (cul_attr != 0)
1170 char_attr = hl_combine_attr(char_attr, cul_attr);
1171# endif
1172 }
1173# endif
1174 p_extra = NULL;
1175 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001176 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177 n_extra = get_breakindent_win(wp,
1178 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaar1aa76b82020-02-23 15:17:27 +01001179 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_p_brisbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001180 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001181 // Correct end of highlighted area for 'breakindent',
1182 // required when 'linebreak' is also set.
1183 if (tocol == vcol)
1184 tocol += n_extra;
1185 }
1186 }
1187#endif
1188
1189#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1190 if (draw_state == WL_SBR - 1 && n_extra == 0)
1191 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001192 char_u *sbr;
1193
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001194 draw_state = WL_SBR;
1195# ifdef FEAT_DIFF
1196 if (filler_todo > 0)
1197 {
1198 // Draw "deleted" diff line(s).
1199 if (char2cells(fill_diff) > 1)
1200 {
1201 c_extra = '-';
1202 c_final = NUL;
1203 }
1204 else
1205 {
1206 c_extra = fill_diff;
1207 c_final = NUL;
1208 }
1209# ifdef FEAT_RIGHTLEFT
1210 if (wp->w_p_rl)
1211 n_extra = col + 1;
1212 else
1213# endif
1214 n_extra = wp->w_width - col;
1215 char_attr = HL_ATTR(HLF_DED);
1216 }
1217# endif
1218# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001219 sbr = get_showbreak_value(wp);
1220 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 {
1222 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001223 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 c_extra = NUL;
1225 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001226 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001227 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1228 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001229 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 // Correct end of highlighted area for 'showbreak',
1231 // required when 'linebreak' is also set.
1232 if (tocol == vcol)
1233 tocol += n_extra;
1234 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001235 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236# ifdef FEAT_SYN_HL
1237 // combine 'showbreak' with 'cursorline'
1238 if (cul_attr != 0)
1239 char_attr = hl_combine_attr(char_attr, cul_attr);
1240# endif
1241 }
1242# endif
1243 }
1244#endif
1245
1246 if (draw_state == WL_LINE - 1 && n_extra == 0)
1247 {
1248 draw_state = WL_LINE;
1249 if (saved_n_extra)
1250 {
1251 // Continue item from end of wrapped line.
1252 n_extra = saved_n_extra;
1253 c_extra = saved_c_extra;
1254 c_final = saved_c_final;
1255 p_extra = saved_p_extra;
1256 char_attr = saved_char_attr;
1257 }
1258 else
1259 char_attr = win_attr;
1260 }
1261 }
1262#ifdef FEAT_SYN_HL
1263 if (cul_screenline)
1264 {
1265 if (draw_state == WL_LINE
1266 && vcol >= left_curline_col
1267 && vcol < right_curline_col)
1268 {
1269 cul_attr = HL_ATTR(HLF_CUL);
1270 line_attr = cul_attr;
1271 }
1272 else
1273 {
1274 cul_attr = 0;
1275 line_attr = line_attr_save;
1276 }
1277 }
1278#endif
1279
1280 // When still displaying '$' of change command, stop at cursor.
1281 // When only displaying the (relative) line number and that's done,
1282 // stop here.
1283 if ((dollar_vcol >= 0 && wp == curwin
1284 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
1285#ifdef FEAT_DIFF
1286 && filler_todo <= 0
1287#endif
1288 )
1289 || (number_only && draw_state > WL_NR))
1290 {
1291 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1292 screen_line_flags);
1293 // Pretend we have finished updating the window. Except when
1294 // 'cursorcolumn' is set.
1295#ifdef FEAT_SYN_HL
1296 if (wp->w_p_cuc)
1297 row = wp->w_cline_row + wp->w_cline_height;
1298 else
1299#endif
1300 row = wp->w_height;
1301 break;
1302 }
1303
Bram Moolenaar34390282019-10-16 14:38:26 +02001304 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001305 {
1306 // handle Visual or match highlighting in this line
1307 if (vcol == fromcol
1308 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1309 && (*mb_ptr2cells)(ptr) > 1)
1310 || ((int)vcol_prev == fromcol_prev
1311 && vcol_prev < vcol // not at margin
1312 && vcol < tocol))
1313 area_attr = vi_attr; // start highlighting
1314 else if (area_attr != 0
1315 && (vcol == tocol
1316 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1317 area_attr = 0; // stop highlighting
1318
1319#ifdef FEAT_SEARCH_EXTRA
1320 if (!n_extra)
1321 {
1322 // Check for start/end of 'hlsearch' and other matches.
1323 // After end, check for start/end of next match.
1324 // When another match, have to check for start again.
1325 v = (long)(ptr - line);
1326 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1327 &screen_search_hl, &has_match_conc,
1328 &match_conc, did_line_attr, lcs_eol_one);
1329 ptr = line + v; // "line" may have been changed
1330 }
1331#endif
1332
1333#ifdef FEAT_DIFF
1334 if (diff_hlf != (hlf_T)0)
1335 {
1336 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1337 && n_extra == 0)
1338 diff_hlf = HLF_TXD; // changed text
1339 if (diff_hlf == HLF_TXD && ptr - line > change_end
1340 && n_extra == 0)
1341 diff_hlf = HLF_CHD; // changed line
1342 line_attr = HL_ATTR(diff_hlf);
1343 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1344 && wp->w_p_culopt_flags != CULOPT_NBR
1345 && (!cul_screenline || (vcol >= left_curline_col
1346 && vcol <= right_curline_col)))
1347 line_attr = hl_combine_attr(
1348 line_attr, HL_ATTR(HLF_CUL));
1349 }
1350#endif
1351
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001352#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001353 if (text_props != NULL)
1354 {
1355 int pi;
1356 int bcol = (int)(ptr - line);
1357
1358 if (n_extra > 0)
1359 --bcol; // still working on the previous char, e.g. Tab
1360
1361 // Check if any active property ends.
1362 for (pi = 0; pi < text_props_active; ++pi)
1363 {
1364 int tpi = text_prop_idxs[pi];
1365
1366 if (bcol >= text_props[tpi].tp_col - 1
1367 + text_props[tpi].tp_len)
1368 {
1369 if (pi + 1 < text_props_active)
1370 mch_memmove(text_prop_idxs + pi,
1371 text_prop_idxs + pi + 1,
1372 sizeof(int)
1373 * (text_props_active - (pi + 1)));
1374 --text_props_active;
1375 --pi;
1376 }
1377 }
1378
1379 // Add any text property that starts in this column.
1380 while (text_prop_next < text_prop_count
1381 && bcol >= text_props[text_prop_next].tp_col - 1)
1382 text_prop_idxs[text_props_active++] = text_prop_next++;
1383
1384 text_prop_attr = 0;
1385 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001386 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 if (text_props_active > 0)
1388 {
1389 // Sort the properties on priority and/or starting last.
1390 // Then combine the attributes, highest priority last.
1391 current_text_props = text_props;
1392 current_buf = wp->w_buffer;
1393 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1394 sizeof(int), text_prop_compare);
1395
1396 for (pi = 0; pi < text_props_active; ++pi)
1397 {
1398 int tpi = text_prop_idxs[pi];
1399 proptype_T *pt = text_prop_type_by_id(
1400 wp->w_buffer, text_props[tpi].tp_type);
1401
1402 if (pt != NULL && pt->pt_hl_id > 0)
1403 {
1404 int pt_attr = syn_id2attr(pt->pt_hl_id);
1405
1406 text_prop_type = pt;
1407 text_prop_attr =
1408 hl_combine_attr(text_prop_attr, pt_attr);
1409 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1410 }
1411 }
1412 }
1413 }
1414#endif
1415
Bram Moolenaara74fda62019-10-19 17:38:03 +02001416#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001417 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001418 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001419 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001420# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001421 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001422 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001423# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001424 // Get syntax attribute.
1425 if (has_syntax)
1426 {
1427 // Get the syntax attribute for the character. If there
1428 // is an error, disable syntax highlighting.
1429 save_did_emsg = did_emsg;
1430 did_emsg = FALSE;
1431
1432 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001433 if (v == prev_syntax_col)
1434 // at same column again
1435 syntax_attr = prev_syntax_attr;
1436 else
1437 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001438# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001439 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001440# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001441 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001442# ifdef FEAT_SPELL
1443 has_spell ? &can_spell :
1444# endif
1445 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001446 prev_syntax_col = v;
1447 prev_syntax_attr = syntax_attr;
1448 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001449
Bram Moolenaar34390282019-10-16 14:38:26 +02001450 if (did_emsg)
1451 {
1452 wp->w_s->b_syn_error = TRUE;
1453 has_syntax = FALSE;
1454 syntax_attr = 0;
1455 }
1456 else
1457 did_emsg = save_did_emsg;
1458# ifdef SYN_TIME_LIMIT
1459 if (wp->w_s->b_syn_slow)
1460 has_syntax = FALSE;
1461# endif
1462
1463 // Need to get the line again, a multi-line regexp may
1464 // have made it invalid.
1465 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1466 ptr = line + v;
1467# ifdef FEAT_CONCEAL
1468 // no concealing past the end of the line, it interferes
1469 // with line highlighting
1470 if (*ptr == NUL)
1471 syntax_flags = 0;
1472 else
1473 syntax_flags = get_syntax_info(&syntax_seqnr);
1474# endif
1475 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001476 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001477# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001478 // Combine text property highlight into syntax highlight.
1479 if (text_prop_type != NULL)
1480 {
1481 if (text_prop_combine)
1482 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1483 else
1484 syntax_attr = text_prop_attr;
1485 }
1486# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001487#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001488
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001489 // Decide which of the highlight attributes to use.
1490 attr_pri = TRUE;
1491#ifdef LINE_ATTR
1492 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001493 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001494 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001495# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001496 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001497# endif
1498 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001499 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001500 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001502# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001503 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001504# endif
1505 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001506 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1507 || vcol < fromcol || vcol_prev < fromcol_prev
1508 || vcol >= tocol))
1509 {
1510 // Use line_attr when not in the Visual or 'incsearch' area
1511 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001512# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001513 char_attr = hl_combine_attr(syntax_attr, line_attr);
1514# else
1515 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001516# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001517 attr_pri = FALSE;
1518 }
1519#else
1520 if (area_attr != 0)
1521 char_attr = area_attr;
1522 else if (search_attr != 0)
1523 char_attr = search_attr;
1524#endif
1525 else
1526 {
1527 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001528#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001529 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001530#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001531 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001532#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001533 }
1534 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001535
1536 // combine attribute with 'wincolor'
1537 if (win_attr != 0)
1538 {
1539 if (char_attr == 0)
1540 char_attr = win_attr;
1541 else
1542 char_attr = hl_combine_attr(win_attr, char_attr);
1543 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001544
1545 // Get the next character to put on the screen.
1546
1547 // The "p_extra" points to the extra stuff that is inserted to
1548 // represent special characters (non-printable stuff) and other
1549 // things. When all characters are the same, c_extra is used.
1550 // If c_final is set, it will compulsorily be used at the end.
1551 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1552 // "p_extra[n_extra]".
1553 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1554 if (n_extra > 0)
1555 {
1556 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1557 {
1558 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1559 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1560 if (enc_utf8 && utf_char2len(c) > 1)
1561 {
1562 mb_utf8 = TRUE;
1563 u8cc[0] = 0;
1564 c = 0xc0;
1565 }
1566 else
1567 mb_utf8 = FALSE;
1568 }
1569 else
1570 {
1571 c = *p_extra;
1572 if (has_mbyte)
1573 {
1574 mb_c = c;
1575 if (enc_utf8)
1576 {
1577 // If the UTF-8 character is more than one byte:
1578 // Decode it into "mb_c".
1579 mb_l = utfc_ptr2len(p_extra);
1580 mb_utf8 = FALSE;
1581 if (mb_l > n_extra)
1582 mb_l = 1;
1583 else if (mb_l > 1)
1584 {
1585 mb_c = utfc_ptr2char(p_extra, u8cc);
1586 mb_utf8 = TRUE;
1587 c = 0xc0;
1588 }
1589 }
1590 else
1591 {
1592 // if this is a DBCS character, put it in "mb_c"
1593 mb_l = MB_BYTE2LEN(c);
1594 if (mb_l >= n_extra)
1595 mb_l = 1;
1596 else if (mb_l > 1)
1597 mb_c = (c << 8) + p_extra[1];
1598 }
1599 if (mb_l == 0) // at the NUL at end-of-line
1600 mb_l = 1;
1601
1602 // If a double-width char doesn't fit display a '>' in the
1603 // last column.
1604 if ((
1605# ifdef FEAT_RIGHTLEFT
1606 wp->w_p_rl ? (col <= 0) :
1607# endif
1608 (col >= wp->w_width - 1))
1609 && (*mb_char2cells)(mb_c) == 2)
1610 {
1611 c = '>';
1612 mb_c = c;
1613 mb_l = 1;
1614 mb_utf8 = FALSE;
1615 multi_attr = HL_ATTR(HLF_AT);
1616#ifdef FEAT_SYN_HL
1617 if (cul_attr)
1618 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1619#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001620 multi_attr = hl_combine_attr(win_attr, multi_attr);
1621
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001622 // put the pointer back to output the double-width
1623 // character at the start of the next line.
1624 ++n_extra;
1625 --p_extra;
1626 }
1627 else
1628 {
1629 n_extra -= mb_l - 1;
1630 p_extra += mb_l - 1;
1631 }
1632 }
1633 ++p_extra;
1634 }
1635 --n_extra;
1636 }
1637 else
1638 {
1639#ifdef FEAT_LINEBREAK
1640 int c0;
1641#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001642 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001643
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001644 // Get a character from the line itself.
1645 c = *ptr;
1646#ifdef FEAT_LINEBREAK
1647 c0 = *ptr;
1648#endif
1649 if (has_mbyte)
1650 {
1651 mb_c = c;
1652 if (enc_utf8)
1653 {
1654 // If the UTF-8 character is more than one byte: Decode it
1655 // into "mb_c".
1656 mb_l = utfc_ptr2len(ptr);
1657 mb_utf8 = FALSE;
1658 if (mb_l > 1)
1659 {
1660 mb_c = utfc_ptr2char(ptr, u8cc);
1661 // Overlong encoded ASCII or ASCII with composing char
1662 // is displayed normally, except a NUL.
1663 if (mb_c < 0x80)
1664 {
1665 c = mb_c;
1666#ifdef FEAT_LINEBREAK
1667 c0 = mb_c;
1668#endif
1669 }
1670 mb_utf8 = TRUE;
1671
1672 // At start of the line we can have a composing char.
1673 // Draw it as a space with a composing char.
1674 if (utf_iscomposing(mb_c))
1675 {
1676 int i;
1677
1678 for (i = Screen_mco - 1; i > 0; --i)
1679 u8cc[i] = u8cc[i - 1];
1680 u8cc[0] = mb_c;
1681 mb_c = ' ';
1682 }
1683 }
1684
1685 if ((mb_l == 1 && c >= 0x80)
1686 || (mb_l >= 1 && mb_c == 0)
1687 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1688 {
1689 // Illegal UTF-8 byte: display as <xx>.
1690 // Non-BMP character : display as ? or fullwidth ?.
1691 transchar_hex(extra, mb_c);
1692# ifdef FEAT_RIGHTLEFT
1693 if (wp->w_p_rl) // reverse
1694 rl_mirror(extra);
1695# endif
1696 p_extra = extra;
1697 c = *p_extra;
1698 mb_c = mb_ptr2char_adv(&p_extra);
1699 mb_utf8 = (c >= 0x80);
1700 n_extra = (int)STRLEN(p_extra);
1701 c_extra = NUL;
1702 c_final = NUL;
1703 if (area_attr == 0 && search_attr == 0)
1704 {
1705 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001706 extra_attr = hl_combine_attr(
1707 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 saved_attr2 = char_attr; // save current attr
1709 }
1710 }
1711 else if (mb_l == 0) // at the NUL at end-of-line
1712 mb_l = 1;
1713#ifdef FEAT_ARABIC
1714 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1715 {
1716 // Do Arabic shaping.
1717 int pc, pc1, nc;
1718 int pcc[MAX_MCO];
1719
1720 // The idea of what is the previous and next
1721 // character depends on 'rightleft'.
1722 if (wp->w_p_rl)
1723 {
1724 pc = prev_c;
1725 pc1 = prev_c1;
1726 nc = utf_ptr2char(ptr + mb_l);
1727 prev_c1 = u8cc[0];
1728 }
1729 else
1730 {
1731 pc = utfc_ptr2char(ptr + mb_l, pcc);
1732 nc = prev_c;
1733 pc1 = pcc[0];
1734 }
1735 prev_c = mb_c;
1736
1737 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1738 }
1739 else
1740 prev_c = mb_c;
1741#endif
1742 }
1743 else // enc_dbcs
1744 {
1745 mb_l = MB_BYTE2LEN(c);
1746 if (mb_l == 0) // at the NUL at end-of-line
1747 mb_l = 1;
1748 else if (mb_l > 1)
1749 {
1750 // We assume a second byte below 32 is illegal.
1751 // Hopefully this is OK for all double-byte encodings!
1752 if (ptr[1] >= 32)
1753 mb_c = (c << 8) + ptr[1];
1754 else
1755 {
1756 if (ptr[1] == NUL)
1757 {
1758 // head byte at end of line
1759 mb_l = 1;
1760 transchar_nonprint(extra, c);
1761 }
1762 else
1763 {
1764 // illegal tail byte
1765 mb_l = 2;
1766 STRCPY(extra, "XX");
1767 }
1768 p_extra = extra;
1769 n_extra = (int)STRLEN(extra) - 1;
1770 c_extra = NUL;
1771 c_final = NUL;
1772 c = *p_extra++;
1773 if (area_attr == 0 && search_attr == 0)
1774 {
1775 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001776 extra_attr = hl_combine_attr(
1777 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 saved_attr2 = char_attr; // save current attr
1779 }
1780 mb_c = c;
1781 }
1782 }
1783 }
1784 // If a double-width char doesn't fit display a '>' in the
1785 // last column; the character is displayed at the start of the
1786 // next line.
1787 if ((
1788# ifdef FEAT_RIGHTLEFT
1789 wp->w_p_rl ? (col <= 0) :
1790# endif
1791 (col >= wp->w_width - 1))
1792 && (*mb_char2cells)(mb_c) == 2)
1793 {
1794 c = '>';
1795 mb_c = c;
1796 mb_utf8 = FALSE;
1797 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001798 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 // Put pointer back so that the character will be
1800 // displayed at the start of the next line.
1801 --ptr;
1802#ifdef FEAT_CONCEAL
1803 did_decrement_ptr = TRUE;
1804#endif
1805 }
1806 else if (*ptr != NUL)
1807 ptr += mb_l - 1;
1808
1809 // If a double-width char doesn't fit at the left side display
1810 // a '<' in the first column. Don't do this for unprintable
1811 // characters.
1812 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1813 {
1814 n_extra = 1;
1815 c_extra = MB_FILLER_CHAR;
1816 c_final = NUL;
1817 c = ' ';
1818 if (area_attr == 0 && search_attr == 0)
1819 {
1820 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001821 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001822 saved_attr2 = char_attr; // save current attr
1823 }
1824 mb_c = c;
1825 mb_utf8 = FALSE;
1826 mb_l = 1;
1827 }
1828
1829 }
1830 ++ptr;
1831
1832 if (extra_check)
1833 {
1834#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001835 // Check spelling (unless at the end of the line).
1836 // Only do this when there is no syntax highlighting, the
1837 // @Spell cluster is not used or the current syntax item
1838 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001839 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 if (has_spell && v >= word_end && v > cur_checked_col)
1841 {
1842 spell_attr = 0;
1843 if (c != 0 && (
1844# ifdef FEAT_SYN_HL
1845 !has_syntax ||
1846# endif
1847 can_spell))
1848 {
1849 char_u *prev_ptr, *p;
1850 int len;
1851 hlf_T spell_hlf = HLF_COUNT;
1852 if (has_mbyte)
1853 {
1854 prev_ptr = ptr - mb_l;
1855 v -= mb_l - 1;
1856 }
1857 else
1858 prev_ptr = ptr - 1;
1859
1860 // Use nextline[] if possible, it has the start of the
1861 // next line concatenated.
1862 if ((prev_ptr - line) - nextlinecol >= 0)
1863 p = nextline + (prev_ptr - line) - nextlinecol;
1864 else
1865 p = prev_ptr;
1866 cap_col -= (int)(prev_ptr - line);
1867 len = spell_check(wp, p, &spell_hlf, &cap_col,
1868 nochange);
1869 word_end = v + len;
1870
1871 // In Insert mode only highlight a word that
1872 // doesn't touch the cursor.
1873 if (spell_hlf != HLF_COUNT
1874 && (State & INSERT) != 0
1875 && wp->w_cursor.lnum == lnum
1876 && wp->w_cursor.col >=
1877 (colnr_T)(prev_ptr - line)
1878 && wp->w_cursor.col < (colnr_T)word_end)
1879 {
1880 spell_hlf = HLF_COUNT;
1881 spell_redraw_lnum = lnum;
1882 }
1883
1884 if (spell_hlf == HLF_COUNT && p != prev_ptr
1885 && (p - nextline) + len > nextline_idx)
1886 {
1887 // Remember that the good word continues at the
1888 // start of the next line.
1889 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001890 checked_col = (int)((p - nextline)
1891 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 }
1893
1894 // Turn index into actual attributes.
1895 if (spell_hlf != HLF_COUNT)
1896 spell_attr = highlight_attr[spell_hlf];
1897
1898 if (cap_col > 0)
1899 {
1900 if (p != prev_ptr
1901 && (p - nextline) + cap_col >= nextline_idx)
1902 {
1903 // Remember that the word in the next line
1904 // must start with a capital.
1905 capcol_lnum = lnum + 1;
1906 cap_col = (int)((p - nextline) + cap_col
1907 - nextline_idx);
1908 }
1909 else
1910 // Compute the actual column.
1911 cap_col += (int)(prev_ptr - line);
1912 }
1913 }
1914 }
1915 if (spell_attr != 0)
1916 {
1917 if (!attr_pri)
1918 char_attr = hl_combine_attr(char_attr, spell_attr);
1919 else
1920 char_attr = hl_combine_attr(spell_attr, char_attr);
1921 }
1922#endif
1923#ifdef FEAT_LINEBREAK
1924 // Found last space before word: check for line break.
1925 if (wp->w_p_lbr && c0 == c
1926 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
1927 {
1928 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
1929 char_u *p = ptr - (mb_off + 1);
1930
1931 // TODO: is passing p for start of the line OK?
1932 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
1933 NULL) - 1;
1934 if (c == TAB && n_extra + col > wp->w_width)
1935# ifdef FEAT_VARTABS
1936 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
1937 wp->w_buffer->b_p_vts_array) - 1;
1938# else
1939 n_extra = (int)wp->w_buffer->b_p_ts
1940 - vcol % (int)wp->w_buffer->b_p_ts - 1;
1941# endif
1942
1943 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
1944 c_final = NUL;
1945 if (VIM_ISWHITE(c))
1946 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001947# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 if (c == TAB)
1949 // See "Tab alignment" below.
1950 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01001951# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001952 if (!wp->w_p_list)
1953 c = ' ';
1954 }
1955 }
1956#endif
1957
1958 // 'list': Change char 160 to lcs_nbsp and space to lcs_space.
1959 // But not when the character is followed by a composing
1960 // character (use mb_l to check that).
1961 if (wp->w_p_list
1962 && ((((c == 160 && mb_l == 1)
1963 || (mb_utf8
1964 && ((mb_c == 160 && mb_l == 2)
1965 || (mb_c == 0x202f && mb_l == 3))))
1966 && lcs_nbsp)
1967 || (c == ' '
1968 && mb_l == 1
1969 && lcs_space
1970 && ptr - line <= trailcol)))
1971 {
1972 c = (c == ' ') ? lcs_space : lcs_nbsp;
1973 if (area_attr == 0 && search_attr == 0)
1974 {
1975 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001976 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001977 saved_attr2 = char_attr; // save current attr
1978 }
1979 mb_c = c;
1980 if (enc_utf8 && utf_char2len(c) > 1)
1981 {
1982 mb_utf8 = TRUE;
1983 u8cc[0] = 0;
1984 c = 0xc0;
1985 }
1986 else
1987 mb_utf8 = FALSE;
1988 }
1989
1990 if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
1991 {
1992 c = lcs_trail;
1993 if (!attr_pri)
1994 {
1995 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001996 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 saved_attr2 = char_attr; // save current attr
1998 }
1999 mb_c = c;
2000 if (enc_utf8 && utf_char2len(c) > 1)
2001 {
2002 mb_utf8 = TRUE;
2003 u8cc[0] = 0;
2004 c = 0xc0;
2005 }
2006 else
2007 mb_utf8 = FALSE;
2008 }
2009 }
2010
2011 // Handling of non-printable characters.
2012 if (!vim_isprintc(c))
2013 {
2014 // when getting a character from the file, we may have to
2015 // turn it into something else on the way to putting it
2016 // into "ScreenLines".
2017 if (c == TAB && (!wp->w_p_list || lcs_tab1))
2018 {
2019 int tab_len = 0;
2020 long vcol_adjusted = vcol; // removed showbreak length
2021#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002022 char_u *sbr = get_showbreak_value(wp);
2023
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002024 // only adjust the tab_len, when at the first column
2025 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002026 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2027 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002028#endif
2029 // tab amount depends on current column
2030#ifdef FEAT_VARTABS
2031 tab_len = tabstop_padding(vcol_adjusted,
2032 wp->w_buffer->b_p_ts,
2033 wp->w_buffer->b_p_vts_array) - 1;
2034#else
2035 tab_len = (int)wp->w_buffer->b_p_ts
2036 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2037#endif
2038
2039#ifdef FEAT_LINEBREAK
2040 if (!wp->w_p_lbr || !wp->w_p_list)
2041#endif
2042 // tab amount depends on current column
2043 n_extra = tab_len;
2044#ifdef FEAT_LINEBREAK
2045 else
2046 {
2047 char_u *p;
2048 int len;
2049 int i;
2050 int saved_nextra = n_extra;
2051
2052#ifdef FEAT_CONCEAL
2053 if (vcol_off > 0)
2054 // there are characters to conceal
2055 tab_len += vcol_off;
2056 // boguscols before FIX_FOR_BOGUSCOLS macro from above
2057 if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
2058 && n_extra > tab_len)
2059 tab_len += n_extra - tab_len;
2060#endif
2061
2062 // if n_extra > 0, it gives the number of chars, to
2063 // use for a tab, else we need to calculate the width
2064 // for a tab
2065 len = (tab_len * mb_char2len(lcs_tab2));
2066 if (n_extra > 0)
2067 len += n_extra - tab_len;
2068 c = lcs_tab1;
2069 p = alloc(len + 1);
2070 vim_memset(p, ' ', len);
2071 p[len] = NUL;
2072 vim_free(p_extra_free);
2073 p_extra_free = p;
2074 for (i = 0; i < tab_len; i++)
2075 {
2076 int lcs = lcs_tab2;
2077
2078 if (*p == NUL)
2079 {
2080 tab_len = i;
2081 break;
2082 }
2083
2084 // if lcs_tab3 is given, need to change the char
2085 // for tab
2086 if (lcs_tab3 && i == tab_len - 1)
2087 lcs = lcs_tab3;
2088 mb_char2bytes(lcs, p);
2089 p += mb_char2len(lcs);
2090 n_extra += mb_char2len(lcs)
2091 - (saved_nextra > 0 ? 1 : 0);
2092 }
2093 p_extra = p_extra_free;
2094#ifdef FEAT_CONCEAL
2095 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2096 // macro below, so need to adjust for that here
2097 if (vcol_off > 0)
2098 n_extra -= vcol_off;
2099#endif
2100 }
2101#endif
2102#ifdef FEAT_CONCEAL
2103 {
2104 int vc_saved = vcol_off;
2105
2106 // Tab alignment should be identical regardless of
2107 // 'conceallevel' value. So tab compensates of all
2108 // previous concealed characters, and thus resets
2109 // vcol_off and boguscols accumulated so far in the
2110 // line. Note that the tab can be longer than
2111 // 'tabstop' when there are concealed characters.
2112 FIX_FOR_BOGUSCOLS;
2113
2114 // Make sure, the highlighting for the tab char will be
2115 // correctly set further below (effectively reverts the
2116 // FIX_FOR_BOGSUCOLS macro
2117 if (n_extra == tab_len + vc_saved && wp->w_p_list
2118 && lcs_tab1)
2119 tab_len += vc_saved;
2120 }
2121#endif
2122 mb_utf8 = FALSE; // don't draw as UTF-8
2123 if (wp->w_p_list)
2124 {
2125 c = (n_extra == 0 && lcs_tab3) ? lcs_tab3 : lcs_tab1;
2126#ifdef FEAT_LINEBREAK
2127 if (wp->w_p_lbr)
2128 c_extra = NUL; // using p_extra from above
2129 else
2130#endif
2131 c_extra = lcs_tab2;
2132 c_final = lcs_tab3;
2133 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002134 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002135 saved_attr2 = char_attr; // save current attr
2136 mb_c = c;
2137 if (enc_utf8 && utf_char2len(c) > 1)
2138 {
2139 mb_utf8 = TRUE;
2140 u8cc[0] = 0;
2141 c = 0xc0;
2142 }
2143 }
2144 else
2145 {
2146 c_final = NUL;
2147 c_extra = ' ';
2148 c = ' ';
2149 }
2150 }
2151 else if (c == NUL
2152 && (wp->w_p_list
2153 || ((fromcol >= 0 || fromcol_prev >= 0)
2154 && tocol > vcol
2155 && VIsual_mode != Ctrl_V
2156 && (
2157# ifdef FEAT_RIGHTLEFT
2158 wp->w_p_rl ? (col >= 0) :
2159# endif
2160 (col < wp->w_width))
2161 && !(noinvcur
2162 && lnum == wp->w_cursor.lnum
2163 && (colnr_T)vcol == wp->w_virtcol)))
2164 && lcs_eol_one > 0)
2165 {
2166 // Display a '$' after the line or highlight an extra
2167 // character if the line break is included.
2168#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2169 // For a diff line the highlighting continues after the
2170 // "$".
2171 if (
2172# ifdef FEAT_DIFF
2173 diff_hlf == (hlf_T)0
2174# ifdef LINE_ATTR
2175 &&
2176# endif
2177# endif
2178# ifdef LINE_ATTR
2179 line_attr == 0
2180# endif
2181 )
2182#endif
2183 {
2184 // In virtualedit, visual selections may extend
2185 // beyond end of line.
2186 if (area_highlighting && virtual_active()
2187 && tocol != MAXCOL && vcol < tocol)
2188 n_extra = 0;
2189 else
2190 {
2191 p_extra = at_end_str;
2192 n_extra = 1;
2193 c_extra = NUL;
2194 c_final = NUL;
2195 }
2196 }
2197 if (wp->w_p_list && lcs_eol > 0)
2198 c = lcs_eol;
2199 else
2200 c = ' ';
2201 lcs_eol_one = -1;
2202 --ptr; // put it back at the NUL
2203 if (!attr_pri)
2204 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002205 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002206 n_attr = 1;
2207 }
2208 mb_c = c;
2209 if (enc_utf8 && utf_char2len(c) > 1)
2210 {
2211 mb_utf8 = TRUE;
2212 u8cc[0] = 0;
2213 c = 0xc0;
2214 }
2215 else
2216 mb_utf8 = FALSE; // don't draw as UTF-8
2217 }
2218 else if (c != NUL)
2219 {
2220 p_extra = transchar(c);
2221 if (n_extra == 0)
2222 n_extra = byte2cells(c) - 1;
2223#ifdef FEAT_RIGHTLEFT
2224 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2225 rl_mirror(p_extra); // reverse "<12>"
2226#endif
2227 c_extra = NUL;
2228 c_final = NUL;
2229#ifdef FEAT_LINEBREAK
2230 if (wp->w_p_lbr)
2231 {
2232 char_u *p;
2233
2234 c = *p_extra;
2235 p = alloc(n_extra + 1);
2236 vim_memset(p, ' ', n_extra);
2237 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2238 p[n_extra] = NUL;
2239 vim_free(p_extra_free);
2240 p_extra_free = p_extra = p;
2241 }
2242 else
2243#endif
2244 {
2245 n_extra = byte2cells(c) - 1;
2246 c = *p_extra++;
2247 }
2248 if (!attr_pri)
2249 {
2250 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002251 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 saved_attr2 = char_attr; // save current attr
2253 }
2254 mb_utf8 = FALSE; // don't draw as UTF-8
2255 }
2256 else if (VIsual_active
2257 && (VIsual_mode == Ctrl_V
2258 || VIsual_mode == 'v')
2259 && virtual_active()
2260 && tocol != MAXCOL
2261 && vcol < tocol
2262 && (
2263#ifdef FEAT_RIGHTLEFT
2264 wp->w_p_rl ? (col >= 0) :
2265#endif
2266 (col < wp->w_width)))
2267 {
2268 c = ' ';
2269 --ptr; // put it back at the NUL
2270 }
2271#if defined(LINE_ATTR)
2272 else if ((
2273# ifdef FEAT_DIFF
2274 diff_hlf != (hlf_T)0 ||
2275# endif
2276# ifdef FEAT_TERMINAL
2277 win_attr != 0 ||
2278# endif
2279 line_attr != 0
2280 ) && (
2281# ifdef FEAT_RIGHTLEFT
2282 wp->w_p_rl ? (col >= 0) :
2283# endif
2284 (col
2285# ifdef FEAT_CONCEAL
2286 - boguscols
2287# endif
2288 < wp->w_width)))
2289 {
2290 // Highlight until the right side of the window
2291 c = ' ';
2292 --ptr; // put it back at the NUL
2293
2294 // Remember we do the char for line highlighting.
2295 ++did_line_attr;
2296
2297 // don't do search HL for the rest of the line
2298 if (line_attr != 0 && char_attr == search_attr
2299 && (did_line_attr > 1
2300 || (wp->w_p_list && lcs_eol > 0)))
2301 char_attr = line_attr;
2302# ifdef FEAT_DIFF
2303 if (diff_hlf == HLF_TXD)
2304 {
2305 diff_hlf = HLF_CHD;
2306 if (vi_attr == 0 || char_attr != vi_attr)
2307 {
2308 char_attr = HL_ATTR(diff_hlf);
2309 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2310 && wp->w_p_culopt_flags != CULOPT_NBR
2311 && (!cul_screenline
2312 || (vcol >= left_curline_col
2313 && vcol <= right_curline_col)))
2314 char_attr = hl_combine_attr(
2315 char_attr, HL_ATTR(HLF_CUL));
2316 }
2317 }
2318# endif
2319# ifdef FEAT_TERMINAL
2320 if (win_attr != 0)
2321 {
2322 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002323 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2324 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002325 {
2326 if (!cul_screenline || (vcol >= left_curline_col
2327 && vcol <= right_curline_col))
2328 char_attr = hl_combine_attr(
2329 char_attr, HL_ATTR(HLF_CUL));
2330 }
2331 else if (line_attr)
2332 char_attr = hl_combine_attr(char_attr, line_attr);
2333 }
2334# endif
2335 }
2336#endif
2337 }
2338
2339#ifdef FEAT_CONCEAL
2340 if ( wp->w_p_cole > 0
2341 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2342 conceal_cursor_line(wp))
2343 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2344 && !(lnum_in_visual_area
2345 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2346 {
2347 char_attr = conceal_attr;
2348 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
2349 && (syn_get_sub_char() != NUL || match_conc
2350 || wp->w_p_cole == 1)
2351 && wp->w_p_cole != 3)
2352 {
2353 // First time at this concealed item: display one
2354 // character.
2355 if (match_conc)
2356 c = match_conc;
2357 else if (syn_get_sub_char() != NUL)
2358 c = syn_get_sub_char();
2359 else if (lcs_conceal != NUL)
2360 c = lcs_conceal;
2361 else
2362 c = ' ';
2363
2364 prev_syntax_id = syntax_seqnr;
2365
2366 if (n_extra > 0)
2367 vcol_off += n_extra;
2368 vcol += n_extra;
2369 if (wp->w_p_wrap && n_extra > 0)
2370 {
2371# ifdef FEAT_RIGHTLEFT
2372 if (wp->w_p_rl)
2373 {
2374 col -= n_extra;
2375 boguscols -= n_extra;
2376 }
2377 else
2378# endif
2379 {
2380 boguscols += n_extra;
2381 col += n_extra;
2382 }
2383 }
2384 n_extra = 0;
2385 n_attr = 0;
2386 }
2387 else if (n_skip == 0)
2388 {
2389 is_concealing = TRUE;
2390 n_skip = 1;
2391 }
2392 mb_c = c;
2393 if (enc_utf8 && utf_char2len(c) > 1)
2394 {
2395 mb_utf8 = TRUE;
2396 u8cc[0] = 0;
2397 c = 0xc0;
2398 }
2399 else
2400 mb_utf8 = FALSE; // don't draw as UTF-8
2401 }
2402 else
2403 {
2404 prev_syntax_id = 0;
2405 is_concealing = FALSE;
2406 }
2407
2408 if (n_skip > 0 && did_decrement_ptr)
2409 // not showing the '>', put pointer back to avoid getting stuck
2410 ++ptr;
2411
2412#endif // FEAT_CONCEAL
2413 }
2414
2415#ifdef FEAT_CONCEAL
2416 // In the cursor line and we may be concealing characters: correct
2417 // the cursor column when we reach its position.
2418 if (!did_wcol && draw_state == WL_LINE
2419 && wp == curwin && lnum == wp->w_cursor.lnum
2420 && conceal_cursor_line(wp)
2421 && (int)wp->w_virtcol <= vcol + n_skip)
2422 {
2423# ifdef FEAT_RIGHTLEFT
2424 if (wp->w_p_rl)
2425 wp->w_wcol = wp->w_width - col + boguscols - 1;
2426 else
2427# endif
2428 wp->w_wcol = col - boguscols;
2429 wp->w_wrow = row;
2430 did_wcol = TRUE;
2431 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
2432 }
2433#endif
2434
2435 // Don't override visual selection highlighting.
2436 if (n_attr > 0
2437 && draw_state == WL_LINE
2438 && !attr_pri)
2439 {
2440#ifdef LINE_ATTR
2441 if (line_attr)
2442 char_attr = hl_combine_attr(extra_attr, line_attr);
2443 else
2444#endif
2445 char_attr = extra_attr;
2446 }
2447
2448#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2449 // XIM don't send preedit_start and preedit_end, but they send
2450 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2451 // im_is_preediting() here.
2452 if (p_imst == IM_ON_THE_SPOT
2453 && xic != NULL
2454 && lnum == wp->w_cursor.lnum
2455 && (State & INSERT)
2456 && !p_imdisable
2457 && im_is_preediting()
2458 && draw_state == WL_LINE)
2459 {
2460 colnr_T tcol;
2461
2462 if (preedit_end_col == MAXCOL)
2463 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2464 else
2465 tcol = preedit_end_col;
2466 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2467 {
2468 if (feedback_old_attr < 0)
2469 {
2470 feedback_col = 0;
2471 feedback_old_attr = char_attr;
2472 }
2473 char_attr = im_get_feedback_attr(feedback_col);
2474 if (char_attr < 0)
2475 char_attr = feedback_old_attr;
2476 feedback_col++;
2477 }
2478 else if (feedback_old_attr >= 0)
2479 {
2480 char_attr = feedback_old_attr;
2481 feedback_old_attr = -1;
2482 feedback_col = 0;
2483 }
2484 }
2485#endif
2486 // Handle the case where we are in column 0 but not on the first
2487 // character of the line and the user wants us to show us a
2488 // special character (via 'listchars' option "precedes:<char>".
2489 if (lcs_prec_todo != NUL
2490 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002491 && (wp->w_p_wrap ?
2492 (wp->w_skipcol > 0 && row == 0) :
2493 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002494#ifdef FEAT_DIFF
2495 && filler_todo <= 0
2496#endif
2497 && draw_state > WL_NR
2498 && c != NUL)
2499 {
2500 c = lcs_prec;
2501 lcs_prec_todo = NUL;
2502 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2503 {
2504 // Double-width character being overwritten by the "precedes"
2505 // character, need to fill up half the character.
2506 c_extra = MB_FILLER_CHAR;
2507 c_final = NUL;
2508 n_extra = 1;
2509 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002510 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 }
2512 mb_c = c;
2513 if (enc_utf8 && utf_char2len(c) > 1)
2514 {
2515 mb_utf8 = TRUE;
2516 u8cc[0] = 0;
2517 c = 0xc0;
2518 }
2519 else
2520 mb_utf8 = FALSE; // don't draw as UTF-8
2521 if (!attr_pri)
2522 {
2523 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002524 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 n_attr3 = 1;
2526 }
2527 }
2528
2529 // At end of the text line or just after the last character.
2530 if ((c == NUL
2531#if defined(LINE_ATTR)
2532 || did_line_attr == 1
2533#endif
2534 ) && eol_hl_off == 0)
2535 {
2536#ifdef FEAT_SEARCH_EXTRA
2537 // flag to indicate whether prevcol equals startcol of search_hl or
2538 // one of the matches
2539 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2540 (long)(ptr - line) - (c == NUL));
2541#endif
2542 // Invert at least one char, used for Visual and empty line or
2543 // highlight match at end of line. If it's beyond the last
2544 // char on the screen, just overwrite that one (tricky!) Not
2545 // needed when a '$' was displayed for 'list'.
2546 if (lcs_eol == lcs_eol_one
2547 && ((area_attr != 0 && vcol == fromcol
2548 && (VIsual_mode != Ctrl_V
2549 || lnum == VIsual.lnum
2550 || lnum == curwin->w_cursor.lnum)
2551 && c == NUL)
2552#ifdef FEAT_SEARCH_EXTRA
2553 // highlight 'hlsearch' match at end of line
2554 || (prevcol_hl_flag
2555# ifdef FEAT_SYN_HL
2556 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2557 && !(wp == curwin && VIsual_active))
2558# endif
2559# ifdef FEAT_DIFF
2560 && diff_hlf == (hlf_T)0
2561# endif
2562# if defined(LINE_ATTR)
2563 && did_line_attr <= 1
2564# endif
2565 )
2566#endif
2567 ))
2568 {
2569 int n = 0;
2570
2571#ifdef FEAT_RIGHTLEFT
2572 if (wp->w_p_rl)
2573 {
2574 if (col < 0)
2575 n = 1;
2576 }
2577 else
2578#endif
2579 {
2580 if (col >= wp->w_width)
2581 n = -1;
2582 }
2583 if (n != 0)
2584 {
2585 // At the window boundary, highlight the last character
2586 // instead (better than nothing).
2587 off += n;
2588 col += n;
2589 }
2590 else
2591 {
2592 // Add a blank character to highlight.
2593 ScreenLines[off] = ' ';
2594 if (enc_utf8)
2595 ScreenLinesUC[off] = 0;
2596 }
2597#ifdef FEAT_SEARCH_EXTRA
2598 if (area_attr == 0)
2599 {
2600 // Use attributes from match with highest priority among
2601 // 'search_hl' and the match list.
2602 get_search_match_hl(wp, &screen_search_hl,
2603 (long)(ptr - line), &char_attr);
2604 }
2605#endif
2606 ScreenAttrs[off] = char_attr;
2607#ifdef FEAT_RIGHTLEFT
2608 if (wp->w_p_rl)
2609 {
2610 --col;
2611 --off;
2612 }
2613 else
2614#endif
2615 {
2616 ++col;
2617 ++off;
2618 }
2619 ++vcol;
2620 eol_hl_off = 1;
2621 }
2622 }
2623
2624 // At end of the text line.
2625 if (c == NUL)
2626 {
2627#ifdef FEAT_SYN_HL
2628 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2629 if (wp->w_p_wrap)
2630 v = wp->w_skipcol;
2631 else
2632 v = wp->w_leftcol;
2633
2634 // check if line ends before left margin
2635 if (vcol < v + col - win_col_off(wp))
2636 vcol = v + col - win_col_off(wp);
2637#ifdef FEAT_CONCEAL
2638 // Get rid of the boguscols now, we want to draw until the right
2639 // edge for 'cursorcolumn'.
2640 col -= boguscols;
2641 boguscols = 0;
2642#endif
2643
2644 if (draw_color_col)
2645 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2646
2647 if (((wp->w_p_cuc
2648 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2649 && (int)wp->w_virtcol <
2650 wp->w_width * (row - startrow + 1) + v
2651 && lnum != wp->w_cursor.lnum)
2652 || draw_color_col
2653 || win_attr != 0)
2654# ifdef FEAT_RIGHTLEFT
2655 && !wp->w_p_rl
2656# endif
2657 )
2658 {
2659 int rightmost_vcol = 0;
2660 int i;
2661
2662 if (wp->w_p_cuc)
2663 rightmost_vcol = wp->w_virtcol;
2664 if (draw_color_col)
2665 // determine rightmost colorcolumn to possibly draw
2666 for (i = 0; color_cols[i] >= 0; ++i)
2667 if (rightmost_vcol < color_cols[i])
2668 rightmost_vcol = color_cols[i];
2669
2670 while (col < wp->w_width)
2671 {
2672 ScreenLines[off] = ' ';
2673 if (enc_utf8)
2674 ScreenLinesUC[off] = 0;
2675 ++col;
2676 if (draw_color_col)
2677 draw_color_col = advance_color_col(VCOL_HLC,
2678 &color_cols);
2679
2680 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2681 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2682 else if (draw_color_col && VCOL_HLC == *color_cols)
2683 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2684 else
2685 ScreenAttrs[off++] = win_attr;
2686
2687 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2688 break;
2689
2690 ++vcol;
2691 }
2692 }
2693#endif
2694
2695 screen_line(screen_row, wp->w_wincol, col,
2696 (int)wp->w_width, screen_line_flags);
2697 row++;
2698
2699 // Update w_cline_height and w_cline_folded if the cursor line was
2700 // updated (saves a call to plines() later).
2701 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2702 {
2703 curwin->w_cline_row = startrow;
2704 curwin->w_cline_height = row - startrow;
2705#ifdef FEAT_FOLDING
2706 curwin->w_cline_folded = FALSE;
2707#endif
2708 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2709 }
2710
2711 break;
2712 }
2713
2714 // Show "extends" character from 'listchars' if beyond the line end and
2715 // 'list' is set.
2716 if (lcs_ext != NUL
2717 && wp->w_p_list
2718 && !wp->w_p_wrap
2719#ifdef FEAT_DIFF
2720 && filler_todo <= 0
2721#endif
2722 && (
2723#ifdef FEAT_RIGHTLEFT
2724 wp->w_p_rl ? col == 0 :
2725#endif
2726 col == wp->w_width - 1)
2727 && (*ptr != NUL
2728 || (wp->w_p_list && lcs_eol_one > 0)
2729 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2730 {
2731 c = lcs_ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002732 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733 mb_c = c;
2734 if (enc_utf8 && utf_char2len(c) > 1)
2735 {
2736 mb_utf8 = TRUE;
2737 u8cc[0] = 0;
2738 c = 0xc0;
2739 }
2740 else
2741 mb_utf8 = FALSE;
2742 }
2743
2744#ifdef FEAT_SYN_HL
2745 // advance to the next 'colorcolumn'
2746 if (draw_color_col)
2747 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2748
2749 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2750 // highlight the cursor position itself.
2751 // Also highlight the 'colorcolumn' if it is different than
2752 // 'cursorcolumn'
2753 vcol_save_attr = -1;
2754 if (draw_state == WL_LINE && !lnum_in_visual_area
2755 && search_attr == 0 && area_attr == 0)
2756 {
2757 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2758 && lnum != wp->w_cursor.lnum)
2759 {
2760 vcol_save_attr = char_attr;
2761 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2762 }
2763 else if (draw_color_col && VCOL_HLC == *color_cols)
2764 {
2765 vcol_save_attr = char_attr;
2766 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2767 }
2768 }
2769#endif
2770
2771 // Store character to be displayed.
2772 // Skip characters that are left of the screen for 'nowrap'.
2773 vcol_prev = vcol;
2774 if (draw_state < WL_LINE || n_skip <= 0)
2775 {
2776 // Store the character.
2777#if defined(FEAT_RIGHTLEFT)
2778 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2779 {
2780 // A double-wide character is: put first halve in left cell.
2781 --off;
2782 --col;
2783 }
2784#endif
2785 ScreenLines[off] = c;
2786 if (enc_dbcs == DBCS_JPNU)
2787 {
2788 if ((mb_c & 0xff00) == 0x8e00)
2789 ScreenLines[off] = 0x8e;
2790 ScreenLines2[off] = mb_c & 0xff;
2791 }
2792 else if (enc_utf8)
2793 {
2794 if (mb_utf8)
2795 {
2796 int i;
2797
2798 ScreenLinesUC[off] = mb_c;
2799 if ((c & 0xff) == 0)
2800 ScreenLines[off] = 0x80; // avoid storing zero
2801 for (i = 0; i < Screen_mco; ++i)
2802 {
2803 ScreenLinesC[i][off] = u8cc[i];
2804 if (u8cc[i] == 0)
2805 break;
2806 }
2807 }
2808 else
2809 ScreenLinesUC[off] = 0;
2810 }
2811 if (multi_attr)
2812 {
2813 ScreenAttrs[off] = multi_attr;
2814 multi_attr = 0;
2815 }
2816 else
2817 ScreenAttrs[off] = char_attr;
2818
2819 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2820 {
2821 // Need to fill two screen columns.
2822 ++off;
2823 ++col;
2824 if (enc_utf8)
2825 // UTF-8: Put a 0 in the second screen char.
2826 ScreenLines[off] = 0;
2827 else
2828 // DBCS: Put second byte in the second screen char.
2829 ScreenLines[off] = mb_c & 0xff;
2830 if (draw_state > WL_NR
2831#ifdef FEAT_DIFF
2832 && filler_todo <= 0
2833#endif
2834 )
2835 ++vcol;
2836 // When "tocol" is halfway a character, set it to the end of
2837 // the character, otherwise highlighting won't stop.
2838 if (tocol == vcol)
2839 ++tocol;
2840#ifdef FEAT_RIGHTLEFT
2841 if (wp->w_p_rl)
2842 {
2843 // now it's time to backup one cell
2844 --off;
2845 --col;
2846 }
2847#endif
2848 }
2849#ifdef FEAT_RIGHTLEFT
2850 if (wp->w_p_rl)
2851 {
2852 --off;
2853 --col;
2854 }
2855 else
2856#endif
2857 {
2858 ++off;
2859 ++col;
2860 }
2861 }
2862#ifdef FEAT_CONCEAL
2863 else if (wp->w_p_cole > 0 && is_concealing)
2864 {
2865 --n_skip;
2866 ++vcol_off;
2867 if (n_extra > 0)
2868 vcol_off += n_extra;
2869 if (wp->w_p_wrap)
2870 {
2871 // Special voodoo required if 'wrap' is on.
2872 //
2873 // Advance the column indicator to force the line
2874 // drawing to wrap early. This will make the line
2875 // take up the same screen space when parts are concealed,
2876 // so that cursor line computations aren't messed up.
2877 //
2878 // To avoid the fictitious advance of 'col' causing
2879 // trailing junk to be written out of the screen line
2880 // we are building, 'boguscols' keeps track of the number
2881 // of bad columns we have advanced.
2882 if (n_extra > 0)
2883 {
2884 vcol += n_extra;
2885# ifdef FEAT_RIGHTLEFT
2886 if (wp->w_p_rl)
2887 {
2888 col -= n_extra;
2889 boguscols -= n_extra;
2890 }
2891 else
2892# endif
2893 {
2894 col += n_extra;
2895 boguscols += n_extra;
2896 }
2897 n_extra = 0;
2898 n_attr = 0;
2899 }
2900
2901
2902 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2903 {
2904 // Need to fill two screen columns.
2905# ifdef FEAT_RIGHTLEFT
2906 if (wp->w_p_rl)
2907 {
2908 --boguscols;
2909 --col;
2910 }
2911 else
2912# endif
2913 {
2914 ++boguscols;
2915 ++col;
2916 }
2917 }
2918
2919# ifdef FEAT_RIGHTLEFT
2920 if (wp->w_p_rl)
2921 {
2922 --boguscols;
2923 --col;
2924 }
2925 else
2926# endif
2927 {
2928 ++boguscols;
2929 ++col;
2930 }
2931 }
2932 else
2933 {
2934 if (n_extra > 0)
2935 {
2936 vcol += n_extra;
2937 n_extra = 0;
2938 n_attr = 0;
2939 }
2940 }
2941
2942 }
2943#endif // FEAT_CONCEAL
2944 else
2945 --n_skip;
2946
2947 // Only advance the "vcol" when after the 'number' or 'relativenumber'
2948 // column.
2949 if (draw_state > WL_NR
2950#ifdef FEAT_DIFF
2951 && filler_todo <= 0
2952#endif
2953 )
2954 ++vcol;
2955
2956#ifdef FEAT_SYN_HL
2957 if (vcol_save_attr >= 0)
2958 char_attr = vcol_save_attr;
2959#endif
2960
2961 // restore attributes after "predeces" in 'listchars'
2962 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
2963 char_attr = saved_attr3;
2964
2965 // restore attributes after last 'listchars' or 'number' char
2966 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
2967 char_attr = saved_attr2;
2968
2969 // At end of screen line and there is more to come: Display the line
2970 // so far. If there is no more to display it is caught above.
2971 if ((
2972#ifdef FEAT_RIGHTLEFT
2973 wp->w_p_rl ? (col < 0) :
2974#endif
2975 (col >= wp->w_width))
2976 && (*ptr != NUL
2977#ifdef FEAT_DIFF
2978 || filler_todo > 0
2979#endif
2980 || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
2981 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
2982 )
2983 {
2984#ifdef FEAT_CONCEAL
2985 screen_line(screen_row, wp->w_wincol, col - boguscols,
2986 (int)wp->w_width, screen_line_flags);
2987 boguscols = 0;
2988#else
2989 screen_line(screen_row, wp->w_wincol, col,
2990 (int)wp->w_width, screen_line_flags);
2991#endif
2992 ++row;
2993 ++screen_row;
2994
2995 // When not wrapping and finished diff lines, or when displayed
2996 // '$' and highlighting until last column, break here.
2997 if ((!wp->w_p_wrap
2998#ifdef FEAT_DIFF
2999 && filler_todo <= 0
3000#endif
3001 ) || lcs_eol_one == -1)
3002 break;
3003
3004 // When the window is too narrow draw all "@" lines.
3005 if (draw_state != WL_LINE
3006#ifdef FEAT_DIFF
3007 && filler_todo <= 0
3008#endif
3009 )
3010 {
3011 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3012 draw_vsep_win(wp, row);
3013 row = endrow;
3014 }
3015
3016 // When line got too long for screen break here.
3017 if (row == endrow)
3018 {
3019 ++row;
3020 break;
3021 }
3022
3023 if (screen_cur_row == screen_row - 1
3024#ifdef FEAT_DIFF
3025 && filler_todo <= 0
3026#endif
3027 && wp->w_width == Columns)
3028 {
3029 // Remember that the line wraps, used for modeless copy.
3030 LineWraps[screen_row - 1] = TRUE;
3031
3032 // Special trick to make copy/paste of wrapped lines work with
3033 // xterm/screen: write an extra character beyond the end of
3034 // the line. This will work with all terminal types
3035 // (regardless of the xn,am settings).
3036 // Only do this on a fast tty.
3037 // Only do this if the cursor is on the current line
3038 // (something has been written in it).
3039 // Don't do this for the GUI.
3040 // Don't do this for double-width characters.
3041 // Don't do this for a window not at the right screen border.
3042 if (p_tf
3043#ifdef FEAT_GUI
3044 && !gui.in_use
3045#endif
3046 && !(has_mbyte
3047 && ((*mb_off2cells)(LineOffset[screen_row],
3048 LineOffset[screen_row] + screen_Columns)
3049 == 2
3050 || (*mb_off2cells)(LineOffset[screen_row - 1]
3051 + (int)Columns - 2,
3052 LineOffset[screen_row] + screen_Columns)
3053 == 2)))
3054 {
3055 // First make sure we are at the end of the screen line,
3056 // then output the same character again to let the
3057 // terminal know about the wrap. If the terminal doesn't
3058 // auto-wrap, we overwrite the character.
3059 if (screen_cur_col != wp->w_width)
3060 screen_char(LineOffset[screen_row - 1]
3061 + (unsigned)Columns - 1,
3062 screen_row - 1, (int)(Columns - 1));
3063
3064 // When there is a multi-byte character, just output a
3065 // space to keep it simple.
3066 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3067 screen_row - 1] + (Columns - 1)]) > 1)
3068 out_char(' ');
3069 else
3070 out_char(ScreenLines[LineOffset[screen_row - 1]
3071 + (Columns - 1)]);
3072 // force a redraw of the first char on the next line
3073 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3074 screen_start(); // don't know where cursor is now
3075 }
3076 }
3077
3078 col = 0;
3079 off = (unsigned)(current_ScreenLine - ScreenLines);
3080#ifdef FEAT_RIGHTLEFT
3081 if (wp->w_p_rl)
3082 {
3083 col = wp->w_width - 1; // col is not used if breaking!
3084 off += col;
3085 }
3086#endif
3087
3088 // reset the drawing state for the start of a wrapped line
3089 draw_state = WL_START;
3090 saved_n_extra = n_extra;
3091 saved_p_extra = p_extra;
3092 saved_c_extra = c_extra;
3093 saved_c_final = c_final;
3094#ifdef FEAT_SYN_HL
3095 if (!(cul_screenline
3096# ifdef FEAT_DIFF
3097 && diff_hlf == (hlf_T)0)
3098# endif
3099 )
3100 saved_char_attr = char_attr;
3101 else
3102#endif
3103 saved_char_attr = 0;
3104 n_extra = 0;
3105 lcs_prec_todo = lcs_prec;
3106#ifdef FEAT_LINEBREAK
3107# ifdef FEAT_DIFF
3108 if (filler_todo <= 0)
3109# endif
3110 need_showbreak = TRUE;
3111#endif
3112#ifdef FEAT_DIFF
3113 --filler_todo;
3114 // When the filler lines are actually below the last line of the
3115 // file, don't draw the line itself, break here.
3116 if (filler_todo == 0 && wp->w_botfill)
3117 break;
3118#endif
3119 }
3120
3121 } // for every character in the line
3122
3123#ifdef FEAT_SPELL
3124 // After an empty line check first word for capital.
3125 if (*skipwhite(line) == NUL)
3126 {
3127 capcol_lnum = lnum + 1;
3128 cap_col = 0;
3129 }
3130#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003131#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 vim_free(text_props);
3133 vim_free(text_prop_idxs);
3134#endif
3135
3136 vim_free(p_extra_free);
3137 return row;
3138}