Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1 | /* 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. |
Bram Moolenaar | e89aeed | 2022-08-22 13:00:16 +0100 | [diff] [blame] | 12 | * This is the middle level, drawscreen.c is the higher level and screen.c the |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 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 |
| 23 | advance_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 |
| 37 | margin_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; |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 42 | static int prev_width1; |
| 43 | static int prev_width2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 44 | static int prev_left_col; |
| 45 | static int prev_right_col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 46 | |
| 47 | int cur_col_off = win_col_off(wp); |
| 48 | int width1; |
| 49 | int width2; |
| 50 | |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 51 | width1 = wp->w_width - cur_col_off; |
| 52 | width2 = width1 + win_col_off2(wp); |
| 53 | |
| 54 | if (saved_w_virtcol == wp->w_virtcol && prev_wp == wp |
| 55 | && prev_width1 == width1 && prev_width2 == width2) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 56 | { |
| 57 | *right_col = prev_right_col; |
| 58 | *left_col = prev_left_col; |
| 59 | return; |
| 60 | } |
| 61 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 62 | *left_col = 0; |
| 63 | *right_col = width1; |
| 64 | |
zeertzjq | 59149f0 | 2024-09-14 10:40:29 +0200 | [diff] [blame] | 65 | if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 66 | *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2; |
| 67 | if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0) |
| 68 | *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1; |
| 69 | |
| 70 | // cache values |
| 71 | prev_left_col = *left_col; |
| 72 | prev_right_col = *right_col; |
| 73 | prev_wp = wp; |
zeertzjq | 86dc4f8 | 2024-09-14 10:37:17 +0200 | [diff] [blame] | 74 | prev_width1 = width1; |
| 75 | prev_width2 = width2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 76 | saved_w_virtcol = wp->w_virtcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 77 | } |
| 78 | #endif |
| 79 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 80 | #if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \ |
| 81 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
| 82 | // using an attribute for the whole line |
| 83 | # define LINE_ATTR |
| 84 | #endif |
| 85 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 86 | // structure with variables passed between win_line() and other functions |
| 87 | typedef struct { |
| 88 | int draw_state; // what to draw next |
| 89 | |
| 90 | linenr_T lnum; // line number to be drawn |
| 91 | |
| 92 | int startrow; // first row in the window to be drawn |
| 93 | int row; // row in the window, excl w_winrow |
| 94 | int screen_row; // row on the screen, incl w_winrow |
| 95 | |
| 96 | long vcol; // virtual column, before wrapping |
| 97 | int col; // visual column on screen, after wrapping |
| 98 | #ifdef FEAT_CONCEAL |
| 99 | int boguscols; // nonexistent columns added to "col" to force |
| 100 | // wrapping |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 101 | int vcol_off_co; // offset for concealed characters |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 102 | #endif |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 103 | int vcol_off_tp; // offset for virtual text |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 104 | #ifdef FEAT_SYN_HL |
| 105 | int draw_color_col; // highlight colorcolumn |
| 106 | int *color_cols; // pointer to according columns array |
| 107 | #endif |
| 108 | int eol_hl_off; // 1 if highlighted char after EOL |
| 109 | |
| 110 | unsigned off; // offset in ScreenLines/ScreenAttrs |
| 111 | |
| 112 | int win_attr; // background for the whole window, except |
| 113 | // margins and "~" lines. |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 114 | int wcr_attr; // attributes from 'wincolor' |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 115 | #ifdef FEAT_SYN_HL |
| 116 | int cul_attr; // set when 'cursorline' active |
| 117 | #endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 118 | #ifdef LINE_ATTR |
| 119 | int line_attr; // for the whole line, includes 'cursorline' |
| 120 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 121 | |
| 122 | int screen_line_flags; // flags for screen_line() |
| 123 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 124 | int fromcol; // start of inverting |
| 125 | int tocol; // end of inverting |
| 126 | |
| 127 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 128 | long vcol_sbr; // virtual column after showbreak |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 129 | int need_showbreak; // overlong line, skipping first x chars |
| 130 | int dont_use_showbreak; // do not use 'showbreak' |
| 131 | #endif |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 132 | #ifdef FEAT_PROP_POPUP |
| 133 | int text_prop_above_count; |
| 134 | #endif |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 135 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 136 | // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line |
| 137 | int cul_screenline; |
| 138 | |
| 139 | int char_attr; // attributes for the next character |
| 140 | |
| 141 | int n_extra; // number of extra bytes |
| 142 | char_u *p_extra; // string of extra chars, plus NUL, only used |
| 143 | // when c_extra and c_final are NUL |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 144 | char_u *p_extra_free; // p_extra buffer that needs to be freed |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 145 | int extra_attr; // attributes for p_extra, should be combined |
| 146 | // with win_attr if needed |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 147 | int n_attr_skip; // chars to skip before using extra_attr |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 148 | int c_extra; // extra chars, all the same |
| 149 | int c_final; // final char, mandatory if set |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 150 | int extra_for_textprop; // n_extra set for textprop |
| 151 | int start_extra_for_textprop; // extra_for_textprop was just set |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 152 | |
| 153 | // saved "extra" items for when draw_state becomes WL_LINE (again) |
| 154 | int saved_n_extra; |
| 155 | char_u *saved_p_extra; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 156 | char_u *saved_p_extra_free; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 157 | int saved_extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 158 | int saved_n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 159 | int saved_extra_for_textprop; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 160 | int saved_c_extra; |
| 161 | int saved_c_final; |
| 162 | int saved_char_attr; |
| 163 | |
Bram Moolenaar | 2b1ddf1 | 2022-09-21 11:21:57 +0100 | [diff] [blame] | 164 | char_u extra[NUMBUFLEN + MB_MAXBYTES]; |
| 165 | // "%ld " and 'fdc' must fit in here, as well |
| 166 | // any text sign |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 167 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 168 | #ifdef FEAT_DIFF |
| 169 | hlf_T diff_hlf; // type of diff highlighting |
| 170 | #endif |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 171 | int filler_lines; // nr of filler lines to be drawn |
| 172 | int filler_todo; // nr of filler lines still to do + 1 |
| 173 | #ifdef FEAT_SIGNS |
| 174 | sign_attrs_T sattr; |
| 175 | #endif |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 176 | #ifdef FEAT_LINEBREAK |
| 177 | // do consider wrapping in linebreak mode only after encountering |
| 178 | // a non whitespace char |
| 179 | int need_lbr; |
| 180 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 181 | } winlinevars_T; |
| 182 | |
| 183 | // draw_state values for items that are drawn in sequence: |
| 184 | #define WL_START 0 // nothing done yet, must be zero |
Martin Tournoij | 7904fa4 | 2022-10-04 16:28:45 +0100 | [diff] [blame] | 185 | #define WL_CMDLINE (WL_START + 1) // cmdline window column |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 186 | #ifdef FEAT_FOLDING |
| 187 | # define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn' |
| 188 | #else |
| 189 | # define WL_FOLD WL_CMDLINE |
| 190 | #endif |
| 191 | #ifdef FEAT_SIGNS |
| 192 | # define WL_SIGN (WL_FOLD + 1) // column for signs |
| 193 | #else |
| 194 | # define WL_SIGN WL_FOLD // column for signs |
| 195 | #endif |
| 196 | #define WL_NR (WL_SIGN + 1) // line number |
| 197 | #ifdef FEAT_LINEBREAK |
| 198 | # define WL_BRI (WL_NR + 1) // 'breakindent' |
| 199 | #else |
| 200 | # define WL_BRI WL_NR |
| 201 | #endif |
| 202 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 203 | # define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff' |
| 204 | #else |
| 205 | # define WL_SBR WL_BRI |
| 206 | #endif |
| 207 | #define WL_LINE (WL_SBR + 1) // text in the line |
| 208 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 209 | #if defined(FEAT_SIGNS) || defined(FEAT_FOLDING) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 210 | /* |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 211 | * Return TRUE if CursorLineSign highlight is to be used. |
| 212 | */ |
| 213 | static int |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 214 | use_cursor_line_highlight(win_T *wp, linenr_T lnum) |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 215 | { |
| 216 | return wp->w_p_cul |
| 217 | && lnum == wp->w_cursor.lnum |
| 218 | && (wp->w_p_culopt_flags & CULOPT_NBR); |
| 219 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 220 | #endif |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 221 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 222 | |
| 223 | #ifdef FEAT_FOLDING |
| 224 | /* |
| 225 | * Setup for drawing the 'foldcolumn', if there is one. |
| 226 | */ |
| 227 | static void |
| 228 | handle_foldcolumn(win_T *wp, winlinevars_T *wlv) |
| 229 | { |
| 230 | int fdc = compute_foldcolumn(wp, 0); |
| 231 | |
| 232 | if (fdc <= 0) |
| 233 | return; |
| 234 | |
| 235 | // Allocate a buffer, "wlv->extra[]" may already be in use. |
| 236 | vim_free(wlv->p_extra_free); |
| 237 | wlv->p_extra_free = alloc(MAX_MCO * fdc + 1); |
Yegappan Lakshmanan | 465de3a | 2022-12-26 12:50:04 +0000 | [diff] [blame] | 238 | if (wlv->p_extra_free == NULL) |
| 239 | return; |
| 240 | |
| 241 | wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free, |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 242 | wp, FALSE, wlv->lnum); |
Yegappan Lakshmanan | 465de3a | 2022-12-26 12:50:04 +0000 | [diff] [blame] | 243 | wlv->p_extra_free[wlv->n_extra] = NUL; |
| 244 | wlv->p_extra = wlv->p_extra_free; |
| 245 | wlv->c_extra = NUL; |
| 246 | wlv->c_final = NUL; |
| 247 | if (use_cursor_line_highlight(wp, wlv->lnum)) |
| 248 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF)); |
| 249 | else |
| 250 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC)); |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 251 | } |
| 252 | #endif |
| 253 | |
| 254 | #ifdef FEAT_SIGNS |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 255 | /* |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 256 | * Get information needed to display the sign in line "wlv->lnum" in window |
| 257 | * "wp". |
| 258 | * If "nrcol" is TRUE, the sign is going to be displayed in the number column. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 259 | * Otherwise the sign is going to be displayed in the sign column. |
| 260 | */ |
| 261 | static void |
| 262 | get_sign_display_info( |
| 263 | int nrcol, |
| 264 | win_T *wp, |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 265 | winlinevars_T *wlv) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 266 | { |
| 267 | int text_sign; |
| 268 | # ifdef FEAT_SIGN_ICONS |
| 269 | int icon_sign; |
| 270 | # endif |
| 271 | |
| 272 | // Draw two cells with the sign value or blank. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 273 | wlv->c_extra = ' '; |
| 274 | wlv->c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 275 | if (nrcol) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 276 | wlv->n_extra = number_width(wp) + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 277 | else |
| 278 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 279 | if (use_cursor_line_highlight(wp, wlv->lnum)) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 280 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS)); |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 281 | else |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 282 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 283 | wlv->n_extra = 2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 284 | } |
| 285 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 286 | if (wlv->row == wlv->startrow |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 287 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 288 | + wlv->filler_lines && wlv->filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 289 | #endif |
| 290 | ) |
| 291 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 292 | text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 293 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 294 | icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 295 | if (gui.in_use && icon_sign != 0) |
| 296 | { |
| 297 | // Use the image in this position. |
| 298 | if (nrcol) |
| 299 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 300 | wlv->c_extra = NUL; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 301 | wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), |
| 302 | "%-*c ", number_width(wp), SIGN_BYTE); |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 303 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 304 | } |
| 305 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 306 | wlv->c_extra = SIGN_BYTE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 307 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 308 | if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum) |
| 309 | > 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 310 | { |
| 311 | if (nrcol) |
| 312 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 313 | wlv->c_extra = NUL; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 314 | wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), |
| 315 | "%-*c ", number_width(wp), MULTISIGN_BYTE); |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 316 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 317 | } |
| 318 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 319 | wlv->c_extra = MULTISIGN_BYTE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 320 | } |
| 321 | # endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 322 | wlv->c_final = NUL; |
| 323 | wlv->char_attr = icon_sign; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 324 | } |
| 325 | else |
| 326 | # endif |
| 327 | if (text_sign != 0) |
| 328 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 329 | wlv->p_extra = wlv->sattr.sat_text; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 330 | if (wlv->p_extra != NULL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 331 | { |
| 332 | if (nrcol) |
| 333 | { |
Bram Moolenaar | 2b1ddf1 | 2022-09-21 11:21:57 +0100 | [diff] [blame] | 334 | int width = number_width(wp) - 2; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 335 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 336 | vim_memset(wlv->extra, ' ', width); |
| 337 | wlv->n_extra = width; |
| 338 | wlv->n_extra += vim_snprintf((char *)wlv->extra + width, |
| 339 | sizeof(wlv->extra) - width, "%s ", wlv->p_extra); |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 340 | wlv->p_extra = wlv->extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 341 | } |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 342 | else |
| 343 | wlv->n_extra = (int)STRLEN(wlv->p_extra); |
| 344 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 345 | wlv->c_extra = NUL; |
| 346 | wlv->c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 347 | } |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 348 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 349 | if (use_cursor_line_highlight(wp, wlv->lnum) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 350 | && wlv->sattr.sat_culhl > 0) |
| 351 | wlv->char_attr = wlv->sattr.sat_culhl; |
Bram Moolenaar | e413ea0 | 2021-11-24 16:20:13 +0000 | [diff] [blame] | 352 | else |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 353 | wlv->char_attr = wlv->sattr.sat_texthl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | } |
| 357 | #endif |
| 358 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 359 | /* |
| 360 | * Display the absolute or relative line number. After the first row fill with |
| 361 | * blanks when the 'n' flag isn't in 'cpo'. |
| 362 | */ |
| 363 | static void |
| 364 | handle_lnum_col( |
| 365 | win_T *wp, |
| 366 | winlinevars_T *wlv, |
| 367 | int sign_present UNUSED, |
Bram Moolenaar | 3172423 | 2022-09-20 20:25:36 +0100 | [diff] [blame] | 368 | int num_attr UNUSED) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 369 | { |
Bram Moolenaar | 35b251d | 2022-10-06 20:18:16 +0100 | [diff] [blame] | 370 | int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL; |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 371 | int lnum_row = wlv->startrow + wlv->filler_lines |
| 372 | #ifdef FEAT_PROP_POPUP |
| 373 | + wlv->text_prop_above_count |
| 374 | #endif |
| 375 | ; |
Bram Moolenaar | 35b251d | 2022-10-06 20:18:16 +0100 | [diff] [blame] | 376 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 377 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 378 | && (wlv->row <= lnum_row || !has_cpo_n) |
Bram Moolenaar | 3725116 | 2022-10-06 20:48:00 +0100 | [diff] [blame] | 379 | // there is no line number in a wrapped line when "n" is in |
| 380 | // 'cpoptions', but 'breakindent' assumes it anyway. |
| 381 | && !((has_cpo_n |
| 382 | #ifdef FEAT_LINEBREAK |
| 383 | && !wp->w_p_bri |
| 384 | #endif |
| 385 | ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline)) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 386 | { |
| 387 | #ifdef FEAT_SIGNS |
| 388 | // If 'signcolumn' is set to 'number' and a sign is present |
| 389 | // in 'lnum', then display the sign instead of the line |
| 390 | // number. |
glepnir | 1b18683 | 2025-05-10 14:59:08 +0200 | [diff] [blame] | 391 | if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present |
| 392 | && wlv->sattr.sat_text != NULL) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 393 | get_sign_display_info(TRUE, wp, wlv); |
| 394 | else |
| 395 | #endif |
| 396 | { |
| 397 | // Draw the line number (empty space after wrapping). |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 398 | // When there are text properties above the line put the line number |
| 399 | // below them. |
Bram Moolenaar | b99e6e6 | 2022-10-17 18:55:03 +0100 | [diff] [blame] | 400 | if (wlv->row == lnum_row |
zeertzjq | 88bb3e0 | 2023-05-02 20:52:59 +0100 | [diff] [blame] | 401 | && (wp->w_skipcol == 0 || wlv->row > 0 |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 402 | || (wp->w_p_nu && wp->w_p_rnu))) |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 403 | { |
| 404 | long num; |
| 405 | char *fmt = "%*ld "; |
| 406 | |
| 407 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 408 | // 'number' + 'norelativenumber' |
| 409 | num = (long)wlv->lnum; |
| 410 | else |
| 411 | { |
| 412 | // 'relativenumber', don't use negative numbers |
| 413 | num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum)); |
| 414 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
| 415 | { |
| 416 | // 'number' + 'relativenumber' |
| 417 | num = wlv->lnum; |
| 418 | fmt = "%-*ld "; |
| 419 | } |
| 420 | } |
| 421 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 422 | vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num); |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 423 | if (wp->w_skipcol > 0 && wlv->startrow == 0) |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 424 | for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' '; |
| 425 | ++wlv->p_extra) |
| 426 | *wlv->p_extra = '-'; |
| 427 | #ifdef FEAT_RIGHTLEFT |
| 428 | if (wp->w_p_rl) // reverse line numbers |
| 429 | { |
| 430 | char_u *p1, *p2; |
| 431 | int t; |
| 432 | |
| 433 | // like rl_mirror(), but keep the space at the end |
| 434 | p2 = skipwhite(wlv->extra); |
| 435 | p2 = skiptowhite(p2) - 1; |
| 436 | for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2) |
| 437 | { |
| 438 | t = *p1; |
| 439 | *p1 = *p2; |
| 440 | *p2 = t; |
| 441 | } |
| 442 | } |
| 443 | #endif |
| 444 | wlv->p_extra = wlv->extra; |
| 445 | wlv->c_extra = NUL; |
| 446 | wlv->c_final = NUL; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 447 | } |
| 448 | else |
| 449 | { |
Bram Moolenaar | ec5e148 | 2022-09-21 16:38:13 +0100 | [diff] [blame] | 450 | wlv->c_extra = ' '; |
| 451 | wlv->c_final = NUL; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 452 | } |
| 453 | wlv->n_extra = number_width(wp) + 1; |
| 454 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N)); |
| 455 | #ifdef FEAT_SYN_HL |
| 456 | // When 'cursorline' is set highlight the line number of |
| 457 | // the current line differently. |
| 458 | // When 'cursorlineopt' does not have "line" only |
| 459 | // highlight the line number itself. |
| 460 | // TODO: Can we use CursorLine instead of CursorLineNr |
| 461 | // when CursorLineNr isn't set? |
| 462 | if (wp->w_p_cul |
| 463 | && wlv->lnum == wp->w_cursor.lnum |
| 464 | && (wp->w_p_culopt_flags & CULOPT_NBR) |
zeertzjq | 62f1954 | 2025-03-08 16:27:37 +0100 | [diff] [blame] | 465 | && (wlv->row == lnum_row |
| 466 | || (wlv->row > lnum_row |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 467 | && (wp->w_p_culopt_flags & CULOPT_LINE)))) |
| 468 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN)); |
| 469 | #endif |
| 470 | if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum |
| 471 | && HL_ATTR(HLF_LNA) != 0) |
| 472 | // Use LineNrAbove |
| 473 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA)); |
| 474 | if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum |
| 475 | && HL_ATTR(HLF_LNB) != 0) |
| 476 | // Use LineNrBelow |
| 477 | wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB)); |
| 478 | } |
| 479 | #ifdef FEAT_SIGNS |
| 480 | if (num_attr) |
| 481 | wlv->char_attr = num_attr; |
| 482 | #endif |
| 483 | } |
| 484 | } |
Bram Moolenaar | 2d2e25b | 2022-09-20 21:09:42 +0100 | [diff] [blame] | 485 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 486 | #ifdef FEAT_LINEBREAK |
| 487 | static void |
| 488 | handle_breakindent(win_T *wp, winlinevars_T *wlv) |
| 489 | { |
| 490 | if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1 |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 491 | && *get_showbreak_value(wp) != NUL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 492 | // draw indent after showbreak value |
| 493 | wlv->draw_state = WL_BRI; |
| 494 | else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR) |
| 495 | // After the showbreak, draw the breakindent |
| 496 | wlv->draw_state = WL_BRI - 1; |
| 497 | |
| 498 | // draw 'breakindent': indent wrapped text accordingly |
| 499 | if (wlv->draw_state == WL_BRI - 1) |
| 500 | { |
| 501 | wlv->draw_state = WL_BRI; |
| 502 | // if wlv->need_showbreak is set, breakindent also applies |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 503 | if (wp->w_p_bri && (wlv->row > wlv->startrow |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 504 | # ifdef FEAT_DIFF |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 505 | + wlv->filler_lines |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 506 | # endif |
zeertzjq | 588f20d | 2023-12-05 15:47:09 +0100 | [diff] [blame] | 507 | || wlv->need_showbreak) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 508 | # ifdef FEAT_PROP_POPUP |
| 509 | && !wlv->dont_use_showbreak |
| 510 | # endif |
| 511 | ) |
| 512 | { |
| 513 | wlv->char_attr = 0; |
| 514 | # ifdef FEAT_DIFF |
| 515 | if (wlv->diff_hlf != (hlf_T)0) |
| 516 | wlv->char_attr = HL_ATTR(wlv->diff_hlf); |
| 517 | # endif |
| 518 | wlv->p_extra = NULL; |
| 519 | wlv->c_extra = ' '; |
| 520 | wlv->c_final = NUL; |
| 521 | wlv->n_extra = get_breakindent_win(wp, |
| 522 | ml_get_buf(wp->w_buffer, wlv->lnum, FALSE)); |
| 523 | if (wlv->row == wlv->startrow) |
| 524 | { |
| 525 | wlv->n_extra -= win_col_off2(wp); |
| 526 | if (wlv->n_extra < 0) |
| 527 | wlv->n_extra = 0; |
| 528 | } |
zeertzjq | 2362772 | 2023-12-27 19:08:53 +0100 | [diff] [blame] | 529 | |
| 530 | // Correct start of highlighted area for 'breakindent', |
| 531 | if (wlv->fromcol >= wlv->vcol |
| 532 | && wlv->fromcol < wlv->vcol + wlv->n_extra) |
| 533 | wlv->fromcol = wlv->vcol + wlv->n_extra; |
| 534 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 535 | // Correct end of highlighted area for 'breakindent', |
| 536 | // required when 'linebreak' is also set. |
| 537 | if (wlv->tocol == wlv->vcol) |
| 538 | wlv->tocol += wlv->n_extra; |
| 539 | } |
zeertzjq | 7e4f62a | 2023-12-28 23:19:52 +0100 | [diff] [blame] | 540 | |
| 541 | if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap |
| 542 | && wp->w_briopt_sbr) |
| 543 | wlv->need_showbreak = FALSE; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 544 | } |
| 545 | } |
| 546 | #endif |
| 547 | |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 548 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 549 | static void |
| 550 | handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv) |
| 551 | { |
| 552 | # ifdef FEAT_DIFF |
| 553 | if (wlv->filler_todo > 0) |
| 554 | { |
| 555 | // Draw "deleted" diff line(s). |
| 556 | if (char2cells(wp->w_fill_chars.diff) > 1) |
| 557 | { |
| 558 | wlv->c_extra = '-'; |
| 559 | wlv->c_final = NUL; |
| 560 | } |
| 561 | else |
| 562 | { |
| 563 | wlv->c_extra = wp->w_fill_chars.diff; |
| 564 | wlv->c_final = NUL; |
| 565 | } |
| 566 | # ifdef FEAT_RIGHTLEFT |
| 567 | if (wp->w_p_rl) |
| 568 | wlv->n_extra = wlv->col + 1; |
| 569 | else |
| 570 | # endif |
| 571 | wlv->n_extra = wp->w_width - wlv->col; |
| 572 | wlv->char_attr = HL_ATTR(HLF_DED); |
| 573 | } |
| 574 | # endif |
| 575 | |
| 576 | # ifdef FEAT_LINEBREAK |
| 577 | char_u *sbr = get_showbreak_value(wp); |
| 578 | if (*sbr != NUL && wlv->need_showbreak) |
| 579 | { |
| 580 | // Draw 'showbreak' at the start of each broken line. |
| 581 | wlv->p_extra = sbr; |
| 582 | wlv->c_extra = NUL; |
| 583 | wlv->c_final = NUL; |
| 584 | wlv->n_extra = (int)STRLEN(sbr); |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 585 | wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr); |
Bram Moolenaar | f578ca2 | 2023-06-10 19:40:30 +0100 | [diff] [blame] | 586 | |
| 587 | // Correct start of highlighted area for 'showbreak'. |
| 588 | if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr) |
| 589 | wlv->fromcol = wlv->vcol_sbr; |
| 590 | |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 591 | // Correct end of highlighted area for 'showbreak', |
| 592 | // required when 'linebreak' is also set. |
| 593 | if (wlv->tocol == wlv->vcol) |
zeertzjq | df23d7f | 2024-02-09 18:14:12 +0100 | [diff] [blame] | 594 | wlv->tocol = wlv->vcol_sbr; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 595 | // combine 'showbreak' with 'wincolor' |
| 596 | wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT)); |
| 597 | # ifdef FEAT_SYN_HL |
| 598 | // combine 'showbreak' with 'cursorline' |
| 599 | if (wlv->cul_attr != 0) |
| 600 | wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr); |
| 601 | # endif |
| 602 | } |
zeertzjq | 7e4f62a | 2023-12-28 23:19:52 +0100 | [diff] [blame] | 603 | |
| 604 | if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap |
| 605 | || !wp->w_briopt_sbr) |
| 606 | wlv->need_showbreak = FALSE; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 607 | # endif |
| 608 | } |
| 609 | #endif |
| 610 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 611 | #if defined(FEAT_PROP_POPUP) || defined(PROTO) |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 612 | /* |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 613 | * Return the cell size of virtual text after truncation. |
| 614 | */ |
| 615 | static int |
| 616 | textprop_size_after_trunc( |
| 617 | win_T *wp, |
| 618 | int flags, // TP_FLAG_ALIGN_* |
| 619 | int added, |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 620 | int padding, |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 621 | char_u *text, |
| 622 | int *n_used_ptr) |
| 623 | { |
| 624 | int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 625 | ? wp->w_width - win_col_off(wp) : added; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 626 | int strsize = 0; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 627 | char_u *p; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 628 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 629 | // if the remaining size is too small and 'wrap' is set we wrap anyway and |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 630 | // use the next line |
| 631 | if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 632 | space += wp->w_width; |
Bram Moolenaar | 9466fb8 | 2022-10-11 14:54:42 +0100 | [diff] [blame] | 633 | if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE)) |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 634 | space -= padding; |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 635 | |
| 636 | for (p = text; *p != NUL; p += (*mb_ptr2len)(p)) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 637 | { |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 638 | int clen = ptr2cells(p); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 639 | |
| 640 | if (strsize + clen > space) |
| 641 | break; |
| 642 | strsize += clen; |
| 643 | } |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 644 | *n_used_ptr = (int)(p - text); |
| 645 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 646 | return strsize; |
| 647 | } |
| 648 | |
| 649 | /* |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 650 | * Take care of padding, right-align and truncation of virtual text after a |
| 651 | * line. |
| 652 | * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any |
| 653 | * padding, right-align and truncation. Otherwise only the size is computed. |
| 654 | * When "n_attr" is NULL returns the number of screen cells used. |
| 655 | * Otherwise returns TRUE when drawing continues on the next line. |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 656 | */ |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 657 | int |
| 658 | text_prop_position( |
| 659 | win_T *wp, |
| 660 | textprop_T *tp, |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 661 | int vcol, // current text column |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 662 | int scr_col, // current screen column |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 663 | int *n_extra, // nr of bytes for virtual text |
| 664 | char_u **p_extra, // virtual text |
| 665 | int *n_attr, // attribute cells, NULL if not used |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 666 | int *n_attr_skip, // cells to skip attr, NULL if not used |
| 667 | int do_skip) // skip_cells is not zero |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 668 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 669 | int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 670 | int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 671 | int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW); |
Bram Moolenaar | 1aeb3eb | 2023-01-01 14:04:51 +0000 | [diff] [blame] | 672 | int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 673 | int padding = tp->tp_col == MAXCOL && tp->tp_len > 1 |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 674 | ? tp->tp_len - 1 : 0; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 675 | int col_with_padding = scr_col + (below ? 0 : padding); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 676 | int room = wp->w_width - col_with_padding; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 677 | int before = room; // spaces before the text |
| 678 | int after = 0; // spaces after the text |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 679 | int n_used = *n_extra; |
| 680 | char_u *l = NULL; |
| 681 | int strsize = vim_strsize(*p_extra); |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 682 | int cells = wrap ? strsize : textprop_size_after_trunc(wp, |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 683 | tp->tp_flags, before, padding, *p_extra, &n_used); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 684 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 685 | if (wrap || right || above || below || padding > 0 || n_used < *n_extra) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 686 | { |
Bram Moolenaar | ccf2837 | 2022-10-10 21:10:03 +0100 | [diff] [blame] | 687 | int col_off = win_col_off(wp) - win_col_off2(wp); |
Bram Moolenaar | b84d565 | 2022-09-20 17:57:53 +0100 | [diff] [blame] | 688 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 689 | if (above) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 690 | { |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 691 | before = 0; |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 692 | after = wp->w_width - cells - win_col_off(wp) - padding; |
Bram Moolenaar | 2354b66 | 2023-04-23 21:42:25 +0100 | [diff] [blame] | 693 | if (after < 0) |
| 694 | { |
| 695 | // text "above" has too much padding to fit |
| 696 | padding += after; |
| 697 | after = 0; |
| 698 | } |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 699 | } |
| 700 | else |
| 701 | { |
| 702 | // Right-align: fill with before |
| 703 | if (right) |
| 704 | before -= cells; |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 705 | |
| 706 | // Below-align: empty line add one character |
Bram Moolenaar | 7c02ad9 | 2022-11-29 21:37:13 +0000 | [diff] [blame] | 707 | if (below && vcol == 0 && col_with_padding == col_off |
| 708 | && wp->w_width - col_off == before) |
| 709 | col_with_padding += 1; |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 710 | |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 711 | if (before < 0 |
| 712 | || !(right || below) |
porygonisaduck | 38854b5 | 2022-11-27 20:55:05 +0000 | [diff] [blame] | 713 | || (below ? (col_with_padding <= col_off || !wp->w_p_wrap) |
| 714 | : (n_used < *n_extra))) |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 715 | { |
Bram Moolenaar | 7e01746 | 2022-10-11 21:02:09 +0100 | [diff] [blame] | 716 | if (right && (wrap |
| 717 | || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap))) |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 718 | { |
| 719 | // right-align on next line instead of wrapping if possible |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 720 | before = wp->w_width - col_off - strsize + room; |
| 721 | if (before < 0) |
| 722 | before = 0; |
| 723 | else |
| 724 | n_used = *n_extra; |
| 725 | } |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 726 | else if (below && before > vcol && do_skip) |
| 727 | before -= vcol; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 728 | else |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 729 | before = 0; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 730 | } |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 731 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 732 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 733 | // With 'nowrap' add one to show the "extends" character if needed (it |
| 734 | // doesn't show if the text just fits). |
| 735 | if (!wp->w_p_wrap |
| 736 | && n_used < *n_extra |
| 737 | && wp->w_lcs_chars.ext != NUL |
| 738 | && wp->w_p_list) |
| 739 | ++n_used; |
| 740 | |
| 741 | // add 1 for NUL, 2 for when '…' is used |
| 742 | if (n_attr != NULL) |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 743 | l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 744 | if (n_attr == NULL || l != NULL) |
| 745 | { |
| 746 | int off = 0; |
| 747 | |
| 748 | if (n_attr != NULL) |
| 749 | { |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 750 | vim_memset(l, ' ', before); |
| 751 | off += before; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 752 | if (padding > 0) |
| 753 | { |
| 754 | vim_memset(l + off, ' ', padding); |
| 755 | off += padding; |
| 756 | } |
| 757 | vim_strncpy(l + off, *p_extra, n_used); |
| 758 | off += n_used; |
| 759 | } |
| 760 | else |
| 761 | { |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 762 | off = before + after + padding + n_used; |
| 763 | cells += before + after + padding; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 764 | } |
| 765 | if (n_attr != NULL) |
| 766 | { |
| 767 | if (n_used < *n_extra && wp->w_p_wrap) |
| 768 | { |
| 769 | char_u *lp = l + off - 1; |
| 770 | |
| 771 | if (has_mbyte) |
| 772 | { |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 773 | char_u buf[MB_MAXBYTES + 1]; |
| 774 | char_u *cp = buf; |
| 775 | |
| 776 | // change the last character to '…', converted to the |
| 777 | // current 'encoding' |
| 778 | STRCPY(buf, "…"); |
| 779 | if (!enc_utf8) |
| 780 | { |
| 781 | vimconv_T vc; |
| 782 | |
| 783 | vc.vc_type = CONV_NONE; |
| 784 | convert_setup(&vc, (char_u *)"utf-8", p_enc); |
| 785 | if (vc.vc_type != CONV_NONE) |
| 786 | { |
| 787 | cp = string_convert(&vc, buf, NULL); |
| 788 | if (cp == NULL) |
| 789 | { |
| 790 | // when conversion fails use '>' |
| 791 | cp = buf; |
| 792 | STRCPY(buf, ">"); |
| 793 | } |
| 794 | convert_setup(&vc, NULL, NULL); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | lp -= (*mb_ptr2cells)(cp) - 1; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 799 | lp -= (*mb_head_off)(l, lp); |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 800 | STRCPY(lp, cp); |
Bram Moolenaar | 13845c4 | 2022-10-09 15:26:03 +0100 | [diff] [blame] | 801 | n_used = lp - l + 3 - before - padding; |
h-east | 4c42c7e | 2023-04-17 21:44:57 +0100 | [diff] [blame] | 802 | if (cp != buf) |
| 803 | vim_free(cp); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 804 | } |
| 805 | else |
| 806 | // change last character to '>' |
| 807 | *lp = '>'; |
| 808 | } |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 809 | else if (after > 0) |
| 810 | { |
| 811 | vim_memset(l + off, ' ', after); |
| 812 | l[off + after] = NUL; |
| 813 | } |
| 814 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 815 | *p_extra = l; |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 816 | *n_extra = n_used + before + after + padding; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 817 | *n_attr = mb_charlen(*p_extra); |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 818 | // n_attr_skip will not be decremented before draw_state is |
| 819 | // WL_LINE |
Christian Brabandt | f1cc4d5 | 2023-08-12 00:14:14 +0200 | [diff] [blame] | 820 | *n_attr_skip = before + (padding > 0 ? padding : 0); |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 821 | *n_attr -= *n_attr_skip; |
| 822 | if (above) |
| 823 | *n_attr -= after; |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 824 | } |
| 825 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 826 | } |
Bram Moolenaar | 952c9b0 | 2022-08-10 16:00:33 +0100 | [diff] [blame] | 827 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 828 | if (n_attr == NULL) |
| 829 | return cells; |
| 830 | return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 831 | } |
| 832 | #endif |
| 833 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 834 | /* |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 835 | * Call screen_line() using values from "wlv". |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 836 | * Also takes care of putting "<<<" on the first line for 'smoothscroll' |
| 837 | * when 'showbreak' is not set. |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 838 | * When "clear_end" is TRUE clear until the end of the screen line. |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 839 | */ |
| 840 | static void |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 841 | wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end) |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 842 | { |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 843 | if (wlv->row == 0 && wp->w_skipcol > 0 |
| 844 | #if defined(FEAT_LINEBREAK) |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 845 | // do not overwrite the 'showbreak' text with "<<<" |
Bram Moolenaar | 0937b9f | 2022-10-06 21:24:34 +0100 | [diff] [blame] | 846 | && *get_showbreak_value(wp) == NUL |
| 847 | #endif |
Bram Moolenaar | 13cdde3 | 2022-10-15 14:07:48 +0100 | [diff] [blame] | 848 | // do not overwrite the 'listchars' "precedes" text with "<<<" |
| 849 | && !(wp->w_p_list && wp->w_lcs_chars.prec != 0)) |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 850 | { |
| 851 | int off = (int)(current_ScreenLine - ScreenLines); |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 852 | int max_off = off + screen_Columns; |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 853 | int skip = 0; |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 854 | |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 855 | if (wp->w_p_nu && wp->w_p_rnu) |
| 856 | // Do not overwrite the line number, change "123 text" to |
Bram Moolenaar | f578ca2 | 2023-06-10 19:40:30 +0100 | [diff] [blame] | 857 | // "123<<<xt". |
Bram Moolenaar | eb4de62 | 2022-10-15 13:42:17 +0100 | [diff] [blame] | 858 | while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off])) |
| 859 | { |
| 860 | ++off; |
| 861 | ++skip; |
| 862 | } |
| 863 | |
| 864 | for (int i = 0; i < 3 && i + skip < wp->w_width; ++i) |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 865 | { |
zeertzjq | ecb87dd | 2023-06-03 19:45:06 +0100 | [diff] [blame] | 866 | if ((*mb_off2cells)(off, max_off) > 1) |
| 867 | // When the first half of a double-width character is |
| 868 | // overwritten, change the second half to a space. |
| 869 | ScreenLines[off + 1] = ' '; |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 870 | ScreenLines[off] = '<'; |
| 871 | if (enc_utf8) |
| 872 | ScreenLinesUC[off] = 0; |
| 873 | ScreenAttrs[off] = HL_ATTR(HLF_AT); |
| 874 | ++off; |
| 875 | } |
| 876 | } |
| 877 | |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 878 | screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col, |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 879 | clear_end ? wp->w_width : -wp->w_width, |
| 880 | wlv->vcol - 1, wlv->screen_line_flags); |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | /* |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 884 | * Called when finished with the line: draw the screen line and handle any |
| 885 | * highlighting until the right of the window. |
| 886 | */ |
| 887 | static void |
| 888 | draw_screen_line(win_T *wp, winlinevars_T *wlv) |
| 889 | { |
| 890 | #ifdef FEAT_SYN_HL |
| 891 | long v; |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 892 | int wcol; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 893 | |
| 894 | // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. |
| 895 | if (wp->w_p_wrap) |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 896 | v = wlv->startrow == 0 ? wp->w_skipcol : 0; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 897 | else |
| 898 | v = wp->w_leftcol; |
| 899 | |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 900 | wcol = |
| 901 | # ifdef FEAT_RIGHTLEFT |
| 902 | wp->w_p_rl ? wp->w_width - wlv->col - 1 : |
| 903 | # endif |
| 904 | wlv->col; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 905 | // check if line ends before left margin |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 906 | if (wlv->vcol < v + wcol - win_col_off(wp)) |
| 907 | wlv->vcol = v + wcol - win_col_off(wp); |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 908 | # ifdef FEAT_CONCEAL |
| 909 | // Get rid of the boguscols now, we want to draw until the right |
| 910 | // edge for 'cursorcolumn'. |
| 911 | wlv->col -= wlv->boguscols; |
| 912 | wlv->boguscols = 0; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 913 | # define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 914 | # else |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 915 | # define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 916 | # endif |
| 917 | |
| 918 | if (wlv->draw_color_col) |
| 919 | wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols); |
| 920 | |
| 921 | if (((wp->w_p_cuc |
| 922 | && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off |
| 923 | && (int)wp->w_virtcol < |
| 924 | (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v |
| 925 | && wlv->lnum != wp->w_cursor.lnum) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 926 | || wlv->draw_color_col |
| 927 | # ifdef LINE_ATTR |
| 928 | || wlv->line_attr != 0 |
| 929 | # endif |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 930 | || wlv->win_attr != 0)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 931 | { |
| 932 | int rightmost_vcol = 0; |
| 933 | int i; |
| 934 | |
| 935 | if (wp->w_p_cuc) |
| 936 | rightmost_vcol = wp->w_virtcol; |
| 937 | if (wlv->draw_color_col) |
| 938 | // determine rightmost colorcolumn to possibly draw |
| 939 | for (i = 0; wlv->color_cols[i] >= 0; ++i) |
| 940 | if (rightmost_vcol < wlv->color_cols[i]) |
| 941 | rightmost_vcol = wlv->color_cols[i]; |
| 942 | |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 943 | while ( |
| 944 | # ifdef FEAT_RIGHTLEFT |
| 945 | wp->w_p_rl ? (wlv->col >= 0) : |
| 946 | # endif |
| 947 | (wlv->col < wp->w_width)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 948 | { |
| 949 | ScreenLines[wlv->off] = ' '; |
| 950 | if (enc_utf8) |
| 951 | ScreenLinesUC[wlv->off] = 0; |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 952 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 953 | if (wlv->draw_color_col) |
| 954 | wlv->draw_color_col = advance_color_col( |
| 955 | VCOL_HLC, &wlv->color_cols); |
| 956 | |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 957 | int attr = wlv->win_attr; |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 958 | # ifdef LINE_ATTR |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 959 | if (wlv->line_attr != 0) |
| 960 | attr = hl_combine_attr(attr, wlv->line_attr); |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 961 | # endif |
zeertzjq | 9352c28 | 2024-03-14 18:16:56 +0100 | [diff] [blame] | 962 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
| 963 | && wlv->lnum != wp->w_cursor.lnum) |
| 964 | attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC)); |
| 965 | else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols) |
| 966 | attr = hl_combine_attr(attr, HL_ATTR(HLF_MC)); |
zeertzjq | f627255 | 2024-03-17 10:01:47 +0100 | [diff] [blame] | 967 | ScreenAttrs[wlv->off] = attr; |
| 968 | ScreenCols[wlv->off] = wlv->vcol; |
| 969 | # ifdef FEAT_RIGHTLEFT |
| 970 | if (wp->w_p_rl) |
| 971 | { |
| 972 | --wlv->off; |
| 973 | --wlv->col; |
| 974 | } |
| 975 | else |
| 976 | # endif |
| 977 | { |
| 978 | ++wlv->off; |
| 979 | ++wlv->col; |
| 980 | } |
zeertzjq | deb2204 | 2024-03-17 19:44:30 +0100 | [diff] [blame] | 981 | ++wlv->vcol; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 982 | |
zeertzjq | deb2204 | 2024-03-17 19:44:30 +0100 | [diff] [blame] | 983 | if (VCOL_HLC > rightmost_vcol |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 984 | # ifdef LINE_ATTR |
| 985 | && wlv->line_attr == 0 |
| 986 | # endif |
| 987 | && wlv->win_attr == 0) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 988 | break; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | #endif |
| 992 | |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 993 | // Set increasing virtual columns in ScreenCols[] to set correct curswant |
| 994 | // (or "coladd" for 'virtualedit') when clicking after end of line. |
| 995 | wlv->screen_line_flags |= SLF_INC_VCOL; |
| 996 | wlv_screen_line(wp, wlv, TRUE); |
| 997 | wlv->screen_line_flags &= ~SLF_INC_VCOL; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 998 | ++wlv->row; |
| 999 | ++wlv->screen_row; |
| 1000 | } |
| 1001 | #undef VCOL_HLC |
| 1002 | |
| 1003 | /* |
| 1004 | * Start a screen line at column zero. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1005 | * When "save_extra" is TRUE save and reset n_extra, p_extra, etc. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1006 | */ |
| 1007 | static void |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1008 | win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1009 | { |
| 1010 | wlv->col = 0; |
| 1011 | wlv->off = (unsigned)(current_ScreenLine - ScreenLines); |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 1012 | #ifdef FEAT_LINEBREAK |
| 1013 | wlv->need_lbr = FALSE; |
| 1014 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1015 | |
| 1016 | #ifdef FEAT_RIGHTLEFT |
| 1017 | if (wp->w_p_rl) |
| 1018 | { |
| 1019 | // Rightleft window: process the text in the normal direction, but put |
| 1020 | // it in current_ScreenLine[] from right to left. Start at the |
| 1021 | // rightmost column of the window. |
| 1022 | wlv->col = wp->w_width - 1; |
| 1023 | wlv->off += wlv->col; |
| 1024 | wlv->screen_line_flags |= SLF_RIGHTLEFT; |
| 1025 | } |
| 1026 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1027 | if (save_extra) |
| 1028 | { |
| 1029 | // reset the drawing state for the start of a wrapped line |
| 1030 | wlv->draw_state = WL_START; |
| 1031 | wlv->saved_n_extra = wlv->n_extra; |
| 1032 | wlv->saved_p_extra = wlv->p_extra; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 1033 | vim_free(wlv->saved_p_extra_free); |
| 1034 | wlv->saved_p_extra_free = wlv->p_extra_free; |
| 1035 | wlv->p_extra_free = NULL; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1036 | wlv->saved_extra_attr = wlv->extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1037 | wlv->saved_n_attr_skip = wlv->n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1038 | wlv->saved_extra_for_textprop = wlv->extra_for_textprop; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1039 | wlv->saved_c_extra = wlv->c_extra; |
| 1040 | wlv->saved_c_final = wlv->c_final; |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 1041 | #ifdef FEAT_LINEBREAK |
| 1042 | wlv->need_lbr = TRUE; |
| 1043 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1044 | #ifdef FEAT_SYN_HL |
| 1045 | if (!(wlv->cul_screenline |
| 1046 | # ifdef FEAT_DIFF |
| 1047 | && wlv->diff_hlf == (hlf_T)0 |
| 1048 | # endif |
| 1049 | )) |
| 1050 | wlv->saved_char_attr = wlv->char_attr; |
| 1051 | else |
| 1052 | #endif |
| 1053 | wlv->saved_char_attr = 0; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1054 | |
| 1055 | // these are not used until restored in win_line_continue() |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1056 | wlv->n_extra = 0; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1057 | wlv->n_attr_skip = 0; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1058 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1059 | } |
| 1060 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1061 | /* |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1062 | * Called when wlv->draw_state is set to WL_LINE. |
| 1063 | */ |
| 1064 | static void |
| 1065 | win_line_continue(winlinevars_T *wlv) |
| 1066 | { |
| 1067 | if (wlv->saved_n_extra > 0) |
| 1068 | { |
| 1069 | // Continue item from end of wrapped line. |
| 1070 | wlv->n_extra = wlv->saved_n_extra; |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 1071 | wlv->saved_n_extra = 0; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1072 | wlv->c_extra = wlv->saved_c_extra; |
| 1073 | wlv->c_final = wlv->saved_c_final; |
| 1074 | wlv->p_extra = wlv->saved_p_extra; |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 1075 | vim_free(wlv->p_extra_free); |
| 1076 | wlv->p_extra_free = wlv->saved_p_extra_free; |
| 1077 | wlv->saved_p_extra_free = NULL; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1078 | wlv->extra_attr = wlv->saved_extra_attr; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 1079 | wlv->n_attr_skip = wlv->saved_n_attr_skip; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 1080 | wlv->extra_for_textprop = wlv->saved_extra_for_textprop; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1081 | wlv->char_attr = wlv->saved_char_attr; |
| 1082 | } |
| 1083 | else |
| 1084 | wlv->char_attr = wlv->win_attr; |
| 1085 | } |
| 1086 | |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1087 | #ifdef FEAT_SYN_HL |
| 1088 | static void |
| 1089 | apply_cursorline_highlight( |
| 1090 | winlinevars_T *wlv, |
| 1091 | int sign_present UNUSED) |
| 1092 | { |
| 1093 | wlv->cul_attr = HL_ATTR(HLF_CUL); |
| 1094 | # ifdef FEAT_SIGNS |
| 1095 | // Combine the 'cursorline' and sign highlighting, depending on |
| 1096 | // the sign priority. |
| 1097 | if (sign_present && wlv->sattr.sat_linehl > 0) |
| 1098 | { |
| 1099 | if (wlv->sattr.sat_priority >= 100) |
| 1100 | wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr); |
| 1101 | else |
| 1102 | wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr); |
| 1103 | } |
| 1104 | else |
| 1105 | # endif |
| 1106 | # if defined(FEAT_QUICKFIX) |
| 1107 | // let the line attribute overrule 'cursorline', otherwise |
| 1108 | // it disappears when both have background set; |
| 1109 | // 'cursorline' can use underline or bold to make it show |
| 1110 | wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr); |
| 1111 | # else |
| 1112 | wlv->line_attr = wlv->cul_attr; |
| 1113 | # endif |
| 1114 | } |
| 1115 | #endif |
| 1116 | |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1117 | /* |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1118 | * Display line "lnum" of window "wp" on the screen. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1119 | * Start at row "startrow", stop when "endrow" is reached. |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1120 | * When only updating the number column, "number_only" is set to the height of |
| 1121 | * the line, otherwise it is set to 0. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1122 | * "spv" is used to store information for spell checking, kept between |
| 1123 | * sequential calls for the same window. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1124 | * wp->w_virtcol needs to be valid. |
| 1125 | * |
| 1126 | * Return the number of last row the line occupies. |
| 1127 | */ |
| 1128 | int |
| 1129 | win_line( |
| 1130 | win_T *wp, |
| 1131 | linenr_T lnum, |
| 1132 | int startrow, |
| 1133 | int endrow, |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1134 | int number_only, |
| 1135 | spellvars_T *spv UNUSED) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1136 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1137 | winlinevars_T wlv; // variables passed between functions |
| 1138 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1139 | int c = 0; // init for GCC |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1140 | long vcol_prev = -1; // "wlv.vcol" of previous character |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1141 | char_u *line; // current line |
| 1142 | char_u *ptr; // current position in "line" |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1143 | int in_curline = wp == curwin && lnum == curwin->w_cursor.lnum; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1144 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1145 | #ifdef FEAT_PROP_POPUP |
| 1146 | char_u *p_extra_free2 = NULL; // another p_extra to be freed |
| 1147 | #endif |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 1148 | #if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 1149 | int in_linebreak = FALSE; // n_extra set for showing linebreak |
| 1150 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1151 | int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 1152 | int lcs_prec_todo = wp->w_lcs_chars.prec; |
| 1153 | // prec until it's been used |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1154 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1155 | int n_attr = 0; // chars with special attr |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1156 | int saved_attr2 = 0; // char_attr saved for n_attr |
| 1157 | int n_attr3 = 0; // chars with overruling special attr |
| 1158 | int saved_attr3 = 0; // char_attr saved for n_attr3 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1159 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1160 | int skip_cells = 0; // nr of cells to skip for w_leftcol or |
| 1161 | // w_skipcol or concealing |
| 1162 | int skipped_cells = 0; // nr of skipped cells for virtual text |
| 1163 | // to be added to wlv.vcol later |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1164 | int fromcol_prev = -2; // start of inverting after cursor |
| 1165 | int noinvcur = FALSE; // don't invert the cursor |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1166 | int lnum_in_visual_area = FALSE; |
| 1167 | pos_T pos; |
| 1168 | long v; |
| 1169 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1170 | int attr_pri = FALSE; // char_attr has priority |
| 1171 | int area_highlighting = FALSE; // Visual or incsearch highlighting |
| 1172 | // in this line |
| 1173 | int vi_attr = 0; // attributes for Visual and incsearch |
| 1174 | // highlighting |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1175 | int area_attr = 0; // attributes desired by highlighting |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1176 | int search_attr = 0; // attributes desired by 'hlsearch' or |
| 1177 | // ComplMatchIns |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1178 | #ifdef FEAT_SYN_HL |
| 1179 | int vcol_save_attr = 0; // saved attr for 'cursorcolumn' |
| 1180 | int syntax_attr = 0; // attributes desired by syntax |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 1181 | int prev_syntax_col = -1; // column of prev_syntax_attr |
| 1182 | int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1183 | int has_syntax = FALSE; // this buffer has syntax highl. |
| 1184 | int save_did_emsg; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1185 | #endif |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1186 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 1187 | int did_line = FALSE; // set to TRUE when line text done |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1188 | int text_prop_count; |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 1189 | int last_textprop_text_idx = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1190 | int text_prop_next = 0; // next text property to use |
| 1191 | textprop_T *text_props = NULL; |
| 1192 | int *text_prop_idxs = NULL; |
| 1193 | int text_props_active = 0; |
| 1194 | proptype_T *text_prop_type = NULL; |
| 1195 | int text_prop_attr = 0; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 1196 | int text_prop_attr_comb = 0; // text_prop_attr combined with |
| 1197 | // syntax_attr |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1198 | int text_prop_id = 0; // active property ID |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 1199 | int text_prop_flags = 0; |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 1200 | int text_prop_above = FALSE; // first doing virtual text above |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 1201 | int text_prop_follows = FALSE; // another text prop to display |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 1202 | int saved_search_attr = 0; // search_attr to be used when n_extra |
| 1203 | // goes to zero |
Bram Moolenaar | 6eda17d | 2022-09-12 19:25:11 +0100 | [diff] [blame] | 1204 | int saved_area_attr = 0; // idem for area_attr |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 1205 | int reset_extra_attr = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1206 | #endif |
| 1207 | #ifdef FEAT_SPELL |
Bram Moolenaar | ae49aa8 | 2022-02-25 21:05:36 +0000 | [diff] [blame] | 1208 | int can_spell = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1209 | # define SPWORDLEN 150 |
| 1210 | char_u nextline[SPWORDLEN * 2];// text with start of the next line |
| 1211 | int nextlinecol = 0; // column where nextline[] starts |
| 1212 | int nextline_idx = 0; // index in nextline[] where next line |
| 1213 | // starts |
| 1214 | int spell_attr = 0; // attributes desired by spelling |
| 1215 | int word_end = 0; // last byte with same spell_attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1216 | int cur_checked_col = 0; // checked column for current line |
| 1217 | #endif |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1218 | int extra_check = FALSE; // has extra highlighting |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1219 | int multi_attr = 0; // attributes desired by multibyte |
| 1220 | int mb_l = 1; // multi-byte byte length |
| 1221 | int mb_c = 0; // decoded multi-byte character |
| 1222 | int mb_utf8 = FALSE; // screen char is UTF-8 char |
| 1223 | int u8cc[MAX_MCO]; // composing UTF-8 chars |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1224 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1225 | int change_start = MAXCOL; // first col of changed area |
| 1226 | int change_end = -1; // last col of changed area |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1227 | diffline_T line_changes; |
| 1228 | int change_index = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1229 | #endif |
| 1230 | colnr_T trailcol = MAXCOL; // start of trailing spaces |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1231 | colnr_T leadcol = 0; // start of leading spaces |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 1232 | int in_multispace = FALSE; // in multiple consecutive spaces |
| 1233 | int multispace_pos = 0; // position in lcs-multispace string |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1234 | #ifdef LINE_ATTR |
Bram Moolenaar | bf91584 | 2022-08-06 22:38:02 +0100 | [diff] [blame] | 1235 | int line_attr_save = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1236 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1237 | int sign_present = FALSE; |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 1238 | int num_attr = 0; // attribute for the number column |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1239 | #ifdef FEAT_ARABIC |
| 1240 | int prev_c = 0; // previous Arabic character |
| 1241 | int prev_c1 = 0; // first composing char for prev_c |
| 1242 | #endif |
| 1243 | #if defined(LINE_ATTR) |
| 1244 | int did_line_attr = 0; |
| 1245 | #endif |
| 1246 | #ifdef FEAT_TERMINAL |
| 1247 | int get_term_attr = FALSE; |
| 1248 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1249 | |
Martin Tournoij | ba43e76 | 2022-10-13 22:12:15 +0100 | [diff] [blame] | 1250 | #if defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1251 | // margin columns for the screen line, needed for when 'cursorlineopt' |
| 1252 | // contains "screenline" |
| 1253 | int left_curline_col = 0; |
| 1254 | int right_curline_col = 0; |
| 1255 | #endif |
| 1256 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1257 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 1258 | int feedback_col = 0; |
| 1259 | int feedback_old_attr = -1; |
| 1260 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1261 | |
| 1262 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
| 1263 | int match_conc = 0; // cchar for match functions |
Martin Tournoij | ba43e76 | 2022-10-13 22:12:15 +0100 | [diff] [blame] | 1264 | #endif |
| 1265 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK) |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 1266 | int on_last_col = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1267 | #endif |
| 1268 | #ifdef FEAT_CONCEAL |
| 1269 | int syntax_flags = 0; |
| 1270 | int syntax_seqnr = 0; |
| 1271 | int prev_syntax_id = 0; |
| 1272 | int conceal_attr = HL_ATTR(HLF_CONCEAL); |
| 1273 | int is_concealing = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1274 | int did_wcol = FALSE; |
| 1275 | int old_boguscols = 0; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1276 | # define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1277 | # define FIX_FOR_BOGUSCOLS \ |
| 1278 | { \ |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1279 | wlv.n_extra += wlv.vcol_off_co; \ |
| 1280 | wlv.vcol -= wlv.vcol_off_co; \ |
| 1281 | wlv.vcol_off_co = 0; \ |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1282 | wlv.col -= wlv.boguscols; \ |
| 1283 | old_boguscols = wlv.boguscols; \ |
| 1284 | wlv.boguscols = 0; \ |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1285 | } |
| 1286 | #else |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 1287 | # define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1288 | #endif |
| 1289 | |
| 1290 | if (startrow > endrow) // past the end already! |
| 1291 | return startrow; |
| 1292 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1293 | CLEAR_FIELD(wlv); |
| 1294 | |
| 1295 | wlv.lnum = lnum; |
| 1296 | wlv.startrow = startrow; |
| 1297 | wlv.row = startrow; |
| 1298 | wlv.screen_row = wlv.row + W_WINROW(wp); |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1299 | wlv.fromcol = -10; |
| 1300 | wlv.tocol = MAXCOL; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1301 | #ifdef FEAT_LINEBREAK |
| 1302 | wlv.vcol_sbr = -1; |
| 1303 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1304 | |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1305 | if (number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1306 | { |
| 1307 | // To speed up the loop below, set extra_check when there is linebreak, |
| 1308 | // trailing white space and/or syntax processing to be done. |
| 1309 | #ifdef FEAT_LINEBREAK |
| 1310 | extra_check = wp->w_p_lbr; |
| 1311 | #endif |
| 1312 | #ifdef FEAT_SYN_HL |
| 1313 | if (syntax_present(wp) && !wp->w_s->b_syn_error |
| 1314 | # ifdef SYN_TIME_LIMIT |
| 1315 | && !wp->w_s->b_syn_slow |
| 1316 | # endif |
| 1317 | ) |
| 1318 | { |
| 1319 | // Prepare for syntax highlighting in this line. When there is an |
| 1320 | // error, stop syntax highlighting. |
| 1321 | save_did_emsg = did_emsg; |
| 1322 | did_emsg = FALSE; |
| 1323 | syntax_start(wp, lnum); |
| 1324 | if (did_emsg) |
| 1325 | wp->w_s->b_syn_error = TRUE; |
| 1326 | else |
| 1327 | { |
| 1328 | did_emsg = save_did_emsg; |
| 1329 | #ifdef SYN_TIME_LIMIT |
| 1330 | if (!wp->w_s->b_syn_slow) |
| 1331 | #endif |
| 1332 | { |
| 1333 | has_syntax = TRUE; |
| 1334 | extra_check = TRUE; |
| 1335 | } |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | // Check for columns to display for 'colorcolumn'. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1340 | wlv.color_cols = wp->w_p_cc_cols; |
| 1341 | if (wlv.color_cols != NULL) |
| 1342 | wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1343 | #endif |
| 1344 | |
| 1345 | #ifdef FEAT_TERMINAL |
| 1346 | if (term_show_buffer(wp->w_buffer)) |
| 1347 | { |
| 1348 | extra_check = TRUE; |
| 1349 | get_term_attr = TRUE; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1350 | wlv.win_attr = term_get_attr(wp, lnum, -1); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1351 | } |
| 1352 | #endif |
| 1353 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1354 | // handle Visual active in this window |
| 1355 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 1356 | { |
Bram Moolenaar | 14285cb | 2020-03-27 20:58:37 +0100 | [diff] [blame] | 1357 | pos_T *top, *bot; |
| 1358 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1359 | if (LTOREQ_POS(curwin->w_cursor, VIsual)) |
| 1360 | { |
| 1361 | // Visual is after curwin->w_cursor |
| 1362 | top = &curwin->w_cursor; |
| 1363 | bot = &VIsual; |
| 1364 | } |
| 1365 | else |
| 1366 | { |
| 1367 | // Visual is before curwin->w_cursor |
| 1368 | top = &VIsual; |
| 1369 | bot = &curwin->w_cursor; |
| 1370 | } |
| 1371 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
| 1372 | if (VIsual_mode == Ctrl_V) |
| 1373 | { |
| 1374 | // block mode |
| 1375 | if (lnum_in_visual_area) |
| 1376 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1377 | wlv.fromcol = wp->w_old_cursor_fcol; |
| 1378 | wlv.tocol = wp->w_old_cursor_lcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1379 | } |
| 1380 | } |
| 1381 | else |
| 1382 | { |
| 1383 | // non-block mode |
| 1384 | if (lnum > top->lnum && lnum <= bot->lnum) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1385 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1386 | else if (lnum == top->lnum) |
| 1387 | { |
| 1388 | if (VIsual_mode == 'V') // linewise |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1389 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1390 | else |
| 1391 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1392 | getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1393 | if (gchar_pos(top) == NUL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1394 | wlv.tocol = wlv.fromcol + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1395 | } |
| 1396 | } |
| 1397 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 1398 | { |
| 1399 | if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0) |
| 1400 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1401 | wlv.fromcol = -10; |
| 1402 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1403 | } |
| 1404 | else if (bot->col == MAXCOL) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1405 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1406 | else |
| 1407 | { |
| 1408 | pos = *bot; |
| 1409 | if (*p_sel == 'e') |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1410 | getvvcol(wp, &pos, (colnr_T *)&wlv.tocol, |
| 1411 | NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1412 | else |
| 1413 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1414 | getvvcol(wp, &pos, NULL, NULL, |
| 1415 | (colnr_T *)&wlv.tocol); |
| 1416 | ++wlv.tocol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1417 | } |
| 1418 | } |
| 1419 | } |
| 1420 | } |
| 1421 | |
| 1422 | // Check if the character under the cursor should not be inverted |
glepnir | 6a38aff | 2024-12-16 21:56:16 +0100 | [diff] [blame] | 1423 | if (!highlight_match && in_curline |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1424 | #ifdef FEAT_GUI |
| 1425 | && !gui.in_use |
| 1426 | #endif |
| 1427 | ) |
| 1428 | noinvcur = TRUE; |
| 1429 | |
| 1430 | // if inverting in this line set area_highlighting |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1431 | if (wlv.fromcol >= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1432 | { |
| 1433 | area_highlighting = TRUE; |
| 1434 | vi_attr = HL_ATTR(HLF_V); |
| 1435 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
| 1436 | if ((clip_star.available && !clip_star.owned |
| 1437 | && clip_isautosel_star()) |
| 1438 | || (clip_plus.available && !clip_plus.owned |
| 1439 | && clip_isautosel_plus())) |
| 1440 | vi_attr = HL_ATTR(HLF_VNC); |
| 1441 | #endif |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | // handle 'incsearch' and ":s///c" highlighting |
| 1446 | else if (highlight_match |
| 1447 | && wp == curwin |
| 1448 | && lnum >= curwin->w_cursor.lnum |
| 1449 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 1450 | { |
| 1451 | if (lnum == curwin->w_cursor.lnum) |
| 1452 | getvcol(curwin, &(curwin->w_cursor), |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1453 | (colnr_T *)&wlv.fromcol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1454 | else |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1455 | wlv.fromcol = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1456 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 1457 | { |
| 1458 | pos.lnum = lnum; |
| 1459 | pos.col = search_match_endcol; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1460 | getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1461 | } |
| 1462 | else |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1463 | wlv.tocol = MAXCOL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1464 | // do at least one character; happens when past end of line |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1465 | if (wlv.fromcol == wlv.tocol && search_match_endcol) |
| 1466 | wlv.tocol = wlv.fromcol + 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1467 | area_highlighting = TRUE; |
| 1468 | vi_attr = HL_ATTR(HLF_I); |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | #ifdef FEAT_DIFF |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1473 | |
| 1474 | int linestatus = 0; |
| 1475 | wlv.filler_lines = diff_check_with_linestatus(wp, lnum, &linestatus); |
| 1476 | |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1477 | CLEAR_FIELD(line_changes); |
| 1478 | |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1479 | if (wlv.filler_lines < 0 || linestatus < 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1480 | { |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1481 | if (wlv.filler_lines == -1 || linestatus == -1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1482 | { |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1483 | if (diff_find_change(wp, lnum, &line_changes)) |
| 1484 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1485 | wlv.diff_hlf = HLF_ADD; // added line |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1486 | } |
| 1487 | else if (line_changes.num_changes > 0) |
| 1488 | { |
| 1489 | int added = diff_change_parse( |
| 1490 | &line_changes, &line_changes.changes[0], |
| 1491 | &change_start, &change_end); |
| 1492 | if (change_start == 0) |
| 1493 | { |
| 1494 | if (added) |
| 1495 | wlv.diff_hlf = HLF_TXA; // added text on changed line |
| 1496 | else |
| 1497 | wlv.diff_hlf = HLF_TXD; // changed text on changed line |
| 1498 | } |
| 1499 | else |
| 1500 | wlv.diff_hlf = HLF_CHD; // unchanged text on changed line |
| 1501 | change_index = 0; |
| 1502 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1503 | else |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1504 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1505 | wlv.diff_hlf = HLF_CHD; // changed line |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 1506 | change_index = 0; |
| 1507 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1508 | } |
| 1509 | else |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1510 | wlv.diff_hlf = HLF_ADD; |
| 1511 | |
| 1512 | if (linestatus == 0) |
| 1513 | wlv.filler_lines = 0; |
| 1514 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1515 | area_highlighting = TRUE; |
| 1516 | } |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1517 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1518 | if (lnum == wp->w_topline) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1519 | wlv.filler_lines = wp->w_topfill; |
Jonathon | 7c7a4e6 | 2025-01-12 09:58:00 +0100 | [diff] [blame] | 1520 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1521 | wlv.filler_todo = wlv.filler_lines; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1522 | #endif |
| 1523 | |
| 1524 | #ifdef FEAT_SIGNS |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1525 | sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr); |
James McCoy | a80aad7 | 2021-12-22 19:45:28 +0000 | [diff] [blame] | 1526 | if (sign_present) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1527 | num_attr = wlv.sattr.sat_numhl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1528 | #endif |
| 1529 | |
| 1530 | #ifdef LINE_ATTR |
| 1531 | # ifdef FEAT_SIGNS |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1532 | // If this line has a sign with line highlighting set wlv.line_attr. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1533 | if (sign_present) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1534 | wlv.line_attr = wlv.sattr.sat_linehl; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1535 | # endif |
| 1536 | # if defined(FEAT_QUICKFIX) |
| 1537 | // Highlight the current line in the quickfix window. |
| 1538 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1539 | wlv.line_attr = HL_ATTR(HLF_QFL); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1540 | # endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1541 | if (wlv.line_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1542 | area_highlighting = TRUE; |
| 1543 | #endif |
| 1544 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1545 | #ifdef FEAT_SPELL |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1546 | if (spv->spv_has_spell && number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1547 | { |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1548 | // Prepare for spell checking. |
| 1549 | extra_check = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1550 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1551 | // When a word wrapped from the previous line the start of the |
| 1552 | // current line is valid. |
| 1553 | if (lnum == spv->spv_checked_lnum) |
| 1554 | cur_checked_col = spv->spv_checked_col; |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1555 | // Previous line was not spell checked, check for capital. This happens |
| 1556 | // for the first line in an updated region or after a closed fold. |
| 1557 | if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0)) |
| 1558 | spv->spv_cap_col = 0; |
| 1559 | else if (lnum != spv->spv_capcol_lnum) |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1560 | spv->spv_cap_col = -1; |
| 1561 | spv->spv_checked_lnum = 0; |
| 1562 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1563 | // Get the start of the next line, so that words that wrap to the |
| 1564 | // next line are found too: "et<line-break>al.". |
| 1565 | // Trick: skip a few chars for C/shell/Vim comments |
| 1566 | nextline[SPWORDLEN] = NUL; |
| 1567 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1568 | { |
| 1569 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 1570 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 1571 | } |
| 1572 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1573 | |
| 1574 | // If current line is empty, check first word in next line for capital. |
| 1575 | ptr = skipwhite(line); |
| 1576 | if (*ptr == NUL) |
| 1577 | { |
| 1578 | spv->spv_cap_col = 0; |
| 1579 | spv->spv_capcol_lnum = lnum + 1; |
| 1580 | } |
| 1581 | // For checking first word with a capital skip white space. |
| 1582 | else if (spv->spv_cap_col == 0) |
| 1583 | spv->spv_cap_col = ptr - line; |
| 1584 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1585 | // Copy the end of the current line into nextline[]. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1586 | if (nextline[SPWORDLEN] == NUL) |
| 1587 | { |
| 1588 | // No next line or it is empty. |
| 1589 | nextlinecol = MAXCOL; |
| 1590 | nextline_idx = 0; |
| 1591 | } |
| 1592 | else |
| 1593 | { |
zeertzjq | 94b7c32 | 2024-03-12 21:50:32 +0100 | [diff] [blame] | 1594 | v = ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1595 | if (v < SPWORDLEN) |
| 1596 | { |
| 1597 | // Short line, use it completely and append the start of the |
| 1598 | // next line. |
| 1599 | nextlinecol = 0; |
| 1600 | mch_memmove(nextline, line, (size_t)v); |
| 1601 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
| 1602 | nextline_idx = v + 1; |
| 1603 | } |
| 1604 | else |
| 1605 | { |
| 1606 | // Long line, use only the last SPWORDLEN bytes. |
| 1607 | nextlinecol = v - SPWORDLEN; |
| 1608 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 1609 | nextline_idx = SPWORDLEN + 1; |
| 1610 | } |
| 1611 | } |
| 1612 | } |
| 1613 | #endif |
| 1614 | |
Luuk van Baal | e84c773 | 2023-05-31 18:57:36 +0100 | [diff] [blame] | 1615 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1616 | ptr = line; |
| 1617 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1618 | if (wp->w_p_list) |
| 1619 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1620 | if (wp->w_lcs_chars.space |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 1621 | || wp->w_lcs_chars.multispace != NULL |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 1622 | || wp->w_lcs_chars.leadmultispace != NULL |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1623 | || wp->w_lcs_chars.trail |
| 1624 | || wp->w_lcs_chars.lead |
| 1625 | || wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1626 | extra_check = TRUE; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1627 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1628 | // find start of trailing whitespace |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 1629 | if (wp->w_lcs_chars.trail) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1630 | { |
zeertzjq | 94b7c32 | 2024-03-12 21:50:32 +0100 | [diff] [blame] | 1631 | trailcol = ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1632 | while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1])) |
| 1633 | --trailcol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1634 | trailcol += (colnr_T)(ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1635 | } |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1636 | // find end of leading whitespace |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 1637 | if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1638 | { |
| 1639 | leadcol = 0; |
| 1640 | while (VIM_ISWHITE(ptr[leadcol])) |
| 1641 | ++leadcol; |
| 1642 | if (ptr[leadcol] == NUL) |
| 1643 | // in a line full of spaces all of them are treated as trailing |
| 1644 | leadcol = (colnr_T)0; |
| 1645 | else |
| 1646 | // keep track of the first column not filled with spaces |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1647 | leadcol += (colnr_T)(ptr - line) + 1; |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 1648 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1649 | } |
| 1650 | |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1651 | wlv.wcr_attr = get_wcr_attr(wp); |
| 1652 | if (wlv.wcr_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1653 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1654 | wlv.win_attr = wlv.wcr_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1655 | area_highlighting = TRUE; |
| 1656 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 1657 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1658 | // When w_skipcol is non-zero and there is virtual text above the actual |
| 1659 | // text, then this much of the virtual text is skipped. |
| 1660 | int skipcol_in_text_prop_above = 0; |
| 1661 | |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 1662 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1663 | if (WIN_IS_POPUP(wp)) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1664 | wlv.screen_line_flags |= SLF_POPUP; |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1665 | |
| 1666 | char_u *prop_start; |
| 1667 | text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE); |
| 1668 | if (text_prop_count > 0) |
| 1669 | { |
| 1670 | // Make a copy of the properties, so that they are properly |
| 1671 | // aligned. |
| 1672 | text_props = ALLOC_MULT(textprop_T, text_prop_count); |
| 1673 | if (text_props != NULL) |
| 1674 | mch_memmove(text_props, prop_start, |
| 1675 | text_prop_count * sizeof(textprop_T)); |
| 1676 | |
| 1677 | // Allocate an array for the indexes. |
| 1678 | text_prop_idxs = ALLOC_MULT(int, text_prop_count); |
| 1679 | if (text_prop_idxs == NULL) |
| 1680 | VIM_CLEAR(text_props); |
| 1681 | |
| 1682 | if (text_props != NULL) |
| 1683 | { |
| 1684 | area_highlighting = TRUE; |
| 1685 | extra_check = TRUE; |
| 1686 | |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 1687 | /* Find the last text property that inserts text. */ |
| 1688 | for (int i = 0; i < text_prop_count; ++i) |
| 1689 | if (text_props[i].tp_id < 0) |
| 1690 | last_textprop_text_idx = i; |
| 1691 | |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1692 | // Text props "above" move the line number down to where the text |
| 1693 | // is. Only count the ones that are visible, not those that are |
| 1694 | // skipped because of w_skipcol. |
| 1695 | int text_width = wp->w_width - win_col_off(wp); |
| 1696 | for (int i = text_prop_count - 1; i >= 0; --i) |
| 1697 | if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE) |
| 1698 | { |
| 1699 | if (lnum == wp->w_topline |
| 1700 | && wp->w_skipcol - skipcol_in_text_prop_above |
| 1701 | >= text_width) |
| 1702 | { |
| 1703 | // This virtual text above is skipped, remove it from |
| 1704 | // the array. |
| 1705 | skipcol_in_text_prop_above += text_width; |
| 1706 | for (int j = i + 1; j < text_prop_count; ++j) |
| 1707 | text_props[j - 1] = text_props[j]; |
| 1708 | ++i; |
| 1709 | --text_prop_count; |
| 1710 | } |
| 1711 | else |
| 1712 | ++wlv.text_prop_above_count; |
| 1713 | } |
| 1714 | } |
| 1715 | } |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1716 | |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1717 | if (number_only > 0) |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1718 | { |
| 1719 | // skip over rows only used for virtual text above |
| 1720 | wlv.row += wlv.text_prop_above_count; |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 1721 | if (wlv.row >= endrow) |
| 1722 | { |
| 1723 | vim_free(text_props); |
| 1724 | vim_free(text_prop_idxs); |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1725 | return wlv.row; |
zeertzjq | 918b92b | 2024-03-20 19:49:20 +0100 | [diff] [blame] | 1726 | } |
Bram Moolenaar | a572b93 | 2023-02-19 14:34:37 +0000 | [diff] [blame] | 1727 | wlv.screen_row += wlv.text_prop_above_count; |
| 1728 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1729 | #endif |
| 1730 | |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 1731 | #if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP) |
| 1732 | colnr_T vcol_first_char = 0; |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1733 | if (wp->w_p_lbr && number_only == 0) |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 1734 | { |
| 1735 | chartabsize_T cts; |
| 1736 | init_chartabsize_arg(&cts, wp, lnum, 0, line, line); |
| 1737 | (void)win_lbr_chartabsize(&cts, NULL); |
| 1738 | vcol_first_char = cts.cts_first_char; |
| 1739 | clear_chartabsize_arg(&cts); |
| 1740 | } |
| 1741 | #endif |
| 1742 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1743 | // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 1744 | // first character to be displayed. |
| 1745 | if (wp->w_p_wrap) |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 1746 | v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1747 | else |
| 1748 | v = wp->w_leftcol; |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1749 | if (v > 0 && number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1750 | { |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1751 | char_u *prev_ptr = ptr; |
| 1752 | chartabsize_T cts; |
Bram Moolenaar | 6d023f9 | 2022-07-25 21:15:45 +0100 | [diff] [blame] | 1753 | int charsize = 0; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1754 | int head = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1755 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1756 | init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr); |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1757 | cts.cts_max_head_vcol = v; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1758 | while (cts.cts_vcol < v && *cts.cts_ptr != NUL) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1759 | { |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1760 | head = 0; |
| 1761 | charsize = win_lbr_chartabsize(&cts, &head); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1762 | cts.cts_vcol += charsize; |
| 1763 | prev_ptr = cts.cts_ptr; |
| 1764 | MB_PTR_ADV(cts.cts_ptr); |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 1765 | if (wp->w_p_list) |
| 1766 | { |
| 1767 | in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' ' |
| 1768 | || (prev_ptr > line && prev_ptr[-1] == ' ')); |
| 1769 | if (!in_multispace) |
| 1770 | multispace_pos = 0; |
| 1771 | else if (cts.cts_ptr >= line + leadcol |
| 1772 | && wp->w_lcs_chars.multispace != NULL) |
| 1773 | { |
| 1774 | ++multispace_pos; |
| 1775 | if (wp->w_lcs_chars.multispace[multispace_pos] == NUL) |
| 1776 | multispace_pos = 0; |
| 1777 | } |
| 1778 | else if (cts.cts_ptr < line + leadcol |
| 1779 | && wp->w_lcs_chars.leadmultispace != NULL) |
| 1780 | { |
| 1781 | ++multispace_pos; |
| 1782 | if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL) |
| 1783 | multispace_pos = 0; |
| 1784 | } |
| 1785 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1786 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1787 | wlv.vcol = cts.cts_vcol; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 1788 | ptr = cts.cts_ptr; |
| 1789 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1790 | |
| 1791 | // When: |
| 1792 | // - 'cuc' is set, or |
| 1793 | // - 'colorcolumn' is set, or |
| 1794 | // - 'virtualedit' is set, or |
| 1795 | // - the visual mode is active, |
| 1796 | // the end of the line may be before the start of the displayed part. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1797 | if (wlv.vcol < v && ( |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1798 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1799 | wp->w_p_cuc || wlv.draw_color_col || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1800 | #endif |
| 1801 | virtual_active() || |
| 1802 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1803 | wlv.vcol = v; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1804 | |
| 1805 | // Handle a character that's not completely on the screen: Put ptr at |
| 1806 | // that character but skip the first few screen characters. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1807 | if (wlv.vcol > v) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1808 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 1809 | wlv.vcol -= charsize; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1810 | ptr = prev_ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1811 | } |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 1812 | if (v > wlv.vcol) |
| 1813 | skip_cells = v - wlv.vcol - head; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 1814 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1815 | // Adjust for when the inverted text is before the screen, |
| 1816 | // and when the start of the inverted text is before the screen. |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1817 | if (wlv.tocol <= wlv.vcol) |
| 1818 | wlv.fromcol = 0; |
| 1819 | else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol) |
| 1820 | wlv.fromcol = wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1821 | |
| 1822 | #ifdef FEAT_LINEBREAK |
| 1823 | // When w_skipcol is non-zero, first line needs 'showbreak' |
| 1824 | if (wp->w_p_wrap) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1825 | wlv.need_showbreak = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1826 | #endif |
| 1827 | #ifdef FEAT_SPELL |
| 1828 | // When spell checking a word we need to figure out the start of the |
| 1829 | // word and if it's badly spelled or not. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 1830 | if (spv->spv_has_spell) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1831 | { |
| 1832 | int len; |
| 1833 | colnr_T linecol = (colnr_T)(ptr - line); |
| 1834 | hlf_T spell_hlf = HLF_COUNT; |
| 1835 | |
| 1836 | pos = wp->w_cursor; |
| 1837 | wp->w_cursor.lnum = lnum; |
| 1838 | wp->w_cursor.col = linecol; |
Christ van Willegen - van Noort | 8e4c4c7 | 2024-05-17 18:49:27 +0200 | [diff] [blame] | 1839 | len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1840 | |
| 1841 | // spell_move_to() may call ml_get() and make "line" invalid |
| 1842 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 1843 | ptr = line + linecol; |
| 1844 | |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 1845 | if (len == 0 || (int)wp->w_cursor.col > linecol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1846 | { |
| 1847 | // no bad word found at line start, don't check until end of a |
| 1848 | // word |
| 1849 | spell_hlf = HLF_COUNT; |
| 1850 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
| 1851 | } |
| 1852 | else |
| 1853 | { |
| 1854 | // bad word found, use attributes until end of word |
| 1855 | word_end = wp->w_cursor.col + len + 1; |
| 1856 | |
| 1857 | // Turn index into actual attributes. |
| 1858 | if (spell_hlf != HLF_COUNT) |
| 1859 | spell_attr = highlight_attr[spell_hlf]; |
| 1860 | } |
| 1861 | wp->w_cursor = pos; |
| 1862 | |
| 1863 | # ifdef FEAT_SYN_HL |
| 1864 | // Need to restart syntax highlighting for this line. |
| 1865 | if (has_syntax) |
| 1866 | syntax_start(wp, lnum); |
| 1867 | # endif |
| 1868 | } |
| 1869 | #endif |
| 1870 | } |
| 1871 | |
| 1872 | // Correct highlighting for cursor that can't be disabled. |
| 1873 | // Avoids having to check this for each character. |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1874 | if (wlv.fromcol >= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1875 | { |
| 1876 | if (noinvcur) |
| 1877 | { |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1878 | if ((colnr_T)wlv.fromcol == wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1879 | { |
| 1880 | // highlighting starts at cursor, let it start just after the |
| 1881 | // cursor |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1882 | fromcol_prev = wlv.fromcol; |
| 1883 | wlv.fromcol = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1884 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1885 | else if ((colnr_T)wlv.fromcol < wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1886 | // restart highlighting after the cursor |
| 1887 | fromcol_prev = wp->w_virtcol; |
| 1888 | } |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1889 | if (wlv.fromcol >= wlv.tocol) |
| 1890 | wlv.fromcol = -1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1891 | } |
| 1892 | |
| 1893 | #ifdef FEAT_SEARCH_EXTRA |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1894 | if (number_only == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1895 | { |
| 1896 | v = (long)(ptr - line); |
| 1897 | area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v, |
| 1898 | &line, &screen_search_hl, |
| 1899 | &search_attr); |
| 1900 | ptr = line + v; // "line" may have been updated |
| 1901 | } |
| 1902 | #endif |
| 1903 | |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 1904 | if ((State & MODE_INSERT) && ins_compl_win_active(wp) |
| 1905 | && (in_curline || ins_compl_lnum_in_range(lnum))) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 1906 | area_highlighting = TRUE; |
| 1907 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1908 | #ifdef FEAT_SYN_HL |
| 1909 | // Cursor line highlighting for 'cursorline' in the current window. |
| 1910 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 1911 | { |
| 1912 | // Do not show the cursor line in the text when Visual mode is active, |
zeertzjq | c20e46a | 2022-03-23 14:55:23 +0000 | [diff] [blame] | 1913 | // because it's not clear what is selected then. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1914 | if (!(wp == curwin && VIsual_active) |
| 1915 | && wp->w_p_culopt_flags != CULOPT_NBR) |
| 1916 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1917 | wlv.cul_screenline = (wp->w_p_wrap |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1918 | && (wp->w_p_culopt_flags & CULOPT_SCRLINE)); |
| 1919 | |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1920 | // Only apply CursorLine highlight here when "screenline" is not |
| 1921 | // present in 'cursorlineopt'. Otherwise it's done later. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1922 | if (!wlv.cul_screenline) |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 1923 | apply_cursorline_highlight(&wlv, sign_present); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1924 | else |
| 1925 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1926 | line_attr_save = wlv.line_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1927 | margin_columns_win(wp, &left_curline_col, &right_curline_col); |
| 1928 | } |
| 1929 | area_highlighting = TRUE; |
| 1930 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1931 | } |
| 1932 | #endif |
| 1933 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1934 | win_line_start(wp, &wlv, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1935 | |
| 1936 | // Repeat for the whole displayed line. |
| 1937 | for (;;) |
| 1938 | { |
| 1939 | #if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1940 | int has_match_conc = 0; // match wants to conceal |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1941 | #endif |
| 1942 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1943 | int did_decrement_ptr = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1944 | #endif |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 1945 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1946 | // Skip this quickly when working on the text. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1947 | if (wlv.draw_state != WL_LINE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1948 | { |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1949 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1950 | if (wlv.cul_screenline) |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1951 | { |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 1952 | wlv.cul_attr = 0; |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 1953 | wlv.line_attr = line_attr_save; |
zeertzjq | 4f33bc2 | 2021-08-05 17:57:02 +0200 | [diff] [blame] | 1954 | } |
| 1955 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1956 | if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1957 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1958 | wlv.draw_state = WL_CMDLINE; |
Sean Dewar | 988f743 | 2023-08-16 14:17:36 +0100 | [diff] [blame] | 1959 | if (wp == cmdwin_win) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1960 | { |
| 1961 | // Draw the cmdline character. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1962 | wlv.n_extra = 1; |
| 1963 | wlv.c_extra = cmdwin_type; |
| 1964 | wlv.c_final = NUL; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1965 | wlv.char_attr = |
| 1966 | hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1967 | } |
| 1968 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1969 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1970 | if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1971 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1972 | wlv.draw_state = WL_FOLD; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1973 | handle_foldcolumn(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1974 | } |
| 1975 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1976 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1977 | if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1978 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1979 | // Show the sign column when desired or when using Netbeans. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1980 | wlv.draw_state = WL_SIGN; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1981 | if (signcolumn_on(wp)) |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1982 | get_sign_display_info(FALSE, wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1983 | } |
| 1984 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1985 | if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1986 | { |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 1987 | // Show the line number, if desired. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 1988 | wlv.draw_state = WL_NR; |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 1989 | handle_lnum_col(wp, &wlv, sign_present, num_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 1990 | } |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1991 | |
| 1992 | // When only displaying the (relative) line number and that's done, |
| 1993 | // stop here. |
| 1994 | if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0) |
| 1995 | { |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 1996 | wlv_screen_line(wp, &wlv, FALSE); |
zeertzjq | ebfd856 | 2024-02-06 10:59:03 +0100 | [diff] [blame] | 1997 | // Need to update more screen lines if: |
| 1998 | // - LineNrAbove or LineNrBelow is used, or |
| 1999 | // - still drawing filler lines. |
| 2000 | if ((wlv.row + 1 - wlv.startrow < number_only |
| 2001 | && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0)) |
| 2002 | #ifdef FEAT_DIFF |
| 2003 | || wlv.filler_todo > 0 |
| 2004 | #endif |
| 2005 | ) |
| 2006 | { |
| 2007 | ++wlv.row; |
| 2008 | ++wlv.screen_row; |
| 2009 | if (wlv.row == endrow) |
| 2010 | break; |
| 2011 | #ifdef FEAT_DIFF |
| 2012 | --wlv.filler_todo; |
| 2013 | if (wlv.filler_todo == 0 && wp->w_botfill) |
| 2014 | break; |
| 2015 | #endif |
| 2016 | win_line_start(wp, &wlv, TRUE); |
| 2017 | continue; |
| 2018 | } |
| 2019 | else |
| 2020 | break; |
| 2021 | } |
| 2022 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2023 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 2024 | // Check if 'breakindent' applies and show it. |
| 2025 | // May change wlv.draw_state to WL_BRI or WL_BRI - 1. |
| 2026 | if (wlv.n_extra == 0) |
| 2027 | handle_breakindent(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2028 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2029 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2030 | if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2031 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2032 | wlv.draw_state = WL_SBR; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2033 | handle_showbreak_and_filler(wp, &wlv); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2034 | } |
| 2035 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2036 | if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2037 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2038 | wlv.draw_state = WL_LINE; |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2039 | win_line_continue(&wlv); // use wlv.saved_ values |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2040 | } |
| 2041 | } |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2042 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2043 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2044 | if (wlv.cul_screenline && wlv.draw_state == WL_LINE |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2045 | && wlv.vcol >= left_curline_col |
| 2046 | && wlv.vcol < right_curline_col) |
zeertzjq | b7acea1 | 2022-12-12 13:20:43 +0000 | [diff] [blame] | 2047 | apply_cursorline_highlight(&wlv, sign_present); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2048 | #endif |
| 2049 | |
| 2050 | // When still displaying '$' of change command, stop at cursor. |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 2051 | if (dollar_vcol >= 0 && in_curline && wlv.vcol >= (long)wp->w_virtcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2052 | { |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 2053 | wlv_screen_line(wp, &wlv, FALSE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2054 | // Pretend we have finished updating the window. Except when |
| 2055 | // 'cursorcolumn' is set. |
| 2056 | #ifdef FEAT_SYN_HL |
| 2057 | if (wp->w_p_cuc) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2058 | wlv.row = wp->w_cline_row + wp->w_cline_height; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2059 | else |
| 2060 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2061 | wlv.row = wp->w_height; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2062 | break; |
| 2063 | } |
| 2064 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2065 | if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2066 | { |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2067 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2068 | if (text_props != NULL) |
| 2069 | { |
| 2070 | int pi; |
| 2071 | int bcol = (int)(ptr - line); |
| 2072 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2073 | if (wlv.n_extra > 0 |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2074 | # ifdef FEAT_LINEBREAK |
| 2075 | && !in_linebreak |
| 2076 | # endif |
| 2077 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2078 | --bcol; // still working on the previous char, e.g. Tab |
| 2079 | |
| 2080 | // Check if any active property ends. |
| 2081 | for (pi = 0; pi < text_props_active; ++pi) |
| 2082 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2083 | int tpi = text_prop_idxs[pi]; |
| 2084 | textprop_T *tp = &text_props[tpi]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2085 | |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2086 | // An inline property ends when after the start column plus |
| 2087 | // length. An "above" property ends when used and n_extra |
| 2088 | // is zero. |
| 2089 | if ((tp->tp_col != MAXCOL |
| 2090 | && bcol >= tp->tp_col - 1 + tp->tp_len)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2091 | { |
| 2092 | if (pi + 1 < text_props_active) |
| 2093 | mch_memmove(text_prop_idxs + pi, |
| 2094 | text_prop_idxs + pi + 1, |
| 2095 | sizeof(int) |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2096 | * (text_props_active - (pi + 1))); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2097 | --text_props_active; |
| 2098 | --pi; |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2099 | # ifdef FEAT_LINEBREAK |
| 2100 | // not exactly right but should work in most cases |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2101 | if (in_linebreak && syntax_attr == text_prop_attr_comb) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2102 | syntax_attr = 0; |
| 2103 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2104 | } |
| 2105 | } |
| 2106 | |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2107 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2108 | if (wlv.n_extra > 0 && in_linebreak) |
Bram Moolenaar | acdc911 | 2021-12-02 19:46:57 +0000 | [diff] [blame] | 2109 | // not on the next char yet, don't start another prop |
| 2110 | --bcol; |
| 2111 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2112 | // Add any text property that starts in this column. |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2113 | while (text_prop_next < text_prop_count) |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 2114 | { |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2115 | int active; |
| 2116 | textprop_T *tp = &text_props[text_prop_next]; |
| 2117 | if (tp->tp_col == MAXCOL) |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2118 | { |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2119 | if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE)) |
| 2120 | active = TRUE; |
| 2121 | else if (*ptr != NUL) |
| 2122 | break; |
| 2123 | else |
| 2124 | { |
| 2125 | // With 'nowrap' and not in the first screen line only "below" |
| 2126 | // text prop can show. |
| 2127 | active = wp->w_p_wrap |
| 2128 | || wlv.row == startrow |
| 2129 | || (tp->tp_flags & TP_FLAG_ALIGN_BELOW); |
| 2130 | } |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2131 | } |
Dylan Thacker-Smith | 1134fdd | 2024-03-28 11:49:46 +0100 | [diff] [blame] | 2132 | else |
| 2133 | { |
| 2134 | if (bcol < tp->tp_col - 1) |
| 2135 | break; |
| 2136 | active = bcol <= tp->tp_col - 1 + tp->tp_len; |
| 2137 | } |
| 2138 | |
| 2139 | if (active) |
| 2140 | text_prop_idxs[text_props_active++] = text_prop_next; |
Bram Moolenaar | f3fa184 | 2021-02-10 17:20:28 +0100 | [diff] [blame] | 2141 | ++text_prop_next; |
| 2142 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2143 | |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2144 | if (wlv.n_extra == 0 || |
| 2145 | (!wlv.extra_for_textprop |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2146 | && !(text_prop_type != NULL && |
| 2147 | text_prop_flags & PT_FLAG_OVERRIDE) |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 2148 | )) |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2149 | { |
| 2150 | text_prop_attr = 0; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2151 | text_prop_attr_comb = 0; |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2152 | text_prop_flags = 0; |
| 2153 | text_prop_type = NULL; |
| 2154 | text_prop_id = 0; |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2155 | reset_extra_attr = FALSE; |
Bram Moolenaar | 9e7e28f | 2022-08-14 16:36:38 +0100 | [diff] [blame] | 2156 | } |
Dylan Thacker-Smith | c8b47f2 | 2024-03-26 18:05:01 +0100 | [diff] [blame] | 2157 | if (text_props_active > 0 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2158 | { |
Bram Moolenaar | be3dbda | 2022-07-26 11:42:34 +0100 | [diff] [blame] | 2159 | int used_tpi = -1; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2160 | int used_attr = 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2161 | int other_tpi = -1; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2162 | |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2163 | text_prop_above = FALSE; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2164 | text_prop_follows = FALSE; |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2165 | |
| 2166 | // Sort the properties on priority and/or starting last. |
| 2167 | // Then combine the attributes, highest priority last. |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2168 | sort_text_props(wp->w_buffer, text_props, |
| 2169 | text_prop_idxs, text_props_active); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2170 | |
| 2171 | for (pi = 0; pi < text_props_active; ++pi) |
| 2172 | { |
| 2173 | int tpi = text_prop_idxs[pi]; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2174 | textprop_T *tp = &text_props[tpi]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2175 | proptype_T *pt = text_prop_type_by_id( |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2176 | wp->w_buffer, tp->tp_type); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2177 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2178 | // Only use a text property that can be displayed. |
| 2179 | // Skip "after" properties when wrap is off and at the |
| 2180 | // end of the window. |
| 2181 | if (pt != NULL |
| 2182 | && (pt->pt_hl_id > 0 || tp->tp_id < 0) |
| 2183 | && tp->tp_id != -MAXCOL |
| 2184 | && !(tp->tp_id < 0 |
| 2185 | && !wp->w_p_wrap |
| 2186 | && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT |
| 2187 | | TP_FLAG_ALIGN_ABOVE |
| 2188 | | TP_FLAG_ALIGN_BELOW)) == 0 |
| 2189 | && wlv.col >= wp->w_width)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2190 | { |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 2191 | if (tp->tp_col == MAXCOL |
| 2192 | && *ptr == NUL |
| 2193 | && ((wp->w_p_list && lcs_eol_one > 0 |
| 2194 | && (tp->tp_flags |
| 2195 | & TP_FLAG_ALIGN_ABOVE) == 0) |
| 2196 | || (ptr == line |
| 2197 | && !did_line |
| 2198 | && (tp->tp_flags |
| 2199 | & TP_FLAG_ALIGN_BELOW)))) |
| 2200 | { |
| 2201 | // skip this prop, first display the '$' after |
| 2202 | // the line or display an empty line |
| 2203 | text_prop_follows = TRUE; |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 2204 | continue; |
| 2205 | } |
| 2206 | |
Bram Moolenaar | 87f3a2c | 2022-08-10 20:50:23 +0100 | [diff] [blame] | 2207 | if (pt->pt_hl_id > 0) |
| 2208 | used_attr = syn_id2attr(pt->pt_hl_id); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2209 | text_prop_type = pt; |
| 2210 | text_prop_attr = |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2211 | hl_combine_attr(text_prop_attr, used_attr); |
Bram Moolenaar | 51b2fc2 | 2023-01-21 15:54:59 +0000 | [diff] [blame] | 2212 | if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0) |
| 2213 | other_tpi = used_tpi; |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2214 | text_prop_flags = pt->pt_flags; |
| 2215 | text_prop_id = tp->tp_id; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2216 | used_tpi = tpi; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2217 | } |
| 2218 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2219 | if (text_prop_id < 0 && used_tpi >= 0 |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2220 | && -text_prop_id |
| 2221 | <= wp->w_buffer->b_textprop_text.ga_len) |
| 2222 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2223 | textprop_T *tp = &text_props[used_tpi]; |
| 2224 | char_u *p = ((char_u **)wp->w_buffer |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2225 | ->b_textprop_text.ga_data)[ |
| 2226 | -text_prop_id - 1]; |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2227 | int above = (tp->tp_flags |
| 2228 | & TP_FLAG_ALIGN_ABOVE); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2229 | int bail_out = FALSE; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2230 | |
| 2231 | // reset the ID in the copy to avoid it being used |
| 2232 | // again |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2233 | tp->tp_id = -MAXCOL; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2234 | |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2235 | if (p != NULL) |
| 2236 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2237 | int right = (tp->tp_flags |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2238 | & TP_FLAG_ALIGN_RIGHT); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2239 | int below = (tp->tp_flags |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2240 | & TP_FLAG_ALIGN_BELOW); |
zeertzjq | 3c3cf1d | 2023-09-02 21:55:00 +0200 | [diff] [blame] | 2241 | int wrap = tp->tp_col < MAXCOL |
| 2242 | || (tp->tp_flags & TP_FLAG_WRAP); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2243 | int padding = tp->tp_col == MAXCOL |
| 2244 | && tp->tp_len > 1 |
| 2245 | ? tp->tp_len - 1 : 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2246 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2247 | // Insert virtual text before the current |
| 2248 | // character, or add after the end of the line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2249 | wlv.p_extra = p; |
| 2250 | wlv.c_extra = NUL; |
| 2251 | wlv.c_final = NUL; |
| 2252 | wlv.n_extra = (int)STRLEN(p); |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2253 | wlv.extra_for_textprop = TRUE; |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2254 | wlv.start_extra_for_textprop = TRUE; |
Bram Moolenaar | ee28c70 | 2022-11-17 14:56:00 +0000 | [diff] [blame] | 2255 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
| 2256 | used_attr); |
Bram Moolenaar | 09ff4b5 | 2022-08-01 16:51:02 +0100 | [diff] [blame] | 2257 | n_attr = mb_charlen(p); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2258 | text_prop_attr = 0; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2259 | text_prop_attr_comb = 0; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2260 | if (*ptr == NUL) |
| 2261 | // don't combine char attr after EOL |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2262 | text_prop_flags &= ~PT_FLAG_COMBINE; |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2263 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 2264 | if (above || below || right || !wrap) |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2265 | { |
| 2266 | // no 'showbreak' before "below" text property |
Bram Moolenaar | 04e0ed1 | 2022-09-10 20:00:56 +0100 | [diff] [blame] | 2267 | // or after "above" or "right" text property |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 2268 | wlv.need_showbreak = FALSE; |
| 2269 | wlv.dont_use_showbreak = TRUE; |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 2270 | } |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2271 | # endif |
Bram Moolenaar | 79f8b84 | 2022-09-11 13:31:01 +0100 | [diff] [blame] | 2272 | if ((right || above || below || !wrap |
| 2273 | || padding > 0) && wp->w_width > 2) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2274 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2275 | char_u *prev_p_extra = wlv.p_extra; |
| 2276 | int start_line; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2277 | |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2278 | // Take care of padding, right-align and |
| 2279 | // truncation. |
| 2280 | // Shared with win_lbr_chartabsize(), must do |
| 2281 | // exactly the same. |
| 2282 | start_line = text_prop_position(wp, tp, |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2283 | wlv.vcol, |
zeertzjq | 6b9c202 | 2023-09-11 20:01:17 +0200 | [diff] [blame] | 2284 | # ifdef FEAT_RIGHTLEFT |
| 2285 | wp->w_p_rl |
| 2286 | ? wp->w_width - wlv.col - 1 |
| 2287 | : |
| 2288 | # endif |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2289 | wlv.col, |
| 2290 | &wlv.n_extra, &wlv.p_extra, |
Bram Moolenaar | 56a40fe | 2022-12-06 14:17:57 +0000 | [diff] [blame] | 2291 | &n_attr, &wlv.n_attr_skip, |
| 2292 | skip_cells > 0); |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2293 | if (wlv.p_extra != prev_p_extra) |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2294 | { |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2295 | // wlv.p_extra was allocated |
| 2296 | vim_free(p_extra_free2); |
| 2297 | p_extra_free2 = wlv.p_extra; |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2298 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2299 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 2300 | if (above) |
Matthias | 2c9f49b | 2025-03-16 19:27:51 +0100 | [diff] [blame] | 2301 | wlv.vcol_off_tp += vim_strsize(wlv.p_extra); |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 2302 | |
Bram Moolenaar | 02edfaa | 2022-11-18 23:13:47 +0000 | [diff] [blame] | 2303 | if (lcs_eol_one < 0 |
| 2304 | && wp->w_p_wrap |
| 2305 | && wlv.col |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 2306 | + wlv.n_extra - 2 > wp->w_width) |
| 2307 | // don't bail out at end of line |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 2308 | text_prop_follows = TRUE; |
Bram Moolenaar | a4abe51 | 2022-09-15 19:44:09 +0100 | [diff] [blame] | 2309 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2310 | // When 'wrap' is off then for "below" we need |
dundargoc | c57b5bc | 2022-11-02 13:30:51 +0000 | [diff] [blame] | 2311 | // to start a new line explicitly. |
Bram Moolenaar | f396ce8 | 2022-08-23 18:39:37 +0100 | [diff] [blame] | 2312 | if (start_line) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2313 | { |
| 2314 | draw_screen_line(wp, &wlv); |
| 2315 | |
| 2316 | // When line got too long for screen break |
| 2317 | // here. |
| 2318 | if (wlv.row == endrow) |
| 2319 | { |
| 2320 | ++wlv.row; |
| 2321 | break; |
| 2322 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2323 | win_line_start(wp, &wlv, TRUE); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2324 | bail_out = TRUE; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2325 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2326 | } |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2327 | } |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2328 | |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2329 | // If the text didn't reach until the first window |
| 2330 | // column we need to skip cells. |
| 2331 | if (skip_cells > 0) |
| 2332 | { |
| 2333 | if (wlv.n_extra > skip_cells) |
| 2334 | { |
| 2335 | wlv.n_extra -= skip_cells; |
| 2336 | wlv.p_extra += skip_cells; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2337 | wlv.n_attr_skip -= skip_cells; |
| 2338 | if (wlv.n_attr_skip < 0) |
| 2339 | wlv.n_attr_skip = 0; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2340 | skipped_cells += skip_cells; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2341 | skip_cells = 0; |
| 2342 | } |
| 2343 | else |
| 2344 | { |
| 2345 | // the whole text is left of the window, drop |
| 2346 | // it and advance to the next one |
| 2347 | skip_cells -= wlv.n_extra; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2348 | skipped_cells += wlv.n_extra; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2349 | wlv.n_extra = 0; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 2350 | wlv.n_attr_skip = 0; |
Bram Moolenaar | cd10541 | 2022-10-10 19:50:42 +0100 | [diff] [blame] | 2351 | bail_out = TRUE; |
| 2352 | } |
| 2353 | } |
| 2354 | |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 2355 | // If another text prop follows the condition below at |
| 2356 | // the last window column must know. |
Dylan Thacker-Smith | 83925be | 2024-02-21 21:03:10 +0100 | [diff] [blame] | 2357 | // If this is an "above" text prop and 'nowrap' then we |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 2358 | // must wrap anyway. |
| 2359 | text_prop_above = above; |
Bram Moolenaar | a9a3648 | 2022-10-11 16:47:22 +0100 | [diff] [blame] | 2360 | text_prop_follows |= other_tpi != -1 |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2361 | && (wp->w_p_wrap |
| 2362 | || (text_props[other_tpi].tp_flags |
Bram Moolenaar | f167c7b | 2022-10-09 21:53:58 +0100 | [diff] [blame] | 2363 | & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT))); |
Bram Moolenaar | 1206c16 | 2022-10-10 15:40:04 +0100 | [diff] [blame] | 2364 | |
| 2365 | if (bail_out) |
| 2366 | // starting a new line for "below" |
| 2367 | continue; |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 2368 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2369 | } |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2370 | else if (text_prop_next < text_prop_count |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 2371 | && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL) |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2372 | || (!wp->w_p_wrap && wlv.col == wp->w_width - 1))) |
| 2373 | { |
Bram Moolenaar | 398649e | 2022-08-04 15:03:48 +0100 | [diff] [blame] | 2374 | // When at last-but-one character and a text property |
| 2375 | // follows after it, we may need to flush the line after |
| 2376 | // displaying that character. |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 2377 | // Or when not wrapping and at the rightmost column. |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2378 | |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2379 | int only_below_follows = !wp->w_p_wrap && wlv.col == wp->w_width - 1; |
Dylan Thacker-Smith | fe0a76b | 2024-03-28 11:47:32 +0100 | [diff] [blame] | 2380 | // TODO: Store "after"/"right"/"below" text properties in order |
| 2381 | // in the buffer so only `text_props[text_prop_count - 1]` |
| 2382 | // needs to be checked for following "below" virtual text |
| 2383 | for (int i = text_prop_next; i < text_prop_count; ++i) |
| 2384 | { |
| 2385 | if (text_props[i].tp_col == MAXCOL |
| 2386 | && (!only_below_follows |
| 2387 | || (text_props[i].tp_flags & TP_FLAG_ALIGN_BELOW))) |
| 2388 | { |
| 2389 | text_prop_follows = TRUE; |
| 2390 | break; |
| 2391 | } |
| 2392 | } |
Dylan Thacker-Smith | b6fac4d | 2024-03-28 11:40:41 +0100 | [diff] [blame] | 2393 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2394 | } |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2395 | |
| 2396 | if (wlv.start_extra_for_textprop) |
| 2397 | { |
| 2398 | wlv.start_extra_for_textprop = FALSE; |
| 2399 | // restore search_attr and area_attr when n_extra |
| 2400 | // is down to zero |
| 2401 | saved_search_attr = search_attr; |
| 2402 | saved_area_attr = area_attr; |
| 2403 | search_attr = 0; |
| 2404 | area_attr = 0; |
| 2405 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2406 | #endif |
| 2407 | |
zeertzjq | 6e940d9 | 2023-08-17 23:21:40 +0200 | [diff] [blame] | 2408 | int *area_attr_p = |
| 2409 | #ifdef FEAT_PROP_POPUP |
| 2410 | wlv.extra_for_textprop ? &saved_area_attr : |
| 2411 | #endif |
| 2412 | &area_attr; |
| 2413 | |
| 2414 | // handle Visual or match highlighting in this line |
| 2415 | if (wlv.vcol == wlv.fromcol |
| 2416 | || (has_mbyte && wlv.vcol + 1 == wlv.fromcol |
| 2417 | && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1) |
| 2418 | || (wlv.n_extra > 0 && wlv.p_extra != NULL |
| 2419 | && (*mb_ptr2cells)(wlv.p_extra) > 1))) |
| 2420 | || ((int)vcol_prev == fromcol_prev |
| 2421 | && vcol_prev < wlv.vcol // not at margin |
| 2422 | && wlv.vcol < wlv.tocol)) |
| 2423 | *area_attr_p = vi_attr; // start highlighting |
| 2424 | else if (*area_attr_p != 0 |
| 2425 | && (wlv.vcol == wlv.tocol |
| 2426 | || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol))) |
| 2427 | *area_attr_p = 0; // stop highlighting |
| 2428 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2429 | if (wlv.n_extra == 0) |
| 2430 | { |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2431 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2432 | // Check for start/end of 'hlsearch' and other matches. |
| 2433 | // After end, check for start/end of next match. |
| 2434 | // When another match, have to check for start again. |
| 2435 | v = (long)(ptr - line); |
| 2436 | search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line, |
| 2437 | &screen_search_hl, &has_match_conc, |
| 2438 | &match_conc, did_line_attr, lcs_eol_one, |
| 2439 | &on_last_col); |
| 2440 | ptr = line + v; // "line" may have been changed |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2441 | |
| 2442 | // Do not allow a conceal over EOL otherwise EOL will be missed |
| 2443 | // and bad things happen. |
| 2444 | if (*ptr == NUL) |
| 2445 | has_match_conc = 0; |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2446 | #else |
| 2447 | search_attr = 0; |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 2448 | #endif |
zeertzjq | b25dbb3 | 2023-08-13 18:11:05 +0200 | [diff] [blame] | 2449 | |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2450 | // Check if ComplMatchIns highlight is needed. |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 2451 | if ((State & MODE_INSERT) && ins_compl_win_active(wp) |
| 2452 | && (in_curline || ins_compl_lnum_in_range(lnum))) |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2453 | { |
| 2454 | int ins_match_attr = |
glepnir | 76bdb82 | 2025-02-08 19:04:51 +0100 | [diff] [blame] | 2455 | ins_compl_col_range_attr(lnum, (int)(ptr - line)); |
zeertzjq | f25d8f9 | 2024-12-18 21:12:25 +0100 | [diff] [blame] | 2456 | if (ins_match_attr > 0) |
| 2457 | search_attr = |
| 2458 | hl_combine_attr(search_attr, ins_match_attr); |
| 2459 | } |
| 2460 | } |
| 2461 | |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2462 | #ifdef FEAT_DIFF |
| 2463 | if (wlv.diff_hlf != (hlf_T)0) |
| 2464 | { |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 2465 | if (line_changes.num_changes > 0 |
| 2466 | && change_index >= 0 |
| 2467 | && change_index < line_changes.num_changes - 1) |
| 2468 | { |
| 2469 | if (ptr - line >= line_changes.changes[change_index+1].dc_start[line_changes.bufidx]) |
| 2470 | change_index += 1; |
| 2471 | } |
| 2472 | int added = FALSE; |
| 2473 | if (line_changes.num_changes > 0 && change_index >= 0 && change_index < line_changes.num_changes) |
| 2474 | { |
| 2475 | added = diff_change_parse(&line_changes, |
| 2476 | &line_changes.changes[change_index], |
| 2477 | &change_start, |
| 2478 | &change_end); |
| 2479 | } |
Bram Moolenaar | d097af7 | 2022-12-17 11:33:00 +0000 | [diff] [blame] | 2480 | // When there is extra text (e.g. virtual text) it gets the |
| 2481 | // diff highlighting for the line, but not for changed text. |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2482 | if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start |
| 2483 | && wlv.n_extra == 0) |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 2484 | wlv.diff_hlf = added ? HLF_TXA : HLF_TXD; // added/changed text |
| 2485 | if ((wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA) |
| 2486 | && ((ptr - line >= change_end && wlv.n_extra == 0) |
Bram Moolenaar | 417e88b | 2022-12-17 15:03:02 +0000 | [diff] [blame] | 2487 | || (wlv.n_extra > 0 && wlv.extra_for_textprop))) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2488 | wlv.diff_hlf = HLF_CHD; // changed line |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2489 | wlv.line_attr = HL_ATTR(wlv.diff_hlf); |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2490 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 2491 | && wp->w_p_culopt_flags != CULOPT_NBR |
| 2492 | && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col |
| 2493 | && wlv.vcol <= right_curline_col))) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2494 | wlv.line_attr = hl_combine_attr( |
| 2495 | wlv.line_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2496 | } |
| 2497 | #endif |
| 2498 | |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2499 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2500 | if (extra_check && wlv.n_extra == 0) |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2501 | { |
Bram Moolenaar | 82260af | 2019-10-20 13:16:22 +0200 | [diff] [blame] | 2502 | syntax_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2503 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2504 | if (get_term_attr) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2505 | syntax_attr = term_get_attr(wp, lnum, wlv.vcol); |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2506 | # endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2507 | // Get syntax attribute. |
| 2508 | if (has_syntax) |
| 2509 | { |
| 2510 | // Get the syntax attribute for the character. If there |
| 2511 | // is an error, disable syntax highlighting. |
| 2512 | save_did_emsg = did_emsg; |
| 2513 | did_emsg = FALSE; |
| 2514 | |
| 2515 | v = (long)(ptr - line); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2516 | if (v == prev_syntax_col) |
| 2517 | // at same column again |
| 2518 | syntax_attr = prev_syntax_attr; |
| 2519 | else |
| 2520 | { |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 2521 | # ifdef FEAT_SPELL |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2522 | can_spell = TRUE; |
Bram Moolenaar | b2fe1d6 | 2019-10-16 21:33:40 +0200 | [diff] [blame] | 2523 | # endif |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2524 | syntax_attr = get_syntax_attr((colnr_T)v, |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2525 | # ifdef FEAT_SPELL |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2526 | spv->spv_has_spell ? &can_spell : |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2527 | # endif |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2528 | NULL, FALSE); |
Bram Moolenaar | 9115c61 | 2019-10-16 16:57:06 +0200 | [diff] [blame] | 2529 | prev_syntax_col = v; |
| 2530 | prev_syntax_attr = syntax_attr; |
| 2531 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2532 | |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2533 | if (did_emsg) |
| 2534 | { |
| 2535 | wp->w_s->b_syn_error = TRUE; |
| 2536 | has_syntax = FALSE; |
| 2537 | syntax_attr = 0; |
| 2538 | } |
| 2539 | else |
| 2540 | did_emsg = save_did_emsg; |
| 2541 | # ifdef SYN_TIME_LIMIT |
| 2542 | if (wp->w_s->b_syn_slow) |
| 2543 | has_syntax = FALSE; |
| 2544 | # endif |
| 2545 | |
| 2546 | // Need to get the line again, a multi-line regexp may |
| 2547 | // have made it invalid. |
| 2548 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 2549 | ptr = line + v; |
| 2550 | # ifdef FEAT_CONCEAL |
| 2551 | // no concealing past the end of the line, it interferes |
| 2552 | // with line highlighting |
| 2553 | if (*ptr == NUL) |
| 2554 | syntax_flags = 0; |
| 2555 | else |
| 2556 | syntax_flags = get_syntax_info(&syntax_seqnr); |
| 2557 | # endif |
| 2558 | } |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2559 | } |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 2560 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2561 | // Combine text property highlight into syntax highlight. |
| 2562 | if (text_prop_type != NULL) |
| 2563 | { |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2564 | if (text_prop_flags & PT_FLAG_COMBINE) |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2565 | syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr); |
| 2566 | else |
| 2567 | syntax_attr = text_prop_attr; |
Bram Moolenaar | cf2bb63 | 2022-09-02 13:26:29 +0100 | [diff] [blame] | 2568 | text_prop_attr_comb = syntax_attr; |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2569 | } |
| 2570 | # endif |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2571 | #endif |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2572 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2573 | // Decide which of the highlight attributes to use. |
| 2574 | attr_pri = TRUE; |
| 2575 | #ifdef LINE_ATTR |
| 2576 | if (area_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2577 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2578 | wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr); |
Bram Moolenaar | 2d5f385 | 2021-04-21 15:11:42 +0200 | [diff] [blame] | 2579 | if (!highlight_match) |
| 2580 | // let search highlight show in Visual area if possible |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2581 | wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2582 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2583 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2584 | # endif |
| 2585 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2586 | else if (search_attr != 0) |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2587 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2588 | wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2589 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2590 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr); |
Bram Moolenaar | 8459006 | 2019-10-18 23:12:20 +0200 | [diff] [blame] | 2591 | # endif |
| 2592 | } |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2593 | else if (wlv.line_attr != 0 |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 2594 | && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL) |
| 2595 | || wlv.vcol < wlv.fromcol |
| 2596 | || vcol_prev < fromcol_prev |
| 2597 | || wlv.vcol >= wlv.tocol)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2598 | { |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2599 | // Use wlv.line_attr when not in the Visual or 'incsearch' area |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2600 | // (area_attr may be 0 when "noinvcur" is set). |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2601 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2602 | wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr); |
Bram Moolenaar | dbd4316 | 2019-11-09 21:28:14 +0100 | [diff] [blame] | 2603 | # else |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 2604 | wlv.char_attr = wlv.line_attr; |
Bram Moolenaar | 3439028 | 2019-10-16 14:38:26 +0200 | [diff] [blame] | 2605 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2606 | attr_pri = FALSE; |
| 2607 | } |
| 2608 | #else |
| 2609 | if (area_attr != 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2610 | wlv.char_attr = area_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2611 | else if (search_attr != 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2612 | wlv.char_attr = search_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2613 | #endif |
| 2614 | else |
| 2615 | { |
| 2616 | attr_pri = FALSE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2617 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2618 | wlv.char_attr = syntax_attr; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2619 | #else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2620 | wlv.char_attr = 0; |
Bram Moolenaar | a74fda6 | 2019-10-19 17:38:03 +0200 | [diff] [blame] | 2621 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2622 | } |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2623 | #ifdef FEAT_PROP_POPUP |
| 2624 | // override with text property highlight when "override" is TRUE |
| 2625 | if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2626 | wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr); |
Bram Moolenaar | 4d2031f | 2022-08-05 20:03:55 +0100 | [diff] [blame] | 2627 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2628 | } |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2629 | |
| 2630 | // combine attribute with 'wincolor' |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2631 | if (wlv.win_attr != 0) |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2632 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2633 | if (wlv.char_attr == 0) |
| 2634 | wlv.char_attr = wlv.win_attr; |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2635 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2636 | wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr); |
Bram Moolenaar | 024dbd2 | 2019-11-02 22:00:15 +0100 | [diff] [blame] | 2637 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2638 | |
| 2639 | // Get the next character to put on the screen. |
| 2640 | |
| 2641 | // The "p_extra" points to the extra stuff that is inserted to |
| 2642 | // represent special characters (non-printable stuff) and other |
| 2643 | // things. When all characters are the same, c_extra is used. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2644 | // If wlv.c_final is set, it will compulsorily be used at the end. |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2645 | // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 2646 | // "p_extra[n_extra]". |
| 2647 | // For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2648 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2649 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2650 | if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2651 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2652 | c = (wlv.n_extra == 1 && wlv.c_final != NUL) |
| 2653 | ? wlv.c_final : wlv.c_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2654 | mb_c = c; // doesn't handle non-utf-8 multi-byte! |
| 2655 | if (enc_utf8 && utf_char2len(c) > 1) |
| 2656 | { |
| 2657 | mb_utf8 = TRUE; |
| 2658 | u8cc[0] = 0; |
| 2659 | c = 0xc0; |
| 2660 | } |
| 2661 | else |
| 2662 | mb_utf8 = FALSE; |
| 2663 | } |
| 2664 | else |
| 2665 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2666 | c = *wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2667 | if (has_mbyte) |
| 2668 | { |
| 2669 | mb_c = c; |
| 2670 | if (enc_utf8) |
| 2671 | { |
| 2672 | // If the UTF-8 character is more than one byte: |
| 2673 | // Decode it into "mb_c". |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2674 | mb_l = utfc_ptr2len(wlv.p_extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2675 | mb_utf8 = FALSE; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2676 | if (mb_l > wlv.n_extra) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2677 | mb_l = 1; |
| 2678 | else if (mb_l > 1) |
| 2679 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2680 | mb_c = utfc_ptr2char(wlv.p_extra, u8cc); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2681 | mb_utf8 = TRUE; |
| 2682 | c = 0xc0; |
| 2683 | } |
| 2684 | } |
| 2685 | else |
| 2686 | { |
| 2687 | // if this is a DBCS character, put it in "mb_c" |
| 2688 | mb_l = MB_BYTE2LEN(c); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2689 | if (mb_l >= wlv.n_extra) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2690 | mb_l = 1; |
| 2691 | else if (mb_l > 1) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2692 | mb_c = (c << 8) + wlv.p_extra[1]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2693 | } |
| 2694 | if (mb_l == 0) // at the NUL at end-of-line |
| 2695 | mb_l = 1; |
| 2696 | |
| 2697 | // If a double-width char doesn't fit display a '>' in the |
| 2698 | // last column. |
| 2699 | if (( |
| 2700 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2701 | wp->w_p_rl ? (wlv.col <= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2702 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2703 | (wlv.col >= wp->w_width - 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2704 | && (*mb_char2cells)(mb_c) == 2) |
| 2705 | { |
| 2706 | c = '>'; |
| 2707 | mb_c = c; |
| 2708 | mb_l = 1; |
| 2709 | mb_utf8 = FALSE; |
| 2710 | multi_attr = HL_ATTR(HLF_AT); |
| 2711 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 2712 | if (wlv.cul_attr) |
| 2713 | multi_attr = hl_combine_attr( |
| 2714 | multi_attr, wlv.cul_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2715 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2716 | multi_attr = hl_combine_attr(wlv.win_attr, multi_attr); |
Bram Moolenaar | 92e25ab | 2019-11-26 22:39:10 +0100 | [diff] [blame] | 2717 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2718 | // put the pointer back to output the double-width |
| 2719 | // character at the start of the next line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2720 | ++wlv.n_extra; |
| 2721 | --wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2722 | } |
| 2723 | else |
| 2724 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2725 | wlv.n_extra -= mb_l - 1; |
| 2726 | wlv.p_extra += mb_l - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2727 | } |
| 2728 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2729 | ++wlv.p_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2730 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2731 | --wlv.n_extra; |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2732 | #if defined(FEAT_PROP_POPUP) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2733 | if (wlv.n_extra <= 0) |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2734 | { |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 2735 | // Only restore search_attr and area_attr after "n_extra" in |
| 2736 | // the next screen line is also done. |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2737 | if (wlv.saved_n_extra <= 0) |
| 2738 | { |
| 2739 | if (search_attr == 0) |
| 2740 | search_attr = saved_search_attr; |
| 2741 | if (area_attr == 0 && *ptr != NUL) |
| 2742 | area_attr = saved_area_attr; |
Bram Moolenaar | 637862f | 2022-11-24 23:04:02 +0000 | [diff] [blame] | 2743 | |
| 2744 | if (wlv.extra_for_textprop) |
| 2745 | // wlv.extra_attr should be used at this position but |
| 2746 | // not any further. |
| 2747 | reset_extra_attr = TRUE; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2748 | } |
Bram Moolenaar | 637862f | 2022-11-24 23:04:02 +0000 | [diff] [blame] | 2749 | |
| 2750 | wlv.extra_for_textprop = FALSE; |
| 2751 | in_linebreak = FALSE; |
Bram Moolenaar | e38fc86 | 2022-08-11 17:24:50 +0100 | [diff] [blame] | 2752 | } |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 2753 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2754 | } |
| 2755 | else |
| 2756 | { |
| 2757 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2758 | int c0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2759 | #endif |
zeertzjq | e500ae8 | 2023-08-17 22:35:26 +0200 | [diff] [blame] | 2760 | char_u *prev_ptr = ptr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2761 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2762 | // Get a character from the line itself. |
| 2763 | c = *ptr; |
| 2764 | #ifdef FEAT_LINEBREAK |
| 2765 | c0 = *ptr; |
| 2766 | #endif |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2767 | if (c == NUL) |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2768 | { |
| 2769 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2770 | // text is finished, may display a "below" virtual text |
| 2771 | did_line = TRUE; |
| 2772 | #endif |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2773 | // no more cells to skip |
| 2774 | skip_cells = 0; |
Christian Brabandt | a899b27 | 2025-06-28 18:40:15 +0200 | [diff] [blame] | 2775 | #ifdef FEAT_TERMINAL |
| 2776 | if (term_show_buffer(wp->w_buffer) |
Christian Brabandt | 66b72f4 | 2025-06-29 22:22:05 +0200 | [diff] [blame] | 2777 | && wlv.vcol == 0 |
Christian Brabandt | a899b27 | 2025-06-28 18:40:15 +0200 | [diff] [blame] | 2778 | && wlv.win_attr == term_get_attr(wp, lnum, -1)) |
| 2779 | // reset highlighting attribute |
| 2780 | wlv.win_attr = 0; |
| 2781 | #endif |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2782 | } |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 2783 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2784 | if (has_mbyte) |
| 2785 | { |
| 2786 | mb_c = c; |
| 2787 | if (enc_utf8) |
| 2788 | { |
| 2789 | // If the UTF-8 character is more than one byte: Decode it |
| 2790 | // into "mb_c". |
| 2791 | mb_l = utfc_ptr2len(ptr); |
| 2792 | mb_utf8 = FALSE; |
| 2793 | if (mb_l > 1) |
| 2794 | { |
| 2795 | mb_c = utfc_ptr2char(ptr, u8cc); |
| 2796 | // Overlong encoded ASCII or ASCII with composing char |
| 2797 | // is displayed normally, except a NUL. |
| 2798 | if (mb_c < 0x80) |
| 2799 | { |
| 2800 | c = mb_c; |
| 2801 | #ifdef FEAT_LINEBREAK |
| 2802 | c0 = mb_c; |
| 2803 | #endif |
| 2804 | } |
| 2805 | mb_utf8 = TRUE; |
| 2806 | |
| 2807 | // At start of the line we can have a composing char. |
| 2808 | // Draw it as a space with a composing char. |
| 2809 | if (utf_iscomposing(mb_c)) |
| 2810 | { |
| 2811 | int i; |
| 2812 | |
| 2813 | for (i = Screen_mco - 1; i > 0; --i) |
| 2814 | u8cc[i] = u8cc[i - 1]; |
| 2815 | u8cc[0] = mb_c; |
| 2816 | mb_c = ' '; |
| 2817 | } |
| 2818 | } |
| 2819 | |
| 2820 | if ((mb_l == 1 && c >= 0x80) |
| 2821 | || (mb_l >= 1 && mb_c == 0) |
| 2822 | || (mb_l > 1 && (!vim_isprintc(mb_c)))) |
| 2823 | { |
| 2824 | // Illegal UTF-8 byte: display as <xx>. |
| 2825 | // Non-BMP character : display as ? or fullwidth ?. |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2826 | transchar_hex(wlv.extra, mb_c); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2827 | # ifdef FEAT_RIGHTLEFT |
| 2828 | if (wp->w_p_rl) // reverse |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2829 | rl_mirror(wlv.extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2830 | # endif |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2831 | wlv.p_extra = wlv.extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2832 | c = *wlv.p_extra; |
| 2833 | mb_c = mb_ptr2char_adv(&wlv.p_extra); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2834 | mb_utf8 = (c >= 0x80); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2835 | wlv.n_extra = (int)STRLEN(wlv.p_extra); |
| 2836 | wlv.c_extra = NUL; |
| 2837 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2838 | if (area_attr == 0 && search_attr == 0) |
| 2839 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2840 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2841 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2842 | wlv.win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2843 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2844 | } |
| 2845 | } |
| 2846 | else if (mb_l == 0) // at the NUL at end-of-line |
| 2847 | mb_l = 1; |
| 2848 | #ifdef FEAT_ARABIC |
| 2849 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 2850 | { |
| 2851 | // Do Arabic shaping. |
| 2852 | int pc, pc1, nc; |
| 2853 | int pcc[MAX_MCO]; |
| 2854 | |
| 2855 | // The idea of what is the previous and next |
| 2856 | // character depends on 'rightleft'. |
| 2857 | if (wp->w_p_rl) |
| 2858 | { |
| 2859 | pc = prev_c; |
| 2860 | pc1 = prev_c1; |
| 2861 | nc = utf_ptr2char(ptr + mb_l); |
| 2862 | prev_c1 = u8cc[0]; |
| 2863 | } |
| 2864 | else |
| 2865 | { |
| 2866 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
| 2867 | nc = prev_c; |
| 2868 | pc1 = pcc[0]; |
| 2869 | } |
| 2870 | prev_c = mb_c; |
| 2871 | |
| 2872 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
| 2873 | } |
| 2874 | else |
| 2875 | prev_c = mb_c; |
| 2876 | #endif |
| 2877 | } |
| 2878 | else // enc_dbcs |
| 2879 | { |
| 2880 | mb_l = MB_BYTE2LEN(c); |
| 2881 | if (mb_l == 0) // at the NUL at end-of-line |
| 2882 | mb_l = 1; |
| 2883 | else if (mb_l > 1) |
| 2884 | { |
| 2885 | // We assume a second byte below 32 is illegal. |
| 2886 | // Hopefully this is OK for all double-byte encodings! |
| 2887 | if (ptr[1] >= 32) |
| 2888 | mb_c = (c << 8) + ptr[1]; |
| 2889 | else |
| 2890 | { |
| 2891 | if (ptr[1] == NUL) |
| 2892 | { |
| 2893 | // head byte at end of line |
| 2894 | mb_l = 1; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2895 | transchar_nonprint(wp->w_buffer, wlv.extra, c); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 2896 | wlv.n_extra = (int)STRLEN(wlv.extra) - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2897 | } |
| 2898 | else |
| 2899 | { |
| 2900 | // illegal tail byte |
| 2901 | mb_l = 2; |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2902 | STRCPY(wlv.extra, "XX"); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 2903 | wlv.n_extra = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2904 | } |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 2905 | wlv.p_extra = wlv.extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2906 | wlv.c_extra = NUL; |
| 2907 | wlv.c_final = NUL; |
| 2908 | c = *wlv.p_extra++; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2909 | if (area_attr == 0 && search_attr == 0) |
| 2910 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2911 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2912 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2913 | wlv.win_attr, HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2914 | // save current attr |
| 2915 | saved_attr2 = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2916 | } |
| 2917 | mb_c = c; |
| 2918 | } |
| 2919 | } |
| 2920 | } |
| 2921 | // If a double-width char doesn't fit display a '>' in the |
| 2922 | // last column; the character is displayed at the start of the |
| 2923 | // next line. |
| 2924 | if (( |
| 2925 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2926 | wp->w_p_rl ? (wlv.col <= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2927 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2928 | (wlv.col >= wp->w_width - 1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2929 | && (*mb_char2cells)(mb_c) == 2) |
| 2930 | { |
| 2931 | c = '>'; |
| 2932 | mb_c = c; |
| 2933 | mb_utf8 = FALSE; |
| 2934 | mb_l = 1; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2935 | multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2936 | // Put pointer back so that the character will be |
| 2937 | // displayed at the start of the next line. |
| 2938 | --ptr; |
| 2939 | #ifdef FEAT_CONCEAL |
| 2940 | did_decrement_ptr = TRUE; |
| 2941 | #endif |
| 2942 | } |
| 2943 | else if (*ptr != NUL) |
| 2944 | ptr += mb_l - 1; |
| 2945 | |
| 2946 | // If a double-width char doesn't fit at the left side display |
| 2947 | // a '<' in the first column. Don't do this for unprintable |
| 2948 | // characters. |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 2949 | if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2950 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2951 | wlv.n_extra = 1; |
| 2952 | wlv.c_extra = MB_FILLER_CHAR; |
| 2953 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2954 | c = ' '; |
| 2955 | if (area_attr == 0 && search_attr == 0) |
| 2956 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2957 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 2958 | wlv.extra_attr = hl_combine_attr( |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 2959 | wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 2960 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2961 | } |
| 2962 | mb_c = c; |
| 2963 | mb_utf8 = FALSE; |
| 2964 | mb_l = 1; |
| 2965 | } |
| 2966 | |
| 2967 | } |
| 2968 | ++ptr; |
| 2969 | |
| 2970 | if (extra_check) |
| 2971 | { |
| 2972 | #ifdef FEAT_SPELL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2973 | // Check spelling (unless at the end of the line). |
| 2974 | // Only do this when there is no syntax highlighting, the |
| 2975 | // @Spell cluster is not used or the current syntax item |
| 2976 | // contains the @Spell cluster. |
Bram Moolenaar | 7751d1d | 2019-10-18 20:37:08 +0200 | [diff] [blame] | 2977 | v = (long)(ptr - line); |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 2978 | if (spv->spv_has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2979 | { |
| 2980 | spell_attr = 0; |
Christian Brabandt | afa23d1 | 2022-08-09 12:25:10 +0100 | [diff] [blame] | 2981 | // do not calculate cap_col at the end of the line or when |
| 2982 | // only white space is following |
| 2983 | if (c != 0 && (*skipwhite(prev_ptr) != NUL) && ( |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2984 | # ifdef FEAT_SYN_HL |
| 2985 | !has_syntax || |
| 2986 | # endif |
| 2987 | can_spell)) |
| 2988 | { |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 2989 | char_u *p; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2990 | int len; |
| 2991 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 2992 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2993 | if (has_mbyte) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2994 | v -= mb_l - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 2995 | |
| 2996 | // Use nextline[] if possible, it has the start of the |
| 2997 | // next line concatenated. |
| 2998 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 2999 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 3000 | else |
| 3001 | p = prev_ptr; |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3002 | spv->spv_cap_col -= (int)(prev_ptr - line); |
| 3003 | len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col, |
| 3004 | spv->spv_unchanged); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3005 | word_end = v + len; |
| 3006 | |
| 3007 | // In Insert mode only highlight a word that |
| 3008 | // doesn't touch the cursor. |
| 3009 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3010 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3011 | && wp->w_cursor.lnum == lnum |
| 3012 | && wp->w_cursor.col >= |
| 3013 | (colnr_T)(prev_ptr - line) |
| 3014 | && wp->w_cursor.col < (colnr_T)word_end) |
| 3015 | { |
| 3016 | spell_hlf = HLF_COUNT; |
| 3017 | spell_redraw_lnum = lnum; |
| 3018 | } |
| 3019 | |
| 3020 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
| 3021 | && (p - nextline) + len > nextline_idx) |
| 3022 | { |
| 3023 | // Remember that the good word continues at the |
| 3024 | // start of the next line. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3025 | spv->spv_checked_lnum = lnum + 1; |
| 3026 | spv->spv_checked_col = (p - nextline) + len |
| 3027 | - nextline_idx; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | // Turn index into actual attributes. |
| 3031 | if (spell_hlf != HLF_COUNT) |
| 3032 | spell_attr = highlight_attr[spell_hlf]; |
| 3033 | |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3034 | if (spv->spv_cap_col > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3035 | { |
| 3036 | if (p != prev_ptr |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3037 | && (p - nextline) + spv->spv_cap_col |
| 3038 | >= nextline_idx) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3039 | { |
| 3040 | // Remember that the word in the next line |
| 3041 | // must start with a capital. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3042 | spv->spv_capcol_lnum = lnum + 1; |
| 3043 | spv->spv_cap_col = ((p - nextline) |
| 3044 | + spv->spv_cap_col - nextline_idx); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3045 | } |
| 3046 | else |
| 3047 | // Compute the actual column. |
Luuk van Baal | 30805a1 | 2023-05-27 22:22:10 +0100 | [diff] [blame] | 3048 | spv->spv_cap_col += (prev_ptr - line); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3049 | } |
| 3050 | } |
| 3051 | } |
| 3052 | if (spell_attr != 0) |
| 3053 | { |
| 3054 | if (!attr_pri) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3055 | wlv.char_attr = hl_combine_attr(wlv.char_attr, |
| 3056 | spell_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3057 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3058 | wlv.char_attr = hl_combine_attr(spell_attr, |
| 3059 | wlv.char_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3060 | } |
| 3061 | #endif |
| 3062 | #ifdef FEAT_LINEBREAK |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 3063 | // we don't want linebreak to apply for lines that start with |
| 3064 | // leading spaces, followed by long letters (since it would add |
| 3065 | // a break at the beginning of a line and this might be unexpected) |
| 3066 | // |
| 3067 | // So only allow to linebreak, once we have found chars not in |
| 3068 | // 'breakat' in the line. |
| 3069 | if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL && |
| 3070 | !VIM_ISBREAK((int)*ptr)) |
| 3071 | wlv.need_lbr = TRUE; |
| 3072 | #endif |
| 3073 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3074 | // Found last space before word: check for line break. |
Christian Brabandt | dd75fcf | 2023-10-11 21:51:19 +0200 | [diff] [blame] | 3075 | if (wp->w_p_lbr && c0 == c && wlv.need_lbr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3076 | && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr)) |
| 3077 | { |
Bram Moolenaar | 20e0c3d | 2021-08-31 20:57:55 +0200 | [diff] [blame] | 3078 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) |
| 3079 | : 0; |
| 3080 | char_u *p = ptr - (mb_off + 1); |
Bram Moolenaar | 7f9969c | 2022-07-25 18:13:54 +0100 | [diff] [blame] | 3081 | chartabsize_T cts; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3082 | |
zeertzjq | ce53e3e | 2023-09-01 18:49:30 +0200 | [diff] [blame] | 3083 | init_chartabsize_arg(&cts, wp, lnum, wlv.vcol |
| 3084 | # ifdef FEAT_PROP_POPUP |
| 3085 | - vcol_first_char, |
| 3086 | # endif |
| 3087 | line, p); |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3088 | # ifdef FEAT_PROP_POPUP |
| 3089 | // do not want virtual text counted here |
| 3090 | cts.cts_has_prop_with_text = FALSE; |
| 3091 | # endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3092 | wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1; |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3093 | clear_chartabsize_arg(&cts); |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 3094 | |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 3095 | if (on_last_col && c != TAB) |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 3096 | // Do not continue search/match highlighting over the |
Bram Moolenaar | 0bbca54 | 2022-01-11 13:14:54 +0000 | [diff] [blame] | 3097 | // line break, but for TABs the highlighting should |
| 3098 | // include the complete width of the character |
Bram Moolenaar | 0c359af | 2021-11-29 19:18:57 +0000 | [diff] [blame] | 3099 | search_attr = 0; |
Bram Moolenaar | a06e345 | 2021-05-29 17:56:37 +0200 | [diff] [blame] | 3100 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3101 | if (c == TAB && wlv.n_extra + wlv.col > wp->w_width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3102 | # ifdef FEAT_VARTABS |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3103 | wlv.n_extra = tabstop_padding(wlv.vcol, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3104 | wp->w_buffer->b_p_ts, |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3105 | wp->w_buffer->b_p_vts_array) - 1; |
| 3106 | # else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3107 | wlv.n_extra = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3108 | - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3109 | # endif |
| 3110 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3111 | wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
| 3112 | wlv.c_final = NUL; |
Bram Moolenaar | 52de3a8 | 2022-08-10 13:12:03 +0100 | [diff] [blame] | 3113 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3114 | if (wlv.n_extra > 0 && c != TAB) |
Bram Moolenaar | 6b839ac | 2021-11-29 21:12:35 +0000 | [diff] [blame] | 3115 | in_linebreak = TRUE; |
Bram Moolenaar | 3569c0d | 2021-12-02 11:34:21 +0000 | [diff] [blame] | 3116 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3117 | if (VIM_ISWHITE(c)) |
| 3118 | { |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 3119 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3120 | if (c == TAB) |
| 3121 | // See "Tab alignment" below. |
| 3122 | FIX_FOR_BOGUSCOLS; |
Bram Moolenaar | 912bc4a | 2019-12-01 18:58:11 +0100 | [diff] [blame] | 3123 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3124 | if (!wp->w_p_list) |
| 3125 | c = ' '; |
| 3126 | } |
| 3127 | } |
| 3128 | #endif |
zeertzjq | abc8081 | 2023-09-24 23:32:18 +0200 | [diff] [blame] | 3129 | if (wp->w_p_list) |
| 3130 | { |
| 3131 | in_multispace = c == ' ' && (*ptr == ' ' |
| 3132 | || (prev_ptr > line && prev_ptr[-1] == ' ')); |
| 3133 | if (!in_multispace) |
| 3134 | multispace_pos = 0; |
| 3135 | } |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3136 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3137 | // 'list': Change char 160 to 'nbsp' and space to 'space' |
| 3138 | // setting in 'listchars'. But not when the character is |
| 3139 | // followed by a composing character (use mb_l to check that). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3140 | if (wp->w_p_list |
| 3141 | && ((((c == 160 && mb_l == 1) |
| 3142 | || (mb_utf8 |
| 3143 | && ((mb_c == 160 && mb_l == 2) |
| 3144 | || (mb_c == 0x202f && mb_l == 3)))) |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3145 | && wp->w_lcs_chars.nbsp) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3146 | || (c == ' ' |
| 3147 | && mb_l == 1 |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3148 | && (wp->w_lcs_chars.space |
| 3149 | || (in_multispace |
| 3150 | && wp->w_lcs_chars.multispace != NULL)) |
Bram Moolenaar | 91478ae | 2021-02-03 15:58:13 +0100 | [diff] [blame] | 3151 | && ptr - line >= leadcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3152 | && ptr - line <= trailcol))) |
| 3153 | { |
zeertzjq | f14b8ba | 2021-09-10 16:58:30 +0200 | [diff] [blame] | 3154 | if (in_multispace && wp->w_lcs_chars.multispace != NULL) |
| 3155 | { |
| 3156 | c = wp->w_lcs_chars.multispace[multispace_pos++]; |
| 3157 | if (wp->w_lcs_chars.multispace[multispace_pos] == NUL) |
| 3158 | multispace_pos = 0; |
| 3159 | } |
| 3160 | else |
| 3161 | c = (c == ' ') ? wp->w_lcs_chars.space |
| 3162 | : wp->w_lcs_chars.nbsp; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3163 | if (area_attr == 0 && search_attr == 0) |
| 3164 | { |
| 3165 | n_attr = 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3166 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3167 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3168 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3169 | } |
| 3170 | mb_c = c; |
| 3171 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3172 | { |
| 3173 | mb_utf8 = TRUE; |
| 3174 | u8cc[0] = 0; |
| 3175 | c = 0xc0; |
| 3176 | } |
| 3177 | else |
| 3178 | mb_utf8 = FALSE; |
| 3179 | } |
| 3180 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3181 | if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol) |
| 3182 | || (leadcol != 0 && ptr < line + leadcol))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3183 | { |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3184 | if (leadcol != 0 && in_multispace && ptr < line + leadcol |
| 3185 | && wp->w_lcs_chars.leadmultispace != NULL) |
| 3186 | { |
| 3187 | c = wp->w_lcs_chars.leadmultispace[multispace_pos++]; |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3188 | if (wp->w_lcs_chars.leadmultispace[multispace_pos] |
| 3189 | == NUL) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3190 | multispace_pos = 0; |
| 3191 | } |
| 3192 | |
| 3193 | else if (ptr > line + trailcol && wp->w_lcs_chars.trail) |
| 3194 | c = wp->w_lcs_chars.trail; |
| 3195 | |
| 3196 | else if (ptr < line + leadcol && wp->w_lcs_chars.lead) |
| 3197 | c = wp->w_lcs_chars.lead; |
| 3198 | |
zeertzjq | 2e7cba3 | 2022-06-10 15:30:32 +0100 | [diff] [blame] | 3199 | else if (leadcol != 0 && wp->w_lcs_chars.space) |
Bram Moolenaar | aca12fd | 2022-06-07 10:16:15 +0100 | [diff] [blame] | 3200 | c = wp->w_lcs_chars.space; |
| 3201 | |
| 3202 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3203 | if (!attr_pri) |
| 3204 | { |
| 3205 | n_attr = 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3206 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3207 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3208 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3209 | } |
| 3210 | mb_c = c; |
| 3211 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3212 | { |
| 3213 | mb_utf8 = TRUE; |
| 3214 | u8cc[0] = 0; |
| 3215 | c = 0xc0; |
| 3216 | } |
| 3217 | else |
| 3218 | mb_utf8 = FALSE; |
| 3219 | } |
| 3220 | } |
| 3221 | |
| 3222 | // Handling of non-printable characters. |
| 3223 | if (!vim_isprintc(c)) |
| 3224 | { |
| 3225 | // when getting a character from the file, we may have to |
| 3226 | // turn it into something else on the way to putting it |
| 3227 | // into "ScreenLines". |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3228 | if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3229 | { |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3230 | int tab_len = 0; |
| 3231 | long vcol_adjusted = wlv.vcol; // removed showbreak len |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3232 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3233 | char_u *sbr = get_showbreak_value(wp); |
Bram Moolenaar | ee85702 | 2019-11-09 23:26:40 +0100 | [diff] [blame] | 3234 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3235 | // only adjust the tab_len, when at the first column |
| 3236 | // after the showbreak value was drawn |
Bram Moolenaar | e49f9ac | 2022-09-21 15:41:28 +0100 | [diff] [blame] | 3237 | if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3238 | vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3239 | #endif |
| 3240 | // tab amount depends on current column |
| 3241 | #ifdef FEAT_VARTABS |
| 3242 | tab_len = tabstop_padding(vcol_adjusted, |
| 3243 | wp->w_buffer->b_p_ts, |
| 3244 | wp->w_buffer->b_p_vts_array) - 1; |
| 3245 | #else |
| 3246 | tab_len = (int)wp->w_buffer->b_p_ts |
| 3247 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 3248 | #endif |
| 3249 | |
| 3250 | #ifdef FEAT_LINEBREAK |
| 3251 | if (!wp->w_p_lbr || !wp->w_p_list) |
| 3252 | #endif |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3253 | { |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3254 | // tab amount depends on current column |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3255 | wlv.n_extra = tab_len; |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3256 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3257 | #ifdef FEAT_LINEBREAK |
| 3258 | else |
| 3259 | { |
| 3260 | char_u *p; |
| 3261 | int len; |
| 3262 | int i; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3263 | int saved_nextra = wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3264 | |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3265 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3266 | if (wlv.vcol_off_co > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3267 | // there are characters to conceal |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3268 | tab_len += wlv.vcol_off_co; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3269 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3270 | // boguscols before FIX_FOR_BOGUSCOLS macro from above |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3271 | if (wp->w_p_list && wp->w_lcs_chars.tab1 |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3272 | && old_boguscols > 0 |
| 3273 | && wlv.n_extra > tab_len) |
| 3274 | tab_len += wlv.n_extra - tab_len; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3275 | # endif |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3276 | if (tab_len > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3277 | { |
Bram Moolenaar | c67c89c | 2022-12-02 16:39:44 +0000 | [diff] [blame] | 3278 | // If wlv.n_extra > 0, it gives the number of chars |
| 3279 | // to use for a tab, else we need to calculate the |
| 3280 | // width for a tab. |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3281 | int tab2_len = mb_char2len(wp->w_lcs_chars.tab2); |
| 3282 | len = tab_len * tab2_len; |
| 3283 | if (wp->w_lcs_chars.tab3) |
| 3284 | len += mb_char2len(wp->w_lcs_chars.tab3) |
| 3285 | - tab2_len; |
| 3286 | if (wlv.n_extra > 0) |
| 3287 | len += wlv.n_extra - tab_len; |
| 3288 | c = wp->w_lcs_chars.tab1; |
| 3289 | p = alloc(len + 1); |
| 3290 | if (p == NULL) |
| 3291 | wlv.n_extra = 0; |
| 3292 | else |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3293 | { |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3294 | vim_memset(p, ' ', len); |
| 3295 | p[len] = NUL; |
| 3296 | vim_free(wlv.p_extra_free); |
| 3297 | wlv.p_extra_free = p; |
| 3298 | for (i = 0; i < tab_len; i++) |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3299 | { |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3300 | int lcs = wp->w_lcs_chars.tab2; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3301 | |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3302 | if (*p == NUL) |
| 3303 | { |
| 3304 | tab_len = i; |
| 3305 | break; |
| 3306 | } |
| 3307 | |
| 3308 | // if tab3 is given, use it for the last |
| 3309 | // char |
| 3310 | if (wp->w_lcs_chars.tab3 |
| 3311 | && i == tab_len - 1) |
| 3312 | lcs = wp->w_lcs_chars.tab3; |
| 3313 | p += mb_char2bytes(lcs, p); |
| 3314 | wlv.n_extra += mb_char2len(lcs) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3315 | - (saved_nextra > 0 ? 1 : 0); |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3316 | } |
| 3317 | wlv.p_extra = wlv.p_extra_free; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3318 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3319 | // n_extra will be increased by |
| 3320 | // FIX_FOX_BOGUSCOLS macro below, so need to |
| 3321 | // adjust for that here |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3322 | if (wlv.vcol_off_co > 0) |
| 3323 | wlv.n_extra -= wlv.vcol_off_co; |
Bram Moolenaar | 89a54b4 | 2021-09-07 20:45:31 +0200 | [diff] [blame] | 3324 | # endif |
Bram Moolenaar | 2b7b4f7 | 2022-10-08 11:46:02 +0100 | [diff] [blame] | 3325 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3326 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3327 | } |
| 3328 | #endif |
| 3329 | #ifdef FEAT_CONCEAL |
| 3330 | { |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3331 | int vc_saved = wlv.vcol_off_co; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3332 | |
| 3333 | // Tab alignment should be identical regardless of |
| 3334 | // 'conceallevel' value. So tab compensates of all |
| 3335 | // previous concealed characters, and thus resets |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3336 | // vcol_off_co and boguscols accumulated so far in the |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3337 | // line. Note that the tab can be longer than |
| 3338 | // 'tabstop' when there are concealed characters. |
| 3339 | FIX_FOR_BOGUSCOLS; |
| 3340 | |
| 3341 | // Make sure, the highlighting for the tab char will be |
| 3342 | // correctly set further below (effectively reverts the |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 3343 | // FIX_FOR_BOGUSCOLS macro). |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3344 | if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3345 | && wp->w_lcs_chars.tab1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3346 | tab_len += vc_saved; |
| 3347 | } |
| 3348 | #endif |
| 3349 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3350 | if (wp->w_p_list) |
| 3351 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3352 | c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3) |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3353 | ? wp->w_lcs_chars.tab3 |
| 3354 | : wp->w_lcs_chars.tab1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3355 | #ifdef FEAT_LINEBREAK |
h-east | 194555c | 2023-03-02 18:49:09 +0000 | [diff] [blame] | 3356 | if (wp->w_p_lbr && wlv.p_extra != NULL |
| 3357 | && *wlv.p_extra != NUL) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3358 | wlv.c_extra = NUL; // using p_extra from above |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3359 | else |
| 3360 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3361 | wlv.c_extra = wp->w_lcs_chars.tab2; |
| 3362 | wlv.c_final = wp->w_lcs_chars.tab3; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3363 | n_attr = tab_len + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3364 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3365 | HL_ATTR(HLF_8)); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3366 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3367 | mb_c = c; |
| 3368 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3369 | { |
| 3370 | mb_utf8 = TRUE; |
| 3371 | u8cc[0] = 0; |
| 3372 | c = 0xc0; |
| 3373 | } |
| 3374 | } |
| 3375 | else |
| 3376 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3377 | wlv.c_final = NUL; |
| 3378 | wlv.c_extra = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3379 | c = ' '; |
| 3380 | } |
| 3381 | } |
| 3382 | else if (c == NUL |
Bram Moolenaar | 234c3fa | 2023-02-12 14:42:15 +0000 | [diff] [blame] | 3383 | && wlv.n_extra == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3384 | && (wp->w_p_list |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3385 | || ((wlv.fromcol >= 0 || fromcol_prev >= 0) |
| 3386 | && wlv.tocol > wlv.vcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3387 | && VIsual_mode != Ctrl_V |
| 3388 | && ( |
| 3389 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3390 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3391 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3392 | (wlv.col < wp->w_width)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3393 | && !(noinvcur |
| 3394 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3395 | && (colnr_T)wlv.vcol == wp->w_virtcol))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3396 | && lcs_eol_one > 0) |
| 3397 | { |
| 3398 | // Display a '$' after the line or highlight an extra |
| 3399 | // character if the line break is included. |
| 3400 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 3401 | // For a diff line the highlighting continues after the |
| 3402 | // "$". |
| 3403 | if ( |
| 3404 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3405 | wlv.diff_hlf == (hlf_T)0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3406 | # ifdef LINE_ATTR |
| 3407 | && |
| 3408 | # endif |
| 3409 | # endif |
| 3410 | # ifdef LINE_ATTR |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3411 | wlv.line_attr == 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3412 | # endif |
| 3413 | ) |
| 3414 | #endif |
| 3415 | { |
| 3416 | // In virtualedit, visual selections may extend |
| 3417 | // beyond end of line. |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3418 | if (!(area_highlighting && virtual_active() |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3419 | && wlv.tocol != MAXCOL |
| 3420 | && wlv.vcol < wlv.tocol)) |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 3421 | wlv.p_extra = (char_u *)""; |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3422 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3423 | } |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3424 | if (wp->w_p_list && wp->w_lcs_chars.eol > 0) |
| 3425 | c = wp->w_lcs_chars.eol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3426 | else |
| 3427 | c = ' '; |
| 3428 | lcs_eol_one = -1; |
| 3429 | --ptr; // put it back at the NUL |
| 3430 | if (!attr_pri) |
| 3431 | { |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3432 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3433 | HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3434 | n_attr = 1; |
| 3435 | } |
| 3436 | mb_c = c; |
| 3437 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3438 | { |
| 3439 | mb_utf8 = TRUE; |
| 3440 | u8cc[0] = 0; |
| 3441 | c = 0xc0; |
| 3442 | } |
| 3443 | else |
| 3444 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3445 | } |
| 3446 | else if (c != NUL) |
| 3447 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3448 | wlv.p_extra = transchar_buf(wp->w_buffer, c); |
| 3449 | if (wlv.n_extra == 0) |
| 3450 | wlv.n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3451 | #ifdef FEAT_RIGHTLEFT |
| 3452 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3453 | rl_mirror(wlv.p_extra); // reverse "<12>" |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3454 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3455 | wlv.c_extra = NUL; |
| 3456 | wlv.c_final = NUL; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3457 | #ifdef FEAT_LINEBREAK |
| 3458 | if (wp->w_p_lbr) |
| 3459 | { |
| 3460 | char_u *p; |
| 3461 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3462 | c = *wlv.p_extra; |
| 3463 | p = alloc(wlv.n_extra + 1); |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 3464 | if (p == NULL) |
| 3465 | wlv.n_extra = 0; |
| 3466 | else |
| 3467 | { |
| 3468 | vim_memset(p, ' ', wlv.n_extra); |
| 3469 | STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1); |
| 3470 | p[wlv.n_extra] = NUL; |
| 3471 | vim_free(wlv.p_extra_free); |
| 3472 | wlv.p_extra_free = wlv.p_extra = p; |
| 3473 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3474 | } |
| 3475 | else |
| 3476 | #endif |
| 3477 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3478 | wlv.n_extra = byte2cells(c) - 1; |
| 3479 | c = *wlv.p_extra++; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3480 | } |
| 3481 | if (!attr_pri) |
| 3482 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3483 | n_attr = wlv.n_extra + 1; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3484 | wlv.extra_attr = hl_combine_attr(wlv.win_attr, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3485 | HL_ATTR(HLF_8)); |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3486 | #ifdef FEAT_PROP_POPUP |
| 3487 | if (text_prop_type != NULL && |
| 3488 | text_prop_flags & PT_FLAG_OVERRIDE) |
| 3489 | wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr); |
| 3490 | #endif |
| 3491 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3492 | saved_attr2 = wlv.char_attr; // save current attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3493 | } |
| 3494 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3495 | } |
| 3496 | else if (VIsual_active |
| 3497 | && (VIsual_mode == Ctrl_V |
| 3498 | || VIsual_mode == 'v') |
| 3499 | && virtual_active() |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3500 | && wlv.tocol != MAXCOL |
| 3501 | && wlv.vcol < wlv.tocol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3502 | && ( |
| 3503 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3504 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3505 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3506 | (wlv.col < wp->w_width))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3507 | { |
| 3508 | c = ' '; |
| 3509 | --ptr; // put it back at the NUL |
| 3510 | } |
| 3511 | #if defined(LINE_ATTR) |
| 3512 | else if (( |
| 3513 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3514 | wlv.diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3515 | # endif |
| 3516 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3517 | wlv.win_attr != 0 || |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3518 | # endif |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3519 | wlv.line_attr != 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3520 | ) && ( |
| 3521 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3522 | wp->w_p_rl ? (wlv.col >= 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3523 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3524 | (wlv.col |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3525 | # ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3526 | - wlv.boguscols |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3527 | # endif |
| 3528 | < wp->w_width))) |
| 3529 | { |
| 3530 | // Highlight until the right side of the window |
| 3531 | c = ' '; |
| 3532 | --ptr; // put it back at the NUL |
| 3533 | |
| 3534 | // Remember we do the char for line highlighting. |
| 3535 | ++did_line_attr; |
| 3536 | |
| 3537 | // don't do search HL for the rest of the line |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3538 | if (wlv.line_attr != 0 && wlv.char_attr == search_attr |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3539 | && (did_line_attr > 1 |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3540 | || (wp->w_p_list && |
| 3541 | wp->w_lcs_chars.eol > 0))) |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3542 | wlv.char_attr = wlv.line_attr; |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3543 | #ifdef FEAT_SIGNS |
| 3544 | // At end of line: if Sign is present with line highlight, reset char_attr |
Christian Brabandt | e1eaae2 | 2023-08-19 22:36:12 +0200 | [diff] [blame] | 3545 | // but not when cursorline is active |
| 3546 | if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE |
| 3547 | && !(wp->w_p_cul && lnum == wp->w_cursor.lnum)) |
Christian Brabandt | dbeadf0 | 2023-08-19 15:35:04 +0200 | [diff] [blame] | 3548 | wlv.char_attr = wlv.sattr.sat_linehl; |
| 3549 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3550 | # ifdef FEAT_DIFF |
Yee Cheng Chin | 9943d47 | 2025-03-26 19:41:02 +0100 | [diff] [blame] | 3551 | if (wlv.diff_hlf == HLF_TXD || wlv.diff_hlf == HLF_TXA) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3552 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3553 | wlv.diff_hlf = HLF_CHD; |
| 3554 | if (vi_attr == 0 || wlv.char_attr != vi_attr) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3555 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3556 | wlv.char_attr = HL_ATTR(wlv.diff_hlf); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3557 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3558 | && wp->w_p_culopt_flags != CULOPT_NBR |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3559 | && (!wlv.cul_screenline |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3560 | || (wlv.vcol >= left_curline_col |
| 3561 | && wlv.vcol <= right_curline_col))) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3562 | wlv.char_attr = hl_combine_attr( |
| 3563 | wlv.char_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3564 | } |
| 3565 | } |
| 3566 | # endif |
| 3567 | # ifdef FEAT_TERMINAL |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3568 | if (wlv.win_attr != 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3569 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3570 | wlv.char_attr = wlv.win_attr; |
Bram Moolenaar | a381773 | 2019-10-16 16:31:44 +0200 | [diff] [blame] | 3571 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3572 | && wp->w_p_culopt_flags != CULOPT_NBR) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3573 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3574 | if (!wlv.cul_screenline |
| 3575 | || (wlv.vcol >= left_curline_col |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3576 | && wlv.vcol <= right_curline_col)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3577 | wlv.char_attr = hl_combine_attr( |
| 3578 | wlv.char_attr, HL_ATTR(HLF_CUL)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3579 | } |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3580 | else if (wlv.line_attr) |
| 3581 | wlv.char_attr = hl_combine_attr( |
| 3582 | wlv.char_attr, wlv.line_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3583 | } |
| 3584 | # endif |
| 3585 | } |
| 3586 | #endif |
| 3587 | } |
| 3588 | |
| 3589 | #ifdef FEAT_CONCEAL |
| 3590 | if ( wp->w_p_cole > 0 |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 3591 | && (wp != curwin || lnum != wp->w_cursor.lnum |
| 3592 | || conceal_cursor_line(wp)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3593 | && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
| 3594 | && !(lnum_in_visual_area |
| 3595 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
| 3596 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3597 | wlv.char_attr = conceal_attr; |
LemonBoy | 9830db6 | 2022-05-08 21:25:20 +0100 | [diff] [blame] | 3598 | if (((prev_syntax_id != syntax_seqnr |
| 3599 | && (syntax_flags & HL_CONCEAL) != 0) |
| 3600 | || has_match_conc > 1) |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 3601 | && (syn_get_sub_char() != NUL |
| 3602 | || (has_match_conc && match_conc) |
| 3603 | || wp->w_p_cole == 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3604 | && wp->w_p_cole != 3) |
| 3605 | { |
| 3606 | // First time at this concealed item: display one |
| 3607 | // character. |
Bram Moolenaar | 211dd3f | 2020-06-25 20:07:04 +0200 | [diff] [blame] | 3608 | if (has_match_conc && match_conc) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3609 | c = match_conc; |
| 3610 | else if (syn_get_sub_char() != NUL) |
| 3611 | c = syn_get_sub_char(); |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3612 | else if (wp->w_lcs_chars.conceal != NUL) |
| 3613 | c = wp->w_lcs_chars.conceal; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3614 | else |
| 3615 | c = ' '; |
| 3616 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 3617 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3618 | // When the first char to be concealed is double-width, |
| 3619 | // need to advance one more virtual column. |
| 3620 | wlv.n_extra++; |
| 3621 | |
| 3622 | mb_c = c; |
| 3623 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3624 | { |
| 3625 | mb_utf8 = TRUE; |
| 3626 | u8cc[0] = 0; |
| 3627 | c = 0xc0; |
| 3628 | } |
| 3629 | else |
| 3630 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3631 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3632 | prev_syntax_id = syntax_seqnr; |
| 3633 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3634 | if (wlv.n_extra > 0) |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 3635 | wlv.vcol_off_co += wlv.n_extra; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3636 | wlv.vcol += wlv.n_extra; |
| 3637 | if (wp->w_p_wrap && wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3638 | { |
| 3639 | # ifdef FEAT_RIGHTLEFT |
| 3640 | if (wp->w_p_rl) |
| 3641 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3642 | wlv.col -= wlv.n_extra; |
| 3643 | wlv.boguscols -= wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3644 | } |
| 3645 | else |
| 3646 | # endif |
| 3647 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3648 | wlv.boguscols += wlv.n_extra; |
| 3649 | wlv.col += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3650 | } |
| 3651 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3652 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3653 | n_attr = 0; |
| 3654 | } |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3655 | else if (skip_cells == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3656 | { |
| 3657 | is_concealing = TRUE; |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3658 | skip_cells = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3659 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3660 | } |
| 3661 | else |
| 3662 | { |
| 3663 | prev_syntax_id = 0; |
| 3664 | is_concealing = FALSE; |
| 3665 | } |
| 3666 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 3667 | if (skip_cells > 0 && did_decrement_ptr) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3668 | // not showing the '>', put pointer back to avoid getting stuck |
| 3669 | ++ptr; |
| 3670 | |
| 3671 | #endif // FEAT_CONCEAL |
| 3672 | } |
| 3673 | |
| 3674 | #ifdef FEAT_CONCEAL |
| 3675 | // In the cursor line and we may be concealing characters: correct |
| 3676 | // the cursor column when we reach its position. |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3677 | // With 'virtualedit' we may never reach cursor position, but we still |
| 3678 | // need to correct the cursor column, so do that at end of line. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3679 | if (!did_wcol && wlv.draw_state == WL_LINE |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 3680 | && in_curline && conceal_cursor_line(wp) |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3681 | && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL)) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3682 | { |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3683 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3684 | if (wp->w_p_rl) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3685 | wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3686 | else |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3687 | # endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3688 | wp->w_wcol = wlv.col - wlv.boguscols; |
zeertzjq | 253ff4d | 2024-03-13 20:38:26 +0100 | [diff] [blame] | 3689 | if (wlv.vcol + skip_cells < wp->w_virtcol) |
| 3690 | // Cursor beyond end of the line with 'virtualedit'. |
| 3691 | wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3692 | wp->w_wrow = wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3693 | did_wcol = TRUE; |
| 3694 | curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3695 | # ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 6a07644 | 2020-11-15 20:32:58 +0100 | [diff] [blame] | 3696 | curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED); |
Bram Moolenaar | 1efefda | 2020-11-17 19:22:06 +0100 | [diff] [blame] | 3697 | # endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3698 | } |
| 3699 | #endif |
| 3700 | |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3701 | // Use "wlv.extra_attr", but don't override visual selection |
| 3702 | // highlighting, unless text property overrides. |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 3703 | // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero. |
| 3704 | if (wlv.n_attr_skip == 0 && n_attr > 0 |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3705 | && wlv.draw_state == WL_LINE |
Bram Moolenaar | 677a39f | 2022-08-14 16:50:42 +0100 | [diff] [blame] | 3706 | && (!attr_pri |
| 3707 | #ifdef FEAT_PROP_POPUP |
| 3708 | || (text_prop_flags & PT_FLAG_OVERRIDE) |
| 3709 | #endif |
| 3710 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3711 | { |
| 3712 | #ifdef LINE_ATTR |
Bram Moolenaar | 45e4eea | 2022-12-01 18:38:02 +0000 | [diff] [blame] | 3713 | if (wlv.line_attr) |
| 3714 | wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3715 | else |
| 3716 | #endif |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3717 | wlv.char_attr = wlv.extra_attr; |
Bram Moolenaar | 6ac16f0 | 2022-11-24 22:42:29 +0000 | [diff] [blame] | 3718 | #ifdef FEAT_PROP_POPUP |
| 3719 | if (reset_extra_attr) |
| 3720 | { |
| 3721 | reset_extra_attr = FALSE; |
| 3722 | wlv.extra_attr = 0; |
| 3723 | } |
| 3724 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
| 3728 | // XIM don't send preedit_start and preedit_end, but they send |
| 3729 | // preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 3730 | // im_is_preediting() here. |
| 3731 | if (p_imst == IM_ON_THE_SPOT |
| 3732 | && xic != NULL |
| 3733 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 2495910 | 2022-05-07 20:01:16 +0100 | [diff] [blame] | 3734 | && (State & MODE_INSERT) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3735 | && !p_imdisable |
| 3736 | && im_is_preediting() |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3737 | && wlv.draw_state == WL_LINE) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3738 | { |
| 3739 | colnr_T tcol; |
| 3740 | |
| 3741 | if (preedit_end_col == MAXCOL) |
| 3742 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
| 3743 | else |
| 3744 | tcol = preedit_end_col; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3745 | if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3746 | { |
| 3747 | if (feedback_old_attr < 0) |
| 3748 | { |
| 3749 | feedback_col = 0; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3750 | feedback_old_attr = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3751 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3752 | wlv.char_attr = im_get_feedback_attr(feedback_col); |
| 3753 | if (wlv.char_attr < 0) |
| 3754 | wlv.char_attr = feedback_old_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3755 | feedback_col++; |
| 3756 | } |
| 3757 | else if (feedback_old_attr >= 0) |
| 3758 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3759 | wlv.char_attr = feedback_old_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3760 | feedback_old_attr = -1; |
| 3761 | feedback_col = 0; |
| 3762 | } |
| 3763 | } |
| 3764 | #endif |
| 3765 | // Handle the case where we are in column 0 but not on the first |
| 3766 | // character of the line and the user wants us to show us a |
zeertzjq | 08a83a0 | 2025-02-20 22:04:09 +0100 | [diff] [blame] | 3767 | // special character (via 'listchars' option "precedes:<char>"). |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3768 | if (lcs_prec_todo != NUL |
| 3769 | && wp->w_p_list |
Bram Moolenaar | f6196f4 | 2022-10-02 21:29:55 +0100 | [diff] [blame] | 3770 | && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0) |
| 3771 | : wp->w_leftcol > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3772 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3773 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3774 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3775 | && wlv.draw_state > WL_NR |
zeertzjq | 13f100e | 2025-02-21 19:49:44 +0100 | [diff] [blame] | 3776 | && skip_cells <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3777 | && c != NUL) |
| 3778 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3779 | c = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3780 | lcs_prec_todo = NUL; |
| 3781 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 3782 | { |
| 3783 | // Double-width character being overwritten by the "precedes" |
| 3784 | // character, need to fill up half the character. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3785 | wlv.c_extra = MB_FILLER_CHAR; |
| 3786 | wlv.c_final = NUL; |
| 3787 | wlv.n_extra = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3788 | n_attr = 2; |
Bram Moolenaar | fc1b2d0 | 2022-11-16 22:12:57 +0000 | [diff] [blame] | 3789 | wlv.extra_attr = |
| 3790 | hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3791 | } |
| 3792 | mb_c = c; |
| 3793 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3794 | { |
| 3795 | mb_utf8 = TRUE; |
| 3796 | u8cc[0] = 0; |
| 3797 | c = 0xc0; |
| 3798 | } |
| 3799 | else |
| 3800 | mb_utf8 = FALSE; // don't draw as UTF-8 |
| 3801 | if (!attr_pri) |
| 3802 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3803 | saved_attr3 = wlv.char_attr; // save current attr |
| 3804 | wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3805 | n_attr3 = 1; |
| 3806 | } |
| 3807 | } |
| 3808 | |
| 3809 | // At end of the text line or just after the last character. |
| 3810 | if ((c == NUL |
| 3811 | #if defined(LINE_ATTR) |
| 3812 | || did_line_attr == 1 |
| 3813 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3814 | ) && wlv.eol_hl_off == 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3815 | { |
| 3816 | #ifdef FEAT_SEARCH_EXTRA |
| 3817 | // flag to indicate whether prevcol equals startcol of search_hl or |
| 3818 | // one of the matches |
| 3819 | int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl, |
| 3820 | (long)(ptr - line) - (c == NUL)); |
| 3821 | #endif |
| 3822 | // Invert at least one char, used for Visual and empty line or |
| 3823 | // highlight match at end of line. If it's beyond the last |
| 3824 | // char on the screen, just overwrite that one (tricky!) Not |
| 3825 | // needed when a '$' was displayed for 'list'. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3826 | if (wp->w_lcs_chars.eol == lcs_eol_one |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 3827 | && ((area_attr != 0 && wlv.vcol == wlv.fromcol |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3828 | && (VIsual_mode != Ctrl_V |
| 3829 | || lnum == VIsual.lnum |
| 3830 | || lnum == curwin->w_cursor.lnum) |
| 3831 | && c == NUL) |
| 3832 | #ifdef FEAT_SEARCH_EXTRA |
| 3833 | // highlight 'hlsearch' match at end of line |
| 3834 | || (prevcol_hl_flag |
| 3835 | # ifdef FEAT_SYN_HL |
| 3836 | && !(wp->w_p_cul && lnum == wp->w_cursor.lnum |
| 3837 | && !(wp == curwin && VIsual_active)) |
| 3838 | # endif |
| 3839 | # ifdef FEAT_DIFF |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3840 | && wlv.diff_hlf == (hlf_T)0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3841 | # endif |
| 3842 | # if defined(LINE_ATTR) |
| 3843 | && did_line_attr <= 1 |
| 3844 | # endif |
| 3845 | ) |
| 3846 | #endif |
| 3847 | )) |
| 3848 | { |
| 3849 | int n = 0; |
| 3850 | |
| 3851 | #ifdef FEAT_RIGHTLEFT |
| 3852 | if (wp->w_p_rl) |
| 3853 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3854 | if (wlv.col < 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3855 | n = 1; |
| 3856 | } |
| 3857 | else |
| 3858 | #endif |
| 3859 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3860 | if (wlv.col >= wp->w_width) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3861 | n = -1; |
| 3862 | } |
| 3863 | if (n != 0) |
| 3864 | { |
| 3865 | // At the window boundary, highlight the last character |
| 3866 | // instead (better than nothing). |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3867 | wlv.off += n; |
| 3868 | wlv.col += n; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3869 | } |
| 3870 | else |
| 3871 | { |
| 3872 | // Add a blank character to highlight. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3873 | ScreenLines[wlv.off] = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3874 | if (enc_utf8) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3875 | ScreenLinesUC[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3876 | } |
| 3877 | #ifdef FEAT_SEARCH_EXTRA |
| 3878 | if (area_attr == 0) |
| 3879 | { |
| 3880 | // Use attributes from match with highest priority among |
| 3881 | // 'search_hl' and the match list. |
| 3882 | get_search_match_hl(wp, &screen_search_hl, |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3883 | (long)(ptr - line), &wlv.char_attr); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3884 | } |
| 3885 | #endif |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3886 | ScreenAttrs[wlv.off] = wlv.char_attr; |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 3887 | ScreenCols[wlv.off] = wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3888 | #ifdef FEAT_RIGHTLEFT |
| 3889 | if (wp->w_p_rl) |
| 3890 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3891 | --wlv.col; |
| 3892 | --wlv.off; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3893 | } |
| 3894 | else |
| 3895 | #endif |
| 3896 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3897 | ++wlv.col; |
| 3898 | ++wlv.off; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3899 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3900 | ++wlv.vcol; |
| 3901 | wlv.eol_hl_off = 1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3902 | } |
| 3903 | } |
| 3904 | |
| 3905 | // At end of the text line. |
| 3906 | if (c == NUL) |
| 3907 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3908 | #ifdef FEAT_PROP_POPUP |
| 3909 | if (text_prop_follows) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3910 | { |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3911 | // Put the pointer back to the NUL. |
| 3912 | --ptr; |
| 3913 | c = ' '; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3914 | } |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3915 | else |
| 3916 | #endif |
| 3917 | { |
| 3918 | draw_screen_line(wp, &wlv); |
| 3919 | |
| 3920 | // Update w_cline_height and w_cline_folded if the cursor line |
| 3921 | // was updated (saves a call to plines() later). |
zeertzjq | f4ccada | 2024-12-17 20:50:19 +0100 | [diff] [blame] | 3922 | if (in_curline) |
Bram Moolenaar | 9d9a20e | 2023-02-11 13:49:01 +0000 | [diff] [blame] | 3923 | { |
| 3924 | curwin->w_cline_row = startrow; |
| 3925 | curwin->w_cline_height = wlv.row - startrow; |
| 3926 | #ifdef FEAT_FOLDING |
| 3927 | curwin->w_cline_folded = FALSE; |
| 3928 | #endif |
| 3929 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 3930 | } |
| 3931 | break; |
| 3932 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | // Show "extends" character from 'listchars' if beyond the line end and |
| 3936 | // 'list' is set. |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3937 | if (wp->w_lcs_chars.ext != NUL |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3938 | && wlv.draw_state == WL_LINE |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3939 | && wp->w_p_list |
| 3940 | && !wp->w_p_wrap |
| 3941 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3942 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3943 | #endif |
| 3944 | && ( |
| 3945 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3946 | wp->w_p_rl ? wlv.col == 0 : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3947 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3948 | wlv.col == wp->w_width - 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3949 | && (*ptr != NUL |
Bram Moolenaar | c3a483f | 2022-08-14 19:37:36 +0100 | [diff] [blame] | 3950 | || lcs_eol_one > 0 |
| 3951 | || (wlv.n_extra > 0 && (wlv.c_extra != NUL |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 3952 | || *wlv.p_extra != NUL)) |
| 3953 | #ifdef FEAT_PROP_POPUP |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 3954 | || text_prop_next <= last_textprop_text_idx |
zeertzjq | 6a38972 | 2023-08-27 19:04:14 +0200 | [diff] [blame] | 3955 | #endif |
| 3956 | )) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3957 | { |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 3958 | c = wp->w_lcs_chars.ext; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3959 | wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3960 | mb_c = c; |
| 3961 | if (enc_utf8 && utf_char2len(c) > 1) |
| 3962 | { |
| 3963 | mb_utf8 = TRUE; |
| 3964 | u8cc[0] = 0; |
| 3965 | c = 0xc0; |
| 3966 | } |
| 3967 | else |
| 3968 | mb_utf8 = FALSE; |
| 3969 | } |
| 3970 | |
| 3971 | #ifdef FEAT_SYN_HL |
| 3972 | // advance to the next 'colorcolumn' |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 3973 | if (wlv.draw_color_col) |
| 3974 | wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3975 | |
| 3976 | // Highlight the cursor column if 'cursorcolumn' is set. But don't |
| 3977 | // highlight the cursor position itself. |
| 3978 | // Also highlight the 'colorcolumn' if it is different than |
| 3979 | // 'cursorcolumn' |
Bram Moolenaar | ad5e563 | 2020-09-15 20:52:26 +0200 | [diff] [blame] | 3980 | // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak' |
| 3981 | // options are set |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3982 | vcol_save_attr = -1; |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3983 | if (((wlv.draw_state == WL_LINE |
| 3984 | || wlv.draw_state == WL_BRI |
| 3985 | || wlv.draw_state == WL_SBR) |
| 3986 | && !lnum_in_visual_area |
| 3987 | && search_attr == 0 |
| 3988 | && area_attr == 0) |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 3989 | # ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 3990 | && wlv.filler_todo <= 0 |
Bram Moolenaar | fabc3ca | 2020-11-05 19:07:21 +0100 | [diff] [blame] | 3991 | # endif |
| 3992 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 3993 | { |
| 3994 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
| 3995 | && lnum != wp->w_cursor.lnum) |
| 3996 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 3997 | vcol_save_attr = wlv.char_attr; |
| 3998 | wlv.char_attr = hl_combine_attr(wlv.char_attr, |
| 3999 | HL_ATTR(HLF_CUC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4000 | } |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4001 | else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4002 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4003 | vcol_save_attr = wlv.char_attr; |
| 4004 | wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4005 | } |
| 4006 | } |
| 4007 | #endif |
| 4008 | |
zeertzjq | 8fc6a1d | 2023-08-20 18:12:54 +0200 | [diff] [blame] | 4009 | if (wlv.draw_state == WL_LINE) |
| 4010 | vcol_prev = wlv.vcol; |
| 4011 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4012 | // Store character to be displayed. |
| 4013 | // Skip characters that are left of the screen for 'nowrap'. |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 4014 | if (wlv.draw_state < WL_LINE || skip_cells <= 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4015 | { |
| 4016 | // Store the character. |
| 4017 | #if defined(FEAT_RIGHTLEFT) |
| 4018 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 4019 | { |
Dominique Pelle | af4a61a | 2021-12-27 17:21:41 +0000 | [diff] [blame] | 4020 | // A double-wide character is: put first half in left cell. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4021 | --wlv.off; |
| 4022 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4023 | } |
| 4024 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4025 | ScreenLines[wlv.off] = c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4026 | if (enc_dbcs == DBCS_JPNU) |
| 4027 | { |
| 4028 | if ((mb_c & 0xff00) == 0x8e00) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4029 | ScreenLines[wlv.off] = 0x8e; |
| 4030 | ScreenLines2[wlv.off] = mb_c & 0xff; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4031 | } |
| 4032 | else if (enc_utf8) |
| 4033 | { |
| 4034 | if (mb_utf8) |
| 4035 | { |
| 4036 | int i; |
| 4037 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4038 | ScreenLinesUC[wlv.off] = mb_c; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4039 | if ((c & 0xff) == 0) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4040 | ScreenLines[wlv.off] = 0x80; // avoid storing zero |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4041 | for (i = 0; i < Screen_mco; ++i) |
| 4042 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4043 | ScreenLinesC[i][wlv.off] = u8cc[i]; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4044 | if (u8cc[i] == 0) |
| 4045 | break; |
| 4046 | } |
| 4047 | } |
| 4048 | else |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4049 | ScreenLinesUC[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4050 | } |
| 4051 | if (multi_attr) |
| 4052 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4053 | ScreenAttrs[wlv.off] = multi_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4054 | multi_attr = 0; |
| 4055 | } |
| 4056 | else |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4057 | ScreenAttrs[wlv.off] = wlv.char_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4058 | |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4059 | if (wlv.draw_state > WL_NR |
| 4060 | #ifdef FEAT_DIFF |
| 4061 | && wlv.filler_todo <= 0 |
| 4062 | #endif |
| 4063 | ) |
| 4064 | ScreenCols[wlv.off] = wlv.vcol; |
| 4065 | else |
| 4066 | ScreenCols[wlv.off] = -1; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 4067 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4068 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 4069 | { |
| 4070 | // Need to fill two screen columns. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4071 | ++wlv.off; |
| 4072 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4073 | if (enc_utf8) |
| 4074 | // UTF-8: Put a 0 in the second screen char. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4075 | ScreenLines[wlv.off] = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4076 | else |
| 4077 | // DBCS: Put second byte in the second screen char. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4078 | ScreenLines[wlv.off] = mb_c & 0xff; |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4079 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4080 | if (wlv.draw_state > WL_NR |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4081 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4082 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4083 | #endif |
| 4084 | ) |
zeertzjq | db54e98 | 2023-09-21 16:33:09 +0200 | [diff] [blame] | 4085 | ScreenCols[wlv.off] = ++wlv.vcol; |
| 4086 | else |
| 4087 | ScreenCols[wlv.off] = -1; |
| 4088 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4089 | // When "wlv.tocol" is halfway a character, set it to the end |
| 4090 | // of the character, otherwise highlighting won't stop. |
| 4091 | if (wlv.tocol == wlv.vcol) |
| 4092 | ++wlv.tocol; |
Bram Moolenaar | b908188 | 2022-07-09 04:56:24 +0100 | [diff] [blame] | 4093 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4094 | #ifdef FEAT_RIGHTLEFT |
| 4095 | if (wp->w_p_rl) |
| 4096 | { |
| 4097 | // now it's time to backup one cell |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4098 | --wlv.off; |
| 4099 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4100 | } |
| 4101 | #endif |
| 4102 | } |
| 4103 | #ifdef FEAT_RIGHTLEFT |
| 4104 | if (wp->w_p_rl) |
| 4105 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4106 | --wlv.off; |
| 4107 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4108 | } |
| 4109 | else |
| 4110 | #endif |
| 4111 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4112 | ++wlv.off; |
| 4113 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | #ifdef FEAT_CONCEAL |
| 4117 | else if (wp->w_p_cole > 0 && is_concealing) |
| 4118 | { |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4119 | int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1; |
| 4120 | |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 4121 | --skip_cells; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4122 | ++wlv.vcol_off_co; |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4123 | if (concealed_wide) |
| 4124 | { |
| 4125 | // When a double-width char is concealed, |
| 4126 | // need to advance one more virtual column. |
| 4127 | ++wlv.vcol; |
| 4128 | ++wlv.vcol_off_co; |
| 4129 | } |
| 4130 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4131 | if (wlv.n_extra > 0) |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4132 | wlv.vcol_off_co += wlv.n_extra; |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4133 | |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4134 | if (wp->w_p_wrap) |
| 4135 | { |
| 4136 | // Special voodoo required if 'wrap' is on. |
| 4137 | // |
| 4138 | // Advance the column indicator to force the line |
| 4139 | // drawing to wrap early. This will make the line |
| 4140 | // take up the same screen space when parts are concealed, |
| 4141 | // so that cursor line computations aren't messed up. |
| 4142 | // |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4143 | // To avoid the fictitious advance of 'wlv.col' causing |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4144 | // trailing junk to be written out of the screen line |
| 4145 | // we are building, 'boguscols' keeps track of the number |
| 4146 | // of bad columns we have advanced. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4147 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4148 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4149 | wlv.vcol += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4150 | # ifdef FEAT_RIGHTLEFT |
| 4151 | if (wp->w_p_rl) |
| 4152 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4153 | wlv.col -= wlv.n_extra; |
| 4154 | wlv.boguscols -= wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4155 | } |
| 4156 | else |
| 4157 | # endif |
| 4158 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4159 | wlv.col += wlv.n_extra; |
| 4160 | wlv.boguscols += wlv.n_extra; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4161 | } |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4162 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4163 | n_attr = 0; |
| 4164 | } |
| 4165 | |
zeertzjq | 010e153 | 2024-03-14 18:22:17 +0100 | [diff] [blame] | 4166 | if (concealed_wide) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4167 | { |
| 4168 | // Need to fill two screen columns. |
| 4169 | # ifdef FEAT_RIGHTLEFT |
| 4170 | if (wp->w_p_rl) |
| 4171 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4172 | --wlv.boguscols; |
| 4173 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4174 | } |
| 4175 | else |
| 4176 | # endif |
| 4177 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4178 | ++wlv.boguscols; |
| 4179 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4180 | } |
| 4181 | } |
| 4182 | |
| 4183 | # ifdef FEAT_RIGHTLEFT |
| 4184 | if (wp->w_p_rl) |
| 4185 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4186 | --wlv.boguscols; |
| 4187 | --wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4188 | } |
| 4189 | else |
| 4190 | # endif |
| 4191 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4192 | ++wlv.boguscols; |
| 4193 | ++wlv.col; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4194 | } |
| 4195 | } |
| 4196 | else |
| 4197 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4198 | if (wlv.n_extra > 0) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4199 | { |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4200 | wlv.vcol += wlv.n_extra; |
| 4201 | wlv.n_extra = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4202 | n_attr = 0; |
| 4203 | } |
| 4204 | } |
| 4205 | |
| 4206 | } |
| 4207 | #endif // FEAT_CONCEAL |
| 4208 | else |
zeertzjq | b557f48 | 2023-08-22 22:07:34 +0200 | [diff] [blame] | 4209 | --skip_cells; |
| 4210 | |
| 4211 | if (wlv.draw_state > WL_NR && skipped_cells > 0) |
| 4212 | { |
| 4213 | wlv.vcol += skipped_cells; |
| 4214 | skipped_cells = 0; |
| 4215 | } |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4216 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4217 | // Only advance the "wlv.vcol" when after the 'number' or |
| 4218 | // 'relativenumber' column. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4219 | if (wlv.draw_state > WL_NR |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4220 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4221 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4222 | #endif |
| 4223 | ) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4224 | ++wlv.vcol; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4225 | |
| 4226 | #ifdef FEAT_SYN_HL |
| 4227 | if (vcol_save_attr >= 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4228 | wlv.char_attr = vcol_save_attr; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4229 | #endif |
| 4230 | |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4231 | // restore attributes after "precedes" in 'listchars' |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4232 | if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 4233 | wlv.char_attr = saved_attr3; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4234 | |
| 4235 | // restore attributes after last 'listchars' or 'number' char |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4236 | if (n_attr > 0 && wlv.draw_state == WL_LINE |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 4237 | && wlv.n_attr_skip == 0 && --n_attr == 0) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4238 | wlv.char_attr = saved_attr2; |
Bram Moolenaar | 37f088e | 2022-12-02 21:50:14 +0000 | [diff] [blame] | 4239 | if (wlv.n_attr_skip > 0) |
| 4240 | --wlv.n_attr_skip; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4241 | |
| 4242 | // At end of screen line and there is more to come: Display the line |
| 4243 | // so far. If there is no more to display it is caught above. |
| 4244 | if (( |
| 4245 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4246 | wp->w_p_rl ? (wlv.col < 0) : |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4247 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4248 | (wlv.col >= wp->w_width)) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4249 | && (wlv.draw_state != WL_LINE |
Bram Moolenaar | 41fb723 | 2021-07-08 12:40:05 +0200 | [diff] [blame] | 4250 | || *ptr != NUL |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4251 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4252 | || wlv.filler_todo > 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4253 | #endif |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4254 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4255 | || text_prop_above || text_prop_follows |
zeertzjq | 4e26a9a | 2023-12-03 17:50:47 +0100 | [diff] [blame] | 4256 | || text_prop_next <= last_textprop_text_idx |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4257 | #endif |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 4258 | || (wp->w_p_list && wp->w_lcs_chars.eol != NUL |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4259 | && lcs_eol_one != -1) |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4260 | || (wlv.n_extra != 0 && (wlv.c_extra != NUL |
| 4261 | || *wlv.p_extra != NUL))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4262 | ) |
| 4263 | { |
| 4264 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 406b5d8 | 2022-10-03 16:44:12 +0100 | [diff] [blame] | 4265 | wlv.col -= wlv.boguscols; |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 4266 | // Apply 'cursorline' and 'wincolor' highlight. |
| 4267 | if (wlv.boguscols != 0 && ( |
| 4268 | # ifdef LINE_ATTR |
| 4269 | wlv.line_attr != 0 || |
| 4270 | # endif |
| 4271 | wlv.win_attr != 0 |
| 4272 | ) |
| 4273 | ) |
| 4274 | { |
| 4275 | int attr = wlv.win_attr; |
| 4276 | # ifdef LINE_ATTR |
| 4277 | if (wlv.line_attr != 0) |
| 4278 | attr = hl_combine_attr(attr, wlv.line_attr); |
| 4279 | # endif |
| 4280 | while (( |
| 4281 | # ifdef FEAT_RIGHTLEFT |
| 4282 | wp->w_p_rl ? wlv.col >= 0 : |
| 4283 | # endif |
| 4284 | wlv.col < wp->w_width)) |
| 4285 | { |
| 4286 | ScreenLines[wlv.off] = ' '; |
| 4287 | if (enc_utf8) |
| 4288 | ScreenLinesUC[wlv.off] = 0; |
| 4289 | ScreenAttrs[wlv.off] = attr; |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4290 | ScreenCols[wlv.off] = wlv.vcol - 1; |
zeertzjq | 21b0a3d | 2024-03-13 20:06:34 +0100 | [diff] [blame] | 4291 | # ifdef FEAT_RIGHTLEFT |
| 4292 | if (wp->w_p_rl) |
| 4293 | { |
| 4294 | wlv.off--; |
| 4295 | wlv.col--; |
| 4296 | wlv.boguscols++; |
| 4297 | } |
| 4298 | else |
| 4299 | # endif |
| 4300 | { |
| 4301 | wlv.off++; |
| 4302 | wlv.col++; |
| 4303 | wlv.boguscols--; |
| 4304 | } |
| 4305 | } |
| 4306 | } |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4307 | wlv_screen_line(wp, &wlv, TRUE); |
Bram Moolenaar | 7500866 | 2022-10-04 22:40:56 +0100 | [diff] [blame] | 4308 | wlv.col += wlv.boguscols; |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4309 | wlv.boguscols = 0; |
Bram Moolenaar | f53e065 | 2023-02-19 14:16:02 +0000 | [diff] [blame] | 4310 | wlv.vcol_off_co = 0; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4311 | #else |
zeertzjq | d0c1b77 | 2024-03-16 15:03:33 +0100 | [diff] [blame] | 4312 | wlv_screen_line(wp, &wlv, TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4313 | #endif |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4314 | ++wlv.row; |
| 4315 | ++wlv.screen_row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4316 | |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4317 | // When not wrapping and finished diff lines, break here. |
| 4318 | if (!wp->w_p_wrap |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4319 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4320 | && wlv.filler_todo <= 0 |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4321 | #endif |
| 4322 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 4323 | && !text_prop_above |
Dylan Thacker-Smith | f548ae7 | 2024-02-24 10:17:11 +0100 | [diff] [blame] | 4324 | && !text_prop_follows |
Bram Moolenaar | 877151b | 2022-10-11 15:29:50 +0100 | [diff] [blame] | 4325 | #endif |
| 4326 | ) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4327 | break; |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4328 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4329 | if (!wp->w_p_wrap && text_prop_follows && !text_prop_above) |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4330 | { |
| 4331 | // do not output more of the line, only the "below" prop |
John Marriott | f51ff96 | 2024-06-02 19:44:11 +0200 | [diff] [blame] | 4332 | ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum); |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4333 | # ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4334 | wlv.dont_use_showbreak = TRUE; |
Bram Moolenaar | 48ca24d | 2022-08-06 22:03:20 +0100 | [diff] [blame] | 4335 | # endif |
| 4336 | } |
| 4337 | #endif |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4338 | |
| 4339 | // When the window is too narrow draw all "@" lines. |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4340 | if (wlv.draw_state != WL_LINE |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4341 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4342 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4343 | #endif |
| 4344 | ) |
| 4345 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4346 | win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT); |
| 4347 | draw_vsep_win(wp, wlv.row); |
| 4348 | wlv.row = endrow; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4349 | } |
| 4350 | |
| 4351 | // When line got too long for screen break here. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4352 | if (wlv.row == endrow) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4353 | { |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4354 | ++wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4355 | break; |
| 4356 | } |
| 4357 | |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4358 | if (screen_cur_row == wlv.screen_row - 1 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4359 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4360 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4361 | #endif |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4362 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | c9dc03f | 2022-09-12 17:51:07 +0100 | [diff] [blame] | 4363 | && !text_prop_above && !text_prop_follows |
Bram Moolenaar | b7963df | 2022-07-31 17:12:43 +0100 | [diff] [blame] | 4364 | #endif |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 4365 | && wp->w_width == Columns) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4366 | { |
| 4367 | // Remember that the line wraps, used for modeless copy. |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4368 | LineWraps[wlv.screen_row - 1] = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4369 | |
| 4370 | // Special trick to make copy/paste of wrapped lines work with |
| 4371 | // xterm/screen: write an extra character beyond the end of |
| 4372 | // the line. This will work with all terminal types |
| 4373 | // (regardless of the xn,am settings). |
| 4374 | // Only do this on a fast tty. |
| 4375 | // Only do this if the cursor is on the current line |
| 4376 | // (something has been written in it). |
| 4377 | // Don't do this for the GUI. |
| 4378 | // Don't do this for double-width characters. |
| 4379 | // Don't do this for a window not at the right screen border. |
| 4380 | if (p_tf |
| 4381 | #ifdef FEAT_GUI |
| 4382 | && !gui.in_use |
| 4383 | #endif |
| 4384 | && !(has_mbyte |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4385 | && ((*mb_off2cells)(LineOffset[wlv.screen_row], |
| 4386 | LineOffset[wlv.screen_row] + screen_Columns) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4387 | == 2 |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4388 | || (*mb_off2cells)( |
| 4389 | LineOffset[wlv.screen_row - 1] |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 4390 | + (int)topframe->fr_width - 2, |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4391 | LineOffset[wlv.screen_row] |
| 4392 | + screen_Columns) == 2))) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4393 | { |
| 4394 | // First make sure we are at the end of the screen line, |
| 4395 | // then output the same character again to let the |
| 4396 | // terminal know about the wrap. If the terminal doesn't |
| 4397 | // auto-wrap, we overwrite the character. |
| 4398 | if (screen_cur_col != wp->w_width) |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4399 | screen_char(LineOffset[wlv.screen_row - 1] |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 4400 | + (unsigned)topframe->fr_width - 1, |
| 4401 | wlv.screen_row - 1, (int)(topframe->fr_width - 1)); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4402 | |
| 4403 | // When there is a multi-byte character, just output a |
| 4404 | // space to keep it simple. |
| 4405 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 4406 | wlv.screen_row - 1] + (topframe->fr_width - 1)]) > 1) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4407 | out_char(' '); |
| 4408 | else |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4409 | out_char(ScreenLines[LineOffset[wlv.screen_row - 1] |
Hirohito Higashi | 3b9b95d | 2025-06-01 20:22:55 +0200 | [diff] [blame] | 4410 | + (topframe->fr_width - 1)]); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4411 | // force a redraw of the first char on the next line |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4412 | ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4413 | screen_start(); // don't know where cursor is now |
| 4414 | } |
| 4415 | } |
| 4416 | |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4417 | win_line_start(wp, &wlv, TRUE); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4418 | |
Bram Moolenaar | eed9d46 | 2021-02-15 20:38:25 +0100 | [diff] [blame] | 4419 | lcs_prec_todo = wp->w_lcs_chars.prec; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4420 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4421 | if (!wlv.dont_use_showbreak |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4422 | # ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4423 | && wlv.filler_todo <= 0 |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4424 | # endif |
Bram Moolenaar | 3ec3b8e | 2022-08-05 21:39:30 +0100 | [diff] [blame] | 4425 | ) |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4426 | wlv.need_showbreak = TRUE; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4427 | #endif |
| 4428 | #ifdef FEAT_DIFF |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4429 | --wlv.filler_todo; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4430 | // When the filler lines are actually below the last line of the |
| 4431 | // file, don't draw the line itself, break here. |
Bram Moolenaar | d7657e9 | 2022-09-20 18:59:30 +0100 | [diff] [blame] | 4432 | if (wlv.filler_todo == 0 && wp->w_botfill) |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4433 | break; |
| 4434 | #endif |
| 4435 | } |
| 4436 | |
| 4437 | } // for every character in the line |
Bram Moolenaar | 05ad5ff | 2019-11-30 22:48:27 +0100 | [diff] [blame] | 4438 | #ifdef FEAT_PROP_POPUP |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4439 | vim_free(text_props); |
| 4440 | vim_free(text_prop_idxs); |
Bram Moolenaar | 1306b36 | 2022-08-06 15:59:06 +0100 | [diff] [blame] | 4441 | vim_free(p_extra_free2); |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4442 | #endif |
| 4443 | |
Bram Moolenaar | c20a419 | 2022-09-21 14:34:28 +0100 | [diff] [blame] | 4444 | vim_free(wlv.p_extra_free); |
zeertzjq | 58e1e01 | 2023-06-04 18:46:28 +0100 | [diff] [blame] | 4445 | vim_free(wlv.saved_p_extra_free); |
Bram Moolenaar | 4d91d34 | 2022-08-06 13:48:20 +0100 | [diff] [blame] | 4446 | return wlv.row; |
Bram Moolenaar | 7528d1f | 2019-09-19 23:06:20 +0200 | [diff] [blame] | 4447 | } |