Bram Moolenaar | edf3f97 | 2016-08-29 22:49:24 +0200 | [diff] [blame] | 1 | /* vi:set ts=8 sts=4 sw=4 noet: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 136 | #ifdef FEAT_WINDOWS |
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 | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 159 | #ifdef FEAT_WINDOWS |
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 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 173 | #ifdef FEAT_WINDOWS |
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 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 183 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 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 |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 194 | redraw_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 195 | { |
| 196 | redraw_win_later(curwin, type); |
| 197 | } |
| 198 | |
| 199 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 200 | redraw_win_later( |
| 201 | win_T *wp, |
| 202 | int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 203 | { |
| 204 | if (wp->w_redr_type < type) |
| 205 | { |
| 206 | wp->w_redr_type = type; |
| 207 | if (type >= NOT_VALID) |
| 208 | wp->w_lines_valid = 0; |
| 209 | if (must_redraw < type) /* must_redraw is the maximum of all windows */ |
| 210 | must_redraw = type; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | /* |
| 215 | * Force a complete redraw later. Also resets the highlighting. To be used |
| 216 | * after executing a shell command that messes up the screen. |
| 217 | */ |
| 218 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 219 | redraw_later_clear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 220 | { |
| 221 | redraw_all_later(CLEAR); |
Bram Moolenaar | 4c3f536 | 2006-04-11 21:38:50 +0000 | [diff] [blame] | 222 | #ifdef FEAT_GUI |
| 223 | if (gui.in_use) |
| 224 | /* Use a code that will reset gui.highlight_mask in |
| 225 | * gui_stop_highlight(). */ |
| 226 | screen_attr = HL_ALL + 1; |
| 227 | else |
| 228 | #endif |
| 229 | /* Use attributes that is very unlikely to appear in text. */ |
| 230 | screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /* |
| 234 | * Mark all windows to be redrawn later. |
| 235 | */ |
| 236 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 237 | redraw_all_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 238 | { |
| 239 | win_T *wp; |
| 240 | |
| 241 | FOR_ALL_WINDOWS(wp) |
| 242 | { |
| 243 | redraw_win_later(wp, type); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | /* |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 248 | * 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] | 249 | */ |
| 250 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 251 | redraw_curbuf_later(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 252 | { |
| 253 | redraw_buf_later(curbuf, type); |
| 254 | } |
| 255 | |
| 256 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 257 | redraw_buf_later(buf_T *buf, int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 258 | { |
| 259 | win_T *wp; |
| 260 | |
| 261 | FOR_ALL_WINDOWS(wp) |
| 262 | { |
| 263 | if (wp->w_buffer == buf) |
| 264 | redraw_win_later(wp, type); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /* |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 269 | * Redraw as soon as possible. When the command line is not scrolled redraw |
| 270 | * right away and restore what was on the command line. |
| 271 | * Return a code indicating what happened. |
| 272 | */ |
| 273 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 274 | redraw_asap(int type) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 275 | { |
| 276 | int rows; |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 277 | int cols = screen_Columns; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 278 | int r; |
| 279 | int ret = 0; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 280 | schar_T *screenline; /* copy from ScreenLines[] */ |
| 281 | sattr_T *screenattr; /* copy from ScreenAttrs[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 282 | #ifdef FEAT_MBYTE |
| 283 | int i; |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 284 | u8char_T *screenlineUC = NULL; /* copy from ScreenLinesUC[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 285 | u8char_T *screenlineC[MAX_MCO]; /* copy from ScreenLinesC[][] */ |
Bram Moolenaar | e1fc4e2 | 2013-07-03 13:29:58 +0200 | [diff] [blame] | 286 | schar_T *screenline2 = NULL; /* copy from ScreenLines2[] */ |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 287 | #endif |
| 288 | |
| 289 | redraw_later(type); |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 290 | if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting) |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 291 | return ret; |
| 292 | |
| 293 | /* Allocate space to save the text displayed in the command line area. */ |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 294 | rows = screen_Rows - cmdline_row; |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 295 | screenline = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 296 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 297 | screenattr = (sattr_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 298 | (long_u)(rows * cols * sizeof(sattr_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 299 | if (screenline == NULL || screenattr == NULL) |
| 300 | ret = 2; |
| 301 | #ifdef FEAT_MBYTE |
| 302 | if (enc_utf8) |
| 303 | { |
| 304 | screenlineUC = (u8char_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 305 | (long_u)(rows * cols * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 306 | if (screenlineUC == NULL) |
| 307 | ret = 2; |
| 308 | for (i = 0; i < p_mco; ++i) |
| 309 | { |
| 310 | screenlineC[i] = (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 (screenlineC[i] == NULL) |
| 313 | ret = 2; |
| 314 | } |
| 315 | } |
| 316 | if (enc_dbcs == DBCS_JPNU) |
| 317 | { |
| 318 | screenline2 = (schar_T *)lalloc( |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 319 | (long_u)(rows * cols * sizeof(schar_T)), FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 320 | if (screenline2 == NULL) |
| 321 | ret = 2; |
| 322 | } |
| 323 | #endif |
| 324 | |
| 325 | if (ret != 2) |
| 326 | { |
| 327 | /* Save the text displayed in the command line area. */ |
| 328 | for (r = 0; r < rows; ++r) |
| 329 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 330 | mch_memmove(screenline + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 331 | ScreenLines + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 332 | (size_t)cols * sizeof(schar_T)); |
| 333 | mch_memmove(screenattr + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 334 | ScreenAttrs + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 335 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 336 | #ifdef FEAT_MBYTE |
| 337 | if (enc_utf8) |
| 338 | { |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 339 | mch_memmove(screenlineUC + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 340 | ScreenLinesUC + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 341 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 342 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 343 | mch_memmove(screenlineC[i] + r * cols, |
| 344 | ScreenLinesC[i] + LineOffset[cmdline_row + r], |
| 345 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 346 | } |
| 347 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 348 | mch_memmove(screenline2 + r * cols, |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 349 | ScreenLines2 + LineOffset[cmdline_row + r], |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 350 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 351 | #endif |
| 352 | } |
| 353 | |
| 354 | update_screen(0); |
| 355 | ret = 3; |
| 356 | |
| 357 | if (must_redraw == 0) |
| 358 | { |
| 359 | int off = (int)(current_ScreenLine - ScreenLines); |
| 360 | |
| 361 | /* Restore the text displayed in the command line area. */ |
| 362 | for (r = 0; r < rows; ++r) |
| 363 | { |
| 364 | mch_memmove(current_ScreenLine, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 365 | screenline + r * cols, |
| 366 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 367 | mch_memmove(ScreenAttrs + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 368 | screenattr + r * cols, |
| 369 | (size_t)cols * sizeof(sattr_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 370 | #ifdef FEAT_MBYTE |
| 371 | if (enc_utf8) |
| 372 | { |
| 373 | mch_memmove(ScreenLinesUC + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 374 | screenlineUC + r * cols, |
| 375 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 376 | for (i = 0; i < p_mco; ++i) |
| 377 | mch_memmove(ScreenLinesC[i] + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 378 | screenlineC[i] + r * cols, |
| 379 | (size_t)cols * sizeof(u8char_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 380 | } |
| 381 | if (enc_dbcs == DBCS_JPNU) |
| 382 | mch_memmove(ScreenLines2 + off, |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 383 | screenline2 + r * cols, |
| 384 | (size_t)cols * sizeof(schar_T)); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 385 | #endif |
Bram Moolenaar | 5f95f28 | 2015-07-25 22:53:00 +0200 | [diff] [blame] | 386 | SCREEN_LINE(cmdline_row + r, 0, cols, cols, FALSE); |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 387 | } |
| 388 | ret = 4; |
| 389 | } |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | vim_free(screenline); |
| 393 | vim_free(screenattr); |
| 394 | #ifdef FEAT_MBYTE |
| 395 | if (enc_utf8) |
| 396 | { |
| 397 | vim_free(screenlineUC); |
| 398 | for (i = 0; i < p_mco; ++i) |
| 399 | vim_free(screenlineC[i]); |
| 400 | } |
| 401 | if (enc_dbcs == DBCS_JPNU) |
| 402 | vim_free(screenline2); |
| 403 | #endif |
| 404 | |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 405 | /* Show the intro message when appropriate. */ |
| 406 | maybe_intro_message(); |
| 407 | |
| 408 | setcursor(); |
| 409 | |
Bram Moolenaar | 2951b77 | 2013-07-03 12:45:31 +0200 | [diff] [blame] | 410 | return ret; |
| 411 | } |
| 412 | |
| 413 | /* |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 414 | * Invoked after an asynchronous callback is called. |
| 415 | * If an echo command was used the cursor needs to be put back where |
| 416 | * it belongs. If highlighting was changed a redraw is needed. |
| 417 | */ |
| 418 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 419 | redraw_after_callback(void) |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 420 | { |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 421 | if (State == HITRETURN || State == ASKMORE) |
| 422 | ; /* do nothing */ |
| 423 | else if (State & CMDLINE) |
| 424 | redrawcmdline(); |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 425 | else if (State & (NORMAL | INSERT)) |
Bram Moolenaar | bfb96c0 | 2016-03-19 17:05:20 +0100 | [diff] [blame] | 426 | { |
| 427 | update_screen(0); |
| 428 | setcursor(); |
| 429 | } |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 430 | cursor_on(); |
| 431 | out_flush(); |
| 432 | #ifdef FEAT_GUI |
| 433 | if (gui.in_use) |
| 434 | { |
Bram Moolenaar | 9d5d3c9 | 2016-07-07 16:43:02 +0200 | [diff] [blame] | 435 | /* Don't update the cursor when it is blinking and off to avoid |
| 436 | * flicker. */ |
| 437 | if (!gui_mch_is_blink_off()) |
Bram Moolenaar | 703a804 | 2016-06-04 16:24:32 +0200 | [diff] [blame] | 438 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 975b527 | 2016-03-15 23:10:59 +0100 | [diff] [blame] | 439 | gui_mch_flush(); |
| 440 | } |
| 441 | #endif |
| 442 | } |
| 443 | |
| 444 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 445 | * Changed something in the current window, at buffer line "lnum", that |
| 446 | * requires that line and possibly other lines to be redrawn. |
| 447 | * Used when entering/leaving Insert mode with the cursor on a folded line. |
| 448 | * Used to remove the "$" from a change command. |
| 449 | * Note that when also inserting/deleting lines w_redraw_top and w_redraw_bot |
| 450 | * may become invalid and the whole window will have to be redrawn. |
| 451 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 452 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 453 | redrawWinline( |
| 454 | linenr_T lnum, |
| 455 | int invalid UNUSED) /* window line height is invalid now */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 456 | { |
| 457 | #ifdef FEAT_FOLDING |
| 458 | int i; |
| 459 | #endif |
| 460 | |
| 461 | if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum) |
| 462 | curwin->w_redraw_top = lnum; |
| 463 | if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum) |
| 464 | curwin->w_redraw_bot = lnum; |
| 465 | redraw_later(VALID); |
| 466 | |
| 467 | #ifdef FEAT_FOLDING |
| 468 | if (invalid) |
| 469 | { |
| 470 | /* A w_lines[] entry for this lnum has become invalid. */ |
| 471 | i = find_wl_entry(curwin, lnum); |
| 472 | if (i >= 0) |
| 473 | curwin->w_lines[i].wl_valid = FALSE; |
| 474 | } |
| 475 | #endif |
| 476 | } |
| 477 | |
| 478 | /* |
| 479 | * update all windows that are editing the current buffer |
| 480 | */ |
| 481 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 482 | update_curbuf(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 483 | { |
| 484 | redraw_curbuf_later(type); |
| 485 | update_screen(type); |
| 486 | } |
| 487 | |
| 488 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 489 | * Based on the current value of curwin->w_topline, transfer a screenfull |
| 490 | * of stuff from Filemem to ScreenLines[], and update curwin->w_botline. |
| 491 | */ |
| 492 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 493 | update_screen(int type) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 494 | { |
| 495 | win_T *wp; |
| 496 | static int did_intro = FALSE; |
| 497 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 498 | int did_one; |
| 499 | #endif |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 500 | #ifdef FEAT_GUI |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 501 | int did_undraw = FALSE; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 502 | int gui_cursor_col; |
| 503 | int gui_cursor_row; |
| 504 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 505 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 506 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 507 | if (!screen_valid(TRUE)) |
| 508 | return; |
| 509 | |
| 510 | if (must_redraw) |
| 511 | { |
| 512 | if (type < must_redraw) /* use maximal type */ |
| 513 | type = must_redraw; |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 514 | |
| 515 | /* must_redraw is reset here, so that when we run into some weird |
| 516 | * reason to redraw while busy redrawing (e.g., asynchronous |
| 517 | * scrolling), or update_topline() in win_update() will cause a |
| 518 | * scroll, the screen will be redrawn later or in win_update(). */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 519 | must_redraw = 0; |
| 520 | } |
| 521 | |
| 522 | /* Need to update w_lines[]. */ |
| 523 | if (curwin->w_lines_valid == 0 && type < NOT_VALID) |
| 524 | type = NOT_VALID; |
| 525 | |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 526 | /* Postpone the redrawing when it's not needed and when being called |
| 527 | * recursively. */ |
| 528 | if (!redrawing() || updating_screen) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 529 | { |
| 530 | redraw_later(type); /* remember type for next time */ |
| 531 | must_redraw = type; |
| 532 | if (type > INVERTED_ALL) |
| 533 | curwin->w_lines_valid = 0; /* don't use w_lines[].wl_size now */ |
| 534 | return; |
| 535 | } |
| 536 | |
| 537 | updating_screen = TRUE; |
| 538 | #ifdef FEAT_SYN_HL |
| 539 | ++display_tick; /* let syntax code know we're in a next round of |
| 540 | * display updating */ |
| 541 | #endif |
| 542 | |
| 543 | /* |
| 544 | * if the screen was scrolled up when displaying a message, scroll it down |
| 545 | */ |
| 546 | if (msg_scrolled) |
| 547 | { |
| 548 | clear_cmdline = TRUE; |
| 549 | if (msg_scrolled > Rows - 5) /* clearing is faster */ |
| 550 | type = CLEAR; |
| 551 | else if (type != CLEAR) |
| 552 | { |
| 553 | check_for_delay(FALSE); |
| 554 | if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, NULL) == FAIL) |
| 555 | type = CLEAR; |
| 556 | FOR_ALL_WINDOWS(wp) |
| 557 | { |
| 558 | if (W_WINROW(wp) < msg_scrolled) |
| 559 | { |
| 560 | if (W_WINROW(wp) + wp->w_height > msg_scrolled |
| 561 | && wp->w_redr_type < REDRAW_TOP |
| 562 | && wp->w_lines_valid > 0 |
| 563 | && wp->w_topline == wp->w_lines[0].wl_lnum) |
| 564 | { |
| 565 | wp->w_upd_rows = msg_scrolled - W_WINROW(wp); |
| 566 | wp->w_redr_type = REDRAW_TOP; |
| 567 | } |
| 568 | else |
| 569 | { |
| 570 | wp->w_redr_type = NOT_VALID; |
| 571 | #ifdef FEAT_WINDOWS |
| 572 | if (W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp) |
| 573 | <= msg_scrolled) |
| 574 | wp->w_redr_status = TRUE; |
| 575 | #endif |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | redraw_cmdline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 580 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 581 | redraw_tabline = TRUE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 582 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 583 | } |
| 584 | msg_scrolled = 0; |
| 585 | need_wait_return = FALSE; |
| 586 | } |
| 587 | |
| 588 | /* reset cmdline_row now (may have been changed temporarily) */ |
| 589 | compute_cmdrow(); |
| 590 | |
| 591 | /* Check for changed highlighting */ |
| 592 | if (need_highlight_changed) |
| 593 | highlight_changed(); |
| 594 | |
| 595 | if (type == CLEAR) /* first clear screen */ |
| 596 | { |
| 597 | screenclear(); /* will reset clear_cmdline */ |
| 598 | type = NOT_VALID; |
| 599 | } |
| 600 | |
| 601 | if (clear_cmdline) /* going to clear cmdline (done below) */ |
| 602 | check_for_delay(FALSE); |
| 603 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 604 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 605 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 606 | * changes. */ |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 607 | if (curwin->w_redr_type < NOT_VALID |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 608 | && curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu) |
| 609 | ? number_width(curwin) : 0)) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 610 | curwin->w_redr_type = NOT_VALID; |
| 611 | #endif |
| 612 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 613 | /* |
| 614 | * Only start redrawing if there is really something to do. |
| 615 | */ |
| 616 | if (type == INVERTED) |
| 617 | update_curswant(); |
| 618 | if (curwin->w_redr_type < type |
| 619 | && !((type == VALID |
| 620 | && curwin->w_lines[0].wl_valid |
| 621 | #ifdef FEAT_DIFF |
| 622 | && curwin->w_topfill == curwin->w_old_topfill |
| 623 | && curwin->w_botfill == curwin->w_old_botfill |
| 624 | #endif |
| 625 | && curwin->w_topline == curwin->w_lines[0].wl_lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 626 | || (type == INVERTED |
Bram Moolenaar | b0c9a85 | 2006-11-28 15:14:56 +0000 | [diff] [blame] | 627 | && VIsual_active |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 628 | && curwin->w_old_cursor_lnum == curwin->w_cursor.lnum |
| 629 | && curwin->w_old_visual_mode == VIsual_mode |
| 630 | && (curwin->w_valid & VALID_VIRTCOL) |
| 631 | && curwin->w_old_curswant == curwin->w_curswant) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 632 | )) |
| 633 | curwin->w_redr_type = type; |
| 634 | |
Bram Moolenaar | 5a30542 | 2006-04-28 22:38:25 +0000 | [diff] [blame] | 635 | #ifdef FEAT_WINDOWS |
| 636 | /* Redraw the tab pages line if needed. */ |
| 637 | if (redraw_tabline || type >= NOT_VALID) |
| 638 | draw_tabline(); |
| 639 | #endif |
| 640 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 641 | #ifdef FEAT_SYN_HL |
| 642 | /* |
| 643 | * Correct stored syntax highlighting info for changes in each displayed |
| 644 | * buffer. Each buffer must only be done once. |
| 645 | */ |
| 646 | FOR_ALL_WINDOWS(wp) |
| 647 | { |
| 648 | if (wp->w_buffer->b_mod_set) |
| 649 | { |
| 650 | # ifdef FEAT_WINDOWS |
| 651 | win_T *wwp; |
| 652 | |
| 653 | /* Check if we already did this buffer. */ |
| 654 | for (wwp = firstwin; wwp != wp; wwp = wwp->w_next) |
| 655 | if (wwp->w_buffer == wp->w_buffer) |
| 656 | break; |
| 657 | # endif |
| 658 | if ( |
| 659 | # ifdef FEAT_WINDOWS |
| 660 | wwp == wp && |
| 661 | # endif |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 662 | syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 663 | syn_stack_apply_changes(wp->w_buffer); |
| 664 | } |
| 665 | } |
| 666 | #endif |
| 667 | |
| 668 | /* |
| 669 | * Go from top to bottom through the windows, redrawing the ones that need |
| 670 | * it. |
| 671 | */ |
| 672 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 673 | did_one = FALSE; |
| 674 | #endif |
| 675 | #ifdef FEAT_SEARCH_EXTRA |
| 676 | search_hl.rm.regprog = NULL; |
| 677 | #endif |
| 678 | FOR_ALL_WINDOWS(wp) |
| 679 | { |
| 680 | if (wp->w_redr_type != 0) |
| 681 | { |
| 682 | cursor_off(); |
| 683 | #if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD) |
| 684 | if (!did_one) |
| 685 | { |
| 686 | did_one = TRUE; |
| 687 | # ifdef FEAT_SEARCH_EXTRA |
| 688 | start_search_hl(); |
| 689 | # endif |
| 690 | # ifdef FEAT_CLIPBOARD |
| 691 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 692 | if (clip_star.available && clip_isautosel_star()) |
| 693 | clip_update_selection(&clip_star); |
| 694 | if (clip_plus.available && clip_isautosel_plus()) |
| 695 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 696 | # endif |
| 697 | #ifdef FEAT_GUI |
| 698 | /* Remove the cursor before starting to do anything, because |
| 699 | * scrolling may make it difficult to redraw the text under |
| 700 | * it. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 701 | if (gui.in_use && wp == curwin) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 702 | { |
| 703 | gui_cursor_col = gui.cursor_col; |
| 704 | gui_cursor_row = gui.cursor_row; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 705 | gui_undraw_cursor(); |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 706 | did_undraw = TRUE; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 707 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 708 | #endif |
| 709 | } |
| 710 | #endif |
| 711 | win_update(wp); |
| 712 | } |
| 713 | |
| 714 | #ifdef FEAT_WINDOWS |
| 715 | /* redraw status line after the window to minimize cursor movement */ |
| 716 | if (wp->w_redr_status) |
| 717 | { |
| 718 | cursor_off(); |
| 719 | win_redr_status(wp); |
| 720 | } |
| 721 | #endif |
| 722 | } |
| 723 | #if defined(FEAT_SEARCH_EXTRA) |
| 724 | end_search_hl(); |
| 725 | #endif |
Bram Moolenaar | 51971b3 | 2013-02-13 12:16:05 +0100 | [diff] [blame] | 726 | #ifdef FEAT_INS_EXPAND |
| 727 | /* May need to redraw the popup menu. */ |
| 728 | if (pum_visible()) |
| 729 | pum_redraw(); |
| 730 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 731 | |
| 732 | #ifdef FEAT_WINDOWS |
| 733 | /* Reset b_mod_set flags. Going through all windows is probably faster |
| 734 | * than going through all buffers (there could be many buffers). */ |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 735 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 736 | wp->w_buffer->b_mod_set = FALSE; |
| 737 | #else |
| 738 | curbuf->b_mod_set = FALSE; |
| 739 | #endif |
| 740 | |
| 741 | updating_screen = FALSE; |
| 742 | #ifdef FEAT_GUI |
| 743 | gui_may_resize_shell(); |
| 744 | #endif |
| 745 | |
| 746 | /* Clear or redraw the command line. Done last, because scrolling may |
| 747 | * mess up the command line. */ |
| 748 | if (clear_cmdline || redraw_cmdline) |
| 749 | showmode(); |
| 750 | |
| 751 | /* May put up an introductory message when not editing a file */ |
Bram Moolenaar | 249f0dd | 2013-07-04 22:31:03 +0200 | [diff] [blame] | 752 | if (!did_intro) |
| 753 | maybe_intro_message(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 754 | did_intro = TRUE; |
| 755 | |
| 756 | #ifdef FEAT_GUI |
| 757 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 758 | * done. */ |
| 759 | if (gui.in_use) |
| 760 | { |
| 761 | out_flush(); /* required before updating the cursor */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 762 | if (did_undraw && !gui_mch_is_blink_off()) |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 763 | { |
| 764 | /* Put the GUI position where the cursor was, gui_update_cursor() |
| 765 | * uses that. */ |
| 766 | gui.col = gui_cursor_col; |
| 767 | gui.row = gui_cursor_row; |
Bram Moolenaar | 84dbd49 | 2016-10-02 23:09:31 +0200 | [diff] [blame] | 768 | # ifdef FEAT_MBYTE |
| 769 | gui.col = mb_fix_col(gui.col, gui.row); |
| 770 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 771 | gui_update_cursor(FALSE, FALSE); |
Bram Moolenaar | 65549bd | 2016-07-08 22:52:37 +0200 | [diff] [blame] | 772 | screen_cur_col = gui.col; |
| 773 | screen_cur_row = gui.row; |
Bram Moolenaar | 144445d | 2016-07-08 21:41:54 +0200 | [diff] [blame] | 774 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 775 | gui_update_scrollbars(FALSE); |
| 776 | } |
| 777 | #endif |
| 778 | } |
| 779 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 780 | #if defined(FEAT_CONCEAL) || defined(PROTO) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 781 | /* |
| 782 | * Return TRUE if the cursor line in window "wp" may be concealed, according |
| 783 | * to the 'concealcursor' option. |
| 784 | */ |
| 785 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 786 | conceal_cursor_line(win_T *wp) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 787 | { |
| 788 | int c; |
| 789 | |
| 790 | if (*wp->w_p_cocu == NUL) |
| 791 | return FALSE; |
| 792 | if (get_real_state() & VISUAL) |
| 793 | c = 'v'; |
| 794 | else if (State & INSERT) |
| 795 | c = 'i'; |
| 796 | else if (State & NORMAL) |
| 797 | c = 'n'; |
Bram Moolenaar | ca8c986 | 2010-07-24 15:00:38 +0200 | [diff] [blame] | 798 | else if (State & CMDLINE) |
| 799 | c = 'c'; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 800 | else |
| 801 | return FALSE; |
| 802 | return vim_strchr(wp->w_p_cocu, c) != NULL; |
| 803 | } |
| 804 | |
| 805 | /* |
| 806 | * Check if the cursor line needs to be redrawn because of 'concealcursor'. |
| 807 | */ |
| 808 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 809 | conceal_check_cursur_line(void) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 810 | { |
| 811 | if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin)) |
| 812 | { |
| 813 | need_cursor_line_redraw = TRUE; |
| 814 | /* Need to recompute cursor column, e.g., when starting Visual mode |
| 815 | * without concealing. */ |
| 816 | curs_columns(TRUE); |
| 817 | } |
| 818 | } |
| 819 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 820 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 821 | update_single_line(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 822 | { |
| 823 | int row; |
| 824 | int j; |
| 825 | |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 826 | /* Don't do anything if the screen structures are (not yet) valid. */ |
Bram Moolenaar | 070b33d | 2017-01-31 21:53:39 +0100 | [diff] [blame] | 827 | if (!screen_valid(TRUE) || updating_screen) |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 828 | return; |
Bram Moolenaar | 070b33d | 2017-01-31 21:53:39 +0100 | [diff] [blame] | 829 | updating_screen = TRUE; |
Bram Moolenaar | 908be43 | 2016-05-24 10:51:30 +0200 | [diff] [blame] | 830 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 831 | if (lnum >= wp->w_topline && lnum < wp->w_botline |
Bram Moolenaar | 370df58 | 2010-06-22 05:16:38 +0200 | [diff] [blame] | 832 | && foldedCount(wp, lnum, &win_foldinfo) == 0) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 833 | { |
| 834 | # ifdef FEAT_GUI |
| 835 | /* Remove the cursor before starting to do anything, because scrolling |
| 836 | * may make it difficult to redraw the text under it. */ |
| 837 | if (gui.in_use) |
| 838 | gui_undraw_cursor(); |
| 839 | # endif |
| 840 | row = 0; |
| 841 | for (j = 0; j < wp->w_lines_valid; ++j) |
| 842 | { |
| 843 | if (lnum == wp->w_lines[j].wl_lnum) |
| 844 | { |
| 845 | screen_start(); /* not sure of screen cursor */ |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 846 | # ifdef FEAT_SEARCH_EXTRA |
| 847 | init_search_hl(wp); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 848 | start_search_hl(); |
| 849 | prepare_search_hl(wp, lnum); |
| 850 | # endif |
| 851 | win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE); |
| 852 | # if defined(FEAT_SEARCH_EXTRA) |
| 853 | end_search_hl(); |
| 854 | # endif |
| 855 | break; |
| 856 | } |
| 857 | row += wp->w_lines[j].wl_size; |
| 858 | } |
| 859 | # ifdef FEAT_GUI |
| 860 | /* Redraw the cursor */ |
| 861 | if (gui.in_use) |
| 862 | { |
| 863 | out_flush(); /* required before updating the cursor */ |
| 864 | gui_update_cursor(FALSE, FALSE); |
| 865 | } |
| 866 | # endif |
| 867 | } |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 868 | need_cursor_line_redraw = FALSE; |
Bram Moolenaar | 070b33d | 2017-01-31 21:53:39 +0100 | [diff] [blame] | 869 | updating_screen = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 870 | } |
| 871 | #endif |
| 872 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 873 | #if defined(FEAT_SIGNS) || defined(FEAT_GUI) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 874 | /* |
| 875 | * Prepare for updating one or more windows. |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 876 | * Caller must check for "updating_screen" already set to avoid recursiveness. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 877 | */ |
| 878 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 879 | update_prepare(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 880 | { |
| 881 | cursor_off(); |
| 882 | updating_screen = TRUE; |
| 883 | #ifdef FEAT_GUI |
| 884 | /* Remove the cursor before starting to do anything, because scrolling may |
| 885 | * make it difficult to redraw the text under it. */ |
| 886 | if (gui.in_use) |
| 887 | gui_undraw_cursor(); |
| 888 | #endif |
| 889 | #ifdef FEAT_SEARCH_EXTRA |
| 890 | start_search_hl(); |
| 891 | #endif |
| 892 | } |
| 893 | |
| 894 | /* |
| 895 | * Finish updating one or more windows. |
| 896 | */ |
| 897 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 898 | update_finish(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 899 | { |
| 900 | if (redraw_cmdline) |
| 901 | showmode(); |
| 902 | |
| 903 | # ifdef FEAT_SEARCH_EXTRA |
| 904 | end_search_hl(); |
| 905 | # endif |
| 906 | |
| 907 | updating_screen = FALSE; |
| 908 | |
| 909 | # ifdef FEAT_GUI |
| 910 | gui_may_resize_shell(); |
| 911 | |
| 912 | /* Redraw the cursor and update the scrollbars when all screen updating is |
| 913 | * done. */ |
| 914 | if (gui.in_use) |
| 915 | { |
| 916 | out_flush(); /* required before updating the cursor */ |
| 917 | gui_update_cursor(FALSE, FALSE); |
| 918 | gui_update_scrollbars(FALSE); |
| 919 | } |
| 920 | # endif |
| 921 | } |
| 922 | #endif |
| 923 | |
| 924 | #if defined(FEAT_SIGNS) || defined(PROTO) |
| 925 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 926 | update_debug_sign(buf_T *buf, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 927 | { |
| 928 | win_T *wp; |
| 929 | int doit = FALSE; |
| 930 | |
| 931 | # ifdef FEAT_FOLDING |
| 932 | win_foldinfo.fi_level = 0; |
| 933 | # endif |
| 934 | |
| 935 | /* update/delete a specific mark */ |
| 936 | FOR_ALL_WINDOWS(wp) |
| 937 | { |
| 938 | if (buf != NULL && lnum > 0) |
| 939 | { |
| 940 | if (wp->w_buffer == buf && lnum >= wp->w_topline |
| 941 | && lnum < wp->w_botline) |
| 942 | { |
| 943 | if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum) |
| 944 | wp->w_redraw_top = lnum; |
| 945 | if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum) |
| 946 | wp->w_redraw_bot = lnum; |
| 947 | redraw_win_later(wp, VALID); |
| 948 | } |
| 949 | } |
| 950 | else |
| 951 | redraw_win_later(wp, VALID); |
| 952 | if (wp->w_redr_type != 0) |
| 953 | doit = TRUE; |
| 954 | } |
| 955 | |
Bram Moolenaar | 738f8fc | 2012-01-10 12:42:09 +0100 | [diff] [blame] | 956 | /* Return when there is nothing to do, screen updating is already |
| 957 | * happening (recursive call) or still starting up. */ |
| 958 | if (!doit || updating_screen |
| 959 | #ifdef FEAT_GUI |
| 960 | || gui.starting |
| 961 | #endif |
| 962 | || starting) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 963 | return; |
| 964 | |
| 965 | /* update all windows that need updating */ |
| 966 | update_prepare(); |
| 967 | |
| 968 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 969 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 970 | { |
| 971 | if (wp->w_redr_type != 0) |
| 972 | win_update(wp); |
| 973 | if (wp->w_redr_status) |
| 974 | win_redr_status(wp); |
| 975 | } |
| 976 | # else |
| 977 | if (curwin->w_redr_type != 0) |
| 978 | win_update(curwin); |
| 979 | # endif |
| 980 | |
| 981 | update_finish(); |
| 982 | } |
| 983 | #endif |
| 984 | |
| 985 | |
| 986 | #if defined(FEAT_GUI) || defined(PROTO) |
| 987 | /* |
| 988 | * Update a single window, its status line and maybe the command line msg. |
| 989 | * Used for the GUI scrollbar. |
| 990 | */ |
| 991 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 992 | updateWindow(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 993 | { |
Bram Moolenaar | 19f990e | 2009-11-25 12:08:03 +0000 | [diff] [blame] | 994 | /* return if already busy updating */ |
| 995 | if (updating_screen) |
| 996 | return; |
| 997 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 998 | update_prepare(); |
| 999 | |
| 1000 | #ifdef FEAT_CLIPBOARD |
| 1001 | /* When Visual area changed, may have to update selection. */ |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 1002 | if (clip_star.available && clip_isautosel_star()) |
| 1003 | clip_update_selection(&clip_star); |
| 1004 | if (clip_plus.available && clip_isautosel_plus()) |
| 1005 | clip_update_selection(&clip_plus); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1006 | #endif |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1007 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1008 | win_update(wp); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1009 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1010 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1011 | /* When the screen was cleared redraw the tab pages line. */ |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 1012 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1013 | draw_tabline(); |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 1014 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1015 | if (wp->w_redr_status |
| 1016 | # ifdef FEAT_CMDL_INFO |
| 1017 | || p_ru |
| 1018 | # endif |
| 1019 | # ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 1020 | || *p_stl != NUL || *wp->w_p_stl != NUL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1021 | # endif |
| 1022 | ) |
| 1023 | win_redr_status(wp); |
| 1024 | #endif |
| 1025 | |
| 1026 | update_finish(); |
| 1027 | } |
| 1028 | #endif |
| 1029 | |
| 1030 | /* |
| 1031 | * Update a single window. |
| 1032 | * |
| 1033 | * This may cause the windows below it also to be redrawn (when clearing the |
| 1034 | * screen or scrolling lines). |
| 1035 | * |
| 1036 | * How the window is redrawn depends on wp->w_redr_type. Each type also |
| 1037 | * implies the one below it. |
| 1038 | * NOT_VALID redraw the whole window |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1039 | * SOME_VALID redraw the whole window but do scroll when possible |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1040 | * REDRAW_TOP redraw the top w_upd_rows window lines, otherwise like VALID |
| 1041 | * INVERTED redraw the changed part of the Visual area |
| 1042 | * INVERTED_ALL redraw the whole Visual area |
| 1043 | * VALID 1. scroll up/down to adjust for a changed w_topline |
| 1044 | * 2. update lines at the top when scrolled down |
| 1045 | * 3. redraw changed text: |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 1046 | * - if wp->w_buffer->b_mod_set set, update lines between |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1047 | * b_mod_top and b_mod_bot. |
| 1048 | * - if wp->w_redraw_top non-zero, redraw lines between |
| 1049 | * wp->w_redraw_top and wp->w_redr_bot. |
| 1050 | * - continue redrawing when syntax status is invalid. |
| 1051 | * 4. if scrolled up, update lines at the bottom. |
| 1052 | * This results in three areas that may need updating: |
| 1053 | * top: from first row to top_end (when scrolled down) |
| 1054 | * mid: from mid_start to mid_end (update inversion or changed text) |
| 1055 | * bot: from bot_start to last row (when scrolled up) |
| 1056 | */ |
| 1057 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 1058 | win_update(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1059 | { |
| 1060 | buf_T *buf = wp->w_buffer; |
| 1061 | int type; |
| 1062 | int top_end = 0; /* Below last row of the top area that needs |
| 1063 | updating. 0 when no top area updating. */ |
| 1064 | int mid_start = 999;/* first row of the mid area that needs |
| 1065 | updating. 999 when no mid area updating. */ |
| 1066 | int mid_end = 0; /* Below last row of the mid area that needs |
| 1067 | updating. 0 when no mid area updating. */ |
| 1068 | int bot_start = 999;/* first row of the bot area that needs |
| 1069 | updating. 999 when no bot area updating */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1070 | int scrolled_down = FALSE; /* TRUE when scrolled down when |
| 1071 | w_topline got smaller a bit */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1072 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1073 | matchitem_T *cur; /* points to the match list */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1074 | int top_to_mod = FALSE; /* redraw above mod_top */ |
| 1075 | #endif |
| 1076 | |
| 1077 | int row; /* current window row to display */ |
| 1078 | linenr_T lnum; /* current buffer lnum to display */ |
| 1079 | int idx; /* current index in w_lines[] */ |
| 1080 | int srow; /* starting row of the current line */ |
| 1081 | |
| 1082 | int eof = FALSE; /* if TRUE, we hit the end of the file */ |
| 1083 | int didline = FALSE; /* if TRUE, we finished the last line */ |
| 1084 | int i; |
| 1085 | long j; |
| 1086 | static int recursive = FALSE; /* being called recursively */ |
| 1087 | int old_botline = wp->w_botline; |
| 1088 | #ifdef FEAT_FOLDING |
| 1089 | long fold_count; |
| 1090 | #endif |
| 1091 | #ifdef FEAT_SYN_HL |
| 1092 | /* remember what happened to the previous line, to know if |
| 1093 | * check_visual_highlight() can be used */ |
| 1094 | #define DID_NONE 1 /* didn't update a line */ |
| 1095 | #define DID_LINE 2 /* updated a normal line */ |
| 1096 | #define DID_FOLD 3 /* updated a folded line */ |
| 1097 | int did_update = DID_NONE; |
| 1098 | linenr_T syntax_last_parsed = 0; /* last parsed text line */ |
| 1099 | #endif |
| 1100 | linenr_T mod_top = 0; |
| 1101 | linenr_T mod_bot = 0; |
| 1102 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1103 | int save_got_int; |
| 1104 | #endif |
| 1105 | |
| 1106 | type = wp->w_redr_type; |
| 1107 | |
| 1108 | if (type == NOT_VALID) |
| 1109 | { |
| 1110 | #ifdef FEAT_WINDOWS |
| 1111 | wp->w_redr_status = TRUE; |
| 1112 | #endif |
| 1113 | wp->w_lines_valid = 0; |
| 1114 | } |
| 1115 | |
| 1116 | /* Window is zero-height: nothing to draw. */ |
| 1117 | if (wp->w_height == 0) |
| 1118 | { |
| 1119 | wp->w_redr_type = 0; |
| 1120 | return; |
| 1121 | } |
| 1122 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 1123 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1124 | /* Window is zero-width: Only need to draw the separator. */ |
| 1125 | if (wp->w_width == 0) |
| 1126 | { |
| 1127 | /* draw the vertical separator right of this window */ |
| 1128 | draw_vsep_win(wp, 0); |
| 1129 | wp->w_redr_type = 0; |
| 1130 | return; |
| 1131 | } |
| 1132 | #endif |
| 1133 | |
| 1134 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 1135 | init_search_hl(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1136 | #endif |
| 1137 | |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1138 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 1139 | /* Force redraw when width of 'number' or 'relativenumber' column |
| 1140 | * changes. */ |
| 1141 | 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] | 1142 | if (wp->w_nrwidth != i) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1143 | { |
| 1144 | type = NOT_VALID; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 1145 | wp->w_nrwidth = i; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 1146 | } |
| 1147 | else |
| 1148 | #endif |
| 1149 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1150 | if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0) |
| 1151 | { |
| 1152 | /* |
| 1153 | * When there are both inserted/deleted lines and specific lines to be |
| 1154 | * redrawn, w_redraw_top and w_redraw_bot may be invalid, just redraw |
| 1155 | * everything (only happens when redrawing is off for while). |
| 1156 | */ |
| 1157 | type = NOT_VALID; |
| 1158 | } |
| 1159 | else |
| 1160 | { |
| 1161 | /* |
| 1162 | * Set mod_top to the first line that needs displaying because of |
| 1163 | * changes. Set mod_bot to the first line after the changes. |
| 1164 | */ |
| 1165 | mod_top = wp->w_redraw_top; |
| 1166 | if (wp->w_redraw_bot != 0) |
| 1167 | mod_bot = wp->w_redraw_bot + 1; |
| 1168 | else |
| 1169 | mod_bot = 0; |
| 1170 | wp->w_redraw_top = 0; /* reset for next time */ |
| 1171 | wp->w_redraw_bot = 0; |
| 1172 | if (buf->b_mod_set) |
| 1173 | { |
| 1174 | if (mod_top == 0 || mod_top > buf->b_mod_top) |
| 1175 | { |
| 1176 | mod_top = buf->b_mod_top; |
| 1177 | #ifdef FEAT_SYN_HL |
| 1178 | /* Need to redraw lines above the change that may be included |
| 1179 | * in a pattern match. */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1180 | if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1181 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1182 | mod_top -= buf->b_s.b_syn_sync_linebreaks; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1183 | if (mod_top < 1) |
| 1184 | mod_top = 1; |
| 1185 | } |
| 1186 | #endif |
| 1187 | } |
| 1188 | if (mod_bot == 0 || mod_bot < buf->b_mod_bot) |
| 1189 | mod_bot = buf->b_mod_bot; |
| 1190 | |
| 1191 | #ifdef FEAT_SEARCH_EXTRA |
| 1192 | /* When 'hlsearch' is on and using a multi-line search pattern, a |
| 1193 | * change in one line may make the Search highlighting in a |
| 1194 | * previous line invalid. Simple solution: redraw all visible |
| 1195 | * lines above the change. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1196 | * Same for a match pattern. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1197 | */ |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1198 | if (search_hl.rm.regprog != NULL |
| 1199 | && re_multiline(search_hl.rm.regprog)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1200 | top_to_mod = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1201 | else |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1202 | { |
| 1203 | cur = wp->w_match_head; |
| 1204 | while (cur != NULL) |
| 1205 | { |
| 1206 | if (cur->match.regprog != NULL |
| 1207 | && re_multiline(cur->match.regprog)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 1208 | { |
| 1209 | top_to_mod = TRUE; |
| 1210 | break; |
| 1211 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 1212 | cur = cur->next; |
| 1213 | } |
| 1214 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1215 | #endif |
| 1216 | } |
| 1217 | #ifdef FEAT_FOLDING |
| 1218 | if (mod_top != 0 && hasAnyFolding(wp)) |
| 1219 | { |
| 1220 | linenr_T lnumt, lnumb; |
| 1221 | |
| 1222 | /* |
| 1223 | * A change in a line can cause lines above it to become folded or |
| 1224 | * unfolded. Find the top most buffer line that may be affected. |
| 1225 | * If the line was previously folded and displayed, get the first |
| 1226 | * line of that fold. If the line is folded now, get the first |
| 1227 | * folded line. Use the minimum of these two. |
| 1228 | */ |
| 1229 | |
| 1230 | /* Find last valid w_lines[] entry above mod_top. Set lnumt to |
| 1231 | * the line below it. If there is no valid entry, use w_topline. |
| 1232 | * Find the first valid w_lines[] entry below mod_bot. Set lnumb |
| 1233 | * to this line. If there is no valid entry, use MAXLNUM. */ |
| 1234 | lnumt = wp->w_topline; |
| 1235 | lnumb = MAXLNUM; |
| 1236 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1237 | if (wp->w_lines[i].wl_valid) |
| 1238 | { |
| 1239 | if (wp->w_lines[i].wl_lastlnum < mod_top) |
| 1240 | lnumt = wp->w_lines[i].wl_lastlnum + 1; |
| 1241 | if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot) |
| 1242 | { |
| 1243 | lnumb = wp->w_lines[i].wl_lnum; |
| 1244 | /* When there is a fold column it might need updating |
| 1245 | * in the next line ("J" just above an open fold). */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 1246 | if (compute_foldcolumn(wp, 0) > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1247 | ++lnumb; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | (void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL); |
| 1252 | if (mod_top > lnumt) |
| 1253 | mod_top = lnumt; |
| 1254 | |
| 1255 | /* Now do the same for the bottom line (one above mod_bot). */ |
| 1256 | --mod_bot; |
| 1257 | (void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL); |
| 1258 | ++mod_bot; |
| 1259 | if (mod_bot < lnumb) |
| 1260 | mod_bot = lnumb; |
| 1261 | } |
| 1262 | #endif |
| 1263 | |
| 1264 | /* When a change starts above w_topline and the end is below |
| 1265 | * w_topline, start redrawing at w_topline. |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1266 | * If the end of the change is above w_topline: do like no change was |
| 1267 | * made, but redraw the first line to find changes in syntax. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1268 | if (mod_top != 0 && mod_top < wp->w_topline) |
| 1269 | { |
| 1270 | if (mod_bot > wp->w_topline) |
| 1271 | mod_top = wp->w_topline; |
| 1272 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1273 | else if (syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1274 | top_end = 1; |
| 1275 | #endif |
| 1276 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 1277 | |
| 1278 | /* When line numbers are displayed need to redraw all lines below |
| 1279 | * inserted/deleted lines. */ |
| 1280 | if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu) |
| 1281 | mod_bot = MAXLNUM; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | /* |
| 1285 | * When only displaying the lines at the top, set top_end. Used when |
| 1286 | * window has scrolled down for msg_scrolled. |
| 1287 | */ |
| 1288 | if (type == REDRAW_TOP) |
| 1289 | { |
| 1290 | j = 0; |
| 1291 | for (i = 0; i < wp->w_lines_valid; ++i) |
| 1292 | { |
| 1293 | j += wp->w_lines[i].wl_size; |
| 1294 | if (j >= wp->w_upd_rows) |
| 1295 | { |
| 1296 | top_end = j; |
| 1297 | break; |
| 1298 | } |
| 1299 | } |
| 1300 | if (top_end == 0) |
| 1301 | /* not found (cannot happen?): redraw everything */ |
| 1302 | type = NOT_VALID; |
| 1303 | else |
| 1304 | /* top area defined, the rest is VALID */ |
| 1305 | type = VALID; |
| 1306 | } |
| 1307 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 1308 | /* Trick: we want to avoid clearing the screen twice. screenclear() will |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1309 | * set "screen_cleared" to TRUE. The special value MAYBE (which is still |
| 1310 | * non-zero and thus not FALSE) will indicate that screenclear() was not |
| 1311 | * called. */ |
| 1312 | if (screen_cleared) |
| 1313 | screen_cleared = MAYBE; |
| 1314 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1315 | /* |
| 1316 | * If there are no changes on the screen that require a complete redraw, |
| 1317 | * handle three cases: |
| 1318 | * 1: we are off the top of the screen by a few lines: scroll down |
| 1319 | * 2: wp->w_topline is below wp->w_lines[0].wl_lnum: may scroll up |
| 1320 | * 3: wp->w_topline is wp->w_lines[0].wl_lnum: find first entry in |
| 1321 | * w_lines[] that needs updating. |
| 1322 | */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1323 | if ((type == VALID || type == SOME_VALID |
| 1324 | || type == INVERTED || type == INVERTED_ALL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1325 | #ifdef FEAT_DIFF |
| 1326 | && !wp->w_botfill && !wp->w_old_botfill |
| 1327 | #endif |
| 1328 | ) |
| 1329 | { |
| 1330 | if (mod_top != 0 && wp->w_topline == mod_top) |
| 1331 | { |
| 1332 | /* |
| 1333 | * w_topline is the first changed line, the scrolling will be done |
| 1334 | * further down. |
| 1335 | */ |
| 1336 | } |
| 1337 | else if (wp->w_lines[0].wl_valid |
| 1338 | && (wp->w_topline < wp->w_lines[0].wl_lnum |
| 1339 | #ifdef FEAT_DIFF |
| 1340 | || (wp->w_topline == wp->w_lines[0].wl_lnum |
| 1341 | && wp->w_topfill > wp->w_old_topfill) |
| 1342 | #endif |
| 1343 | )) |
| 1344 | { |
| 1345 | /* |
| 1346 | * New topline is above old topline: May scroll down. |
| 1347 | */ |
| 1348 | #ifdef FEAT_FOLDING |
| 1349 | if (hasAnyFolding(wp)) |
| 1350 | { |
| 1351 | linenr_T ln; |
| 1352 | |
| 1353 | /* count the number of lines we are off, counting a sequence |
| 1354 | * of folded lines as one */ |
| 1355 | j = 0; |
| 1356 | for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln) |
| 1357 | { |
| 1358 | ++j; |
| 1359 | if (j >= wp->w_height - 2) |
| 1360 | break; |
| 1361 | (void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL); |
| 1362 | } |
| 1363 | } |
| 1364 | else |
| 1365 | #endif |
| 1366 | j = wp->w_lines[0].wl_lnum - wp->w_topline; |
| 1367 | if (j < wp->w_height - 2) /* not too far off */ |
| 1368 | { |
| 1369 | i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1); |
| 1370 | #ifdef FEAT_DIFF |
| 1371 | /* insert extra lines for previously invisible filler lines */ |
| 1372 | if (wp->w_lines[0].wl_lnum != wp->w_topline) |
| 1373 | i += diff_check_fill(wp, wp->w_lines[0].wl_lnum) |
| 1374 | - wp->w_old_topfill; |
| 1375 | #endif |
| 1376 | if (i < wp->w_height - 2) /* less than a screen off */ |
| 1377 | { |
| 1378 | /* |
| 1379 | * Try to insert the correct number of lines. |
| 1380 | * If not the last window, delete the lines at the bottom. |
| 1381 | * win_ins_lines may fail when the terminal can't do it. |
| 1382 | */ |
| 1383 | if (i > 0) |
| 1384 | check_for_delay(FALSE); |
| 1385 | if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK) |
| 1386 | { |
| 1387 | if (wp->w_lines_valid != 0) |
| 1388 | { |
| 1389 | /* Need to update rows that are new, stop at the |
| 1390 | * first one that scrolled down. */ |
| 1391 | top_end = i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1392 | scrolled_down = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1393 | |
| 1394 | /* Move the entries that were scrolled, disable |
| 1395 | * the entries for the lines to be redrawn. */ |
| 1396 | if ((wp->w_lines_valid += j) > wp->w_height) |
| 1397 | wp->w_lines_valid = wp->w_height; |
| 1398 | for (idx = wp->w_lines_valid; idx - j >= 0; idx--) |
| 1399 | wp->w_lines[idx] = wp->w_lines[idx - j]; |
| 1400 | while (idx >= 0) |
| 1401 | wp->w_lines[idx--].wl_valid = FALSE; |
| 1402 | } |
| 1403 | } |
| 1404 | else |
| 1405 | mid_start = 0; /* redraw all lines */ |
| 1406 | } |
| 1407 | else |
| 1408 | mid_start = 0; /* redraw all lines */ |
| 1409 | } |
| 1410 | else |
| 1411 | mid_start = 0; /* redraw all lines */ |
| 1412 | } |
| 1413 | else |
| 1414 | { |
| 1415 | /* |
| 1416 | * New topline is at or below old topline: May scroll up. |
| 1417 | * When topline didn't change, find first entry in w_lines[] that |
| 1418 | * needs updating. |
| 1419 | */ |
| 1420 | |
| 1421 | /* try to find wp->w_topline in wp->w_lines[].wl_lnum */ |
| 1422 | j = -1; |
| 1423 | row = 0; |
| 1424 | for (i = 0; i < wp->w_lines_valid; i++) |
| 1425 | { |
| 1426 | if (wp->w_lines[i].wl_valid |
| 1427 | && wp->w_lines[i].wl_lnum == wp->w_topline) |
| 1428 | { |
| 1429 | j = i; |
| 1430 | break; |
| 1431 | } |
| 1432 | row += wp->w_lines[i].wl_size; |
| 1433 | } |
| 1434 | if (j == -1) |
| 1435 | { |
| 1436 | /* if wp->w_topline is not in wp->w_lines[].wl_lnum redraw all |
| 1437 | * lines */ |
| 1438 | mid_start = 0; |
| 1439 | } |
| 1440 | else |
| 1441 | { |
| 1442 | /* |
| 1443 | * Try to delete the correct number of lines. |
| 1444 | * wp->w_topline is at wp->w_lines[i].wl_lnum. |
| 1445 | */ |
| 1446 | #ifdef FEAT_DIFF |
| 1447 | /* If the topline didn't change, delete old filler lines, |
| 1448 | * otherwise delete filler lines of the new topline... */ |
| 1449 | if (wp->w_lines[0].wl_lnum == wp->w_topline) |
| 1450 | row += wp->w_old_topfill; |
| 1451 | else |
| 1452 | row += diff_check_fill(wp, wp->w_topline); |
| 1453 | /* ... but don't delete new filler lines. */ |
| 1454 | row -= wp->w_topfill; |
| 1455 | #endif |
| 1456 | if (row > 0) |
| 1457 | { |
| 1458 | check_for_delay(FALSE); |
| 1459 | if (win_del_lines(wp, 0, row, FALSE, wp == firstwin) == OK) |
| 1460 | bot_start = wp->w_height - row; |
| 1461 | else |
| 1462 | mid_start = 0; /* redraw all lines */ |
| 1463 | } |
| 1464 | if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0) |
| 1465 | { |
| 1466 | /* |
| 1467 | * Skip the lines (below the deleted lines) that are still |
| 1468 | * valid and don't need redrawing. Copy their info |
| 1469 | * upwards, to compensate for the deleted lines. Set |
| 1470 | * bot_start to the first row that needs redrawing. |
| 1471 | */ |
| 1472 | bot_start = 0; |
| 1473 | idx = 0; |
| 1474 | for (;;) |
| 1475 | { |
| 1476 | wp->w_lines[idx] = wp->w_lines[j]; |
| 1477 | /* stop at line that didn't fit, unless it is still |
| 1478 | * valid (no lines deleted) */ |
| 1479 | if (row > 0 && bot_start + row |
| 1480 | + (int)wp->w_lines[j].wl_size > wp->w_height) |
| 1481 | { |
| 1482 | wp->w_lines_valid = idx + 1; |
| 1483 | break; |
| 1484 | } |
| 1485 | bot_start += wp->w_lines[idx++].wl_size; |
| 1486 | |
| 1487 | /* stop at the last valid entry in w_lines[].wl_size */ |
| 1488 | if (++j >= wp->w_lines_valid) |
| 1489 | { |
| 1490 | wp->w_lines_valid = idx; |
| 1491 | break; |
| 1492 | } |
| 1493 | } |
| 1494 | #ifdef FEAT_DIFF |
| 1495 | /* Correct the first entry for filler lines at the top |
| 1496 | * when it won't get updated below. */ |
| 1497 | if (wp->w_p_diff && bot_start > 0) |
| 1498 | wp->w_lines[0].wl_size = |
| 1499 | plines_win_nofill(wp, wp->w_topline, TRUE) |
| 1500 | + wp->w_topfill; |
| 1501 | #endif |
| 1502 | } |
| 1503 | } |
| 1504 | } |
| 1505 | |
| 1506 | /* When starting redraw in the first line, redraw all lines. When |
| 1507 | * there is only one window it's probably faster to clear the screen |
| 1508 | * first. */ |
| 1509 | if (mid_start == 0) |
| 1510 | { |
| 1511 | mid_end = wp->w_height; |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 1512 | if (ONE_WINDOW) |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1513 | { |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1514 | /* Clear the screen when it was not done by win_del_lines() or |
| 1515 | * win_ins_lines() above, "screen_cleared" is FALSE or MAYBE |
| 1516 | * then. */ |
| 1517 | if (screen_cleared != TRUE) |
| 1518 | screenclear(); |
Bram Moolenaar | bc1a7c3 | 2006-09-14 19:04:14 +0000 | [diff] [blame] | 1519 | #ifdef FEAT_WINDOWS |
| 1520 | /* The screen was cleared, redraw the tab pages line. */ |
| 1521 | if (redraw_tabline) |
| 1522 | draw_tabline(); |
| 1523 | #endif |
| 1524 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1525 | } |
Bram Moolenaar | 943fae4 | 2007-07-30 20:00:38 +0000 | [diff] [blame] | 1526 | |
| 1527 | /* When win_del_lines() or win_ins_lines() caused the screen to be |
| 1528 | * cleared (only happens for the first window) or when screenclear() |
| 1529 | * was called directly above, "must_redraw" will have been set to |
| 1530 | * NOT_VALID, need to reset it here to avoid redrawing twice. */ |
| 1531 | if (screen_cleared == TRUE) |
| 1532 | must_redraw = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1533 | } |
| 1534 | else |
| 1535 | { |
| 1536 | /* Not VALID or INVERTED: redraw all lines. */ |
| 1537 | mid_start = 0; |
| 1538 | mid_end = wp->w_height; |
| 1539 | } |
| 1540 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 1541 | if (type == SOME_VALID) |
| 1542 | { |
| 1543 | /* SOME_VALID: redraw all lines. */ |
| 1544 | mid_start = 0; |
| 1545 | mid_end = wp->w_height; |
| 1546 | type = NOT_VALID; |
| 1547 | } |
| 1548 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1549 | /* check if we are updating or removing the inverted part */ |
| 1550 | if ((VIsual_active && buf == curwin->w_buffer) |
| 1551 | || (wp->w_old_cursor_lnum != 0 && type != NOT_VALID)) |
| 1552 | { |
| 1553 | linenr_T from, to; |
| 1554 | |
| 1555 | if (VIsual_active) |
| 1556 | { |
| 1557 | if (VIsual_active |
| 1558 | && (VIsual_mode != wp->w_old_visual_mode |
| 1559 | || type == INVERTED_ALL)) |
| 1560 | { |
| 1561 | /* |
| 1562 | * If the type of Visual selection changed, redraw the whole |
| 1563 | * selection. Also when the ownership of the X selection is |
| 1564 | * gained or lost. |
| 1565 | */ |
| 1566 | if (curwin->w_cursor.lnum < VIsual.lnum) |
| 1567 | { |
| 1568 | from = curwin->w_cursor.lnum; |
| 1569 | to = VIsual.lnum; |
| 1570 | } |
| 1571 | else |
| 1572 | { |
| 1573 | from = VIsual.lnum; |
| 1574 | to = curwin->w_cursor.lnum; |
| 1575 | } |
| 1576 | /* redraw more when the cursor moved as well */ |
| 1577 | if (wp->w_old_cursor_lnum < from) |
| 1578 | from = wp->w_old_cursor_lnum; |
| 1579 | if (wp->w_old_cursor_lnum > to) |
| 1580 | to = wp->w_old_cursor_lnum; |
| 1581 | if (wp->w_old_visual_lnum < from) |
| 1582 | from = wp->w_old_visual_lnum; |
| 1583 | if (wp->w_old_visual_lnum > to) |
| 1584 | to = wp->w_old_visual_lnum; |
| 1585 | } |
| 1586 | else |
| 1587 | { |
| 1588 | /* |
| 1589 | * Find the line numbers that need to be updated: The lines |
| 1590 | * between the old cursor position and the current cursor |
| 1591 | * position. Also check if the Visual position changed. |
| 1592 | */ |
| 1593 | if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum) |
| 1594 | { |
| 1595 | from = curwin->w_cursor.lnum; |
| 1596 | to = wp->w_old_cursor_lnum; |
| 1597 | } |
| 1598 | else |
| 1599 | { |
| 1600 | from = wp->w_old_cursor_lnum; |
| 1601 | to = curwin->w_cursor.lnum; |
| 1602 | if (from == 0) /* Visual mode just started */ |
| 1603 | from = to; |
| 1604 | } |
| 1605 | |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1606 | if (VIsual.lnum != wp->w_old_visual_lnum |
| 1607 | || VIsual.col != wp->w_old_visual_col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1608 | { |
| 1609 | if (wp->w_old_visual_lnum < from |
| 1610 | && wp->w_old_visual_lnum != 0) |
| 1611 | from = wp->w_old_visual_lnum; |
| 1612 | if (wp->w_old_visual_lnum > to) |
| 1613 | to = wp->w_old_visual_lnum; |
| 1614 | if (VIsual.lnum < from) |
| 1615 | from = VIsual.lnum; |
| 1616 | if (VIsual.lnum > to) |
| 1617 | to = VIsual.lnum; |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | /* |
| 1622 | * If in block mode and changed column or curwin->w_curswant: |
| 1623 | * update all lines. |
| 1624 | * First compute the actual start and end column. |
| 1625 | */ |
| 1626 | if (VIsual_mode == Ctrl_V) |
| 1627 | { |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1628 | colnr_T fromc, toc; |
| 1629 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1630 | int save_ve_flags = ve_flags; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1631 | |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1632 | if (curwin->w_p_lbr) |
| 1633 | ve_flags = VE_ALL; |
| 1634 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1635 | getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc); |
Bram Moolenaar | 404406a | 2014-10-09 13:24:43 +0200 | [diff] [blame] | 1636 | #if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK) |
| 1637 | ve_flags = save_ve_flags; |
| 1638 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1639 | ++toc; |
| 1640 | if (curwin->w_curswant == MAXCOL) |
| 1641 | toc = MAXCOL; |
| 1642 | |
| 1643 | if (fromc != wp->w_old_cursor_fcol |
| 1644 | || toc != wp->w_old_cursor_lcol) |
| 1645 | { |
| 1646 | if (from > VIsual.lnum) |
| 1647 | from = VIsual.lnum; |
| 1648 | if (to < VIsual.lnum) |
| 1649 | to = VIsual.lnum; |
| 1650 | } |
| 1651 | wp->w_old_cursor_fcol = fromc; |
| 1652 | wp->w_old_cursor_lcol = toc; |
| 1653 | } |
| 1654 | } |
| 1655 | else |
| 1656 | { |
| 1657 | /* Use the line numbers of the old Visual area. */ |
| 1658 | if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum) |
| 1659 | { |
| 1660 | from = wp->w_old_cursor_lnum; |
| 1661 | to = wp->w_old_visual_lnum; |
| 1662 | } |
| 1663 | else |
| 1664 | { |
| 1665 | from = wp->w_old_visual_lnum; |
| 1666 | to = wp->w_old_cursor_lnum; |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | /* |
| 1671 | * There is no need to update lines above the top of the window. |
| 1672 | */ |
| 1673 | if (from < wp->w_topline) |
| 1674 | from = wp->w_topline; |
| 1675 | |
| 1676 | /* |
| 1677 | * If we know the value of w_botline, use it to restrict the update to |
| 1678 | * the lines that are visible in the window. |
| 1679 | */ |
| 1680 | if (wp->w_valid & VALID_BOTLINE) |
| 1681 | { |
| 1682 | if (from >= wp->w_botline) |
| 1683 | from = wp->w_botline - 1; |
| 1684 | if (to >= wp->w_botline) |
| 1685 | to = wp->w_botline - 1; |
| 1686 | } |
| 1687 | |
| 1688 | /* |
| 1689 | * Find the minimal part to be updated. |
| 1690 | * Watch out for scrolling that made entries in w_lines[] invalid. |
| 1691 | * E.g., CTRL-U makes the first half of w_lines[] invalid and sets |
| 1692 | * top_end; need to redraw from top_end to the "to" line. |
| 1693 | * A middle mouse click with a Visual selection may change the text |
| 1694 | * above the Visual area and reset wl_valid, do count these for |
| 1695 | * mid_end (in srow). |
| 1696 | */ |
| 1697 | if (mid_start > 0) |
| 1698 | { |
| 1699 | lnum = wp->w_topline; |
| 1700 | idx = 0; |
| 1701 | srow = 0; |
| 1702 | if (scrolled_down) |
| 1703 | mid_start = top_end; |
| 1704 | else |
| 1705 | mid_start = 0; |
| 1706 | while (lnum < from && idx < wp->w_lines_valid) /* find start */ |
| 1707 | { |
| 1708 | if (wp->w_lines[idx].wl_valid) |
| 1709 | mid_start += wp->w_lines[idx].wl_size; |
| 1710 | else if (!scrolled_down) |
| 1711 | srow += wp->w_lines[idx].wl_size; |
| 1712 | ++idx; |
| 1713 | # ifdef FEAT_FOLDING |
| 1714 | if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid) |
| 1715 | lnum = wp->w_lines[idx].wl_lnum; |
| 1716 | else |
| 1717 | # endif |
| 1718 | ++lnum; |
| 1719 | } |
| 1720 | srow += mid_start; |
| 1721 | mid_end = wp->w_height; |
| 1722 | for ( ; idx < wp->w_lines_valid; ++idx) /* find end */ |
| 1723 | { |
| 1724 | if (wp->w_lines[idx].wl_valid |
| 1725 | && wp->w_lines[idx].wl_lnum >= to + 1) |
| 1726 | { |
| 1727 | /* Only update until first row of this line */ |
| 1728 | mid_end = srow; |
| 1729 | break; |
| 1730 | } |
| 1731 | srow += wp->w_lines[idx].wl_size; |
| 1732 | } |
| 1733 | } |
| 1734 | } |
| 1735 | |
| 1736 | if (VIsual_active && buf == curwin->w_buffer) |
| 1737 | { |
| 1738 | wp->w_old_visual_mode = VIsual_mode; |
| 1739 | wp->w_old_cursor_lnum = curwin->w_cursor.lnum; |
| 1740 | wp->w_old_visual_lnum = VIsual.lnum; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1741 | wp->w_old_visual_col = VIsual.col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1742 | wp->w_old_curswant = curwin->w_curswant; |
| 1743 | } |
| 1744 | else |
| 1745 | { |
| 1746 | wp->w_old_visual_mode = 0; |
| 1747 | wp->w_old_cursor_lnum = 0; |
| 1748 | wp->w_old_visual_lnum = 0; |
Bram Moolenaar | 6c131c4 | 2005-07-19 22:17:30 +0000 | [diff] [blame] | 1749 | wp->w_old_visual_col = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1750 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1751 | |
| 1752 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 1753 | /* reset got_int, otherwise regexp won't work */ |
| 1754 | save_got_int = got_int; |
| 1755 | got_int = 0; |
| 1756 | #endif |
| 1757 | #ifdef FEAT_FOLDING |
| 1758 | win_foldinfo.fi_level = 0; |
| 1759 | #endif |
| 1760 | |
| 1761 | /* |
| 1762 | * Update all the window rows. |
| 1763 | */ |
| 1764 | idx = 0; /* first entry in w_lines[].wl_size */ |
| 1765 | row = 0; |
| 1766 | srow = 0; |
| 1767 | lnum = wp->w_topline; /* first line shown in window */ |
| 1768 | for (;;) |
| 1769 | { |
| 1770 | /* stop updating when reached the end of the window (check for _past_ |
| 1771 | * the end of the window is at the end of the loop) */ |
| 1772 | if (row == wp->w_height) |
| 1773 | { |
| 1774 | didline = TRUE; |
| 1775 | break; |
| 1776 | } |
| 1777 | |
| 1778 | /* stop updating when hit the end of the file */ |
| 1779 | if (lnum > buf->b_ml.ml_line_count) |
| 1780 | { |
| 1781 | eof = TRUE; |
| 1782 | break; |
| 1783 | } |
| 1784 | |
| 1785 | /* Remember the starting row of the line that is going to be dealt |
| 1786 | * with. It is used further down when the line doesn't fit. */ |
| 1787 | srow = row; |
| 1788 | |
| 1789 | /* |
| 1790 | * Update a line when it is in an area that needs updating, when it |
| 1791 | * has changes or w_lines[idx] is invalid. |
| 1792 | * bot_start may be halfway a wrapped line after using |
| 1793 | * win_del_lines(), check if the current line includes it. |
| 1794 | * When syntax folding is being used, the saved syntax states will |
| 1795 | * already have been updated, we can't see where the syntax state is |
| 1796 | * the same again, just update until the end of the window. |
| 1797 | */ |
| 1798 | if (row < top_end |
| 1799 | || (row >= mid_start && row < mid_end) |
| 1800 | #ifdef FEAT_SEARCH_EXTRA |
| 1801 | || top_to_mod |
| 1802 | #endif |
| 1803 | || idx >= wp->w_lines_valid |
| 1804 | || (row + wp->w_lines[idx].wl_size > bot_start) |
| 1805 | || (mod_top != 0 |
| 1806 | && (lnum == mod_top |
| 1807 | || (lnum >= mod_top |
| 1808 | && (lnum < mod_bot |
| 1809 | #ifdef FEAT_SYN_HL |
| 1810 | || did_update == DID_FOLD |
| 1811 | || (did_update == DID_LINE |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 1812 | && syntax_present(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1813 | && ( |
| 1814 | # ifdef FEAT_FOLDING |
| 1815 | (foldmethodIsSyntax(wp) |
| 1816 | && hasAnyFolding(wp)) || |
| 1817 | # endif |
| 1818 | syntax_check_changed(lnum))) |
| 1819 | #endif |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1820 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | dab70c6 | 2014-07-02 17:16:58 +0200 | [diff] [blame] | 1821 | /* match in fixed position might need redraw |
| 1822 | * if lines were inserted or deleted */ |
| 1823 | || (wp->w_match_head != NULL |
| 1824 | && buf->b_mod_xlines != 0) |
Bram Moolenaar | 4ce239b | 2013-06-15 23:00:30 +0200 | [diff] [blame] | 1825 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1826 | ))))) |
| 1827 | { |
| 1828 | #ifdef FEAT_SEARCH_EXTRA |
| 1829 | if (lnum == mod_top) |
| 1830 | top_to_mod = FALSE; |
| 1831 | #endif |
| 1832 | |
| 1833 | /* |
| 1834 | * When at start of changed lines: May scroll following lines |
| 1835 | * up or down to minimize redrawing. |
| 1836 | * Don't do this when the change continues until the end. |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1837 | * Don't scroll when dollar_vcol >= 0, keep the "$". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1838 | */ |
| 1839 | if (lnum == mod_top |
| 1840 | && mod_bot != MAXLNUM |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 1841 | && !(dollar_vcol >= 0 && mod_bot == mod_top + 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1842 | { |
| 1843 | int old_rows = 0; |
| 1844 | int new_rows = 0; |
| 1845 | int xtra_rows; |
| 1846 | linenr_T l; |
| 1847 | |
| 1848 | /* Count the old number of window rows, using w_lines[], which |
| 1849 | * should still contain the sizes for the lines as they are |
| 1850 | * currently displayed. */ |
| 1851 | for (i = idx; i < wp->w_lines_valid; ++i) |
| 1852 | { |
| 1853 | /* Only valid lines have a meaningful wl_lnum. Invalid |
| 1854 | * lines are part of the changed area. */ |
| 1855 | if (wp->w_lines[i].wl_valid |
| 1856 | && wp->w_lines[i].wl_lnum == mod_bot) |
| 1857 | break; |
| 1858 | old_rows += wp->w_lines[i].wl_size; |
| 1859 | #ifdef FEAT_FOLDING |
| 1860 | if (wp->w_lines[i].wl_valid |
| 1861 | && wp->w_lines[i].wl_lastlnum + 1 == mod_bot) |
| 1862 | { |
| 1863 | /* Must have found the last valid entry above mod_bot. |
| 1864 | * Add following invalid entries. */ |
| 1865 | ++i; |
| 1866 | while (i < wp->w_lines_valid |
| 1867 | && !wp->w_lines[i].wl_valid) |
| 1868 | old_rows += wp->w_lines[i++].wl_size; |
| 1869 | break; |
| 1870 | } |
| 1871 | #endif |
| 1872 | } |
| 1873 | |
| 1874 | if (i >= wp->w_lines_valid) |
| 1875 | { |
| 1876 | /* We can't find a valid line below the changed lines, |
| 1877 | * need to redraw until the end of the window. |
| 1878 | * Inserting/deleting lines has no use. */ |
| 1879 | bot_start = 0; |
| 1880 | } |
| 1881 | else |
| 1882 | { |
| 1883 | /* Able to count old number of rows: Count new window |
| 1884 | * rows, and may insert/delete lines */ |
| 1885 | j = idx; |
| 1886 | for (l = lnum; l < mod_bot; ++l) |
| 1887 | { |
| 1888 | #ifdef FEAT_FOLDING |
| 1889 | if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL)) |
| 1890 | ++new_rows; |
| 1891 | else |
| 1892 | #endif |
| 1893 | #ifdef FEAT_DIFF |
| 1894 | if (l == wp->w_topline) |
| 1895 | new_rows += plines_win_nofill(wp, l, TRUE) |
| 1896 | + wp->w_topfill; |
| 1897 | else |
| 1898 | #endif |
| 1899 | new_rows += plines_win(wp, l, TRUE); |
| 1900 | ++j; |
| 1901 | if (new_rows > wp->w_height - row - 2) |
| 1902 | { |
| 1903 | /* it's getting too much, must redraw the rest */ |
| 1904 | new_rows = 9999; |
| 1905 | break; |
| 1906 | } |
| 1907 | } |
| 1908 | xtra_rows = new_rows - old_rows; |
| 1909 | if (xtra_rows < 0) |
| 1910 | { |
| 1911 | /* May scroll text up. If there is not enough |
| 1912 | * remaining text or scrolling fails, must redraw the |
| 1913 | * rest. If scrolling works, must redraw the text |
| 1914 | * below the scrolled text. */ |
| 1915 | if (row - xtra_rows >= wp->w_height - 2) |
| 1916 | mod_bot = MAXLNUM; |
| 1917 | else |
| 1918 | { |
| 1919 | check_for_delay(FALSE); |
| 1920 | if (win_del_lines(wp, row, |
| 1921 | -xtra_rows, FALSE, FALSE) == FAIL) |
| 1922 | mod_bot = MAXLNUM; |
| 1923 | else |
| 1924 | bot_start = wp->w_height + xtra_rows; |
| 1925 | } |
| 1926 | } |
| 1927 | else if (xtra_rows > 0) |
| 1928 | { |
| 1929 | /* May scroll text down. If there is not enough |
| 1930 | * remaining text of scrolling fails, must redraw the |
| 1931 | * rest. */ |
| 1932 | if (row + xtra_rows >= wp->w_height - 2) |
| 1933 | mod_bot = MAXLNUM; |
| 1934 | else |
| 1935 | { |
| 1936 | check_for_delay(FALSE); |
| 1937 | if (win_ins_lines(wp, row + old_rows, |
| 1938 | xtra_rows, FALSE, FALSE) == FAIL) |
| 1939 | mod_bot = MAXLNUM; |
| 1940 | else if (top_end > row + old_rows) |
| 1941 | /* Scrolled the part at the top that requires |
| 1942 | * updating down. */ |
| 1943 | top_end += xtra_rows; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* When not updating the rest, may need to move w_lines[] |
| 1948 | * entries. */ |
| 1949 | if (mod_bot != MAXLNUM && i != j) |
| 1950 | { |
| 1951 | if (j < i) |
| 1952 | { |
| 1953 | int x = row + new_rows; |
| 1954 | |
| 1955 | /* move entries in w_lines[] upwards */ |
| 1956 | for (;;) |
| 1957 | { |
| 1958 | /* stop at last valid entry in w_lines[] */ |
| 1959 | if (i >= wp->w_lines_valid) |
| 1960 | { |
| 1961 | wp->w_lines_valid = j; |
| 1962 | break; |
| 1963 | } |
| 1964 | wp->w_lines[j] = wp->w_lines[i]; |
| 1965 | /* stop at a line that won't fit */ |
| 1966 | if (x + (int)wp->w_lines[j].wl_size |
| 1967 | > wp->w_height) |
| 1968 | { |
| 1969 | wp->w_lines_valid = j + 1; |
| 1970 | break; |
| 1971 | } |
| 1972 | x += wp->w_lines[j++].wl_size; |
| 1973 | ++i; |
| 1974 | } |
| 1975 | if (bot_start > x) |
| 1976 | bot_start = x; |
| 1977 | } |
| 1978 | else /* j > i */ |
| 1979 | { |
| 1980 | /* move entries in w_lines[] downwards */ |
| 1981 | j -= i; |
| 1982 | wp->w_lines_valid += j; |
| 1983 | if (wp->w_lines_valid > wp->w_height) |
| 1984 | wp->w_lines_valid = wp->w_height; |
| 1985 | for (i = wp->w_lines_valid; i - j >= idx; --i) |
| 1986 | wp->w_lines[i] = wp->w_lines[i - j]; |
| 1987 | |
| 1988 | /* The w_lines[] entries for inserted lines are |
| 1989 | * now invalid, but wl_size may be used above. |
| 1990 | * Reset to zero. */ |
| 1991 | while (i >= idx) |
| 1992 | { |
| 1993 | wp->w_lines[i].wl_size = 0; |
| 1994 | wp->w_lines[i--].wl_valid = FALSE; |
| 1995 | } |
| 1996 | } |
| 1997 | } |
| 1998 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | #ifdef FEAT_FOLDING |
| 2002 | /* |
| 2003 | * When lines are folded, display one line for all of them. |
| 2004 | * Otherwise, display normally (can be several display lines when |
| 2005 | * 'wrap' is on). |
| 2006 | */ |
| 2007 | fold_count = foldedCount(wp, lnum, &win_foldinfo); |
| 2008 | if (fold_count != 0) |
| 2009 | { |
| 2010 | fold_line(wp, fold_count, &win_foldinfo, lnum, row); |
| 2011 | ++row; |
| 2012 | --fold_count; |
| 2013 | wp->w_lines[idx].wl_folded = TRUE; |
| 2014 | wp->w_lines[idx].wl_lastlnum = lnum + fold_count; |
| 2015 | # ifdef FEAT_SYN_HL |
| 2016 | did_update = DID_FOLD; |
| 2017 | # endif |
| 2018 | } |
| 2019 | else |
| 2020 | #endif |
| 2021 | if (idx < wp->w_lines_valid |
| 2022 | && wp->w_lines[idx].wl_valid |
| 2023 | && wp->w_lines[idx].wl_lnum == lnum |
| 2024 | && lnum > wp->w_topline |
Bram Moolenaar | ad9c2a0 | 2016-07-27 23:26:04 +0200 | [diff] [blame] | 2025 | && !(dy_flags & (DY_LASTLINE | DY_TRUNCATE)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2026 | && srow + wp->w_lines[idx].wl_size > wp->w_height |
| 2027 | #ifdef FEAT_DIFF |
| 2028 | && diff_check_fill(wp, lnum) == 0 |
| 2029 | #endif |
| 2030 | ) |
| 2031 | { |
| 2032 | /* This line is not going to fit. Don't draw anything here, |
| 2033 | * will draw "@ " lines below. */ |
| 2034 | row = wp->w_height + 1; |
| 2035 | } |
| 2036 | else |
| 2037 | { |
| 2038 | #ifdef FEAT_SEARCH_EXTRA |
| 2039 | prepare_search_hl(wp, lnum); |
| 2040 | #endif |
| 2041 | #ifdef FEAT_SYN_HL |
| 2042 | /* Let the syntax stuff know we skipped a few lines. */ |
| 2043 | if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2044 | && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2045 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2046 | #endif |
| 2047 | |
| 2048 | /* |
| 2049 | * Display one line. |
| 2050 | */ |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 2051 | row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2052 | |
| 2053 | #ifdef FEAT_FOLDING |
| 2054 | wp->w_lines[idx].wl_folded = FALSE; |
| 2055 | wp->w_lines[idx].wl_lastlnum = lnum; |
| 2056 | #endif |
| 2057 | #ifdef FEAT_SYN_HL |
| 2058 | did_update = DID_LINE; |
| 2059 | syntax_last_parsed = lnum; |
| 2060 | #endif |
| 2061 | } |
| 2062 | |
| 2063 | wp->w_lines[idx].wl_lnum = lnum; |
| 2064 | wp->w_lines[idx].wl_valid = TRUE; |
| 2065 | if (row > wp->w_height) /* past end of screen */ |
| 2066 | { |
| 2067 | /* we may need the size of that too long line later on */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2068 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2069 | wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE); |
| 2070 | ++idx; |
| 2071 | break; |
| 2072 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2073 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2074 | wp->w_lines[idx].wl_size = row - srow; |
| 2075 | ++idx; |
| 2076 | #ifdef FEAT_FOLDING |
| 2077 | lnum += fold_count + 1; |
| 2078 | #else |
| 2079 | ++lnum; |
| 2080 | #endif |
| 2081 | } |
| 2082 | else |
| 2083 | { |
| 2084 | /* This line does not need updating, advance to the next one */ |
| 2085 | row += wp->w_lines[idx++].wl_size; |
| 2086 | if (row > wp->w_height) /* past end of screen */ |
| 2087 | break; |
| 2088 | #ifdef FEAT_FOLDING |
| 2089 | lnum = wp->w_lines[idx - 1].wl_lastlnum + 1; |
| 2090 | #else |
| 2091 | ++lnum; |
| 2092 | #endif |
| 2093 | #ifdef FEAT_SYN_HL |
| 2094 | did_update = DID_NONE; |
| 2095 | #endif |
| 2096 | } |
| 2097 | |
| 2098 | if (lnum > buf->b_ml.ml_line_count) |
| 2099 | { |
| 2100 | eof = TRUE; |
| 2101 | break; |
| 2102 | } |
| 2103 | } |
| 2104 | /* |
| 2105 | * End of loop over all window lines. |
| 2106 | */ |
| 2107 | |
| 2108 | |
| 2109 | if (idx > wp->w_lines_valid) |
| 2110 | wp->w_lines_valid = idx; |
| 2111 | |
| 2112 | #ifdef FEAT_SYN_HL |
| 2113 | /* |
| 2114 | * Let the syntax stuff know we stop parsing here. |
| 2115 | */ |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 2116 | if (syntax_last_parsed != 0 && syntax_present(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2117 | syntax_end_parsing(syntax_last_parsed + 1); |
| 2118 | #endif |
| 2119 | |
| 2120 | /* |
| 2121 | * If we didn't hit the end of the file, and we didn't finish the last |
| 2122 | * line we were working on, then the line didn't fit. |
| 2123 | */ |
| 2124 | wp->w_empty_rows = 0; |
| 2125 | #ifdef FEAT_DIFF |
| 2126 | wp->w_filler_rows = 0; |
| 2127 | #endif |
| 2128 | if (!eof && !didline) |
| 2129 | { |
| 2130 | if (lnum == wp->w_topline) |
| 2131 | { |
| 2132 | /* |
| 2133 | * Single line that does not fit! |
| 2134 | * Don't overwrite it, it can be edited. |
| 2135 | */ |
| 2136 | wp->w_botline = lnum + 1; |
| 2137 | } |
| 2138 | #ifdef FEAT_DIFF |
| 2139 | else if (diff_check_fill(wp, lnum) >= wp->w_height - srow) |
| 2140 | { |
| 2141 | /* Window ends in filler lines. */ |
| 2142 | wp->w_botline = lnum; |
| 2143 | wp->w_filler_rows = wp->w_height - srow; |
| 2144 | } |
| 2145 | #endif |
Bram Moolenaar | ad9c2a0 | 2016-07-27 23:26:04 +0200 | [diff] [blame] | 2146 | else if (dy_flags & DY_TRUNCATE) /* 'display' has "truncate" */ |
| 2147 | { |
| 2148 | int scr_row = W_WINROW(wp) + wp->w_height - 1; |
| 2149 | |
| 2150 | /* |
| 2151 | * Last line isn't finished: Display "@@@" in the last screen line. |
| 2152 | */ |
| 2153 | screen_puts_len((char_u *)"@@", 2, scr_row, W_WINCOL(wp), |
| 2154 | hl_attr(HLF_AT)); |
| 2155 | screen_fill(scr_row, scr_row + 1, |
| 2156 | (int)W_WINCOL(wp) + 2, (int)W_ENDCOL(wp), |
| 2157 | '@', ' ', hl_attr(HLF_AT)); |
| 2158 | set_empty_rows(wp, srow); |
| 2159 | wp->w_botline = lnum; |
| 2160 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2161 | else if (dy_flags & DY_LASTLINE) /* 'display' has "lastline" */ |
| 2162 | { |
| 2163 | /* |
| 2164 | * Last line isn't finished: Display "@@@" at the end. |
| 2165 | */ |
| 2166 | screen_fill(W_WINROW(wp) + wp->w_height - 1, |
| 2167 | W_WINROW(wp) + wp->w_height, |
| 2168 | (int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp), |
| 2169 | '@', '@', hl_attr(HLF_AT)); |
| 2170 | set_empty_rows(wp, srow); |
| 2171 | wp->w_botline = lnum; |
| 2172 | } |
| 2173 | else |
| 2174 | { |
| 2175 | win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT); |
| 2176 | wp->w_botline = lnum; |
| 2177 | } |
| 2178 | } |
| 2179 | else |
| 2180 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 2181 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2182 | draw_vsep_win(wp, row); |
| 2183 | #endif |
| 2184 | if (eof) /* we hit the end of the file */ |
| 2185 | { |
| 2186 | wp->w_botline = buf->b_ml.ml_line_count + 1; |
| 2187 | #ifdef FEAT_DIFF |
| 2188 | j = diff_check_fill(wp, wp->w_botline); |
| 2189 | if (j > 0 && !wp->w_botfill) |
| 2190 | { |
| 2191 | /* |
| 2192 | * Display filler lines at the end of the file |
| 2193 | */ |
| 2194 | if (char2cells(fill_diff) > 1) |
| 2195 | i = '-'; |
| 2196 | else |
| 2197 | i = fill_diff; |
| 2198 | if (row + j > wp->w_height) |
| 2199 | j = wp->w_height - row; |
| 2200 | win_draw_end(wp, i, i, row, row + (int)j, HLF_DED); |
| 2201 | row += j; |
| 2202 | } |
| 2203 | #endif |
| 2204 | } |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2205 | else if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2206 | wp->w_botline = lnum; |
| 2207 | |
| 2208 | /* make sure the rest of the screen is blank */ |
| 2209 | /* put '~'s on rows that aren't part of the file. */ |
Bram Moolenaar | 58b8534 | 2016-08-14 19:54:54 +0200 | [diff] [blame] | 2210 | win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_EOB); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2211 | } |
| 2212 | |
| 2213 | /* Reset the type of redrawing required, the window has been updated. */ |
| 2214 | wp->w_redr_type = 0; |
| 2215 | #ifdef FEAT_DIFF |
| 2216 | wp->w_old_topfill = wp->w_topfill; |
| 2217 | wp->w_old_botfill = wp->w_botfill; |
| 2218 | #endif |
| 2219 | |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 2220 | if (dollar_vcol == -1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2221 | { |
| 2222 | /* |
| 2223 | * There is a trick with w_botline. If we invalidate it on each |
| 2224 | * change that might modify it, this will cause a lot of expensive |
| 2225 | * calls to plines() in update_topline() each time. Therefore the |
| 2226 | * value of w_botline is often approximated, and this value is used to |
| 2227 | * compute the value of w_topline. If the value of w_botline was |
| 2228 | * wrong, check that the value of w_topline is correct (cursor is on |
| 2229 | * the visible part of the text). If it's not, we need to redraw |
| 2230 | * again. Mostly this just means scrolling up a few lines, so it |
| 2231 | * doesn't look too bad. Only do this for the current window (where |
| 2232 | * changes are relevant). |
| 2233 | */ |
| 2234 | wp->w_valid |= VALID_BOTLINE; |
| 2235 | if (wp == curwin && wp->w_botline != old_botline && !recursive) |
| 2236 | { |
| 2237 | recursive = TRUE; |
| 2238 | curwin->w_valid &= ~VALID_TOPLINE; |
| 2239 | update_topline(); /* may invalidate w_botline again */ |
| 2240 | if (must_redraw != 0) |
| 2241 | { |
| 2242 | /* Don't update for changes in buffer again. */ |
| 2243 | i = curbuf->b_mod_set; |
| 2244 | curbuf->b_mod_set = FALSE; |
| 2245 | win_update(curwin); |
| 2246 | must_redraw = 0; |
| 2247 | curbuf->b_mod_set = i; |
| 2248 | } |
| 2249 | recursive = FALSE; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | #if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA) |
| 2254 | /* restore got_int, unless CTRL-C was hit while redrawing */ |
| 2255 | if (!got_int) |
| 2256 | got_int = save_got_int; |
| 2257 | #endif |
| 2258 | } |
| 2259 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2260 | /* |
| 2261 | * Clear the rest of the window and mark the unused lines with "c1". use "c2" |
| 2262 | * as the filler character. |
| 2263 | */ |
| 2264 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2265 | win_draw_end( |
| 2266 | win_T *wp, |
| 2267 | int c1, |
| 2268 | int c2, |
| 2269 | int row, |
| 2270 | int endrow, |
| 2271 | hlf_T hl) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2272 | { |
| 2273 | #if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN) |
| 2274 | int n = 0; |
| 2275 | # define FDC_OFF n |
| 2276 | #else |
| 2277 | # define FDC_OFF 0 |
| 2278 | #endif |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2279 | #ifdef FEAT_FOLDING |
| 2280 | int fdc = compute_foldcolumn(wp, 0); |
| 2281 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2282 | |
| 2283 | #ifdef FEAT_RIGHTLEFT |
| 2284 | if (wp->w_p_rl) |
| 2285 | { |
| 2286 | /* No check for cmdline window: should never be right-left. */ |
| 2287 | # ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2288 | n = fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2289 | |
| 2290 | if (n > 0) |
| 2291 | { |
| 2292 | /* draw the fold column at the right */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2293 | if (n > W_WIDTH(wp)) |
| 2294 | n = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2295 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2296 | W_ENDCOL(wp) - n, (int)W_ENDCOL(wp), |
| 2297 | ' ', ' ', hl_attr(HLF_FC)); |
| 2298 | } |
| 2299 | # endif |
| 2300 | # ifdef FEAT_SIGNS |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2301 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2302 | { |
| 2303 | int nn = n + 2; |
| 2304 | |
| 2305 | /* draw the sign column left of the fold column */ |
Bram Moolenaar | 383f9bc | 2005-01-19 22:18:32 +0000 | [diff] [blame] | 2306 | if (nn > W_WIDTH(wp)) |
| 2307 | nn = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2308 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2309 | W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n, |
| 2310 | ' ', ' ', hl_attr(HLF_SC)); |
| 2311 | n = nn; |
| 2312 | } |
| 2313 | # endif |
| 2314 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2315 | W_WINCOL(wp), W_ENDCOL(wp) - 1 - FDC_OFF, |
| 2316 | c2, c2, hl_attr(hl)); |
| 2317 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2318 | W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF, |
| 2319 | c1, c2, hl_attr(hl)); |
| 2320 | } |
| 2321 | else |
| 2322 | #endif |
| 2323 | { |
| 2324 | #ifdef FEAT_CMDWIN |
| 2325 | if (cmdwin_type != 0 && wp == curwin) |
| 2326 | { |
| 2327 | /* draw the cmdline character in the leftmost column */ |
| 2328 | n = 1; |
| 2329 | if (n > wp->w_width) |
| 2330 | n = wp->w_width; |
| 2331 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2332 | W_WINCOL(wp), (int)W_WINCOL(wp) + n, |
| 2333 | cmdwin_type, ' ', hl_attr(HLF_AT)); |
| 2334 | } |
| 2335 | #endif |
| 2336 | #ifdef FEAT_FOLDING |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2337 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2338 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2339 | int nn = n + fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2340 | |
| 2341 | /* draw the fold column at the left */ |
| 2342 | if (nn > W_WIDTH(wp)) |
| 2343 | nn = W_WIDTH(wp); |
| 2344 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2345 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2346 | ' ', ' ', hl_attr(HLF_FC)); |
| 2347 | n = nn; |
| 2348 | } |
| 2349 | #endif |
| 2350 | #ifdef FEAT_SIGNS |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2351 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2352 | { |
| 2353 | int nn = n + 2; |
| 2354 | |
| 2355 | /* draw the sign column after the fold column */ |
| 2356 | if (nn > W_WIDTH(wp)) |
| 2357 | nn = W_WIDTH(wp); |
| 2358 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2359 | W_WINCOL(wp) + n, (int)W_WINCOL(wp) + nn, |
| 2360 | ' ', ' ', hl_attr(HLF_SC)); |
| 2361 | n = nn; |
| 2362 | } |
| 2363 | #endif |
| 2364 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow, |
| 2365 | W_WINCOL(wp) + FDC_OFF, (int)W_ENDCOL(wp), |
| 2366 | c1, c2, hl_attr(hl)); |
| 2367 | } |
| 2368 | set_empty_rows(wp, row); |
| 2369 | } |
| 2370 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2371 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 2372 | static int advance_color_col(int vcol, int **color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2373 | |
| 2374 | /* |
| 2375 | * Advance **color_cols and return TRUE when there are columns to draw. |
| 2376 | */ |
| 2377 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2378 | advance_color_col(int vcol, int **color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2379 | { |
| 2380 | while (**color_cols >= 0 && vcol > **color_cols) |
| 2381 | ++*color_cols; |
| 2382 | return (**color_cols >= 0); |
| 2383 | } |
| 2384 | #endif |
| 2385 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2386 | #ifdef FEAT_FOLDING |
| 2387 | /* |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2388 | * Compute the width of the foldcolumn. Based on 'foldcolumn' and how much |
| 2389 | * space is available for window "wp", minus "col". |
| 2390 | */ |
| 2391 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2392 | compute_foldcolumn(win_T *wp, int col) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2393 | { |
| 2394 | int fdc = wp->w_p_fdc; |
| 2395 | int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw; |
| 2396 | int wwidth = W_WIDTH(wp); |
| 2397 | |
| 2398 | if (fdc > wwidth - (col + wmw)) |
| 2399 | fdc = wwidth - (col + wmw); |
| 2400 | return fdc; |
| 2401 | } |
| 2402 | |
| 2403 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2404 | * Display one folded line. |
| 2405 | */ |
| 2406 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2407 | fold_line( |
| 2408 | win_T *wp, |
| 2409 | long fold_count, |
| 2410 | foldinfo_T *foldinfo, |
| 2411 | linenr_T lnum, |
| 2412 | int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2413 | { |
Bram Moolenaar | ee695f7 | 2016-08-03 22:08:45 +0200 | [diff] [blame] | 2414 | char_u buf[FOLD_TEXT_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2415 | pos_T *top, *bot; |
| 2416 | linenr_T lnume = lnum + fold_count - 1; |
| 2417 | int len; |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2418 | char_u *text; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2419 | int fdc; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2420 | int col; |
| 2421 | int txtcol; |
| 2422 | int off = (int)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2423 | int ri; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2424 | |
| 2425 | /* Build the fold line: |
| 2426 | * 1. Add the cmdwin_type for the command-line window |
| 2427 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2428 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2429 | * 4. Compose the text |
| 2430 | * 5. Add the text |
| 2431 | * 6. set highlighting for the Visual area an other text |
| 2432 | */ |
| 2433 | col = 0; |
| 2434 | |
| 2435 | /* |
| 2436 | * 1. Add the cmdwin_type for the command-line window |
| 2437 | * Ignores 'rightleft', this window is never right-left. |
| 2438 | */ |
| 2439 | #ifdef FEAT_CMDWIN |
| 2440 | if (cmdwin_type != 0 && wp == curwin) |
| 2441 | { |
| 2442 | ScreenLines[off] = cmdwin_type; |
| 2443 | ScreenAttrs[off] = hl_attr(HLF_AT); |
| 2444 | #ifdef FEAT_MBYTE |
| 2445 | if (enc_utf8) |
| 2446 | ScreenLinesUC[off] = 0; |
| 2447 | #endif |
| 2448 | ++col; |
| 2449 | } |
| 2450 | #endif |
| 2451 | |
| 2452 | /* |
| 2453 | * 2. Add the 'foldcolumn' |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2454 | * Reduce the width when there is not enough space. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2455 | */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2456 | fdc = compute_foldcolumn(wp, col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2457 | if (fdc > 0) |
| 2458 | { |
| 2459 | fill_foldcolumn(buf, wp, TRUE, lnum); |
| 2460 | #ifdef FEAT_RIGHTLEFT |
| 2461 | if (wp->w_p_rl) |
| 2462 | { |
| 2463 | int i; |
| 2464 | |
| 2465 | copy_text_attr(off + W_WIDTH(wp) - fdc - col, buf, fdc, |
| 2466 | hl_attr(HLF_FC)); |
| 2467 | /* reverse the fold column */ |
| 2468 | for (i = 0; i < fdc; ++i) |
| 2469 | ScreenLines[off + W_WIDTH(wp) - i - 1 - col] = buf[i]; |
| 2470 | } |
| 2471 | else |
| 2472 | #endif |
| 2473 | copy_text_attr(off + col, buf, fdc, hl_attr(HLF_FC)); |
| 2474 | col += fdc; |
| 2475 | } |
| 2476 | |
| 2477 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2478 | # define RL_MEMSET(p, v, l) if (wp->w_p_rl) \ |
| 2479 | for (ri = 0; ri < l; ++ri) \ |
| 2480 | ScreenAttrs[off + (W_WIDTH(wp) - (p) - (l)) + ri] = v; \ |
| 2481 | else \ |
| 2482 | for (ri = 0; ri < l; ++ri) \ |
| 2483 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2484 | #else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2485 | # define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \ |
| 2486 | ScreenAttrs[off + (p) + ri] = v |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2487 | #endif |
| 2488 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2489 | /* Set all attributes of the 'number' or 'relativenumber' column and the |
| 2490 | * text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2491 | RL_MEMSET(col, hl_attr(HLF_FL), W_WIDTH(wp) - col); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2492 | |
| 2493 | #ifdef FEAT_SIGNS |
| 2494 | /* If signs are being displayed, add two spaces. */ |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 2495 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2496 | { |
| 2497 | len = W_WIDTH(wp) - col; |
| 2498 | if (len > 0) |
| 2499 | { |
| 2500 | if (len > 2) |
| 2501 | len = 2; |
| 2502 | # ifdef FEAT_RIGHTLEFT |
| 2503 | if (wp->w_p_rl) |
| 2504 | /* the line number isn't reversed */ |
| 2505 | copy_text_attr(off + W_WIDTH(wp) - len - col, |
| 2506 | (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2507 | else |
| 2508 | # endif |
| 2509 | copy_text_attr(off + col, (char_u *)" ", len, hl_attr(HLF_FL)); |
| 2510 | col += len; |
| 2511 | } |
| 2512 | } |
| 2513 | #endif |
| 2514 | |
| 2515 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2516 | * 3. Add the 'number' or 'relativenumber' column |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2517 | */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2518 | if (wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2519 | { |
| 2520 | len = W_WIDTH(wp) - col; |
| 2521 | if (len > 0) |
| 2522 | { |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2523 | int w = number_width(wp); |
Bram Moolenaar | 24dc230 | 2014-05-13 20:19:58 +0200 | [diff] [blame] | 2524 | long num; |
| 2525 | char *fmt = "%*ld "; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 2526 | |
| 2527 | if (len > w + 1) |
| 2528 | len = w + 1; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2529 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2530 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 2531 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2532 | num = (long)lnum; |
| 2533 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2534 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2535 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 2536 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2537 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2538 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 2539 | /* 'number' + 'relativenumber': cursor line shows absolute |
| 2540 | * line number */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2541 | num = lnum; |
| 2542 | fmt = "%-*ld "; |
| 2543 | } |
| 2544 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 2545 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 2546 | sprintf((char *)buf, fmt, w, num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2547 | #ifdef FEAT_RIGHTLEFT |
| 2548 | if (wp->w_p_rl) |
| 2549 | /* the line number isn't reversed */ |
| 2550 | copy_text_attr(off + W_WIDTH(wp) - len - col, buf, len, |
| 2551 | hl_attr(HLF_FL)); |
| 2552 | else |
| 2553 | #endif |
| 2554 | copy_text_attr(off + col, buf, len, hl_attr(HLF_FL)); |
| 2555 | col += len; |
| 2556 | } |
| 2557 | } |
| 2558 | |
| 2559 | /* |
| 2560 | * 4. Compose the folded-line string with 'foldtext', if set. |
| 2561 | */ |
Bram Moolenaar | 7b0294c | 2004-10-11 10:16:09 +0000 | [diff] [blame] | 2562 | text = get_foldtext(wp, lnum, lnume, foldinfo, buf); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2563 | |
| 2564 | txtcol = col; /* remember where text starts */ |
| 2565 | |
| 2566 | /* |
| 2567 | * 5. move the text to current_ScreenLine. Fill up with "fill_fold". |
| 2568 | * Right-left text is put in columns 0 - number-col, normal text is put |
| 2569 | * in columns number-col - window-width. |
| 2570 | */ |
| 2571 | #ifdef FEAT_MBYTE |
| 2572 | if (has_mbyte) |
| 2573 | { |
| 2574 | int cells; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2575 | int u8c, u8cc[MAX_MCO]; |
| 2576 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2577 | int idx; |
| 2578 | int c_len; |
Bram Moolenaar | 009b259 | 2004-10-24 19:18:58 +0000 | [diff] [blame] | 2579 | char_u *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2580 | # ifdef FEAT_ARABIC |
| 2581 | int prev_c = 0; /* previous Arabic character */ |
| 2582 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 2583 | # endif |
| 2584 | |
| 2585 | # ifdef FEAT_RIGHTLEFT |
| 2586 | if (wp->w_p_rl) |
| 2587 | idx = off; |
| 2588 | else |
| 2589 | # endif |
| 2590 | idx = off + col; |
| 2591 | |
| 2592 | /* Store multibyte characters in ScreenLines[] et al. correctly. */ |
| 2593 | for (p = text; *p != NUL; ) |
| 2594 | { |
| 2595 | cells = (*mb_ptr2cells)(p); |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 2596 | c_len = (*mb_ptr2len)(p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2597 | if (col + cells > W_WIDTH(wp) |
| 2598 | # ifdef FEAT_RIGHTLEFT |
| 2599 | - (wp->w_p_rl ? col : 0) |
| 2600 | # endif |
| 2601 | ) |
| 2602 | break; |
| 2603 | ScreenLines[idx] = *p; |
| 2604 | if (enc_utf8) |
| 2605 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2606 | u8c = utfc_ptr2char(p, u8cc); |
| 2607 | if (*p < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2608 | { |
| 2609 | ScreenLinesUC[idx] = 0; |
| 2610 | #ifdef FEAT_ARABIC |
| 2611 | prev_c = u8c; |
| 2612 | #endif |
| 2613 | } |
| 2614 | else |
| 2615 | { |
| 2616 | #ifdef FEAT_ARABIC |
| 2617 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 2618 | { |
| 2619 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2620 | int pc, pc1, nc; |
| 2621 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2622 | int firstbyte = *p; |
| 2623 | |
| 2624 | /* The idea of what is the previous and next |
| 2625 | * character depends on 'rightleft'. */ |
| 2626 | if (wp->w_p_rl) |
| 2627 | { |
| 2628 | pc = prev_c; |
| 2629 | pc1 = prev_c1; |
| 2630 | nc = utf_ptr2char(p + c_len); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2631 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2632 | } |
| 2633 | else |
| 2634 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2635 | pc = utfc_ptr2char(p + c_len, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2636 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2637 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2638 | } |
| 2639 | prev_c = u8c; |
| 2640 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2641 | u8c = arabic_shape(u8c, &firstbyte, &u8cc[0], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2642 | pc, pc1, nc); |
| 2643 | ScreenLines[idx] = firstbyte; |
| 2644 | } |
| 2645 | else |
| 2646 | prev_c = u8c; |
| 2647 | #endif |
| 2648 | /* Non-BMP character: display as ? or fullwidth ?. */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2649 | #ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2650 | if (u8c >= 0x10000) |
| 2651 | ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?'; |
| 2652 | else |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 2653 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2654 | ScreenLinesUC[idx] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2655 | for (i = 0; i < Screen_mco; ++i) |
| 2656 | { |
| 2657 | ScreenLinesC[i][idx] = u8cc[i]; |
| 2658 | if (u8cc[i] == 0) |
| 2659 | break; |
| 2660 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2661 | } |
| 2662 | if (cells > 1) |
| 2663 | ScreenLines[idx + 1] = 0; |
| 2664 | } |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 2665 | else if (enc_dbcs == DBCS_JPNU && *p == 0x8e) |
| 2666 | /* double-byte single width character */ |
| 2667 | ScreenLines2[idx] = p[1]; |
| 2668 | else if (cells > 1) |
| 2669 | /* double-width character */ |
| 2670 | ScreenLines[idx + 1] = p[1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2671 | col += cells; |
| 2672 | idx += cells; |
| 2673 | p += c_len; |
| 2674 | } |
| 2675 | } |
| 2676 | else |
| 2677 | #endif |
| 2678 | { |
| 2679 | len = (int)STRLEN(text); |
| 2680 | if (len > W_WIDTH(wp) - col) |
| 2681 | len = W_WIDTH(wp) - col; |
| 2682 | if (len > 0) |
| 2683 | { |
| 2684 | #ifdef FEAT_RIGHTLEFT |
| 2685 | if (wp->w_p_rl) |
| 2686 | STRNCPY(current_ScreenLine, text, len); |
| 2687 | else |
| 2688 | #endif |
| 2689 | STRNCPY(current_ScreenLine + col, text, len); |
| 2690 | col += len; |
| 2691 | } |
| 2692 | } |
| 2693 | |
| 2694 | /* Fill the rest of the line with the fold filler */ |
| 2695 | #ifdef FEAT_RIGHTLEFT |
| 2696 | if (wp->w_p_rl) |
| 2697 | col -= txtcol; |
| 2698 | #endif |
| 2699 | while (col < W_WIDTH(wp) |
| 2700 | #ifdef FEAT_RIGHTLEFT |
| 2701 | - (wp->w_p_rl ? txtcol : 0) |
| 2702 | #endif |
| 2703 | ) |
| 2704 | { |
| 2705 | #ifdef FEAT_MBYTE |
| 2706 | if (enc_utf8) |
| 2707 | { |
| 2708 | if (fill_fold >= 0x80) |
| 2709 | { |
| 2710 | ScreenLinesUC[off + col] = fill_fold; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 2711 | ScreenLinesC[0][off + col] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2712 | } |
| 2713 | else |
| 2714 | ScreenLinesUC[off + col] = 0; |
| 2715 | } |
| 2716 | #endif |
| 2717 | ScreenLines[off + col++] = fill_fold; |
| 2718 | } |
| 2719 | |
| 2720 | if (text != buf) |
| 2721 | vim_free(text); |
| 2722 | |
| 2723 | /* |
| 2724 | * 6. set highlighting for the Visual area an other text. |
| 2725 | * If all folded lines are in the Visual area, highlight the line. |
| 2726 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2727 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 2728 | { |
| 2729 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 2730 | { |
| 2731 | /* Visual is after curwin->w_cursor */ |
| 2732 | top = &curwin->w_cursor; |
| 2733 | bot = &VIsual; |
| 2734 | } |
| 2735 | else |
| 2736 | { |
| 2737 | /* Visual is before curwin->w_cursor */ |
| 2738 | top = &VIsual; |
| 2739 | bot = &curwin->w_cursor; |
| 2740 | } |
| 2741 | if (lnum >= top->lnum |
| 2742 | && lnume <= bot->lnum |
| 2743 | && (VIsual_mode != 'v' |
| 2744 | || ((lnum > top->lnum |
| 2745 | || (lnum == top->lnum |
| 2746 | && top->col == 0)) |
| 2747 | && (lnume < bot->lnum |
| 2748 | || (lnume == bot->lnum |
| 2749 | && (bot->col - (*p_sel == 'e')) |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 2750 | >= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE))))))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2751 | { |
| 2752 | if (VIsual_mode == Ctrl_V) |
| 2753 | { |
| 2754 | /* Visual block mode: highlight the chars part of the block */ |
| 2755 | if (wp->w_old_cursor_fcol + txtcol < (colnr_T)W_WIDTH(wp)) |
| 2756 | { |
Bram Moolenaar | 6c167c6 | 2011-09-02 14:07:36 +0200 | [diff] [blame] | 2757 | if (wp->w_old_cursor_lcol != MAXCOL |
| 2758 | && wp->w_old_cursor_lcol + txtcol |
| 2759 | < (colnr_T)W_WIDTH(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2760 | len = wp->w_old_cursor_lcol; |
| 2761 | else |
| 2762 | len = W_WIDTH(wp) - txtcol; |
| 2763 | RL_MEMSET(wp->w_old_cursor_fcol + txtcol, hl_attr(HLF_V), |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 2764 | len - (int)wp->w_old_cursor_fcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2765 | } |
| 2766 | } |
| 2767 | else |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2768 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2769 | /* Set all attributes of the text */ |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2770 | RL_MEMSET(txtcol, hl_attr(HLF_V), W_WIDTH(wp) - txtcol); |
| 2771 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2772 | } |
| 2773 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2774 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2775 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | fbc25b2 | 2015-03-20 17:16:27 +0100 | [diff] [blame] | 2776 | /* Show colorcolumn in the fold line, but let cursorcolumn override it. */ |
| 2777 | if (wp->w_p_cc_cols) |
| 2778 | { |
| 2779 | int i = 0; |
| 2780 | int j = wp->w_p_cc_cols[i]; |
| 2781 | int old_txtcol = txtcol; |
| 2782 | |
| 2783 | while (j > -1) |
| 2784 | { |
| 2785 | txtcol += j; |
| 2786 | if (wp->w_p_wrap) |
| 2787 | txtcol -= wp->w_skipcol; |
| 2788 | else |
| 2789 | txtcol -= wp->w_leftcol; |
| 2790 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2791 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2792 | ScreenAttrs[off + txtcol], hl_attr(HLF_MC)); |
| 2793 | txtcol = old_txtcol; |
| 2794 | j = wp->w_p_cc_cols[++i]; |
| 2795 | } |
| 2796 | } |
| 2797 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2798 | /* Show 'cursorcolumn' in the fold line. */ |
Bram Moolenaar | 85595c5 | 2008-10-02 16:04:05 +0000 | [diff] [blame] | 2799 | if (wp->w_p_cuc) |
| 2800 | { |
| 2801 | txtcol += wp->w_virtcol; |
| 2802 | if (wp->w_p_wrap) |
| 2803 | txtcol -= wp->w_skipcol; |
| 2804 | else |
| 2805 | txtcol -= wp->w_leftcol; |
| 2806 | if (txtcol >= 0 && txtcol < W_WIDTH(wp)) |
| 2807 | ScreenAttrs[off + txtcol] = hl_combine_attr( |
| 2808 | ScreenAttrs[off + txtcol], hl_attr(HLF_CUC)); |
| 2809 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2810 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2811 | |
| 2812 | SCREEN_LINE(row + W_WINROW(wp), W_WINCOL(wp), (int)W_WIDTH(wp), |
| 2813 | (int)W_WIDTH(wp), FALSE); |
| 2814 | |
| 2815 | /* |
| 2816 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 2817 | * updated (saves a call to plines() later). |
| 2818 | */ |
| 2819 | if (wp == curwin |
| 2820 | && lnum <= curwin->w_cursor.lnum |
| 2821 | && lnume >= curwin->w_cursor.lnum) |
| 2822 | { |
| 2823 | curwin->w_cline_row = row; |
| 2824 | curwin->w_cline_height = 1; |
| 2825 | curwin->w_cline_folded = TRUE; |
| 2826 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 2827 | } |
| 2828 | } |
| 2829 | |
| 2830 | /* |
| 2831 | * Copy "buf[len]" to ScreenLines["off"] and set attributes to "attr". |
| 2832 | */ |
| 2833 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2834 | copy_text_attr( |
| 2835 | int off, |
| 2836 | char_u *buf, |
| 2837 | int len, |
| 2838 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2839 | { |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2840 | int i; |
| 2841 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2842 | mch_memmove(ScreenLines + off, buf, (size_t)len); |
| 2843 | # ifdef FEAT_MBYTE |
| 2844 | if (enc_utf8) |
| 2845 | vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len); |
| 2846 | # endif |
Bram Moolenaar | 4317d9b | 2005-03-18 20:25:31 +0000 | [diff] [blame] | 2847 | for (i = 0; i < len; ++i) |
| 2848 | ScreenAttrs[off + i] = attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | /* |
| 2852 | * Fill the foldcolumn at "p" for window "wp". |
Bram Moolenaar | d5cdbeb | 2005-10-10 20:59:28 +0000 | [diff] [blame] | 2853 | * Only to be called when 'foldcolumn' > 0. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2854 | */ |
| 2855 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2856 | fill_foldcolumn( |
| 2857 | char_u *p, |
| 2858 | win_T *wp, |
| 2859 | int closed, /* TRUE of FALSE */ |
| 2860 | linenr_T lnum) /* current line number */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2861 | { |
| 2862 | int i = 0; |
| 2863 | int level; |
| 2864 | int first_level; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2865 | int empty; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2866 | int fdc = compute_foldcolumn(wp, 0); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2867 | |
| 2868 | /* Init to all spaces. */ |
Bram Moolenaar | 2536d4f | 2015-07-17 13:22:51 +0200 | [diff] [blame] | 2869 | vim_memset(p, ' ', (size_t)fdc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2870 | |
| 2871 | level = win_foldinfo.fi_level; |
| 2872 | if (level > 0) |
| 2873 | { |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2874 | /* If there is only one column put more info in it. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2875 | empty = (fdc == 1) ? 0 : 1; |
Bram Moolenaar | 578b49e | 2005-09-10 19:22:57 +0000 | [diff] [blame] | 2876 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2877 | /* If the column is too narrow, we start at the lowest level that |
| 2878 | * fits and use numbers to indicated the depth. */ |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2879 | first_level = level - fdc - closed + 1 + empty; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2880 | if (first_level < 1) |
| 2881 | first_level = 1; |
| 2882 | |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2883 | for (i = 0; i + empty < fdc; ++i) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2884 | { |
| 2885 | if (win_foldinfo.fi_lnum == lnum |
| 2886 | && first_level + i >= win_foldinfo.fi_low_level) |
| 2887 | p[i] = '-'; |
| 2888 | else if (first_level == 1) |
| 2889 | p[i] = '|'; |
| 2890 | else if (first_level + i <= 9) |
| 2891 | p[i] = '0' + first_level + i; |
| 2892 | else |
| 2893 | p[i] = '>'; |
| 2894 | if (first_level + i == level) |
| 2895 | break; |
| 2896 | } |
| 2897 | } |
| 2898 | if (closed) |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 2899 | p[i >= fdc ? i - 1 : i] = '+'; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2900 | } |
| 2901 | #endif /* FEAT_FOLDING */ |
| 2902 | |
| 2903 | /* |
| 2904 | * Display line "lnum" of window 'wp' on the screen. |
| 2905 | * Start at row "startrow", stop when "endrow" is reached. |
| 2906 | * wp->w_virtcol needs to be valid. |
| 2907 | * |
| 2908 | * Return the number of last row the line occupies. |
| 2909 | */ |
| 2910 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 2911 | win_line( |
| 2912 | win_T *wp, |
| 2913 | linenr_T lnum, |
| 2914 | int startrow, |
| 2915 | int endrow, |
| 2916 | int nochange UNUSED) /* not updating for changed text */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2917 | { |
| 2918 | int col; /* visual column on screen */ |
| 2919 | unsigned off; /* offset in ScreenLines/ScreenAttrs */ |
| 2920 | int c = 0; /* init for GCC */ |
| 2921 | long vcol = 0; /* virtual column (for tabs) */ |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 2922 | #ifdef FEAT_LINEBREAK |
| 2923 | long vcol_sbr = -1; /* virtual column after showbreak */ |
| 2924 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2925 | long vcol_prev = -1; /* "vcol" of previous character */ |
| 2926 | char_u *line; /* current line */ |
| 2927 | char_u *ptr; /* current position in "line" */ |
| 2928 | int row; /* row in the window, excl w_winrow */ |
| 2929 | int screen_row; /* row on the screen, incl w_winrow */ |
| 2930 | |
| 2931 | char_u extra[18]; /* "%ld" and 'fdc' must fit in here */ |
| 2932 | int n_extra = 0; /* number of extra chars */ |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 2933 | char_u *p_extra = NULL; /* string of extra chars, plus NUL */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 2934 | char_u *p_extra_free = NULL; /* p_extra needs to be freed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2935 | int c_extra = NUL; /* extra chars, all the same */ |
| 2936 | int extra_attr = 0; /* attributes when n_extra != 0 */ |
| 2937 | static char_u *at_end_str = (char_u *)""; /* used for p_extra when |
| 2938 | displaying lcs_eol at end-of-line */ |
| 2939 | int lcs_eol_one = lcs_eol; /* lcs_eol until it's been used */ |
| 2940 | int lcs_prec_todo = lcs_prec; /* lcs_prec until it's been used */ |
| 2941 | |
| 2942 | /* saved "extra" items for when draw_state becomes WL_LINE (again) */ |
| 2943 | int saved_n_extra = 0; |
| 2944 | char_u *saved_p_extra = NULL; |
| 2945 | int saved_c_extra = 0; |
| 2946 | int saved_char_attr = 0; |
| 2947 | |
| 2948 | int n_attr = 0; /* chars with special attr */ |
| 2949 | int saved_attr2 = 0; /* char_attr saved for n_attr */ |
| 2950 | int n_attr3 = 0; /* chars with overruling special attr */ |
| 2951 | int saved_attr3 = 0; /* char_attr saved for n_attr3 */ |
| 2952 | |
| 2953 | int n_skip = 0; /* nr of chars to skip for 'nowrap' */ |
| 2954 | |
| 2955 | int fromcol, tocol; /* start/end of inverting */ |
| 2956 | int fromcol_prev = -2; /* start of inverting after cursor */ |
| 2957 | int noinvcur = FALSE; /* don't invert the cursor */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2958 | pos_T *top, *bot; |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 2959 | int lnum_in_visual_area = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2960 | pos_T pos; |
| 2961 | long v; |
| 2962 | |
| 2963 | int char_attr = 0; /* attributes for next character */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 2964 | int attr_pri = FALSE; /* char_attr has priority */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2965 | int area_highlighting = FALSE; /* Visual or incsearch highlighting |
| 2966 | in this line */ |
| 2967 | int attr = 0; /* attributes for area highlighting */ |
| 2968 | int area_attr = 0; /* attributes desired by highlighting */ |
| 2969 | int search_attr = 0; /* attributes desired by 'hlsearch' */ |
| 2970 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2971 | int vcol_save_attr = 0; /* saved attr for 'cursorcolumn' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2972 | int syntax_attr = 0; /* attributes desired by syntax */ |
| 2973 | int has_syntax = FALSE; /* this buffer has syntax highl. */ |
| 2974 | int save_did_emsg; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 2975 | int eol_hl_off = 0; /* 1 if highlighted char after EOL */ |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 2976 | int draw_color_col = FALSE; /* highlight colorcolumn */ |
| 2977 | int *color_cols = NULL; /* pointer to according columns array */ |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 2978 | #endif |
| 2979 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2980 | int has_spell = FALSE; /* this buffer has spell checking */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2981 | # define SPWORDLEN 150 |
| 2982 | char_u nextline[SPWORDLEN * 2];/* text with start of the next line */ |
Bram Moolenaar | 3b50694 | 2005-06-23 22:36:45 +0000 | [diff] [blame] | 2983 | int nextlinecol = 0; /* column where nextline[] starts */ |
| 2984 | int nextline_idx = 0; /* index in nextline[] where next line |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2985 | starts */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 2986 | int spell_attr = 0; /* attributes desired by spelling */ |
| 2987 | int word_end = 0; /* last byte with same spell_attr */ |
Bram Moolenaar | d042c56 | 2005-06-30 22:04:15 +0000 | [diff] [blame] | 2988 | static linenr_T checked_lnum = 0; /* line number for "checked_col" */ |
| 2989 | static int checked_col = 0; /* column in "checked_lnum" up to which |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2990 | * there are no spell errors */ |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 2991 | static int cap_col = -1; /* column to check for Cap word */ |
| 2992 | static linenr_T capcol_lnum = 0; /* line number where "cap_col" used */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 2993 | int cur_checked_col = 0; /* checked column for current line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2994 | #endif |
| 2995 | int extra_check; /* has syntax or linebreak */ |
| 2996 | #ifdef FEAT_MBYTE |
| 2997 | int multi_attr = 0; /* attributes desired by multibyte */ |
| 2998 | int mb_l = 1; /* multi-byte byte length */ |
| 2999 | int mb_c = 0; /* decoded multi-byte character */ |
| 3000 | int mb_utf8 = FALSE; /* screen char is UTF-8 char */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 3001 | int u8cc[MAX_MCO]; /* composing UTF-8 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3002 | #endif |
| 3003 | #ifdef FEAT_DIFF |
| 3004 | int filler_lines; /* nr of filler lines to be drawn */ |
| 3005 | int filler_todo; /* nr of filler lines still to do + 1 */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3006 | hlf_T diff_hlf = (hlf_T)0; /* type of diff highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3007 | int change_start = MAXCOL; /* first col of changed area */ |
| 3008 | int change_end = -1; /* last col of changed area */ |
| 3009 | #endif |
| 3010 | colnr_T trailcol = MAXCOL; /* start of trailing spaces */ |
| 3011 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3012 | int need_showbreak = FALSE; /* overlong line, skipping first x |
| 3013 | chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3014 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3015 | #if defined(FEAT_SIGNS) || (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ |
| 3016 | || defined(FEAT_SYN_HL) || defined(FEAT_DIFF) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3017 | # define LINE_ATTR |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3018 | int line_attr = 0; /* attribute for the whole line */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3019 | #endif |
| 3020 | #ifdef FEAT_SEARCH_EXTRA |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3021 | matchitem_T *cur; /* points to the match list */ |
| 3022 | match_T *shl; /* points to search_hl or a match */ |
| 3023 | int shl_flag; /* flag to indicate whether search_hl |
| 3024 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3025 | int pos_inprogress; /* marks that position match search is |
| 3026 | in progress */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3027 | int prevcol_hl_flag; /* flag to indicate whether prevcol |
| 3028 | equals startcol of search_hl or one |
| 3029 | of the matches */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3030 | #endif |
| 3031 | #ifdef FEAT_ARABIC |
| 3032 | int prev_c = 0; /* previous Arabic character */ |
| 3033 | int prev_c1 = 0; /* first composing char for prev_c */ |
| 3034 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 3035 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 3036 | int did_line_attr = 0; |
| 3037 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3038 | |
| 3039 | /* draw_state: items that are drawn in sequence: */ |
| 3040 | #define WL_START 0 /* nothing done yet */ |
| 3041 | #ifdef FEAT_CMDWIN |
| 3042 | # define WL_CMDLINE WL_START + 1 /* cmdline window column */ |
| 3043 | #else |
| 3044 | # define WL_CMDLINE WL_START |
| 3045 | #endif |
| 3046 | #ifdef FEAT_FOLDING |
| 3047 | # define WL_FOLD WL_CMDLINE + 1 /* 'foldcolumn' */ |
| 3048 | #else |
| 3049 | # define WL_FOLD WL_CMDLINE |
| 3050 | #endif |
| 3051 | #ifdef FEAT_SIGNS |
| 3052 | # define WL_SIGN WL_FOLD + 1 /* column for signs */ |
| 3053 | #else |
| 3054 | # define WL_SIGN WL_FOLD /* column for signs */ |
| 3055 | #endif |
| 3056 | #define WL_NR WL_SIGN + 1 /* line number */ |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3057 | #ifdef FEAT_LINEBREAK |
| 3058 | # define WL_BRI WL_NR + 1 /* 'breakindent' */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3059 | #else |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3060 | # define WL_BRI WL_NR |
| 3061 | #endif |
| 3062 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3063 | # define WL_SBR WL_BRI + 1 /* 'showbreak' or 'diff' */ |
| 3064 | #else |
| 3065 | # define WL_SBR WL_BRI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3066 | #endif |
| 3067 | #define WL_LINE WL_SBR + 1 /* text in the line */ |
| 3068 | int draw_state = WL_START; /* what to draw next */ |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 3069 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3070 | int feedback_col = 0; |
| 3071 | int feedback_old_attr = -1; |
| 3072 | #endif |
| 3073 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3074 | #ifdef FEAT_CONCEAL |
| 3075 | int syntax_flags = 0; |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 3076 | int syntax_seqnr = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 3077 | int prev_syntax_id = 0; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3078 | int conceal_attr = hl_attr(HLF_CONCEAL); |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3079 | int is_concealing = FALSE; |
| 3080 | int boguscols = 0; /* nonexistent columns added to force |
| 3081 | wrapping */ |
Bram Moolenaar | 8d9b40e | 2010-07-25 15:49:07 +0200 | [diff] [blame] | 3082 | int vcol_off = 0; /* offset for concealed characters */ |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 3083 | int did_wcol = FALSE; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3084 | int match_conc = 0; /* cchar for match functions */ |
| 3085 | int has_match_conc = 0; /* match wants to conceal */ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3086 | int old_boguscols = 0; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3087 | # define VCOL_HLC (vcol - vcol_off) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3088 | # define FIX_FOR_BOGUSCOLS \ |
| 3089 | { \ |
| 3090 | n_extra += vcol_off; \ |
| 3091 | vcol -= vcol_off; \ |
| 3092 | vcol_off = 0; \ |
| 3093 | col -= boguscols; \ |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 3094 | old_boguscols = boguscols; \ |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 3095 | boguscols = 0; \ |
| 3096 | } |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3097 | #else |
| 3098 | # define VCOL_HLC (vcol) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3099 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3100 | |
| 3101 | if (startrow > endrow) /* past the end already! */ |
| 3102 | return startrow; |
| 3103 | |
| 3104 | row = startrow; |
| 3105 | screen_row = row + W_WINROW(wp); |
| 3106 | |
| 3107 | /* |
| 3108 | * To speed up the loop below, set extra_check when there is linebreak, |
| 3109 | * trailing white space and/or syntax processing to be done. |
| 3110 | */ |
| 3111 | #ifdef FEAT_LINEBREAK |
| 3112 | extra_check = wp->w_p_lbr; |
| 3113 | #else |
| 3114 | extra_check = 0; |
| 3115 | #endif |
| 3116 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3117 | if (syntax_present(wp) && !wp->w_s->b_syn_error) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3118 | { |
| 3119 | /* Prepare for syntax highlighting in this line. When there is an |
| 3120 | * error, stop syntax highlighting. */ |
| 3121 | save_did_emsg = did_emsg; |
| 3122 | did_emsg = FALSE; |
| 3123 | syntax_start(wp, lnum); |
| 3124 | if (did_emsg) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3125 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3126 | else |
| 3127 | { |
| 3128 | did_emsg = save_did_emsg; |
| 3129 | has_syntax = TRUE; |
| 3130 | extra_check = TRUE; |
| 3131 | } |
| 3132 | } |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3133 | |
| 3134 | /* Check for columns to display for 'colorcolumn'. */ |
| 3135 | color_cols = wp->w_p_cc_cols; |
| 3136 | if (color_cols != NULL) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 3137 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3138 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3139 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3140 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0cb032e | 2005-04-23 20:52:00 +0000 | [diff] [blame] | 3141 | if (wp->w_p_spell |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 3142 | && *wp->w_s->b_p_spl != NUL |
| 3143 | && wp->w_s->b_langp.ga_len > 0 |
| 3144 | && *(char **)(wp->w_s->b_langp.ga_data) != NULL) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3145 | { |
| 3146 | /* Prepare for spell checking. */ |
| 3147 | has_spell = TRUE; |
| 3148 | extra_check = TRUE; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3149 | |
| 3150 | /* Get the start of the next line, so that words that wrap to the next |
| 3151 | * line are found too: "et<line-break>al.". |
| 3152 | * Trick: skip a few chars for C/shell/Vim comments */ |
| 3153 | nextline[SPWORDLEN] = NUL; |
| 3154 | if (lnum < wp->w_buffer->b_ml.ml_line_count) |
| 3155 | { |
| 3156 | line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE); |
| 3157 | spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN); |
| 3158 | } |
| 3159 | |
| 3160 | /* When a word wrapped from the previous line the start of the current |
| 3161 | * line is valid. */ |
| 3162 | if (lnum == checked_lnum) |
| 3163 | cur_checked_col = checked_col; |
| 3164 | checked_lnum = 0; |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3165 | |
| 3166 | /* When there was a sentence end in the previous line may require a |
| 3167 | * word starting with capital in this line. In line 1 always check |
| 3168 | * the first word. */ |
| 3169 | if (lnum != capcol_lnum) |
| 3170 | cap_col = -1; |
| 3171 | if (lnum == 1) |
| 3172 | cap_col = 0; |
| 3173 | capcol_lnum = 0; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 3174 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3175 | #endif |
| 3176 | |
| 3177 | /* |
| 3178 | * handle visual active in this window |
| 3179 | */ |
| 3180 | fromcol = -10; |
| 3181 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3182 | if (VIsual_active && wp->w_buffer == curwin->w_buffer) |
| 3183 | { |
| 3184 | /* Visual is after curwin->w_cursor */ |
| 3185 | if (ltoreq(curwin->w_cursor, VIsual)) |
| 3186 | { |
| 3187 | top = &curwin->w_cursor; |
| 3188 | bot = &VIsual; |
| 3189 | } |
| 3190 | else /* Visual is before curwin->w_cursor */ |
| 3191 | { |
| 3192 | top = &VIsual; |
| 3193 | bot = &curwin->w_cursor; |
| 3194 | } |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3195 | lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3196 | if (VIsual_mode == Ctrl_V) /* block mode */ |
| 3197 | { |
Bram Moolenaar | 54ef711 | 2009-02-21 20:11:41 +0000 | [diff] [blame] | 3198 | if (lnum_in_visual_area) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3199 | { |
| 3200 | fromcol = wp->w_old_cursor_fcol; |
| 3201 | tocol = wp->w_old_cursor_lcol; |
| 3202 | } |
| 3203 | } |
| 3204 | else /* non-block mode */ |
| 3205 | { |
| 3206 | if (lnum > top->lnum && lnum <= bot->lnum) |
| 3207 | fromcol = 0; |
| 3208 | else if (lnum == top->lnum) |
| 3209 | { |
| 3210 | if (VIsual_mode == 'V') /* linewise */ |
| 3211 | fromcol = 0; |
| 3212 | else |
| 3213 | { |
| 3214 | getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL); |
| 3215 | if (gchar_pos(top) == NUL) |
| 3216 | tocol = fromcol + 1; |
| 3217 | } |
| 3218 | } |
| 3219 | if (VIsual_mode != 'V' && lnum == bot->lnum) |
| 3220 | { |
| 3221 | if (*p_sel == 'e' && bot->col == 0 |
| 3222 | #ifdef FEAT_VIRTUALEDIT |
| 3223 | && bot->coladd == 0 |
| 3224 | #endif |
| 3225 | ) |
| 3226 | { |
| 3227 | fromcol = -10; |
| 3228 | tocol = MAXCOL; |
| 3229 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3230 | else if (bot->col == MAXCOL) |
| 3231 | tocol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3232 | else |
| 3233 | { |
| 3234 | pos = *bot; |
| 3235 | if (*p_sel == 'e') |
| 3236 | getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3237 | else |
| 3238 | { |
| 3239 | getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol); |
| 3240 | ++tocol; |
| 3241 | } |
| 3242 | } |
| 3243 | } |
| 3244 | } |
| 3245 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3246 | /* Check if the character under the cursor should not be inverted */ |
| 3247 | if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3248 | #ifdef FEAT_GUI |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3249 | && !gui.in_use |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 3250 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3251 | ) |
| 3252 | noinvcur = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3253 | |
| 3254 | /* if inverting in this line set area_highlighting */ |
| 3255 | if (fromcol >= 0) |
| 3256 | { |
| 3257 | area_highlighting = TRUE; |
| 3258 | attr = hl_attr(HLF_V); |
| 3259 | #if defined(FEAT_CLIPBOARD) && defined(FEAT_X11) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 3260 | if ((clip_star.available && !clip_star.owned |
| 3261 | && clip_isautosel_star()) |
| 3262 | || (clip_plus.available && !clip_plus.owned |
| 3263 | && clip_isautosel_plus())) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3264 | attr = hl_attr(HLF_VNC); |
| 3265 | #endif |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | /* |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 3270 | * handle 'incsearch' and ":s///c" highlighting |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3271 | */ |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3272 | else if (highlight_match |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3273 | && wp == curwin |
| 3274 | && lnum >= curwin->w_cursor.lnum |
| 3275 | && lnum <= curwin->w_cursor.lnum + search_match_lines) |
| 3276 | { |
| 3277 | if (lnum == curwin->w_cursor.lnum) |
| 3278 | getvcol(curwin, &(curwin->w_cursor), |
| 3279 | (colnr_T *)&fromcol, NULL, NULL); |
| 3280 | else |
| 3281 | fromcol = 0; |
| 3282 | if (lnum == curwin->w_cursor.lnum + search_match_lines) |
| 3283 | { |
| 3284 | pos.lnum = lnum; |
| 3285 | pos.col = search_match_endcol; |
| 3286 | getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL); |
| 3287 | } |
| 3288 | else |
| 3289 | tocol = MAXCOL; |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 3290 | /* do at least one character; happens when past end of line */ |
| 3291 | if (fromcol == tocol) |
| 3292 | tocol = fromcol + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3293 | area_highlighting = TRUE; |
| 3294 | attr = hl_attr(HLF_I); |
| 3295 | } |
| 3296 | |
| 3297 | #ifdef FEAT_DIFF |
| 3298 | filler_lines = diff_check(wp, lnum); |
| 3299 | if (filler_lines < 0) |
| 3300 | { |
| 3301 | if (filler_lines == -1) |
| 3302 | { |
| 3303 | if (diff_find_change(wp, lnum, &change_start, &change_end)) |
| 3304 | diff_hlf = HLF_ADD; /* added line */ |
| 3305 | else if (change_start == 0) |
| 3306 | diff_hlf = HLF_TXD; /* changed text */ |
| 3307 | else |
| 3308 | diff_hlf = HLF_CHD; /* changed line */ |
| 3309 | } |
| 3310 | else |
| 3311 | diff_hlf = HLF_ADD; /* added line */ |
| 3312 | filler_lines = 0; |
| 3313 | area_highlighting = TRUE; |
| 3314 | } |
| 3315 | if (lnum == wp->w_topline) |
| 3316 | filler_lines = wp->w_topfill; |
| 3317 | filler_todo = filler_lines; |
| 3318 | #endif |
| 3319 | |
| 3320 | #ifdef LINE_ATTR |
| 3321 | # ifdef FEAT_SIGNS |
| 3322 | /* If this line has a sign with line highlighting set line_attr. */ |
| 3323 | v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL); |
| 3324 | if (v != 0) |
| 3325 | line_attr = sign_get_attr((int)v, TRUE); |
| 3326 | # endif |
| 3327 | # if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) |
| 3328 | /* Highlight the current line in the quickfix window. */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 3329 | if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3330 | line_attr = hl_attr(HLF_L); |
| 3331 | # endif |
| 3332 | if (line_attr != 0) |
| 3333 | area_highlighting = TRUE; |
| 3334 | #endif |
| 3335 | |
| 3336 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3337 | ptr = line; |
| 3338 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3339 | #ifdef FEAT_SPELL |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3340 | if (has_spell) |
| 3341 | { |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3342 | /* For checking first word with a capital skip white space. */ |
| 3343 | if (cap_col == 0) |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3344 | cap_col = (int)(skipwhite(line) - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 3345 | |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3346 | /* To be able to spell-check over line boundaries copy the end of the |
| 3347 | * current line into nextline[]. Above the start of the next line was |
| 3348 | * copied to nextline[SPWORDLEN]. */ |
| 3349 | if (nextline[SPWORDLEN] == NUL) |
| 3350 | { |
| 3351 | /* No next line or it is empty. */ |
| 3352 | nextlinecol = MAXCOL; |
| 3353 | nextline_idx = 0; |
| 3354 | } |
| 3355 | else |
| 3356 | { |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3357 | v = (long)STRLEN(line); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3358 | if (v < SPWORDLEN) |
| 3359 | { |
| 3360 | /* Short line, use it completely and append the start of the |
| 3361 | * next line. */ |
| 3362 | nextlinecol = 0; |
| 3363 | mch_memmove(nextline, line, (size_t)v); |
Bram Moolenaar | 446cb83 | 2008-06-24 21:56:24 +0000 | [diff] [blame] | 3364 | STRMOVE(nextline + v, nextline + SPWORDLEN); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 3365 | nextline_idx = v + 1; |
| 3366 | } |
| 3367 | else |
| 3368 | { |
| 3369 | /* Long line, use only the last SPWORDLEN bytes. */ |
| 3370 | nextlinecol = v - SPWORDLEN; |
| 3371 | mch_memmove(nextline, line + nextlinecol, SPWORDLEN); |
| 3372 | nextline_idx = SPWORDLEN + 1; |
| 3373 | } |
| 3374 | } |
| 3375 | } |
| 3376 | #endif |
| 3377 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3378 | if (wp->w_p_list) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3379 | { |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 3380 | if (lcs_space || lcs_trail) |
| 3381 | extra_check = TRUE; |
| 3382 | /* find start of trailing whitespace */ |
| 3383 | if (lcs_trail) |
| 3384 | { |
| 3385 | trailcol = (colnr_T)STRLEN(ptr); |
| 3386 | while (trailcol > (colnr_T)0 && vim_iswhite(ptr[trailcol - 1])) |
| 3387 | --trailcol; |
| 3388 | trailcol += (colnr_T) (ptr - line); |
| 3389 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3390 | } |
| 3391 | |
| 3392 | /* |
| 3393 | * 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the |
| 3394 | * first character to be displayed. |
| 3395 | */ |
| 3396 | if (wp->w_p_wrap) |
| 3397 | v = wp->w_skipcol; |
| 3398 | else |
| 3399 | v = wp->w_leftcol; |
| 3400 | if (v > 0) |
| 3401 | { |
| 3402 | #ifdef FEAT_MBYTE |
| 3403 | char_u *prev_ptr = ptr; |
| 3404 | #endif |
| 3405 | while (vcol < v && *ptr != NUL) |
| 3406 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3407 | c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3408 | vcol += c; |
| 3409 | #ifdef FEAT_MBYTE |
| 3410 | prev_ptr = ptr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3411 | #endif |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 3412 | mb_ptr_adv(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3415 | /* When: |
| 3416 | * - 'cuc' is set, or |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 3417 | * - 'colorcolumn' is set, or |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3418 | * - 'virtualedit' is set, or |
| 3419 | * - the visual mode is active, |
| 3420 | * the end of the line may be before the start of the displayed part. |
| 3421 | */ |
| 3422 | if (vcol < v && ( |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 3423 | #ifdef FEAT_SYN_HL |
| 3424 | wp->w_p_cuc || draw_color_col || |
| 3425 | #endif |
| 3426 | #ifdef FEAT_VIRTUALEDIT |
| 3427 | virtual_active() || |
| 3428 | #endif |
| 3429 | (VIsual_active && wp->w_buffer == curwin->w_buffer))) |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3430 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3431 | vcol = v; |
Bram Moolenaar | bb6a705 | 2009-11-03 16:36:44 +0000 | [diff] [blame] | 3432 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3433 | |
| 3434 | /* Handle a character that's not completely on the screen: Put ptr at |
| 3435 | * that character but skip the first few screen characters. */ |
| 3436 | if (vcol > v) |
| 3437 | { |
| 3438 | vcol -= c; |
| 3439 | #ifdef FEAT_MBYTE |
| 3440 | ptr = prev_ptr; |
| 3441 | #else |
| 3442 | --ptr; |
| 3443 | #endif |
| 3444 | n_skip = v - vcol; |
| 3445 | } |
| 3446 | |
| 3447 | /* |
| 3448 | * Adjust for when the inverted text is before the screen, |
| 3449 | * and when the start of the inverted text is before the screen. |
| 3450 | */ |
| 3451 | if (tocol <= vcol) |
| 3452 | fromcol = 0; |
| 3453 | else if (fromcol >= 0 && fromcol < vcol) |
| 3454 | fromcol = vcol; |
| 3455 | |
| 3456 | #ifdef FEAT_LINEBREAK |
| 3457 | /* When w_skipcol is non-zero, first line needs 'showbreak' */ |
| 3458 | if (wp->w_p_wrap) |
| 3459 | need_showbreak = TRUE; |
| 3460 | #endif |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3461 | #ifdef FEAT_SPELL |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3462 | /* When spell checking a word we need to figure out the start of the |
| 3463 | * word and if it's badly spelled or not. */ |
| 3464 | if (has_spell) |
| 3465 | { |
| 3466 | int len; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3467 | colnr_T linecol = (colnr_T)(ptr - line); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3468 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3469 | |
| 3470 | pos = wp->w_cursor; |
| 3471 | wp->w_cursor.lnum = lnum; |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3472 | wp->w_cursor.col = linecol; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3473 | len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf); |
Bram Moolenaar | 4ef9e49 | 2008-02-13 20:49:04 +0000 | [diff] [blame] | 3474 | |
| 3475 | /* spell_move_to() may call ml_get() and make "line" invalid */ |
| 3476 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3477 | ptr = line + linecol; |
| 3478 | |
Bram Moolenaar | 60a795a | 2005-09-16 21:55:43 +0000 | [diff] [blame] | 3479 | if (len == 0 || (int)wp->w_cursor.col > ptr - line) |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3480 | { |
| 3481 | /* no bad word found at line start, don't check until end of a |
| 3482 | * word */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3483 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 3b393a0 | 2012-06-06 19:05:50 +0200 | [diff] [blame] | 3484 | word_end = (int)(spell_to_word_end(ptr, wp) - line + 1); |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3485 | } |
| 3486 | else |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3487 | { |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3488 | /* bad word found, use attributes until end of word */ |
| 3489 | word_end = wp->w_cursor.col + len + 1; |
| 3490 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 3491 | /* Turn index into actual attributes. */ |
| 3492 | if (spell_hlf != HLF_COUNT) |
| 3493 | spell_attr = highlight_attr[spell_hlf]; |
| 3494 | } |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3495 | wp->w_cursor = pos; |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3496 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3497 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | da2303d | 2005-08-30 21:55:26 +0000 | [diff] [blame] | 3498 | /* Need to restart syntax highlighting for this line. */ |
| 3499 | if (has_syntax) |
| 3500 | syntax_start(wp, lnum); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3501 | # endif |
Bram Moolenaar | 81f1ecb | 2005-08-25 21:27:31 +0000 | [diff] [blame] | 3502 | } |
| 3503 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | /* |
| 3507 | * Correct highlighting for cursor that can't be disabled. |
| 3508 | * Avoids having to check this for each character. |
| 3509 | */ |
| 3510 | if (fromcol >= 0) |
| 3511 | { |
| 3512 | if (noinvcur) |
| 3513 | { |
| 3514 | if ((colnr_T)fromcol == wp->w_virtcol) |
| 3515 | { |
| 3516 | /* highlighting starts at cursor, let it start just after the |
| 3517 | * cursor */ |
| 3518 | fromcol_prev = fromcol; |
| 3519 | fromcol = -1; |
| 3520 | } |
| 3521 | else if ((colnr_T)fromcol < wp->w_virtcol) |
| 3522 | /* restart highlighting after the cursor */ |
| 3523 | fromcol_prev = wp->w_virtcol; |
| 3524 | } |
| 3525 | if (fromcol >= tocol) |
| 3526 | fromcol = -1; |
| 3527 | } |
| 3528 | |
| 3529 | #ifdef FEAT_SEARCH_EXTRA |
| 3530 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3531 | * Handle highlighting the last used search pattern and matches. |
| 3532 | * Do this for both search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3533 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3534 | cur = wp->w_match_head; |
| 3535 | shl_flag = FALSE; |
| 3536 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3537 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3538 | if (shl_flag == FALSE) |
| 3539 | { |
| 3540 | shl = &search_hl; |
| 3541 | shl_flag = TRUE; |
| 3542 | } |
| 3543 | else |
| 3544 | shl = &cur->hl; |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3545 | shl->startcol = MAXCOL; |
| 3546 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3547 | shl->attr_cur = 0; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 3548 | shl->is_addpos = FALSE; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3549 | v = (long)(ptr - line); |
| 3550 | if (cur != NULL) |
| 3551 | cur->pos.cur = 0; |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 3552 | next_search_hl(wp, shl, lnum, (colnr_T)v, |
| 3553 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3554 | |
| 3555 | /* Need to get the line again, a multi-line regexp may have made it |
| 3556 | * invalid. */ |
| 3557 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 3558 | ptr = line + v; |
| 3559 | |
| 3560 | if (shl->lnum != 0 && shl->lnum <= lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3561 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3562 | if (shl->lnum == lnum) |
| 3563 | shl->startcol = shl->rm.startpos[0].col; |
| 3564 | else |
| 3565 | shl->startcol = 0; |
| 3566 | if (lnum == shl->lnum + shl->rm.endpos[0].lnum |
| 3567 | - shl->rm.startpos[0].lnum) |
| 3568 | shl->endcol = shl->rm.endpos[0].col; |
| 3569 | else |
| 3570 | shl->endcol = MAXCOL; |
| 3571 | /* Highlight one character for an empty match. */ |
| 3572 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3573 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3574 | #ifdef FEAT_MBYTE |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3575 | if (has_mbyte && line[shl->endcol] != NUL) |
| 3576 | shl->endcol += (*mb_ptr2len)(line + shl->endcol); |
| 3577 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3578 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3579 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3580 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3581 | if ((long)shl->startcol < v) /* match at leftcol */ |
| 3582 | { |
| 3583 | shl->attr_cur = shl->attr; |
| 3584 | search_attr = shl->attr; |
| 3585 | } |
| 3586 | area_highlighting = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3587 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3588 | if (shl != &search_hl && cur != NULL) |
| 3589 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3590 | } |
| 3591 | #endif |
| 3592 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3593 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3594 | /* Cursor line highlighting for 'cursorline' in the current window. Not |
| 3595 | * when Visual mode is active, because it's not clear what is selected |
| 3596 | * then. */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3597 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3598 | && !(wp == curwin && VIsual_active)) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3599 | { |
| 3600 | line_attr = hl_attr(HLF_CUL); |
| 3601 | area_highlighting = TRUE; |
| 3602 | } |
| 3603 | #endif |
| 3604 | |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 3605 | off = (unsigned)(current_ScreenLine - ScreenLines); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3606 | col = 0; |
| 3607 | #ifdef FEAT_RIGHTLEFT |
| 3608 | if (wp->w_p_rl) |
| 3609 | { |
| 3610 | /* Rightleft window: process the text in the normal direction, but put |
| 3611 | * it in current_ScreenLine[] from right to left. Start at the |
| 3612 | * rightmost column of the window. */ |
| 3613 | col = W_WIDTH(wp) - 1; |
| 3614 | off += col; |
| 3615 | } |
| 3616 | #endif |
| 3617 | |
| 3618 | /* |
| 3619 | * Repeat for the whole displayed line. |
| 3620 | */ |
| 3621 | for (;;) |
| 3622 | { |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3623 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3624 | has_match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3625 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3626 | /* Skip this quickly when working on the text. */ |
| 3627 | if (draw_state != WL_LINE) |
| 3628 | { |
| 3629 | #ifdef FEAT_CMDWIN |
| 3630 | if (draw_state == WL_CMDLINE - 1 && n_extra == 0) |
| 3631 | { |
| 3632 | draw_state = WL_CMDLINE; |
| 3633 | if (cmdwin_type != 0 && wp == curwin) |
| 3634 | { |
| 3635 | /* Draw the cmdline character. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3636 | n_extra = 1; |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 3637 | c_extra = cmdwin_type; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3638 | char_attr = hl_attr(HLF_AT); |
| 3639 | } |
| 3640 | } |
| 3641 | #endif |
| 3642 | |
| 3643 | #ifdef FEAT_FOLDING |
| 3644 | if (draw_state == WL_FOLD - 1 && n_extra == 0) |
| 3645 | { |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3646 | int fdc = compute_foldcolumn(wp, 0); |
| 3647 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3648 | draw_state = WL_FOLD; |
Bram Moolenaar | 1c93429 | 2015-01-27 16:39:29 +0100 | [diff] [blame] | 3649 | if (fdc > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3650 | { |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 3651 | /* Draw the 'foldcolumn'. Allocate a buffer, "extra" may |
Bram Moolenaar | c695cec | 2017-01-08 20:00:04 +0100 | [diff] [blame] | 3652 | * already be in use. */ |
Bram Moolenaar | b031c4e | 2017-01-24 20:14:48 +0100 | [diff] [blame] | 3653 | vim_free(p_extra_free); |
Bram Moolenaar | 6270660 | 2016-12-09 19:28:48 +0100 | [diff] [blame] | 3654 | p_extra_free = alloc(12 + 1); |
| 3655 | |
| 3656 | if (p_extra_free != NULL) |
| 3657 | { |
| 3658 | fill_foldcolumn(p_extra_free, wp, FALSE, lnum); |
| 3659 | n_extra = fdc; |
| 3660 | p_extra_free[n_extra] = NUL; |
| 3661 | p_extra = p_extra_free; |
| 3662 | c_extra = NUL; |
| 3663 | char_attr = hl_attr(HLF_FC); |
| 3664 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3665 | } |
| 3666 | } |
| 3667 | #endif |
| 3668 | |
| 3669 | #ifdef FEAT_SIGNS |
| 3670 | if (draw_state == WL_SIGN - 1 && n_extra == 0) |
| 3671 | { |
| 3672 | draw_state = WL_SIGN; |
| 3673 | /* Show the sign column when there are any signs in this |
| 3674 | * buffer or when using Netbeans. */ |
Bram Moolenaar | 95ec9d6 | 2016-08-12 18:29:59 +0200 | [diff] [blame] | 3675 | if (signcolumn_on(wp)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3676 | { |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3677 | int text_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3678 | # ifdef FEAT_SIGN_ICONS |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 3679 | int icon_sign; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3680 | # endif |
| 3681 | |
| 3682 | /* Draw two cells with the sign value or blank. */ |
| 3683 | c_extra = ' '; |
| 3684 | char_attr = hl_attr(HLF_SC); |
| 3685 | n_extra = 2; |
| 3686 | |
Bram Moolenaar | bc6cf6c | 2014-05-22 15:51:04 +0200 | [diff] [blame] | 3687 | if (row == startrow |
| 3688 | #ifdef FEAT_DIFF |
| 3689 | + filler_lines && filler_todo <= 0 |
| 3690 | #endif |
| 3691 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3692 | { |
| 3693 | text_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3694 | SIGN_TEXT); |
| 3695 | # ifdef FEAT_SIGN_ICONS |
| 3696 | icon_sign = buf_getsigntype(wp->w_buffer, lnum, |
| 3697 | SIGN_ICON); |
| 3698 | if (gui.in_use && icon_sign != 0) |
| 3699 | { |
| 3700 | /* Use the image in this position. */ |
| 3701 | c_extra = SIGN_BYTE; |
| 3702 | # ifdef FEAT_NETBEANS_INTG |
| 3703 | if (buf_signcount(wp->w_buffer, lnum) > 1) |
| 3704 | c_extra = MULTISIGN_BYTE; |
| 3705 | # endif |
| 3706 | char_attr = icon_sign; |
| 3707 | } |
| 3708 | else |
| 3709 | # endif |
| 3710 | if (text_sign != 0) |
| 3711 | { |
| 3712 | p_extra = sign_get_text(text_sign); |
| 3713 | if (p_extra != NULL) |
| 3714 | { |
| 3715 | c_extra = NUL; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 3716 | n_extra = (int)STRLEN(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3717 | } |
| 3718 | char_attr = sign_get_attr(text_sign, FALSE); |
| 3719 | } |
| 3720 | } |
| 3721 | } |
| 3722 | } |
| 3723 | #endif |
| 3724 | |
| 3725 | if (draw_state == WL_NR - 1 && n_extra == 0) |
| 3726 | { |
| 3727 | draw_state = WL_NR; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3728 | /* Display the absolute or relative line number. After the |
| 3729 | * first fill with blanks when the 'n' flag isn't in 'cpo' */ |
| 3730 | if ((wp->w_p_nu || wp->w_p_rnu) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3731 | && (row == startrow |
| 3732 | #ifdef FEAT_DIFF |
| 3733 | + filler_lines |
| 3734 | #endif |
| 3735 | || vim_strchr(p_cpo, CPO_NUMCOL) == NULL)) |
| 3736 | { |
| 3737 | /* Draw the line number (empty space after wrapping). */ |
| 3738 | if (row == startrow |
| 3739 | #ifdef FEAT_DIFF |
| 3740 | + filler_lines |
| 3741 | #endif |
| 3742 | ) |
| 3743 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3744 | long num; |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3745 | char *fmt = "%*ld "; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3746 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3747 | if (wp->w_p_nu && !wp->w_p_rnu) |
| 3748 | /* 'number' + 'norelativenumber' */ |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3749 | num = (long)lnum; |
| 3750 | else |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3751 | { |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3752 | /* 'relativenumber', don't use negative numbers */ |
Bram Moolenaar | 7eb4652 | 2010-12-30 14:57:08 +0100 | [diff] [blame] | 3753 | num = labs((long)get_cursor_rel_lnum(wp, lnum)); |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3754 | if (num == 0 && wp->w_p_nu && wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3755 | { |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 3756 | /* 'number' + 'relativenumber' */ |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3757 | num = lnum; |
| 3758 | fmt = "%-*ld "; |
| 3759 | } |
| 3760 | } |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3761 | |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3762 | sprintf((char *)extra, fmt, |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 3763 | number_width(wp), num); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3764 | if (wp->w_skipcol > 0) |
| 3765 | for (p_extra = extra; *p_extra == ' '; ++p_extra) |
| 3766 | *p_extra = '-'; |
| 3767 | #ifdef FEAT_RIGHTLEFT |
| 3768 | if (wp->w_p_rl) /* reverse line numbers */ |
| 3769 | rl_mirror(extra); |
| 3770 | #endif |
| 3771 | p_extra = extra; |
| 3772 | c_extra = NUL; |
| 3773 | } |
| 3774 | else |
| 3775 | c_extra = ' '; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 3776 | n_extra = number_width(wp) + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3777 | char_attr = hl_attr(HLF_N); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3778 | #ifdef FEAT_SYN_HL |
| 3779 | /* When 'cursorline' is set highlight the line number of |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3780 | * the current line differently. |
| 3781 | * TODO: Can we use CursorLine instead of CursorLineNr |
| 3782 | * when CursorLineNr isn't set? */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3783 | if ((wp->w_p_cul || wp->w_p_rnu) |
Bram Moolenaar | 700e734 | 2013-01-30 12:31:36 +0100 | [diff] [blame] | 3784 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | 06ca513 | 2012-03-23 16:25:17 +0100 | [diff] [blame] | 3785 | char_attr = hl_attr(HLF_CLN); |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 3786 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3787 | } |
| 3788 | } |
| 3789 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3790 | #ifdef FEAT_LINEBREAK |
| 3791 | if (wp->w_p_brisbr && draw_state == WL_BRI - 1 |
| 3792 | && n_extra == 0 && *p_sbr != NUL) |
| 3793 | /* draw indent after showbreak value */ |
| 3794 | draw_state = WL_BRI; |
| 3795 | else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0) |
| 3796 | /* After the showbreak, draw the breakindent */ |
| 3797 | draw_state = WL_BRI - 1; |
| 3798 | |
| 3799 | /* draw 'breakindent': indent wrapped text accordingly */ |
| 3800 | if (draw_state == WL_BRI - 1 && n_extra == 0) |
| 3801 | { |
| 3802 | draw_state = WL_BRI; |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3803 | /* if need_showbreak is set, breakindent also applies */ |
| 3804 | if (wp->w_p_bri && n_extra == 0 |
| 3805 | && (row != startrow || need_showbreak) |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3806 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3807 | && filler_lines == 0 |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3808 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3809 | ) |
| 3810 | { |
Bram Moolenaar | 6c89686 | 2016-11-17 19:46:51 +0100 | [diff] [blame] | 3811 | char_attr = 0; |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3812 | # ifdef FEAT_DIFF |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3813 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3814 | { |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3815 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3816 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3817 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 3818 | char_attr = hl_combine_attr(char_attr, |
| 3819 | hl_attr(HLF_CUL)); |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3820 | # endif |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3821 | } |
Bram Moolenaar | d710e0d | 2015-06-10 12:16:47 +0200 | [diff] [blame] | 3822 | # endif |
Bram Moolenaar | b8b5746 | 2014-07-03 22:54:08 +0200 | [diff] [blame] | 3823 | p_extra = NULL; |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 3824 | c_extra = ' '; |
| 3825 | n_extra = get_breakindent_win(wp, |
| 3826 | ml_get_buf(wp->w_buffer, lnum, FALSE)); |
| 3827 | /* Correct end of highlighted area for 'breakindent', |
| 3828 | * required when 'linebreak' is also set. */ |
| 3829 | if (tocol == vcol) |
| 3830 | tocol += n_extra; |
| 3831 | } |
| 3832 | } |
| 3833 | #endif |
| 3834 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3835 | #if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF) |
| 3836 | if (draw_state == WL_SBR - 1 && n_extra == 0) |
| 3837 | { |
| 3838 | draw_state = WL_SBR; |
| 3839 | # ifdef FEAT_DIFF |
| 3840 | if (filler_todo > 0) |
| 3841 | { |
| 3842 | /* Draw "deleted" diff line(s). */ |
| 3843 | if (char2cells(fill_diff) > 1) |
| 3844 | c_extra = '-'; |
| 3845 | else |
| 3846 | c_extra = fill_diff; |
| 3847 | # ifdef FEAT_RIGHTLEFT |
| 3848 | if (wp->w_p_rl) |
| 3849 | n_extra = col + 1; |
| 3850 | else |
| 3851 | # endif |
| 3852 | n_extra = W_WIDTH(wp) - col; |
| 3853 | char_attr = hl_attr(HLF_DED); |
| 3854 | } |
| 3855 | # endif |
| 3856 | # ifdef FEAT_LINEBREAK |
| 3857 | if (*p_sbr != NUL && need_showbreak) |
| 3858 | { |
| 3859 | /* Draw 'showbreak' at the start of each broken line. */ |
| 3860 | p_extra = p_sbr; |
| 3861 | c_extra = NUL; |
| 3862 | n_extra = (int)STRLEN(p_sbr); |
| 3863 | char_attr = hl_attr(HLF_AT); |
| 3864 | need_showbreak = FALSE; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 3865 | vcol_sbr = vcol + MB_CHARLEN(p_sbr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3866 | /* Correct end of highlighted area for 'showbreak', |
| 3867 | * required when 'linebreak' is also set. */ |
| 3868 | if (tocol == vcol) |
| 3869 | tocol += n_extra; |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3870 | #ifdef FEAT_SYN_HL |
| 3871 | /* combine 'showbreak' with 'cursorline' */ |
Bram Moolenaar | bd65c46 | 2013-07-01 20:18:33 +0200 | [diff] [blame] | 3872 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 3873 | char_attr = hl_combine_attr(char_attr, |
| 3874 | hl_attr(HLF_CUL)); |
Bram Moolenaar | 5a4d51e | 2013-06-30 17:24:16 +0200 | [diff] [blame] | 3875 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3876 | } |
| 3877 | # endif |
| 3878 | } |
| 3879 | #endif |
| 3880 | |
| 3881 | if (draw_state == WL_LINE - 1 && n_extra == 0) |
| 3882 | { |
| 3883 | draw_state = WL_LINE; |
| 3884 | if (saved_n_extra) |
| 3885 | { |
| 3886 | /* Continue item from end of wrapped line. */ |
| 3887 | n_extra = saved_n_extra; |
| 3888 | c_extra = saved_c_extra; |
| 3889 | p_extra = saved_p_extra; |
| 3890 | char_attr = saved_char_attr; |
| 3891 | } |
| 3892 | else |
| 3893 | char_attr = 0; |
| 3894 | } |
| 3895 | } |
| 3896 | |
| 3897 | /* When still displaying '$' of change command, stop at cursor */ |
Bram Moolenaar | 76b9b36 | 2012-02-04 23:35:00 +0100 | [diff] [blame] | 3898 | if (dollar_vcol >= 0 && wp == curwin |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3899 | && lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3900 | #ifdef FEAT_DIFF |
| 3901 | && filler_todo <= 0 |
| 3902 | #endif |
| 3903 | ) |
| 3904 | { |
| 3905 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, -(int)W_WIDTH(wp), |
| 3906 | wp->w_p_rl); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 3907 | /* Pretend we have finished updating the window. Except when |
| 3908 | * 'cursorcolumn' is set. */ |
| 3909 | #ifdef FEAT_SYN_HL |
| 3910 | if (wp->w_p_cuc) |
| 3911 | row = wp->w_cline_row + wp->w_cline_height; |
| 3912 | else |
| 3913 | #endif |
| 3914 | row = wp->w_height; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3915 | break; |
| 3916 | } |
| 3917 | |
| 3918 | if (draw_state == WL_LINE && area_highlighting) |
| 3919 | { |
| 3920 | /* handle Visual or match highlighting in this line */ |
| 3921 | if (vcol == fromcol |
| 3922 | #ifdef FEAT_MBYTE |
| 3923 | || (has_mbyte && vcol + 1 == fromcol && n_extra == 0 |
| 3924 | && (*mb_ptr2cells)(ptr) > 1) |
| 3925 | #endif |
| 3926 | || ((int)vcol_prev == fromcol_prev |
Bram Moolenaar | fa363cd | 2009-02-21 20:23:59 +0000 | [diff] [blame] | 3927 | && vcol_prev < vcol /* not at margin */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3928 | && vcol < tocol)) |
| 3929 | area_attr = attr; /* start highlighting */ |
| 3930 | else if (area_attr != 0 |
| 3931 | && (vcol == tocol |
| 3932 | || (noinvcur && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3933 | area_attr = 0; /* stop highlighting */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3934 | |
| 3935 | #ifdef FEAT_SEARCH_EXTRA |
| 3936 | if (!n_extra) |
| 3937 | { |
| 3938 | /* |
| 3939 | * Check for start/end of search pattern match. |
| 3940 | * After end, check for start/end of next match. |
| 3941 | * When another match, have to check for start again. |
| 3942 | * Watch out for matching an empty string! |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3943 | * Do this for 'search_hl' and the match list (ordered by |
| 3944 | * priority). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3945 | */ |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3946 | v = (long)(ptr - line); |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3947 | cur = wp->w_match_head; |
| 3948 | shl_flag = FALSE; |
| 3949 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3950 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 3951 | if (shl_flag == FALSE |
| 3952 | && ((cur != NULL |
| 3953 | && cur->priority > SEARCH_HL_PRIORITY) |
| 3954 | || cur == NULL)) |
| 3955 | { |
| 3956 | shl = &search_hl; |
| 3957 | shl_flag = TRUE; |
| 3958 | } |
| 3959 | else |
| 3960 | shl = &cur->hl; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3961 | if (cur != NULL) |
| 3962 | cur->pos.cur = 0; |
| 3963 | pos_inprogress = TRUE; |
| 3964 | while (shl->rm.regprog != NULL |
| 3965 | || (cur != NULL && pos_inprogress)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3966 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 3967 | if (shl->startcol != MAXCOL |
| 3968 | && v >= (long)shl->startcol |
| 3969 | && v < (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3970 | { |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3971 | #ifdef FEAT_MBYTE |
| 3972 | int tmp_col = v + MB_PTR2LEN(ptr); |
| 3973 | |
| 3974 | if (shl->endcol < tmp_col) |
| 3975 | shl->endcol = tmp_col; |
| 3976 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3977 | shl->attr_cur = shl->attr; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3978 | #ifdef FEAT_CONCEAL |
| 3979 | if (cur != NULL && syn_name2id((char_u *)"Conceal") |
| 3980 | == cur->hlg_id) |
| 3981 | { |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3982 | has_match_conc = |
| 3983 | v == (long)shl->startcol ? 2 : 1; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3984 | match_conc = cur->conceal_char; |
| 3985 | } |
| 3986 | else |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 3987 | has_match_conc = match_conc = 0; |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3988 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3989 | } |
Bram Moolenaar | aff5c3a | 2014-12-13 03:36:39 +0100 | [diff] [blame] | 3990 | else if (v == (long)shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3991 | { |
| 3992 | shl->attr_cur = 0; |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 3993 | next_search_hl(wp, shl, lnum, (colnr_T)v, |
| 3994 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 3995 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 3996 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 3997 | |
| 3998 | /* Need to get the line again, a multi-line regexp |
| 3999 | * may have made it invalid. */ |
| 4000 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4001 | ptr = line + v; |
| 4002 | |
| 4003 | if (shl->lnum == lnum) |
| 4004 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4005 | shl->startcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4006 | if (shl->rm.endpos[0].lnum == 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4007 | shl->endcol = shl->rm.endpos[0].col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4008 | else |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4009 | shl->endcol = MAXCOL; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4010 | |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4011 | if (shl->startcol == shl->endcol) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4012 | { |
| 4013 | /* highlight empty match, try again after |
| 4014 | * it */ |
| 4015 | #ifdef FEAT_MBYTE |
| 4016 | if (has_mbyte) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4017 | shl->endcol += (*mb_ptr2len)(line |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4018 | + shl->endcol); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4019 | else |
| 4020 | #endif |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4021 | ++shl->endcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4022 | } |
| 4023 | |
| 4024 | /* Loop to check if the match starts at the |
| 4025 | * current position */ |
| 4026 | continue; |
| 4027 | } |
| 4028 | } |
| 4029 | break; |
| 4030 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4031 | if (shl != &search_hl && cur != NULL) |
| 4032 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4033 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4034 | |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4035 | /* Use attributes from match with highest priority among |
| 4036 | * 'search_hl' and the match list. */ |
| 4037 | search_attr = search_hl.attr_cur; |
| 4038 | cur = wp->w_match_head; |
| 4039 | shl_flag = FALSE; |
| 4040 | while (cur != NULL || shl_flag == FALSE) |
| 4041 | { |
| 4042 | if (shl_flag == FALSE |
| 4043 | && ((cur != NULL |
| 4044 | && cur->priority > SEARCH_HL_PRIORITY) |
| 4045 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4046 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4047 | shl = &search_hl; |
| 4048 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 4049 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4050 | else |
| 4051 | shl = &cur->hl; |
| 4052 | if (shl->attr_cur != 0) |
| 4053 | search_attr = shl->attr_cur; |
| 4054 | if (shl != &search_hl && cur != NULL) |
| 4055 | cur = cur->next; |
| 4056 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4057 | } |
| 4058 | #endif |
| 4059 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4060 | #ifdef FEAT_DIFF |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4061 | if (diff_hlf != (hlf_T)0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4062 | { |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4063 | if (diff_hlf == HLF_CHD && ptr - line >= change_start |
| 4064 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4065 | diff_hlf = HLF_TXD; /* changed text */ |
Bram Moolenaar | 4b80a51 | 2007-06-19 15:44:58 +0000 | [diff] [blame] | 4066 | if (diff_hlf == HLF_TXD && ptr - line > change_end |
| 4067 | && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4068 | diff_hlf = HLF_CHD; /* changed line */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4069 | line_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4070 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4071 | line_attr = hl_combine_attr(line_attr, hl_attr(HLF_CUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4072 | } |
| 4073 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4074 | |
| 4075 | /* Decide which of the highlight attributes to use. */ |
| 4076 | attr_pri = TRUE; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4077 | #ifdef LINE_ATTR |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4078 | if (area_attr != 0) |
| 4079 | char_attr = hl_combine_attr(line_attr, area_attr); |
| 4080 | else if (search_attr != 0) |
| 4081 | char_attr = hl_combine_attr(line_attr, search_attr); |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4082 | /* Use line_attr when not in the Visual or 'incsearch' area |
| 4083 | * (area_attr may be 0 when "noinvcur" is set). */ |
| 4084 | else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL) |
Bram Moolenaar | f837ef9 | 2009-03-11 16:47:21 +0000 | [diff] [blame] | 4085 | || vcol < fromcol || vcol_prev < fromcol_prev |
| 4086 | || vcol >= tocol)) |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4087 | char_attr = line_attr; |
Bram Moolenaar | 09deeb7 | 2015-03-24 18:22:41 +0100 | [diff] [blame] | 4088 | #else |
| 4089 | if (area_attr != 0) |
| 4090 | char_attr = area_attr; |
| 4091 | else if (search_attr != 0) |
| 4092 | char_attr = search_attr; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4093 | #endif |
| 4094 | else |
| 4095 | { |
| 4096 | attr_pri = FALSE; |
| 4097 | #ifdef FEAT_SYN_HL |
| 4098 | if (has_syntax) |
| 4099 | char_attr = syntax_attr; |
| 4100 | else |
| 4101 | #endif |
| 4102 | char_attr = 0; |
| 4103 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4104 | } |
| 4105 | |
| 4106 | /* |
| 4107 | * Get the next character to put on the screen. |
| 4108 | */ |
| 4109 | /* |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 4110 | * The "p_extra" points to the extra stuff that is inserted to |
| 4111 | * represent special characters (non-printable stuff) and other |
| 4112 | * things. When all characters are the same, c_extra is used. |
| 4113 | * "p_extra" must end in a NUL to avoid mb_ptr2len() reads past |
| 4114 | * "p_extra[n_extra]". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4115 | * For the '$' of the 'list' option, n_extra == 1, p_extra == "". |
| 4116 | */ |
| 4117 | if (n_extra > 0) |
| 4118 | { |
| 4119 | if (c_extra != NUL) |
| 4120 | { |
| 4121 | c = c_extra; |
| 4122 | #ifdef FEAT_MBYTE |
| 4123 | mb_c = c; /* doesn't handle non-utf-8 multi-byte! */ |
| 4124 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4125 | { |
| 4126 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4127 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4128 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4129 | } |
| 4130 | else |
| 4131 | mb_utf8 = FALSE; |
| 4132 | #endif |
| 4133 | } |
| 4134 | else |
| 4135 | { |
| 4136 | c = *p_extra; |
| 4137 | #ifdef FEAT_MBYTE |
| 4138 | if (has_mbyte) |
| 4139 | { |
| 4140 | mb_c = c; |
| 4141 | if (enc_utf8) |
| 4142 | { |
| 4143 | /* If the UTF-8 character is more than one byte: |
| 4144 | * Decode it into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4145 | mb_l = (*mb_ptr2len)(p_extra); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4146 | mb_utf8 = FALSE; |
| 4147 | if (mb_l > n_extra) |
| 4148 | mb_l = 1; |
| 4149 | else if (mb_l > 1) |
| 4150 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4151 | mb_c = utfc_ptr2char(p_extra, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4152 | mb_utf8 = TRUE; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4153 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4154 | } |
| 4155 | } |
| 4156 | else |
| 4157 | { |
| 4158 | /* if this is a DBCS character, put it in "mb_c" */ |
| 4159 | mb_l = MB_BYTE2LEN(c); |
| 4160 | if (mb_l >= n_extra) |
| 4161 | mb_l = 1; |
| 4162 | else if (mb_l > 1) |
| 4163 | mb_c = (c << 8) + p_extra[1]; |
| 4164 | } |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4165 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4166 | mb_l = 1; |
| 4167 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4168 | /* If a double-width char doesn't fit display a '>' in the |
| 4169 | * last column. */ |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4170 | if (( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4171 | # ifdef FEAT_RIGHTLEFT |
| 4172 | wp->w_p_rl ? (col <= 0) : |
| 4173 | # endif |
Bram Moolenaar | 92d640f | 2005-09-05 22:11:52 +0000 | [diff] [blame] | 4174 | (col >= W_WIDTH(wp) - 1)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4175 | && (*mb_char2cells)(mb_c) == 2) |
| 4176 | { |
| 4177 | c = '>'; |
| 4178 | mb_c = c; |
| 4179 | mb_l = 1; |
| 4180 | mb_utf8 = FALSE; |
| 4181 | multi_attr = hl_attr(HLF_AT); |
| 4182 | /* put the pointer back to output the double-width |
| 4183 | * character at the start of the next line. */ |
| 4184 | ++n_extra; |
| 4185 | --p_extra; |
| 4186 | } |
| 4187 | else |
| 4188 | { |
| 4189 | n_extra -= mb_l - 1; |
| 4190 | p_extra += mb_l - 1; |
| 4191 | } |
| 4192 | } |
| 4193 | #endif |
| 4194 | ++p_extra; |
| 4195 | } |
| 4196 | --n_extra; |
| 4197 | } |
| 4198 | else |
| 4199 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4200 | if (p_extra_free != NULL) |
| 4201 | { |
| 4202 | vim_free(p_extra_free); |
| 4203 | p_extra_free = NULL; |
| 4204 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4205 | /* |
| 4206 | * Get a character from the line itself. |
| 4207 | */ |
| 4208 | c = *ptr; |
| 4209 | #ifdef FEAT_MBYTE |
| 4210 | if (has_mbyte) |
| 4211 | { |
| 4212 | mb_c = c; |
| 4213 | if (enc_utf8) |
| 4214 | { |
| 4215 | /* If the UTF-8 character is more than one byte: Decode it |
| 4216 | * into "mb_c". */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 4217 | mb_l = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4218 | mb_utf8 = FALSE; |
| 4219 | if (mb_l > 1) |
| 4220 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4221 | mb_c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4222 | /* Overlong encoded ASCII or ASCII with composing char |
| 4223 | * is displayed normally, except a NUL. */ |
| 4224 | if (mb_c < 0x80) |
| 4225 | c = mb_c; |
| 4226 | mb_utf8 = TRUE; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4227 | |
| 4228 | /* At start of the line we can have a composing char. |
| 4229 | * Draw it as a space with a composing char. */ |
| 4230 | if (utf_iscomposing(mb_c)) |
| 4231 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 4232 | int i; |
| 4233 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4234 | for (i = Screen_mco - 1; i > 0; --i) |
| 4235 | u8cc[i] = u8cc[i - 1]; |
| 4236 | u8cc[0] = mb_c; |
Bram Moolenaar | cafda4f | 2005-09-06 19:25:11 +0000 | [diff] [blame] | 4237 | mb_c = ' '; |
| 4238 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | if ((mb_l == 1 && c >= 0x80) |
| 4242 | || (mb_l >= 1 && mb_c == 0) |
| 4243 | || (mb_l > 1 && (!vim_isprintc(mb_c) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4244 | # ifdef UNICODE16 |
| 4245 | || mb_c >= 0x10000 |
| 4246 | # endif |
| 4247 | ))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4248 | { |
| 4249 | /* |
| 4250 | * Illegal UTF-8 byte: display as <xx>. |
| 4251 | * Non-BMP character : display as ? or fullwidth ?. |
| 4252 | */ |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4253 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4254 | if (mb_c < 0x10000) |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4255 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4256 | { |
| 4257 | transchar_hex(extra, mb_c); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4258 | # ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4259 | if (wp->w_p_rl) /* reverse */ |
| 4260 | rl_mirror(extra); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4261 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4262 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4263 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4264 | else if (utf_char2cells(mb_c) != 2) |
| 4265 | STRCPY(extra, "?"); |
| 4266 | else |
| 4267 | /* 0xff1f in UTF-8: full-width '?' */ |
| 4268 | STRCPY(extra, "\357\274\237"); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 4269 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4270 | |
| 4271 | p_extra = extra; |
| 4272 | c = *p_extra; |
| 4273 | mb_c = mb_ptr2char_adv(&p_extra); |
| 4274 | mb_utf8 = (c >= 0x80); |
| 4275 | n_extra = (int)STRLEN(p_extra); |
| 4276 | c_extra = NUL; |
| 4277 | if (area_attr == 0 && search_attr == 0) |
| 4278 | { |
| 4279 | n_attr = n_extra + 1; |
| 4280 | extra_attr = hl_attr(HLF_8); |
| 4281 | saved_attr2 = char_attr; /* save current attr */ |
| 4282 | } |
| 4283 | } |
| 4284 | else if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4285 | mb_l = 1; |
| 4286 | #ifdef FEAT_ARABIC |
| 4287 | else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c)) |
| 4288 | { |
| 4289 | /* Do Arabic shaping. */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4290 | int pc, pc1, nc; |
| 4291 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4292 | |
| 4293 | /* The idea of what is the previous and next |
| 4294 | * character depends on 'rightleft'. */ |
| 4295 | if (wp->w_p_rl) |
| 4296 | { |
| 4297 | pc = prev_c; |
| 4298 | pc1 = prev_c1; |
| 4299 | nc = utf_ptr2char(ptr + mb_l); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4300 | prev_c1 = u8cc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4301 | } |
| 4302 | else |
| 4303 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4304 | pc = utfc_ptr2char(ptr + mb_l, pcc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4305 | nc = prev_c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4306 | pc1 = pcc[0]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4307 | } |
| 4308 | prev_c = mb_c; |
| 4309 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4310 | mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4311 | } |
| 4312 | else |
| 4313 | prev_c = mb_c; |
| 4314 | #endif |
| 4315 | } |
| 4316 | else /* enc_dbcs */ |
| 4317 | { |
| 4318 | mb_l = MB_BYTE2LEN(c); |
| 4319 | if (mb_l == 0) /* at the NUL at end-of-line */ |
| 4320 | mb_l = 1; |
| 4321 | else if (mb_l > 1) |
| 4322 | { |
| 4323 | /* We assume a second byte below 32 is illegal. |
| 4324 | * Hopefully this is OK for all double-byte encodings! |
| 4325 | */ |
| 4326 | if (ptr[1] >= 32) |
| 4327 | mb_c = (c << 8) + ptr[1]; |
| 4328 | else |
| 4329 | { |
| 4330 | if (ptr[1] == NUL) |
| 4331 | { |
| 4332 | /* head byte at end of line */ |
| 4333 | mb_l = 1; |
| 4334 | transchar_nonprint(extra, c); |
| 4335 | } |
| 4336 | else |
| 4337 | { |
| 4338 | /* illegal tail byte */ |
| 4339 | mb_l = 2; |
| 4340 | STRCPY(extra, "XX"); |
| 4341 | } |
| 4342 | p_extra = extra; |
| 4343 | n_extra = (int)STRLEN(extra) - 1; |
| 4344 | c_extra = NUL; |
| 4345 | c = *p_extra++; |
| 4346 | if (area_attr == 0 && search_attr == 0) |
| 4347 | { |
| 4348 | n_attr = n_extra + 1; |
| 4349 | extra_attr = hl_attr(HLF_8); |
| 4350 | saved_attr2 = char_attr; /* save current attr */ |
| 4351 | } |
| 4352 | mb_c = c; |
| 4353 | } |
| 4354 | } |
| 4355 | } |
| 4356 | /* If a double-width char doesn't fit display a '>' in the |
| 4357 | * last column; the character is displayed at the start of the |
| 4358 | * next line. */ |
| 4359 | if (( |
| 4360 | # ifdef FEAT_RIGHTLEFT |
| 4361 | wp->w_p_rl ? (col <= 0) : |
| 4362 | # endif |
| 4363 | (col >= W_WIDTH(wp) - 1)) |
| 4364 | && (*mb_char2cells)(mb_c) == 2) |
| 4365 | { |
| 4366 | c = '>'; |
| 4367 | mb_c = c; |
| 4368 | mb_utf8 = FALSE; |
| 4369 | mb_l = 1; |
| 4370 | multi_attr = hl_attr(HLF_AT); |
| 4371 | /* Put pointer back so that the character will be |
| 4372 | * displayed at the start of the next line. */ |
| 4373 | --ptr; |
| 4374 | } |
| 4375 | else if (*ptr != NUL) |
| 4376 | ptr += mb_l - 1; |
| 4377 | |
| 4378 | /* 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] | 4379 | * a '<' in the first column. Don't do this for unprintable |
Bram Moolenaar | 84a05ac | 2013-05-06 04:24:17 +0200 | [diff] [blame] | 4380 | * characters. */ |
Bram Moolenaar | 7ba6ed3 | 2010-08-07 16:38:13 +0200 | [diff] [blame] | 4381 | if (n_skip > 0 && mb_l > 1 && n_extra == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4382 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4383 | n_extra = 1; |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 4384 | c_extra = MB_FILLER_CHAR; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4385 | c = ' '; |
| 4386 | if (area_attr == 0 && search_attr == 0) |
| 4387 | { |
| 4388 | n_attr = n_extra + 1; |
| 4389 | extra_attr = hl_attr(HLF_AT); |
| 4390 | saved_attr2 = char_attr; /* save current attr */ |
| 4391 | } |
| 4392 | mb_c = c; |
| 4393 | mb_utf8 = FALSE; |
| 4394 | mb_l = 1; |
| 4395 | } |
| 4396 | |
| 4397 | } |
| 4398 | #endif |
| 4399 | ++ptr; |
| 4400 | |
| 4401 | if (extra_check) |
| 4402 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4403 | #ifdef FEAT_SPELL |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4404 | int can_spell = TRUE; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4405 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4406 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4407 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4408 | /* Get syntax attribute, unless still at the start of the line |
| 4409 | * (double-wide char that doesn't fit). */ |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4410 | v = (long)(ptr - line); |
| 4411 | if (has_syntax && v > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4412 | { |
| 4413 | /* Get the syntax attribute for the character. If there |
| 4414 | * is an error, disable syntax highlighting. */ |
| 4415 | save_did_emsg = did_emsg; |
| 4416 | did_emsg = FALSE; |
| 4417 | |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4418 | syntax_attr = get_syntax_attr((colnr_T)v - 1, |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4419 | # ifdef FEAT_SPELL |
| 4420 | has_spell ? &can_spell : |
| 4421 | # endif |
| 4422 | NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4423 | |
| 4424 | if (did_emsg) |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4425 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4426 | wp->w_s->b_syn_error = TRUE; |
Bram Moolenaar | 5b8d8fd | 2005-08-16 23:01:50 +0000 | [diff] [blame] | 4427 | has_syntax = FALSE; |
| 4428 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4429 | else |
| 4430 | did_emsg = save_did_emsg; |
| 4431 | |
| 4432 | /* Need to get the line again, a multi-line regexp may |
| 4433 | * have made it invalid. */ |
| 4434 | line = ml_get_buf(wp->w_buffer, lnum, FALSE); |
| 4435 | ptr = line + v; |
| 4436 | |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4437 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4438 | char_attr = syntax_attr; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4439 | else |
Bram Moolenaar | bc045ea | 2005-06-05 22:01:26 +0000 | [diff] [blame] | 4440 | char_attr = hl_combine_attr(syntax_attr, char_attr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4441 | # ifdef FEAT_CONCEAL |
| 4442 | /* no concealing past the end of the line, it interferes |
| 4443 | * with line highlighting */ |
| 4444 | if (c == NUL) |
| 4445 | syntax_flags = 0; |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4446 | else |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4447 | syntax_flags = get_syntax_info(&syntax_seqnr); |
Bram Moolenaar | c095b28 | 2010-07-20 22:33:34 +0200 | [diff] [blame] | 4448 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4449 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4450 | #endif |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4451 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4452 | #ifdef FEAT_SPELL |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4453 | /* Check spelling (unless at the end of the line). |
Bram Moolenaar | f3681cc | 2005-06-08 22:03:13 +0000 | [diff] [blame] | 4454 | * Only do this when there is no syntax highlighting, the |
| 4455 | * @Spell cluster is not used or the current syntax item |
| 4456 | * contains the @Spell cluster. */ |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4457 | if (has_spell && v >= word_end && v > cur_checked_col) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4458 | { |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4459 | spell_attr = 0; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4460 | # ifdef FEAT_SYN_HL |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4461 | if (!attr_pri) |
Bram Moolenaar | 68b76a6 | 2005-03-25 21:53:48 +0000 | [diff] [blame] | 4462 | char_attr = syntax_attr; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 4463 | # endif |
| 4464 | if (c != 0 && ( |
| 4465 | # ifdef FEAT_SYN_HL |
| 4466 | !has_syntax || |
| 4467 | # endif |
| 4468 | can_spell)) |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4469 | { |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4470 | char_u *prev_ptr, *p; |
| 4471 | int len; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4472 | hlf_T spell_hlf = HLF_COUNT; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4473 | # ifdef FEAT_MBYTE |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4474 | if (has_mbyte) |
| 4475 | { |
| 4476 | prev_ptr = ptr - mb_l; |
| 4477 | v -= mb_l - 1; |
| 4478 | } |
| 4479 | else |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4480 | # endif |
Bram Moolenaar | e756604 | 2005-06-17 22:00:15 +0000 | [diff] [blame] | 4481 | prev_ptr = ptr - 1; |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4482 | |
| 4483 | /* Use nextline[] if possible, it has the start of the |
| 4484 | * next line concatenated. */ |
| 4485 | if ((prev_ptr - line) - nextlinecol >= 0) |
| 4486 | p = nextline + (prev_ptr - line) - nextlinecol; |
| 4487 | else |
| 4488 | p = prev_ptr; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4489 | cap_col -= (int)(prev_ptr - line); |
Bram Moolenaar | 4770d09 | 2006-01-12 23:22:24 +0000 | [diff] [blame] | 4490 | len = spell_check(wp, p, &spell_hlf, &cap_col, |
| 4491 | nochange); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4492 | word_end = v + len; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4493 | |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4494 | /* In Insert mode only highlight a word that |
| 4495 | * doesn't touch the cursor. */ |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4496 | if (spell_hlf != HLF_COUNT |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4497 | && (State & INSERT) != 0 |
| 4498 | && wp->w_cursor.lnum == lnum |
| 4499 | && wp->w_cursor.col >= |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4500 | (colnr_T)(prev_ptr - line) |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4501 | && wp->w_cursor.col < (colnr_T)word_end) |
| 4502 | { |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4503 | spell_hlf = HLF_COUNT; |
Bram Moolenaar | 75c50c4 | 2005-06-04 22:06:24 +0000 | [diff] [blame] | 4504 | spell_redraw_lnum = lnum; |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4505 | } |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4506 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4507 | if (spell_hlf == HLF_COUNT && p != prev_ptr |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4508 | && (p - nextline) + len > nextline_idx) |
| 4509 | { |
| 4510 | /* Remember that the good word continues at the |
| 4511 | * start of the next line. */ |
| 4512 | checked_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4513 | checked_col = (int)((p - nextline) + len - nextline_idx); |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4514 | } |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4515 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4516 | /* Turn index into actual attributes. */ |
| 4517 | if (spell_hlf != HLF_COUNT) |
| 4518 | spell_attr = highlight_attr[spell_hlf]; |
| 4519 | |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4520 | if (cap_col > 0) |
| 4521 | { |
| 4522 | if (p != prev_ptr |
| 4523 | && (p - nextline) + cap_col >= nextline_idx) |
| 4524 | { |
| 4525 | /* Remember that the word in the next line |
| 4526 | * must start with a capital. */ |
| 4527 | capcol_lnum = lnum + 1; |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4528 | cap_col = (int)((p - nextline) + cap_col |
| 4529 | - nextline_idx); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4530 | } |
| 4531 | else |
| 4532 | /* Compute the actual column. */ |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 4533 | cap_col += (int)(prev_ptr - line); |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 4534 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4535 | } |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4536 | } |
| 4537 | if (spell_attr != 0) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4538 | { |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4539 | if (!attr_pri) |
Bram Moolenaar | 30abd28 | 2005-06-22 22:35:10 +0000 | [diff] [blame] | 4540 | char_attr = hl_combine_attr(char_attr, spell_attr); |
| 4541 | else |
| 4542 | char_attr = hl_combine_attr(spell_attr, char_attr); |
| 4543 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4544 | #endif |
| 4545 | #ifdef FEAT_LINEBREAK |
| 4546 | /* |
Bram Moolenaar | 217ad92 | 2005-03-20 22:37:15 +0000 | [diff] [blame] | 4547 | * Found last space before word: check for line break. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4548 | */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4549 | if (wp->w_p_lbr && vim_isbreak(c) && !vim_isbreak(*ptr)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4550 | { |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4551 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4552 | int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4553 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4554 | char_u *p = ptr - ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4555 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4556 | mb_off + |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4557 | # endif |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4558 | 1); |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4559 | |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4560 | /* TODO: is passing p for start of the line OK? */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4561 | n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol, |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 4562 | NULL) - 1; |
Bram Moolenaar | a365091 | 2014-11-19 13:21:57 +0100 | [diff] [blame] | 4563 | if (c == TAB && n_extra + col > W_WIDTH(wp)) |
| 4564 | n_extra = (int)wp->w_buffer->b_p_ts |
| 4565 | - vcol % (int)wp->w_buffer->b_p_ts - 1; |
| 4566 | |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4567 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 4df7029 | 2015-03-21 14:20:16 +0100 | [diff] [blame] | 4568 | c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4569 | # else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4570 | c_extra = ' '; |
Bram Moolenaar | 76feaf1 | 2015-03-20 15:58:52 +0100 | [diff] [blame] | 4571 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4572 | if (vim_iswhite(c)) |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4573 | { |
| 4574 | #ifdef FEAT_CONCEAL |
| 4575 | if (c == TAB) |
| 4576 | /* See "Tab alignment" below. */ |
| 4577 | FIX_FOR_BOGUSCOLS; |
| 4578 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4579 | if (!wp->w_p_list) |
| 4580 | c = ' '; |
Bram Moolenaar | 3ff9b18 | 2013-07-13 12:36:55 +0200 | [diff] [blame] | 4581 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4582 | } |
| 4583 | #endif |
| 4584 | |
Bram Moolenaar | 9bc01eb | 2015-12-17 21:14:58 +0100 | [diff] [blame] | 4585 | /* 'list': change char 160 to lcs_nbsp and space to lcs_space. |
| 4586 | */ |
| 4587 | if (wp->w_p_list |
| 4588 | && (((c == 160 |
| 4589 | #ifdef FEAT_MBYTE |
| 4590 | || (mb_utf8 && (mb_c == 160 || mb_c == 0x202f)) |
| 4591 | #endif |
| 4592 | ) && lcs_nbsp) |
| 4593 | || (c == ' ' && lcs_space && ptr - line <= trailcol))) |
| 4594 | { |
| 4595 | c = (c == ' ') ? lcs_space : lcs_nbsp; |
| 4596 | if (area_attr == 0 && search_attr == 0) |
| 4597 | { |
| 4598 | n_attr = 1; |
| 4599 | extra_attr = hl_attr(HLF_8); |
| 4600 | saved_attr2 = char_attr; /* save current attr */ |
| 4601 | } |
| 4602 | #ifdef FEAT_MBYTE |
| 4603 | mb_c = c; |
| 4604 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4605 | { |
| 4606 | mb_utf8 = TRUE; |
| 4607 | u8cc[0] = 0; |
| 4608 | c = 0xc0; |
| 4609 | } |
| 4610 | else |
| 4611 | mb_utf8 = FALSE; |
| 4612 | #endif |
| 4613 | } |
| 4614 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4615 | if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ') |
| 4616 | { |
| 4617 | c = lcs_trail; |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4618 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4619 | { |
| 4620 | n_attr = 1; |
| 4621 | extra_attr = hl_attr(HLF_8); |
| 4622 | saved_attr2 = char_attr; /* save current attr */ |
| 4623 | } |
| 4624 | #ifdef FEAT_MBYTE |
| 4625 | mb_c = c; |
| 4626 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4627 | { |
| 4628 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4629 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4630 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4631 | } |
| 4632 | else |
| 4633 | mb_utf8 = FALSE; |
| 4634 | #endif |
| 4635 | } |
| 4636 | } |
| 4637 | |
| 4638 | /* |
| 4639 | * Handling of non-printable characters. |
| 4640 | */ |
Bram Moolenaar | 88e8f9f | 2016-01-20 22:48:02 +0100 | [diff] [blame] | 4641 | if (!vim_isprintc(c)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4642 | { |
| 4643 | /* |
| 4644 | * when getting a character from the file, we may have to |
| 4645 | * turn it into something else on the way to putting it |
| 4646 | * into "ScreenLines". |
| 4647 | */ |
| 4648 | if (c == TAB && (!wp->w_p_list || lcs_tab1)) |
| 4649 | { |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4650 | int tab_len = 0; |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4651 | long vcol_adjusted = vcol; /* removed showbreak length */ |
| 4652 | #ifdef FEAT_LINEBREAK |
| 4653 | /* only adjust the tab_len, when at the first column |
| 4654 | * after the showbreak value was drawn */ |
| 4655 | if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap) |
| 4656 | vcol_adjusted = vcol - MB_CHARLEN(p_sbr); |
| 4657 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4658 | /* tab amount depends on current column */ |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4659 | tab_len = (int)wp->w_buffer->b_p_ts |
Bram Moolenaar | d574ea2 | 2015-01-14 19:35:14 +0100 | [diff] [blame] | 4660 | - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1; |
| 4661 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4662 | #ifdef FEAT_LINEBREAK |
Bram Moolenaar | b81c85d | 2014-07-30 16:44:22 +0200 | [diff] [blame] | 4663 | if (!wp->w_p_lbr || !wp->w_p_list) |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4664 | #endif |
| 4665 | /* tab amount depends on current column */ |
| 4666 | n_extra = tab_len; |
| 4667 | #ifdef FEAT_LINEBREAK |
| 4668 | else |
| 4669 | { |
| 4670 | char_u *p; |
| 4671 | int len = n_extra; |
| 4672 | int i; |
| 4673 | int saved_nextra = n_extra; |
| 4674 | |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4675 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4676 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4677 | /* there are characters to conceal */ |
| 4678 | tab_len += vcol_off; |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4679 | /* boguscols before FIX_FOR_BOGUSCOLS macro from above |
| 4680 | */ |
| 4681 | if (wp->w_p_list && lcs_tab1 && old_boguscols > 0 |
| 4682 | && n_extra > tab_len) |
| 4683 | tab_len += n_extra - tab_len; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4684 | #endif |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4685 | |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4686 | /* if n_extra > 0, it gives the number of chars, to |
| 4687 | * use for a tab, else we need to calculate the width |
| 4688 | * for a tab */ |
| 4689 | #ifdef FEAT_MBYTE |
| 4690 | len = (tab_len * mb_char2len(lcs_tab2)); |
| 4691 | if (n_extra > 0) |
| 4692 | len += n_extra - tab_len; |
| 4693 | #endif |
| 4694 | c = lcs_tab1; |
| 4695 | p = alloc((unsigned)(len + 1)); |
| 4696 | vim_memset(p, ' ', len); |
| 4697 | p[len] = NUL; |
Bram Moolenaar | b031c4e | 2017-01-24 20:14:48 +0100 | [diff] [blame] | 4698 | vim_free(p_extra_free); |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4699 | p_extra_free = p; |
| 4700 | for (i = 0; i < tab_len; i++) |
| 4701 | { |
| 4702 | #ifdef FEAT_MBYTE |
| 4703 | mb_char2bytes(lcs_tab2, p); |
| 4704 | p += mb_char2len(lcs_tab2); |
| 4705 | n_extra += mb_char2len(lcs_tab2) |
| 4706 | - (saved_nextra > 0 ? 1 : 0); |
| 4707 | #else |
| 4708 | p[i] = lcs_tab2; |
| 4709 | #endif |
| 4710 | } |
| 4711 | p_extra = p_extra_free; |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4712 | #ifdef FEAT_CONCEAL |
| 4713 | /* n_extra will be increased by FIX_FOX_BOGUSCOLS |
| 4714 | * macro below, so need to adjust for that here */ |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4715 | if (vcol_off > 0) |
Bram Moolenaar | 49f9dd7 | 2014-08-29 12:08:43 +0200 | [diff] [blame] | 4716 | n_extra -= vcol_off; |
| 4717 | #endif |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4718 | } |
| 4719 | #endif |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4720 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4721 | { |
| 4722 | int vc_saved = vcol_off; |
| 4723 | |
| 4724 | /* Tab alignment should be identical regardless of |
| 4725 | * 'conceallevel' value. So tab compensates of all |
| 4726 | * previous concealed characters, and thus resets |
| 4727 | * vcol_off and boguscols accumulated so far in the |
| 4728 | * line. Note that the tab can be longer than |
| 4729 | * 'tabstop' when there are concealed characters. */ |
| 4730 | FIX_FOR_BOGUSCOLS; |
| 4731 | |
| 4732 | /* Make sure, the highlighting for the tab char will be |
| 4733 | * correctly set further below (effectively reverts the |
| 4734 | * FIX_FOR_BOGSUCOLS macro */ |
| 4735 | if (n_extra == tab_len + vc_saved && wp->w_p_list |
Bram Moolenaar | 6a6028c | 2015-01-20 19:01:35 +0100 | [diff] [blame] | 4736 | && lcs_tab1) |
Bram Moolenaar | 8fc6bc7 | 2015-02-17 17:26:10 +0100 | [diff] [blame] | 4737 | tab_len += vc_saved; |
| 4738 | } |
Bram Moolenaar | 0f9d086 | 2012-12-05 15:32:30 +0100 | [diff] [blame] | 4739 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4740 | #ifdef FEAT_MBYTE |
| 4741 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4742 | #endif |
| 4743 | if (wp->w_p_list) |
| 4744 | { |
| 4745 | c = lcs_tab1; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4746 | #ifdef FEAT_LINEBREAK |
| 4747 | if (wp->w_p_lbr) |
| 4748 | c_extra = NUL; /* using p_extra from above */ |
| 4749 | else |
| 4750 | #endif |
| 4751 | c_extra = lcs_tab2; |
| 4752 | n_attr = tab_len + 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4753 | extra_attr = hl_attr(HLF_8); |
| 4754 | saved_attr2 = char_attr; /* save current attr */ |
| 4755 | #ifdef FEAT_MBYTE |
| 4756 | mb_c = c; |
| 4757 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4758 | { |
| 4759 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4760 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4761 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4762 | } |
| 4763 | #endif |
| 4764 | } |
| 4765 | else |
| 4766 | { |
| 4767 | c_extra = ' '; |
| 4768 | c = ' '; |
| 4769 | } |
| 4770 | } |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4771 | else if (c == NUL |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4772 | && (wp->w_p_list |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4773 | || ((fromcol >= 0 || fromcol_prev >= 0) |
| 4774 | && tocol > vcol |
| 4775 | && VIsual_mode != Ctrl_V |
| 4776 | && ( |
| 4777 | # ifdef FEAT_RIGHTLEFT |
| 4778 | wp->w_p_rl ? (col >= 0) : |
| 4779 | # endif |
| 4780 | (col < W_WIDTH(wp))) |
| 4781 | && !(noinvcur |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 4782 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4783 | && (colnr_T)vcol == wp->w_virtcol))) |
Bram Moolenaar | 0481fee | 2015-05-14 05:56:09 +0200 | [diff] [blame] | 4784 | && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4785 | { |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4786 | /* Display a '$' after the line or highlight an extra |
| 4787 | * character if the line break is included. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4788 | #if defined(FEAT_DIFF) || defined(LINE_ATTR) |
| 4789 | /* For a diff line the highlighting continues after the |
| 4790 | * "$". */ |
| 4791 | if ( |
| 4792 | # ifdef FEAT_DIFF |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 4793 | diff_hlf == (hlf_T)0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4794 | # ifdef LINE_ATTR |
| 4795 | && |
| 4796 | # endif |
| 4797 | # endif |
| 4798 | # ifdef LINE_ATTR |
| 4799 | line_attr == 0 |
| 4800 | # endif |
| 4801 | ) |
| 4802 | #endif |
| 4803 | { |
| 4804 | #ifdef FEAT_VIRTUALEDIT |
| 4805 | /* In virtualedit, visual selections may extend |
| 4806 | * beyond end of line. */ |
| 4807 | if (area_highlighting && virtual_active() |
| 4808 | && tocol != MAXCOL && vcol < tocol) |
| 4809 | n_extra = 0; |
| 4810 | else |
| 4811 | #endif |
| 4812 | { |
| 4813 | p_extra = at_end_str; |
| 4814 | n_extra = 1; |
| 4815 | c_extra = NUL; |
| 4816 | } |
| 4817 | } |
Bram Moolenaar | d59c099 | 2015-05-04 16:52:01 +0200 | [diff] [blame] | 4818 | if (wp->w_p_list && lcs_eol > 0) |
Bram Moolenaar | 293ee4d | 2004-12-09 21:34:53 +0000 | [diff] [blame] | 4819 | c = lcs_eol; |
| 4820 | else |
| 4821 | c = ' '; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4822 | lcs_eol_one = -1; |
| 4823 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4824 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4825 | { |
| 4826 | extra_attr = hl_attr(HLF_AT); |
| 4827 | n_attr = 1; |
| 4828 | } |
| 4829 | #ifdef FEAT_MBYTE |
| 4830 | mb_c = c; |
| 4831 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4832 | { |
| 4833 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 4834 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 4835 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4836 | } |
| 4837 | else |
| 4838 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4839 | #endif |
| 4840 | } |
| 4841 | else if (c != NUL) |
| 4842 | { |
| 4843 | p_extra = transchar(c); |
Bram Moolenaar | 5524aeb | 2014-07-16 17:29:51 +0200 | [diff] [blame] | 4844 | if (n_extra == 0) |
| 4845 | n_extra = byte2cells(c) - 1; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4846 | #ifdef FEAT_RIGHTLEFT |
| 4847 | if ((dy_flags & DY_UHEX) && wp->w_p_rl) |
| 4848 | rl_mirror(p_extra); /* reverse "<12>" */ |
| 4849 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4850 | c_extra = NUL; |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4851 | #ifdef FEAT_LINEBREAK |
| 4852 | if (wp->w_p_lbr) |
| 4853 | { |
| 4854 | char_u *p; |
| 4855 | |
| 4856 | c = *p_extra; |
| 4857 | p = alloc((unsigned)n_extra + 1); |
| 4858 | vim_memset(p, ' ', n_extra); |
| 4859 | STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1); |
| 4860 | p[n_extra] = NUL; |
Bram Moolenaar | b031c4e | 2017-01-24 20:14:48 +0100 | [diff] [blame] | 4861 | vim_free(p_extra_free); |
Bram Moolenaar | 86b17e9 | 2014-07-02 20:00:47 +0200 | [diff] [blame] | 4862 | p_extra_free = p_extra = p; |
| 4863 | } |
| 4864 | else |
| 4865 | #endif |
| 4866 | { |
| 4867 | n_extra = byte2cells(c) - 1; |
| 4868 | c = *p_extra++; |
| 4869 | } |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 4870 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4871 | { |
| 4872 | n_attr = n_extra + 1; |
| 4873 | extra_attr = hl_attr(HLF_8); |
| 4874 | saved_attr2 = char_attr; /* save current attr */ |
| 4875 | } |
| 4876 | #ifdef FEAT_MBYTE |
| 4877 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 4878 | #endif |
| 4879 | } |
| 4880 | #ifdef FEAT_VIRTUALEDIT |
| 4881 | else if (VIsual_active |
| 4882 | && (VIsual_mode == Ctrl_V |
| 4883 | || VIsual_mode == 'v') |
| 4884 | && virtual_active() |
| 4885 | && tocol != MAXCOL |
| 4886 | && vcol < tocol |
| 4887 | && ( |
| 4888 | # ifdef FEAT_RIGHTLEFT |
| 4889 | wp->w_p_rl ? (col >= 0) : |
| 4890 | # endif |
| 4891 | (col < W_WIDTH(wp)))) |
| 4892 | { |
| 4893 | c = ' '; |
| 4894 | --ptr; /* put it back at the NUL */ |
| 4895 | } |
| 4896 | #endif |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4897 | #if defined(LINE_ATTR) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4898 | else if (( |
| 4899 | # ifdef FEAT_DIFF |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 4900 | diff_hlf != (hlf_T)0 || |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4901 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4902 | line_attr != 0 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4903 | ) && ( |
| 4904 | # ifdef FEAT_RIGHTLEFT |
| 4905 | wp->w_p_rl ? (col >= 0) : |
| 4906 | # endif |
Bram Moolenaar | 2a988a1 | 2010-08-13 15:24:39 +0200 | [diff] [blame] | 4907 | (col |
| 4908 | # ifdef FEAT_CONCEAL |
| 4909 | - boguscols |
| 4910 | # endif |
| 4911 | < W_WIDTH(wp)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4912 | { |
| 4913 | /* Highlight until the right side of the window */ |
| 4914 | c = ' '; |
| 4915 | --ptr; /* put it back at the NUL */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 4916 | |
| 4917 | /* Remember we do the char for line highlighting. */ |
| 4918 | ++did_line_attr; |
| 4919 | |
| 4920 | /* don't do search HL for the rest of the line */ |
| 4921 | if (line_attr != 0 && char_attr == search_attr && col > 0) |
| 4922 | char_attr = line_attr; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4923 | # ifdef FEAT_DIFF |
| 4924 | if (diff_hlf == HLF_TXD) |
| 4925 | { |
| 4926 | diff_hlf = HLF_CHD; |
| 4927 | if (attr == 0 || char_attr != attr) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4928 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4929 | char_attr = hl_attr(diff_hlf); |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 4930 | if (wp->w_p_cul && lnum == wp->w_cursor.lnum) |
| 4931 | char_attr = hl_combine_attr(char_attr, |
| 4932 | hl_attr(HLF_CUL)); |
| 4933 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 4934 | } |
| 4935 | # endif |
| 4936 | } |
| 4937 | #endif |
| 4938 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4939 | |
| 4940 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4941 | if ( wp->w_p_cole > 0 |
| 4942 | && (wp != curwin || lnum != wp->w_cursor.lnum || |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4943 | conceal_cursor_line(wp) ) |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4944 | && ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0) |
Bram Moolenaar | e6dc573 | 2010-07-24 23:52:26 +0200 | [diff] [blame] | 4945 | && !(lnum_in_visual_area |
| 4946 | && vim_strchr(wp->w_p_cocu, 'v') == NULL)) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4947 | { |
| 4948 | char_attr = conceal_attr; |
Bram Moolenaar | 4d58502 | 2016-04-14 19:50:22 +0200 | [diff] [blame] | 4949 | if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1) |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4950 | && (syn_get_sub_char() != NUL || match_conc |
| 4951 | || wp->w_p_cole == 1) |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 4952 | && wp->w_p_cole != 3) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4953 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 4954 | /* First time at this concealed item: display one |
| 4955 | * character. */ |
Bram Moolenaar | 6561d52 | 2015-07-21 15:48:27 +0200 | [diff] [blame] | 4956 | if (match_conc) |
| 4957 | c = match_conc; |
| 4958 | else if (syn_get_sub_char() != NUL) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4959 | c = syn_get_sub_char(); |
| 4960 | else if (lcs_conceal != NUL) |
| 4961 | c = lcs_conceal; |
| 4962 | else |
| 4963 | c = ' '; |
| 4964 | |
Bram Moolenaar | ffbbcb5 | 2010-07-24 17:29:03 +0200 | [diff] [blame] | 4965 | prev_syntax_id = syntax_seqnr; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4966 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 4967 | if (n_extra > 0) |
| 4968 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 4969 | vcol += n_extra; |
| 4970 | if (wp->w_p_wrap && n_extra > 0) |
| 4971 | { |
| 4972 | # ifdef FEAT_RIGHTLEFT |
| 4973 | if (wp->w_p_rl) |
| 4974 | { |
| 4975 | col -= n_extra; |
| 4976 | boguscols -= n_extra; |
| 4977 | } |
| 4978 | else |
| 4979 | # endif |
| 4980 | { |
| 4981 | boguscols += n_extra; |
| 4982 | col += n_extra; |
| 4983 | } |
| 4984 | } |
| 4985 | n_extra = 0; |
| 4986 | n_attr = 0; |
| 4987 | } |
| 4988 | else if (n_skip == 0) |
| 4989 | { |
| 4990 | is_concealing = TRUE; |
| 4991 | n_skip = 1; |
| 4992 | } |
| 4993 | # ifdef FEAT_MBYTE |
| 4994 | mb_c = c; |
| 4995 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 4996 | { |
| 4997 | mb_utf8 = TRUE; |
| 4998 | u8cc[0] = 0; |
| 4999 | c = 0xc0; |
| 5000 | } |
| 5001 | else |
| 5002 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5003 | # endif |
| 5004 | } |
| 5005 | else |
| 5006 | { |
Bram Moolenaar | 27c735b | 2010-07-22 22:16:29 +0200 | [diff] [blame] | 5007 | prev_syntax_id = 0; |
Bram Moolenaar | c400cb9 | 2010-07-19 19:52:13 +0200 | [diff] [blame] | 5008 | is_concealing = FALSE; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5009 | } |
| 5010 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5011 | } |
| 5012 | |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5013 | #ifdef FEAT_CONCEAL |
| 5014 | /* In the cursor line and we may be concealing characters: correct |
| 5015 | * the cursor column when we reach its position. */ |
Bram Moolenaar | f691b84 | 2010-07-24 13:31:09 +0200 | [diff] [blame] | 5016 | if (!did_wcol && draw_state == WL_LINE |
| 5017 | && wp == curwin && lnum == wp->w_cursor.lnum |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5018 | && conceal_cursor_line(wp) |
| 5019 | && (int)wp->w_virtcol <= vcol + n_skip) |
| 5020 | { |
Bram Moolenaar | e39b3d9 | 2016-01-15 22:52:22 +0100 | [diff] [blame] | 5021 | # ifdef FEAT_RIGHTLEFT |
| 5022 | if (wp->w_p_rl) |
| 5023 | wp->w_wcol = W_WIDTH(wp) - col + boguscols - 1; |
| 5024 | else |
| 5025 | # endif |
| 5026 | wp->w_wcol = col - boguscols; |
Bram Moolenaar | 72ada0f | 2010-07-24 17:39:52 +0200 | [diff] [blame] | 5027 | wp->w_wrow = row; |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5028 | did_wcol = TRUE; |
| 5029 | } |
| 5030 | #endif |
| 5031 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5032 | /* Don't override visual selection highlighting. */ |
| 5033 | if (n_attr > 0 |
| 5034 | && draw_state == WL_LINE |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5035 | && !attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5036 | char_attr = extra_attr; |
| 5037 | |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 5038 | #if defined(FEAT_XIM) && defined(FEAT_GUI_GTK) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5039 | /* XIM don't send preedit_start and preedit_end, but they send |
| 5040 | * preedit_changed and commit. Thus Vim can't set "im_is_active", use |
| 5041 | * im_is_preediting() here. */ |
| 5042 | if (xic != NULL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5043 | && lnum == wp->w_cursor.lnum |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5044 | && (State & INSERT) |
| 5045 | && !p_imdisable |
| 5046 | && im_is_preediting() |
| 5047 | && draw_state == WL_LINE) |
| 5048 | { |
| 5049 | colnr_T tcol; |
| 5050 | |
| 5051 | if (preedit_end_col == MAXCOL) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5052 | getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5053 | else |
| 5054 | tcol = preedit_end_col; |
| 5055 | if ((long)preedit_start_col <= vcol && vcol < (long)tcol) |
| 5056 | { |
| 5057 | if (feedback_old_attr < 0) |
| 5058 | { |
| 5059 | feedback_col = 0; |
| 5060 | feedback_old_attr = char_attr; |
| 5061 | } |
| 5062 | char_attr = im_get_feedback_attr(feedback_col); |
| 5063 | if (char_attr < 0) |
| 5064 | char_attr = feedback_old_attr; |
| 5065 | feedback_col++; |
| 5066 | } |
| 5067 | else if (feedback_old_attr >= 0) |
| 5068 | { |
| 5069 | char_attr = feedback_old_attr; |
| 5070 | feedback_old_attr = -1; |
| 5071 | feedback_col = 0; |
| 5072 | } |
| 5073 | } |
| 5074 | #endif |
| 5075 | /* |
| 5076 | * Handle the case where we are in column 0 but not on the first |
| 5077 | * character of the line and the user wants us to show us a |
| 5078 | * special character (via 'listchars' option "precedes:<char>". |
| 5079 | */ |
| 5080 | if (lcs_prec_todo != NUL |
Bram Moolenaar | 7425b93 | 2014-10-10 15:28:46 +0200 | [diff] [blame] | 5081 | && wp->w_p_list |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5082 | && (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0) |
| 5083 | #ifdef FEAT_DIFF |
| 5084 | && filler_todo <= 0 |
| 5085 | #endif |
| 5086 | && draw_state > WL_NR |
| 5087 | && c != NUL) |
| 5088 | { |
| 5089 | c = lcs_prec; |
| 5090 | lcs_prec_todo = NUL; |
| 5091 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 5641f38 | 2012-06-13 18:06:36 +0200 | [diff] [blame] | 5092 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5093 | { |
| 5094 | /* Double-width character being overwritten by the "precedes" |
| 5095 | * character, need to fill up half the character. */ |
| 5096 | c_extra = MB_FILLER_CHAR; |
| 5097 | n_extra = 1; |
| 5098 | n_attr = 2; |
| 5099 | extra_attr = hl_attr(HLF_AT); |
| 5100 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5101 | mb_c = c; |
| 5102 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5103 | { |
| 5104 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5105 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5106 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5107 | } |
| 5108 | else |
| 5109 | mb_utf8 = FALSE; /* don't draw as UTF-8 */ |
| 5110 | #endif |
Bram Moolenaar | 7e8fd63 | 2006-02-18 22:14:51 +0000 | [diff] [blame] | 5111 | if (!attr_pri) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5112 | { |
| 5113 | saved_attr3 = char_attr; /* save current attr */ |
| 5114 | char_attr = hl_attr(HLF_AT); /* later copied to char_attr */ |
| 5115 | n_attr3 = 1; |
| 5116 | } |
| 5117 | } |
| 5118 | |
| 5119 | /* |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5120 | * At end of the text line or just after the last character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5121 | */ |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5122 | if (c == NUL |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5123 | #if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5124 | || did_line_attr == 1 |
| 5125 | #endif |
| 5126 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5127 | { |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5128 | #ifdef FEAT_SEARCH_EXTRA |
| 5129 | long prevcol = (long)(ptr - line) - (c == NUL); |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5130 | |
| 5131 | /* we're not really at that column when skipping some text */ |
Bram Moolenaar | 33741a0 | 2007-11-08 20:24:19 +0000 | [diff] [blame] | 5132 | 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] | 5133 | ++prevcol; |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5134 | #endif |
| 5135 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5136 | /* Invert at least one char, used for Visual and empty line or |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5137 | * highlight match at end of line. If it's beyond the last |
| 5138 | * char on the screen, just overwrite that one (tricky!) Not |
| 5139 | * needed when a '$' was displayed for 'list'. */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5140 | #ifdef FEAT_SEARCH_EXTRA |
| 5141 | prevcol_hl_flag = FALSE; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5142 | if (!search_hl.is_addpos && prevcol == (long)search_hl.startcol) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5143 | prevcol_hl_flag = TRUE; |
| 5144 | else |
| 5145 | { |
| 5146 | cur = wp->w_match_head; |
| 5147 | while (cur != NULL) |
| 5148 | { |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5149 | if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5150 | { |
| 5151 | prevcol_hl_flag = TRUE; |
| 5152 | break; |
| 5153 | } |
| 5154 | cur = cur->next; |
| 5155 | } |
| 5156 | } |
| 5157 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5158 | if (lcs_eol == lcs_eol_one |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5159 | && ((area_attr != 0 && vcol == fromcol |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5160 | && (VIsual_mode != Ctrl_V |
| 5161 | || lnum == VIsual.lnum |
| 5162 | || lnum == curwin->w_cursor.lnum) |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5163 | && c == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5164 | #ifdef FEAT_SEARCH_EXTRA |
| 5165 | /* highlight 'hlsearch' match at end of line */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5166 | || (prevcol_hl_flag == TRUE |
Bram Moolenaar | 6c60ea2 | 2006-07-11 20:36:45 +0000 | [diff] [blame] | 5167 | # if defined(LINE_ATTR) |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5168 | && did_line_attr <= 1 |
| 5169 | # endif |
| 5170 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5171 | #endif |
| 5172 | )) |
| 5173 | { |
| 5174 | int n = 0; |
| 5175 | |
| 5176 | #ifdef FEAT_RIGHTLEFT |
| 5177 | if (wp->w_p_rl) |
| 5178 | { |
| 5179 | if (col < 0) |
| 5180 | n = 1; |
| 5181 | } |
| 5182 | else |
| 5183 | #endif |
| 5184 | { |
| 5185 | if (col >= W_WIDTH(wp)) |
| 5186 | n = -1; |
| 5187 | } |
| 5188 | if (n != 0) |
| 5189 | { |
| 5190 | /* At the window boundary, highlight the last character |
| 5191 | * instead (better than nothing). */ |
| 5192 | off += n; |
| 5193 | col += n; |
| 5194 | } |
| 5195 | else |
| 5196 | { |
| 5197 | /* Add a blank character to highlight. */ |
| 5198 | ScreenLines[off] = ' '; |
| 5199 | #ifdef FEAT_MBYTE |
| 5200 | if (enc_utf8) |
| 5201 | ScreenLinesUC[off] = 0; |
| 5202 | #endif |
| 5203 | } |
| 5204 | #ifdef FEAT_SEARCH_EXTRA |
| 5205 | if (area_attr == 0) |
| 5206 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5207 | /* Use attributes from match with highest priority among |
| 5208 | * 'search_hl' and the match list. */ |
| 5209 | char_attr = search_hl.attr; |
| 5210 | cur = wp->w_match_head; |
| 5211 | shl_flag = FALSE; |
| 5212 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5213 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5214 | if (shl_flag == FALSE |
| 5215 | && ((cur != NULL |
| 5216 | && cur->priority > SEARCH_HL_PRIORITY) |
| 5217 | || cur == NULL)) |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5218 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5219 | shl = &search_hl; |
| 5220 | shl_flag = TRUE; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5221 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5222 | else |
| 5223 | shl = &cur->hl; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 5224 | if ((ptr - line) - 1 == (long)shl->startcol |
| 5225 | && (shl == &search_hl || !shl->is_addpos)) |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5226 | char_attr = shl->attr; |
| 5227 | if (shl != &search_hl && cur != NULL) |
| 5228 | cur = cur->next; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 5229 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5230 | } |
| 5231 | #endif |
| 5232 | ScreenAttrs[off] = char_attr; |
| 5233 | #ifdef FEAT_RIGHTLEFT |
| 5234 | if (wp->w_p_rl) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5235 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5236 | --col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5237 | --off; |
| 5238 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5239 | else |
| 5240 | #endif |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5241 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5242 | ++col; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5243 | ++off; |
| 5244 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5245 | ++vcol; |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5246 | #ifdef FEAT_SYN_HL |
| 5247 | eol_hl_off = 1; |
| 5248 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5249 | } |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5250 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5251 | |
Bram Moolenaar | 91170f8 | 2006-05-05 21:15:17 +0000 | [diff] [blame] | 5252 | /* |
| 5253 | * At end of the text line. |
| 5254 | */ |
| 5255 | if (c == NUL) |
| 5256 | { |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5257 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | f3205d1 | 2009-03-18 18:09:03 +0000 | [diff] [blame] | 5258 | if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol |
| 5259 | && lnum == wp->w_cursor.lnum) |
Bram Moolenaar | a443af8 | 2007-11-08 13:51:42 +0000 | [diff] [blame] | 5260 | { |
| 5261 | /* highlight last char after line */ |
| 5262 | --col; |
| 5263 | --off; |
| 5264 | --vcol; |
| 5265 | } |
| 5266 | |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5267 | /* Highlight 'cursorcolumn' & 'colorcolumn' past end of the line. */ |
Bram Moolenaar | 1f4d4de | 2006-03-14 23:00:46 +0000 | [diff] [blame] | 5268 | if (wp->w_p_wrap) |
| 5269 | v = wp->w_skipcol; |
| 5270 | else |
| 5271 | v = wp->w_leftcol; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5272 | |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5273 | /* check if line ends before left margin */ |
| 5274 | if (vcol < v + col - win_col_off(wp)) |
Bram Moolenaar | 8dff818 | 2006-04-06 20:18:50 +0000 | [diff] [blame] | 5275 | vcol = v + col - win_col_off(wp); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5276 | #ifdef FEAT_CONCEAL |
| 5277 | /* Get rid of the boguscols now, we want to draw until the right |
| 5278 | * edge for 'cursorcolumn'. */ |
| 5279 | col -= boguscols; |
| 5280 | boguscols = 0; |
| 5281 | #endif |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5282 | |
| 5283 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5284 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5285 | |
| 5286 | if (((wp->w_p_cuc |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5287 | && (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off |
| 5288 | && (int)wp->w_virtcol < |
| 5289 | W_WIDTH(wp) * (row - startrow + 1) + v |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5290 | && lnum != wp->w_cursor.lnum) |
| 5291 | || draw_color_col) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5292 | # ifdef FEAT_RIGHTLEFT |
| 5293 | && !wp->w_p_rl |
| 5294 | # endif |
| 5295 | ) |
| 5296 | { |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5297 | int rightmost_vcol = 0; |
| 5298 | int i; |
| 5299 | |
| 5300 | if (wp->w_p_cuc) |
| 5301 | rightmost_vcol = wp->w_virtcol; |
| 5302 | if (draw_color_col) |
| 5303 | /* determine rightmost colorcolumn to possibly draw */ |
| 5304 | for (i = 0; color_cols[i] >= 0; ++i) |
| 5305 | if (rightmost_vcol < color_cols[i]) |
| 5306 | rightmost_vcol = color_cols[i]; |
| 5307 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5308 | while (col < W_WIDTH(wp)) |
| 5309 | { |
| 5310 | ScreenLines[off] = ' '; |
| 5311 | #ifdef FEAT_MBYTE |
| 5312 | if (enc_utf8) |
| 5313 | ScreenLinesUC[off] = 0; |
| 5314 | #endif |
| 5315 | ++col; |
Bram Moolenaar | 973bd47 | 2010-07-20 11:29:07 +0200 | [diff] [blame] | 5316 | if (draw_color_col) |
| 5317 | draw_color_col = advance_color_col(VCOL_HLC, |
| 5318 | &color_cols); |
| 5319 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5320 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5321 | ScreenAttrs[off++] = hl_attr(HLF_CUC); |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5322 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5323 | ScreenAttrs[off++] = hl_attr(HLF_MC); |
| 5324 | else |
| 5325 | ScreenAttrs[off++] = 0; |
| 5326 | |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5327 | if (VCOL_HLC >= rightmost_vcol) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5328 | break; |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5329 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5330 | ++vcol; |
| 5331 | } |
| 5332 | } |
| 5333 | #endif |
| 5334 | |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5335 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5336 | (int)W_WIDTH(wp), wp->w_p_rl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5337 | row++; |
| 5338 | |
| 5339 | /* |
| 5340 | * Update w_cline_height and w_cline_folded if the cursor line was |
| 5341 | * updated (saves a call to plines() later). |
| 5342 | */ |
| 5343 | if (wp == curwin && lnum == curwin->w_cursor.lnum) |
| 5344 | { |
| 5345 | curwin->w_cline_row = startrow; |
| 5346 | curwin->w_cline_height = row - startrow; |
| 5347 | #ifdef FEAT_FOLDING |
| 5348 | curwin->w_cline_folded = FALSE; |
| 5349 | #endif |
| 5350 | curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW); |
| 5351 | } |
| 5352 | |
| 5353 | break; |
| 5354 | } |
| 5355 | |
| 5356 | /* line continues beyond line end */ |
| 5357 | if (lcs_ext |
| 5358 | && !wp->w_p_wrap |
| 5359 | #ifdef FEAT_DIFF |
| 5360 | && filler_todo <= 0 |
| 5361 | #endif |
| 5362 | && ( |
| 5363 | #ifdef FEAT_RIGHTLEFT |
| 5364 | wp->w_p_rl ? col == 0 : |
| 5365 | #endif |
| 5366 | col == W_WIDTH(wp) - 1) |
| 5367 | && (*ptr != NUL |
Bram Moolenaar | 5bbc21d | 2008-03-09 13:30:56 +0000 | [diff] [blame] | 5368 | || (wp->w_p_list && lcs_eol_one > 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5369 | || (n_extra && (c_extra != NUL || *p_extra != NUL)))) |
| 5370 | { |
| 5371 | c = lcs_ext; |
| 5372 | char_attr = hl_attr(HLF_AT); |
| 5373 | #ifdef FEAT_MBYTE |
| 5374 | mb_c = c; |
| 5375 | if (enc_utf8 && (*mb_char2len)(c) > 1) |
| 5376 | { |
| 5377 | mb_utf8 = TRUE; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5378 | u8cc[0] = 0; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5379 | c = 0xc0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5380 | } |
| 5381 | else |
| 5382 | mb_utf8 = FALSE; |
| 5383 | #endif |
| 5384 | } |
| 5385 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5386 | #ifdef FEAT_SYN_HL |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5387 | /* advance to the next 'colorcolumn' */ |
| 5388 | if (draw_color_col) |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5389 | draw_color_col = advance_color_col(VCOL_HLC, &color_cols); |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5390 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5391 | /* Highlight the cursor column if 'cursorcolumn' is set. But don't |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5392 | * highlight the cursor position itself. |
| 5393 | * Also highlight the 'colorcolumn' if it is different than |
| 5394 | * 'cursorcolumn' */ |
| 5395 | vcol_save_attr = -1; |
| 5396 | if (draw_state == WL_LINE && !lnum_in_visual_area) |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5397 | { |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5398 | if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5399 | && lnum != wp->w_cursor.lnum) |
| 5400 | { |
| 5401 | vcol_save_attr = char_attr; |
| 5402 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_CUC)); |
| 5403 | } |
Bram Moolenaar | d160c34 | 2010-07-18 23:30:34 +0200 | [diff] [blame] | 5404 | else if (draw_color_col && VCOL_HLC == *color_cols) |
Bram Moolenaar | 1a38442 | 2010-07-14 19:53:30 +0200 | [diff] [blame] | 5405 | { |
| 5406 | vcol_save_attr = char_attr; |
| 5407 | char_attr = hl_combine_attr(char_attr, hl_attr(HLF_MC)); |
| 5408 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5409 | } |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5410 | #endif |
| 5411 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5412 | /* |
| 5413 | * Store character to be displayed. |
| 5414 | * Skip characters that are left of the screen for 'nowrap'. |
| 5415 | */ |
| 5416 | vcol_prev = vcol; |
| 5417 | if (draw_state < WL_LINE || n_skip <= 0) |
| 5418 | { |
| 5419 | /* |
| 5420 | * Store the character. |
| 5421 | */ |
| 5422 | #if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE) |
| 5423 | if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) |
| 5424 | { |
| 5425 | /* A double-wide character is: put first halve in left cell. */ |
| 5426 | --off; |
| 5427 | --col; |
| 5428 | } |
| 5429 | #endif |
| 5430 | ScreenLines[off] = c; |
| 5431 | #ifdef FEAT_MBYTE |
| 5432 | if (enc_dbcs == DBCS_JPNU) |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5433 | { |
| 5434 | if ((mb_c & 0xff00) == 0x8e00) |
| 5435 | ScreenLines[off] = 0x8e; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5436 | ScreenLines2[off] = mb_c & 0xff; |
Bram Moolenaar | 990bb66 | 2010-02-03 15:48:04 +0100 | [diff] [blame] | 5437 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5438 | else if (enc_utf8) |
| 5439 | { |
| 5440 | if (mb_utf8) |
| 5441 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 5442 | int i; |
| 5443 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5444 | ScreenLinesUC[off] = mb_c; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 5445 | if ((c & 0xff) == 0) |
| 5446 | ScreenLines[off] = 0x80; /* avoid storing zero */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5447 | for (i = 0; i < Screen_mco; ++i) |
| 5448 | { |
| 5449 | ScreenLinesC[i][off] = u8cc[i]; |
| 5450 | if (u8cc[i] == 0) |
| 5451 | break; |
| 5452 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5453 | } |
| 5454 | else |
| 5455 | ScreenLinesUC[off] = 0; |
| 5456 | } |
| 5457 | if (multi_attr) |
| 5458 | { |
| 5459 | ScreenAttrs[off] = multi_attr; |
| 5460 | multi_attr = 0; |
| 5461 | } |
| 5462 | else |
| 5463 | #endif |
| 5464 | ScreenAttrs[off] = char_attr; |
| 5465 | |
| 5466 | #ifdef FEAT_MBYTE |
| 5467 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5468 | { |
| 5469 | /* Need to fill two screen columns. */ |
| 5470 | ++off; |
| 5471 | ++col; |
| 5472 | if (enc_utf8) |
| 5473 | /* UTF-8: Put a 0 in the second screen char. */ |
| 5474 | ScreenLines[off] = 0; |
| 5475 | else |
| 5476 | /* DBCS: Put second byte in the second screen char. */ |
| 5477 | ScreenLines[off] = mb_c & 0xff; |
Bram Moolenaar | 32a214e | 2015-12-03 14:29:02 +0100 | [diff] [blame] | 5478 | if (draw_state > WL_NR |
| 5479 | #ifdef FEAT_DIFF |
| 5480 | && filler_todo <= 0 |
| 5481 | #endif |
| 5482 | ) |
| 5483 | ++vcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5484 | /* When "tocol" is halfway a character, set it to the end of |
| 5485 | * the character, otherwise highlighting won't stop. */ |
| 5486 | if (tocol == vcol) |
| 5487 | ++tocol; |
| 5488 | #ifdef FEAT_RIGHTLEFT |
| 5489 | if (wp->w_p_rl) |
| 5490 | { |
| 5491 | /* now it's time to backup one cell */ |
| 5492 | --off; |
| 5493 | --col; |
| 5494 | } |
| 5495 | #endif |
| 5496 | } |
| 5497 | #endif |
| 5498 | #ifdef FEAT_RIGHTLEFT |
| 5499 | if (wp->w_p_rl) |
| 5500 | { |
| 5501 | --off; |
| 5502 | --col; |
| 5503 | } |
| 5504 | else |
| 5505 | #endif |
| 5506 | { |
| 5507 | ++off; |
| 5508 | ++col; |
| 5509 | } |
| 5510 | } |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5511 | #ifdef FEAT_CONCEAL |
Bram Moolenaar | f5963f7 | 2010-07-23 22:10:27 +0200 | [diff] [blame] | 5512 | else if (wp->w_p_cole > 0 && is_concealing) |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5513 | { |
| 5514 | --n_skip; |
Bram Moolenaar | ac550fd | 2010-07-18 13:55:02 +0200 | [diff] [blame] | 5515 | ++vcol_off; |
| 5516 | if (n_extra > 0) |
| 5517 | vcol_off += n_extra; |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5518 | if (wp->w_p_wrap) |
| 5519 | { |
| 5520 | /* |
| 5521 | * Special voodoo required if 'wrap' is on. |
| 5522 | * |
| 5523 | * Advance the column indicator to force the line |
| 5524 | * drawing to wrap early. This will make the line |
| 5525 | * take up the same screen space when parts are concealed, |
| 5526 | * so that cursor line computations aren't messed up. |
| 5527 | * |
| 5528 | * To avoid the fictitious advance of 'col' causing |
| 5529 | * trailing junk to be written out of the screen line |
| 5530 | * we are building, 'boguscols' keeps track of the number |
| 5531 | * of bad columns we have advanced. |
| 5532 | */ |
| 5533 | if (n_extra > 0) |
| 5534 | { |
| 5535 | vcol += n_extra; |
| 5536 | # ifdef FEAT_RIGHTLEFT |
| 5537 | if (wp->w_p_rl) |
| 5538 | { |
| 5539 | col -= n_extra; |
| 5540 | boguscols -= n_extra; |
| 5541 | } |
| 5542 | else |
| 5543 | # endif |
| 5544 | { |
| 5545 | col += n_extra; |
| 5546 | boguscols += n_extra; |
| 5547 | } |
| 5548 | n_extra = 0; |
| 5549 | n_attr = 0; |
| 5550 | } |
| 5551 | |
| 5552 | |
| 5553 | # ifdef FEAT_MBYTE |
| 5554 | if (has_mbyte && (*mb_char2cells)(mb_c) > 1) |
| 5555 | { |
| 5556 | /* Need to fill two screen columns. */ |
| 5557 | # ifdef FEAT_RIGHTLEFT |
| 5558 | if (wp->w_p_rl) |
| 5559 | { |
| 5560 | --boguscols; |
| 5561 | --col; |
| 5562 | } |
| 5563 | else |
| 5564 | # endif |
| 5565 | { |
| 5566 | ++boguscols; |
| 5567 | ++col; |
| 5568 | } |
| 5569 | } |
| 5570 | # endif |
| 5571 | |
| 5572 | # ifdef FEAT_RIGHTLEFT |
| 5573 | if (wp->w_p_rl) |
| 5574 | { |
| 5575 | --boguscols; |
| 5576 | --col; |
| 5577 | } |
| 5578 | else |
| 5579 | # endif |
| 5580 | { |
| 5581 | ++boguscols; |
| 5582 | ++col; |
| 5583 | } |
| 5584 | } |
| 5585 | else |
| 5586 | { |
| 5587 | if (n_extra > 0) |
| 5588 | { |
| 5589 | vcol += n_extra; |
| 5590 | n_extra = 0; |
| 5591 | n_attr = 0; |
| 5592 | } |
| 5593 | } |
| 5594 | |
| 5595 | } |
| 5596 | #endif /* FEAT_CONCEAL */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5597 | else |
| 5598 | --n_skip; |
| 5599 | |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 5600 | /* Only advance the "vcol" when after the 'number' or 'relativenumber' |
| 5601 | * column. */ |
Bram Moolenaar | 1b636fa | 2009-03-18 15:28:08 +0000 | [diff] [blame] | 5602 | if (draw_state > WL_NR |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5603 | #ifdef FEAT_DIFF |
| 5604 | && filler_todo <= 0 |
| 5605 | #endif |
| 5606 | ) |
| 5607 | ++vcol; |
| 5608 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5609 | #ifdef FEAT_SYN_HL |
| 5610 | if (vcol_save_attr >= 0) |
| 5611 | char_attr = vcol_save_attr; |
| 5612 | #endif |
| 5613 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5614 | /* restore attributes after "predeces" in 'listchars' */ |
| 5615 | if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0) |
| 5616 | char_attr = saved_attr3; |
| 5617 | |
| 5618 | /* restore attributes after last 'listchars' or 'number' char */ |
| 5619 | if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0) |
| 5620 | char_attr = saved_attr2; |
| 5621 | |
| 5622 | /* |
| 5623 | * 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] | 5624 | * 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] | 5625 | */ |
| 5626 | if (( |
| 5627 | #ifdef FEAT_RIGHTLEFT |
| 5628 | wp->w_p_rl ? (col < 0) : |
| 5629 | #endif |
| 5630 | (col >= W_WIDTH(wp))) |
| 5631 | && (*ptr != NUL |
| 5632 | #ifdef FEAT_DIFF |
| 5633 | || filler_todo > 0 |
| 5634 | #endif |
Bram Moolenaar | e9d4b58 | 2011-03-22 13:29:24 +0100 | [diff] [blame] | 5635 | || (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5636 | || (n_extra != 0 && (c_extra != NUL || *p_extra != NUL))) |
| 5637 | ) |
| 5638 | { |
Bram Moolenaar | 860cae1 | 2010-06-05 23:22:07 +0200 | [diff] [blame] | 5639 | #ifdef FEAT_CONCEAL |
| 5640 | SCREEN_LINE(screen_row, W_WINCOL(wp), col - boguscols, |
| 5641 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5642 | boguscols = 0; |
| 5643 | #else |
| 5644 | SCREEN_LINE(screen_row, W_WINCOL(wp), col, |
| 5645 | (int)W_WIDTH(wp), wp->w_p_rl); |
| 5646 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5647 | ++row; |
| 5648 | ++screen_row; |
| 5649 | |
| 5650 | /* When not wrapping and finished diff lines, or when displayed |
| 5651 | * '$' and highlighting until last column, break here. */ |
| 5652 | if ((!wp->w_p_wrap |
| 5653 | #ifdef FEAT_DIFF |
| 5654 | && filler_todo <= 0 |
| 5655 | #endif |
| 5656 | ) || lcs_eol_one == -1) |
| 5657 | break; |
| 5658 | |
| 5659 | /* When the window is too narrow draw all "@" lines. */ |
| 5660 | if (draw_state != WL_LINE |
| 5661 | #ifdef FEAT_DIFF |
| 5662 | && filler_todo <= 0 |
| 5663 | #endif |
| 5664 | ) |
| 5665 | { |
| 5666 | win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5667 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5668 | draw_vsep_win(wp, row); |
| 5669 | #endif |
| 5670 | row = endrow; |
| 5671 | } |
| 5672 | |
| 5673 | /* When line got too long for screen break here. */ |
| 5674 | if (row == endrow) |
| 5675 | { |
| 5676 | ++row; |
| 5677 | break; |
| 5678 | } |
| 5679 | |
| 5680 | if (screen_cur_row == screen_row - 1 |
| 5681 | #ifdef FEAT_DIFF |
| 5682 | && filler_todo <= 0 |
| 5683 | #endif |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 5684 | #ifdef FEAT_WINDOWS |
| 5685 | && W_WIDTH(wp) == Columns |
| 5686 | #endif |
| 5687 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5688 | { |
| 5689 | /* Remember that the line wraps, used for modeless copy. */ |
| 5690 | LineWraps[screen_row - 1] = TRUE; |
| 5691 | |
| 5692 | /* |
| 5693 | * Special trick to make copy/paste of wrapped lines work with |
| 5694 | * xterm/screen: write an extra character beyond the end of |
| 5695 | * the line. This will work with all terminal types |
| 5696 | * (regardless of the xn,am settings). |
| 5697 | * Only do this on a fast tty. |
| 5698 | * Only do this if the cursor is on the current line |
| 5699 | * (something has been written in it). |
| 5700 | * Don't do this for the GUI. |
| 5701 | * Don't do this for double-width characters. |
| 5702 | * Don't do this for a window not at the right screen border. |
| 5703 | */ |
| 5704 | if (p_tf |
| 5705 | #ifdef FEAT_GUI |
| 5706 | && !gui.in_use |
| 5707 | #endif |
| 5708 | #ifdef FEAT_MBYTE |
| 5709 | && !(has_mbyte |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5710 | && ((*mb_off2cells)(LineOffset[screen_row], |
| 5711 | LineOffset[screen_row] + screen_Columns) |
| 5712 | == 2 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5713 | || (*mb_off2cells)(LineOffset[screen_row - 1] |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5714 | + (int)Columns - 2, |
| 5715 | LineOffset[screen_row] + screen_Columns) |
| 5716 | == 2)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5717 | #endif |
| 5718 | ) |
| 5719 | { |
| 5720 | /* First make sure we are at the end of the screen line, |
| 5721 | * then output the same character again to let the |
| 5722 | * terminal know about the wrap. If the terminal doesn't |
| 5723 | * auto-wrap, we overwrite the character. */ |
| 5724 | if (screen_cur_col != W_WIDTH(wp)) |
| 5725 | screen_char(LineOffset[screen_row - 1] |
| 5726 | + (unsigned)Columns - 1, |
| 5727 | screen_row - 1, (int)(Columns - 1)); |
| 5728 | |
| 5729 | #ifdef FEAT_MBYTE |
| 5730 | /* When there is a multi-byte character, just output a |
| 5731 | * space to keep it simple. */ |
Bram Moolenaar | 2ce06f6 | 2005-01-31 19:19:04 +0000 | [diff] [blame] | 5732 | if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[ |
| 5733 | screen_row - 1] + (Columns - 1)]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5734 | out_char(' '); |
| 5735 | else |
| 5736 | #endif |
| 5737 | out_char(ScreenLines[LineOffset[screen_row - 1] |
| 5738 | + (Columns - 1)]); |
| 5739 | /* force a redraw of the first char on the next line */ |
| 5740 | ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1; |
| 5741 | screen_start(); /* don't know where cursor is now */ |
| 5742 | } |
| 5743 | } |
| 5744 | |
| 5745 | col = 0; |
| 5746 | off = (unsigned)(current_ScreenLine - ScreenLines); |
| 5747 | #ifdef FEAT_RIGHTLEFT |
| 5748 | if (wp->w_p_rl) |
| 5749 | { |
| 5750 | col = W_WIDTH(wp) - 1; /* col is not used if breaking! */ |
| 5751 | off += col; |
| 5752 | } |
| 5753 | #endif |
| 5754 | |
| 5755 | /* reset the drawing state for the start of a wrapped line */ |
| 5756 | draw_state = WL_START; |
| 5757 | saved_n_extra = n_extra; |
| 5758 | saved_p_extra = p_extra; |
| 5759 | saved_c_extra = c_extra; |
| 5760 | saved_char_attr = char_attr; |
| 5761 | n_extra = 0; |
| 5762 | lcs_prec_todo = lcs_prec; |
| 5763 | #ifdef FEAT_LINEBREAK |
| 5764 | # ifdef FEAT_DIFF |
| 5765 | if (filler_todo <= 0) |
| 5766 | # endif |
| 5767 | need_showbreak = TRUE; |
| 5768 | #endif |
| 5769 | #ifdef FEAT_DIFF |
| 5770 | --filler_todo; |
| 5771 | /* When the filler lines are actually below the last line of the |
| 5772 | * file, don't draw the line itself, break here. */ |
| 5773 | if (filler_todo == 0 && wp->w_botfill) |
| 5774 | break; |
| 5775 | #endif |
| 5776 | } |
| 5777 | |
| 5778 | } /* for every character in the line */ |
| 5779 | |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5780 | #ifdef FEAT_SPELL |
Bram Moolenaar | 0d9c26d | 2005-07-02 23:19:16 +0000 | [diff] [blame] | 5781 | /* After an empty line check first word for capital. */ |
| 5782 | if (*skipwhite(line) == NUL) |
| 5783 | { |
| 5784 | capcol_lnum = lnum + 1; |
| 5785 | cap_col = 0; |
| 5786 | } |
| 5787 | #endif |
| 5788 | |
Bram Moolenaar | b031c4e | 2017-01-24 20:14:48 +0100 | [diff] [blame] | 5789 | vim_free(p_extra_free); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5790 | return row; |
| 5791 | } |
| 5792 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5793 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 5794 | static int comp_char_differs(int, int); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5795 | |
| 5796 | /* |
| 5797 | * Return if the composing characters at "off_from" and "off_to" differ. |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 5798 | * Only to be used when ScreenLinesUC[off_from] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5799 | */ |
| 5800 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5801 | comp_char_differs(int off_from, int off_to) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 5802 | { |
| 5803 | int i; |
| 5804 | |
| 5805 | for (i = 0; i < Screen_mco; ++i) |
| 5806 | { |
| 5807 | if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to]) |
| 5808 | return TRUE; |
| 5809 | if (ScreenLinesC[i][off_from] == 0) |
| 5810 | break; |
| 5811 | } |
| 5812 | return FALSE; |
| 5813 | } |
| 5814 | #endif |
| 5815 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5816 | /* |
| 5817 | * Check whether the given character needs redrawing: |
| 5818 | * - the (first byte of the) character is different |
| 5819 | * - the attributes are different |
| 5820 | * - the character is multi-byte and the next byte is different |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5821 | * - the character is two cells wide and the second cell differs. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5822 | */ |
| 5823 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5824 | char_needs_redraw(int off_from, int off_to, int cols) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5825 | { |
| 5826 | if (cols > 0 |
| 5827 | && ((ScreenLines[off_from] != ScreenLines[off_to] |
| 5828 | || ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5829 | |
| 5830 | #ifdef FEAT_MBYTE |
| 5831 | || (enc_dbcs != 0 |
| 5832 | && MB_BYTE2LEN(ScreenLines[off_from]) > 1 |
| 5833 | && (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e |
| 5834 | ? ScreenLines2[off_from] != ScreenLines2[off_to] |
| 5835 | : (cols > 1 && ScreenLines[off_from + 1] |
| 5836 | != ScreenLines[off_to + 1]))) |
| 5837 | || (enc_utf8 |
| 5838 | && (ScreenLinesUC[off_from] != ScreenLinesUC[off_to] |
| 5839 | || (ScreenLinesUC[off_from] != 0 |
Bram Moolenaar | 88f3d3a | 2008-06-21 12:14:30 +0000 | [diff] [blame] | 5840 | && comp_char_differs(off_from, off_to)) |
Bram Moolenaar | 451cf63 | 2012-08-23 18:58:14 +0200 | [diff] [blame] | 5841 | || ((*mb_off2cells)(off_from, off_from + cols) > 1 |
| 5842 | && ScreenLines[off_from + 1] |
| 5843 | != ScreenLines[off_to + 1]))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5844 | #endif |
| 5845 | )) |
| 5846 | return TRUE; |
| 5847 | return FALSE; |
| 5848 | } |
| 5849 | |
| 5850 | /* |
| 5851 | * Move one "cooked" screen line to the screen, but only the characters that |
| 5852 | * have actually changed. Handle insert/delete character. |
| 5853 | * "coloff" gives the first column on the screen for this line. |
| 5854 | * "endcol" gives the columns where valid characters are. |
| 5855 | * "clear_width" is the width of the window. It's > 0 if the rest of the line |
| 5856 | * needs to be cleared, negative otherwise. |
| 5857 | * "rlflag" is TRUE in a rightleft window: |
| 5858 | * When TRUE and "clear_width" > 0, clear columns 0 to "endcol" |
| 5859 | * When FALSE and "clear_width" > 0, clear columns "endcol" to "clear_width" |
| 5860 | */ |
| 5861 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5862 | screen_line( |
| 5863 | int row, |
| 5864 | int coloff, |
| 5865 | int endcol, |
| 5866 | int clear_width |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5867 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5868 | , int rlflag |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5869 | #endif |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 5870 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5871 | { |
| 5872 | unsigned off_from; |
| 5873 | unsigned off_to; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5874 | #ifdef FEAT_MBYTE |
| 5875 | unsigned max_off_from; |
| 5876 | unsigned max_off_to; |
| 5877 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5878 | int col = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 5879 | #if defined(FEAT_GUI) || defined(UNIX) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5880 | int hl; |
| 5881 | #endif |
| 5882 | int force = FALSE; /* force update rest of the line */ |
| 5883 | int redraw_this /* bool: does character need redraw? */ |
| 5884 | #ifdef FEAT_GUI |
| 5885 | = TRUE /* For GUI when while-loop empty */ |
| 5886 | #endif |
| 5887 | ; |
| 5888 | int redraw_next; /* redraw_this for next character */ |
| 5889 | #ifdef FEAT_MBYTE |
| 5890 | int clear_next = FALSE; |
| 5891 | int char_cells; /* 1: normal char */ |
| 5892 | /* 2: occupies two display cells */ |
| 5893 | # define CHAR_CELLS char_cells |
| 5894 | #else |
| 5895 | # define CHAR_CELLS 1 |
| 5896 | #endif |
| 5897 | |
Bram Moolenaar | 5ad15df | 2012-03-16 19:07:58 +0100 | [diff] [blame] | 5898 | /* Check for illegal row and col, just in case. */ |
| 5899 | if (row >= Rows) |
| 5900 | row = Rows - 1; |
| 5901 | if (endcol > Columns) |
| 5902 | endcol = Columns; |
| 5903 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5904 | # ifdef FEAT_CLIPBOARD |
| 5905 | clip_may_clear_selection(row, row); |
| 5906 | # endif |
| 5907 | |
| 5908 | off_from = (unsigned)(current_ScreenLine - ScreenLines); |
| 5909 | off_to = LineOffset[row] + coloff; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5910 | #ifdef FEAT_MBYTE |
| 5911 | max_off_from = off_from + screen_Columns; |
| 5912 | max_off_to = LineOffset[row] + screen_Columns; |
| 5913 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5914 | |
| 5915 | #ifdef FEAT_RIGHTLEFT |
| 5916 | if (rlflag) |
| 5917 | { |
| 5918 | /* Clear rest first, because it's left of the text. */ |
| 5919 | if (clear_width > 0) |
| 5920 | { |
| 5921 | while (col <= endcol && ScreenLines[off_to] == ' ' |
| 5922 | && ScreenAttrs[off_to] == 0 |
| 5923 | # ifdef FEAT_MBYTE |
| 5924 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 5925 | # endif |
| 5926 | ) |
| 5927 | { |
| 5928 | ++off_to; |
| 5929 | ++col; |
| 5930 | } |
| 5931 | if (col <= endcol) |
| 5932 | screen_fill(row, row + 1, col + coloff, |
| 5933 | endcol + coloff + 1, ' ', ' ', 0); |
| 5934 | } |
| 5935 | col = endcol + 1; |
| 5936 | off_to = LineOffset[row] + col + coloff; |
| 5937 | off_from += col; |
| 5938 | endcol = (clear_width > 0 ? clear_width : -clear_width); |
| 5939 | } |
| 5940 | #endif /* FEAT_RIGHTLEFT */ |
| 5941 | |
| 5942 | redraw_next = char_needs_redraw(off_from, off_to, endcol - col); |
| 5943 | |
| 5944 | while (col < endcol) |
| 5945 | { |
| 5946 | #ifdef FEAT_MBYTE |
| 5947 | if (has_mbyte && (col + 1 < endcol)) |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 5948 | char_cells = (*mb_off2cells)(off_from, max_off_from); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5949 | else |
| 5950 | char_cells = 1; |
| 5951 | #endif |
| 5952 | |
| 5953 | redraw_this = redraw_next; |
| 5954 | redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS, |
| 5955 | off_to + CHAR_CELLS, endcol - col - CHAR_CELLS); |
| 5956 | |
| 5957 | #ifdef FEAT_GUI |
| 5958 | /* If the next character was bold, then redraw the current character to |
| 5959 | * remove any pixels that might have spilt over into us. This only |
| 5960 | * happens in the GUI. |
| 5961 | */ |
| 5962 | if (redraw_next && gui.in_use) |
| 5963 | { |
| 5964 | hl = ScreenAttrs[off_to + CHAR_CELLS]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 5965 | if (hl > HL_ALL) |
| 5966 | hl = syn_attr2attr(hl); |
| 5967 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5968 | redraw_this = TRUE; |
| 5969 | } |
| 5970 | #endif |
| 5971 | |
| 5972 | if (redraw_this) |
| 5973 | { |
| 5974 | /* |
| 5975 | * Special handling when 'xs' termcap flag set (hpterm): |
| 5976 | * Attributes for characters are stored at the position where the |
| 5977 | * cursor is when writing the highlighting code. The |
| 5978 | * start-highlighting code must be written with the cursor on the |
| 5979 | * first highlighted character. The stop-highlighting code must |
| 5980 | * be written with the cursor just after the last highlighted |
| 5981 | * character. |
| 5982 | * Overwriting a character doesn't remove it's highlighting. Need |
| 5983 | * to clear the rest of the line, and force redrawing it |
| 5984 | * completely. |
| 5985 | */ |
| 5986 | if ( p_wiv |
| 5987 | && !force |
| 5988 | #ifdef FEAT_GUI |
| 5989 | && !gui.in_use |
| 5990 | #endif |
| 5991 | && ScreenAttrs[off_to] != 0 |
| 5992 | && ScreenAttrs[off_from] != ScreenAttrs[off_to]) |
| 5993 | { |
| 5994 | /* |
| 5995 | * Need to remove highlighting attributes here. |
| 5996 | */ |
| 5997 | windgoto(row, col + coloff); |
| 5998 | out_str(T_CE); /* clear rest of this screen line */ |
| 5999 | screen_start(); /* don't know where cursor is now */ |
| 6000 | force = TRUE; /* force redraw of rest of the line */ |
| 6001 | redraw_next = TRUE; /* or else next char would miss out */ |
| 6002 | |
| 6003 | /* |
| 6004 | * If the previous character was highlighted, need to stop |
| 6005 | * highlighting at this character. |
| 6006 | */ |
| 6007 | if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0) |
| 6008 | { |
| 6009 | screen_attr = ScreenAttrs[off_to - 1]; |
| 6010 | term_windgoto(row, col + coloff); |
| 6011 | screen_stop_highlight(); |
| 6012 | } |
| 6013 | else |
| 6014 | screen_attr = 0; /* highlighting has stopped */ |
| 6015 | } |
| 6016 | #ifdef FEAT_MBYTE |
| 6017 | if (enc_dbcs != 0) |
| 6018 | { |
| 6019 | /* Check if overwriting a double-byte with a single-byte or |
| 6020 | * the other way around requires another character to be |
| 6021 | * redrawn. For UTF-8 this isn't needed, because comparing |
| 6022 | * ScreenLinesUC[] is sufficient. */ |
| 6023 | if (char_cells == 1 |
| 6024 | && col + 1 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6025 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6026 | { |
| 6027 | /* Writing a single-cell character over a double-cell |
| 6028 | * character: need to redraw the next cell. */ |
| 6029 | ScreenLines[off_to + 1] = 0; |
| 6030 | redraw_next = TRUE; |
| 6031 | } |
| 6032 | else if (char_cells == 2 |
| 6033 | && col + 2 < endcol |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6034 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6035 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6036 | { |
| 6037 | /* Writing the second half of a double-cell character over |
| 6038 | * a double-cell character: need to redraw the second |
| 6039 | * cell. */ |
| 6040 | ScreenLines[off_to + 2] = 0; |
| 6041 | redraw_next = TRUE; |
| 6042 | } |
| 6043 | |
| 6044 | if (enc_dbcs == DBCS_JPNU) |
| 6045 | ScreenLines2[off_to] = ScreenLines2[off_from]; |
| 6046 | } |
| 6047 | /* When writing a single-width character over a double-width |
| 6048 | * character and at the end of the redrawn text, need to clear out |
| 6049 | * the right halve of the old character. |
| 6050 | * Also required when writing the right halve of a double-width |
| 6051 | * char over the left halve of an existing one. */ |
| 6052 | if (has_mbyte && col + char_cells == endcol |
| 6053 | && ((char_cells == 1 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6054 | && (*mb_off2cells)(off_to, max_off_to) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6055 | || (char_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6056 | && (*mb_off2cells)(off_to, max_off_to) == 1 |
| 6057 | && (*mb_off2cells)(off_to + 1, max_off_to) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6058 | clear_next = TRUE; |
| 6059 | #endif |
| 6060 | |
| 6061 | ScreenLines[off_to] = ScreenLines[off_from]; |
| 6062 | #ifdef FEAT_MBYTE |
| 6063 | if (enc_utf8) |
| 6064 | { |
| 6065 | ScreenLinesUC[off_to] = ScreenLinesUC[off_from]; |
| 6066 | if (ScreenLinesUC[off_from] != 0) |
| 6067 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6068 | int i; |
| 6069 | |
| 6070 | for (i = 0; i < Screen_mco; ++i) |
| 6071 | ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6072 | } |
| 6073 | } |
| 6074 | if (char_cells == 2) |
| 6075 | ScreenLines[off_to + 1] = ScreenLines[off_from + 1]; |
| 6076 | #endif |
| 6077 | |
| 6078 | #if defined(FEAT_GUI) || defined(UNIX) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 6079 | /* The bold trick makes a single column of pixels appear in the |
| 6080 | * next character. When a bold character is removed, the next |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6081 | * character should be redrawn too. This happens for our own GUI |
| 6082 | * and for some xterms. */ |
| 6083 | if ( |
| 6084 | # ifdef FEAT_GUI |
| 6085 | gui.in_use |
| 6086 | # endif |
| 6087 | # if defined(FEAT_GUI) && defined(UNIX) |
| 6088 | || |
| 6089 | # endif |
| 6090 | # ifdef UNIX |
| 6091 | term_is_xterm |
| 6092 | # endif |
| 6093 | ) |
| 6094 | { |
| 6095 | hl = ScreenAttrs[off_to]; |
Bram Moolenaar | 600dddc | 2006-03-12 22:05:10 +0000 | [diff] [blame] | 6096 | if (hl > HL_ALL) |
| 6097 | hl = syn_attr2attr(hl); |
| 6098 | if (hl & HL_BOLD) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6099 | redraw_next = TRUE; |
| 6100 | } |
| 6101 | #endif |
| 6102 | ScreenAttrs[off_to] = ScreenAttrs[off_from]; |
| 6103 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6104 | /* For simplicity set the attributes of second half of a |
| 6105 | * double-wide character equal to the first half. */ |
| 6106 | if (char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6107 | ScreenAttrs[off_to + 1] = ScreenAttrs[off_from]; |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 6108 | |
| 6109 | if (enc_dbcs != 0 && char_cells == 2) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6110 | screen_char_2(off_to, row, col + coloff); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6111 | else |
| 6112 | #endif |
| 6113 | screen_char(off_to, row, col + coloff); |
| 6114 | } |
| 6115 | else if ( p_wiv |
| 6116 | #ifdef FEAT_GUI |
| 6117 | && !gui.in_use |
| 6118 | #endif |
| 6119 | && col + coloff > 0) |
| 6120 | { |
| 6121 | if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1]) |
| 6122 | { |
| 6123 | /* |
| 6124 | * Don't output stop-highlight when moving the cursor, it will |
| 6125 | * stop the highlighting when it should continue. |
| 6126 | */ |
| 6127 | screen_attr = 0; |
| 6128 | } |
| 6129 | else if (screen_attr != 0) |
| 6130 | screen_stop_highlight(); |
| 6131 | } |
| 6132 | |
| 6133 | off_to += CHAR_CELLS; |
| 6134 | off_from += CHAR_CELLS; |
| 6135 | col += CHAR_CELLS; |
| 6136 | } |
| 6137 | |
| 6138 | #ifdef FEAT_MBYTE |
| 6139 | if (clear_next) |
| 6140 | { |
| 6141 | /* Clear the second half of a double-wide character of which the left |
| 6142 | * half was overwritten with a single-wide character. */ |
| 6143 | ScreenLines[off_to] = ' '; |
| 6144 | if (enc_utf8) |
| 6145 | ScreenLinesUC[off_to] = 0; |
| 6146 | screen_char(off_to, row, col + coloff); |
| 6147 | } |
| 6148 | #endif |
| 6149 | |
| 6150 | if (clear_width > 0 |
| 6151 | #ifdef FEAT_RIGHTLEFT |
| 6152 | && !rlflag |
| 6153 | #endif |
| 6154 | ) |
| 6155 | { |
| 6156 | #ifdef FEAT_GUI |
| 6157 | int startCol = col; |
| 6158 | #endif |
| 6159 | |
| 6160 | /* blank out the rest of the line */ |
| 6161 | while (col < clear_width && ScreenLines[off_to] == ' ' |
| 6162 | && ScreenAttrs[off_to] == 0 |
| 6163 | #ifdef FEAT_MBYTE |
| 6164 | && (!enc_utf8 || ScreenLinesUC[off_to] == 0) |
| 6165 | #endif |
| 6166 | ) |
| 6167 | { |
| 6168 | ++off_to; |
| 6169 | ++col; |
| 6170 | } |
| 6171 | if (col < clear_width) |
| 6172 | { |
| 6173 | #ifdef FEAT_GUI |
| 6174 | /* |
| 6175 | * In the GUI, clearing the rest of the line may leave pixels |
| 6176 | * behind if the first character cleared was bold. Some bold |
| 6177 | * fonts spill over the left. In this case we redraw the previous |
| 6178 | * character too. If we didn't skip any blanks above, then we |
| 6179 | * only redraw if the character wasn't already redrawn anyway. |
| 6180 | */ |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6181 | if (gui.in_use && (col > startCol || !redraw_this)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6182 | { |
| 6183 | hl = ScreenAttrs[off_to]; |
| 6184 | if (hl > HL_ALL || (hl & HL_BOLD)) |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6185 | { |
| 6186 | int prev_cells = 1; |
| 6187 | # ifdef FEAT_MBYTE |
| 6188 | if (enc_utf8) |
| 6189 | /* for utf-8, ScreenLines[char_offset + 1] == 0 means |
| 6190 | * that its width is 2. */ |
| 6191 | prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1; |
| 6192 | else if (enc_dbcs != 0) |
| 6193 | { |
| 6194 | /* find previous character by counting from first |
| 6195 | * column and get its width. */ |
| 6196 | unsigned off = LineOffset[row]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6197 | unsigned max_off = LineOffset[row] + screen_Columns; |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6198 | |
| 6199 | while (off < off_to) |
| 6200 | { |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6201 | prev_cells = (*mb_off2cells)(off, max_off); |
Bram Moolenaar | 9c69732 | 2006-10-09 20:11:17 +0000 | [diff] [blame] | 6202 | off += prev_cells; |
| 6203 | } |
| 6204 | } |
| 6205 | |
| 6206 | if (enc_dbcs != 0 && prev_cells > 1) |
| 6207 | screen_char_2(off_to - prev_cells, row, |
| 6208 | col + coloff - prev_cells); |
| 6209 | else |
| 6210 | # endif |
| 6211 | screen_char(off_to - prev_cells, row, |
| 6212 | col + coloff - prev_cells); |
| 6213 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6214 | } |
| 6215 | #endif |
| 6216 | screen_fill(row, row + 1, col + coloff, clear_width + coloff, |
| 6217 | ' ', ' ', 0); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6218 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6219 | off_to += clear_width - col; |
| 6220 | col = clear_width; |
| 6221 | #endif |
| 6222 | } |
| 6223 | } |
| 6224 | |
| 6225 | if (clear_width > 0) |
| 6226 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6227 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6228 | /* For a window that's left of another, draw the separator char. */ |
| 6229 | if (col + coloff < Columns) |
| 6230 | { |
| 6231 | int c; |
| 6232 | |
| 6233 | c = fillchar_vsep(&hl); |
Bram Moolenaar | c60c4f6 | 2015-01-07 19:04:28 +0100 | [diff] [blame] | 6234 | if (ScreenLines[off_to] != (schar_T)c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6235 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6236 | || (enc_utf8 && (int)ScreenLinesUC[off_to] |
| 6237 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6238 | # endif |
| 6239 | || ScreenAttrs[off_to] != hl) |
| 6240 | { |
| 6241 | ScreenLines[off_to] = c; |
| 6242 | ScreenAttrs[off_to] = hl; |
| 6243 | # ifdef FEAT_MBYTE |
| 6244 | if (enc_utf8) |
| 6245 | { |
| 6246 | if (c >= 0x80) |
| 6247 | { |
| 6248 | ScreenLinesUC[off_to] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6249 | ScreenLinesC[0][off_to] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6250 | } |
| 6251 | else |
| 6252 | ScreenLinesUC[off_to] = 0; |
| 6253 | } |
| 6254 | # endif |
| 6255 | screen_char(off_to, row, col + coloff); |
| 6256 | } |
| 6257 | } |
| 6258 | else |
| 6259 | #endif |
| 6260 | LineWraps[row] = FALSE; |
| 6261 | } |
| 6262 | } |
| 6263 | |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6264 | #if defined(FEAT_RIGHTLEFT) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6265 | /* |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6266 | * Mirror text "str" for right-left displaying. |
| 6267 | * Only works for single-byte characters (e.g., numbers). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6268 | */ |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6269 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6270 | rl_mirror(char_u *str) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6271 | { |
| 6272 | char_u *p1, *p2; |
| 6273 | int t; |
| 6274 | |
| 6275 | for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2) |
| 6276 | { |
| 6277 | t = *p1; |
| 6278 | *p1 = *p2; |
| 6279 | *p2 = t; |
| 6280 | } |
| 6281 | } |
| 6282 | #endif |
| 6283 | |
| 6284 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6285 | /* |
| 6286 | * mark all status lines for redraw; used after first :cd |
| 6287 | */ |
| 6288 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6289 | status_redraw_all(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6290 | { |
| 6291 | win_T *wp; |
| 6292 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6293 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6294 | if (wp->w_status_height) |
| 6295 | { |
| 6296 | wp->w_redr_status = TRUE; |
| 6297 | redraw_later(VALID); |
| 6298 | } |
| 6299 | } |
| 6300 | |
| 6301 | /* |
| 6302 | * mark all status lines of the current buffer for redraw |
| 6303 | */ |
| 6304 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6305 | status_redraw_curbuf(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6306 | { |
| 6307 | win_T *wp; |
| 6308 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6309 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6310 | if (wp->w_status_height != 0 && wp->w_buffer == curbuf) |
| 6311 | { |
| 6312 | wp->w_redr_status = TRUE; |
| 6313 | redraw_later(VALID); |
| 6314 | } |
| 6315 | } |
| 6316 | |
| 6317 | /* |
| 6318 | * Redraw all status lines that need to be redrawn. |
| 6319 | */ |
| 6320 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6321 | redraw_statuslines(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6322 | { |
| 6323 | win_T *wp; |
| 6324 | |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 6325 | FOR_ALL_WINDOWS(wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6326 | if (wp->w_redr_status) |
| 6327 | win_redr_status(wp); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 6328 | if (redraw_tabline) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6329 | draw_tabline(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6330 | } |
| 6331 | #endif |
| 6332 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6333 | #if (defined(FEAT_WILDMENU) && defined(FEAT_WINDOWS)) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6334 | /* |
| 6335 | * Redraw all status lines at the bottom of frame "frp". |
| 6336 | */ |
| 6337 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6338 | win_redraw_last_status(frame_T *frp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6339 | { |
| 6340 | if (frp->fr_layout == FR_LEAF) |
| 6341 | frp->fr_win->w_redr_status = TRUE; |
| 6342 | else if (frp->fr_layout == FR_ROW) |
| 6343 | { |
| 6344 | for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next) |
| 6345 | win_redraw_last_status(frp); |
| 6346 | } |
| 6347 | else /* frp->fr_layout == FR_COL */ |
| 6348 | { |
| 6349 | frp = frp->fr_child; |
| 6350 | while (frp->fr_next != NULL) |
| 6351 | frp = frp->fr_next; |
| 6352 | win_redraw_last_status(frp); |
| 6353 | } |
| 6354 | } |
| 6355 | #endif |
| 6356 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6357 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6358 | /* |
| 6359 | * Draw the verticap separator right of window "wp" starting with line "row". |
| 6360 | */ |
| 6361 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6362 | draw_vsep_win(win_T *wp, int row) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6363 | { |
| 6364 | int hl; |
| 6365 | int c; |
| 6366 | |
| 6367 | if (wp->w_vsep_width) |
| 6368 | { |
| 6369 | /* draw the vertical separator right of this window */ |
| 6370 | c = fillchar_vsep(&hl); |
| 6371 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 6372 | W_ENDCOL(wp), W_ENDCOL(wp) + 1, |
| 6373 | c, ' ', hl); |
| 6374 | } |
| 6375 | } |
| 6376 | #endif |
| 6377 | |
| 6378 | #ifdef FEAT_WILDMENU |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 6379 | static int status_match_len(expand_T *xp, char_u *s); |
| 6380 | static int skip_status_match_char(expand_T *xp, char_u *s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6381 | |
| 6382 | /* |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6383 | * 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] | 6384 | */ |
| 6385 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6386 | status_match_len(expand_T *xp, char_u *s) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6387 | { |
| 6388 | int len = 0; |
| 6389 | |
| 6390 | #ifdef FEAT_MENU |
| 6391 | int emenu = (xp->xp_context == EXPAND_MENUS |
| 6392 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6393 | |
| 6394 | /* Check for menu separators - replace with '|'. */ |
| 6395 | if (emenu && menu_is_separator(s)) |
| 6396 | return 1; |
| 6397 | #endif |
| 6398 | |
| 6399 | while (*s != NUL) |
| 6400 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6401 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 8169525 | 2004-12-29 20:58:21 +0000 | [diff] [blame] | 6402 | len += ptr2cells(s); |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6403 | mb_ptr_adv(s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6404 | } |
| 6405 | |
| 6406 | return len; |
| 6407 | } |
| 6408 | |
| 6409 | /* |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6410 | * 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] | 6411 | * These are backslashes used for escaping. Do show backslashes in help tags. |
| 6412 | */ |
| 6413 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6414 | skip_status_match_char(expand_T *xp, char_u *s) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6415 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6416 | if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP) |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6417 | #ifdef FEAT_MENU |
| 6418 | || ((xp->xp_context == EXPAND_MENUS |
| 6419 | || xp->xp_context == EXPAND_MENUNAMES) |
| 6420 | && (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL))) |
| 6421 | #endif |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6422 | ) |
| 6423 | { |
| 6424 | #ifndef BACKSLASH_IN_FILENAME |
| 6425 | if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!') |
| 6426 | return 2; |
| 6427 | #endif |
| 6428 | return 1; |
| 6429 | } |
| 6430 | return 0; |
Bram Moolenaar | 35c54e5 | 2005-05-20 21:25:31 +0000 | [diff] [blame] | 6431 | } |
| 6432 | |
| 6433 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6434 | * Show wildchar matches in the status line. |
| 6435 | * Show at least the "match" item. |
| 6436 | * We start at item 'first_match' in the list and show all matches that fit. |
| 6437 | * |
| 6438 | * If inversion is possible we use it. Else '=' characters are used. |
| 6439 | */ |
| 6440 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6441 | win_redr_status_matches( |
| 6442 | expand_T *xp, |
| 6443 | int num_matches, |
| 6444 | char_u **matches, /* list of matches */ |
| 6445 | int match, |
| 6446 | int showtail) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6447 | { |
| 6448 | #define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m]) |
| 6449 | int row; |
| 6450 | char_u *buf; |
| 6451 | int len; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 6452 | int clen; /* length in screen cells */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6453 | int fillchar; |
| 6454 | int attr; |
| 6455 | int i; |
| 6456 | int highlight = TRUE; |
| 6457 | char_u *selstart = NULL; |
| 6458 | int selstart_col = 0; |
| 6459 | char_u *selend = NULL; |
| 6460 | static int first_match = 0; |
| 6461 | int add_left = FALSE; |
| 6462 | char_u *s; |
| 6463 | #ifdef FEAT_MENU |
| 6464 | int emenu; |
| 6465 | #endif |
| 6466 | #if defined(FEAT_MBYTE) || defined(FEAT_MENU) |
| 6467 | int l; |
| 6468 | #endif |
| 6469 | |
| 6470 | if (matches == NULL) /* interrupted completion? */ |
| 6471 | return; |
| 6472 | |
Bram Moolenaar | 1cd871b | 2004-12-19 22:46:22 +0000 | [diff] [blame] | 6473 | #ifdef FEAT_MBYTE |
| 6474 | if (has_mbyte) |
| 6475 | buf = alloc((unsigned)Columns * MB_MAXBYTES + 1); |
| 6476 | else |
| 6477 | #endif |
| 6478 | buf = alloc((unsigned)Columns + 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6479 | if (buf == NULL) |
| 6480 | return; |
| 6481 | |
| 6482 | if (match == -1) /* don't show match but original text */ |
| 6483 | { |
| 6484 | match = 0; |
| 6485 | highlight = FALSE; |
| 6486 | } |
| 6487 | /* count 1 for the ending ">" */ |
| 6488 | clen = status_match_len(xp, L_MATCH(match)) + 3; |
| 6489 | if (match == 0) |
| 6490 | first_match = 0; |
| 6491 | else if (match < first_match) |
| 6492 | { |
| 6493 | /* jumping left, as far as we can go */ |
| 6494 | first_match = match; |
| 6495 | add_left = TRUE; |
| 6496 | } |
| 6497 | else |
| 6498 | { |
| 6499 | /* check if match fits on the screen */ |
| 6500 | for (i = first_match; i < match; ++i) |
| 6501 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6502 | if (first_match > 0) |
| 6503 | clen += 2; |
| 6504 | /* jumping right, put match at the left */ |
| 6505 | if ((long)clen > Columns) |
| 6506 | { |
| 6507 | first_match = match; |
| 6508 | /* if showing the last match, we can add some on the left */ |
| 6509 | clen = 2; |
| 6510 | for (i = match; i < num_matches; ++i) |
| 6511 | { |
| 6512 | clen += status_match_len(xp, L_MATCH(i)) + 2; |
| 6513 | if ((long)clen >= Columns) |
| 6514 | break; |
| 6515 | } |
| 6516 | if (i == num_matches) |
| 6517 | add_left = TRUE; |
| 6518 | } |
| 6519 | } |
| 6520 | if (add_left) |
| 6521 | while (first_match > 0) |
| 6522 | { |
| 6523 | clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2; |
| 6524 | if ((long)clen >= Columns) |
| 6525 | break; |
| 6526 | --first_match; |
| 6527 | } |
| 6528 | |
| 6529 | fillchar = fillchar_status(&attr, TRUE); |
| 6530 | |
| 6531 | if (first_match == 0) |
| 6532 | { |
| 6533 | *buf = NUL; |
| 6534 | len = 0; |
| 6535 | } |
| 6536 | else |
| 6537 | { |
| 6538 | STRCPY(buf, "< "); |
| 6539 | len = 2; |
| 6540 | } |
| 6541 | clen = len; |
| 6542 | |
| 6543 | i = first_match; |
| 6544 | while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns) |
| 6545 | { |
| 6546 | if (i == match) |
| 6547 | { |
| 6548 | selstart = buf + len; |
| 6549 | selstart_col = clen; |
| 6550 | } |
| 6551 | |
| 6552 | s = L_MATCH(i); |
| 6553 | /* Check for menu separators - replace with '|' */ |
| 6554 | #ifdef FEAT_MENU |
| 6555 | emenu = (xp->xp_context == EXPAND_MENUS |
| 6556 | || xp->xp_context == EXPAND_MENUNAMES); |
| 6557 | if (emenu && menu_is_separator(s)) |
| 6558 | { |
| 6559 | STRCPY(buf + len, transchar('|')); |
| 6560 | l = (int)STRLEN(buf + len); |
| 6561 | len += l; |
| 6562 | clen += l; |
| 6563 | } |
| 6564 | else |
| 6565 | #endif |
| 6566 | for ( ; *s != NUL; ++s) |
| 6567 | { |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 6568 | s += skip_status_match_char(xp, s); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6569 | clen += ptr2cells(s); |
| 6570 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6571 | if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6572 | { |
| 6573 | STRNCPY(buf + len, s, l); |
| 6574 | s += l - 1; |
| 6575 | len += l; |
| 6576 | } |
| 6577 | else |
| 6578 | #endif |
| 6579 | { |
| 6580 | STRCPY(buf + len, transchar_byte(*s)); |
| 6581 | len += (int)STRLEN(buf + len); |
| 6582 | } |
| 6583 | } |
| 6584 | if (i == match) |
| 6585 | selend = buf + len; |
| 6586 | |
| 6587 | *(buf + len++) = ' '; |
| 6588 | *(buf + len++) = ' '; |
| 6589 | clen += 2; |
| 6590 | if (++i == num_matches) |
| 6591 | break; |
| 6592 | } |
| 6593 | |
| 6594 | if (i != num_matches) |
| 6595 | { |
| 6596 | *(buf + len++) = '>'; |
| 6597 | ++clen; |
| 6598 | } |
| 6599 | |
| 6600 | buf[len] = NUL; |
| 6601 | |
| 6602 | row = cmdline_row - 1; |
| 6603 | if (row >= 0) |
| 6604 | { |
| 6605 | if (wild_menu_showing == 0) |
| 6606 | { |
| 6607 | if (msg_scrolled > 0) |
| 6608 | { |
| 6609 | /* Put the wildmenu just above the command line. If there is |
| 6610 | * no room, scroll the screen one line up. */ |
| 6611 | if (cmdline_row == Rows - 1) |
| 6612 | { |
| 6613 | screen_del_lines(0, 0, 1, (int)Rows, TRUE, NULL); |
| 6614 | ++msg_scrolled; |
| 6615 | } |
| 6616 | else |
| 6617 | { |
| 6618 | ++cmdline_row; |
| 6619 | ++row; |
| 6620 | } |
| 6621 | wild_menu_showing = WM_SCROLLED; |
| 6622 | } |
| 6623 | else |
| 6624 | { |
| 6625 | /* Create status line if needed by setting 'laststatus' to 2. |
| 6626 | * Set 'winminheight' to zero to avoid that the window is |
| 6627 | * resized. */ |
| 6628 | if (lastwin->w_status_height == 0) |
| 6629 | { |
| 6630 | save_p_ls = p_ls; |
| 6631 | save_p_wmh = p_wmh; |
| 6632 | p_ls = 2; |
| 6633 | p_wmh = 0; |
| 6634 | last_status(FALSE); |
| 6635 | } |
| 6636 | wild_menu_showing = WM_SHOWN; |
| 6637 | } |
| 6638 | } |
| 6639 | |
| 6640 | screen_puts(buf, row, 0, attr); |
| 6641 | if (selstart != NULL && highlight) |
| 6642 | { |
| 6643 | *selend = NUL; |
| 6644 | screen_puts(selstart, row, selstart_col, hl_attr(HLF_WM)); |
| 6645 | } |
| 6646 | |
| 6647 | screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr); |
| 6648 | } |
| 6649 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6650 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6651 | win_redraw_last_status(topframe); |
| 6652 | #else |
| 6653 | lastwin->w_redr_status = TRUE; |
| 6654 | #endif |
| 6655 | vim_free(buf); |
| 6656 | } |
| 6657 | #endif |
| 6658 | |
| 6659 | #if defined(FEAT_WINDOWS) || defined(PROTO) |
| 6660 | /* |
| 6661 | * Redraw the status line of window wp. |
| 6662 | * |
| 6663 | * If inversion is possible we use it. Else '=' characters are used. |
| 6664 | */ |
| 6665 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6666 | win_redr_status(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6667 | { |
| 6668 | int row; |
| 6669 | char_u *p; |
| 6670 | int len; |
| 6671 | int fillchar; |
| 6672 | int attr; |
| 6673 | int this_ru_col; |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6674 | static int busy = FALSE; |
| 6675 | |
| 6676 | /* It's possible to get here recursively when 'statusline' (indirectly) |
| 6677 | * invokes ":redrawstatus". Simply ignore the call then. */ |
| 6678 | if (busy) |
| 6679 | return; |
| 6680 | busy = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6681 | |
| 6682 | wp->w_redr_status = FALSE; |
| 6683 | if (wp->w_status_height == 0) |
| 6684 | { |
| 6685 | /* no status line, can only be last window */ |
| 6686 | redraw_cmdline = TRUE; |
| 6687 | } |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 6688 | else if (!redrawing() |
| 6689 | #ifdef FEAT_INS_EXPAND |
| 6690 | /* don't update status line when popup menu is visible and may be |
| 6691 | * drawn over it */ |
| 6692 | || pum_visible() |
| 6693 | #endif |
| 6694 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6695 | { |
| 6696 | /* Don't redraw right now, do it later. */ |
| 6697 | wp->w_redr_status = TRUE; |
| 6698 | } |
| 6699 | #ifdef FEAT_STL_OPT |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 6700 | else if (*p_stl != NUL || *wp->w_p_stl != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6701 | { |
| 6702 | /* redraw custom status line */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6703 | redraw_custom_statusline(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6704 | } |
| 6705 | #endif |
| 6706 | else |
| 6707 | { |
| 6708 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6709 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 6710 | get_trans_bufname(wp->w_buffer); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6711 | p = NameBuff; |
| 6712 | len = (int)STRLEN(p); |
| 6713 | |
| 6714 | if (wp->w_buffer->b_help |
| 6715 | #ifdef FEAT_QUICKFIX |
| 6716 | || wp->w_p_pvw |
| 6717 | #endif |
| 6718 | || bufIsChanged(wp->w_buffer) |
| 6719 | || wp->w_buffer->b_p_ro) |
| 6720 | *(p + len++) = ' '; |
| 6721 | if (wp->w_buffer->b_help) |
| 6722 | { |
Bram Moolenaar | 899dddf | 2006-03-26 21:06:50 +0000 | [diff] [blame] | 6723 | STRCPY(p + len, _("[Help]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6724 | len += (int)STRLEN(p + len); |
| 6725 | } |
| 6726 | #ifdef FEAT_QUICKFIX |
| 6727 | if (wp->w_p_pvw) |
| 6728 | { |
| 6729 | STRCPY(p + len, _("[Preview]")); |
| 6730 | len += (int)STRLEN(p + len); |
| 6731 | } |
| 6732 | #endif |
| 6733 | if (bufIsChanged(wp->w_buffer)) |
| 6734 | { |
| 6735 | STRCPY(p + len, "[+]"); |
| 6736 | len += 3; |
| 6737 | } |
| 6738 | if (wp->w_buffer->b_p_ro) |
| 6739 | { |
Bram Moolenaar | 2358403 | 2013-06-07 20:17:11 +0200 | [diff] [blame] | 6740 | STRCPY(p + len, _("[RO]")); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6741 | len += 4; |
| 6742 | } |
| 6743 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6744 | this_ru_col = ru_col - (Columns - W_WIDTH(wp)); |
| 6745 | if (this_ru_col < (W_WIDTH(wp) + 1) / 2) |
| 6746 | this_ru_col = (W_WIDTH(wp) + 1) / 2; |
| 6747 | if (this_ru_col <= 1) |
| 6748 | { |
| 6749 | p = (char_u *)"<"; /* No room for file name! */ |
| 6750 | len = 1; |
| 6751 | } |
| 6752 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6753 | #ifdef FEAT_MBYTE |
| 6754 | if (has_mbyte) |
| 6755 | { |
| 6756 | int clen = 0, i; |
| 6757 | |
| 6758 | /* Count total number of display cells. */ |
Bram Moolenaar | 72597a5 | 2010-07-18 15:31:08 +0200 | [diff] [blame] | 6759 | clen = mb_string2cells(p, -1); |
| 6760 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6761 | /* Find first character that will fit. |
| 6762 | * Going from start to end is much faster for DBCS. */ |
| 6763 | for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 6764 | i += (*mb_ptr2len)(p + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6765 | clen -= (*mb_ptr2cells)(p + i); |
| 6766 | len = clen; |
| 6767 | if (i > 0) |
| 6768 | { |
| 6769 | p = p + i - 1; |
| 6770 | *p = '<'; |
| 6771 | ++len; |
| 6772 | } |
| 6773 | |
| 6774 | } |
| 6775 | else |
| 6776 | #endif |
| 6777 | if (len > this_ru_col - 1) |
| 6778 | { |
| 6779 | p += len - (this_ru_col - 1); |
| 6780 | *p = '<'; |
| 6781 | len = this_ru_col - 1; |
| 6782 | } |
| 6783 | |
| 6784 | row = W_WINROW(wp) + wp->w_height; |
| 6785 | screen_puts(p, row, W_WINCOL(wp), attr); |
| 6786 | screen_fill(row, row + 1, len + W_WINCOL(wp), |
| 6787 | this_ru_col + W_WINCOL(wp), fillchar, fillchar, attr); |
| 6788 | |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6789 | if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6790 | && (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1)) |
| 6791 | screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff) |
| 6792 | - 1 + W_WINCOL(wp)), attr); |
| 6793 | |
| 6794 | #ifdef FEAT_CMDL_INFO |
| 6795 | win_redr_ruler(wp, TRUE); |
| 6796 | #endif |
| 6797 | } |
| 6798 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6799 | /* |
| 6800 | * May need to draw the character below the vertical separator. |
| 6801 | */ |
| 6802 | if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing()) |
| 6803 | { |
| 6804 | if (stl_connected(wp)) |
| 6805 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6806 | else |
| 6807 | fillchar = fillchar_vsep(&attr); |
| 6808 | screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp), |
| 6809 | attr); |
| 6810 | } |
Bram Moolenaar | adb09c2 | 2009-06-16 15:22:12 +0000 | [diff] [blame] | 6811 | busy = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6812 | } |
| 6813 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6814 | #ifdef FEAT_STL_OPT |
| 6815 | /* |
| 6816 | * Redraw the status line according to 'statusline' and take care of any |
| 6817 | * errors encountered. |
| 6818 | */ |
| 6819 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6820 | redraw_custom_statusline(win_T *wp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6821 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6822 | static int entered = FALSE; |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6823 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6824 | |
| 6825 | /* When called recursively return. This can happen when the statusline |
| 6826 | * contains an expression that triggers a redraw. */ |
| 6827 | if (entered) |
| 6828 | return; |
| 6829 | entered = TRUE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6830 | |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6831 | did_emsg = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6832 | win_redr_custom(wp, FALSE); |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6833 | if (did_emsg) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6834 | { |
| 6835 | /* When there is an error disable the statusline, otherwise the |
| 6836 | * display is messed up with errors and a redraw triggers the problem |
| 6837 | * again and again. */ |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6838 | set_string_option_direct((char_u *)"statusline", -1, |
| 6839 | (char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 6840 | ? OPT_LOCAL : OPT_GLOBAL), SID_ERROR); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6841 | } |
Bram Moolenaar | a742e08 | 2016-04-05 21:10:38 +0200 | [diff] [blame] | 6842 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6843 | entered = FALSE; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 6844 | } |
| 6845 | #endif |
| 6846 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6847 | /* |
| 6848 | * Return TRUE if the status line of window "wp" is connected to the status |
| 6849 | * line of the window right of it. If not, then it's a vertical separator. |
| 6850 | * Only call if (wp->w_vsep_width != 0). |
| 6851 | */ |
| 6852 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6853 | stl_connected(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6854 | { |
| 6855 | frame_T *fr; |
| 6856 | |
| 6857 | fr = wp->w_frame; |
| 6858 | while (fr->fr_parent != NULL) |
| 6859 | { |
| 6860 | if (fr->fr_parent->fr_layout == FR_COL) |
| 6861 | { |
| 6862 | if (fr->fr_next != NULL) |
| 6863 | break; |
| 6864 | } |
| 6865 | else |
| 6866 | { |
| 6867 | if (fr->fr_next != NULL) |
| 6868 | return TRUE; |
| 6869 | } |
| 6870 | fr = fr->fr_parent; |
| 6871 | } |
| 6872 | return FALSE; |
| 6873 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6874 | |
| 6875 | #endif /* FEAT_WINDOWS */ |
| 6876 | |
| 6877 | #if defined(FEAT_WINDOWS) || defined(FEAT_STL_OPT) || defined(PROTO) |
| 6878 | /* |
| 6879 | * Get the value to show for the language mappings, active 'keymap'. |
| 6880 | */ |
| 6881 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6882 | get_keymap_str( |
| 6883 | win_T *wp, |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6884 | char_u *fmt, /* format string containing one %s item */ |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6885 | char_u *buf, /* buffer for the result */ |
| 6886 | int len) /* length of buffer */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6887 | { |
| 6888 | char_u *p; |
| 6889 | |
| 6890 | if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP) |
| 6891 | return FALSE; |
| 6892 | |
| 6893 | { |
| 6894 | #ifdef FEAT_EVAL |
| 6895 | buf_T *old_curbuf = curbuf; |
| 6896 | win_T *old_curwin = curwin; |
| 6897 | char_u *s; |
| 6898 | |
| 6899 | curbuf = wp->w_buffer; |
| 6900 | curwin = wp; |
| 6901 | STRCPY(buf, "b:keymap_name"); /* must be writable */ |
| 6902 | ++emsg_skip; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 6903 | s = p = eval_to_string(buf, NULL, FALSE); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6904 | --emsg_skip; |
| 6905 | curbuf = old_curbuf; |
| 6906 | curwin = old_curwin; |
| 6907 | if (p == NULL || *p == NUL) |
| 6908 | #endif |
| 6909 | { |
| 6910 | #ifdef FEAT_KEYMAP |
| 6911 | if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) |
| 6912 | p = wp->w_buffer->b_p_keymap; |
| 6913 | else |
| 6914 | #endif |
| 6915 | p = (char_u *)"lang"; |
| 6916 | } |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 6917 | if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6918 | buf[0] = NUL; |
| 6919 | #ifdef FEAT_EVAL |
| 6920 | vim_free(s); |
| 6921 | #endif |
| 6922 | } |
| 6923 | return buf[0] != NUL; |
| 6924 | } |
| 6925 | #endif |
| 6926 | |
| 6927 | #if defined(FEAT_STL_OPT) || defined(PROTO) |
| 6928 | /* |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6929 | * Redraw the status line or ruler of window "wp". |
| 6930 | * When "wp" is NULL redraw the tab pages line from 'tabline'. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6931 | */ |
| 6932 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 6933 | win_redr_custom( |
| 6934 | win_T *wp, |
| 6935 | int draw_ruler) /* TRUE or FALSE */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6936 | { |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6937 | static int entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6938 | int attr; |
| 6939 | int curattr; |
| 6940 | int row; |
| 6941 | int col = 0; |
| 6942 | int maxwidth; |
| 6943 | int width; |
| 6944 | int n; |
| 6945 | int len; |
| 6946 | int fillchar; |
| 6947 | char_u buf[MAXPATHL]; |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6948 | char_u *stl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6949 | char_u *p; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6950 | struct stl_hlrec hltab[STL_MAX_ITEM]; |
| 6951 | struct stl_hlrec tabtab[STL_MAX_ITEM]; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6952 | int use_sandbox = FALSE; |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 6953 | win_T *ewp; |
| 6954 | int p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6955 | |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 6956 | /* There is a tiny chance that this gets called recursively: When |
| 6957 | * redrawing a status line triggers redrawing the ruler or tabline. |
| 6958 | * Avoid trouble by not allowing recursion. */ |
| 6959 | if (entered) |
| 6960 | return; |
| 6961 | entered = TRUE; |
| 6962 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6963 | /* setup environment for the task at hand */ |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6964 | if (wp == NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6965 | { |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6966 | /* Use 'tabline'. Always at the first line of the screen. */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6967 | stl = p_tal; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6968 | row = 0; |
Bram Moolenaar | 65c923a | 2006-03-03 22:56:30 +0000 | [diff] [blame] | 6969 | fillchar = ' '; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6970 | attr = hl_attr(HLF_TPF); |
| 6971 | maxwidth = Columns; |
| 6972 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 6973 | use_sandbox = was_set_insecurely((char_u *)"tabline", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6974 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 6975 | } |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6976 | else |
| 6977 | { |
| 6978 | row = W_WINROW(wp) + wp->w_height; |
| 6979 | fillchar = fillchar_status(&attr, wp == curwin); |
| 6980 | maxwidth = W_WIDTH(wp); |
| 6981 | |
| 6982 | if (draw_ruler) |
| 6983 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6984 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6985 | /* advance past any leading group spec - implicit in ru_col */ |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6986 | if (*stl == '%') |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6987 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 6988 | if (*++stl == '-') |
| 6989 | stl++; |
| 6990 | if (atoi((char *)stl)) |
| 6991 | while (VIM_ISDIGIT(*stl)) |
| 6992 | stl++; |
| 6993 | if (*stl++ != '(') |
| 6994 | stl = p_ruf; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6995 | } |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 6996 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 6997 | col = ru_col - (Columns - W_WIDTH(wp)); |
| 6998 | if (col < (W_WIDTH(wp) + 1) / 2) |
| 6999 | col = (W_WIDTH(wp) + 1) / 2; |
| 7000 | #else |
| 7001 | col = ru_col; |
| 7002 | if (col > (Columns + 1) / 2) |
| 7003 | col = (Columns + 1) / 2; |
| 7004 | #endif |
| 7005 | maxwidth = W_WIDTH(wp) - col; |
| 7006 | #ifdef FEAT_WINDOWS |
| 7007 | if (!wp->w_status_height) |
| 7008 | #endif |
| 7009 | { |
| 7010 | row = Rows - 1; |
| 7011 | --maxwidth; /* writing in last column may cause scrolling */ |
| 7012 | fillchar = ' '; |
| 7013 | attr = 0; |
| 7014 | } |
| 7015 | |
| 7016 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7017 | use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7018 | # endif |
| 7019 | } |
| 7020 | else |
| 7021 | { |
| 7022 | if (*wp->w_p_stl != NUL) |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7023 | stl = wp->w_p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7024 | else |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7025 | stl = p_stl; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7026 | # ifdef FEAT_EVAL |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7027 | use_sandbox = was_set_insecurely((char_u *)"statusline", |
| 7028 | *wp->w_p_stl == NUL ? 0 : OPT_LOCAL); |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7029 | # endif |
| 7030 | } |
| 7031 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 7032 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 7033 | col += W_WINCOL(wp); |
| 7034 | #endif |
| 7035 | } |
| 7036 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7037 | if (maxwidth <= 0) |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7038 | goto theend; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7039 | |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7040 | /* Temporarily reset 'cursorbind', we don't want a side effect from moving |
| 7041 | * the cursor away and back. */ |
| 7042 | ewp = wp == NULL ? curwin : wp; |
| 7043 | p_crb_save = ewp->w_p_crb; |
| 7044 | ewp->w_p_crb = FALSE; |
| 7045 | |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7046 | /* Make a copy, because the statusline may include a function call that |
| 7047 | * might change the option value and free the memory. */ |
| 7048 | stl = vim_strsave(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7049 | width = build_stl_str_hl(ewp, buf, sizeof(buf), |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7050 | stl, use_sandbox, |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7051 | fillchar, maxwidth, hltab, tabtab); |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 7052 | vim_free(stl); |
Bram Moolenaar | 6145285 | 2011-02-01 18:01:11 +0100 | [diff] [blame] | 7053 | ewp->w_p_crb = p_crb_save; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7054 | |
Bram Moolenaar | 7c5676b | 2010-12-08 19:56:58 +0100 | [diff] [blame] | 7055 | /* Make all characters printable. */ |
| 7056 | p = transstr(buf); |
| 7057 | if (p != NULL) |
| 7058 | { |
| 7059 | vim_strncpy(buf, p, sizeof(buf) - 1); |
| 7060 | vim_free(p); |
| 7061 | } |
| 7062 | |
| 7063 | /* fill up with "fillchar" */ |
| 7064 | len = (int)STRLEN(buf); |
Bram Moolenaar | 2c4278f | 2009-05-17 11:33:22 +0000 | [diff] [blame] | 7065 | while (width < maxwidth && len < (int)sizeof(buf) - 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7066 | { |
| 7067 | #ifdef FEAT_MBYTE |
| 7068 | len += (*mb_char2bytes)(fillchar, buf + len); |
| 7069 | #else |
| 7070 | buf[len++] = fillchar; |
| 7071 | #endif |
| 7072 | ++width; |
| 7073 | } |
| 7074 | buf[len] = NUL; |
| 7075 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7076 | /* |
| 7077 | * Draw each snippet with the specified highlighting. |
| 7078 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7079 | curattr = attr; |
| 7080 | p = buf; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7081 | for (n = 0; hltab[n].start != NULL; n++) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7082 | { |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7083 | len = (int)(hltab[n].start - p); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7084 | screen_puts_len(p, len, row, col, curattr); |
| 7085 | col += vim_strnsize(p, len); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7086 | p = hltab[n].start; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7087 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7088 | if (hltab[n].userhl == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7089 | curattr = attr; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7090 | else if (hltab[n].userhl < 0) |
| 7091 | curattr = syn_id2attr(-hltab[n].userhl); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7092 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 7093 | else if (wp != NULL && wp != curwin && wp->w_status_height != 0) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7094 | curattr = highlight_stlnc[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7095 | #endif |
| 7096 | else |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7097 | curattr = highlight_user[hltab[n].userhl - 1]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7098 | } |
| 7099 | screen_puts(p, row, col, curattr); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7100 | |
| 7101 | if (wp == NULL) |
| 7102 | { |
| 7103 | /* Fill the TabPageIdxs[] array for clicking in the tab pagesline. */ |
| 7104 | col = 0; |
| 7105 | len = 0; |
| 7106 | p = buf; |
| 7107 | fillchar = 0; |
| 7108 | for (n = 0; tabtab[n].start != NULL; n++) |
| 7109 | { |
| 7110 | len += vim_strnsize(p, (int)(tabtab[n].start - p)); |
| 7111 | while (col < len) |
| 7112 | TabPageIdxs[col++] = fillchar; |
| 7113 | p = tabtab[n].start; |
| 7114 | fillchar = tabtab[n].userhl; |
| 7115 | } |
| 7116 | while (col < Columns) |
| 7117 | TabPageIdxs[col++] = fillchar; |
| 7118 | } |
Bram Moolenaar | 1d63341 | 2013-12-11 15:52:01 +0100 | [diff] [blame] | 7119 | |
| 7120 | theend: |
| 7121 | entered = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | #endif /* FEAT_STL_OPT */ |
| 7125 | |
| 7126 | /* |
| 7127 | * Output a single character directly to the screen and update ScreenLines. |
| 7128 | */ |
| 7129 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7130 | screen_putchar(int c, int row, int col, int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7131 | { |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7132 | char_u buf[MB_MAXBYTES + 1]; |
| 7133 | |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7134 | #ifdef FEAT_MBYTE |
| 7135 | if (has_mbyte) |
| 7136 | buf[(*mb_char2bytes)(c, buf)] = NUL; |
| 7137 | else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7138 | #endif |
Bram Moolenaar | 9a920d8 | 2012-06-01 15:21:02 +0200 | [diff] [blame] | 7139 | { |
| 7140 | buf[0] = c; |
| 7141 | buf[1] = NUL; |
| 7142 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7143 | screen_puts(buf, row, col, attr); |
| 7144 | } |
| 7145 | |
| 7146 | /* |
| 7147 | * Get a single character directly from ScreenLines into "bytes[]". |
| 7148 | * Also return its attribute in *attrp; |
| 7149 | */ |
| 7150 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7151 | screen_getbytes(int row, int col, char_u *bytes, int *attrp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7152 | { |
| 7153 | unsigned off; |
| 7154 | |
| 7155 | /* safety check */ |
| 7156 | if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns) |
| 7157 | { |
| 7158 | off = LineOffset[row] + col; |
| 7159 | *attrp = ScreenAttrs[off]; |
| 7160 | bytes[0] = ScreenLines[off]; |
| 7161 | bytes[1] = NUL; |
| 7162 | |
| 7163 | #ifdef FEAT_MBYTE |
| 7164 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 7165 | bytes[utfc_char2bytes(off, bytes)] = NUL; |
| 7166 | else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 7167 | { |
| 7168 | bytes[0] = ScreenLines[off]; |
| 7169 | bytes[1] = ScreenLines2[off]; |
| 7170 | bytes[2] = NUL; |
| 7171 | } |
| 7172 | else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1) |
| 7173 | { |
| 7174 | bytes[1] = ScreenLines[off + 1]; |
| 7175 | bytes[2] = NUL; |
| 7176 | } |
| 7177 | #endif |
| 7178 | } |
| 7179 | } |
| 7180 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7181 | #ifdef FEAT_MBYTE |
Bram Moolenaar | baaa7e9 | 2016-01-29 22:47:03 +0100 | [diff] [blame] | 7182 | static int screen_comp_differs(int, int*); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7183 | |
| 7184 | /* |
| 7185 | * Return TRUE if composing characters for screen posn "off" differs from |
| 7186 | * composing characters in "u8cc". |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7187 | * Only to be used when ScreenLinesUC[off] != 0. |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7188 | */ |
| 7189 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7190 | screen_comp_differs(int off, int *u8cc) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7191 | { |
| 7192 | int i; |
| 7193 | |
| 7194 | for (i = 0; i < Screen_mco; ++i) |
| 7195 | { |
| 7196 | if (ScreenLinesC[i][off] != (u8char_T)u8cc[i]) |
| 7197 | return TRUE; |
| 7198 | if (u8cc[i] == 0) |
| 7199 | break; |
| 7200 | } |
| 7201 | return FALSE; |
| 7202 | } |
| 7203 | #endif |
| 7204 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7205 | /* |
| 7206 | * Put string '*text' on the screen at position 'row' and 'col', with |
| 7207 | * attributes 'attr', and update ScreenLines[] and ScreenAttrs[]. |
| 7208 | * Note: only outputs within one row, message is truncated at screen boundary! |
| 7209 | * Note: if ScreenLines[], row and/or col is invalid, nothing is done. |
| 7210 | */ |
| 7211 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7212 | screen_puts( |
| 7213 | char_u *text, |
| 7214 | int row, |
| 7215 | int col, |
| 7216 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7217 | { |
| 7218 | screen_puts_len(text, -1, row, col, attr); |
| 7219 | } |
| 7220 | |
| 7221 | /* |
| 7222 | * Like screen_puts(), but output "text[len]". When "len" is -1 output up to |
| 7223 | * a NUL. |
| 7224 | */ |
| 7225 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7226 | screen_puts_len( |
| 7227 | char_u *text, |
| 7228 | int textlen, |
| 7229 | int row, |
| 7230 | int col, |
| 7231 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7232 | { |
| 7233 | unsigned off; |
| 7234 | char_u *ptr = text; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7235 | int len = textlen; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7236 | int c; |
| 7237 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7238 | unsigned max_off; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7239 | int mbyte_blen = 1; |
| 7240 | int mbyte_cells = 1; |
| 7241 | int u8c = 0; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7242 | int u8cc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7243 | int clear_next_cell = FALSE; |
| 7244 | # ifdef FEAT_ARABIC |
| 7245 | int prev_c = 0; /* previous Arabic character */ |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7246 | int pc, nc, nc1; |
| 7247 | int pcc[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7248 | # endif |
| 7249 | #endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7250 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7251 | int force_redraw_this; |
| 7252 | int force_redraw_next = FALSE; |
| 7253 | #endif |
| 7254 | int need_redraw; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7255 | |
| 7256 | if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ |
| 7257 | return; |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7258 | off = LineOffset[row] + col; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7259 | |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7260 | #ifdef FEAT_MBYTE |
| 7261 | /* When drawing over the right halve of a double-wide char clear out the |
| 7262 | * left halve. Only needed in a terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 7263 | if (has_mbyte && col > 0 && col < screen_Columns |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7264 | # ifdef FEAT_GUI |
| 7265 | && !gui.in_use |
| 7266 | # endif |
| 7267 | && mb_fix_col(col, row) != col) |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7268 | { |
| 7269 | ScreenLines[off - 1] = ' '; |
| 7270 | ScreenAttrs[off - 1] = 0; |
| 7271 | if (enc_utf8) |
| 7272 | { |
| 7273 | ScreenLinesUC[off - 1] = 0; |
| 7274 | ScreenLinesC[0][off - 1] = 0; |
| 7275 | } |
| 7276 | /* redraw the previous cell, make it empty */ |
| 7277 | screen_char(off - 1, row, col - 1); |
| 7278 | /* force the cell at "col" to be redrawn */ |
| 7279 | force_redraw_next = TRUE; |
| 7280 | } |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 7281 | #endif |
| 7282 | |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7283 | #ifdef FEAT_MBYTE |
| 7284 | max_off = LineOffset[row] + screen_Columns; |
| 7285 | #endif |
Bram Moolenaar | a064ac8 | 2007-08-05 18:10:54 +0000 | [diff] [blame] | 7286 | while (col < screen_Columns |
| 7287 | && (len < 0 || (int)(ptr - text) < len) |
| 7288 | && *ptr != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7289 | { |
| 7290 | c = *ptr; |
| 7291 | #ifdef FEAT_MBYTE |
| 7292 | /* check if this is the first byte of a multibyte */ |
| 7293 | if (has_mbyte) |
| 7294 | { |
| 7295 | if (enc_utf8 && len > 0) |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7296 | mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7297 | else |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 7298 | mbyte_blen = (*mb_ptr2len)(ptr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7299 | if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7300 | mbyte_cells = 1; |
| 7301 | else if (enc_dbcs != 0) |
| 7302 | mbyte_cells = mbyte_blen; |
| 7303 | else /* enc_utf8 */ |
| 7304 | { |
| 7305 | if (len >= 0) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7306 | u8c = utfc_ptr2char_len(ptr, u8cc, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7307 | (int)((text + len) - ptr)); |
| 7308 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7309 | u8c = utfc_ptr2char(ptr, u8cc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7310 | mbyte_cells = utf_char2cells(u8c); |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7311 | # ifdef UNICODE16 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7312 | /* Non-BMP character: display as ? or fullwidth ?. */ |
| 7313 | if (u8c >= 0x10000) |
| 7314 | { |
| 7315 | u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?'; |
| 7316 | if (attr == 0) |
| 7317 | attr = hl_attr(HLF_8); |
| 7318 | } |
Bram Moolenaar | 1193636 | 2007-09-17 20:39:42 +0000 | [diff] [blame] | 7319 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7320 | # ifdef FEAT_ARABIC |
| 7321 | if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) |
| 7322 | { |
| 7323 | /* Do Arabic shaping. */ |
| 7324 | if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len) |
| 7325 | { |
| 7326 | /* Past end of string to be displayed. */ |
| 7327 | nc = NUL; |
| 7328 | nc1 = NUL; |
| 7329 | } |
| 7330 | else |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7331 | { |
Bram Moolenaar | 5462018 | 2009-11-11 16:07:20 +0000 | [diff] [blame] | 7332 | nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc, |
| 7333 | (int)((text + len) - ptr - mbyte_blen)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7334 | nc1 = pcc[0]; |
| 7335 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7336 | pc = prev_c; |
| 7337 | prev_c = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7338 | u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7339 | } |
| 7340 | else |
| 7341 | prev_c = u8c; |
| 7342 | # endif |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 7343 | if (col + mbyte_cells > screen_Columns) |
| 7344 | { |
| 7345 | /* Only 1 cell left, but character requires 2 cells: |
| 7346 | * display a '>' in the last column to avoid wrapping. */ |
| 7347 | c = '>'; |
| 7348 | mbyte_cells = 1; |
| 7349 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7350 | } |
| 7351 | } |
| 7352 | #endif |
| 7353 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7354 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7355 | force_redraw_this = force_redraw_next; |
| 7356 | force_redraw_next = FALSE; |
| 7357 | #endif |
| 7358 | |
| 7359 | need_redraw = ScreenLines[off] != c |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7360 | #ifdef FEAT_MBYTE |
| 7361 | || (mbyte_cells == 2 |
| 7362 | && ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) |
| 7363 | || (enc_dbcs == DBCS_JPNU |
| 7364 | && c == 0x8e |
| 7365 | && ScreenLines2[off] != ptr[1]) |
| 7366 | || (enc_utf8 |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 7367 | && (ScreenLinesUC[off] != |
| 7368 | (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) |
| 7369 | || (ScreenLinesUC[off] != 0 |
| 7370 | && screen_comp_differs(off, u8cc)))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7371 | #endif |
| 7372 | || ScreenAttrs[off] != attr |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7373 | || exmode_active; |
| 7374 | |
| 7375 | if (need_redraw |
| 7376 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7377 | || force_redraw_this |
| 7378 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7379 | ) |
| 7380 | { |
| 7381 | #if defined(FEAT_GUI) || defined(UNIX) |
| 7382 | /* The bold trick makes a single row of pixels appear in the next |
| 7383 | * character. When a bold character is removed, the next |
| 7384 | * character should be redrawn too. This happens for our own GUI |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7385 | * and for some xterms. */ |
| 7386 | if (need_redraw && ScreenLines[off] != ' ' && ( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7387 | # ifdef FEAT_GUI |
| 7388 | gui.in_use |
| 7389 | # endif |
| 7390 | # if defined(FEAT_GUI) && defined(UNIX) |
| 7391 | || |
| 7392 | # endif |
| 7393 | # ifdef UNIX |
| 7394 | term_is_xterm |
| 7395 | # endif |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7396 | )) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7397 | { |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7398 | int n = ScreenAttrs[off]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7399 | |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7400 | if (n > HL_ALL) |
| 7401 | n = syn_attr2attr(n); |
| 7402 | if (n & HL_BOLD) |
| 7403 | force_redraw_next = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7404 | } |
| 7405 | #endif |
| 7406 | #ifdef FEAT_MBYTE |
| 7407 | /* When at the end of the text and overwriting a two-cell |
| 7408 | * character with a one-cell character, need to clear the next |
| 7409 | * cell. Also when overwriting the left halve of a two-cell char |
| 7410 | * with the right halve of a two-cell char. Do this only once |
| 7411 | * (mb_off2cells() may return 2 on the right halve). */ |
| 7412 | if (clear_next_cell) |
| 7413 | clear_next_cell = FALSE; |
| 7414 | else if (has_mbyte |
| 7415 | && (len < 0 ? ptr[mbyte_blen] == NUL |
| 7416 | : ptr + mbyte_blen >= text + len) |
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 | clear_next_cell = TRUE; |
| 7422 | |
| 7423 | /* Make sure we never leave a second byte of a double-byte behind, |
| 7424 | * it confuses mb_off2cells(). */ |
| 7425 | if (enc_dbcs |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7426 | && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7427 | || (mbyte_cells == 2 |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 7428 | && (*mb_off2cells)(off, max_off) == 1 |
| 7429 | && (*mb_off2cells)(off + 1, max_off) > 1))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7430 | ScreenLines[off + mbyte_blen] = 0; |
| 7431 | #endif |
| 7432 | ScreenLines[off] = c; |
| 7433 | ScreenAttrs[off] = attr; |
| 7434 | #ifdef FEAT_MBYTE |
| 7435 | if (enc_utf8) |
| 7436 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7437 | if (c < 0x80 && u8cc[0] == 0) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7438 | ScreenLinesUC[off] = 0; |
| 7439 | else |
| 7440 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7441 | int i; |
| 7442 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7443 | ScreenLinesUC[off] = u8c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 7444 | for (i = 0; i < Screen_mco; ++i) |
| 7445 | { |
| 7446 | ScreenLinesC[i][off] = u8cc[i]; |
| 7447 | if (u8cc[i] == 0) |
| 7448 | break; |
| 7449 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7450 | } |
| 7451 | if (mbyte_cells == 2) |
| 7452 | { |
| 7453 | ScreenLines[off + 1] = 0; |
| 7454 | ScreenAttrs[off + 1] = attr; |
| 7455 | } |
| 7456 | screen_char(off, row, col); |
| 7457 | } |
| 7458 | else if (mbyte_cells == 2) |
| 7459 | { |
| 7460 | ScreenLines[off + 1] = ptr[1]; |
| 7461 | ScreenAttrs[off + 1] = attr; |
| 7462 | screen_char_2(off, row, col); |
| 7463 | } |
| 7464 | else if (enc_dbcs == DBCS_JPNU && c == 0x8e) |
| 7465 | { |
| 7466 | ScreenLines2[off] = ptr[1]; |
| 7467 | screen_char(off, row, col); |
| 7468 | } |
| 7469 | else |
| 7470 | #endif |
| 7471 | screen_char(off, row, col); |
| 7472 | } |
| 7473 | #ifdef FEAT_MBYTE |
| 7474 | if (has_mbyte) |
| 7475 | { |
| 7476 | off += mbyte_cells; |
| 7477 | col += mbyte_cells; |
| 7478 | ptr += mbyte_blen; |
| 7479 | if (clear_next_cell) |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7480 | { |
| 7481 | /* This only happens at the end, display one space next. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7482 | ptr = (char_u *)" "; |
Bram Moolenaar | e4c21e6 | 2014-05-22 16:05:19 +0200 | [diff] [blame] | 7483 | len = -1; |
| 7484 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7485 | } |
| 7486 | else |
| 7487 | #endif |
| 7488 | { |
| 7489 | ++off; |
| 7490 | ++col; |
| 7491 | ++ptr; |
| 7492 | } |
| 7493 | } |
Bram Moolenaar | 2bea291 | 2009-03-11 16:58:40 +0000 | [diff] [blame] | 7494 | |
| 7495 | #if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX) |
| 7496 | /* If we detected the next character needs to be redrawn, but the text |
| 7497 | * doesn't extend up to there, update the character here. */ |
| 7498 | if (force_redraw_next && col < screen_Columns) |
| 7499 | { |
| 7500 | # ifdef FEAT_MBYTE |
| 7501 | if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) |
| 7502 | screen_char_2(off, row, col); |
| 7503 | else |
| 7504 | # endif |
| 7505 | screen_char(off, row, col); |
| 7506 | } |
| 7507 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7508 | } |
| 7509 | |
| 7510 | #ifdef FEAT_SEARCH_EXTRA |
| 7511 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7512 | * Prepare for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7513 | */ |
| 7514 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7515 | start_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7516 | { |
| 7517 | if (p_hls && !no_hlsearch) |
| 7518 | { |
| 7519 | last_pat_prog(&search_hl.rm); |
| 7520 | search_hl.attr = hl_attr(HLF_L); |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7521 | # ifdef FEAT_RELTIME |
| 7522 | /* Set the time limit to 'redrawtime'. */ |
| 7523 | profile_setlimit(p_rdt, &search_hl.tm); |
| 7524 | # endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7525 | } |
| 7526 | } |
| 7527 | |
| 7528 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7529 | * Clean up for 'hlsearch' highlighting. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7530 | */ |
| 7531 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7532 | end_search_hl(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7533 | { |
| 7534 | if (search_hl.rm.regprog != NULL) |
| 7535 | { |
Bram Moolenaar | 473de61 | 2013-06-08 18:19:48 +0200 | [diff] [blame] | 7536 | vim_regfree(search_hl.rm.regprog); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7537 | search_hl.rm.regprog = NULL; |
| 7538 | } |
| 7539 | } |
| 7540 | |
| 7541 | /* |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7542 | * Init for calling prepare_search_hl(). |
| 7543 | */ |
| 7544 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7545 | init_search_hl(win_T *wp) |
Bram Moolenaar | 0af8ceb | 2010-07-05 22:22:57 +0200 | [diff] [blame] | 7546 | { |
| 7547 | matchitem_T *cur; |
| 7548 | |
| 7549 | /* Setup for match and 'hlsearch' highlighting. Disable any previous |
| 7550 | * match */ |
| 7551 | cur = wp->w_match_head; |
| 7552 | while (cur != NULL) |
| 7553 | { |
| 7554 | cur->hl.rm = cur->match; |
| 7555 | if (cur->hlg_id == 0) |
| 7556 | cur->hl.attr = 0; |
| 7557 | else |
| 7558 | cur->hl.attr = syn_id2attr(cur->hlg_id); |
| 7559 | cur->hl.buf = wp->w_buffer; |
| 7560 | cur->hl.lnum = 0; |
| 7561 | cur->hl.first_lnum = 0; |
| 7562 | # ifdef FEAT_RELTIME |
| 7563 | /* Set the time limit to 'redrawtime'. */ |
| 7564 | profile_setlimit(p_rdt, &(cur->hl.tm)); |
| 7565 | # endif |
| 7566 | cur = cur->next; |
| 7567 | } |
| 7568 | search_hl.buf = wp->w_buffer; |
| 7569 | search_hl.lnum = 0; |
| 7570 | search_hl.first_lnum = 0; |
| 7571 | /* time limit is set at the toplevel, for all windows */ |
| 7572 | } |
| 7573 | |
| 7574 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7575 | * Advance to the match in window "wp" line "lnum" or past it. |
| 7576 | */ |
| 7577 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7578 | prepare_search_hl(win_T *wp, linenr_T lnum) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7579 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7580 | matchitem_T *cur; /* points to the match list */ |
| 7581 | match_T *shl; /* points to search_hl or a match */ |
| 7582 | int shl_flag; /* flag to indicate whether search_hl |
| 7583 | has been processed or not */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7584 | int pos_inprogress; /* marks that position match search is |
| 7585 | in progress */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7586 | int n; |
| 7587 | |
| 7588 | /* |
| 7589 | * When using a multi-line pattern, start searching at the top |
| 7590 | * of the window or just after a closed fold. |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7591 | * Do this both for search_hl and the match list. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7592 | */ |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7593 | cur = wp->w_match_head; |
| 7594 | shl_flag = FALSE; |
| 7595 | while (cur != NULL || shl_flag == FALSE) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7596 | { |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7597 | if (shl_flag == FALSE) |
| 7598 | { |
| 7599 | shl = &search_hl; |
| 7600 | shl_flag = TRUE; |
| 7601 | } |
| 7602 | else |
| 7603 | shl = &cur->hl; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7604 | if (shl->rm.regprog != NULL |
| 7605 | && shl->lnum == 0 |
| 7606 | && re_multiline(shl->rm.regprog)) |
| 7607 | { |
| 7608 | if (shl->first_lnum == 0) |
| 7609 | { |
| 7610 | # ifdef FEAT_FOLDING |
| 7611 | for (shl->first_lnum = lnum; |
| 7612 | shl->first_lnum > wp->w_topline; --shl->first_lnum) |
| 7613 | if (hasFoldingWin(wp, shl->first_lnum - 1, |
| 7614 | NULL, NULL, TRUE, NULL)) |
| 7615 | break; |
| 7616 | # else |
| 7617 | shl->first_lnum = wp->w_topline; |
| 7618 | # endif |
| 7619 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7620 | if (cur != NULL) |
| 7621 | cur->pos.cur = 0; |
| 7622 | pos_inprogress = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7623 | n = 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7624 | while (shl->first_lnum < lnum && (shl->rm.regprog != NULL |
| 7625 | || (cur != NULL && pos_inprogress))) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7626 | { |
Bram Moolenaar | e17bdff | 2016-08-27 18:34:29 +0200 | [diff] [blame] | 7627 | next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n, |
| 7628 | shl == &search_hl ? NULL : cur); |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7629 | pos_inprogress = cur == NULL || cur->pos.cur == 0 |
| 7630 | ? FALSE : TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7631 | if (shl->lnum != 0) |
| 7632 | { |
| 7633 | shl->first_lnum = shl->lnum |
| 7634 | + shl->rm.endpos[0].lnum |
| 7635 | - shl->rm.startpos[0].lnum; |
| 7636 | n = shl->rm.endpos[0].col; |
| 7637 | } |
| 7638 | else |
| 7639 | { |
| 7640 | ++shl->first_lnum; |
| 7641 | n = 0; |
| 7642 | } |
| 7643 | } |
| 7644 | } |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7645 | if (shl != &search_hl && cur != NULL) |
| 7646 | cur = cur->next; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7647 | } |
| 7648 | } |
| 7649 | |
| 7650 | /* |
Bram Moolenaar | 6ee1016 | 2007-07-26 20:58:42 +0000 | [diff] [blame] | 7651 | * Search for a next 'hlsearch' or match. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7652 | * Uses shl->buf. |
| 7653 | * Sets shl->lnum and shl->rm contents. |
| 7654 | * Note: Assumes a previous match is always before "lnum", unless |
| 7655 | * shl->lnum is zero. |
| 7656 | * Careful: Any pointers for buffer lines will become invalid. |
| 7657 | */ |
| 7658 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7659 | next_search_hl( |
| 7660 | win_T *win, |
| 7661 | match_T *shl, /* points to search_hl or a match */ |
| 7662 | linenr_T lnum, |
| 7663 | colnr_T mincol, /* minimal column for a match */ |
| 7664 | matchitem_T *cur) /* to retrieve match positions if any */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7665 | { |
| 7666 | linenr_T l; |
| 7667 | colnr_T matchcol; |
| 7668 | long nmatched; |
| 7669 | |
| 7670 | if (shl->lnum != 0) |
| 7671 | { |
| 7672 | /* Check for three situations: |
| 7673 | * 1. If the "lnum" is below a previous match, start a new search. |
| 7674 | * 2. If the previous match includes "mincol", use it. |
| 7675 | * 3. Continue after the previous match. |
| 7676 | */ |
| 7677 | l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum; |
| 7678 | if (lnum > l) |
| 7679 | shl->lnum = 0; |
| 7680 | else if (lnum < l || shl->rm.endpos[0].col > mincol) |
| 7681 | return; |
| 7682 | } |
| 7683 | |
| 7684 | /* |
| 7685 | * Repeat searching for a match until one is found that includes "mincol" |
| 7686 | * or none is found in this line. |
| 7687 | */ |
| 7688 | called_emsg = FALSE; |
| 7689 | for (;;) |
| 7690 | { |
Bram Moolenaar | 91a4e82 | 2008-01-19 14:59:58 +0000 | [diff] [blame] | 7691 | #ifdef FEAT_RELTIME |
| 7692 | /* Stop searching after passing the time limit. */ |
| 7693 | if (profile_passed_limit(&(shl->tm))) |
| 7694 | { |
| 7695 | shl->lnum = 0; /* no match found in time */ |
| 7696 | break; |
| 7697 | } |
| 7698 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7699 | /* Three situations: |
| 7700 | * 1. No useful previous match: search from start of line. |
| 7701 | * 2. Not Vi compatible or empty match: continue at next character. |
| 7702 | * Break the loop if this is beyond the end of the line. |
| 7703 | * 3. Vi compatible searching: continue at end of previous match. |
| 7704 | */ |
| 7705 | if (shl->lnum == 0) |
| 7706 | matchcol = 0; |
| 7707 | else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL |
| 7708 | || (shl->rm.endpos[0].lnum == 0 |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7709 | && shl->rm.endpos[0].col <= shl->rm.startpos[0].col)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7710 | { |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7711 | char_u *ml; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7712 | |
| 7713 | matchcol = shl->rm.startpos[0].col; |
Bram Moolenaar | 5c8837f | 2006-02-25 21:52:33 +0000 | [diff] [blame] | 7714 | ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol; |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7715 | if (*ml == NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7716 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7717 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7718 | shl->lnum = 0; |
| 7719 | break; |
| 7720 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 7721 | #ifdef FEAT_MBYTE |
| 7722 | if (has_mbyte) |
| 7723 | matchcol += mb_ptr2len(ml); |
| 7724 | else |
| 7725 | #endif |
| 7726 | ++matchcol; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7727 | } |
| 7728 | else |
| 7729 | matchcol = shl->rm.endpos[0].col; |
| 7730 | |
| 7731 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7732 | if (shl->rm.regprog != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7733 | { |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7734 | /* Remember whether shl->rm is using a copy of the regprog in |
| 7735 | * cur->match. */ |
| 7736 | int regprog_is_copy = (shl != &search_hl && cur != NULL |
| 7737 | && shl == &cur->hl |
| 7738 | && cur->match.regprog == cur->hl.rm.regprog); |
| 7739 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7740 | nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum, |
| 7741 | matchcol, |
| 7742 | #ifdef FEAT_RELTIME |
| 7743 | &(shl->tm) |
| 7744 | #else |
| 7745 | NULL |
| 7746 | #endif |
| 7747 | ); |
Bram Moolenaar | cbdf0a0 | 2014-11-27 13:37:10 +0100 | [diff] [blame] | 7748 | /* Copy the regprog, in case it got freed and recompiled. */ |
| 7749 | if (regprog_is_copy) |
| 7750 | cur->match.regprog = cur->hl.rm.regprog; |
| 7751 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7752 | if (called_emsg || got_int) |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7753 | { |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7754 | /* Error while handling regexp: stop using this regexp. */ |
| 7755 | if (shl == &search_hl) |
| 7756 | { |
| 7757 | /* don't free regprog in the match list, it's a copy */ |
| 7758 | vim_regfree(shl->rm.regprog); |
| 7759 | SET_NO_HLSEARCH(TRUE); |
| 7760 | } |
| 7761 | shl->rm.regprog = NULL; |
| 7762 | shl->lnum = 0; |
| 7763 | got_int = FALSE; /* avoid the "Type :quit to exit Vim" |
| 7764 | message */ |
| 7765 | break; |
Bram Moolenaar | 0ddf0a7 | 2007-05-01 20:04:53 +0000 | [diff] [blame] | 7766 | } |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7767 | } |
| 7768 | else if (cur != NULL) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7769 | nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol); |
Bram Moolenaar | deae0f2 | 2014-06-18 21:20:11 +0200 | [diff] [blame] | 7770 | else |
| 7771 | nmatched = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7772 | if (nmatched == 0) |
| 7773 | { |
| 7774 | shl->lnum = 0; /* no match found */ |
| 7775 | break; |
| 7776 | } |
| 7777 | if (shl->rm.startpos[0].lnum > 0 |
| 7778 | || shl->rm.startpos[0].col >= mincol |
| 7779 | || nmatched > 1 |
| 7780 | || shl->rm.endpos[0].col > mincol) |
| 7781 | { |
| 7782 | shl->lnum += shl->rm.startpos[0].lnum; |
| 7783 | break; /* useful match found */ |
| 7784 | } |
| 7785 | } |
| 7786 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7787 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7788 | /* |
| 7789 | * If there is a match fill "shl" and return one. |
| 7790 | * Return zero otherwise. |
| 7791 | */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7792 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7793 | next_search_hl_pos( |
| 7794 | match_T *shl, /* points to a match */ |
| 7795 | linenr_T lnum, |
| 7796 | posmatch_T *posmatch, /* match positions */ |
| 7797 | colnr_T mincol) /* minimal column for a match */ |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7798 | { |
| 7799 | int i; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7800 | int found = -1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7801 | |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7802 | for (i = posmatch->cur; i < MAXPOSMATCH; i++) |
| 7803 | { |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7804 | llpos_T *pos = &posmatch->pos[i]; |
| 7805 | |
| 7806 | if (pos->lnum == 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7807 | break; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7808 | if (pos->len == 0 && pos->col < mincol) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7809 | continue; |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7810 | if (pos->lnum == lnum) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7811 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7812 | if (found >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7813 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7814 | /* if this match comes before the one at "found" then swap |
| 7815 | * them */ |
| 7816 | if (pos->col < posmatch->pos[found].col) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7817 | { |
Bram Moolenaar | a6c27ee | 2016-10-15 14:56:30 +0200 | [diff] [blame] | 7818 | llpos_T tmp = *pos; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7819 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7820 | *pos = posmatch->pos[found]; |
| 7821 | posmatch->pos[found] = tmp; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7822 | } |
| 7823 | } |
| 7824 | else |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7825 | found = i; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7826 | } |
| 7827 | } |
| 7828 | posmatch->cur = 0; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7829 | if (found >= 0) |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7830 | { |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7831 | colnr_T start = posmatch->pos[found].col == 0 |
| 7832 | ? 0 : posmatch->pos[found].col - 1; |
| 7833 | colnr_T end = posmatch->pos[found].col == 0 |
| 7834 | ? MAXCOL : start + posmatch->pos[found].len; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7835 | |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7836 | shl->lnum = lnum; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7837 | shl->rm.startpos[0].lnum = 0; |
| 7838 | shl->rm.startpos[0].col = start; |
| 7839 | shl->rm.endpos[0].lnum = 0; |
| 7840 | shl->rm.endpos[0].col = end; |
Bram Moolenaar | 4f416e4 | 2016-08-16 16:08:18 +0200 | [diff] [blame] | 7841 | shl->is_addpos = TRUE; |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7842 | posmatch->cur = found + 1; |
| 7843 | return 1; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7844 | } |
Bram Moolenaar | 8507747 | 2016-10-16 14:35:48 +0200 | [diff] [blame] | 7845 | return 0; |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7846 | } |
Bram Moolenaar | de993ea | 2014-06-17 23:18:01 +0200 | [diff] [blame] | 7847 | #endif |
Bram Moolenaar | b341459 | 2014-06-17 17:48:32 +0200 | [diff] [blame] | 7848 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7849 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7850 | screen_start_highlight(int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7851 | { |
| 7852 | attrentry_T *aep = NULL; |
| 7853 | |
| 7854 | screen_attr = attr; |
| 7855 | if (full_screen |
| 7856 | #ifdef WIN3264 |
| 7857 | && termcap_active |
| 7858 | #endif |
| 7859 | ) |
| 7860 | { |
| 7861 | #ifdef FEAT_GUI |
| 7862 | if (gui.in_use) |
| 7863 | { |
| 7864 | char buf[20]; |
| 7865 | |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7866 | /* The GUI handles this internally. */ |
| 7867 | sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7868 | OUT_STR(buf); |
| 7869 | } |
| 7870 | else |
| 7871 | #endif |
| 7872 | { |
| 7873 | if (attr > HL_ALL) /* special HL attr. */ |
| 7874 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7875 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7876 | aep = syn_cterm_attr2entry(attr); |
| 7877 | else |
| 7878 | aep = syn_term_attr2entry(attr); |
| 7879 | if (aep == NULL) /* did ":syntax clear" */ |
| 7880 | attr = 0; |
| 7881 | else |
| 7882 | attr = aep->ae_attr; |
| 7883 | } |
| 7884 | if ((attr & HL_BOLD) && T_MD != NULL) /* bold */ |
| 7885 | out_str(T_MD); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7886 | else if (aep != NULL && cterm_normal_fg_bold && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7887 | #ifdef FEAT_TERMGUICOLORS |
| 7888 | (p_tgc ? |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7889 | (aep->ae_u.cterm.fg_rgb != INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7890 | #endif |
| 7891 | (t_colors > 1 && aep->ae_u.cterm.fg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7892 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7893 | ) |
| 7894 | #endif |
| 7895 | ) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 7896 | /* If the Normal FG color has BOLD attribute and the new HL |
| 7897 | * has a FG color defined, clear BOLD. */ |
| 7898 | out_str(T_ME); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7899 | if ((attr & HL_STANDOUT) && T_SO != NULL) /* standout */ |
| 7900 | out_str(T_SO); |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 7901 | if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL) |
| 7902 | /* underline or undercurl */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7903 | out_str(T_US); |
| 7904 | if ((attr & HL_ITALIC) && T_CZH != NULL) /* italic */ |
| 7905 | out_str(T_CZH); |
| 7906 | if ((attr & HL_INVERSE) && T_MR != NULL) /* inverse (reverse) */ |
| 7907 | out_str(T_MR); |
| 7908 | |
| 7909 | /* |
| 7910 | * Output the color or start string after bold etc., in case the |
| 7911 | * bold etc. override the color setting. |
| 7912 | */ |
| 7913 | if (aep != NULL) |
| 7914 | { |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7915 | #ifdef FEAT_TERMGUICOLORS |
| 7916 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7917 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7918 | if (aep->ae_u.cterm.fg_rgb != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7919 | term_fg_rgb_color(aep->ae_u.cterm.fg_rgb); |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7920 | if (aep->ae_u.cterm.bg_rgb != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7921 | term_bg_rgb_color(aep->ae_u.cterm.bg_rgb); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7922 | } |
| 7923 | else |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7924 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7925 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7926 | if (t_colors > 1) |
| 7927 | { |
| 7928 | if (aep->ae_u.cterm.fg_color) |
| 7929 | term_fg_color(aep->ae_u.cterm.fg_color - 1); |
| 7930 | if (aep->ae_u.cterm.bg_color) |
| 7931 | term_bg_color(aep->ae_u.cterm.bg_color - 1); |
| 7932 | } |
| 7933 | else |
| 7934 | { |
| 7935 | if (aep->ae_u.term.start != NULL) |
| 7936 | out_str(aep->ae_u.term.start); |
| 7937 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7938 | } |
| 7939 | } |
| 7940 | } |
| 7941 | } |
| 7942 | } |
| 7943 | |
| 7944 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 7945 | screen_stop_highlight(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7946 | { |
| 7947 | int do_ME = FALSE; /* output T_ME code */ |
| 7948 | |
| 7949 | if (screen_attr != 0 |
| 7950 | #ifdef WIN3264 |
| 7951 | && termcap_active |
| 7952 | #endif |
| 7953 | ) |
| 7954 | { |
| 7955 | #ifdef FEAT_GUI |
| 7956 | if (gui.in_use) |
| 7957 | { |
| 7958 | char buf[20]; |
| 7959 | |
| 7960 | /* use internal GUI code */ |
| 7961 | sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr); |
| 7962 | OUT_STR(buf); |
| 7963 | } |
| 7964 | else |
| 7965 | #endif |
| 7966 | { |
| 7967 | if (screen_attr > HL_ALL) /* special HL attr. */ |
| 7968 | { |
| 7969 | attrentry_T *aep; |
| 7970 | |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7971 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7972 | { |
| 7973 | /* |
| 7974 | * Assume that t_me restores the original colors! |
| 7975 | */ |
| 7976 | aep = syn_cterm_attr2entry(screen_attr); |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7977 | if (aep != NULL && |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7978 | #ifdef FEAT_TERMGUICOLORS |
| 7979 | (p_tgc ? |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 7980 | (aep->ae_u.cterm.fg_rgb != INVALCOLOR |
| 7981 | || aep->ae_u.cterm.bg_rgb != INVALCOLOR): |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7982 | #endif |
| 7983 | (aep->ae_u.cterm.fg_color || aep->ae_u.cterm.bg_color) |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 7984 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 7985 | ) |
| 7986 | #endif |
| 7987 | ) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 7988 | do_ME = TRUE; |
| 7989 | } |
| 7990 | else |
| 7991 | { |
| 7992 | aep = syn_term_attr2entry(screen_attr); |
| 7993 | if (aep != NULL && aep->ae_u.term.stop != NULL) |
| 7994 | { |
| 7995 | if (STRCMP(aep->ae_u.term.stop, T_ME) == 0) |
| 7996 | do_ME = TRUE; |
| 7997 | else |
| 7998 | out_str(aep->ae_u.term.stop); |
| 7999 | } |
| 8000 | } |
| 8001 | if (aep == NULL) /* did ":syntax clear" */ |
| 8002 | screen_attr = 0; |
| 8003 | else |
| 8004 | screen_attr = aep->ae_attr; |
| 8005 | } |
| 8006 | |
| 8007 | /* |
| 8008 | * Often all ending-codes are equal to T_ME. Avoid outputting the |
| 8009 | * same sequence several times. |
| 8010 | */ |
| 8011 | if (screen_attr & HL_STANDOUT) |
| 8012 | { |
| 8013 | if (STRCMP(T_SE, T_ME) == 0) |
| 8014 | do_ME = TRUE; |
| 8015 | else |
| 8016 | out_str(T_SE); |
| 8017 | } |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 8018 | if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8019 | { |
| 8020 | if (STRCMP(T_UE, T_ME) == 0) |
| 8021 | do_ME = TRUE; |
| 8022 | else |
| 8023 | out_str(T_UE); |
| 8024 | } |
| 8025 | if (screen_attr & HL_ITALIC) |
| 8026 | { |
| 8027 | if (STRCMP(T_CZR, T_ME) == 0) |
| 8028 | do_ME = TRUE; |
| 8029 | else |
| 8030 | out_str(T_CZR); |
| 8031 | } |
| 8032 | if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE))) |
| 8033 | out_str(T_ME); |
| 8034 | |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8035 | #ifdef FEAT_TERMGUICOLORS |
| 8036 | if (p_tgc) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8037 | { |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8038 | if (cterm_normal_fg_gui_color != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8039 | term_fg_rgb_color(cterm_normal_fg_gui_color); |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8040 | if (cterm_normal_bg_gui_color != INVALCOLOR) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8041 | term_bg_rgb_color(cterm_normal_bg_gui_color); |
| 8042 | } |
| 8043 | else |
| 8044 | #endif |
| 8045 | { |
| 8046 | if (t_colors > 1) |
| 8047 | { |
| 8048 | /* set Normal cterm colors */ |
| 8049 | if (cterm_normal_fg_color != 0) |
| 8050 | term_fg_color(cterm_normal_fg_color - 1); |
| 8051 | if (cterm_normal_bg_color != 0) |
| 8052 | term_bg_color(cterm_normal_bg_color - 1); |
| 8053 | if (cterm_normal_fg_bold) |
| 8054 | out_str(T_MD); |
| 8055 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8056 | } |
| 8057 | } |
| 8058 | } |
| 8059 | screen_attr = 0; |
| 8060 | } |
| 8061 | |
| 8062 | /* |
| 8063 | * Reset the colors for a cterm. Used when leaving Vim. |
| 8064 | * The machine specific code may override this again. |
| 8065 | */ |
| 8066 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8067 | reset_cterm_colors(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8068 | { |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8069 | if (IS_CTERM) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8070 | { |
| 8071 | /* set Normal cterm colors */ |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 8072 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 8073 | if (p_tgc ? (cterm_normal_fg_gui_color != INVALCOLOR |
| 8074 | || cterm_normal_bg_gui_color != INVALCOLOR) |
| 8075 | : (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8076 | #else |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8077 | if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0) |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8078 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8079 | { |
| 8080 | out_str(T_OP); |
| 8081 | screen_attr = -1; |
| 8082 | } |
| 8083 | if (cterm_normal_fg_bold) |
| 8084 | { |
| 8085 | out_str(T_ME); |
| 8086 | screen_attr = -1; |
| 8087 | } |
| 8088 | } |
| 8089 | } |
| 8090 | |
| 8091 | /* |
| 8092 | * Put character ScreenLines["off"] on the screen at position "row" and "col", |
| 8093 | * using the attributes from ScreenAttrs["off"]. |
| 8094 | */ |
| 8095 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8096 | screen_char(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8097 | { |
| 8098 | int attr; |
| 8099 | |
| 8100 | /* Check for illegal values, just in case (could happen just after |
| 8101 | * resizing). */ |
| 8102 | if (row >= screen_Rows || col >= screen_Columns) |
| 8103 | return; |
| 8104 | |
Bram Moolenaar | 494838a | 2015-02-10 19:20:37 +0100 | [diff] [blame] | 8105 | /* Outputting a character in the last cell on the screen may scroll the |
| 8106 | * screen up. Only do it when the "xn" termcap property is set, otherwise |
| 8107 | * mark the character invalid (update it when scrolled up). */ |
| 8108 | if (*T_XN == NUL |
| 8109 | && row == screen_Rows - 1 && col == screen_Columns - 1 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8110 | #ifdef FEAT_RIGHTLEFT |
| 8111 | /* account for first command-line character in rightleft mode */ |
| 8112 | && !cmdmsg_rl |
| 8113 | #endif |
| 8114 | ) |
| 8115 | { |
| 8116 | ScreenAttrs[off] = (sattr_T)-1; |
| 8117 | return; |
| 8118 | } |
| 8119 | |
| 8120 | /* |
| 8121 | * Stop highlighting first, so it's easier to move the cursor. |
| 8122 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8123 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8124 | if (screen_char_attr != 0) |
| 8125 | attr = screen_char_attr; |
| 8126 | else |
| 8127 | #endif |
| 8128 | attr = ScreenAttrs[off]; |
| 8129 | if (screen_attr != attr) |
| 8130 | screen_stop_highlight(); |
| 8131 | |
| 8132 | windgoto(row, col); |
| 8133 | |
| 8134 | if (screen_attr != attr) |
| 8135 | screen_start_highlight(attr); |
| 8136 | |
| 8137 | #ifdef FEAT_MBYTE |
| 8138 | if (enc_utf8 && ScreenLinesUC[off] != 0) |
| 8139 | { |
| 8140 | char_u buf[MB_MAXBYTES + 1]; |
| 8141 | |
| 8142 | /* Convert UTF-8 character to bytes and write it. */ |
| 8143 | |
| 8144 | buf[utfc_char2bytes(off, buf)] = NUL; |
| 8145 | |
| 8146 | out_str(buf); |
Bram Moolenaar | cb07008 | 2016-04-02 22:14:51 +0200 | [diff] [blame] | 8147 | if (utf_ambiguous_width(ScreenLinesUC[off])) |
| 8148 | screen_cur_col = 9999; |
| 8149 | else if (utf_char2cells(ScreenLinesUC[off]) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8150 | ++screen_cur_col; |
| 8151 | } |
| 8152 | else |
| 8153 | #endif |
| 8154 | { |
| 8155 | #ifdef FEAT_MBYTE |
| 8156 | out_flush_check(); |
| 8157 | #endif |
| 8158 | out_char(ScreenLines[off]); |
| 8159 | #ifdef FEAT_MBYTE |
| 8160 | /* double-byte character in single-width cell */ |
| 8161 | if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e) |
| 8162 | out_char(ScreenLines2[off]); |
| 8163 | #endif |
| 8164 | } |
| 8165 | |
| 8166 | screen_cur_col++; |
| 8167 | } |
| 8168 | |
| 8169 | #ifdef FEAT_MBYTE |
| 8170 | |
| 8171 | /* |
| 8172 | * Used for enc_dbcs only: Put one double-wide character at ScreenLines["off"] |
| 8173 | * on the screen at position 'row' and 'col'. |
| 8174 | * The attributes of the first byte is used for all. This is required to |
| 8175 | * output the two bytes of a double-byte character with nothing in between. |
| 8176 | */ |
| 8177 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8178 | screen_char_2(unsigned off, int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8179 | { |
| 8180 | /* Check for illegal values (could be wrong when screen was resized). */ |
| 8181 | if (off + 1 >= (unsigned)(screen_Rows * screen_Columns)) |
| 8182 | return; |
| 8183 | |
| 8184 | /* Outputting the last character on the screen may scrollup the screen. |
| 8185 | * Don't to it! Mark the character invalid (update it when scrolled up) */ |
| 8186 | if (row == screen_Rows - 1 && col >= screen_Columns - 2) |
| 8187 | { |
| 8188 | ScreenAttrs[off] = (sattr_T)-1; |
| 8189 | return; |
| 8190 | } |
| 8191 | |
| 8192 | /* Output the first byte normally (positions the cursor), then write the |
| 8193 | * second byte directly. */ |
| 8194 | screen_char(off, row, col); |
| 8195 | out_char(ScreenLines[off + 1]); |
| 8196 | ++screen_cur_col; |
| 8197 | } |
| 8198 | #endif |
| 8199 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8200 | #if defined(FEAT_CLIPBOARD) || defined(FEAT_WINDOWS) || defined(PROTO) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8201 | /* |
| 8202 | * Draw a rectangle of the screen, inverted when "invert" is TRUE. |
| 8203 | * This uses the contents of ScreenLines[] and doesn't change it. |
| 8204 | */ |
| 8205 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8206 | screen_draw_rectangle( |
| 8207 | int row, |
| 8208 | int col, |
| 8209 | int height, |
| 8210 | int width, |
| 8211 | int invert) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8212 | { |
| 8213 | int r, c; |
| 8214 | int off; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8215 | #ifdef FEAT_MBYTE |
| 8216 | int max_off; |
| 8217 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8218 | |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8219 | /* Can't use ScreenLines unless initialized */ |
| 8220 | if (ScreenLines == NULL) |
| 8221 | return; |
| 8222 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8223 | if (invert) |
| 8224 | screen_char_attr = HL_INVERSE; |
| 8225 | for (r = row; r < row + height; ++r) |
| 8226 | { |
| 8227 | off = LineOffset[r]; |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8228 | #ifdef FEAT_MBYTE |
| 8229 | max_off = off + screen_Columns; |
| 8230 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8231 | for (c = col; c < col + width; ++c) |
| 8232 | { |
| 8233 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8234 | if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8235 | { |
| 8236 | screen_char_2(off + c, r, c); |
| 8237 | ++c; |
| 8238 | } |
| 8239 | else |
| 8240 | #endif |
| 8241 | { |
| 8242 | screen_char(off + c, r, c); |
| 8243 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 367329b | 2007-08-30 11:53:22 +0000 | [diff] [blame] | 8244 | if (utf_off2cells(off + c, max_off) > 1) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8245 | ++c; |
| 8246 | #endif |
| 8247 | } |
| 8248 | } |
| 8249 | } |
| 8250 | screen_char_attr = 0; |
| 8251 | } |
| 8252 | #endif |
| 8253 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8254 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8255 | /* |
| 8256 | * Redraw the characters for a vertically split window. |
| 8257 | */ |
| 8258 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8259 | redraw_block(int row, int end, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8260 | { |
| 8261 | int col; |
| 8262 | int width; |
| 8263 | |
| 8264 | # ifdef FEAT_CLIPBOARD |
| 8265 | clip_may_clear_selection(row, end - 1); |
| 8266 | # endif |
| 8267 | |
| 8268 | if (wp == NULL) |
| 8269 | { |
| 8270 | col = 0; |
| 8271 | width = Columns; |
| 8272 | } |
| 8273 | else |
| 8274 | { |
| 8275 | col = wp->w_wincol; |
| 8276 | width = wp->w_width; |
| 8277 | } |
| 8278 | screen_draw_rectangle(row, col, end - row, width, FALSE); |
| 8279 | } |
| 8280 | #endif |
| 8281 | |
| 8282 | /* |
| 8283 | * Fill the screen from 'start_row' to 'end_row', from 'start_col' to 'end_col' |
| 8284 | * with character 'c1' in first column followed by 'c2' in the other columns. |
| 8285 | * Use attributes 'attr'. |
| 8286 | */ |
| 8287 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8288 | screen_fill( |
| 8289 | int start_row, |
| 8290 | int end_row, |
| 8291 | int start_col, |
| 8292 | int end_col, |
| 8293 | int c1, |
| 8294 | int c2, |
| 8295 | int attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8296 | { |
| 8297 | int row; |
| 8298 | int col; |
| 8299 | int off; |
| 8300 | int end_off; |
| 8301 | int did_delete; |
| 8302 | int c; |
| 8303 | int norm_term; |
| 8304 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8305 | int force_next = FALSE; |
| 8306 | #endif |
| 8307 | |
| 8308 | if (end_row > screen_Rows) /* safety check */ |
| 8309 | end_row = screen_Rows; |
| 8310 | if (end_col > screen_Columns) /* safety check */ |
| 8311 | end_col = screen_Columns; |
| 8312 | if (ScreenLines == NULL |
| 8313 | || start_row >= end_row |
| 8314 | || start_col >= end_col) /* nothing to do */ |
| 8315 | return; |
| 8316 | |
| 8317 | /* it's a "normal" terminal when not in a GUI or cterm */ |
| 8318 | norm_term = ( |
| 8319 | #ifdef FEAT_GUI |
| 8320 | !gui.in_use && |
| 8321 | #endif |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 8322 | !IS_CTERM); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8323 | for (row = start_row; row < end_row; ++row) |
| 8324 | { |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8325 | #ifdef FEAT_MBYTE |
| 8326 | if (has_mbyte |
| 8327 | # ifdef FEAT_GUI |
| 8328 | && !gui.in_use |
| 8329 | # endif |
| 8330 | ) |
| 8331 | { |
| 8332 | /* When drawing over the right halve of a double-wide char clear |
| 8333 | * out the left halve. When drawing over the left halve of a |
| 8334 | * double wide-char clear out the right halve. Only needed in a |
| 8335 | * terminal. */ |
Bram Moolenaar | 7693ec6 | 2008-07-24 18:29:37 +0000 | [diff] [blame] | 8336 | if (start_col > 0 && mb_fix_col(start_col, row) != start_col) |
Bram Moolenaar | d91ffe9 | 2008-07-14 17:51:11 +0000 | [diff] [blame] | 8337 | screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0); |
Bram Moolenaar | a1aed62 | 2008-07-18 15:14:43 +0000 | [diff] [blame] | 8338 | 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] | 8339 | screen_puts_len((char_u *)" ", 1, row, end_col, 0); |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 8340 | } |
| 8341 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8342 | /* |
| 8343 | * Try to use delete-line termcap code, when no attributes or in a |
| 8344 | * "normal" terminal, where a bold/italic space is just a |
| 8345 | * space. |
| 8346 | */ |
| 8347 | did_delete = FALSE; |
| 8348 | if (c2 == ' ' |
| 8349 | && end_col == Columns |
| 8350 | && can_clear(T_CE) |
| 8351 | && (attr == 0 |
| 8352 | || (norm_term |
| 8353 | && attr <= HL_ALL |
| 8354 | && ((attr & ~(HL_BOLD | HL_ITALIC)) == 0)))) |
| 8355 | { |
| 8356 | /* |
| 8357 | * check if we really need to clear something |
| 8358 | */ |
| 8359 | col = start_col; |
| 8360 | if (c1 != ' ') /* don't clear first char */ |
| 8361 | ++col; |
| 8362 | |
| 8363 | off = LineOffset[row] + col; |
| 8364 | end_off = LineOffset[row] + end_col; |
| 8365 | |
| 8366 | /* skip blanks (used often, keep it fast!) */ |
| 8367 | #ifdef FEAT_MBYTE |
| 8368 | if (enc_utf8) |
| 8369 | while (off < end_off && ScreenLines[off] == ' ' |
| 8370 | && ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0) |
| 8371 | ++off; |
| 8372 | else |
| 8373 | #endif |
| 8374 | while (off < end_off && ScreenLines[off] == ' ' |
| 8375 | && ScreenAttrs[off] == 0) |
| 8376 | ++off; |
| 8377 | if (off < end_off) /* something to be cleared */ |
| 8378 | { |
| 8379 | col = off - LineOffset[row]; |
| 8380 | screen_stop_highlight(); |
| 8381 | term_windgoto(row, col);/* clear rest of this screen line */ |
| 8382 | out_str(T_CE); |
| 8383 | screen_start(); /* don't know where cursor is now */ |
| 8384 | col = end_col - col; |
| 8385 | while (col--) /* clear chars in ScreenLines */ |
| 8386 | { |
| 8387 | ScreenLines[off] = ' '; |
| 8388 | #ifdef FEAT_MBYTE |
| 8389 | if (enc_utf8) |
| 8390 | ScreenLinesUC[off] = 0; |
| 8391 | #endif |
| 8392 | ScreenAttrs[off] = 0; |
| 8393 | ++off; |
| 8394 | } |
| 8395 | } |
| 8396 | did_delete = TRUE; /* the chars are cleared now */ |
| 8397 | } |
| 8398 | |
| 8399 | off = LineOffset[row] + start_col; |
| 8400 | c = c1; |
| 8401 | for (col = start_col; col < end_col; ++col) |
| 8402 | { |
| 8403 | if (ScreenLines[off] != c |
| 8404 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8405 | || (enc_utf8 && (int)ScreenLinesUC[off] |
| 8406 | != (c >= 0x80 ? c : 0)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8407 | #endif |
| 8408 | || ScreenAttrs[off] != attr |
| 8409 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8410 | || force_next |
| 8411 | #endif |
| 8412 | ) |
| 8413 | { |
| 8414 | #if defined(FEAT_GUI) || defined(UNIX) |
| 8415 | /* The bold trick may make a single row of pixels appear in |
| 8416 | * the next character. When a bold character is removed, the |
| 8417 | * next character should be redrawn too. This happens for our |
| 8418 | * own GUI and for some xterms. */ |
| 8419 | if ( |
| 8420 | # ifdef FEAT_GUI |
| 8421 | gui.in_use |
| 8422 | # endif |
| 8423 | # if defined(FEAT_GUI) && defined(UNIX) |
| 8424 | || |
| 8425 | # endif |
| 8426 | # ifdef UNIX |
| 8427 | term_is_xterm |
| 8428 | # endif |
| 8429 | ) |
| 8430 | { |
| 8431 | if (ScreenLines[off] != ' ' |
| 8432 | && (ScreenAttrs[off] > HL_ALL |
| 8433 | || ScreenAttrs[off] & HL_BOLD)) |
| 8434 | force_next = TRUE; |
| 8435 | else |
| 8436 | force_next = FALSE; |
| 8437 | } |
| 8438 | #endif |
| 8439 | ScreenLines[off] = c; |
| 8440 | #ifdef FEAT_MBYTE |
| 8441 | if (enc_utf8) |
| 8442 | { |
| 8443 | if (c >= 0x80) |
| 8444 | { |
| 8445 | ScreenLinesUC[off] = c; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8446 | ScreenLinesC[0][off] = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8447 | } |
| 8448 | else |
| 8449 | ScreenLinesUC[off] = 0; |
| 8450 | } |
| 8451 | #endif |
| 8452 | ScreenAttrs[off] = attr; |
| 8453 | if (!did_delete || c != ' ') |
| 8454 | screen_char(off, row, col); |
| 8455 | } |
| 8456 | ++off; |
| 8457 | if (col == start_col) |
| 8458 | { |
| 8459 | if (did_delete) |
| 8460 | break; |
| 8461 | c = c2; |
| 8462 | } |
| 8463 | } |
| 8464 | if (end_col == Columns) |
| 8465 | LineWraps[row] = FALSE; |
| 8466 | if (row == Rows - 1) /* overwritten the command line */ |
| 8467 | { |
| 8468 | redraw_cmdline = TRUE; |
| 8469 | if (c1 == ' ' && c2 == ' ') |
| 8470 | clear_cmdline = FALSE; /* command line has been cleared */ |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8471 | if (start_col == 0) |
| 8472 | mode_displayed = FALSE; /* mode cleared or overwritten */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8473 | } |
| 8474 | } |
| 8475 | } |
| 8476 | |
| 8477 | /* |
| 8478 | * Check if there should be a delay. Used before clearing or redrawing the |
| 8479 | * screen or the command line. |
| 8480 | */ |
| 8481 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8482 | check_for_delay(int check_msg_scroll) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8483 | { |
| 8484 | if ((emsg_on_display || (check_msg_scroll && msg_scroll)) |
| 8485 | && !did_wait_return |
| 8486 | && emsg_silent == 0) |
| 8487 | { |
| 8488 | out_flush(); |
| 8489 | ui_delay(1000L, TRUE); |
| 8490 | emsg_on_display = FALSE; |
| 8491 | if (check_msg_scroll) |
| 8492 | msg_scroll = FALSE; |
| 8493 | } |
| 8494 | } |
| 8495 | |
| 8496 | /* |
| 8497 | * screen_valid - allocate screen buffers if size changed |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8498 | * If "doclear" is TRUE: clear screen if it has been resized. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8499 | * Returns TRUE if there is a valid screen to write to. |
| 8500 | * Returns FALSE when starting up and screen not initialized yet. |
| 8501 | */ |
| 8502 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8503 | screen_valid(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8504 | { |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8505 | screenalloc(doclear); /* allocate screen buffers if size changed */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8506 | return (ScreenLines != NULL); |
| 8507 | } |
| 8508 | |
| 8509 | /* |
| 8510 | * Resize the shell to Rows and Columns. |
| 8511 | * Allocate ScreenLines[] and associated items. |
| 8512 | * |
| 8513 | * There may be some time between setting Rows and Columns and (re)allocating |
| 8514 | * ScreenLines[]. This happens when starting up and when (manually) changing |
| 8515 | * the shell size. Always use screen_Rows and screen_Columns to access items |
| 8516 | * in ScreenLines[]. Use Rows and Columns for positioning text etc. where the |
| 8517 | * final size of the shell is needed. |
| 8518 | */ |
| 8519 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8520 | screenalloc(int doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8521 | { |
| 8522 | int new_row, old_row; |
| 8523 | #ifdef FEAT_GUI |
| 8524 | int old_Rows; |
| 8525 | #endif |
| 8526 | win_T *wp; |
| 8527 | int outofmem = FALSE; |
| 8528 | int len; |
| 8529 | schar_T *new_ScreenLines; |
| 8530 | #ifdef FEAT_MBYTE |
| 8531 | u8char_T *new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8532 | u8char_T *new_ScreenLinesC[MAX_MCO]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8533 | schar_T *new_ScreenLines2 = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8534 | int i; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8535 | #endif |
| 8536 | sattr_T *new_ScreenAttrs; |
| 8537 | unsigned *new_LineOffset; |
| 8538 | char_u *new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8539 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8540 | short *new_TabPageIdxs; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8541 | tabpage_T *tp; |
| 8542 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8543 | static int entered = FALSE; /* avoid recursiveness */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8544 | static int done_outofmem_msg = FALSE; /* did outofmem message */ |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8545 | #ifdef FEAT_AUTOCMD |
| 8546 | int retry_count = 0; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8547 | |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8548 | retry: |
| 8549 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8550 | /* |
| 8551 | * Allocation of the screen buffers is done only when the size changes and |
| 8552 | * when Rows and Columns have been set and we have started doing full |
| 8553 | * screen stuff. |
| 8554 | */ |
| 8555 | if ((ScreenLines != NULL |
| 8556 | && Rows == screen_Rows |
| 8557 | && Columns == screen_Columns |
| 8558 | #ifdef FEAT_MBYTE |
| 8559 | && enc_utf8 == (ScreenLinesUC != NULL) |
| 8560 | && (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL) |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8561 | && p_mco == Screen_mco |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8562 | #endif |
| 8563 | ) |
| 8564 | || Rows == 0 |
| 8565 | || Columns == 0 |
| 8566 | || (!full_screen && ScreenLines == NULL)) |
| 8567 | return; |
| 8568 | |
| 8569 | /* |
| 8570 | * It's possible that we produce an out-of-memory message below, which |
| 8571 | * will cause this function to be called again. To break the loop, just |
| 8572 | * return here. |
| 8573 | */ |
| 8574 | if (entered) |
| 8575 | return; |
| 8576 | entered = TRUE; |
| 8577 | |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8578 | /* |
| 8579 | * Note that the window sizes are updated before reallocating the arrays, |
| 8580 | * thus we must not redraw here! |
| 8581 | */ |
| 8582 | ++RedrawingDisabled; |
| 8583 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8584 | win_new_shellsize(); /* fit the windows in the new sized shell */ |
| 8585 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8586 | comp_col(); /* recompute columns for shown command and ruler */ |
| 8587 | |
| 8588 | /* |
| 8589 | * We're changing the size of the screen. |
| 8590 | * - Allocate new arrays for ScreenLines and ScreenAttrs. |
| 8591 | * - Move lines from the old arrays into the new arrays, clear extra |
| 8592 | * lines (unless the screen is going to be cleared). |
| 8593 | * - Free the old arrays. |
| 8594 | * |
| 8595 | * If anything fails, make ScreenLines NULL, so we don't do anything! |
| 8596 | * Continuing with the old ScreenLines may result in a crash, because the |
| 8597 | * size is wrong. |
| 8598 | */ |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8599 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8600 | win_free_lsize(wp); |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8601 | #ifdef FEAT_AUTOCMD |
| 8602 | if (aucmd_win != NULL) |
| 8603 | win_free_lsize(aucmd_win); |
| 8604 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8605 | |
| 8606 | new_ScreenLines = (schar_T *)lalloc((long_u)( |
| 8607 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8608 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 216b710 | 2010-03-23 13:56:59 +0100 | [diff] [blame] | 8609 | vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8610 | if (enc_utf8) |
| 8611 | { |
| 8612 | new_ScreenLinesUC = (u8char_T *)lalloc((long_u)( |
| 8613 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8614 | for (i = 0; i < p_mco; ++i) |
Bram Moolenaar | 70c49c1 | 2010-03-23 15:36:35 +0100 | [diff] [blame] | 8615 | new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)( |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8616 | (Rows + 1) * Columns * sizeof(u8char_T)), FALSE); |
| 8617 | } |
| 8618 | if (enc_dbcs == DBCS_JPNU) |
| 8619 | new_ScreenLines2 = (schar_T *)lalloc((long_u)( |
| 8620 | (Rows + 1) * Columns * sizeof(schar_T)), FALSE); |
| 8621 | #endif |
| 8622 | new_ScreenAttrs = (sattr_T *)lalloc((long_u)( |
| 8623 | (Rows + 1) * Columns * sizeof(sattr_T)), FALSE); |
| 8624 | new_LineOffset = (unsigned *)lalloc((long_u)( |
| 8625 | Rows * sizeof(unsigned)), FALSE); |
| 8626 | new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8627 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 8628 | new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8629 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8630 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 8631 | FOR_ALL_TAB_WINDOWS(tp, wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8632 | { |
| 8633 | if (win_alloc_lines(wp) == FAIL) |
| 8634 | { |
| 8635 | outofmem = TRUE; |
| 8636 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8637 | goto give_up; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8638 | #endif |
| 8639 | } |
| 8640 | } |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8641 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 5e9b454 | 2009-07-29 14:24:36 +0000 | [diff] [blame] | 8642 | if (aucmd_win != NULL && aucmd_win->w_lines == NULL |
| 8643 | && win_alloc_lines(aucmd_win) == FAIL) |
Bram Moolenaar | 746ebd3 | 2009-06-16 14:01:43 +0000 | [diff] [blame] | 8644 | outofmem = TRUE; |
| 8645 | #endif |
Bram Moolenaar | bb9c7d1 | 2009-02-21 23:03:09 +0000 | [diff] [blame] | 8646 | #ifdef FEAT_WINDOWS |
| 8647 | give_up: |
| 8648 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8649 | |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8650 | #ifdef FEAT_MBYTE |
| 8651 | for (i = 0; i < p_mco; ++i) |
| 8652 | if (new_ScreenLinesC[i] == NULL) |
| 8653 | break; |
| 8654 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8655 | if (new_ScreenLines == NULL |
| 8656 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8657 | || (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8658 | || (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL) |
| 8659 | #endif |
| 8660 | || new_ScreenAttrs == NULL |
| 8661 | || new_LineOffset == NULL |
| 8662 | || new_LineWraps == NULL |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8663 | #ifdef FEAT_WINDOWS |
| 8664 | || new_TabPageIdxs == NULL |
| 8665 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8666 | || outofmem) |
| 8667 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8668 | if (ScreenLines != NULL || !done_outofmem_msg) |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8669 | { |
| 8670 | /* guess the size */ |
| 8671 | do_outofmem_msg((long_u)((Rows + 1) * Columns)); |
| 8672 | |
| 8673 | /* Remember we did this to avoid getting outofmem messages over |
| 8674 | * and over again. */ |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8675 | done_outofmem_msg = TRUE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8676 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8677 | vim_free(new_ScreenLines); |
| 8678 | new_ScreenLines = NULL; |
| 8679 | #ifdef FEAT_MBYTE |
| 8680 | vim_free(new_ScreenLinesUC); |
| 8681 | new_ScreenLinesUC = NULL; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8682 | for (i = 0; i < p_mco; ++i) |
| 8683 | { |
| 8684 | vim_free(new_ScreenLinesC[i]); |
| 8685 | new_ScreenLinesC[i] = NULL; |
| 8686 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8687 | vim_free(new_ScreenLines2); |
| 8688 | new_ScreenLines2 = NULL; |
| 8689 | #endif |
| 8690 | vim_free(new_ScreenAttrs); |
| 8691 | new_ScreenAttrs = NULL; |
| 8692 | vim_free(new_LineOffset); |
| 8693 | new_LineOffset = NULL; |
| 8694 | vim_free(new_LineWraps); |
| 8695 | new_LineWraps = NULL; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8696 | #ifdef FEAT_WINDOWS |
| 8697 | vim_free(new_TabPageIdxs); |
| 8698 | new_TabPageIdxs = NULL; |
| 8699 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8700 | } |
| 8701 | else |
| 8702 | { |
Bram Moolenaar | 89d4032 | 2006-08-29 15:30:07 +0000 | [diff] [blame] | 8703 | done_outofmem_msg = FALSE; |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8704 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8705 | for (new_row = 0; new_row < Rows; ++new_row) |
| 8706 | { |
| 8707 | new_LineOffset[new_row] = new_row * Columns; |
| 8708 | new_LineWraps[new_row] = FALSE; |
| 8709 | |
| 8710 | /* |
| 8711 | * If the screen is not going to be cleared, copy as much as |
| 8712 | * possible from the old screen to the new one and clear the rest |
| 8713 | * (used when resizing the window at the "--more--" prompt or when |
| 8714 | * executing an external command, for the GUI). |
| 8715 | */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8716 | if (!doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8717 | { |
| 8718 | (void)vim_memset(new_ScreenLines + new_row * Columns, |
| 8719 | ' ', (size_t)Columns * sizeof(schar_T)); |
| 8720 | #ifdef FEAT_MBYTE |
| 8721 | if (enc_utf8) |
| 8722 | { |
| 8723 | (void)vim_memset(new_ScreenLinesUC + new_row * Columns, |
| 8724 | 0, (size_t)Columns * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8725 | for (i = 0; i < p_mco; ++i) |
| 8726 | (void)vim_memset(new_ScreenLinesC[i] |
| 8727 | + new_row * Columns, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8728 | 0, (size_t)Columns * sizeof(u8char_T)); |
| 8729 | } |
| 8730 | if (enc_dbcs == DBCS_JPNU) |
| 8731 | (void)vim_memset(new_ScreenLines2 + new_row * Columns, |
| 8732 | 0, (size_t)Columns * sizeof(schar_T)); |
| 8733 | #endif |
| 8734 | (void)vim_memset(new_ScreenAttrs + new_row * Columns, |
| 8735 | 0, (size_t)Columns * sizeof(sattr_T)); |
| 8736 | old_row = new_row + (screen_Rows - Rows); |
Bram Moolenaar | 482aaeb | 2005-09-29 18:26:07 +0000 | [diff] [blame] | 8737 | if (old_row >= 0 && ScreenLines != NULL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8738 | { |
| 8739 | if (screen_Columns < Columns) |
| 8740 | len = screen_Columns; |
| 8741 | else |
| 8742 | len = Columns; |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8743 | #ifdef FEAT_MBYTE |
Bram Moolenaar | f4d1145 | 2005-12-02 00:46:37 +0000 | [diff] [blame] | 8744 | /* When switching to utf-8 don't copy characters, they |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8745 | * may be invalid now. Also when p_mco changes. */ |
| 8746 | if (!(enc_utf8 && ScreenLinesUC == NULL) |
| 8747 | && p_mco == Screen_mco) |
Bram Moolenaar | 3fdfa4a | 2004-10-07 21:02:47 +0000 | [diff] [blame] | 8748 | #endif |
| 8749 | mch_memmove(new_ScreenLines + new_LineOffset[new_row], |
| 8750 | ScreenLines + LineOffset[old_row], |
| 8751 | (size_t)len * sizeof(schar_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8752 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8753 | if (enc_utf8 && ScreenLinesUC != NULL |
| 8754 | && p_mco == Screen_mco) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8755 | { |
| 8756 | mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row], |
| 8757 | ScreenLinesUC + LineOffset[old_row], |
| 8758 | (size_t)len * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8759 | for (i = 0; i < p_mco; ++i) |
| 8760 | mch_memmove(new_ScreenLinesC[i] |
| 8761 | + new_LineOffset[new_row], |
| 8762 | ScreenLinesC[i] + LineOffset[old_row], |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8763 | (size_t)len * sizeof(u8char_T)); |
| 8764 | } |
| 8765 | if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL) |
| 8766 | mch_memmove(new_ScreenLines2 + new_LineOffset[new_row], |
| 8767 | ScreenLines2 + LineOffset[old_row], |
| 8768 | (size_t)len * sizeof(schar_T)); |
| 8769 | #endif |
| 8770 | mch_memmove(new_ScreenAttrs + new_LineOffset[new_row], |
| 8771 | ScreenAttrs + LineOffset[old_row], |
| 8772 | (size_t)len * sizeof(sattr_T)); |
| 8773 | } |
| 8774 | } |
| 8775 | } |
| 8776 | /* Use the last line of the screen for the current line. */ |
| 8777 | current_ScreenLine = new_ScreenLines + Rows * Columns; |
| 8778 | } |
| 8779 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8780 | free_screenlines(); |
| 8781 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8782 | ScreenLines = new_ScreenLines; |
| 8783 | #ifdef FEAT_MBYTE |
| 8784 | ScreenLinesUC = new_ScreenLinesUC; |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8785 | for (i = 0; i < p_mco; ++i) |
| 8786 | ScreenLinesC[i] = new_ScreenLinesC[i]; |
| 8787 | Screen_mco = p_mco; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8788 | ScreenLines2 = new_ScreenLines2; |
| 8789 | #endif |
| 8790 | ScreenAttrs = new_ScreenAttrs; |
| 8791 | LineOffset = new_LineOffset; |
| 8792 | LineWraps = new_LineWraps; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8793 | #ifdef FEAT_WINDOWS |
| 8794 | TabPageIdxs = new_TabPageIdxs; |
| 8795 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8796 | |
| 8797 | /* It's important that screen_Rows and screen_Columns reflect the actual |
| 8798 | * size of ScreenLines[]. Set them before calling anything. */ |
| 8799 | #ifdef FEAT_GUI |
| 8800 | old_Rows = screen_Rows; |
| 8801 | #endif |
| 8802 | screen_Rows = Rows; |
| 8803 | screen_Columns = Columns; |
| 8804 | |
| 8805 | must_redraw = CLEAR; /* need to clear the screen later */ |
Bram Moolenaar | 70b2a56 | 2012-01-10 22:26:17 +0100 | [diff] [blame] | 8806 | if (doclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8807 | screenclear2(); |
| 8808 | |
| 8809 | #ifdef FEAT_GUI |
| 8810 | else if (gui.in_use |
| 8811 | && !gui.starting |
| 8812 | && ScreenLines != NULL |
| 8813 | && old_Rows != Rows) |
| 8814 | { |
| 8815 | (void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0); |
| 8816 | /* |
| 8817 | * Adjust the position of the cursor, for when executing an external |
| 8818 | * command. |
| 8819 | */ |
| 8820 | if (msg_row >= Rows) /* Rows got smaller */ |
| 8821 | msg_row = Rows - 1; /* put cursor at last row */ |
| 8822 | else if (Rows > old_Rows) /* Rows got bigger */ |
| 8823 | msg_row += Rows - old_Rows; /* put cursor in same place */ |
| 8824 | if (msg_col >= Columns) /* Columns got smaller */ |
| 8825 | msg_col = Columns - 1; /* put cursor at last column */ |
| 8826 | } |
| 8827 | #endif |
| 8828 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8829 | entered = FALSE; |
Bram Moolenaar | a3f2ecd | 2006-07-11 21:01:01 +0000 | [diff] [blame] | 8830 | --RedrawingDisabled; |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8831 | |
| 8832 | #ifdef FEAT_AUTOCMD |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8833 | /* |
| 8834 | * Do not apply autocommands more than 3 times to avoid an endless loop |
| 8835 | * in case applying autocommands always changes Rows or Columns. |
| 8836 | */ |
| 8837 | if (starting == 0 && ++retry_count <= 3) |
| 8838 | { |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8839 | apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf); |
Bram Moolenaar | 87e817c | 2009-02-22 20:13:39 +0000 | [diff] [blame] | 8840 | /* In rare cases, autocommands may have altered Rows or Columns, |
| 8841 | * jump back to check if we need to allocate the screen again. */ |
| 8842 | goto retry; |
| 8843 | } |
Bram Moolenaar | 7d47b6e | 2006-03-15 22:59:18 +0000 | [diff] [blame] | 8844 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8845 | } |
| 8846 | |
| 8847 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8848 | free_screenlines(void) |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8849 | { |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8850 | #ifdef FEAT_MBYTE |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8851 | int i; |
| 8852 | |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8853 | vim_free(ScreenLinesUC); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8854 | for (i = 0; i < Screen_mco; ++i) |
| 8855 | vim_free(ScreenLinesC[i]); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8856 | vim_free(ScreenLines2); |
| 8857 | #endif |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8858 | vim_free(ScreenLines); |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8859 | vim_free(ScreenAttrs); |
| 8860 | vim_free(LineOffset); |
| 8861 | vim_free(LineWraps); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 8862 | #ifdef FEAT_WINDOWS |
| 8863 | vim_free(TabPageIdxs); |
| 8864 | #endif |
Bram Moolenaar | 1ec484f | 2005-06-24 23:07:47 +0000 | [diff] [blame] | 8865 | } |
| 8866 | |
| 8867 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8868 | screenclear(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8869 | { |
| 8870 | check_for_delay(FALSE); |
| 8871 | screenalloc(FALSE); /* allocate screen buffers if size changed */ |
| 8872 | screenclear2(); /* clear the screen */ |
| 8873 | } |
| 8874 | |
| 8875 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8876 | screenclear2(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8877 | { |
| 8878 | int i; |
| 8879 | |
| 8880 | if (starting == NO_SCREEN || ScreenLines == NULL |
| 8881 | #ifdef FEAT_GUI |
| 8882 | || (gui.in_use && gui.starting) |
| 8883 | #endif |
| 8884 | ) |
| 8885 | return; |
| 8886 | |
| 8887 | #ifdef FEAT_GUI |
| 8888 | if (!gui.in_use) |
| 8889 | #endif |
| 8890 | screen_attr = -1; /* force setting the Normal colors */ |
| 8891 | screen_stop_highlight(); /* don't want highlighting here */ |
| 8892 | |
| 8893 | #ifdef FEAT_CLIPBOARD |
| 8894 | /* disable selection without redrawing it */ |
| 8895 | clip_scroll_selection(9999); |
| 8896 | #endif |
| 8897 | |
| 8898 | /* blank out ScreenLines */ |
| 8899 | for (i = 0; i < Rows; ++i) |
| 8900 | { |
| 8901 | lineclear(LineOffset[i], (int)Columns); |
| 8902 | LineWraps[i] = FALSE; |
| 8903 | } |
| 8904 | |
| 8905 | if (can_clear(T_CL)) |
| 8906 | { |
| 8907 | out_str(T_CL); /* clear the display */ |
| 8908 | clear_cmdline = FALSE; |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 8909 | mode_displayed = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8910 | } |
| 8911 | else |
| 8912 | { |
| 8913 | /* can't clear the screen, mark all chars with invalid attributes */ |
| 8914 | for (i = 0; i < Rows; ++i) |
| 8915 | lineinvalid(LineOffset[i], (int)Columns); |
| 8916 | clear_cmdline = TRUE; |
| 8917 | } |
| 8918 | |
| 8919 | screen_cleared = TRUE; /* can use contents of ScreenLines now */ |
| 8920 | |
| 8921 | win_rest_invalid(firstwin); |
| 8922 | redraw_cmdline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8923 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 8924 | redraw_tabline = TRUE; |
Bram Moolenaar | 4c7ed46 | 2006-02-15 22:18:42 +0000 | [diff] [blame] | 8925 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8926 | if (must_redraw == CLEAR) /* no need to clear again */ |
| 8927 | must_redraw = NOT_VALID; |
| 8928 | compute_cmdrow(); |
| 8929 | msg_row = cmdline_row; /* put cursor on last line for messages */ |
| 8930 | msg_col = 0; |
| 8931 | screen_start(); /* don't know where cursor is now */ |
| 8932 | msg_scrolled = 0; /* can't scroll back */ |
| 8933 | msg_didany = FALSE; |
| 8934 | msg_didout = FALSE; |
| 8935 | } |
| 8936 | |
| 8937 | /* |
| 8938 | * Clear one line in ScreenLines. |
| 8939 | */ |
| 8940 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8941 | lineclear(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8942 | { |
| 8943 | (void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T)); |
| 8944 | #ifdef FEAT_MBYTE |
| 8945 | if (enc_utf8) |
| 8946 | (void)vim_memset(ScreenLinesUC + off, 0, |
| 8947 | (size_t)width * sizeof(u8char_T)); |
| 8948 | #endif |
| 8949 | (void)vim_memset(ScreenAttrs + off, 0, (size_t)width * sizeof(sattr_T)); |
| 8950 | } |
| 8951 | |
| 8952 | /* |
| 8953 | * Mark one line in ScreenLines invalid by setting the attributes to an |
| 8954 | * invalid value. |
| 8955 | */ |
| 8956 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8957 | lineinvalid(unsigned off, int width) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8958 | { |
| 8959 | (void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T)); |
| 8960 | } |
| 8961 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 8962 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8963 | /* |
| 8964 | * Copy part of a Screenline for vertically split window "wp". |
| 8965 | */ |
| 8966 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8967 | linecopy(int to, int from, win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8968 | { |
| 8969 | unsigned off_to = LineOffset[to] + wp->w_wincol; |
| 8970 | unsigned off_from = LineOffset[from] + wp->w_wincol; |
| 8971 | |
| 8972 | mch_memmove(ScreenLines + off_to, ScreenLines + off_from, |
| 8973 | wp->w_width * sizeof(schar_T)); |
| 8974 | # ifdef FEAT_MBYTE |
| 8975 | if (enc_utf8) |
| 8976 | { |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8977 | int i; |
| 8978 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8979 | mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from, |
| 8980 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 362e1a3 | 2006-03-06 23:29:24 +0000 | [diff] [blame] | 8981 | for (i = 0; i < p_mco; ++i) |
| 8982 | mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from, |
| 8983 | wp->w_width * sizeof(u8char_T)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 8984 | } |
| 8985 | if (enc_dbcs == DBCS_JPNU) |
| 8986 | mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from, |
| 8987 | wp->w_width * sizeof(schar_T)); |
| 8988 | # endif |
| 8989 | mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from, |
| 8990 | wp->w_width * sizeof(sattr_T)); |
| 8991 | } |
| 8992 | #endif |
| 8993 | |
| 8994 | /* |
| 8995 | * Return TRUE if clearing with term string "p" would work. |
| 8996 | * It can't work when the string is empty or it won't set the right background. |
| 8997 | */ |
| 8998 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 8999 | can_clear(char_u *p) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9000 | { |
| 9001 | return (*p != NUL && (t_colors <= 1 |
| 9002 | #ifdef FEAT_GUI |
| 9003 | || gui.in_use |
| 9004 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 9005 | #ifdef FEAT_TERMGUICOLORS |
Bram Moolenaar | 1b58cdd | 2016-08-22 23:04:33 +0200 | [diff] [blame] | 9006 | || (p_tgc && cterm_normal_bg_gui_color == INVALCOLOR) |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 9007 | || (!p_tgc && cterm_normal_bg_color == 0) |
| 9008 | #else |
| 9009 | || cterm_normal_bg_color == 0 |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 9010 | #endif |
Bram Moolenaar | d18f672 | 2016-06-17 13:18:49 +0200 | [diff] [blame] | 9011 | || *T_UT != NUL)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9012 | } |
| 9013 | |
| 9014 | /* |
| 9015 | * Reset cursor position. Use whenever cursor was moved because of outputting |
| 9016 | * something directly to the screen (shell commands) or a terminal control |
| 9017 | * code. |
| 9018 | */ |
| 9019 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9020 | screen_start(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9021 | { |
| 9022 | screen_cur_row = screen_cur_col = 9999; |
| 9023 | } |
| 9024 | |
| 9025 | /* |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9026 | * Move the cursor to position "row","col" in the screen. |
| 9027 | * This tries to find the most efficient way to move, minimizing the number of |
| 9028 | * characters sent to the terminal. |
| 9029 | */ |
| 9030 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9031 | windgoto(int row, int col) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9032 | { |
Bram Moolenaar | e2cc970 | 2005-03-15 22:43:58 +0000 | [diff] [blame] | 9033 | sattr_T *p; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9034 | int i; |
| 9035 | int plan; |
| 9036 | int cost; |
| 9037 | int wouldbe_col; |
| 9038 | int noinvcurs; |
| 9039 | char_u *bs; |
| 9040 | int goto_cost; |
| 9041 | int attr; |
| 9042 | |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9043 | #define GOTO_COST 7 /* assume a term_windgoto() takes about 7 chars */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9044 | #define HIGHL_COST 5 /* assume unhighlight takes 5 chars */ |
| 9045 | |
| 9046 | #define PLAN_LE 1 |
| 9047 | #define PLAN_CR 2 |
| 9048 | #define PLAN_NL 3 |
| 9049 | #define PLAN_WRITE 4 |
| 9050 | /* Can't use ScreenLines unless initialized */ |
| 9051 | if (ScreenLines == NULL) |
| 9052 | return; |
| 9053 | |
| 9054 | if (col != screen_cur_col || row != screen_cur_row) |
| 9055 | { |
| 9056 | /* Check for valid position. */ |
| 9057 | if (row < 0) /* window without text lines? */ |
| 9058 | row = 0; |
| 9059 | if (row >= screen_Rows) |
| 9060 | row = screen_Rows - 1; |
| 9061 | if (col >= screen_Columns) |
| 9062 | col = screen_Columns - 1; |
| 9063 | |
| 9064 | /* check if no cursor movement is allowed in highlight mode */ |
| 9065 | if (screen_attr && *T_MS == NUL) |
| 9066 | noinvcurs = HIGHL_COST; |
| 9067 | else |
| 9068 | noinvcurs = 0; |
| 9069 | goto_cost = GOTO_COST + noinvcurs; |
| 9070 | |
| 9071 | /* |
| 9072 | * Plan how to do the positioning: |
| 9073 | * 1. Use CR to move it to column 0, same row. |
| 9074 | * 2. Use T_LE to move it a few columns to the left. |
| 9075 | * 3. Use NL to move a few lines down, column 0. |
| 9076 | * 4. Move a few columns to the right with T_ND or by writing chars. |
| 9077 | * |
| 9078 | * Don't do this if the cursor went beyond the last column, the cursor |
| 9079 | * position is unknown then (some terminals wrap, some don't ) |
| 9080 | * |
Bram Moolenaar | 2c7a763 | 2007-05-10 18:19:11 +0000 | [diff] [blame] | 9081 | * First check if the highlighting attributes allow us to write |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9082 | * characters to move the cursor to the right. |
| 9083 | */ |
| 9084 | if (row >= screen_cur_row && screen_cur_col < Columns) |
| 9085 | { |
| 9086 | /* |
| 9087 | * If the cursor is in the same row, bigger col, we can use CR |
| 9088 | * or T_LE. |
| 9089 | */ |
| 9090 | bs = NULL; /* init for GCC */ |
| 9091 | attr = screen_attr; |
| 9092 | if (row == screen_cur_row && col < screen_cur_col) |
| 9093 | { |
| 9094 | /* "le" is preferred over "bc", because "bc" is obsolete */ |
| 9095 | if (*T_LE) |
| 9096 | bs = T_LE; /* "cursor left" */ |
| 9097 | else |
| 9098 | bs = T_BC; /* "backspace character (old) */ |
| 9099 | if (*bs) |
| 9100 | cost = (screen_cur_col - col) * (int)STRLEN(bs); |
| 9101 | else |
| 9102 | cost = 999; |
| 9103 | if (col + 1 < cost) /* using CR is less characters */ |
| 9104 | { |
| 9105 | plan = PLAN_CR; |
| 9106 | wouldbe_col = 0; |
| 9107 | cost = 1; /* CR is just one character */ |
| 9108 | } |
| 9109 | else |
| 9110 | { |
| 9111 | plan = PLAN_LE; |
| 9112 | wouldbe_col = col; |
| 9113 | } |
| 9114 | if (noinvcurs) /* will stop highlighting */ |
| 9115 | { |
| 9116 | cost += noinvcurs; |
| 9117 | attr = 0; |
| 9118 | } |
| 9119 | } |
| 9120 | |
| 9121 | /* |
| 9122 | * If the cursor is above where we want to be, we can use CR LF. |
| 9123 | */ |
| 9124 | else if (row > screen_cur_row) |
| 9125 | { |
| 9126 | plan = PLAN_NL; |
| 9127 | wouldbe_col = 0; |
| 9128 | cost = (row - screen_cur_row) * 2; /* CR LF */ |
| 9129 | if (noinvcurs) /* will stop highlighting */ |
| 9130 | { |
| 9131 | cost += noinvcurs; |
| 9132 | attr = 0; |
| 9133 | } |
| 9134 | } |
| 9135 | |
| 9136 | /* |
| 9137 | * If the cursor is in the same row, smaller col, just use write. |
| 9138 | */ |
| 9139 | else |
| 9140 | { |
| 9141 | plan = PLAN_WRITE; |
| 9142 | wouldbe_col = screen_cur_col; |
| 9143 | cost = 0; |
| 9144 | } |
| 9145 | |
| 9146 | /* |
| 9147 | * Check if any characters that need to be written have the |
| 9148 | * correct attributes. Also avoid UTF-8 characters. |
| 9149 | */ |
| 9150 | i = col - wouldbe_col; |
| 9151 | if (i > 0) |
| 9152 | cost += i; |
| 9153 | if (cost < goto_cost && i > 0) |
| 9154 | { |
| 9155 | /* |
| 9156 | * Check if the attributes are correct without additionally |
| 9157 | * stopping highlighting. |
| 9158 | */ |
| 9159 | p = ScreenAttrs + LineOffset[row] + wouldbe_col; |
| 9160 | while (i && *p++ == attr) |
| 9161 | --i; |
| 9162 | if (i != 0) |
| 9163 | { |
| 9164 | /* |
| 9165 | * Try if it works when highlighting is stopped here. |
| 9166 | */ |
| 9167 | if (*--p == 0) |
| 9168 | { |
| 9169 | cost += noinvcurs; |
| 9170 | while (i && *p++ == 0) |
| 9171 | --i; |
| 9172 | } |
| 9173 | if (i != 0) |
| 9174 | cost = 999; /* different attributes, don't do it */ |
| 9175 | } |
| 9176 | #ifdef FEAT_MBYTE |
| 9177 | if (enc_utf8) |
| 9178 | { |
| 9179 | /* Don't use an UTF-8 char for positioning, it's slow. */ |
| 9180 | for (i = wouldbe_col; i < col; ++i) |
| 9181 | if (ScreenLinesUC[LineOffset[row] + i] != 0) |
| 9182 | { |
| 9183 | cost = 999; |
| 9184 | break; |
| 9185 | } |
| 9186 | } |
| 9187 | #endif |
| 9188 | } |
| 9189 | |
| 9190 | /* |
| 9191 | * We can do it without term_windgoto()! |
| 9192 | */ |
| 9193 | if (cost < goto_cost) |
| 9194 | { |
| 9195 | if (plan == PLAN_LE) |
| 9196 | { |
| 9197 | if (noinvcurs) |
| 9198 | screen_stop_highlight(); |
| 9199 | while (screen_cur_col > col) |
| 9200 | { |
| 9201 | out_str(bs); |
| 9202 | --screen_cur_col; |
| 9203 | } |
| 9204 | } |
| 9205 | else if (plan == PLAN_CR) |
| 9206 | { |
| 9207 | if (noinvcurs) |
| 9208 | screen_stop_highlight(); |
| 9209 | out_char('\r'); |
| 9210 | screen_cur_col = 0; |
| 9211 | } |
| 9212 | else if (plan == PLAN_NL) |
| 9213 | { |
| 9214 | if (noinvcurs) |
| 9215 | screen_stop_highlight(); |
| 9216 | while (screen_cur_row < row) |
| 9217 | { |
| 9218 | out_char('\n'); |
| 9219 | ++screen_cur_row; |
| 9220 | } |
| 9221 | screen_cur_col = 0; |
| 9222 | } |
| 9223 | |
| 9224 | i = col - screen_cur_col; |
| 9225 | if (i > 0) |
| 9226 | { |
| 9227 | /* |
| 9228 | * Use cursor-right if it's one character only. Avoids |
| 9229 | * removing a line of pixels from the last bold char, when |
| 9230 | * using the bold trick in the GUI. |
| 9231 | */ |
| 9232 | if (T_ND[0] != NUL && T_ND[1] == NUL) |
| 9233 | { |
| 9234 | while (i-- > 0) |
| 9235 | out_char(*T_ND); |
| 9236 | } |
| 9237 | else |
| 9238 | { |
| 9239 | int off; |
| 9240 | |
| 9241 | off = LineOffset[row] + screen_cur_col; |
| 9242 | while (i-- > 0) |
| 9243 | { |
| 9244 | if (ScreenAttrs[off] != screen_attr) |
| 9245 | screen_stop_highlight(); |
| 9246 | #ifdef FEAT_MBYTE |
| 9247 | out_flush_check(); |
| 9248 | #endif |
| 9249 | out_char(ScreenLines[off]); |
| 9250 | #ifdef FEAT_MBYTE |
| 9251 | if (enc_dbcs == DBCS_JPNU |
| 9252 | && ScreenLines[off] == 0x8e) |
| 9253 | out_char(ScreenLines2[off]); |
| 9254 | #endif |
| 9255 | ++off; |
| 9256 | } |
| 9257 | } |
| 9258 | } |
| 9259 | } |
| 9260 | } |
| 9261 | else |
| 9262 | cost = 999; |
| 9263 | |
| 9264 | if (cost >= goto_cost) |
| 9265 | { |
| 9266 | if (noinvcurs) |
| 9267 | screen_stop_highlight(); |
Bram Moolenaar | 597a422 | 2014-06-25 14:39:50 +0200 | [diff] [blame] | 9268 | if (row == screen_cur_row && (col > screen_cur_col) |
| 9269 | && *T_CRI != NUL) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9270 | term_cursor_right(col - screen_cur_col); |
| 9271 | else |
| 9272 | term_windgoto(row, col); |
| 9273 | } |
| 9274 | screen_cur_row = row; |
| 9275 | screen_cur_col = col; |
| 9276 | } |
| 9277 | } |
| 9278 | |
| 9279 | /* |
| 9280 | * Set cursor to its position in the current window. |
| 9281 | */ |
| 9282 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9283 | setcursor(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9284 | { |
| 9285 | if (redrawing()) |
| 9286 | { |
| 9287 | validate_cursor(); |
| 9288 | windgoto(W_WINROW(curwin) + curwin->w_wrow, |
| 9289 | W_WINCOL(curwin) + ( |
| 9290 | #ifdef FEAT_RIGHTLEFT |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9291 | /* With 'rightleft' set and the cursor on a double-wide |
| 9292 | * character, position it on the leftmost column. */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9293 | curwin->w_p_rl ? ((int)W_WIDTH(curwin) - curwin->w_wcol - ( |
| 9294 | # ifdef FEAT_MBYTE |
Bram Moolenaar | 561f9db | 2008-02-20 13:16:29 +0000 | [diff] [blame] | 9295 | (has_mbyte |
| 9296 | && (*mb_ptr2cells)(ml_get_cursor()) == 2 |
| 9297 | && vim_isprintc(gchar_cursor())) ? 2 : |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9298 | # endif |
| 9299 | 1)) : |
| 9300 | #endif |
| 9301 | curwin->w_wcol)); |
| 9302 | } |
| 9303 | } |
| 9304 | |
| 9305 | |
| 9306 | /* |
| 9307 | * insert 'line_count' lines at 'row' in window 'wp' |
| 9308 | * if 'invalid' is TRUE the wp->w_lines[].wl_lnum is invalidated. |
| 9309 | * if 'mayclear' is TRUE the screen will be cleared if it is faster than |
| 9310 | * scrolling. |
| 9311 | * Returns FAIL if the lines are not inserted, OK for success. |
| 9312 | */ |
| 9313 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9314 | win_ins_lines( |
| 9315 | win_T *wp, |
| 9316 | int row, |
| 9317 | int line_count, |
| 9318 | int invalid, |
| 9319 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9320 | { |
| 9321 | int did_delete; |
| 9322 | int nextrow; |
| 9323 | int lastrow; |
| 9324 | int retval; |
| 9325 | |
| 9326 | if (invalid) |
| 9327 | wp->w_lines_valid = 0; |
| 9328 | |
| 9329 | if (wp->w_height < 5) |
| 9330 | return FAIL; |
| 9331 | |
| 9332 | if (line_count > wp->w_height - row) |
| 9333 | line_count = wp->w_height - row; |
| 9334 | |
| 9335 | retval = win_do_lines(wp, row, line_count, mayclear, FALSE); |
| 9336 | if (retval != MAYBE) |
| 9337 | return retval; |
| 9338 | |
| 9339 | /* |
| 9340 | * If there is a next window or a status line, we first try to delete the |
| 9341 | * lines at the bottom to avoid messing what is after the window. |
| 9342 | * If this fails and there are following windows, don't do anything to avoid |
| 9343 | * messing up those windows, better just redraw. |
| 9344 | */ |
| 9345 | did_delete = FALSE; |
| 9346 | #ifdef FEAT_WINDOWS |
| 9347 | if (wp->w_next != NULL || wp->w_status_height) |
| 9348 | { |
| 9349 | if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9350 | line_count, (int)Rows, FALSE, NULL) == OK) |
| 9351 | did_delete = TRUE; |
| 9352 | else if (wp->w_next) |
| 9353 | return FAIL; |
| 9354 | } |
| 9355 | #endif |
| 9356 | /* |
| 9357 | * if no lines deleted, blank the lines that will end up below the window |
| 9358 | */ |
| 9359 | if (!did_delete) |
| 9360 | { |
| 9361 | #ifdef FEAT_WINDOWS |
| 9362 | wp->w_redr_status = TRUE; |
| 9363 | #endif |
| 9364 | redraw_cmdline = TRUE; |
| 9365 | nextrow = W_WINROW(wp) + wp->w_height + W_STATUS_HEIGHT(wp); |
| 9366 | lastrow = nextrow + line_count; |
| 9367 | if (lastrow > Rows) |
| 9368 | lastrow = Rows; |
| 9369 | screen_fill(nextrow - line_count, lastrow - line_count, |
| 9370 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9371 | ' ', ' ', 0); |
| 9372 | } |
| 9373 | |
| 9374 | if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, NULL) |
| 9375 | == FAIL) |
| 9376 | { |
| 9377 | /* deletion will have messed up other windows */ |
| 9378 | if (did_delete) |
| 9379 | { |
| 9380 | #ifdef FEAT_WINDOWS |
| 9381 | wp->w_redr_status = TRUE; |
| 9382 | #endif |
| 9383 | win_rest_invalid(W_NEXT(wp)); |
| 9384 | } |
| 9385 | return FAIL; |
| 9386 | } |
| 9387 | |
| 9388 | return OK; |
| 9389 | } |
| 9390 | |
| 9391 | /* |
| 9392 | * delete "line_count" window lines at "row" in window "wp" |
| 9393 | * If "invalid" is TRUE curwin->w_lines[] is invalidated. |
| 9394 | * If "mayclear" is TRUE the screen will be cleared if it is faster than |
| 9395 | * scrolling |
| 9396 | * Return OK for success, FAIL if the lines are not deleted. |
| 9397 | */ |
| 9398 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9399 | win_del_lines( |
| 9400 | win_T *wp, |
| 9401 | int row, |
| 9402 | int line_count, |
| 9403 | int invalid, |
| 9404 | int mayclear) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9405 | { |
| 9406 | int retval; |
| 9407 | |
| 9408 | if (invalid) |
| 9409 | wp->w_lines_valid = 0; |
| 9410 | |
| 9411 | if (line_count > wp->w_height - row) |
| 9412 | line_count = wp->w_height - row; |
| 9413 | |
| 9414 | retval = win_do_lines(wp, row, line_count, mayclear, TRUE); |
| 9415 | if (retval != MAYBE) |
| 9416 | return retval; |
| 9417 | |
| 9418 | if (screen_del_lines(0, W_WINROW(wp) + row, line_count, |
| 9419 | (int)Rows, FALSE, NULL) == FAIL) |
| 9420 | return FAIL; |
| 9421 | |
| 9422 | #ifdef FEAT_WINDOWS |
| 9423 | /* |
| 9424 | * If there are windows or status lines below, try to put them at the |
| 9425 | * correct place. If we can't do that, they have to be redrawn. |
| 9426 | */ |
| 9427 | if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1) |
| 9428 | { |
| 9429 | if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count, |
| 9430 | line_count, (int)Rows, NULL) == FAIL) |
| 9431 | { |
| 9432 | wp->w_redr_status = TRUE; |
| 9433 | win_rest_invalid(wp->w_next); |
| 9434 | } |
| 9435 | } |
| 9436 | /* |
| 9437 | * If this is the last window and there is no status line, redraw the |
| 9438 | * command line later. |
| 9439 | */ |
| 9440 | else |
| 9441 | #endif |
| 9442 | redraw_cmdline = TRUE; |
| 9443 | return OK; |
| 9444 | } |
| 9445 | |
| 9446 | /* |
| 9447 | * Common code for win_ins_lines() and win_del_lines(). |
| 9448 | * Returns OK or FAIL when the work has been done. |
| 9449 | * Returns MAYBE when not finished yet. |
| 9450 | */ |
| 9451 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9452 | win_do_lines( |
| 9453 | win_T *wp, |
| 9454 | int row, |
| 9455 | int line_count, |
| 9456 | int mayclear, |
| 9457 | int del) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9458 | { |
| 9459 | int retval; |
| 9460 | |
| 9461 | if (!redrawing() || line_count <= 0) |
| 9462 | return FAIL; |
| 9463 | |
| 9464 | /* only a few lines left: redraw is faster */ |
| 9465 | if (mayclear && Rows - line_count < 5 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9466 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9467 | && wp->w_width == Columns |
| 9468 | #endif |
| 9469 | ) |
| 9470 | { |
| 9471 | screenclear(); /* will set wp->w_lines_valid to 0 */ |
| 9472 | return FAIL; |
| 9473 | } |
| 9474 | |
| 9475 | /* |
| 9476 | * Delete all remaining lines |
| 9477 | */ |
| 9478 | if (row + line_count >= wp->w_height) |
| 9479 | { |
| 9480 | screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height, |
| 9481 | W_WINCOL(wp), (int)W_ENDCOL(wp), |
| 9482 | ' ', ' ', 0); |
| 9483 | return OK; |
| 9484 | } |
| 9485 | |
| 9486 | /* |
| 9487 | * when scrolling, the message on the command line should be cleared, |
| 9488 | * otherwise it will stay there forever. |
| 9489 | */ |
| 9490 | clear_cmdline = TRUE; |
| 9491 | |
| 9492 | /* |
| 9493 | * If the terminal can set a scroll region, use that. |
| 9494 | * Always do this in a vertically split window. This will redraw from |
| 9495 | * ScreenLines[] when t_CV isn't defined. That's faster than using |
| 9496 | * win_line(). |
| 9497 | * Don't use a scroll region when we are going to redraw the text, writing |
Bram Moolenaar | 48e330a | 2016-02-23 14:53:34 +0100 | [diff] [blame] | 9498 | * a character in the lower right corner of the scroll region may cause a |
| 9499 | * scroll-up . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9500 | */ |
| 9501 | if (scroll_region |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9502 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9503 | || W_WIDTH(wp) != Columns |
| 9504 | #endif |
| 9505 | ) |
| 9506 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9507 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9508 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9509 | #endif |
| 9510 | scroll_region_set(wp, row); |
| 9511 | if (del) |
| 9512 | retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count, |
| 9513 | wp->w_height - row, FALSE, wp); |
| 9514 | else |
| 9515 | retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count, |
| 9516 | wp->w_height - row, wp); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9517 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9518 | if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL)) |
| 9519 | #endif |
| 9520 | scroll_region_reset(); |
| 9521 | return retval; |
| 9522 | } |
| 9523 | |
| 9524 | #ifdef FEAT_WINDOWS |
| 9525 | if (wp->w_next != NULL && p_tf) /* don't delete/insert on fast terminal */ |
| 9526 | return FAIL; |
| 9527 | #endif |
| 9528 | |
| 9529 | return MAYBE; |
| 9530 | } |
| 9531 | |
| 9532 | /* |
| 9533 | * window 'wp' and everything after it is messed up, mark it for redraw |
| 9534 | */ |
| 9535 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9536 | win_rest_invalid(win_T *wp) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9537 | { |
| 9538 | #ifdef FEAT_WINDOWS |
| 9539 | while (wp != NULL) |
| 9540 | #else |
| 9541 | if (wp != NULL) |
| 9542 | #endif |
| 9543 | { |
| 9544 | redraw_win_later(wp, NOT_VALID); |
| 9545 | #ifdef FEAT_WINDOWS |
| 9546 | wp->w_redr_status = TRUE; |
| 9547 | wp = wp->w_next; |
| 9548 | #endif |
| 9549 | } |
| 9550 | redraw_cmdline = TRUE; |
| 9551 | } |
| 9552 | |
| 9553 | /* |
| 9554 | * The rest of the routines in this file perform screen manipulations. The |
| 9555 | * given operation is performed physically on the screen. The corresponding |
| 9556 | * change is also made to the internal screen image. In this way, the editor |
| 9557 | * anticipates the effect of editing changes on the appearance of the screen. |
| 9558 | * That way, when we call screenupdate a complete redraw isn't usually |
| 9559 | * necessary. Another advantage is that we can keep adding code to anticipate |
| 9560 | * screen changes, and in the meantime, everything still works. |
| 9561 | */ |
| 9562 | |
| 9563 | /* |
| 9564 | * types for inserting or deleting lines |
| 9565 | */ |
| 9566 | #define USE_T_CAL 1 |
| 9567 | #define USE_T_CDL 2 |
| 9568 | #define USE_T_AL 3 |
| 9569 | #define USE_T_CE 4 |
| 9570 | #define USE_T_DL 5 |
| 9571 | #define USE_T_SR 6 |
| 9572 | #define USE_NL 7 |
| 9573 | #define USE_T_CD 8 |
| 9574 | #define USE_REDRAW 9 |
| 9575 | |
| 9576 | /* |
| 9577 | * insert lines on the screen and update ScreenLines[] |
| 9578 | * 'end' is the line after the scrolled part. Normally it is Rows. |
| 9579 | * When scrolling region used 'off' is the offset from the top for the region. |
| 9580 | * 'row' and 'end' are relative to the start of the region. |
| 9581 | * |
| 9582 | * return FAIL for failure, OK for success. |
| 9583 | */ |
Bram Moolenaar | 87e25fd | 2005-07-27 21:13:01 +0000 | [diff] [blame] | 9584 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9585 | screen_ins_lines( |
| 9586 | int off, |
| 9587 | int row, |
| 9588 | int line_count, |
| 9589 | int end, |
| 9590 | win_T *wp) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9591 | { |
| 9592 | int i; |
| 9593 | int j; |
| 9594 | unsigned temp; |
| 9595 | int cursor_row; |
| 9596 | int type; |
| 9597 | int result_empty; |
| 9598 | int can_ce = can_clear(T_CE); |
| 9599 | |
| 9600 | /* |
| 9601 | * FAIL if |
| 9602 | * - there is no valid screen |
| 9603 | * - the screen has to be redrawn completely |
| 9604 | * - the line count is less than one |
| 9605 | * - the line count is more than 'ttyscroll' |
| 9606 | */ |
| 9607 | if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll) |
| 9608 | return FAIL; |
| 9609 | |
| 9610 | /* |
| 9611 | * There are seven ways to insert lines: |
| 9612 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9613 | * characters from ScreenLines[]. |
| 9614 | * 1. Use T_CD (clear to end of display) if it exists and the result of |
| 9615 | * the insert is just empty lines |
| 9616 | * 2. Use T_CAL (insert multiple lines) if it exists and T_AL is not |
| 9617 | * present or line_count > 1. It looks better if we do all the inserts |
| 9618 | * at once. |
| 9619 | * 3. Use T_CDL (delete multiple lines) if it exists and the result of the |
| 9620 | * insert is just empty lines and T_CE is not present or line_count > |
| 9621 | * 1. |
| 9622 | * 4. Use T_AL (insert line) if it exists. |
| 9623 | * 5. Use T_CE (erase line) if it exists and the result of the insert is |
| 9624 | * just empty lines. |
| 9625 | * 6. Use T_DL (delete line) if it exists and the result of the insert is |
| 9626 | * just empty lines. |
| 9627 | * 7. Use T_SR (scroll reverse) if it exists and inserting at row 0 and |
| 9628 | * the 'da' flag is not set or we have clear line capability. |
| 9629 | * 8. redraw the characters from ScreenLines[]. |
| 9630 | * |
| 9631 | * Careful: In a hpterm scroll reverse doesn't work as expected, it moves |
| 9632 | * the scrollbar for the window. It does have insert line, use that if it |
| 9633 | * exists. |
| 9634 | */ |
| 9635 | result_empty = (row + line_count >= end); |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9636 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9637 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9638 | type = USE_REDRAW; |
| 9639 | else |
| 9640 | #endif |
| 9641 | if (can_clear(T_CD) && result_empty) |
| 9642 | type = USE_T_CD; |
| 9643 | else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL)) |
| 9644 | type = USE_T_CAL; |
| 9645 | else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce)) |
| 9646 | type = USE_T_CDL; |
| 9647 | else if (*T_AL != NUL) |
| 9648 | type = USE_T_AL; |
| 9649 | else if (can_ce && result_empty) |
| 9650 | type = USE_T_CE; |
| 9651 | else if (*T_DL != NUL && result_empty) |
| 9652 | type = USE_T_DL; |
| 9653 | else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce)) |
| 9654 | type = USE_T_SR; |
| 9655 | else |
| 9656 | return FAIL; |
| 9657 | |
| 9658 | /* |
| 9659 | * For clearing the lines screen_del_lines() is used. This will also take |
| 9660 | * care of t_db if necessary. |
| 9661 | */ |
| 9662 | if (type == USE_T_CD || type == USE_T_CDL || |
| 9663 | type == USE_T_CE || type == USE_T_DL) |
| 9664 | return screen_del_lines(off, row, line_count, end, FALSE, wp); |
| 9665 | |
| 9666 | /* |
| 9667 | * If text is retained below the screen, first clear or delete as many |
| 9668 | * lines at the bottom of the window as are about to be inserted so that |
| 9669 | * the deleted lines won't later surface during a screen_del_lines. |
| 9670 | */ |
| 9671 | if (*T_DB) |
| 9672 | screen_del_lines(off, end - line_count, line_count, end, FALSE, wp); |
| 9673 | |
| 9674 | #ifdef FEAT_CLIPBOARD |
| 9675 | /* Remove a modeless selection when inserting lines halfway the screen |
| 9676 | * or not the full width of the screen. */ |
| 9677 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9678 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9679 | || (wp != NULL && wp->w_width != Columns) |
| 9680 | # endif |
| 9681 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9682 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9683 | else |
| 9684 | clip_scroll_selection(-line_count); |
| 9685 | #endif |
| 9686 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9687 | #ifdef FEAT_GUI |
| 9688 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9689 | * scrolling is actually carried out. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9690 | gui_dont_update_cursor(row + off <= gui.cursor_row); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9691 | #endif |
| 9692 | |
| 9693 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9694 | cursor_row = row; |
| 9695 | else |
| 9696 | cursor_row = row + off; |
| 9697 | |
| 9698 | /* |
| 9699 | * Shift LineOffset[] line_count down to reflect the inserted lines. |
| 9700 | * Clear the inserted lines in ScreenLines[]. |
| 9701 | */ |
| 9702 | row += off; |
| 9703 | end += off; |
| 9704 | for (i = 0; i < line_count; ++i) |
| 9705 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9706 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9707 | if (wp != NULL && wp->w_width != Columns) |
| 9708 | { |
| 9709 | /* need to copy part of a line */ |
| 9710 | j = end - 1 - i; |
| 9711 | while ((j -= line_count) >= row) |
| 9712 | linecopy(j + line_count, j, wp); |
| 9713 | j += line_count; |
| 9714 | if (can_clear((char_u *)" ")) |
| 9715 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9716 | else |
| 9717 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9718 | LineWraps[j] = FALSE; |
| 9719 | } |
| 9720 | else |
| 9721 | #endif |
| 9722 | { |
| 9723 | j = end - 1 - i; |
| 9724 | temp = LineOffset[j]; |
| 9725 | while ((j -= line_count) >= row) |
| 9726 | { |
| 9727 | LineOffset[j + line_count] = LineOffset[j]; |
| 9728 | LineWraps[j + line_count] = LineWraps[j]; |
| 9729 | } |
| 9730 | LineOffset[j + line_count] = temp; |
| 9731 | LineWraps[j + line_count] = FALSE; |
| 9732 | if (can_clear((char_u *)" ")) |
| 9733 | lineclear(temp, (int)Columns); |
| 9734 | else |
| 9735 | lineinvalid(temp, (int)Columns); |
| 9736 | } |
| 9737 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9738 | |
| 9739 | screen_stop_highlight(); |
| 9740 | windgoto(cursor_row, 0); |
| 9741 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9742 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9743 | /* redraw the characters */ |
| 9744 | if (type == USE_REDRAW) |
| 9745 | redraw_block(row, end, wp); |
| 9746 | else |
| 9747 | #endif |
| 9748 | if (type == USE_T_CAL) |
| 9749 | { |
| 9750 | term_append_lines(line_count); |
| 9751 | screen_start(); /* don't know where cursor is now */ |
| 9752 | } |
| 9753 | else |
| 9754 | { |
| 9755 | for (i = 0; i < line_count; i++) |
| 9756 | { |
| 9757 | if (type == USE_T_AL) |
| 9758 | { |
| 9759 | if (i && cursor_row != 0) |
| 9760 | windgoto(cursor_row, 0); |
| 9761 | out_str(T_AL); |
| 9762 | } |
| 9763 | else /* type == USE_T_SR */ |
| 9764 | out_str(T_SR); |
| 9765 | screen_start(); /* don't know where cursor is now */ |
| 9766 | } |
| 9767 | } |
| 9768 | |
| 9769 | /* |
| 9770 | * With scroll-reverse and 'da' flag set we need to clear the lines that |
| 9771 | * have been scrolled down into the region. |
| 9772 | */ |
| 9773 | if (type == USE_T_SR && *T_DA) |
| 9774 | { |
| 9775 | for (i = 0; i < line_count; ++i) |
| 9776 | { |
| 9777 | windgoto(off + i, 0); |
| 9778 | out_str(T_CE); |
| 9779 | screen_start(); /* don't know where cursor is now */ |
| 9780 | } |
| 9781 | } |
| 9782 | |
| 9783 | #ifdef FEAT_GUI |
| 9784 | gui_can_update_cursor(); |
| 9785 | if (gui.in_use) |
| 9786 | out_flush(); /* always flush after a scroll */ |
| 9787 | #endif |
| 9788 | return OK; |
| 9789 | } |
| 9790 | |
| 9791 | /* |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9792 | * Delete lines on the screen and update ScreenLines[]. |
| 9793 | * "end" is the line after the scrolled part. Normally it is Rows. |
| 9794 | * When scrolling region used "off" is the offset from the top for the region. |
| 9795 | * "row" and "end" are relative to the start of the region. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9796 | * |
| 9797 | * Return OK for success, FAIL if the lines are not deleted. |
| 9798 | */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9799 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 9800 | screen_del_lines( |
| 9801 | int off, |
| 9802 | int row, |
| 9803 | int line_count, |
| 9804 | int end, |
| 9805 | int force, /* even when line_count > p_ttyscroll */ |
| 9806 | win_T *wp UNUSED) /* NULL or window to use width from */ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9807 | { |
| 9808 | int j; |
| 9809 | int i; |
| 9810 | unsigned temp; |
| 9811 | int cursor_row; |
| 9812 | int cursor_end; |
| 9813 | int result_empty; /* result is empty until end of region */ |
| 9814 | int can_delete; /* deleting line codes can be used */ |
| 9815 | int type; |
| 9816 | |
| 9817 | /* |
| 9818 | * FAIL if |
| 9819 | * - there is no valid screen |
| 9820 | * - the screen has to be redrawn completely |
| 9821 | * - the line count is less than one |
| 9822 | * - the line count is more than 'ttyscroll' |
| 9823 | */ |
| 9824 | if (!screen_valid(TRUE) || line_count <= 0 || |
| 9825 | (!force && line_count > p_ttyscroll)) |
| 9826 | return FAIL; |
| 9827 | |
| 9828 | /* |
| 9829 | * Check if the rest of the current region will become empty. |
| 9830 | */ |
| 9831 | result_empty = row + line_count >= end; |
| 9832 | |
| 9833 | /* |
| 9834 | * We can delete lines only when 'db' flag not set or when 'ce' option |
| 9835 | * available. |
| 9836 | */ |
| 9837 | can_delete = (*T_DB == NUL || can_clear(T_CE)); |
| 9838 | |
| 9839 | /* |
| 9840 | * There are six ways to delete lines: |
| 9841 | * 0. When in a vertically split window and t_CV isn't set, redraw the |
| 9842 | * characters from ScreenLines[]. |
| 9843 | * 1. Use T_CD if it exists and the result is empty. |
| 9844 | * 2. Use newlines if row == 0 and count == 1 or T_CDL does not exist. |
| 9845 | * 3. Use T_CDL (delete multiple lines) if it exists and line_count > 1 or |
| 9846 | * none of the other ways work. |
| 9847 | * 4. Use T_CE (erase line) if the result is empty. |
| 9848 | * 5. Use T_DL (delete line) if it exists. |
| 9849 | * 6. redraw the characters from ScreenLines[]. |
| 9850 | */ |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9851 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9852 | if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL) |
| 9853 | type = USE_REDRAW; |
| 9854 | else |
| 9855 | #endif |
| 9856 | if (can_clear(T_CD) && result_empty) |
| 9857 | type = USE_T_CD; |
| 9858 | #if defined(__BEOS__) && defined(BEOS_DR8) |
| 9859 | /* |
| 9860 | * USE_NL does not seem to work in Terminal of DR8 so we set T_DB="" in |
| 9861 | * its internal termcap... this works okay for tests which test *T_DB != |
| 9862 | * NUL. It has the disadvantage that the user cannot use any :set t_* |
| 9863 | * command to get T_DB (back) to empty_option, only :set term=... will do |
| 9864 | * the trick... |
| 9865 | * Anyway, this hack will hopefully go away with the next OS release. |
| 9866 | * (Olaf Seibert) |
| 9867 | */ |
| 9868 | else if (row == 0 && T_DB == empty_option |
| 9869 | && (line_count == 1 || *T_CDL == NUL)) |
| 9870 | #else |
| 9871 | else if (row == 0 && ( |
| 9872 | #ifndef AMIGA |
| 9873 | /* On the Amiga, somehow '\n' on the last line doesn't always scroll |
| 9874 | * up, so use delete-line command */ |
| 9875 | line_count == 1 || |
| 9876 | #endif |
| 9877 | *T_CDL == NUL)) |
| 9878 | #endif |
| 9879 | type = USE_NL; |
| 9880 | else if (*T_CDL != NUL && line_count > 1 && can_delete) |
| 9881 | type = USE_T_CDL; |
| 9882 | else if (can_clear(T_CE) && result_empty |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9883 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9884 | && (wp == NULL || wp->w_width == Columns) |
| 9885 | #endif |
| 9886 | ) |
| 9887 | type = USE_T_CE; |
| 9888 | else if (*T_DL != NUL && can_delete) |
| 9889 | type = USE_T_DL; |
| 9890 | else if (*T_CDL != NUL && can_delete) |
| 9891 | type = USE_T_CDL; |
| 9892 | else |
| 9893 | return FAIL; |
| 9894 | |
| 9895 | #ifdef FEAT_CLIPBOARD |
| 9896 | /* Remove a modeless selection when deleting lines halfway the screen or |
| 9897 | * not the full width of the screen. */ |
| 9898 | if (off + row > 0 |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9899 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9900 | || (wp != NULL && wp->w_width != Columns) |
| 9901 | # endif |
| 9902 | ) |
Bram Moolenaar | c0885aa | 2012-07-10 16:49:23 +0200 | [diff] [blame] | 9903 | clip_clear_selection(&clip_star); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9904 | else |
| 9905 | clip_scroll_selection(line_count); |
| 9906 | #endif |
| 9907 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9908 | #ifdef FEAT_GUI |
| 9909 | /* Don't update the GUI cursor here, ScreenLines[] is invalid until the |
| 9910 | * scrolling is actually carried out. */ |
Bram Moolenaar | 107abd2 | 2016-08-12 14:08:25 +0200 | [diff] [blame] | 9911 | gui_dont_update_cursor(gui.cursor_row >= row + off |
| 9912 | && gui.cursor_row < end + off); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9913 | #endif |
| 9914 | |
| 9915 | if (*T_CCS != NUL) /* cursor relative to region */ |
| 9916 | { |
| 9917 | cursor_row = row; |
| 9918 | cursor_end = end; |
| 9919 | } |
| 9920 | else |
| 9921 | { |
| 9922 | cursor_row = row + off; |
| 9923 | cursor_end = end + off; |
| 9924 | } |
| 9925 | |
| 9926 | /* |
| 9927 | * Now shift LineOffset[] line_count up to reflect the deleted lines. |
| 9928 | * Clear the inserted lines in ScreenLines[]. |
| 9929 | */ |
| 9930 | row += off; |
| 9931 | end += off; |
| 9932 | for (i = 0; i < line_count; ++i) |
| 9933 | { |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9934 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9935 | if (wp != NULL && wp->w_width != Columns) |
| 9936 | { |
| 9937 | /* need to copy part of a line */ |
| 9938 | j = row + i; |
| 9939 | while ((j += line_count) <= end - 1) |
| 9940 | linecopy(j - line_count, j, wp); |
| 9941 | j -= line_count; |
| 9942 | if (can_clear((char_u *)" ")) |
| 9943 | lineclear(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9944 | else |
| 9945 | lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width); |
| 9946 | LineWraps[j] = FALSE; |
| 9947 | } |
| 9948 | else |
| 9949 | #endif |
| 9950 | { |
| 9951 | /* whole width, moving the line pointers is faster */ |
| 9952 | j = row + i; |
| 9953 | temp = LineOffset[j]; |
| 9954 | while ((j += line_count) <= end - 1) |
| 9955 | { |
| 9956 | LineOffset[j - line_count] = LineOffset[j]; |
| 9957 | LineWraps[j - line_count] = LineWraps[j]; |
| 9958 | } |
| 9959 | LineOffset[j - line_count] = temp; |
| 9960 | LineWraps[j - line_count] = FALSE; |
| 9961 | if (can_clear((char_u *)" ")) |
| 9962 | lineclear(temp, (int)Columns); |
| 9963 | else |
| 9964 | lineinvalid(temp, (int)Columns); |
| 9965 | } |
| 9966 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9967 | |
| 9968 | screen_stop_highlight(); |
| 9969 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 9970 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 9971 | /* redraw the characters */ |
| 9972 | if (type == USE_REDRAW) |
| 9973 | redraw_block(row, end, wp); |
| 9974 | else |
| 9975 | #endif |
| 9976 | if (type == USE_T_CD) /* delete the lines */ |
| 9977 | { |
| 9978 | windgoto(cursor_row, 0); |
| 9979 | out_str(T_CD); |
| 9980 | screen_start(); /* don't know where cursor is now */ |
| 9981 | } |
| 9982 | else if (type == USE_T_CDL) |
| 9983 | { |
| 9984 | windgoto(cursor_row, 0); |
| 9985 | term_delete_lines(line_count); |
| 9986 | screen_start(); /* don't know where cursor is now */ |
| 9987 | } |
| 9988 | /* |
| 9989 | * Deleting lines at top of the screen or scroll region: Just scroll |
| 9990 | * the whole screen (scroll region) up by outputting newlines on the |
| 9991 | * last line. |
| 9992 | */ |
| 9993 | else if (type == USE_NL) |
| 9994 | { |
| 9995 | windgoto(cursor_end - 1, 0); |
| 9996 | for (i = line_count; --i >= 0; ) |
| 9997 | out_char('\n'); /* cursor will remain on same line */ |
| 9998 | } |
| 9999 | else |
| 10000 | { |
| 10001 | for (i = line_count; --i >= 0; ) |
| 10002 | { |
| 10003 | if (type == USE_T_DL) |
| 10004 | { |
| 10005 | windgoto(cursor_row, 0); |
| 10006 | out_str(T_DL); /* delete a line */ |
| 10007 | } |
| 10008 | else /* type == USE_T_CE */ |
| 10009 | { |
| 10010 | windgoto(cursor_row + i, 0); |
| 10011 | out_str(T_CE); /* erase a line */ |
| 10012 | } |
| 10013 | screen_start(); /* don't know where cursor is now */ |
| 10014 | } |
| 10015 | } |
| 10016 | |
| 10017 | /* |
| 10018 | * If the 'db' flag is set, we need to clear the lines that have been |
| 10019 | * scrolled up at the bottom of the region. |
| 10020 | */ |
| 10021 | if (*T_DB && (type == USE_T_DL || type == USE_T_CDL)) |
| 10022 | { |
| 10023 | for (i = line_count; i > 0; --i) |
| 10024 | { |
| 10025 | windgoto(cursor_end - i, 0); |
| 10026 | out_str(T_CE); /* erase a line */ |
| 10027 | screen_start(); /* don't know where cursor is now */ |
| 10028 | } |
| 10029 | } |
| 10030 | |
| 10031 | #ifdef FEAT_GUI |
| 10032 | gui_can_update_cursor(); |
| 10033 | if (gui.in_use) |
| 10034 | out_flush(); /* always flush after a scroll */ |
| 10035 | #endif |
| 10036 | |
| 10037 | return OK; |
| 10038 | } |
| 10039 | |
| 10040 | /* |
| 10041 | * show the current mode and ruler |
| 10042 | * |
| 10043 | * If clear_cmdline is TRUE, clear the rest of the cmdline. |
| 10044 | * If clear_cmdline is FALSE there may be a message there that needs to be |
| 10045 | * cleared only if a mode is shown. |
| 10046 | * Return the length of the message (0 if no message). |
| 10047 | */ |
| 10048 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10049 | showmode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10050 | { |
| 10051 | int need_clear; |
| 10052 | int length = 0; |
| 10053 | int do_mode; |
| 10054 | int attr; |
| 10055 | int nwr_save; |
| 10056 | #ifdef FEAT_INS_EXPAND |
| 10057 | int sub_attr; |
| 10058 | #endif |
| 10059 | |
Bram Moolenaar | 7df351e | 2006-01-23 22:30:28 +0000 | [diff] [blame] | 10060 | do_mode = ((p_smd && msg_silent == 0) |
| 10061 | && ((State & INSERT) |
| 10062 | || restart_edit |
Bram Moolenaar | f7ff6e8 | 2014-03-23 15:13:05 +0100 | [diff] [blame] | 10063 | || VIsual_active)); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10064 | if (do_mode || Recording) |
| 10065 | { |
| 10066 | /* |
| 10067 | * Don't show mode right now, when not redrawing or inside a mapping. |
| 10068 | * Call char_avail() only when we are going to show something, because |
| 10069 | * it takes a bit of time. |
| 10070 | */ |
| 10071 | if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0) |
| 10072 | { |
| 10073 | redraw_cmdline = TRUE; /* show mode later */ |
| 10074 | return 0; |
| 10075 | } |
| 10076 | |
| 10077 | nwr_save = need_wait_return; |
| 10078 | |
| 10079 | /* wait a bit before overwriting an important message */ |
| 10080 | check_for_delay(FALSE); |
| 10081 | |
| 10082 | /* if the cmdline is more than one line high, erase top lines */ |
| 10083 | need_clear = clear_cmdline; |
| 10084 | if (clear_cmdline && cmdline_row < Rows - 1) |
| 10085 | msg_clr_cmdline(); /* will reset clear_cmdline */ |
| 10086 | |
| 10087 | /* Position on the last line in the window, column 0 */ |
| 10088 | msg_pos_mode(); |
| 10089 | cursor_off(); |
| 10090 | attr = hl_attr(HLF_CM); /* Highlight mode */ |
| 10091 | if (do_mode) |
| 10092 | { |
| 10093 | MSG_PUTS_ATTR("--", attr); |
| 10094 | #if defined(FEAT_XIM) |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10095 | if ( |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10096 | # ifdef FEAT_GUI_GTK |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10097 | preedit_get_status() |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10098 | # else |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10099 | im_get_status() |
Bram Moolenaar | c236c16 | 2008-07-13 17:41:49 +0000 | [diff] [blame] | 10100 | # endif |
Bram Moolenaar | 0909215 | 2010-08-08 16:38:42 +0200 | [diff] [blame] | 10101 | ) |
Bram Moolenaar | 0eda7ac | 2010-06-26 05:38:18 +0200 | [diff] [blame] | 10102 | # 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] | 10103 | MSG_PUTS_ATTR(" IM", attr); |
| 10104 | # else |
| 10105 | MSG_PUTS_ATTR(" XIM", attr); |
| 10106 | # endif |
| 10107 | #endif |
| 10108 | #if defined(FEAT_HANGULIN) && defined(FEAT_GUI) |
| 10109 | if (gui.in_use) |
| 10110 | { |
| 10111 | if (hangul_input_state_get()) |
Bram Moolenaar | 72f4cc4 | 2015-11-10 14:35:18 +0100 | [diff] [blame] | 10112 | { |
| 10113 | /* HANGUL */ |
| 10114 | if (enc_utf8) |
| 10115 | MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr); |
| 10116 | else |
| 10117 | MSG_PUTS_ATTR(" \307\321\261\333", attr); |
| 10118 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10119 | } |
| 10120 | #endif |
| 10121 | #ifdef FEAT_INS_EXPAND |
Bram Moolenaar | ea389e9 | 2014-05-28 21:40:52 +0200 | [diff] [blame] | 10122 | /* CTRL-X in Insert mode */ |
| 10123 | if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10124 | { |
| 10125 | /* These messages can get long, avoid a wrap in a narrow |
| 10126 | * window. Prefer showing edit_submode_extra. */ |
| 10127 | length = (Rows - msg_row) * Columns - 3; |
| 10128 | if (edit_submode_extra != NULL) |
| 10129 | length -= vim_strsize(edit_submode_extra); |
| 10130 | if (length > 0) |
| 10131 | { |
| 10132 | if (edit_submode_pre != NULL) |
| 10133 | length -= vim_strsize(edit_submode_pre); |
| 10134 | if (length - vim_strsize(edit_submode) > 0) |
| 10135 | { |
| 10136 | if (edit_submode_pre != NULL) |
| 10137 | msg_puts_attr(edit_submode_pre, attr); |
| 10138 | msg_puts_attr(edit_submode, attr); |
| 10139 | } |
| 10140 | if (edit_submode_extra != NULL) |
| 10141 | { |
| 10142 | MSG_PUTS_ATTR(" ", attr); /* add a space in between */ |
| 10143 | if ((int)edit_submode_highl < (int)HLF_COUNT) |
| 10144 | sub_attr = hl_attr(edit_submode_highl); |
| 10145 | else |
| 10146 | sub_attr = attr; |
| 10147 | msg_puts_attr(edit_submode_extra, sub_attr); |
| 10148 | } |
| 10149 | } |
| 10150 | length = 0; |
| 10151 | } |
| 10152 | else |
| 10153 | #endif |
| 10154 | { |
| 10155 | #ifdef FEAT_VREPLACE |
| 10156 | if (State & VREPLACE_FLAG) |
| 10157 | MSG_PUTS_ATTR(_(" VREPLACE"), attr); |
| 10158 | else |
| 10159 | #endif |
| 10160 | if (State & REPLACE_FLAG) |
| 10161 | MSG_PUTS_ATTR(_(" REPLACE"), attr); |
| 10162 | else if (State & INSERT) |
| 10163 | { |
| 10164 | #ifdef FEAT_RIGHTLEFT |
| 10165 | if (p_ri) |
| 10166 | MSG_PUTS_ATTR(_(" REVERSE"), attr); |
| 10167 | #endif |
| 10168 | MSG_PUTS_ATTR(_(" INSERT"), attr); |
| 10169 | } |
| 10170 | else if (restart_edit == 'I') |
| 10171 | MSG_PUTS_ATTR(_(" (insert)"), attr); |
| 10172 | else if (restart_edit == 'R') |
| 10173 | MSG_PUTS_ATTR(_(" (replace)"), attr); |
| 10174 | else if (restart_edit == 'V') |
| 10175 | MSG_PUTS_ATTR(_(" (vreplace)"), attr); |
| 10176 | #ifdef FEAT_RIGHTLEFT |
| 10177 | if (p_hkmap) |
| 10178 | MSG_PUTS_ATTR(_(" Hebrew"), attr); |
| 10179 | # ifdef FEAT_FKMAP |
| 10180 | if (p_fkmap) |
| 10181 | MSG_PUTS_ATTR(farsi_text_5, attr); |
| 10182 | # endif |
| 10183 | #endif |
| 10184 | #ifdef FEAT_KEYMAP |
| 10185 | if (State & LANGMAP) |
| 10186 | { |
| 10187 | # ifdef FEAT_ARABIC |
| 10188 | if (curwin->w_p_arab) |
| 10189 | MSG_PUTS_ATTR(_(" Arabic"), attr); |
| 10190 | else |
| 10191 | # endif |
Bram Moolenaar | 73ac0c4 | 2016-07-24 16:17:59 +0200 | [diff] [blame] | 10192 | if (get_keymap_str(curwin, (char_u *)" (%s)", |
| 10193 | NameBuff, MAXPATHL)) |
| 10194 | MSG_PUTS_ATTR(NameBuff, attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10195 | } |
| 10196 | #endif |
| 10197 | if ((State & INSERT) && p_paste) |
| 10198 | MSG_PUTS_ATTR(_(" (paste)"), attr); |
| 10199 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10200 | if (VIsual_active) |
| 10201 | { |
| 10202 | char *p; |
| 10203 | |
| 10204 | /* Don't concatenate separate words to avoid translation |
| 10205 | * problems. */ |
| 10206 | switch ((VIsual_select ? 4 : 0) |
| 10207 | + (VIsual_mode == Ctrl_V) * 2 |
| 10208 | + (VIsual_mode == 'V')) |
| 10209 | { |
| 10210 | case 0: p = N_(" VISUAL"); break; |
| 10211 | case 1: p = N_(" VISUAL LINE"); break; |
| 10212 | case 2: p = N_(" VISUAL BLOCK"); break; |
| 10213 | case 4: p = N_(" SELECT"); break; |
| 10214 | case 5: p = N_(" SELECT LINE"); break; |
| 10215 | default: p = N_(" SELECT BLOCK"); break; |
| 10216 | } |
| 10217 | MSG_PUTS_ATTR(_(p), attr); |
| 10218 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10219 | MSG_PUTS_ATTR(" --", attr); |
| 10220 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10221 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10222 | need_clear = TRUE; |
| 10223 | } |
| 10224 | if (Recording |
| 10225 | #ifdef FEAT_INS_EXPAND |
| 10226 | && edit_submode == NULL /* otherwise it gets too long */ |
| 10227 | #endif |
| 10228 | ) |
| 10229 | { |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10230 | recording_mode(attr); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10231 | need_clear = TRUE; |
| 10232 | } |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10233 | |
| 10234 | mode_displayed = TRUE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10235 | if (need_clear || clear_cmdline) |
| 10236 | msg_clr_eos(); |
| 10237 | msg_didout = FALSE; /* overwrite this message */ |
| 10238 | length = msg_col; |
| 10239 | msg_col = 0; |
| 10240 | need_wait_return = nwr_save; /* never ask for hit-return for this */ |
| 10241 | } |
| 10242 | else if (clear_cmdline && msg_silent == 0) |
| 10243 | /* Clear the whole command line. Will reset "clear_cmdline". */ |
| 10244 | msg_clr_cmdline(); |
| 10245 | |
| 10246 | #ifdef FEAT_CMDL_INFO |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10247 | /* In Visual mode the size of the selected area must be redrawn. */ |
| 10248 | if (VIsual_active) |
| 10249 | clear_showcmd(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10250 | |
| 10251 | /* If the last window has no status line, the ruler is after the mode |
| 10252 | * message and must be redrawn */ |
| 10253 | if (redrawing() |
| 10254 | # ifdef FEAT_WINDOWS |
| 10255 | && lastwin->w_status_height == 0 |
| 10256 | # endif |
| 10257 | ) |
| 10258 | win_redr_ruler(lastwin, TRUE); |
| 10259 | #endif |
| 10260 | redraw_cmdline = FALSE; |
| 10261 | clear_cmdline = FALSE; |
| 10262 | |
| 10263 | return length; |
| 10264 | } |
| 10265 | |
| 10266 | /* |
| 10267 | * Position for a mode message. |
| 10268 | */ |
| 10269 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10270 | msg_pos_mode(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10271 | { |
| 10272 | msg_col = 0; |
| 10273 | msg_row = Rows - 1; |
| 10274 | } |
| 10275 | |
| 10276 | /* |
| 10277 | * Delete mode message. Used when ESC is typed which is expected to end |
| 10278 | * Insert mode (but Insert mode didn't end yet!). |
Bram Moolenaar | d12f5c1 | 2006-01-25 22:10:52 +0000 | [diff] [blame] | 10279 | * Caller should check "mode_displayed". |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10280 | */ |
| 10281 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10282 | unshowmode(int force) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10283 | { |
| 10284 | /* |
Bram Moolenaar | e4ebd29 | 2010-01-19 17:40:46 +0100 | [diff] [blame] | 10285 | * 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] | 10286 | */ |
| 10287 | if (!redrawing() || (!force && char_avail() && !KeyTyped)) |
| 10288 | redraw_cmdline = TRUE; /* delete mode later */ |
| 10289 | else |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10290 | clearmode(); |
| 10291 | } |
| 10292 | |
| 10293 | /* |
| 10294 | * Clear the mode message. |
| 10295 | */ |
| 10296 | void |
Bram Moolenaar | cf08946 | 2016-06-12 21:18:43 +0200 | [diff] [blame] | 10297 | clearmode(void) |
Bram Moolenaar | fd773e9 | 2016-04-02 19:39:16 +0200 | [diff] [blame] | 10298 | { |
| 10299 | msg_pos_mode(); |
| 10300 | if (Recording) |
| 10301 | recording_mode(hl_attr(HLF_CM)); |
| 10302 | msg_clr_eos(); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10303 | } |
| 10304 | |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10305 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10306 | recording_mode(int attr) |
Bram Moolenaar | a0ed84a | 2015-11-19 17:56:13 +0100 | [diff] [blame] | 10307 | { |
| 10308 | MSG_PUTS_ATTR(_("recording"), attr); |
| 10309 | if (!shortmess(SHM_RECORDING)) |
| 10310 | { |
| 10311 | char_u s[4]; |
| 10312 | sprintf((char *)s, " @%c", Recording); |
| 10313 | MSG_PUTS_ATTR(s, attr); |
| 10314 | } |
| 10315 | } |
| 10316 | |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10317 | #if defined(FEAT_WINDOWS) |
| 10318 | /* |
| 10319 | * Draw the tab pages line at the top of the Vim window. |
| 10320 | */ |
| 10321 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10322 | draw_tabline(void) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10323 | { |
| 10324 | int tabcount = 0; |
| 10325 | tabpage_T *tp; |
| 10326 | int tabwidth; |
| 10327 | int col = 0; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10328 | int scol = 0; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10329 | int attr; |
| 10330 | win_T *wp; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10331 | win_T *cwp; |
| 10332 | int wincount; |
| 10333 | int modified; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10334 | int c; |
| 10335 | int len; |
| 10336 | int attr_sel = hl_attr(HLF_TPS); |
| 10337 | int attr_nosel = hl_attr(HLF_TP); |
| 10338 | int attr_fill = hl_attr(HLF_TPF); |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10339 | char_u *p; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10340 | int room; |
| 10341 | int use_sep_chars = (t_colors < 8 |
| 10342 | #ifdef FEAT_GUI |
| 10343 | && !gui.in_use |
| 10344 | #endif |
Bram Moolenaar | 61be73b | 2016-04-29 22:59:22 +0200 | [diff] [blame] | 10345 | #ifdef FEAT_TERMGUICOLORS |
| 10346 | && !p_tgc |
Bram Moolenaar | 8a633e3 | 2016-04-21 21:10:14 +0200 | [diff] [blame] | 10347 | #endif |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10348 | ); |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10349 | |
Bram Moolenaar | c695cec | 2017-01-08 20:00:04 +0100 | [diff] [blame] | 10350 | if (ScreenLines == NULL) |
| 10351 | return; |
Bram Moolenaar | 997fb4b | 2006-02-17 21:53:23 +0000 | [diff] [blame] | 10352 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10353 | |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10354 | #ifdef FEAT_GUI_TABLINE |
Bram Moolenaar | db552d60 | 2006-03-23 22:59:57 +0000 | [diff] [blame] | 10355 | /* Take care of a GUI tabline. */ |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10356 | if (gui_use_tabline()) |
| 10357 | { |
| 10358 | gui_update_tabline(); |
| 10359 | return; |
| 10360 | } |
| 10361 | #endif |
| 10362 | |
| 10363 | if (tabline_height() < 1) |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10364 | return; |
| 10365 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10366 | #if defined(FEAT_STL_OPT) |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10367 | |
| 10368 | /* Init TabPageIdxs[] to zero: Clicking outside of tabs has no effect. */ |
| 10369 | for (scol = 0; scol < Columns; ++scol) |
| 10370 | TabPageIdxs[scol] = 0; |
| 10371 | |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10372 | /* Use the 'tabline' option if it's set. */ |
| 10373 | if (*p_tal != NUL) |
| 10374 | { |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10375 | int saved_did_emsg = did_emsg; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10376 | |
| 10377 | /* Check for an error. If there is one we would loop in redrawing the |
| 10378 | * screen. Avoid that by making 'tabline' empty. */ |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10379 | did_emsg = FALSE; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10380 | win_redr_custom(NULL, FALSE); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10381 | if (did_emsg) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10382 | set_string_option_direct((char_u *)"tabline", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10383 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | f73d3bc | 2016-04-11 21:55:15 +0200 | [diff] [blame] | 10384 | did_emsg |= saved_did_emsg; |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10385 | } |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10386 | else |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10387 | #endif |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10388 | { |
Bram Moolenaar | 2932359 | 2016-07-24 22:04:11 +0200 | [diff] [blame] | 10389 | FOR_ALL_TABPAGES(tp) |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10390 | ++tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10391 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10392 | tabwidth = (Columns - 1 + tabcount / 2) / tabcount; |
| 10393 | if (tabwidth < 6) |
| 10394 | tabwidth = 6; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10395 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10396 | attr = attr_nosel; |
| 10397 | tabcount = 0; |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10398 | scol = 0; |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10399 | for (tp = first_tabpage; tp != NULL && col < Columns - 4; |
| 10400 | tp = tp->tp_next) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10401 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10402 | scol = col; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10403 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10404 | if (tp->tp_topframe == topframe) |
| 10405 | attr = attr_sel; |
| 10406 | if (use_sep_chars && col > 0) |
| 10407 | screen_putchar('|', 0, col++, attr); |
| 10408 | |
| 10409 | if (tp->tp_topframe != topframe) |
| 10410 | attr = attr_nosel; |
| 10411 | |
| 10412 | screen_putchar(' ', 0, col++, attr); |
| 10413 | |
| 10414 | if (tp == curtab) |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10415 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10416 | cwp = curwin; |
| 10417 | wp = firstwin; |
| 10418 | } |
| 10419 | else |
| 10420 | { |
| 10421 | cwp = tp->tp_curwin; |
| 10422 | wp = tp->tp_firstwin; |
| 10423 | } |
| 10424 | |
| 10425 | modified = FALSE; |
| 10426 | for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount) |
| 10427 | if (bufIsChanged(wp->w_buffer)) |
| 10428 | modified = TRUE; |
| 10429 | if (modified || wincount > 1) |
| 10430 | { |
| 10431 | if (wincount > 1) |
| 10432 | { |
| 10433 | vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount); |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10434 | len = (int)STRLEN(NameBuff); |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10435 | if (col + len >= Columns - 3) |
| 10436 | break; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10437 | screen_puts_len(NameBuff, len, 0, col, |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10438 | #if defined(FEAT_SYN_HL) |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10439 | hl_combine_attr(attr, hl_attr(HLF_T)) |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10440 | #else |
Bram Moolenaar | e0f1482 | 2014-08-06 13:20:56 +0200 | [diff] [blame] | 10441 | attr |
Bram Moolenaar | faa959a | 2006-02-20 21:37:40 +0000 | [diff] [blame] | 10442 | #endif |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10443 | ); |
| 10444 | col += len; |
| 10445 | } |
| 10446 | if (modified) |
| 10447 | screen_puts_len((char_u *)"+", 1, 0, col++, attr); |
| 10448 | screen_putchar(' ', 0, col++, attr); |
| 10449 | } |
| 10450 | |
| 10451 | room = scol - col + tabwidth - 1; |
| 10452 | if (room > 0) |
| 10453 | { |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10454 | /* Get buffer name in NameBuff[] */ |
| 10455 | get_trans_bufname(cwp->w_buffer); |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 10456 | shorten_dir(NameBuff); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10457 | len = vim_strsize(NameBuff); |
| 10458 | p = NameBuff; |
| 10459 | #ifdef FEAT_MBYTE |
| 10460 | if (has_mbyte) |
| 10461 | while (len > room) |
| 10462 | { |
| 10463 | len -= ptr2cells(p); |
| 10464 | mb_ptr_adv(p); |
| 10465 | } |
| 10466 | else |
| 10467 | #endif |
| 10468 | if (len > room) |
| 10469 | { |
| 10470 | p += len - room; |
| 10471 | len = room; |
| 10472 | } |
Bram Moolenaar | fd2ac76 | 2006-03-01 22:09:21 +0000 | [diff] [blame] | 10473 | if (len > Columns - col - 1) |
| 10474 | len = Columns - col - 1; |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10475 | |
Bram Moolenaar | a93fa7e | 2006-04-17 22:14:47 +0000 | [diff] [blame] | 10476 | screen_puts_len(p, (int)STRLEN(p), 0, col, attr); |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10477 | col += len; |
| 10478 | } |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10479 | screen_putchar(' ', 0, col++, attr); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10480 | |
| 10481 | /* Store the tab page number in TabPageIdxs[], so that |
| 10482 | * jump_to_mouse() knows where each one is. */ |
| 10483 | ++tabcount; |
| 10484 | while (scol < col) |
| 10485 | TabPageIdxs[scol++] = tabcount; |
Bram Moolenaar | f740b29 | 2006-02-16 22:11:02 +0000 | [diff] [blame] | 10486 | } |
| 10487 | |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10488 | if (use_sep_chars) |
| 10489 | c = '_'; |
| 10490 | else |
| 10491 | c = ' '; |
| 10492 | screen_fill(0, 1, col, (int)Columns, c, c, attr_fill); |
Bram Moolenaar | d1f56e6 | 2006-02-22 21:25:37 +0000 | [diff] [blame] | 10493 | |
| 10494 | /* Put an "X" for closing the current tab if there are several. */ |
| 10495 | if (first_tabpage->tp_next != NULL) |
| 10496 | { |
| 10497 | screen_putchar('X', 0, (int)Columns - 1, attr_nosel); |
| 10498 | TabPageIdxs[Columns - 1] = -999; |
| 10499 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10500 | } |
Bram Moolenaar | b21e584 | 2006-04-16 18:30:08 +0000 | [diff] [blame] | 10501 | |
| 10502 | /* Reset the flag here again, in case evaluating 'tabline' causes it to be |
| 10503 | * set. */ |
| 10504 | redraw_tabline = FALSE; |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10505 | } |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10506 | |
| 10507 | /* |
| 10508 | * Get buffer name for "buf" into NameBuff[]. |
| 10509 | * Takes care of special buffer names and translates special characters. |
| 10510 | */ |
| 10511 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10512 | get_trans_bufname(buf_T *buf) |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10513 | { |
| 10514 | if (buf_spname(buf) != NULL) |
Bram Moolenaar | e1704ba | 2012-10-03 18:25:00 +0200 | [diff] [blame] | 10515 | vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1); |
Bram Moolenaar | 32466aa | 2006-02-24 23:53:04 +0000 | [diff] [blame] | 10516 | else |
| 10517 | home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE); |
| 10518 | trans_characters(NameBuff, MAXPATHL); |
| 10519 | } |
Bram Moolenaar | 1d2ba7f | 2006-02-14 22:29:30 +0000 | [diff] [blame] | 10520 | #endif |
| 10521 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10522 | #if defined(FEAT_WINDOWS) || defined(FEAT_WILDMENU) || defined(FEAT_STL_OPT) |
| 10523 | /* |
| 10524 | * Get the character to use in a status line. Get its attributes in "*attr". |
| 10525 | */ |
| 10526 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10527 | fillchar_status(int *attr, int is_curwin) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10528 | { |
| 10529 | int fill; |
| 10530 | if (is_curwin) |
| 10531 | { |
| 10532 | *attr = hl_attr(HLF_S); |
| 10533 | fill = fill_stl; |
| 10534 | } |
| 10535 | else |
| 10536 | { |
| 10537 | *attr = hl_attr(HLF_SNC); |
| 10538 | fill = fill_stlnc; |
| 10539 | } |
| 10540 | /* Use fill when there is highlighting, and highlighting of current |
| 10541 | * window differs, or the fillchars differ, or this is not the |
| 10542 | * current window */ |
| 10543 | if (*attr != 0 && ((hl_attr(HLF_S) != hl_attr(HLF_SNC) |
Bram Moolenaar | a1f4cb9 | 2016-11-06 15:25:42 +0100 | [diff] [blame] | 10544 | || !is_curwin || ONE_WINDOW) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10545 | || (fill_stl != fill_stlnc))) |
| 10546 | return fill; |
| 10547 | if (is_curwin) |
| 10548 | return '^'; |
| 10549 | return '='; |
| 10550 | } |
| 10551 | #endif |
| 10552 | |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10553 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10554 | /* |
| 10555 | * Get the character to use in a separator between vertically split windows. |
| 10556 | * Get its attributes in "*attr". |
| 10557 | */ |
| 10558 | static int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10559 | fillchar_vsep(int *attr) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10560 | { |
| 10561 | *attr = hl_attr(HLF_C); |
| 10562 | if (*attr == 0 && fill_vert == ' ') |
| 10563 | return '|'; |
| 10564 | else |
| 10565 | return fill_vert; |
| 10566 | } |
| 10567 | #endif |
| 10568 | |
| 10569 | /* |
| 10570 | * Return TRUE if redrawing should currently be done. |
| 10571 | */ |
| 10572 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10573 | redrawing(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10574 | { |
| 10575 | return (!RedrawingDisabled |
| 10576 | && !(p_lz && char_avail() && !KeyTyped && !do_redraw)); |
| 10577 | } |
| 10578 | |
| 10579 | /* |
| 10580 | * Return TRUE if printing messages should currently be done. |
| 10581 | */ |
| 10582 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10583 | messaging(void) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10584 | { |
| 10585 | return (!(p_lz && char_avail() && !KeyTyped)); |
| 10586 | } |
| 10587 | |
| 10588 | /* |
| 10589 | * Show current status info in ruler and various other places |
| 10590 | * If always is FALSE, only show ruler if position has changed. |
| 10591 | */ |
| 10592 | void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10593 | showruler(int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10594 | { |
| 10595 | if (!always && !redrawing()) |
| 10596 | return; |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10597 | #ifdef FEAT_INS_EXPAND |
| 10598 | if (pum_visible()) |
| 10599 | { |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10600 | # ifdef FEAT_WINDOWS |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10601 | /* Don't redraw right now, do it later. */ |
| 10602 | curwin->w_redr_status = TRUE; |
Bram Moolenaar | 71fe80d | 2006-01-22 23:25:56 +0000 | [diff] [blame] | 10603 | # endif |
Bram Moolenaar | 9372a11 | 2005-12-06 19:59:18 +0000 | [diff] [blame] | 10604 | return; |
| 10605 | } |
| 10606 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10607 | #if defined(FEAT_STL_OPT) && defined(FEAT_WINDOWS) |
Bram Moolenaar | b5bf5b8 | 2004-12-24 14:35:23 +0000 | [diff] [blame] | 10608 | 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] | 10609 | { |
Bram Moolenaar | 362f356 | 2009-11-03 16:20:34 +0000 | [diff] [blame] | 10610 | redraw_custom_statusline(curwin); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10611 | } |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10612 | else |
| 10613 | #endif |
| 10614 | #ifdef FEAT_CMDL_INFO |
| 10615 | win_redr_ruler(curwin, always); |
| 10616 | #endif |
| 10617 | |
| 10618 | #ifdef FEAT_TITLE |
| 10619 | if (need_maketitle |
| 10620 | # ifdef FEAT_STL_OPT |
| 10621 | || (p_icon && (stl_syntax & STL_IN_ICON)) |
| 10622 | || (p_title && (stl_syntax & STL_IN_TITLE)) |
| 10623 | # endif |
| 10624 | ) |
| 10625 | maketitle(); |
| 10626 | #endif |
Bram Moolenaar | 497683b | 2008-05-28 17:02:46 +0000 | [diff] [blame] | 10627 | #ifdef FEAT_WINDOWS |
| 10628 | /* Redraw the tab pages line if needed. */ |
| 10629 | if (redraw_tabline) |
| 10630 | draw_tabline(); |
| 10631 | #endif |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10632 | } |
| 10633 | |
| 10634 | #ifdef FEAT_CMDL_INFO |
| 10635 | static void |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10636 | win_redr_ruler(win_T *wp, int always) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10637 | { |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10638 | #define RULER_BUF_LEN 70 |
| 10639 | char_u buffer[RULER_BUF_LEN]; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10640 | int row; |
| 10641 | int fillchar; |
| 10642 | int attr; |
| 10643 | int empty_line = FALSE; |
| 10644 | colnr_T virtcol; |
| 10645 | int i; |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10646 | size_t len; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10647 | int o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10648 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10649 | int this_ru_col; |
| 10650 | int off = 0; |
| 10651 | int width = Columns; |
| 10652 | # define WITH_OFF(x) x |
| 10653 | # define WITH_WIDTH(x) x |
| 10654 | #else |
| 10655 | # define WITH_OFF(x) 0 |
| 10656 | # define WITH_WIDTH(x) Columns |
| 10657 | # define this_ru_col ru_col |
| 10658 | #endif |
| 10659 | |
| 10660 | /* If 'ruler' off or redrawing disabled, don't do anything */ |
| 10661 | if (!p_ru) |
| 10662 | return; |
| 10663 | |
| 10664 | /* |
| 10665 | * Check if cursor.lnum is valid, since win_redr_ruler() may be called |
| 10666 | * after deleting lines, before cursor.lnum is corrected. |
| 10667 | */ |
| 10668 | if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count) |
| 10669 | return; |
| 10670 | |
| 10671 | #ifdef FEAT_INS_EXPAND |
| 10672 | /* Don't draw the ruler while doing insert-completion, it might overwrite |
| 10673 | * the (long) mode message. */ |
| 10674 | # ifdef FEAT_WINDOWS |
| 10675 | if (wp == lastwin && lastwin->w_status_height == 0) |
| 10676 | # endif |
| 10677 | if (edit_submode != NULL) |
| 10678 | return; |
Bram Moolenaar | 1c7715d | 2005-10-03 22:02:18 +0000 | [diff] [blame] | 10679 | /* Don't draw the ruler when the popup menu is visible, it may overlap. */ |
| 10680 | if (pum_visible()) |
| 10681 | return; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10682 | #endif |
| 10683 | |
| 10684 | #ifdef FEAT_STL_OPT |
| 10685 | if (*p_ruf) |
| 10686 | { |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10687 | int save_called_emsg = called_emsg; |
| 10688 | |
| 10689 | called_emsg = FALSE; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10690 | win_redr_custom(wp, TRUE); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10691 | if (called_emsg) |
| 10692 | set_string_option_direct((char_u *)"rulerformat", -1, |
Bram Moolenaar | 5e3cb7e | 2006-02-27 23:58:35 +0000 | [diff] [blame] | 10693 | (char_u *)"", OPT_FREE, SID_ERROR); |
Bram Moolenaar | 238a564 | 2006-02-21 22:12:05 +0000 | [diff] [blame] | 10694 | called_emsg |= save_called_emsg; |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10695 | return; |
| 10696 | } |
| 10697 | #endif |
| 10698 | |
| 10699 | /* |
| 10700 | * Check if not in Insert mode and the line is empty (will show "0-1"). |
| 10701 | */ |
| 10702 | if (!(State & INSERT) |
| 10703 | && *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL) |
| 10704 | empty_line = TRUE; |
| 10705 | |
| 10706 | /* |
| 10707 | * Only draw the ruler when something changed. |
| 10708 | */ |
| 10709 | validate_virtcol_win(wp); |
| 10710 | if ( redraw_cmdline |
| 10711 | || always |
| 10712 | || wp->w_cursor.lnum != wp->w_ru_cursor.lnum |
| 10713 | || wp->w_cursor.col != wp->w_ru_cursor.col |
| 10714 | || wp->w_virtcol != wp->w_ru_virtcol |
| 10715 | #ifdef FEAT_VIRTUALEDIT |
| 10716 | || wp->w_cursor.coladd != wp->w_ru_cursor.coladd |
| 10717 | #endif |
| 10718 | || wp->w_topline != wp->w_ru_topline |
| 10719 | || wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count |
| 10720 | #ifdef FEAT_DIFF |
| 10721 | || wp->w_topfill != wp->w_ru_topfill |
| 10722 | #endif |
| 10723 | || empty_line != wp->w_ru_empty) |
| 10724 | { |
| 10725 | cursor_off(); |
| 10726 | #ifdef FEAT_WINDOWS |
| 10727 | if (wp->w_status_height) |
| 10728 | { |
| 10729 | row = W_WINROW(wp) + wp->w_height; |
| 10730 | fillchar = fillchar_status(&attr, wp == curwin); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10731 | off = W_WINCOL(wp); |
| 10732 | width = W_WIDTH(wp); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10733 | } |
| 10734 | else |
| 10735 | #endif |
| 10736 | { |
| 10737 | row = Rows - 1; |
| 10738 | fillchar = ' '; |
| 10739 | attr = 0; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10740 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10741 | width = Columns; |
| 10742 | off = 0; |
| 10743 | #endif |
| 10744 | } |
| 10745 | |
| 10746 | /* In list mode virtcol needs to be recomputed */ |
| 10747 | virtcol = wp->w_virtcol; |
| 10748 | if (wp->w_p_list && lcs_tab1 == NUL) |
| 10749 | { |
| 10750 | wp->w_p_list = FALSE; |
| 10751 | getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL); |
| 10752 | wp->w_p_list = TRUE; |
| 10753 | } |
| 10754 | |
| 10755 | /* |
| 10756 | * Some sprintfs return the length, some return a pointer. |
| 10757 | * To avoid portability problems we use strlen() here. |
| 10758 | */ |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10759 | vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,", |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10760 | (wp->w_buffer->b_ml.ml_flags & ML_EMPTY) |
| 10761 | ? 0L |
| 10762 | : (long)(wp->w_cursor.lnum)); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10763 | len = STRLEN(buffer); |
| 10764 | col_print(buffer + len, RULER_BUF_LEN - len, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10765 | empty_line ? 0 : (int)wp->w_cursor.col + 1, |
| 10766 | (int)virtcol + 1); |
| 10767 | |
| 10768 | /* |
| 10769 | * Add a "50%" if there is room for it. |
| 10770 | * On the last line, don't print in the last column (scrolls the |
| 10771 | * screen up on some terminals). |
| 10772 | */ |
| 10773 | i = (int)STRLEN(buffer); |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10774 | get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10775 | o = i + vim_strsize(buffer + i + 1); |
| 10776 | #ifdef FEAT_WINDOWS |
| 10777 | if (wp->w_status_height == 0) /* can't use last char of screen */ |
| 10778 | #endif |
| 10779 | ++o; |
Bram Moolenaar | 44a2f92 | 2016-03-19 22:11:51 +0100 | [diff] [blame] | 10780 | #ifdef FEAT_WINDOWS |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10781 | this_ru_col = ru_col - (Columns - width); |
| 10782 | if (this_ru_col < 0) |
| 10783 | this_ru_col = 0; |
| 10784 | #endif |
| 10785 | /* Never use more than half the window/screen width, leave the other |
| 10786 | * half for the filename. */ |
| 10787 | if (this_ru_col < (WITH_WIDTH(width) + 1) / 2) |
| 10788 | this_ru_col = (WITH_WIDTH(width) + 1) / 2; |
| 10789 | if (this_ru_col + o < WITH_WIDTH(width)) |
| 10790 | { |
Bram Moolenaar | 0027c21 | 2015-01-07 13:31:52 +0100 | [diff] [blame] | 10791 | /* need at least 3 chars left for get_rel_pos() + NUL */ |
| 10792 | 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] | 10793 | { |
| 10794 | #ifdef FEAT_MBYTE |
| 10795 | if (has_mbyte) |
| 10796 | i += (*mb_char2bytes)(fillchar, buffer + i); |
| 10797 | else |
| 10798 | #endif |
| 10799 | buffer[i++] = fillchar; |
| 10800 | ++o; |
| 10801 | } |
Bram Moolenaar | 0ab2a88 | 2009-05-13 10:51:08 +0000 | [diff] [blame] | 10802 | get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i); |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10803 | } |
| 10804 | /* Truncate at window boundary. */ |
| 10805 | #ifdef FEAT_MBYTE |
| 10806 | if (has_mbyte) |
| 10807 | { |
| 10808 | o = 0; |
Bram Moolenaar | 0fa313a | 2005-08-10 21:07:57 +0000 | [diff] [blame] | 10809 | for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i)) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 10810 | { |
| 10811 | o += (*mb_ptr2cells)(buffer + i); |
| 10812 | if (this_ru_col + o > WITH_WIDTH(width)) |
| 10813 | { |
| 10814 | buffer[i] = NUL; |
| 10815 | break; |
| 10816 | } |
| 10817 | } |
| 10818 | } |
| 10819 | else |
| 10820 | #endif |
| 10821 | if (this_ru_col + (int)STRLEN(buffer) > WITH_WIDTH(width)) |
| 10822 | buffer[WITH_WIDTH(width) - this_ru_col] = NUL; |
| 10823 | |
| 10824 | screen_puts(buffer, row, this_ru_col + WITH_OFF(off), attr); |
| 10825 | i = redraw_cmdline; |
| 10826 | screen_fill(row, row + 1, |
| 10827 | this_ru_col + WITH_OFF(off) + (int)STRLEN(buffer), |
| 10828 | (int)(WITH_OFF(off) + WITH_WIDTH(width)), |
| 10829 | fillchar, fillchar, attr); |
| 10830 | /* don't redraw the cmdline because of showing the ruler */ |
| 10831 | redraw_cmdline = i; |
| 10832 | wp->w_ru_cursor = wp->w_cursor; |
| 10833 | wp->w_ru_virtcol = wp->w_virtcol; |
| 10834 | wp->w_ru_empty = empty_line; |
| 10835 | wp->w_ru_topline = wp->w_topline; |
| 10836 | wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count; |
| 10837 | #ifdef FEAT_DIFF |
| 10838 | wp->w_ru_topfill = wp->w_topfill; |
| 10839 | #endif |
| 10840 | } |
| 10841 | } |
| 10842 | #endif |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10843 | |
| 10844 | #if defined(FEAT_LINEBREAK) || defined(PROTO) |
| 10845 | /* |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10846 | * Return the width of the 'number' and 'relativenumber' column. |
| 10847 | * Caller may need to check if 'number' or 'relativenumber' is set. |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10848 | * Otherwise it depends on 'numberwidth' and the line count. |
| 10849 | */ |
| 10850 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10851 | number_width(win_T *wp) |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10852 | { |
| 10853 | int n; |
| 10854 | linenr_T lnum; |
| 10855 | |
Bram Moolenaar | 5ebc09b | 2013-06-04 22:13:50 +0200 | [diff] [blame] | 10856 | if (wp->w_p_rnu && !wp->w_p_nu) |
| 10857 | /* cursor line shows "0" */ |
| 10858 | lnum = wp->w_height; |
| 10859 | else |
| 10860 | /* cursor line shows absolute line number */ |
| 10861 | lnum = wp->w_buffer->b_ml.ml_line_count; |
Bram Moolenaar | 6448667 | 2010-05-16 15:46:46 +0200 | [diff] [blame] | 10862 | |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10863 | 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] | 10864 | return wp->w_nrwidth_width; |
| 10865 | wp->w_nrwidth_line_count = lnum; |
| 10866 | |
| 10867 | n = 0; |
| 10868 | do |
| 10869 | { |
Bram Moolenaar | c9b4b05 | 2006-04-30 18:54:39 +0000 | [diff] [blame] | 10870 | lnum /= 10; |
| 10871 | ++n; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10872 | } while (lnum > 0); |
| 10873 | |
| 10874 | /* 'numberwidth' gives the minimal width plus one */ |
| 10875 | if (n < wp->w_p_nuw - 1) |
| 10876 | n = wp->w_p_nuw - 1; |
| 10877 | |
| 10878 | wp->w_nrwidth_width = n; |
Bram Moolenaar | 6b31467 | 2015-03-20 15:42:10 +0100 | [diff] [blame] | 10879 | wp->w_nuw_cached = wp->w_p_nuw; |
Bram Moolenaar | 592e0a2 | 2004-07-03 16:05:59 +0000 | [diff] [blame] | 10880 | return n; |
| 10881 | } |
| 10882 | #endif |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10883 | |
| 10884 | /* |
| 10885 | * Return the current cursor column. This is the actual position on the |
| 10886 | * screen. First column is 0. |
| 10887 | */ |
| 10888 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10889 | screen_screencol(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10890 | { |
| 10891 | return screen_cur_col; |
| 10892 | } |
| 10893 | |
| 10894 | /* |
| 10895 | * Return the current cursor row. This is the actual position on the screen. |
| 10896 | * First row is 0. |
| 10897 | */ |
| 10898 | int |
Bram Moolenaar | 0554097 | 2016-01-30 20:31:25 +0100 | [diff] [blame] | 10899 | screen_screenrow(void) |
Bram Moolenaar | 9750bb1 | 2012-12-05 16:10:42 +0100 | [diff] [blame] | 10900 | { |
| 10901 | return screen_cur_row; |
| 10902 | } |