blob: 7d6d4fd8aa26f7273408fa600733c36d12b7d6f3 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
12 * This is the middle level, drawscreen. is the higher level and screen.c the
13 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
78#ifdef FEAT_SIGNS
79/*
Bram Moolenaare413ea02021-11-24 16:20:13 +000080 * Return TRUE if CursorLineSign highlight is to be used.
81 */
82 static int
83use_cursor_line_sign(win_T *wp, linenr_T lnum)
84{
85 return wp->w_p_cul
86 && lnum == wp->w_cursor.lnum
87 && (wp->w_p_culopt_flags & CULOPT_NBR);
88}
89
90/*
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020091 * Get information needed to display the sign in line 'lnum' in window 'wp'.
92 * If 'nrcol' is TRUE, the sign is going to be displayed in the number column.
93 * Otherwise the sign is going to be displayed in the sign column.
94 */
95 static void
96get_sign_display_info(
97 int nrcol,
98 win_T *wp,
Bram Moolenaare413ea02021-11-24 16:20:13 +000099 linenr_T lnum,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200100 sign_attrs_T *sattr,
101 int wcr_attr,
102 int row,
103 int startrow,
104 int filler_lines UNUSED,
105 int filler_todo UNUSED,
106 int *c_extrap,
107 int *c_finalp,
108 char_u *extra,
109 char_u **pp_extra,
110 int *n_extrap,
111 int *char_attrp)
112{
113 int text_sign;
114# ifdef FEAT_SIGN_ICONS
115 int icon_sign;
116# endif
117
118 // Draw two cells with the sign value or blank.
119 *c_extrap = ' ';
120 *c_finalp = NUL;
121 if (nrcol)
122 *n_extrap = number_width(wp) + 1;
123 else
124 {
Bram Moolenaare413ea02021-11-24 16:20:13 +0000125 if (use_cursor_line_sign(wp, lnum))
126 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLS));
127 else
128 *char_attrp = hl_combine_attr(wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200129 *n_extrap = 2;
130 }
131
132 if (row == startrow
133#ifdef FEAT_DIFF
134 + filler_lines && filler_todo <= 0
135#endif
136 )
137 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200138 text_sign = (sattr->sat_text != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200139# ifdef FEAT_SIGN_ICONS
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200140 icon_sign = (sattr->sat_icon != NULL) ? sattr->sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200141 if (gui.in_use && icon_sign != 0)
142 {
143 // Use the image in this position.
144 if (nrcol)
145 {
146 *c_extrap = NUL;
147 sprintf((char *)extra, "%-*c ", number_width(wp), SIGN_BYTE);
148 *pp_extra = extra;
149 *n_extrap = (int)STRLEN(*pp_extra);
150 }
151 else
152 *c_extrap = SIGN_BYTE;
153# ifdef FEAT_NETBEANS_INTG
154 if (netbeans_active() && (buf_signcount(wp->w_buffer, lnum) > 1))
155 {
156 if (nrcol)
157 {
158 *c_extrap = NUL;
159 sprintf((char *)extra, "%-*c ", number_width(wp),
160 MULTISIGN_BYTE);
161 *pp_extra = extra;
162 *n_extrap = (int)STRLEN(*pp_extra);
163 }
164 else
165 *c_extrap = MULTISIGN_BYTE;
166 }
167# endif
168 *c_finalp = NUL;
169 *char_attrp = icon_sign;
170 }
171 else
172# endif
173 if (text_sign != 0)
174 {
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200175 *pp_extra = sattr->sat_text;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200176 if (*pp_extra != NULL)
177 {
178 if (nrcol)
179 {
180 int n, width = number_width(wp) - 2;
181
182 for (n = 0; n < width; n++)
183 extra[n] = ' ';
184 extra[n] = 0;
185 STRCAT(extra, *pp_extra);
186 STRCAT(extra, " ");
187 *pp_extra = extra;
188 }
189 *c_extrap = NUL;
190 *c_finalp = NUL;
191 *n_extrap = (int)STRLEN(*pp_extra);
192 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000193
194 if (use_cursor_line_sign(wp, lnum) && sattr->sat_culhl > 0)
195 *char_attrp = sattr->sat_culhl;
196 else
197 *char_attrp = sattr->sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200198 }
199 }
200}
201#endif
202
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100203#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200204static textprop_T *current_text_props = NULL;
205static buf_T *current_buf = NULL;
206
207 static int
208text_prop_compare(const void *s1, const void *s2)
209{
210 int idx1, idx2;
211 proptype_T *pt1, *pt2;
212 colnr_T col1, col2;
213
214 idx1 = *(int *)s1;
215 idx2 = *(int *)s2;
216 pt1 = text_prop_type_by_id(current_buf, current_text_props[idx1].tp_type);
217 pt2 = text_prop_type_by_id(current_buf, current_text_props[idx2].tp_type);
218 if (pt1 == pt2)
219 return 0;
220 if (pt1 == NULL)
221 return -1;
222 if (pt2 == NULL)
223 return 1;
224 if (pt1->pt_priority != pt2->pt_priority)
225 return pt1->pt_priority > pt2->pt_priority ? 1 : -1;
226 col1 = current_text_props[idx1].tp_col;
227 col2 = current_text_props[idx2].tp_col;
228 return col1 == col2 ? 0 : col1 > col2 ? 1 : -1;
229}
230#endif
231
232/*
233 * Display line "lnum" of window 'wp' on the screen.
234 * Start at row "startrow", stop when "endrow" is reached.
235 * wp->w_virtcol needs to be valid.
236 *
237 * Return the number of last row the line occupies.
238 */
239 int
240win_line(
241 win_T *wp,
242 linenr_T lnum,
243 int startrow,
244 int endrow,
245 int nochange UNUSED, // not updating for changed text
246 int number_only) // only update the number column
247{
248 int col = 0; // visual column on screen
249 unsigned off; // offset in ScreenLines/ScreenAttrs
250 int c = 0; // init for GCC
251 long vcol = 0; // virtual column (for tabs)
252#ifdef FEAT_LINEBREAK
253 long vcol_sbr = -1; // virtual column after showbreak
254#endif
255 long vcol_prev = -1; // "vcol" of previous character
256 char_u *line; // current line
257 char_u *ptr; // current position in "line"
258 int row; // row in the window, excl w_winrow
259 int screen_row; // row on the screen, incl w_winrow
260
261 char_u extra[21]; // "%ld " and 'fdc' must fit in here
262 int n_extra = 0; // number of extra chars
263 char_u *p_extra = NULL; // string of extra chars, plus NUL
264 char_u *p_extra_free = NULL; // p_extra needs to be freed
265 int c_extra = NUL; // extra chars, all the same
266 int c_final = NUL; // final char, mandatory if set
267 int extra_attr = 0; // attributes when n_extra != 0
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000268#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +0000269 int in_linebreak = FALSE; // n_extra set for showing linebreak
270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200271 static char_u *at_end_str = (char_u *)""; // used for p_extra when
Bram Moolenaareed9d462021-02-15 20:38:25 +0100272 // displaying eol at end-of-line
273 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +0000274 int lcs_prec_todo = wp->w_lcs_chars.prec;
275 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200276
277 // saved "extra" items for when draw_state becomes WL_LINE (again)
278 int saved_n_extra = 0;
279 char_u *saved_p_extra = NULL;
280 int saved_c_extra = 0;
281 int saved_c_final = 0;
282 int saved_char_attr = 0;
283
284 int n_attr = 0; // chars with special attr
285 int saved_attr2 = 0; // char_attr saved for n_attr
286 int n_attr3 = 0; // chars with overruling special attr
287 int saved_attr3 = 0; // char_attr saved for n_attr3
288
289 int n_skip = 0; // nr of chars to skip for 'nowrap'
290
291 int fromcol = -10; // start of inverting
292 int tocol = MAXCOL; // end of inverting
293 int fromcol_prev = -2; // start of inverting after cursor
294 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 int lnum_in_visual_area = FALSE;
296 pos_T pos;
297 long v;
298
299 int char_attr = 0; // attributes for next character
300 int attr_pri = FALSE; // char_attr has priority
301 int area_highlighting = FALSE; // Visual or incsearch highlighting
302 // in this line
303 int vi_attr = 0; // attributes for Visual and incsearch
304 // highlighting
305 int wcr_attr = 0; // attributes from 'wincolor'
306 int win_attr = 0; // background for whole window, except
307 // margins and "~" lines.
308 int area_attr = 0; // attributes desired by highlighting
309 int search_attr = 0; // attributes desired by 'hlsearch'
310#ifdef FEAT_SYN_HL
311 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
312 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +0200313 int prev_syntax_col = -1; // column of prev_syntax_attr
314 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200315 int has_syntax = FALSE; // this buffer has syntax highl.
316 int save_did_emsg;
317 int draw_color_col = FALSE; // highlight colorcolumn
318 int *color_cols = NULL; // pointer to according columns array
319#endif
320 int eol_hl_off = 0; // 1 if highlighted char after EOL
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100321#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200322 int text_prop_count;
323 int text_prop_next = 0; // next text property to use
324 textprop_T *text_props = NULL;
325 int *text_prop_idxs = NULL;
326 int text_props_active = 0;
327 proptype_T *text_prop_type = NULL;
328 int text_prop_attr = 0;
329 int text_prop_combine = FALSE;
330#endif
331#ifdef FEAT_SPELL
332 int has_spell = FALSE; // this buffer has spell checking
Bram Moolenaar34390282019-10-16 14:38:26 +0200333 int can_spell;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200334# define SPWORDLEN 150
335 char_u nextline[SPWORDLEN * 2];// text with start of the next line
336 int nextlinecol = 0; // column where nextline[] starts
337 int nextline_idx = 0; // index in nextline[] where next line
338 // starts
339 int spell_attr = 0; // attributes desired by spelling
340 int word_end = 0; // last byte with same spell_attr
341 static linenr_T checked_lnum = 0; // line number for "checked_col"
342 static int checked_col = 0; // column in "checked_lnum" up to which
343 // there are no spell errors
344 static int cap_col = -1; // column to check for Cap word
345 static linenr_T capcol_lnum = 0; // line number where "cap_col" used
346 int cur_checked_col = 0; // checked column for current line
347#endif
348 int extra_check = 0; // has extra highlighting
349 int multi_attr = 0; // attributes desired by multibyte
350 int mb_l = 1; // multi-byte byte length
351 int mb_c = 0; // decoded multi-byte character
352 int mb_utf8 = FALSE; // screen char is UTF-8 char
353 int u8cc[MAX_MCO]; // composing UTF-8 chars
354#if defined(FEAT_DIFF) || defined(FEAT_SIGNS)
355 int filler_lines = 0; // nr of filler lines to be drawn
356 int filler_todo = 0; // nr of filler lines still to do + 1
357#endif
358#ifdef FEAT_DIFF
359 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
360 int change_start = MAXCOL; // first col of changed area
361 int change_end = -1; // last col of changed area
362#endif
363 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100364 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200365 int in_multispace = FALSE; // in multiple consecutive spaces
366 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200367#ifdef FEAT_LINEBREAK
368 int need_showbreak = FALSE; // overlong line, skipping first x
369 // chars
370#endif
371#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
372 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
373# define LINE_ATTR
374 int line_attr = 0; // attribute for the whole line
375 int line_attr_save;
376#endif
377#ifdef FEAT_SIGNS
378 int sign_present = FALSE;
379 sign_attrs_T sattr;
380#endif
381#ifdef FEAT_ARABIC
382 int prev_c = 0; // previous Arabic character
383 int prev_c1 = 0; // first composing char for prev_c
384#endif
385#if defined(LINE_ATTR)
386 int did_line_attr = 0;
387#endif
388#ifdef FEAT_TERMINAL
389 int get_term_attr = FALSE;
390#endif
391#ifdef FEAT_SYN_HL
392 int cul_attr = 0; // set when 'cursorline' active
393
394 // 'cursorlineopt' has "screenline" and cursor is in this line
395 int cul_screenline = FALSE;
396
397 // margin columns for the screen line, needed for when 'cursorlineopt'
398 // contains "screenline"
399 int left_curline_col = 0;
400 int right_curline_col = 0;
401#endif
402
403 // draw_state: items that are drawn in sequence:
404#define WL_START 0 // nothing done yet
405#ifdef FEAT_CMDWIN
406# define WL_CMDLINE WL_START + 1 // cmdline window column
407#else
408# define WL_CMDLINE WL_START
409#endif
410#ifdef FEAT_FOLDING
411# define WL_FOLD WL_CMDLINE + 1 // 'foldcolumn'
412#else
413# define WL_FOLD WL_CMDLINE
414#endif
415#ifdef FEAT_SIGNS
416# define WL_SIGN WL_FOLD + 1 // column for signs
417#else
418# define WL_SIGN WL_FOLD // column for signs
419#endif
420#define WL_NR WL_SIGN + 1 // line number
421#ifdef FEAT_LINEBREAK
422# define WL_BRI WL_NR + 1 // 'breakindent'
423#else
424# define WL_BRI WL_NR
425#endif
426#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
427# define WL_SBR WL_BRI + 1 // 'showbreak' or 'diff'
428#else
429# define WL_SBR WL_BRI
430#endif
431#define WL_LINE WL_SBR + 1 // text in the line
432 int draw_state = WL_START; // what to draw next
433#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
434 int feedback_col = 0;
435 int feedback_old_attr = -1;
436#endif
437 int screen_line_flags = 0;
438
439#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
440 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000441 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200442#endif
443#ifdef FEAT_CONCEAL
444 int syntax_flags = 0;
445 int syntax_seqnr = 0;
446 int prev_syntax_id = 0;
447 int conceal_attr = HL_ATTR(HLF_CONCEAL);
448 int is_concealing = FALSE;
449 int boguscols = 0; // nonexistent columns added to force
450 // wrapping
451 int vcol_off = 0; // offset for concealed characters
452 int did_wcol = FALSE;
453 int old_boguscols = 0;
454# define VCOL_HLC (vcol - vcol_off)
455# define FIX_FOR_BOGUSCOLS \
456 { \
457 n_extra += vcol_off; \
458 vcol -= vcol_off; \
459 vcol_off = 0; \
460 col -= boguscols; \
461 old_boguscols = boguscols; \
462 boguscols = 0; \
463 }
464#else
465# define VCOL_HLC (vcol)
466#endif
467
468 if (startrow > endrow) // past the end already!
469 return startrow;
470
471 row = startrow;
472 screen_row = row + W_WINROW(wp);
473
474 if (!number_only)
475 {
476 // To speed up the loop below, set extra_check when there is linebreak,
477 // trailing white space and/or syntax processing to be done.
478#ifdef FEAT_LINEBREAK
479 extra_check = wp->w_p_lbr;
480#endif
481#ifdef FEAT_SYN_HL
482 if (syntax_present(wp) && !wp->w_s->b_syn_error
483# ifdef SYN_TIME_LIMIT
484 && !wp->w_s->b_syn_slow
485# endif
486 )
487 {
488 // Prepare for syntax highlighting in this line. When there is an
489 // error, stop syntax highlighting.
490 save_did_emsg = did_emsg;
491 did_emsg = FALSE;
492 syntax_start(wp, lnum);
493 if (did_emsg)
494 wp->w_s->b_syn_error = TRUE;
495 else
496 {
497 did_emsg = save_did_emsg;
498#ifdef SYN_TIME_LIMIT
499 if (!wp->w_s->b_syn_slow)
500#endif
501 {
502 has_syntax = TRUE;
503 extra_check = TRUE;
504 }
505 }
506 }
507
508 // Check for columns to display for 'colorcolumn'.
509 color_cols = wp->w_p_cc_cols;
510 if (color_cols != NULL)
511 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
512#endif
513
514#ifdef FEAT_TERMINAL
515 if (term_show_buffer(wp->w_buffer))
516 {
517 extra_check = TRUE;
518 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100519 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200520 }
521#endif
522
523#ifdef FEAT_SPELL
524 if (wp->w_p_spell
525 && *wp->w_s->b_p_spl != NUL
526 && wp->w_s->b_langp.ga_len > 0
527 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
528 {
529 // Prepare for spell checking.
530 has_spell = TRUE;
531 extra_check = TRUE;
532
533 // Get the start of the next line, so that words that wrap to the
534 // next line are found too: "et<line-break>al.".
535 // Trick: skip a few chars for C/shell/Vim comments
536 nextline[SPWORDLEN] = NUL;
537 if (lnum < wp->w_buffer->b_ml.ml_line_count)
538 {
539 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
540 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
541 }
542
543 // When a word wrapped from the previous line the start of the
544 // current line is valid.
545 if (lnum == checked_lnum)
546 cur_checked_col = checked_col;
547 checked_lnum = 0;
548
549 // When there was a sentence end in the previous line may require a
550 // word starting with capital in this line. In line 1 always check
551 // the first word.
552 if (lnum != capcol_lnum)
553 cap_col = -1;
554 if (lnum == 1)
555 cap_col = 0;
556 capcol_lnum = 0;
557 }
558#endif
559
560 // handle Visual active in this window
561 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
562 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100563 pos_T *top, *bot;
564
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200565 if (LTOREQ_POS(curwin->w_cursor, VIsual))
566 {
567 // Visual is after curwin->w_cursor
568 top = &curwin->w_cursor;
569 bot = &VIsual;
570 }
571 else
572 {
573 // Visual is before curwin->w_cursor
574 top = &VIsual;
575 bot = &curwin->w_cursor;
576 }
577 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
578 if (VIsual_mode == Ctrl_V)
579 {
580 // block mode
581 if (lnum_in_visual_area)
582 {
583 fromcol = wp->w_old_cursor_fcol;
584 tocol = wp->w_old_cursor_lcol;
585 }
586 }
587 else
588 {
589 // non-block mode
590 if (lnum > top->lnum && lnum <= bot->lnum)
591 fromcol = 0;
592 else if (lnum == top->lnum)
593 {
594 if (VIsual_mode == 'V') // linewise
595 fromcol = 0;
596 else
597 {
598 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
599 if (gchar_pos(top) == NUL)
600 tocol = fromcol + 1;
601 }
602 }
603 if (VIsual_mode != 'V' && lnum == bot->lnum)
604 {
605 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
606 {
607 fromcol = -10;
608 tocol = MAXCOL;
609 }
610 else if (bot->col == MAXCOL)
611 tocol = MAXCOL;
612 else
613 {
614 pos = *bot;
615 if (*p_sel == 'e')
616 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
617 else
618 {
619 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
620 ++tocol;
621 }
622 }
623 }
624 }
625
626 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200627 if (!highlight_match && lnum == curwin->w_cursor.lnum
628 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200629#ifdef FEAT_GUI
630 && !gui.in_use
631#endif
632 )
633 noinvcur = TRUE;
634
635 // if inverting in this line set area_highlighting
636 if (fromcol >= 0)
637 {
638 area_highlighting = TRUE;
639 vi_attr = HL_ATTR(HLF_V);
640#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
641 if ((clip_star.available && !clip_star.owned
642 && clip_isautosel_star())
643 || (clip_plus.available && !clip_plus.owned
644 && clip_isautosel_plus()))
645 vi_attr = HL_ATTR(HLF_VNC);
646#endif
647 }
648 }
649
650 // handle 'incsearch' and ":s///c" highlighting
651 else if (highlight_match
652 && wp == curwin
653 && lnum >= curwin->w_cursor.lnum
654 && lnum <= curwin->w_cursor.lnum + search_match_lines)
655 {
656 if (lnum == curwin->w_cursor.lnum)
657 getvcol(curwin, &(curwin->w_cursor),
658 (colnr_T *)&fromcol, NULL, NULL);
659 else
660 fromcol = 0;
661 if (lnum == curwin->w_cursor.lnum + search_match_lines)
662 {
663 pos.lnum = lnum;
664 pos.col = search_match_endcol;
665 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
666 }
667 else
668 tocol = MAXCOL;
669 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100670 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200671 tocol = fromcol + 1;
672 area_highlighting = TRUE;
673 vi_attr = HL_ATTR(HLF_I);
674 }
675 }
676
677#ifdef FEAT_DIFF
678 filler_lines = diff_check(wp, lnum);
679 if (filler_lines < 0)
680 {
681 if (filler_lines == -1)
682 {
683 if (diff_find_change(wp, lnum, &change_start, &change_end))
684 diff_hlf = HLF_ADD; // added line
685 else if (change_start == 0)
686 diff_hlf = HLF_TXD; // changed text
687 else
688 diff_hlf = HLF_CHD; // changed line
689 }
690 else
691 diff_hlf = HLF_ADD; // added line
692 filler_lines = 0;
693 area_highlighting = TRUE;
694 }
695 if (lnum == wp->w_topline)
696 filler_lines = wp->w_topfill;
697 filler_todo = filler_lines;
698#endif
699
700#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100701 sign_present = buf_get_signattrs(wp, lnum, &sattr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200702#endif
703
704#ifdef LINE_ATTR
705# ifdef FEAT_SIGNS
706 // If this line has a sign with line highlighting set line_attr.
707 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200708 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200709# endif
710# if defined(FEAT_QUICKFIX)
711 // Highlight the current line in the quickfix window.
712 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
713 line_attr = HL_ATTR(HLF_QFL);
714# endif
715 if (line_attr != 0)
716 area_highlighting = TRUE;
717#endif
718
719 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
720 ptr = line;
721
722#ifdef FEAT_SPELL
723 if (has_spell && !number_only)
724 {
725 // For checking first word with a capital skip white space.
726 if (cap_col == 0)
727 cap_col = getwhitecols(line);
728
729 // To be able to spell-check over line boundaries copy the end of the
730 // current line into nextline[]. Above the start of the next line was
731 // copied to nextline[SPWORDLEN].
732 if (nextline[SPWORDLEN] == NUL)
733 {
734 // No next line or it is empty.
735 nextlinecol = MAXCOL;
736 nextline_idx = 0;
737 }
738 else
739 {
740 v = (long)STRLEN(line);
741 if (v < SPWORDLEN)
742 {
743 // Short line, use it completely and append the start of the
744 // next line.
745 nextlinecol = 0;
746 mch_memmove(nextline, line, (size_t)v);
747 STRMOVE(nextline + v, nextline + SPWORDLEN);
748 nextline_idx = v + 1;
749 }
750 else
751 {
752 // Long line, use only the last SPWORDLEN bytes.
753 nextlinecol = v - SPWORDLEN;
754 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
755 nextline_idx = SPWORDLEN + 1;
756 }
757 }
758 }
759#endif
760
761 if (wp->w_p_list)
762 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100763 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200764 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100765 || wp->w_lcs_chars.trail
766 || wp->w_lcs_chars.lead
767 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200768 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100769
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200770 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100771 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200772 {
773 trailcol = (colnr_T)STRLEN(ptr);
774 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
775 --trailcol;
776 trailcol += (colnr_T) (ptr - line);
777 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100778 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100779 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100780 {
781 leadcol = 0;
782 while (VIM_ISWHITE(ptr[leadcol]))
783 ++leadcol;
784 if (ptr[leadcol] == NUL)
785 // in a line full of spaces all of them are treated as trailing
786 leadcol = (colnr_T)0;
787 else
788 // keep track of the first column not filled with spaces
789 leadcol += (colnr_T) (ptr - line) + 1;
790 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200791 }
792
793 wcr_attr = get_wcr_attr(wp);
794 if (wcr_attr != 0)
795 {
796 win_attr = wcr_attr;
797 area_highlighting = TRUE;
798 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200799
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100800#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200801 if (WIN_IS_POPUP(wp))
802 screen_line_flags |= SLF_POPUP;
803#endif
804
805 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
806 // first character to be displayed.
807 if (wp->w_p_wrap)
808 v = wp->w_skipcol;
809 else
810 v = wp->w_leftcol;
811 if (v > 0 && !number_only)
812 {
813 char_u *prev_ptr = ptr;
814
815 while (vcol < v && *ptr != NUL)
816 {
817 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
818 vcol += c;
819 prev_ptr = ptr;
820 MB_PTR_ADV(ptr);
821 }
822
823 // When:
824 // - 'cuc' is set, or
825 // - 'colorcolumn' is set, or
826 // - 'virtualedit' is set, or
827 // - the visual mode is active,
828 // the end of the line may be before the start of the displayed part.
829 if (vcol < v && (
830#ifdef FEAT_SYN_HL
831 wp->w_p_cuc || draw_color_col ||
832#endif
833 virtual_active() ||
834 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
835 vcol = v;
836
837 // Handle a character that's not completely on the screen: Put ptr at
838 // that character but skip the first few screen characters.
839 if (vcol > v)
840 {
841 vcol -= c;
842 ptr = prev_ptr;
843 // If the character fits on the screen, don't need to skip it.
844 // Except for a TAB.
845 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
846 n_skip = v - vcol;
847 }
848
849 // Adjust for when the inverted text is before the screen,
850 // and when the start of the inverted text is before the screen.
851 if (tocol <= vcol)
852 fromcol = 0;
853 else if (fromcol >= 0 && fromcol < vcol)
854 fromcol = vcol;
855
856#ifdef FEAT_LINEBREAK
857 // When w_skipcol is non-zero, first line needs 'showbreak'
858 if (wp->w_p_wrap)
859 need_showbreak = TRUE;
860#endif
861#ifdef FEAT_SPELL
862 // When spell checking a word we need to figure out the start of the
863 // word and if it's badly spelled or not.
864 if (has_spell)
865 {
866 int len;
867 colnr_T linecol = (colnr_T)(ptr - line);
868 hlf_T spell_hlf = HLF_COUNT;
869
870 pos = wp->w_cursor;
871 wp->w_cursor.lnum = lnum;
872 wp->w_cursor.col = linecol;
873 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
874
875 // spell_move_to() may call ml_get() and make "line" invalid
876 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
877 ptr = line + linecol;
878
879 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
880 {
881 // no bad word found at line start, don't check until end of a
882 // word
883 spell_hlf = HLF_COUNT;
884 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
885 }
886 else
887 {
888 // bad word found, use attributes until end of word
889 word_end = wp->w_cursor.col + len + 1;
890
891 // Turn index into actual attributes.
892 if (spell_hlf != HLF_COUNT)
893 spell_attr = highlight_attr[spell_hlf];
894 }
895 wp->w_cursor = pos;
896
897# ifdef FEAT_SYN_HL
898 // Need to restart syntax highlighting for this line.
899 if (has_syntax)
900 syntax_start(wp, lnum);
901# endif
902 }
903#endif
904 }
905
906 // Correct highlighting for cursor that can't be disabled.
907 // Avoids having to check this for each character.
908 if (fromcol >= 0)
909 {
910 if (noinvcur)
911 {
912 if ((colnr_T)fromcol == wp->w_virtcol)
913 {
914 // highlighting starts at cursor, let it start just after the
915 // cursor
916 fromcol_prev = fromcol;
917 fromcol = -1;
918 }
919 else if ((colnr_T)fromcol < wp->w_virtcol)
920 // restart highlighting after the cursor
921 fromcol_prev = wp->w_virtcol;
922 }
923 if (fromcol >= tocol)
924 fromcol = -1;
925 }
926
927#ifdef FEAT_SEARCH_EXTRA
928 if (!number_only)
929 {
930 v = (long)(ptr - line);
931 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
932 &line, &screen_search_hl,
933 &search_attr);
934 ptr = line + v; // "line" may have been updated
935 }
936#endif
937
938#ifdef FEAT_SYN_HL
939 // Cursor line highlighting for 'cursorline' in the current window.
940 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
941 {
942 // Do not show the cursor line in the text when Visual mode is active,
943 // because it's not clear what is selected then. Do update
944 // w_last_cursorline.
945 if (!(wp == curwin && VIsual_active)
946 && wp->w_p_culopt_flags != CULOPT_NBR)
947 {
948 cul_screenline = (wp->w_p_wrap
949 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
950
951 // Only set line_attr here when "screenline" is not present in
952 // 'cursorlineopt'. Otherwise it's done later.
953 if (!cul_screenline)
954 {
955 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200956# ifdef FEAT_SIGNS
957 // Combine the 'cursorline' and sign highlighting, depending on
958 // the sign priority.
959 if (sign_present && sattr.sat_linehl > 0)
960 {
961 if (sattr.sat_priority >= 100)
962 line_attr = hl_combine_attr(cul_attr, line_attr);
963 else
964 line_attr = hl_combine_attr(line_attr, cul_attr);
965 }
966 else
967# endif
968 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200969 wp->w_last_cursorline = wp->w_cursor.lnum;
970 }
971 else
972 {
973 line_attr_save = line_attr;
974 wp->w_last_cursorline = 0;
975 margin_columns_win(wp, &left_curline_col, &right_curline_col);
976 }
977 area_highlighting = TRUE;
978 }
979 else
980 wp->w_last_cursorline = wp->w_cursor.lnum;
981 }
982#endif
983
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100984#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200985 {
986 char_u *prop_start;
987
988 text_prop_count = get_text_props(wp->w_buffer, lnum,
989 &prop_start, FALSE);
990 if (text_prop_count > 0)
991 {
992 // Make a copy of the properties, so that they are properly
993 // aligned.
994 text_props = ALLOC_MULT(textprop_T, text_prop_count);
995 if (text_props != NULL)
996 mch_memmove(text_props, prop_start,
997 text_prop_count * sizeof(textprop_T));
998
999 // Allocate an array for the indexes.
1000 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1001 area_highlighting = TRUE;
1002 extra_check = TRUE;
1003 }
1004 }
1005#endif
1006
1007 off = (unsigned)(current_ScreenLine - ScreenLines);
1008 col = 0;
1009
1010#ifdef FEAT_RIGHTLEFT
1011 if (wp->w_p_rl)
1012 {
1013 // Rightleft window: process the text in the normal direction, but put
1014 // it in current_ScreenLine[] from right to left. Start at the
1015 // rightmost column of the window.
1016 col = wp->w_width - 1;
1017 off += col;
1018 screen_line_flags |= SLF_RIGHTLEFT;
1019 }
1020#endif
1021
1022 // Repeat for the whole displayed line.
1023 for (;;)
1024 {
1025#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001026 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001027#endif
1028#ifdef FEAT_CONCEAL
1029 int did_decrement_ptr = FALSE;
1030#endif
1031 // Skip this quickly when working on the text.
1032 if (draw_state != WL_LINE)
1033 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001034#ifdef FEAT_SYN_HL
1035 if (cul_screenline)
1036 {
1037 cul_attr = 0;
1038 line_attr = line_attr_save;
1039 }
1040#endif
1041
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001042#ifdef FEAT_CMDWIN
1043 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1044 {
1045 draw_state = WL_CMDLINE;
1046 if (cmdwin_type != 0 && wp == curwin)
1047 {
1048 // Draw the cmdline character.
1049 n_extra = 1;
1050 c_extra = cmdwin_type;
1051 c_final = NUL;
1052 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1053 }
1054 }
1055#endif
1056
1057#ifdef FEAT_FOLDING
1058 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1059 {
1060 int fdc = compute_foldcolumn(wp, 0);
1061
1062 draw_state = WL_FOLD;
1063 if (fdc > 0)
1064 {
1065 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1066 // already be in use.
1067 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001068 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001069 if (p_extra_free != NULL)
1070 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001071 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001072 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001073 p_extra_free[n_extra] = NUL;
1074 p_extra = p_extra_free;
1075 c_extra = NUL;
1076 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001077 if (use_cursor_line_sign(wp, lnum))
1078 char_attr =
1079 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1080 else
1081 char_attr =
1082 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001083 }
1084 }
1085 }
1086#endif
1087
1088#ifdef FEAT_SIGNS
1089 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1090 {
1091 draw_state = WL_SIGN;
1092 // Show the sign column when there are any signs in this
1093 // buffer or when using Netbeans.
1094 if (signcolumn_on(wp))
1095 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1096 row, startrow, filler_lines, filler_todo, &c_extra,
1097 &c_final, extra, &p_extra, &n_extra, &char_attr);
1098 }
1099#endif
1100
1101 if (draw_state == WL_NR - 1 && n_extra == 0)
1102 {
1103 draw_state = WL_NR;
1104 // Display the absolute or relative line number. After the
1105 // first fill with blanks when the 'n' flag isn't in 'cpo'
1106 if ((wp->w_p_nu || wp->w_p_rnu)
1107 && (row == startrow
1108#ifdef FEAT_DIFF
1109 + filler_lines
1110#endif
1111 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1112 {
1113#ifdef FEAT_SIGNS
1114 // If 'signcolumn' is set to 'number' and a sign is present
1115 // in 'lnum', then display the sign instead of the line
1116 // number.
1117 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1118 && sign_present)
1119 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1120 row, startrow, filler_lines, filler_todo,
1121 &c_extra, &c_final, extra, &p_extra, &n_extra,
1122 &char_attr);
1123 else
1124#endif
1125 {
1126 // Draw the line number (empty space after wrapping).
1127 if (row == startrow
1128#ifdef FEAT_DIFF
1129 + filler_lines
1130#endif
1131 )
1132 {
1133 long num;
1134 char *fmt = "%*ld ";
1135
1136 if (wp->w_p_nu && !wp->w_p_rnu)
1137 // 'number' + 'norelativenumber'
1138 num = (long)lnum;
1139 else
1140 {
1141 // 'relativenumber', don't use negative numbers
1142 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1143 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1144 {
1145 // 'number' + 'relativenumber'
1146 num = lnum;
1147 fmt = "%-*ld ";
1148 }
1149 }
1150
1151 sprintf((char *)extra, fmt,
1152 number_width(wp), num);
1153 if (wp->w_skipcol > 0)
1154 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1155 *p_extra = '-';
1156#ifdef FEAT_RIGHTLEFT
1157 if (wp->w_p_rl) // reverse line numbers
1158 {
1159 char_u *p1, *p2;
1160 int t;
1161
1162 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001163 p2 = skipwhite(extra);
1164 p2 = skiptowhite(p2) - 1;
1165 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 {
1167 t = *p1;
1168 *p1 = *p2;
1169 *p2 = t;
1170 }
1171 }
1172#endif
1173 p_extra = extra;
1174 c_extra = NUL;
1175 c_final = NUL;
1176 }
1177 else
1178 {
1179 c_extra = ' ';
1180 c_final = NUL;
1181 }
1182 n_extra = number_width(wp) + 1;
1183 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1184#ifdef FEAT_SYN_HL
1185 // When 'cursorline' is set highlight the line number of
1186 // the current line differently.
1187 // When 'cursorlineopt' has "screenline" only highlight
1188 // the line number itself.
1189 // TODO: Can we use CursorLine instead of CursorLineNr
1190 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001191 if (wp->w_p_cul
1192 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001193 && (wp->w_p_culopt_flags & CULOPT_NBR)
1194 && (row == startrow
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001195 || wp->w_p_culopt_flags & CULOPT_LINE))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001196 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1197#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001198 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1199 && HL_ATTR(HLF_LNA) != 0)
1200 // Use LineNrAbove
1201 char_attr = hl_combine_attr(wcr_attr,
1202 HL_ATTR(HLF_LNA));
1203 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1204 && HL_ATTR(HLF_LNB) != 0)
1205 // Use LineNrBelow
1206 char_attr = hl_combine_attr(wcr_attr,
1207 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208 }
1209 }
1210 }
1211
1212#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001213 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001214 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 // draw indent after showbreak value
1216 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001217 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 // After the showbreak, draw the breakindent
1219 draw_state = WL_BRI - 1;
1220
1221 // draw 'breakindent': indent wrapped text accordingly
1222 if (draw_state == WL_BRI - 1 && n_extra == 0)
1223 {
1224 draw_state = WL_BRI;
1225 // if need_showbreak is set, breakindent also applies
1226 if (wp->w_p_bri && n_extra == 0
1227 && (row != startrow || need_showbreak)
1228# ifdef FEAT_DIFF
1229 && filler_lines == 0
1230# endif
1231 )
1232 {
1233 char_attr = 0;
1234# ifdef FEAT_DIFF
1235 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001237# endif
1238 p_extra = NULL;
1239 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001240 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001241 n_extra = get_breakindent_win(wp,
1242 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001243 if (row == startrow)
1244 {
1245 n_extra -= win_col_off2(wp);
1246 if (n_extra < 0)
1247 n_extra = 0;
1248 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001249 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001250 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001251 // Correct end of highlighted area for 'breakindent',
1252 // required when 'linebreak' is also set.
1253 if (tocol == vcol)
1254 tocol += n_extra;
1255 }
1256 }
1257#endif
1258
1259#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1260 if (draw_state == WL_SBR - 1 && n_extra == 0)
1261 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001262 char_u *sbr;
1263
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264 draw_state = WL_SBR;
1265# ifdef FEAT_DIFF
1266 if (filler_todo > 0)
1267 {
1268 // Draw "deleted" diff line(s).
1269 if (char2cells(fill_diff) > 1)
1270 {
1271 c_extra = '-';
1272 c_final = NUL;
1273 }
1274 else
1275 {
1276 c_extra = fill_diff;
1277 c_final = NUL;
1278 }
1279# ifdef FEAT_RIGHTLEFT
1280 if (wp->w_p_rl)
1281 n_extra = col + 1;
1282 else
1283# endif
1284 n_extra = wp->w_width - col;
1285 char_attr = HL_ATTR(HLF_DED);
1286 }
1287# endif
1288# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001289 sbr = get_showbreak_value(wp);
1290 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001291 {
1292 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001293 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 c_extra = NUL;
1295 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001296 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001297 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1298 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001299 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001300 // Correct end of highlighted area for 'showbreak',
1301 // required when 'linebreak' is also set.
1302 if (tocol == vcol)
1303 tocol += n_extra;
1304 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001305 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001306# ifdef FEAT_SYN_HL
1307 // combine 'showbreak' with 'cursorline'
1308 if (cul_attr != 0)
1309 char_attr = hl_combine_attr(char_attr, cul_attr);
1310# endif
1311 }
1312# endif
1313 }
1314#endif
1315
1316 if (draw_state == WL_LINE - 1 && n_extra == 0)
1317 {
1318 draw_state = WL_LINE;
1319 if (saved_n_extra)
1320 {
1321 // Continue item from end of wrapped line.
1322 n_extra = saved_n_extra;
1323 c_extra = saved_c_extra;
1324 c_final = saved_c_final;
1325 p_extra = saved_p_extra;
1326 char_attr = saved_char_attr;
1327 }
1328 else
1329 char_attr = win_attr;
1330 }
1331 }
1332#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001333 if (cul_screenline && draw_state == WL_LINE
1334 && vcol >= left_curline_col
1335 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001337 cul_attr = HL_ATTR(HLF_CUL);
1338 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 }
1340#endif
1341
1342 // When still displaying '$' of change command, stop at cursor.
1343 // When only displaying the (relative) line number and that's done,
1344 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001345 if (((dollar_vcol >= 0 && wp == curwin
1346 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1347 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348#ifdef FEAT_DIFF
1349 && filler_todo <= 0
1350#endif
1351 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 {
1353 screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
1354 screen_line_flags);
1355 // Pretend we have finished updating the window. Except when
1356 // 'cursorcolumn' is set.
1357#ifdef FEAT_SYN_HL
1358 if (wp->w_p_cuc)
1359 row = wp->w_cline_row + wp->w_cline_height;
1360 else
1361#endif
1362 row = wp->w_height;
1363 break;
1364 }
1365
Bram Moolenaar34390282019-10-16 14:38:26 +02001366 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001367 {
1368 // handle Visual or match highlighting in this line
1369 if (vcol == fromcol
1370 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1371 && (*mb_ptr2cells)(ptr) > 1)
1372 || ((int)vcol_prev == fromcol_prev
1373 && vcol_prev < vcol // not at margin
1374 && vcol < tocol))
1375 area_attr = vi_attr; // start highlighting
1376 else if (area_attr != 0
1377 && (vcol == tocol
1378 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1379 area_attr = 0; // stop highlighting
1380
1381#ifdef FEAT_SEARCH_EXTRA
1382 if (!n_extra)
1383 {
1384 // Check for start/end of 'hlsearch' and other matches.
1385 // After end, check for start/end of next match.
1386 // When another match, have to check for start again.
1387 v = (long)(ptr - line);
1388 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1389 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001390 &match_conc, did_line_attr, lcs_eol_one,
1391 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001393
1394 // Do not allow a conceal over EOL otherwise EOL will be missed
1395 // and bad things happen.
1396 if (*ptr == NUL)
1397 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001398 }
1399#endif
1400
1401#ifdef FEAT_DIFF
1402 if (diff_hlf != (hlf_T)0)
1403 {
1404 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1405 && n_extra == 0)
1406 diff_hlf = HLF_TXD; // changed text
1407 if (diff_hlf == HLF_TXD && ptr - line > change_end
1408 && n_extra == 0)
1409 diff_hlf = HLF_CHD; // changed line
1410 line_attr = HL_ATTR(diff_hlf);
1411 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1412 && wp->w_p_culopt_flags != CULOPT_NBR
1413 && (!cul_screenline || (vcol >= left_curline_col
1414 && vcol <= right_curline_col)))
1415 line_attr = hl_combine_attr(
1416 line_attr, HL_ATTR(HLF_CUL));
1417 }
1418#endif
1419
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001420#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421 if (text_props != NULL)
1422 {
1423 int pi;
1424 int bcol = (int)(ptr - line);
1425
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001426 if (n_extra > 0
1427# ifdef FEAT_LINEBREAK
1428 && !in_linebreak
1429# endif
1430 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001431 --bcol; // still working on the previous char, e.g. Tab
1432
1433 // Check if any active property ends.
1434 for (pi = 0; pi < text_props_active; ++pi)
1435 {
1436 int tpi = text_prop_idxs[pi];
1437
1438 if (bcol >= text_props[tpi].tp_col - 1
1439 + text_props[tpi].tp_len)
1440 {
1441 if (pi + 1 < text_props_active)
1442 mch_memmove(text_prop_idxs + pi,
1443 text_prop_idxs + pi + 1,
1444 sizeof(int)
1445 * (text_props_active - (pi + 1)));
1446 --text_props_active;
1447 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001448# ifdef FEAT_LINEBREAK
1449 // not exactly right but should work in most cases
1450 if (in_linebreak && syntax_attr == text_prop_attr)
1451 syntax_attr = 0;
1452# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 }
1454 }
1455
1456 // Add any text property that starts in this column.
1457 while (text_prop_next < text_prop_count
1458 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001459 {
1460 if (bcol <= text_props[text_prop_next].tp_col - 1
1461 + text_props[text_prop_next].tp_len)
1462 text_prop_idxs[text_props_active++] = text_prop_next;
1463 ++text_prop_next;
1464 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001465
1466 text_prop_attr = 0;
1467 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001468 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 if (text_props_active > 0)
1470 {
1471 // Sort the properties on priority and/or starting last.
1472 // Then combine the attributes, highest priority last.
1473 current_text_props = text_props;
1474 current_buf = wp->w_buffer;
1475 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1476 sizeof(int), text_prop_compare);
1477
1478 for (pi = 0; pi < text_props_active; ++pi)
1479 {
1480 int tpi = text_prop_idxs[pi];
1481 proptype_T *pt = text_prop_type_by_id(
1482 wp->w_buffer, text_props[tpi].tp_type);
1483
1484 if (pt != NULL && pt->pt_hl_id > 0)
1485 {
1486 int pt_attr = syn_id2attr(pt->pt_hl_id);
1487
1488 text_prop_type = pt;
1489 text_prop_attr =
1490 hl_combine_attr(text_prop_attr, pt_attr);
1491 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1492 }
1493 }
1494 }
1495 }
1496#endif
1497
Bram Moolenaara74fda62019-10-19 17:38:03 +02001498#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001499 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001500 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001501 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001502# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001503 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001504 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001505# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001506 // Get syntax attribute.
1507 if (has_syntax)
1508 {
1509 // Get the syntax attribute for the character. If there
1510 // is an error, disable syntax highlighting.
1511 save_did_emsg = did_emsg;
1512 did_emsg = FALSE;
1513
1514 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001515 if (v == prev_syntax_col)
1516 // at same column again
1517 syntax_attr = prev_syntax_attr;
1518 else
1519 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001520# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001521 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001522# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001523 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001524# ifdef FEAT_SPELL
1525 has_spell ? &can_spell :
1526# endif
1527 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001528 prev_syntax_col = v;
1529 prev_syntax_attr = syntax_attr;
1530 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001531
Bram Moolenaar34390282019-10-16 14:38:26 +02001532 if (did_emsg)
1533 {
1534 wp->w_s->b_syn_error = TRUE;
1535 has_syntax = FALSE;
1536 syntax_attr = 0;
1537 }
1538 else
1539 did_emsg = save_did_emsg;
1540# ifdef SYN_TIME_LIMIT
1541 if (wp->w_s->b_syn_slow)
1542 has_syntax = FALSE;
1543# endif
1544
1545 // Need to get the line again, a multi-line regexp may
1546 // have made it invalid.
1547 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1548 ptr = line + v;
1549# ifdef FEAT_CONCEAL
1550 // no concealing past the end of the line, it interferes
1551 // with line highlighting
1552 if (*ptr == NUL)
1553 syntax_flags = 0;
1554 else
1555 syntax_flags = get_syntax_info(&syntax_seqnr);
1556# endif
1557 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001558 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001559# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001560 // Combine text property highlight into syntax highlight.
1561 if (text_prop_type != NULL)
1562 {
1563 if (text_prop_combine)
1564 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1565 else
1566 syntax_attr = text_prop_attr;
1567 }
1568# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001569#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001570
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001571 // Decide which of the highlight attributes to use.
1572 attr_pri = TRUE;
1573#ifdef LINE_ATTR
1574 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001575 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001576 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001577 if (!highlight_match)
1578 // let search highlight show in Visual area if possible
1579 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001580# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001581 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001582# endif
1583 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001585 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001587# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001588 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001589# endif
1590 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1592 || vcol < fromcol || vcol_prev < fromcol_prev
1593 || vcol >= tocol))
1594 {
1595 // Use line_attr when not in the Visual or 'incsearch' area
1596 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001597# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001598 char_attr = hl_combine_attr(syntax_attr, line_attr);
1599# else
1600 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001601# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001602 attr_pri = FALSE;
1603 }
1604#else
1605 if (area_attr != 0)
1606 char_attr = area_attr;
1607 else if (search_attr != 0)
1608 char_attr = search_attr;
1609#endif
1610 else
1611 {
1612 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001613#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001614 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001615#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001616 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001617#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 }
1619 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001620
1621 // combine attribute with 'wincolor'
1622 if (win_attr != 0)
1623 {
1624 if (char_attr == 0)
1625 char_attr = win_attr;
1626 else
1627 char_attr = hl_combine_attr(win_attr, char_attr);
1628 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001629
1630 // Get the next character to put on the screen.
1631
1632 // The "p_extra" points to the extra stuff that is inserted to
1633 // represent special characters (non-printable stuff) and other
1634 // things. When all characters are the same, c_extra is used.
1635 // If c_final is set, it will compulsorily be used at the end.
1636 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1637 // "p_extra[n_extra]".
1638 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1639 if (n_extra > 0)
1640 {
1641 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1642 {
1643 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1644 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1645 if (enc_utf8 && utf_char2len(c) > 1)
1646 {
1647 mb_utf8 = TRUE;
1648 u8cc[0] = 0;
1649 c = 0xc0;
1650 }
1651 else
1652 mb_utf8 = FALSE;
1653 }
1654 else
1655 {
1656 c = *p_extra;
1657 if (has_mbyte)
1658 {
1659 mb_c = c;
1660 if (enc_utf8)
1661 {
1662 // If the UTF-8 character is more than one byte:
1663 // Decode it into "mb_c".
1664 mb_l = utfc_ptr2len(p_extra);
1665 mb_utf8 = FALSE;
1666 if (mb_l > n_extra)
1667 mb_l = 1;
1668 else if (mb_l > 1)
1669 {
1670 mb_c = utfc_ptr2char(p_extra, u8cc);
1671 mb_utf8 = TRUE;
1672 c = 0xc0;
1673 }
1674 }
1675 else
1676 {
1677 // if this is a DBCS character, put it in "mb_c"
1678 mb_l = MB_BYTE2LEN(c);
1679 if (mb_l >= n_extra)
1680 mb_l = 1;
1681 else if (mb_l > 1)
1682 mb_c = (c << 8) + p_extra[1];
1683 }
1684 if (mb_l == 0) // at the NUL at end-of-line
1685 mb_l = 1;
1686
1687 // If a double-width char doesn't fit display a '>' in the
1688 // last column.
1689 if ((
1690# ifdef FEAT_RIGHTLEFT
1691 wp->w_p_rl ? (col <= 0) :
1692# endif
1693 (col >= wp->w_width - 1))
1694 && (*mb_char2cells)(mb_c) == 2)
1695 {
1696 c = '>';
1697 mb_c = c;
1698 mb_l = 1;
1699 mb_utf8 = FALSE;
1700 multi_attr = HL_ATTR(HLF_AT);
1701#ifdef FEAT_SYN_HL
1702 if (cul_attr)
1703 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1704#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001705 multi_attr = hl_combine_attr(win_attr, multi_attr);
1706
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001707 // put the pointer back to output the double-width
1708 // character at the start of the next line.
1709 ++n_extra;
1710 --p_extra;
1711 }
1712 else
1713 {
1714 n_extra -= mb_l - 1;
1715 p_extra += mb_l - 1;
1716 }
1717 }
1718 ++p_extra;
1719 }
1720 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001721#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001722 if (n_extra <= 0)
1723 in_linebreak = FALSE;
1724#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001725 }
1726 else
1727 {
1728#ifdef FEAT_LINEBREAK
1729 int c0;
1730#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001731 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001732
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 // Get a character from the line itself.
1734 c = *ptr;
1735#ifdef FEAT_LINEBREAK
1736 c0 = *ptr;
1737#endif
1738 if (has_mbyte)
1739 {
1740 mb_c = c;
1741 if (enc_utf8)
1742 {
1743 // If the UTF-8 character is more than one byte: Decode it
1744 // into "mb_c".
1745 mb_l = utfc_ptr2len(ptr);
1746 mb_utf8 = FALSE;
1747 if (mb_l > 1)
1748 {
1749 mb_c = utfc_ptr2char(ptr, u8cc);
1750 // Overlong encoded ASCII or ASCII with composing char
1751 // is displayed normally, except a NUL.
1752 if (mb_c < 0x80)
1753 {
1754 c = mb_c;
1755#ifdef FEAT_LINEBREAK
1756 c0 = mb_c;
1757#endif
1758 }
1759 mb_utf8 = TRUE;
1760
1761 // At start of the line we can have a composing char.
1762 // Draw it as a space with a composing char.
1763 if (utf_iscomposing(mb_c))
1764 {
1765 int i;
1766
1767 for (i = Screen_mco - 1; i > 0; --i)
1768 u8cc[i] = u8cc[i - 1];
1769 u8cc[0] = mb_c;
1770 mb_c = ' ';
1771 }
1772 }
1773
1774 if ((mb_l == 1 && c >= 0x80)
1775 || (mb_l >= 1 && mb_c == 0)
1776 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1777 {
1778 // Illegal UTF-8 byte: display as <xx>.
1779 // Non-BMP character : display as ? or fullwidth ?.
1780 transchar_hex(extra, mb_c);
1781# ifdef FEAT_RIGHTLEFT
1782 if (wp->w_p_rl) // reverse
1783 rl_mirror(extra);
1784# endif
1785 p_extra = extra;
1786 c = *p_extra;
1787 mb_c = mb_ptr2char_adv(&p_extra);
1788 mb_utf8 = (c >= 0x80);
1789 n_extra = (int)STRLEN(p_extra);
1790 c_extra = NUL;
1791 c_final = NUL;
1792 if (area_attr == 0 && search_attr == 0)
1793 {
1794 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001795 extra_attr = hl_combine_attr(
1796 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001797 saved_attr2 = char_attr; // save current attr
1798 }
1799 }
1800 else if (mb_l == 0) // at the NUL at end-of-line
1801 mb_l = 1;
1802#ifdef FEAT_ARABIC
1803 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1804 {
1805 // Do Arabic shaping.
1806 int pc, pc1, nc;
1807 int pcc[MAX_MCO];
1808
1809 // The idea of what is the previous and next
1810 // character depends on 'rightleft'.
1811 if (wp->w_p_rl)
1812 {
1813 pc = prev_c;
1814 pc1 = prev_c1;
1815 nc = utf_ptr2char(ptr + mb_l);
1816 prev_c1 = u8cc[0];
1817 }
1818 else
1819 {
1820 pc = utfc_ptr2char(ptr + mb_l, pcc);
1821 nc = prev_c;
1822 pc1 = pcc[0];
1823 }
1824 prev_c = mb_c;
1825
1826 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1827 }
1828 else
1829 prev_c = mb_c;
1830#endif
1831 }
1832 else // enc_dbcs
1833 {
1834 mb_l = MB_BYTE2LEN(c);
1835 if (mb_l == 0) // at the NUL at end-of-line
1836 mb_l = 1;
1837 else if (mb_l > 1)
1838 {
1839 // We assume a second byte below 32 is illegal.
1840 // Hopefully this is OK for all double-byte encodings!
1841 if (ptr[1] >= 32)
1842 mb_c = (c << 8) + ptr[1];
1843 else
1844 {
1845 if (ptr[1] == NUL)
1846 {
1847 // head byte at end of line
1848 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001849 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001850 }
1851 else
1852 {
1853 // illegal tail byte
1854 mb_l = 2;
1855 STRCPY(extra, "XX");
1856 }
1857 p_extra = extra;
1858 n_extra = (int)STRLEN(extra) - 1;
1859 c_extra = NUL;
1860 c_final = NUL;
1861 c = *p_extra++;
1862 if (area_attr == 0 && search_attr == 0)
1863 {
1864 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001865 extra_attr = hl_combine_attr(
1866 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001867 saved_attr2 = char_attr; // save current attr
1868 }
1869 mb_c = c;
1870 }
1871 }
1872 }
1873 // If a double-width char doesn't fit display a '>' in the
1874 // last column; the character is displayed at the start of the
1875 // next line.
1876 if ((
1877# ifdef FEAT_RIGHTLEFT
1878 wp->w_p_rl ? (col <= 0) :
1879# endif
1880 (col >= wp->w_width - 1))
1881 && (*mb_char2cells)(mb_c) == 2)
1882 {
1883 c = '>';
1884 mb_c = c;
1885 mb_utf8 = FALSE;
1886 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001887 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 // Put pointer back so that the character will be
1889 // displayed at the start of the next line.
1890 --ptr;
1891#ifdef FEAT_CONCEAL
1892 did_decrement_ptr = TRUE;
1893#endif
1894 }
1895 else if (*ptr != NUL)
1896 ptr += mb_l - 1;
1897
1898 // If a double-width char doesn't fit at the left side display
1899 // a '<' in the first column. Don't do this for unprintable
1900 // characters.
1901 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1902 {
1903 n_extra = 1;
1904 c_extra = MB_FILLER_CHAR;
1905 c_final = NUL;
1906 c = ' ';
1907 if (area_attr == 0 && search_attr == 0)
1908 {
1909 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001910 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911 saved_attr2 = char_attr; // save current attr
1912 }
1913 mb_c = c;
1914 mb_utf8 = FALSE;
1915 mb_l = 1;
1916 }
1917
1918 }
1919 ++ptr;
1920
1921 if (extra_check)
1922 {
1923#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 // Check spelling (unless at the end of the line).
1925 // Only do this when there is no syntax highlighting, the
1926 // @Spell cluster is not used or the current syntax item
1927 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001928 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001929 if (has_spell && v >= word_end && v > cur_checked_col)
1930 {
1931 spell_attr = 0;
1932 if (c != 0 && (
1933# ifdef FEAT_SYN_HL
1934 !has_syntax ||
1935# endif
1936 can_spell))
1937 {
1938 char_u *prev_ptr, *p;
1939 int len;
1940 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001941
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 if (has_mbyte)
1943 {
1944 prev_ptr = ptr - mb_l;
1945 v -= mb_l - 1;
1946 }
1947 else
1948 prev_ptr = ptr - 1;
1949
1950 // Use nextline[] if possible, it has the start of the
1951 // next line concatenated.
1952 if ((prev_ptr - line) - nextlinecol >= 0)
1953 p = nextline + (prev_ptr - line) - nextlinecol;
1954 else
1955 p = prev_ptr;
1956 cap_col -= (int)(prev_ptr - line);
1957 len = spell_check(wp, p, &spell_hlf, &cap_col,
1958 nochange);
1959 word_end = v + len;
1960
1961 // In Insert mode only highlight a word that
1962 // doesn't touch the cursor.
1963 if (spell_hlf != HLF_COUNT
1964 && (State & INSERT) != 0
1965 && wp->w_cursor.lnum == lnum
1966 && wp->w_cursor.col >=
1967 (colnr_T)(prev_ptr - line)
1968 && wp->w_cursor.col < (colnr_T)word_end)
1969 {
1970 spell_hlf = HLF_COUNT;
1971 spell_redraw_lnum = lnum;
1972 }
1973
1974 if (spell_hlf == HLF_COUNT && p != prev_ptr
1975 && (p - nextline) + len > nextline_idx)
1976 {
1977 // Remember that the good word continues at the
1978 // start of the next line.
1979 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001980 checked_col = (int)((p - nextline)
1981 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001982 }
1983
1984 // Turn index into actual attributes.
1985 if (spell_hlf != HLF_COUNT)
1986 spell_attr = highlight_attr[spell_hlf];
1987
1988 if (cap_col > 0)
1989 {
1990 if (p != prev_ptr
1991 && (p - nextline) + cap_col >= nextline_idx)
1992 {
1993 // Remember that the word in the next line
1994 // must start with a capital.
1995 capcol_lnum = lnum + 1;
1996 cap_col = (int)((p - nextline) + cap_col
1997 - nextline_idx);
1998 }
1999 else
2000 // Compute the actual column.
2001 cap_col += (int)(prev_ptr - line);
2002 }
2003 }
2004 }
2005 if (spell_attr != 0)
2006 {
2007 if (!attr_pri)
2008 char_attr = hl_combine_attr(char_attr, spell_attr);
2009 else
2010 char_attr = hl_combine_attr(spell_attr, char_attr);
2011 }
2012#endif
2013#ifdef FEAT_LINEBREAK
2014 // Found last space before word: check for line break.
2015 if (wp->w_p_lbr && c0 == c
2016 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2017 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002018 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2019 : 0;
2020 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021
2022 // TODO: is passing p for start of the line OK?
2023 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2024 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002025
2026 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002027 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002028 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002029 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002030 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002031 if (n_extra < 0)
2032 n_extra = 0;
2033 }
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002034 if (on_last_col)
2035 // Do not continue search/match highlighting over the
2036 // line break.
2037 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002038
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002039 if (c == TAB && n_extra + col > wp->w_width)
2040# ifdef FEAT_VARTABS
2041 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2042 wp->w_buffer->b_p_vts_array) - 1;
2043# else
2044 n_extra = (int)wp->w_buffer->b_p_ts
2045 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2046# endif
2047
2048 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2049 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002050# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002051 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002052 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002053# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 if (VIM_ISWHITE(c))
2055 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002056# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002057 if (c == TAB)
2058 // See "Tab alignment" below.
2059 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002060# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002061 if (!wp->w_p_list)
2062 c = ' ';
2063 }
2064 }
2065#endif
2066
zeertzjqf14b8ba2021-09-10 16:58:30 +02002067 in_multispace = c == ' '
2068 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2069 if (!in_multispace)
2070 multispace_pos = 0;
2071
Bram Moolenaareed9d462021-02-15 20:38:25 +01002072 // 'list': Change char 160 to 'nbsp' and space to 'space'
2073 // setting in 'listchars'. But not when the character is
2074 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 if (wp->w_p_list
2076 && ((((c == 160 && mb_l == 1)
2077 || (mb_utf8
2078 && ((mb_c == 160 && mb_l == 2)
2079 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002080 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002081 || (c == ' '
2082 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002083 && (wp->w_lcs_chars.space
2084 || (in_multispace
2085 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002086 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002087 && ptr - line <= trailcol)))
2088 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002089 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2090 {
2091 c = wp->w_lcs_chars.multispace[multispace_pos++];
2092 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2093 multispace_pos = 0;
2094 }
2095 else
2096 c = (c == ' ') ? wp->w_lcs_chars.space
2097 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098 if (area_attr == 0 && search_attr == 0)
2099 {
2100 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002101 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002102 saved_attr2 = char_attr; // save current attr
2103 }
2104 mb_c = c;
2105 if (enc_utf8 && utf_char2len(c) > 1)
2106 {
2107 mb_utf8 = TRUE;
2108 u8cc[0] = 0;
2109 c = 0xc0;
2110 }
2111 else
2112 mb_utf8 = FALSE;
2113 }
2114
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002115 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2116 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002117 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002118 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2119 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002120 if (!attr_pri)
2121 {
2122 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002123 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002124 saved_attr2 = char_attr; // save current attr
2125 }
2126 mb_c = c;
2127 if (enc_utf8 && utf_char2len(c) > 1)
2128 {
2129 mb_utf8 = TRUE;
2130 u8cc[0] = 0;
2131 c = 0xc0;
2132 }
2133 else
2134 mb_utf8 = FALSE;
2135 }
2136 }
2137
2138 // Handling of non-printable characters.
2139 if (!vim_isprintc(c))
2140 {
2141 // when getting a character from the file, we may have to
2142 // turn it into something else on the way to putting it
2143 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002144 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002145 {
2146 int tab_len = 0;
2147 long vcol_adjusted = vcol; // removed showbreak length
2148#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002149 char_u *sbr = get_showbreak_value(wp);
2150
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002151 // only adjust the tab_len, when at the first column
2152 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002153 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2154 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002155#endif
2156 // tab amount depends on current column
2157#ifdef FEAT_VARTABS
2158 tab_len = tabstop_padding(vcol_adjusted,
2159 wp->w_buffer->b_p_ts,
2160 wp->w_buffer->b_p_vts_array) - 1;
2161#else
2162 tab_len = (int)wp->w_buffer->b_p_ts
2163 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2164#endif
2165
2166#ifdef FEAT_LINEBREAK
2167 if (!wp->w_p_lbr || !wp->w_p_list)
2168#endif
2169 // tab amount depends on current column
2170 n_extra = tab_len;
2171#ifdef FEAT_LINEBREAK
2172 else
2173 {
2174 char_u *p;
2175 int len;
2176 int i;
2177 int saved_nextra = n_extra;
2178
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002179# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002180 if (vcol_off > 0)
2181 // there are characters to conceal
2182 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002183
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002185 if (wp->w_p_list && wp->w_lcs_chars.tab1
2186 && old_boguscols > 0
2187 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002188 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002189# endif
2190 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002191 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002192 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002193 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002194 if (wp->w_lcs_chars.tab3)
2195 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002196 if (n_extra > 0)
2197 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002198 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002199 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002200 if (p == NULL)
2201 n_extra = 0;
2202 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002203 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002204 vim_memset(p, ' ', len);
2205 p[len] = NUL;
2206 vim_free(p_extra_free);
2207 p_extra_free = p;
2208 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002209 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002210 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002211
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002212 if (*p == NUL)
2213 {
2214 tab_len = i;
2215 break;
2216 }
2217
2218 // if tab3 is given, use it for the last char
2219 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2220 lcs = wp->w_lcs_chars.tab3;
2221 p += mb_char2bytes(lcs, p);
2222 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002223 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002224 }
2225 p_extra = p_extra_free;
2226# ifdef FEAT_CONCEAL
2227 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2228 // macro below, so need to adjust for that here
2229 if (vcol_off > 0)
2230 n_extra -= vcol_off;
2231# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002233 }
2234#endif
2235#ifdef FEAT_CONCEAL
2236 {
2237 int vc_saved = vcol_off;
2238
2239 // Tab alignment should be identical regardless of
2240 // 'conceallevel' value. So tab compensates of all
2241 // previous concealed characters, and thus resets
2242 // vcol_off and boguscols accumulated so far in the
2243 // line. Note that the tab can be longer than
2244 // 'tabstop' when there are concealed characters.
2245 FIX_FOR_BOGUSCOLS;
2246
2247 // Make sure, the highlighting for the tab char will be
2248 // correctly set further below (effectively reverts the
2249 // FIX_FOR_BOGSUCOLS macro
2250 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002251 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002252 tab_len += vc_saved;
2253 }
2254#endif
2255 mb_utf8 = FALSE; // don't draw as UTF-8
2256 if (wp->w_p_list)
2257 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002258 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2259 ? wp->w_lcs_chars.tab3
2260 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261#ifdef FEAT_LINEBREAK
2262 if (wp->w_p_lbr)
2263 c_extra = NUL; // using p_extra from above
2264 else
2265#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002266 c_extra = wp->w_lcs_chars.tab2;
2267 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002268 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002269 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270 saved_attr2 = char_attr; // save current attr
2271 mb_c = c;
2272 if (enc_utf8 && utf_char2len(c) > 1)
2273 {
2274 mb_utf8 = TRUE;
2275 u8cc[0] = 0;
2276 c = 0xc0;
2277 }
2278 }
2279 else
2280 {
2281 c_final = NUL;
2282 c_extra = ' ';
2283 c = ' ';
2284 }
2285 }
2286 else if (c == NUL
2287 && (wp->w_p_list
2288 || ((fromcol >= 0 || fromcol_prev >= 0)
2289 && tocol > vcol
2290 && VIsual_mode != Ctrl_V
2291 && (
2292# ifdef FEAT_RIGHTLEFT
2293 wp->w_p_rl ? (col >= 0) :
2294# endif
2295 (col < wp->w_width))
2296 && !(noinvcur
2297 && lnum == wp->w_cursor.lnum
2298 && (colnr_T)vcol == wp->w_virtcol)))
2299 && lcs_eol_one > 0)
2300 {
2301 // Display a '$' after the line or highlight an extra
2302 // character if the line break is included.
2303#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2304 // For a diff line the highlighting continues after the
2305 // "$".
2306 if (
2307# ifdef FEAT_DIFF
2308 diff_hlf == (hlf_T)0
2309# ifdef LINE_ATTR
2310 &&
2311# endif
2312# endif
2313# ifdef LINE_ATTR
2314 line_attr == 0
2315# endif
2316 )
2317#endif
2318 {
2319 // In virtualedit, visual selections may extend
2320 // beyond end of line.
2321 if (area_highlighting && virtual_active()
2322 && tocol != MAXCOL && vcol < tocol)
2323 n_extra = 0;
2324 else
2325 {
2326 p_extra = at_end_str;
2327 n_extra = 1;
2328 c_extra = NUL;
2329 c_final = NUL;
2330 }
2331 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002332 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2333 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002334 else
2335 c = ' ';
2336 lcs_eol_one = -1;
2337 --ptr; // put it back at the NUL
2338 if (!attr_pri)
2339 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002340 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 n_attr = 1;
2342 }
2343 mb_c = c;
2344 if (enc_utf8 && utf_char2len(c) > 1)
2345 {
2346 mb_utf8 = TRUE;
2347 u8cc[0] = 0;
2348 c = 0xc0;
2349 }
2350 else
2351 mb_utf8 = FALSE; // don't draw as UTF-8
2352 }
2353 else if (c != NUL)
2354 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002355 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002356 if (n_extra == 0)
2357 n_extra = byte2cells(c) - 1;
2358#ifdef FEAT_RIGHTLEFT
2359 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2360 rl_mirror(p_extra); // reverse "<12>"
2361#endif
2362 c_extra = NUL;
2363 c_final = NUL;
2364#ifdef FEAT_LINEBREAK
2365 if (wp->w_p_lbr)
2366 {
2367 char_u *p;
2368
2369 c = *p_extra;
2370 p = alloc(n_extra + 1);
2371 vim_memset(p, ' ', n_extra);
2372 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2373 p[n_extra] = NUL;
2374 vim_free(p_extra_free);
2375 p_extra_free = p_extra = p;
2376 }
2377 else
2378#endif
2379 {
2380 n_extra = byte2cells(c) - 1;
2381 c = *p_extra++;
2382 }
2383 if (!attr_pri)
2384 {
2385 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002386 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002387 saved_attr2 = char_attr; // save current attr
2388 }
2389 mb_utf8 = FALSE; // don't draw as UTF-8
2390 }
2391 else if (VIsual_active
2392 && (VIsual_mode == Ctrl_V
2393 || VIsual_mode == 'v')
2394 && virtual_active()
2395 && tocol != MAXCOL
2396 && vcol < tocol
2397 && (
2398#ifdef FEAT_RIGHTLEFT
2399 wp->w_p_rl ? (col >= 0) :
2400#endif
2401 (col < wp->w_width)))
2402 {
2403 c = ' ';
2404 --ptr; // put it back at the NUL
2405 }
2406#if defined(LINE_ATTR)
2407 else if ((
2408# ifdef FEAT_DIFF
2409 diff_hlf != (hlf_T)0 ||
2410# endif
2411# ifdef FEAT_TERMINAL
2412 win_attr != 0 ||
2413# endif
2414 line_attr != 0
2415 ) && (
2416# ifdef FEAT_RIGHTLEFT
2417 wp->w_p_rl ? (col >= 0) :
2418# endif
2419 (col
2420# ifdef FEAT_CONCEAL
2421 - boguscols
2422# endif
2423 < wp->w_width)))
2424 {
2425 // Highlight until the right side of the window
2426 c = ' ';
2427 --ptr; // put it back at the NUL
2428
2429 // Remember we do the char for line highlighting.
2430 ++did_line_attr;
2431
2432 // don't do search HL for the rest of the line
2433 if (line_attr != 0 && char_attr == search_attr
2434 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002435 || (wp->w_p_list &&
2436 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002437 char_attr = line_attr;
2438# ifdef FEAT_DIFF
2439 if (diff_hlf == HLF_TXD)
2440 {
2441 diff_hlf = HLF_CHD;
2442 if (vi_attr == 0 || char_attr != vi_attr)
2443 {
2444 char_attr = HL_ATTR(diff_hlf);
2445 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2446 && wp->w_p_culopt_flags != CULOPT_NBR
2447 && (!cul_screenline
2448 || (vcol >= left_curline_col
2449 && vcol <= right_curline_col)))
2450 char_attr = hl_combine_attr(
2451 char_attr, HL_ATTR(HLF_CUL));
2452 }
2453 }
2454# endif
2455# ifdef FEAT_TERMINAL
2456 if (win_attr != 0)
2457 {
2458 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002459 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2460 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002461 {
2462 if (!cul_screenline || (vcol >= left_curline_col
2463 && vcol <= right_curline_col))
2464 char_attr = hl_combine_attr(
2465 char_attr, HL_ATTR(HLF_CUL));
2466 }
2467 else if (line_attr)
2468 char_attr = hl_combine_attr(char_attr, line_attr);
2469 }
2470# endif
2471 }
2472#endif
2473 }
2474
2475#ifdef FEAT_CONCEAL
2476 if ( wp->w_p_cole > 0
2477 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2478 conceal_cursor_line(wp))
2479 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2480 && !(lnum_in_visual_area
2481 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2482 {
2483 char_attr = conceal_attr;
2484 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002485 && (syn_get_sub_char() != NUL
2486 || (has_match_conc && match_conc)
2487 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 && wp->w_p_cole != 3)
2489 {
2490 // First time at this concealed item: display one
2491 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002492 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002493 c = match_conc;
2494 else if (syn_get_sub_char() != NUL)
2495 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002496 else if (wp->w_lcs_chars.conceal != NUL)
2497 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002498 else
2499 c = ' ';
2500
2501 prev_syntax_id = syntax_seqnr;
2502
2503 if (n_extra > 0)
2504 vcol_off += n_extra;
2505 vcol += n_extra;
2506 if (wp->w_p_wrap && n_extra > 0)
2507 {
2508# ifdef FEAT_RIGHTLEFT
2509 if (wp->w_p_rl)
2510 {
2511 col -= n_extra;
2512 boguscols -= n_extra;
2513 }
2514 else
2515# endif
2516 {
2517 boguscols += n_extra;
2518 col += n_extra;
2519 }
2520 }
2521 n_extra = 0;
2522 n_attr = 0;
2523 }
2524 else if (n_skip == 0)
2525 {
2526 is_concealing = TRUE;
2527 n_skip = 1;
2528 }
2529 mb_c = c;
2530 if (enc_utf8 && utf_char2len(c) > 1)
2531 {
2532 mb_utf8 = TRUE;
2533 u8cc[0] = 0;
2534 c = 0xc0;
2535 }
2536 else
2537 mb_utf8 = FALSE; // don't draw as UTF-8
2538 }
2539 else
2540 {
2541 prev_syntax_id = 0;
2542 is_concealing = FALSE;
2543 }
2544
2545 if (n_skip > 0 && did_decrement_ptr)
2546 // not showing the '>', put pointer back to avoid getting stuck
2547 ++ptr;
2548
2549#endif // FEAT_CONCEAL
2550 }
2551
2552#ifdef FEAT_CONCEAL
2553 // In the cursor line and we may be concealing characters: correct
2554 // the cursor column when we reach its position.
2555 if (!did_wcol && draw_state == WL_LINE
2556 && wp == curwin && lnum == wp->w_cursor.lnum
2557 && conceal_cursor_line(wp)
2558 && (int)wp->w_virtcol <= vcol + n_skip)
2559 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002560# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002561 if (wp->w_p_rl)
2562 wp->w_wcol = wp->w_width - col + boguscols - 1;
2563 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002564# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002565 wp->w_wcol = col - boguscols;
2566 wp->w_wrow = row;
2567 did_wcol = TRUE;
2568 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002569# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002570 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002571# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002572 }
2573#endif
2574
2575 // Don't override visual selection highlighting.
2576 if (n_attr > 0
2577 && draw_state == WL_LINE
2578 && !attr_pri)
2579 {
2580#ifdef LINE_ATTR
2581 if (line_attr)
2582 char_attr = hl_combine_attr(extra_attr, line_attr);
2583 else
2584#endif
2585 char_attr = extra_attr;
2586 }
2587
2588#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2589 // XIM don't send preedit_start and preedit_end, but they send
2590 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2591 // im_is_preediting() here.
2592 if (p_imst == IM_ON_THE_SPOT
2593 && xic != NULL
2594 && lnum == wp->w_cursor.lnum
2595 && (State & INSERT)
2596 && !p_imdisable
2597 && im_is_preediting()
2598 && draw_state == WL_LINE)
2599 {
2600 colnr_T tcol;
2601
2602 if (preedit_end_col == MAXCOL)
2603 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2604 else
2605 tcol = preedit_end_col;
2606 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2607 {
2608 if (feedback_old_attr < 0)
2609 {
2610 feedback_col = 0;
2611 feedback_old_attr = char_attr;
2612 }
2613 char_attr = im_get_feedback_attr(feedback_col);
2614 if (char_attr < 0)
2615 char_attr = feedback_old_attr;
2616 feedback_col++;
2617 }
2618 else if (feedback_old_attr >= 0)
2619 {
2620 char_attr = feedback_old_attr;
2621 feedback_old_attr = -1;
2622 feedback_col = 0;
2623 }
2624 }
2625#endif
2626 // Handle the case where we are in column 0 but not on the first
2627 // character of the line and the user wants us to show us a
2628 // special character (via 'listchars' option "precedes:<char>".
2629 if (lcs_prec_todo != NUL
2630 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002631 && (wp->w_p_wrap ?
2632 (wp->w_skipcol > 0 && row == 0) :
2633 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634#ifdef FEAT_DIFF
2635 && filler_todo <= 0
2636#endif
2637 && draw_state > WL_NR
2638 && c != NUL)
2639 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002640 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 lcs_prec_todo = NUL;
2642 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2643 {
2644 // Double-width character being overwritten by the "precedes"
2645 // character, need to fill up half the character.
2646 c_extra = MB_FILLER_CHAR;
2647 c_final = NUL;
2648 n_extra = 1;
2649 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002650 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002651 }
2652 mb_c = c;
2653 if (enc_utf8 && utf_char2len(c) > 1)
2654 {
2655 mb_utf8 = TRUE;
2656 u8cc[0] = 0;
2657 c = 0xc0;
2658 }
2659 else
2660 mb_utf8 = FALSE; // don't draw as UTF-8
2661 if (!attr_pri)
2662 {
2663 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002664 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002665 n_attr3 = 1;
2666 }
2667 }
2668
2669 // At end of the text line or just after the last character.
2670 if ((c == NUL
2671#if defined(LINE_ATTR)
2672 || did_line_attr == 1
2673#endif
2674 ) && eol_hl_off == 0)
2675 {
2676#ifdef FEAT_SEARCH_EXTRA
2677 // flag to indicate whether prevcol equals startcol of search_hl or
2678 // one of the matches
2679 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2680 (long)(ptr - line) - (c == NUL));
2681#endif
2682 // Invert at least one char, used for Visual and empty line or
2683 // highlight match at end of line. If it's beyond the last
2684 // char on the screen, just overwrite that one (tricky!) Not
2685 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002686 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002687 && ((area_attr != 0 && vcol == fromcol
2688 && (VIsual_mode != Ctrl_V
2689 || lnum == VIsual.lnum
2690 || lnum == curwin->w_cursor.lnum)
2691 && c == NUL)
2692#ifdef FEAT_SEARCH_EXTRA
2693 // highlight 'hlsearch' match at end of line
2694 || (prevcol_hl_flag
2695# ifdef FEAT_SYN_HL
2696 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2697 && !(wp == curwin && VIsual_active))
2698# endif
2699# ifdef FEAT_DIFF
2700 && diff_hlf == (hlf_T)0
2701# endif
2702# if defined(LINE_ATTR)
2703 && did_line_attr <= 1
2704# endif
2705 )
2706#endif
2707 ))
2708 {
2709 int n = 0;
2710
2711#ifdef FEAT_RIGHTLEFT
2712 if (wp->w_p_rl)
2713 {
2714 if (col < 0)
2715 n = 1;
2716 }
2717 else
2718#endif
2719 {
2720 if (col >= wp->w_width)
2721 n = -1;
2722 }
2723 if (n != 0)
2724 {
2725 // At the window boundary, highlight the last character
2726 // instead (better than nothing).
2727 off += n;
2728 col += n;
2729 }
2730 else
2731 {
2732 // Add a blank character to highlight.
2733 ScreenLines[off] = ' ';
2734 if (enc_utf8)
2735 ScreenLinesUC[off] = 0;
2736 }
2737#ifdef FEAT_SEARCH_EXTRA
2738 if (area_attr == 0)
2739 {
2740 // Use attributes from match with highest priority among
2741 // 'search_hl' and the match list.
2742 get_search_match_hl(wp, &screen_search_hl,
2743 (long)(ptr - line), &char_attr);
2744 }
2745#endif
2746 ScreenAttrs[off] = char_attr;
2747#ifdef FEAT_RIGHTLEFT
2748 if (wp->w_p_rl)
2749 {
2750 --col;
2751 --off;
2752 }
2753 else
2754#endif
2755 {
2756 ++col;
2757 ++off;
2758 }
2759 ++vcol;
2760 eol_hl_off = 1;
2761 }
2762 }
2763
2764 // At end of the text line.
2765 if (c == NUL)
2766 {
2767#ifdef FEAT_SYN_HL
2768 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2769 if (wp->w_p_wrap)
2770 v = wp->w_skipcol;
2771 else
2772 v = wp->w_leftcol;
2773
2774 // check if line ends before left margin
2775 if (vcol < v + col - win_col_off(wp))
2776 vcol = v + col - win_col_off(wp);
2777#ifdef FEAT_CONCEAL
2778 // Get rid of the boguscols now, we want to draw until the right
2779 // edge for 'cursorcolumn'.
2780 col -= boguscols;
2781 boguscols = 0;
2782#endif
2783
2784 if (draw_color_col)
2785 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2786
2787 if (((wp->w_p_cuc
2788 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2789 && (int)wp->w_virtcol <
2790 wp->w_width * (row - startrow + 1) + v
2791 && lnum != wp->w_cursor.lnum)
2792 || draw_color_col
2793 || win_attr != 0)
2794# ifdef FEAT_RIGHTLEFT
2795 && !wp->w_p_rl
2796# endif
2797 )
2798 {
2799 int rightmost_vcol = 0;
2800 int i;
2801
2802 if (wp->w_p_cuc)
2803 rightmost_vcol = wp->w_virtcol;
2804 if (draw_color_col)
2805 // determine rightmost colorcolumn to possibly draw
2806 for (i = 0; color_cols[i] >= 0; ++i)
2807 if (rightmost_vcol < color_cols[i])
2808 rightmost_vcol = color_cols[i];
2809
2810 while (col < wp->w_width)
2811 {
2812 ScreenLines[off] = ' ';
2813 if (enc_utf8)
2814 ScreenLinesUC[off] = 0;
2815 ++col;
2816 if (draw_color_col)
2817 draw_color_col = advance_color_col(VCOL_HLC,
2818 &color_cols);
2819
2820 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2821 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2822 else if (draw_color_col && VCOL_HLC == *color_cols)
2823 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2824 else
2825 ScreenAttrs[off++] = win_attr;
2826
2827 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2828 break;
2829
2830 ++vcol;
2831 }
2832 }
2833#endif
2834
2835 screen_line(screen_row, wp->w_wincol, col,
2836 (int)wp->w_width, screen_line_flags);
2837 row++;
2838
2839 // Update w_cline_height and w_cline_folded if the cursor line was
2840 // updated (saves a call to plines() later).
2841 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2842 {
2843 curwin->w_cline_row = startrow;
2844 curwin->w_cline_height = row - startrow;
2845#ifdef FEAT_FOLDING
2846 curwin->w_cline_folded = FALSE;
2847#endif
2848 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2849 }
2850
2851 break;
2852 }
2853
2854 // Show "extends" character from 'listchars' if beyond the line end and
2855 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002856 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002857 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002858 && wp->w_p_list
2859 && !wp->w_p_wrap
2860#ifdef FEAT_DIFF
2861 && filler_todo <= 0
2862#endif
2863 && (
2864#ifdef FEAT_RIGHTLEFT
2865 wp->w_p_rl ? col == 0 :
2866#endif
2867 col == wp->w_width - 1)
2868 && (*ptr != NUL
2869 || (wp->w_p_list && lcs_eol_one > 0)
2870 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2871 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002872 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002873 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002874 mb_c = c;
2875 if (enc_utf8 && utf_char2len(c) > 1)
2876 {
2877 mb_utf8 = TRUE;
2878 u8cc[0] = 0;
2879 c = 0xc0;
2880 }
2881 else
2882 mb_utf8 = FALSE;
2883 }
2884
2885#ifdef FEAT_SYN_HL
2886 // advance to the next 'colorcolumn'
2887 if (draw_color_col)
2888 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2889
2890 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2891 // highlight the cursor position itself.
2892 // Also highlight the 'colorcolumn' if it is different than
2893 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002894 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2895 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002896 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002897 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002898 draw_state == WL_BRI ||
2899 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002901# ifdef FEAT_DIFF
2902 && filler_todo <= 0
2903# endif
2904 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 {
2906 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2907 && lnum != wp->w_cursor.lnum)
2908 {
2909 vcol_save_attr = char_attr;
2910 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2911 }
2912 else if (draw_color_col && VCOL_HLC == *color_cols)
2913 {
2914 vcol_save_attr = char_attr;
2915 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2916 }
2917 }
2918#endif
2919
2920 // Store character to be displayed.
2921 // Skip characters that are left of the screen for 'nowrap'.
2922 vcol_prev = vcol;
2923 if (draw_state < WL_LINE || n_skip <= 0)
2924 {
2925 // Store the character.
2926#if defined(FEAT_RIGHTLEFT)
2927 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2928 {
2929 // A double-wide character is: put first halve in left cell.
2930 --off;
2931 --col;
2932 }
2933#endif
2934 ScreenLines[off] = c;
2935 if (enc_dbcs == DBCS_JPNU)
2936 {
2937 if ((mb_c & 0xff00) == 0x8e00)
2938 ScreenLines[off] = 0x8e;
2939 ScreenLines2[off] = mb_c & 0xff;
2940 }
2941 else if (enc_utf8)
2942 {
2943 if (mb_utf8)
2944 {
2945 int i;
2946
2947 ScreenLinesUC[off] = mb_c;
2948 if ((c & 0xff) == 0)
2949 ScreenLines[off] = 0x80; // avoid storing zero
2950 for (i = 0; i < Screen_mco; ++i)
2951 {
2952 ScreenLinesC[i][off] = u8cc[i];
2953 if (u8cc[i] == 0)
2954 break;
2955 }
2956 }
2957 else
2958 ScreenLinesUC[off] = 0;
2959 }
2960 if (multi_attr)
2961 {
2962 ScreenAttrs[off] = multi_attr;
2963 multi_attr = 0;
2964 }
2965 else
2966 ScreenAttrs[off] = char_attr;
2967
2968 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2969 {
2970 // Need to fill two screen columns.
2971 ++off;
2972 ++col;
2973 if (enc_utf8)
2974 // UTF-8: Put a 0 in the second screen char.
2975 ScreenLines[off] = 0;
2976 else
2977 // DBCS: Put second byte in the second screen char.
2978 ScreenLines[off] = mb_c & 0xff;
2979 if (draw_state > WL_NR
2980#ifdef FEAT_DIFF
2981 && filler_todo <= 0
2982#endif
2983 )
2984 ++vcol;
2985 // When "tocol" is halfway a character, set it to the end of
2986 // the character, otherwise highlighting won't stop.
2987 if (tocol == vcol)
2988 ++tocol;
2989#ifdef FEAT_RIGHTLEFT
2990 if (wp->w_p_rl)
2991 {
2992 // now it's time to backup one cell
2993 --off;
2994 --col;
2995 }
2996#endif
2997 }
2998#ifdef FEAT_RIGHTLEFT
2999 if (wp->w_p_rl)
3000 {
3001 --off;
3002 --col;
3003 }
3004 else
3005#endif
3006 {
3007 ++off;
3008 ++col;
3009 }
3010 }
3011#ifdef FEAT_CONCEAL
3012 else if (wp->w_p_cole > 0 && is_concealing)
3013 {
3014 --n_skip;
3015 ++vcol_off;
3016 if (n_extra > 0)
3017 vcol_off += n_extra;
3018 if (wp->w_p_wrap)
3019 {
3020 // Special voodoo required if 'wrap' is on.
3021 //
3022 // Advance the column indicator to force the line
3023 // drawing to wrap early. This will make the line
3024 // take up the same screen space when parts are concealed,
3025 // so that cursor line computations aren't messed up.
3026 //
3027 // To avoid the fictitious advance of 'col' causing
3028 // trailing junk to be written out of the screen line
3029 // we are building, 'boguscols' keeps track of the number
3030 // of bad columns we have advanced.
3031 if (n_extra > 0)
3032 {
3033 vcol += n_extra;
3034# ifdef FEAT_RIGHTLEFT
3035 if (wp->w_p_rl)
3036 {
3037 col -= n_extra;
3038 boguscols -= n_extra;
3039 }
3040 else
3041# endif
3042 {
3043 col += n_extra;
3044 boguscols += n_extra;
3045 }
3046 n_extra = 0;
3047 n_attr = 0;
3048 }
3049
3050
3051 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3052 {
3053 // Need to fill two screen columns.
3054# ifdef FEAT_RIGHTLEFT
3055 if (wp->w_p_rl)
3056 {
3057 --boguscols;
3058 --col;
3059 }
3060 else
3061# endif
3062 {
3063 ++boguscols;
3064 ++col;
3065 }
3066 }
3067
3068# ifdef FEAT_RIGHTLEFT
3069 if (wp->w_p_rl)
3070 {
3071 --boguscols;
3072 --col;
3073 }
3074 else
3075# endif
3076 {
3077 ++boguscols;
3078 ++col;
3079 }
3080 }
3081 else
3082 {
3083 if (n_extra > 0)
3084 {
3085 vcol += n_extra;
3086 n_extra = 0;
3087 n_attr = 0;
3088 }
3089 }
3090
3091 }
3092#endif // FEAT_CONCEAL
3093 else
3094 --n_skip;
3095
3096 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3097 // column.
3098 if (draw_state > WL_NR
3099#ifdef FEAT_DIFF
3100 && filler_todo <= 0
3101#endif
3102 )
3103 ++vcol;
3104
3105#ifdef FEAT_SYN_HL
3106 if (vcol_save_attr >= 0)
3107 char_attr = vcol_save_attr;
3108#endif
3109
3110 // restore attributes after "predeces" in 'listchars'
3111 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3112 char_attr = saved_attr3;
3113
3114 // restore attributes after last 'listchars' or 'number' char
3115 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3116 char_attr = saved_attr2;
3117
3118 // At end of screen line and there is more to come: Display the line
3119 // so far. If there is no more to display it is caught above.
3120 if ((
3121#ifdef FEAT_RIGHTLEFT
3122 wp->w_p_rl ? (col < 0) :
3123#endif
3124 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003125 && (draw_state != WL_LINE
3126 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127#ifdef FEAT_DIFF
3128 || filler_todo > 0
3129#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003130 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3131 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003132 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3133 )
3134 {
3135#ifdef FEAT_CONCEAL
3136 screen_line(screen_row, wp->w_wincol, col - boguscols,
3137 (int)wp->w_width, screen_line_flags);
3138 boguscols = 0;
3139#else
3140 screen_line(screen_row, wp->w_wincol, col,
3141 (int)wp->w_width, screen_line_flags);
3142#endif
3143 ++row;
3144 ++screen_row;
3145
3146 // When not wrapping and finished diff lines, or when displayed
3147 // '$' and highlighting until last column, break here.
3148 if ((!wp->w_p_wrap
3149#ifdef FEAT_DIFF
3150 && filler_todo <= 0
3151#endif
3152 ) || lcs_eol_one == -1)
3153 break;
3154
3155 // When the window is too narrow draw all "@" lines.
3156 if (draw_state != WL_LINE
3157#ifdef FEAT_DIFF
3158 && filler_todo <= 0
3159#endif
3160 )
3161 {
3162 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3163 draw_vsep_win(wp, row);
3164 row = endrow;
3165 }
3166
3167 // When line got too long for screen break here.
3168 if (row == endrow)
3169 {
3170 ++row;
3171 break;
3172 }
3173
3174 if (screen_cur_row == screen_row - 1
3175#ifdef FEAT_DIFF
3176 && filler_todo <= 0
3177#endif
3178 && wp->w_width == Columns)
3179 {
3180 // Remember that the line wraps, used for modeless copy.
3181 LineWraps[screen_row - 1] = TRUE;
3182
3183 // Special trick to make copy/paste of wrapped lines work with
3184 // xterm/screen: write an extra character beyond the end of
3185 // the line. This will work with all terminal types
3186 // (regardless of the xn,am settings).
3187 // Only do this on a fast tty.
3188 // Only do this if the cursor is on the current line
3189 // (something has been written in it).
3190 // Don't do this for the GUI.
3191 // Don't do this for double-width characters.
3192 // Don't do this for a window not at the right screen border.
3193 if (p_tf
3194#ifdef FEAT_GUI
3195 && !gui.in_use
3196#endif
3197 && !(has_mbyte
3198 && ((*mb_off2cells)(LineOffset[screen_row],
3199 LineOffset[screen_row] + screen_Columns)
3200 == 2
3201 || (*mb_off2cells)(LineOffset[screen_row - 1]
3202 + (int)Columns - 2,
3203 LineOffset[screen_row] + screen_Columns)
3204 == 2)))
3205 {
3206 // First make sure we are at the end of the screen line,
3207 // then output the same character again to let the
3208 // terminal know about the wrap. If the terminal doesn't
3209 // auto-wrap, we overwrite the character.
3210 if (screen_cur_col != wp->w_width)
3211 screen_char(LineOffset[screen_row - 1]
3212 + (unsigned)Columns - 1,
3213 screen_row - 1, (int)(Columns - 1));
3214
3215 // When there is a multi-byte character, just output a
3216 // space to keep it simple.
3217 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3218 screen_row - 1] + (Columns - 1)]) > 1)
3219 out_char(' ');
3220 else
3221 out_char(ScreenLines[LineOffset[screen_row - 1]
3222 + (Columns - 1)]);
3223 // force a redraw of the first char on the next line
3224 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3225 screen_start(); // don't know where cursor is now
3226 }
3227 }
3228
3229 col = 0;
3230 off = (unsigned)(current_ScreenLine - ScreenLines);
3231#ifdef FEAT_RIGHTLEFT
3232 if (wp->w_p_rl)
3233 {
3234 col = wp->w_width - 1; // col is not used if breaking!
3235 off += col;
3236 }
3237#endif
3238
3239 // reset the drawing state for the start of a wrapped line
3240 draw_state = WL_START;
3241 saved_n_extra = n_extra;
3242 saved_p_extra = p_extra;
3243 saved_c_extra = c_extra;
3244 saved_c_final = c_final;
3245#ifdef FEAT_SYN_HL
3246 if (!(cul_screenline
3247# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003248 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003249# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003250 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 saved_char_attr = char_attr;
3252 else
3253#endif
3254 saved_char_attr = 0;
3255 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003256 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257#ifdef FEAT_LINEBREAK
3258# ifdef FEAT_DIFF
3259 if (filler_todo <= 0)
3260# endif
3261 need_showbreak = TRUE;
3262#endif
3263#ifdef FEAT_DIFF
3264 --filler_todo;
3265 // When the filler lines are actually below the last line of the
3266 // file, don't draw the line itself, break here.
3267 if (filler_todo == 0 && wp->w_botfill)
3268 break;
3269#endif
3270 }
3271
3272 } // for every character in the line
3273
3274#ifdef FEAT_SPELL
3275 // After an empty line check first word for capital.
3276 if (*skipwhite(line) == NUL)
3277 {
3278 capcol_lnum = lnum + 1;
3279 cap_col = 0;
3280 }
3281#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003282#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003283 vim_free(text_props);
3284 vim_free(text_prop_idxs);
3285#endif
3286
3287 vim_free(p_extra_free);
3288 return row;
3289}