Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4: |
| 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 | * screen.c: code for displaying on the screen |
| 12 | * |
| 13 | * Output to the screen (console, terminal emulator or GUI window) is minimized |
| 14 | * by remembering what is already on the screen, and only updating the parts |
| 15 | * that changed. |
| 16 | * |
| 17 | * ScreenLines[off] Contains a copy of the whole screen, as it is currently |
| 18 | * displayed (excluding text written by external commands). |
| 19 | * ScreenAttrs[off] Contains the associated attributes. |
| 20 | * LineOffset[row] Contains the offset into ScreenLines*[] and ScreenAttrs[] |
| 21 | * for each line. |
| 22 | * LineWraps[row] Flag for each line whether it wraps to the next line. |
| 23 | * |
| 24 | * For double-byte characters, two consecutive bytes in ScreenLines[] can form |
| 25 | * one character which occupies two display cells. |
| 26 | * For UTF-8 a multi-byte character is converted to Unicode and stored in |
| 27 | * ScreenLinesUC[]. ScreenLines[] contains the first byte only. For an ASCII |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 28 | * character without composing chars ScreenLinesUC[] will be 0 and |
| 29 | * ScreenLinesC[][] is not used. When the character occupies two display |
| 30 | * cells the next byte in ScreenLines[] is 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 31 | * ScreenLinesC[][] contain up to 'maxcombine' composing characters |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 32 | * (drawn on top of the first character). There is 0 after the last one used. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 33 | * ScreenLines2[] is only used for euc-jp to store the second byte if the |
| 34 | * first byte is 0x8e (single-width character). |
| 35 | * |
| 36 | * The screen_*() functions write to the screen and handle updating |
| 37 | * ScreenLines[]. |
| 38 | * |
| 39 | * update_screen() is the function that updates all windows and status lines. |
| 40 | * It is called form the main loop when must_redraw is non-zero. It may be |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 41 | * called from other places when an immediate screen update is needed. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 42 | * |
| 43 | * The part of the buffer that is displayed in a window is set with: |
| 44 | * - w_topline (first buffer line in window) |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 45 | * - w_topfill (filler lines above the first line) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 46 | * - w_leftcol (leftmost window cell in window), |
| 47 | * - w_skipcol (skipped window cells of first line) |
| 48 | * |
| 49 | * Commands that only move the cursor around in a window, do not need to take |
| 50 | * action to update the display. The main loop will check if w_topline is |
| 51 | * valid and update it (scroll the window) when needed. |
| 52 | * |
| 53 | * Commands that scroll a window change w_topline and must call |
| 54 | * check_cursor() to move the cursor into the visible part of the window, and |
| 55 | * call redraw_later(VALID) to have the window displayed by update_screen() |
| 56 | * later. |
| 57 | * |
| 58 | * Commands that change text in the buffer must call changed_bytes() or |
| 59 | * changed_lines() to mark the area that changed and will require updating |
| 60 | * later. The main loop will call update_screen(), which will update each |
| 61 | * window that shows the changed buffer. This assumes text above the change |
| 62 | * can remain displayed as it is. Text after the change may need updating for |
| 63 | * scrolling, folding and syntax highlighting. |
| 64 | * |
| 65 | * Commands that change how a window is displayed (e.g., setting 'list') or |
| 66 | * invalidate the contents of a window in another way (e.g., change fold |
| 67 | * settings), must call redraw_later(NOT_VALID) to have the whole window |
| 68 | * redisplayed by update_screen() later. |
| 69 | * |
| 70 | * Commands that change how a buffer is displayed (e.g., setting 'tabstop') |
| 71 | * must call redraw_curbuf_later(NOT_VALID) to have all the windows for the |
| 72 | * buffer redisplayed by update_screen() later. |
| 73 | * |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 74 | * Commands that change highlighting and possibly cause a scroll too must call |
| 75 | * redraw_later(SOME_VALID) to update the whole window but still use scrolling |
| 76 | * to avoid redrawing everything. But the length of displayed lines must not |
| 77 | * change, use NOT_VALID then. |
| 78 | * |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 79 | * Commands that move the window position must call redraw_later(NOT_VALID). |
| 80 | * TODO: should minimize redrawing by scrolling when possible. |
| 81 | * |
| 82 | * Commands that change everything (e.g., resizing the screen) must call |
| 83 | * redraw_all_later(NOT_VALID) or redraw_all_later(CLEAR). |
| 84 | * |
| 85 | * Things that are handled indirectly: |
| 86 | * - When messages scroll the screen up, msg_scrolled will be set and |
| 87 | * update_screen() called to redraw. |
| 88 | */ |
| 89 | |
| 90 | #include "vim.h" |
| 91 | |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 92 | #define MB_FILLER_CHAR '<' /* character used when a double-width character |
| 93 | * doesn't fit. */ |
| 94 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 95 | /* |
| 96 | * The attributes that are actually active for writing to the screen. |
| 97 | */ |
| 98 | static int screen_attr = 0; |
| 99 | |
| 100 | /* |
| 101 | * Positioning the cursor is reduced by remembering the last position. |
| 102 | * Mostly used by windgoto() and screen_char(). |
| 103 | */ |
| 104 | static int screen_cur_row, screen_cur_col; /* last known cursor position */ |
| 105 | |
| 106 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 107 | static match_T search_hl; /* used for 'hlsearch' highlight matching */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | #ifdef FEAT_FOLDING |
| 111 | static foldinfo_T win_foldinfo; /* info for 'foldcolumn' */ |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 112 | static int compute_foldcolumn(win_T *wp, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 113 | #endif |
| 114 | |
| 115 | /* |
| 116 | * Buffer for one screen line (characters and attributes). |
| 117 | */ |
| 118 | static schar_T *current_ScreenLine; |
| 119 | |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 120 | static void win_update(win_T *wp); |
| 121 | static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 122 | #ifdef FEAT_FOLDING |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 123 | static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row); |
| 124 | static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum); |
| 125 | static void copy_text_attr(int off, char_u *buf, int len, int attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 126 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 127 | static int win_line(win_T *, linenr_T, int, int, int nochange); |
| 128 | static int char_needs_redraw(int off_from, int off_to, int cols); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 129 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 130 | static void screen_line(int row, int coloff, int endcol, int clear_width, int rlflag); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 131 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c), (rl)) |
| 132 | #else |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 133 | static void screen_line(int row, int coloff, int endcol, int clear_width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 134 | # define SCREEN_LINE(r, o, e, c, rl) screen_line((r), (o), (e), (c)) |
| 135 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 136 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 137 | static void draw_vsep_win(win_T *wp, int row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 138 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 139 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 140 | static void redraw_custom_statusline(win_T *wp); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 141 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 142 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 143 | # define SEARCH_HL_PRIORITY 0 |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 144 | static void start_search_hl(void); |
| 145 | static void end_search_hl(void); |
| 146 | static void init_search_hl(win_T *wp); |
| 147 | static void prepare_search_hl(win_T *wp, linenr_T lnum); |
| 148 | static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur); |
| 149 | static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 150 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 151 | static void screen_start_highlight(int attr); |
| 152 | static void screen_char(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 153 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 154 | static void screen_char_2(unsigned off, int row, int col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 155 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 156 | static void screenclear2(void); |
| 157 | static void lineclear(unsigned off, int width); |
| 158 | static void lineinvalid(unsigned off, int width); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 159 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 160 | static void linecopy(int to, int from, win_T *wp); |
| 161 | static void redraw_block(int row, int end, win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 162 | #endif |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 163 | static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del); |
| 164 | static void win_rest_invalid(win_T *wp); |
| 165 | static void msg_pos_mode(void); |
| 166 | static void recording_mode(int attr); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 167 | #if defined(FEAT_WINDOWS) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 168 | static void draw_tabline(void); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 169 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 170 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 171 | static int fillchar_status(int *attr, int is_curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 172 | #endif |
| 173 | #ifdef FEAT_VERTSPLIT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 174 | static int fillchar_vsep(int *attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 175 | #endif |
| 176 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 177 | static void win_redr_custom(win_T *wp, int draw_ruler); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 178 | #endif |
| 179 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 180 | static void win_redr_ruler(win_T *wp, int always); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 181 | #endif |
| 182 | |
| 183 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 184 | /* Ugly global: overrule attribute used by screen_char() */ |
| 185 | static int screen_char_attr = 0; |
| 186 | #endif |
| 187 | |
| 188 | /* |
| 189 | * Redraw the current window later, with update_screen(type). |
| 190 | * Set must_redraw only if not already set to a higher value. |
| 191 | * e.g. if must_redraw is CLEAR, type NOT_VALID will do nothing. |
| 192 | */ |
| 193 | void |
| 194 | redraw_later(type) |
| 195 | int type; |
| 196 | { |
| 197 | redraw_win_later(curwin, type); |
| 198 | } |
| 199 | |
| 200 | void |
| 201 | redraw_win_later(wp, type) |
| 202 | win_T *wp; |
| 203 | int type; |
| 204 | { |
| 205 | if (wp->w_redr_type < type) |
| 206 | { |
| 207 | wp->w_redr_type = type; |
| 208 | if (type >= NOT_VALID) |
| 209 | wp->w_lines_valid = 0; |
| 210 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 211 | must_redraw = type; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | /* |
| 216 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 217 | * after executing a shell command that messes up the screen. |
| 218 | */ |
| 219 | void |
| 220 | redraw_later_clear() |
| 221 | { |
| 222 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 223 | #ifdef FEAT_GUI |
| 224 | if (gui.in_use) |
| 225 | /* Use a code that will reset gui.highlight_mask in |
| 226 | * gui_stop_highlight(). */ |
| 227 | screen_attr = HL_ALL + 1; |
| 228 | else |
| 229 | #endif |
| 230 | /* Use attributes that is very unlikely to appear in text. */ |
| 231 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* |
| 235 | * Mark all windows to be redrawn later. |
| 236 | */ |
| 237 | void |
| 238 | redraw_all_later(type) |
| 239 | int type; |
| 240 | { |
| 241 | win_T *wp; |
| 242 | |
| 243 | FOR_ALL_WINDOWS(wp) |
| 244 | { |
| 245 | redraw_win_later(wp, type); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 250 | * Mark all windows that are editing the current buffer to be updated later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 251 | */ |
| 252 | void |
| 253 | redraw_curbuf_later(type) |
| 254 | int type; |
| 255 | { |
| 256 | redraw_buf_later(curbuf, type); |
| 257 | } |
| 258 | |
| 259 | void |
| 260 | redraw_buf_later(buf, type) |
| 261 | buf_T *buf; |
| 262 | int type; |
| 263 | { |
| 264 | win_T *wp; |
| 265 | |
| 266 | FOR_ALL_WINDOWS(wp) |
| 267 | { |
| 268 | if (wp->w_buffer == buf) |
| 269 | redraw_win_later(wp, type); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | /* |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 274 | * Redraw as soon as possible. When the command line is not scrolled redraw |
| 275 | * right away and restore what was on the command line. |
| 276 | * Return a code indicating what happened. |
| 277 | */ |
| 278 | int |
| 279 | redraw_asap(type) |
| 280 | int type; |
| 281 | { |
| 282 | int rows; |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 283 | int cols = screen_Columns; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 284 | int r; |
| 285 | int ret = 0; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 286 | schar_T *screenline; /* copy from ScreenLines[] */ |
| 287 | sattr_T *screenattr; /* copy from ScreenAttrs[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 288 | #ifdef FEAT_MBYTE |
| 289 | int i; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 290 | u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 291 | u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */ |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 292 | schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 293 | #endif |
| 294 | |
| 295 | redraw_later(type); |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 296 | if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 297 | return ret; |
| 298 | |
| 299 | /* Allocate space to save the text displayed in the command line area. */ |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 300 | rows = screen_Rows - cmdline_row; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 301 | screenline = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 302 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 303 | screenattr = (sattr_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 304 | (long_u)(rows * cols * sizeof(sattr_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 305 | if (screenline == NULL || screenattr == NULL) |
| 306 | ret = 2; |
| 307 | #ifdef FEAT_MBYTE |
| 308 | if (enc_utf8) |
| 309 | { |
| 310 | screenlineUC = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 311 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 312 | if (screenlineUC == NULL) |
| 313 | ret = 2; |
| 314 | for (i = 0; i < p_mco; ++i) |
| 315 | { |
| 316 | screenlineC[i] = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 317 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 318 | if (screenlineC[i] == NULL) |
| 319 | ret = 2; |
| 320 | } |
| 321 | } |
| 322 | if (enc_dbcs == DBCS_JPNU) |
| 323 | { |
| 324 | screenline2 = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 325 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 326 | if (screenline2 == NULL) |
| 327 | ret = 2; |
| 328 | } |
| 329 | #endif |
| 330 | |
| 331 | if (ret != 2) |
| 332 | { |
| 333 | /* Save the text displayed in the command line area. */ |
| 334 | for (r = 0; r < rows; ++r) |
| 335 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 336 | mch_memmove(screenline + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 337 | ScreenLines + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 338 | (size_t)cols * sizeof(schar_T)); |
| 339 | mch_memmove(screenattr + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 340 | ScreenAttrs + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 341 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 342 | #ifdef FEAT_MBYTE |
| 343 | if (enc_utf8) |
| 344 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 345 | mch_memmove(screenlineUC + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 346 | ScreenLinesUC + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 347 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 348 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 349 | mch_memmove(screenlineC[i] + r * cols, |
| 350 | ScreenLinesC[i] + LineOffset[cmdline_row + r], |
| 351 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 352 | } |
| 353 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 354 | mch_memmove(screenline2 + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 355 | ScreenLines2 + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 356 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 357 | #endif |
| 358 | } |
| 359 | |
| 360 | update_screen(0); |
| 361 | ret = 3; |
| 362 | |
| 363 | if (must_redraw == 0) |
| 364 | { |
| 365 | int off = (int)(current_ScreenLine - ScreenLines); |
| 366 | |
| 367 | /* Restore the text displayed in the command line area. */ |
| 368 | for (r = 0; r < rows; ++r) |
| 369 | { |
| 370 | mch_memmove(current_ScreenLine, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 371 | screenline + r * cols, |
| 372 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 373 | mch_memmove(ScreenAttrs + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 374 | screenattr + r * cols, |
| 375 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 376 | #ifdef FEAT_MBYTE |
| 377 | if (enc_utf8) |
| 378 | { |
| 379 | mch_memmove(ScreenLinesUC + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 380 | screenlineUC + r * cols, |
| 381 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 382 | for (i = 0; i < p_mco; ++i) |
| 383 | mch_memmove(ScreenLinesC[i] + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 384 | screenlineC[i] + r * cols, |
| 385 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 386 | } |
| 387 | if (enc_dbcs == DBCS_JPNU) |
| 388 | mch_memmove(ScreenLines2 + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 389 | screenline2 + r * cols, |
| 390 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 391 | #endif |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 392 | SCREEN_LINE(cmdline_row + r, 0, cols, cols, FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 393 | } |
| 394 | ret = 4; |
| 395 | } |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | vim_free(screenline); |
| 399 | vim_free(screenattr); |
| 400 | #ifdef FEAT_MBYTE |
| 401 | if (enc_utf8) |
| 402 | { |
| 403 | vim_free(screenlineUC); |
| 404 | for (i = 0; i < p_mco; ++i) |
| 405 | vim_free(screenlineC[i]); |
| 406 | } |
| 407 | if (enc_dbcs == DBCS_JPNU) |
| 408 | vim_free(screenline2); |
| 409 | #endif |
| 410 | |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 411 | /* Show the intro message when appropriate. */ |
| 412 | maybe_intro_message(); |
| 413 | |
| 414 | setcursor(); |
| 415 | |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 420 | * Changed something in the current window, at buffer line "lnum", that |
| 421 | * requires that line and possibly other lines to be redrawn. |
| 422 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 423 | * Used to remove the "$" from a change command. |
| 424 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 425 | * may become invalid and the whole window will have to be redrawn. |
| 426 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 427 | void |
| 428 | redrawWinline(lnum, invalid) |
| 429 | linenr_T lnum; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 430 | int invalid UNUSED; /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 431 | { |
| 432 | #ifdef FEAT_FOLDING |
| 433 | int i; |
| 434 | #endif |
| 435 | |
| 436 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 437 | curwin->w_redraw_top = lnum; |
| 438 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 439 | curwin->w_redraw_bot = lnum; |
| 440 | redraw_later(VALID); |
| 441 | |
| 442 | #ifdef FEAT_FOLDING |
| 443 | if (invalid) |
| 444 | { |
| 445 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 446 | i = find_wl_entry(curwin, lnum); |
| 447 | if (i >= 0) |
| 448 | curwin->w_lines[i].wl_valid = FALSE; |
| 449 | } |
| 450 | #endif |
| 451 | } |
| 452 | |
| 453 | /* |
| 454 | * update all windows that are editing the current buffer |
| 455 | */ |
| 456 | void |
| 457 | update_curbuf(type) |
| 458 | int type; |
| 459 | { |
| 460 | redraw_curbuf_later(type); |
| 461 | update_screen(type); |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * update_screen() |
| 466 | * |
| 467 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 468 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 469 | */ |
| 470 | void |
| 471 | update_screen(type) |
| 472 | int type; |
| 473 | { |
| 474 | win_T *wp; |
| 475 | static int did_intro = FALSE; |
| 476 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 477 | int did_one; |
| 478 | #endif |
| 479 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 480 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 481 | if (!screen_valid(TRUE)) |
| 482 | return; |
| 483 | |
| 484 | if (must_redraw) |
| 485 | { |
| 486 | if (type < must_redraw) /* use maximal type */ |
| 487 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 488 | |
| 489 | /* must_redraw is reset here, so that when we run into some weird |
| 490 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 491 | * scrolling), or update_topline() in win_update() will cause a |
| 492 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 493 | must_redraw = 0; |
| 494 | } |
| 495 | |
| 496 | /* Need to update w_lines[]. */ |
| 497 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 498 | type = NOT_VALID; |
| 499 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 500 | /* Postpone the redrawing when it's not needed and when being called |
| 501 | * recursively. */ |
| 502 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 503 | { |
| 504 | redraw_later(type); /* remember type for next time */ |
| 505 | must_redraw = type; |
| 506 | if (type > INVERTED_ALL) |
| 507 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 508 | return; |
| 509 | } |
| 510 | |
| 511 | updating_screen = TRUE; |
| 512 | #ifdef FEAT_SYN_HL |
| 513 | ++display_tick; /* let syntax code know we're in a next round of |
| 514 | * display updating */ |
| 515 | #endif |
| 516 | |
| 517 | /* |
| 518 | * if the screen was scrolled up when displaying a message, scroll it down |
| 519 | */ |
| 520 | if (msg_scrolled) |
| 521 | { |
| 522 | clear_cmdline = TRUE; |
| 523 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 524 | type = CLEAR; |
| 525 | else if (type != CLEAR) |
| 526 | { |
| 527 | check_for_delay(FALSE); |
| 528 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 529 | type = CLEAR; |
| 530 | FOR_ALL_WINDOWS(wp) |
| 531 | { |
| 532 | if (W_WINROW(wp) < msg_scrolled) |
| 533 | { |
| 534 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 535 | && wp->w_redr_type < REDRAW_TOP |
| 536 | && wp->w_lines_valid > 0 |
| 537 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 538 | { |
| 539 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 540 | wp->w_redr_type = REDRAW_TOP; |
| 541 | } |
| 542 | else |
| 543 | { |
| 544 | wp->w_redr_type = NOT_VALID; |
| 545 | #ifdef FEAT_WINDOWS |
| 546 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 547 | <= msg_scrolled) |
| 548 | wp->w_redr_status = TRUE; |
| 549 | #endif |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 554 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 555 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 556 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 557 | } |
| 558 | msg_scrolled = 0; |
| 559 | need_wait_return = FALSE; |
| 560 | } |
| 561 | |
| 562 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 563 | compute_cmdrow(); |
| 564 | |
| 565 | /* Check for changed highlighting */ |
| 566 | if (need_highlight_changed) |
| 567 | highlight_changed(); |
| 568 | |
| 569 | if (type == CLEAR) /* first clear screen */ |
| 570 | { |
| 571 | screenclear(); /* will reset clear_cmdline */ |
| 572 | type = NOT_VALID; |
| 573 | } |
| 574 | |
| 575 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 576 | check_for_delay(FALSE); |
| 577 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 578 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 579 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 580 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 581 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 582 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 583 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 584 | curwin->w_redr_type = NOT_VALID; |
| 585 | #endif |
| 586 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 587 | /* |
| 588 | * Only start redrawing if there is really something to do. |
| 589 | */ |
| 590 | if (type == INVERTED) |
| 591 | update_curswant(); |
| 592 | if (curwin->w_redr_type < type |
| 593 | && !((type == VALID |
| 594 | && curwin->w_lines[0].wl_valid |
| 595 | #ifdef FEAT_DIFF |
| 596 | && curwin->w_topfill == curwin->w_old_topfill |
| 597 | && curwin->w_botfill == curwin->w_old_botfill |
| 598 | #endif |
| 599 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 600 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 601 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 602 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 603 | && curwin->w_old_visual_mode == VIsual_mode |
| 604 | && (curwin->w_valid & VALID_VIRTCOL) |
| 605 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 606 | )) |
| 607 | curwin->w_redr_type = type; |
| 608 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 609 | #ifdef FEAT_WINDOWS |
| 610 | /* Redraw the tab pages line if needed. */ |
| 611 | if (redraw_tabline || type >= NOT_VALID) |
| 612 | draw_tabline(); |
| 613 | #endif |
| 614 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 615 | #ifdef FEAT_SYN_HL |
| 616 | /* |
| 617 | * Correct stored syntax highlighting info for changes in each displayed |
| 618 | * buffer. Each buffer must only be done once. |
| 619 | */ |
| 620 | FOR_ALL_WINDOWS(wp) |
| 621 | { |
| 622 | if (wp->w_buffer->b_mod_set) |
| 623 | { |
| 624 | # ifdef FEAT_WINDOWS |
| 625 | win_T *wwp; |
| 626 | |
| 627 | /* Check if we already did this buffer. */ |
| 628 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 629 | if (wwp->w_buffer == wp->w_buffer) |
| 630 | break; |
| 631 | # endif |
| 632 | if ( |
| 633 | # ifdef FEAT_WINDOWS |
| 634 | wwp == wp && |
| 635 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 636 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 637 | syn_stack_apply_changes(wp->w_buffer); |
| 638 | } |
| 639 | } |
| 640 | #endif |
| 641 | |
| 642 | /* |
| 643 | * Go from top to bottom through the windows, redrawing the ones that need |
| 644 | * it. |
| 645 | */ |
| 646 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 647 | did_one = FALSE; |
| 648 | #endif |
| 649 | #ifdef FEAT_SEARCH_EXTRA |
| 650 | search_hl.rm.regprog = NULL; |
| 651 | #endif |
| 652 | FOR_ALL_WINDOWS(wp) |
| 653 | { |
| 654 | if (wp->w_redr_type != 0) |
| 655 | { |
| 656 | cursor_off(); |
| 657 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 658 | if (!did_one) |
| 659 | { |
| 660 | did_one = TRUE; |
| 661 | # ifdef FEAT_SEARCH_EXTRA |
| 662 | start_search_hl(); |
| 663 | # endif |
| 664 | # ifdef FEAT_CLIPBOARD |
| 665 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 666 | if (clip_star.available && clip_isautosel_star()) |
| 667 | clip_update_selection(&clip_star); |
| 668 | if (clip_plus.available && clip_isautosel_plus()) |
| 669 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 670 | # endif |
| 671 | #ifdef FEAT_GUI |
| 672 | /* Remove the cursor before starting to do anything, because |
| 673 | * scrolling may make it difficult to redraw the text under |
| 674 | * it. */ |
| 675 | if (gui.in_use) |
| 676 | gui_undraw_cursor(); |
| 677 | #endif |
| 678 | } |
| 679 | #endif |
| 680 | win_update(wp); |
| 681 | } |
| 682 | |
| 683 | #ifdef FEAT_WINDOWS |
| 684 | /* redraw status line after the window to minimize cursor movement */ |
| 685 | if (wp->w_redr_status) |
| 686 | { |
| 687 | cursor_off(); |
| 688 | win_redr_status(wp); |
| 689 | } |
| 690 | #endif |
| 691 | } |
| 692 | #if defined(FEAT_SEARCH_EXTRA) |
| 693 | end_search_hl(); |
| 694 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 695 | #ifdef FEAT_INS_EXPAND |
| 696 | /* May need to redraw the popup menu. */ |
| 697 | if (pum_visible()) |
| 698 | pum_redraw(); |
| 699 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 700 | |
| 701 | #ifdef FEAT_WINDOWS |
| 702 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 703 | * than going through all buffers (there could be many buffers). */ |
| 704 | for (wp = firstwin; wp != NULL; wp = wp->w_next) |
| 705 | wp->w_buffer->b_mod_set = FALSE; |
| 706 | #else |
| 707 | curbuf->b_mod_set = FALSE; |
| 708 | #endif |
| 709 | |
| 710 | updating_screen = FALSE; |
| 711 | #ifdef FEAT_GUI |
| 712 | gui_may_resize_shell(); |
| 713 | #endif |
| 714 | |
| 715 | /* Clear or redraw the command line. Done last, because scrolling may |
| 716 | * mess up the command line. */ |
| 717 | if (clear_cmdline || redraw_cmdline) |
| 718 | showmode(); |
| 719 | |
| 720 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 721 | if (!did_intro) |
| 722 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 723 | did_intro = TRUE; |
| 724 | |
| 725 | #ifdef FEAT_GUI |
| 726 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 727 | * done. */ |
| 728 | if (gui.in_use) |
| 729 | { |
| 730 | out_flush(); /* required before updating the cursor */ |
| 731 | if (did_one) |
| 732 | gui_update_cursor(FALSE, FALSE); |
| 733 | gui_update_scrollbars(FALSE); |
| 734 | } |
| 735 | #endif |
| 736 | } |
| 737 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 738 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 739 | /* |
| 740 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 741 | * to the 'concealcursor' option. |
| 742 | */ |
| 743 | int |
| 744 | conceal_cursor_line(wp) |
| 745 | win_T *wp; |
| 746 | { |
| 747 | int c; |
| 748 | |
| 749 | if (*wp->w_p_cocu == NUL) |
| 750 | return FALSE; |
| 751 | if (get_real_state() & VISUAL) |
| 752 | c = 'v'; |
| 753 | else if (State & INSERT) |
| 754 | c = 'i'; |
| 755 | else if (State & NORMAL) |
| 756 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 757 | else if (State & CMDLINE) |
| 758 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 759 | else |
| 760 | return FALSE; |
| 761 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 762 | } |
| 763 | |
| 764 | /* |
| 765 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 766 | */ |
| 767 | void |
Bram Moolenaar | 8e46927 | 2010-07-28 19:38:16 +0200 | [diff] [blame] | 768 | conceal_check_cursur_line() |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 769 | { |
| 770 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 771 | { |
| 772 | need_cursor_line_redraw = TRUE; |
| 773 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 774 | * without concealing. */ |
| 775 | curs_columns(TRUE); |
| 776 | } |
| 777 | } |
| 778 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 779 | void |
| 780 | update_single_line(wp, lnum) |
| 781 | win_T *wp; |
| 782 | linenr_T lnum; |
| 783 | { |
| 784 | int row; |
| 785 | int j; |
| 786 | |
| 787 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 788 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 789 | { |
| 790 | # ifdef FEAT_GUI |
| 791 | /* Remove the cursor before starting to do anything, because scrolling |
| 792 | * may make it difficult to redraw the text under it. */ |
| 793 | if (gui.in_use) |
| 794 | gui_undraw_cursor(); |
| 795 | # endif |
| 796 | row = 0; |
| 797 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 798 | { |
| 799 | if (lnum == wp->w_lines[j].wl_lnum) |
| 800 | { |
| 801 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 802 | # ifdef FEAT_SEARCH_EXTRA |
| 803 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 804 | start_search_hl(); |
| 805 | prepare_search_hl(wp, lnum); |
| 806 | # endif |
| 807 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 808 | # if defined(FEAT_SEARCH_EXTRA) |
| 809 | end_search_hl(); |
| 810 | # endif |
| 811 | break; |
| 812 | } |
| 813 | row += wp->w_lines[j].wl_size; |
| 814 | } |
| 815 | # ifdef FEAT_GUI |
| 816 | /* Redraw the cursor */ |
| 817 | if (gui.in_use) |
| 818 | { |
| 819 | out_flush(); /* required before updating the cursor */ |
| 820 | gui_update_cursor(FALSE, FALSE); |
| 821 | } |
| 822 | # endif |
| 823 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 824 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 825 | } |
| 826 | #endif |
| 827 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 828 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 829 | static void update_prepare(void); |
| 830 | static void update_finish(void); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 831 | |
| 832 | /* |
| 833 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 834 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 835 | */ |
| 836 | static void |
| 837 | update_prepare() |
| 838 | { |
| 839 | cursor_off(); |
| 840 | updating_screen = TRUE; |
| 841 | #ifdef FEAT_GUI |
| 842 | /* Remove the cursor before starting to do anything, because scrolling may |
| 843 | * make it difficult to redraw the text under it. */ |
| 844 | if (gui.in_use) |
| 845 | gui_undraw_cursor(); |
| 846 | #endif |
| 847 | #ifdef FEAT_SEARCH_EXTRA |
| 848 | start_search_hl(); |
| 849 | #endif |
| 850 | } |
| 851 | |
| 852 | /* |
| 853 | * Finish updating one or more windows. |
| 854 | */ |
| 855 | static void |
| 856 | update_finish() |
| 857 | { |
| 858 | if (redraw_cmdline) |
| 859 | showmode(); |
| 860 | |
| 861 | # ifdef FEAT_SEARCH_EXTRA |
| 862 | end_search_hl(); |
| 863 | # endif |
| 864 | |
| 865 | updating_screen = FALSE; |
| 866 | |
| 867 | # ifdef FEAT_GUI |
| 868 | gui_may_resize_shell(); |
| 869 | |
| 870 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 871 | * done. */ |
| 872 | if (gui.in_use) |
| 873 | { |
| 874 | out_flush(); /* required before updating the cursor */ |
| 875 | gui_update_cursor(FALSE, FALSE); |
| 876 | gui_update_scrollbars(FALSE); |
| 877 | } |
| 878 | # endif |
| 879 | } |
| 880 | #endif |
| 881 | |
| 882 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 883 | void |
| 884 | update_debug_sign(buf, lnum) |
| 885 | buf_T *buf; |
| 886 | linenr_T lnum; |
| 887 | { |
| 888 | win_T *wp; |
| 889 | int doit = FALSE; |
| 890 | |
| 891 | # ifdef FEAT_FOLDING |
| 892 | win_foldinfo.fi_level = 0; |
| 893 | # endif |
| 894 | |
| 895 | /* update/delete a specific mark */ |
| 896 | FOR_ALL_WINDOWS(wp) |
| 897 | { |
| 898 | if (buf != NULL && lnum > 0) |
| 899 | { |
| 900 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 901 | && lnum < wp->w_botline) |
| 902 | { |
| 903 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 904 | wp->w_redraw_top = lnum; |
| 905 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 906 | wp->w_redraw_bot = lnum; |
| 907 | redraw_win_later(wp, VALID); |
| 908 | } |
| 909 | } |
| 910 | else |
| 911 | redraw_win_later(wp, VALID); |
| 912 | if (wp->w_redr_type != 0) |
| 913 | doit = TRUE; |
| 914 | } |
| 915 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 916 | /* Return when there is nothing to do, screen updating is already |
| 917 | * happening (recursive call) or still starting up. */ |
| 918 | if (!doit || updating_screen |
| 919 | #ifdef FEAT_GUI |
| 920 | || gui.starting |
| 921 | #endif |
| 922 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 923 | return; |
| 924 | |
| 925 | /* update all windows that need updating */ |
| 926 | update_prepare(); |
| 927 | |
| 928 | # ifdef FEAT_WINDOWS |
| 929 | for (wp = firstwin; wp; wp = wp->w_next) |
| 930 | { |
| 931 | if (wp->w_redr_type != 0) |
| 932 | win_update(wp); |
| 933 | if (wp->w_redr_status) |
| 934 | win_redr_status(wp); |
| 935 | } |
| 936 | # else |
| 937 | if (curwin->w_redr_type != 0) |
| 938 | win_update(curwin); |
| 939 | # endif |
| 940 | |
| 941 | update_finish(); |
| 942 | } |
| 943 | #endif |
| 944 | |
| 945 | |
| 946 | #if defined(FEAT_GUI) || defined(PROTO) |
| 947 | /* |
| 948 | * Update a single window, its status line and maybe the command line msg. |
| 949 | * Used for the GUI scrollbar. |
| 950 | */ |
| 951 | void |
| 952 | updateWindow(wp) |
| 953 | win_T *wp; |
| 954 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 955 | /* return if already busy updating */ |
| 956 | if (updating_screen) |
| 957 | return; |
| 958 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 959 | update_prepare(); |
| 960 | |
| 961 | #ifdef FEAT_CLIPBOARD |
| 962 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 963 | if (clip_star.available && clip_isautosel_star()) |
| 964 | clip_update_selection(&clip_star); |
| 965 | if (clip_plus.available && clip_isautosel_plus()) |
| 966 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 967 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 968 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 969 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 970 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 971 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 972 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 973 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 974 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 975 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 976 | if (wp->w_redr_status |
| 977 | # ifdef FEAT_CMDL_INFO |
| 978 | || p_ru |
| 979 | # endif |
| 980 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 981 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 982 | # endif |
| 983 | ) |
| 984 | win_redr_status(wp); |
| 985 | #endif |
| 986 | |
| 987 | update_finish(); |
| 988 | } |
| 989 | #endif |
| 990 | |
| 991 | /* |
| 992 | * Update a single window. |
| 993 | * |
| 994 | * This may cause the windows below it also to be redrawn (when clearing the |
| 995 | * screen or scrolling lines). |
| 996 | * |
| 997 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 998 | * implies the one below it. |
| 999 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1000 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1001 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 1002 | * INVERTED redraw the changed part of the Visual area |
| 1003 | * INVERTED_ALL redraw the whole Visual area |
| 1004 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 1005 | * 2. update lines at the top when scrolled down |
| 1006 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 1007 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1008 | * b_mod_top and b_mod_bot. |
| 1009 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 1010 | * wp->w_redraw_top and wp->w_redr_bot. |
| 1011 | * - continue redrawing when syntax status is invalid. |
| 1012 | * 4. if scrolled up, update lines at the bottom. |
| 1013 | * This results in three areas that may need updating: |
| 1014 | * top: from first row to top_end (when scrolled down) |
| 1015 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1016 | * bot: from bot_start to last row (when scrolled up) |
| 1017 | */ |
| 1018 | static void |
| 1019 | win_update(wp) |
| 1020 | win_T *wp; |
| 1021 | { |
| 1022 | buf_T *buf = wp->w_buffer; |
| 1023 | int type; |
| 1024 | int top_end = 0; /* Below last row of the top area that needs |
| 1025 | updating. 0 when no top area updating. */ |
| 1026 | int mid_start = 999;/* first row of the mid area that needs |
| 1027 | updating. 999 when no mid area updating. */ |
| 1028 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1029 | updating. 0 when no mid area updating. */ |
| 1030 | int bot_start = 999;/* first row of the bot area that needs |
| 1031 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1032 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1033 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1034 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1035 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1036 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1037 | #endif |
| 1038 | |
| 1039 | int row; /* current window row to display */ |
| 1040 | linenr_T lnum; /* current buffer lnum to display */ |
| 1041 | int idx; /* current index in w_lines[] */ |
| 1042 | int srow; /* starting row of the current line */ |
| 1043 | |
| 1044 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1045 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1046 | int i; |
| 1047 | long j; |
| 1048 | static int recursive = FALSE; /* being called recursively */ |
| 1049 | int old_botline = wp->w_botline; |
| 1050 | #ifdef FEAT_FOLDING |
| 1051 | long fold_count; |
| 1052 | #endif |
| 1053 | #ifdef FEAT_SYN_HL |
| 1054 | /* remember what happened to the previous line, to know if |
| 1055 | * check_visual_highlight() can be used */ |
| 1056 | #define DID_NONE 1 /* didn't update a line */ |
| 1057 | #define DID_LINE 2 /* updated a normal line */ |
| 1058 | #define DID_FOLD 3 /* updated a folded line */ |
| 1059 | int did_update = DID_NONE; |
| 1060 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1061 | #endif |
| 1062 | linenr_T mod_top = 0; |
| 1063 | linenr_T mod_bot = 0; |
| 1064 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1065 | int save_got_int; |
| 1066 | #endif |
| 1067 | |
| 1068 | type = wp->w_redr_type; |
| 1069 | |
| 1070 | if (type == NOT_VALID) |
| 1071 | { |
| 1072 | #ifdef FEAT_WINDOWS |
| 1073 | wp->w_redr_status = TRUE; |
| 1074 | #endif |
| 1075 | wp->w_lines_valid = 0; |
| 1076 | } |
| 1077 | |
| 1078 | /* Window is zero-height: nothing to draw. */ |
| 1079 | if (wp->w_height == 0) |
| 1080 | { |
| 1081 | wp->w_redr_type = 0; |
| 1082 | return; |
| 1083 | } |
| 1084 | |
| 1085 | #ifdef FEAT_VERTSPLIT |
| 1086 | /* Window is zero-width: Only need to draw the separator. */ |
| 1087 | if (wp->w_width == 0) |
| 1088 | { |
| 1089 | /* draw the vertical separator right of this window */ |
| 1090 | draw_vsep_win(wp, 0); |
| 1091 | wp->w_redr_type = 0; |
| 1092 | return; |
| 1093 | } |
| 1094 | #endif |
| 1095 | |
| 1096 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1097 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1098 | #endif |
| 1099 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1100 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1101 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1102 | * changes. */ |
| 1103 | i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1104 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1105 | { |
| 1106 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1107 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1108 | } |
| 1109 | else |
| 1110 | #endif |
| 1111 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1112 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1113 | { |
| 1114 | /* |
| 1115 | * When there are both inserted/deleted lines and specific lines to be |
| 1116 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1117 | * everything (only happens when redrawing is off for while). |
| 1118 | */ |
| 1119 | type = NOT_VALID; |
| 1120 | } |
| 1121 | else |
| 1122 | { |
| 1123 | /* |
| 1124 | * Set mod_top to the first line that needs displaying because of |
| 1125 | * changes. Set mod_bot to the first line after the changes. |
| 1126 | */ |
| 1127 | mod_top = wp->w_redraw_top; |
| 1128 | if (wp->w_redraw_bot != 0) |
| 1129 | mod_bot = wp->w_redraw_bot + 1; |
| 1130 | else |
| 1131 | mod_bot = 0; |
| 1132 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1133 | wp->w_redraw_bot = 0; |
| 1134 | if (buf->b_mod_set) |
| 1135 | { |
| 1136 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1137 | { |
| 1138 | mod_top = buf->b_mod_top; |
| 1139 | #ifdef FEAT_SYN_HL |
| 1140 | /* Need to redraw lines above the change that may be included |
| 1141 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1142 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1143 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1144 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1145 | if (mod_top < 1) |
| 1146 | mod_top = 1; |
| 1147 | } |
| 1148 | #endif |
| 1149 | } |
| 1150 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1151 | mod_bot = buf->b_mod_bot; |
| 1152 | |
| 1153 | #ifdef FEAT_SEARCH_EXTRA |
| 1154 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1155 | * change in one line may make the Search highlighting in a |
| 1156 | * previous line invalid. Simple solution: redraw all visible |
| 1157 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1158 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1159 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1160 | if (search_hl.rm.regprog != NULL |
| 1161 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1162 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1163 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1164 | { |
| 1165 | cur = wp->w_match_head; |
| 1166 | while (cur != NULL) |
| 1167 | { |
| 1168 | if (cur->match.regprog != NULL |
| 1169 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1170 | { |
| 1171 | top_to_mod = TRUE; |
| 1172 | break; |
| 1173 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1174 | cur = cur->next; |
| 1175 | } |
| 1176 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1177 | #endif |
| 1178 | } |
| 1179 | #ifdef FEAT_FOLDING |
| 1180 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1181 | { |
| 1182 | linenr_T lnumt, lnumb; |
| 1183 | |
| 1184 | /* |
| 1185 | * A change in a line can cause lines above it to become folded or |
| 1186 | * unfolded. Find the top most buffer line that may be affected. |
| 1187 | * If the line was previously folded and displayed, get the first |
| 1188 | * line of that fold. If the line is folded now, get the first |
| 1189 | * folded line. Use the minimum of these two. |
| 1190 | */ |
| 1191 | |
| 1192 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1193 | * the line below it. If there is no valid entry, use w_topline. |
| 1194 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1195 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1196 | lnumt = wp->w_topline; |
| 1197 | lnumb = MAXLNUM; |
| 1198 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1199 | if (wp->w_lines[i].wl_valid) |
| 1200 | { |
| 1201 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1202 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1203 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1204 | { |
| 1205 | lnumb = wp->w_lines[i].wl_lnum; |
| 1206 | /* When there is a fold column it might need updating |
| 1207 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1208 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1209 | ++lnumb; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1214 | if (mod_top > lnumt) |
| 1215 | mod_top = lnumt; |
| 1216 | |
| 1217 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1218 | --mod_bot; |
| 1219 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1220 | ++mod_bot; |
| 1221 | if (mod_bot < lnumb) |
| 1222 | mod_bot = lnumb; |
| 1223 | } |
| 1224 | #endif |
| 1225 | |
| 1226 | /* When a change starts above w_topline and the end is below |
| 1227 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1228 | * If the end of the change is above w_topline: do like no change was |
| 1229 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1230 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1231 | { |
| 1232 | if (mod_bot > wp->w_topline) |
| 1233 | mod_top = wp->w_topline; |
| 1234 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1235 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1236 | top_end = 1; |
| 1237 | #endif |
| 1238 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1239 | |
| 1240 | /* When line numbers are displayed need to redraw all lines below |
| 1241 | * inserted/deleted lines. */ |
| 1242 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1243 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * When only displaying the lines at the top, set top_end. Used when |
| 1248 | * window has scrolled down for msg_scrolled. |
| 1249 | */ |
| 1250 | if (type == REDRAW_TOP) |
| 1251 | { |
| 1252 | j = 0; |
| 1253 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1254 | { |
| 1255 | j += wp->w_lines[i].wl_size; |
| 1256 | if (j >= wp->w_upd_rows) |
| 1257 | { |
| 1258 | top_end = j; |
| 1259 | break; |
| 1260 | } |
| 1261 | } |
| 1262 | if (top_end == 0) |
| 1263 | /* not found (cannot happen?): redraw everything */ |
| 1264 | type = NOT_VALID; |
| 1265 | else |
| 1266 | /* top area defined, the rest is VALID */ |
| 1267 | type = VALID; |
| 1268 | } |
| 1269 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1270 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1271 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1272 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1273 | * called. */ |
| 1274 | if (screen_cleared) |
| 1275 | screen_cleared = MAYBE; |
| 1276 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1277 | /* |
| 1278 | * If there are no changes on the screen that require a complete redraw, |
| 1279 | * handle three cases: |
| 1280 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1281 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1282 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1283 | * w_lines[] that needs updating. |
| 1284 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1285 | if ((type == VALID || type == SOME_VALID |
| 1286 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1287 | #ifdef FEAT_DIFF |
| 1288 | && !wp->w_botfill && !wp->w_old_botfill |
| 1289 | #endif |
| 1290 | ) |
| 1291 | { |
| 1292 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1293 | { |
| 1294 | /* |
| 1295 | * w_topline is the first changed line, the scrolling will be done |
| 1296 | * further down. |
| 1297 | */ |
| 1298 | } |
| 1299 | else if (wp->w_lines[0].wl_valid |
| 1300 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1301 | #ifdef FEAT_DIFF |
| 1302 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1303 | && wp->w_topfill > wp->w_old_topfill) |
| 1304 | #endif |
| 1305 | )) |
| 1306 | { |
| 1307 | /* |
| 1308 | * New topline is above old topline: May scroll down. |
| 1309 | */ |
| 1310 | #ifdef FEAT_FOLDING |
| 1311 | if (hasAnyFolding(wp)) |
| 1312 | { |
| 1313 | linenr_T ln; |
| 1314 | |
| 1315 | /* count the number of lines we are off, counting a sequence |
| 1316 | * of folded lines as one */ |
| 1317 | j = 0; |
| 1318 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1319 | { |
| 1320 | ++j; |
| 1321 | if (j >= wp->w_height - 2) |
| 1322 | break; |
| 1323 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1324 | } |
| 1325 | } |
| 1326 | else |
| 1327 | #endif |
| 1328 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1329 | if (j < wp->w_height - 2) /* not too far off */ |
| 1330 | { |
| 1331 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1332 | #ifdef FEAT_DIFF |
| 1333 | /* insert extra lines for previously invisible filler lines */ |
| 1334 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1335 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1336 | - wp->w_old_topfill; |
| 1337 | #endif |
| 1338 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1339 | { |
| 1340 | /* |
| 1341 | * Try to insert the correct number of lines. |
| 1342 | * If not the last window, delete the lines at the bottom. |
| 1343 | * win_ins_lines may fail when the terminal can't do it. |
| 1344 | */ |
| 1345 | if (i > 0) |
| 1346 | check_for_delay(FALSE); |
| 1347 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1348 | { |
| 1349 | if (wp->w_lines_valid != 0) |
| 1350 | { |
| 1351 | /* Need to update rows that are new, stop at the |
| 1352 | * first one that scrolled down. */ |
| 1353 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1354 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1355 | |
| 1356 | /* Move the entries that were scrolled, disable |
| 1357 | * the entries for the lines to be redrawn. */ |
| 1358 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1359 | wp->w_lines_valid = wp->w_height; |
| 1360 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1361 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1362 | while (idx >= 0) |
| 1363 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1364 | } |
| 1365 | } |
| 1366 | else |
| 1367 | mid_start = 0; /* redraw all lines */ |
| 1368 | } |
| 1369 | else |
| 1370 | mid_start = 0; /* redraw all lines */ |
| 1371 | } |
| 1372 | else |
| 1373 | mid_start = 0; /* redraw all lines */ |
| 1374 | } |
| 1375 | else |
| 1376 | { |
| 1377 | /* |
| 1378 | * New topline is at or below old topline: May scroll up. |
| 1379 | * When topline didn't change, find first entry in w_lines[] that |
| 1380 | * needs updating. |
| 1381 | */ |
| 1382 | |
| 1383 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1384 | j = -1; |
| 1385 | row = 0; |
| 1386 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1387 | { |
| 1388 | if (wp->w_lines[i].wl_valid |
| 1389 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1390 | { |
| 1391 | j = i; |
| 1392 | break; |
| 1393 | } |
| 1394 | row += wp->w_lines[i].wl_size; |
| 1395 | } |
| 1396 | if (j == -1) |
| 1397 | { |
| 1398 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1399 | * lines */ |
| 1400 | mid_start = 0; |
| 1401 | } |
| 1402 | else |
| 1403 | { |
| 1404 | /* |
| 1405 | * Try to delete the correct number of lines. |
| 1406 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1407 | */ |
| 1408 | #ifdef FEAT_DIFF |
| 1409 | /* If the topline didn't change, delete old filler lines, |
| 1410 | * otherwise delete filler lines of the new topline... */ |
| 1411 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1412 | row += wp->w_old_topfill; |
| 1413 | else |
| 1414 | row += diff_check_fill(wp, wp->w_topline); |
| 1415 | /* ... but don't delete new filler lines. */ |
| 1416 | row -= wp->w_topfill; |
| 1417 | #endif |
| 1418 | if (row > 0) |
| 1419 | { |
| 1420 | check_for_delay(FALSE); |
| 1421 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1422 | bot_start = wp->w_height - row; |
| 1423 | else |
| 1424 | mid_start = 0; /* redraw all lines */ |
| 1425 | } |
| 1426 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1427 | { |
| 1428 | /* |
| 1429 | * Skip the lines (below the deleted lines) that are still |
| 1430 | * valid and don't need redrawing. Copy their info |
| 1431 | * upwards, to compensate for the deleted lines. Set |
| 1432 | * bot_start to the first row that needs redrawing. |
| 1433 | */ |
| 1434 | bot_start = 0; |
| 1435 | idx = 0; |
| 1436 | for (;;) |
| 1437 | { |
| 1438 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1439 | /* stop at line that didn't fit, unless it is still |
| 1440 | * valid (no lines deleted) */ |
| 1441 | if (row > 0 && bot_start + row |
| 1442 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1443 | { |
| 1444 | wp->w_lines_valid = idx + 1; |
| 1445 | break; |
| 1446 | } |
| 1447 | bot_start += wp->w_lines[idx++].wl_size; |
| 1448 | |
| 1449 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1450 | if (++j >= wp->w_lines_valid) |
| 1451 | { |
| 1452 | wp->w_lines_valid = idx; |
| 1453 | break; |
| 1454 | } |
| 1455 | } |
| 1456 | #ifdef FEAT_DIFF |
| 1457 | /* Correct the first entry for filler lines at the top |
| 1458 | * when it won't get updated below. */ |
| 1459 | if (wp->w_p_diff && bot_start > 0) |
| 1460 | wp->w_lines[0].wl_size = |
| 1461 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1462 | + wp->w_topfill; |
| 1463 | #endif |
| 1464 | } |
| 1465 | } |
| 1466 | } |
| 1467 | |
| 1468 | /* When starting redraw in the first line, redraw all lines. When |
| 1469 | * there is only one window it's probably faster to clear the screen |
| 1470 | * first. */ |
| 1471 | if (mid_start == 0) |
| 1472 | { |
| 1473 | mid_end = wp->w_height; |
| 1474 | if (lastwin == firstwin) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1475 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1476 | /* Clear the screen when it was not done by win_del_lines() or |
| 1477 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1478 | * then. */ |
| 1479 | if (screen_cleared != TRUE) |
| 1480 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1481 | #ifdef FEAT_WINDOWS |
| 1482 | /* The screen was cleared, redraw the tab pages line. */ |
| 1483 | if (redraw_tabline) |
| 1484 | draw_tabline(); |
| 1485 | #endif |
| 1486 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1487 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1488 | |
| 1489 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1490 | * cleared (only happens for the first window) or when screenclear() |
| 1491 | * was called directly above, "must_redraw" will have been set to |
| 1492 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1493 | if (screen_cleared == TRUE) |
| 1494 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1495 | } |
| 1496 | else |
| 1497 | { |
| 1498 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1499 | mid_start = 0; |
| 1500 | mid_end = wp->w_height; |
| 1501 | } |
| 1502 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1503 | if (type == SOME_VALID) |
| 1504 | { |
| 1505 | /* SOME_VALID: redraw all lines. */ |
| 1506 | mid_start = 0; |
| 1507 | mid_end = wp->w_height; |
| 1508 | type = NOT_VALID; |
| 1509 | } |
| 1510 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1511 | /* check if we are updating or removing the inverted part */ |
| 1512 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1513 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1514 | { |
| 1515 | linenr_T from, to; |
| 1516 | |
| 1517 | if (VIsual_active) |
| 1518 | { |
| 1519 | if (VIsual_active |
| 1520 | && (VIsual_mode != wp->w_old_visual_mode |
| 1521 | || type == INVERTED_ALL)) |
| 1522 | { |
| 1523 | /* |
| 1524 | * If the type of Visual selection changed, redraw the whole |
| 1525 | * selection. Also when the ownership of the X selection is |
| 1526 | * gained or lost. |
| 1527 | */ |
| 1528 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1529 | { |
| 1530 | from = curwin->w_cursor.lnum; |
| 1531 | to = VIsual.lnum; |
| 1532 | } |
| 1533 | else |
| 1534 | { |
| 1535 | from = VIsual.lnum; |
| 1536 | to = curwin->w_cursor.lnum; |
| 1537 | } |
| 1538 | /* redraw more when the cursor moved as well */ |
| 1539 | if (wp->w_old_cursor_lnum < from) |
| 1540 | from = wp->w_old_cursor_lnum; |
| 1541 | if (wp->w_old_cursor_lnum > to) |
| 1542 | to = wp->w_old_cursor_lnum; |
| 1543 | if (wp->w_old_visual_lnum < from) |
| 1544 | from = wp->w_old_visual_lnum; |
| 1545 | if (wp->w_old_visual_lnum > to) |
| 1546 | to = wp->w_old_visual_lnum; |
| 1547 | } |
| 1548 | else |
| 1549 | { |
| 1550 | /* |
| 1551 | * Find the line numbers that need to be updated: The lines |
| 1552 | * between the old cursor position and the current cursor |
| 1553 | * position. Also check if the Visual position changed. |
| 1554 | */ |
| 1555 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1556 | { |
| 1557 | from = curwin->w_cursor.lnum; |
| 1558 | to = wp->w_old_cursor_lnum; |
| 1559 | } |
| 1560 | else |
| 1561 | { |
| 1562 | from = wp->w_old_cursor_lnum; |
| 1563 | to = curwin->w_cursor.lnum; |
| 1564 | if (from == 0) /* Visual mode just started */ |
| 1565 | from = to; |
| 1566 | } |
| 1567 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1568 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1569 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1570 | { |
| 1571 | if (wp->w_old_visual_lnum < from |
| 1572 | && wp->w_old_visual_lnum != 0) |
| 1573 | from = wp->w_old_visual_lnum; |
| 1574 | if (wp->w_old_visual_lnum > to) |
| 1575 | to = wp->w_old_visual_lnum; |
| 1576 | if (VIsual.lnum < from) |
| 1577 | from = VIsual.lnum; |
| 1578 | if (VIsual.lnum > to) |
| 1579 | to = VIsual.lnum; |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | /* |
| 1584 | * If in block mode and changed column or curwin->w_curswant: |
| 1585 | * update all lines. |
| 1586 | * First compute the actual start and end column. |
| 1587 | */ |
| 1588 | if (VIsual_mode == Ctrl_V) |
| 1589 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1590 | colnr_T fromc, toc; |
| 1591 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1592 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1593 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1594 | if (curwin->w_p_lbr) |
| 1595 | ve_flags = VE_ALL; |
| 1596 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1597 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1598 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1599 | ve_flags = save_ve_flags; |
| 1600 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1601 | ++toc; |
| 1602 | if (curwin->w_curswant == MAXCOL) |
| 1603 | toc = MAXCOL; |
| 1604 | |
| 1605 | if (fromc != wp->w_old_cursor_fcol |
| 1606 | || toc != wp->w_old_cursor_lcol) |
| 1607 | { |
| 1608 | if (from > VIsual.lnum) |
| 1609 | from = VIsual.lnum; |
| 1610 | if (to < VIsual.lnum) |
| 1611 | to = VIsual.lnum; |
| 1612 | } |
| 1613 | wp->w_old_cursor_fcol = fromc; |
| 1614 | wp->w_old_cursor_lcol = toc; |
| 1615 | } |
| 1616 | } |
| 1617 | else |
| 1618 | { |
| 1619 | /* Use the line numbers of the old Visual area. */ |
| 1620 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1621 | { |
| 1622 | from = wp->w_old_cursor_lnum; |
| 1623 | to = wp->w_old_visual_lnum; |
| 1624 | } |
| 1625 | else |
| 1626 | { |
| 1627 | from = wp->w_old_visual_lnum; |
| 1628 | to = wp->w_old_cursor_lnum; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | /* |
| 1633 | * There is no need to update lines above the top of the window. |
| 1634 | */ |
| 1635 | if (from < wp->w_topline) |
| 1636 | from = wp->w_topline; |
| 1637 | |
| 1638 | /* |
| 1639 | * If we know the value of w_botline, use it to restrict the update to |
| 1640 | * the lines that are visible in the window. |
| 1641 | */ |
| 1642 | if (wp->w_valid & VALID_BOTLINE) |
| 1643 | { |
| 1644 | if (from >= wp->w_botline) |
| 1645 | from = wp->w_botline - 1; |
| 1646 | if (to >= wp->w_botline) |
| 1647 | to = wp->w_botline - 1; |
| 1648 | } |
| 1649 | |
| 1650 | /* |
| 1651 | * Find the minimal part to be updated. |
| 1652 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1653 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1654 | * top_end; need to redraw from top_end to the "to" line. |
| 1655 | * A middle mouse click with a Visual selection may change the text |
| 1656 | * above the Visual area and reset wl_valid, do count these for |
| 1657 | * mid_end (in srow). |
| 1658 | */ |
| 1659 | if (mid_start > 0) |
| 1660 | { |
| 1661 | lnum = wp->w_topline; |
| 1662 | idx = 0; |
| 1663 | srow = 0; |
| 1664 | if (scrolled_down) |
| 1665 | mid_start = top_end; |
| 1666 | else |
| 1667 | mid_start = 0; |
| 1668 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1669 | { |
| 1670 | if (wp->w_lines[idx].wl_valid) |
| 1671 | mid_start += wp->w_lines[idx].wl_size; |
| 1672 | else if (!scrolled_down) |
| 1673 | srow += wp->w_lines[idx].wl_size; |
| 1674 | ++idx; |
| 1675 | # ifdef FEAT_FOLDING |
| 1676 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1677 | lnum = wp->w_lines[idx].wl_lnum; |
| 1678 | else |
| 1679 | # endif |
| 1680 | ++lnum; |
| 1681 | } |
| 1682 | srow += mid_start; |
| 1683 | mid_end = wp->w_height; |
| 1684 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1685 | { |
| 1686 | if (wp->w_lines[idx].wl_valid |
| 1687 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1688 | { |
| 1689 | /* Only update until first row of this line */ |
| 1690 | mid_end = srow; |
| 1691 | break; |
| 1692 | } |
| 1693 | srow += wp->w_lines[idx].wl_size; |
| 1694 | } |
| 1695 | } |
| 1696 | } |
| 1697 | |
| 1698 | if (VIsual_active && buf == curwin->w_buffer) |
| 1699 | { |
| 1700 | wp->w_old_visual_mode = VIsual_mode; |
| 1701 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1702 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1703 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1704 | wp->w_old_curswant = curwin->w_curswant; |
| 1705 | } |
| 1706 | else |
| 1707 | { |
| 1708 | wp->w_old_visual_mode = 0; |
| 1709 | wp->w_old_cursor_lnum = 0; |
| 1710 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1711 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1712 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1713 | |
| 1714 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1715 | /* reset got_int, otherwise regexp won't work */ |
| 1716 | save_got_int = got_int; |
| 1717 | got_int = 0; |
| 1718 | #endif |
| 1719 | #ifdef FEAT_FOLDING |
| 1720 | win_foldinfo.fi_level = 0; |
| 1721 | #endif |
| 1722 | |
| 1723 | /* |
| 1724 | * Update all the window rows. |
| 1725 | */ |
| 1726 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1727 | row = 0; |
| 1728 | srow = 0; |
| 1729 | lnum = wp->w_topline; /* first line shown in window */ |
| 1730 | for (;;) |
| 1731 | { |
| 1732 | /* stop updating when reached the end of the window (check for _past_ |
| 1733 | * the end of the window is at the end of the loop) */ |
| 1734 | if (row == wp->w_height) |
| 1735 | { |
| 1736 | didline = TRUE; |
| 1737 | break; |
| 1738 | } |
| 1739 | |
| 1740 | /* stop updating when hit the end of the file */ |
| 1741 | if (lnum > buf->b_ml.ml_line_count) |
| 1742 | { |
| 1743 | eof = TRUE; |
| 1744 | break; |
| 1745 | } |
| 1746 | |
| 1747 | /* Remember the starting row of the line that is going to be dealt |
| 1748 | * with. It is used further down when the line doesn't fit. */ |
| 1749 | srow = row; |
| 1750 | |
| 1751 | /* |
| 1752 | * Update a line when it is in an area that needs updating, when it |
| 1753 | * has changes or w_lines[idx] is invalid. |
| 1754 | * bot_start may be halfway a wrapped line after using |
| 1755 | * win_del_lines(), check if the current line includes it. |
| 1756 | * When syntax folding is being used, the saved syntax states will |
| 1757 | * already have been updated, we can't see where the syntax state is |
| 1758 | * the same again, just update until the end of the window. |
| 1759 | */ |
| 1760 | if (row < top_end |
| 1761 | || (row >= mid_start && row < mid_end) |
| 1762 | #ifdef FEAT_SEARCH_EXTRA |
| 1763 | || top_to_mod |
| 1764 | #endif |
| 1765 | || idx >= wp->w_lines_valid |
| 1766 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1767 | || (mod_top != 0 |
| 1768 | && (lnum == mod_top |
| 1769 | || (lnum >= mod_top |
| 1770 | && (lnum < mod_bot |
| 1771 | #ifdef FEAT_SYN_HL |
| 1772 | || did_update == DID_FOLD |
| 1773 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1774 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1775 | && ( |
| 1776 | # ifdef FEAT_FOLDING |
| 1777 | (foldmethodIsSyntax(wp) |
| 1778 | && hasAnyFolding(wp)) || |
| 1779 | # endif |
| 1780 | syntax_check_changed(lnum))) |
| 1781 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1782 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1783 | /* match in fixed position might need redraw |
| 1784 | * if lines were inserted or deleted */ |
| 1785 | || (wp->w_match_head != NULL |
| 1786 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1787 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1788 | ))))) |
| 1789 | { |
| 1790 | #ifdef FEAT_SEARCH_EXTRA |
| 1791 | if (lnum == mod_top) |
| 1792 | top_to_mod = FALSE; |
| 1793 | #endif |
| 1794 | |
| 1795 | /* |
| 1796 | * When at start of changed lines: May scroll following lines |
| 1797 | * up or down to minimize redrawing. |
| 1798 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1799 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1800 | */ |
| 1801 | if (lnum == mod_top |
| 1802 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1803 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1804 | { |
| 1805 | int old_rows = 0; |
| 1806 | int new_rows = 0; |
| 1807 | int xtra_rows; |
| 1808 | linenr_T l; |
| 1809 | |
| 1810 | /* Count the old number of window rows, using w_lines[], which |
| 1811 | * should still contain the sizes for the lines as they are |
| 1812 | * currently displayed. */ |
| 1813 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1814 | { |
| 1815 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1816 | * lines are part of the changed area. */ |
| 1817 | if (wp->w_lines[i].wl_valid |
| 1818 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1819 | break; |
| 1820 | old_rows += wp->w_lines[i].wl_size; |
| 1821 | #ifdef FEAT_FOLDING |
| 1822 | if (wp->w_lines[i].wl_valid |
| 1823 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1824 | { |
| 1825 | /* Must have found the last valid entry above mod_bot. |
| 1826 | * Add following invalid entries. */ |
| 1827 | ++i; |
| 1828 | while (i < wp->w_lines_valid |
| 1829 | && !wp->w_lines[i].wl_valid) |
| 1830 | old_rows += wp->w_lines[i++].wl_size; |
| 1831 | break; |
| 1832 | } |
| 1833 | #endif |
| 1834 | } |
| 1835 | |
| 1836 | if (i >= wp->w_lines_valid) |
| 1837 | { |
| 1838 | /* We can't find a valid line below the changed lines, |
| 1839 | * need to redraw until the end of the window. |
| 1840 | * Inserting/deleting lines has no use. */ |
| 1841 | bot_start = 0; |
| 1842 | } |
| 1843 | else |
| 1844 | { |
| 1845 | /* Able to count old number of rows: Count new window |
| 1846 | * rows, and may insert/delete lines */ |
| 1847 | j = idx; |
| 1848 | for (l = lnum; l < mod_bot; ++l) |
| 1849 | { |
| 1850 | #ifdef FEAT_FOLDING |
| 1851 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1852 | ++new_rows; |
| 1853 | else |
| 1854 | #endif |
| 1855 | #ifdef FEAT_DIFF |
| 1856 | if (l == wp->w_topline) |
| 1857 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1858 | + wp->w_topfill; |
| 1859 | else |
| 1860 | #endif |
| 1861 | new_rows += plines_win(wp, l, TRUE); |
| 1862 | ++j; |
| 1863 | if (new_rows > wp->w_height - row - 2) |
| 1864 | { |
| 1865 | /* it's getting too much, must redraw the rest */ |
| 1866 | new_rows = 9999; |
| 1867 | break; |
| 1868 | } |
| 1869 | } |
| 1870 | xtra_rows = new_rows - old_rows; |
| 1871 | if (xtra_rows < 0) |
| 1872 | { |
| 1873 | /* May scroll text up. If there is not enough |
| 1874 | * remaining text or scrolling fails, must redraw the |
| 1875 | * rest. If scrolling works, must redraw the text |
| 1876 | * below the scrolled text. */ |
| 1877 | if (row - xtra_rows >= wp->w_height - 2) |
| 1878 | mod_bot = MAXLNUM; |
| 1879 | else |
| 1880 | { |
| 1881 | check_for_delay(FALSE); |
| 1882 | if (win_del_lines(wp, row, |
| 1883 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1884 | mod_bot = MAXLNUM; |
| 1885 | else |
| 1886 | bot_start = wp->w_height + xtra_rows; |
| 1887 | } |
| 1888 | } |
| 1889 | else if (xtra_rows > 0) |
| 1890 | { |
| 1891 | /* May scroll text down. If there is not enough |
| 1892 | * remaining text of scrolling fails, must redraw the |
| 1893 | * rest. */ |
| 1894 | if (row + xtra_rows >= wp->w_height - 2) |
| 1895 | mod_bot = MAXLNUM; |
| 1896 | else |
| 1897 | { |
| 1898 | check_for_delay(FALSE); |
| 1899 | if (win_ins_lines(wp, row + old_rows, |
| 1900 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1901 | mod_bot = MAXLNUM; |
| 1902 | else if (top_end > row + old_rows) |
| 1903 | /* Scrolled the part at the top that requires |
| 1904 | * updating down. */ |
| 1905 | top_end += xtra_rows; |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | /* When not updating the rest, may need to move w_lines[] |
| 1910 | * entries. */ |
| 1911 | if (mod_bot != MAXLNUM && i != j) |
| 1912 | { |
| 1913 | if (j < i) |
| 1914 | { |
| 1915 | int x = row + new_rows; |
| 1916 | |
| 1917 | /* move entries in w_lines[] upwards */ |
| 1918 | for (;;) |
| 1919 | { |
| 1920 | /* stop at last valid entry in w_lines[] */ |
| 1921 | if (i >= wp->w_lines_valid) |
| 1922 | { |
| 1923 | wp->w_lines_valid = j; |
| 1924 | break; |
| 1925 | } |
| 1926 | wp->w_lines[j] = wp->w_lines[i]; |
| 1927 | /* stop at a line that won't fit */ |
| 1928 | if (x + (int)wp->w_lines[j].wl_size |
| 1929 | > wp->w_height) |
| 1930 | { |
| 1931 | wp->w_lines_valid = j + 1; |
| 1932 | break; |
| 1933 | } |
| 1934 | x += wp->w_lines[j++].wl_size; |
| 1935 | ++i; |
| 1936 | } |
| 1937 | if (bot_start > x) |
| 1938 | bot_start = x; |
| 1939 | } |
| 1940 | else /* j > i */ |
| 1941 | { |
| 1942 | /* move entries in w_lines[] downwards */ |
| 1943 | j -= i; |
| 1944 | wp->w_lines_valid += j; |
| 1945 | if (wp->w_lines_valid > wp->w_height) |
| 1946 | wp->w_lines_valid = wp->w_height; |
| 1947 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1948 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1949 | |
| 1950 | /* The w_lines[] entries for inserted lines are |
| 1951 | * now invalid, but wl_size may be used above. |
| 1952 | * Reset to zero. */ |
| 1953 | while (i >= idx) |
| 1954 | { |
| 1955 | wp->w_lines[i].wl_size = 0; |
| 1956 | wp->w_lines[i--].wl_valid = FALSE; |
| 1957 | } |
| 1958 | } |
| 1959 | } |
| 1960 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
| 1963 | #ifdef FEAT_FOLDING |
| 1964 | /* |
| 1965 | * When lines are folded, display one line for all of them. |
| 1966 | * Otherwise, display normally (can be several display lines when |
| 1967 | * 'wrap' is on). |
| 1968 | */ |
| 1969 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 1970 | if (fold_count != 0) |
| 1971 | { |
| 1972 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 1973 | ++row; |
| 1974 | --fold_count; |
| 1975 | wp->w_lines[idx].wl_folded = TRUE; |
| 1976 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 1977 | # ifdef FEAT_SYN_HL |
| 1978 | did_update = DID_FOLD; |
| 1979 | # endif |
| 1980 | } |
| 1981 | else |
| 1982 | #endif |
| 1983 | if (idx < wp->w_lines_valid |
| 1984 | && wp->w_lines[idx].wl_valid |
| 1985 | && wp->w_lines[idx].wl_lnum == lnum |
| 1986 | && lnum > wp->w_topline |
| 1987 | && !(dy_flags & DY_LASTLINE) |
| 1988 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 1989 | #ifdef FEAT_DIFF |
| 1990 | && diff_check_fill(wp, lnum) == 0 |
| 1991 | #endif |
| 1992 | ) |
| 1993 | { |
| 1994 | /* This line is not going to fit. Don't draw anything here, |
| 1995 | * will draw "@ " lines below. */ |
| 1996 | row = wp->w_height + 1; |
| 1997 | } |
| 1998 | else |
| 1999 | { |
| 2000 | #ifdef FEAT_SEARCH_EXTRA |
| 2001 | prepare_search_hl(wp, lnum); |
| 2002 | #endif |
| 2003 | #ifdef FEAT_SYN_HL |
| 2004 | /* Let the syntax stuff know we skipped a few lines. */ |
| 2005 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2006 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2007 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2008 | #endif |
| 2009 | |
| 2010 | /* |
| 2011 | * Display one line. |
| 2012 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2013 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2014 | |
| 2015 | #ifdef FEAT_FOLDING |
| 2016 | wp->w_lines[idx].wl_folded = FALSE; |
| 2017 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2018 | #endif |
| 2019 | #ifdef FEAT_SYN_HL |
| 2020 | did_update = DID_LINE; |
| 2021 | syntax_last_parsed = lnum; |
| 2022 | #endif |
| 2023 | } |
| 2024 | |
| 2025 | wp->w_lines[idx].wl_lnum = lnum; |
| 2026 | wp->w_lines[idx].wl_valid = TRUE; |
| 2027 | if (row > wp->w_height) /* past end of screen */ |
| 2028 | { |
| 2029 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2030 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2031 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2032 | ++idx; |
| 2033 | break; |
| 2034 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2035 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2036 | wp->w_lines[idx].wl_size = row - srow; |
| 2037 | ++idx; |
| 2038 | #ifdef FEAT_FOLDING |
| 2039 | lnum += fold_count + 1; |
| 2040 | #else |
| 2041 | ++lnum; |
| 2042 | #endif |
| 2043 | } |
| 2044 | else |
| 2045 | { |
| 2046 | /* This line does not need updating, advance to the next one */ |
| 2047 | row += wp->w_lines[idx++].wl_size; |
| 2048 | if (row > wp->w_height) /* past end of screen */ |
| 2049 | break; |
| 2050 | #ifdef FEAT_FOLDING |
| 2051 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2052 | #else |
| 2053 | ++lnum; |
| 2054 | #endif |
| 2055 | #ifdef FEAT_SYN_HL |
| 2056 | did_update = DID_NONE; |
| 2057 | #endif |
| 2058 | } |
| 2059 | |
| 2060 | if (lnum > buf->b_ml.ml_line_count) |
| 2061 | { |
| 2062 | eof = TRUE; |
| 2063 | break; |
| 2064 | } |
| 2065 | } |
| 2066 | /* |
| 2067 | * End of loop over all window lines. |
| 2068 | */ |
| 2069 | |
| 2070 | |
| 2071 | if (idx > wp->w_lines_valid) |
| 2072 | wp->w_lines_valid = idx; |
| 2073 | |
| 2074 | #ifdef FEAT_SYN_HL |
| 2075 | /* |
| 2076 | * Let the syntax stuff know we stop parsing here. |
| 2077 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2078 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2079 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2080 | #endif |
| 2081 | |
| 2082 | /* |
| 2083 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2084 | * line we were working on, then the line didn't fit. |
| 2085 | */ |
| 2086 | wp->w_empty_rows = 0; |
| 2087 | #ifdef FEAT_DIFF |
| 2088 | wp->w_filler_rows = 0; |
| 2089 | #endif |
| 2090 | if (!eof && !didline) |
| 2091 | { |
| 2092 | if (lnum == wp->w_topline) |
| 2093 | { |
| 2094 | /* |
| 2095 | * Single line that does not fit! |
| 2096 | * Don't overwrite it, it can be edited. |
| 2097 | */ |
| 2098 | wp->w_botline = lnum + 1; |
| 2099 | } |
| 2100 | #ifdef FEAT_DIFF |
| 2101 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2102 | { |
| 2103 | /* Window ends in filler lines. */ |
| 2104 | wp->w_botline = lnum; |
| 2105 | wp->w_filler_rows = wp->w_height - srow; |
| 2106 | } |
| 2107 | #endif |
| 2108 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2109 | { |
| 2110 | /* |
| 2111 | * Last line isn't finished: Display "@@@" at the end. |
| 2112 | */ |
| 2113 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2114 | W_WINROW(wp) + wp->w_height, |
| 2115 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2116 | '@', '@', hl_attr(HLF_AT)); |
| 2117 | set_empty_rows(wp, srow); |
| 2118 | wp->w_botline = lnum; |
| 2119 | } |
| 2120 | else |
| 2121 | { |
| 2122 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2123 | wp->w_botline = lnum; |
| 2124 | } |
| 2125 | } |
| 2126 | else |
| 2127 | { |
| 2128 | #ifdef FEAT_VERTSPLIT |
| 2129 | draw_vsep_win(wp, row); |
| 2130 | #endif |
| 2131 | if (eof) /* we hit the end of the file */ |
| 2132 | { |
| 2133 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2134 | #ifdef FEAT_DIFF |
| 2135 | j = diff_check_fill(wp, wp->w_botline); |
| 2136 | if (j > 0 && !wp->w_botfill) |
| 2137 | { |
| 2138 | /* |
| 2139 | * Display filler lines at the end of the file |
| 2140 | */ |
| 2141 | if (char2cells(fill_diff) > 1) |
| 2142 | i = '-'; |
| 2143 | else |
| 2144 | i = fill_diff; |
| 2145 | if (row + j > wp->w_height) |
| 2146 | j = wp->w_height - row; |
| 2147 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2148 | row += j; |
| 2149 | } |
| 2150 | #endif |
| 2151 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2152 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2153 | wp->w_botline = lnum; |
| 2154 | |
| 2155 | /* make sure the rest of the screen is blank */ |
| 2156 | /* put '~'s on rows that aren't part of the file. */ |
| 2157 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_AT); |
| 2158 | } |
| 2159 | |
| 2160 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2161 | wp->w_redr_type = 0; |
| 2162 | #ifdef FEAT_DIFF |
| 2163 | wp->w_old_topfill = wp->w_topfill; |
| 2164 | wp->w_old_botfill = wp->w_botfill; |
| 2165 | #endif |
| 2166 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2167 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2168 | { |
| 2169 | /* |
| 2170 | * There is a trick with w_botline. If we invalidate it on each |
| 2171 | * change that might modify it, this will cause a lot of expensive |
| 2172 | * calls to plines() in update_topline() each time. Therefore the |
| 2173 | * value of w_botline is often approximated, and this value is used to |
| 2174 | * compute the value of w_topline. If the value of w_botline was |
| 2175 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2176 | * the visible part of the text). If it's not, we need to redraw |
| 2177 | * again. Mostly this just means scrolling up a few lines, so it |
| 2178 | * doesn't look too bad. Only do this for the current window (where |
| 2179 | * changes are relevant). |
| 2180 | */ |
| 2181 | wp->w_valid |= VALID_BOTLINE; |
| 2182 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2183 | { |
| 2184 | recursive = TRUE; |
| 2185 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2186 | update_topline(); /* may invalidate w_botline again */ |
| 2187 | if (must_redraw != 0) |
| 2188 | { |
| 2189 | /* Don't update for changes in buffer again. */ |
| 2190 | i = curbuf->b_mod_set; |
| 2191 | curbuf->b_mod_set = FALSE; |
| 2192 | win_update(curwin); |
| 2193 | must_redraw = 0; |
| 2194 | curbuf->b_mod_set = i; |
| 2195 | } |
| 2196 | recursive = FALSE; |
| 2197 | } |
| 2198 | } |
| 2199 | |
| 2200 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2201 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2202 | if (!got_int) |
| 2203 | got_int = save_got_int; |
| 2204 | #endif |
| 2205 | } |
| 2206 | |
| 2207 | #ifdef FEAT_SIGNS |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2208 | static int draw_signcolumn(win_T *wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2209 | |
| 2210 | /* |
| 2211 | * Return TRUE when window "wp" has a column to draw signs in. |
| 2212 | */ |
| 2213 | static int |
| 2214 | draw_signcolumn(wp) |
| 2215 | win_T *wp; |
| 2216 | { |
| 2217 | return (wp->w_buffer->b_signlist != NULL |
| 2218 | # ifdef FEAT_NETBEANS_INTG |
Bram Moolenaar | 3b7b836 | 2015-03-20 18:11:48 +0100 | [diff] [blame] | 2219 | || wp->w_buffer->b_has_sign_column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2220 | # endif |
| 2221 | ); |
| 2222 | } |
| 2223 | #endif |
| 2224 | |
| 2225 | /* |
| 2226 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2227 | * as the filler character. |
| 2228 | */ |
| 2229 | static void |
| 2230 | win_draw_end(wp, c1, c2, row, endrow, hl) |
| 2231 | win_T *wp; |
| 2232 | int c1; |
| 2233 | int c2; |
| 2234 | int row; |
| 2235 | int endrow; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2236 | hlf_T hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2237 | { |
| 2238 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2239 | int n = 0; |
| 2240 | # define FDC_OFF n |
| 2241 | #else |
| 2242 | # define FDC_OFF 0 |
| 2243 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2244 | #ifdef FEAT_FOLDING |
| 2245 | int fdc = compute_foldcolumn(wp, 0); |
| 2246 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2247 | |
| 2248 | #ifdef FEAT_RIGHTLEFT |
| 2249 | if (wp->w_p_rl) |
| 2250 | { |
| 2251 | /* No check for cmdline window: should never be right-left. */ |
| 2252 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2253 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2254 | |
| 2255 | if (n > 0) |
| 2256 | { |
| 2257 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2258 | if (n > W_WIDTH(wp)) |
| 2259 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2260 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2261 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2262 | ' ', ' ', hl_attr(HLF_FC)); |
| 2263 | } |
| 2264 | # endif |
| 2265 | # ifdef FEAT_SIGNS |
| 2266 | if (draw_signcolumn(wp)) |
| 2267 | { |
| 2268 | int nn = n + 2; |
| 2269 | |
| 2270 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2271 | if (nn > W_WIDTH(wp)) |
| 2272 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2273 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2274 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2275 | ' ', ' ', hl_attr(HLF_SC)); |
| 2276 | n = nn; |
| 2277 | } |
| 2278 | # endif |
| 2279 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2280 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2281 | c2, c2, hl_attr(hl)); |
| 2282 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2283 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2284 | c1, c2, hl_attr(hl)); |
| 2285 | } |
| 2286 | else |
| 2287 | #endif |
| 2288 | { |
| 2289 | #ifdef FEAT_CMDWIN |
| 2290 | if (cmdwin_type != 0 && wp == curwin) |
| 2291 | { |
| 2292 | /* draw the cmdline character in the leftmost column */ |
| 2293 | n = 1; |
| 2294 | if (n > wp->w_width) |
| 2295 | n = wp->w_width; |
| 2296 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2297 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2298 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2299 | } |
| 2300 | #endif |
| 2301 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2302 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2303 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2304 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2305 | |
| 2306 | /* draw the fold column at the left */ |
| 2307 | if (nn > W_WIDTH(wp)) |
| 2308 | nn = W_WIDTH(wp); |
| 2309 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2310 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2311 | ' ', ' ', hl_attr(HLF_FC)); |
| 2312 | n = nn; |
| 2313 | } |
| 2314 | #endif |
| 2315 | #ifdef FEAT_SIGNS |
| 2316 | if (draw_signcolumn(wp)) |
| 2317 | { |
| 2318 | int nn = n + 2; |
| 2319 | |
| 2320 | /* draw the sign column after the fold column */ |
| 2321 | if (nn > W_WIDTH(wp)) |
| 2322 | nn = W_WIDTH(wp); |
| 2323 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2324 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2325 | ' ', ' ', hl_attr(HLF_SC)); |
| 2326 | n = nn; |
| 2327 | } |
| 2328 | #endif |
| 2329 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2330 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2331 | c1, c2, hl_attr(hl)); |
| 2332 | } |
| 2333 | set_empty_rows(wp, row); |
| 2334 | } |
| 2335 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2336 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2337 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2338 | |
| 2339 | /* |
| 2340 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2341 | */ |
| 2342 | static int |
| 2343 | advance_color_col(vcol, color_cols) |
| 2344 | int vcol; |
| 2345 | int **color_cols; |
| 2346 | { |
| 2347 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2348 | ++*color_cols; |
| 2349 | return (**color_cols >= 0); |
| 2350 | } |
| 2351 | #endif |
| 2352 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2353 | #ifdef FEAT_FOLDING |
| 2354 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2355 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2356 | * space is available for window "wp", minus "col". |
| 2357 | */ |
| 2358 | static int |
| 2359 | compute_foldcolumn(wp, col) |
| 2360 | win_T *wp; |
| 2361 | int col; |
| 2362 | { |
| 2363 | int fdc = wp->w_p_fdc; |
| 2364 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2365 | int wwidth = W_WIDTH(wp); |
| 2366 | |
| 2367 | if (fdc > wwidth - (col + wmw)) |
| 2368 | fdc = wwidth - (col + wmw); |
| 2369 | return fdc; |
| 2370 | } |
| 2371 | |
| 2372 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2373 | * Display one folded line. |
| 2374 | */ |
| 2375 | static void |
| 2376 | fold_line(wp, fold_count, foldinfo, lnum, row) |
| 2377 | win_T *wp; |
| 2378 | long fold_count; |
| 2379 | foldinfo_T *foldinfo; |
| 2380 | linenr_T lnum; |
| 2381 | int row; |
| 2382 | { |
| 2383 | char_u buf[51]; |
| 2384 | pos_T *top, *bot; |
| 2385 | linenr_T lnume = lnum + fold_count - 1; |
| 2386 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2387 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2388 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2389 | int col; |
| 2390 | int txtcol; |
| 2391 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2392 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2393 | |
| 2394 | /* Build the fold line: |
| 2395 | * 1. Add the cmdwin_type for the command-line window |
| 2396 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2397 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2398 | * 4. Compose the text |
| 2399 | * 5. Add the text |
| 2400 | * 6. set highlighting for the Visual area an other text |
| 2401 | */ |
| 2402 | col = 0; |
| 2403 | |
| 2404 | /* |
| 2405 | * 1. Add the cmdwin_type for the command-line window |
| 2406 | * Ignores 'rightleft', this window is never right-left. |
| 2407 | */ |
| 2408 | #ifdef FEAT_CMDWIN |
| 2409 | if (cmdwin_type != 0 && wp == curwin) |
| 2410 | { |
| 2411 | ScreenLines[off] = cmdwin_type; |
| 2412 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2413 | #ifdef FEAT_MBYTE |
| 2414 | if (enc_utf8) |
| 2415 | ScreenLinesUC[off] = 0; |
| 2416 | #endif |
| 2417 | ++col; |
| 2418 | } |
| 2419 | #endif |
| 2420 | |
| 2421 | /* |
| 2422 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2423 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2424 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2425 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2426 | if (fdc > 0) |
| 2427 | { |
| 2428 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2429 | #ifdef FEAT_RIGHTLEFT |
| 2430 | if (wp->w_p_rl) |
| 2431 | { |
| 2432 | int i; |
| 2433 | |
| 2434 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2435 | hl_attr(HLF_FC)); |
| 2436 | /* reverse the fold column */ |
| 2437 | for (i = 0; i < fdc; ++i) |
| 2438 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2439 | } |
| 2440 | else |
| 2441 | #endif |
| 2442 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2443 | col += fdc; |
| 2444 | } |
| 2445 | |
| 2446 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2447 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2448 | for (ri = 0; ri < l; ++ri) \ |
| 2449 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2450 | else \ |
| 2451 | for (ri = 0; ri < l; ++ri) \ |
| 2452 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2453 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2454 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2455 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2456 | #endif |
| 2457 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2458 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2459 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2460 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2461 | |
| 2462 | #ifdef FEAT_SIGNS |
| 2463 | /* If signs are being displayed, add two spaces. */ |
| 2464 | if (draw_signcolumn(wp)) |
| 2465 | { |
| 2466 | len = W_WIDTH(wp) - col; |
| 2467 | if (len > 0) |
| 2468 | { |
| 2469 | if (len > 2) |
| 2470 | len = 2; |
| 2471 | # ifdef FEAT_RIGHTLEFT |
| 2472 | if (wp->w_p_rl) |
| 2473 | /* the line number isn't reversed */ |
| 2474 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2475 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2476 | else |
| 2477 | # endif |
| 2478 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2479 | col += len; |
| 2480 | } |
| 2481 | } |
| 2482 | #endif |
| 2483 | |
| 2484 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2485 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2486 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2487 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2488 | { |
| 2489 | len = W_WIDTH(wp) - col; |
| 2490 | if (len > 0) |
| 2491 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2492 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2493 | long num; |
| 2494 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2495 | |
| 2496 | if (len > w + 1) |
| 2497 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2498 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2499 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2500 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2501 | num = (long)lnum; |
| 2502 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2503 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2504 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2505 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2506 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2507 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2508 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2509 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2510 | num = lnum; |
| 2511 | fmt = "%-*ld "; |
| 2512 | } |
| 2513 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2514 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2515 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2516 | #ifdef FEAT_RIGHTLEFT |
| 2517 | if (wp->w_p_rl) |
| 2518 | /* the line number isn't reversed */ |
| 2519 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2520 | hl_attr(HLF_FL)); |
| 2521 | else |
| 2522 | #endif |
| 2523 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2524 | col += len; |
| 2525 | } |
| 2526 | } |
| 2527 | |
| 2528 | /* |
| 2529 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2530 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2531 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2532 | |
| 2533 | txtcol = col; /* remember where text starts */ |
| 2534 | |
| 2535 | /* |
| 2536 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2537 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2538 | * in columns number-col - window-width. |
| 2539 | */ |
| 2540 | #ifdef FEAT_MBYTE |
| 2541 | if (has_mbyte) |
| 2542 | { |
| 2543 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2544 | int u8c, u8cc[MAX_MCO]; |
| 2545 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2546 | int idx; |
| 2547 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2548 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2549 | # ifdef FEAT_ARABIC |
| 2550 | int prev_c = 0; /* previous Arabic character */ |
| 2551 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2552 | # endif |
| 2553 | |
| 2554 | # ifdef FEAT_RIGHTLEFT |
| 2555 | if (wp->w_p_rl) |
| 2556 | idx = off; |
| 2557 | else |
| 2558 | # endif |
| 2559 | idx = off + col; |
| 2560 | |
| 2561 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2562 | for (p = text; *p != NUL; ) |
| 2563 | { |
| 2564 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2565 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2566 | if (col + cells > W_WIDTH(wp) |
| 2567 | # ifdef FEAT_RIGHTLEFT |
| 2568 | - (wp->w_p_rl ? col : 0) |
| 2569 | # endif |
| 2570 | ) |
| 2571 | break; |
| 2572 | ScreenLines[idx] = *p; |
| 2573 | if (enc_utf8) |
| 2574 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2575 | u8c = utfc_ptr2char(p, u8cc); |
| 2576 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2577 | { |
| 2578 | ScreenLinesUC[idx] = 0; |
| 2579 | #ifdef FEAT_ARABIC |
| 2580 | prev_c = u8c; |
| 2581 | #endif |
| 2582 | } |
| 2583 | else |
| 2584 | { |
| 2585 | #ifdef FEAT_ARABIC |
| 2586 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2587 | { |
| 2588 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2589 | int pc, pc1, nc; |
| 2590 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2591 | int firstbyte = *p; |
| 2592 | |
| 2593 | /* The idea of what is the previous and next |
| 2594 | * character depends on 'rightleft'. */ |
| 2595 | if (wp->w_p_rl) |
| 2596 | { |
| 2597 | pc = prev_c; |
| 2598 | pc1 = prev_c1; |
| 2599 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2600 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2601 | } |
| 2602 | else |
| 2603 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2604 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2605 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2606 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2607 | } |
| 2608 | prev_c = u8c; |
| 2609 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2610 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2611 | pc, pc1, nc); |
| 2612 | ScreenLines[idx] = firstbyte; |
| 2613 | } |
| 2614 | else |
| 2615 | prev_c = u8c; |
| 2616 | #endif |
| 2617 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2618 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2619 | if (u8c >= 0x10000) |
| 2620 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2621 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2622 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2623 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2624 | for (i = 0; i < Screen_mco; ++i) |
| 2625 | { |
| 2626 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2627 | if (u8cc[i] == 0) |
| 2628 | break; |
| 2629 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2630 | } |
| 2631 | if (cells > 1) |
| 2632 | ScreenLines[idx + 1] = 0; |
| 2633 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2634 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2635 | /* double-byte single width character */ |
| 2636 | ScreenLines2[idx] = p[1]; |
| 2637 | else if (cells > 1) |
| 2638 | /* double-width character */ |
| 2639 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2640 | col += cells; |
| 2641 | idx += cells; |
| 2642 | p += c_len; |
| 2643 | } |
| 2644 | } |
| 2645 | else |
| 2646 | #endif |
| 2647 | { |
| 2648 | len = (int)STRLEN(text); |
| 2649 | if (len > W_WIDTH(wp) - col) |
| 2650 | len = W_WIDTH(wp) - col; |
| 2651 | if (len > 0) |
| 2652 | { |
| 2653 | #ifdef FEAT_RIGHTLEFT |
| 2654 | if (wp->w_p_rl) |
| 2655 | STRNCPY(current_ScreenLine, text, len); |
| 2656 | else |
| 2657 | #endif |
| 2658 | STRNCPY(current_ScreenLine + col, text, len); |
| 2659 | col += len; |
| 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | /* Fill the rest of the line with the fold filler */ |
| 2664 | #ifdef FEAT_RIGHTLEFT |
| 2665 | if (wp->w_p_rl) |
| 2666 | col -= txtcol; |
| 2667 | #endif |
| 2668 | while (col < W_WIDTH(wp) |
| 2669 | #ifdef FEAT_RIGHTLEFT |
| 2670 | - (wp->w_p_rl ? txtcol : 0) |
| 2671 | #endif |
| 2672 | ) |
| 2673 | { |
| 2674 | #ifdef FEAT_MBYTE |
| 2675 | if (enc_utf8) |
| 2676 | { |
| 2677 | if (fill_fold >= 0x80) |
| 2678 | { |
| 2679 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2680 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2681 | } |
| 2682 | else |
| 2683 | ScreenLinesUC[off + col] = 0; |
| 2684 | } |
| 2685 | #endif |
| 2686 | ScreenLines[off + col++] = fill_fold; |
| 2687 | } |
| 2688 | |
| 2689 | if (text != buf) |
| 2690 | vim_free(text); |
| 2691 | |
| 2692 | /* |
| 2693 | * 6. set highlighting for the Visual area an other text. |
| 2694 | * If all folded lines are in the Visual area, highlight the line. |
| 2695 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2696 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2697 | { |
| 2698 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2699 | { |
| 2700 | /* Visual is after curwin->w_cursor */ |
| 2701 | top = &curwin->w_cursor; |
| 2702 | bot = &VIsual; |
| 2703 | } |
| 2704 | else |
| 2705 | { |
| 2706 | /* Visual is before curwin->w_cursor */ |
| 2707 | top = &VIsual; |
| 2708 | bot = &curwin->w_cursor; |
| 2709 | } |
| 2710 | if (lnum >= top->lnum |
| 2711 | && lnume <= bot->lnum |
| 2712 | && (VIsual_mode != 'v' |
| 2713 | || ((lnum > top->lnum |
| 2714 | || (lnum == top->lnum |
| 2715 | && top->col == 0)) |
| 2716 | && (lnume < bot->lnum |
| 2717 | || (lnume == bot->lnum |
| 2718 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2719 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2720 | { |
| 2721 | if (VIsual_mode == Ctrl_V) |
| 2722 | { |
| 2723 | /* Visual block mode: highlight the chars part of the block */ |
| 2724 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2725 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2726 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2727 | && wp->w_old_cursor_lcol + txtcol |
| 2728 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2729 | len = wp->w_old_cursor_lcol; |
| 2730 | else |
| 2731 | len = W_WIDTH(wp) - txtcol; |
| 2732 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2733 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2737 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2738 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2739 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2740 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2741 | } |
| 2742 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2743 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2744 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2745 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2746 | if (wp->w_p_cc_cols) |
| 2747 | { |
| 2748 | int i = 0; |
| 2749 | int j = wp->w_p_cc_cols[i]; |
| 2750 | int old_txtcol = txtcol; |
| 2751 | |
| 2752 | while (j > -1) |
| 2753 | { |
| 2754 | txtcol += j; |
| 2755 | if (wp->w_p_wrap) |
| 2756 | txtcol -= wp->w_skipcol; |
| 2757 | else |
| 2758 | txtcol -= wp->w_leftcol; |
| 2759 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2760 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2761 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2762 | txtcol = old_txtcol; |
| 2763 | j = wp->w_p_cc_cols[++i]; |
| 2764 | } |
| 2765 | } |
| 2766 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2767 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2768 | if (wp->w_p_cuc) |
| 2769 | { |
| 2770 | txtcol += wp->w_virtcol; |
| 2771 | if (wp->w_p_wrap) |
| 2772 | txtcol -= wp->w_skipcol; |
| 2773 | else |
| 2774 | txtcol -= wp->w_leftcol; |
| 2775 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2776 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2777 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2778 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2779 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2780 | |
| 2781 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2782 | (int)W_WIDTH(wp), FALSE); |
| 2783 | |
| 2784 | /* |
| 2785 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2786 | * updated (saves a call to plines() later). |
| 2787 | */ |
| 2788 | if (wp == curwin |
| 2789 | && lnum <= curwin->w_cursor.lnum |
| 2790 | && lnume >= curwin->w_cursor.lnum) |
| 2791 | { |
| 2792 | curwin->w_cline_row = row; |
| 2793 | curwin->w_cline_height = 1; |
| 2794 | curwin->w_cline_folded = TRUE; |
| 2795 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2796 | } |
| 2797 | } |
| 2798 | |
| 2799 | /* |
| 2800 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2801 | */ |
| 2802 | static void |
| 2803 | copy_text_attr(off, buf, len, attr) |
| 2804 | int off; |
| 2805 | char_u *buf; |
| 2806 | int len; |
| 2807 | int attr; |
| 2808 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2809 | int i; |
| 2810 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2811 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2812 | # ifdef FEAT_MBYTE |
| 2813 | if (enc_utf8) |
| 2814 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2815 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2816 | for (i = 0; i < len; ++i) |
| 2817 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | /* |
| 2821 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2822 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2823 | */ |
| 2824 | static void |
| 2825 | fill_foldcolumn(p, wp, closed, lnum) |
| 2826 | char_u *p; |
| 2827 | win_T *wp; |
| 2828 | int closed; /* TRUE of FALSE */ |
| 2829 | linenr_T lnum; /* current line number */ |
| 2830 | { |
| 2831 | int i = 0; |
| 2832 | int level; |
| 2833 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2834 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2835 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2836 | |
| 2837 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2838 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2839 | |
| 2840 | level = win_foldinfo.fi_level; |
| 2841 | if (level > 0) |
| 2842 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2843 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2844 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2845 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2846 | /* If the column is too narrow, we start at the lowest level that |
| 2847 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2848 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2849 | if (first_level < 1) |
| 2850 | first_level = 1; |
| 2851 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2852 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2853 | { |
| 2854 | if (win_foldinfo.fi_lnum == lnum |
| 2855 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2856 | p[i] = '-'; |
| 2857 | else if (first_level == 1) |
| 2858 | p[i] = '|'; |
| 2859 | else if (first_level + i <= 9) |
| 2860 | p[i] = '0' + first_level + i; |
| 2861 | else |
| 2862 | p[i] = '>'; |
| 2863 | if (first_level + i == level) |
| 2864 | break; |
| 2865 | } |
| 2866 | } |
| 2867 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2868 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2869 | } |
| 2870 | #endif /* FEAT_FOLDING */ |
| 2871 | |
| 2872 | /* |
| 2873 | * Display line "lnum" of window 'wp' on the screen. |
| 2874 | * Start at row "startrow", stop when "endrow" is reached. |
| 2875 | * wp->w_virtcol needs to be valid. |
| 2876 | * |
| 2877 | * Return the number of last row the line occupies. |
| 2878 | */ |
| 2879 | static int |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2880 | win_line(wp, lnum, startrow, endrow, nochange) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2881 | win_T *wp; |
| 2882 | linenr_T lnum; |
| 2883 | int startrow; |
| 2884 | int endrow; |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2885 | int nochange UNUSED; /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2886 | { |
| 2887 | int col; /* visual column on screen */ |
| 2888 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2889 | int c = 0; /* init for GCC */ |
| 2890 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2891 | #ifdef FEAT_LINEBREAK |
| 2892 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2893 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2894 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2895 | char_u *line; /* current line */ |
| 2896 | char_u *ptr; /* current position in "line" */ |
| 2897 | int row; /* row in the window, excl w_winrow */ |
| 2898 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2899 | |
| 2900 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2901 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2902 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2903 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2904 | int c_extra = NUL; /* extra chars, all the same */ |
| 2905 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2906 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2907 | displaying lcs_eol at end-of-line */ |
| 2908 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2909 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2910 | |
| 2911 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2912 | int saved_n_extra = 0; |
| 2913 | char_u *saved_p_extra = NULL; |
| 2914 | int saved_c_extra = 0; |
| 2915 | int saved_char_attr = 0; |
| 2916 | |
| 2917 | int n_attr = 0; /* chars with special attr */ |
| 2918 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2919 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2920 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2921 | |
| 2922 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2923 | |
| 2924 | int fromcol, tocol; /* start/end of inverting */ |
| 2925 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2926 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2927 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2928 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2929 | pos_T pos; |
| 2930 | long v; |
| 2931 | |
| 2932 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2933 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2934 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2935 | in this line */ |
| 2936 | int attr = 0; /* attributes for area highlighting */ |
| 2937 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2938 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2939 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2940 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2941 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2942 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2943 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2944 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2945 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2946 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2947 | #endif |
| 2948 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2949 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2950 | # define SPWORDLEN 150 |
| 2951 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2952 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2953 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2954 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2955 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2956 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2957 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2958 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2959 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2960 | static int cap_col = -1; /* column to check for Cap word */ |
| 2961 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2962 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2963 | #endif |
| 2964 | int extra_check; /* has syntax or linebreak */ |
| 2965 | #ifdef FEAT_MBYTE |
| 2966 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2967 | int mb_l = 1; /* multi-byte byte length */ |
| 2968 | int mb_c = 0; /* decoded multi-byte character */ |
| 2969 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2970 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2971 | #endif |
| 2972 | #ifdef FEAT_DIFF |
| 2973 | int filler_lines; /* nr of filler lines to be drawn */ |
| 2974 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 2975 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2976 | int change_start = MAXCOL; /* first col of changed area */ |
| 2977 | int change_end = -1; /* last col of changed area */ |
| 2978 | #endif |
| 2979 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 2980 | #ifdef FEAT_LINEBREAK |
| 2981 | int need_showbreak = FALSE; |
| 2982 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 2983 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 2984 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2985 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 2986 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2987 | #endif |
| 2988 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2989 | matchitem_T *cur; /* points to the match list */ |
| 2990 | match_T *shl; /* points to search_hl or a match */ |
| 2991 | int shl_flag; /* flag to indicate whether search_hl |
| 2992 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 2993 | int pos_inprogress; /* marks that position match search is |
| 2994 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 2995 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 2996 | equals startcol of search_hl or one |
| 2997 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2998 | #endif |
| 2999 | #ifdef FEAT_ARABIC |
| 3000 | int prev_c = 0; /* previous Arabic character */ |
| 3001 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 3002 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3003 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 3004 | int did_line_attr = 0; |
| 3005 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3006 | |
| 3007 | /* draw_state: items that are drawn in sequence: */ |
| 3008 | #define WL_START 0 /* nothing done yet */ |
| 3009 | #ifdef FEAT_CMDWIN |
| 3010 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 3011 | #else |
| 3012 | # define WL_CMDLINE WL_START |
| 3013 | #endif |
| 3014 | #ifdef FEAT_FOLDING |
| 3015 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 3016 | #else |
| 3017 | # define WL_FOLD WL_CMDLINE |
| 3018 | #endif |
| 3019 | #ifdef FEAT_SIGNS |
| 3020 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3021 | #else |
| 3022 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3023 | #endif |
| 3024 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3025 | #ifdef FEAT_LINEBREAK |
| 3026 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3027 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3028 | # define WL_BRI WL_NR |
| 3029 | #endif |
| 3030 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3031 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3032 | #else |
| 3033 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3034 | #endif |
| 3035 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3036 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3037 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3038 | int feedback_col = 0; |
| 3039 | int feedback_old_attr = -1; |
| 3040 | #endif |
| 3041 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3042 | #ifdef FEAT_CONCEAL |
| 3043 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3044 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3045 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3046 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3047 | int is_concealing = FALSE; |
| 3048 | int boguscols = 0; /* nonexistent columns added to force |
| 3049 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3050 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3051 | int did_wcol = FALSE; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3052 | int match_conc = FALSE; /* cchar for match functions */ |
| 3053 | int has_match_conc = FALSE; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3054 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3055 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3056 | # define FIX_FOR_BOGUSCOLS \ |
| 3057 | { \ |
| 3058 | n_extra += vcol_off; \ |
| 3059 | vcol -= vcol_off; \ |
| 3060 | vcol_off = 0; \ |
| 3061 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3062 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3063 | boguscols = 0; \ |
| 3064 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3065 | #else |
| 3066 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3067 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3068 | |
| 3069 | if (startrow > endrow) /* past the end already! */ |
| 3070 | return startrow; |
| 3071 | |
| 3072 | row = startrow; |
| 3073 | screen_row = row + W_WINROW(wp); |
| 3074 | |
| 3075 | /* |
| 3076 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3077 | * trailing white space and/or syntax processing to be done. |
| 3078 | */ |
| 3079 | #ifdef FEAT_LINEBREAK |
| 3080 | extra_check = wp->w_p_lbr; |
| 3081 | #else |
| 3082 | extra_check = 0; |
| 3083 | #endif |
| 3084 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3085 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3086 | { |
| 3087 | /* Prepare for syntax highlighting in this line. When there is an |
| 3088 | * error, stop syntax highlighting. */ |
| 3089 | save_did_emsg = did_emsg; |
| 3090 | did_emsg = FALSE; |
| 3091 | syntax_start(wp, lnum); |
| 3092 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3093 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3094 | else |
| 3095 | { |
| 3096 | did_emsg = save_did_emsg; |
| 3097 | has_syntax = TRUE; |
| 3098 | extra_check = TRUE; |
| 3099 | } |
| 3100 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3101 | |
| 3102 | /* Check for columns to display for 'colorcolumn'. */ |
| 3103 | color_cols = wp->w_p_cc_cols; |
| 3104 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3105 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3106 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3107 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3108 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3109 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3110 | && *wp->w_s->b_p_spl != NUL |
| 3111 | && wp->w_s->b_langp.ga_len > 0 |
| 3112 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3113 | { |
| 3114 | /* Prepare for spell checking. */ |
| 3115 | has_spell = TRUE; |
| 3116 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3117 | |
| 3118 | /* Get the start of the next line, so that words that wrap to the next |
| 3119 | * line are found too: "et<line-break>al.". |
| 3120 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3121 | nextline[SPWORDLEN] = NUL; |
| 3122 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3123 | { |
| 3124 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3125 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3126 | } |
| 3127 | |
| 3128 | /* When a word wrapped from the previous line the start of the current |
| 3129 | * line is valid. */ |
| 3130 | if (lnum == checked_lnum) |
| 3131 | cur_checked_col = checked_col; |
| 3132 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3133 | |
| 3134 | /* When there was a sentence end in the previous line may require a |
| 3135 | * word starting with capital in this line. In line 1 always check |
| 3136 | * the first word. */ |
| 3137 | if (lnum != capcol_lnum) |
| 3138 | cap_col = -1; |
| 3139 | if (lnum == 1) |
| 3140 | cap_col = 0; |
| 3141 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3142 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3143 | #endif |
| 3144 | |
| 3145 | /* |
| 3146 | * handle visual active in this window |
| 3147 | */ |
| 3148 | fromcol = -10; |
| 3149 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3150 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3151 | { |
| 3152 | /* Visual is after curwin->w_cursor */ |
| 3153 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3154 | { |
| 3155 | top = &curwin->w_cursor; |
| 3156 | bot = &VIsual; |
| 3157 | } |
| 3158 | else /* Visual is before curwin->w_cursor */ |
| 3159 | { |
| 3160 | top = &VIsual; |
| 3161 | bot = &curwin->w_cursor; |
| 3162 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3163 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3164 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3165 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3166 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3167 | { |
| 3168 | fromcol = wp->w_old_cursor_fcol; |
| 3169 | tocol = wp->w_old_cursor_lcol; |
| 3170 | } |
| 3171 | } |
| 3172 | else /* non-block mode */ |
| 3173 | { |
| 3174 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3175 | fromcol = 0; |
| 3176 | else if (lnum == top->lnum) |
| 3177 | { |
| 3178 | if (VIsual_mode == 'V') /* linewise */ |
| 3179 | fromcol = 0; |
| 3180 | else |
| 3181 | { |
| 3182 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3183 | if (gchar_pos(top) == NUL) |
| 3184 | tocol = fromcol + 1; |
| 3185 | } |
| 3186 | } |
| 3187 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3188 | { |
| 3189 | if (*p_sel == 'e' && bot->col == 0 |
| 3190 | #ifdef FEAT_VIRTUALEDIT |
| 3191 | && bot->coladd == 0 |
| 3192 | #endif |
| 3193 | ) |
| 3194 | { |
| 3195 | fromcol = -10; |
| 3196 | tocol = MAXCOL; |
| 3197 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3198 | else if (bot->col == MAXCOL) |
| 3199 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3200 | else |
| 3201 | { |
| 3202 | pos = *bot; |
| 3203 | if (*p_sel == 'e') |
| 3204 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3205 | else |
| 3206 | { |
| 3207 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3208 | ++tocol; |
| 3209 | } |
| 3210 | } |
| 3211 | } |
| 3212 | } |
| 3213 | |
| 3214 | #ifndef MSDOS |
| 3215 | /* Check if the character under the cursor should not be inverted */ |
| 3216 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
| 3217 | # ifdef FEAT_GUI |
| 3218 | && !gui.in_use |
| 3219 | # endif |
| 3220 | ) |
| 3221 | noinvcur = TRUE; |
| 3222 | #endif |
| 3223 | |
| 3224 | /* if inverting in this line set area_highlighting */ |
| 3225 | if (fromcol >= 0) |
| 3226 | { |
| 3227 | area_highlighting = TRUE; |
| 3228 | attr = hl_attr(HLF_V); |
| 3229 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3230 | if ((clip_star.available && !clip_star.owned |
| 3231 | && clip_isautosel_star()) |
| 3232 | || (clip_plus.available && !clip_plus.owned |
| 3233 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3234 | attr = hl_attr(HLF_VNC); |
| 3235 | #endif |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3240 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3241 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3242 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3243 | && wp == curwin |
| 3244 | && lnum >= curwin->w_cursor.lnum |
| 3245 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3246 | { |
| 3247 | if (lnum == curwin->w_cursor.lnum) |
| 3248 | getvcol(curwin, &(curwin->w_cursor), |
| 3249 | (colnr_T *)&fromcol, NULL, NULL); |
| 3250 | else |
| 3251 | fromcol = 0; |
| 3252 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3253 | { |
| 3254 | pos.lnum = lnum; |
| 3255 | pos.col = search_match_endcol; |
| 3256 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3257 | } |
| 3258 | else |
| 3259 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3260 | /* do at least one character; happens when past end of line */ |
| 3261 | if (fromcol == tocol) |
| 3262 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3263 | area_highlighting = TRUE; |
| 3264 | attr = hl_attr(HLF_I); |
| 3265 | } |
| 3266 | |
| 3267 | #ifdef FEAT_DIFF |
| 3268 | filler_lines = diff_check(wp, lnum); |
| 3269 | if (filler_lines < 0) |
| 3270 | { |
| 3271 | if (filler_lines == -1) |
| 3272 | { |
| 3273 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3274 | diff_hlf = HLF_ADD; /* added line */ |
| 3275 | else if (change_start == 0) |
| 3276 | diff_hlf = HLF_TXD; /* changed text */ |
| 3277 | else |
| 3278 | diff_hlf = HLF_CHD; /* changed line */ |
| 3279 | } |
| 3280 | else |
| 3281 | diff_hlf = HLF_ADD; /* added line */ |
| 3282 | filler_lines = 0; |
| 3283 | area_highlighting = TRUE; |
| 3284 | } |
| 3285 | if (lnum == wp->w_topline) |
| 3286 | filler_lines = wp->w_topfill; |
| 3287 | filler_todo = filler_lines; |
| 3288 | #endif |
| 3289 | |
| 3290 | #ifdef LINE_ATTR |
| 3291 | # ifdef FEAT_SIGNS |
| 3292 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3293 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3294 | if (v != 0) |
| 3295 | line_attr = sign_get_attr((int)v, TRUE); |
| 3296 | # endif |
| 3297 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3298 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3299 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3300 | line_attr = hl_attr(HLF_L); |
| 3301 | # endif |
| 3302 | if (line_attr != 0) |
| 3303 | area_highlighting = TRUE; |
| 3304 | #endif |
| 3305 | |
| 3306 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3307 | ptr = line; |
| 3308 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3309 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3310 | if (has_spell) |
| 3311 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3312 | /* For checking first word with a capital skip white space. */ |
| 3313 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3314 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3315 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3316 | /* To be able to spell-check over line boundaries copy the end of the |
| 3317 | * current line into nextline[]. Above the start of the next line was |
| 3318 | * copied to nextline[SPWORDLEN]. */ |
| 3319 | if (nextline[SPWORDLEN] == NUL) |
| 3320 | { |
| 3321 | /* No next line or it is empty. */ |
| 3322 | nextlinecol = MAXCOL; |
| 3323 | nextline_idx = 0; |
| 3324 | } |
| 3325 | else |
| 3326 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3327 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3328 | if (v < SPWORDLEN) |
| 3329 | { |
| 3330 | /* Short line, use it completely and append the start of the |
| 3331 | * next line. */ |
| 3332 | nextlinecol = 0; |
| 3333 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3334 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3335 | nextline_idx = v + 1; |
| 3336 | } |
| 3337 | else |
| 3338 | { |
| 3339 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3340 | nextlinecol = v - SPWORDLEN; |
| 3341 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3342 | nextline_idx = SPWORDLEN + 1; |
| 3343 | } |
| 3344 | } |
| 3345 | } |
| 3346 | #endif |
| 3347 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3348 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3349 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3350 | if (lcs_space || lcs_trail) |
| 3351 | extra_check = TRUE; |
| 3352 | /* find start of trailing whitespace */ |
| 3353 | if (lcs_trail) |
| 3354 | { |
| 3355 | trailcol = (colnr_T)STRLEN(ptr); |
| 3356 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3357 | --trailcol; |
| 3358 | trailcol += (colnr_T) (ptr - line); |
| 3359 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | /* |
| 3363 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3364 | * first character to be displayed. |
| 3365 | */ |
| 3366 | if (wp->w_p_wrap) |
| 3367 | v = wp->w_skipcol; |
| 3368 | else |
| 3369 | v = wp->w_leftcol; |
| 3370 | if (v > 0) |
| 3371 | { |
| 3372 | #ifdef FEAT_MBYTE |
| 3373 | char_u *prev_ptr = ptr; |
| 3374 | #endif |
| 3375 | while (vcol < v && *ptr != NUL) |
| 3376 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3377 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3378 | vcol += c; |
| 3379 | #ifdef FEAT_MBYTE |
| 3380 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3381 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3382 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3383 | } |
| 3384 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3385 | /* When: |
| 3386 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3387 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3388 | * - 'virtualedit' is set, or |
| 3389 | * - the visual mode is active, |
| 3390 | * the end of the line may be before the start of the displayed part. |
| 3391 | */ |
| 3392 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3393 | #ifdef FEAT_SYN_HL |
| 3394 | wp->w_p_cuc || draw_color_col || |
| 3395 | #endif |
| 3396 | #ifdef FEAT_VIRTUALEDIT |
| 3397 | virtual_active() || |
| 3398 | #endif |
| 3399 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3400 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3401 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3402 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3403 | |
| 3404 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3405 | * that character but skip the first few screen characters. */ |
| 3406 | if (vcol > v) |
| 3407 | { |
| 3408 | vcol -= c; |
| 3409 | #ifdef FEAT_MBYTE |
| 3410 | ptr = prev_ptr; |
| 3411 | #else |
| 3412 | --ptr; |
| 3413 | #endif |
| 3414 | n_skip = v - vcol; |
| 3415 | } |
| 3416 | |
| 3417 | /* |
| 3418 | * Adjust for when the inverted text is before the screen, |
| 3419 | * and when the start of the inverted text is before the screen. |
| 3420 | */ |
| 3421 | if (tocol <= vcol) |
| 3422 | fromcol = 0; |
| 3423 | else if (fromcol >= 0 && fromcol < vcol) |
| 3424 | fromcol = vcol; |
| 3425 | |
| 3426 | #ifdef FEAT_LINEBREAK |
| 3427 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3428 | if (wp->w_p_wrap) |
| 3429 | need_showbreak = TRUE; |
| 3430 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3431 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3432 | /* When spell checking a word we need to figure out the start of the |
| 3433 | * word and if it's badly spelled or not. */ |
| 3434 | if (has_spell) |
| 3435 | { |
| 3436 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3437 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3438 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3439 | |
| 3440 | pos = wp->w_cursor; |
| 3441 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3442 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3443 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3444 | |
| 3445 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3446 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3447 | ptr = line + linecol; |
| 3448 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3449 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3450 | { |
| 3451 | /* no bad word found at line start, don't check until end of a |
| 3452 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3453 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3454 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3455 | } |
| 3456 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3457 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3458 | /* bad word found, use attributes until end of word */ |
| 3459 | word_end = wp->w_cursor.col + len + 1; |
| 3460 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3461 | /* Turn index into actual attributes. */ |
| 3462 | if (spell_hlf != HLF_COUNT) |
| 3463 | spell_attr = highlight_attr[spell_hlf]; |
| 3464 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3465 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3466 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3467 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3468 | /* Need to restart syntax highlighting for this line. */ |
| 3469 | if (has_syntax) |
| 3470 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3471 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3472 | } |
| 3473 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3474 | } |
| 3475 | |
| 3476 | /* |
| 3477 | * Correct highlighting for cursor that can't be disabled. |
| 3478 | * Avoids having to check this for each character. |
| 3479 | */ |
| 3480 | if (fromcol >= 0) |
| 3481 | { |
| 3482 | if (noinvcur) |
| 3483 | { |
| 3484 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3485 | { |
| 3486 | /* highlighting starts at cursor, let it start just after the |
| 3487 | * cursor */ |
| 3488 | fromcol_prev = fromcol; |
| 3489 | fromcol = -1; |
| 3490 | } |
| 3491 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3492 | /* restart highlighting after the cursor */ |
| 3493 | fromcol_prev = wp->w_virtcol; |
| 3494 | } |
| 3495 | if (fromcol >= tocol) |
| 3496 | fromcol = -1; |
| 3497 | } |
| 3498 | |
| 3499 | #ifdef FEAT_SEARCH_EXTRA |
| 3500 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3501 | * Handle highlighting the last used search pattern and matches. |
| 3502 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3503 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3504 | cur = wp->w_match_head; |
| 3505 | shl_flag = FALSE; |
| 3506 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3507 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3508 | if (shl_flag == FALSE) |
| 3509 | { |
| 3510 | shl = &search_hl; |
| 3511 | shl_flag = TRUE; |
| 3512 | } |
| 3513 | else |
| 3514 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3515 | shl->startcol = MAXCOL; |
| 3516 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3517 | shl->attr_cur = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3518 | v = (long)(ptr - line); |
| 3519 | if (cur != NULL) |
| 3520 | cur->pos.cur = 0; |
| 3521 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3522 | |
| 3523 | /* Need to get the line again, a multi-line regexp may have made it |
| 3524 | * invalid. */ |
| 3525 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3526 | ptr = line + v; |
| 3527 | |
| 3528 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3529 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3530 | if (shl->lnum == lnum) |
| 3531 | shl->startcol = shl->rm.startpos[0].col; |
| 3532 | else |
| 3533 | shl->startcol = 0; |
| 3534 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3535 | - shl->rm.startpos[0].lnum) |
| 3536 | shl->endcol = shl->rm.endpos[0].col; |
| 3537 | else |
| 3538 | shl->endcol = MAXCOL; |
| 3539 | /* Highlight one character for an empty match. */ |
| 3540 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3541 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3542 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3543 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3544 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3545 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3546 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3547 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3548 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3549 | if ((long)shl->startcol < v) /* match at leftcol */ |
| 3550 | { |
| 3551 | shl->attr_cur = shl->attr; |
| 3552 | search_attr = shl->attr; |
| 3553 | } |
| 3554 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3555 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3556 | if (shl != &search_hl && cur != NULL) |
| 3557 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3558 | } |
| 3559 | #endif |
| 3560 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3561 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3562 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3563 | * when Visual mode is active, because it's not clear what is selected |
| 3564 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3565 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3566 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3567 | { |
| 3568 | line_attr = hl_attr(HLF_CUL); |
| 3569 | area_highlighting = TRUE; |
| 3570 | } |
| 3571 | #endif |
| 3572 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3573 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3574 | col = 0; |
| 3575 | #ifdef FEAT_RIGHTLEFT |
| 3576 | if (wp->w_p_rl) |
| 3577 | { |
| 3578 | /* Rightleft window: process the text in the normal direction, but put |
| 3579 | * it in current_ScreenLine[] from right to left. Start at the |
| 3580 | * rightmost column of the window. */ |
| 3581 | col = W_WIDTH(wp) - 1; |
| 3582 | off += col; |
| 3583 | } |
| 3584 | #endif |
| 3585 | |
| 3586 | /* |
| 3587 | * Repeat for the whole displayed line. |
| 3588 | */ |
| 3589 | for (;;) |
| 3590 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3591 | #ifdef FEAT_CONCEAL |
| 3592 | has_match_conc = FALSE; |
| 3593 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3594 | /* Skip this quickly when working on the text. */ |
| 3595 | if (draw_state != WL_LINE) |
| 3596 | { |
| 3597 | #ifdef FEAT_CMDWIN |
| 3598 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3599 | { |
| 3600 | draw_state = WL_CMDLINE; |
| 3601 | if (cmdwin_type != 0 && wp == curwin) |
| 3602 | { |
| 3603 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3604 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3605 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3606 | char_attr = hl_attr(HLF_AT); |
| 3607 | } |
| 3608 | } |
| 3609 | #endif |
| 3610 | |
| 3611 | #ifdef FEAT_FOLDING |
| 3612 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3613 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3614 | int fdc = compute_foldcolumn(wp, 0); |
| 3615 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3616 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3617 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3618 | { |
| 3619 | /* Draw the 'foldcolumn'. */ |
| 3620 | fill_foldcolumn(extra, wp, FALSE, lnum); |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3621 | n_extra = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3622 | p_extra = extra; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3623 | p_extra[n_extra] = NUL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3624 | c_extra = NUL; |
| 3625 | char_attr = hl_attr(HLF_FC); |
| 3626 | } |
| 3627 | } |
| 3628 | #endif |
| 3629 | |
| 3630 | #ifdef FEAT_SIGNS |
| 3631 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3632 | { |
| 3633 | draw_state = WL_SIGN; |
| 3634 | /* Show the sign column when there are any signs in this |
| 3635 | * buffer or when using Netbeans. */ |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3636 | if (draw_signcolumn(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3637 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3638 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3639 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3640 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3641 | # endif |
| 3642 | |
| 3643 | /* Draw two cells with the sign value or blank. */ |
| 3644 | c_extra = ' '; |
| 3645 | char_attr = hl_attr(HLF_SC); |
| 3646 | n_extra = 2; |
| 3647 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3648 | if (row == startrow |
| 3649 | #ifdef FEAT_DIFF |
| 3650 | + filler_lines && filler_todo <= 0 |
| 3651 | #endif |
| 3652 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3653 | { |
| 3654 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3655 | SIGN_TEXT); |
| 3656 | # ifdef FEAT_SIGN_ICONS |
| 3657 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3658 | SIGN_ICON); |
| 3659 | if (gui.in_use && icon_sign != 0) |
| 3660 | { |
| 3661 | /* Use the image in this position. */ |
| 3662 | c_extra = SIGN_BYTE; |
| 3663 | # ifdef FEAT_NETBEANS_INTG |
| 3664 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3665 | c_extra = MULTISIGN_BYTE; |
| 3666 | # endif |
| 3667 | char_attr = icon_sign; |
| 3668 | } |
| 3669 | else |
| 3670 | # endif |
| 3671 | if (text_sign != 0) |
| 3672 | { |
| 3673 | p_extra = sign_get_text(text_sign); |
| 3674 | if (p_extra != NULL) |
| 3675 | { |
| 3676 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3677 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3678 | } |
| 3679 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3680 | } |
| 3681 | } |
| 3682 | } |
| 3683 | } |
| 3684 | #endif |
| 3685 | |
| 3686 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3687 | { |
| 3688 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3689 | /* Display the absolute or relative line number. After the |
| 3690 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3691 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3692 | && (row == startrow |
| 3693 | #ifdef FEAT_DIFF |
| 3694 | + filler_lines |
| 3695 | #endif |
| 3696 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3697 | { |
| 3698 | /* Draw the line number (empty space after wrapping). */ |
| 3699 | if (row == startrow |
| 3700 | #ifdef FEAT_DIFF |
| 3701 | + filler_lines |
| 3702 | #endif |
| 3703 | ) |
| 3704 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3705 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3706 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3707 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3708 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3709 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3710 | num = (long)lnum; |
| 3711 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3712 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3713 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3714 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3715 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3716 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3717 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3718 | num = lnum; |
| 3719 | fmt = "%-*ld "; |
| 3720 | } |
| 3721 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3722 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3723 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3724 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3725 | if (wp->w_skipcol > 0) |
| 3726 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3727 | *p_extra = '-'; |
| 3728 | #ifdef FEAT_RIGHTLEFT |
| 3729 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3730 | rl_mirror(extra); |
| 3731 | #endif |
| 3732 | p_extra = extra; |
| 3733 | c_extra = NUL; |
| 3734 | } |
| 3735 | else |
| 3736 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3737 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3738 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3739 | #ifdef FEAT_SYN_HL |
| 3740 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3741 | * the current line differently. |
| 3742 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3743 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3744 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3745 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3746 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3747 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3748 | } |
| 3749 | } |
| 3750 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3751 | #ifdef FEAT_LINEBREAK |
| 3752 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3753 | && n_extra == 0 && *p_sbr != NUL) |
| 3754 | /* draw indent after showbreak value */ |
| 3755 | draw_state = WL_BRI; |
| 3756 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3757 | /* After the showbreak, draw the breakindent */ |
| 3758 | draw_state = WL_BRI - 1; |
| 3759 | |
| 3760 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3761 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3762 | { |
| 3763 | draw_state = WL_BRI; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3764 | if (wp->w_p_bri && n_extra == 0 && row != startrow |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3765 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3766 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3767 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3768 | ) |
| 3769 | { |
| 3770 | char_attr = 0; /* was: hl_attr(HLF_AT); */ |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3771 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3772 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3773 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3774 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3775 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3776 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3777 | char_attr = hl_combine_attr(char_attr, |
| 3778 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3779 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3780 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3781 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3782 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3783 | c_extra = ' '; |
| 3784 | n_extra = get_breakindent_win(wp, |
| 3785 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3786 | /* Correct end of highlighted area for 'breakindent', |
| 3787 | * required when 'linebreak' is also set. */ |
| 3788 | if (tocol == vcol) |
| 3789 | tocol += n_extra; |
| 3790 | } |
| 3791 | } |
| 3792 | #endif |
| 3793 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3794 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3795 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3796 | { |
| 3797 | draw_state = WL_SBR; |
| 3798 | # ifdef FEAT_DIFF |
| 3799 | if (filler_todo > 0) |
| 3800 | { |
| 3801 | /* Draw "deleted" diff line(s). */ |
| 3802 | if (char2cells(fill_diff) > 1) |
| 3803 | c_extra = '-'; |
| 3804 | else |
| 3805 | c_extra = fill_diff; |
| 3806 | # ifdef FEAT_RIGHTLEFT |
| 3807 | if (wp->w_p_rl) |
| 3808 | n_extra = col + 1; |
| 3809 | else |
| 3810 | # endif |
| 3811 | n_extra = W_WIDTH(wp) - col; |
| 3812 | char_attr = hl_attr(HLF_DED); |
| 3813 | } |
| 3814 | # endif |
| 3815 | # ifdef FEAT_LINEBREAK |
| 3816 | if (*p_sbr != NUL && need_showbreak) |
| 3817 | { |
| 3818 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3819 | p_extra = p_sbr; |
| 3820 | c_extra = NUL; |
| 3821 | n_extra = (int)STRLEN(p_sbr); |
| 3822 | char_attr = hl_attr(HLF_AT); |
| 3823 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3824 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3825 | /* Correct end of highlighted area for 'showbreak', |
| 3826 | * required when 'linebreak' is also set. */ |
| 3827 | if (tocol == vcol) |
| 3828 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3829 | #ifdef FEAT_SYN_HL |
| 3830 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3831 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3832 | char_attr = hl_combine_attr(char_attr, |
| 3833 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3834 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3835 | } |
| 3836 | # endif |
| 3837 | } |
| 3838 | #endif |
| 3839 | |
| 3840 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3841 | { |
| 3842 | draw_state = WL_LINE; |
| 3843 | if (saved_n_extra) |
| 3844 | { |
| 3845 | /* Continue item from end of wrapped line. */ |
| 3846 | n_extra = saved_n_extra; |
| 3847 | c_extra = saved_c_extra; |
| 3848 | p_extra = saved_p_extra; |
| 3849 | char_attr = saved_char_attr; |
| 3850 | } |
| 3851 | else |
| 3852 | char_attr = 0; |
| 3853 | } |
| 3854 | } |
| 3855 | |
| 3856 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3857 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3858 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3859 | #ifdef FEAT_DIFF |
| 3860 | && filler_todo <= 0 |
| 3861 | #endif |
| 3862 | ) |
| 3863 | { |
| 3864 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3865 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3866 | /* Pretend we have finished updating the window. Except when |
| 3867 | * 'cursorcolumn' is set. */ |
| 3868 | #ifdef FEAT_SYN_HL |
| 3869 | if (wp->w_p_cuc) |
| 3870 | row = wp->w_cline_row + wp->w_cline_height; |
| 3871 | else |
| 3872 | #endif |
| 3873 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3874 | break; |
| 3875 | } |
| 3876 | |
| 3877 | if (draw_state == WL_LINE && area_highlighting) |
| 3878 | { |
| 3879 | /* handle Visual or match highlighting in this line */ |
| 3880 | if (vcol == fromcol |
| 3881 | #ifdef FEAT_MBYTE |
| 3882 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3883 | && (*mb_ptr2cells)(ptr) > 1) |
| 3884 | #endif |
| 3885 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3886 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3887 | && vcol < tocol)) |
| 3888 | area_attr = attr; /* start highlighting */ |
| 3889 | else if (area_attr != 0 |
| 3890 | && (vcol == tocol |
| 3891 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3892 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3893 | |
| 3894 | #ifdef FEAT_SEARCH_EXTRA |
| 3895 | if (!n_extra) |
| 3896 | { |
| 3897 | /* |
| 3898 | * Check for start/end of search pattern match. |
| 3899 | * After end, check for start/end of next match. |
| 3900 | * When another match, have to check for start again. |
| 3901 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3902 | * Do this for 'search_hl' and the match list (ordered by |
| 3903 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3904 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3905 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3906 | cur = wp->w_match_head; |
| 3907 | shl_flag = FALSE; |
| 3908 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3909 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3910 | if (shl_flag == FALSE |
| 3911 | && ((cur != NULL |
| 3912 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3913 | || cur == NULL)) |
| 3914 | { |
| 3915 | shl = &search_hl; |
| 3916 | shl_flag = TRUE; |
| 3917 | } |
| 3918 | else |
| 3919 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3920 | if (cur != NULL) |
| 3921 | cur->pos.cur = 0; |
| 3922 | pos_inprogress = TRUE; |
| 3923 | while (shl->rm.regprog != NULL |
| 3924 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3925 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3926 | if (shl->startcol != MAXCOL |
| 3927 | && v >= (long)shl->startcol |
| 3928 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3929 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3930 | #ifdef FEAT_MBYTE |
| 3931 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3932 | |
| 3933 | if (shl->endcol < tmp_col) |
| 3934 | shl->endcol = tmp_col; |
| 3935 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3936 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3937 | #ifdef FEAT_CONCEAL |
| 3938 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3939 | == cur->hlg_id) |
| 3940 | { |
| 3941 | has_match_conc = TRUE; |
| 3942 | match_conc = cur->conceal_char; |
| 3943 | } |
| 3944 | else |
| 3945 | has_match_conc = match_conc = FALSE; |
| 3946 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3947 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3948 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3949 | { |
| 3950 | shl->attr_cur = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3951 | #ifdef FEAT_CONCEAL |
| 3952 | prev_syntax_id = 0; |
| 3953 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3954 | next_search_hl(wp, shl, lnum, (colnr_T)v, cur); |
| 3955 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3956 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3957 | |
| 3958 | /* Need to get the line again, a multi-line regexp |
| 3959 | * may have made it invalid. */ |
| 3960 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3961 | ptr = line + v; |
| 3962 | |
| 3963 | if (shl->lnum == lnum) |
| 3964 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3965 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3966 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3967 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3968 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3969 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3970 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3971 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3972 | { |
| 3973 | /* highlight empty match, try again after |
| 3974 | * it */ |
| 3975 | #ifdef FEAT_MBYTE |
| 3976 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 3977 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3978 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3979 | else |
| 3980 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3981 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | /* Loop to check if the match starts at the |
| 3985 | * current position */ |
| 3986 | continue; |
| 3987 | } |
| 3988 | } |
| 3989 | break; |
| 3990 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3991 | if (shl != &search_hl && cur != NULL) |
| 3992 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3993 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 3994 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3995 | /* Use attributes from match with highest priority among |
| 3996 | * 'search_hl' and the match list. */ |
| 3997 | search_attr = search_hl.attr_cur; |
| 3998 | cur = wp->w_match_head; |
| 3999 | shl_flag = FALSE; |
| 4000 | while (cur != NULL || shl_flag == FALSE) |
| 4001 | { |
| 4002 | if (shl_flag == FALSE |
| 4003 | && ((cur != NULL |
| 4004 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4005 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4006 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4007 | shl = &search_hl; |
| 4008 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4009 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4010 | else |
| 4011 | shl = &cur->hl; |
| 4012 | if (shl->attr_cur != 0) |
| 4013 | search_attr = shl->attr_cur; |
| 4014 | if (shl != &search_hl && cur != NULL) |
| 4015 | cur = cur->next; |
| 4016 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4017 | } |
| 4018 | #endif |
| 4019 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4020 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4021 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4022 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4023 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4024 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4025 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4026 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4027 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4028 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4029 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4030 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4031 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4032 | } |
| 4033 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4034 | |
| 4035 | /* Decide which of the highlight attributes to use. */ |
| 4036 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4037 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4038 | if (area_attr != 0) |
| 4039 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4040 | else if (search_attr != 0) |
| 4041 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4042 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4043 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4044 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4045 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4046 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4047 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4048 | #else |
| 4049 | if (area_attr != 0) |
| 4050 | char_attr = area_attr; |
| 4051 | else if (search_attr != 0) |
| 4052 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4053 | #endif |
| 4054 | else |
| 4055 | { |
| 4056 | attr_pri = FALSE; |
| 4057 | #ifdef FEAT_SYN_HL |
| 4058 | if (has_syntax) |
| 4059 | char_attr = syntax_attr; |
| 4060 | else |
| 4061 | #endif |
| 4062 | char_attr = 0; |
| 4063 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | /* |
| 4067 | * Get the next character to put on the screen. |
| 4068 | */ |
| 4069 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4070 | * The "p_extra" points to the extra stuff that is inserted to |
| 4071 | * represent special characters (non-printable stuff) and other |
| 4072 | * things. When all characters are the same, c_extra is used. |
| 4073 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4074 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4075 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4076 | */ |
| 4077 | if (n_extra > 0) |
| 4078 | { |
| 4079 | if (c_extra != NUL) |
| 4080 | { |
| 4081 | c = c_extra; |
| 4082 | #ifdef FEAT_MBYTE |
| 4083 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4084 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4085 | { |
| 4086 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4087 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4088 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4089 | } |
| 4090 | else |
| 4091 | mb_utf8 = FALSE; |
| 4092 | #endif |
| 4093 | } |
| 4094 | else |
| 4095 | { |
| 4096 | c = *p_extra; |
| 4097 | #ifdef FEAT_MBYTE |
| 4098 | if (has_mbyte) |
| 4099 | { |
| 4100 | mb_c = c; |
| 4101 | if (enc_utf8) |
| 4102 | { |
| 4103 | /* If the UTF-8 character is more than one byte: |
| 4104 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4105 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4106 | mb_utf8 = FALSE; |
| 4107 | if (mb_l > n_extra) |
| 4108 | mb_l = 1; |
| 4109 | else if (mb_l > 1) |
| 4110 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4111 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4112 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4113 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4114 | } |
| 4115 | } |
| 4116 | else |
| 4117 | { |
| 4118 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4119 | mb_l = MB_BYTE2LEN(c); |
| 4120 | if (mb_l >= n_extra) |
| 4121 | mb_l = 1; |
| 4122 | else if (mb_l > 1) |
| 4123 | mb_c = (c << 8) + p_extra[1]; |
| 4124 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4125 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4126 | mb_l = 1; |
| 4127 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4128 | /* If a double-width char doesn't fit display a '>' in the |
| 4129 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4130 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4131 | # ifdef FEAT_RIGHTLEFT |
| 4132 | wp->w_p_rl ? (col <= 0) : |
| 4133 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4134 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4135 | && (*mb_char2cells)(mb_c) == 2) |
| 4136 | { |
| 4137 | c = '>'; |
| 4138 | mb_c = c; |
| 4139 | mb_l = 1; |
| 4140 | mb_utf8 = FALSE; |
| 4141 | multi_attr = hl_attr(HLF_AT); |
| 4142 | /* put the pointer back to output the double-width |
| 4143 | * character at the start of the next line. */ |
| 4144 | ++n_extra; |
| 4145 | --p_extra; |
| 4146 | } |
| 4147 | else |
| 4148 | { |
| 4149 | n_extra -= mb_l - 1; |
| 4150 | p_extra += mb_l - 1; |
| 4151 | } |
| 4152 | } |
| 4153 | #endif |
| 4154 | ++p_extra; |
| 4155 | } |
| 4156 | --n_extra; |
| 4157 | } |
| 4158 | else |
| 4159 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4160 | if (p_extra_free != NULL) |
| 4161 | { |
| 4162 | vim_free(p_extra_free); |
| 4163 | p_extra_free = NULL; |
| 4164 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4165 | /* |
| 4166 | * Get a character from the line itself. |
| 4167 | */ |
| 4168 | c = *ptr; |
| 4169 | #ifdef FEAT_MBYTE |
| 4170 | if (has_mbyte) |
| 4171 | { |
| 4172 | mb_c = c; |
| 4173 | if (enc_utf8) |
| 4174 | { |
| 4175 | /* If the UTF-8 character is more than one byte: Decode it |
| 4176 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4177 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4178 | mb_utf8 = FALSE; |
| 4179 | if (mb_l > 1) |
| 4180 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4181 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4182 | /* Overlong encoded ASCII or ASCII with composing char |
| 4183 | * is displayed normally, except a NUL. */ |
| 4184 | if (mb_c < 0x80) |
| 4185 | c = mb_c; |
| 4186 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4187 | |
| 4188 | /* At start of the line we can have a composing char. |
| 4189 | * Draw it as a space with a composing char. */ |
| 4190 | if (utf_iscomposing(mb_c)) |
| 4191 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4192 | int i; |
| 4193 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4194 | for (i = Screen_mco - 1; i > 0; --i) |
| 4195 | u8cc[i] = u8cc[i - 1]; |
| 4196 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4197 | mb_c = ' '; |
| 4198 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | if ((mb_l == 1 && c >= 0x80) |
| 4202 | || (mb_l >= 1 && mb_c == 0) |
| 4203 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4204 | # ifdef UNICODE16 |
| 4205 | || mb_c >= 0x10000 |
| 4206 | # endif |
| 4207 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4208 | { |
| 4209 | /* |
| 4210 | * Illegal UTF-8 byte: display as <xx>. |
| 4211 | * Non-BMP character : display as ? or fullwidth ?. |
| 4212 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4213 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4214 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4215 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4216 | { |
| 4217 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4218 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4219 | if (wp->w_p_rl) /* reverse */ |
| 4220 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4221 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4222 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4223 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4224 | else if (utf_char2cells(mb_c) != 2) |
| 4225 | STRCPY(extra, "?"); |
| 4226 | else |
| 4227 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4228 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4229 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4230 | |
| 4231 | p_extra = extra; |
| 4232 | c = *p_extra; |
| 4233 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4234 | mb_utf8 = (c >= 0x80); |
| 4235 | n_extra = (int)STRLEN(p_extra); |
| 4236 | c_extra = NUL; |
| 4237 | if (area_attr == 0 && search_attr == 0) |
| 4238 | { |
| 4239 | n_attr = n_extra + 1; |
| 4240 | extra_attr = hl_attr(HLF_8); |
| 4241 | saved_attr2 = char_attr; /* save current attr */ |
| 4242 | } |
| 4243 | } |
| 4244 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4245 | mb_l = 1; |
| 4246 | #ifdef FEAT_ARABIC |
| 4247 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4248 | { |
| 4249 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4250 | int pc, pc1, nc; |
| 4251 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4252 | |
| 4253 | /* The idea of what is the previous and next |
| 4254 | * character depends on 'rightleft'. */ |
| 4255 | if (wp->w_p_rl) |
| 4256 | { |
| 4257 | pc = prev_c; |
| 4258 | pc1 = prev_c1; |
| 4259 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4260 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4261 | } |
| 4262 | else |
| 4263 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4264 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4265 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4266 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4267 | } |
| 4268 | prev_c = mb_c; |
| 4269 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4270 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4271 | } |
| 4272 | else |
| 4273 | prev_c = mb_c; |
| 4274 | #endif |
| 4275 | } |
| 4276 | else /* enc_dbcs */ |
| 4277 | { |
| 4278 | mb_l = MB_BYTE2LEN(c); |
| 4279 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4280 | mb_l = 1; |
| 4281 | else if (mb_l > 1) |
| 4282 | { |
| 4283 | /* We assume a second byte below 32 is illegal. |
| 4284 | * Hopefully this is OK for all double-byte encodings! |
| 4285 | */ |
| 4286 | if (ptr[1] >= 32) |
| 4287 | mb_c = (c << 8) + ptr[1]; |
| 4288 | else |
| 4289 | { |
| 4290 | if (ptr[1] == NUL) |
| 4291 | { |
| 4292 | /* head byte at end of line */ |
| 4293 | mb_l = 1; |
| 4294 | transchar_nonprint(extra, c); |
| 4295 | } |
| 4296 | else |
| 4297 | { |
| 4298 | /* illegal tail byte */ |
| 4299 | mb_l = 2; |
| 4300 | STRCPY(extra, "XX"); |
| 4301 | } |
| 4302 | p_extra = extra; |
| 4303 | n_extra = (int)STRLEN(extra) - 1; |
| 4304 | c_extra = NUL; |
| 4305 | c = *p_extra++; |
| 4306 | if (area_attr == 0 && search_attr == 0) |
| 4307 | { |
| 4308 | n_attr = n_extra + 1; |
| 4309 | extra_attr = hl_attr(HLF_8); |
| 4310 | saved_attr2 = char_attr; /* save current attr */ |
| 4311 | } |
| 4312 | mb_c = c; |
| 4313 | } |
| 4314 | } |
| 4315 | } |
| 4316 | /* If a double-width char doesn't fit display a '>' in the |
| 4317 | * last column; the character is displayed at the start of the |
| 4318 | * next line. */ |
| 4319 | if (( |
| 4320 | # ifdef FEAT_RIGHTLEFT |
| 4321 | wp->w_p_rl ? (col <= 0) : |
| 4322 | # endif |
| 4323 | (col >= W_WIDTH(wp) - 1)) |
| 4324 | && (*mb_char2cells)(mb_c) == 2) |
| 4325 | { |
| 4326 | c = '>'; |
| 4327 | mb_c = c; |
| 4328 | mb_utf8 = FALSE; |
| 4329 | mb_l = 1; |
| 4330 | multi_attr = hl_attr(HLF_AT); |
| 4331 | /* Put pointer back so that the character will be |
| 4332 | * displayed at the start of the next line. */ |
| 4333 | --ptr; |
| 4334 | } |
| 4335 | else if (*ptr != NUL) |
| 4336 | ptr += mb_l - 1; |
| 4337 | |
| 4338 | /* If a double-width char doesn't fit at the left side display |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4339 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4340 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4341 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4342 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4343 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4344 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4345 | c = ' '; |
| 4346 | if (area_attr == 0 && search_attr == 0) |
| 4347 | { |
| 4348 | n_attr = n_extra + 1; |
| 4349 | extra_attr = hl_attr(HLF_AT); |
| 4350 | saved_attr2 = char_attr; /* save current attr */ |
| 4351 | } |
| 4352 | mb_c = c; |
| 4353 | mb_utf8 = FALSE; |
| 4354 | mb_l = 1; |
| 4355 | } |
| 4356 | |
| 4357 | } |
| 4358 | #endif |
| 4359 | ++ptr; |
| 4360 | |
| 4361 | if (extra_check) |
| 4362 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4363 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4364 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4365 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4366 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4367 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4368 | /* Get syntax attribute, unless still at the start of the line |
| 4369 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4370 | v = (long)(ptr - line); |
| 4371 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4372 | { |
| 4373 | /* Get the syntax attribute for the character. If there |
| 4374 | * is an error, disable syntax highlighting. */ |
| 4375 | save_did_emsg = did_emsg; |
| 4376 | did_emsg = FALSE; |
| 4377 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4378 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4379 | # ifdef FEAT_SPELL |
| 4380 | has_spell ? &can_spell : |
| 4381 | # endif |
| 4382 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4383 | |
| 4384 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4385 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4386 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4387 | has_syntax = FALSE; |
| 4388 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4389 | else |
| 4390 | did_emsg = save_did_emsg; |
| 4391 | |
| 4392 | /* Need to get the line again, a multi-line regexp may |
| 4393 | * have made it invalid. */ |
| 4394 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4395 | ptr = line + v; |
| 4396 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4397 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4398 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4399 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4400 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4401 | # ifdef FEAT_CONCEAL |
| 4402 | /* no concealing past the end of the line, it interferes |
| 4403 | * with line highlighting */ |
| 4404 | if (c == NUL) |
| 4405 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4406 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4407 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4408 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4409 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4410 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4411 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4412 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4413 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4414 | * Only do this when there is no syntax highlighting, the |
| 4415 | * @Spell cluster is not used or the current syntax item |
| 4416 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4417 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4418 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4419 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4420 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4421 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4422 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4423 | # endif |
| 4424 | if (c != 0 && ( |
| 4425 | # ifdef FEAT_SYN_HL |
| 4426 | !has_syntax || |
| 4427 | # endif |
| 4428 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4429 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4430 | char_u *prev_ptr, *p; |
| 4431 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4432 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4433 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4434 | if (has_mbyte) |
| 4435 | { |
| 4436 | prev_ptr = ptr - mb_l; |
| 4437 | v -= mb_l - 1; |
| 4438 | } |
| 4439 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4440 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4441 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4442 | |
| 4443 | /* Use nextline[] if possible, it has the start of the |
| 4444 | * next line concatenated. */ |
| 4445 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4446 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4447 | else |
| 4448 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4449 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4450 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4451 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4452 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4453 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4454 | /* In Insert mode only highlight a word that |
| 4455 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4456 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4457 | && (State & INSERT) != 0 |
| 4458 | && wp->w_cursor.lnum == lnum |
| 4459 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4460 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4461 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4462 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4463 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4464 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4465 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4466 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4467 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4468 | && (p - nextline) + len > nextline_idx) |
| 4469 | { |
| 4470 | /* Remember that the good word continues at the |
| 4471 | * start of the next line. */ |
| 4472 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4473 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4474 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4475 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4476 | /* Turn index into actual attributes. */ |
| 4477 | if (spell_hlf != HLF_COUNT) |
| 4478 | spell_attr = highlight_attr[spell_hlf]; |
| 4479 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4480 | if (cap_col > 0) |
| 4481 | { |
| 4482 | if (p != prev_ptr |
| 4483 | && (p - nextline) + cap_col >= nextline_idx) |
| 4484 | { |
| 4485 | /* Remember that the word in the next line |
| 4486 | * must start with a capital. */ |
| 4487 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4488 | cap_col = (int)((p - nextline) + cap_col |
| 4489 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4490 | } |
| 4491 | else |
| 4492 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4493 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4494 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4495 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4496 | } |
| 4497 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4498 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4499 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4500 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4501 | else |
| 4502 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4503 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4504 | #endif |
| 4505 | #ifdef FEAT_LINEBREAK |
| 4506 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4507 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4508 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4509 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4510 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4511 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4512 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4513 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4514 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4515 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4516 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4517 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4518 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4519 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4520 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4521 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4522 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4523 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4524 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4525 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4526 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4527 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4528 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4529 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4530 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4531 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4532 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4533 | { |
| 4534 | #ifdef FEAT_CONCEAL |
| 4535 | if (c == TAB) |
| 4536 | /* See "Tab alignment" below. */ |
| 4537 | FIX_FOR_BOGUSCOLS; |
| 4538 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4539 | if (!wp->w_p_list) |
| 4540 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4541 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4542 | } |
| 4543 | #endif |
| 4544 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4545 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4546 | */ |
| 4547 | if (wp->w_p_list |
| 4548 | && (((c == 160 |
| 4549 | #ifdef FEAT_MBYTE |
| 4550 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4551 | #endif |
| 4552 | ) && lcs_nbsp) |
| 4553 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4554 | { |
| 4555 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4556 | if (area_attr == 0 && search_attr == 0) |
| 4557 | { |
| 4558 | n_attr = 1; |
| 4559 | extra_attr = hl_attr(HLF_8); |
| 4560 | saved_attr2 = char_attr; /* save current attr */ |
| 4561 | } |
| 4562 | #ifdef FEAT_MBYTE |
| 4563 | mb_c = c; |
| 4564 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4565 | { |
| 4566 | mb_utf8 = TRUE; |
| 4567 | u8cc[0] = 0; |
| 4568 | c = 0xc0; |
| 4569 | } |
| 4570 | else |
| 4571 | mb_utf8 = FALSE; |
| 4572 | #endif |
| 4573 | } |
| 4574 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4575 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4576 | { |
| 4577 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4578 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4579 | { |
| 4580 | n_attr = 1; |
| 4581 | extra_attr = hl_attr(HLF_8); |
| 4582 | saved_attr2 = char_attr; /* save current attr */ |
| 4583 | } |
| 4584 | #ifdef FEAT_MBYTE |
| 4585 | mb_c = c; |
| 4586 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4587 | { |
| 4588 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4589 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4590 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4591 | } |
| 4592 | else |
| 4593 | mb_utf8 = FALSE; |
| 4594 | #endif |
| 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | /* |
| 4599 | * Handling of non-printable characters. |
| 4600 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4601 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4602 | { |
| 4603 | /* |
| 4604 | * when getting a character from the file, we may have to |
| 4605 | * turn it into something else on the way to putting it |
| 4606 | * into "ScreenLines". |
| 4607 | */ |
| 4608 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4609 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4610 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4611 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4612 | #ifdef FEAT_LINEBREAK |
| 4613 | /* only adjust the tab_len, when at the first column |
| 4614 | * after the showbreak value was drawn */ |
| 4615 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4616 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4617 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4618 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4619 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4620 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4621 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4622 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4623 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4624 | #endif |
| 4625 | /* tab amount depends on current column */ |
| 4626 | n_extra = tab_len; |
| 4627 | #ifdef FEAT_LINEBREAK |
| 4628 | else |
| 4629 | { |
| 4630 | char_u *p; |
| 4631 | int len = n_extra; |
| 4632 | int i; |
| 4633 | int saved_nextra = n_extra; |
| 4634 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4635 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4636 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4637 | /* there are characters to conceal */ |
| 4638 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4639 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4640 | */ |
| 4641 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4642 | && n_extra > tab_len) |
| 4643 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4644 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4645 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4646 | /* if n_extra > 0, it gives the number of chars, to |
| 4647 | * use for a tab, else we need to calculate the width |
| 4648 | * for a tab */ |
| 4649 | #ifdef FEAT_MBYTE |
| 4650 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4651 | if (n_extra > 0) |
| 4652 | len += n_extra - tab_len; |
| 4653 | #endif |
| 4654 | c = lcs_tab1; |
| 4655 | p = alloc((unsigned)(len + 1)); |
| 4656 | vim_memset(p, ' ', len); |
| 4657 | p[len] = NUL; |
| 4658 | p_extra_free = p; |
| 4659 | for (i = 0; i < tab_len; i++) |
| 4660 | { |
| 4661 | #ifdef FEAT_MBYTE |
| 4662 | mb_char2bytes(lcs_tab2, p); |
| 4663 | p += mb_char2len(lcs_tab2); |
| 4664 | n_extra += mb_char2len(lcs_tab2) |
| 4665 | - (saved_nextra > 0 ? 1 : 0); |
| 4666 | #else |
| 4667 | p[i] = lcs_tab2; |
| 4668 | #endif |
| 4669 | } |
| 4670 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4671 | #ifdef FEAT_CONCEAL |
| 4672 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4673 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4674 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4675 | n_extra -= vcol_off; |
| 4676 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4677 | } |
| 4678 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4679 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4680 | { |
| 4681 | int vc_saved = vcol_off; |
| 4682 | |
| 4683 | /* Tab alignment should be identical regardless of |
| 4684 | * 'conceallevel' value. So tab compensates of all |
| 4685 | * previous concealed characters, and thus resets |
| 4686 | * vcol_off and boguscols accumulated so far in the |
| 4687 | * line. Note that the tab can be longer than |
| 4688 | * 'tabstop' when there are concealed characters. */ |
| 4689 | FIX_FOR_BOGUSCOLS; |
| 4690 | |
| 4691 | /* Make sure, the highlighting for the tab char will be |
| 4692 | * correctly set further below (effectively reverts the |
| 4693 | * FIX_FOR_BOGSUCOLS macro */ |
| 4694 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4695 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4696 | tab_len += vc_saved; |
| 4697 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4698 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4699 | #ifdef FEAT_MBYTE |
| 4700 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4701 | #endif |
| 4702 | if (wp->w_p_list) |
| 4703 | { |
| 4704 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4705 | #ifdef FEAT_LINEBREAK |
| 4706 | if (wp->w_p_lbr) |
| 4707 | c_extra = NUL; /* using p_extra from above */ |
| 4708 | else |
| 4709 | #endif |
| 4710 | c_extra = lcs_tab2; |
| 4711 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4712 | extra_attr = hl_attr(HLF_8); |
| 4713 | saved_attr2 = char_attr; /* save current attr */ |
| 4714 | #ifdef FEAT_MBYTE |
| 4715 | mb_c = c; |
| 4716 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4717 | { |
| 4718 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4719 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4720 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4721 | } |
| 4722 | #endif |
| 4723 | } |
| 4724 | else |
| 4725 | { |
| 4726 | c_extra = ' '; |
| 4727 | c = ' '; |
| 4728 | } |
| 4729 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4730 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4731 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4732 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4733 | && tocol > vcol |
| 4734 | && VIsual_mode != Ctrl_V |
| 4735 | && ( |
| 4736 | # ifdef FEAT_RIGHTLEFT |
| 4737 | wp->w_p_rl ? (col >= 0) : |
| 4738 | # endif |
| 4739 | (col < W_WIDTH(wp))) |
| 4740 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4741 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4742 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4743 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4744 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4745 | /* Display a '$' after the line or highlight an extra |
| 4746 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4747 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4748 | /* For a diff line the highlighting continues after the |
| 4749 | * "$". */ |
| 4750 | if ( |
| 4751 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4752 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4753 | # ifdef LINE_ATTR |
| 4754 | && |
| 4755 | # endif |
| 4756 | # endif |
| 4757 | # ifdef LINE_ATTR |
| 4758 | line_attr == 0 |
| 4759 | # endif |
| 4760 | ) |
| 4761 | #endif |
| 4762 | { |
| 4763 | #ifdef FEAT_VIRTUALEDIT |
| 4764 | /* In virtualedit, visual selections may extend |
| 4765 | * beyond end of line. */ |
| 4766 | if (area_highlighting && virtual_active() |
| 4767 | && tocol != MAXCOL && vcol < tocol) |
| 4768 | n_extra = 0; |
| 4769 | else |
| 4770 | #endif |
| 4771 | { |
| 4772 | p_extra = at_end_str; |
| 4773 | n_extra = 1; |
| 4774 | c_extra = NUL; |
| 4775 | } |
| 4776 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4777 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4778 | c = lcs_eol; |
| 4779 | else |
| 4780 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4781 | lcs_eol_one = -1; |
| 4782 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4783 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4784 | { |
| 4785 | extra_attr = hl_attr(HLF_AT); |
| 4786 | n_attr = 1; |
| 4787 | } |
| 4788 | #ifdef FEAT_MBYTE |
| 4789 | mb_c = c; |
| 4790 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4791 | { |
| 4792 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4793 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4794 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4795 | } |
| 4796 | else |
| 4797 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4798 | #endif |
| 4799 | } |
| 4800 | else if (c != NUL) |
| 4801 | { |
| 4802 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4803 | if (n_extra == 0) |
| 4804 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4805 | #ifdef FEAT_RIGHTLEFT |
| 4806 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4807 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4808 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4809 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4810 | #ifdef FEAT_LINEBREAK |
| 4811 | if (wp->w_p_lbr) |
| 4812 | { |
| 4813 | char_u *p; |
| 4814 | |
| 4815 | c = *p_extra; |
| 4816 | p = alloc((unsigned)n_extra + 1); |
| 4817 | vim_memset(p, ' ', n_extra); |
| 4818 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4819 | p[n_extra] = NUL; |
| 4820 | p_extra_free = p_extra = p; |
| 4821 | } |
| 4822 | else |
| 4823 | #endif |
| 4824 | { |
| 4825 | n_extra = byte2cells(c) - 1; |
| 4826 | c = *p_extra++; |
| 4827 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4828 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4829 | { |
| 4830 | n_attr = n_extra + 1; |
| 4831 | extra_attr = hl_attr(HLF_8); |
| 4832 | saved_attr2 = char_attr; /* save current attr */ |
| 4833 | } |
| 4834 | #ifdef FEAT_MBYTE |
| 4835 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4836 | #endif |
| 4837 | } |
| 4838 | #ifdef FEAT_VIRTUALEDIT |
| 4839 | else if (VIsual_active |
| 4840 | && (VIsual_mode == Ctrl_V |
| 4841 | || VIsual_mode == 'v') |
| 4842 | && virtual_active() |
| 4843 | && tocol != MAXCOL |
| 4844 | && vcol < tocol |
| 4845 | && ( |
| 4846 | # ifdef FEAT_RIGHTLEFT |
| 4847 | wp->w_p_rl ? (col >= 0) : |
| 4848 | # endif |
| 4849 | (col < W_WIDTH(wp)))) |
| 4850 | { |
| 4851 | c = ' '; |
| 4852 | --ptr; /* put it back at the NUL */ |
| 4853 | } |
| 4854 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4855 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4856 | else if (( |
| 4857 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4858 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4859 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4860 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4861 | ) && ( |
| 4862 | # ifdef FEAT_RIGHTLEFT |
| 4863 | wp->w_p_rl ? (col >= 0) : |
| 4864 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4865 | (col |
| 4866 | # ifdef FEAT_CONCEAL |
| 4867 | - boguscols |
| 4868 | # endif |
| 4869 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4870 | { |
| 4871 | /* Highlight until the right side of the window */ |
| 4872 | c = ' '; |
| 4873 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4874 | |
| 4875 | /* Remember we do the char for line highlighting. */ |
| 4876 | ++did_line_attr; |
| 4877 | |
| 4878 | /* don't do search HL for the rest of the line */ |
| 4879 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4880 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4881 | # ifdef FEAT_DIFF |
| 4882 | if (diff_hlf == HLF_TXD) |
| 4883 | { |
| 4884 | diff_hlf = HLF_CHD; |
| 4885 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4886 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4887 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4888 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4889 | char_attr = hl_combine_attr(char_attr, |
| 4890 | hl_attr(HLF_CUL)); |
| 4891 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4892 | } |
| 4893 | # endif |
| 4894 | } |
| 4895 | #endif |
| 4896 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4897 | |
| 4898 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4899 | if ( wp->w_p_cole > 0 |
| 4900 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4901 | conceal_cursor_line(wp) ) |
| 4902 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4903 | && !(lnum_in_visual_area |
| 4904 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4905 | { |
| 4906 | char_attr = conceal_attr; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4907 | if (prev_syntax_id != syntax_seqnr |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4908 | && (syn_get_sub_char() != NUL || match_conc |
| 4909 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4910 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4911 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4912 | /* First time at this concealed item: display one |
| 4913 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4914 | if (match_conc) |
| 4915 | c = match_conc; |
| 4916 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4917 | c = syn_get_sub_char(); |
| 4918 | else if (lcs_conceal != NUL) |
| 4919 | c = lcs_conceal; |
| 4920 | else |
| 4921 | c = ' '; |
| 4922 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4923 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4924 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4925 | if (n_extra > 0) |
| 4926 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4927 | vcol += n_extra; |
| 4928 | if (wp->w_p_wrap && n_extra > 0) |
| 4929 | { |
| 4930 | # ifdef FEAT_RIGHTLEFT |
| 4931 | if (wp->w_p_rl) |
| 4932 | { |
| 4933 | col -= n_extra; |
| 4934 | boguscols -= n_extra; |
| 4935 | } |
| 4936 | else |
| 4937 | # endif |
| 4938 | { |
| 4939 | boguscols += n_extra; |
| 4940 | col += n_extra; |
| 4941 | } |
| 4942 | } |
| 4943 | n_extra = 0; |
| 4944 | n_attr = 0; |
| 4945 | } |
| 4946 | else if (n_skip == 0) |
| 4947 | { |
| 4948 | is_concealing = TRUE; |
| 4949 | n_skip = 1; |
| 4950 | } |
| 4951 | # ifdef FEAT_MBYTE |
| 4952 | mb_c = c; |
| 4953 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4954 | { |
| 4955 | mb_utf8 = TRUE; |
| 4956 | u8cc[0] = 0; |
| 4957 | c = 0xc0; |
| 4958 | } |
| 4959 | else |
| 4960 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4961 | # endif |
| 4962 | } |
| 4963 | else |
| 4964 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4965 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 4966 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4967 | } |
| 4968 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4969 | } |
| 4970 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4971 | #ifdef FEAT_CONCEAL |
| 4972 | /* In the cursor line and we may be concealing characters: correct |
| 4973 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 4974 | if (!did_wcol && draw_state == WL_LINE |
| 4975 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4976 | && conceal_cursor_line(wp) |
| 4977 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 4978 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 4979 | # ifdef FEAT_RIGHTLEFT |
| 4980 | if (wp->w_p_rl) |
| 4981 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 4982 | else |
| 4983 | # endif |
| 4984 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 4985 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4986 | did_wcol = TRUE; |
| 4987 | } |
| 4988 | #endif |
| 4989 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4990 | /* Don't override visual selection highlighting. */ |
| 4991 | if (n_attr > 0 |
| 4992 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4993 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4994 | char_attr = extra_attr; |
| 4995 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 4996 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4997 | /* XIM don't send preedit_start and preedit_end, but they send |
| 4998 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 4999 | * im_is_preediting() here. */ |
| 5000 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5001 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5002 | && (State & INSERT) |
| 5003 | && !p_imdisable |
| 5004 | && im_is_preediting() |
| 5005 | && draw_state == WL_LINE) |
| 5006 | { |
| 5007 | colnr_T tcol; |
| 5008 | |
| 5009 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5010 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5011 | else |
| 5012 | tcol = preedit_end_col; |
| 5013 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 5014 | { |
| 5015 | if (feedback_old_attr < 0) |
| 5016 | { |
| 5017 | feedback_col = 0; |
| 5018 | feedback_old_attr = char_attr; |
| 5019 | } |
| 5020 | char_attr = im_get_feedback_attr(feedback_col); |
| 5021 | if (char_attr < 0) |
| 5022 | char_attr = feedback_old_attr; |
| 5023 | feedback_col++; |
| 5024 | } |
| 5025 | else if (feedback_old_attr >= 0) |
| 5026 | { |
| 5027 | char_attr = feedback_old_attr; |
| 5028 | feedback_old_attr = -1; |
| 5029 | feedback_col = 0; |
| 5030 | } |
| 5031 | } |
| 5032 | #endif |
| 5033 | /* |
| 5034 | * Handle the case where we are in column 0 but not on the first |
| 5035 | * character of the line and the user wants us to show us a |
| 5036 | * special character (via 'listchars' option "precedes:<char>". |
| 5037 | */ |
| 5038 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5039 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5040 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5041 | #ifdef FEAT_DIFF |
| 5042 | && filler_todo <= 0 |
| 5043 | #endif |
| 5044 | && draw_state > WL_NR |
| 5045 | && c != NUL) |
| 5046 | { |
| 5047 | c = lcs_prec; |
| 5048 | lcs_prec_todo = NUL; |
| 5049 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5050 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5051 | { |
| 5052 | /* Double-width character being overwritten by the "precedes" |
| 5053 | * character, need to fill up half the character. */ |
| 5054 | c_extra = MB_FILLER_CHAR; |
| 5055 | n_extra = 1; |
| 5056 | n_attr = 2; |
| 5057 | extra_attr = hl_attr(HLF_AT); |
| 5058 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5059 | mb_c = c; |
| 5060 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5061 | { |
| 5062 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5063 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5064 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5065 | } |
| 5066 | else |
| 5067 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5068 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5069 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5070 | { |
| 5071 | saved_attr3 = char_attr; /* save current attr */ |
| 5072 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5073 | n_attr3 = 1; |
| 5074 | } |
| 5075 | } |
| 5076 | |
| 5077 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5078 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5079 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5080 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5081 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5082 | || did_line_attr == 1 |
| 5083 | #endif |
| 5084 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5085 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5086 | #ifdef FEAT_SEARCH_EXTRA |
| 5087 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5088 | |
| 5089 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5090 | if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5091 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5092 | #endif |
| 5093 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5094 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5095 | * highlight match at end of line. If it's beyond the last |
| 5096 | * char on the screen, just overwrite that one (tricky!) Not |
| 5097 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5098 | #ifdef FEAT_SEARCH_EXTRA |
| 5099 | prevcol_hl_flag = FALSE; |
| 5100 | if (prevcol == (long)search_hl.startcol) |
| 5101 | prevcol_hl_flag = TRUE; |
| 5102 | else |
| 5103 | { |
| 5104 | cur = wp->w_match_head; |
| 5105 | while (cur != NULL) |
| 5106 | { |
| 5107 | if (prevcol == (long)cur->hl.startcol) |
| 5108 | { |
| 5109 | prevcol_hl_flag = TRUE; |
| 5110 | break; |
| 5111 | } |
| 5112 | cur = cur->next; |
| 5113 | } |
| 5114 | } |
| 5115 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5116 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5117 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5118 | && (VIsual_mode != Ctrl_V |
| 5119 | || lnum == VIsual.lnum |
| 5120 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5121 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5122 | #ifdef FEAT_SEARCH_EXTRA |
| 5123 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5124 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5125 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5126 | && did_line_attr <= 1 |
| 5127 | # endif |
| 5128 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5129 | #endif |
| 5130 | )) |
| 5131 | { |
| 5132 | int n = 0; |
| 5133 | |
| 5134 | #ifdef FEAT_RIGHTLEFT |
| 5135 | if (wp->w_p_rl) |
| 5136 | { |
| 5137 | if (col < 0) |
| 5138 | n = 1; |
| 5139 | } |
| 5140 | else |
| 5141 | #endif |
| 5142 | { |
| 5143 | if (col >= W_WIDTH(wp)) |
| 5144 | n = -1; |
| 5145 | } |
| 5146 | if (n != 0) |
| 5147 | { |
| 5148 | /* At the window boundary, highlight the last character |
| 5149 | * instead (better than nothing). */ |
| 5150 | off += n; |
| 5151 | col += n; |
| 5152 | } |
| 5153 | else |
| 5154 | { |
| 5155 | /* Add a blank character to highlight. */ |
| 5156 | ScreenLines[off] = ' '; |
| 5157 | #ifdef FEAT_MBYTE |
| 5158 | if (enc_utf8) |
| 5159 | ScreenLinesUC[off] = 0; |
| 5160 | #endif |
| 5161 | } |
| 5162 | #ifdef FEAT_SEARCH_EXTRA |
| 5163 | if (area_attr == 0) |
| 5164 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5165 | /* Use attributes from match with highest priority among |
| 5166 | * 'search_hl' and the match list. */ |
| 5167 | char_attr = search_hl.attr; |
| 5168 | cur = wp->w_match_head; |
| 5169 | shl_flag = FALSE; |
| 5170 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5171 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5172 | if (shl_flag == FALSE |
| 5173 | && ((cur != NULL |
| 5174 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5175 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5176 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5177 | shl = &search_hl; |
| 5178 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5179 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5180 | else |
| 5181 | shl = &cur->hl; |
| 5182 | if ((ptr - line) - 1 == (long)shl->startcol) |
| 5183 | char_attr = shl->attr; |
| 5184 | if (shl != &search_hl && cur != NULL) |
| 5185 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5186 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5187 | } |
| 5188 | #endif |
| 5189 | ScreenAttrs[off] = char_attr; |
| 5190 | #ifdef FEAT_RIGHTLEFT |
| 5191 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5192 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5193 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5194 | --off; |
| 5195 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5196 | else |
| 5197 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5198 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5199 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5200 | ++off; |
| 5201 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5202 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5203 | #ifdef FEAT_SYN_HL |
| 5204 | eol_hl_off = 1; |
| 5205 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5206 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5207 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5208 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5209 | /* |
| 5210 | * At end of the text line. |
| 5211 | */ |
| 5212 | if (c == NUL) |
| 5213 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5214 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5215 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5216 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5217 | { |
| 5218 | /* highlight last char after line */ |
| 5219 | --col; |
| 5220 | --off; |
| 5221 | --vcol; |
| 5222 | } |
| 5223 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5224 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5225 | if (wp->w_p_wrap) |
| 5226 | v = wp->w_skipcol; |
| 5227 | else |
| 5228 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5229 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5230 | /* check if line ends before left margin */ |
| 5231 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5232 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5233 | #ifdef FEAT_CONCEAL |
| 5234 | /* Get rid of the boguscols now, we want to draw until the right |
| 5235 | * edge for 'cursorcolumn'. */ |
| 5236 | col -= boguscols; |
| 5237 | boguscols = 0; |
| 5238 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5239 | |
| 5240 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5241 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5242 | |
| 5243 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5244 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5245 | && (int)wp->w_virtcol < |
| 5246 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5247 | && lnum != wp->w_cursor.lnum) |
| 5248 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5249 | # ifdef FEAT_RIGHTLEFT |
| 5250 | && !wp->w_p_rl |
| 5251 | # endif |
| 5252 | ) |
| 5253 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5254 | int rightmost_vcol = 0; |
| 5255 | int i; |
| 5256 | |
| 5257 | if (wp->w_p_cuc) |
| 5258 | rightmost_vcol = wp->w_virtcol; |
| 5259 | if (draw_color_col) |
| 5260 | /* determine rightmost colorcolumn to possibly draw */ |
| 5261 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5262 | if (rightmost_vcol < color_cols[i]) |
| 5263 | rightmost_vcol = color_cols[i]; |
| 5264 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5265 | while (col < W_WIDTH(wp)) |
| 5266 | { |
| 5267 | ScreenLines[off] = ' '; |
| 5268 | #ifdef FEAT_MBYTE |
| 5269 | if (enc_utf8) |
| 5270 | ScreenLinesUC[off] = 0; |
| 5271 | #endif |
| 5272 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5273 | if (draw_color_col) |
| 5274 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5275 | &color_cols); |
| 5276 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5277 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5278 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5279 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5280 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5281 | else |
| 5282 | ScreenAttrs[off++] = 0; |
| 5283 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5284 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5285 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5286 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5287 | ++vcol; |
| 5288 | } |
| 5289 | } |
| 5290 | #endif |
| 5291 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5292 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5293 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5294 | row++; |
| 5295 | |
| 5296 | /* |
| 5297 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5298 | * updated (saves a call to plines() later). |
| 5299 | */ |
| 5300 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5301 | { |
| 5302 | curwin->w_cline_row = startrow; |
| 5303 | curwin->w_cline_height = row - startrow; |
| 5304 | #ifdef FEAT_FOLDING |
| 5305 | curwin->w_cline_folded = FALSE; |
| 5306 | #endif |
| 5307 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5308 | } |
| 5309 | |
| 5310 | break; |
| 5311 | } |
| 5312 | |
| 5313 | /* line continues beyond line end */ |
| 5314 | if (lcs_ext |
| 5315 | && !wp->w_p_wrap |
| 5316 | #ifdef FEAT_DIFF |
| 5317 | && filler_todo <= 0 |
| 5318 | #endif |
| 5319 | && ( |
| 5320 | #ifdef FEAT_RIGHTLEFT |
| 5321 | wp->w_p_rl ? col == 0 : |
| 5322 | #endif |
| 5323 | col == W_WIDTH(wp) - 1) |
| 5324 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5325 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5326 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5327 | { |
| 5328 | c = lcs_ext; |
| 5329 | char_attr = hl_attr(HLF_AT); |
| 5330 | #ifdef FEAT_MBYTE |
| 5331 | mb_c = c; |
| 5332 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5333 | { |
| 5334 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5335 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5336 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5337 | } |
| 5338 | else |
| 5339 | mb_utf8 = FALSE; |
| 5340 | #endif |
| 5341 | } |
| 5342 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5343 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5344 | /* advance to the next 'colorcolumn' */ |
| 5345 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5346 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5347 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5348 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5349 | * highlight the cursor position itself. |
| 5350 | * Also highlight the 'colorcolumn' if it is different than |
| 5351 | * 'cursorcolumn' */ |
| 5352 | vcol_save_attr = -1; |
| 5353 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5354 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5355 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5356 | && lnum != wp->w_cursor.lnum) |
| 5357 | { |
| 5358 | vcol_save_attr = char_attr; |
| 5359 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5360 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5361 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5362 | { |
| 5363 | vcol_save_attr = char_attr; |
| 5364 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5365 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5366 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5367 | #endif |
| 5368 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5369 | /* |
| 5370 | * Store character to be displayed. |
| 5371 | * Skip characters that are left of the screen for 'nowrap'. |
| 5372 | */ |
| 5373 | vcol_prev = vcol; |
| 5374 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5375 | { |
| 5376 | /* |
| 5377 | * Store the character. |
| 5378 | */ |
| 5379 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5380 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5381 | { |
| 5382 | /* A double-wide character is: put first halve in left cell. */ |
| 5383 | --off; |
| 5384 | --col; |
| 5385 | } |
| 5386 | #endif |
| 5387 | ScreenLines[off] = c; |
| 5388 | #ifdef FEAT_MBYTE |
| 5389 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5390 | { |
| 5391 | if ((mb_c & 0xff00) == 0x8e00) |
| 5392 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5393 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5394 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5395 | else if (enc_utf8) |
| 5396 | { |
| 5397 | if (mb_utf8) |
| 5398 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5399 | int i; |
| 5400 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5401 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5402 | if ((c & 0xff) == 0) |
| 5403 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5404 | for (i = 0; i < Screen_mco; ++i) |
| 5405 | { |
| 5406 | ScreenLinesC[i][off] = u8cc[i]; |
| 5407 | if (u8cc[i] == 0) |
| 5408 | break; |
| 5409 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5410 | } |
| 5411 | else |
| 5412 | ScreenLinesUC[off] = 0; |
| 5413 | } |
| 5414 | if (multi_attr) |
| 5415 | { |
| 5416 | ScreenAttrs[off] = multi_attr; |
| 5417 | multi_attr = 0; |
| 5418 | } |
| 5419 | else |
| 5420 | #endif |
| 5421 | ScreenAttrs[off] = char_attr; |
| 5422 | |
| 5423 | #ifdef FEAT_MBYTE |
| 5424 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5425 | { |
| 5426 | /* Need to fill two screen columns. */ |
| 5427 | ++off; |
| 5428 | ++col; |
| 5429 | if (enc_utf8) |
| 5430 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5431 | ScreenLines[off] = 0; |
| 5432 | else |
| 5433 | /* DBCS: Put second byte in the second screen char. */ |
| 5434 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5435 | if (draw_state > WL_NR |
| 5436 | #ifdef FEAT_DIFF |
| 5437 | && filler_todo <= 0 |
| 5438 | #endif |
| 5439 | ) |
| 5440 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5441 | /* When "tocol" is halfway a character, set it to the end of |
| 5442 | * the character, otherwise highlighting won't stop. */ |
| 5443 | if (tocol == vcol) |
| 5444 | ++tocol; |
| 5445 | #ifdef FEAT_RIGHTLEFT |
| 5446 | if (wp->w_p_rl) |
| 5447 | { |
| 5448 | /* now it's time to backup one cell */ |
| 5449 | --off; |
| 5450 | --col; |
| 5451 | } |
| 5452 | #endif |
| 5453 | } |
| 5454 | #endif |
| 5455 | #ifdef FEAT_RIGHTLEFT |
| 5456 | if (wp->w_p_rl) |
| 5457 | { |
| 5458 | --off; |
| 5459 | --col; |
| 5460 | } |
| 5461 | else |
| 5462 | #endif |
| 5463 | { |
| 5464 | ++off; |
| 5465 | ++col; |
| 5466 | } |
| 5467 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5468 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5469 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5470 | { |
| 5471 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5472 | ++vcol_off; |
| 5473 | if (n_extra > 0) |
| 5474 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5475 | if (wp->w_p_wrap) |
| 5476 | { |
| 5477 | /* |
| 5478 | * Special voodoo required if 'wrap' is on. |
| 5479 | * |
| 5480 | * Advance the column indicator to force the line |
| 5481 | * drawing to wrap early. This will make the line |
| 5482 | * take up the same screen space when parts are concealed, |
| 5483 | * so that cursor line computations aren't messed up. |
| 5484 | * |
| 5485 | * To avoid the fictitious advance of 'col' causing |
| 5486 | * trailing junk to be written out of the screen line |
| 5487 | * we are building, 'boguscols' keeps track of the number |
| 5488 | * of bad columns we have advanced. |
| 5489 | */ |
| 5490 | if (n_extra > 0) |
| 5491 | { |
| 5492 | vcol += n_extra; |
| 5493 | # ifdef FEAT_RIGHTLEFT |
| 5494 | if (wp->w_p_rl) |
| 5495 | { |
| 5496 | col -= n_extra; |
| 5497 | boguscols -= n_extra; |
| 5498 | } |
| 5499 | else |
| 5500 | # endif |
| 5501 | { |
| 5502 | col += n_extra; |
| 5503 | boguscols += n_extra; |
| 5504 | } |
| 5505 | n_extra = 0; |
| 5506 | n_attr = 0; |
| 5507 | } |
| 5508 | |
| 5509 | |
| 5510 | # ifdef FEAT_MBYTE |
| 5511 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5512 | { |
| 5513 | /* Need to fill two screen columns. */ |
| 5514 | # ifdef FEAT_RIGHTLEFT |
| 5515 | if (wp->w_p_rl) |
| 5516 | { |
| 5517 | --boguscols; |
| 5518 | --col; |
| 5519 | } |
| 5520 | else |
| 5521 | # endif |
| 5522 | { |
| 5523 | ++boguscols; |
| 5524 | ++col; |
| 5525 | } |
| 5526 | } |
| 5527 | # endif |
| 5528 | |
| 5529 | # ifdef FEAT_RIGHTLEFT |
| 5530 | if (wp->w_p_rl) |
| 5531 | { |
| 5532 | --boguscols; |
| 5533 | --col; |
| 5534 | } |
| 5535 | else |
| 5536 | # endif |
| 5537 | { |
| 5538 | ++boguscols; |
| 5539 | ++col; |
| 5540 | } |
| 5541 | } |
| 5542 | else |
| 5543 | { |
| 5544 | if (n_extra > 0) |
| 5545 | { |
| 5546 | vcol += n_extra; |
| 5547 | n_extra = 0; |
| 5548 | n_attr = 0; |
| 5549 | } |
| 5550 | } |
| 5551 | |
| 5552 | } |
| 5553 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5554 | else |
| 5555 | --n_skip; |
| 5556 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5557 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5558 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5559 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5560 | #ifdef FEAT_DIFF |
| 5561 | && filler_todo <= 0 |
| 5562 | #endif |
| 5563 | ) |
| 5564 | ++vcol; |
| 5565 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5566 | #ifdef FEAT_SYN_HL |
| 5567 | if (vcol_save_attr >= 0) |
| 5568 | char_attr = vcol_save_attr; |
| 5569 | #endif |
| 5570 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5571 | /* restore attributes after "predeces" in 'listchars' */ |
| 5572 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5573 | char_attr = saved_attr3; |
| 5574 | |
| 5575 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5576 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5577 | char_attr = saved_attr2; |
| 5578 | |
| 5579 | /* |
| 5580 | * At end of screen line and there is more to come: Display the line |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5581 | * so far. If there is no more to display it is caught above. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5582 | */ |
| 5583 | if (( |
| 5584 | #ifdef FEAT_RIGHTLEFT |
| 5585 | wp->w_p_rl ? (col < 0) : |
| 5586 | #endif |
| 5587 | (col >= W_WIDTH(wp))) |
| 5588 | && (*ptr != NUL |
| 5589 | #ifdef FEAT_DIFF |
| 5590 | || filler_todo > 0 |
| 5591 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5592 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5593 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5594 | ) |
| 5595 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5596 | #ifdef FEAT_CONCEAL |
| 5597 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5598 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5599 | boguscols = 0; |
| 5600 | #else |
| 5601 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5602 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5603 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5604 | ++row; |
| 5605 | ++screen_row; |
| 5606 | |
| 5607 | /* When not wrapping and finished diff lines, or when displayed |
| 5608 | * '$' and highlighting until last column, break here. */ |
| 5609 | if ((!wp->w_p_wrap |
| 5610 | #ifdef FEAT_DIFF |
| 5611 | && filler_todo <= 0 |
| 5612 | #endif |
| 5613 | ) || lcs_eol_one == -1) |
| 5614 | break; |
| 5615 | |
| 5616 | /* When the window is too narrow draw all "@" lines. */ |
| 5617 | if (draw_state != WL_LINE |
| 5618 | #ifdef FEAT_DIFF |
| 5619 | && filler_todo <= 0 |
| 5620 | #endif |
| 5621 | ) |
| 5622 | { |
| 5623 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
| 5624 | #ifdef FEAT_VERTSPLIT |
| 5625 | draw_vsep_win(wp, row); |
| 5626 | #endif |
| 5627 | row = endrow; |
| 5628 | } |
| 5629 | |
| 5630 | /* When line got too long for screen break here. */ |
| 5631 | if (row == endrow) |
| 5632 | { |
| 5633 | ++row; |
| 5634 | break; |
| 5635 | } |
| 5636 | |
| 5637 | if (screen_cur_row == screen_row - 1 |
| 5638 | #ifdef FEAT_DIFF |
| 5639 | && filler_todo <= 0 |
| 5640 | #endif |
| 5641 | && W_WIDTH(wp) == Columns) |
| 5642 | { |
| 5643 | /* Remember that the line wraps, used for modeless copy. */ |
| 5644 | LineWraps[screen_row - 1] = TRUE; |
| 5645 | |
| 5646 | /* |
| 5647 | * Special trick to make copy/paste of wrapped lines work with |
| 5648 | * xterm/screen: write an extra character beyond the end of |
| 5649 | * the line. This will work with all terminal types |
| 5650 | * (regardless of the xn,am settings). |
| 5651 | * Only do this on a fast tty. |
| 5652 | * Only do this if the cursor is on the current line |
| 5653 | * (something has been written in it). |
| 5654 | * Don't do this for the GUI. |
| 5655 | * Don't do this for double-width characters. |
| 5656 | * Don't do this for a window not at the right screen border. |
| 5657 | */ |
| 5658 | if (p_tf |
| 5659 | #ifdef FEAT_GUI |
| 5660 | && !gui.in_use |
| 5661 | #endif |
| 5662 | #ifdef FEAT_MBYTE |
| 5663 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5664 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5665 | LineOffset[screen_row] + screen_Columns) |
| 5666 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5667 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5668 | + (int)Columns - 2, |
| 5669 | LineOffset[screen_row] + screen_Columns) |
| 5670 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5671 | #endif |
| 5672 | ) |
| 5673 | { |
| 5674 | /* First make sure we are at the end of the screen line, |
| 5675 | * then output the same character again to let the |
| 5676 | * terminal know about the wrap. If the terminal doesn't |
| 5677 | * auto-wrap, we overwrite the character. */ |
| 5678 | if (screen_cur_col != W_WIDTH(wp)) |
| 5679 | screen_char(LineOffset[screen_row - 1] |
| 5680 | + (unsigned)Columns - 1, |
| 5681 | screen_row - 1, (int)(Columns - 1)); |
| 5682 | |
| 5683 | #ifdef FEAT_MBYTE |
| 5684 | /* When there is a multi-byte character, just output a |
| 5685 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5686 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5687 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5688 | out_char(' '); |
| 5689 | else |
| 5690 | #endif |
| 5691 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5692 | + (Columns - 1)]); |
| 5693 | /* force a redraw of the first char on the next line */ |
| 5694 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5695 | screen_start(); /* don't know where cursor is now */ |
| 5696 | } |
| 5697 | } |
| 5698 | |
| 5699 | col = 0; |
| 5700 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5701 | #ifdef FEAT_RIGHTLEFT |
| 5702 | if (wp->w_p_rl) |
| 5703 | { |
| 5704 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5705 | off += col; |
| 5706 | } |
| 5707 | #endif |
| 5708 | |
| 5709 | /* reset the drawing state for the start of a wrapped line */ |
| 5710 | draw_state = WL_START; |
| 5711 | saved_n_extra = n_extra; |
| 5712 | saved_p_extra = p_extra; |
| 5713 | saved_c_extra = c_extra; |
| 5714 | saved_char_attr = char_attr; |
| 5715 | n_extra = 0; |
| 5716 | lcs_prec_todo = lcs_prec; |
| 5717 | #ifdef FEAT_LINEBREAK |
| 5718 | # ifdef FEAT_DIFF |
| 5719 | if (filler_todo <= 0) |
| 5720 | # endif |
| 5721 | need_showbreak = TRUE; |
| 5722 | #endif |
| 5723 | #ifdef FEAT_DIFF |
| 5724 | --filler_todo; |
| 5725 | /* When the filler lines are actually below the last line of the |
| 5726 | * file, don't draw the line itself, break here. */ |
| 5727 | if (filler_todo == 0 && wp->w_botfill) |
| 5728 | break; |
| 5729 | #endif |
| 5730 | } |
| 5731 | |
| 5732 | } /* for every character in the line */ |
| 5733 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5734 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5735 | /* After an empty line check first word for capital. */ |
| 5736 | if (*skipwhite(line) == NUL) |
| 5737 | { |
| 5738 | capcol_lnum = lnum + 1; |
| 5739 | cap_col = 0; |
| 5740 | } |
| 5741 | #endif |
| 5742 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5743 | return row; |
| 5744 | } |
| 5745 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5746 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5747 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5748 | |
| 5749 | /* |
| 5750 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5751 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5752 | */ |
| 5753 | static int |
| 5754 | comp_char_differs(off_from, off_to) |
| 5755 | int off_from; |
| 5756 | int off_to; |
| 5757 | { |
| 5758 | int i; |
| 5759 | |
| 5760 | for (i = 0; i < Screen_mco; ++i) |
| 5761 | { |
| 5762 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5763 | return TRUE; |
| 5764 | if (ScreenLinesC[i][off_from] == 0) |
| 5765 | break; |
| 5766 | } |
| 5767 | return FALSE; |
| 5768 | } |
| 5769 | #endif |
| 5770 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5771 | /* |
| 5772 | * Check whether the given character needs redrawing: |
| 5773 | * - the (first byte of the) character is different |
| 5774 | * - the attributes are different |
| 5775 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5776 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5777 | */ |
| 5778 | static int |
| 5779 | char_needs_redraw(off_from, off_to, cols) |
| 5780 | int off_from; |
| 5781 | int off_to; |
| 5782 | int cols; |
| 5783 | { |
| 5784 | if (cols > 0 |
| 5785 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5786 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5787 | |
| 5788 | #ifdef FEAT_MBYTE |
| 5789 | || (enc_dbcs != 0 |
| 5790 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5791 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5792 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5793 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5794 | != ScreenLines[off_to + 1]))) |
| 5795 | || (enc_utf8 |
| 5796 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5797 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5798 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5799 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5800 | && ScreenLines[off_from + 1] |
| 5801 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5802 | #endif |
| 5803 | )) |
| 5804 | return TRUE; |
| 5805 | return FALSE; |
| 5806 | } |
| 5807 | |
| 5808 | /* |
| 5809 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5810 | * have actually changed. Handle insert/delete character. |
| 5811 | * "coloff" gives the first column on the screen for this line. |
| 5812 | * "endcol" gives the columns where valid characters are. |
| 5813 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5814 | * needs to be cleared, negative otherwise. |
| 5815 | * "rlflag" is TRUE in a rightleft window: |
| 5816 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5817 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5818 | */ |
| 5819 | static void |
| 5820 | screen_line(row, coloff, endcol, clear_width |
| 5821 | #ifdef FEAT_RIGHTLEFT |
| 5822 | , rlflag |
| 5823 | #endif |
| 5824 | ) |
| 5825 | int row; |
| 5826 | int coloff; |
| 5827 | int endcol; |
| 5828 | int clear_width; |
| 5829 | #ifdef FEAT_RIGHTLEFT |
| 5830 | int rlflag; |
| 5831 | #endif |
| 5832 | { |
| 5833 | unsigned off_from; |
| 5834 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5835 | #ifdef FEAT_MBYTE |
| 5836 | unsigned max_off_from; |
| 5837 | unsigned max_off_to; |
| 5838 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5839 | int col = 0; |
| 5840 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_VERTSPLIT) |
| 5841 | int hl; |
| 5842 | #endif |
| 5843 | int force = FALSE; /* force update rest of the line */ |
| 5844 | int redraw_this /* bool: does character need redraw? */ |
| 5845 | #ifdef FEAT_GUI |
| 5846 | = TRUE /* For GUI when while-loop empty */ |
| 5847 | #endif |
| 5848 | ; |
| 5849 | int redraw_next; /* redraw_this for next character */ |
| 5850 | #ifdef FEAT_MBYTE |
| 5851 | int clear_next = FALSE; |
| 5852 | int char_cells; /* 1: normal char */ |
| 5853 | /* 2: occupies two display cells */ |
| 5854 | # define CHAR_CELLS char_cells |
| 5855 | #else |
| 5856 | # define CHAR_CELLS 1 |
| 5857 | #endif |
| 5858 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5859 | /* Check for illegal row and col, just in case. */ |
| 5860 | if (row >= Rows) |
| 5861 | row = Rows - 1; |
| 5862 | if (endcol > Columns) |
| 5863 | endcol = Columns; |
| 5864 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5865 | # ifdef FEAT_CLIPBOARD |
| 5866 | clip_may_clear_selection(row, row); |
| 5867 | # endif |
| 5868 | |
| 5869 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5870 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5871 | #ifdef FEAT_MBYTE |
| 5872 | max_off_from = off_from + screen_Columns; |
| 5873 | max_off_to = LineOffset[row] + screen_Columns; |
| 5874 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5875 | |
| 5876 | #ifdef FEAT_RIGHTLEFT |
| 5877 | if (rlflag) |
| 5878 | { |
| 5879 | /* Clear rest first, because it's left of the text. */ |
| 5880 | if (clear_width > 0) |
| 5881 | { |
| 5882 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5883 | && ScreenAttrs[off_to] == 0 |
| 5884 | # ifdef FEAT_MBYTE |
| 5885 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5886 | # endif |
| 5887 | ) |
| 5888 | { |
| 5889 | ++off_to; |
| 5890 | ++col; |
| 5891 | } |
| 5892 | if (col <= endcol) |
| 5893 | screen_fill(row, row + 1, col + coloff, |
| 5894 | endcol + coloff + 1, ' ', ' ', 0); |
| 5895 | } |
| 5896 | col = endcol + 1; |
| 5897 | off_to = LineOffset[row] + col + coloff; |
| 5898 | off_from += col; |
| 5899 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5900 | } |
| 5901 | #endif /* FEAT_RIGHTLEFT */ |
| 5902 | |
| 5903 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5904 | |
| 5905 | while (col < endcol) |
| 5906 | { |
| 5907 | #ifdef FEAT_MBYTE |
| 5908 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5909 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5910 | else |
| 5911 | char_cells = 1; |
| 5912 | #endif |
| 5913 | |
| 5914 | redraw_this = redraw_next; |
| 5915 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5916 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5917 | |
| 5918 | #ifdef FEAT_GUI |
| 5919 | /* If the next character was bold, then redraw the current character to |
| 5920 | * remove any pixels that might have spilt over into us. This only |
| 5921 | * happens in the GUI. |
| 5922 | */ |
| 5923 | if (redraw_next && gui.in_use) |
| 5924 | { |
| 5925 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5926 | if (hl > HL_ALL) |
| 5927 | hl = syn_attr2attr(hl); |
| 5928 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5929 | redraw_this = TRUE; |
| 5930 | } |
| 5931 | #endif |
| 5932 | |
| 5933 | if (redraw_this) |
| 5934 | { |
| 5935 | /* |
| 5936 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5937 | * Attributes for characters are stored at the position where the |
| 5938 | * cursor is when writing the highlighting code. The |
| 5939 | * start-highlighting code must be written with the cursor on the |
| 5940 | * first highlighted character. The stop-highlighting code must |
| 5941 | * be written with the cursor just after the last highlighted |
| 5942 | * character. |
| 5943 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5944 | * to clear the rest of the line, and force redrawing it |
| 5945 | * completely. |
| 5946 | */ |
| 5947 | if ( p_wiv |
| 5948 | && !force |
| 5949 | #ifdef FEAT_GUI |
| 5950 | && !gui.in_use |
| 5951 | #endif |
| 5952 | && ScreenAttrs[off_to] != 0 |
| 5953 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5954 | { |
| 5955 | /* |
| 5956 | * Need to remove highlighting attributes here. |
| 5957 | */ |
| 5958 | windgoto(row, col + coloff); |
| 5959 | out_str(T_CE); /* clear rest of this screen line */ |
| 5960 | screen_start(); /* don't know where cursor is now */ |
| 5961 | force = TRUE; /* force redraw of rest of the line */ |
| 5962 | redraw_next = TRUE; /* or else next char would miss out */ |
| 5963 | |
| 5964 | /* |
| 5965 | * If the previous character was highlighted, need to stop |
| 5966 | * highlighting at this character. |
| 5967 | */ |
| 5968 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 5969 | { |
| 5970 | screen_attr = ScreenAttrs[off_to - 1]; |
| 5971 | term_windgoto(row, col + coloff); |
| 5972 | screen_stop_highlight(); |
| 5973 | } |
| 5974 | else |
| 5975 | screen_attr = 0; /* highlighting has stopped */ |
| 5976 | } |
| 5977 | #ifdef FEAT_MBYTE |
| 5978 | if (enc_dbcs != 0) |
| 5979 | { |
| 5980 | /* Check if overwriting a double-byte with a single-byte or |
| 5981 | * the other way around requires another character to be |
| 5982 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 5983 | * ScreenLinesUC[] is sufficient. */ |
| 5984 | if (char_cells == 1 |
| 5985 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5986 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5987 | { |
| 5988 | /* Writing a single-cell character over a double-cell |
| 5989 | * character: need to redraw the next cell. */ |
| 5990 | ScreenLines[off_to + 1] = 0; |
| 5991 | redraw_next = TRUE; |
| 5992 | } |
| 5993 | else if (char_cells == 2 |
| 5994 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5995 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 5996 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5997 | { |
| 5998 | /* Writing the second half of a double-cell character over |
| 5999 | * a double-cell character: need to redraw the second |
| 6000 | * cell. */ |
| 6001 | ScreenLines[off_to + 2] = 0; |
| 6002 | redraw_next = TRUE; |
| 6003 | } |
| 6004 | |
| 6005 | if (enc_dbcs == DBCS_JPNU) |
| 6006 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 6007 | } |
| 6008 | /* When writing a single-width character over a double-width |
| 6009 | * character and at the end of the redrawn text, need to clear out |
| 6010 | * the right halve of the old character. |
| 6011 | * Also required when writing the right halve of a double-width |
| 6012 | * char over the left halve of an existing one. */ |
| 6013 | if (has_mbyte && col + char_cells == endcol |
| 6014 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6015 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6016 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6017 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6018 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6019 | clear_next = TRUE; |
| 6020 | #endif |
| 6021 | |
| 6022 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 6023 | #ifdef FEAT_MBYTE |
| 6024 | if (enc_utf8) |
| 6025 | { |
| 6026 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 6027 | if (ScreenLinesUC[off_from] != 0) |
| 6028 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6029 | int i; |
| 6030 | |
| 6031 | for (i = 0; i < Screen_mco; ++i) |
| 6032 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6033 | } |
| 6034 | } |
| 6035 | if (char_cells == 2) |
| 6036 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6037 | #endif |
| 6038 | |
| 6039 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6040 | /* The bold trick makes a single column of pixels appear in the |
| 6041 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6042 | * character should be redrawn too. This happens for our own GUI |
| 6043 | * and for some xterms. */ |
| 6044 | if ( |
| 6045 | # ifdef FEAT_GUI |
| 6046 | gui.in_use |
| 6047 | # endif |
| 6048 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6049 | || |
| 6050 | # endif |
| 6051 | # ifdef UNIX |
| 6052 | term_is_xterm |
| 6053 | # endif |
| 6054 | ) |
| 6055 | { |
| 6056 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6057 | if (hl > HL_ALL) |
| 6058 | hl = syn_attr2attr(hl); |
| 6059 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6060 | redraw_next = TRUE; |
| 6061 | } |
| 6062 | #endif |
| 6063 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6064 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6065 | /* For simplicity set the attributes of second half of a |
| 6066 | * double-wide character equal to the first half. */ |
| 6067 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6068 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6069 | |
| 6070 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6071 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6072 | else |
| 6073 | #endif |
| 6074 | screen_char(off_to, row, col + coloff); |
| 6075 | } |
| 6076 | else if ( p_wiv |
| 6077 | #ifdef FEAT_GUI |
| 6078 | && !gui.in_use |
| 6079 | #endif |
| 6080 | && col + coloff > 0) |
| 6081 | { |
| 6082 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6083 | { |
| 6084 | /* |
| 6085 | * Don't output stop-highlight when moving the cursor, it will |
| 6086 | * stop the highlighting when it should continue. |
| 6087 | */ |
| 6088 | screen_attr = 0; |
| 6089 | } |
| 6090 | else if (screen_attr != 0) |
| 6091 | screen_stop_highlight(); |
| 6092 | } |
| 6093 | |
| 6094 | off_to += CHAR_CELLS; |
| 6095 | off_from += CHAR_CELLS; |
| 6096 | col += CHAR_CELLS; |
| 6097 | } |
| 6098 | |
| 6099 | #ifdef FEAT_MBYTE |
| 6100 | if (clear_next) |
| 6101 | { |
| 6102 | /* Clear the second half of a double-wide character of which the left |
| 6103 | * half was overwritten with a single-wide character. */ |
| 6104 | ScreenLines[off_to] = ' '; |
| 6105 | if (enc_utf8) |
| 6106 | ScreenLinesUC[off_to] = 0; |
| 6107 | screen_char(off_to, row, col + coloff); |
| 6108 | } |
| 6109 | #endif |
| 6110 | |
| 6111 | if (clear_width > 0 |
| 6112 | #ifdef FEAT_RIGHTLEFT |
| 6113 | && !rlflag |
| 6114 | #endif |
| 6115 | ) |
| 6116 | { |
| 6117 | #ifdef FEAT_GUI |
| 6118 | int startCol = col; |
| 6119 | #endif |
| 6120 | |
| 6121 | /* blank out the rest of the line */ |
| 6122 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6123 | && ScreenAttrs[off_to] == 0 |
| 6124 | #ifdef FEAT_MBYTE |
| 6125 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6126 | #endif |
| 6127 | ) |
| 6128 | { |
| 6129 | ++off_to; |
| 6130 | ++col; |
| 6131 | } |
| 6132 | if (col < clear_width) |
| 6133 | { |
| 6134 | #ifdef FEAT_GUI |
| 6135 | /* |
| 6136 | * In the GUI, clearing the rest of the line may leave pixels |
| 6137 | * behind if the first character cleared was bold. Some bold |
| 6138 | * fonts spill over the left. In this case we redraw the previous |
| 6139 | * character too. If we didn't skip any blanks above, then we |
| 6140 | * only redraw if the character wasn't already redrawn anyway. |
| 6141 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6142 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6143 | { |
| 6144 | hl = ScreenAttrs[off_to]; |
| 6145 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6146 | { |
| 6147 | int prev_cells = 1; |
| 6148 | # ifdef FEAT_MBYTE |
| 6149 | if (enc_utf8) |
| 6150 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6151 | * that its width is 2. */ |
| 6152 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6153 | else if (enc_dbcs != 0) |
| 6154 | { |
| 6155 | /* find previous character by counting from first |
| 6156 | * column and get its width. */ |
| 6157 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6158 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6159 | |
| 6160 | while (off < off_to) |
| 6161 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6162 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6163 | off += prev_cells; |
| 6164 | } |
| 6165 | } |
| 6166 | |
| 6167 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6168 | screen_char_2(off_to - prev_cells, row, |
| 6169 | col + coloff - prev_cells); |
| 6170 | else |
| 6171 | # endif |
| 6172 | screen_char(off_to - prev_cells, row, |
| 6173 | col + coloff - prev_cells); |
| 6174 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6175 | } |
| 6176 | #endif |
| 6177 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6178 | ' ', ' ', 0); |
| 6179 | #ifdef FEAT_VERTSPLIT |
| 6180 | off_to += clear_width - col; |
| 6181 | col = clear_width; |
| 6182 | #endif |
| 6183 | } |
| 6184 | } |
| 6185 | |
| 6186 | if (clear_width > 0) |
| 6187 | { |
| 6188 | #ifdef FEAT_VERTSPLIT |
| 6189 | /* For a window that's left of another, draw the separator char. */ |
| 6190 | if (col + coloff < Columns) |
| 6191 | { |
| 6192 | int c; |
| 6193 | |
| 6194 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6195 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6196 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6197 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6198 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6199 | # endif |
| 6200 | || ScreenAttrs[off_to] != hl) |
| 6201 | { |
| 6202 | ScreenLines[off_to] = c; |
| 6203 | ScreenAttrs[off_to] = hl; |
| 6204 | # ifdef FEAT_MBYTE |
| 6205 | if (enc_utf8) |
| 6206 | { |
| 6207 | if (c >= 0x80) |
| 6208 | { |
| 6209 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6210 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6211 | } |
| 6212 | else |
| 6213 | ScreenLinesUC[off_to] = 0; |
| 6214 | } |
| 6215 | # endif |
| 6216 | screen_char(off_to, row, col + coloff); |
| 6217 | } |
| 6218 | } |
| 6219 | else |
| 6220 | #endif |
| 6221 | LineWraps[row] = FALSE; |
| 6222 | } |
| 6223 | } |
| 6224 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6225 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6226 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6227 | * Mirror text "str" for right-left displaying. |
| 6228 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6229 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6230 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6231 | rl_mirror(str) |
| 6232 | char_u *str; |
| 6233 | { |
| 6234 | char_u *p1, *p2; |
| 6235 | int t; |
| 6236 | |
| 6237 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6238 | { |
| 6239 | t = *p1; |
| 6240 | *p1 = *p2; |
| 6241 | *p2 = t; |
| 6242 | } |
| 6243 | } |
| 6244 | #endif |
| 6245 | |
| 6246 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6247 | /* |
| 6248 | * mark all status lines for redraw; used after first :cd |
| 6249 | */ |
| 6250 | void |
| 6251 | status_redraw_all() |
| 6252 | { |
| 6253 | win_T *wp; |
| 6254 | |
| 6255 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6256 | if (wp->w_status_height) |
| 6257 | { |
| 6258 | wp->w_redr_status = TRUE; |
| 6259 | redraw_later(VALID); |
| 6260 | } |
| 6261 | } |
| 6262 | |
| 6263 | /* |
| 6264 | * mark all status lines of the current buffer for redraw |
| 6265 | */ |
| 6266 | void |
| 6267 | status_redraw_curbuf() |
| 6268 | { |
| 6269 | win_T *wp; |
| 6270 | |
| 6271 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6272 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6273 | { |
| 6274 | wp->w_redr_status = TRUE; |
| 6275 | redraw_later(VALID); |
| 6276 | } |
| 6277 | } |
| 6278 | |
| 6279 | /* |
| 6280 | * Redraw all status lines that need to be redrawn. |
| 6281 | */ |
| 6282 | void |
| 6283 | redraw_statuslines() |
| 6284 | { |
| 6285 | win_T *wp; |
| 6286 | |
| 6287 | for (wp = firstwin; wp; wp = wp->w_next) |
| 6288 | if (wp->w_redr_status) |
| 6289 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6290 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6291 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6292 | } |
| 6293 | #endif |
| 6294 | |
| 6295 | #if (defined(FEAT_WILDMENU) && defined(FEAT_VERTSPLIT)) || defined(PROTO) |
| 6296 | /* |
| 6297 | * Redraw all status lines at the bottom of frame "frp". |
| 6298 | */ |
| 6299 | void |
| 6300 | win_redraw_last_status(frp) |
| 6301 | frame_T *frp; |
| 6302 | { |
| 6303 | if (frp->fr_layout == FR_LEAF) |
| 6304 | frp->fr_win->w_redr_status = TRUE; |
| 6305 | else if (frp->fr_layout == FR_ROW) |
| 6306 | { |
| 6307 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6308 | win_redraw_last_status(frp); |
| 6309 | } |
| 6310 | else /* frp->fr_layout == FR_COL */ |
| 6311 | { |
| 6312 | frp = frp->fr_child; |
| 6313 | while (frp->fr_next != NULL) |
| 6314 | frp = frp->fr_next; |
| 6315 | win_redraw_last_status(frp); |
| 6316 | } |
| 6317 | } |
| 6318 | #endif |
| 6319 | |
| 6320 | #ifdef FEAT_VERTSPLIT |
| 6321 | /* |
| 6322 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6323 | */ |
| 6324 | static void |
| 6325 | draw_vsep_win(wp, row) |
| 6326 | win_T *wp; |
| 6327 | int row; |
| 6328 | { |
| 6329 | int hl; |
| 6330 | int c; |
| 6331 | |
| 6332 | if (wp->w_vsep_width) |
| 6333 | { |
| 6334 | /* draw the vertical separator right of this window */ |
| 6335 | c = fillchar_vsep(&hl); |
| 6336 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6337 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6338 | c, ' ', hl); |
| 6339 | } |
| 6340 | } |
| 6341 | #endif |
| 6342 | |
| 6343 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6344 | static int status_match_len(expand_T *xp, char_u *s); |
| 6345 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6346 | |
| 6347 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6348 | * Get the length of an item as it will be shown in the status line. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6349 | */ |
| 6350 | static int |
| 6351 | status_match_len(xp, s) |
| 6352 | expand_T *xp; |
| 6353 | char_u *s; |
| 6354 | { |
| 6355 | int len = 0; |
| 6356 | |
| 6357 | #ifdef FEAT_MENU |
| 6358 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6359 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6360 | |
| 6361 | /* Check for menu separators - replace with '|'. */ |
| 6362 | if (emenu && menu_is_separator(s)) |
| 6363 | return 1; |
| 6364 | #endif |
| 6365 | |
| 6366 | while (*s != NUL) |
| 6367 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6368 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6369 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6370 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6371 | } |
| 6372 | |
| 6373 | return len; |
| 6374 | } |
| 6375 | |
| 6376 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6377 | * Return the number of characters that should be skipped in a status match. |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6378 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6379 | */ |
| 6380 | static int |
| 6381 | skip_status_match_char(xp, s) |
| 6382 | expand_T *xp; |
| 6383 | char_u *s; |
| 6384 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6385 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6386 | #ifdef FEAT_MENU |
| 6387 | || ((xp->xp_context == EXPAND_MENUS |
| 6388 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6389 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6390 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6391 | ) |
| 6392 | { |
| 6393 | #ifndef BACKSLASH_IN_FILENAME |
| 6394 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6395 | return 2; |
| 6396 | #endif |
| 6397 | return 1; |
| 6398 | } |
| 6399 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6400 | } |
| 6401 | |
| 6402 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6403 | * Show wildchar matches in the status line. |
| 6404 | * Show at least the "match" item. |
| 6405 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6406 | * |
| 6407 | * If inversion is possible we use it. Else '=' characters are used. |
| 6408 | */ |
| 6409 | void |
| 6410 | win_redr_status_matches(xp, num_matches, matches, match, showtail) |
| 6411 | expand_T *xp; |
| 6412 | int num_matches; |
| 6413 | char_u **matches; /* list of matches */ |
| 6414 | int match; |
| 6415 | int showtail; |
| 6416 | { |
| 6417 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6418 | int row; |
| 6419 | char_u *buf; |
| 6420 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6421 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6422 | int fillchar; |
| 6423 | int attr; |
| 6424 | int i; |
| 6425 | int highlight = TRUE; |
| 6426 | char_u *selstart = NULL; |
| 6427 | int selstart_col = 0; |
| 6428 | char_u *selend = NULL; |
| 6429 | static int first_match = 0; |
| 6430 | int add_left = FALSE; |
| 6431 | char_u *s; |
| 6432 | #ifdef FEAT_MENU |
| 6433 | int emenu; |
| 6434 | #endif |
| 6435 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6436 | int l; |
| 6437 | #endif |
| 6438 | |
| 6439 | if (matches == NULL) /* interrupted completion? */ |
| 6440 | return; |
| 6441 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6442 | #ifdef FEAT_MBYTE |
| 6443 | if (has_mbyte) |
| 6444 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6445 | else |
| 6446 | #endif |
| 6447 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6448 | if (buf == NULL) |
| 6449 | return; |
| 6450 | |
| 6451 | if (match == -1) /* don't show match but original text */ |
| 6452 | { |
| 6453 | match = 0; |
| 6454 | highlight = FALSE; |
| 6455 | } |
| 6456 | /* count 1 for the ending ">" */ |
| 6457 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6458 | if (match == 0) |
| 6459 | first_match = 0; |
| 6460 | else if (match < first_match) |
| 6461 | { |
| 6462 | /* jumping left, as far as we can go */ |
| 6463 | first_match = match; |
| 6464 | add_left = TRUE; |
| 6465 | } |
| 6466 | else |
| 6467 | { |
| 6468 | /* check if match fits on the screen */ |
| 6469 | for (i = first_match; i < match; ++i) |
| 6470 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6471 | if (first_match > 0) |
| 6472 | clen += 2; |
| 6473 | /* jumping right, put match at the left */ |
| 6474 | if ((long)clen > Columns) |
| 6475 | { |
| 6476 | first_match = match; |
| 6477 | /* if showing the last match, we can add some on the left */ |
| 6478 | clen = 2; |
| 6479 | for (i = match; i < num_matches; ++i) |
| 6480 | { |
| 6481 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6482 | if ((long)clen >= Columns) |
| 6483 | break; |
| 6484 | } |
| 6485 | if (i == num_matches) |
| 6486 | add_left = TRUE; |
| 6487 | } |
| 6488 | } |
| 6489 | if (add_left) |
| 6490 | while (first_match > 0) |
| 6491 | { |
| 6492 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6493 | if ((long)clen >= Columns) |
| 6494 | break; |
| 6495 | --first_match; |
| 6496 | } |
| 6497 | |
| 6498 | fillchar = fillchar_status(&attr, TRUE); |
| 6499 | |
| 6500 | if (first_match == 0) |
| 6501 | { |
| 6502 | *buf = NUL; |
| 6503 | len = 0; |
| 6504 | } |
| 6505 | else |
| 6506 | { |
| 6507 | STRCPY(buf, "< "); |
| 6508 | len = 2; |
| 6509 | } |
| 6510 | clen = len; |
| 6511 | |
| 6512 | i = first_match; |
| 6513 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6514 | { |
| 6515 | if (i == match) |
| 6516 | { |
| 6517 | selstart = buf + len; |
| 6518 | selstart_col = clen; |
| 6519 | } |
| 6520 | |
| 6521 | s = L_MATCH(i); |
| 6522 | /* Check for menu separators - replace with '|' */ |
| 6523 | #ifdef FEAT_MENU |
| 6524 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6525 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6526 | if (emenu && menu_is_separator(s)) |
| 6527 | { |
| 6528 | STRCPY(buf + len, transchar('|')); |
| 6529 | l = (int)STRLEN(buf + len); |
| 6530 | len += l; |
| 6531 | clen += l; |
| 6532 | } |
| 6533 | else |
| 6534 | #endif |
| 6535 | for ( ; *s != NUL; ++s) |
| 6536 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6537 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6538 | clen += ptr2cells(s); |
| 6539 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6540 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6541 | { |
| 6542 | STRNCPY(buf + len, s, l); |
| 6543 | s += l - 1; |
| 6544 | len += l; |
| 6545 | } |
| 6546 | else |
| 6547 | #endif |
| 6548 | { |
| 6549 | STRCPY(buf + len, transchar_byte(*s)); |
| 6550 | len += (int)STRLEN(buf + len); |
| 6551 | } |
| 6552 | } |
| 6553 | if (i == match) |
| 6554 | selend = buf + len; |
| 6555 | |
| 6556 | *(buf + len++) = ' '; |
| 6557 | *(buf + len++) = ' '; |
| 6558 | clen += 2; |
| 6559 | if (++i == num_matches) |
| 6560 | break; |
| 6561 | } |
| 6562 | |
| 6563 | if (i != num_matches) |
| 6564 | { |
| 6565 | *(buf + len++) = '>'; |
| 6566 | ++clen; |
| 6567 | } |
| 6568 | |
| 6569 | buf[len] = NUL; |
| 6570 | |
| 6571 | row = cmdline_row - 1; |
| 6572 | if (row >= 0) |
| 6573 | { |
| 6574 | if (wild_menu_showing == 0) |
| 6575 | { |
| 6576 | if (msg_scrolled > 0) |
| 6577 | { |
| 6578 | /* Put the wildmenu just above the command line. If there is |
| 6579 | * no room, scroll the screen one line up. */ |
| 6580 | if (cmdline_row == Rows - 1) |
| 6581 | { |
| 6582 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6583 | ++msg_scrolled; |
| 6584 | } |
| 6585 | else |
| 6586 | { |
| 6587 | ++cmdline_row; |
| 6588 | ++row; |
| 6589 | } |
| 6590 | wild_menu_showing = WM_SCROLLED; |
| 6591 | } |
| 6592 | else |
| 6593 | { |
| 6594 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6595 | * Set 'winminheight' to zero to avoid that the window is |
| 6596 | * resized. */ |
| 6597 | if (lastwin->w_status_height == 0) |
| 6598 | { |
| 6599 | save_p_ls = p_ls; |
| 6600 | save_p_wmh = p_wmh; |
| 6601 | p_ls = 2; |
| 6602 | p_wmh = 0; |
| 6603 | last_status(FALSE); |
| 6604 | } |
| 6605 | wild_menu_showing = WM_SHOWN; |
| 6606 | } |
| 6607 | } |
| 6608 | |
| 6609 | screen_puts(buf, row, 0, attr); |
| 6610 | if (selstart != NULL && highlight) |
| 6611 | { |
| 6612 | *selend = NUL; |
| 6613 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6614 | } |
| 6615 | |
| 6616 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6617 | } |
| 6618 | |
| 6619 | #ifdef FEAT_VERTSPLIT |
| 6620 | win_redraw_last_status(topframe); |
| 6621 | #else |
| 6622 | lastwin->w_redr_status = TRUE; |
| 6623 | #endif |
| 6624 | vim_free(buf); |
| 6625 | } |
| 6626 | #endif |
| 6627 | |
| 6628 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6629 | /* |
| 6630 | * Redraw the status line of window wp. |
| 6631 | * |
| 6632 | * If inversion is possible we use it. Else '=' characters are used. |
| 6633 | */ |
| 6634 | void |
| 6635 | win_redr_status(wp) |
| 6636 | win_T *wp; |
| 6637 | { |
| 6638 | int row; |
| 6639 | char_u *p; |
| 6640 | int len; |
| 6641 | int fillchar; |
| 6642 | int attr; |
| 6643 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6644 | static int busy = FALSE; |
| 6645 | |
| 6646 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6647 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6648 | if (busy) |
| 6649 | return; |
| 6650 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6651 | |
| 6652 | wp->w_redr_status = FALSE; |
| 6653 | if (wp->w_status_height == 0) |
| 6654 | { |
| 6655 | /* no status line, can only be last window */ |
| 6656 | redraw_cmdline = TRUE; |
| 6657 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6658 | else if (!redrawing() |
| 6659 | #ifdef FEAT_INS_EXPAND |
| 6660 | /* don't update status line when popup menu is visible and may be |
| 6661 | * drawn over it */ |
| 6662 | || pum_visible() |
| 6663 | #endif |
| 6664 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6665 | { |
| 6666 | /* Don't redraw right now, do it later. */ |
| 6667 | wp->w_redr_status = TRUE; |
| 6668 | } |
| 6669 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6670 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6671 | { |
| 6672 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6673 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6674 | } |
| 6675 | #endif |
| 6676 | else |
| 6677 | { |
| 6678 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6679 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6680 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6681 | p = NameBuff; |
| 6682 | len = (int)STRLEN(p); |
| 6683 | |
| 6684 | if (wp->w_buffer->b_help |
| 6685 | #ifdef FEAT_QUICKFIX |
| 6686 | || wp->w_p_pvw |
| 6687 | #endif |
| 6688 | || bufIsChanged(wp->w_buffer) |
| 6689 | || wp->w_buffer->b_p_ro) |
| 6690 | *(p + len++) = ' '; |
| 6691 | if (wp->w_buffer->b_help) |
| 6692 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6693 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6694 | len += (int)STRLEN(p + len); |
| 6695 | } |
| 6696 | #ifdef FEAT_QUICKFIX |
| 6697 | if (wp->w_p_pvw) |
| 6698 | { |
| 6699 | STRCPY(p + len, _("[Preview]")); |
| 6700 | len += (int)STRLEN(p + len); |
| 6701 | } |
| 6702 | #endif |
| 6703 | if (bufIsChanged(wp->w_buffer)) |
| 6704 | { |
| 6705 | STRCPY(p + len, "[+]"); |
| 6706 | len += 3; |
| 6707 | } |
| 6708 | if (wp->w_buffer->b_p_ro) |
| 6709 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6710 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6711 | len += 4; |
| 6712 | } |
| 6713 | |
| 6714 | #ifndef FEAT_VERTSPLIT |
| 6715 | this_ru_col = ru_col; |
| 6716 | if (this_ru_col < (Columns + 1) / 2) |
| 6717 | this_ru_col = (Columns + 1) / 2; |
| 6718 | #else |
| 6719 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6720 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6721 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6722 | if (this_ru_col <= 1) |
| 6723 | { |
| 6724 | p = (char_u *)"<"; /* No room for file name! */ |
| 6725 | len = 1; |
| 6726 | } |
| 6727 | else |
| 6728 | #endif |
| 6729 | #ifdef FEAT_MBYTE |
| 6730 | if (has_mbyte) |
| 6731 | { |
| 6732 | int clen = 0, i; |
| 6733 | |
| 6734 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6735 | clen = mb_string2cells(p, -1); |
| 6736 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6737 | /* Find first character that will fit. |
| 6738 | * Going from start to end is much faster for DBCS. */ |
| 6739 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6740 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6741 | clen -= (*mb_ptr2cells)(p + i); |
| 6742 | len = clen; |
| 6743 | if (i > 0) |
| 6744 | { |
| 6745 | p = p + i - 1; |
| 6746 | *p = '<'; |
| 6747 | ++len; |
| 6748 | } |
| 6749 | |
| 6750 | } |
| 6751 | else |
| 6752 | #endif |
| 6753 | if (len > this_ru_col - 1) |
| 6754 | { |
| 6755 | p += len - (this_ru_col - 1); |
| 6756 | *p = '<'; |
| 6757 | len = this_ru_col - 1; |
| 6758 | } |
| 6759 | |
| 6760 | row = W_WINROW(wp) + wp->w_height; |
| 6761 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6762 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6763 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6764 | |
| 6765 | if (get_keymap_str(wp, NameBuff, MAXPATHL) |
| 6766 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6767 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6768 | - 1 + W_WINCOL(wp)), attr); |
| 6769 | |
| 6770 | #ifdef FEAT_CMDL_INFO |
| 6771 | win_redr_ruler(wp, TRUE); |
| 6772 | #endif |
| 6773 | } |
| 6774 | |
| 6775 | #ifdef FEAT_VERTSPLIT |
| 6776 | /* |
| 6777 | * May need to draw the character below the vertical separator. |
| 6778 | */ |
| 6779 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6780 | { |
| 6781 | if (stl_connected(wp)) |
| 6782 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6783 | else |
| 6784 | fillchar = fillchar_vsep(&attr); |
| 6785 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6786 | attr); |
| 6787 | } |
| 6788 | #endif |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6789 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6790 | } |
| 6791 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6792 | #ifdef FEAT_STL_OPT |
| 6793 | /* |
| 6794 | * Redraw the status line according to 'statusline' and take care of any |
| 6795 | * errors encountered. |
| 6796 | */ |
| 6797 | static void |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6798 | redraw_custom_statusline(wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6799 | win_T *wp; |
| 6800 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6801 | static int entered = FALSE; |
| 6802 | int save_called_emsg = called_emsg; |
| 6803 | |
| 6804 | /* When called recursively return. This can happen when the statusline |
| 6805 | * contains an expression that triggers a redraw. */ |
| 6806 | if (entered) |
| 6807 | return; |
| 6808 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6809 | |
| 6810 | called_emsg = FALSE; |
| 6811 | win_redr_custom(wp, FALSE); |
| 6812 | if (called_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6813 | { |
| 6814 | /* When there is an error disable the statusline, otherwise the |
| 6815 | * display is messed up with errors and a redraw triggers the problem |
| 6816 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6817 | set_string_option_direct((char_u *)"statusline", -1, |
| 6818 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6819 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6820 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6821 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6822 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6823 | } |
| 6824 | #endif |
| 6825 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6826 | # ifdef FEAT_VERTSPLIT |
| 6827 | /* |
| 6828 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6829 | * line of the window right of it. If not, then it's a vertical separator. |
| 6830 | * Only call if (wp->w_vsep_width != 0). |
| 6831 | */ |
| 6832 | int |
| 6833 | stl_connected(wp) |
| 6834 | win_T *wp; |
| 6835 | { |
| 6836 | frame_T *fr; |
| 6837 | |
| 6838 | fr = wp->w_frame; |
| 6839 | while (fr->fr_parent != NULL) |
| 6840 | { |
| 6841 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6842 | { |
| 6843 | if (fr->fr_next != NULL) |
| 6844 | break; |
| 6845 | } |
| 6846 | else |
| 6847 | { |
| 6848 | if (fr->fr_next != NULL) |
| 6849 | return TRUE; |
| 6850 | } |
| 6851 | fr = fr->fr_parent; |
| 6852 | } |
| 6853 | return FALSE; |
| 6854 | } |
| 6855 | # endif |
| 6856 | |
| 6857 | #endif /* FEAT_WINDOWS */ |
| 6858 | |
| 6859 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6860 | /* |
| 6861 | * Get the value to show for the language mappings, active 'keymap'. |
| 6862 | */ |
| 6863 | int |
| 6864 | get_keymap_str(wp, buf, len) |
| 6865 | win_T *wp; |
| 6866 | char_u *buf; /* buffer for the result */ |
| 6867 | int len; /* length of buffer */ |
| 6868 | { |
| 6869 | char_u *p; |
| 6870 | |
| 6871 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6872 | return FALSE; |
| 6873 | |
| 6874 | { |
| 6875 | #ifdef FEAT_EVAL |
| 6876 | buf_T *old_curbuf = curbuf; |
| 6877 | win_T *old_curwin = curwin; |
| 6878 | char_u *s; |
| 6879 | |
| 6880 | curbuf = wp->w_buffer; |
| 6881 | curwin = wp; |
| 6882 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6883 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6884 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6885 | --emsg_skip; |
| 6886 | curbuf = old_curbuf; |
| 6887 | curwin = old_curwin; |
| 6888 | if (p == NULL || *p == NUL) |
| 6889 | #endif |
| 6890 | { |
| 6891 | #ifdef FEAT_KEYMAP |
| 6892 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6893 | p = wp->w_buffer->b_p_keymap; |
| 6894 | else |
| 6895 | #endif |
| 6896 | p = (char_u *)"lang"; |
| 6897 | } |
| 6898 | if ((int)(STRLEN(p) + 3) < len) |
| 6899 | sprintf((char *)buf, "<%s>", p); |
| 6900 | else |
| 6901 | buf[0] = NUL; |
| 6902 | #ifdef FEAT_EVAL |
| 6903 | vim_free(s); |
| 6904 | #endif |
| 6905 | } |
| 6906 | return buf[0] != NUL; |
| 6907 | } |
| 6908 | #endif |
| 6909 | |
| 6910 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6911 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6912 | * Redraw the status line or ruler of window "wp". |
| 6913 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6914 | */ |
| 6915 | static void |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6916 | win_redr_custom(wp, draw_ruler) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6917 | win_T *wp; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 6918 | int draw_ruler; /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6919 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6920 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6921 | int attr; |
| 6922 | int curattr; |
| 6923 | int row; |
| 6924 | int col = 0; |
| 6925 | int maxwidth; |
| 6926 | int width; |
| 6927 | int n; |
| 6928 | int len; |
| 6929 | int fillchar; |
| 6930 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6931 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6932 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6933 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6934 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6935 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6936 | win_T *ewp; |
| 6937 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6938 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6939 | /* There is a tiny chance that this gets called recursively: When |
| 6940 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6941 | * Avoid trouble by not allowing recursion. */ |
| 6942 | if (entered) |
| 6943 | return; |
| 6944 | entered = TRUE; |
| 6945 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6946 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6947 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6948 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6949 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6950 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6951 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6952 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6953 | attr = hl_attr(HLF_TPF); |
| 6954 | maxwidth = Columns; |
| 6955 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6956 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6957 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6958 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6959 | else |
| 6960 | { |
| 6961 | row = W_WINROW(wp) + wp->w_height; |
| 6962 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6963 | maxwidth = W_WIDTH(wp); |
| 6964 | |
| 6965 | if (draw_ruler) |
| 6966 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6967 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6968 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6969 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6970 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6971 | if (*++stl == '-') |
| 6972 | stl++; |
| 6973 | if (atoi((char *)stl)) |
| 6974 | while (VIM_ISDIGIT(*stl)) |
| 6975 | stl++; |
| 6976 | if (*stl++ != '(') |
| 6977 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6978 | } |
| 6979 | #ifdef FEAT_VERTSPLIT |
| 6980 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6981 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6982 | col = (W_WIDTH(wp) + 1) / 2; |
| 6983 | #else |
| 6984 | col = ru_col; |
| 6985 | if (col > (Columns + 1) / 2) |
| 6986 | col = (Columns + 1) / 2; |
| 6987 | #endif |
| 6988 | maxwidth = W_WIDTH(wp) - col; |
| 6989 | #ifdef FEAT_WINDOWS |
| 6990 | if (!wp->w_status_height) |
| 6991 | #endif |
| 6992 | { |
| 6993 | row = Rows - 1; |
| 6994 | --maxwidth; /* writing in last column may cause scrolling */ |
| 6995 | fillchar = ' '; |
| 6996 | attr = 0; |
| 6997 | } |
| 6998 | |
| 6999 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7000 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7001 | # endif |
| 7002 | } |
| 7003 | else |
| 7004 | { |
| 7005 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7006 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7007 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7008 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7009 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7010 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 7011 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7012 | # endif |
| 7013 | } |
| 7014 | |
| 7015 | #ifdef FEAT_VERTSPLIT |
| 7016 | col += W_WINCOL(wp); |
| 7017 | #endif |
| 7018 | } |
| 7019 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7020 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7021 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7022 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7023 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 7024 | * the cursor away and back. */ |
| 7025 | ewp = wp == NULL ? curwin : wp; |
| 7026 | p_crb_save = ewp->w_p_crb; |
| 7027 | ewp->w_p_crb = FALSE; |
| 7028 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7029 | /* Make a copy, because the statusline may include a function call that |
| 7030 | * might change the option value and free the memory. */ |
| 7031 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7032 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7033 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7034 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7035 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7036 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7037 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 7038 | /* Make all characters printable. */ |
| 7039 | p = transstr(buf); |
| 7040 | if (p != NULL) |
| 7041 | { |
| 7042 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7043 | vim_free(p); |
| 7044 | } |
| 7045 | |
| 7046 | /* fill up with "fillchar" */ |
| 7047 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7048 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7049 | { |
| 7050 | #ifdef FEAT_MBYTE |
| 7051 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7052 | #else |
| 7053 | buf[len++] = fillchar; |
| 7054 | #endif |
| 7055 | ++width; |
| 7056 | } |
| 7057 | buf[len] = NUL; |
| 7058 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7059 | /* |
| 7060 | * Draw each snippet with the specified highlighting. |
| 7061 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7062 | curattr = attr; |
| 7063 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7064 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7065 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7066 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7067 | screen_puts_len(p, len, row, col, curattr); |
| 7068 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7069 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7070 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7071 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7072 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7073 | else if (hltab[n].userhl < 0) |
| 7074 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7075 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7076 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7077 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7078 | #endif |
| 7079 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7080 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7081 | } |
| 7082 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7083 | |
| 7084 | if (wp == NULL) |
| 7085 | { |
| 7086 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7087 | col = 0; |
| 7088 | len = 0; |
| 7089 | p = buf; |
| 7090 | fillchar = 0; |
| 7091 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7092 | { |
| 7093 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7094 | while (col < len) |
| 7095 | TabPageIdxs[col++] = fillchar; |
| 7096 | p = tabtab[n].start; |
| 7097 | fillchar = tabtab[n].userhl; |
| 7098 | } |
| 7099 | while (col < Columns) |
| 7100 | TabPageIdxs[col++] = fillchar; |
| 7101 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7102 | |
| 7103 | theend: |
| 7104 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7105 | } |
| 7106 | |
| 7107 | #endif /* FEAT_STL_OPT */ |
| 7108 | |
| 7109 | /* |
| 7110 | * Output a single character directly to the screen and update ScreenLines. |
| 7111 | */ |
| 7112 | void |
| 7113 | screen_putchar(c, row, col, attr) |
| 7114 | int c; |
| 7115 | int row, col; |
| 7116 | int attr; |
| 7117 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7118 | char_u buf[MB_MAXBYTES + 1]; |
| 7119 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7120 | #ifdef FEAT_MBYTE |
| 7121 | if (has_mbyte) |
| 7122 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7123 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7124 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7125 | { |
| 7126 | buf[0] = c; |
| 7127 | buf[1] = NUL; |
| 7128 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7129 | screen_puts(buf, row, col, attr); |
| 7130 | } |
| 7131 | |
| 7132 | /* |
| 7133 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7134 | * Also return its attribute in *attrp; |
| 7135 | */ |
| 7136 | void |
| 7137 | screen_getbytes(row, col, bytes, attrp) |
| 7138 | int row, col; |
| 7139 | char_u *bytes; |
| 7140 | int *attrp; |
| 7141 | { |
| 7142 | unsigned off; |
| 7143 | |
| 7144 | /* safety check */ |
| 7145 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7146 | { |
| 7147 | off = LineOffset[row] + col; |
| 7148 | *attrp = ScreenAttrs[off]; |
| 7149 | bytes[0] = ScreenLines[off]; |
| 7150 | bytes[1] = NUL; |
| 7151 | |
| 7152 | #ifdef FEAT_MBYTE |
| 7153 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7154 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7155 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7156 | { |
| 7157 | bytes[0] = ScreenLines[off]; |
| 7158 | bytes[1] = ScreenLines2[off]; |
| 7159 | bytes[2] = NUL; |
| 7160 | } |
| 7161 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7162 | { |
| 7163 | bytes[1] = ScreenLines[off + 1]; |
| 7164 | bytes[2] = NUL; |
| 7165 | } |
| 7166 | #endif |
| 7167 | } |
| 7168 | } |
| 7169 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7170 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7171 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7172 | |
| 7173 | /* |
| 7174 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7175 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7176 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7177 | */ |
| 7178 | static int |
| 7179 | screen_comp_differs(off, u8cc) |
| 7180 | int off; |
| 7181 | int *u8cc; |
| 7182 | { |
| 7183 | int i; |
| 7184 | |
| 7185 | for (i = 0; i < Screen_mco; ++i) |
| 7186 | { |
| 7187 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7188 | return TRUE; |
| 7189 | if (u8cc[i] == 0) |
| 7190 | break; |
| 7191 | } |
| 7192 | return FALSE; |
| 7193 | } |
| 7194 | #endif |
| 7195 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7196 | /* |
| 7197 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7198 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7199 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7200 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7201 | */ |
| 7202 | void |
| 7203 | screen_puts(text, row, col, attr) |
| 7204 | char_u *text; |
| 7205 | int row; |
| 7206 | int col; |
| 7207 | int attr; |
| 7208 | { |
| 7209 | screen_puts_len(text, -1, row, col, attr); |
| 7210 | } |
| 7211 | |
| 7212 | /* |
| 7213 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7214 | * a NUL. |
| 7215 | */ |
| 7216 | void |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7217 | screen_puts_len(text, textlen, row, col, attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7218 | char_u *text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7219 | int textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7220 | int row; |
| 7221 | int col; |
| 7222 | int attr; |
| 7223 | { |
| 7224 | unsigned off; |
| 7225 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7226 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7227 | int c; |
| 7228 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7229 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7230 | int mbyte_blen = 1; |
| 7231 | int mbyte_cells = 1; |
| 7232 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7233 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7234 | int clear_next_cell = FALSE; |
| 7235 | # ifdef FEAT_ARABIC |
| 7236 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7237 | int pc, nc, nc1; |
| 7238 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7239 | # endif |
| 7240 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7241 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7242 | int force_redraw_this; |
| 7243 | int force_redraw_next = FALSE; |
| 7244 | #endif |
| 7245 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7246 | |
| 7247 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7248 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7249 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7250 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7251 | #ifdef FEAT_MBYTE |
| 7252 | /* When drawing over the right halve of a double-wide char clear out the |
| 7253 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7254 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7255 | # ifdef FEAT_GUI |
| 7256 | && !gui.in_use |
| 7257 | # endif |
| 7258 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7259 | { |
| 7260 | ScreenLines[off - 1] = ' '; |
| 7261 | ScreenAttrs[off - 1] = 0; |
| 7262 | if (enc_utf8) |
| 7263 | { |
| 7264 | ScreenLinesUC[off - 1] = 0; |
| 7265 | ScreenLinesC[0][off - 1] = 0; |
| 7266 | } |
| 7267 | /* redraw the previous cell, make it empty */ |
| 7268 | screen_char(off - 1, row, col - 1); |
| 7269 | /* force the cell at "col" to be redrawn */ |
| 7270 | force_redraw_next = TRUE; |
| 7271 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7272 | #endif |
| 7273 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7274 | #ifdef FEAT_MBYTE |
| 7275 | max_off = LineOffset[row] + screen_Columns; |
| 7276 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7277 | while (col < screen_Columns |
| 7278 | && (len < 0 || (int)(ptr - text) < len) |
| 7279 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7280 | { |
| 7281 | c = *ptr; |
| 7282 | #ifdef FEAT_MBYTE |
| 7283 | /* check if this is the first byte of a multibyte */ |
| 7284 | if (has_mbyte) |
| 7285 | { |
| 7286 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7287 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7288 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7289 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7290 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7291 | mbyte_cells = 1; |
| 7292 | else if (enc_dbcs != 0) |
| 7293 | mbyte_cells = mbyte_blen; |
| 7294 | else /* enc_utf8 */ |
| 7295 | { |
| 7296 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7297 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7298 | (int)((text + len) - ptr)); |
| 7299 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7300 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7301 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7302 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7303 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7304 | if (u8c >= 0x10000) |
| 7305 | { |
| 7306 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7307 | if (attr == 0) |
| 7308 | attr = hl_attr(HLF_8); |
| 7309 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7310 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7311 | # ifdef FEAT_ARABIC |
| 7312 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7313 | { |
| 7314 | /* Do Arabic shaping. */ |
| 7315 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7316 | { |
| 7317 | /* Past end of string to be displayed. */ |
| 7318 | nc = NUL; |
| 7319 | nc1 = NUL; |
| 7320 | } |
| 7321 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7322 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7323 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7324 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7325 | nc1 = pcc[0]; |
| 7326 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7327 | pc = prev_c; |
| 7328 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7329 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7330 | } |
| 7331 | else |
| 7332 | prev_c = u8c; |
| 7333 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7334 | if (col + mbyte_cells > screen_Columns) |
| 7335 | { |
| 7336 | /* Only 1 cell left, but character requires 2 cells: |
| 7337 | * display a '>' in the last column to avoid wrapping. */ |
| 7338 | c = '>'; |
| 7339 | mbyte_cells = 1; |
| 7340 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7341 | } |
| 7342 | } |
| 7343 | #endif |
| 7344 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7345 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7346 | force_redraw_this = force_redraw_next; |
| 7347 | force_redraw_next = FALSE; |
| 7348 | #endif |
| 7349 | |
| 7350 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7351 | #ifdef FEAT_MBYTE |
| 7352 | || (mbyte_cells == 2 |
| 7353 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7354 | || (enc_dbcs == DBCS_JPNU |
| 7355 | && c == 0x8e |
| 7356 | && ScreenLines2[off] != ptr[1]) |
| 7357 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7358 | && (ScreenLinesUC[off] != |
| 7359 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7360 | || (ScreenLinesUC[off] != 0 |
| 7361 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7362 | #endif |
| 7363 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7364 | || exmode_active; |
| 7365 | |
| 7366 | if (need_redraw |
| 7367 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7368 | || force_redraw_this |
| 7369 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7370 | ) |
| 7371 | { |
| 7372 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7373 | /* The bold trick makes a single row of pixels appear in the next |
| 7374 | * character. When a bold character is removed, the next |
| 7375 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7376 | * and for some xterms. */ |
| 7377 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7378 | # ifdef FEAT_GUI |
| 7379 | gui.in_use |
| 7380 | # endif |
| 7381 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7382 | || |
| 7383 | # endif |
| 7384 | # ifdef UNIX |
| 7385 | term_is_xterm |
| 7386 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7387 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7388 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7389 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7390 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7391 | if (n > HL_ALL) |
| 7392 | n = syn_attr2attr(n); |
| 7393 | if (n & HL_BOLD) |
| 7394 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7395 | } |
| 7396 | #endif |
| 7397 | #ifdef FEAT_MBYTE |
| 7398 | /* When at the end of the text and overwriting a two-cell |
| 7399 | * character with a one-cell character, need to clear the next |
| 7400 | * cell. Also when overwriting the left halve of a two-cell char |
| 7401 | * with the right halve of a two-cell char. Do this only once |
| 7402 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7403 | if (clear_next_cell) |
| 7404 | clear_next_cell = FALSE; |
| 7405 | else if (has_mbyte |
| 7406 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7407 | : ptr + mbyte_blen >= text + len) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7408 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7409 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7410 | && (*mb_off2cells)(off, max_off) == 1 |
| 7411 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7412 | clear_next_cell = TRUE; |
| 7413 | |
| 7414 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7415 | * it confuses mb_off2cells(). */ |
| 7416 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7417 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7418 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7419 | && (*mb_off2cells)(off, max_off) == 1 |
| 7420 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7421 | ScreenLines[off + mbyte_blen] = 0; |
| 7422 | #endif |
| 7423 | ScreenLines[off] = c; |
| 7424 | ScreenAttrs[off] = attr; |
| 7425 | #ifdef FEAT_MBYTE |
| 7426 | if (enc_utf8) |
| 7427 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7428 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7429 | ScreenLinesUC[off] = 0; |
| 7430 | else |
| 7431 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7432 | int i; |
| 7433 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7434 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7435 | for (i = 0; i < Screen_mco; ++i) |
| 7436 | { |
| 7437 | ScreenLinesC[i][off] = u8cc[i]; |
| 7438 | if (u8cc[i] == 0) |
| 7439 | break; |
| 7440 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7441 | } |
| 7442 | if (mbyte_cells == 2) |
| 7443 | { |
| 7444 | ScreenLines[off + 1] = 0; |
| 7445 | ScreenAttrs[off + 1] = attr; |
| 7446 | } |
| 7447 | screen_char(off, row, col); |
| 7448 | } |
| 7449 | else if (mbyte_cells == 2) |
| 7450 | { |
| 7451 | ScreenLines[off + 1] = ptr[1]; |
| 7452 | ScreenAttrs[off + 1] = attr; |
| 7453 | screen_char_2(off, row, col); |
| 7454 | } |
| 7455 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7456 | { |
| 7457 | ScreenLines2[off] = ptr[1]; |
| 7458 | screen_char(off, row, col); |
| 7459 | } |
| 7460 | else |
| 7461 | #endif |
| 7462 | screen_char(off, row, col); |
| 7463 | } |
| 7464 | #ifdef FEAT_MBYTE |
| 7465 | if (has_mbyte) |
| 7466 | { |
| 7467 | off += mbyte_cells; |
| 7468 | col += mbyte_cells; |
| 7469 | ptr += mbyte_blen; |
| 7470 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7471 | { |
| 7472 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7473 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7474 | len = -1; |
| 7475 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7476 | } |
| 7477 | else |
| 7478 | #endif |
| 7479 | { |
| 7480 | ++off; |
| 7481 | ++col; |
| 7482 | ++ptr; |
| 7483 | } |
| 7484 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7485 | |
| 7486 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7487 | /* If we detected the next character needs to be redrawn, but the text |
| 7488 | * doesn't extend up to there, update the character here. */ |
| 7489 | if (force_redraw_next && col < screen_Columns) |
| 7490 | { |
| 7491 | # ifdef FEAT_MBYTE |
| 7492 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7493 | screen_char_2(off, row, col); |
| 7494 | else |
| 7495 | # endif |
| 7496 | screen_char(off, row, col); |
| 7497 | } |
| 7498 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7499 | } |
| 7500 | |
| 7501 | #ifdef FEAT_SEARCH_EXTRA |
| 7502 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7503 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7504 | */ |
| 7505 | static void |
| 7506 | start_search_hl() |
| 7507 | { |
| 7508 | if (p_hls && !no_hlsearch) |
| 7509 | { |
| 7510 | last_pat_prog(&search_hl.rm); |
| 7511 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7512 | # ifdef FEAT_RELTIME |
| 7513 | /* Set the time limit to 'redrawtime'. */ |
| 7514 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7515 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7516 | } |
| 7517 | } |
| 7518 | |
| 7519 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7520 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7521 | */ |
| 7522 | static void |
| 7523 | end_search_hl() |
| 7524 | { |
| 7525 | if (search_hl.rm.regprog != NULL) |
| 7526 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7527 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7528 | search_hl.rm.regprog = NULL; |
| 7529 | } |
| 7530 | } |
| 7531 | |
| 7532 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7533 | * Init for calling prepare_search_hl(). |
| 7534 | */ |
| 7535 | static void |
| 7536 | init_search_hl(wp) |
| 7537 | win_T *wp; |
| 7538 | { |
| 7539 | matchitem_T *cur; |
| 7540 | |
| 7541 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7542 | * match */ |
| 7543 | cur = wp->w_match_head; |
| 7544 | while (cur != NULL) |
| 7545 | { |
| 7546 | cur->hl.rm = cur->match; |
| 7547 | if (cur->hlg_id == 0) |
| 7548 | cur->hl.attr = 0; |
| 7549 | else |
| 7550 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7551 | cur->hl.buf = wp->w_buffer; |
| 7552 | cur->hl.lnum = 0; |
| 7553 | cur->hl.first_lnum = 0; |
| 7554 | # ifdef FEAT_RELTIME |
| 7555 | /* Set the time limit to 'redrawtime'. */ |
| 7556 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7557 | # endif |
| 7558 | cur = cur->next; |
| 7559 | } |
| 7560 | search_hl.buf = wp->w_buffer; |
| 7561 | search_hl.lnum = 0; |
| 7562 | search_hl.first_lnum = 0; |
| 7563 | /* time limit is set at the toplevel, for all windows */ |
| 7564 | } |
| 7565 | |
| 7566 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7567 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7568 | */ |
| 7569 | static void |
| 7570 | prepare_search_hl(wp, lnum) |
| 7571 | win_T *wp; |
| 7572 | linenr_T lnum; |
| 7573 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7574 | matchitem_T *cur; /* points to the match list */ |
| 7575 | match_T *shl; /* points to search_hl or a match */ |
| 7576 | int shl_flag; /* flag to indicate whether search_hl |
| 7577 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7578 | int pos_inprogress; /* marks that position match search is |
| 7579 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7580 | int n; |
| 7581 | |
| 7582 | /* |
| 7583 | * When using a multi-line pattern, start searching at the top |
| 7584 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7585 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7586 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7587 | cur = wp->w_match_head; |
| 7588 | shl_flag = FALSE; |
| 7589 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7590 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7591 | if (shl_flag == FALSE) |
| 7592 | { |
| 7593 | shl = &search_hl; |
| 7594 | shl_flag = TRUE; |
| 7595 | } |
| 7596 | else |
| 7597 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7598 | if (shl->rm.regprog != NULL |
| 7599 | && shl->lnum == 0 |
| 7600 | && re_multiline(shl->rm.regprog)) |
| 7601 | { |
| 7602 | if (shl->first_lnum == 0) |
| 7603 | { |
| 7604 | # ifdef FEAT_FOLDING |
| 7605 | for (shl->first_lnum = lnum; |
| 7606 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7607 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7608 | NULL, NULL, TRUE, NULL)) |
| 7609 | break; |
| 7610 | # else |
| 7611 | shl->first_lnum = wp->w_topline; |
| 7612 | # endif |
| 7613 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7614 | if (cur != NULL) |
| 7615 | cur->pos.cur = 0; |
| 7616 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7617 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7618 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7619 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7620 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7621 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, cur); |
| 7622 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7623 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7624 | if (shl->lnum != 0) |
| 7625 | { |
| 7626 | shl->first_lnum = shl->lnum |
| 7627 | + shl->rm.endpos[0].lnum |
| 7628 | - shl->rm.startpos[0].lnum; |
| 7629 | n = shl->rm.endpos[0].col; |
| 7630 | } |
| 7631 | else |
| 7632 | { |
| 7633 | ++shl->first_lnum; |
| 7634 | n = 0; |
| 7635 | } |
| 7636 | } |
| 7637 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7638 | if (shl != &search_hl && cur != NULL) |
| 7639 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7640 | } |
| 7641 | } |
| 7642 | |
| 7643 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7644 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7645 | * Uses shl->buf. |
| 7646 | * Sets shl->lnum and shl->rm contents. |
| 7647 | * Note: Assumes a previous match is always before "lnum", unless |
| 7648 | * shl->lnum is zero. |
| 7649 | * Careful: Any pointers for buffer lines will become invalid. |
| 7650 | */ |
| 7651 | static void |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7652 | next_search_hl(win, shl, lnum, mincol, cur) |
| 7653 | win_T *win; |
| 7654 | match_T *shl; /* points to search_hl or a match */ |
| 7655 | linenr_T lnum; |
| 7656 | colnr_T mincol; /* minimal column for a match */ |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7657 | matchitem_T *cur; /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7658 | { |
| 7659 | linenr_T l; |
| 7660 | colnr_T matchcol; |
| 7661 | long nmatched; |
| 7662 | |
| 7663 | if (shl->lnum != 0) |
| 7664 | { |
| 7665 | /* Check for three situations: |
| 7666 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7667 | * 2. If the previous match includes "mincol", use it. |
| 7668 | * 3. Continue after the previous match. |
| 7669 | */ |
| 7670 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7671 | if (lnum > l) |
| 7672 | shl->lnum = 0; |
| 7673 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7674 | return; |
| 7675 | } |
| 7676 | |
| 7677 | /* |
| 7678 | * Repeat searching for a match until one is found that includes "mincol" |
| 7679 | * or none is found in this line. |
| 7680 | */ |
| 7681 | called_emsg = FALSE; |
| 7682 | for (;;) |
| 7683 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7684 | #ifdef FEAT_RELTIME |
| 7685 | /* Stop searching after passing the time limit. */ |
| 7686 | if (profile_passed_limit(&(shl->tm))) |
| 7687 | { |
| 7688 | shl->lnum = 0; /* no match found in time */ |
| 7689 | break; |
| 7690 | } |
| 7691 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7692 | /* Three situations: |
| 7693 | * 1. No useful previous match: search from start of line. |
| 7694 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7695 | * Break the loop if this is beyond the end of the line. |
| 7696 | * 3. Vi compatible searching: continue at end of previous match. |
| 7697 | */ |
| 7698 | if (shl->lnum == 0) |
| 7699 | matchcol = 0; |
| 7700 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7701 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7702 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7703 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7704 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7705 | |
| 7706 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7707 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7708 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7709 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7710 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7711 | shl->lnum = 0; |
| 7712 | break; |
| 7713 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7714 | #ifdef FEAT_MBYTE |
| 7715 | if (has_mbyte) |
| 7716 | matchcol += mb_ptr2len(ml); |
| 7717 | else |
| 7718 | #endif |
| 7719 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7720 | } |
| 7721 | else |
| 7722 | matchcol = shl->rm.endpos[0].col; |
| 7723 | |
| 7724 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7725 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7726 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7727 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7728 | * cur->match. */ |
| 7729 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7730 | && shl == &cur->hl |
| 7731 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7732 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7733 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7734 | matchcol, |
| 7735 | #ifdef FEAT_RELTIME |
| 7736 | &(shl->tm) |
| 7737 | #else |
| 7738 | NULL |
| 7739 | #endif |
| 7740 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7741 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7742 | if (regprog_is_copy) |
| 7743 | cur->match.regprog = cur->hl.rm.regprog; |
| 7744 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7745 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7746 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7747 | /* Error while handling regexp: stop using this regexp. */ |
| 7748 | if (shl == &search_hl) |
| 7749 | { |
| 7750 | /* don't free regprog in the match list, it's a copy */ |
| 7751 | vim_regfree(shl->rm.regprog); |
| 7752 | SET_NO_HLSEARCH(TRUE); |
| 7753 | } |
| 7754 | shl->rm.regprog = NULL; |
| 7755 | shl->lnum = 0; |
| 7756 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7757 | message */ |
| 7758 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7759 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7760 | } |
| 7761 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7762 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7763 | else |
| 7764 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7765 | if (nmatched == 0) |
| 7766 | { |
| 7767 | shl->lnum = 0; /* no match found */ |
| 7768 | break; |
| 7769 | } |
| 7770 | if (shl->rm.startpos[0].lnum > 0 |
| 7771 | || shl->rm.startpos[0].col >= mincol |
| 7772 | || nmatched > 1 |
| 7773 | || shl->rm.endpos[0].col > mincol) |
| 7774 | { |
| 7775 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7776 | break; /* useful match found */ |
| 7777 | } |
| 7778 | } |
| 7779 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7780 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7781 | static int |
| 7782 | next_search_hl_pos(shl, lnum, posmatch, mincol) |
| 7783 | match_T *shl; /* points to a match */ |
| 7784 | linenr_T lnum; |
| 7785 | posmatch_T *posmatch; /* match positions */ |
| 7786 | colnr_T mincol; /* minimal column for a match */ |
| 7787 | { |
| 7788 | int i; |
Bram Moolenaar | b6da44a | 2014-06-25 18:15:22 +0200 | [diff] [blame] | 7789 | int bot = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7790 | |
| 7791 | shl->lnum = 0; |
| 7792 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7793 | { |
| 7794 | if (posmatch->pos[i].lnum == 0) |
| 7795 | break; |
| 7796 | if (posmatch->pos[i].col < mincol) |
| 7797 | continue; |
| 7798 | if (posmatch->pos[i].lnum == lnum) |
| 7799 | { |
| 7800 | if (shl->lnum == lnum) |
| 7801 | { |
| 7802 | /* partially sort positions by column numbers |
| 7803 | * on the same line */ |
| 7804 | if (posmatch->pos[i].col < posmatch->pos[bot].col) |
| 7805 | { |
| 7806 | llpos_T tmp = posmatch->pos[i]; |
| 7807 | |
| 7808 | posmatch->pos[i] = posmatch->pos[bot]; |
| 7809 | posmatch->pos[bot] = tmp; |
| 7810 | } |
| 7811 | } |
| 7812 | else |
| 7813 | { |
| 7814 | bot = i; |
| 7815 | shl->lnum = lnum; |
| 7816 | } |
| 7817 | } |
| 7818 | } |
| 7819 | posmatch->cur = 0; |
Bram Moolenaar | bd8539a | 2015-08-11 18:53:03 +0200 | [diff] [blame] | 7820 | if (shl->lnum == lnum && bot >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7821 | { |
| 7822 | colnr_T start = posmatch->pos[bot].col == 0 |
| 7823 | ? 0 : posmatch->pos[bot].col - 1; |
| 7824 | colnr_T end = posmatch->pos[bot].col == 0 |
| 7825 | ? MAXCOL : start + posmatch->pos[bot].len; |
| 7826 | |
| 7827 | shl->rm.startpos[0].lnum = 0; |
| 7828 | shl->rm.startpos[0].col = start; |
| 7829 | shl->rm.endpos[0].lnum = 0; |
| 7830 | shl->rm.endpos[0].col = end; |
| 7831 | posmatch->cur = bot + 1; |
| 7832 | return TRUE; |
| 7833 | } |
| 7834 | return FALSE; |
| 7835 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7836 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7837 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7838 | static void |
| 7839 | screen_start_highlight(attr) |
| 7840 | int attr; |
| 7841 | { |
| 7842 | attrentry_T *aep = NULL; |
| 7843 | |
| 7844 | screen_attr = attr; |
| 7845 | if (full_screen |
| 7846 | #ifdef WIN3264 |
| 7847 | && termcap_active |
| 7848 | #endif |
| 7849 | ) |
| 7850 | { |
| 7851 | #ifdef FEAT_GUI |
| 7852 | if (gui.in_use) |
| 7853 | { |
| 7854 | char buf[20]; |
| 7855 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7856 | /* The GUI handles this internally. */ |
| 7857 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7858 | OUT_STR(buf); |
| 7859 | } |
| 7860 | else |
| 7861 | #endif |
| 7862 | { |
| 7863 | if (attr > HL_ALL) /* special HL attr. */ |
| 7864 | { |
| 7865 | if (t_colors > 1) |
| 7866 | aep = syn_cterm_attr2entry(attr); |
| 7867 | else |
| 7868 | aep = syn_term_attr2entry(attr); |
| 7869 | if (aep == NULL) /* did ":syntax clear" */ |
| 7870 | attr = 0; |
| 7871 | else |
| 7872 | attr = aep->ae_attr; |
| 7873 | } |
| 7874 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7875 | out_str(T_MD); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7876 | else if (aep != NULL && t_colors > 1 && aep->ae_u.cterm.fg_color |
| 7877 | && cterm_normal_fg_bold) |
| 7878 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7879 | * has a FG color defined, clear BOLD. */ |
| 7880 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7881 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7882 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7883 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7884 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7885 | out_str(T_US); |
| 7886 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7887 | out_str(T_CZH); |
| 7888 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7889 | out_str(T_MR); |
| 7890 | |
| 7891 | /* |
| 7892 | * Output the color or start string after bold etc., in case the |
| 7893 | * bold etc. override the color setting. |
| 7894 | */ |
| 7895 | if (aep != NULL) |
| 7896 | { |
| 7897 | if (t_colors > 1) |
| 7898 | { |
| 7899 | if (aep->ae_u.cterm.fg_color) |
| 7900 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7901 | if (aep->ae_u.cterm.bg_color) |
| 7902 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7903 | } |
| 7904 | else |
| 7905 | { |
| 7906 | if (aep->ae_u.term.start != NULL) |
| 7907 | out_str(aep->ae_u.term.start); |
| 7908 | } |
| 7909 | } |
| 7910 | } |
| 7911 | } |
| 7912 | } |
| 7913 | |
| 7914 | void |
| 7915 | screen_stop_highlight() |
| 7916 | { |
| 7917 | int do_ME = FALSE; /* output T_ME code */ |
| 7918 | |
| 7919 | if (screen_attr != 0 |
| 7920 | #ifdef WIN3264 |
| 7921 | && termcap_active |
| 7922 | #endif |
| 7923 | ) |
| 7924 | { |
| 7925 | #ifdef FEAT_GUI |
| 7926 | if (gui.in_use) |
| 7927 | { |
| 7928 | char buf[20]; |
| 7929 | |
| 7930 | /* use internal GUI code */ |
| 7931 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7932 | OUT_STR(buf); |
| 7933 | } |
| 7934 | else |
| 7935 | #endif |
| 7936 | { |
| 7937 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7938 | { |
| 7939 | attrentry_T *aep; |
| 7940 | |
| 7941 | if (t_colors > 1) |
| 7942 | { |
| 7943 | /* |
| 7944 | * Assume that t_me restores the original colors! |
| 7945 | */ |
| 7946 | aep = syn_cterm_attr2entry(screen_attr); |
| 7947 | if (aep != NULL && (aep->ae_u.cterm.fg_color |
| 7948 | || aep->ae_u.cterm.bg_color)) |
| 7949 | do_ME = TRUE; |
| 7950 | } |
| 7951 | else |
| 7952 | { |
| 7953 | aep = syn_term_attr2entry(screen_attr); |
| 7954 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7955 | { |
| 7956 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7957 | do_ME = TRUE; |
| 7958 | else |
| 7959 | out_str(aep->ae_u.term.stop); |
| 7960 | } |
| 7961 | } |
| 7962 | if (aep == NULL) /* did ":syntax clear" */ |
| 7963 | screen_attr = 0; |
| 7964 | else |
| 7965 | screen_attr = aep->ae_attr; |
| 7966 | } |
| 7967 | |
| 7968 | /* |
| 7969 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 7970 | * same sequence several times. |
| 7971 | */ |
| 7972 | if (screen_attr & HL_STANDOUT) |
| 7973 | { |
| 7974 | if (STRCMP(T_SE, T_ME) == 0) |
| 7975 | do_ME = TRUE; |
| 7976 | else |
| 7977 | out_str(T_SE); |
| 7978 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7979 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7980 | { |
| 7981 | if (STRCMP(T_UE, T_ME) == 0) |
| 7982 | do_ME = TRUE; |
| 7983 | else |
| 7984 | out_str(T_UE); |
| 7985 | } |
| 7986 | if (screen_attr & HL_ITALIC) |
| 7987 | { |
| 7988 | if (STRCMP(T_CZR, T_ME) == 0) |
| 7989 | do_ME = TRUE; |
| 7990 | else |
| 7991 | out_str(T_CZR); |
| 7992 | } |
| 7993 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 7994 | out_str(T_ME); |
| 7995 | |
| 7996 | if (t_colors > 1) |
| 7997 | { |
| 7998 | /* set Normal cterm colors */ |
| 7999 | if (cterm_normal_fg_color != 0) |
| 8000 | term_fg_color(cterm_normal_fg_color - 1); |
| 8001 | if (cterm_normal_bg_color != 0) |
| 8002 | term_bg_color(cterm_normal_bg_color - 1); |
| 8003 | if (cterm_normal_fg_bold) |
| 8004 | out_str(T_MD); |
| 8005 | } |
| 8006 | } |
| 8007 | } |
| 8008 | screen_attr = 0; |
| 8009 | } |
| 8010 | |
| 8011 | /* |
| 8012 | * Reset the colors for a cterm. Used when leaving Vim. |
| 8013 | * The machine specific code may override this again. |
| 8014 | */ |
| 8015 | void |
| 8016 | reset_cterm_colors() |
| 8017 | { |
| 8018 | if (t_colors > 1) |
| 8019 | { |
| 8020 | /* set Normal cterm colors */ |
| 8021 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
| 8022 | { |
| 8023 | out_str(T_OP); |
| 8024 | screen_attr = -1; |
| 8025 | } |
| 8026 | if (cterm_normal_fg_bold) |
| 8027 | { |
| 8028 | out_str(T_ME); |
| 8029 | screen_attr = -1; |
| 8030 | } |
| 8031 | } |
| 8032 | } |
| 8033 | |
| 8034 | /* |
| 8035 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 8036 | * using the attributes from ScreenAttrs["off"]. |
| 8037 | */ |
| 8038 | static void |
| 8039 | screen_char(off, row, col) |
| 8040 | unsigned off; |
| 8041 | int row; |
| 8042 | int col; |
| 8043 | { |
| 8044 | int attr; |
| 8045 | |
| 8046 | /* Check for illegal values, just in case (could happen just after |
| 8047 | * resizing). */ |
| 8048 | if (row >= screen_Rows || col >= screen_Columns) |
| 8049 | return; |
| 8050 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 8051 | /* Outputting a character in the last cell on the screen may scroll the |
| 8052 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 8053 | * mark the character invalid (update it when scrolled up). */ |
| 8054 | if (*T_XN == NUL |
| 8055 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8056 | #ifdef FEAT_RIGHTLEFT |
| 8057 | /* account for first command-line character in rightleft mode */ |
| 8058 | && !cmdmsg_rl |
| 8059 | #endif |
| 8060 | ) |
| 8061 | { |
| 8062 | ScreenAttrs[off] = (sattr_T)-1; |
| 8063 | return; |
| 8064 | } |
| 8065 | |
| 8066 | /* |
| 8067 | * Stop highlighting first, so it's easier to move the cursor. |
| 8068 | */ |
| 8069 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) |
| 8070 | if (screen_char_attr != 0) |
| 8071 | attr = screen_char_attr; |
| 8072 | else |
| 8073 | #endif |
| 8074 | attr = ScreenAttrs[off]; |
| 8075 | if (screen_attr != attr) |
| 8076 | screen_stop_highlight(); |
| 8077 | |
| 8078 | windgoto(row, col); |
| 8079 | |
| 8080 | if (screen_attr != attr) |
| 8081 | screen_start_highlight(attr); |
| 8082 | |
| 8083 | #ifdef FEAT_MBYTE |
| 8084 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8085 | { |
| 8086 | char_u buf[MB_MAXBYTES + 1]; |
| 8087 | |
| 8088 | /* Convert UTF-8 character to bytes and write it. */ |
| 8089 | |
| 8090 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8091 | |
| 8092 | out_str(buf); |
| 8093 | if (utf_char2cells(ScreenLinesUC[off]) > 1) |
| 8094 | ++screen_cur_col; |
| 8095 | } |
| 8096 | else |
| 8097 | #endif |
| 8098 | { |
| 8099 | #ifdef FEAT_MBYTE |
| 8100 | out_flush_check(); |
| 8101 | #endif |
| 8102 | out_char(ScreenLines[off]); |
| 8103 | #ifdef FEAT_MBYTE |
| 8104 | /* double-byte character in single-width cell */ |
| 8105 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8106 | out_char(ScreenLines2[off]); |
| 8107 | #endif |
| 8108 | } |
| 8109 | |
| 8110 | screen_cur_col++; |
| 8111 | } |
| 8112 | |
| 8113 | #ifdef FEAT_MBYTE |
| 8114 | |
| 8115 | /* |
| 8116 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8117 | * on the screen at position 'row' and 'col'. |
| 8118 | * The attributes of the first byte is used for all. This is required to |
| 8119 | * output the two bytes of a double-byte character with nothing in between. |
| 8120 | */ |
| 8121 | static void |
| 8122 | screen_char_2(off, row, col) |
| 8123 | unsigned off; |
| 8124 | int row; |
| 8125 | int col; |
| 8126 | { |
| 8127 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8128 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8129 | return; |
| 8130 | |
| 8131 | /* Outputting the last character on the screen may scrollup the screen. |
| 8132 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8133 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8134 | { |
| 8135 | ScreenAttrs[off] = (sattr_T)-1; |
| 8136 | return; |
| 8137 | } |
| 8138 | |
| 8139 | /* Output the first byte normally (positions the cursor), then write the |
| 8140 | * second byte directly. */ |
| 8141 | screen_char(off, row, col); |
| 8142 | out_char(ScreenLines[off + 1]); |
| 8143 | ++screen_cur_col; |
| 8144 | } |
| 8145 | #endif |
| 8146 | |
| 8147 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_VERTSPLIT) || defined(PROTO) |
| 8148 | /* |
| 8149 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8150 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8151 | */ |
| 8152 | void |
| 8153 | screen_draw_rectangle(row, col, height, width, invert) |
| 8154 | int row; |
| 8155 | int col; |
| 8156 | int height; |
| 8157 | int width; |
| 8158 | int invert; |
| 8159 | { |
| 8160 | int r, c; |
| 8161 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8162 | #ifdef FEAT_MBYTE |
| 8163 | int max_off; |
| 8164 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8165 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8166 | /* Can't use ScreenLines unless initialized */ |
| 8167 | if (ScreenLines == NULL) |
| 8168 | return; |
| 8169 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8170 | if (invert) |
| 8171 | screen_char_attr = HL_INVERSE; |
| 8172 | for (r = row; r < row + height; ++r) |
| 8173 | { |
| 8174 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8175 | #ifdef FEAT_MBYTE |
| 8176 | max_off = off + screen_Columns; |
| 8177 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8178 | for (c = col; c < col + width; ++c) |
| 8179 | { |
| 8180 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8181 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8182 | { |
| 8183 | screen_char_2(off + c, r, c); |
| 8184 | ++c; |
| 8185 | } |
| 8186 | else |
| 8187 | #endif |
| 8188 | { |
| 8189 | screen_char(off + c, r, c); |
| 8190 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8191 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8192 | ++c; |
| 8193 | #endif |
| 8194 | } |
| 8195 | } |
| 8196 | } |
| 8197 | screen_char_attr = 0; |
| 8198 | } |
| 8199 | #endif |
| 8200 | |
| 8201 | #ifdef FEAT_VERTSPLIT |
| 8202 | /* |
| 8203 | * Redraw the characters for a vertically split window. |
| 8204 | */ |
| 8205 | static void |
| 8206 | redraw_block(row, end, wp) |
| 8207 | int row; |
| 8208 | int end; |
| 8209 | win_T *wp; |
| 8210 | { |
| 8211 | int col; |
| 8212 | int width; |
| 8213 | |
| 8214 | # ifdef FEAT_CLIPBOARD |
| 8215 | clip_may_clear_selection(row, end - 1); |
| 8216 | # endif |
| 8217 | |
| 8218 | if (wp == NULL) |
| 8219 | { |
| 8220 | col = 0; |
| 8221 | width = Columns; |
| 8222 | } |
| 8223 | else |
| 8224 | { |
| 8225 | col = wp->w_wincol; |
| 8226 | width = wp->w_width; |
| 8227 | } |
| 8228 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8229 | } |
| 8230 | #endif |
| 8231 | |
| 8232 | /* |
| 8233 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8234 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8235 | * Use attributes 'attr'. |
| 8236 | */ |
| 8237 | void |
| 8238 | screen_fill(start_row, end_row, start_col, end_col, c1, c2, attr) |
| 8239 | int start_row, end_row; |
| 8240 | int start_col, end_col; |
| 8241 | int c1, c2; |
| 8242 | int attr; |
| 8243 | { |
| 8244 | int row; |
| 8245 | int col; |
| 8246 | int off; |
| 8247 | int end_off; |
| 8248 | int did_delete; |
| 8249 | int c; |
| 8250 | int norm_term; |
| 8251 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8252 | int force_next = FALSE; |
| 8253 | #endif |
| 8254 | |
| 8255 | if (end_row > screen_Rows) /* safety check */ |
| 8256 | end_row = screen_Rows; |
| 8257 | if (end_col > screen_Columns) /* safety check */ |
| 8258 | end_col = screen_Columns; |
| 8259 | if (ScreenLines == NULL |
| 8260 | || start_row >= end_row |
| 8261 | || start_col >= end_col) /* nothing to do */ |
| 8262 | return; |
| 8263 | |
| 8264 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8265 | norm_term = ( |
| 8266 | #ifdef FEAT_GUI |
| 8267 | !gui.in_use && |
| 8268 | #endif |
| 8269 | t_colors <= 1); |
| 8270 | for (row = start_row; row < end_row; ++row) |
| 8271 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8272 | #ifdef FEAT_MBYTE |
| 8273 | if (has_mbyte |
| 8274 | # ifdef FEAT_GUI |
| 8275 | && !gui.in_use |
| 8276 | # endif |
| 8277 | ) |
| 8278 | { |
| 8279 | /* When drawing over the right halve of a double-wide char clear |
| 8280 | * out the left halve. When drawing over the left halve of a |
| 8281 | * double wide-char clear out the right halve. Only needed in a |
| 8282 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8283 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8284 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8285 | if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8286 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8287 | } |
| 8288 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8289 | /* |
| 8290 | * Try to use delete-line termcap code, when no attributes or in a |
| 8291 | * "normal" terminal, where a bold/italic space is just a |
| 8292 | * space. |
| 8293 | */ |
| 8294 | did_delete = FALSE; |
| 8295 | if (c2 == ' ' |
| 8296 | && end_col == Columns |
| 8297 | && can_clear(T_CE) |
| 8298 | && (attr == 0 |
| 8299 | || (norm_term |
| 8300 | && attr <= HL_ALL |
| 8301 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8302 | { |
| 8303 | /* |
| 8304 | * check if we really need to clear something |
| 8305 | */ |
| 8306 | col = start_col; |
| 8307 | if (c1 != ' ') /* don't clear first char */ |
| 8308 | ++col; |
| 8309 | |
| 8310 | off = LineOffset[row] + col; |
| 8311 | end_off = LineOffset[row] + end_col; |
| 8312 | |
| 8313 | /* skip blanks (used often, keep it fast!) */ |
| 8314 | #ifdef FEAT_MBYTE |
| 8315 | if (enc_utf8) |
| 8316 | while (off < end_off && ScreenLines[off] == ' ' |
| 8317 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8318 | ++off; |
| 8319 | else |
| 8320 | #endif |
| 8321 | while (off < end_off && ScreenLines[off] == ' ' |
| 8322 | && ScreenAttrs[off] == 0) |
| 8323 | ++off; |
| 8324 | if (off < end_off) /* something to be cleared */ |
| 8325 | { |
| 8326 | col = off - LineOffset[row]; |
| 8327 | screen_stop_highlight(); |
| 8328 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8329 | out_str(T_CE); |
| 8330 | screen_start(); /* don't know where cursor is now */ |
| 8331 | col = end_col - col; |
| 8332 | while (col--) /* clear chars in ScreenLines */ |
| 8333 | { |
| 8334 | ScreenLines[off] = ' '; |
| 8335 | #ifdef FEAT_MBYTE |
| 8336 | if (enc_utf8) |
| 8337 | ScreenLinesUC[off] = 0; |
| 8338 | #endif |
| 8339 | ScreenAttrs[off] = 0; |
| 8340 | ++off; |
| 8341 | } |
| 8342 | } |
| 8343 | did_delete = TRUE; /* the chars are cleared now */ |
| 8344 | } |
| 8345 | |
| 8346 | off = LineOffset[row] + start_col; |
| 8347 | c = c1; |
| 8348 | for (col = start_col; col < end_col; ++col) |
| 8349 | { |
| 8350 | if (ScreenLines[off] != c |
| 8351 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8352 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8353 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8354 | #endif |
| 8355 | || ScreenAttrs[off] != attr |
| 8356 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8357 | || force_next |
| 8358 | #endif |
| 8359 | ) |
| 8360 | { |
| 8361 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8362 | /* The bold trick may make a single row of pixels appear in |
| 8363 | * the next character. When a bold character is removed, the |
| 8364 | * next character should be redrawn too. This happens for our |
| 8365 | * own GUI and for some xterms. */ |
| 8366 | if ( |
| 8367 | # ifdef FEAT_GUI |
| 8368 | gui.in_use |
| 8369 | # endif |
| 8370 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8371 | || |
| 8372 | # endif |
| 8373 | # ifdef UNIX |
| 8374 | term_is_xterm |
| 8375 | # endif |
| 8376 | ) |
| 8377 | { |
| 8378 | if (ScreenLines[off] != ' ' |
| 8379 | && (ScreenAttrs[off] > HL_ALL |
| 8380 | || ScreenAttrs[off] & HL_BOLD)) |
| 8381 | force_next = TRUE; |
| 8382 | else |
| 8383 | force_next = FALSE; |
| 8384 | } |
| 8385 | #endif |
| 8386 | ScreenLines[off] = c; |
| 8387 | #ifdef FEAT_MBYTE |
| 8388 | if (enc_utf8) |
| 8389 | { |
| 8390 | if (c >= 0x80) |
| 8391 | { |
| 8392 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8393 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8394 | } |
| 8395 | else |
| 8396 | ScreenLinesUC[off] = 0; |
| 8397 | } |
| 8398 | #endif |
| 8399 | ScreenAttrs[off] = attr; |
| 8400 | if (!did_delete || c != ' ') |
| 8401 | screen_char(off, row, col); |
| 8402 | } |
| 8403 | ++off; |
| 8404 | if (col == start_col) |
| 8405 | { |
| 8406 | if (did_delete) |
| 8407 | break; |
| 8408 | c = c2; |
| 8409 | } |
| 8410 | } |
| 8411 | if (end_col == Columns) |
| 8412 | LineWraps[row] = FALSE; |
| 8413 | if (row == Rows - 1) /* overwritten the command line */ |
| 8414 | { |
| 8415 | redraw_cmdline = TRUE; |
| 8416 | if (c1 == ' ' && c2 == ' ') |
| 8417 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8418 | if (start_col == 0) |
| 8419 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8420 | } |
| 8421 | } |
| 8422 | } |
| 8423 | |
| 8424 | /* |
| 8425 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8426 | * screen or the command line. |
| 8427 | */ |
| 8428 | void |
| 8429 | check_for_delay(check_msg_scroll) |
| 8430 | int check_msg_scroll; |
| 8431 | { |
| 8432 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8433 | && !did_wait_return |
| 8434 | && emsg_silent == 0) |
| 8435 | { |
| 8436 | out_flush(); |
| 8437 | ui_delay(1000L, TRUE); |
| 8438 | emsg_on_display = FALSE; |
| 8439 | if (check_msg_scroll) |
| 8440 | msg_scroll = FALSE; |
| 8441 | } |
| 8442 | } |
| 8443 | |
| 8444 | /* |
| 8445 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8446 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8447 | * Returns TRUE if there is a valid screen to write to. |
| 8448 | * Returns FALSE when starting up and screen not initialized yet. |
| 8449 | */ |
| 8450 | int |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8451 | screen_valid(doclear) |
| 8452 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8453 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8454 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8455 | return (ScreenLines != NULL); |
| 8456 | } |
| 8457 | |
| 8458 | /* |
| 8459 | * Resize the shell to Rows and Columns. |
| 8460 | * Allocate ScreenLines[] and associated items. |
| 8461 | * |
| 8462 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8463 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8464 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8465 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8466 | * final size of the shell is needed. |
| 8467 | */ |
| 8468 | void |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8469 | screenalloc(doclear) |
| 8470 | int doclear; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8471 | { |
| 8472 | int new_row, old_row; |
| 8473 | #ifdef FEAT_GUI |
| 8474 | int old_Rows; |
| 8475 | #endif |
| 8476 | win_T *wp; |
| 8477 | int outofmem = FALSE; |
| 8478 | int len; |
| 8479 | schar_T *new_ScreenLines; |
| 8480 | #ifdef FEAT_MBYTE |
| 8481 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8482 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8483 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8484 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8485 | #endif |
| 8486 | sattr_T *new_ScreenAttrs; |
| 8487 | unsigned *new_LineOffset; |
| 8488 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8489 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8490 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8491 | tabpage_T *tp; |
| 8492 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8493 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8494 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8495 | #ifdef FEAT_AUTOCMD |
| 8496 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8497 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8498 | retry: |
| 8499 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8500 | /* |
| 8501 | * Allocation of the screen buffers is done only when the size changes and |
| 8502 | * when Rows and Columns have been set and we have started doing full |
| 8503 | * screen stuff. |
| 8504 | */ |
| 8505 | if ((ScreenLines != NULL |
| 8506 | && Rows == screen_Rows |
| 8507 | && Columns == screen_Columns |
| 8508 | #ifdef FEAT_MBYTE |
| 8509 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8510 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8511 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8512 | #endif |
| 8513 | ) |
| 8514 | || Rows == 0 |
| 8515 | || Columns == 0 |
| 8516 | || (!full_screen && ScreenLines == NULL)) |
| 8517 | return; |
| 8518 | |
| 8519 | /* |
| 8520 | * It's possible that we produce an out-of-memory message below, which |
| 8521 | * will cause this function to be called again. To break the loop, just |
| 8522 | * return here. |
| 8523 | */ |
| 8524 | if (entered) |
| 8525 | return; |
| 8526 | entered = TRUE; |
| 8527 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8528 | /* |
| 8529 | * Note that the window sizes are updated before reallocating the arrays, |
| 8530 | * thus we must not redraw here! |
| 8531 | */ |
| 8532 | ++RedrawingDisabled; |
| 8533 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8534 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8535 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8536 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8537 | |
| 8538 | /* |
| 8539 | * We're changing the size of the screen. |
| 8540 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8541 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8542 | * lines (unless the screen is going to be cleared). |
| 8543 | * - Free the old arrays. |
| 8544 | * |
| 8545 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8546 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8547 | * size is wrong. |
| 8548 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8549 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8550 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8551 | #ifdef FEAT_AUTOCMD |
| 8552 | if (aucmd_win != NULL) |
| 8553 | win_free_lsize(aucmd_win); |
| 8554 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8555 | |
| 8556 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8557 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8558 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8559 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8560 | if (enc_utf8) |
| 8561 | { |
| 8562 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8563 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8564 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8565 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8566 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8567 | } |
| 8568 | if (enc_dbcs == DBCS_JPNU) |
| 8569 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8570 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8571 | #endif |
| 8572 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8573 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8574 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8575 | Rows * sizeof(unsigned)), FALSE); |
| 8576 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8577 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8578 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8579 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8580 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8581 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8582 | { |
| 8583 | if (win_alloc_lines(wp) == FAIL) |
| 8584 | { |
| 8585 | outofmem = TRUE; |
| 8586 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8587 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8588 | #endif |
| 8589 | } |
| 8590 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8591 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8592 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8593 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8594 | outofmem = TRUE; |
| 8595 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8596 | #ifdef FEAT_WINDOWS |
| 8597 | give_up: |
| 8598 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8599 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8600 | #ifdef FEAT_MBYTE |
| 8601 | for (i = 0; i < p_mco; ++i) |
| 8602 | if (new_ScreenLinesC[i] == NULL) |
| 8603 | break; |
| 8604 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8605 | if (new_ScreenLines == NULL |
| 8606 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8607 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8608 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8609 | #endif |
| 8610 | || new_ScreenAttrs == NULL |
| 8611 | || new_LineOffset == NULL |
| 8612 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8613 | #ifdef FEAT_WINDOWS |
| 8614 | || new_TabPageIdxs == NULL |
| 8615 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8616 | || outofmem) |
| 8617 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8618 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8619 | { |
| 8620 | /* guess the size */ |
| 8621 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8622 | |
| 8623 | /* Remember we did this to avoid getting outofmem messages over |
| 8624 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8625 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8626 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8627 | vim_free(new_ScreenLines); |
| 8628 | new_ScreenLines = NULL; |
| 8629 | #ifdef FEAT_MBYTE |
| 8630 | vim_free(new_ScreenLinesUC); |
| 8631 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8632 | for (i = 0; i < p_mco; ++i) |
| 8633 | { |
| 8634 | vim_free(new_ScreenLinesC[i]); |
| 8635 | new_ScreenLinesC[i] = NULL; |
| 8636 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8637 | vim_free(new_ScreenLines2); |
| 8638 | new_ScreenLines2 = NULL; |
| 8639 | #endif |
| 8640 | vim_free(new_ScreenAttrs); |
| 8641 | new_ScreenAttrs = NULL; |
| 8642 | vim_free(new_LineOffset); |
| 8643 | new_LineOffset = NULL; |
| 8644 | vim_free(new_LineWraps); |
| 8645 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8646 | #ifdef FEAT_WINDOWS |
| 8647 | vim_free(new_TabPageIdxs); |
| 8648 | new_TabPageIdxs = NULL; |
| 8649 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8650 | } |
| 8651 | else |
| 8652 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8653 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8654 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8655 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8656 | { |
| 8657 | new_LineOffset[new_row] = new_row * Columns; |
| 8658 | new_LineWraps[new_row] = FALSE; |
| 8659 | |
| 8660 | /* |
| 8661 | * If the screen is not going to be cleared, copy as much as |
| 8662 | * possible from the old screen to the new one and clear the rest |
| 8663 | * (used when resizing the window at the "--more--" prompt or when |
| 8664 | * executing an external command, for the GUI). |
| 8665 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8666 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8667 | { |
| 8668 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8669 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8670 | #ifdef FEAT_MBYTE |
| 8671 | if (enc_utf8) |
| 8672 | { |
| 8673 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8674 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8675 | for (i = 0; i < p_mco; ++i) |
| 8676 | (void)vim_memset(new_ScreenLinesC[i] |
| 8677 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8678 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8679 | } |
| 8680 | if (enc_dbcs == DBCS_JPNU) |
| 8681 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8682 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8683 | #endif |
| 8684 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8685 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8686 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8687 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8688 | { |
| 8689 | if (screen_Columns < Columns) |
| 8690 | len = screen_Columns; |
| 8691 | else |
| 8692 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8693 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8694 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8695 | * may be invalid now. Also when p_mco changes. */ |
| 8696 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8697 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8698 | #endif |
| 8699 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8700 | ScreenLines + LineOffset[old_row], |
| 8701 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8702 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8703 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8704 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8705 | { |
| 8706 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8707 | ScreenLinesUC + LineOffset[old_row], |
| 8708 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8709 | for (i = 0; i < p_mco; ++i) |
| 8710 | mch_memmove(new_ScreenLinesC[i] |
| 8711 | + new_LineOffset[new_row], |
| 8712 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8713 | (size_t)len * sizeof(u8char_T)); |
| 8714 | } |
| 8715 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8716 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8717 | ScreenLines2 + LineOffset[old_row], |
| 8718 | (size_t)len * sizeof(schar_T)); |
| 8719 | #endif |
| 8720 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8721 | ScreenAttrs + LineOffset[old_row], |
| 8722 | (size_t)len * sizeof(sattr_T)); |
| 8723 | } |
| 8724 | } |
| 8725 | } |
| 8726 | /* Use the last line of the screen for the current line. */ |
| 8727 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8728 | } |
| 8729 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8730 | free_screenlines(); |
| 8731 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8732 | ScreenLines = new_ScreenLines; |
| 8733 | #ifdef FEAT_MBYTE |
| 8734 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8735 | for (i = 0; i < p_mco; ++i) |
| 8736 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8737 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8738 | ScreenLines2 = new_ScreenLines2; |
| 8739 | #endif |
| 8740 | ScreenAttrs = new_ScreenAttrs; |
| 8741 | LineOffset = new_LineOffset; |
| 8742 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8743 | #ifdef FEAT_WINDOWS |
| 8744 | TabPageIdxs = new_TabPageIdxs; |
| 8745 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8746 | |
| 8747 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8748 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8749 | #ifdef FEAT_GUI |
| 8750 | old_Rows = screen_Rows; |
| 8751 | #endif |
| 8752 | screen_Rows = Rows; |
| 8753 | screen_Columns = Columns; |
| 8754 | |
| 8755 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8756 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8757 | screenclear2(); |
| 8758 | |
| 8759 | #ifdef FEAT_GUI |
| 8760 | else if (gui.in_use |
| 8761 | && !gui.starting |
| 8762 | && ScreenLines != NULL |
| 8763 | && old_Rows != Rows) |
| 8764 | { |
| 8765 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8766 | /* |
| 8767 | * Adjust the position of the cursor, for when executing an external |
| 8768 | * command. |
| 8769 | */ |
| 8770 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8771 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8772 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8773 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8774 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8775 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8776 | } |
| 8777 | #endif |
| 8778 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8779 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8780 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8781 | |
| 8782 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8783 | /* |
| 8784 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8785 | * in case applying autocommands always changes Rows or Columns. |
| 8786 | */ |
| 8787 | if (starting == 0 && ++retry_count <= 3) |
| 8788 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8789 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8790 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8791 | * jump back to check if we need to allocate the screen again. */ |
| 8792 | goto retry; |
| 8793 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8794 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8795 | } |
| 8796 | |
| 8797 | void |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8798 | free_screenlines() |
| 8799 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8800 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8801 | int i; |
| 8802 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8803 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8804 | for (i = 0; i < Screen_mco; ++i) |
| 8805 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8806 | vim_free(ScreenLines2); |
| 8807 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8808 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8809 | vim_free(ScreenAttrs); |
| 8810 | vim_free(LineOffset); |
| 8811 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8812 | #ifdef FEAT_WINDOWS |
| 8813 | vim_free(TabPageIdxs); |
| 8814 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8815 | } |
| 8816 | |
| 8817 | void |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8818 | screenclear() |
| 8819 | { |
| 8820 | check_for_delay(FALSE); |
| 8821 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8822 | screenclear2(); /* clear the screen */ |
| 8823 | } |
| 8824 | |
| 8825 | static void |
| 8826 | screenclear2() |
| 8827 | { |
| 8828 | int i; |
| 8829 | |
| 8830 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8831 | #ifdef FEAT_GUI |
| 8832 | || (gui.in_use && gui.starting) |
| 8833 | #endif |
| 8834 | ) |
| 8835 | return; |
| 8836 | |
| 8837 | #ifdef FEAT_GUI |
| 8838 | if (!gui.in_use) |
| 8839 | #endif |
| 8840 | screen_attr = -1; /* force setting the Normal colors */ |
| 8841 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8842 | |
| 8843 | #ifdef FEAT_CLIPBOARD |
| 8844 | /* disable selection without redrawing it */ |
| 8845 | clip_scroll_selection(9999); |
| 8846 | #endif |
| 8847 | |
| 8848 | /* blank out ScreenLines */ |
| 8849 | for (i = 0; i < Rows; ++i) |
| 8850 | { |
| 8851 | lineclear(LineOffset[i], (int)Columns); |
| 8852 | LineWraps[i] = FALSE; |
| 8853 | } |
| 8854 | |
| 8855 | if (can_clear(T_CL)) |
| 8856 | { |
| 8857 | out_str(T_CL); /* clear the display */ |
| 8858 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8859 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8860 | } |
| 8861 | else |
| 8862 | { |
| 8863 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8864 | for (i = 0; i < Rows; ++i) |
| 8865 | lineinvalid(LineOffset[i], (int)Columns); |
| 8866 | clear_cmdline = TRUE; |
| 8867 | } |
| 8868 | |
| 8869 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8870 | |
| 8871 | win_rest_invalid(firstwin); |
| 8872 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8873 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8874 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8875 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8876 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8877 | must_redraw = NOT_VALID; |
| 8878 | compute_cmdrow(); |
| 8879 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8880 | msg_col = 0; |
| 8881 | screen_start(); /* don't know where cursor is now */ |
| 8882 | msg_scrolled = 0; /* can't scroll back */ |
| 8883 | msg_didany = FALSE; |
| 8884 | msg_didout = FALSE; |
| 8885 | } |
| 8886 | |
| 8887 | /* |
| 8888 | * Clear one line in ScreenLines. |
| 8889 | */ |
| 8890 | static void |
| 8891 | lineclear(off, width) |
| 8892 | unsigned off; |
| 8893 | int width; |
| 8894 | { |
| 8895 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8896 | #ifdef FEAT_MBYTE |
| 8897 | if (enc_utf8) |
| 8898 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8899 | (size_t)width * sizeof(u8char_T)); |
| 8900 | #endif |
| 8901 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8902 | } |
| 8903 | |
| 8904 | /* |
| 8905 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8906 | * invalid value. |
| 8907 | */ |
| 8908 | static void |
| 8909 | lineinvalid(off, width) |
| 8910 | unsigned off; |
| 8911 | int width; |
| 8912 | { |
| 8913 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8914 | } |
| 8915 | |
| 8916 | #ifdef FEAT_VERTSPLIT |
| 8917 | /* |
| 8918 | * Copy part of a Screenline for vertically split window "wp". |
| 8919 | */ |
| 8920 | static void |
| 8921 | linecopy(to, from, wp) |
| 8922 | int to; |
| 8923 | int from; |
| 8924 | win_T *wp; |
| 8925 | { |
| 8926 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8927 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8928 | |
| 8929 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8930 | wp->w_width * sizeof(schar_T)); |
| 8931 | # ifdef FEAT_MBYTE |
| 8932 | if (enc_utf8) |
| 8933 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8934 | int i; |
| 8935 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8936 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8937 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8938 | for (i = 0; i < p_mco; ++i) |
| 8939 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8940 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8941 | } |
| 8942 | if (enc_dbcs == DBCS_JPNU) |
| 8943 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8944 | wp->w_width * sizeof(schar_T)); |
| 8945 | # endif |
| 8946 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8947 | wp->w_width * sizeof(sattr_T)); |
| 8948 | } |
| 8949 | #endif |
| 8950 | |
| 8951 | /* |
| 8952 | * Return TRUE if clearing with term string "p" would work. |
| 8953 | * It can't work when the string is empty or it won't set the right background. |
| 8954 | */ |
| 8955 | int |
| 8956 | can_clear(p) |
| 8957 | char_u *p; |
| 8958 | { |
| 8959 | return (*p != NUL && (t_colors <= 1 |
| 8960 | #ifdef FEAT_GUI |
| 8961 | || gui.in_use |
| 8962 | #endif |
| 8963 | || cterm_normal_bg_color == 0 || *T_UT != NUL)); |
| 8964 | } |
| 8965 | |
| 8966 | /* |
| 8967 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 8968 | * something directly to the screen (shell commands) or a terminal control |
| 8969 | * code. |
| 8970 | */ |
| 8971 | void |
| 8972 | screen_start() |
| 8973 | { |
| 8974 | screen_cur_row = screen_cur_col = 9999; |
| 8975 | } |
| 8976 | |
| 8977 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8978 | * Move the cursor to position "row","col" in the screen. |
| 8979 | * This tries to find the most efficient way to move, minimizing the number of |
| 8980 | * characters sent to the terminal. |
| 8981 | */ |
| 8982 | void |
| 8983 | windgoto(row, col) |
| 8984 | int row; |
| 8985 | int col; |
| 8986 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8987 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8988 | int i; |
| 8989 | int plan; |
| 8990 | int cost; |
| 8991 | int wouldbe_col; |
| 8992 | int noinvcurs; |
| 8993 | char_u *bs; |
| 8994 | int goto_cost; |
| 8995 | int attr; |
| 8996 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 8997 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8998 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 8999 | |
| 9000 | #define PLAN_LE 1 |
| 9001 | #define PLAN_CR 2 |
| 9002 | #define PLAN_NL 3 |
| 9003 | #define PLAN_WRITE 4 |
| 9004 | /* Can't use ScreenLines unless initialized */ |
| 9005 | if (ScreenLines == NULL) |
| 9006 | return; |
| 9007 | |
| 9008 | if (col != screen_cur_col || row != screen_cur_row) |
| 9009 | { |
| 9010 | /* Check for valid position. */ |
| 9011 | if (row < 0) /* window without text lines? */ |
| 9012 | row = 0; |
| 9013 | if (row >= screen_Rows) |
| 9014 | row = screen_Rows - 1; |
| 9015 | if (col >= screen_Columns) |
| 9016 | col = screen_Columns - 1; |
| 9017 | |
| 9018 | /* check if no cursor movement is allowed in highlight mode */ |
| 9019 | if (screen_attr && *T_MS == NUL) |
| 9020 | noinvcurs = HIGHL_COST; |
| 9021 | else |
| 9022 | noinvcurs = 0; |
| 9023 | goto_cost = GOTO_COST + noinvcurs; |
| 9024 | |
| 9025 | /* |
| 9026 | * Plan how to do the positioning: |
| 9027 | * 1. Use CR to move it to column 0, same row. |
| 9028 | * 2. Use T_LE to move it a few columns to the left. |
| 9029 | * 3. Use NL to move a few lines down, column 0. |
| 9030 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 9031 | * |
| 9032 | * Don't do this if the cursor went beyond the last column, the cursor |
| 9033 | * position is unknown then (some terminals wrap, some don't ) |
| 9034 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9035 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9036 | * characters to move the cursor to the right. |
| 9037 | */ |
| 9038 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 9039 | { |
| 9040 | /* |
| 9041 | * If the cursor is in the same row, bigger col, we can use CR |
| 9042 | * or T_LE. |
| 9043 | */ |
| 9044 | bs = NULL; /* init for GCC */ |
| 9045 | attr = screen_attr; |
| 9046 | if (row == screen_cur_row && col < screen_cur_col) |
| 9047 | { |
| 9048 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 9049 | if (*T_LE) |
| 9050 | bs = T_LE; /* "cursor left" */ |
| 9051 | else |
| 9052 | bs = T_BC; /* "backspace character (old) */ |
| 9053 | if (*bs) |
| 9054 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 9055 | else |
| 9056 | cost = 999; |
| 9057 | if (col + 1 < cost) /* using CR is less characters */ |
| 9058 | { |
| 9059 | plan = PLAN_CR; |
| 9060 | wouldbe_col = 0; |
| 9061 | cost = 1; /* CR is just one character */ |
| 9062 | } |
| 9063 | else |
| 9064 | { |
| 9065 | plan = PLAN_LE; |
| 9066 | wouldbe_col = col; |
| 9067 | } |
| 9068 | if (noinvcurs) /* will stop highlighting */ |
| 9069 | { |
| 9070 | cost += noinvcurs; |
| 9071 | attr = 0; |
| 9072 | } |
| 9073 | } |
| 9074 | |
| 9075 | /* |
| 9076 | * If the cursor is above where we want to be, we can use CR LF. |
| 9077 | */ |
| 9078 | else if (row > screen_cur_row) |
| 9079 | { |
| 9080 | plan = PLAN_NL; |
| 9081 | wouldbe_col = 0; |
| 9082 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9083 | if (noinvcurs) /* will stop highlighting */ |
| 9084 | { |
| 9085 | cost += noinvcurs; |
| 9086 | attr = 0; |
| 9087 | } |
| 9088 | } |
| 9089 | |
| 9090 | /* |
| 9091 | * If the cursor is in the same row, smaller col, just use write. |
| 9092 | */ |
| 9093 | else |
| 9094 | { |
| 9095 | plan = PLAN_WRITE; |
| 9096 | wouldbe_col = screen_cur_col; |
| 9097 | cost = 0; |
| 9098 | } |
| 9099 | |
| 9100 | /* |
| 9101 | * Check if any characters that need to be written have the |
| 9102 | * correct attributes. Also avoid UTF-8 characters. |
| 9103 | */ |
| 9104 | i = col - wouldbe_col; |
| 9105 | if (i > 0) |
| 9106 | cost += i; |
| 9107 | if (cost < goto_cost && i > 0) |
| 9108 | { |
| 9109 | /* |
| 9110 | * Check if the attributes are correct without additionally |
| 9111 | * stopping highlighting. |
| 9112 | */ |
| 9113 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9114 | while (i && *p++ == attr) |
| 9115 | --i; |
| 9116 | if (i != 0) |
| 9117 | { |
| 9118 | /* |
| 9119 | * Try if it works when highlighting is stopped here. |
| 9120 | */ |
| 9121 | if (*--p == 0) |
| 9122 | { |
| 9123 | cost += noinvcurs; |
| 9124 | while (i && *p++ == 0) |
| 9125 | --i; |
| 9126 | } |
| 9127 | if (i != 0) |
| 9128 | cost = 999; /* different attributes, don't do it */ |
| 9129 | } |
| 9130 | #ifdef FEAT_MBYTE |
| 9131 | if (enc_utf8) |
| 9132 | { |
| 9133 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9134 | for (i = wouldbe_col; i < col; ++i) |
| 9135 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9136 | { |
| 9137 | cost = 999; |
| 9138 | break; |
| 9139 | } |
| 9140 | } |
| 9141 | #endif |
| 9142 | } |
| 9143 | |
| 9144 | /* |
| 9145 | * We can do it without term_windgoto()! |
| 9146 | */ |
| 9147 | if (cost < goto_cost) |
| 9148 | { |
| 9149 | if (plan == PLAN_LE) |
| 9150 | { |
| 9151 | if (noinvcurs) |
| 9152 | screen_stop_highlight(); |
| 9153 | while (screen_cur_col > col) |
| 9154 | { |
| 9155 | out_str(bs); |
| 9156 | --screen_cur_col; |
| 9157 | } |
| 9158 | } |
| 9159 | else if (plan == PLAN_CR) |
| 9160 | { |
| 9161 | if (noinvcurs) |
| 9162 | screen_stop_highlight(); |
| 9163 | out_char('\r'); |
| 9164 | screen_cur_col = 0; |
| 9165 | } |
| 9166 | else if (plan == PLAN_NL) |
| 9167 | { |
| 9168 | if (noinvcurs) |
| 9169 | screen_stop_highlight(); |
| 9170 | while (screen_cur_row < row) |
| 9171 | { |
| 9172 | out_char('\n'); |
| 9173 | ++screen_cur_row; |
| 9174 | } |
| 9175 | screen_cur_col = 0; |
| 9176 | } |
| 9177 | |
| 9178 | i = col - screen_cur_col; |
| 9179 | if (i > 0) |
| 9180 | { |
| 9181 | /* |
| 9182 | * Use cursor-right if it's one character only. Avoids |
| 9183 | * removing a line of pixels from the last bold char, when |
| 9184 | * using the bold trick in the GUI. |
| 9185 | */ |
| 9186 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9187 | { |
| 9188 | while (i-- > 0) |
| 9189 | out_char(*T_ND); |
| 9190 | } |
| 9191 | else |
| 9192 | { |
| 9193 | int off; |
| 9194 | |
| 9195 | off = LineOffset[row] + screen_cur_col; |
| 9196 | while (i-- > 0) |
| 9197 | { |
| 9198 | if (ScreenAttrs[off] != screen_attr) |
| 9199 | screen_stop_highlight(); |
| 9200 | #ifdef FEAT_MBYTE |
| 9201 | out_flush_check(); |
| 9202 | #endif |
| 9203 | out_char(ScreenLines[off]); |
| 9204 | #ifdef FEAT_MBYTE |
| 9205 | if (enc_dbcs == DBCS_JPNU |
| 9206 | && ScreenLines[off] == 0x8e) |
| 9207 | out_char(ScreenLines2[off]); |
| 9208 | #endif |
| 9209 | ++off; |
| 9210 | } |
| 9211 | } |
| 9212 | } |
| 9213 | } |
| 9214 | } |
| 9215 | else |
| 9216 | cost = 999; |
| 9217 | |
| 9218 | if (cost >= goto_cost) |
| 9219 | { |
| 9220 | if (noinvcurs) |
| 9221 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9222 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9223 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9224 | term_cursor_right(col - screen_cur_col); |
| 9225 | else |
| 9226 | term_windgoto(row, col); |
| 9227 | } |
| 9228 | screen_cur_row = row; |
| 9229 | screen_cur_col = col; |
| 9230 | } |
| 9231 | } |
| 9232 | |
| 9233 | /* |
| 9234 | * Set cursor to its position in the current window. |
| 9235 | */ |
| 9236 | void |
| 9237 | setcursor() |
| 9238 | { |
| 9239 | if (redrawing()) |
| 9240 | { |
| 9241 | validate_cursor(); |
| 9242 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9243 | W_WINCOL(curwin) + ( |
| 9244 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9245 | /* With 'rightleft' set and the cursor on a double-wide |
| 9246 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9247 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9248 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9249 | (has_mbyte |
| 9250 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9251 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9252 | # endif |
| 9253 | 1)) : |
| 9254 | #endif |
| 9255 | curwin->w_wcol)); |
| 9256 | } |
| 9257 | } |
| 9258 | |
| 9259 | |
| 9260 | /* |
| 9261 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9262 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9263 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9264 | * scrolling. |
| 9265 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9266 | */ |
| 9267 | int |
| 9268 | win_ins_lines(wp, row, line_count, invalid, mayclear) |
| 9269 | win_T *wp; |
| 9270 | int row; |
| 9271 | int line_count; |
| 9272 | int invalid; |
| 9273 | int mayclear; |
| 9274 | { |
| 9275 | int did_delete; |
| 9276 | int nextrow; |
| 9277 | int lastrow; |
| 9278 | int retval; |
| 9279 | |
| 9280 | if (invalid) |
| 9281 | wp->w_lines_valid = 0; |
| 9282 | |
| 9283 | if (wp->w_height < 5) |
| 9284 | return FAIL; |
| 9285 | |
| 9286 | if (line_count > wp->w_height - row) |
| 9287 | line_count = wp->w_height - row; |
| 9288 | |
| 9289 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9290 | if (retval != MAYBE) |
| 9291 | return retval; |
| 9292 | |
| 9293 | /* |
| 9294 | * If there is a next window or a status line, we first try to delete the |
| 9295 | * lines at the bottom to avoid messing what is after the window. |
| 9296 | * If this fails and there are following windows, don't do anything to avoid |
| 9297 | * messing up those windows, better just redraw. |
| 9298 | */ |
| 9299 | did_delete = FALSE; |
| 9300 | #ifdef FEAT_WINDOWS |
| 9301 | if (wp->w_next != NULL || wp->w_status_height) |
| 9302 | { |
| 9303 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9304 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9305 | did_delete = TRUE; |
| 9306 | else if (wp->w_next) |
| 9307 | return FAIL; |
| 9308 | } |
| 9309 | #endif |
| 9310 | /* |
| 9311 | * if no lines deleted, blank the lines that will end up below the window |
| 9312 | */ |
| 9313 | if (!did_delete) |
| 9314 | { |
| 9315 | #ifdef FEAT_WINDOWS |
| 9316 | wp->w_redr_status = TRUE; |
| 9317 | #endif |
| 9318 | redraw_cmdline = TRUE; |
| 9319 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9320 | lastrow = nextrow + line_count; |
| 9321 | if (lastrow > Rows) |
| 9322 | lastrow = Rows; |
| 9323 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9324 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9325 | ' ', ' ', 0); |
| 9326 | } |
| 9327 | |
| 9328 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9329 | == FAIL) |
| 9330 | { |
| 9331 | /* deletion will have messed up other windows */ |
| 9332 | if (did_delete) |
| 9333 | { |
| 9334 | #ifdef FEAT_WINDOWS |
| 9335 | wp->w_redr_status = TRUE; |
| 9336 | #endif |
| 9337 | win_rest_invalid(W_NEXT(wp)); |
| 9338 | } |
| 9339 | return FAIL; |
| 9340 | } |
| 9341 | |
| 9342 | return OK; |
| 9343 | } |
| 9344 | |
| 9345 | /* |
| 9346 | * delete "line_count" window lines at "row" in window "wp" |
| 9347 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9348 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9349 | * scrolling |
| 9350 | * Return OK for success, FAIL if the lines are not deleted. |
| 9351 | */ |
| 9352 | int |
| 9353 | win_del_lines(wp, row, line_count, invalid, mayclear) |
| 9354 | win_T *wp; |
| 9355 | int row; |
| 9356 | int line_count; |
| 9357 | int invalid; |
| 9358 | int mayclear; |
| 9359 | { |
| 9360 | int retval; |
| 9361 | |
| 9362 | if (invalid) |
| 9363 | wp->w_lines_valid = 0; |
| 9364 | |
| 9365 | if (line_count > wp->w_height - row) |
| 9366 | line_count = wp->w_height - row; |
| 9367 | |
| 9368 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9369 | if (retval != MAYBE) |
| 9370 | return retval; |
| 9371 | |
| 9372 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9373 | (int)Rows, FALSE, NULL) == FAIL) |
| 9374 | return FAIL; |
| 9375 | |
| 9376 | #ifdef FEAT_WINDOWS |
| 9377 | /* |
| 9378 | * If there are windows or status lines below, try to put them at the |
| 9379 | * correct place. If we can't do that, they have to be redrawn. |
| 9380 | */ |
| 9381 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9382 | { |
| 9383 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9384 | line_count, (int)Rows, NULL) == FAIL) |
| 9385 | { |
| 9386 | wp->w_redr_status = TRUE; |
| 9387 | win_rest_invalid(wp->w_next); |
| 9388 | } |
| 9389 | } |
| 9390 | /* |
| 9391 | * If this is the last window and there is no status line, redraw the |
| 9392 | * command line later. |
| 9393 | */ |
| 9394 | else |
| 9395 | #endif |
| 9396 | redraw_cmdline = TRUE; |
| 9397 | return OK; |
| 9398 | } |
| 9399 | |
| 9400 | /* |
| 9401 | * Common code for win_ins_lines() and win_del_lines(). |
| 9402 | * Returns OK or FAIL when the work has been done. |
| 9403 | * Returns MAYBE when not finished yet. |
| 9404 | */ |
| 9405 | static int |
| 9406 | win_do_lines(wp, row, line_count, mayclear, del) |
| 9407 | win_T *wp; |
| 9408 | int row; |
| 9409 | int line_count; |
| 9410 | int mayclear; |
| 9411 | int del; |
| 9412 | { |
| 9413 | int retval; |
| 9414 | |
| 9415 | if (!redrawing() || line_count <= 0) |
| 9416 | return FAIL; |
| 9417 | |
| 9418 | /* only a few lines left: redraw is faster */ |
| 9419 | if (mayclear && Rows - line_count < 5 |
| 9420 | #ifdef FEAT_VERTSPLIT |
| 9421 | && wp->w_width == Columns |
| 9422 | #endif |
| 9423 | ) |
| 9424 | { |
| 9425 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9426 | return FAIL; |
| 9427 | } |
| 9428 | |
| 9429 | /* |
| 9430 | * Delete all remaining lines |
| 9431 | */ |
| 9432 | if (row + line_count >= wp->w_height) |
| 9433 | { |
| 9434 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9435 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9436 | ' ', ' ', 0); |
| 9437 | return OK; |
| 9438 | } |
| 9439 | |
| 9440 | /* |
| 9441 | * when scrolling, the message on the command line should be cleared, |
| 9442 | * otherwise it will stay there forever. |
| 9443 | */ |
| 9444 | clear_cmdline = TRUE; |
| 9445 | |
| 9446 | /* |
| 9447 | * If the terminal can set a scroll region, use that. |
| 9448 | * Always do this in a vertically split window. This will redraw from |
| 9449 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9450 | * win_line(). |
| 9451 | * Don't use a scroll region when we are going to redraw the text, writing |
| 9452 | * a character in the lower right corner of the scroll region causes a |
| 9453 | * scroll-up in the DJGPP version. |
| 9454 | */ |
| 9455 | if (scroll_region |
| 9456 | #ifdef FEAT_VERTSPLIT |
| 9457 | || W_WIDTH(wp) != Columns |
| 9458 | #endif |
| 9459 | ) |
| 9460 | { |
| 9461 | #ifdef FEAT_VERTSPLIT |
| 9462 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9463 | #endif |
| 9464 | scroll_region_set(wp, row); |
| 9465 | if (del) |
| 9466 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9467 | wp->w_height - row, FALSE, wp); |
| 9468 | else |
| 9469 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9470 | wp->w_height - row, wp); |
| 9471 | #ifdef FEAT_VERTSPLIT |
| 9472 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9473 | #endif |
| 9474 | scroll_region_reset(); |
| 9475 | return retval; |
| 9476 | } |
| 9477 | |
| 9478 | #ifdef FEAT_WINDOWS |
| 9479 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9480 | return FAIL; |
| 9481 | #endif |
| 9482 | |
| 9483 | return MAYBE; |
| 9484 | } |
| 9485 | |
| 9486 | /* |
| 9487 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9488 | */ |
| 9489 | static void |
| 9490 | win_rest_invalid(wp) |
| 9491 | win_T *wp; |
| 9492 | { |
| 9493 | #ifdef FEAT_WINDOWS |
| 9494 | while (wp != NULL) |
| 9495 | #else |
| 9496 | if (wp != NULL) |
| 9497 | #endif |
| 9498 | { |
| 9499 | redraw_win_later(wp, NOT_VALID); |
| 9500 | #ifdef FEAT_WINDOWS |
| 9501 | wp->w_redr_status = TRUE; |
| 9502 | wp = wp->w_next; |
| 9503 | #endif |
| 9504 | } |
| 9505 | redraw_cmdline = TRUE; |
| 9506 | } |
| 9507 | |
| 9508 | /* |
| 9509 | * The rest of the routines in this file perform screen manipulations. The |
| 9510 | * given operation is performed physically on the screen. The corresponding |
| 9511 | * change is also made to the internal screen image. In this way, the editor |
| 9512 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9513 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9514 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9515 | * screen changes, and in the meantime, everything still works. |
| 9516 | */ |
| 9517 | |
| 9518 | /* |
| 9519 | * types for inserting or deleting lines |
| 9520 | */ |
| 9521 | #define USE_T_CAL 1 |
| 9522 | #define USE_T_CDL 2 |
| 9523 | #define USE_T_AL 3 |
| 9524 | #define USE_T_CE 4 |
| 9525 | #define USE_T_DL 5 |
| 9526 | #define USE_T_SR 6 |
| 9527 | #define USE_NL 7 |
| 9528 | #define USE_T_CD 8 |
| 9529 | #define USE_REDRAW 9 |
| 9530 | |
| 9531 | /* |
| 9532 | * insert lines on the screen and update ScreenLines[] |
| 9533 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9534 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9535 | * 'row' and 'end' are relative to the start of the region. |
| 9536 | * |
| 9537 | * return FAIL for failure, OK for success. |
| 9538 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9539 | int |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9540 | screen_ins_lines(off, row, line_count, end, wp) |
| 9541 | int off; |
| 9542 | int row; |
| 9543 | int line_count; |
| 9544 | int end; |
| 9545 | win_T *wp; /* NULL or window to use width from */ |
| 9546 | { |
| 9547 | int i; |
| 9548 | int j; |
| 9549 | unsigned temp; |
| 9550 | int cursor_row; |
| 9551 | int type; |
| 9552 | int result_empty; |
| 9553 | int can_ce = can_clear(T_CE); |
| 9554 | |
| 9555 | /* |
| 9556 | * FAIL if |
| 9557 | * - there is no valid screen |
| 9558 | * - the screen has to be redrawn completely |
| 9559 | * - the line count is less than one |
| 9560 | * - the line count is more than 'ttyscroll' |
| 9561 | */ |
| 9562 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9563 | return FAIL; |
| 9564 | |
| 9565 | /* |
| 9566 | * There are seven ways to insert lines: |
| 9567 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9568 | * characters from ScreenLines[]. |
| 9569 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9570 | * the insert is just empty lines |
| 9571 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9572 | * present or line_count > 1. It looks better if we do all the inserts |
| 9573 | * at once. |
| 9574 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9575 | * insert is just empty lines and T_CE is not present or line_count > |
| 9576 | * 1. |
| 9577 | * 4. Use T_AL (insert line) if it exists. |
| 9578 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9579 | * just empty lines. |
| 9580 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9581 | * just empty lines. |
| 9582 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9583 | * the 'da' flag is not set or we have clear line capability. |
| 9584 | * 8. redraw the characters from ScreenLines[]. |
| 9585 | * |
| 9586 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9587 | * the scrollbar for the window. It does have insert line, use that if it |
| 9588 | * exists. |
| 9589 | */ |
| 9590 | result_empty = (row + line_count >= end); |
| 9591 | #ifdef FEAT_VERTSPLIT |
| 9592 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9593 | type = USE_REDRAW; |
| 9594 | else |
| 9595 | #endif |
| 9596 | if (can_clear(T_CD) && result_empty) |
| 9597 | type = USE_T_CD; |
| 9598 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9599 | type = USE_T_CAL; |
| 9600 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9601 | type = USE_T_CDL; |
| 9602 | else if (*T_AL != NUL) |
| 9603 | type = USE_T_AL; |
| 9604 | else if (can_ce && result_empty) |
| 9605 | type = USE_T_CE; |
| 9606 | else if (*T_DL != NUL && result_empty) |
| 9607 | type = USE_T_DL; |
| 9608 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9609 | type = USE_T_SR; |
| 9610 | else |
| 9611 | return FAIL; |
| 9612 | |
| 9613 | /* |
| 9614 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9615 | * care of t_db if necessary. |
| 9616 | */ |
| 9617 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9618 | type == USE_T_CE || type == USE_T_DL) |
| 9619 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9620 | |
| 9621 | /* |
| 9622 | * If text is retained below the screen, first clear or delete as many |
| 9623 | * lines at the bottom of the window as are about to be inserted so that |
| 9624 | * the deleted lines won't later surface during a screen_del_lines. |
| 9625 | */ |
| 9626 | if (*T_DB) |
| 9627 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9628 | |
| 9629 | #ifdef FEAT_CLIPBOARD |
| 9630 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9631 | * or not the full width of the screen. */ |
| 9632 | if (off + row > 0 |
| 9633 | # ifdef FEAT_VERTSPLIT |
| 9634 | || (wp != NULL && wp->w_width != Columns) |
| 9635 | # endif |
| 9636 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9637 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9638 | else |
| 9639 | clip_scroll_selection(-line_count); |
| 9640 | #endif |
| 9641 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9642 | #ifdef FEAT_GUI |
| 9643 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9644 | * scrolling is actually carried out. */ |
| 9645 | gui_dont_update_cursor(); |
| 9646 | #endif |
| 9647 | |
| 9648 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9649 | cursor_row = row; |
| 9650 | else |
| 9651 | cursor_row = row + off; |
| 9652 | |
| 9653 | /* |
| 9654 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9655 | * Clear the inserted lines in ScreenLines[]. |
| 9656 | */ |
| 9657 | row += off; |
| 9658 | end += off; |
| 9659 | for (i = 0; i < line_count; ++i) |
| 9660 | { |
| 9661 | #ifdef FEAT_VERTSPLIT |
| 9662 | if (wp != NULL && wp->w_width != Columns) |
| 9663 | { |
| 9664 | /* need to copy part of a line */ |
| 9665 | j = end - 1 - i; |
| 9666 | while ((j -= line_count) >= row) |
| 9667 | linecopy(j + line_count, j, wp); |
| 9668 | j += line_count; |
| 9669 | if (can_clear((char_u *)" ")) |
| 9670 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9671 | else |
| 9672 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9673 | LineWraps[j] = FALSE; |
| 9674 | } |
| 9675 | else |
| 9676 | #endif |
| 9677 | { |
| 9678 | j = end - 1 - i; |
| 9679 | temp = LineOffset[j]; |
| 9680 | while ((j -= line_count) >= row) |
| 9681 | { |
| 9682 | LineOffset[j + line_count] = LineOffset[j]; |
| 9683 | LineWraps[j + line_count] = LineWraps[j]; |
| 9684 | } |
| 9685 | LineOffset[j + line_count] = temp; |
| 9686 | LineWraps[j + line_count] = FALSE; |
| 9687 | if (can_clear((char_u *)" ")) |
| 9688 | lineclear(temp, (int)Columns); |
| 9689 | else |
| 9690 | lineinvalid(temp, (int)Columns); |
| 9691 | } |
| 9692 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9693 | |
| 9694 | screen_stop_highlight(); |
| 9695 | windgoto(cursor_row, 0); |
| 9696 | |
| 9697 | #ifdef FEAT_VERTSPLIT |
| 9698 | /* redraw the characters */ |
| 9699 | if (type == USE_REDRAW) |
| 9700 | redraw_block(row, end, wp); |
| 9701 | else |
| 9702 | #endif |
| 9703 | if (type == USE_T_CAL) |
| 9704 | { |
| 9705 | term_append_lines(line_count); |
| 9706 | screen_start(); /* don't know where cursor is now */ |
| 9707 | } |
| 9708 | else |
| 9709 | { |
| 9710 | for (i = 0; i < line_count; i++) |
| 9711 | { |
| 9712 | if (type == USE_T_AL) |
| 9713 | { |
| 9714 | if (i && cursor_row != 0) |
| 9715 | windgoto(cursor_row, 0); |
| 9716 | out_str(T_AL); |
| 9717 | } |
| 9718 | else /* type == USE_T_SR */ |
| 9719 | out_str(T_SR); |
| 9720 | screen_start(); /* don't know where cursor is now */ |
| 9721 | } |
| 9722 | } |
| 9723 | |
| 9724 | /* |
| 9725 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9726 | * have been scrolled down into the region. |
| 9727 | */ |
| 9728 | if (type == USE_T_SR && *T_DA) |
| 9729 | { |
| 9730 | for (i = 0; i < line_count; ++i) |
| 9731 | { |
| 9732 | windgoto(off + i, 0); |
| 9733 | out_str(T_CE); |
| 9734 | screen_start(); /* don't know where cursor is now */ |
| 9735 | } |
| 9736 | } |
| 9737 | |
| 9738 | #ifdef FEAT_GUI |
| 9739 | gui_can_update_cursor(); |
| 9740 | if (gui.in_use) |
| 9741 | out_flush(); /* always flush after a scroll */ |
| 9742 | #endif |
| 9743 | return OK; |
| 9744 | } |
| 9745 | |
| 9746 | /* |
| 9747 | * delete lines on the screen and update ScreenLines[] |
| 9748 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9749 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9750 | * 'row' and 'end' are relative to the start of the region. |
| 9751 | * |
| 9752 | * Return OK for success, FAIL if the lines are not deleted. |
| 9753 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9754 | int |
| 9755 | screen_del_lines(off, row, line_count, end, force, wp) |
| 9756 | int off; |
| 9757 | int row; |
| 9758 | int line_count; |
| 9759 | int end; |
| 9760 | int force; /* even when line_count > p_ttyscroll */ |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 9761 | win_T *wp UNUSED; /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9762 | { |
| 9763 | int j; |
| 9764 | int i; |
| 9765 | unsigned temp; |
| 9766 | int cursor_row; |
| 9767 | int cursor_end; |
| 9768 | int result_empty; /* result is empty until end of region */ |
| 9769 | int can_delete; /* deleting line codes can be used */ |
| 9770 | int type; |
| 9771 | |
| 9772 | /* |
| 9773 | * FAIL if |
| 9774 | * - there is no valid screen |
| 9775 | * - the screen has to be redrawn completely |
| 9776 | * - the line count is less than one |
| 9777 | * - the line count is more than 'ttyscroll' |
| 9778 | */ |
| 9779 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9780 | (!force && line_count > p_ttyscroll)) |
| 9781 | return FAIL; |
| 9782 | |
| 9783 | /* |
| 9784 | * Check if the rest of the current region will become empty. |
| 9785 | */ |
| 9786 | result_empty = row + line_count >= end; |
| 9787 | |
| 9788 | /* |
| 9789 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9790 | * available. |
| 9791 | */ |
| 9792 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9793 | |
| 9794 | /* |
| 9795 | * There are six ways to delete lines: |
| 9796 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9797 | * characters from ScreenLines[]. |
| 9798 | * 1. Use T_CD if it exists and the result is empty. |
| 9799 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9800 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9801 | * none of the other ways work. |
| 9802 | * 4. Use T_CE (erase line) if the result is empty. |
| 9803 | * 5. Use T_DL (delete line) if it exists. |
| 9804 | * 6. redraw the characters from ScreenLines[]. |
| 9805 | */ |
| 9806 | #ifdef FEAT_VERTSPLIT |
| 9807 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9808 | type = USE_REDRAW; |
| 9809 | else |
| 9810 | #endif |
| 9811 | if (can_clear(T_CD) && result_empty) |
| 9812 | type = USE_T_CD; |
| 9813 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9814 | /* |
| 9815 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9816 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9817 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9818 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9819 | * the trick... |
| 9820 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9821 | * (Olaf Seibert) |
| 9822 | */ |
| 9823 | else if (row == 0 && T_DB == empty_option |
| 9824 | && (line_count == 1 || *T_CDL == NUL)) |
| 9825 | #else |
| 9826 | else if (row == 0 && ( |
| 9827 | #ifndef AMIGA |
| 9828 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9829 | * up, so use delete-line command */ |
| 9830 | line_count == 1 || |
| 9831 | #endif |
| 9832 | *T_CDL == NUL)) |
| 9833 | #endif |
| 9834 | type = USE_NL; |
| 9835 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9836 | type = USE_T_CDL; |
| 9837 | else if (can_clear(T_CE) && result_empty |
| 9838 | #ifdef FEAT_VERTSPLIT |
| 9839 | && (wp == NULL || wp->w_width == Columns) |
| 9840 | #endif |
| 9841 | ) |
| 9842 | type = USE_T_CE; |
| 9843 | else if (*T_DL != NUL && can_delete) |
| 9844 | type = USE_T_DL; |
| 9845 | else if (*T_CDL != NUL && can_delete) |
| 9846 | type = USE_T_CDL; |
| 9847 | else |
| 9848 | return FAIL; |
| 9849 | |
| 9850 | #ifdef FEAT_CLIPBOARD |
| 9851 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9852 | * not the full width of the screen. */ |
| 9853 | if (off + row > 0 |
| 9854 | # ifdef FEAT_VERTSPLIT |
| 9855 | || (wp != NULL && wp->w_width != Columns) |
| 9856 | # endif |
| 9857 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9858 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9859 | else |
| 9860 | clip_scroll_selection(line_count); |
| 9861 | #endif |
| 9862 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9863 | #ifdef FEAT_GUI |
| 9864 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9865 | * scrolling is actually carried out. */ |
| 9866 | gui_dont_update_cursor(); |
| 9867 | #endif |
| 9868 | |
| 9869 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9870 | { |
| 9871 | cursor_row = row; |
| 9872 | cursor_end = end; |
| 9873 | } |
| 9874 | else |
| 9875 | { |
| 9876 | cursor_row = row + off; |
| 9877 | cursor_end = end + off; |
| 9878 | } |
| 9879 | |
| 9880 | /* |
| 9881 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9882 | * Clear the inserted lines in ScreenLines[]. |
| 9883 | */ |
| 9884 | row += off; |
| 9885 | end += off; |
| 9886 | for (i = 0; i < line_count; ++i) |
| 9887 | { |
| 9888 | #ifdef FEAT_VERTSPLIT |
| 9889 | if (wp != NULL && wp->w_width != Columns) |
| 9890 | { |
| 9891 | /* need to copy part of a line */ |
| 9892 | j = row + i; |
| 9893 | while ((j += line_count) <= end - 1) |
| 9894 | linecopy(j - line_count, j, wp); |
| 9895 | j -= line_count; |
| 9896 | if (can_clear((char_u *)" ")) |
| 9897 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9898 | else |
| 9899 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9900 | LineWraps[j] = FALSE; |
| 9901 | } |
| 9902 | else |
| 9903 | #endif |
| 9904 | { |
| 9905 | /* whole width, moving the line pointers is faster */ |
| 9906 | j = row + i; |
| 9907 | temp = LineOffset[j]; |
| 9908 | while ((j += line_count) <= end - 1) |
| 9909 | { |
| 9910 | LineOffset[j - line_count] = LineOffset[j]; |
| 9911 | LineWraps[j - line_count] = LineWraps[j]; |
| 9912 | } |
| 9913 | LineOffset[j - line_count] = temp; |
| 9914 | LineWraps[j - line_count] = FALSE; |
| 9915 | if (can_clear((char_u *)" ")) |
| 9916 | lineclear(temp, (int)Columns); |
| 9917 | else |
| 9918 | lineinvalid(temp, (int)Columns); |
| 9919 | } |
| 9920 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9921 | |
| 9922 | screen_stop_highlight(); |
| 9923 | |
| 9924 | #ifdef FEAT_VERTSPLIT |
| 9925 | /* redraw the characters */ |
| 9926 | if (type == USE_REDRAW) |
| 9927 | redraw_block(row, end, wp); |
| 9928 | else |
| 9929 | #endif |
| 9930 | if (type == USE_T_CD) /* delete the lines */ |
| 9931 | { |
| 9932 | windgoto(cursor_row, 0); |
| 9933 | out_str(T_CD); |
| 9934 | screen_start(); /* don't know where cursor is now */ |
| 9935 | } |
| 9936 | else if (type == USE_T_CDL) |
| 9937 | { |
| 9938 | windgoto(cursor_row, 0); |
| 9939 | term_delete_lines(line_count); |
| 9940 | screen_start(); /* don't know where cursor is now */ |
| 9941 | } |
| 9942 | /* |
| 9943 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9944 | * the whole screen (scroll region) up by outputting newlines on the |
| 9945 | * last line. |
| 9946 | */ |
| 9947 | else if (type == USE_NL) |
| 9948 | { |
| 9949 | windgoto(cursor_end - 1, 0); |
| 9950 | for (i = line_count; --i >= 0; ) |
| 9951 | out_char('\n'); /* cursor will remain on same line */ |
| 9952 | } |
| 9953 | else |
| 9954 | { |
| 9955 | for (i = line_count; --i >= 0; ) |
| 9956 | { |
| 9957 | if (type == USE_T_DL) |
| 9958 | { |
| 9959 | windgoto(cursor_row, 0); |
| 9960 | out_str(T_DL); /* delete a line */ |
| 9961 | } |
| 9962 | else /* type == USE_T_CE */ |
| 9963 | { |
| 9964 | windgoto(cursor_row + i, 0); |
| 9965 | out_str(T_CE); /* erase a line */ |
| 9966 | } |
| 9967 | screen_start(); /* don't know where cursor is now */ |
| 9968 | } |
| 9969 | } |
| 9970 | |
| 9971 | /* |
| 9972 | * If the 'db' flag is set, we need to clear the lines that have been |
| 9973 | * scrolled up at the bottom of the region. |
| 9974 | */ |
| 9975 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 9976 | { |
| 9977 | for (i = line_count; i > 0; --i) |
| 9978 | { |
| 9979 | windgoto(cursor_end - i, 0); |
| 9980 | out_str(T_CE); /* erase a line */ |
| 9981 | screen_start(); /* don't know where cursor is now */ |
| 9982 | } |
| 9983 | } |
| 9984 | |
| 9985 | #ifdef FEAT_GUI |
| 9986 | gui_can_update_cursor(); |
| 9987 | if (gui.in_use) |
| 9988 | out_flush(); /* always flush after a scroll */ |
| 9989 | #endif |
| 9990 | |
| 9991 | return OK; |
| 9992 | } |
| 9993 | |
| 9994 | /* |
| 9995 | * show the current mode and ruler |
| 9996 | * |
| 9997 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 9998 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 9999 | * cleared only if a mode is shown. |
| 10000 | * Return the length of the message (0 if no message). |
| 10001 | */ |
| 10002 | int |
| 10003 | showmode() |
| 10004 | { |
| 10005 | int need_clear; |
| 10006 | int length = 0; |
| 10007 | int do_mode; |
| 10008 | int attr; |
| 10009 | int nwr_save; |
| 10010 | #ifdef FEAT_INS_EXPAND |
| 10011 | int sub_attr; |
| 10012 | #endif |
| 10013 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 10014 | do_mode = ((p_smd && msg_silent == 0) |
| 10015 | && ((State & INSERT) |
| 10016 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 10017 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10018 | if (do_mode || Recording) |
| 10019 | { |
| 10020 | /* |
| 10021 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 10022 | * Call char_avail() only when we are going to show something, because |
| 10023 | * it takes a bit of time. |
| 10024 | */ |
| 10025 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 10026 | { |
| 10027 | redraw_cmdline = TRUE; /* show mode later */ |
| 10028 | return 0; |
| 10029 | } |
| 10030 | |
| 10031 | nwr_save = need_wait_return; |
| 10032 | |
| 10033 | /* wait a bit before overwriting an important message */ |
| 10034 | check_for_delay(FALSE); |
| 10035 | |
| 10036 | /* if the cmdline is more than one line high, erase top lines */ |
| 10037 | need_clear = clear_cmdline; |
| 10038 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 10039 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 10040 | |
| 10041 | /* Position on the last line in the window, column 0 */ |
| 10042 | msg_pos_mode(); |
| 10043 | cursor_off(); |
| 10044 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 10045 | if (do_mode) |
| 10046 | { |
| 10047 | MSG_PUTS_ATTR("--", attr); |
| 10048 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10049 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10050 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10051 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10052 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10053 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10054 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10055 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 10056 | # ifdef FEAT_GUI_GTK /* most of the time, it's not XIM being used */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10057 | MSG_PUTS_ATTR(" IM", attr); |
| 10058 | # else |
| 10059 | MSG_PUTS_ATTR(" XIM", attr); |
| 10060 | # endif |
| 10061 | #endif |
| 10062 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 10063 | if (gui.in_use) |
| 10064 | { |
| 10065 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 10066 | { |
| 10067 | /* HANGUL */ |
| 10068 | if (enc_utf8) |
| 10069 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 10070 | else |
| 10071 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 10072 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10073 | } |
| 10074 | #endif |
| 10075 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10076 | /* CTRL-X in Insert mode */ |
| 10077 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10078 | { |
| 10079 | /* These messages can get long, avoid a wrap in a narrow |
| 10080 | * window. Prefer showing edit_submode_extra. */ |
| 10081 | length = (Rows - msg_row) * Columns - 3; |
| 10082 | if (edit_submode_extra != NULL) |
| 10083 | length -= vim_strsize(edit_submode_extra); |
| 10084 | if (length > 0) |
| 10085 | { |
| 10086 | if (edit_submode_pre != NULL) |
| 10087 | length -= vim_strsize(edit_submode_pre); |
| 10088 | if (length - vim_strsize(edit_submode) > 0) |
| 10089 | { |
| 10090 | if (edit_submode_pre != NULL) |
| 10091 | msg_puts_attr(edit_submode_pre, attr); |
| 10092 | msg_puts_attr(edit_submode, attr); |
| 10093 | } |
| 10094 | if (edit_submode_extra != NULL) |
| 10095 | { |
| 10096 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10097 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10098 | sub_attr = hl_attr(edit_submode_highl); |
| 10099 | else |
| 10100 | sub_attr = attr; |
| 10101 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10102 | } |
| 10103 | } |
| 10104 | length = 0; |
| 10105 | } |
| 10106 | else |
| 10107 | #endif |
| 10108 | { |
| 10109 | #ifdef FEAT_VREPLACE |
| 10110 | if (State & VREPLACE_FLAG) |
| 10111 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10112 | else |
| 10113 | #endif |
| 10114 | if (State & REPLACE_FLAG) |
| 10115 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10116 | else if (State & INSERT) |
| 10117 | { |
| 10118 | #ifdef FEAT_RIGHTLEFT |
| 10119 | if (p_ri) |
| 10120 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10121 | #endif |
| 10122 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10123 | } |
| 10124 | else if (restart_edit == 'I') |
| 10125 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10126 | else if (restart_edit == 'R') |
| 10127 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10128 | else if (restart_edit == 'V') |
| 10129 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10130 | #ifdef FEAT_RIGHTLEFT |
| 10131 | if (p_hkmap) |
| 10132 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10133 | # ifdef FEAT_FKMAP |
| 10134 | if (p_fkmap) |
| 10135 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10136 | # endif |
| 10137 | #endif |
| 10138 | #ifdef FEAT_KEYMAP |
| 10139 | if (State & LANGMAP) |
| 10140 | { |
| 10141 | # ifdef FEAT_ARABIC |
| 10142 | if (curwin->w_p_arab) |
| 10143 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10144 | else |
| 10145 | # endif |
| 10146 | MSG_PUTS_ATTR(_(" (lang)"), attr); |
| 10147 | } |
| 10148 | #endif |
| 10149 | if ((State & INSERT) && p_paste) |
| 10150 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10151 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10152 | if (VIsual_active) |
| 10153 | { |
| 10154 | char *p; |
| 10155 | |
| 10156 | /* Don't concatenate separate words to avoid translation |
| 10157 | * problems. */ |
| 10158 | switch ((VIsual_select ? 4 : 0) |
| 10159 | + (VIsual_mode == Ctrl_V) * 2 |
| 10160 | + (VIsual_mode == 'V')) |
| 10161 | { |
| 10162 | case 0: p = N_(" VISUAL"); break; |
| 10163 | case 1: p = N_(" VISUAL LINE"); break; |
| 10164 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10165 | case 4: p = N_(" SELECT"); break; |
| 10166 | case 5: p = N_(" SELECT LINE"); break; |
| 10167 | default: p = N_(" SELECT BLOCK"); break; |
| 10168 | } |
| 10169 | MSG_PUTS_ATTR(_(p), attr); |
| 10170 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10171 | MSG_PUTS_ATTR(" --", attr); |
| 10172 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10173 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10174 | need_clear = TRUE; |
| 10175 | } |
| 10176 | if (Recording |
| 10177 | #ifdef FEAT_INS_EXPAND |
| 10178 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10179 | #endif |
| 10180 | ) |
| 10181 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10182 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10183 | need_clear = TRUE; |
| 10184 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10185 | |
| 10186 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10187 | if (need_clear || clear_cmdline) |
| 10188 | msg_clr_eos(); |
| 10189 | msg_didout = FALSE; /* overwrite this message */ |
| 10190 | length = msg_col; |
| 10191 | msg_col = 0; |
| 10192 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10193 | } |
| 10194 | else if (clear_cmdline && msg_silent == 0) |
| 10195 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10196 | msg_clr_cmdline(); |
| 10197 | |
| 10198 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10199 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10200 | if (VIsual_active) |
| 10201 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10202 | |
| 10203 | /* If the last window has no status line, the ruler is after the mode |
| 10204 | * message and must be redrawn */ |
| 10205 | if (redrawing() |
| 10206 | # ifdef FEAT_WINDOWS |
| 10207 | && lastwin->w_status_height == 0 |
| 10208 | # endif |
| 10209 | ) |
| 10210 | win_redr_ruler(lastwin, TRUE); |
| 10211 | #endif |
| 10212 | redraw_cmdline = FALSE; |
| 10213 | clear_cmdline = FALSE; |
| 10214 | |
| 10215 | return length; |
| 10216 | } |
| 10217 | |
| 10218 | /* |
| 10219 | * Position for a mode message. |
| 10220 | */ |
| 10221 | static void |
| 10222 | msg_pos_mode() |
| 10223 | { |
| 10224 | msg_col = 0; |
| 10225 | msg_row = Rows - 1; |
| 10226 | } |
| 10227 | |
| 10228 | /* |
| 10229 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10230 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10231 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10232 | */ |
| 10233 | void |
| 10234 | unshowmode(force) |
| 10235 | int force; |
| 10236 | { |
| 10237 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10238 | * Don't delete it right now, when not redrawing or inside a mapping. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10239 | */ |
| 10240 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10241 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10242 | else |
| 10243 | { |
| 10244 | msg_pos_mode(); |
| 10245 | if (Recording) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10246 | recording_mode(hl_attr(HLF_CM)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10247 | msg_clr_eos(); |
| 10248 | } |
| 10249 | } |
| 10250 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10251 | static void |
| 10252 | recording_mode(attr) |
| 10253 | int attr; |
| 10254 | { |
| 10255 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10256 | if (!shortmess(SHM_RECORDING)) |
| 10257 | { |
| 10258 | char_u s[4]; |
| 10259 | sprintf((char *)s, " @%c", Recording); |
| 10260 | MSG_PUTS_ATTR(s, attr); |
| 10261 | } |
| 10262 | } |
| 10263 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10264 | #if defined(FEAT_WINDOWS) |
| 10265 | /* |
| 10266 | * Draw the tab pages line at the top of the Vim window. |
| 10267 | */ |
| 10268 | static void |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10269 | draw_tabline() |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10270 | { |
| 10271 | int tabcount = 0; |
| 10272 | tabpage_T *tp; |
| 10273 | int tabwidth; |
| 10274 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10275 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10276 | int attr; |
| 10277 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10278 | win_T *cwp; |
| 10279 | int wincount; |
| 10280 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10281 | int c; |
| 10282 | int len; |
| 10283 | int attr_sel = hl_attr(HLF_TPS); |
| 10284 | int attr_nosel = hl_attr(HLF_TP); |
| 10285 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10286 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10287 | int room; |
| 10288 | int use_sep_chars = (t_colors < 8 |
| 10289 | #ifdef FEAT_GUI |
| 10290 | && !gui.in_use |
| 10291 | #endif |
| 10292 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10293 | |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10294 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10295 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10296 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10297 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10298 | if (gui_use_tabline()) |
| 10299 | { |
| 10300 | gui_update_tabline(); |
| 10301 | return; |
| 10302 | } |
| 10303 | #endif |
| 10304 | |
| 10305 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10306 | return; |
| 10307 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10308 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10309 | |
| 10310 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10311 | for (scol = 0; scol < Columns; ++scol) |
| 10312 | TabPageIdxs[scol] = 0; |
| 10313 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10314 | /* Use the 'tabline' option if it's set. */ |
| 10315 | if (*p_tal != NUL) |
| 10316 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10317 | int save_called_emsg = called_emsg; |
| 10318 | |
| 10319 | /* Check for an error. If there is one we would loop in redrawing the |
| 10320 | * screen. Avoid that by making 'tabline' empty. */ |
| 10321 | called_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10322 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10323 | if (called_emsg) |
| 10324 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10325 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10326 | called_emsg |= save_called_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10327 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10328 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10329 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10330 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10331 | for (tp = first_tabpage; tp != NULL; tp = tp->tp_next) |
| 10332 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10333 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10334 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10335 | if (tabwidth < 6) |
| 10336 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10337 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10338 | attr = attr_nosel; |
| 10339 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10340 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10341 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10342 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10343 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10344 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10345 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10346 | if (tp->tp_topframe == topframe) |
| 10347 | attr = attr_sel; |
| 10348 | if (use_sep_chars && col > 0) |
| 10349 | screen_putchar('|', 0, col++, attr); |
| 10350 | |
| 10351 | if (tp->tp_topframe != topframe) |
| 10352 | attr = attr_nosel; |
| 10353 | |
| 10354 | screen_putchar(' ', 0, col++, attr); |
| 10355 | |
| 10356 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10357 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10358 | cwp = curwin; |
| 10359 | wp = firstwin; |
| 10360 | } |
| 10361 | else |
| 10362 | { |
| 10363 | cwp = tp->tp_curwin; |
| 10364 | wp = tp->tp_firstwin; |
| 10365 | } |
| 10366 | |
| 10367 | modified = FALSE; |
| 10368 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10369 | if (bufIsChanged(wp->w_buffer)) |
| 10370 | modified = TRUE; |
| 10371 | if (modified || wincount > 1) |
| 10372 | { |
| 10373 | if (wincount > 1) |
| 10374 | { |
| 10375 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10376 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10377 | if (col + len >= Columns - 3) |
| 10378 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10379 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10380 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10381 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10382 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10383 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10384 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10385 | ); |
| 10386 | col += len; |
| 10387 | } |
| 10388 | if (modified) |
| 10389 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10390 | screen_putchar(' ', 0, col++, attr); |
| 10391 | } |
| 10392 | |
| 10393 | room = scol - col + tabwidth - 1; |
| 10394 | if (room > 0) |
| 10395 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10396 | /* Get buffer name in NameBuff[] */ |
| 10397 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10398 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10399 | len = vim_strsize(NameBuff); |
| 10400 | p = NameBuff; |
| 10401 | #ifdef FEAT_MBYTE |
| 10402 | if (has_mbyte) |
| 10403 | while (len > room) |
| 10404 | { |
| 10405 | len -= ptr2cells(p); |
| 10406 | mb_ptr_adv(p); |
| 10407 | } |
| 10408 | else |
| 10409 | #endif |
| 10410 | if (len > room) |
| 10411 | { |
| 10412 | p += len - room; |
| 10413 | len = room; |
| 10414 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10415 | if (len > Columns - col - 1) |
| 10416 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10417 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10418 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10419 | col += len; |
| 10420 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10421 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10422 | |
| 10423 | /* Store the tab page number in TabPageIdxs[], so that |
| 10424 | * jump_to_mouse() knows where each one is. */ |
| 10425 | ++tabcount; |
| 10426 | while (scol < col) |
| 10427 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10428 | } |
| 10429 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10430 | if (use_sep_chars) |
| 10431 | c = '_'; |
| 10432 | else |
| 10433 | c = ' '; |
| 10434 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10435 | |
| 10436 | /* Put an "X" for closing the current tab if there are several. */ |
| 10437 | if (first_tabpage->tp_next != NULL) |
| 10438 | { |
| 10439 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10440 | TabPageIdxs[Columns - 1] = -999; |
| 10441 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10442 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10443 | |
| 10444 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10445 | * set. */ |
| 10446 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10447 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10448 | |
| 10449 | /* |
| 10450 | * Get buffer name for "buf" into NameBuff[]. |
| 10451 | * Takes care of special buffer names and translates special characters. |
| 10452 | */ |
| 10453 | void |
| 10454 | get_trans_bufname(buf) |
| 10455 | buf_T *buf; |
| 10456 | { |
| 10457 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10458 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10459 | else |
| 10460 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10461 | trans_characters(NameBuff, MAXPATHL); |
| 10462 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10463 | #endif |
| 10464 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10465 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10466 | /* |
| 10467 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10468 | */ |
| 10469 | static int |
| 10470 | fillchar_status(attr, is_curwin) |
| 10471 | int *attr; |
| 10472 | int is_curwin; |
| 10473 | { |
| 10474 | int fill; |
| 10475 | if (is_curwin) |
| 10476 | { |
| 10477 | *attr = hl_attr(HLF_S); |
| 10478 | fill = fill_stl; |
| 10479 | } |
| 10480 | else |
| 10481 | { |
| 10482 | *attr = hl_attr(HLF_SNC); |
| 10483 | fill = fill_stlnc; |
| 10484 | } |
| 10485 | /* Use fill when there is highlighting, and highlighting of current |
| 10486 | * window differs, or the fillchars differ, or this is not the |
| 10487 | * current window */ |
| 10488 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
| 10489 | || !is_curwin || firstwin == lastwin) |
| 10490 | || (fill_stl != fill_stlnc))) |
| 10491 | return fill; |
| 10492 | if (is_curwin) |
| 10493 | return '^'; |
| 10494 | return '='; |
| 10495 | } |
| 10496 | #endif |
| 10497 | |
| 10498 | #ifdef FEAT_VERTSPLIT |
| 10499 | /* |
| 10500 | * Get the character to use in a separator between vertically split windows. |
| 10501 | * Get its attributes in "*attr". |
| 10502 | */ |
| 10503 | static int |
| 10504 | fillchar_vsep(attr) |
| 10505 | int *attr; |
| 10506 | { |
| 10507 | *attr = hl_attr(HLF_C); |
| 10508 | if (*attr == 0 && fill_vert == ' ') |
| 10509 | return '|'; |
| 10510 | else |
| 10511 | return fill_vert; |
| 10512 | } |
| 10513 | #endif |
| 10514 | |
| 10515 | /* |
| 10516 | * Return TRUE if redrawing should currently be done. |
| 10517 | */ |
| 10518 | int |
| 10519 | redrawing() |
| 10520 | { |
| 10521 | return (!RedrawingDisabled |
| 10522 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10523 | } |
| 10524 | |
| 10525 | /* |
| 10526 | * Return TRUE if printing messages should currently be done. |
| 10527 | */ |
| 10528 | int |
| 10529 | messaging() |
| 10530 | { |
| 10531 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10532 | } |
| 10533 | |
| 10534 | /* |
| 10535 | * Show current status info in ruler and various other places |
| 10536 | * If always is FALSE, only show ruler if position has changed. |
| 10537 | */ |
| 10538 | void |
| 10539 | showruler(always) |
| 10540 | int always; |
| 10541 | { |
| 10542 | if (!always && !redrawing()) |
| 10543 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10544 | #ifdef FEAT_INS_EXPAND |
| 10545 | if (pum_visible()) |
| 10546 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10547 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10548 | /* Don't redraw right now, do it later. */ |
| 10549 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10550 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10551 | return; |
| 10552 | } |
| 10553 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10554 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10555 | if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10556 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10557 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10558 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10559 | else |
| 10560 | #endif |
| 10561 | #ifdef FEAT_CMDL_INFO |
| 10562 | win_redr_ruler(curwin, always); |
| 10563 | #endif |
| 10564 | |
| 10565 | #ifdef FEAT_TITLE |
| 10566 | if (need_maketitle |
| 10567 | # ifdef FEAT_STL_OPT |
| 10568 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10569 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10570 | # endif |
| 10571 | ) |
| 10572 | maketitle(); |
| 10573 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10574 | #ifdef FEAT_WINDOWS |
| 10575 | /* Redraw the tab pages line if needed. */ |
| 10576 | if (redraw_tabline) |
| 10577 | draw_tabline(); |
| 10578 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10579 | } |
| 10580 | |
| 10581 | #ifdef FEAT_CMDL_INFO |
| 10582 | static void |
| 10583 | win_redr_ruler(wp, always) |
| 10584 | win_T *wp; |
| 10585 | int always; |
| 10586 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10587 | #define RULER_BUF_LEN 70 |
| 10588 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10589 | int row; |
| 10590 | int fillchar; |
| 10591 | int attr; |
| 10592 | int empty_line = FALSE; |
| 10593 | colnr_T virtcol; |
| 10594 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10595 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10596 | int o; |
| 10597 | #ifdef FEAT_VERTSPLIT |
| 10598 | int this_ru_col; |
| 10599 | int off = 0; |
| 10600 | int width = Columns; |
| 10601 | # define WITH_OFF(x) x |
| 10602 | # define WITH_WIDTH(x) x |
| 10603 | #else |
| 10604 | # define WITH_OFF(x) 0 |
| 10605 | # define WITH_WIDTH(x) Columns |
| 10606 | # define this_ru_col ru_col |
| 10607 | #endif |
| 10608 | |
| 10609 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10610 | if (!p_ru) |
| 10611 | return; |
| 10612 | |
| 10613 | /* |
| 10614 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10615 | * after deleting lines, before cursor.lnum is corrected. |
| 10616 | */ |
| 10617 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10618 | return; |
| 10619 | |
| 10620 | #ifdef FEAT_INS_EXPAND |
| 10621 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10622 | * the (long) mode message. */ |
| 10623 | # ifdef FEAT_WINDOWS |
| 10624 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10625 | # endif |
| 10626 | if (edit_submode != NULL) |
| 10627 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10628 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10629 | if (pum_visible()) |
| 10630 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10631 | #endif |
| 10632 | |
| 10633 | #ifdef FEAT_STL_OPT |
| 10634 | if (*p_ruf) |
| 10635 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10636 | int save_called_emsg = called_emsg; |
| 10637 | |
| 10638 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10639 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10640 | if (called_emsg) |
| 10641 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10642 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10643 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10644 | return; |
| 10645 | } |
| 10646 | #endif |
| 10647 | |
| 10648 | /* |
| 10649 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10650 | */ |
| 10651 | if (!(State & INSERT) |
| 10652 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10653 | empty_line = TRUE; |
| 10654 | |
| 10655 | /* |
| 10656 | * Only draw the ruler when something changed. |
| 10657 | */ |
| 10658 | validate_virtcol_win(wp); |
| 10659 | if ( redraw_cmdline |
| 10660 | || always |
| 10661 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10662 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10663 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10664 | #ifdef FEAT_VIRTUALEDIT |
| 10665 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10666 | #endif |
| 10667 | || wp->w_topline != wp->w_ru_topline |
| 10668 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10669 | #ifdef FEAT_DIFF |
| 10670 | || wp->w_topfill != wp->w_ru_topfill |
| 10671 | #endif |
| 10672 | || empty_line != wp->w_ru_empty) |
| 10673 | { |
| 10674 | cursor_off(); |
| 10675 | #ifdef FEAT_WINDOWS |
| 10676 | if (wp->w_status_height) |
| 10677 | { |
| 10678 | row = W_WINROW(wp) + wp->w_height; |
| 10679 | fillchar = fillchar_status(&attr, wp == curwin); |
| 10680 | # ifdef FEAT_VERTSPLIT |
| 10681 | off = W_WINCOL(wp); |
| 10682 | width = W_WIDTH(wp); |
| 10683 | # endif |
| 10684 | } |
| 10685 | else |
| 10686 | #endif |
| 10687 | { |
| 10688 | row = Rows - 1; |
| 10689 | fillchar = ' '; |
| 10690 | attr = 0; |
| 10691 | #ifdef FEAT_VERTSPLIT |
| 10692 | width = Columns; |
| 10693 | off = 0; |
| 10694 | #endif |
| 10695 | } |
| 10696 | |
| 10697 | /* In list mode virtcol needs to be recomputed */ |
| 10698 | virtcol = wp->w_virtcol; |
| 10699 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10700 | { |
| 10701 | wp->w_p_list = FALSE; |
| 10702 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10703 | wp->w_p_list = TRUE; |
| 10704 | } |
| 10705 | |
| 10706 | /* |
| 10707 | * Some sprintfs return the length, some return a pointer. |
| 10708 | * To avoid portability problems we use strlen() here. |
| 10709 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10710 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10711 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10712 | ? 0L |
| 10713 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10714 | len = STRLEN(buffer); |
| 10715 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10716 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10717 | (int)virtcol + 1); |
| 10718 | |
| 10719 | /* |
| 10720 | * Add a "50%" if there is room for it. |
| 10721 | * On the last line, don't print in the last column (scrolls the |
| 10722 | * screen up on some terminals). |
| 10723 | */ |
| 10724 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10725 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10726 | o = i + vim_strsize(buffer + i + 1); |
| 10727 | #ifdef FEAT_WINDOWS |
| 10728 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10729 | #endif |
| 10730 | ++o; |
| 10731 | #ifdef FEAT_VERTSPLIT |
| 10732 | this_ru_col = ru_col - (Columns - width); |
| 10733 | if (this_ru_col < 0) |
| 10734 | this_ru_col = 0; |
| 10735 | #endif |
| 10736 | /* Never use more than half the window/screen width, leave the other |
| 10737 | * half for the filename. */ |
| 10738 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10739 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10740 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10741 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10742 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10743 | while (this_ru_col + o < WITH_WIDTH(width) && RULER_BUF_LEN > i + 4) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10744 | { |
| 10745 | #ifdef FEAT_MBYTE |
| 10746 | if (has_mbyte) |
| 10747 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10748 | else |
| 10749 | #endif |
| 10750 | buffer[i++] = fillchar; |
| 10751 | ++o; |
| 10752 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10753 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10754 | } |
| 10755 | /* Truncate at window boundary. */ |
| 10756 | #ifdef FEAT_MBYTE |
| 10757 | if (has_mbyte) |
| 10758 | { |
| 10759 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10760 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10761 | { |
| 10762 | o += (*mb_ptr2cells)(buffer + i); |
| 10763 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10764 | { |
| 10765 | buffer[i] = NUL; |
| 10766 | break; |
| 10767 | } |
| 10768 | } |
| 10769 | } |
| 10770 | else |
| 10771 | #endif |
| 10772 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10773 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10774 | |
| 10775 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10776 | i = redraw_cmdline; |
| 10777 | screen_fill(row, row + 1, |
| 10778 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10779 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10780 | fillchar, fillchar, attr); |
| 10781 | /* don't redraw the cmdline because of showing the ruler */ |
| 10782 | redraw_cmdline = i; |
| 10783 | wp->w_ru_cursor = wp->w_cursor; |
| 10784 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10785 | wp->w_ru_empty = empty_line; |
| 10786 | wp->w_ru_topline = wp->w_topline; |
| 10787 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10788 | #ifdef FEAT_DIFF |
| 10789 | wp->w_ru_topfill = wp->w_topfill; |
| 10790 | #endif |
| 10791 | } |
| 10792 | } |
| 10793 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10794 | |
| 10795 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10796 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10797 | * Return the width of the 'number' and 'relativenumber' column. |
| 10798 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10799 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10800 | */ |
| 10801 | int |
| 10802 | number_width(wp) |
| 10803 | win_T *wp; |
| 10804 | { |
| 10805 | int n; |
| 10806 | linenr_T lnum; |
| 10807 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10808 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10809 | /* cursor line shows "0" */ |
| 10810 | lnum = wp->w_height; |
| 10811 | else |
| 10812 | /* cursor line shows absolute line number */ |
| 10813 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10814 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10815 | if (lnum == wp->w_nrwidth_line_count && wp->w_nuw_cached == wp->w_p_nuw) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10816 | return wp->w_nrwidth_width; |
| 10817 | wp->w_nrwidth_line_count = lnum; |
| 10818 | |
| 10819 | n = 0; |
| 10820 | do |
| 10821 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10822 | lnum /= 10; |
| 10823 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10824 | } while (lnum > 0); |
| 10825 | |
| 10826 | /* 'numberwidth' gives the minimal width plus one */ |
| 10827 | if (n < wp->w_p_nuw - 1) |
| 10828 | n = wp->w_p_nuw - 1; |
| 10829 | |
| 10830 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10831 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10832 | return n; |
| 10833 | } |
| 10834 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10835 | |
| 10836 | /* |
| 10837 | * Return the current cursor column. This is the actual position on the |
| 10838 | * screen. First column is 0. |
| 10839 | */ |
| 10840 | int |
| 10841 | screen_screencol() |
| 10842 | { |
| 10843 | return screen_cur_col; |
| 10844 | } |
| 10845 | |
| 10846 | /* |
| 10847 | * Return the current cursor row. This is the actual position on the screen. |
| 10848 | * First row is 0. |
| 10849 | */ |
| 10850 | int |
| 10851 | screen_screenrow() |
| 10852 | { |
| 10853 | return screen_cur_row; |
| 10854 | } |