blob: d8b7c4aad19d98e747f5fe58da68880b0b994d66 [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 Moolenaarae49aa82022-02-25 21:05:36 +0000333 int can_spell = FALSE;
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
Bram Moolenaar936dc602022-03-06 20:47:01 +0000357#else
358# define filler_lines 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200359#endif
360#ifdef FEAT_DIFF
361 hlf_T diff_hlf = (hlf_T)0; // type of diff highlighting
362 int change_start = MAXCOL; // first col of changed area
363 int change_end = -1; // last col of changed area
364#endif
365 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100366 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +0200367 int in_multispace = FALSE; // in multiple consecutive spaces
368 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200369#ifdef FEAT_LINEBREAK
370 int need_showbreak = FALSE; // overlong line, skipping first x
371 // chars
372#endif
373#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
374 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
375# define LINE_ATTR
376 int line_attr = 0; // attribute for the whole line
377 int line_attr_save;
378#endif
379#ifdef FEAT_SIGNS
380 int sign_present = FALSE;
381 sign_attrs_T sattr;
James McCoya80aad72021-12-22 19:45:28 +0000382 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200383#endif
384#ifdef FEAT_ARABIC
385 int prev_c = 0; // previous Arabic character
386 int prev_c1 = 0; // first composing char for prev_c
387#endif
388#if defined(LINE_ATTR)
389 int did_line_attr = 0;
390#endif
391#ifdef FEAT_TERMINAL
392 int get_term_attr = FALSE;
393#endif
394#ifdef FEAT_SYN_HL
395 int cul_attr = 0; // set when 'cursorline' active
396
397 // 'cursorlineopt' has "screenline" and cursor is in this line
398 int cul_screenline = FALSE;
399
400 // margin columns for the screen line, needed for when 'cursorlineopt'
401 // contains "screenline"
402 int left_curline_col = 0;
403 int right_curline_col = 0;
404#endif
405
406 // draw_state: items that are drawn in sequence:
407#define WL_START 0 // nothing done yet
408#ifdef FEAT_CMDWIN
kylo252ae6f1d82022-02-16 19:24:07 +0000409# define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200410#else
411# define WL_CMDLINE WL_START
412#endif
413#ifdef FEAT_FOLDING
kylo252ae6f1d82022-02-16 19:24:07 +0000414# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200415#else
416# define WL_FOLD WL_CMDLINE
417#endif
418#ifdef FEAT_SIGNS
kylo252ae6f1d82022-02-16 19:24:07 +0000419# define WL_SIGN (WL_FOLD + 1) // column for signs
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200420#else
421# define WL_SIGN WL_FOLD // column for signs
422#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000423#define WL_NR (WL_SIGN + 1) // line number
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200424#ifdef FEAT_LINEBREAK
kylo252ae6f1d82022-02-16 19:24:07 +0000425# define WL_BRI (WL_NR + 1) // 'breakindent'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200426#else
427# define WL_BRI WL_NR
428#endif
429#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
kylo252ae6f1d82022-02-16 19:24:07 +0000430# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200431#else
432# define WL_SBR WL_BRI
433#endif
kylo252ae6f1d82022-02-16 19:24:07 +0000434#define WL_LINE (WL_SBR + 1) // text in the line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200435 int draw_state = WL_START; // what to draw next
436#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
437 int feedback_col = 0;
438 int feedback_old_attr = -1;
439#endif
440 int screen_line_flags = 0;
441
442#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
443 int match_conc = 0; // cchar for match functions
Bram Moolenaar0c359af2021-11-29 19:18:57 +0000444 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200445#endif
446#ifdef FEAT_CONCEAL
447 int syntax_flags = 0;
448 int syntax_seqnr = 0;
449 int prev_syntax_id = 0;
450 int conceal_attr = HL_ATTR(HLF_CONCEAL);
451 int is_concealing = FALSE;
452 int boguscols = 0; // nonexistent columns added to force
453 // wrapping
454 int vcol_off = 0; // offset for concealed characters
455 int did_wcol = FALSE;
456 int old_boguscols = 0;
457# define VCOL_HLC (vcol - vcol_off)
458# define FIX_FOR_BOGUSCOLS \
459 { \
460 n_extra += vcol_off; \
461 vcol -= vcol_off; \
462 vcol_off = 0; \
463 col -= boguscols; \
464 old_boguscols = boguscols; \
465 boguscols = 0; \
466 }
467#else
468# define VCOL_HLC (vcol)
469#endif
470
471 if (startrow > endrow) // past the end already!
472 return startrow;
473
474 row = startrow;
475 screen_row = row + W_WINROW(wp);
476
477 if (!number_only)
478 {
479 // To speed up the loop below, set extra_check when there is linebreak,
480 // trailing white space and/or syntax processing to be done.
481#ifdef FEAT_LINEBREAK
482 extra_check = wp->w_p_lbr;
483#endif
484#ifdef FEAT_SYN_HL
485 if (syntax_present(wp) && !wp->w_s->b_syn_error
486# ifdef SYN_TIME_LIMIT
487 && !wp->w_s->b_syn_slow
488# endif
489 )
490 {
491 // Prepare for syntax highlighting in this line. When there is an
492 // error, stop syntax highlighting.
493 save_did_emsg = did_emsg;
494 did_emsg = FALSE;
495 syntax_start(wp, lnum);
496 if (did_emsg)
497 wp->w_s->b_syn_error = TRUE;
498 else
499 {
500 did_emsg = save_did_emsg;
501#ifdef SYN_TIME_LIMIT
502 if (!wp->w_s->b_syn_slow)
503#endif
504 {
505 has_syntax = TRUE;
506 extra_check = TRUE;
507 }
508 }
509 }
510
511 // Check for columns to display for 'colorcolumn'.
512 color_cols = wp->w_p_cc_cols;
513 if (color_cols != NULL)
514 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
515#endif
516
517#ifdef FEAT_TERMINAL
518 if (term_show_buffer(wp->w_buffer))
519 {
520 extra_check = TRUE;
521 get_term_attr = TRUE;
Bram Moolenaar219c7d02020-02-01 21:57:29 +0100522 win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200523 }
524#endif
525
526#ifdef FEAT_SPELL
527 if (wp->w_p_spell
528 && *wp->w_s->b_p_spl != NUL
529 && wp->w_s->b_langp.ga_len > 0
530 && *(char **)(wp->w_s->b_langp.ga_data) != NULL)
531 {
532 // Prepare for spell checking.
533 has_spell = TRUE;
534 extra_check = TRUE;
535
536 // Get the start of the next line, so that words that wrap to the
537 // next line are found too: "et<line-break>al.".
538 // Trick: skip a few chars for C/shell/Vim comments
539 nextline[SPWORDLEN] = NUL;
540 if (lnum < wp->w_buffer->b_ml.ml_line_count)
541 {
542 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
543 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
544 }
545
546 // When a word wrapped from the previous line the start of the
547 // current line is valid.
548 if (lnum == checked_lnum)
549 cur_checked_col = checked_col;
550 checked_lnum = 0;
551
552 // When there was a sentence end in the previous line may require a
553 // word starting with capital in this line. In line 1 always check
554 // the first word.
555 if (lnum != capcol_lnum)
556 cap_col = -1;
557 if (lnum == 1)
558 cap_col = 0;
559 capcol_lnum = 0;
560 }
561#endif
562
563 // handle Visual active in this window
564 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
565 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +0100566 pos_T *top, *bot;
567
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200568 if (LTOREQ_POS(curwin->w_cursor, VIsual))
569 {
570 // Visual is after curwin->w_cursor
571 top = &curwin->w_cursor;
572 bot = &VIsual;
573 }
574 else
575 {
576 // Visual is before curwin->w_cursor
577 top = &VIsual;
578 bot = &curwin->w_cursor;
579 }
580 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
581 if (VIsual_mode == Ctrl_V)
582 {
583 // block mode
584 if (lnum_in_visual_area)
585 {
586 fromcol = wp->w_old_cursor_fcol;
587 tocol = wp->w_old_cursor_lcol;
588 }
589 }
590 else
591 {
592 // non-block mode
593 if (lnum > top->lnum && lnum <= bot->lnum)
594 fromcol = 0;
595 else if (lnum == top->lnum)
596 {
597 if (VIsual_mode == 'V') // linewise
598 fromcol = 0;
599 else
600 {
601 getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
602 if (gchar_pos(top) == NUL)
603 tocol = fromcol + 1;
604 }
605 }
606 if (VIsual_mode != 'V' && lnum == bot->lnum)
607 {
608 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
609 {
610 fromcol = -10;
611 tocol = MAXCOL;
612 }
613 else if (bot->col == MAXCOL)
614 tocol = MAXCOL;
615 else
616 {
617 pos = *bot;
618 if (*p_sel == 'e')
619 getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
620 else
621 {
622 getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
623 ++tocol;
624 }
625 }
626 }
627 }
628
629 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200630 if (!highlight_match && lnum == curwin->w_cursor.lnum
631 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200632#ifdef FEAT_GUI
633 && !gui.in_use
634#endif
635 )
636 noinvcur = TRUE;
637
638 // if inverting in this line set area_highlighting
639 if (fromcol >= 0)
640 {
641 area_highlighting = TRUE;
642 vi_attr = HL_ATTR(HLF_V);
643#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
644 if ((clip_star.available && !clip_star.owned
645 && clip_isautosel_star())
646 || (clip_plus.available && !clip_plus.owned
647 && clip_isautosel_plus()))
648 vi_attr = HL_ATTR(HLF_VNC);
649#endif
650 }
651 }
652
653 // handle 'incsearch' and ":s///c" highlighting
654 else if (highlight_match
655 && wp == curwin
656 && lnum >= curwin->w_cursor.lnum
657 && lnum <= curwin->w_cursor.lnum + search_match_lines)
658 {
659 if (lnum == curwin->w_cursor.lnum)
660 getvcol(curwin, &(curwin->w_cursor),
661 (colnr_T *)&fromcol, NULL, NULL);
662 else
663 fromcol = 0;
664 if (lnum == curwin->w_cursor.lnum + search_match_lines)
665 {
666 pos.lnum = lnum;
667 pos.col = search_match_endcol;
668 getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
669 }
670 else
671 tocol = MAXCOL;
672 // do at least one character; happens when past end of line
Bram Moolenaar448465e2020-11-25 13:49:27 +0100673 if (fromcol == tocol && search_match_endcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200674 tocol = fromcol + 1;
675 area_highlighting = TRUE;
676 vi_attr = HL_ATTR(HLF_I);
677 }
678 }
679
680#ifdef FEAT_DIFF
681 filler_lines = diff_check(wp, lnum);
682 if (filler_lines < 0)
683 {
684 if (filler_lines == -1)
685 {
686 if (diff_find_change(wp, lnum, &change_start, &change_end))
687 diff_hlf = HLF_ADD; // added line
688 else if (change_start == 0)
689 diff_hlf = HLF_TXD; // changed text
690 else
691 diff_hlf = HLF_CHD; // changed line
692 }
693 else
694 diff_hlf = HLF_ADD; // added line
695 filler_lines = 0;
696 area_highlighting = TRUE;
697 }
698 if (lnum == wp->w_topline)
699 filler_lines = wp->w_topfill;
700 filler_todo = filler_lines;
701#endif
702
703#ifdef FEAT_SIGNS
Bram Moolenaar4eb7dae2019-11-12 22:33:45 +0100704 sign_present = buf_get_signattrs(wp, lnum, &sattr);
James McCoya80aad72021-12-22 19:45:28 +0000705 if (sign_present)
706 num_attr = sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200707#endif
708
709#ifdef LINE_ATTR
710# ifdef FEAT_SIGNS
711 // If this line has a sign with line highlighting set line_attr.
712 if (sign_present)
Bram Moolenaar6656c2e2019-10-24 15:00:04 +0200713 line_attr = sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200714# endif
715# if defined(FEAT_QUICKFIX)
716 // Highlight the current line in the quickfix window.
717 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
718 line_attr = HL_ATTR(HLF_QFL);
719# endif
720 if (line_attr != 0)
721 area_highlighting = TRUE;
722#endif
723
724 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
725 ptr = line;
726
727#ifdef FEAT_SPELL
728 if (has_spell && !number_only)
729 {
730 // For checking first word with a capital skip white space.
731 if (cap_col == 0)
732 cap_col = getwhitecols(line);
733
734 // To be able to spell-check over line boundaries copy the end of the
735 // current line into nextline[]. Above the start of the next line was
736 // copied to nextline[SPWORDLEN].
737 if (nextline[SPWORDLEN] == NUL)
738 {
739 // No next line or it is empty.
740 nextlinecol = MAXCOL;
741 nextline_idx = 0;
742 }
743 else
744 {
745 v = (long)STRLEN(line);
746 if (v < SPWORDLEN)
747 {
748 // Short line, use it completely and append the start of the
749 // next line.
750 nextlinecol = 0;
751 mch_memmove(nextline, line, (size_t)v);
752 STRMOVE(nextline + v, nextline + SPWORDLEN);
753 nextline_idx = v + 1;
754 }
755 else
756 {
757 // Long line, use only the last SPWORDLEN bytes.
758 nextlinecol = v - SPWORDLEN;
759 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
760 nextline_idx = SPWORDLEN + 1;
761 }
762 }
763 }
764#endif
765
766 if (wp->w_p_list)
767 {
Bram Moolenaareed9d462021-02-15 20:38:25 +0100768 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +0200769 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +0100770 || wp->w_lcs_chars.trail
771 || wp->w_lcs_chars.lead
772 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200773 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100774
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200775 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100776 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200777 {
778 trailcol = (colnr_T)STRLEN(ptr);
779 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
780 --trailcol;
781 trailcol += (colnr_T) (ptr - line);
782 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100783 // find end of leading whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +0100784 if (wp->w_lcs_chars.lead)
Bram Moolenaar91478ae2021-02-03 15:58:13 +0100785 {
786 leadcol = 0;
787 while (VIM_ISWHITE(ptr[leadcol]))
788 ++leadcol;
789 if (ptr[leadcol] == NUL)
790 // in a line full of spaces all of them are treated as trailing
791 leadcol = (colnr_T)0;
792 else
793 // keep track of the first column not filled with spaces
794 leadcol += (colnr_T) (ptr - line) + 1;
795 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200796 }
797
798 wcr_attr = get_wcr_attr(wp);
799 if (wcr_attr != 0)
800 {
801 win_attr = wcr_attr;
802 area_highlighting = TRUE;
803 }
Bram Moolenaar34390282019-10-16 14:38:26 +0200804
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100805#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200806 if (WIN_IS_POPUP(wp))
807 screen_line_flags |= SLF_POPUP;
808#endif
809
810 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
811 // first character to be displayed.
812 if (wp->w_p_wrap)
813 v = wp->w_skipcol;
814 else
815 v = wp->w_leftcol;
816 if (v > 0 && !number_only)
817 {
818 char_u *prev_ptr = ptr;
819
820 while (vcol < v && *ptr != NUL)
821 {
822 c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
823 vcol += c;
824 prev_ptr = ptr;
825 MB_PTR_ADV(ptr);
826 }
827
828 // When:
829 // - 'cuc' is set, or
830 // - 'colorcolumn' is set, or
831 // - 'virtualedit' is set, or
832 // - the visual mode is active,
833 // the end of the line may be before the start of the displayed part.
834 if (vcol < v && (
835#ifdef FEAT_SYN_HL
836 wp->w_p_cuc || draw_color_col ||
837#endif
838 virtual_active() ||
839 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
840 vcol = v;
841
842 // Handle a character that's not completely on the screen: Put ptr at
843 // that character but skip the first few screen characters.
844 if (vcol > v)
845 {
846 vcol -= c;
847 ptr = prev_ptr;
848 // If the character fits on the screen, don't need to skip it.
849 // Except for a TAB.
850 if (( (*mb_ptr2cells)(ptr) >= c || *ptr == TAB) && col == 0)
851 n_skip = v - vcol;
852 }
853
854 // Adjust for when the inverted text is before the screen,
855 // and when the start of the inverted text is before the screen.
856 if (tocol <= vcol)
857 fromcol = 0;
858 else if (fromcol >= 0 && fromcol < vcol)
859 fromcol = vcol;
860
861#ifdef FEAT_LINEBREAK
862 // When w_skipcol is non-zero, first line needs 'showbreak'
863 if (wp->w_p_wrap)
864 need_showbreak = TRUE;
865#endif
866#ifdef FEAT_SPELL
867 // When spell checking a word we need to figure out the start of the
868 // word and if it's badly spelled or not.
869 if (has_spell)
870 {
871 int len;
872 colnr_T linecol = (colnr_T)(ptr - line);
873 hlf_T spell_hlf = HLF_COUNT;
874
875 pos = wp->w_cursor;
876 wp->w_cursor.lnum = lnum;
877 wp->w_cursor.col = linecol;
878 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
879
880 // spell_move_to() may call ml_get() and make "line" invalid
881 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
882 ptr = line + linecol;
883
884 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
885 {
886 // no bad word found at line start, don't check until end of a
887 // word
888 spell_hlf = HLF_COUNT;
889 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
890 }
891 else
892 {
893 // bad word found, use attributes until end of word
894 word_end = wp->w_cursor.col + len + 1;
895
896 // Turn index into actual attributes.
897 if (spell_hlf != HLF_COUNT)
898 spell_attr = highlight_attr[spell_hlf];
899 }
900 wp->w_cursor = pos;
901
902# ifdef FEAT_SYN_HL
903 // Need to restart syntax highlighting for this line.
904 if (has_syntax)
905 syntax_start(wp, lnum);
906# endif
907 }
908#endif
909 }
910
911 // Correct highlighting for cursor that can't be disabled.
912 // Avoids having to check this for each character.
913 if (fromcol >= 0)
914 {
915 if (noinvcur)
916 {
917 if ((colnr_T)fromcol == wp->w_virtcol)
918 {
919 // highlighting starts at cursor, let it start just after the
920 // cursor
921 fromcol_prev = fromcol;
922 fromcol = -1;
923 }
924 else if ((colnr_T)fromcol < wp->w_virtcol)
925 // restart highlighting after the cursor
926 fromcol_prev = wp->w_virtcol;
927 }
928 if (fromcol >= tocol)
929 fromcol = -1;
930 }
931
932#ifdef FEAT_SEARCH_EXTRA
933 if (!number_only)
934 {
935 v = (long)(ptr - line);
936 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
937 &line, &screen_search_hl,
938 &search_attr);
939 ptr = line + v; // "line" may have been updated
940 }
941#endif
942
943#ifdef FEAT_SYN_HL
944 // Cursor line highlighting for 'cursorline' in the current window.
945 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
946 {
947 // Do not show the cursor line in the text when Visual mode is active,
948 // because it's not clear what is selected then. Do update
949 // w_last_cursorline.
950 if (!(wp == curwin && VIsual_active)
951 && wp->w_p_culopt_flags != CULOPT_NBR)
952 {
953 cul_screenline = (wp->w_p_wrap
954 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
955
956 // Only set line_attr here when "screenline" is not present in
957 // 'cursorlineopt'. Otherwise it's done later.
958 if (!cul_screenline)
959 {
960 cul_attr = HL_ATTR(HLF_CUL);
Bram Moolenaar39f7aa32020-08-31 22:00:05 +0200961# ifdef FEAT_SIGNS
962 // Combine the 'cursorline' and sign highlighting, depending on
963 // the sign priority.
964 if (sign_present && sattr.sat_linehl > 0)
965 {
966 if (sattr.sat_priority >= 100)
967 line_attr = hl_combine_attr(cul_attr, line_attr);
968 else
969 line_attr = hl_combine_attr(line_attr, cul_attr);
970 }
971 else
972# endif
973 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200974 wp->w_last_cursorline = wp->w_cursor.lnum;
975 }
976 else
977 {
978 line_attr_save = line_attr;
979 wp->w_last_cursorline = 0;
980 margin_columns_win(wp, &left_curline_col, &right_curline_col);
981 }
982 area_highlighting = TRUE;
983 }
984 else
985 wp->w_last_cursorline = wp->w_cursor.lnum;
986 }
987#endif
988
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +0100989#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200990 {
991 char_u *prop_start;
992
993 text_prop_count = get_text_props(wp->w_buffer, lnum,
994 &prop_start, FALSE);
995 if (text_prop_count > 0)
996 {
997 // Make a copy of the properties, so that they are properly
998 // aligned.
999 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1000 if (text_props != NULL)
1001 mch_memmove(text_props, prop_start,
1002 text_prop_count * sizeof(textprop_T));
1003
1004 // Allocate an array for the indexes.
1005 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1006 area_highlighting = TRUE;
1007 extra_check = TRUE;
1008 }
1009 }
1010#endif
1011
1012 off = (unsigned)(current_ScreenLine - ScreenLines);
1013 col = 0;
1014
1015#ifdef FEAT_RIGHTLEFT
1016 if (wp->w_p_rl)
1017 {
1018 // Rightleft window: process the text in the normal direction, but put
1019 // it in current_ScreenLine[] from right to left. Start at the
1020 // rightmost column of the window.
1021 col = wp->w_width - 1;
1022 off += col;
1023 screen_line_flags |= SLF_RIGHTLEFT;
1024 }
1025#endif
1026
1027 // Repeat for the whole displayed line.
1028 for (;;)
1029 {
1030#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02001031 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001032#endif
1033#ifdef FEAT_CONCEAL
1034 int did_decrement_ptr = FALSE;
1035#endif
1036 // Skip this quickly when working on the text.
1037 if (draw_state != WL_LINE)
1038 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001039#ifdef FEAT_SYN_HL
1040 if (cul_screenline)
1041 {
1042 cul_attr = 0;
1043 line_attr = line_attr_save;
1044 }
1045#endif
1046
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001047#ifdef FEAT_CMDWIN
1048 if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
1049 {
1050 draw_state = WL_CMDLINE;
1051 if (cmdwin_type != 0 && wp == curwin)
1052 {
1053 // Draw the cmdline character.
1054 n_extra = 1;
1055 c_extra = cmdwin_type;
1056 c_final = NUL;
1057 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_AT));
1058 }
1059 }
1060#endif
1061
1062#ifdef FEAT_FOLDING
1063 if (draw_state == WL_FOLD - 1 && n_extra == 0)
1064 {
1065 int fdc = compute_foldcolumn(wp, 0);
1066
1067 draw_state = WL_FOLD;
1068 if (fdc > 0)
1069 {
1070 // Draw the 'foldcolumn'. Allocate a buffer, "extra" may
1071 // already be in use.
1072 vim_free(p_extra_free);
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001073 p_extra_free = alloc(MAX_MCO * fdc + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001074 if (p_extra_free != NULL)
1075 {
Bram Moolenaar9355ae42021-03-08 19:04:05 +01001076 n_extra = (int)fill_foldcolumn(p_extra_free, wp,
Bram Moolenaar4fa11752021-03-03 13:26:02 +01001077 FALSE, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001078 p_extra_free[n_extra] = NUL;
1079 p_extra = p_extra_free;
1080 c_extra = NUL;
1081 c_final = NUL;
Bram Moolenaare413ea02021-11-24 16:20:13 +00001082 if (use_cursor_line_sign(wp, lnum))
1083 char_attr =
1084 hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLF));
1085 else
1086 char_attr =
1087 hl_combine_attr(wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001088 }
1089 }
1090 }
1091#endif
1092
1093#ifdef FEAT_SIGNS
1094 if (draw_state == WL_SIGN - 1 && n_extra == 0)
1095 {
1096 draw_state = WL_SIGN;
1097 // Show the sign column when there are any signs in this
1098 // buffer or when using Netbeans.
1099 if (signcolumn_on(wp))
1100 get_sign_display_info(FALSE, wp, lnum, &sattr, wcr_attr,
1101 row, startrow, filler_lines, filler_todo, &c_extra,
1102 &c_final, extra, &p_extra, &n_extra, &char_attr);
1103 }
1104#endif
1105
1106 if (draw_state == WL_NR - 1 && n_extra == 0)
1107 {
1108 draw_state = WL_NR;
1109 // Display the absolute or relative line number. After the
1110 // first fill with blanks when the 'n' flag isn't in 'cpo'
1111 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaar936dc602022-03-06 20:47:01 +00001112 && (row == startrow + filler_lines
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001113 || vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
1114 {
1115#ifdef FEAT_SIGNS
1116 // If 'signcolumn' is set to 'number' and a sign is present
1117 // in 'lnum', then display the sign instead of the line
1118 // number.
1119 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u')
1120 && sign_present)
1121 get_sign_display_info(TRUE, wp, lnum, &sattr, wcr_attr,
1122 row, startrow, filler_lines, filler_todo,
1123 &c_extra, &c_final, extra, &p_extra, &n_extra,
1124 &char_attr);
1125 else
1126#endif
1127 {
1128 // Draw the line number (empty space after wrapping).
Bram Moolenaar936dc602022-03-06 20:47:01 +00001129 if (row == startrow + filler_lines)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001130 {
1131 long num;
1132 char *fmt = "%*ld ";
1133
1134 if (wp->w_p_nu && !wp->w_p_rnu)
1135 // 'number' + 'norelativenumber'
1136 num = (long)lnum;
1137 else
1138 {
1139 // 'relativenumber', don't use negative numbers
1140 num = labs((long)get_cursor_rel_lnum(wp, lnum));
1141 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
1142 {
1143 // 'number' + 'relativenumber'
1144 num = lnum;
1145 fmt = "%-*ld ";
1146 }
1147 }
1148
1149 sprintf((char *)extra, fmt,
1150 number_width(wp), num);
1151 if (wp->w_skipcol > 0)
1152 for (p_extra = extra; *p_extra == ' '; ++p_extra)
1153 *p_extra = '-';
1154#ifdef FEAT_RIGHTLEFT
1155 if (wp->w_p_rl) // reverse line numbers
1156 {
1157 char_u *p1, *p2;
1158 int t;
1159
1160 // like rl_mirror(), but keep the space at the end
Christian Brabandt29f0dc32021-06-16 19:28:34 +02001161 p2 = skipwhite(extra);
1162 p2 = skiptowhite(p2) - 1;
1163 for (p1 = skipwhite(extra); p1 < p2; ++p1, --p2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001164 {
1165 t = *p1;
1166 *p1 = *p2;
1167 *p2 = t;
1168 }
1169 }
1170#endif
1171 p_extra = extra;
1172 c_extra = NUL;
1173 c_final = NUL;
1174 }
1175 else
1176 {
1177 c_extra = ' ';
1178 c_final = NUL;
1179 }
1180 n_extra = number_width(wp) + 1;
1181 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_N));
1182#ifdef FEAT_SYN_HL
1183 // When 'cursorline' is set highlight the line number of
1184 // the current line differently.
zeertzjq754d2b42022-03-13 13:40:45 +00001185 // When 'cursorlineopt' does not have "line" only
1186 // highlight the line number itself.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 // TODO: Can we use CursorLine instead of CursorLineNr
1188 // when CursorLineNr isn't set?
Bram Moolenaar49474ca2019-10-05 21:57:12 +02001189 if (wp->w_p_cul
1190 && lnum == wp->w_cursor.lnum
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001191 && (wp->w_p_culopt_flags & CULOPT_NBR)
Bram Moolenaar127969c2022-03-06 19:54:13 +00001192 && (row == startrow + filler_lines
1193 || (row > startrow + filler_lines
zeertzjq754d2b42022-03-13 13:40:45 +00001194 && (wp->w_p_culopt_flags & CULOPT_LINE))))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001195 char_attr = hl_combine_attr(wcr_attr, HL_ATTR(HLF_CLN));
1196#endif
Bram Moolenaarefae76a2019-10-27 22:54:58 +01001197 if (wp->w_p_rnu && lnum < wp->w_cursor.lnum
1198 && HL_ATTR(HLF_LNA) != 0)
1199 // Use LineNrAbove
1200 char_attr = hl_combine_attr(wcr_attr,
1201 HL_ATTR(HLF_LNA));
1202 if (wp->w_p_rnu && lnum > wp->w_cursor.lnum
1203 && HL_ATTR(HLF_LNB) != 0)
1204 // Use LineNrBelow
1205 char_attr = hl_combine_attr(wcr_attr,
1206 HL_ATTR(HLF_LNB));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001207 }
James McCoya80aad72021-12-22 19:45:28 +00001208#ifdef FEAT_SIGNS
1209 if (num_attr)
1210 char_attr = num_attr;
1211#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001212 }
1213 }
1214
1215#ifdef FEAT_LINEBREAK
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001216 if (wp->w_briopt_sbr && draw_state == WL_BRI - 1
Bram Moolenaaree857022019-11-09 23:26:40 +01001217 && n_extra == 0 && *get_showbreak_value(wp) != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 // draw indent after showbreak value
1219 draw_state = WL_BRI;
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001220 else if (wp->w_briopt_sbr && draw_state == WL_SBR && n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001221 // After the showbreak, draw the breakindent
1222 draw_state = WL_BRI - 1;
1223
1224 // draw 'breakindent': indent wrapped text accordingly
1225 if (draw_state == WL_BRI - 1 && n_extra == 0)
1226 {
1227 draw_state = WL_BRI;
1228 // if need_showbreak is set, breakindent also applies
1229 if (wp->w_p_bri && n_extra == 0
1230 && (row != startrow || need_showbreak)
1231# ifdef FEAT_DIFF
1232 && filler_lines == 0
1233# endif
1234 )
1235 {
1236 char_attr = 0;
1237# ifdef FEAT_DIFF
1238 if (diff_hlf != (hlf_T)0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001239 char_attr = HL_ATTR(diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001240# endif
1241 p_extra = NULL;
1242 c_extra = ' ';
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001243 c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 n_extra = get_breakindent_win(wp,
1245 ml_get_buf(wp->w_buffer, lnum, FALSE));
Bram Moolenaare882f7a2020-05-16 14:07:39 +02001246 if (row == startrow)
1247 {
1248 n_extra -= win_col_off2(wp);
1249 if (n_extra < 0)
1250 n_extra = 0;
1251 }
Bram Moolenaarb81f56f2020-02-23 15:29:46 +01001252 if (wp->w_skipcol > 0 && wp->w_p_wrap && wp->w_briopt_sbr)
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001253 need_showbreak = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254 // Correct end of highlighted area for 'breakindent',
1255 // required when 'linebreak' is also set.
1256 if (tocol == vcol)
1257 tocol += n_extra;
1258 }
1259 }
1260#endif
1261
1262#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
1263 if (draw_state == WL_SBR - 1 && n_extra == 0)
1264 {
Bram Moolenaaree857022019-11-09 23:26:40 +01001265 char_u *sbr;
1266
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 draw_state = WL_SBR;
1268# ifdef FEAT_DIFF
1269 if (filler_todo > 0)
1270 {
1271 // Draw "deleted" diff line(s).
1272 if (char2cells(fill_diff) > 1)
1273 {
1274 c_extra = '-';
1275 c_final = NUL;
1276 }
1277 else
1278 {
1279 c_extra = fill_diff;
1280 c_final = NUL;
1281 }
1282# ifdef FEAT_RIGHTLEFT
1283 if (wp->w_p_rl)
1284 n_extra = col + 1;
1285 else
1286# endif
1287 n_extra = wp->w_width - col;
1288 char_attr = HL_ATTR(HLF_DED);
1289 }
1290# endif
1291# ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01001292 sbr = get_showbreak_value(wp);
1293 if (*sbr != NUL && need_showbreak)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001294 {
1295 // Draw 'showbreak' at the start of each broken line.
Bram Moolenaaree857022019-11-09 23:26:40 +01001296 p_extra = sbr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297 c_extra = NUL;
1298 c_final = NUL;
Bram Moolenaaree857022019-11-09 23:26:40 +01001299 n_extra = (int)STRLEN(sbr);
Bram Moolenaardfede9a2020-01-23 19:59:22 +01001300 if (wp->w_skipcol == 0 || !wp->w_p_wrap)
1301 need_showbreak = FALSE;
Bram Moolenaaree857022019-11-09 23:26:40 +01001302 vcol_sbr = vcol + MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 // Correct end of highlighted area for 'showbreak',
1304 // required when 'linebreak' is also set.
1305 if (tocol == vcol)
1306 tocol += n_extra;
1307 // combine 'showbreak' with 'wincolor'
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001308 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001309# ifdef FEAT_SYN_HL
1310 // combine 'showbreak' with 'cursorline'
1311 if (cul_attr != 0)
1312 char_attr = hl_combine_attr(char_attr, cul_attr);
1313# endif
1314 }
1315# endif
1316 }
1317#endif
1318
1319 if (draw_state == WL_LINE - 1 && n_extra == 0)
1320 {
1321 draw_state = WL_LINE;
1322 if (saved_n_extra)
1323 {
1324 // Continue item from end of wrapped line.
1325 n_extra = saved_n_extra;
1326 c_extra = saved_c_extra;
1327 c_final = saved_c_final;
1328 p_extra = saved_p_extra;
1329 char_attr = saved_char_attr;
1330 }
1331 else
1332 char_attr = win_attr;
1333 }
1334 }
1335#ifdef FEAT_SYN_HL
zeertzjq4f33bc22021-08-05 17:57:02 +02001336 if (cul_screenline && draw_state == WL_LINE
1337 && vcol >= left_curline_col
1338 && vcol < right_curline_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001339 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001340 cul_attr = HL_ATTR(HLF_CUL);
1341 line_attr = cul_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001342 }
1343#endif
1344
1345 // When still displaying '$' of change command, stop at cursor.
1346 // When only displaying the (relative) line number and that's done,
1347 // stop here.
Bram Moolenaar511feec2020-06-18 19:15:27 +02001348 if (((dollar_vcol >= 0 && wp == curwin
1349 && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol)
1350 || (number_only && draw_state > WL_NR))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351#ifdef FEAT_DIFF
1352 && filler_todo <= 0
1353#endif
1354 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001355 {
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00001356 screen_line(screen_row, wp->w_wincol, col, -wp->w_width,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001357 screen_line_flags);
1358 // Pretend we have finished updating the window. Except when
1359 // 'cursorcolumn' is set.
1360#ifdef FEAT_SYN_HL
1361 if (wp->w_p_cuc)
1362 row = wp->w_cline_row + wp->w_cline_height;
1363 else
1364#endif
1365 row = wp->w_height;
1366 break;
1367 }
1368
Bram Moolenaar34390282019-10-16 14:38:26 +02001369 if (draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001370 {
1371 // handle Visual or match highlighting in this line
1372 if (vcol == fromcol
1373 || (has_mbyte && vcol + 1 == fromcol && n_extra == 0
1374 && (*mb_ptr2cells)(ptr) > 1)
1375 || ((int)vcol_prev == fromcol_prev
1376 && vcol_prev < vcol // not at margin
1377 && vcol < tocol))
1378 area_attr = vi_attr; // start highlighting
1379 else if (area_attr != 0
1380 && (vcol == tocol
1381 || (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
1382 area_attr = 0; // stop highlighting
1383
1384#ifdef FEAT_SEARCH_EXTRA
1385 if (!n_extra)
1386 {
1387 // Check for start/end of 'hlsearch' and other matches.
1388 // After end, check for start/end of next match.
1389 // When another match, have to check for start again.
1390 v = (long)(ptr - line);
1391 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
1392 &screen_search_hl, &has_match_conc,
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001393 &match_conc, did_line_attr, lcs_eol_one,
1394 &on_last_col);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001395 ptr = line + v; // "line" may have been changed
Bram Moolenaarfc838d62020-06-25 22:23:48 +02001396
1397 // Do not allow a conceal over EOL otherwise EOL will be missed
1398 // and bad things happen.
1399 if (*ptr == NUL)
1400 has_match_conc = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001401 }
1402#endif
1403
1404#ifdef FEAT_DIFF
1405 if (diff_hlf != (hlf_T)0)
1406 {
1407 if (diff_hlf == HLF_CHD && ptr - line >= change_start
1408 && n_extra == 0)
1409 diff_hlf = HLF_TXD; // changed text
1410 if (diff_hlf == HLF_TXD && ptr - line > change_end
1411 && n_extra == 0)
1412 diff_hlf = HLF_CHD; // changed line
1413 line_attr = HL_ATTR(diff_hlf);
1414 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
1415 && wp->w_p_culopt_flags != CULOPT_NBR
1416 && (!cul_screenline || (vcol >= left_curline_col
1417 && vcol <= right_curline_col)))
1418 line_attr = hl_combine_attr(
1419 line_attr, HL_ATTR(HLF_CUL));
1420 }
1421#endif
1422
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001423#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001424 if (text_props != NULL)
1425 {
1426 int pi;
1427 int bcol = (int)(ptr - line);
1428
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001429 if (n_extra > 0
1430# ifdef FEAT_LINEBREAK
1431 && !in_linebreak
1432# endif
1433 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001434 --bcol; // still working on the previous char, e.g. Tab
1435
1436 // Check if any active property ends.
1437 for (pi = 0; pi < text_props_active; ++pi)
1438 {
1439 int tpi = text_prop_idxs[pi];
1440
1441 if (bcol >= text_props[tpi].tp_col - 1
1442 + text_props[tpi].tp_len)
1443 {
1444 if (pi + 1 < text_props_active)
1445 mch_memmove(text_prop_idxs + pi,
1446 text_prop_idxs + pi + 1,
1447 sizeof(int)
1448 * (text_props_active - (pi + 1)));
1449 --text_props_active;
1450 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001451# ifdef FEAT_LINEBREAK
1452 // not exactly right but should work in most cases
1453 if (in_linebreak && syntax_attr == text_prop_attr)
1454 syntax_attr = 0;
1455# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001456 }
1457 }
1458
Bram Moolenaaracdc9112021-12-02 19:46:57 +00001459# ifdef FEAT_LINEBREAK
1460 if (n_extra > 0 && in_linebreak)
1461 // not on the next char yet, don't start another prop
1462 --bcol;
1463# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 // Add any text property that starts in this column.
1465 while (text_prop_next < text_prop_count
1466 && bcol >= text_props[text_prop_next].tp_col - 1)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01001467 {
1468 if (bcol <= text_props[text_prop_next].tp_col - 1
1469 + text_props[text_prop_next].tp_len)
1470 text_prop_idxs[text_props_active++] = text_prop_next;
1471 ++text_prop_next;
1472 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001473
1474 text_prop_attr = 0;
1475 text_prop_combine = FALSE;
Bram Moolenaar053f7122019-09-23 22:17:15 +02001476 text_prop_type = NULL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 if (text_props_active > 0)
1478 {
1479 // Sort the properties on priority and/or starting last.
1480 // Then combine the attributes, highest priority last.
1481 current_text_props = text_props;
1482 current_buf = wp->w_buffer;
1483 qsort((void *)text_prop_idxs, (size_t)text_props_active,
1484 sizeof(int), text_prop_compare);
1485
1486 for (pi = 0; pi < text_props_active; ++pi)
1487 {
1488 int tpi = text_prop_idxs[pi];
1489 proptype_T *pt = text_prop_type_by_id(
1490 wp->w_buffer, text_props[tpi].tp_type);
1491
1492 if (pt != NULL && pt->pt_hl_id > 0)
1493 {
1494 int pt_attr = syn_id2attr(pt->pt_hl_id);
1495
1496 text_prop_type = pt;
1497 text_prop_attr =
1498 hl_combine_attr(text_prop_attr, pt_attr);
1499 text_prop_combine = pt->pt_flags & PT_FLAG_COMBINE;
1500 }
1501 }
1502 }
1503 }
1504#endif
1505
Bram Moolenaara74fda62019-10-19 17:38:03 +02001506#ifdef FEAT_SYN_HL
Bram Moolenaara74fda62019-10-19 17:38:03 +02001507 if (extra_check && n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02001508 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02001509 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001510# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02001511 if (get_term_attr)
Bram Moolenaar219c7d02020-02-01 21:57:29 +01001512 syntax_attr = term_get_attr(wp, lnum, vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02001513# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001514 // Get syntax attribute.
1515 if (has_syntax)
1516 {
1517 // Get the syntax attribute for the character. If there
1518 // is an error, disable syntax highlighting.
1519 save_did_emsg = did_emsg;
1520 did_emsg = FALSE;
1521
1522 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001523 if (v == prev_syntax_col)
1524 // at same column again
1525 syntax_attr = prev_syntax_attr;
1526 else
1527 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001528# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02001529 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02001530# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02001531 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02001532# ifdef FEAT_SPELL
1533 has_spell ? &can_spell :
1534# endif
1535 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02001536 prev_syntax_col = v;
1537 prev_syntax_attr = syntax_attr;
1538 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001539
Bram Moolenaar34390282019-10-16 14:38:26 +02001540 if (did_emsg)
1541 {
1542 wp->w_s->b_syn_error = TRUE;
1543 has_syntax = FALSE;
1544 syntax_attr = 0;
1545 }
1546 else
1547 did_emsg = save_did_emsg;
1548# ifdef SYN_TIME_LIMIT
1549 if (wp->w_s->b_syn_slow)
1550 has_syntax = FALSE;
1551# endif
1552
1553 // Need to get the line again, a multi-line regexp may
1554 // have made it invalid.
1555 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1556 ptr = line + v;
1557# ifdef FEAT_CONCEAL
1558 // no concealing past the end of the line, it interferes
1559 // with line highlighting
1560 if (*ptr == NUL)
1561 syntax_flags = 0;
1562 else
1563 syntax_flags = get_syntax_info(&syntax_seqnr);
1564# endif
1565 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001566 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001567# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01001568 // Combine text property highlight into syntax highlight.
1569 if (text_prop_type != NULL)
1570 {
1571 if (text_prop_combine)
1572 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
1573 else
1574 syntax_attr = text_prop_attr;
1575 }
1576# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02001577#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02001578
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001579 // Decide which of the highlight attributes to use.
1580 attr_pri = TRUE;
1581#ifdef LINE_ATTR
1582 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001583 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001584 char_attr = hl_combine_attr(line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02001585 if (!highlight_match)
1586 // let search highlight show in Visual area if possible
1587 char_attr = hl_combine_attr(search_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001588# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001589 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001590# endif
1591 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001592 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02001593 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 char_attr = hl_combine_attr(line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001595# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001596 char_attr = hl_combine_attr(syntax_attr, char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02001597# endif
1598 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001599 else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
1600 || vcol < fromcol || vcol_prev < fromcol_prev
1601 || vcol >= tocol))
1602 {
1603 // Use line_attr when not in the Visual or 'incsearch' area
1604 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02001605# ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001606 char_attr = hl_combine_attr(syntax_attr, line_attr);
1607# else
1608 char_attr = line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02001609# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001610 attr_pri = FALSE;
1611 }
1612#else
1613 if (area_attr != 0)
1614 char_attr = area_attr;
1615 else if (search_attr != 0)
1616 char_attr = search_attr;
1617#endif
1618 else
1619 {
1620 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621#ifdef FEAT_SYN_HL
Bram Moolenaardbd43162019-11-09 21:28:14 +01001622 char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001623#else
Bram Moolenaardbd43162019-11-09 21:28:14 +01001624 char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02001625#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001626 }
1627 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01001628
1629 // combine attribute with 'wincolor'
1630 if (win_attr != 0)
1631 {
1632 if (char_attr == 0)
1633 char_attr = win_attr;
1634 else
1635 char_attr = hl_combine_attr(win_attr, char_attr);
1636 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001637
1638 // Get the next character to put on the screen.
1639
1640 // The "p_extra" points to the extra stuff that is inserted to
1641 // represent special characters (non-printable stuff) and other
1642 // things. When all characters are the same, c_extra is used.
1643 // If c_final is set, it will compulsorily be used at the end.
1644 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
1645 // "p_extra[n_extra]".
1646 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
1647 if (n_extra > 0)
1648 {
1649 if (c_extra != NUL || (n_extra == 1 && c_final != NUL))
1650 {
1651 c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra;
1652 mb_c = c; // doesn't handle non-utf-8 multi-byte!
1653 if (enc_utf8 && utf_char2len(c) > 1)
1654 {
1655 mb_utf8 = TRUE;
1656 u8cc[0] = 0;
1657 c = 0xc0;
1658 }
1659 else
1660 mb_utf8 = FALSE;
1661 }
1662 else
1663 {
1664 c = *p_extra;
1665 if (has_mbyte)
1666 {
1667 mb_c = c;
1668 if (enc_utf8)
1669 {
1670 // If the UTF-8 character is more than one byte:
1671 // Decode it into "mb_c".
1672 mb_l = utfc_ptr2len(p_extra);
1673 mb_utf8 = FALSE;
1674 if (mb_l > n_extra)
1675 mb_l = 1;
1676 else if (mb_l > 1)
1677 {
1678 mb_c = utfc_ptr2char(p_extra, u8cc);
1679 mb_utf8 = TRUE;
1680 c = 0xc0;
1681 }
1682 }
1683 else
1684 {
1685 // if this is a DBCS character, put it in "mb_c"
1686 mb_l = MB_BYTE2LEN(c);
1687 if (mb_l >= n_extra)
1688 mb_l = 1;
1689 else if (mb_l > 1)
1690 mb_c = (c << 8) + p_extra[1];
1691 }
1692 if (mb_l == 0) // at the NUL at end-of-line
1693 mb_l = 1;
1694
1695 // If a double-width char doesn't fit display a '>' in the
1696 // last column.
1697 if ((
1698# ifdef FEAT_RIGHTLEFT
1699 wp->w_p_rl ? (col <= 0) :
1700# endif
1701 (col >= wp->w_width - 1))
1702 && (*mb_char2cells)(mb_c) == 2)
1703 {
1704 c = '>';
1705 mb_c = c;
1706 mb_l = 1;
1707 mb_utf8 = FALSE;
1708 multi_attr = HL_ATTR(HLF_AT);
1709#ifdef FEAT_SYN_HL
1710 if (cul_attr)
1711 multi_attr = hl_combine_attr(multi_attr, cul_attr);
1712#endif
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001713 multi_attr = hl_combine_attr(win_attr, multi_attr);
1714
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 // put the pointer back to output the double-width
1716 // character at the start of the next line.
1717 ++n_extra;
1718 --p_extra;
1719 }
1720 else
1721 {
1722 n_extra -= mb_l - 1;
1723 p_extra += mb_l - 1;
1724 }
1725 }
1726 ++p_extra;
1727 }
1728 --n_extra;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001729#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001730 if (n_extra <= 0)
1731 in_linebreak = FALSE;
1732#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001733 }
1734 else
1735 {
1736#ifdef FEAT_LINEBREAK
1737 int c0;
1738#endif
Bram Moolenaar2f7b7b12019-11-03 15:46:48 +01001739 VIM_CLEAR(p_extra_free);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001740
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001741 // Get a character from the line itself.
1742 c = *ptr;
1743#ifdef FEAT_LINEBREAK
1744 c0 = *ptr;
1745#endif
1746 if (has_mbyte)
1747 {
1748 mb_c = c;
1749 if (enc_utf8)
1750 {
1751 // If the UTF-8 character is more than one byte: Decode it
1752 // into "mb_c".
1753 mb_l = utfc_ptr2len(ptr);
1754 mb_utf8 = FALSE;
1755 if (mb_l > 1)
1756 {
1757 mb_c = utfc_ptr2char(ptr, u8cc);
1758 // Overlong encoded ASCII or ASCII with composing char
1759 // is displayed normally, except a NUL.
1760 if (mb_c < 0x80)
1761 {
1762 c = mb_c;
1763#ifdef FEAT_LINEBREAK
1764 c0 = mb_c;
1765#endif
1766 }
1767 mb_utf8 = TRUE;
1768
1769 // At start of the line we can have a composing char.
1770 // Draw it as a space with a composing char.
1771 if (utf_iscomposing(mb_c))
1772 {
1773 int i;
1774
1775 for (i = Screen_mco - 1; i > 0; --i)
1776 u8cc[i] = u8cc[i - 1];
1777 u8cc[0] = mb_c;
1778 mb_c = ' ';
1779 }
1780 }
1781
1782 if ((mb_l == 1 && c >= 0x80)
1783 || (mb_l >= 1 && mb_c == 0)
1784 || (mb_l > 1 && (!vim_isprintc(mb_c))))
1785 {
1786 // Illegal UTF-8 byte: display as <xx>.
1787 // Non-BMP character : display as ? or fullwidth ?.
1788 transchar_hex(extra, mb_c);
1789# ifdef FEAT_RIGHTLEFT
1790 if (wp->w_p_rl) // reverse
1791 rl_mirror(extra);
1792# endif
1793 p_extra = extra;
1794 c = *p_extra;
1795 mb_c = mb_ptr2char_adv(&p_extra);
1796 mb_utf8 = (c >= 0x80);
1797 n_extra = (int)STRLEN(p_extra);
1798 c_extra = NUL;
1799 c_final = NUL;
1800 if (area_attr == 0 && search_attr == 0)
1801 {
1802 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001803 extra_attr = hl_combine_attr(
1804 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001805 saved_attr2 = char_attr; // save current attr
1806 }
1807 }
1808 else if (mb_l == 0) // at the NUL at end-of-line
1809 mb_l = 1;
1810#ifdef FEAT_ARABIC
1811 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
1812 {
1813 // Do Arabic shaping.
1814 int pc, pc1, nc;
1815 int pcc[MAX_MCO];
1816
1817 // The idea of what is the previous and next
1818 // character depends on 'rightleft'.
1819 if (wp->w_p_rl)
1820 {
1821 pc = prev_c;
1822 pc1 = prev_c1;
1823 nc = utf_ptr2char(ptr + mb_l);
1824 prev_c1 = u8cc[0];
1825 }
1826 else
1827 {
1828 pc = utfc_ptr2char(ptr + mb_l, pcc);
1829 nc = prev_c;
1830 pc1 = pcc[0];
1831 }
1832 prev_c = mb_c;
1833
1834 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
1835 }
1836 else
1837 prev_c = mb_c;
1838#endif
1839 }
1840 else // enc_dbcs
1841 {
1842 mb_l = MB_BYTE2LEN(c);
1843 if (mb_l == 0) // at the NUL at end-of-line
1844 mb_l = 1;
1845 else if (mb_l > 1)
1846 {
1847 // We assume a second byte below 32 is illegal.
1848 // Hopefully this is OK for all double-byte encodings!
1849 if (ptr[1] >= 32)
1850 mb_c = (c << 8) + ptr[1];
1851 else
1852 {
1853 if (ptr[1] == NUL)
1854 {
1855 // head byte at end of line
1856 mb_l = 1;
Bram Moolenaar32ee6272020-06-10 14:16:49 +02001857 transchar_nonprint(wp->w_buffer, extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001858 }
1859 else
1860 {
1861 // illegal tail byte
1862 mb_l = 2;
1863 STRCPY(extra, "XX");
1864 }
1865 p_extra = extra;
1866 n_extra = (int)STRLEN(extra) - 1;
1867 c_extra = NUL;
1868 c_final = NUL;
1869 c = *p_extra++;
1870 if (area_attr == 0 && search_attr == 0)
1871 {
1872 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001873 extra_attr = hl_combine_attr(
1874 win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 saved_attr2 = char_attr; // save current attr
1876 }
1877 mb_c = c;
1878 }
1879 }
1880 }
1881 // If a double-width char doesn't fit display a '>' in the
1882 // last column; the character is displayed at the start of the
1883 // next line.
1884 if ((
1885# ifdef FEAT_RIGHTLEFT
1886 wp->w_p_rl ? (col <= 0) :
1887# endif
1888 (col >= wp->w_width - 1))
1889 && (*mb_char2cells)(mb_c) == 2)
1890 {
1891 c = '>';
1892 mb_c = c;
1893 mb_utf8 = FALSE;
1894 mb_l = 1;
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01001895 multi_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896 // Put pointer back so that the character will be
1897 // displayed at the start of the next line.
1898 --ptr;
1899#ifdef FEAT_CONCEAL
1900 did_decrement_ptr = TRUE;
1901#endif
1902 }
1903 else if (*ptr != NUL)
1904 ptr += mb_l - 1;
1905
1906 // If a double-width char doesn't fit at the left side display
1907 // a '<' in the first column. Don't do this for unprintable
1908 // characters.
1909 if (n_skip > 0 && mb_l > 1 && n_extra == 0)
1910 {
1911 n_extra = 1;
1912 c_extra = MB_FILLER_CHAR;
1913 c_final = NUL;
1914 c = ' ';
1915 if (area_attr == 0 && search_attr == 0)
1916 {
1917 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01001918 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001919 saved_attr2 = char_attr; // save current attr
1920 }
1921 mb_c = c;
1922 mb_utf8 = FALSE;
1923 mb_l = 1;
1924 }
1925
1926 }
1927 ++ptr;
1928
1929 if (extra_check)
1930 {
1931#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 // Check spelling (unless at the end of the line).
1933 // Only do this when there is no syntax highlighting, the
1934 // @Spell cluster is not used or the current syntax item
1935 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001936 v = (long)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937 if (has_spell && v >= word_end && v > cur_checked_col)
1938 {
1939 spell_attr = 0;
1940 if (c != 0 && (
1941# ifdef FEAT_SYN_HL
1942 !has_syntax ||
1943# endif
1944 can_spell))
1945 {
1946 char_u *prev_ptr, *p;
1947 int len;
1948 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01001949
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 if (has_mbyte)
1951 {
1952 prev_ptr = ptr - mb_l;
1953 v -= mb_l - 1;
1954 }
1955 else
1956 prev_ptr = ptr - 1;
1957
1958 // Use nextline[] if possible, it has the start of the
1959 // next line concatenated.
1960 if ((prev_ptr - line) - nextlinecol >= 0)
1961 p = nextline + (prev_ptr - line) - nextlinecol;
1962 else
1963 p = prev_ptr;
1964 cap_col -= (int)(prev_ptr - line);
1965 len = spell_check(wp, p, &spell_hlf, &cap_col,
1966 nochange);
1967 word_end = v + len;
1968
1969 // In Insert mode only highlight a word that
1970 // doesn't touch the cursor.
1971 if (spell_hlf != HLF_COUNT
1972 && (State & INSERT) != 0
1973 && wp->w_cursor.lnum == lnum
1974 && wp->w_cursor.col >=
1975 (colnr_T)(prev_ptr - line)
1976 && wp->w_cursor.col < (colnr_T)word_end)
1977 {
1978 spell_hlf = HLF_COUNT;
1979 spell_redraw_lnum = lnum;
1980 }
1981
1982 if (spell_hlf == HLF_COUNT && p != prev_ptr
1983 && (p - nextline) + len > nextline_idx)
1984 {
1985 // Remember that the good word continues at the
1986 // start of the next line.
1987 checked_lnum = lnum + 1;
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02001988 checked_col = (int)((p - nextline)
1989 + len - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990 }
1991
1992 // Turn index into actual attributes.
1993 if (spell_hlf != HLF_COUNT)
1994 spell_attr = highlight_attr[spell_hlf];
1995
1996 if (cap_col > 0)
1997 {
1998 if (p != prev_ptr
1999 && (p - nextline) + cap_col >= nextline_idx)
2000 {
2001 // Remember that the word in the next line
2002 // must start with a capital.
2003 capcol_lnum = lnum + 1;
2004 cap_col = (int)((p - nextline) + cap_col
2005 - nextline_idx);
2006 }
2007 else
2008 // Compute the actual column.
2009 cap_col += (int)(prev_ptr - line);
2010 }
2011 }
2012 }
2013 if (spell_attr != 0)
2014 {
2015 if (!attr_pri)
2016 char_attr = hl_combine_attr(char_attr, spell_attr);
2017 else
2018 char_attr = hl_combine_attr(spell_attr, char_attr);
2019 }
2020#endif
2021#ifdef FEAT_LINEBREAK
2022 // Found last space before word: check for line break.
2023 if (wp->w_p_lbr && c0 == c
2024 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2025 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002026 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2027 : 0;
2028 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029
2030 // TODO: is passing p for start of the line OK?
2031 n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
2032 NULL) - 1;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002033
2034 // We have just drawn the showbreak value, no need to add
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002035 // space for it again.
Bram Moolenaara06e3452021-05-29 17:56:37 +02002036 if (vcol == vcol_sbr)
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002037 {
Bram Moolenaara06e3452021-05-29 17:56:37 +02002038 n_extra -= MB_CHARLEN(get_showbreak_value(wp));
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002039 if (n_extra < 0)
2040 n_extra = 0;
2041 }
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002042 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002043 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00002044 // line break, but for TABs the highlighting should
2045 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00002046 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02002047
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048 if (c == TAB && n_extra + col > wp->w_width)
2049# ifdef FEAT_VARTABS
2050 n_extra = tabstop_padding(vcol, wp->w_buffer->b_p_ts,
2051 wp->w_buffer->b_p_vts_array) - 1;
2052# else
2053 n_extra = (int)wp->w_buffer->b_p_ts
2054 - vcol % (int)wp->w_buffer->b_p_ts - 1;
2055# endif
2056
2057 c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
2058 c_final = NUL;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002059# if defined(FEAT_PROP_POPUP)
Bram Moolenaar42eba042021-11-30 20:22:49 +00002060 if (n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002061 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00002062# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002063 if (VIM_ISWHITE(c))
2064 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002065# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002066 if (c == TAB)
2067 // See "Tab alignment" below.
2068 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01002069# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002070 if (!wp->w_p_list)
2071 c = ' ';
2072 }
2073 }
2074#endif
2075
zeertzjqf14b8ba2021-09-10 16:58:30 +02002076 in_multispace = c == ' '
2077 && ((ptr > line + 1 && ptr[-2] == ' ') || *ptr == ' ');
2078 if (!in_multispace)
2079 multispace_pos = 0;
2080
Bram Moolenaareed9d462021-02-15 20:38:25 +01002081 // 'list': Change char 160 to 'nbsp' and space to 'space'
2082 // setting in 'listchars'. But not when the character is
2083 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002084 if (wp->w_p_list
2085 && ((((c == 160 && mb_l == 1)
2086 || (mb_utf8
2087 && ((mb_c == 160 && mb_l == 2)
2088 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01002089 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002090 || (c == ' '
2091 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02002092 && (wp->w_lcs_chars.space
2093 || (in_multispace
2094 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002095 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096 && ptr - line <= trailcol)))
2097 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02002098 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
2099 {
2100 c = wp->w_lcs_chars.multispace[multispace_pos++];
2101 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
2102 multispace_pos = 0;
2103 }
2104 else
2105 c = (c == ' ') ? wp->w_lcs_chars.space
2106 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002107 if (area_attr == 0 && search_attr == 0)
2108 {
2109 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002110 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 saved_attr2 = char_attr; // save current attr
2112 }
2113 mb_c = c;
2114 if (enc_utf8 && utf_char2len(c) > 1)
2115 {
2116 mb_utf8 = TRUE;
2117 u8cc[0] = 0;
2118 c = 0xc0;
2119 }
2120 else
2121 mb_utf8 = FALSE;
2122 }
2123
Bram Moolenaar91478ae2021-02-03 15:58:13 +01002124 if ((trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
2125 || (leadcol != 0 && ptr < line + leadcol && c == ' '))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002127 c = (ptr > line + trailcol) ? wp->w_lcs_chars.trail
2128 : wp->w_lcs_chars.lead;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002129 if (!attr_pri)
2130 {
2131 n_attr = 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002132 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133 saved_attr2 = char_attr; // save current attr
2134 }
2135 mb_c = c;
2136 if (enc_utf8 && utf_char2len(c) > 1)
2137 {
2138 mb_utf8 = TRUE;
2139 u8cc[0] = 0;
2140 c = 0xc0;
2141 }
2142 else
2143 mb_utf8 = FALSE;
2144 }
2145 }
2146
2147 // Handling of non-printable characters.
2148 if (!vim_isprintc(c))
2149 {
2150 // when getting a character from the file, we may have to
2151 // turn it into something else on the way to putting it
2152 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01002153 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002154 {
2155 int tab_len = 0;
2156 long vcol_adjusted = vcol; // removed showbreak length
2157#ifdef FEAT_LINEBREAK
Bram Moolenaaree857022019-11-09 23:26:40 +01002158 char_u *sbr = get_showbreak_value(wp);
2159
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002160 // only adjust the tab_len, when at the first column
2161 // after the showbreak value was drawn
Bram Moolenaaree857022019-11-09 23:26:40 +01002162 if (*sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
2163 vcol_adjusted = vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002164#endif
2165 // tab amount depends on current column
2166#ifdef FEAT_VARTABS
2167 tab_len = tabstop_padding(vcol_adjusted,
2168 wp->w_buffer->b_p_ts,
2169 wp->w_buffer->b_p_vts_array) - 1;
2170#else
2171 tab_len = (int)wp->w_buffer->b_p_ts
2172 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
2173#endif
2174
2175#ifdef FEAT_LINEBREAK
2176 if (!wp->w_p_lbr || !wp->w_p_list)
2177#endif
2178 // tab amount depends on current column
2179 n_extra = tab_len;
2180#ifdef FEAT_LINEBREAK
2181 else
2182 {
2183 char_u *p;
2184 int len;
2185 int i;
2186 int saved_nextra = n_extra;
2187
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002188# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002189 if (vcol_off > 0)
2190 // there are characters to conceal
2191 tab_len += vcol_off;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002192
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002193 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01002194 if (wp->w_p_list && wp->w_lcs_chars.tab1
2195 && old_boguscols > 0
2196 && n_extra > tab_len)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002197 tab_len += n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002198# endif
2199 // If n_extra > 0, it gives the number of chars, to
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002200 // use for a tab, else we need to calculate the width
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002201 // for a tab.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002202 len = (tab_len * mb_char2len(wp->w_lcs_chars.tab2));
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002203 if (wp->w_lcs_chars.tab3)
2204 len += mb_char2len(wp->w_lcs_chars.tab3);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002205 if (n_extra > 0)
2206 len += n_extra - tab_len;
Bram Moolenaareed9d462021-02-15 20:38:25 +01002207 c = wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002208 p = alloc(len + 1);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002209 if (p == NULL)
2210 n_extra = 0;
2211 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002212 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002213 vim_memset(p, ' ', len);
2214 p[len] = NUL;
2215 vim_free(p_extra_free);
2216 p_extra_free = p;
2217 for (i = 0; i < tab_len; i++)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002218 {
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002219 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002220
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002221 if (*p == NUL)
2222 {
2223 tab_len = i;
2224 break;
2225 }
2226
2227 // if tab3 is given, use it for the last char
2228 if (wp->w_lcs_chars.tab3 && i == tab_len - 1)
2229 lcs = wp->w_lcs_chars.tab3;
2230 p += mb_char2bytes(lcs, p);
2231 n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002232 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar89a54b42021-09-07 20:45:31 +02002233 }
2234 p_extra = p_extra_free;
2235# ifdef FEAT_CONCEAL
2236 // n_extra will be increased by FIX_FOX_BOGUSCOLS
2237 // macro below, so need to adjust for that here
2238 if (vcol_off > 0)
2239 n_extra -= vcol_off;
2240# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002241 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002242 }
2243#endif
2244#ifdef FEAT_CONCEAL
2245 {
2246 int vc_saved = vcol_off;
2247
2248 // Tab alignment should be identical regardless of
2249 // 'conceallevel' value. So tab compensates of all
2250 // previous concealed characters, and thus resets
2251 // vcol_off and boguscols accumulated so far in the
2252 // line. Note that the tab can be longer than
2253 // 'tabstop' when there are concealed characters.
2254 FIX_FOR_BOGUSCOLS;
2255
2256 // Make sure, the highlighting for the tab char will be
2257 // correctly set further below (effectively reverts the
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002258 // FIX_FOR_BOGSUCOLS macro).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002259 if (n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01002260 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002261 tab_len += vc_saved;
2262 }
2263#endif
2264 mb_utf8 = FALSE; // don't draw as UTF-8
2265 if (wp->w_p_list)
2266 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002267 c = (n_extra == 0 && wp->w_lcs_chars.tab3)
2268 ? wp->w_lcs_chars.tab3
2269 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002270#ifdef FEAT_LINEBREAK
2271 if (wp->w_p_lbr)
2272 c_extra = NUL; // using p_extra from above
2273 else
2274#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01002275 c_extra = wp->w_lcs_chars.tab2;
2276 c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002277 n_attr = tab_len + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002278 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002279 saved_attr2 = char_attr; // save current attr
2280 mb_c = c;
2281 if (enc_utf8 && utf_char2len(c) > 1)
2282 {
2283 mb_utf8 = TRUE;
2284 u8cc[0] = 0;
2285 c = 0xc0;
2286 }
2287 }
2288 else
2289 {
2290 c_final = NUL;
2291 c_extra = ' ';
2292 c = ' ';
2293 }
2294 }
2295 else if (c == NUL
2296 && (wp->w_p_list
2297 || ((fromcol >= 0 || fromcol_prev >= 0)
2298 && tocol > vcol
2299 && VIsual_mode != Ctrl_V
2300 && (
2301# ifdef FEAT_RIGHTLEFT
2302 wp->w_p_rl ? (col >= 0) :
2303# endif
2304 (col < wp->w_width))
2305 && !(noinvcur
2306 && lnum == wp->w_cursor.lnum
2307 && (colnr_T)vcol == wp->w_virtcol)))
2308 && lcs_eol_one > 0)
2309 {
2310 // Display a '$' after the line or highlight an extra
2311 // character if the line break is included.
2312#if defined(FEAT_DIFF) || defined(LINE_ATTR)
2313 // For a diff line the highlighting continues after the
2314 // "$".
2315 if (
2316# ifdef FEAT_DIFF
2317 diff_hlf == (hlf_T)0
2318# ifdef LINE_ATTR
2319 &&
2320# endif
2321# endif
2322# ifdef LINE_ATTR
2323 line_attr == 0
2324# endif
2325 )
2326#endif
2327 {
2328 // In virtualedit, visual selections may extend
2329 // beyond end of line.
2330 if (area_highlighting && virtual_active()
2331 && tocol != MAXCOL && vcol < tocol)
2332 n_extra = 0;
2333 else
2334 {
2335 p_extra = at_end_str;
2336 n_extra = 1;
2337 c_extra = NUL;
2338 c_final = NUL;
2339 }
2340 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01002341 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
2342 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002343 else
2344 c = ' ';
2345 lcs_eol_one = -1;
2346 --ptr; // put it back at the NUL
2347 if (!attr_pri)
2348 {
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002349 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002350 n_attr = 1;
2351 }
2352 mb_c = c;
2353 if (enc_utf8 && utf_char2len(c) > 1)
2354 {
2355 mb_utf8 = TRUE;
2356 u8cc[0] = 0;
2357 c = 0xc0;
2358 }
2359 else
2360 mb_utf8 = FALSE; // don't draw as UTF-8
2361 }
2362 else if (c != NUL)
2363 {
Bram Moolenaar32ee6272020-06-10 14:16:49 +02002364 p_extra = transchar_buf(wp->w_buffer, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002365 if (n_extra == 0)
2366 n_extra = byte2cells(c) - 1;
2367#ifdef FEAT_RIGHTLEFT
2368 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
2369 rl_mirror(p_extra); // reverse "<12>"
2370#endif
2371 c_extra = NUL;
2372 c_final = NUL;
2373#ifdef FEAT_LINEBREAK
2374 if (wp->w_p_lbr)
2375 {
2376 char_u *p;
2377
2378 c = *p_extra;
2379 p = alloc(n_extra + 1);
2380 vim_memset(p, ' ', n_extra);
2381 STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
2382 p[n_extra] = NUL;
2383 vim_free(p_extra_free);
2384 p_extra_free = p_extra = p;
2385 }
2386 else
2387#endif
2388 {
2389 n_extra = byte2cells(c) - 1;
2390 c = *p_extra++;
2391 }
2392 if (!attr_pri)
2393 {
2394 n_attr = n_extra + 1;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002395 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_8));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002396 saved_attr2 = char_attr; // save current attr
2397 }
2398 mb_utf8 = FALSE; // don't draw as UTF-8
2399 }
2400 else if (VIsual_active
2401 && (VIsual_mode == Ctrl_V
2402 || VIsual_mode == 'v')
2403 && virtual_active()
2404 && tocol != MAXCOL
2405 && vcol < tocol
2406 && (
2407#ifdef FEAT_RIGHTLEFT
2408 wp->w_p_rl ? (col >= 0) :
2409#endif
2410 (col < wp->w_width)))
2411 {
2412 c = ' ';
2413 --ptr; // put it back at the NUL
2414 }
2415#if defined(LINE_ATTR)
2416 else if ((
2417# ifdef FEAT_DIFF
2418 diff_hlf != (hlf_T)0 ||
2419# endif
2420# ifdef FEAT_TERMINAL
2421 win_attr != 0 ||
2422# endif
2423 line_attr != 0
2424 ) && (
2425# ifdef FEAT_RIGHTLEFT
2426 wp->w_p_rl ? (col >= 0) :
2427# endif
2428 (col
2429# ifdef FEAT_CONCEAL
2430 - boguscols
2431# endif
2432 < wp->w_width)))
2433 {
2434 // Highlight until the right side of the window
2435 c = ' ';
2436 --ptr; // put it back at the NUL
2437
2438 // Remember we do the char for line highlighting.
2439 ++did_line_attr;
2440
2441 // don't do search HL for the rest of the line
2442 if (line_attr != 0 && char_attr == search_attr
2443 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01002444 || (wp->w_p_list &&
2445 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002446 char_attr = line_attr;
2447# ifdef FEAT_DIFF
2448 if (diff_hlf == HLF_TXD)
2449 {
2450 diff_hlf = HLF_CHD;
2451 if (vi_attr == 0 || char_attr != vi_attr)
2452 {
2453 char_attr = HL_ATTR(diff_hlf);
2454 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2455 && wp->w_p_culopt_flags != CULOPT_NBR
2456 && (!cul_screenline
2457 || (vcol >= left_curline_col
2458 && vcol <= right_curline_col)))
2459 char_attr = hl_combine_attr(
2460 char_attr, HL_ATTR(HLF_CUL));
2461 }
2462 }
2463# endif
2464# ifdef FEAT_TERMINAL
2465 if (win_attr != 0)
2466 {
2467 char_attr = win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02002468 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2469 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002470 {
2471 if (!cul_screenline || (vcol >= left_curline_col
2472 && vcol <= right_curline_col))
2473 char_attr = hl_combine_attr(
2474 char_attr, HL_ATTR(HLF_CUL));
2475 }
2476 else if (line_attr)
2477 char_attr = hl_combine_attr(char_attr, line_attr);
2478 }
2479# endif
2480 }
2481#endif
2482 }
2483
2484#ifdef FEAT_CONCEAL
2485 if ( wp->w_p_cole > 0
2486 && (wp != curwin || lnum != wp->w_cursor.lnum ||
2487 conceal_cursor_line(wp))
2488 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
2489 && !(lnum_in_visual_area
2490 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
2491 {
2492 char_attr = conceal_attr;
2493 if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002494 && (syn_get_sub_char() != NUL
2495 || (has_match_conc && match_conc)
2496 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002497 && wp->w_p_cole != 3)
2498 {
2499 // First time at this concealed item: display one
2500 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02002501 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002502 c = match_conc;
2503 else if (syn_get_sub_char() != NUL)
2504 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01002505 else if (wp->w_lcs_chars.conceal != NUL)
2506 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002507 else
2508 c = ' ';
2509
2510 prev_syntax_id = syntax_seqnr;
2511
2512 if (n_extra > 0)
2513 vcol_off += n_extra;
2514 vcol += n_extra;
2515 if (wp->w_p_wrap && n_extra > 0)
2516 {
2517# ifdef FEAT_RIGHTLEFT
2518 if (wp->w_p_rl)
2519 {
2520 col -= n_extra;
2521 boguscols -= n_extra;
2522 }
2523 else
2524# endif
2525 {
2526 boguscols += n_extra;
2527 col += n_extra;
2528 }
2529 }
2530 n_extra = 0;
2531 n_attr = 0;
2532 }
2533 else if (n_skip == 0)
2534 {
2535 is_concealing = TRUE;
2536 n_skip = 1;
2537 }
2538 mb_c = c;
2539 if (enc_utf8 && utf_char2len(c) > 1)
2540 {
2541 mb_utf8 = TRUE;
2542 u8cc[0] = 0;
2543 c = 0xc0;
2544 }
2545 else
2546 mb_utf8 = FALSE; // don't draw as UTF-8
2547 }
2548 else
2549 {
2550 prev_syntax_id = 0;
2551 is_concealing = FALSE;
2552 }
2553
2554 if (n_skip > 0 && did_decrement_ptr)
2555 // not showing the '>', put pointer back to avoid getting stuck
2556 ++ptr;
2557
2558#endif // FEAT_CONCEAL
2559 }
2560
2561#ifdef FEAT_CONCEAL
2562 // In the cursor line and we may be concealing characters: correct
2563 // the cursor column when we reach its position.
2564 if (!did_wcol && draw_state == WL_LINE
2565 && wp == curwin && lnum == wp->w_cursor.lnum
2566 && conceal_cursor_line(wp)
2567 && (int)wp->w_virtcol <= vcol + n_skip)
2568 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002569# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 if (wp->w_p_rl)
2571 wp->w_wcol = wp->w_width - col + boguscols - 1;
2572 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002573# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002574 wp->w_wcol = col - boguscols;
2575 wp->w_wrow = row;
2576 did_wcol = TRUE;
2577 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002578# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01002579 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01002580# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002581 }
2582#endif
2583
2584 // Don't override visual selection highlighting.
2585 if (n_attr > 0
2586 && draw_state == WL_LINE
2587 && !attr_pri)
2588 {
2589#ifdef LINE_ATTR
2590 if (line_attr)
2591 char_attr = hl_combine_attr(extra_attr, line_attr);
2592 else
2593#endif
2594 char_attr = extra_attr;
2595 }
2596
2597#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
2598 // XIM don't send preedit_start and preedit_end, but they send
2599 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
2600 // im_is_preediting() here.
2601 if (p_imst == IM_ON_THE_SPOT
2602 && xic != NULL
2603 && lnum == wp->w_cursor.lnum
2604 && (State & INSERT)
2605 && !p_imdisable
2606 && im_is_preediting()
2607 && draw_state == WL_LINE)
2608 {
2609 colnr_T tcol;
2610
2611 if (preedit_end_col == MAXCOL)
2612 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
2613 else
2614 tcol = preedit_end_col;
2615 if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
2616 {
2617 if (feedback_old_attr < 0)
2618 {
2619 feedback_col = 0;
2620 feedback_old_attr = char_attr;
2621 }
2622 char_attr = im_get_feedback_attr(feedback_col);
2623 if (char_attr < 0)
2624 char_attr = feedback_old_attr;
2625 feedback_col++;
2626 }
2627 else if (feedback_old_attr >= 0)
2628 {
2629 char_attr = feedback_old_attr;
2630 feedback_old_attr = -1;
2631 feedback_col = 0;
2632 }
2633 }
2634#endif
2635 // Handle the case where we are in column 0 but not on the first
2636 // character of the line and the user wants us to show us a
2637 // special character (via 'listchars' option "precedes:<char>".
2638 if (lcs_prec_todo != NUL
2639 && wp->w_p_list
Bram Moolenaarbffba7f2019-09-20 17:00:17 +02002640 && (wp->w_p_wrap ?
2641 (wp->w_skipcol > 0 && row == 0) :
2642 wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643#ifdef FEAT_DIFF
2644 && filler_todo <= 0
2645#endif
2646 && draw_state > WL_NR
2647 && c != NUL)
2648 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002649 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002650 lcs_prec_todo = NUL;
2651 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2652 {
2653 // Double-width character being overwritten by the "precedes"
2654 // character, need to fill up half the character.
2655 c_extra = MB_FILLER_CHAR;
2656 c_final = NUL;
2657 n_extra = 1;
2658 n_attr = 2;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002659 extra_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002660 }
2661 mb_c = c;
2662 if (enc_utf8 && utf_char2len(c) > 1)
2663 {
2664 mb_utf8 = TRUE;
2665 u8cc[0] = 0;
2666 c = 0xc0;
2667 }
2668 else
2669 mb_utf8 = FALSE; // don't draw as UTF-8
2670 if (!attr_pri)
2671 {
2672 saved_attr3 = char_attr; // save current attr
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002673 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674 n_attr3 = 1;
2675 }
2676 }
2677
2678 // At end of the text line or just after the last character.
2679 if ((c == NUL
2680#if defined(LINE_ATTR)
2681 || did_line_attr == 1
2682#endif
2683 ) && eol_hl_off == 0)
2684 {
2685#ifdef FEAT_SEARCH_EXTRA
2686 // flag to indicate whether prevcol equals startcol of search_hl or
2687 // one of the matches
2688 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
2689 (long)(ptr - line) - (c == NUL));
2690#endif
2691 // Invert at least one char, used for Visual and empty line or
2692 // highlight match at end of line. If it's beyond the last
2693 // char on the screen, just overwrite that one (tricky!) Not
2694 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002695 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 && ((area_attr != 0 && vcol == fromcol
2697 && (VIsual_mode != Ctrl_V
2698 || lnum == VIsual.lnum
2699 || lnum == curwin->w_cursor.lnum)
2700 && c == NUL)
2701#ifdef FEAT_SEARCH_EXTRA
2702 // highlight 'hlsearch' match at end of line
2703 || (prevcol_hl_flag
2704# ifdef FEAT_SYN_HL
2705 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
2706 && !(wp == curwin && VIsual_active))
2707# endif
2708# ifdef FEAT_DIFF
2709 && diff_hlf == (hlf_T)0
2710# endif
2711# if defined(LINE_ATTR)
2712 && did_line_attr <= 1
2713# endif
2714 )
2715#endif
2716 ))
2717 {
2718 int n = 0;
2719
2720#ifdef FEAT_RIGHTLEFT
2721 if (wp->w_p_rl)
2722 {
2723 if (col < 0)
2724 n = 1;
2725 }
2726 else
2727#endif
2728 {
2729 if (col >= wp->w_width)
2730 n = -1;
2731 }
2732 if (n != 0)
2733 {
2734 // At the window boundary, highlight the last character
2735 // instead (better than nothing).
2736 off += n;
2737 col += n;
2738 }
2739 else
2740 {
2741 // Add a blank character to highlight.
2742 ScreenLines[off] = ' ';
2743 if (enc_utf8)
2744 ScreenLinesUC[off] = 0;
2745 }
2746#ifdef FEAT_SEARCH_EXTRA
2747 if (area_attr == 0)
2748 {
2749 // Use attributes from match with highest priority among
2750 // 'search_hl' and the match list.
2751 get_search_match_hl(wp, &screen_search_hl,
2752 (long)(ptr - line), &char_attr);
2753 }
2754#endif
2755 ScreenAttrs[off] = char_attr;
2756#ifdef FEAT_RIGHTLEFT
2757 if (wp->w_p_rl)
2758 {
2759 --col;
2760 --off;
2761 }
2762 else
2763#endif
2764 {
2765 ++col;
2766 ++off;
2767 }
2768 ++vcol;
2769 eol_hl_off = 1;
2770 }
2771 }
2772
2773 // At end of the text line.
2774 if (c == NUL)
2775 {
2776#ifdef FEAT_SYN_HL
2777 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
2778 if (wp->w_p_wrap)
2779 v = wp->w_skipcol;
2780 else
2781 v = wp->w_leftcol;
2782
2783 // check if line ends before left margin
2784 if (vcol < v + col - win_col_off(wp))
2785 vcol = v + col - win_col_off(wp);
2786#ifdef FEAT_CONCEAL
2787 // Get rid of the boguscols now, we want to draw until the right
2788 // edge for 'cursorcolumn'.
2789 col -= boguscols;
2790 boguscols = 0;
2791#endif
2792
2793 if (draw_color_col)
2794 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2795
2796 if (((wp->w_p_cuc
2797 && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
2798 && (int)wp->w_virtcol <
=?UTF-8?q?Dundar=20G=C3=B6c?=d5cec1f2022-01-29 15:19:23 +00002799 (long)wp->w_width * (row - startrow + 1) + v
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002800 && lnum != wp->w_cursor.lnum)
2801 || draw_color_col
2802 || win_attr != 0)
2803# ifdef FEAT_RIGHTLEFT
2804 && !wp->w_p_rl
2805# endif
2806 )
2807 {
2808 int rightmost_vcol = 0;
2809 int i;
2810
2811 if (wp->w_p_cuc)
2812 rightmost_vcol = wp->w_virtcol;
2813 if (draw_color_col)
2814 // determine rightmost colorcolumn to possibly draw
2815 for (i = 0; color_cols[i] >= 0; ++i)
2816 if (rightmost_vcol < color_cols[i])
2817 rightmost_vcol = color_cols[i];
2818
2819 while (col < wp->w_width)
2820 {
2821 ScreenLines[off] = ' ';
2822 if (enc_utf8)
2823 ScreenLinesUC[off] = 0;
2824 ++col;
2825 if (draw_color_col)
2826 draw_color_col = advance_color_col(VCOL_HLC,
2827 &color_cols);
2828
2829 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
2830 ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
2831 else if (draw_color_col && VCOL_HLC == *color_cols)
2832 ScreenAttrs[off++] = HL_ATTR(HLF_MC);
2833 else
2834 ScreenAttrs[off++] = win_attr;
2835
2836 if (VCOL_HLC >= rightmost_vcol && win_attr == 0)
2837 break;
2838
2839 ++vcol;
2840 }
2841 }
2842#endif
2843
2844 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00002845 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002846 row++;
2847
2848 // Update w_cline_height and w_cline_folded if the cursor line was
2849 // updated (saves a call to plines() later).
2850 if (wp == curwin && lnum == curwin->w_cursor.lnum)
2851 {
2852 curwin->w_cline_row = startrow;
2853 curwin->w_cline_height = row - startrow;
2854#ifdef FEAT_FOLDING
2855 curwin->w_cline_folded = FALSE;
2856#endif
2857 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
2858 }
2859
2860 break;
2861 }
2862
2863 // Show "extends" character from 'listchars' if beyond the line end and
2864 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01002865 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar41fb7232021-07-08 12:40:05 +02002866 && draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002867 && wp->w_p_list
2868 && !wp->w_p_wrap
2869#ifdef FEAT_DIFF
2870 && filler_todo <= 0
2871#endif
2872 && (
2873#ifdef FEAT_RIGHTLEFT
2874 wp->w_p_rl ? col == 0 :
2875#endif
2876 col == wp->w_width - 1)
2877 && (*ptr != NUL
2878 || (wp->w_p_list && lcs_eol_one > 0)
2879 || (n_extra && (c_extra != NUL || *p_extra != NUL))))
2880 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01002881 c = wp->w_lcs_chars.ext;
Bram Moolenaar42e931b2019-12-04 19:08:50 +01002882 char_attr = hl_combine_attr(win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002883 mb_c = c;
2884 if (enc_utf8 && utf_char2len(c) > 1)
2885 {
2886 mb_utf8 = TRUE;
2887 u8cc[0] = 0;
2888 c = 0xc0;
2889 }
2890 else
2891 mb_utf8 = FALSE;
2892 }
2893
2894#ifdef FEAT_SYN_HL
2895 // advance to the next 'colorcolumn'
2896 if (draw_color_col)
2897 draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
2898
2899 // Highlight the cursor column if 'cursorcolumn' is set. But don't
2900 // highlight the cursor position itself.
2901 // Also highlight the 'colorcolumn' if it is different than
2902 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002903 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
2904 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 vcol_save_attr = -1;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002906 if (((draw_state == WL_LINE ||
Bram Moolenaarad5e5632020-09-15 20:52:26 +02002907 draw_state == WL_BRI ||
2908 draw_state == WL_SBR) && !lnum_in_visual_area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002909 && search_attr == 0 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002910# ifdef FEAT_DIFF
2911 && filler_todo <= 0
2912# endif
2913 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002914 {
2915 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
2916 && lnum != wp->w_cursor.lnum)
2917 {
2918 vcol_save_attr = char_attr;
2919 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
2920 }
2921 else if (draw_color_col && VCOL_HLC == *color_cols)
2922 {
2923 vcol_save_attr = char_attr;
2924 char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
2925 }
2926 }
2927#endif
2928
2929 // Store character to be displayed.
2930 // Skip characters that are left of the screen for 'nowrap'.
2931 vcol_prev = vcol;
2932 if (draw_state < WL_LINE || n_skip <= 0)
2933 {
2934 // Store the character.
2935#if defined(FEAT_RIGHTLEFT)
2936 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
2937 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00002938 // A double-wide character is: put first half in left cell.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 --off;
2940 --col;
2941 }
2942#endif
2943 ScreenLines[off] = c;
2944 if (enc_dbcs == DBCS_JPNU)
2945 {
2946 if ((mb_c & 0xff00) == 0x8e00)
2947 ScreenLines[off] = 0x8e;
2948 ScreenLines2[off] = mb_c & 0xff;
2949 }
2950 else if (enc_utf8)
2951 {
2952 if (mb_utf8)
2953 {
2954 int i;
2955
2956 ScreenLinesUC[off] = mb_c;
2957 if ((c & 0xff) == 0)
2958 ScreenLines[off] = 0x80; // avoid storing zero
2959 for (i = 0; i < Screen_mco; ++i)
2960 {
2961 ScreenLinesC[i][off] = u8cc[i];
2962 if (u8cc[i] == 0)
2963 break;
2964 }
2965 }
2966 else
2967 ScreenLinesUC[off] = 0;
2968 }
2969 if (multi_attr)
2970 {
2971 ScreenAttrs[off] = multi_attr;
2972 multi_attr = 0;
2973 }
2974 else
2975 ScreenAttrs[off] = char_attr;
2976
2977 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
2978 {
2979 // Need to fill two screen columns.
2980 ++off;
2981 ++col;
2982 if (enc_utf8)
2983 // UTF-8: Put a 0 in the second screen char.
2984 ScreenLines[off] = 0;
2985 else
2986 // DBCS: Put second byte in the second screen char.
2987 ScreenLines[off] = mb_c & 0xff;
2988 if (draw_state > WL_NR
2989#ifdef FEAT_DIFF
2990 && filler_todo <= 0
2991#endif
2992 )
2993 ++vcol;
2994 // When "tocol" is halfway a character, set it to the end of
2995 // the character, otherwise highlighting won't stop.
2996 if (tocol == vcol)
2997 ++tocol;
2998#ifdef FEAT_RIGHTLEFT
2999 if (wp->w_p_rl)
3000 {
3001 // now it's time to backup one cell
3002 --off;
3003 --col;
3004 }
3005#endif
3006 }
3007#ifdef FEAT_RIGHTLEFT
3008 if (wp->w_p_rl)
3009 {
3010 --off;
3011 --col;
3012 }
3013 else
3014#endif
3015 {
3016 ++off;
3017 ++col;
3018 }
3019 }
3020#ifdef FEAT_CONCEAL
3021 else if (wp->w_p_cole > 0 && is_concealing)
3022 {
3023 --n_skip;
3024 ++vcol_off;
3025 if (n_extra > 0)
3026 vcol_off += n_extra;
3027 if (wp->w_p_wrap)
3028 {
3029 // Special voodoo required if 'wrap' is on.
3030 //
3031 // Advance the column indicator to force the line
3032 // drawing to wrap early. This will make the line
3033 // take up the same screen space when parts are concealed,
3034 // so that cursor line computations aren't messed up.
3035 //
3036 // To avoid the fictitious advance of 'col' causing
3037 // trailing junk to be written out of the screen line
3038 // we are building, 'boguscols' keeps track of the number
3039 // of bad columns we have advanced.
3040 if (n_extra > 0)
3041 {
3042 vcol += n_extra;
3043# ifdef FEAT_RIGHTLEFT
3044 if (wp->w_p_rl)
3045 {
3046 col -= n_extra;
3047 boguscols -= n_extra;
3048 }
3049 else
3050# endif
3051 {
3052 col += n_extra;
3053 boguscols += n_extra;
3054 }
3055 n_extra = 0;
3056 n_attr = 0;
3057 }
3058
3059
3060 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3061 {
3062 // Need to fill two screen columns.
3063# ifdef FEAT_RIGHTLEFT
3064 if (wp->w_p_rl)
3065 {
3066 --boguscols;
3067 --col;
3068 }
3069 else
3070# endif
3071 {
3072 ++boguscols;
3073 ++col;
3074 }
3075 }
3076
3077# ifdef FEAT_RIGHTLEFT
3078 if (wp->w_p_rl)
3079 {
3080 --boguscols;
3081 --col;
3082 }
3083 else
3084# endif
3085 {
3086 ++boguscols;
3087 ++col;
3088 }
3089 }
3090 else
3091 {
3092 if (n_extra > 0)
3093 {
3094 vcol += n_extra;
3095 n_extra = 0;
3096 n_attr = 0;
3097 }
3098 }
3099
3100 }
3101#endif // FEAT_CONCEAL
3102 else
3103 --n_skip;
3104
3105 // Only advance the "vcol" when after the 'number' or 'relativenumber'
3106 // column.
3107 if (draw_state > WL_NR
3108#ifdef FEAT_DIFF
3109 && filler_todo <= 0
3110#endif
3111 )
3112 ++vcol;
3113
3114#ifdef FEAT_SYN_HL
3115 if (vcol_save_attr >= 0)
3116 char_attr = vcol_save_attr;
3117#endif
3118
3119 // restore attributes after "predeces" in 'listchars'
3120 if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
3121 char_attr = saved_attr3;
3122
3123 // restore attributes after last 'listchars' or 'number' char
3124 if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
3125 char_attr = saved_attr2;
3126
3127 // At end of screen line and there is more to come: Display the line
3128 // so far. If there is no more to display it is caught above.
3129 if ((
3130#ifdef FEAT_RIGHTLEFT
3131 wp->w_p_rl ? (col < 0) :
3132#endif
3133 (col >= wp->w_width))
Bram Moolenaar41fb7232021-07-08 12:40:05 +02003134 && (draw_state != WL_LINE
3135 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136#ifdef FEAT_DIFF
3137 || filler_todo > 0
3138#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01003139 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
3140 && p_extra != at_end_str)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003141 || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
3142 )
3143 {
3144#ifdef FEAT_CONCEAL
3145 screen_line(screen_row, wp->w_wincol, col - boguscols,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003146 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 boguscols = 0;
3148#else
3149 screen_line(screen_row, wp->w_wincol, col,
=?UTF-8?q?Dundar=20G=C3=B6c?=420fabc2022-01-28 15:28:04 +00003150 wp->w_width, screen_line_flags);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003151#endif
3152 ++row;
3153 ++screen_row;
3154
3155 // When not wrapping and finished diff lines, or when displayed
3156 // '$' and highlighting until last column, break here.
3157 if ((!wp->w_p_wrap
3158#ifdef FEAT_DIFF
3159 && filler_todo <= 0
3160#endif
3161 ) || lcs_eol_one == -1)
3162 break;
3163
3164 // When the window is too narrow draw all "@" lines.
3165 if (draw_state != WL_LINE
3166#ifdef FEAT_DIFF
3167 && filler_todo <= 0
3168#endif
3169 )
3170 {
3171 win_draw_end(wp, '@', ' ', TRUE, row, wp->w_height, HLF_AT);
3172 draw_vsep_win(wp, row);
3173 row = endrow;
3174 }
3175
3176 // When line got too long for screen break here.
3177 if (row == endrow)
3178 {
3179 ++row;
3180 break;
3181 }
3182
3183 if (screen_cur_row == screen_row - 1
3184#ifdef FEAT_DIFF
3185 && filler_todo <= 0
3186#endif
3187 && wp->w_width == Columns)
3188 {
3189 // Remember that the line wraps, used for modeless copy.
3190 LineWraps[screen_row - 1] = TRUE;
3191
3192 // Special trick to make copy/paste of wrapped lines work with
3193 // xterm/screen: write an extra character beyond the end of
3194 // the line. This will work with all terminal types
3195 // (regardless of the xn,am settings).
3196 // Only do this on a fast tty.
3197 // Only do this if the cursor is on the current line
3198 // (something has been written in it).
3199 // Don't do this for the GUI.
3200 // Don't do this for double-width characters.
3201 // Don't do this for a window not at the right screen border.
3202 if (p_tf
3203#ifdef FEAT_GUI
3204 && !gui.in_use
3205#endif
3206 && !(has_mbyte
3207 && ((*mb_off2cells)(LineOffset[screen_row],
3208 LineOffset[screen_row] + screen_Columns)
3209 == 2
3210 || (*mb_off2cells)(LineOffset[screen_row - 1]
3211 + (int)Columns - 2,
3212 LineOffset[screen_row] + screen_Columns)
3213 == 2)))
3214 {
3215 // First make sure we are at the end of the screen line,
3216 // then output the same character again to let the
3217 // terminal know about the wrap. If the terminal doesn't
3218 // auto-wrap, we overwrite the character.
3219 if (screen_cur_col != wp->w_width)
3220 screen_char(LineOffset[screen_row - 1]
3221 + (unsigned)Columns - 1,
3222 screen_row - 1, (int)(Columns - 1));
3223
3224 // When there is a multi-byte character, just output a
3225 // space to keep it simple.
3226 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
3227 screen_row - 1] + (Columns - 1)]) > 1)
3228 out_char(' ');
3229 else
3230 out_char(ScreenLines[LineOffset[screen_row - 1]
3231 + (Columns - 1)]);
3232 // force a redraw of the first char on the next line
3233 ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
3234 screen_start(); // don't know where cursor is now
3235 }
3236 }
3237
3238 col = 0;
3239 off = (unsigned)(current_ScreenLine - ScreenLines);
3240#ifdef FEAT_RIGHTLEFT
3241 if (wp->w_p_rl)
3242 {
3243 col = wp->w_width - 1; // col is not used if breaking!
3244 off += col;
3245 }
3246#endif
3247
3248 // reset the drawing state for the start of a wrapped line
3249 draw_state = WL_START;
3250 saved_n_extra = n_extra;
3251 saved_p_extra = p_extra;
3252 saved_c_extra = c_extra;
3253 saved_c_final = c_final;
3254#ifdef FEAT_SYN_HL
3255 if (!(cul_screenline
3256# ifdef FEAT_DIFF
Bram Moolenaare7705982020-04-21 22:23:15 +02003257 && diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003258# endif
Bram Moolenaare7705982020-04-21 22:23:15 +02003259 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260 saved_char_attr = char_attr;
3261 else
3262#endif
3263 saved_char_attr = 0;
3264 n_extra = 0;
Bram Moolenaareed9d462021-02-15 20:38:25 +01003265 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266#ifdef FEAT_LINEBREAK
3267# ifdef FEAT_DIFF
3268 if (filler_todo <= 0)
3269# endif
3270 need_showbreak = TRUE;
3271#endif
3272#ifdef FEAT_DIFF
3273 --filler_todo;
3274 // When the filler lines are actually below the last line of the
3275 // file, don't draw the line itself, break here.
3276 if (filler_todo == 0 && wp->w_botfill)
3277 break;
3278#endif
3279 }
3280
3281 } // for every character in the line
3282
3283#ifdef FEAT_SPELL
3284 // After an empty line check first word for capital.
3285 if (*skipwhite(line) == NUL)
3286 {
3287 capcol_lnum = lnum + 1;
3288 cap_col = 0;
3289 }
3290#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01003291#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 vim_free(text_props);
3293 vim_free(text_prop_idxs);
3294#endif
3295
3296 vim_free(p_extra_free);
3297 return row;
3298}